KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jahia > opentools > advancedapprunner > AdvancedAppRunnerPropertyPage


1 package com.jahia.opentools.advancedapprunner;
2
3 import java.util.Map JavaDoc;
4
5 import java.awt.Dimension JavaDoc;
6 import java.awt.GridBagConstraints JavaDoc;
7 import java.awt.GridBagLayout JavaDoc;
8 import java.awt.Insets JavaDoc;
9 import java.awt.event.ActionEvent JavaDoc;
10 import javax.swing.JButton JavaDoc;
11 import javax.swing.JLabel JavaDoc;
12 import javax.swing.JTextField JavaDoc;
13 import javax.swing.event.ChangeEvent JavaDoc;
14 import javax.swing.event.ChangeListener JavaDoc;
15
16 import com.borland.primetime.help.HelpTopic;
17 import com.borland.primetime.help.ZipHelpBook;
18 import com.borland.primetime.help.ZipHelpTopic;
19 import com.borland.primetime.node.Project;
20 import com.borland.primetime.properties.GlobalArrayProperty;
21 import com.borland.primetime.properties.PropertyPage;
22
23 /**
24  * <p>Title: Property page for the Advanced Application runner</p>
25  * <p>Description: </p>
26  * <p>Copyright: Copyright (c) 2004</p>
27  * <p>Company: </p>
28  * @author Serge Huber (shuber@jahia.com)
29  * @author Keith Wood (kbwood@compuserve.com)
30  * @version 1.0
31  */

32 public class AdvancedAppRunnerPropertyPage extends PropertyPage implements
33     ChangeListener JavaDoc {
34
35     public static final String JavaDoc CATEGORY =
36         "com.jahia.opentools.advancedapprunner";
37     public static final GlobalArrayProperty DEFAULT_DIRS =
38         new GlobalArrayProperty(CATEGORY, "defaultDirs");
39
40     private GridBagLayout JavaDoc gridBagLayout = new GridBagLayout JavaDoc();
41     private JLabel JavaDoc mainClassNameLabel = new JLabel JavaDoc();
42     private JTextField JavaDoc mainClassNameField = new JTextField JavaDoc();
43     private JLabel JavaDoc vmParametersLabel = new JLabel JavaDoc();
44     private JTextField JavaDoc vmparamsField = new JTextField JavaDoc();
45     private JLabel JavaDoc appParamsLabel = new JLabel JavaDoc();
46     private JTextField JavaDoc jbparamsField = new JTextField JavaDoc();
47     private JLabel JavaDoc classPathLabel = new JLabel JavaDoc();
48     private JButton JavaDoc loadButton = new JButton JavaDoc();
49     private JButton JavaDoc saveButton = new JButton JavaDoc();
50     private ClassPathListPanel classPathList = new ClassPathListPanel();
51
52     private Map JavaDoc propertyMap = null;
53
54     public AdvancedAppRunnerPropertyPage(Project project, Map JavaDoc propertyMap) {
55         this.propertyMap = propertyMap;
56         try {
57             jbInit();
58         } catch (Exception JavaDoc e) {
59             e.printStackTrace();
60         }
61     }
62
63     /**
64      * UI initialisation.
65      */

66     private void jbInit() throws Exception JavaDoc {
67         this.setLayout(gridBagLayout);
68         mainClassNameLabel.setDisplayedMnemonic('M');
69         mainClassNameLabel.setLabelFor(mainClassNameField);
70         mainClassNameLabel.setText("Main Class name:");
71         mainClassNameField.setToolTipText("Fully qualified main class name");
72         vmParametersLabel.setDisplayedMnemonic('V');
73         vmParametersLabel.setLabelFor(vmparamsField);
74         vmParametersLabel.setText("VM parameters:");
75         vmparamsField.setToolTipText("Parameters for the JVM");
76         appParamsLabel.setDisplayedMnemonic('J');
77         appParamsLabel.setLabelFor(jbparamsField);
78         appParamsLabel.setText("Application parameters:");
79         jbparamsField.setToolTipText("Parameters for the application");
80         classPathLabel.setDisplayedMnemonic('O');
81         classPathLabel.setLabelFor(classPathList);
82         classPathLabel.setText("Class path (add class directories and JARs here) :");
83         loadButton.setMinimumSize(new Dimension JavaDoc(53, 21));
84         loadButton.setPreferredSize(new Dimension JavaDoc(53, 21));
85         loadButton.setToolTipText("Reload directory list from defaults");
86         loadButton.setActionCommand("Load");
87         loadButton.setMargin(new Insets JavaDoc(2, 4, 2, 4));
88         loadButton.setMnemonic('L');
89         loadButton.setText("Load");
90         loadButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
91             public void actionPerformed(ActionEvent JavaDoc e) {
92                 loadButton_actionPerformed(e);
93             }
94         });
95         loadButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
96             public void actionPerformed(ActionEvent JavaDoc e) {
97                 loadButton_actionPerformed(e);
98             }
99         });
100         saveButton.setMinimumSize(new Dimension JavaDoc(53, 21));
101         saveButton.setPreferredSize(new Dimension JavaDoc(53, 21));
102         saveButton.setToolTipText("Save directory list as defaults");
103         saveButton.setActionCommand("Save");
104         saveButton.setMargin(new Insets JavaDoc(2, 4, 2, 4));
105         saveButton.setMnemonic('S');
106         saveButton.setText("Save");
107         saveButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
108             public void actionPerformed(ActionEvent JavaDoc e) {
109                 saveButton_actionPerformed(e);
110             }
111         });
112         this.add(mainClassNameLabel, new GridBagConstraints JavaDoc(0, 0, 2, 1, 0.0, 0.0
113                                                  , GridBagConstraints.CENTER,
114                                                  GridBagConstraints.HORIZONTAL,
115                                                  new Insets JavaDoc(0, 4, 0, 4), 0, 0));
116         this.add(mainClassNameField,
117                  new GridBagConstraints JavaDoc(0, 1, 3, 1, 0.0, 0.0
118                                         , GridBagConstraints.WEST,
119                                         GridBagConstraints.HORIZONTAL,
120                                         new Insets JavaDoc(0, 4, 0, 4), 0, 0));
121
122         this.add(vmParametersLabel, new GridBagConstraints JavaDoc(0, 2, 2, 1, 0.0, 0.0
123                                                  , GridBagConstraints.CENTER,
124                                                  GridBagConstraints.HORIZONTAL,
125                                                  new Insets JavaDoc(0, 4, 0, 4), 0, 0));
126         this.add(vmparamsField, new GridBagConstraints JavaDoc(0, 3, 3, 1, 0.0, 0.0
127             , GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
128             new Insets JavaDoc(0, 4, 0, 4), 0, 0));
129
130         this.add(appParamsLabel, new GridBagConstraints JavaDoc(0, 4, 2, 1, 0.0, 0.0
131                                                  , GridBagConstraints.CENTER,
132                                                  GridBagConstraints.HORIZONTAL,
133                                                  new Insets JavaDoc(4, 4, 0, 4), 0, 0));
134         this.add(jbparamsField, new GridBagConstraints JavaDoc(0, 5, 3, 1, 0.0, 0.0
135             , GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
136             new Insets JavaDoc(0, 4, 0, 4), 0, 0));
137
138         this.add(classPathLabel, new GridBagConstraints JavaDoc(0, 6, 1, 1, 1.0, 0.0
139                                                  , GridBagConstraints.CENTER,
140                                                  GridBagConstraints.HORIZONTAL,
141                                                  new Insets JavaDoc(4, 4, 4, 4), 0, 0));
142         this.add(classPathList, new GridBagConstraints JavaDoc(0, 7, 3, 1, 1.0, 1.0
143                                                  , GridBagConstraints.CENTER,
144                                                  GridBagConstraints.BOTH,
145                                                  new Insets JavaDoc(0, 0, 0, 0), 0, 0));
146         this.add(loadButton, new GridBagConstraints JavaDoc(1, 6, 1, 1, 0.0, 0.0
147             , GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
148             new Insets JavaDoc(4, 0, 0, 0), 0, 0));
149         this.add(saveButton, new GridBagConstraints JavaDoc(2, 6, 1, 1, 0.0, 0.0
150             , GridBagConstraints.CENTER, GridBagConstraints.NONE,
151             new Insets JavaDoc(4, 4, 0, 4), 0, 0));
152         disEnableButtons();
153     }
154
155     /**
156      * Disable/enable buttons depending on current state.
157      */

