1 /*
2 * Copyright (c) 2007 Creative Sphere Limited.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 *
10 * Creative Sphere - initial API and implementation
11 *
12 */
13 package org.abstracthorizon.aequo.action;
14
15 import java.awt.event.ActionEvent;
16 import java.awt.event.ActionListener;
17 import java.io.File;
18
19 import javax.swing.AbstractAction;
20 import javax.swing.JFrame;
21
22 import org.abstracthorizon.aequo.GlobalContext;
23 import org.abstracthorizon.aequo.file.FileCompareWindow;
24 import org.abstracthorizon.aequo.util.filters.Filter;
25
26 /**
27 * Shows {@link FileCompareWindow}
28 *
29 * @author Daniel Sendula
30 */
31 public class CompareFilesAction extends AbstractAction implements ActionListener {
32
33 /** Left file */
34 protected File left;
35
36 /** Right file */
37 protected File right;
38
39 /** Filters to be applied */
40 protected Filter filters;
41
42 /** Global context */
43 protected GlobalContext context;
44
45 /** Window to be closed */
46 protected JFrame window;
47
48 /**
49 * Constructor
50 * @param context context
51 */
52 public CompareFilesAction(GlobalContext context) {
53 this(context, null);
54 }
55
56 /**
57 * Constructor
58 * @param context global context
59 * @param window window to be closed when action is invoked
60 */
61 public CompareFilesAction(GlobalContext context, JFrame window) {
62 this.context = context;
63 this.window = window;
64 }
65
66 /**
67 * Constructor
68 * @param left left file
69 * @param right right file
70 * @param filters filters to be applied
71 * @param context global context
72 */
73 public CompareFilesAction(File left, File right, Filter filters, GlobalContext context) {
74 this(left, right, filters, context, null);
75 }
76
77 /**
78 * Constructor
79 * @param left left file
80 * @param right right file
81 * @param filters filters
82 * @param context global context
83 * @param window window to be closes when action is invoked
84 */
85 public CompareFilesAction(File left, File right, Filter filters, GlobalContext context, JFrame window) {
86 this.left = left;
87 this.right = right;
88 this.filters = filters;
89 this.context = context;
90 this.window = window;
91 }
92
93 /**
94 * This method creates {@link FileCompareWindow} and makes it visible. Also it disposes the window
95 * given in costructor (if any).
96 * @param e event
97 */
98 public void actionPerformed(ActionEvent e) {
99 FileCompareWindow compareWindow = new FileCompareWindow(context, getLeft(), getRight(), getFilters());
100 compareWindow.initialise();
101 compareWindow.setVisible(true);
102 if (window != null) {
103 window.dispose();
104 }
105 }
106
107 /**
108 * Returns left file
109 * @return left file
110 */
111 protected File getLeft() {
112 return left;
113 }
114
115 /**
116 * Returns right file
117 * @return right file
118 */
119 protected File getRight() {
120 return right;
121 }
122
123 /**
124 * Returns filters
125 * @return filters
126 */
127 protected Filter getFilters() {
128 return filters;
129 }
130 }