KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > common > xmlc > MapDialog


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  */

22 package org.enhydra.kelp.common.xmlc;
23
24 // ToolBox imports
25
import org.enhydra.tool.common.SwingUtil;
26
27 // Kelp imports
28
import org.enhydra.kelp.common.event.SwingTableSelectionEvent;
29 import org.enhydra.kelp.common.event.SwingTableSelectionListener;
30 import org.enhydra.kelp.common.node.OtterProject;
31
32 // Standard imports
33
import javax.swing.*;
34 import java.beans.*;
35 import java.awt.*;
36 import java.awt.event.*;
37 import java.util.ResourceBundle JavaDoc;
38
39 /**
40  * Class declaration
41  *
42  *
43  * @author Paul Mahar
44  */

45 public class MapDialog extends JDialog
46     implements SwingTableSelectionListener {
47     static ResourceBundle JavaDoc res =
48         ResourceBundle.getBundle("org.enhydra.kelp.common.Res"); // nores
49
private boolean standalone = false;
50     private OtterProject project = null;
51     private LocalButtonListener buttonListener = null;
52     private JPanel panelMain;
53     private MapPanel mapPanel;
54     private GridBagLayout layoutMain;
55     private JPanel panelButton;
56     private GridBagLayout layoutButton;
57     private JButton buttonAdd;
58     private JButton buttonRemove;
59     private JButton buttonClose;
60     private JPanel jPanel1;
61     private JPanel panelFiller;
62     private JButton buttonEdit;
63
64     /**
65      * Constructor declaration
66      *
67      *
68      * @param owner
69      * @param title
70      * @param modal
71      */

72     public MapDialog(Frame owner, String JavaDoc title, boolean modal) {
73         super(owner, title, modal);
74         construct();
75     }
76
77     /**
78      * Constructor declaration
79      *
80      *
81      * @param owner
82      * @param title
83      * @param modal
84      */

85     public MapDialog(Dialog owner, String JavaDoc title, boolean modal) {
86         super(owner, title, modal);
87         construct();
88     }
89
90     // overloading
91

92     /**
93      * Method declaration
94      *
95      */

96     public void show() {
97
98         // setResizable(false); // crashes Win98
99
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 JavaDoc 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 JavaDoc {
204         panelMain = (JPanel) Beans.instantiate(getClass().getClassLoader(),
205                                                JPanel.class.getName());
206         mapPanel = (MapPanel) Beans.instantiate(getClass().getClassLoader(),
207                                                 MapPanel.class.getName());
208         layoutMain =
209             (GridBagLayout) Beans.instantiate(getClass().getClassLoader(),
210                                               GridBagLayout.class.getName());
211         panelButton = (JPanel) Beans.instantiate(getClass().getClassLoader(),
212                                                  JPanel.class.getName());
213         layoutButton =
214             (GridBagLayout) Beans.instantiate(getClass().getClassLoader(),
215                                               GridBagLayout.class.getName());
216         buttonAdd = (JButton) Beans.instantiate(getClass().getClassLoader(),
217                                                 JButton.class.getName());
218         buttonRemove =
219             (JButton) Beans.instantiate(getClass().getClassLoader(),
220                                         JButton.class.getName());
221         buttonClose = (JButton) Beans.instantiate(getClass().getClassLoader(),
222                                                   JButton.class.getName());
223         jPanel1 = (JPanel) Beans.instantiate(getClass().getClassLoader(),
224                                              JPanel.class.getName());
225         panelFiller = (JPanel) Beans.instantiate(getClass().getClassLoader(),
226                                                  JPanel.class.getName());
227         buttonEdit = (JButton) Beans.instantiate(getClass().getClassLoader(),
228                                                  JButton.class.getName());
229         panelMain.setLayout(layoutMain);
230         panelButton.setLayout(layoutButton);
231         buttonAdd.setText(res.getString("buttonAdd_Text"));
232         buttonRemove.setText(res.getString("Remove_"));
233         buttonClose.setText(res.getString("Close"));
234         buttonEdit.setText(res.getString("Edit"));
235         panelMain.add(mapPanel,
236                       new GridBagConstraints(0, 0, 1, 1, 0.7, 0.7,
237                                              GridBagConstraints.CENTER,
238                                              GridBagConstraints.BOTH,
239                                              new Insets(0, 0, 0, 0), 0, 0));
240         panelMain.add(panelButton,
241                       new GridBagConstraints(0, 1, 1, 1, 0.3, 0.3,
242                                              GridBagConstraints.CENTER,
243                                              GridBagConstraints.BOTH,
244                                              new Insets(0, 0, 0, 0), 20, 20));
245         panelButton.add(buttonAdd,
246                         new GridBagConstraints(1, 0, 2, 1, 0.0, 0.0,
247                                                GridBagConstraints.CENTER,
248                                                GridBagConstraints.NONE,
249                                                new Insets(5, 5, 5, 5), 0, 0));
250         panelButton.add(buttonRemove,
251                         new GridBagConstraints(4, 0, 1, 1, 0.0, 0.0,
252                                                GridBagConstraints.CENTER,
253                                                GridBagConstraints.NONE,
254                                                new Insets(5, 5, 5, 5), 0, 0));
255         panelButton.add(buttonClose,
256                         new GridBagConstraints(5, 0, 1, 1, 0.0, 0.0,
257                                                GridBagConstraints.CENTER,
258                                                GridBagConstraints.NONE,
259                                                new Insets(5, 5, 5, 5), 0, 0));
260         panelButton.add(panelFiller,
261                         new GridBagConstraints(0, 0, 1, 1, 0.1, 0.1,
262                                                GridBagConstraints.CENTER,
263                                                GridBagConstraints.BOTH,
264                                                new Insets(0, 0, 0, 0), 0, 0));
265         panelButton.add(buttonEdit,
266                         new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0,
267                                                GridBagConstraints.CENTER,
268                                                GridBagConstraints.NONE,
269                                                new Insets(5, 5, 5, 5), 0, 0));
270         this.getContentPane().add(panelMain);
271     }
272
273     /**
274      * Method declaration
275      *
276      */

277     private void actionAdd() {
278         MapEditorDialog d =
279             new MapEditorDialog(this, res.getString("Add_a_new_directory"),
280                                 true);
281
282         d.setProject(getProject());
283         d.show();
284         if (d.getOption() == MapEditorDialog.ACTION_OK) {
285             if (d.getFolder().trim().length() > 0) {
286                 mapPanel.addRow(d.getFolder(), d.getPackageName());
287             }
288         }
289     }
290
291     private void actionEdit() {
292         MapEditorDialog d =
293             new MapEditorDialog(this, res.getString("Edit_directory_to"),
294                                 true);
295
296         d.setFolder(mapPanel.getSelectedFolder());
297         d.setPackageName(mapPanel.getSelectedPackageName());
298         d.setProject(project);
299         d.show();
300         if (d.getOption() == MapEditorDialog.ACTION_OK) {
301             if (d.getFolder().trim().length() > 0) {
302                 mapPanel.updateSelectedRow(d.getFolder(), d.getPackageName());
303             }
304         }
305     }
306
307     /**
308      * Method declaration
309      *
310      */

311     private void actionRemove() {
312         if (mapPanel.getCurrentSelectionIndex() == MapPanel.NO_SELECTION) {
313
314             // does this ever happen?
315
// if so, would be good to have user alert here
316
} else {
317             int result =
318                 JOptionPane.showConfirmDialog(this,
319                                               res.getString("Remove_the_current"),
320                                               res.getString("Remove_Mapping"),
321                                               JOptionPane.YES_NO_OPTION);
322
323             if (result == JOptionPane.YES_OPTION) {
324                 mapPanel.removeRow(mapPanel.getCurrentSelectionIndex());
325             }
326         }
327     }
328
329     /**
330      * Class declaration
331      *
332      *
333      * @author
334      * @version %I%, %G%
335      */

336     class LocalButtonListener implements ActionListener {
337
338         /**
339          * Method declaration
340          *
341          *
342          * @param event
343          */

344         public void actionPerformed(ActionEvent event) {
345             Object JavaDoc source = event.getSource();
346
347             if (source == buttonAdd) {
348                 actionAdd();
349             } else if (source == buttonEdit) {
350                 actionEdit();
351             } else if (source == buttonRemove) {
352                 actionRemove();
353             } else if (source == buttonClose) {
354                 closeDialog();
355             }
356         }
357
358     }
359 }
360
Popular Tags