KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > tool > common > wizard > TBWizardPage


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.common.wizard;
25
26 // ToolBox imports
27
import org.enhydra.tool.common.ToolException;
28
29 // Standard imports
30
import java.awt.*;
31 import java.beans.*;
32 import java.util.ArrayList JavaDoc;
33 import javax.swing.*;
34
35 /**
36  * The CodeGenPage is a panel that you can add to a WizardDialog. It displays
37  * a page title, instructions and a CodeGenPanel.
38  * <P><I>
39  * This class is used when creating a standalone wizard. Use the
40  * OpenTools BasicWizardPage when developing JBuilder add-ins.
41  * </I></P>
42  */

43 public class TBWizardPage extends JPanel {
44     transient private BorderLayout layoutCustom;
45     transient private BorderLayout layoutMain;
46     transient private GridBagLayout layoutWizard;
47     transient private JLabel image;
48     transient private JLabel pageTitle;
49     transient private JPanel panelCustom;
50     transient private JPanel panelWizard;
51     transient private JTextArea instructions;
52     transient private TBWizardPanel wizardPanel = null;
53
54     /**
55      * Create a ToolBoxWizardPage.
56      */

57     public TBWizardPage() {
58         try {
59             jbInit();
60             pmInit();
61         } catch (Exception JavaDoc e) {
62             e.printStackTrace();
63         }
64     }
65
66     public void preparePage() {}
67
68     /**
69      * Get the instructions that display in a normal font under the page title.
70      */

71     public String JavaDoc getInstructions() {
72         return instructions.getText();
73     }
74
75     /**
76      * Set the instructions that display in a normal font under the page title.
77      * The instructions will word wrap.
78      *
79      * @param s
80      * A paragraph to display in a read only word wrapped text area
81      */

82     public void setInstructions(String JavaDoc s) {
83         instructions.setText(s);
84     }
85
86     /**
87      * Get the text that appears in bold at the top of the page.
88      */

89     public String JavaDoc getPageTitle() {
90         return pageTitle.getText();
91     }
92
93     /**
94      * Set the text that appears in bold at the top of the page.
95      */

96     public void setPageTitle(String JavaDoc s) {
97         pageTitle.setText(s);
98     }
99
100     /**
101      * Add a CodeGenPanel to a panel below the instruction text.
102      *
103      * @param panel
104      * The CodeGenPanel containing swing controls for gathering
105      * option values.
106      */

107     public void add(TBWizardPanel panel) {
108         wizardPanel = panel;
109         panelCustom.add(wizardPanel, BorderLayout.CENTER);
110     }
111
112     public TBWizardPanel getWizardPanel() {
113         return wizardPanel;
114     }
115
116     public void validatePage() throws ToolException {}
117
118     //
119
protected Component[] getChildPanelComponents() {
120         Component[] comps = new Component[0];
121         ArrayList JavaDoc list = new ArrayList JavaDoc();
122         list = addAllChildren(wizardPanel, list);
123         list.trimToSize();
124         comps = new Component[list.size()];
125         comps = (Component[]) list.toArray(comps);
126         list.clear();
127         return comps;
128     }
129
130     private ArrayList JavaDoc addAllChildren(Container container, ArrayList JavaDoc list) {
131         Component[] children = new Component[0];
132
133         children = container.getComponents();
134         for (int i = 0; i < children.length; i++) {
135             list.add(children[i]);
136             if (children[i] instanceof Container) {
137                 list = addAllChildren((Container) children[i], list);
138             }
139         }
140         return list;
141     }
142
143     // /
144
// / PRIVATE METHODS
145
// /
146

147     /**
148      * Do construtor operations that are not generated by
149      * the JBuilder designer.
150      */

151     private void pmInit() {
152         image.setText(new String JavaDoc());
153     }
154
155     /**
156      * UI code generated by JBuilder.
157      * <P><I>Do not modify the signature of this method.</I></P>
158      */

159     private void jbInit() throws Exception JavaDoc {
160         panelWizard = (JPanel) Beans.instantiate(getClass().getClassLoader(),
161                                                  JPanel.class.getName());
162         layoutWizard =
163             (GridBagLayout) Beans.instantiate(getClass().getClassLoader(),
164                                               GridBagLayout.class.getName());
165         pageTitle = (JLabel) Beans.instantiate(getClass().getClassLoader(),
166                                                JLabel.class.getName());
167         instructions =
168             (JTextArea) Beans.instantiate(getClass().getClassLoader(),
169                                           JTextArea.class.getName());
170         panelCustom = (JPanel) Beans.instantiate(getClass().getClassLoader(),
171                                                  JPanel.class.getName());
172         layoutCustom =
173             (BorderLayout) Beans.instantiate(getClass().getClassLoader(),
174                                              BorderLayout.class.getName());
175         layoutMain =
176             (BorderLayout) Beans.instantiate(getClass().getClassLoader(),
177                                              BorderLayout.class.getName());
178         image = (JLabel) Beans.instantiate(getClass().getClassLoader(),
179                                            JLabel.class.getName());
180         panelWizard.setLayout(layoutWizard);
181         pageTitle.setFont(new Font(pageTitle.getFont().getName(), 1, 12));
182         pageTitle.setText("PAGE TITLE"); // nores
183
instructions.setLineWrap(true);
184         instructions.setWrapStyleWord(true);
185         instructions.setDisabledTextColor(SystemColor.windowText);
186         instructions.setBackground(SystemColor.inactiveCaptionBorder);
187         instructions.setEnabled(false);
188         instructions.setText("INSTRUCTIONS"); // nores
189
instructions.setEditable(false);
190         instructions.setFont(new Font(pageTitle.getFont().getName(), 0, 12));
191         panelCustom.setLayout(layoutCustom);
192         panelWizard.add(pageTitle,
193                         new GridBagConstraints(0, 0, 1, 1, 0.1, 0.1,
194                                                GridBagConstraints.CENTER,
195                                                GridBagConstraints.BOTH,
196                                                new Insets(2, 5, 2, 5), 5, 5));
197         panelWizard.add(instructions,
198                         new GridBagConstraints(0, 1, 1, 1, 0.2, 0.2,
199                                                GridBagConstraints.CENTER,
200                                                GridBagConstraints.BOTH,
201                                                new Insets(2, 5, 2, 5), 5, 5));
202         panelWizard.add(panelCustom,
203                         new GridBagConstraints(0, 2, 1, 2, 0.7, 0.7,
204                                                GridBagConstraints.CENTER,
205                                                GridBagConstraints.BOTH,
206                                                new Insets(2, 5, 2, 5), 5, 5));
207         this.setLayout(layoutMain);
208         this.add(image, BorderLayout.WEST);
209         this.add(panelWizard, BorderLayout.CENTER);
210     }
211
212 }
213
Popular Tags