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.deployer;
024:
025: // ToolBox imports
026: import org.enhydra.tool.common.SwingUtil;
027:
028: // Standard imports
029: import java.awt.Dimension;
030: import java.awt.Dialog;
031: import java.awt.Frame;
032: import java.awt.GridBagLayout;
033: import java.awt.GridBagConstraints;
034: import java.awt.Insets;
035: import java.awt.Point;
036: import java.awt.event.ActionEvent;
037: import java.awt.event.ActionListener;
038: import java.io.File;
039: import java.beans.Beans;
040: import javax.swing.JButton;
041: import javax.swing.JDialog;
042: import javax.swing.JPanel;
043: import javax.swing.JTextField;
044: import javax.swing.JLabel;
045: import java.util.ResourceBundle;
046:
047: /**
048: * Class declaration
049: *
050: *
051: * @author
052: * @version %I%, %G%
053: */
054: public class ReplaceEditorDialog extends JDialog {
055: static ResourceBundle res = ResourceBundle
056: .getBundle("org.enhydra.kelp.common.Res"); // nores
057: public static final int ACTION_OK = 0;
058: public static final int ACTION_CANCEL = 1;
059: private static File startFolder = null;
060: private int option = ACTION_CANCEL;
061: private LocalButtonListener buttonListener = null;
062: private JPanel panelMain = new JPanel();
063: private GridBagLayout layoutMain;
064: private JPanel panelEntry;
065: private GridBagLayout layoutEntry;
066: private JPanel panelButtons;
067: private GridBagLayout layoutButton;
068: private JLabel labelFind;
069: private JTextField textFind;
070: private JButton buttonBrowse;
071: private JLabel labelReplaceWith;
072: private JTextField textReplaceWith;
073: private JButton buttonCancel;
074: private JButton buttonOK;
075:
076: /**
077: * Constructor declaration
078: *
079: *
080: * @param owner
081: * @param title
082: * @param modal
083: */
084: public ReplaceEditorDialog(Dialog owner, String title, boolean modal) {
085: super (owner, title, modal);
086: construct();
087: }
088:
089: public ReplaceEditorDialog(Frame owner, String title, boolean modal) {
090: super (owner, title, modal);
091: construct();
092: }
093:
094: private void construct() {
095: try {
096: jbInit();
097: pmInit();
098: pack();
099: } catch (Exception ex) {
100: ex.printStackTrace();
101: }
102: }
103:
104: /**
105: * Constructor declaration
106: *
107: */
108: public ReplaceEditorDialog() {
109: this (new Frame(), new String(), false);
110: }
111:
112: /**
113: * Method declaration
114: *
115: */
116: public void show() {
117: setResizable(false);
118: Point cPoint;
119:
120: invalidate();
121: doLayout();
122: pack();
123: cPoint = SwingUtil.getCenteringPoint(getSize());
124: setLocation(cPoint);
125: super .show();
126: }
127:
128: /**
129: * Method declaration
130: *
131: */
132: private void pmInit() {
133: buttonListener = new LocalButtonListener();
134: buttonBrowse.addActionListener(buttonListener);
135: buttonOK.addActionListener(buttonListener);
136: buttonCancel.addActionListener(buttonListener);
137: textFind.setText(new String());
138: textReplaceWith.setText(new String());
139: }
140:
141: /**
142: * Method declaration
143: *
144: *
145: * @throws Exception
146: */
147: private void jbInit() throws Exception {
148: layoutMain = (GridBagLayout) Beans.instantiate(getClass()
149: .getClassLoader(), GridBagLayout.class.getName());
150: panelEntry = (JPanel) Beans.instantiate(getClass()
151: .getClassLoader(), JPanel.class.getName());
152: layoutEntry = (GridBagLayout) Beans.instantiate(getClass()
153: .getClassLoader(), GridBagLayout.class.getName());
154: panelButtons = (JPanel) Beans.instantiate(getClass()
155: .getClassLoader(), JPanel.class.getName());
156: layoutButton = (GridBagLayout) Beans.instantiate(getClass()
157: .getClassLoader(), GridBagLayout.class.getName());
158: labelFind = (JLabel) Beans.instantiate(getClass()
159: .getClassLoader(), JLabel.class.getName());
160: textFind = (JTextField) Beans.instantiate(getClass()
161: .getClassLoader(), JTextField.class.getName());
162: buttonBrowse = (JButton) Beans.instantiate(getClass()
163: .getClassLoader(), JButton.class.getName());
164: labelReplaceWith = (JLabel) Beans.instantiate(getClass()
165: .getClassLoader(), JLabel.class.getName());
166: textReplaceWith = (JTextField) Beans.instantiate(getClass()
167: .getClassLoader(), JTextField.class.getName());
168: buttonCancel = (JButton) Beans.instantiate(getClass()
169: .getClassLoader(), JButton.class.getName());
170: buttonOK = (JButton) Beans.instantiate(getClass()
171: .getClassLoader(), JButton.class.getName());
172: panelMain.setLayout(layoutMain);
173: panelEntry.setLayout(layoutEntry);
174: panelButtons.setLayout(layoutButton);
175: labelFind.setText(res.getString("labelFind_Text"));
176: textFind.setPreferredSize(new Dimension(250, 21));
177: labelReplaceWith
178: .setText(res.getString("labelReplaceWith_Text"));
179: textReplaceWith.setPreferredSize(new Dimension(250, 21));
180: buttonBrowse.setText(res.getString("Browse"));
181: buttonCancel.setText(res.getString("Cancel"));
182: buttonOK.setText(res.getString("OK"));
183: getContentPane().add(panelMain);
184: panelMain.add(panelEntry, new GridBagConstraints(0, 0, 1, 1,
185: 0.2, 0.2, GridBagConstraints.CENTER,
186: GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
187: panelEntry.add(labelFind, new GridBagConstraints(0, 0, 1, 1,
188: 0.2, 0.2, GridBagConstraints.WEST,
189: GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
190: 0, 0));
191: panelEntry.add(textFind, new GridBagConstraints(0, 1, 1, 1,
192: 0.4, 0.4, GridBagConstraints.WEST,
193: GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
194: 200, 0));
195: panelEntry.add(labelReplaceWith, new GridBagConstraints(0, 2,
196: 1, 1, 0.2, 0.2, GridBagConstraints.WEST,
197: GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
198: 0, 0));
199: panelEntry.add(textReplaceWith, new GridBagConstraints(0, 3, 1,
200: 1, 0.4, 0.4, GridBagConstraints.WEST,
201: GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
202: 200, 0));
203: panelEntry.add(buttonBrowse, new GridBagConstraints(1, 3, 1, 1,
204: 0.2, 0.2, GridBagConstraints.CENTER,
205: GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
206: panelMain.add(panelButtons, new GridBagConstraints(0, 1, 1, 1,
207: 0.2, 0.2, GridBagConstraints.CENTER,
208: GridBagConstraints.BOTH, new Insets(5, 5, 5, 0), 0, 0));
209: panelButtons.add(buttonOK, new GridBagConstraints(0, 0, 1, 1,
210: 0.0, 0.0, GridBagConstraints.CENTER,
211: GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
212: panelButtons.add(buttonCancel, new GridBagConstraints(1, 0, 1,
213: 1, 0.0, 0.0, GridBagConstraints.CENTER,
214: GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
215: }
216:
217: /**
218: * Method declaration
219: *
220: */
221: protected void closeDialog() {
222: setVisible(false);
223: removeAll();
224: dispose();
225: }
226:
227: /**
228: * Method declaration
229: *
230: *
231: * @return
232: */
233: protected int getOption() {
234: return option;
235: }
236:
237: /**
238: * Method declaration
239: *
240: *
241: * @return
242: */
243: protected String getFind() {
244: return textFind.getText();
245: }
246:
247: protected void setFind(String find) {
248: textFind.setText(find);
249: }
250:
251: /**
252: * Method declaration
253: *
254: *
255: * @return
256: */
257: protected String getReplaceWith() {
258: return textReplaceWith.getText();
259: }
260:
261: protected void setReplaceWith(String replace) {
262: textReplaceWith.setText(replace);
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: startFolder = new File(textReplaceWith.getText());
284: }
285: choice = SwingUtil.getDirectoryChoice(this , startFolder, res
286: .getString("Select_folder_to_use"));
287: buttonBrowse.requestFocus();
288: if (choice != null) {
289: textReplaceWith.setText(choice.toString());
290: startFolder = choice; // persist this choice for next call
291: }
292: }
293:
294: class LocalButtonListener implements ActionListener {
295:
296: /**
297: * Method declaration
298: *
299: *
300: * @param event
301: */
302: public void actionPerformed(ActionEvent event) {
303: Object source = event.getSource();
304:
305: if (source == buttonBrowse) {
306: browseAction();
307: } else if (source == buttonOK) {
308: setOption(ACTION_OK);
309: closeDialog();
310: } else if (source == buttonCancel) {
311: setOption(ACTION_CANCEL);
312: closeDialog();
313: }
314: }
315:
316: }
317: }
|