KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > tool > archive > wizard > ArchiveSelectionPanel


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

24 package org.enhydra.tool.archive.wizard;
25
26 // ToolBox
27
import org.enhydra.tool.archive.ArchiveException;
28 import org.enhydra.tool.archive.JarPlan;
29 import org.enhydra.tool.common.PathHandle;
30
31 // JDK
32
import javax.swing.*;
33 import javax.swing.border.*;
34 import java.awt.event.ActionEvent JavaDoc;
35 import java.awt.event.ActionListener JavaDoc;
36 import java.awt.event.ItemEvent JavaDoc;
37 import java.awt.event.ItemListener JavaDoc;
38 import java.awt.*;
39 import java.beans.*;
40 import java.io.File JavaDoc;
41 import java.util.ResourceBundle JavaDoc;
42
43 /**
44  * This class defines the type of panel you can add to an
45  * OpenTool's BasicWizardPage or an CodeGenPage.
46  */

47 public class ArchiveSelectionPanel extends ArchivePanel {
48
49     //
50
transient private GridBagLayout layoutMain;
51     transient private BorderLayout layoutDescription;
52     transient private JComboBox comboArchive;
53     transient private JLabel labelArchive;
54     transient private JPanel panelDescription;
55     transient private JTextArea textDescription;
56     transient private LocalItemListener itemListener = null;
57     transient private ArchiveType selection = null;
58     transient private JPanel panelFiller;
59
60     /**
61      * Create an ArchivePanel for use in an OpenTool
62      * BasicWizardPage or an ArchivePage.
63      */

64     public ArchiveSelectionPanel() {
65         try {
66             jbInit();
67             pmInit();
68         } catch (Exception JavaDoc ex) {
69             ex.printStackTrace();
70         }
71     }
72
73     public void validatePlan() throws ArchiveException {
74
75         // no-op
76
}
77
78     public void readPlan(JarPlan plan) throws ArchiveException {
79
80         // no-op
81
}
82
83     public void writePlan(JarPlan plan) throws ArchiveException {
84
85         // no-op
86
}
87
88     /**
89      * Get the title to use on the current page.
90      *
91      * @return
92      * A string to place at the top of a CodeGen wizard panel.
93      */

94     public String JavaDoc getPageTitle() {
95         return "Archive Type";
96     }
97
98     /**
99      * Get the instructions for selecting a generator.
100      *
101      * @return
102      * A string to place below the page title.
103      */

104     public String JavaDoc getInstructions() {
105         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
106
107         buf.append("Choose an archive type and view a description of ");
108         buf.append("your selection.");
109         return buf.toString();
110     }
111
112     /**
113      * Get the type selected by the user.
114      *
115      * @return
116      * The archive type
117      */

118     public ArchiveType getSelection() {
119         return selection;
120     }
121
122     // /
123
// / PRIVATE METHODS
124
// /
125

126     /**
127      * Method declaration
128      *
129      *
130      * @exception Exception
131      */

132     private void jbInit() throws Exception JavaDoc {
133         panelDescription =
134             (JPanel) Beans.instantiate(getClass().getClassLoader(),
135                                        JPanel.class.getName());
136         labelArchive = (JLabel) Beans.instantiate(getClass().getClassLoader(),
137                                                   JLabel.class.getName());
138         textDescription =
139             (JTextArea) Beans.instantiate(getClass().getClassLoader(),
140                                           JTextArea.class.getName());
141         comboArchive =
142             (JComboBox) Beans.instantiate(getClass().getClassLoader(),
143                                           JComboBox.class.getName());
144         layoutMain =
145             (GridBagLayout) Beans.instantiate(getClass().getClassLoader(),
146                                               GridBagLayout.class.getName());
147         layoutDescription =
148             (BorderLayout) Beans.instantiate(getClass().getClassLoader(),
149                                              BorderLayout.class.getName());
150         panelFiller = (JPanel) Beans.instantiate(getClass().getClassLoader(),
151                                                  JPanel.class.getName());
152         labelArchive.setMaximumSize(new Dimension(80, 20));
153         labelArchive.setMinimumSize(new Dimension(80, 20));
154         labelArchive.setPreferredSize(new Dimension(80, 20));
155         labelArchive.setLabelFor(comboArchive);
156         labelArchive.setText("Archive type:");
157         textDescription.setDisabledTextColor(SystemColor.controlText);
158         textDescription.setBackground(SystemColor.text);
159         textDescription.setBounds(2, 2, 2, 2);
160         textDescription.setMargin(new Insets(5, 5, 5, 5));
161         textDescription.setEnabled(false);
162         textDescription.setEditable(false);
163         textDescription.setWrapStyleWord(true);
164         textDescription.setFont(labelArchive.getFont());
165         textDescription.setLineWrap(true);
166         panelDescription.setLayout(layoutDescription);
167         panelDescription.setBorder(BorderFactory.createEtchedBorder());
168         panelDescription.setMaximumSize(new Dimension(220, 70));
169         panelDescription.setMinimumSize(new Dimension(220, 70));
170         panelDescription.setPreferredSize(new Dimension(220, 70));
171         comboArchive.setMaximumSize(new Dimension(100, 21));
172         comboArchive.setMinimumSize(new Dimension(100, 21));
173         comboArchive.setPreferredSize(new Dimension(100, 21));
174         panelDescription.add(textDescription, BorderLayout.CENTER);
175         this.setLayout(layoutMain);
176         this.add(panelFiller,
177                  new GridBagConstraints(3, 0, 1, 1, 0.1, 0.1,
178                                         GridBagConstraints.CENTER,
179                                         GridBagConstraints.BOTH,
180                                         new Insets(0, 0, 0, 0), 0, 0));
181         this.add(comboArchive,
182                  new GridBagConstraints(1, 0, 2, 1, 0.5, 0.5,
183                                         GridBagConstraints.WEST,
184                                         GridBagConstraints.NONE,
185                                         new Insets(5, 5, 5, 5), 100, 0));
186         this.add(labelArchive,
187                  new GridBagConstraints(0, 0, 1, 1, 0.5, 0.5,
188                                         GridBagConstraints.WEST,
189                                         GridBagConstraints.NONE,
190                                         new Insets(5, 10, 5, 0), 60, 15));
191         this.add(panelDescription,
192                  new GridBagConstraints(0, 1, 4, 1, 0.5, 0.5,
193                                         GridBagConstraints.NORTHWEST,
194                                         GridBagConstraints.VERTICAL,
195                                         new Insets(5, 5, 5, 5), 150, 80));
196     }
197
198     private void pmInit() {
199         ArchiveType[] types = null;
200
201         types = ArchiveType.getAllTypes();
202         comboArchive.removeAllItems();
203         for (int i = 0; i < types.length; i++) {
204             comboArchive.addItem(types[i]);
205         }
206         if (types.length > 0) {
207             textDescription.setText(types[0].getDescription());
208             selection = types[0];
209         }
210         comboArchive.repaint();
211         itemListener = new LocalItemListener();
212         comboArchive.addItemListener(itemListener);
213     }
214
215     private class LocalItemListener implements ItemListener JavaDoc {
216         public void itemStateChanged(ItemEvent JavaDoc event) {
217             Object JavaDoc item = comboArchive.getSelectedItem();
218
219             if (item instanceof ArchiveType) {
220                 selection = (ArchiveType) item;
221                 System.setProperty("user.dir", getWorkingRoot());
222                 textDescription.setText(selection.getDescription());
223             } else {
224                 selection = null;
225                 textDescription.setText(new String JavaDoc());
226             }
227         }
228
229     }
230 }
231
Popular Tags