158     private void disEnableButtons() {
159         loadButton.setEnabled(DEFAULT_DIRS.getValues().length > 0);
160         saveButton.setEnabled(classPathList.getList().size() > 0);
161     }
162
163     /**
164      * Respond to changes in the directory list.
165      */

166     public void stateChanged(ChangeEvent JavaDoc e) {
167         disEnableButtons();
168     }
169
170     /**
171      * Load the list of default directories.
172      */

173     void loadButton_actionPerformed(ActionEvent JavaDoc e) {
174         loadDirectories(DEFAULT_DIRS.getValues());
175         disEnableButtons();
176     }
177
178     /**
179      * Save the list of default directories.
180      */

181     void saveButton_actionPerformed(ActionEvent JavaDoc e) {
182         DEFAULT_DIRS.setValues(saveDirectories());
183     }
184
185     /**
186      * Load the properties into the UI.
187      */

188     public void readProperties() {
189         mainClassNameField.setText(AdvancedAppRunner.MAIN_CLASS.getValue(
190             propertyMap));
191         vmparamsField.setText(AdvancedAppRunner.VM_PARAMS.getValue(propertyMap));
192         jbparamsField.setText(AdvancedAppRunner.JB_PARAMS.getValue(propertyMap));
193         loadDirectories(AdvancedAppRunner.OTHER_DIRS.getValues(propertyMap));
194         disEnableButtons();
195     }
196
197     /**
198      * Load the list of directories into the UI.
199      *
200      * @param dirs the list of directories to load
201      */

202     public void loadDirectories(String JavaDoc[] dirs) {
203         classPathList.clear();
204         for (int index = 0; index < dirs.length; index++) {
205             classPathList.addListElement(dirs[index]);
206         }
207     }
208
209     /**
210      * Save the properties from the UI.
211      */

212     public void writeProperties() {
213         AdvancedAppRunner.MAIN_CLASS.setValue(propertyMap,
214                                               mainClassNameField.getText());
215         AdvancedAppRunner.VM_PARAMS.setValue(propertyMap, vmparamsField.getText());
216         AdvancedAppRunner.JB_PARAMS.setValue(propertyMap, jbparamsField.getText());
217         AdvancedAppRunner.OTHER_DIRS.setValues(propertyMap, saveDirectories());
218     }
219
220     /**
221      * Save the list of directories from the UI.
222      *
223      * @return the list of directories to save
224      */

225     public String JavaDoc[] saveDirectories() {
226         String JavaDoc[] dirs = new String JavaDoc[classPathList.getList().size()];
227         for (int index = 0; index < dirs.length; index++) {
228             dirs[index] = (String JavaDoc) classPathList.getList().get(index);
229         }
230         return dirs;
231     }
232
233     /**
234      * Provide help for this page.
235      */

236     public HelpTopic getHelpTopic() {
237         return new ZipHelpTopic(new ZipHelpBook("advancedapprunner-doc.jar"),
238                                 "AdvancedAppRunner.html");
239     }
240 }
241
Popular Tags