KickJava   Java API By Example, From Geeks To Geeks.

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


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.InnerPanel;
28
29 // Standard imports
30
import java.awt.*;
31 import javax.swing.*;
32 import java.beans.Beans JavaDoc;
33 //
34
public class TBWizardInnerPanel extends InnerPanel {
35     private final String JavaDoc FILE_WIZARD_JPG =
36         "org/enhydra/tool/common/media/lutris/otterwizard.jpg"; // nores
37
private BorderLayout layoutImage;
38     private boolean showImage = true;
39     private GridBagLayout layoutMain = null;
40     private JPanel panelImage;
41     private JLabel labelImage;
42     private TBWizardDeck deck = null;
43
44     public TBWizardInnerPanel() {
45         try {
46             jbInit();
47             pmInit();
48         } catch (Exception JavaDoc ex) {
49             ex.printStackTrace();
50         }
51     }
52
53     public TBWizardDeck getDeck() {
54         return deck;
55     }
56
57     public void setDeck(TBWizardDeck d) {
58         Component[] comps = new Component[0];
59
60         deck = d;
61         deck.setMinimumSize(new Dimension(100, 100));
62         deck.setPreferredSize(new Dimension(100, 100));
63         comps = getComponents();
64         for (int i = 0; i < comps.length; i++) {
65             if (comps[i] instanceof TBWizardDeck) {
66                 remove(comps[i]);
67             }
68         }
69         this.add(deck,
70             new GridBagConstraints(1, 0, 1, 1, 0.9, 0.9,
71                                    GridBagConstraints.CENTER,
72                                    GridBagConstraints.BOTH,
73                                    new Insets(2, 2, 2, 2), 0, 0));
74
75     }
76
77     public void setLargeIcon(Icon icon) {
78         if (icon == null) {
79             panelImage.setVisible(false);
80             labelImage.setIcon(null);
81         } else {
82             panelImage.setVisible(true);
83             labelImage.setText(new String JavaDoc());
84             labelImage.setIcon(icon);
85         }
86     }
87
88     public Icon getLargeIcon() {
89         return labelImage.getIcon();
90     }
91
92     // override InnerPanel
93
public void save() {
94        // do nothing on purpose
95
}
96
97
98     // override InnerPanel
99
protected Component[] getFirstFocusComponents() {
100         Component[] comps = new Component[0];
101         TBWizardPage pageOne = null;
102         if (getDeck() == null) {
103           comps = super.getFirstFocusComponents();
104         } else if (getDeck().getPages().length > 0) {
105           pageOne = getDeck().getPages()[0];
106           comps = pageOne.getChildPanelComponents();
107         } else {
108           comps = super.getFirstFocusComponents();
109         }
110         return comps;
111     }
112
113
114     /**
115      * Add a page to the wizard.
116      *
117      * @param page
118      * A panel that contains swing controls that
119      * are specific to the current wizard.
120      */

121     public void addWizardPage(TBWizardPage page) {
122         deck.addWizardPage(page);
123     }
124
125     private void jbInit() throws Exception JavaDoc {
126         layoutMain =
127             (GridBagLayout) Beans.instantiate(getClass().getClassLoader(),
128                                               GridBagLayout.class.getName());
129         deck = (TBWizardDeck) Beans.instantiate(getClass().getClassLoader(),
130                                                 TBWizardDeck.class.getName());
131         panelImage = (JPanel) Beans.instantiate(getClass().getClassLoader(),
132                                                 JPanel.class.getName());
133         layoutImage =
134             (BorderLayout) Beans.instantiate(getClass().getClassLoader(),
135                                              BorderLayout.class.getName());
136         labelImage = (JLabel) Beans.instantiate(getClass().getClassLoader(),
137                                                 JLabel.class.getName());
138         panelImage.setLayout(layoutImage);
139         panelImage.add(labelImage, BorderLayout.CENTER);
140         this.setLayout(layoutMain);
141         this.add(panelImage,
142                  new GridBagConstraints(0, 0, 1, 1, 0.1, 0.1,
143                                         GridBagConstraints.CENTER,
144                                         GridBagConstraints.NONE,
145                                         new Insets(2, 2, 2, 2), 0, 0));
146         this.add(deck,
147             new GridBagConstraints(1, 0, 1, 1, 0.9, 0.9,
148                                    GridBagConstraints.CENTER,
149                                    GridBagConstraints.BOTH,
150                                    new Insets(2, 2, 2, 2), 0, 0));
151
152     }
153
154     private void pmInit() {
155         setDeck(deck);
156         ImageIcon image = null;
157         try {
158             //dacha&strale
159
image = new ImageIcon(this.getClass().getClassLoader().getResource(FILE_WIZARD_JPG));
160 // image =
161
// new ImageIcon(ClassLoader.getSystemResource(FILE_WIZARD_JPG));
162
//end d&s
163
} catch (NullPointerException JavaDoc e) {
164             image = null;
165         }
166         setLargeIcon(image);
167     }
168
169 }
170
Popular Tags