KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > common > xmlc > XMLCButtonPanel


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  * Paul Mahar
21  *
22  */

23 package org.enhydra.kelp.common.xmlc;
24
25 // ToolBox imports
26
import org.enhydra.tool.common.ButtonPanel;
27
28 // Standard imports
29
import java.awt.*;
30 import java.awt.event.ActionEvent JavaDoc;
31 import java.awt.event.ActionListener JavaDoc;
32 import java.beans.*;
33 import javax.swing.*;
34
35 //
36
public class XMLCButtonPanel extends ButtonPanel {
37
38     //
39
private GridBagLayout layoutMain;
40     private JButton buttonCompile = null;
41     private JButton buttonClose = null;
42     private JButton buttonHelp = null;
43     private JButton buttonAbout = null;
44     private JPanel panelFiller = null;
45     private LocalButtonListener buttonListener = null;
46
47     public final static String JavaDoc[] getOptions() {
48         final String JavaDoc[] options = {
49             ButtonPanel.COMMAND_COMPILE, ButtonPanel.COMMAND_CLOSE,
50             ButtonPanel.COMMAND_HELP, ButtonPanel.COMMAND_ABOUT
51         };
52
53         return options;
54     }
55
56     public XMLCButtonPanel() {
57         try {
58             jbInit();
59             pmInit();
60         } catch (Exception JavaDoc e) {
61             e.printStackTrace();
62         }
63     }
64
65     // override ButtonPanel
66
public void removeHelp() {
67         remove(buttonHelp);
68         invalidate();
69         doLayout();
70     }
71
72     //
73
//
74
private void pmInit() {
75         buttonListener = new LocalButtonListener();
76         buttonCompile.addActionListener(buttonListener);
77         buttonClose.addActionListener(buttonListener);
78         buttonAbout.addActionListener(buttonListener);
79         buttonHelp.addActionListener(buttonListener);
80         buttonCompile.setText(ButtonPanel.COMMAND_COMPILE);
81         buttonClose.setText(ButtonPanel.COMMAND_CLOSE);
82         buttonAbout.setText(ButtonPanel.COMMAND_ABOUT);
83         buttonHelp.setText(ButtonPanel.COMMAND_HELP);
84
85         //
86
buttonCompile.setActionCommand(buttonCompile.getText());
87         buttonClose.setActionCommand(buttonClose.getText());
88         buttonAbout.setActionCommand(buttonAbout.getText());
89         buttonHelp.setActionCommand(buttonHelp.getText());
90     }
91
92     private void jbInit() throws Exception JavaDoc {
93         layoutMain =
94             (GridBagLayout) Beans.instantiate(getClass().getClassLoader(),
95                                               GridBagLayout.class.getName());
96         buttonCompile =
97             (JButton) Beans.instantiate(getClass().getClassLoader(),
98                                         JButton.class.getName());
99         buttonClose = (JButton) Beans.instantiate(getClass().getClassLoader(),
100                                                   JButton.class.getName());
101         buttonAbout = (JButton) Beans.instantiate(getClass().getClassLoader(),
102                                                   JButton.class.getName());
103         buttonHelp = (JButton) Beans.instantiate(getClass().getClassLoader(),
104                                                  JButton.class.getName());
105         panelFiller = (JPanel) Beans.instantiate(getClass().getClassLoader(),
106                                                  JPanel.class.getName());
107         buttonCompile.setText("COMPILE");
108         buttonCompile.setEnabled(false);
109         buttonClose.setText("CLOSE");
110         buttonAbout.setText("ABOUT");
111         buttonHelp.setText("HELP");
112         this.setLayout(layoutMain);
113         this.add(buttonCompile,
114                  new GridBagConstraints(2, 0, 1, 1, 0.1, 0.0,
115                                         GridBagConstraints.CENTER,
116                                         GridBagConstraints.NONE,
117                                         new Insets(5, 0, 5, 5), 0, 0));
118         this.add(buttonClose,
119                  new GridBagConstraints(3, 0, 1, 1, 0.1, 0.0,
120                                         GridBagConstraints.CENTER,
121                                         GridBagConstraints.NONE,
122                                         new Insets(5, 5, 5, 5), 0, 0));
123         this.add(buttonAbout,
124                  new GridBagConstraints(5, 0, 1, 1, 0.1, 0.0,
125                                         GridBagConstraints.CENTER,
126                                         GridBagConstraints.NONE,
127                                         new Insets(5, 5, 5, 5), 0, 0));
128         this.add(buttonHelp,
129                  new GridBagConstraints(4, 0, 1, 1, 0.1, 0.0,
130                                         GridBagConstraints.CENTER,
131                                         GridBagConstraints.NONE,
132                                         new Insets(5, 5, 5, 5), 0, 0));
133         this.add(panelFiller,
134                  new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0,
135                                         GridBagConstraints.CENTER,
136                                         GridBagConstraints.HORIZONTAL,
137                                         new Insets(0, 0, 0, 0), 50, 0));
138     }
139
140     private class LocalButtonListener implements ActionListener JavaDoc {
141
142         /**
143          * ActionListener implementation.
144          *
145          * @param event
146          * Event that triggered this listener.
147          *
148          */

149         public void actionPerformed(ActionEvent JavaDoc e) {
150             Object JavaDoc source = null;
151             ActionEvent JavaDoc event = null;
152
153             source = e.getSource();
154             if (source == buttonCompile) {
155                 event = new ActionEvent JavaDoc(buttonCompile, ButtonPanel.COMPILE,
156                                         buttonCompile.getActionCommand());
157             } else if (source == buttonClose) {
158                 event = new ActionEvent JavaDoc(buttonClose, ButtonPanel.CLOSE,
159                                         buttonClose.getActionCommand());
160             } else if (source == buttonHelp) {
161                 event = new ActionEvent JavaDoc(buttonHelp, ButtonPanel.HELP,
162                                         buttonHelp.getActionCommand());
163             } else if (source == buttonAbout) {
164                 event = new ActionEvent JavaDoc(buttonAbout, ButtonPanel.ABOUT,
165                                         buttonAbout.getActionCommand());
166             }
167             if (event != null) {
168                 notifyActionListeners(event);
169             }
170         }
171
172     }
173 }
174
Popular Tags