1 package org.devaki.nextobjects;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 import java.awt.FlowLayout;
18 import java.awt.GridBagConstraints;
19 import java.awt.GridBagLayout;
20 import java.awt.Insets;
21 import java.io.File;
22 import java.awt.Toolkit;
23 import java.awt.event.WindowAdapter;
24 import java.awt.event.WindowEvent;
25 import org.devaki.nextobjects.util.NOFileUtil;
26 import javax.swing.JFrame;
27 import javax.swing.JLabel;
28 import javax.swing.JPanel;
29 import javax.swing.JSplitPane;
30 import javax.swing.ImageIcon;
31 import javax.swing.WindowConstants;
32 import org.apache.commons.logging.Log;
33 import org.apache.commons.logging.LogFactory;
34 import org.devaki.nextobjects.ui.components.CustomSplitPane;
35 import org.devaki.nextobjects.ui.main.InitHome;
36 import org.devaki.nextobjects.ui.main.NOLog;
37 import org.devaki.nextobjects.ui.main.NOTreeView;
38 import org.devaki.nextobjects.ui.main.NOWorkspace;
39 import org.devaki.nextobjects.ui.main.SplashScreen;
40 import org.devaki.nextobjects.ui.menus.NOMenuBar;
41 import org.devaki.nextobjects.ui.toolbars.NOToolBar1;
42 import org.devaki.nextobjects.ui.toolbars.NOToolBar2;
43 import org.devaki.nextobjects.util.NOFileManager;
44 import org.devaki.nextobjects.util.NOPreferences;
45 import org
46 .devaki
47 .nextobjects
48 .ui
49 .workspace
50 .models
51 .objects
52 .DataDictionaryEdit;
53 /***
54 * Nextobjects is an Integrated Development Tool for Entreprise Applications.
55 * Nextobjects will help you choose database structure from system analysis and
56 * design, down to generating strongly designed data layer Object Model.
57 *
58 * @author <a href="mailto:eflorent@devaki.org">Emmanuel Florent</a>
59 */
60 public class NextObjects extends JFrame
61 {
62 /*** Reference to the instantiated 'NextObjects' object */
63 private static NextObjects nextObjects;
64 /*** Logger */
65 private static Log logger =
66 LogFactory.getLog(NextObjects.class.getName());
67 /*** Component */
68 private static JLabel jLabelStatus = new JLabel(" ");
69 /*** Components */
70 private NOMenuBar menuBar;
71 /*** Components */
72 private NOToolBar1 toolBar1;
73 /*** Components */
74 private NOToolBar2 toolBar2;
75 /*** Components */
76 private CustomSplitPane jSplitPane1 =
77 new CustomSplitPane(JSplitPane.HORIZONTAL_SPLIT, 220);
78 /*** Components */
79 private CustomSplitPane jSplitPane2 =
80 new CustomSplitPane(JSplitPane.VERTICAL_SPLIT, 0);
81 /*** Components */
82 private JPanel jPanelStatusBar = new JPanel(new GridBagLayout());
83 /*** Thetabbedpane */
84 private NOWorkspace nOWorkspace;
85 /*** The treeview */
86 private static DataDictionaryEdit dataDictionaryEdit;
87 /*** Component spl */
88 private static SplashScreen splash;
89 /*** logger as textarea pre-initialized */
90
91 /*** Construct a new 'NextObjects' object */
92 public NextObjects()
93 {
94 super("devaki-nextobjects");
95 System.out.println(
96 "This product includes software developed by "
97 + "the Apache Software Foundation");
98 System.out.println("http://www.apache.org/");
99
100 nextObjects = this;
101 splash.jProgressBar1.setValue(10);
102 splash.jProgressBar1.setString("Checking User Installation");
103
104
105 if (!(new File(NOPreferences.APP_HOME)).exists())
106 {
107 System.out.println(
108 "Initializing APP home " + NOPreferences.APP_HOME);
109 NOFileUtil.createDirectory(NOPreferences.APP_HOME);
110 System.out.println("Initializing default.properties");
111 InitHome.copyDefaultProperties();
112 System.out.println("Initializing defaultbuild.properties");
113 InitHome.copyDefaultBuildProperties();
114 }
115 splash.jProgressBar1.setValue(20);
116 splash.jProgressBar1.setString("Loading Preferences");
117 new NOPreferences();
118 splash.jProgressBar1.setValue(25);
119 InitHome initHome = new InitHome();
120 initHome.checkForTorque();
121
122 initHome = null;
123 splash.jProgressBar1.setValue(30);
124
125 splash.jProgressBar1.setString("Loading Logger");
126 NOLog.init();
127 splash.jProgressBar1.setValue(40);
128
129 splash.jProgressBar1.setString("Loading Data Dictionary");
130 dataDictionaryEdit = new DataDictionaryEdit();
131 splash.jProgressBar1.setValue(50);
132
133
134 splash.jProgressBar1.setString("Loading File Manager");
135 NOFileManager.initChooser();
136
137 splash.jProgressBar1.setString("Building Tool Bars");
138 toolBar1 = new NOToolBar1();
139 splash.jProgressBar1.setValue(60);
140 toolBar2 = new NOToolBar2();
141 splash.jProgressBar1.setValue(70);
142
143 splash.jProgressBar1.setString("Building Menu Bars");
144 menuBar = new NOMenuBar();
145 this.setJMenuBar(this.menuBar);
146 splash.jProgressBar1.setValue(75);
147
148 splash.jProgressBar1.setString("Building Tree View");
149 this.jSplitPane1.setLeftComponent(new NOTreeView());
150 splash.jProgressBar1.setValue(85);
151 splash.jProgressBar1.setString("Building Workspace");
152 nOWorkspace = new NOWorkspace();
153 this.jSplitPane1.setRightComponent(nOWorkspace);
154 splash.jProgressBar1.setValue(90);
155 splash.jProgressBar1.setString("Assembling Main Window");
156 buildMainWindow();
157 NOToolBar1.fixIcons();
158
159 int w = 640;
160 int h = 480;
161 try
162 {
163 w =
164 Integer.parseInt(
165 NOPreferences.getProperty(
166 "nextobjects.screen.width"));
167 h =
168 Integer.parseInt(
169 NOPreferences.getProperty(
170 "nextobjects.screen.height"));
171 }
172 catch (Exception e)
173 {
174 System.err.println(e);
175 }
176 if (w < 10 || h < 10)
177 {
178 h = 480;
179 w = 480;
180 }
181 this.setSize(w, h);
182 this.setVisible(true);
183
184 splash.jProgressBar1.setString("Done");
185 splash.jProgressBar1.setValue(100);
186 }
187 /***
188 * Assemble window
189 *
190 */
191 private void buildMainWindow()
192 {
193
194 jSplitPane2.setDividerLocation(
195 (int) this.getSize().getHeight() - 220);
196
197 this.addWindowListener(new WindowAdapter()
198 {
199
200 public final void windowClosing(final WindowEvent evt)
201 {
202 NOFileManager.goodbye();
203 }
204 });
205
206 this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
207
208 this.setIconImage(
209 Toolkit.getDefaultToolkit().getImage(
210 org.devaki.nextobjects.NextObjects.class.getResource(
211 "/org/devaki/nextobjects/icons/icon.png")));
212
213 this.getContentPane().setLayout(new GridBagLayout());
214
215 this.jSplitPane2.setTopComponent(this.jSplitPane1);
216 JPanel bottomPanel = new JPanel();
217 bottomPanel.setLayout(new GridBagLayout());
218 bottomPanel.add(
219 NOLog.getJTabbedPane(),
220 new GridBagConstraints(
221 0,
222 0,
223 1,
224 1,
225 1.0,
226 1.0,
227 GridBagConstraints.CENTER,
228 GridBagConstraints.BOTH,
229 new Insets(3, 3, 3, 3),
230 0,
231 0));
232 this.jSplitPane2.setBottomComponent(bottomPanel);
233
234 this.jPanelStatusBar.add(
235 jLabelStatus,
236 new GridBagConstraints(
237 0,
238 0,
239 1,
240 1,
241 1.0,
242 0.0,
243 GridBagConstraints.CENTER,
244 GridBagConstraints.HORIZONTAL,
245 new Insets(0, 0, 0, 0),
246 0,
247 0));
248
249 JPanel toolbarPanel = new JPanel();
250 toolbarPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
251 toolbarPanel.add(toolBar1);
252 toolbarPanel.add(toolBar2);
253 this.getContentPane().add(
254 toolbarPanel,
255 new GridBagConstraints(
256 0,
257 0,
258 1,
259 1,
260 1.0,
261 0.0,
262 GridBagConstraints.CENTER,
263 GridBagConstraints.HORIZONTAL,
264 new Insets(0, 0, 0, 0),
265 0,
266 0));
267 this.getContentPane().add(
268 this.jSplitPane2,
269 new GridBagConstraints(
270 0,
271 1,
272 1,
273 1,
274 1.0,
275 1.0,
276 GridBagConstraints.CENTER,
277 GridBagConstraints.BOTH,
278 new Insets(0, 0, 0, 0),
279 0,
280 0));
281 this.getContentPane().add(
282 this.jPanelStatusBar,
283 new GridBagConstraints(
284 0,
285 2,
286 1,
287 1,
288 0.0,
289 0.0,
290 GridBagConstraints.CENTER,
291 GridBagConstraints.HORIZONTAL,
292 new Insets(0, 0, 0, 0),
293 0,
294 0));
295 }
296
297 /***
298 * main function : nextObjects launcher
299 *
300 * @param args Arguments passed to the launcher
301 */
302 public static void main(final String[] args)
303 {
304
305 splash = new SplashScreen();
306
307 splash.setVisible(true);
308
309 new NextObjects();
310
311 splash.setVisible(false);
312
313
314 splash = null;
315 logger.info(" _");
316 logger.info("| // , _Nextobjects_ O");
317 logger.info("| ] | -_) v / _| |//| |");
318 logger.info("|__/ //__|//_///__|_|////|_|");
319 System.gc();
320 }
321
322 /***
323 * Return a reference to the 'NextObjects' object
324 *
325 * @return The 'NextObjects' object
326 */
327 public static NextObjects getReference()
328 {
329 return nextObjects;
330 }
331 /***
332 * Change the text in the status bar
333 * @param text Text to display
334 */
335 public static void setStatusBarText(final String text)
336 {
337 jLabelStatus.setText(text);
338 }
339 /***
340 * Load an icon
341 *
342 * @param pImgName the name of the image
343 * @return the image icon
344 */
345 public final ImageIcon loadIconResource(final String pImgName)
346 {
347 try
348 {
349
350 ClassLoader cl = this.getClass().getClassLoader();
351 return new ImageIcon(
352 cl.getResource("org/devaki/nextobjects/icons/" + pImgName));
353 }
354 catch (Throwable t)
355 {
356 System.err.println("Image_Load_Error : " + pImgName);
357 return null;
358 }
359 }
360 /***
361 * Return a reference to the 'DataDictionary' object
362 *
363 * @return The 'DataDictionary' object
364 */
365 public static DataDictionaryEdit getDataDictionaryEdit()
366 {
367 return dataDictionaryEdit;
368 }
369 /***
370 * Return a reference to the workspace
371 * @return a reference to the workspace
372 */
373 public final NOWorkspace getNOWorkspace()
374 {
375 return nOWorkspace;
376 }
377 }