001: //==============================================================================
002: //=== Copyright (C) 2001-2007 Food and Agriculture Organization of the
003: //=== United Nations (FAO-UN), United Nations World Food Programme (WFP)
004: //=== and United Nations Environment Programme (UNEP)
005: //===
006: //=== This program is free software; you can redistribute it and/or modify
007: //=== it under the terms of the GNU General Public License as published by
008: //=== the Free Software Foundation; either version 2 of the License, or (at
009: //=== your option) any later version.
010: //===
011: //=== This program is distributed in the hope that it will be useful, but
012: //=== WITHOUT ANY WARRANTY; without even the implied warranty of
013: //=== MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: //=== General Public License for more details.
015: //===
016: //=== You should have received a copy of the GNU General Public License
017: //=== along with this program; if not, write to the Free Software
018: //=== Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
019: //===
020: //=== Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2,
021: //=== Rome - Italy. email: geonetwork@osgeo.org
022: //==============================================================================
023:
024: package org.fao.gast.gui;
025:
026: import java.awt.BorderLayout;
027: import java.awt.event.ActionEvent;
028: import java.awt.event.ActionListener;
029: import javax.swing.JFrame;
030: import javax.swing.JMenu;
031: import javax.swing.JMenuBar;
032: import javax.swing.JMenuItem;
033: import javax.swing.JSplitPane;
034: import javax.swing.KeyStroke;
035: import org.fao.gast.app.App;
036: import org.fao.gast.boot.Starter;
037: import org.fao.gast.gui.dialogs.ConfigDialog;
038: import org.fao.gast.lib.Lib;
039:
040: //==============================================================================
041:
042: public class MainFrame extends JFrame implements Starter,
043: ActionListener {
044: //---------------------------------------------------------------------------
045: //---
046: //--- Constructor
047: //---
048: //---------------------------------------------------------------------------
049:
050: public MainFrame() {
051: setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
052: setTitle("GAST : GeoNetwork's administrator survival tool");
053:
054: JSplitPane sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
055: panView, panWork);
056: sp.setDividerLocation(150);
057: sp.setContinuousLayout(true);
058:
059: getContentPane().add(sp, BorderLayout.CENTER);
060:
061: panView.setActionListener(new ActionListener() {
062: public void actionPerformed(ActionEvent e) {
063: panWork.show(e.getActionCommand());
064: }
065: });
066:
067: setJMenuBar(createMenuBar());
068: }
069:
070: //---------------------------------------------------------------------------
071: //---
072: //--- ActionListener
073: //---
074: //---------------------------------------------------------------------------
075:
076: public void start(String appPath, String[] args) throws Exception {
077: Lib.init(appPath);
078: App.init(appPath, dlgConfig.getConfig());
079:
080: GuiBuilder builder = new GuiBuilder(appPath, panView, panWork);
081: builder.build("/gast/data/gui.xml");
082:
083: checkAndCreateDB();
084:
085: setSize(700, 500);
086: setVisible(true);
087: }
088:
089: //---------------------------------------------------------------------------
090:
091: private void checkAndCreateDB() throws Exception {
092: String user = Lib.embeddedDB.getUser();
093: String pass = Lib.embeddedDB.getPassword();
094:
095: if (user == null || pass == null) {
096: //--- user & password can be null only if the data files of the
097: //--- embedded database are not there, so we create them
098:
099: Lib.embeddedDB.createDB();
100:
101: user = Lib.embeddedDB.getUser();
102: pass = Lib.embeddedDB.getPassword();
103:
104: //--- then we store the generated account into the config.xml file
105: //--- and save it
106:
107: Lib.config.setDbmsUser(user);
108: Lib.config.setDbmsPassword(pass);
109: Lib.config.save();
110: }
111: }
112:
113: //---------------------------------------------------------------------------
114: //---
115: //--- ActionListener
116: //---
117: //---------------------------------------------------------------------------
118:
119: public void actionPerformed(ActionEvent e) {
120: String cmd = e.getActionCommand();
121:
122: if (cmd.equals("config"))
123: handleConfig();
124: }
125:
126: //---------------------------------------------------------------------------
127:
128: private void handleConfig() {
129: dlgConfig.showDialog();
130: }
131:
132: //---------------------------------------------------------------------------
133: //---
134: //--- Private Methods
135: //---
136: //---------------------------------------------------------------------------
137:
138: private JMenuBar createMenuBar() {
139: JMenuBar menu = new JMenuBar();
140: JMenu options = new JMenu("Options");
141: JMenuItem config = new JMenuItem("Config");
142:
143: menu.add(options);
144: options.add(config);
145:
146: config.addActionListener(this );
147: config.setActionCommand("config");
148: config.setAccelerator(KeyStroke.getKeyStroke("alt C"));
149: return menu;
150: }
151:
152: //---------------------------------------------------------------------------
153: //---
154: //--- Variables
155: //---
156: //---------------------------------------------------------------------------
157:
158: private ViewPanel panView = new ViewPanel();
159: private WorkPanel panWork = new WorkPanel();
160: private ConfigDialog dlgConfig = new ConfigDialog(this );
161: }
162:
163: //==============================================================================
|