1 package org.devaki.nextobjects.ui.components;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
67 super(pModel.toString(), true, true, true, true);
68
69 this.model = pModel;
70
71 if (pModel instanceof ConceptualModel)
72 {
73 this.setFrameIcon(CstImages.ICN_CDM);
74 }
75 else
76 {
77 this.setFrameIcon(CstImages.ICN_PDM);
78 }
79
80 this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
81
82 this.setLocation(X_OFFSET * openFrameCount, Y_OFFSET * openFrameCount);
83
84 this.setSize(WIDTH, HEIGHT);
85
86 openFrameCount++;
87
88
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 }