Source code: com/cybertivity/powerjournal/MainActionFactory.java
1 /*
2 * Title: Similated Intelligence
3 * Copyright: Copyright (c) 2001 Cybertivity
4 * Company: <A HREF="http://www.cybertivity.com">Cybertivity</A>
5 * @author <A HREF="mailto:chris.arrowood@cybertivity.com">Chris Arrowood</A>
6 * @version $Id: MainActionFactory.java,v 1.9 2001/12/27 20:28:12 arrowood Exp $
7 */
8 package com.cybertivity.powerjournal;
9 import com.cybertivity.powerjournal.framework.ActionFactory;
10 import java.awt.Event;
11 import javax.swing.Action;
12 import javax.swing.KeyStroke;
13
14 /**
15 * Description of the Class
16 *
17 * @author arrowood
18 * @created June 2, 2001
19 */
20 public class MainActionFactory extends ActionFactory {
21
22 public static final String ACTION_QUIT = "Quit";
23 public static final String ACTION_CANCEL = "Cancel";
24 public static final String ACTION_ABOUT = "About";
25 public static final String ACTION_VIEW_ENTRY = "View Entry";
26 public static final String ACTION_VIEW_ALL_ENTRIES = "View All";
27 public static final String ACTION_DB_OPTIONS = "Database Options";
28 public static final String ACTION_NEW_JOURNAL = "New Journal";
29 public static final String ACTION_DELETE_JOURNAL = "Delete Journal";
30 public static final String ACTION_CHANGE_PASSWORD = "Change Password";
31 public static final String ACTION_CHANGE_JOURNAL = "Select Journal";
32 public static final String ACTION_EXPORT_CSV = "... as Comma Seperated Values";
33 public static final String ACTION_EXPORT_TEXT = "... as Text";
34 public static final String ACTION_EXPORT_HTML = "... as HTML";
35 public static final String ACTION_SKINS_USE = "Use Skins";
36 public static final String ACTION_SKINS_CHOOSE = "Change Skin";
37
38 public MainActionFactory(String path) {
39 super(path);
40 }
41
42
43 public DefaultAction createAction(String command) {
44 DefaultAction action = super.createAction(command);
45
46
47 if(command.equals(ACTION_QUIT)) {
48 action = new QuitAction();
49 } else if(command.equals(ACTION_CANCEL)) {
50 action = new CancelAction();
51 } else if(command.equals(ACTION_ABOUT)) {
52 action = new AboutAction();
53 } else if(command.equals(ACTION_VIEW_ENTRY)) {
54 action = new ViewAction();
55 } else if(command.equals(ACTION_VIEW_ALL_ENTRIES)) {
56 action = new GenericAction(ACTION_VIEW_ALL_ENTRIES);
57 } else if(command.equals(ACTION_DB_OPTIONS)) {
58 action = new OptionsDatabaseAction();
59 } else if(command.equals(ACTION_NEW_JOURNAL)) {
60 action = new GenericAction(ACTION_NEW_JOURNAL);
61 } else if(command.equals(ACTION_DELETE_JOURNAL)) {
62 action = new GenericAction(ACTION_DELETE_JOURNAL,'D',Event.CTRL_MASK);
63 } else if(command.equals(ACTION_CHANGE_PASSWORD)) {
64 action = new GenericAction(ACTION_CHANGE_PASSWORD);
65 } else if(command.equals(ACTION_CHANGE_JOURNAL)) {
66 action = new GenericAction(ACTION_CHANGE_JOURNAL,'S',Event.CTRL_MASK);
67 } else if(command.equals(ACTION_EXPORT_CSV)) {
68 action = new GenericAction(ACTION_EXPORT_CSV);
69 } else if(command.equals(ACTION_EXPORT_TEXT)) {
70 action = new GenericAction(ACTION_EXPORT_TEXT);
71 } else if(command.equals(ACTION_EXPORT_HTML)) {
72 action = new GenericAction(ACTION_EXPORT_HTML);
73 } else if(command.equals(ACTION_SKINS_CHOOSE)) {
74 action = new GenericAction(ACTION_SKINS_CHOOSE);
75 } else if(command.equals(ACTION_SKINS_USE)) {
76 action = new GenericToggleAction(ACTION_SKINS_USE);
77 }
78
79 return action;
80 }
81
82
83
84 public ToggleAction createToggleAction(String command) {
85 ToggleAction action = super.createToggleAction(command);
86
87 if(command.equals(ACTION_SKINS_USE)) {
88 action = new GenericToggleAction(ACTION_SKINS_USE);
89 }
90
91 return action;
92 }
93
94 private class OptionsDatabaseAction extends DefaultAction {
95 public OptionsDatabaseAction() {
96 super(ACTION_DB_OPTIONS);
97 putValue(Action.NAME, ACTION_DB_OPTIONS);
98 putValue(Action.SMALL_ICON, null);
99 putValue(LARGE_ICON, null);
100 putValue(TOOL_TIP, ACTION_DB_OPTIONS);
101 putValue(ACTION_COMMAND_KEY, ACTION_DB_OPTIONS);
102 // putValue(ACCELERATOR_KEY,
103 // KeyStroke.getKeyStroke('E', Event.CTRL_MASK, false));
104 }
105 }
106
107 private class ViewAction extends DefaultAction {
108 public ViewAction() {
109 super(ACTION_VIEW_ENTRY);
110 putValue(Action.NAME, ACTION_VIEW_ENTRY);
111 putValue(Action.SMALL_ICON, null);
112 putValue(LARGE_ICON, null);
113 putValue(TOOL_TIP, "View Entry");
114 putValue(ACTION_COMMAND_KEY, ACTION_VIEW_ENTRY);
115 putValue(ACCELERATOR_KEY,
116 KeyStroke.getKeyStroke('E', Event.CTRL_MASK, false));
117 }
118 }
119
120 private class QuitAction extends DefaultAction {
121 public QuitAction() {
122 super(ACTION_QUIT);
123 putValue(Action.NAME, ACTION_QUIT);
124 putValue(Action.SMALL_ICON, null);
125 putValue(LARGE_ICON, null);
126 putValue(TOOL_TIP, "Quit application");
127 putValue(ACTION_COMMAND_KEY, ACTION_QUIT);
128 putValue(ACCELERATOR_KEY,
129 KeyStroke.getKeyStroke('Q', Event.CTRL_MASK, false));
130 }
131 }
132
133
134 private class CancelAction extends DefaultAction {
135 public CancelAction() {
136 super(ACTION_CANCEL);
137 putValue(Action.NAME, ACTION_CANCEL);
138 //putValue(Action.SMALL_ICON, getIcon("Stop16.gif"));
139 //putValue(LARGE_ICON, getIcon("Stop24.gif"));
140 putValue(TOOL_TIP, "Cancel query");
141 putValue(ACTION_COMMAND_KEY, "cancel");
142 putValue(ACCELERATOR_KEY, null);
143 }
144 }
145
146
147 private class AboutAction extends DefaultAction {
148 public AboutAction() {
149 super(ACTION_ABOUT);
150 putValue(Action.NAME, ACTION_ABOUT);
151 putValue(Action.SMALL_ICON, null);
152 putValue(LARGE_ICON, null);
153 putValue(ACTION_COMMAND_KEY, ACTION_ABOUT);
154 putValue(ACCELERATOR_KEY, null);
155 }
156 }
157
158 private class GenericAction extends DefaultAction {
159 public GenericAction(String actionName) {
160 super(actionName);
161 putValue(Action.NAME, actionName);
162 putValue(Action.SMALL_ICON, null);
163 putValue(LARGE_ICON, null);
164 putValue(ACTION_COMMAND_KEY, actionName);
165 putValue(ACCELERATOR_KEY, null);
166 }
167 public GenericAction(String actionName, char keyStroke, int mask) {
168 super(actionName);
169 putValue(Action.NAME, actionName);
170 putValue(Action.SMALL_ICON, null);
171 putValue(LARGE_ICON, null);
172 putValue(ACTION_COMMAND_KEY, actionName);
173 putValue(ACCELERATOR_KEY, null);
174 putValue(ACCELERATOR_KEY,
175 KeyStroke.getKeyStroke(keyStroke, mask, false));
176 }
177 }
178
179 private class GenericToggleAction extends ToggleAction {
180 public GenericToggleAction(String actionName) {
181 super(actionName);
182 putValue(Action.NAME, actionName);
183 putValue(Action.SMALL_ICON, null);
184 putValue(LARGE_ICON, null);
185 putValue(ACTION_COMMAND_KEY, actionName);
186 putValue(ACCELERATOR_KEY, null);
187 }
188 public GenericToggleAction(String actionName, char keyStroke, int mask) {
189 super(actionName);
190 putValue(Action.NAME, actionName);
191 putValue(Action.SMALL_ICON, null);
192 putValue(LARGE_ICON, null);
193 putValue(ACTION_COMMAND_KEY, actionName);
194 putValue(ACCELERATOR_KEY, null);
195 putValue(ACCELERATOR_KEY,
196 KeyStroke.getKeyStroke(keyStroke, mask, false));
197 }
198 }
199
200 }
201