1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.gui.action;
21
22 import java.io.File;
23 import java.util.Iterator;
24 import java.util.LinkedList;
25
26 import javax.swing.Action;
27
28 /***
29 * Provides a helper class for the file actions. All
30 * <code>PasteFileAction</code> should call {@link #addPasteListener} to get
31 * enabled or disabled when actions are pending.
32 *
33 * <p>All calls to this class need to be swing synchronized.
34 *
35 * @see CopyFileAction
36 * @see CutFileAction
37 * @see PasteFileAction
38 */
39 public class FileActionManager {
40
41
42
43 /***
44 * The action type for no pending action.
45 */
46 public static final int ACTION_DO_NOTHING = 0;
47
48 /***
49 * The action type for a copy operation.
50 */
51 public static final int ACTION_COPY = 1;
52
53 /***
54 * The action type for a move operation.
55 */
56 public static final int ACTION_MOVE = 2;
57
58
59
60 private static int action = 0;
61 private static File[] files = null;
62
63 /***
64 * A list of <code>Action</code> objects.
65 */
66 private static LinkedList pasteActions = new LinkedList();
67
68
69
70 private FileActionManager()
71 {
72 }
73
74
75
76 /***
77 * Adds a listener. The <code>action</code> object will be enabled, when
78 * an action is pending and disabled after the paste action has been
79 * performed.
80 */
81 public static void addPasteListener(Action action)
82 {
83 pasteActions.add(action);
84 action.setEnabled(getFiles() != null);
85 }
86
87 /***
88 * Returns the pending action.
89 *
90 * @return the action type
91 */
92 public static int getAction()
93 {
94 return action;
95 }
96
97 /***
98 * Returns the pending <code>File</code> objects.
99 */
100 public static File[] getFiles()
101 {
102 return files;
103 }
104
105 /***
106 * Sets the <code>File</code> objects and <code>action</code> that a
107 * subsequent <code>PasteFileAction</code> would perform.
108 */
109 public static void setFiles(File[] files, int action)
110 {
111 FileActionManager.files = files;
112 FileActionManager.action = action;
113
114 for (Iterator i = pasteActions.iterator(); i.hasNext();) {
115 ((PasteFileAction)i.next()).setEnabled(files != null);
116 }
117 }
118
119 /***
120 * Cancels the pending action.
121 */
122 public static void unsetFiles()
123 {
124 setFiles(null, ACTION_DO_NOTHING);
125 }
126
127 }