KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > common > dods > DodsButtonPanel


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.dods;
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
37 //
38
public class DodsButtonPanel extends ButtonPanel {
39     //
40
private GridBagLayout layoutMain = null;
41     private JButton buttonGenerate = null;
42     private JButton buttonClose = null;
43     private JButton buttonHelp = null;
44     private JButton buttonAbout = null;
45     private LocalButtonListener buttonListener = null;
46     private JPanel panelFiller;
47 // private JTextField textFile = null;
48

49     public static final String JavaDoc[] getOptions() {
50       final String JavaDoc[] options = {ButtonPanel.COMMAND_GENERATE,
51          ButtonPanel.COMMAND_CLOSE, ButtonPanel.COMMAND_HELP,
52          ButtonPanel.COMMAND_ABOUT};
53       return options;
54     }
55
56     public DodsButtonPanel() {
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         buttonGenerate.addActionListener(buttonListener);
77         buttonClose.addActionListener(buttonListener);
78         buttonAbout.addActionListener(buttonListener);
79         buttonHelp.addActionListener(buttonListener);
80
81         buttonGenerate.setText(ButtonPanel.COMMAND_GENERATE);
82         buttonClose.setText(ButtonPanel.COMMAND_CLOSE);
83         buttonAbout.setText(ButtonPanel.COMMAND_ABOUT);
84         buttonHelp.setText(ButtonPanel.COMMAND_HELP);
85         //
86
buttonGenerate.setActionCommand(buttonGenerate.getText());
87         buttonClose.setActionCommand(buttonClose.getText());
88         buttonAbout.setActionCommand(buttonAbout.getText());
89         buttonHelp.setActionCommand(buttonHelp.getText());
90         //
91
buttonClose.requestFocus();
92     }
93
94     private void jbInit() throws Exception JavaDoc {
95         layoutMain =
96             (GridBagLayout) Beans.instantiate(getClass().getClassLoader(),
97                                               GridBagLayout.class.getName());
98         buttonGenerate =
99             (JButton) Beans.instantiate(getClass().getClassLoader(),
100                                         JButton.class.getName());
101         buttonClose =
102             (JButton) Beans.instantiate(getClass().getClassLoader(),
103                                         JButton.class.getName());
104         buttonAbout = (JButton) Beans.instantiate(getClass().getClassLoader(),
105                                                   JButton.class.getName());
106         buttonHelp = (JButton) Beans.instantiate(getClass().getClassLoader(),
107                                                  JButton.class.getName());
108         panelFiller = (JPanel) Beans.instantiate(getClass().getClassLoader(),
109                                                  JPanel.class.getName());
110         buttonGenerate.setText("GENERATE");
111         buttonClose.setText("CLOSE");
112         buttonAbout.setText("ABOUT");
113         buttonHelp.setText("HELP");
114         this.setLayout(layoutMain);
115         this.add(buttonGenerate, new GridBagConstraints(1, 0, 1, 1, 0.1, 0.0
116             ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 20, 5, 2), 0, 0));
117         this.add(buttonClose, new GridBagConstraints(2, 0, 1, 1, 0.1, 0.0
118             ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 2, 5, 2), 0, 0));
119         this.add(buttonHelp, new GridBagConstraints(3, 0, 1, 1, 0.1, 0.0
120             ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 2, 5, 2), 0, 0));
121         this.add(buttonAbout, new GridBagConstraints(4, 0, 1, 1, 0.1, 0.0
122             ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 2, 5, 2), 0, 0));
123         this.add(panelFiller, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0
124             ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 50, 0));
125     }
126
127     private class LocalButtonListener implements ActionListener JavaDoc {
128
129         /**
130          * ActionListener implementation.
131          *
132          * @param event
133          * Event that triggered this listener.
134          *
135          */

136         public void actionPerformed(ActionEvent JavaDoc e) {
137             Object JavaDoc source = null;
138             ActionEvent JavaDoc event = null;
139
140             source = e.getSource();
141             if (source == buttonGenerate) {
142                 event = new ActionEvent JavaDoc(buttonGenerate,
143                                         ButtonPanel.GENERATE,
144                                         buttonGenerate.getActionCommand());
145
146             } else if (source == buttonClose) {
147                 event = new ActionEvent JavaDoc(buttonClose,
148                                         ButtonPanel.CLOSE,
149                                         buttonClose.getActionCommand());
150             } else if (source == buttonHelp) {
151                 event = new ActionEvent JavaDoc(buttonHelp, ButtonPanel.HELP,
152                                         buttonHelp.getActionCommand());
153             } else if (source == buttonAbout) {
154                 event = new ActionEvent JavaDoc(buttonAbout, ButtonPanel.ABOUT,
155                                         buttonAbout.getActionCommand());
156             }
157             if (event != null) {
158                 notifyActionListeners(event);
159             }
160         }
161
162     }
163
164
165
166 }
167
Popular Tags