001: package hero.client.grapheditor;
002:
003: /**
004: * WFMenuBar.java
005: *
006: *
007: * Created: Fri Aug 09 16:01:06 2002
008: *
009: * @version 1.0
010: */
011:
012: import java.awt.Color;
013: import java.awt.FileDialog;
014: import java.awt.event.ActionEvent;
015: import java.awt.event.ActionListener;
016: import java.awt.event.KeyEvent;
017: import java.awt.image.BufferedImage;
018: import java.io.File;
019: import java.io.FileOutputStream;
020: import java.io.IOException;
021:
022: import javax.imageio.ImageIO;
023: import javax.swing.AbstractAction;
024: import javax.swing.ImageIcon;
025: import javax.swing.JCheckBoxMenuItem;
026: import javax.swing.JMenu;
027: import javax.swing.JMenuItem;
028: import javax.swing.JOptionPane;
029: import javax.swing.KeyStroke;
030:
031: public class WFMenuBar extends javax.swing.JMenuBar {
032: static java.util.ResourceBundle resource = java.util.ResourceBundle
033: .getBundle("resources.Traduction")/*#BundleType=List*/;
034: Frame frame;
035:
036: public WFMenuBar(final Frame frame, final WFManager manager) {
037: this .frame = frame;
038: boolean buttonState = manager.getPersistence().hasPermission();
039: ClassLoader cl = frame.getClass().getClassLoader();
040:
041: JMenu menu;
042: JMenuItem mi;
043:
044: menu = new JMenu(resource.getString("wfmenubar.file")); // File
045: menu.setBackground(new Color(153, 153, 255));
046: add(menu);
047:
048: // New
049: mi = new JMenuItem(new ImageIcon(cl
050: .getResource("images/new.png")));
051: mi.setText(resource.getString("wfmenubar.new"));
052: mi.setBackground(new Color(153, 153, 255));
053: mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,
054: ActionEvent.ALT_MASK));
055: mi.addActionListener(new ActionListener() {
056: public void actionPerformed(ActionEvent e) {
057: manager.newProject();
058: }
059: });
060: menu.add(mi);
061:
062: // Clone
063: mi = new JMenuItem(new ImageIcon(cl
064: .getResource("images/clone.gif")));
065: mi.setText(resource.getString("wfmenubar.clone"));
066: mi.setBackground(new Color(153, 153, 255));
067: mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D,
068: ActionEvent.ALT_MASK));
069: mi.addActionListener(new ActionListener() {
070: public void actionPerformed(ActionEvent e) {
071: manager.cloneProject();
072: }
073: });
074: menu.add(mi);
075:
076: // Open
077: mi = new JMenuItem(new ImageIcon(cl
078: .getResource("images/open.png")));
079: mi.setText(resource.getString("wfmenubar.open"));
080: mi.setBackground(new Color(153, 153, 255));
081: mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,
082: ActionEvent.ALT_MASK));
083: mi.addActionListener(new ActionListener() {
084: public void actionPerformed(ActionEvent e) {
085: manager.openProject();
086: }
087: });
088: menu.add(mi);
089:
090: menu.addSeparator();
091:
092: JMenu export = new JMenu(resource.getString("wfmenubar.export"));
093: export.setBackground(new Color(153, 153, 255));
094: export.setIcon(new ImageIcon(cl
095: .getResource("images/export.gif")));
096: // ImageIO Writers
097: AbstractAction a;
098:
099: String[] s = javax.imageio.ImageIO.getWriterFormatNames();
100: for (int i = 0; i < s.length; i++) {
101: final String format = s[i];
102: if (format.toUpperCase().equals(format)) {
103: a = new AbstractAction(format) {
104: public void actionPerformed(ActionEvent e) {
105: String name = saveDialog(resource
106: .getString("wfmenubar.saveas")
107: + format.toUpperCase());
108: if (manager.getGraph().getModel()
109: .getRootCount() > 0) {
110: if (name != null) {
111: try {
112: BufferedImage im = manager
113: .getGraphImage();
114: if (im != null) {
115: File f = new File(name);
116: ImageIO.write(im, format, f);
117: JOptionPane
118: .showMessageDialog(
119: null,
120: resource
121: .getString("wfmenubar.successexport"));
122: } else
123: error("");
124: } catch (IOException ex) {
125: error(ex.toString());
126: }
127: }
128: } else
129: error("");
130: }
131: };
132: JMenuItem imageFormat = new JMenuItem(a);
133: imageFormat.setBackground(new Color(153, 153, 255));
134: export.add(imageFormat);
135: }
136: }
137:
138: menu.addSeparator();
139:
140: AbstractAction b = new AbstractAction("VRML") {
141: public void actionPerformed(ActionEvent e) {
142: String name = saveDialog(resource
143: .getString("wfmenubar.saveasvrm"));
144: if (manager.getGraph().getModel().getRootCount() > 0) {
145: if (name != null) {
146: try {
147: String data = manager.getGraphVRML();
148: if (data != null) {
149: File f = new File(name + ".wrl");
150: FileOutputStream fout = new FileOutputStream(
151: f);
152: fout.write(data.getBytes());
153: fout.close();
154: JOptionPane
155: .showMessageDialog(
156: null,
157: resource
158: .getString("wfmenubar.successexport"));
159: } else
160: error("");
161: } catch (IOException ex) {
162: error(ex.toString());
163: }
164: }
165: } else
166: error("");
167: }
168: };
169: JMenuItem vrmlFormat = new JMenuItem(b);
170: vrmlFormat.setBackground(new Color(153, 153, 255));
171: export.add(vrmlFormat);
172:
173: menu.add(export);
174:
175: menu.addSeparator();
176:
177: mi = new JMenuItem(resource.getString("wfmenubar.exit")); // - Exit
178: mi.setBackground(new Color(153, 153, 255));
179: mi.setIcon(new ImageIcon(cl.getResource("images/exit.png")));
180: mi.addActionListener(new ActionListener() {
181: public void actionPerformed(ActionEvent e) {
182: manager.exit();
183: }
184: });
185: menu.add(mi);
186:
187: menu = new JMenu(resource.getString("wfmenubar.edit")); //Edit
188: menu.setBackground(new Color(153, 153, 255));
189: add(menu);
190:
191: mi = new JMenuItem(resource.getString("wfmenubar.copy")); // - Copy
192: mi.setBackground(new Color(153, 153, 255));
193: // mi.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_C, ActionEvent.CTRL_MASK));
194: mi.setIcon(new ImageIcon(cl.getResource("images/Copy.gif")));
195: mi.setEnabled(buttonState);
196: mi.addActionListener(new ActionListener() {
197: public void actionPerformed(ActionEvent e) {
198: manager.copySelection();
199: }
200: });
201: menu.add(mi);
202: mi = new JMenuItem(resource.getString("wfmenubar.paste")); // - Paste
203: mi.setBackground(new Color(153, 153, 255));
204: // mi.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_V, ActionEvent.CTRL_MASK));
205: mi.setIcon(new ImageIcon(cl.getResource("images/Paste.gif")));
206: mi.setEnabled(buttonState);
207: mi.addActionListener(new ActionListener() {
208: public void actionPerformed(ActionEvent e) {
209: manager.pasteSelection();
210: }
211: });
212: menu.add(mi);
213:
214: mi = new JMenuItem(resource.getString("wfmenubar.delete")); // - Delete
215: mi.setBackground(new Color(153, 153, 255));
216: mi
217: .setAccelerator(KeyStroke.getKeyStroke(
218: KeyEvent.VK_DELETE, 0));
219: mi.setIcon(new ImageIcon(cl.getResource("images/Delete.gif")));
220: mi.setEnabled(buttonState);
221: mi.addActionListener(new ActionListener() {
222: public void actionPerformed(ActionEvent e) {
223: manager.deleteSelection();
224: }
225: });
226: menu.add(mi);
227:
228: menu.addSeparator();
229:
230: mi = new JMenuItem(resource.getString("wfmenubar.selectall"),
231: 'A'); // - Select all
232: mi.setBackground(new Color(153, 153, 255));
233: mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A,
234: ActionEvent.CTRL_MASK));
235: mi.addActionListener(new ActionListener() {
236: public void actionPerformed(ActionEvent e) {
237: manager.selectAll();
238: }
239: });
240: menu.add(mi);
241:
242: mi = new JMenuItem(resource.getString("wfmenubar.deselectall"),
243: 'D'); // - Deselect all
244: mi.setBackground(new Color(153, 153, 255));
245:
246: mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D,
247: ActionEvent.CTRL_MASK));
248: mi.addActionListener(new ActionListener() {
249: public void actionPerformed(ActionEvent e) {
250: manager.clearSelection();
251: }
252: });
253: menu.add(mi);
254:
255: menu = new JMenu(resource.getString("wfmenubar.format")); //Format
256: menu.setBackground(new Color(153, 153, 255));
257: add(menu);
258:
259: final JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(
260: resource.getString("wfmenubar.autolay"));
261: menu.add(menuItem);
262: menu.setBackground(new Color(153, 153, 255));
263: menuItem.setState(true);
264: menuItem.setBackground(new Color(153, 153, 255));
265: menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L,
266: ActionEvent.CTRL_MASK));
267: menuItem.addActionListener(new ActionListener() {
268: public void actionPerformed(ActionEvent e) {
269: manager.automaticLayout();
270: }
271: });
272: menu.add(menuItem);
273:
274: mi = new JMenuItem(resource.getString("wfmenubar.circlelay"));
275: mi.setBackground(new Color(153, 153, 255));
276: mi.setIcon(new ImageIcon(cl.getResource("images/Arrange.gif")));
277: mi.addActionListener(new ActionListener() {
278: public void actionPerformed(ActionEvent e) {
279: manager.setLayout1();
280: }
281: });
282:
283: menu.add(mi);
284:
285: mi = new JMenuItem(resource.getString("wfmenubar.expandlay"));
286: mi.setBackground(new Color(153, 153, 255));
287: mi.setIcon(new ImageIcon(cl.getResource("images/Layout.gif")));
288: mi.addActionListener(new ActionListener() {
289: public void actionPerformed(ActionEvent e) {
290: manager.setLayout2();
291: }
292: });
293:
294: menu.add(mi);
295:
296: menu = new JMenu(resource.getString("wfmenubar.user")); //Users
297: menu.setEnabled(buttonState);
298: menu.setBackground(new Color(153, 153, 255));
299: add(menu);
300: mi = (JMenuItem) menu.add(new JMenuItem(resource
301: .getString("wfmenubar.newuser")));
302: mi.setBackground(new Color(153, 153, 255));
303: mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_U,
304: ActionEvent.CTRL_MASK));
305: mi.setIcon(new ImageIcon(cl.getResource("images/User.gif")));
306: mi.setEnabled(buttonState);
307: mi.addActionListener(new ActionListener() {
308: public void actionPerformed(ActionEvent e) {
309: manager.newUser();
310: }
311: });
312: menu.add(mi);
313:
314: mi = (JMenuItem) menu.add(new JMenuItem(resource
315: .getString("wfmenubar.projuser")));
316: mi.setBackground(new Color(153, 153, 255));
317: mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T,
318: ActionEvent.CTRL_MASK));
319: mi.setIcon(new ImageIcon(cl.getResource("images/User2.gif")));
320: mi.setEnabled(buttonState);
321: mi.addActionListener(new ActionListener() {
322: public void actionPerformed(ActionEvent e) {
323: manager.usersInProject();
324: }
325: });
326: menu.add(mi);
327:
328: menu.addSeparator();
329:
330: mi = (JMenuItem) menu.add(new JMenuItem(resource
331: .getString("wfmenubar.addrole")));
332: mi.setBackground(new Color(153, 153, 255));
333: mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R,
334: ActionEvent.CTRL_MASK));
335: mi.setIcon(new ImageIcon(cl.getResource("images/Role2.gif")));
336: mi.setEnabled(buttonState);
337: mi.addActionListener(new ActionListener() {
338: public void actionPerformed(ActionEvent e) {
339: manager.newRole();
340: }
341: });
342: menu.add(mi);
343: mi = (JMenuItem) menu.add(new JMenuItem(resource
344: .getString("wfmenubar.addrole2")));
345: mi.setBackground(new Color(153, 153, 255));
346: mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_J,
347: ActionEvent.CTRL_MASK));
348: mi.setIcon(new ImageIcon(cl.getResource("images/Role.gif")));
349: mi.setEnabled(buttonState);
350: mi.addActionListener(new ActionListener() {
351: public void actionPerformed(ActionEvent e) {
352: manager.addUserToRole();
353: }
354: });
355: menu.add(mi);
356:
357: mi = (JMenuItem) menu.add(new JMenuItem(resource
358: .getString("wfmenubar.addmapper")));
359: mi.setBackground(new Color(153, 153, 255));
360: mi.setIcon(new ImageIcon(cl
361: .getResource("images/rolemapper.gif")));
362: mi.setEnabled(buttonState);
363: mi.addActionListener(new ActionListener() {
364: public void actionPerformed(ActionEvent e) {
365: manager.addMapperToRole();
366: }
367: });
368: menu.add(mi);
369:
370: menu = new JMenu(resource.getString("wfmenubar.zoom")); //Zoom
371: menu.setBackground(new Color(153, 153, 255));
372: add(menu);
373:
374: mi = new JMenuItem(resource.getString("wfmenubar.fit"));
375: mi.setBackground(new Color(153, 153, 255));
376: mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F,
377: ActionEvent.CTRL_MASK));
378: mi.addActionListener(new ActionListener() {
379: public void actionPerformed(ActionEvent e) {
380: manager.fitWindow();
381: }
382: });
383: menu.add(mi);
384:
385: mi = new JMenuItem(resource.getString("wfmenubar.zoom100"));
386: mi.setBackground(new Color(153, 153, 255));
387: mi.setIcon(new ImageIcon(cl.getResource("images/Zoom100.gif")));
388: mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M,
389: ActionEvent.CTRL_MASK));
390: mi.addActionListener(new ActionListener() {
391: public void actionPerformed(ActionEvent e) {
392: manager.zoom(100);
393: }
394: });
395: menu.add(mi);
396:
397: mi = new JMenuItem(resource.getString("wfmenubar.zoomin"));
398: mi.setBackground(new Color(153, 153, 255));
399: mi.setIcon(new ImageIcon(cl.getResource("images/ZoomIn.gif")));
400: mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I,
401: ActionEvent.CTRL_MASK));
402: mi.addActionListener(new ActionListener() {
403: public void actionPerformed(ActionEvent e) {
404: manager.zoomIn();
405: }
406: });
407: menu.add(mi);
408:
409: mi = new JMenuItem(resource.getString("wfmenubar.zoomout"));
410: mi.setBackground(new Color(153, 153, 255));
411: mi.setIcon(new ImageIcon(cl.getResource("images/ZoomOut.gif")));
412: mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,
413: ActionEvent.CTRL_MASK));
414: mi.addActionListener(new ActionListener() {
415: public void actionPerformed(ActionEvent e) {
416: manager.zoomOut();
417: }
418: });
419: menu.add(mi);
420: /*
421: menu = new JMenu("Help"); //HELP
422: add(menu);
423: */
424:
425: menu = new JMenu(resource.getString("wfmenubar.info")); //Info
426: menu.setBackground(new Color(153, 153, 255));
427: add(menu);
428:
429: mi = new JMenuItem(resource.getString("wfmenubar.about")); // - Copy
430: mi.setBackground(new Color(153, 153, 255));
431: // mi.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_C, ActionEvent.CTRL_MASK));
432: mi.setIcon(new ImageIcon(cl
433: .getResource("images/toolbar-info.png")));
434: mi.addActionListener(new ActionListener() {
435: public void actionPerformed(ActionEvent e) {
436: manager.Info();
437: }
438: });
439: menu.add(mi);
440:
441: }
442:
443: /* Show a dialog with the given error message. */
444: public void error(String message) {
445: JOptionPane
446: .showMessageDialog(this , message, resource
447: .getString("wfmenubar.info"),
448: JOptionPane.ERROR_MESSAGE);
449: }
450:
451: /* Show a file save dialog and return the filename. */
452: public String saveDialog(String message) {
453: return dialog(message, FileDialog.SAVE);
454: }
455:
456: /* Show a file load dialog and return the filename. */
457: public String loadDialog(String message) {
458: return dialog(message, FileDialog.LOAD);
459: }
460:
461: /* Open a dialog and return the filename. Returns null if cancelled. */
462: protected String dialog(String message, int mode) {
463: FileDialog f = new FileDialog(frame, message, mode);
464: f.show();
465: if (f.getFile() != null)
466: return f.getDirectory() + f.getFile();
467: else
468: return null;
469: }
470:
471: }
|