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.xmlc;
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 XMLCButtonPanel extends ButtonPanel {
037:
038: //
039: private GridBagLayout layoutMain;
040: private JButton buttonCompile = null;
041: private JButton buttonClose = null;
042: private JButton buttonHelp = null;
043: private JButton buttonAbout = null;
044: private JPanel panelFiller = null;
045: private LocalButtonListener buttonListener = null;
046:
047: public final static String[] getOptions() {
048: final String[] options = { ButtonPanel.COMMAND_COMPILE,
049: ButtonPanel.COMMAND_CLOSE, ButtonPanel.COMMAND_HELP,
050: ButtonPanel.COMMAND_ABOUT };
051:
052: return options;
053: }
054:
055: public XMLCButtonPanel() {
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: buttonCompile.addActionListener(buttonListener);
076: buttonClose.addActionListener(buttonListener);
077: buttonAbout.addActionListener(buttonListener);
078: buttonHelp.addActionListener(buttonListener);
079: buttonCompile.setText(ButtonPanel.COMMAND_COMPILE);
080: buttonClose.setText(ButtonPanel.COMMAND_CLOSE);
081: buttonAbout.setText(ButtonPanel.COMMAND_ABOUT);
082: buttonHelp.setText(ButtonPanel.COMMAND_HELP);
083:
084: //
085: buttonCompile.setActionCommand(buttonCompile.getText());
086: buttonClose.setActionCommand(buttonClose.getText());
087: buttonAbout.setActionCommand(buttonAbout.getText());
088: buttonHelp.setActionCommand(buttonHelp.getText());
089: }
090:
091: private void jbInit() throws Exception {
092: layoutMain = (GridBagLayout) Beans.instantiate(getClass()
093: .getClassLoader(), GridBagLayout.class.getName());
094: buttonCompile = (JButton) Beans.instantiate(getClass()
095: .getClassLoader(), JButton.class.getName());
096: buttonClose = (JButton) Beans.instantiate(getClass()
097: .getClassLoader(), JButton.class.getName());
098: buttonAbout = (JButton) Beans.instantiate(getClass()
099: .getClassLoader(), JButton.class.getName());
100: buttonHelp = (JButton) Beans.instantiate(getClass()
101: .getClassLoader(), JButton.class.getName());
102: panelFiller = (JPanel) Beans.instantiate(getClass()
103: .getClassLoader(), JPanel.class.getName());
104: buttonCompile.setText("COMPILE");
105: buttonCompile.setEnabled(false);
106: buttonClose.setText("CLOSE");
107: buttonAbout.setText("ABOUT");
108: buttonHelp.setText("HELP");
109: this .setLayout(layoutMain);
110: this .add(buttonCompile, new GridBagConstraints(2, 0, 1, 1, 0.1,
111: 0.0, GridBagConstraints.CENTER,
112: GridBagConstraints.NONE, new Insets(5, 0, 5, 5), 0, 0));
113: this .add(buttonClose, new GridBagConstraints(3, 0, 1, 1, 0.1,
114: 0.0, GridBagConstraints.CENTER,
115: GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
116: this .add(buttonAbout, new GridBagConstraints(5, 0, 1, 1, 0.1,
117: 0.0, GridBagConstraints.CENTER,
118: GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
119: this .add(buttonHelp, new GridBagConstraints(4, 0, 1, 1, 0.1,
120: 0.0, GridBagConstraints.CENTER,
121: GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
122: this .add(panelFiller, new GridBagConstraints(1, 0, 1, 1, 1.0,
123: 0.0, GridBagConstraints.CENTER,
124: GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0),
125: 50, 0));
126: }
127:
128: private class LocalButtonListener implements ActionListener {
129:
130: /**
131: * ActionListener implementation.
132: *
133: * @param event
134: * Event that triggered this listener.
135: *
136: */
137: public void actionPerformed(ActionEvent e) {
138: Object source = null;
139: ActionEvent event = null;
140:
141: source = e.getSource();
142: if (source == buttonCompile) {
143: event = new ActionEvent(buttonCompile,
144: ButtonPanel.COMPILE, buttonCompile
145: .getActionCommand());
146: } else if (source == buttonClose) {
147: event = new ActionEvent(buttonClose, ButtonPanel.CLOSE,
148: buttonClose.getActionCommand());
149: } else if (source == buttonHelp) {
150: event = new ActionEvent(buttonHelp, ButtonPanel.HELP,
151: buttonHelp.getActionCommand());
152: } else if (source == buttonAbout) {
153: event = new ActionEvent(buttonAbout, ButtonPanel.ABOUT,
154: buttonAbout.getActionCommand());
155: }
156: if (event != null) {
157: notifyActionListeners(event);
158: }
159: }
160:
161: }
162: }
|