1
2
3
4
5
6
7
8
9
10 package nl.tudelft.simulation.dsol.gui.editor2D.actions;
11
12 import java.awt.event.ActionEvent;
13 import java.awt.event.ActionListener;
14 import java.util.ArrayList;
15 import java.util.Iterator;
16 import java.util.List;
17
18 import javax.swing.JCheckBoxMenuItem;
19 import javax.swing.SwingConstants;
20
21 import nl.tudelft.simulation.dsol.animation.Editable;
22 import nl.tudelft.simulation.dsol.animation.D2.EditableRenderable2DInterface;
23 import nl.tudelft.simulation.dsol.animation.D2.Renderable2DInterface;
24 import nl.tudelft.simulation.dsol.gui.DSOLApplicationInterface;
25 import nl.tudelft.simulation.dsol.gui.editor2D.EditableSaverInterface;
26 import nl.tudelft.simulation.dsol.gui.editor2D.Editor2DPanel;
27 import nl.tudelft.simulation.dsol.gui.editor2D.MenuBar;
28 import nl.tudelft.simulation.logger.Logger;
29
30 /***
31 * MenuBarActions.java <br>
32 * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
33 * University of Technology </a>, the Netherlands. <br>
34 * See for project information <a
35 * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
36 * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
37 * License (GPL) </a>, no warranty <br>
38 *
39 * @version 1.0 <br>
40 * @author <a href="http://www.tbm.tudelft.nl/webstaf/royc/index.htm">Roy Chin
41 * </a>
42 */
43 public class MenuBarActions implements ActionListener
44 {
45
46 /*** Menubar */
47 private MenuBar source = null;
48
49 /*** The application */
50 private DSOLApplicationInterface application = null;
51
52 /***
53 * Constructor
54 *
55 * @param source Parent
56 * @param application The application
57 */
58 public MenuBarActions(final MenuBar source,
59 final DSOLApplicationInterface application)
60 {
61 super();
62 this.source = source;
63 this.application = application;
64 }
65
66 /***
67 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
68 */
69 public void actionPerformed(final ActionEvent event)
70 {
71 Object src = event.getSource();
72 if (src.equals(this.source.getExitItem()))
73 {
74 this.source.getParentFrame().setVisible(false);
75 } else if (src.equals(this.source.getSaveEditablesItem()))
76 {
77 try
78 {
79
80
81 List editables = new ArrayList();
82 Editor2DPanel panel = this.source.getSource()
83 .getEditableAnimationPanel();
84 for (Iterator i = panel.getElements().iterator(); i.hasNext();)
85 {
86 Renderable2DInterface renderable = (Renderable2DInterface) i
87 .next();
88 if (renderable instanceof EditableRenderable2DInterface)
89 {
90 Editable editable = (Editable) renderable.getSource();
91 editables.add(editable);
92 }
93 }
94
95 String editableSaver = application.getProperties().getProperty(
96 "dsol-gui.editor2D.panel.editableSaver");
97
98 if (editableSaver != null)
99 {
100 try
101 {
102 Class editableSaverClass = Class.forName(editableSaver);
103 EditableSaverInterface saver = (EditableSaverInterface) editableSaverClass
104 .newInstance();
105 saver.saveEditables(editables);
106 } catch (Exception exception)
107 {
108 Logger.warning(this, "actionPerformed", exception);
109 }
110 }
111 } catch (ClassCastException exception)
112 {
113 Logger.warning(this, "actionPerformed", exception);
114 }
115 } else if (src.equals(this.source.getNavigationItem()))
116 {
117
118
119 JCheckBoxMenuItem item = (JCheckBoxMenuItem) src;
120 if (item.getState())
121 {
122 this.source.getParentFrame().addJToolBar(
123 this.source.getParentFrame().getNavigationToolbar(),
124 SwingConstants.TOP);
125 } else
126 {
127 this.source.getParentFrame().removeJToolBar(
128 this.source.getParentFrame().getNavigationToolbar());
129 this.source.getParentFrame().repaint();
130 this.source.getParentFrame().getContentPane().repaint();
131 }
132 }
133
134 }
135
136 }