1 package com.explosion.expf.supportmodules;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 import java.awt.event.KeyEvent;
24 import java.util.Hashtable;
25 import java.util.Properties;
26 import java.util.Vector;
27
28 import javax.swing.JButton;
29 import javax.swing.JPanel;
30 import javax.swing.KeyStroke;
31
32 import com.explosion.expf.Application;
33 import com.explosion.expf.ExpActionListener;
34 import com.explosion.expf.ExpConstants;
35 import com.explosion.expf.ExpFrame;
36 import com.explosion.expf.ExpModuleManager;
37 import com.explosion.expf.menusandtools.menu.ExpMenu;
38 import com.explosion.expf.menusandtools.menu.ExpMenuBar;
39 import com.explosion.expf.menusandtools.menu.MenuHelper;
40 import com.explosion.expf.menusandtools.menu.segmented.ExpMenuSegment;
41 import com.explosion.expf.menusandtools.menu.segmented.ExpSegmentedMenu;
42 import com.explosion.expf.menusandtools.tool.ExpToolBar;
43 import com.explosion.expf.menusandtools.tool.ExpToolBarSegment;
44 import com.explosion.utilities.preferences.Preference;
45
46 /***
47 * Author: Stephen Cowx Date: Dec 1, 2002 Time: 12:50:18 PM
48 *
49 * This ExpModuleManager sets up theApplication with support (menu's , button
50 * etc) for editing.
51 */
52
53 public class FileSupportModule implements ExpModuleManager
54 {
55
56 private Vector preferences;
57 private Hashtable preferenceHash;
58
59 private static String newMenuItemName = "New";
60 private static String openMenuItemName = "Open";
61 private static String saveMenuItemName = "Save";
62 private static String saveAsMenuItemName = "Save As";
63 private static String saveAllMenuItemName = "Save All";
64 private static String closeMenuItemName = "Close";
65 private static String closeAllMenuItemName = "Close All";
66
67 public void initialiseGui() throws Exception
68 {
69 ExpMenuBar menuBar = ((ExpFrame) Application.getApplicationFrame()).getExpMenuBar();
70 MenuHelper helper = menuBar.getMenuHelper();
71 ExpMenu menuFile = (ExpMenu) helper.getMenu(ExpConstants.MENU_FILE);
72
73 populateFileMenuSegment(helper, menuFile);
74
75
76 ExpToolBar toolbar = ((ExpFrame) Application.getApplicationFrame()).getExpToolBar();
77 ExpToolBarSegment openclose = toolbar.createNewSegment(ExpToolBarSegment.ANY_POSITION);
78
79 JButton newButton = toolbar.createExpToolBarItem(ExpConstants.DEFAULT_NEW_ICON, "New", ExpConstants.MENU_NEW, 1);
80 JButton openButton = toolbar.createExpToolBarItem(ExpConstants.DEFAULT_FILEOPEN_ICON, "Open", ExpConstants.MENU_OPEN, 1);
81 JButton saveButton = toolbar.createExpToolBarItem(ExpConstants.DEFAULT_FILESAVE_ICON, "Save", ExpConstants.MENU_SAVE, 1);
82
83 openclose.addElement(newButton);
84 openclose.addElement(openButton);
85 openclose.addElement(saveButton);
86 openclose.addElement(null);
87 }
88
89 /***
90 * @param helper
91 * @param menuFile
92 * @throws Exception
93 */
94 public static void populateFileMenuSegment(MenuHelper helper, ExpSegmentedMenu menu) throws Exception
95 {
96
97 ExpMenuSegment newSegment = menu.createNewSegment(ExpMenuSegment.ALWAYS_FIRST_SEGMENT);
98 newSegment.addElement(helper.createMenuItem(newMenuItemName, 'n', ExpConstants.MENU_NEW, KeyStroke.getKeyStroke(KeyEvent.VK_N, KeyEvent.CTRL_MASK), 1));
99 newSegment.addElement(helper.createMenuItem(openMenuItemName, 'o', ExpConstants.MENU_OPEN, KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_MASK), 1));
100
101 ExpMenuSegment saveSegment = menu.createNewSegment(ExpMenuSegment.ANY_POSITION);
102 saveSegment.addElement(helper.createMenuItem(saveMenuItemName, 's', ExpConstants.MENU_SAVE, KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_MASK), 1));
103 saveSegment.addElement(helper.createMenuItem(saveAsMenuItemName, 'a', ExpConstants.MENU_SAVEAS, KeyStroke.getKeyStroke(KeyEvent.VK_A, KeyEvent.CTRL_MASK), 1));
104 saveSegment.addElement(helper.createMenuItem(saveAllMenuItemName, 'v', ExpConstants.MENU_SAVEALL, null, 2));
105
106 ExpMenuSegment closeSegment = menu.createNewSegment(ExpMenuSegment.ANY_POSITION);
107 closeSegment.addElement(helper.createMenuItem(closeMenuItemName, 'c', ExpConstants.MENU_CLOSE, null, 1));
108 closeSegment.addElement(helper.createMenuItem(closeAllMenuItemName, 'l', ExpConstants.MENU_CLOSEALL, null, 2));
109 }
110
111 /***
112 * @param helper
113 * @param menuFile
114 * @throws Exception
115 */
116 public static void populateSaveAndCloseSegment(MenuHelper helper, ExpMenuSegment segment) throws Exception
117 {
118 segment.addElement(helper.createMenuItem(saveMenuItemName, 's', ExpConstants.MENU_SAVE, KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_MASK), 1));
119 segment.addElement(helper.createMenuItem(saveAsMenuItemName, 'a', ExpConstants.MENU_SAVEAS, KeyStroke.getKeyStroke(KeyEvent.VK_A, KeyEvent.CTRL_MASK), 1));
120 segment.addElement(helper.createMenuItem(closeMenuItemName, 'c', ExpConstants.MENU_CLOSE, null, 1));
121 }
122
123 public String getVersion()
124 {
125 return "1.0";
126 }
127
128 public String getName()
129 {
130 return "File Support";
131 }
132
133 public String getDescription()
134 {
135 return "Menu and toolbar support for opening, closing and saving multiple files.";
136 }
137
138 public void initialiseCore(Properties properties)
139 {
140
141 String newName = properties.getProperty(ExpConstants.MENU_NEW);
142 if (newName != null)
143 newMenuItemName = newName;
144
145 String openName = properties.getProperty(ExpConstants.MENU_OPEN);
146 if (openName != null)
147 openMenuItemName = openName;
148
149 String saveName = properties.getProperty(ExpConstants.MENU_SAVE);
150 if (saveName != null)
151 saveMenuItemName = saveName;
152
153 String saveAsName = properties.getProperty(ExpConstants.MENU_SAVEAS);
154 if (saveAsName != null)
155 saveAsMenuItemName = saveAsName;
156
157 String saveAllName = properties.getProperty(ExpConstants.MENU_SAVEALL);
158 if (saveAllName != null)
159 saveAllMenuItemName = saveAllName;
160
161 String closeName = properties.getProperty(ExpConstants.MENU_CLOSE);
162 if (closeName != null)
163 closeMenuItemName = closeName;
164
165 String closeAllName = properties.getProperty(ExpConstants.MENU_CLOSEALL);
166 if (closeAllName != null)
167 closeAllMenuItemName = closeAllName;
168 }
169
170 public Vector getPreferences()
171 {
172 return preferences;
173 }
174
175 public Preference getPreference(String preferenceName)
176 {
177 return (Preference) preferenceHash.get(preferenceName);
178 }
179
180 public JPanel getPreferencesEditor()
181 {
182 return null;
183 }
184
185 public ExpActionListener getGlobalListener()
186 {
187 return null;
188 }
189
190 }
191