001: /*
002: * Enhydra Java Application Server Project
003: *
004: * The contents of this file are subject to the Enhydra Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License on
007: * the Enhydra web site ( http://www.enhydra.org/ ).
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011: * the License for the specific terms governing rights and limitations
012: * under the License.
013: *
014: * The Initial Developer of the Enhydra Application Server is Lutris
015: * Technologies, Inc. The Enhydra Application Server and portions created
016: * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017: * All Rights Reserved.
018: *
019: * Contributor(s):
020: * Paul Mahar
021: *
022: */
023: package org.enhydra.kelp.common.dods;
024:
025: // ToolBox imports
026: import org.enhydra.tool.common.ButtonPanel;
027:
028: // Standard imports
029: import java.awt.*;
030: import java.awt.event.ActionEvent;
031: import java.awt.event.ActionListener;
032: import java.beans.*;
033: import javax.swing.*;
034:
035: //
036: public class DodsButtonPanel extends ButtonPanel {
037: //
038: private GridBagLayout layoutMain = null;
039: private JButton buttonGenerate = null;
040: private JButton buttonClose = null;
041: private JButton buttonHelp = null;
042: private JButton buttonAbout = null;
043: private LocalButtonListener buttonListener = null;
044: private JPanel panelFiller;
045:
046: // private JTextField textFile = null;
047:
048: public static final String[] getOptions() {
049: final String[] options = { ButtonPanel.COMMAND_GENERATE,
050: ButtonPanel.COMMAND_CLOSE, ButtonPanel.COMMAND_HELP,
051: ButtonPanel.COMMAND_ABOUT };
052: return options;
053: }
054:
055: public DodsButtonPanel() {
056: try {
057: jbInit();
058: pmInit();
059: } catch (Exception e) {
060: e.printStackTrace();
061: }
062: }
063:
064: // override ButtonPanel
065: public void removeHelp() {
066: remove(buttonHelp);
067: invalidate();
068: doLayout();
069: }
070:
071: //
072: //
073: private void pmInit() {
074: buttonListener = new LocalButtonListener();
075: buttonGenerate.addActionListener(buttonListener);
076: buttonClose.addActionListener(buttonListener);
077: buttonAbout.addActionListener(buttonListener);
078: buttonHelp.addActionListener(buttonListener);
079:
080: buttonGenerate.setText(ButtonPanel.COMMAND_GENERATE);
081: buttonClose.setText(ButtonPanel.COMMAND_CLOSE);
082: buttonAbout.setText(ButtonPanel.COMMAND_ABOUT);
083: buttonHelp.setText(ButtonPanel.COMMAND_HELP);
084: //
085: buttonGenerate.setActionCommand(buttonGenerate.getText());
086: buttonClose.setActionCommand(buttonClose.getText());
087: buttonAbout.setActionCommand(buttonAbout.getText());
088: buttonHelp.setActionCommand(buttonHelp.getText());
089: //
090: buttonClose.requestFocus();
091: }
092:
093: private void jbInit() throws Exception {
094: layoutMain = (GridBagLayout) Beans.instantiate(getClass()
095: .getClassLoader(), GridBagLayout.class.getName());
096: buttonGenerate = (JButton) Beans.instantiate(getClass()
097: .getClassLoader(), JButton.class.getName());
098: buttonClose = (JButton) Beans.instantiate(getClass()
099: .getClassLoader(), JButton.class.getName());
100: buttonAbout = (JButton) Beans.instantiate(getClass()
101: .getClassLoader(), JButton.class.getName());
102: buttonHelp = (JButton) Beans.instantiate(getClass()
103: .getClassLoader(), JButton.class.getName());
104: panelFiller = (JPanel) Beans.instantiate(getClass()
105: .getClassLoader(), JPanel.class.getName());
106: buttonGenerate.setText("GENERATE");
107: buttonClose.setText("CLOSE");
108: buttonAbout.setText("ABOUT");
109: buttonHelp.setText("HELP");
110: this .setLayout(layoutMain);
111: this
112: .add(buttonGenerate, new GridBagConstraints(1, 0, 1, 1,
113: 0.1, 0.0, GridBagConstraints.CENTER,
114: GridBagConstraints.NONE,
115: new Insets(5, 20, 5, 2), 0, 0));
116: this .add(buttonClose, new GridBagConstraints(2, 0, 1, 1, 0.1,
117: 0.0, GridBagConstraints.CENTER,
118: GridBagConstraints.NONE, new Insets(5, 2, 5, 2), 0, 0));
119: this .add(buttonHelp, new GridBagConstraints(3, 0, 1, 1, 0.1,
120: 0.0, GridBagConstraints.CENTER,
121: GridBagConstraints.NONE, new Insets(5, 2, 5, 2), 0, 0));
122: this .add(buttonAbout, new GridBagConstraints(4, 0, 1, 1, 0.1,
123: 0.0, GridBagConstraints.CENTER,
124: GridBagConstraints.NONE, new Insets(5, 2, 5, 2), 0, 0));
125: this .add(panelFiller, new GridBagConstraints(0, 0, 1, 1, 1.0,
126: 0.0, GridBagConstraints.CENTER,
127: GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0),
128: 50, 0));
129: }
130:
131: private class LocalButtonListener implements ActionListener {
132:
133: /**
134: * ActionListener implementation.
135: *
136: * @param event
137: * Event that triggered this listener.
138: *
139: */
140: public void actionPerformed(ActionEvent e) {
141: Object source = null;
142: ActionEvent event = null;
143:
144: source = e.getSource();
145: if (source == buttonGenerate) {
146: event = new ActionEvent(buttonGenerate,
147: ButtonPanel.GENERATE, buttonGenerate
148: .getActionCommand());
149:
150: } else if (source == buttonClose) {
151: event = new ActionEvent(buttonClose, ButtonPanel.CLOSE,
152: buttonClose.getActionCommand());
153: } else if (source == buttonHelp) {
154: event = new ActionEvent(buttonHelp, ButtonPanel.HELP,
155: buttonHelp.getActionCommand());
156: } else if (source == buttonAbout) {
157: event = new ActionEvent(buttonAbout, ButtonPanel.ABOUT,
158: buttonAbout.getActionCommand());
159: }
160: if (event != null) {
161: notifyActionListeners(event);
162: }
163: }
164:
165: }
166:
167: }
|