KickJava   Java API By Example, From Geeks To Geeks.

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


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.ButtonPanel;
28
29 // Standard imports
30
import java.awt.*;
31 import java.awt.event.ActionEvent JavaDoc;
32 import java.awt.event.ActionListener JavaDoc;
33 import java.beans.*;
34 import javax.swing.*;
35
36 //
37
public class TBWizardButtonPanel extends ButtonPanel {
38
39     //
40
private GridBagLayout layoutMain = null;
41     private JPanel panelFiller = null;
42     private JPanel panelLine;
43     private JButton buttonBack = null;
44     private JButton buttonNext = null;
45     private JButton buttonFinish = null;
46     private JButton buttonCancel = null;
47     private JButton buttonHelp = null;
48     private LocalButtonListener buttonListener = null;
49
50     public final static String JavaDoc[] getOptions() {
51         final String JavaDoc[] options = {
52             ButtonPanel.COMMAND_BACK, ButtonPanel.COMMAND_NEXT,
53             ButtonPanel.COMMAND_FINISH, ButtonPanel.COMMAND_CANCEL,
54             ButtonPanel.COMMAND_HELP
55         };
56
57         return options;
58     }
59
60     public TBWizardButtonPanel() {
61         super();
62         try {
63             jbInit();
64             pmInit();
65         } catch (Exception JavaDoc e) {
66             e.printStackTrace();
67         }
68     }
69
70     // override ButtonPanel
71
public void removeHelp() {
72         remove(buttonHelp);
73         invalidate();
74         doLayout();
75     }
76
77     //
78
//
79
private void pmInit() {
80         buttonListener = new LocalButtonListener();
81
82         //
83
buttonBack.addActionListener(buttonListener);
84         buttonNext.addActionListener(buttonListener);
85         buttonFinish.addActionListener(buttonListener);
86         buttonCancel.addActionListener(buttonListener);
87         buttonHelp.addActionListener(buttonListener);
88
89         //
90
buttonBack.setText(ButtonPanel.COMMAND_BACK);
91         buttonNext.setText(ButtonPanel.COMMAND_NEXT);
92         buttonFinish.setText(ButtonPanel.COMMAND_FINISH);
93         buttonCancel.setText(ButtonPanel.COMMAND_CANCEL);
94         buttonHelp.setText(ButtonPanel.COMMAND_HELP);
95
96         //
97
buttonBack.setActionCommand(buttonBack.getText());
98         buttonNext.setActionCommand(buttonNext.getText());
99         buttonFinish.setActionCommand(buttonFinish.getText());
100         buttonCancel.setActionCommand(buttonCancel.getText());
101         buttonHelp.setActionCommand(buttonHelp.getText());
102         buttonBack.setMnemonic('B');
103         buttonNext.setMnemonic('N');
104         buttonHelp.setMnemonic('H');
105         buttonFinish.setEnabled(false);
106         buttonBack.setEnabled(false);
107     }
108
109     private void jbInit() throws Exception JavaDoc {
110         layoutMain =
111             (GridBagLayout) Beans.instantiate(getClass().getClassLoader(),
112                                               GridBagLayout.class.getName());
113         panelLine = (JPanel) Beans.instantiate(getClass().getClassLoader(),
114                                                JPanel.class.getName());
115         panelFiller = (JPanel) Beans.instantiate(getClass().getClassLoader(),
116                                                  JPanel.class.getName());
117         buttonBack = (JButton) Beans.instantiate(getClass().getClassLoader(),
118                                                  JButton.class.getName());
119         buttonNext = (JButton) Beans.instantiate(getClass().getClassLoader(),
120                                                  JButton.class.getName());
121         buttonFinish =
122             (JButton) Beans.instantiate(getClass().getClassLoader(),
123                                         JButton.class.getName());
124         buttonCancel =
125             (JButton) Beans.instantiate(getClass().getClassLoader(),
126                                         JButton.class.getName());
127         buttonHelp = (JButton) Beans.instantiate(getClass().getClassLoader(),
128                                                  JButton.class.getName());
129         panelLine.setMinimumSize(new Dimension(5, 5));
130         panelLine.setPreferredSize(new Dimension(5, 5));
131         panelLine.setBorder(BorderFactory.createEtchedBorder());
132
133         buttonBack.setText("BACK");
134
135         // buttonBack.setEnabled(false);
136
buttonNext.setText("NEXT");
137         buttonFinish.setText("FINISH");
138
139         // buttonFinish.setEnabled(false);
140
buttonCancel.setText("CANCEL");
141         buttonHelp.setText("HELP");
142         this.setLayout(layoutMain);
143         this.add(panelLine, new GridBagConstraints(0, 0, 6, 1, 0.0, 0.0
144             ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1, 1), 0, 0));
145          this.add(panelFiller,
146                  new GridBagConstraints(0, 0, 1, 1, 0.1, 0.1,
147                                         GridBagConstraints.CENTER,
148                                         GridBagConstraints.BOTH,
149                                         new Insets(0, 0, 0, 0), 0, 0));
150         this.add(buttonBack, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0
151             ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0));
152         this.add(buttonNext, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0
153             ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0));
154         this.add(buttonFinish, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0
155             ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0));
156         this.add(buttonCancel, new GridBagConstraints(4, 1, 1, 1, 0.0, 0.0
157             ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0));
158         this.add(buttonHelp, new GridBagConstraints(5, 1, 1, 1, 0.0, 0.0
159             ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0));
160     }
161
162     private class LocalButtonListener implements ActionListener JavaDoc {
163
164         /**
165          * ActionListener implementation.
166          *
167          * @param event
168          * Event that triggered this listener.
169          *
170          */

171         public void actionPerformed(ActionEvent JavaDoc e) {
172             Object JavaDoc source = null;
173             ActionEvent JavaDoc event = null;
174
175             source = e.getSource();
176             if (source == buttonBack) {
177                 event = new ActionEvent JavaDoc(buttonBack, ButtonPanel.BACK,
178                                         buttonBack.getActionCommand());
179             } else if (source == buttonNext) {
180                 event = new ActionEvent JavaDoc(buttonNext, ButtonPanel.NEXT,
181                                         buttonNext.getActionCommand());
182             } else if (source == buttonFinish) {
183                 event = new ActionEvent JavaDoc(buttonFinish, ButtonPanel.FINISH,
184                                         buttonFinish.getActionCommand());
185             } else if (source == buttonCancel) {
186                 event = new ActionEvent JavaDoc(buttonCancel, ButtonPanel.CANCEL,
187                                         buttonCancel.getActionCommand());
188             } else if (source == buttonHelp) {
189                 event = new ActionEvent JavaDoc(buttonHelp, ButtonPanel.HELP,
190                                         buttonHelp.getActionCommand());
191             }
192             if (event != null) {
193                 notifyActionListeners(event);
194             }
195         }
196
197     }
198 }
199
Popular Tags