View Javadoc

1   package org.devaki.nextobjects.ui.components;
2   /*
3   
4   nextobjects Copyright (C) 2001-2005 Emmanuel Florent
5   
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by the
8   Free Software Foundation; either version 2 of the License, or (at your
9   option) any later version.
10  
11  This program is distributed in the hope that it will
12  be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13  of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the GNU General Public License for more details.
15  
16  You should have received a copy of the GNU General Public License along
17  with this program; if not, write to the Free Software Foundation, Inc., 59
18  Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  
20  */
21  import javax.swing.JInternalFrame;
22  import javax.swing.event.InternalFrameAdapter;
23  import javax.swing.event.InternalFrameEvent;
24  import org.devaki.nextobjects.constants.CstImages;
25  import org.devaki.nextobjects.ui.toolbars.NOToolBar2;
26  import org.devaki.nextobjects.util.ModelMan;
27  import org.devaki.nextobjects.util.NOFileManager;
28  import org.devaki.nextobjects.workspace.models.BaseModel;
29  import org.devaki.nextobjects.workspace.models.ConceptualModel;
30  /***
31   * This class overwrite the InternalFrame Swing component
32    * @author     <a href="mailto:eflorent@devaki.org">Emmanuel Florent</a>
33   */
34  public class CustomInternalFrame extends JInternalFrame
35  {
36      /***
37       *  default  xOffset
38       */
39      private static final int X_OFFSET = 28;
40      /***
41       *  default  yOffset
42       */
43      private static final int Y_OFFSET = 28;
44      /***
45       *  default  width
46       */
47      private static final int WIDTH = 700;
48      /***
49       *  default  height
50       */
51      private static final int HEIGHT = 500;
52      /***
53       *  Local reference the 'NOModel' object hosted in the frame
54       */
55      private BaseModel model;
56      /***
57       * Number of frames that have been created
58       */
59      private static int openFrameCount = 0;
60      /***
61       * Construct a 'CustomInternalFrame' object
62       * @param pModel The 'NOModel' object to be hosted
63       */
64      public CustomInternalFrame(final BaseModel pModel)
65      {
66          //Initialization
67          super(pModel.toString(), true, true, true, true);
68          // Initiliaze the local reference of the 'NOModel' object
69          this.model = pModel;
70          // Set the icon in the top-left corner
71          if (pModel instanceof ConceptualModel)
72          {
73              this.setFrameIcon(CstImages.ICN_CDM);
74          }
75          else
76          {
77              this.setFrameIcon(CstImages.ICN_PDM);
78          }
79          // Define what to do when closing the window
80          this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
81          // Set location in the desktop pane
82          this.setLocation(X_OFFSET * openFrameCount, Y_OFFSET * openFrameCount);
83          // Define the size
84          this.setSize(WIDTH, HEIGHT);
85          // Increment the number of frame that have been created
86          openFrameCount++;
87          // Listeners
88          // Internal Frame Listeners
89          this.addInternalFrameListener(new InternalFrameAdapter()
90          {
91              public final void internalFrameClosing(final InternalFrameEvent evt)
92              {
93                  NOFileManager.close(model);
94                  ModelMan.setCurrentObject(null);
95                  NOToolBar2.fixIcons();
96              }
97              public final void internalFrameActivated(final InternalFrameEvent e)
98              {
99                  ModelMan.setCurrentObject(null);
100                 ModelMan.setCurrentModel(model);
101                 NOToolBar2.fixIcons();
102             }
103         });
104     }
105     /***
106      * Get the 'NOModel' object hosted by the instancied frame
107      * @return A 'NOModel' object
108      */
109     public final BaseModel getModel()
110     {
111         return this.model;
112     }
113     /***
114      * Refresh the title of the frame
115      */
116     public final void refreshTitle()
117     {
118         String kind = new String();
119         if (this.model instanceof ConceptualModel)
120         {
121             kind = "cdm:";
122         }
123         else
124         {
125             kind = "pdm:";
126         }
127         this.setTitle(
128             new StringBuffer()
129                 .append(kind)
130                 .append(this.model.getName())
131                 .toString());
132     }
133     /***
134      * Get the number of frames
135      * @return the count
136      */
137     public static int getOpenFrameCount()
138     {
139         return openFrameCount;
140     }
141 }