KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > adminGui > widget > ButtonPanel


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Library License version 1 published by ozone-db.org.
3
//
4
// The original code and portions created by SMB are
5
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
6
//
7
package org.ozoneDB.adminGui.widget;
8
9 import java.awt.Dimension JavaDoc;
10 import java.awt.GridBagConstraints JavaDoc;
11 import java.awt.GridBagLayout JavaDoc;
12 import java.awt.Insets JavaDoc;
13 import java.awt.event.ActionEvent JavaDoc;
14 import java.awt.event.ActionListener JavaDoc;
15 import javax.swing.JButton JavaDoc;
16 import javax.swing.JPanel JavaDoc;
17 import javax.swing.event.EventListenerList JavaDoc;
18
19
20 //#############################################################################
21
/**
22  * This class creates the button panel that can control up to 4 account defined
23  * buttons. Usually used at the bottom of the forms.
24  *
25  * @author <p align=center>Ibsen Ramos-Bonilla
26  * <br>Copyright &copy 1997-@year@ by SMB GmbH. All Rights Reserved.</p>
27  *
28  * @version 1.0
29  */

30 //#############################################################################
31

32 public class ButtonPanel extends JPanel JavaDoc {
33
34     /** The listener list. */
35     protected EventListenerList JavaDoc listenerList = new EventListenerList JavaDoc();
36
37
38     /**
39      * Default constructor not used.
40      */

41     private ButtonPanel() {
42     }
43
44     /**
45      * Overloaded constructor creates the panel buttons.
46      *
47      * @param buttonName - an array of button names.
48      */

49     public ButtonPanel(String JavaDoc[] buttonName) {
50         super();
51
52         //init
53
if (buttonName != null)
54             init(buttonName);
55     }
56
57     /**
58      * This method initializes the button panel.
59      *
60      * @param buttonName - an array of button names.
61      */

62     private void init(final String JavaDoc[] buttonName) {
63
64         //add buttons
65
this.setLayout(new GridBagLayout JavaDoc());
66
67         //create the buttons
68
JButton JavaDoc[] button = new JButton JavaDoc[buttonName.length];
69
70         //set buttons
71
for (int i = 0; i < buttonName.length; i++) {
72             final String JavaDoc name = buttonName[i].toString();
73             button[i] = new JButton JavaDoc(name);
74             button[i].setPreferredSize(new Dimension JavaDoc(80, 27));
75             button[i].setDefaultCapable(true);
76
77             button[i].addActionListener(new ActionListener JavaDoc() {
78                 public void actionPerformed(ActionEvent JavaDoc e) {
79                     fireExecute(name);
80                 }
81             });
82
83             this.add(button[i],
84                     new GridBagConstraints JavaDoc(i, 0, 1, 1, 0.0, 0.0,
85                             GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
86                             new Insets JavaDoc(10, 10, 15, 10), 0, 0));
87         }
88     }
89
90     /**
91      * This method allows classes to register for connection events.
92      *
93      * @param listener - a connection listener.
94      */

95     public void addConnectionListener(ButtonPanelListener listener) {
96         listenerList.add(ButtonPanelListener.class, listener);
97     }
98
99     /**
100      * This method allows classes to unregister from connection events.
101      *
102      * @param listener - a connection listener.
103      */

104     public void removeConnectionListener(ButtonPanelListener listener) {
105         listenerList.remove(ButtonPanelListener.class, listener);
106     }
107
108     /**
109      * This method notifies all when the login process is fired.
110      *
111      * @param buttonName - the name associated with the button.
112      */

113     private void fireExecute(String JavaDoc buttonName) {
114         Object JavaDoc[] listeners = listenerList.getListenerList();
115
116         //each listener occupies two elements - the first is the listener
117
//class, and the second is the listener instance
118
for (int i = 0; i < listeners.length; i += 2) {
119             if (listeners[i] == ButtonPanelListener.class) {
120                 ((ButtonPanelListener) listeners[i + 1]).buttonExecute(buttonName);
121             }
122         }
123     }
124
125 } //--------------------------------- E O F -----------------------------------
126
Popular Tags