1
2
3
4
5
6
7 package nl.tudelft.simulation.dsol.gui.editor2D.actions;
8
9 import java.awt.event.ActionEvent;
10 import java.awt.event.ActionListener;
11 import java.util.Iterator;
12 import java.util.Map;
13 import java.util.Set;
14
15 import javax.swing.JMenuItem;
16
17 import nl.tudelft.simulation.dsol.animation.Editable;
18 import nl.tudelft.simulation.dsol.gui.editor2D.Editor2DPanel;
19 import nl.tudelft.simulation.dsol.gui.editor2D.EditorToolbar;
20 import nl.tudelft.simulation.logger.Logger;
21
22 /***
23 * EditorToolbarActions.java <br>
24 * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
25 * University of Technology </a>, the Netherlands. <br>
26 * See for project information <a
27 * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
28 * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
29 * License (GPL) </a>, no warranty <br>
30 *
31 * @version 1.0 <br>
32 * @author <a href="http://www.tbm.tudelft.nl/webstaf/royc/index.htm">Roy Chin
33 * </a>
34 */
35 public class EditorToolbarActions implements ActionListener
36 {
37 /*** Parent */
38 private EditorToolbar source = null;
39
40 /*** The panel */
41 private Editor2DPanel panel = null;
42
43 /***
44 * Constructor
45 *
46 * @param source The EditorToolbar
47 * @param panel The panel
48 */
49 public EditorToolbarActions(final EditorToolbar source,
50 final Editor2DPanel panel)
51 {
52 super();
53 this.source = source;
54 this.panel = panel;
55 }
56
57 /***
58 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
59 */
60 public void actionPerformed(final ActionEvent event)
61 {
62 Object src = event.getSource();
63
64
65 this.source.getSelectObject().setSelected(false);
66 this.source.getNewObject().setSelected(false);
67 this.source.getEditObject().setSelected(false);
68 this.source.getDeleteObject().setSelected(false);
69 panel.setSelectedMode(Editor2DPanel.MODE_IDLE);
70
71
72 if (src.equals(this.source.getSelectObject()))
73 {
74 this.source.getSelectObject().setSelected(true);
75 panel.setSelectedMode(Editor2DPanel.MODE_SELECT);
76 } else if (src.equals(this.source.getNewObject()))
77 {
78 this.source.getNewObject().setSelected(true);
79 panel.setSelectedMode(Editor2DPanel.MODE_NEW);
80
81 this.source.getItems().show(this.source.getNewObject(), 0, 0);
82
83 } else if (src.equals(this.source.getEditObject()))
84 {
85 this.source.getEditObject().setSelected(true);
86 panel.setSelectedMode(Editor2DPanel.MODE_EDIT);
87 } else if (src.equals(this.source.getDeleteObject()))
88 {
89 EditorUtilities.deleteEditable(panel
90 .getSelectedEditableRenderable(), this.panel);
91
92 panel.setSelectedMode(Editor2DPanel.MODE_SELECT);
93 this.source.getSelectObject().setSelected(true);
94 this.source.getSelectObject().requestFocus();
95 } else if (src instanceof JMenuItem)
96 {
97
98 String text = ((JMenuItem) src).getText();
99 Class editableClass = null;
100 try
101 {
102 Map editables = Editable.listEditables();
103 Set keys = editables.keySet();
104
105 Iterator i = keys.iterator();
106 boolean found = false;
107 while ((i.hasNext()) && (!found))
108 {
109 String key = (String) i.next();
110 if (key.equals(text))
111 {
112 String className = (String) editables.get(key);
113 editableClass = Class.forName(className);
114 found = true;
115 }
116 }
117 } catch (Exception exception)
118 {
119 Logger.warning(this, "actionPerformed", exception);
120 }
121
122
123 if (editableClass != null)
124 {
125 panel.setSelectedRenderableClass(editableClass);
126 }
127
128
129 this.source.getNewObject().setSelected(true);
130 panel.setSelectedMode(Editor2DPanel.MODE_NEW);
131 }
132
133 }
134
135 }