View Javadoc

1   /*
2    * @(#) Editor2DFrame.java 20-jul-2004 Copyright (c) 2003 Delft University of
3    * Technology Jaffalaan 5, 2628 BX Delft, the Netherlands All rights reserved.
4    * This software is proprietary information of Delft University of Technology
5    * The code is published under the General Public License
6    */
7   package nl.tudelft.simulation.dsol.gui.editor2D;
8   
9   import java.awt.BorderLayout;
10  import java.awt.Container;
11  import java.awt.Dimension;
12  import java.awt.geom.Rectangle2D;
13  
14  import javax.swing.SwingConstants;
15  
16  import nl.tudelft.simulation.dsol.gui.DSOLApplicationInterface;
17  import nl.tudelft.simulation.language.swing.JMultiToolbarFrame;
18  
19  /***
20   * Editor2DFrame.java <br>
21   * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
22   * University of Technology </a>, the Netherlands. <br>
23   * See for project information <a
24   * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
25   * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
26   * License (GPL) </a>, no warranty <br>
27   * 
28   * @version 1.0 <br>
29   * @author <a href="http://www.tbm.tudelft.nl/webstaf/royc/index.htm">Roy Chin
30   *         </a>
31   */
32  public class Editor2DFrame extends JMultiToolbarFrame
33  {
34  
35      /*** The application */
36      private DSOLApplicationInterface application = null;
37  
38      /*** Navigation toolbar */
39      private NavigationToolbar navigationToolbar = null;
40  
41      /*** Editor toolbar */
42      private EditorToolbar editorToolbar = null;
43  
44      /*** The editable animation editor2DPanel */
45      private Editor2DPanel editor2DPanel = null;
46  
47      /***
48       * Constructs a new frame
49       * 
50       * @param application
51       *            The application
52       */
53      public Editor2DFrame(final DSOLApplicationInterface application)
54      {
55          super();
56          this.application = application;
57  
58          // Initialize the frame
59          this.initialize();
60      }
61  
62      /***
63       * Initialize the frame
64       */
65      private void initialize()
66      {
67          this.setSize(640, 480);
68          this.setTitle("Animation Editor 2D");
69  
70          Container pane = this.getContentPane();
71          pane.setLayout(new BorderLayout());
72  
73          // Initialize animation editor2DPanel
74  
75          Rectangle2D extent = null;
76          String extentString = this.application.getProperties().getProperty(
77                  "dsol-gui.animation.panel.extent");
78          if (extentString != null)
79          {
80              double[] values = new double[4];
81              for (int i = 0; i < 3; i++)
82              {
83                  values[i] = new Double(extentString.substring(0, extentString
84                          .indexOf(";"))).doubleValue();
85                  extentString = extentString
86                          .substring(extentString.indexOf(";") + 1);
87              }
88              values[3] = new Double(extentString).doubleValue();
89              extent = new Rectangle2D.Double(values[0], values[1], values[2],
90                      values[3]);
91          } else
92          {
93              extent = new Rectangle2D.Double(-100, -100, 200, 200);
94          }
95          String sizeString = this.application.getProperties().getProperty(
96                  "dsol-gui.animation.panel.size");
97          Dimension size = new Dimension(600, 600);
98          if (sizeString != null)
99          {
100             double width = new Double(sizeString.substring(0, sizeString
101                     .indexOf(";"))).doubleValue();
102             double height = new Double(sizeString.substring(sizeString
103                     .indexOf(";") + 1)).doubleValue();
104             size = new Dimension((int) width, (int) height);
105         }
106 
107         this.editor2DPanel = this.createAnimationPanel();
108         // Set the editor mode to select
109         editor2DPanel.setSelectedMode(Editor2DPanel.MODE_SELECT);
110         this.editor2DPanel.getExtent().setRect(extent);
111         this.editor2DPanel.setSize(size);
112         this.editor2DPanel.setFocusable(true);
113         this.editor2DPanel.setFocusCycleRoot(true);
114         this.editor2DPanel.setFocusTraversalKeysEnabled(true);
115 
116         // Create menubar
117         MenuBar menuBar = new MenuBar(this, this.application);
118         this.setJMenuBar(menuBar);
119 
120         // Create panels;
121         //pane.add(new
122         // NavigationToolbar(editor2DPanel),BorderLayout.NORTH);
123         //pane.add(new EditorToolbar(),BorderLayout.WEST);
124         this.navigationToolbar = new NavigationToolbar(this.editor2DPanel);
125         this.addJToolBar(this.navigationToolbar, SwingConstants.TOP);
126         this.editorToolbar = new EditorToolbar(this.application,
127                 this.editor2DPanel);
128         this.addJToolBar(this.editorToolbar, SwingConstants.LEFT);
129         pane.add(this.editor2DPanel, BorderLayout.CENTER);
130 
131         // What to do to exit
132         addWindowListener(new java.awt.event.WindowAdapter()
133         {
134 
135             public void windowClosing(final java.awt.event.WindowEvent evt)
136             {
137                 Editor2DFrame.this.closeFrame();
138             }
139         });
140 
141         this.pack();
142         this.setVisible(true);
143     }
144 
145     /***
146      * Create the animation panel
147      * @return a panel
148      */
149     private Editor2DPanel createAnimationPanel()
150     {
151         Rectangle2D extent = null;
152         String extentString = this.application.getProperties().getProperty(
153                 "dsol-gui.animation.editor2DPanel.extent");
154         if (extentString != null)
155         {
156             double[] values = new double[4];
157             for (int i = 0; i < 3; i++)
158             {
159                 values[i] = new Double(extentString.substring(0, extentString
160                         .indexOf(";"))).doubleValue();
161                 extentString = extentString
162                         .substring(extentString.indexOf(";") + 1);
163             }
164             values[3] = new Double(extentString).doubleValue();
165             extent = new Rectangle2D.Double(values[0], values[1], values[2],
166                     values[3]);
167         } else
168         {
169             extent = new Rectangle2D.Double(-100, -100, 200, 200);
170         }
171         String sizeString = this.application.getProperties().getProperty(
172                 "dsol-gui.animation.editor2DPanel.size");
173         Dimension size = new Dimension(600, 600);
174         if (sizeString != null)
175         {
176             double width = new Double(sizeString.substring(0, sizeString
177                     .indexOf(";"))).doubleValue();
178             double height = new Double(sizeString.substring(sizeString
179                     .indexOf(";") + 1)).doubleValue();
180             size = new Dimension((int) width, (int) height);
181         }
182         Editor2DPanel panel = new Editor2DPanel(extent, size, this.application);
183         return panel;
184     }
185 
186     /***
187      * Close this frame
188      */
189     protected void closeFrame()
190     {
191         this.setVisible(false);
192     }
193 
194     /***
195      * @return Returns the editorToolbar.
196      */
197     public EditorToolbar getEditorToolbar()
198     {
199         return this.editorToolbar;
200     }
201 
202     /***
203      * @return Returns the navigationTooolbar.
204      */
205     public NavigationToolbar getNavigationToolbar()
206     {
207         return this.navigationToolbar;
208     }
209 
210     /***
211      * @return Returns the editor2DPanel.
212      */
213     public Editor2DPanel getEditableAnimationPanel()
214     {
215         return this.editor2DPanel;
216     }
217 }