001: /*
002: * Enhydra Java Application Server Project
003: *
004: * The contents of this file are subject to the Enhydra Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License on
007: * the Enhydra web site ( http://www.enhydra.org/ ).
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011: * the License for the specific terms governing rights and limitations
012: * under the License.
013: *
014: * The Initial Developer of the Enhydra Application Server is Lutris
015: * Technologies, Inc. The Enhydra Application Server and portions created
016: * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017: * All Rights Reserved.
018: *
019: * Contributor(s):
020: * Paul Mahar
021: *
022: */
023: package org.enhydra.kelp.common.xmlc;
024:
025: // ToolBox imports
026: import org.enhydra.tool.common.PathHandle;
027: import org.enhydra.tool.common.SwingUtil;
028:
029: // Kelp imports
030: import org.enhydra.kelp.common.node.OtterProject;
031:
032: // Standard imports
033: import javax.swing.*;
034: import java.awt.*;
035: import java.awt.event.*;
036: import java.io.*;
037: import java.beans.*;
038: import java.util.ResourceBundle;
039:
040: /**
041: * Class declaration
042: *
043: *
044: * @author Paul Mahar
045: */
046: public class MapEditorDialog extends JDialog {
047: static ResourceBundle res = ResourceBundle
048: .getBundle("org.enhydra.kelp.common.Res"); // nores
049: public static final int ACTION_OK = 0;
050: public static final int ACTION_CANCEL = 1;
051: private static File startFolder = null;
052: private int option = ACTION_CANCEL;
053: private LocalButtonListener buttonListener = null;
054: private JPanel panelMain = new JPanel();
055: private GridBagLayout layoutMain;
056: private JPanel panelEntry;
057: private GridBagLayout layoutEntry;
058: private JPanel panelButtons;
059: private GridBagLayout layoutButton;
060: private JLabel labelFolder;
061: private JTextField textFolder;
062: private JButton buttonBrowse;
063: private JLabel labelPackage;
064: private JTextField textPackage;
065: private JButton buttonCancel;
066: private JButton buttonOK;
067: private OtterProject project;
068:
069: /**
070: * Constructor declaration
071: *
072: *
073: * @param owner
074: * @param title
075: * @param modal
076: */
077: public MapEditorDialog(Frame owner, String title, boolean modal) {
078: super (owner, title, modal);
079: construct();
080: }
081:
082: public MapEditorDialog(JDialog owner, String title, boolean modal) {
083: super (owner, title, modal);
084: construct();
085: }
086:
087: private void construct() {
088: try {
089: jbInit();
090: pmInit();
091: pack();
092: } catch (Exception ex) {
093: ex.printStackTrace();
094: }
095: }
096:
097: /**
098: * Constructor declaration
099: *
100: */
101: public MapEditorDialog() {
102: this (new Frame(), new String(), false);
103: }
104:
105: /**
106: * Method declaration
107: *
108: */
109: public void show() {
110: setResizable(false);
111: Point cPoint;
112:
113: invalidate();
114: doLayout();
115: pack();
116: cPoint = SwingUtil.getCenteringPoint(getSize());
117: setLocation(cPoint);
118: super .show();
119: }
120:
121: /**
122: * Method declaration
123: *
124: */
125: private void pmInit() {
126: buttonListener = new LocalButtonListener();
127: buttonBrowse.addActionListener(buttonListener);
128: buttonOK.addActionListener(buttonListener);
129: buttonCancel.addActionListener(buttonListener);
130: textFolder.setText(new String());
131: textPackage.setText(new String());
132: }
133:
134: /**
135: * Method declaration
136: *
137: *
138: * @throws Exception
139: */
140: private void jbInit() throws Exception {
141: layoutMain = (GridBagLayout) Beans.instantiate(getClass()
142: .getClassLoader(), GridBagLayout.class.getName());
143: panelEntry = (JPanel) Beans.instantiate(getClass()
144: .getClassLoader(), JPanel.class.getName());
145: layoutEntry = (GridBagLayout) Beans.instantiate(getClass()
146: .getClassLoader(), GridBagLayout.class.getName());
147: panelButtons = (JPanel) Beans.instantiate(getClass()
148: .getClassLoader(), JPanel.class.getName());
149: layoutButton = (GridBagLayout) Beans.instantiate(getClass()
150: .getClassLoader(), GridBagLayout.class.getName());
151: labelFolder = (JLabel) Beans.instantiate(getClass()
152: .getClassLoader(), JLabel.class.getName());
153: textFolder = (JTextField) Beans.instantiate(getClass()
154: .getClassLoader(), JTextField.class.getName());
155: buttonBrowse = (JButton) Beans.instantiate(getClass()
156: .getClassLoader(), JButton.class.getName());
157: labelPackage = (JLabel) Beans.instantiate(getClass()
158: .getClassLoader(), JLabel.class.getName());
159: textPackage = (JTextField) Beans.instantiate(getClass()
160: .getClassLoader(), JTextField.class.getName());
161: buttonCancel = (JButton) Beans.instantiate(getClass()
162: .getClassLoader(), JButton.class.getName());
163: buttonOK = (JButton) Beans.instantiate(getClass()
164: .getClassLoader(), JButton.class.getName());
165: panelMain.setLayout(layoutMain);
166: panelEntry.setLayout(layoutEntry);
167: panelButtons.setLayout(layoutButton);
168: labelFolder.setText(res.getString("labelFolder_Text"));
169: textFolder.setPreferredSize(new Dimension(250, 21));
170: buttonBrowse.setText(res.getString("Browse"));
171: labelPackage.setText(res.getString("labelPackage_Text"));
172: textPackage.setPreferredSize(new Dimension(250, 21));
173: buttonCancel.setText(res.getString("Cancel"));
174: buttonOK.setText(res.getString("OK"));
175: getContentPane().add(panelMain);
176: panelMain.add(panelEntry, new GridBagConstraints(0, 0, 1, 1,
177: 0.2, 0.2, GridBagConstraints.CENTER,
178: GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
179: panelEntry.add(labelFolder, new GridBagConstraints(0, 0, 1, 1,
180: 0.2, 0.2, GridBagConstraints.WEST,
181: GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
182: 0, 0));
183: panelEntry.add(textFolder, new GridBagConstraints(0, 1, 1, 1,
184: 0.4, 0.4, GridBagConstraints.WEST,
185: GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
186: 200, 0));
187: panelEntry.add(buttonBrowse, new GridBagConstraints(1, 1, 1, 1,
188: 0.2, 0.2, GridBagConstraints.CENTER,
189: GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
190: panelEntry.add(labelPackage, new GridBagConstraints(0, 2, 1, 1,
191: 0.2, 0.2, GridBagConstraints.WEST,
192: GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
193: 0, 0));
194: panelEntry.add(textPackage, new GridBagConstraints(0, 3, 1, 1,
195: 0.4, 0.4, GridBagConstraints.WEST,
196: GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
197: 200, 0));
198: panelMain.add(panelButtons, new GridBagConstraints(0, 1, 1, 1,
199: 0.2, 0.2, GridBagConstraints.CENTER,
200: GridBagConstraints.BOTH, new Insets(5, 5, 5, 0), 0, 0));
201: panelButtons.add(buttonOK, new GridBagConstraints(0, 0, 1, 1,
202: 0.0, 0.0, GridBagConstraints.CENTER,
203: GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
204: panelButtons.add(buttonCancel, new GridBagConstraints(1, 0, 1,
205: 1, 0.0, 0.0, GridBagConstraints.CENTER,
206: GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
207: }
208:
209: /**
210: * Method declaration
211: *
212: */
213: protected void closeDialog() {
214: setVisible(false);
215: removeAll();
216: dispose();
217: }
218:
219: /**
220: * Method declaration
221: *
222: *
223: * @return
224: */
225: protected int getOption() {
226: return option;
227: }
228:
229: /**
230: * Method declaration
231: *
232: *
233: * @return
234: */
235: protected String getFolder() {
236: return textFolder.getText();
237: }
238:
239: protected void setFolder(String folder) {
240: textFolder.setText(folder);
241: }
242:
243: protected void setProject(OtterProject p) {
244: project = p;
245: }
246:
247: protected OtterProject getProject() {
248: return project;
249: }
250:
251: /**
252: * Method declaration
253: *
254: *
255: * @return
256: */
257: protected String getPackageName() {
258: return textPackage.getText();
259: }
260:
261: protected void setPackageName(String pack) {
262: textPackage.setText(pack);
263: }
264:
265: /**
266: * Method declaration
267: *
268: *
269: * @param o
270: */
271: private void setOption(int o) {
272: option = o;
273: }
274:
275: /**
276: * Method declaration
277: *
278: */
279: private void browseAction() {
280: File choice;
281:
282: if (startFolder == null || !startFolder.exists()) {
283: if (textFolder.getText().trim().length() == 0) {
284: startFolder = new File(getProject().getRootPath());
285: //
286: } else {
287: startFolder = new File(textFolder.getText());
288: }
289: }
290: choice = SwingUtil.getDirectoryChoice(this , startFolder, res
291: .getString("Select_directory_to"));
292: buttonBrowse.requestFocus();
293: if (choice != null) {
294: textFolder.setText(PathHandle.createPathString(choice));
295: startFolder = choice; // persist this choice for next call
296: }
297: }
298:
299: /**
300: * Class declaration
301: *
302: *
303: * @author
304: * @version %I%, %G%
305: */
306: class LocalButtonListener implements ActionListener {
307:
308: /**
309: * Method declaration
310: *
311: *
312: * @param event
313: */
314: public void actionPerformed(ActionEvent event) {
315: Object source = event.getSource();
316:
317: if (source == buttonBrowse) {
318: browseAction();
319: } else if (source == buttonOK) {
320: setOption(ACTION_OK);
321: closeDialog();
322: } else if (source == buttonCancel) {
323: setOption(ACTION_CANCEL);
324: closeDialog();
325: }
326: }
327:
328: }
329: }
|