1
2
3
4
5
6
7
8
9
10 package nl.tudelft.simulation.dsol.gui.windows;
11
12 import java.awt.BorderLayout;
13 import java.awt.Color;
14 import java.awt.Component;
15 import java.awt.Dimension;
16 import java.awt.Toolkit;
17 import java.io.IOException;
18 import java.net.URL;
19
20 import javax.swing.BorderFactory;
21 import javax.swing.JEditorPane;
22 import javax.swing.JFrame;
23 import javax.swing.JMenuBar;
24 import javax.swing.JPanel;
25 import javax.swing.JScrollPane;
26 import javax.swing.JTree;
27 import javax.swing.SwingConstants;
28 import javax.swing.UIManager;
29 import javax.swing.WindowConstants;
30
31 import nl.tudelft.simulation.dsol.experiment.Experiment;
32 import nl.tudelft.simulation.dsol.gui.DSOLApplicationInterface;
33 import nl.tudelft.simulation.dsol.gui.UIInitializer;
34 import nl.tudelft.simulation.dsol.gui.menu.FileMenu;
35 import nl.tudelft.simulation.dsol.gui.menu.HelpMenu;
36 import nl.tudelft.simulation.dsol.gui.menu.ToolsMenu;
37 import nl.tudelft.simulation.dsol.gui.menu.WindowMenu;
38 import nl.tudelft.simulation.dsol.gui.panels.ControlPanel;
39 import nl.tudelft.simulation.dsol.gui.panels.ExperimentTree;
40 import nl.tudelft.simulation.dsol.gui.panels.Statusbar;
41 import nl.tudelft.simulation.dsol.gui.panels.TabbedPane;
42 import nl.tudelft.simulation.event.EventInterface;
43 import nl.tudelft.simulation.event.EventListenerInterface;
44 import nl.tudelft.simulation.language.io.URLResource;
45 import nl.tudelft.simulation.logger.Logger;
46
47 /***
48 * DSOL Frame <br>
49 * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
50 * University of Technology </a>, the Netherlands. <br>
51 * See for project information <a
52 * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
53 * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
54 * License (GPL) </a>, no warranty <br>
55 *
56 * @version 1.0 18.10.2003 <br>
57 * @author <a href="http://www.simulation.tudelft.nl/people/jacobs.html">Peter
58 * Jacobs </a>
59 */
60 public class DSOLFrame extends JFrame implements EventListenerInterface
61 {
62 /*** the preferredSize is the preferredSize of the panel */
63 public static final Dimension PREFERRED_SIZE = new Dimension(400, 375);
64
65 /*** the application */
66 protected DSOLApplicationInterface application = null;
67
68 /*** tabbedPanel */
69 protected TabbedPane tabbedPanel = null;
70
71 /*** the experimentTree */
72 protected JTree experimentTree = null;
73
74 /*** the statusbar */
75 protected Statusbar statusbar = null;
76
77 /*** the controlPanel */
78 protected ControlPanel controlPanel = null;
79
80 /***
81 * constructs a new DSOLFrame
82 *
83 * @param application the application
84 */
85 public DSOLFrame(final DSOLApplicationInterface application)
86 {
87 super("DSOL main window");
88
89 try
90 {
91 UIManager
92 .setLookAndFeel("com.jgoodies.plaf.plastic.Plastic3DLookAndFeel");
93
94
95 UIInitializer.initialize();
96 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
97 this.setLocation((int) Math.round(screenSize.width * 0.5 - 0.5
98 * PREFERRED_SIZE.width), (int) Math.round(screenSize.height
99 * 0.33 - 0.5 * PREFERRED_SIZE.height));
100 this.application = application;
101 this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
102 this.application.addListener(this,
103 DSOLApplicationInterface.EXPERIMENT_CHANGED_EVENT);
104 } catch (Exception exception)
105 {
106 Logger.warning(this, "DSOLFrame", exception);
107 }
108 this.initialize();
109 this.pack();
110 this.setVisible(true);
111 }
112
113 /***
114 * initializes the DSOL Frame
115 */
116 private void initialize()
117 {
118 JPanel contentPane = new JPanel();
119 contentPane.setPreferredSize(PREFERRED_SIZE);
120 contentPane.setLayout(new BorderLayout());
121 this.setContentPane(contentPane);
122
123 JMenuBar menuBar = new JMenuBar();
124 menuBar.setBorder(BorderFactory.createLineBorder(Color.GRAY));
125
126 menuBar.add(new FileMenu(this.application));
127 menuBar.add(new ToolsMenu(this.application));
128 menuBar.add(new WindowMenu(this.application));
129 menuBar.add(new HelpMenu(this.application));
130 this.setJMenuBar(menuBar);
131
132 this.controlPanel = new ControlPanel(this.application);
133
134 this.tabbedPanel = new TabbedPane(SwingConstants.TOP);
135 this.tabbedPanel.setBorder(BorderFactory.createCompoundBorder(
136 BorderFactory.createEtchedBorder(), BorderFactory
137 .createEmptyBorder()));
138 contentPane.add(this.tabbedPanel, BorderLayout.CENTER);
139 this.statusbar = new Statusbar(this.application);
140
141 this.experimentTree = new JTree();
142 this.experimentTree.setEditable(false);
143 this.experimentTree.setFocusable(false);
144
145 URL about = URLResource
146 .getResource("/nl/tudelft/simulation/dsol/gui/about.html");
147 JEditorPane aboutPane = null;
148 try
149 {
150 aboutPane = new JEditorPane(about);
151 } catch (IOException exception)
152 {
153 Logger.warning(this, "initialize", exception);
154 }
155 aboutPane.setAlignmentY(Component.BOTTOM_ALIGNMENT);
156 aboutPane.setEditable(false);
157 this.tabbedPanel.add("About", aboutPane);
158 }
159
160 /***
161 * @see nl.tudelft.simulation.event.EventListenerInterface
162 * #notify(nl.tudelft.simulation.event.EventInterface)
163 */
164 public void notify(final EventInterface event)
165 {
166 if (event.getSource().equals(this.application)
167 && event.getType().equals(
168 DSOLApplicationInterface.EXPERIMENT_CHANGED_EVENT))
169 {
170 this.tabbedPanel.remove("Description");
171 this.tabbedPanel.remove("Experiment");
172 this.tabbedPanel.remove("Control");
173 if (event.getContent() != null)
174 {
175 Experiment experiment = (Experiment) event.getContent();
176 try
177 {
178 String descriptionName = "/";
179 if (experiment.getModel().getClass().getPackage() != null)
180 {
181 descriptionName = descriptionName
182 + experiment.getModel().getClass().getPackage()
183 .getName().replace('.', '/');
184 }
185 descriptionName = descriptionName + "/package.html";
186 URL description = experiment.getModel().getClass()
187 .getResource(descriptionName);
188 JEditorPane descriptionPane = null;
189 descriptionPane = new JEditorPane(description);
190 descriptionPane.setAlignmentY(Component.BOTTOM_ALIGNMENT);
191 descriptionPane.setEditable(false);
192 this.tabbedPanel.add("Description", 0, new JScrollPane(
193 descriptionPane));
194 } catch (IOException exception)
195 {
196 Logger
197 .fine(this, "initialize",
198 "experiment has no package.html describing the experiment");
199 }
200 this.setTitle("DSOL main window ("
201 + experiment.getProperty(Experiment.EXPERIMENT_NAME)
202 + ")");
203 this.experimentTree.setModel(new ExperimentTree(experiment));
204 this.tabbedPanel.add("Experiment", 1, new JScrollPane(
205 this.experimentTree));
206 this.tabbedPanel.add("Control", 2, this.controlPanel);
207 this.getContentPane().add(this.statusbar, BorderLayout.SOUTH);
208 } else
209 {
210 this.setTitle("DSOL main window");
211 this.getContentPane().remove(this.statusbar);
212 }
213 this.validate();
214 this.repaint();
215 }
216 }
217 }