KickJava   Java API By Example, From Geeks To Geeks.

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


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.CardLayout JavaDoc;
31 import java.beans.Beans JavaDoc;
32 import java.util.Arrays JavaDoc;
33 import java.util.ArrayList JavaDoc;
34 import java.util.ResourceBundle JavaDoc;
35 import javax.swing.JPanel JavaDoc;
36 import javax.swing.JOptionPane JavaDoc;
37
38 //
39
public class TBWizardDeck extends JPanel JavaDoc {
40     static ResourceBundle JavaDoc res =
41         ResourceBundle.getBundle("org.enhydra.tool.common.Res"); // nores
42

43     //
44
private CardLayout JavaDoc cardLayout = null;
45     private int pageIndex = 0;
46     private TBWizardPage[] pages = new TBWizardPage[0];
47
48     public TBWizardDeck() {
49         try {
50             jbInit();
51         } catch (Exception JavaDoc e) {
52             e.printStackTrace();
53         }
54     }
55
56     /**
57      * Method declaration
58      *
59      */

60     public void next() {
61         if (!isLastPageShowing()) {
62             TBWizardPage currentPage = pages[pageIndex];
63             TBWizardPage nextPage = pages[pageIndex +1];
64
65             try {
66                 currentPage.validatePage();
67                 nextPage.preparePage();
68                 cardLayout.next(this);
69                 pageIndex++;
70             } catch (ToolException e) {
71                 JOptionPane.showMessageDialog(this, e.getMessage(),
72                                               res.getString("Validation_Error"),
73                                               JOptionPane.ERROR_MESSAGE);
74             }
75         }
76     }
77
78     //
79
protected TBWizardPage[] getPages() {
80         return pages;
81     }
82
83     public int getPageIndex() {
84         return pageIndex;
85     }
86
87     /**
88      * Method declaration
89      *
90      *
91      * @return
92      */

93     protected boolean isFirstPageShowing() {
94         boolean atFirst = (pageIndex == 0);
95
96         return (atFirst);
97     }
98
99     /**
100      * Method declaration
101      *
102      *
103      * @return
104      */

105     protected boolean isLastPageShowing() {
106         return (pageIndex == (pages.length - 1));
107     }
108
109     /**
110      * Method declaration
111      *
112      */

113     protected void back() {
114         if (!isFirstPageShowing()) {
115             cardLayout.previous(this);
116             pageIndex--;
117         }
118     }
119
120     /**
121      * Method declaration
122      *
123      *
124      * @param page
125      */

126     protected void addWizardPage(TBWizardPage page) {
127         ArrayList JavaDoc list = null;
128         this.add(page, (new String JavaDoc()) + pages.length);
129         list = new ArrayList JavaDoc(Arrays.asList(pages));
130         list.add(page);
131         list.trimToSize();
132         pages = new TBWizardPage[list.size()];
133         pages = (TBWizardPage[]) list.toArray(pages);
134         list.clear();
135     }
136
137     protected void removeWizardPage(TBWizardPage page) {
138         ArrayList JavaDoc list = null;
139         list = new ArrayList JavaDoc(Arrays.asList(pages));
140         if (list.contains(page)) {
141             remove(page);
142            list.remove(page);
143         }
144         list.trimToSize();
145         pages = new TBWizardPage[list.size()];
146         pages = (TBWizardPage[]) list.toArray(pages);
147         list.clear();
148     }
149
150
151     /**
152      * Method declaration
153      *
154      *
155      * @exception Exception
156      */

157     private void jbInit() throws Exception JavaDoc {
158         cardLayout =
159             (CardLayout JavaDoc) Beans.instantiate(getClass().getClassLoader(),
160                                            CardLayout JavaDoc.class.getName());
161         this.setLayout(cardLayout);
162     }
163
164 }
165
Popular Tags