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: *
021: */
022: package org.enhydra.kelp.common.xmlc;
023:
024: // ToolBox imports
025: import org.enhydra.tool.common.SwingUtil;
026:
027: // Kelp imports
028: import org.enhydra.kelp.common.event.SwingTableSelectionEvent;
029: import org.enhydra.kelp.common.event.SwingTableSelectionListener;
030: import org.enhydra.kelp.common.node.OtterProject;
031:
032: // Standard imports
033: import javax.swing.*;
034: import java.beans.*;
035: import java.awt.*;
036: import java.awt.event.*;
037: import java.util.ResourceBundle;
038:
039: /**
040: * Class declaration
041: *
042: *
043: * @author Paul Mahar
044: */
045: public class MapDialog extends JDialog implements
046: SwingTableSelectionListener {
047: static ResourceBundle res = ResourceBundle
048: .getBundle("org.enhydra.kelp.common.Res"); // nores
049: private boolean standalone = false;
050: private OtterProject project = null;
051: private LocalButtonListener buttonListener = null;
052: private JPanel panelMain;
053: private MapPanel mapPanel;
054: private GridBagLayout layoutMain;
055: private JPanel panelButton;
056: private GridBagLayout layoutButton;
057: private JButton buttonAdd;
058: private JButton buttonRemove;
059: private JButton buttonClose;
060: private JPanel jPanel1;
061: private JPanel panelFiller;
062: private JButton buttonEdit;
063:
064: /**
065: * Constructor declaration
066: *
067: *
068: * @param owner
069: * @param title
070: * @param modal
071: */
072: public MapDialog(Frame owner, String title, boolean modal) {
073: super (owner, title, modal);
074: construct();
075: }
076:
077: /**
078: * Constructor declaration
079: *
080: *
081: * @param owner
082: * @param title
083: * @param modal
084: */
085: public MapDialog(Dialog owner, String title, boolean modal) {
086: super (owner, title, modal);
087: construct();
088: }
089:
090: // overloading
091:
092: /**
093: * Method declaration
094: *
095: */
096: public void show() {
097:
098: // setResizable(false); // crashes Win98
099: Point cPoint;
100:
101: invalidate();
102: doLayout();
103: pack();
104: cPoint = SwingUtil.getCenteringPoint(getSize());
105: setLocation(cPoint);
106: super .show();
107: }
108:
109: // /
110: // /
111: public void onSwingTableSelection(SwingTableSelectionEvent event) {
112: boolean en = (!event.isSelectionNull());
113:
114: buttonEdit.setEnabled(en);
115: buttonRemove.setEnabled(en);
116: }
117:
118: /**
119: * Method declaration
120: *
121: */
122: protected void clearAll() {
123: layoutMain.removeLayoutComponent(mapPanel);
124: panelMain.removeAll();
125: layoutMain = null;
126: panelMain = null;
127: setTitle(null);
128: }
129:
130: /**
131: * Method declaration
132: *
133: *
134: * @return
135: */
136: public OtterProject getProject() {
137: return project;
138: }
139:
140: /**
141: * Method declaration
142: *
143: *
144: * @param p
145: */
146: public void setProject(OtterProject p) {
147: project = p;
148: mapPanel.setMap(project.getPackageMap());
149: }
150:
151: /**
152: * Method declaration
153: *
154: */
155: protected void closeDialog() {
156: project.setPackageMap(mapPanel.getMap());
157: setVisible(false);
158: removeAll();
159: dispose();
160: if (standalone) {
161: System.exit(0);
162: }
163: }
164:
165: // /
166: // /
167:
168: /**
169: * Method declaration
170: *
171: */
172: private void construct() {
173: try {
174: jbInit();
175: pmInit();
176: pack();
177: } catch (Exception ex) {
178: ex.printStackTrace();
179: }
180: }
181:
182: /**
183: * Method declaration
184: *
185: */
186: private void pmInit() {
187: buttonListener = new LocalButtonListener();
188: buttonAdd.addActionListener(buttonListener);
189: buttonEdit.addActionListener(buttonListener);
190: buttonRemove.addActionListener(buttonListener);
191: buttonClose.addActionListener(buttonListener);
192: buttonEdit.setEnabled(false);
193: buttonRemove.setEnabled(false);
194: mapPanel.addSwingTableSelectionListener(this );
195: }
196:
197: /**
198: * Method declaration
199: *
200: *
201: * @throws Exception
202: */
203: private void jbInit() throws Exception {
204: panelMain = (JPanel) Beans.instantiate(getClass()
205: .getClassLoader(), JPanel.class.getName());
206: mapPanel = (MapPanel) Beans.instantiate(getClass()
207: .getClassLoader(), MapPanel.class.getName());
208: layoutMain = (GridBagLayout) Beans.instantiate(getClass()
209: .getClassLoader(), GridBagLayout.class.getName());
210: panelButton = (JPanel) Beans.instantiate(getClass()
211: .getClassLoader(), JPanel.class.getName());
212: layoutButton = (GridBagLayout) Beans.instantiate(getClass()
213: .getClassLoader(), GridBagLayout.class.getName());
214: buttonAdd = (JButton) Beans.instantiate(getClass()
215: .getClassLoader(), JButton.class.getName());
216: buttonRemove = (JButton) Beans.instantiate(getClass()
217: .getClassLoader(), JButton.class.getName());
218: buttonClose = (JButton) Beans.instantiate(getClass()
219: .getClassLoader(), JButton.class.getName());
220: jPanel1 = (JPanel) Beans.instantiate(getClass()
221: .getClassLoader(), JPanel.class.getName());
222: panelFiller = (JPanel) Beans.instantiate(getClass()
223: .getClassLoader(), JPanel.class.getName());
224: buttonEdit = (JButton) Beans.instantiate(getClass()
225: .getClassLoader(), JButton.class.getName());
226: panelMain.setLayout(layoutMain);
227: panelButton.setLayout(layoutButton);
228: buttonAdd.setText(res.getString("buttonAdd_Text"));
229: buttonRemove.setText(res.getString("Remove_"));
230: buttonClose.setText(res.getString("Close"));
231: buttonEdit.setText(res.getString("Edit"));
232: panelMain.add(mapPanel, new GridBagConstraints(0, 0, 1, 1, 0.7,
233: 0.7, GridBagConstraints.CENTER,
234: GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
235: panelMain.add(panelButton,
236: new GridBagConstraints(0, 1, 1, 1, 0.3, 0.3,
237: GridBagConstraints.CENTER,
238: GridBagConstraints.BOTH,
239: new Insets(0, 0, 0, 0), 20, 20));
240: panelButton.add(buttonAdd, new GridBagConstraints(1, 0, 2, 1,
241: 0.0, 0.0, GridBagConstraints.CENTER,
242: GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
243: panelButton.add(buttonRemove, new GridBagConstraints(4, 0, 1,
244: 1, 0.0, 0.0, GridBagConstraints.CENTER,
245: GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
246: panelButton.add(buttonClose, new GridBagConstraints(5, 0, 1, 1,
247: 0.0, 0.0, GridBagConstraints.CENTER,
248: GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
249: panelButton.add(panelFiller, new GridBagConstraints(0, 0, 1, 1,
250: 0.1, 0.1, GridBagConstraints.CENTER,
251: GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
252: panelButton.add(buttonEdit, new GridBagConstraints(3, 0, 1, 1,
253: 0.0, 0.0, GridBagConstraints.CENTER,
254: GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
255: this .getContentPane().add(panelMain);
256: }
257:
258: /**
259: * Method declaration
260: *
261: */
262: private void actionAdd() {
263: MapEditorDialog d = new MapEditorDialog(this , res
264: .getString("Add_a_new_directory"), true);
265:
266: d.setProject(getProject());
267: d.show();
268: if (d.getOption() == MapEditorDialog.ACTION_OK) {
269: if (d.getFolder().trim().length() > 0) {
270: mapPanel.addRow(d.getFolder(), d.getPackageName());
271: }
272: }
273: }
274:
275: private void actionEdit() {
276: MapEditorDialog d = new MapEditorDialog(this , res
277: .getString("Edit_directory_to"), true);
278:
279: d.setFolder(mapPanel.getSelectedFolder());
280: d.setPackageName(mapPanel.getSelectedPackageName());
281: d.setProject(project);
282: d.show();
283: if (d.getOption() == MapEditorDialog.ACTION_OK) {
284: if (d.getFolder().trim().length() > 0) {
285: mapPanel.updateSelectedRow(d.getFolder(), d
286: .getPackageName());
287: }
288: }
289: }
290:
291: /**
292: * Method declaration
293: *
294: */
295: private void actionRemove() {
296: if (mapPanel.getCurrentSelectionIndex() == MapPanel.NO_SELECTION) {
297:
298: // does this ever happen?
299: // if so, would be good to have user alert here
300: } else {
301: int result = JOptionPane.showConfirmDialog(this , res
302: .getString("Remove_the_current"), res
303: .getString("Remove_Mapping"),
304: JOptionPane.YES_NO_OPTION);
305:
306: if (result == JOptionPane.YES_OPTION) {
307: mapPanel.removeRow(mapPanel.getCurrentSelectionIndex());
308: }
309: }
310: }
311:
312: /**
313: * Class declaration
314: *
315: *
316: * @author
317: * @version %I%, %G%
318: */
319: class LocalButtonListener implements ActionListener {
320:
321: /**
322: * Method declaration
323: *
324: *
325: * @param event
326: */
327: public void actionPerformed(ActionEvent event) {
328: Object source = event.getSource();
329:
330: if (source == buttonAdd) {
331: actionAdd();
332: } else if (source == buttonEdit) {
333: actionEdit();
334: } else if (source == buttonRemove) {
335: actionRemove();
336: } else if (source == buttonClose) {
337: closeDialog();
338: }
339: }
340:
341: }
342: }
|