001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.jmeter.gui.util;
020:
021: import java.awt.Dimension;
022: import java.awt.GridBagConstraints;
023: import java.awt.GridBagLayout;
024: import java.awt.event.ActionListener;
025:
026: import javax.swing.JButton;
027: import javax.swing.JPanel;
028:
029: import org.apache.jmeter.util.JMeterUtils;
030:
031: // TODO - does not appear to be used
032:
033: public class ButtonPanel extends JPanel {
034: public final static int ADD_BUTTON = 1;
035:
036: public final static int EDIT_BUTTON = 2;
037:
038: public final static int DELETE_BUTTON = 3;
039:
040: public final static int LOAD_BUTTON = 4;
041:
042: public final static int SAVE_BUTTON = 5;
043:
044: private JButton add, delete, edit, load, save;
045:
046: public ButtonPanel() {
047: init();
048: }
049:
050: public void addButtonListener(int button, ActionListener listener) {
051: switch (button) {
052: case ADD_BUTTON:
053: add.addActionListener(listener);
054: break;
055: case EDIT_BUTTON:
056: edit.addActionListener(listener);
057: break;
058: case DELETE_BUTTON:
059: delete.addActionListener(listener);
060: break;
061: case LOAD_BUTTON:
062: load.addActionListener(listener);
063: break;
064: case SAVE_BUTTON:
065: save.addActionListener(listener);
066: break;
067: }
068: }
069:
070: /*
071: * NOTUSED private void initButtonMap() { }
072: */
073: private void init() {
074: add = new JButton(JMeterUtils.getResString("add")); // $NON-NLS-1$
075: add.setActionCommand("Add");
076: edit = new JButton(JMeterUtils.getResString("edit")); // $NON-NLS-1$
077: edit.setActionCommand("Edit");
078: delete = new JButton(JMeterUtils.getResString("delete")); // $NON-NLS-1$
079: delete.setActionCommand("Delete");
080: load = new JButton(JMeterUtils.getResString("load")); // $NON-NLS-1$
081: load.setActionCommand("Load");
082: save = new JButton(JMeterUtils.getResString("save")); // $NON-NLS-1$
083: save.setActionCommand("Save");
084: Dimension d = delete.getPreferredSize();
085: add.setPreferredSize(d);
086: edit.setPreferredSize(d);
087: // close.setPreferredSize(d);
088: load.setPreferredSize(d);
089: save.setPreferredSize(d);
090: GridBagLayout g = new GridBagLayout();
091: this .setLayout(g);
092: GridBagConstraints c = new GridBagConstraints();
093: c.fill = GridBagConstraints.NONE;
094: c.gridwidth = 1;
095: c.gridheight = 1;
096: c.gridx = 1;
097: c.gridy = 1;
098: g.setConstraints(add, c);
099: this .add(add);
100: c.gridx = 2;
101: c.gridy = 1;
102: g.setConstraints(edit, c);
103: this .add(edit);
104: c.gridx = 3;
105: c.gridy = 1;
106: g.setConstraints(delete, c);
107: this .add(delete);
108: /*
109: * c.gridx = 1; c.gridy = 2; g.setConstraints(close, c);
110: * panel.add(close);
111: */
112: c.gridx = 2;
113: c.gridy = 2;
114: g.setConstraints(load, c);
115: this .add(load);
116: c.gridx = 3;
117: c.gridy = 2;
118: g.setConstraints(save, c);
119: this.add(save);
120: }
121: }
|