KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > common > properties > XMLCProjectPropertyPanel


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  * Paul Mahar
21  *
22  */

23 package org.enhydra.kelp.common.properties;
24
25 // ToolBox
26
import org.enhydra.tool.ToolBoxInfo;
27 import org.enhydra.tool.common.DataValidationException;
28
29 // AddinCore
30
import org.enhydra.kelp.common.event.ExtensionChangeEvent;
31 import org.enhydra.kelp.common.event.ExtensionChangeListener;
32 import org.enhydra.kelp.common.node.OtterProject;
33 import org.enhydra.kelp.common.node.OtterNode;
34 import org.enhydra.kelp.common.swing.AddinInnerPanel;
35 import org.enhydra.kelp.common.swing.ExtensionPanel;
36 import org.enhydra.kelp.common.xmlc.XMLCOptionPanel;
37 import org.enhydra.kelp.common.xmlc.XMLCInnerPanel;
38 import org.enhydra.kelp.common.xmlc.MapDialog;
39
40 // JDK
41
import javax.swing.*;
42 import javax.swing.border.*;
43 import java.awt.*;
44 import java.awt.event.*;
45 import java.beans.*;
46 import java.io.File JavaDoc;
47 import java.util.ResourceBundle JavaDoc;
48
49 //
50
public class XMLCProjectPropertyPanel extends AddinInnerPanel
51     implements ExtensionChangeListener {
52
53     // strings OK to resource
54
static ResourceBundle JavaDoc res =
55         ResourceBundle.getBundle("org.enhydra.kelp.common.Res"); // nores
56
private final String JavaDoc mapAll = res.getString("All");
57     private final String JavaDoc mapSelected = res.getString("Selected");
58     private final String JavaDoc mapNone = res.getString("None");
59
60     //
61
private boolean active = false;
62     private GridBagLayout layoutCompile;
63     private TitledBorder borderMappings;
64     private JPanel panelMappings;
65     private GridBagLayout layoutMap;
66     private JButton buttonMap;
67     private JPanel panelTrace;
68     private GridBagLayout layoutTrace;
69     private JCheckBox checkPrintParseInfo;
70     private JCheckBox checkPrintAccessorInfo;
71     private JCheckBox checkPrintDocumentInfo;
72     private JCheckBox checkPrintDOM;
73     private JCheckBox checkVerbose;
74     private JComboBox comboMap;
75     private JLabel labelMap;
76     private ExtensionPanel extensionPanel;
77     private XMLCOptionPanel optionPanel;
78     private JPanel panelMake;
79     private JCheckBox checkBuild;
80     private GridBagLayout layoutMake;
81     private JTabbedPane tabPane;
82     private JPanel panelCompile;
83     private BorderLayout layoutMain;
84     private LocalButtonListener buttonListener = null;
85
86     /**
87      * Constructor declaration
88      *
89      */

90     public XMLCProjectPropertyPanel() {
91         try {
92             jbInit();
93             pmInit();
94         } catch (Exception JavaDoc e) {
95             e.printStackTrace();
96         }
97     }
98
99     // ExtensionChangeListener
100
public void onChange(ExtensionChangeEvent event) {
101         XMLCInnerPanel innerPanel = null;
102
103         innerPanel = XMLCInnerPanel.XMLCfindAncestor(this);
104         if (innerPanel == null) {
105
106             // nothing to refresh;
107
} else {
108             getProject().setDocTypes(event.getExtensions());
109             innerPanel.getSelectionPanel().setNodes(getProject().getAllDocuments());
110         }
111     }
112
113     // override AddinInnerPanel
114
public void read(OtterNode node) {
115         super.read(node);
116         OtterProject project = null;
117
118         project = getProject();
119         optionPanel.setNode(project);
120         optionPanel.readProperties();
121         if (comboMap.getItemCount() > 0) {
122             comboMap.removeAllItems();
123         }
124         if (project.isOpenBuild()) {
125
126             // Primetime
127
checkBuild.setEnabled(true);
128             checkBuild.setSelected(project.isXMLCBuild());
129             comboMap.addItem(mapAll);
130             comboMap.addItem(mapSelected);
131             comboMap.addItem(mapNone);
132             int vScope = project.getVerifiedMapScope();
133
134             switch (vScope) {
135             case OtterProject.MAP_SCOPE_NONE:
136                 comboMap.setSelectedItem(mapNone);
137                 break;
138             case OtterProject.MAP_SCOPE_SELECTED:
139                 comboMap.setSelectedItem(mapSelected);
140                 break;
141             default:
142                 project.setMapScope(OtterProject.MAP_SCOPE_ALL);
143                 comboMap.setSelectedItem(mapAll);
144                 break;
145             }
146         } else {
147
148             // Win32 and JDeveloper
149
checkBuild.setEnabled(false);
150             checkBuild.setSelected(false);
151             comboMap.addItem(mapAll);
152             comboMap.addItem(mapNone);
153             if (project.getMapScope() == OtterProject.MAP_SCOPE_NONE) {
154                 comboMap.setSelectedItem(mapNone);
155             } else {
156                 comboMap.setSelectedItem(mapAll);
157                 project.setMapScope(OtterProject.MAP_SCOPE_ALL);
158             }
159         }
160         checkPrintDOM.setSelected(project.isPrintDOM());
161         checkPrintParseInfo.setSelected(project.isPrintParseInfo());
162         checkPrintAccessorInfo.setSelected(project.isPrintAccessorInfo());
163         checkPrintDocumentInfo.setSelected(project.isPrintDocumentInfo());
164         checkVerbose.setSelected(project.isVerbose());
165         extensionPanel.setExtensions(project.getDocTypes());
166         extensionPanel.setDefaults(ToolBoxInfo.getSupportedDocTypes());
167         active = true;
168     }
169
170     // override AddinInnerPanel
171
public void write(OtterNode node) throws DataValidationException {
172         super.write(node);
173         String JavaDoc item = null;
174         OtterProject project = null;
175
176         project = getProject();
177         item = comboMap.getSelectedItem().toString().trim();
178         optionPanel.writeProperties();
179         if (project != null && active) {
180             if (item.equalsIgnoreCase(mapAll)) {
181                 project.setMapScope(OtterProject.MAP_SCOPE_ALL);
182             } else if (item.equalsIgnoreCase(mapSelected)) {
183                 project.setMapScope(OtterProject.MAP_SCOPE_SELECTED);
184             } else if (item.equalsIgnoreCase(mapNone)) {
185                 project.setMapScope(OtterProject.MAP_SCOPE_NONE);
186             }
187         }
188         if (project.isOpenBuild()) {
189             // Primetime
190
project.setXMLCBuild(checkBuild.isSelected());
191         } else {
192
193             // Win32 and JDeveloper
194
project.setXMLCBuild(false);
195         }
196         project.setPrintDOM(checkPrintDOM.isSelected());
197         project.setPrintParseInfo(checkPrintParseInfo.isSelected());
198         project.setPrintAccessorInfo(checkPrintAccessorInfo.isSelected());
199         project.setPrintDocumentInfo(checkPrintDocumentInfo.isSelected());
200         project.setVerbose(checkVerbose.isSelected());
201         project.setDocTypes(extensionPanel.getExtensions());
202     }
203
204     // override AddinInnerPanel
205
public Component[] getFirstFocusComponents() {
206         Component[] comps = new Component[14];
207
208         comps[0] = panelMappings;
209         comps[1] = buttonMap;
210         comps[2] = checkPrintParseInfo;
211         comps[3] = checkPrintAccessorInfo;
212         comps[4] = checkPrintDocumentInfo;
213         comps[5] = checkPrintDOM;
214         comps[6] = checkVerbose;
215         comps[7] = comboMap;
216         comps[8] = extensionPanel;
217         comps[9] = optionPanel;
218         comps[10] = panelMake;
219         comps[11] = checkBuild;
220         comps[12] = tabPane;
221         comps[13] = panelCompile;
222         return comps;
223     }
224
225     /**
226      * Method declaration
227      *
228      */

229     private void pmInit() {
230         buttonListener = new LocalButtonListener();
231         buttonMap.addActionListener(buttonListener);
232         extensionPanel.addListener(this);
233     }
234
235     /**
236      * Method declaration
237      *
238      *
239      * @throws Exception
240      */

241     private void jbInit() throws Exception JavaDoc {
242         layoutCompile =
243             (GridBagLayout) Beans.instantiate(getClass().getClassLoader(),
244                                               GridBagLayout.class.getName());
245         extensionPanel =
246             (ExtensionPanel) Beans.instantiate(getClass().getClassLoader(),
247                                                ExtensionPanel.class.getName());
248         optionPanel =
249             (XMLCOptionPanel) Beans.instantiate(getClass().getClassLoader(),
250                                                 XMLCOptionPanel.class.getName());
251         borderMappings = new TitledBorder(new String JavaDoc());
252         panelMappings =
253             (JPanel) Beans.instantiate(getClass().getClassLoader(),
254                                        JPanel.class.getName());
255         layoutMap =
256             (GridBagLayout) Beans.instantiate(getClass().getClassLoader(),
257                                               GridBagLayout.class.getName());
258         buttonMap = (JButton) Beans.instantiate(getClass().getClassLoader(),
259                                                 JButton.class.getName());
260         panelTrace = (JPanel) Beans.instantiate(getClass().getClassLoader(),
261                                                 JPanel.class.getName());
262         layoutTrace =
263             (GridBagLayout) Beans.instantiate(getClass().getClassLoader(),
264                                               GridBagLayout.class.getName());
265         checkPrintParseInfo =
266             (JCheckBox) Beans.instantiate(getClass().getClassLoader(),
267                                           JCheckBox.class.getName());
268         checkPrintAccessorInfo =
269             (JCheckBox) Beans.instantiate(getClass().getClassLoader(),
270                                           JCheckBox.class.getName());
271         checkPrintDocumentInfo =
272             (JCheckBox) Beans.instantiate(getClass().getClassLoader(),
273                                           JCheckBox.class.getName());
274         checkPrintDOM =
275             (JCheckBox) Beans.instantiate(getClass().getClassLoader(),
276                                           JCheckBox.class.getName());
277         checkVerbose =
278             (JCheckBox) Beans.instantiate(getClass().getClassLoader(),
279                                           JCheckBox.class.getName());
280         comboMap = (JComboBox) Beans.instantiate(getClass().getClassLoader(),
281                                                  JComboBox.class.getName());
282         labelMap = (JLabel) Beans.instantiate(getClass().getClassLoader(),
283                                               JLabel.class.getName());
284         panelMake = (JPanel) Beans.instantiate(getClass().getClassLoader(),
285                                                JPanel.class.getName());
286         checkBuild =
287             (JCheckBox) Beans.instantiate(getClass().getClassLoader(),
288                                           JCheckBox.class.getName());
289         layoutMake =
290             (GridBagLayout) Beans.instantiate(getClass().getClassLoader(),
291                                               GridBagLayout.class.getName());
292         tabPane =
293             (JTabbedPane) Beans.instantiate(getClass().getClassLoader(),
294                                             JTabbedPane.class.getName());
295         panelCompile = (JPanel) Beans.instantiate(getClass().getClassLoader(),
296                                                   JPanel.class.getName());
297         layoutMain =
298             (BorderLayout) Beans.instantiate(getClass().getClassLoader(),
299                                              BorderLayout.class.getName());
300         borderMappings.setTitle(res.getString("borderMappings_Title"));
301         panelMappings.setBorder(borderMappings);
302         panelTrace.setLayout(layoutTrace);
303         panelMappings.setLayout(layoutMap);
304         buttonMap.setText(res.getString("buttonMap_Text"));
305         checkPrintParseInfo.setText(res.getString("checkPrintParseInfo_Text"));
306         checkPrintDocumentInfo.setText(res.getString("checkPrintDocumentInfo_Text"));
307         checkPrintDOM.setText(res.getString("checkPrintDOM_Text"));
308         checkVerbose.setText(res.getString("checkVerbose_Text"));
309         checkPrintAccessorInfo.setText(res.getString("checkPrintAccessorInfo_Text"));
310         labelMap.setHorizontalAlignment(SwingConstants.RIGHT);
311         labelMap.setText(res.getString("labelMap_Text"));
312         checkBuild.setEnabled(false);
313         checkBuild.setText(res.getString("checkBuild_Text"));
314         panelMake.setLayout(layoutMake);
315         panelMake.add(checkBuild,
316                       new GridBagConstraints(0, 0, 1, 1, 0.1, 0.1,
317                                              GridBagConstraints.CENTER,
318                                              GridBagConstraints.HORIZONTAL,
319                                              new Insets(2, 2, 2, 2), 0, 0));
320         panelMappings.add(buttonMap,
321                           new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0,
322                                                  GridBagConstraints.CENTER,
323                                                  GridBagConstraints.NONE,
324                                                  new Insets(2, 2, 1, 2), 0,
325                                                  0));
326         panelMappings.add(comboMap,
327                           new GridBagConstraints(1, 0, 1, 1, 0.2, 0.2,
328                                                  GridBagConstraints.CENTER,
329                                                  GridBagConstraints.HORIZONTAL,
330                                                  new Insets(2, 2, 1, 2), 0,
331                                                  0));
332         panelMappings.add(labelMap,
333                           new GridBagConstraints(0, 0, 1, 1, 0.2, 0.2,
334                                                  GridBagConstraints.EAST,
335                                                  GridBagConstraints.HORIZONTAL,
336                                                  new Insets(2, 2, 1, 2), 0,
337                                                  0));
338         panelCompile.setLayout(layoutCompile);
339         panelCompile.add(panelMappings,
340                          new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0,
341                                                 GridBagConstraints.CENTER,
342                                                 GridBagConstraints.HORIZONTAL,
343                                                 new Insets(2, 2, 2, 0), 5,
344                                                 5));
345         panelCompile.add(optionPanel,
346                          new GridBagConstraints(0, 3, 1, 1, 0.1, 0.1,
347                                                 GridBagConstraints.CENTER,
348                                                 GridBagConstraints.HORIZONTAL,
349                                                 new Insets(1, 2, 2, 2), 0,
350                                                 0));
351         panelTrace.add(checkPrintDocumentInfo,
352                        new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
353                                               GridBagConstraints.WEST,
354                                               GridBagConstraints.HORIZONTAL,
355                                               new Insets(0, 0, 0, 0), 0, 0));
356         panelTrace.add(checkPrintParseInfo,
357                        new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0,
358                                               GridBagConstraints.WEST,
359                                               GridBagConstraints.HORIZONTAL,
360                                               new Insets(2, 2, 2, 2), 5, 0));
361         panelTrace.add(checkPrintDOM,
362                        new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0,
363                                               GridBagConstraints.WEST,
364                                               GridBagConstraints.HORIZONTAL,
365                                               new Insets(2, 2, 2, 2), 5, 0));
366         panelTrace.add(checkVerbose,
367                        new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
368                                               GridBagConstraints.CENTER,
369                                               GridBagConstraints.NONE,
370                                               new Insets(2, 2, 2, 2), 5, 0));
371         panelTrace.add(checkPrintAccessorInfo,
372                        new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
373                                               GridBagConstraints.WEST,
374                                               GridBagConstraints.HORIZONTAL,
375                                               new Insets(2, 2, 2, 2), 5, 0));
376         tabPane.add(panelCompile, res.getString("Compile"));
377         tabPane.add(extensionPanel, res.getString("XMLC_Types"));
378         tabPane.add(panelTrace, res.getString("Trace"));
379         this.setLayout(layoutMain);
380         this.add(tabPane, BorderLayout.CENTER);
381         this.add(panelMake, BorderLayout.NORTH);
382     }
383
384     /**
385      * Method declaration
386      *
387      */

388     private void editProjectMap() {
389         MapDialog dialog =
390             new MapDialog(((JDialog) this.getTopLevelAncestor()),
391                           res.getString("Edit_Project_Map"), true);
392
393         dialog.setProject(getProject());
394         dialog.show();
395     }
396
397     private class LocalButtonListener implements ActionListener {
398         public void actionPerformed(ActionEvent event) {
399             Object JavaDoc source = event.getSource();
400
401             if (source == buttonMap) {
402                 editProjectMap();
403             }
404         }
405
406     }
407 }
408
Popular Tags