1 18 19 package org.apache.jmeter.gui.util; 20 21 import java.awt.Dimension ; 22 import java.awt.GridBagConstraints ; 23 import java.awt.GridBagLayout ; 24 import java.awt.event.ActionListener ; 25 26 import javax.swing.JButton ; 27 import javax.swing.JPanel ; 28 29 import org.apache.jmeter.util.JMeterUtils; 30 31 35 public class ButtonPanel extends JPanel 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 add, delete, edit, load, save; 44 45 public ButtonPanel() 46 { 47 init(); 48 } 49 50 public void addButtonListener(int button, ActionListener 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 77 private void init() 78 { 79 add = new JButton (JMeterUtils.getResString("add")); 80 add.setActionCommand("Add"); 81 edit = new JButton (JMeterUtils.getResString("edit")); 82 edit.setActionCommand("Edit"); 83 delete = new JButton (JMeterUtils.getResString("delete")); 84 delete.setActionCommand("Delete"); 85 load = new JButton (JMeterUtils.getResString("load")); 86 load.setActionCommand("Load"); 87 save = new JButton (JMeterUtils.getResString("save")); 88 save.setActionCommand("Save"); 89 Dimension d = delete.getPreferredSize(); 90 add.setPreferredSize(d); 91 edit.setPreferredSize(d); 92 load.setPreferredSize(d); 94 save.setPreferredSize(d); 95 GridBagLayout g = new GridBagLayout (); 96 this.setLayout(g); 97 GridBagConstraints c = new GridBagConstraints (); 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 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 |