KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > tool > common > ButtonPanel


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;
25
26 // Standard imports
27
import java.awt.event.ActionEvent JavaDoc;
28 import java.awt.event.ActionListener JavaDoc;
29 import java.util.ArrayList JavaDoc;
30 import java.util.Arrays JavaDoc;
31 import java.util.ResourceBundle JavaDoc;
32 import javax.swing.AbstractButton JavaDoc;
33 import javax.swing.JPanel JavaDoc;
34 import java.awt.*;
35 import java.beans.*;
36
37 //
38
public class ButtonPanel extends JPanel JavaDoc {
39     public static final int BACK = 0;
40     public static final int NEXT = 1;
41     public static final int DEPLOY = 2;
42     public static final int HELP = 3;
43     public static final int ABOUT = 4;
44     public static final int CLOSE = 5;
45     public static final int COMPILE = 6;
46     public static final int CANCEL = 7;
47     public static final int FINISH = 7;
48     public static final int GENERATE = 8;
49
50     //
51
public static ResourceBundle JavaDoc res =
52         ResourceBundle.getBundle("org.enhydra.tool.common.Res"); // nores
53

54     //
55
public static final String JavaDoc COMMAND_BACK = res.getString("_Back");
56     public static final String JavaDoc COMMAND_NEXT = res.getString("Next_");
57     public static final String JavaDoc COMMAND_DEPLOY = res.getString("Deploy");
58     public static final String JavaDoc COMMAND_HELP = res.getString("Help");
59     public static final String JavaDoc COMMAND_ABOUT = res.getString("About_");
60     public static final String JavaDoc COMMAND_CLOSE = res.getString("Close");
61     public static final String JavaDoc COMMAND_COMPILE = res.getString("Compile");
62     public static final String JavaDoc COMMAND_CANCEL = res.getString("Cancel");
63     public static final String JavaDoc COMMAND_FINISH = res.getString("Finish");
64     public static final String JavaDoc COMMAND_GENERATE = res.getString("Generate");
65
66     //
67
private ActionListener JavaDoc[] actionListeners = new ActionListener JavaDoc[0];
68     private GridBagLayout layoutDefault;
69
70     public static Component findButton(Container container, String JavaDoc command) {
71         Component[] children = null;
72         Component button = null;
73
74         if (container == null) {
75             children = new Component[0];
76         } else {
77             children = container.getComponents();
78         }
79         for (int i = 0; i < children.length; i++) {
80             if (children[i] instanceof AbstractButton JavaDoc) {
81                 AbstractButton JavaDoc suspect = null;
82
83                 suspect = (AbstractButton JavaDoc) children[i];
84                 if (suspect.getActionCommand().equals(command)) {
85                     button = suspect;
86                 }
87             } else if (children[i] instanceof Button JavaDoc) {
88                 Button JavaDoc suspect = null;
89
90                 suspect = (Button JavaDoc) children[i];
91                 if (suspect.getActionCommand().equals(command)) {
92                     button = suspect;
93                 }
94             } else if (children[i] instanceof Container) {
95                 button = findButton((Container) children[i], command);
96             }
97             if (button != null) {
98                 break;
99             }
100         }
101         return button;
102     }
103
104     public ButtonPanel() {
105         try {
106             jbInit();
107         } catch (Exception JavaDoc e) {
108             e.printStackTrace();
109         }
110     }
111
112     public Window getWindow() {
113         return (Window) getTopLevelAncestor();
114     }
115
116     public void removeHelp() {}
117
118     public void clearAll() {
119         removeAll();
120         actionListeners = new ActionListener JavaDoc[0];
121     }
122
123     public synchronized void addActionListener(ActionListener JavaDoc l) {
124         ArrayList JavaDoc list = null;
125
126         list = new ArrayList JavaDoc(Arrays.asList(actionListeners));
127         if (!list.contains(l)) {
128             list.add(l);
129         }
130         list.trimToSize();
131         actionListeners = new ActionListener JavaDoc[list.size()];
132         actionListeners = (ActionListener JavaDoc[]) list.toArray(actionListeners);
133         list.clear();
134     }
135
136     public synchronized void removeActionListener(ActionListener JavaDoc l) {
137         ArrayList JavaDoc list = null;
138
139         list = new ArrayList JavaDoc(Arrays.asList(actionListeners));
140         if (list.contains(l)) {
141             list.remove(l);
142         }
143         list.trimToSize();
144         actionListeners = new ActionListener JavaDoc[list.size()];
145         actionListeners = (ActionListener JavaDoc[]) list.toArray(actionListeners);
146         list.clear();
147     }
148
149     public void notifyActionListeners(ActionEvent JavaDoc event) {
150         for (int i = 0; i < actionListeners.length; i++) {
151             actionListeners[i].actionPerformed(event);
152         }
153     }
154
155     private void jbInit() throws Exception JavaDoc {
156         layoutDefault =
157             (GridBagLayout) Beans.instantiate(getClass().getClassLoader(),
158                                               GridBagLayout.class.getName());
159         this.setLayout(layoutDefault);
160     }
161
162 }
163
Popular Tags