KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > gui > util > ButtonPanel


1 // $Header: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/gui/util/ButtonPanel.java,v 1.6 2004/02/13 02:21:38 sebb Exp $
2
/*
3  * Copyright 2001-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17 */

18
19 package org.apache.jmeter.gui.util;
20
21 import java.awt.Dimension JavaDoc;
22 import java.awt.GridBagConstraints JavaDoc;
23 import java.awt.GridBagLayout JavaDoc;
24 import java.awt.event.ActionListener JavaDoc;
25
26 import javax.swing.JButton JavaDoc;
27 import javax.swing.JPanel JavaDoc;
28
29 import org.apache.jmeter.util.JMeterUtils;
30
31 /**
32  * @author Michael Stover
33  * @version $Revision: 1.6 $
34  */

35 public class ButtonPanel extends JPanel JavaDoc
36 {
37     public final static int ADD_BUTTON = 1;
38     public final static int EDIT_BUTTON = 2;
39     public final static int DELETE_BUTTON = 3;
40     public final static int LOAD_BUTTON = 4;
41     public final static int SAVE_BUTTON = 5;
42
43     private JButton JavaDoc add, delete, edit, load, save;
44
45     public ButtonPanel()
46     {
47         init();
48     }
49
50     public void addButtonListener(int button, ActionListener JavaDoc listener)
51     {
52         switch (button)
53         {
54             case ADD_BUTTON :
55                 add.addActionListener(listener);
56                 break;
57             case EDIT_BUTTON :
58                 edit.addActionListener(listener);
59                 break;
60             case DELETE_BUTTON :
61                 delete.addActionListener(listener);
62                 break;
63             case LOAD_BUTTON :
64                 load.addActionListener(listener);
65                 break;
66             case SAVE_BUTTON :
67                 save.addActionListener(listener);
68                 break;
69         }
70     }
71
72 /* NOTUSED
73     private void initButtonMap()
74     {
75     }
76 */

77     private void init()
78     {
79         add = new JButton JavaDoc(JMeterUtils.getResString("add"));
80         add.setActionCommand("Add");
81         edit = new JButton JavaDoc(JMeterUtils.getResString("edit"));
82         edit.setActionCommand("Edit");
83         delete = new JButton JavaDoc(JMeterUtils.getResString("delete"));
84         delete.setActionCommand("Delete");
85         load = new JButton JavaDoc(JMeterUtils.getResString("load"));
86         load.setActionCommand("Load");
87         save = new JButton JavaDoc(JMeterUtils.getResString("save"));
88         save.setActionCommand("Save");
89         Dimension JavaDoc d = delete.getPreferredSize();
90         add.setPreferredSize(d);
91         edit.setPreferredSize(d);
92         //close.setPreferredSize(d);
93
load.setPreferredSize(d);
94         save.setPreferredSize(d);
95         GridBagLayout JavaDoc g = new GridBagLayout JavaDoc();
96         this.setLayout(g);
97         GridBagConstraints JavaDoc c = new GridBagConstraints JavaDoc();
98         c.fill = GridBagConstraints.NONE;
99         c.gridwidth = 1;
100         c.gridheight = 1;
101         c.gridx = 1;
102         c.gridy = 1;
103         g.setConstraints(add, c);
104         this.add(add);
105         c.gridx = 2;
106         c.gridy = 1;
107         g.setConstraints(edit, c);
108         this.add(edit);
109         c.gridx = 3;
110         c.gridy = 1;
111         g.setConstraints(delete, c);
112         this.add(delete);
113         /*
114          * c.gridx = 1;
115          * c.gridy = 2;
116          * g.setConstraints(close, c);
117          * panel.add(close);
118          */

119         c.gridx = 2;
120         c.gridy = 2;
121         g.setConstraints(load, c);
122         this.add(load);
123         c.gridx = 3;
124         c.gridy = 2;
125         g.setConstraints(save, c);
126         this.add(save);
127     }
128 }
129
Popular Tags