01: package org.dbbrowser.ui.panel;
02:
03: import java.awt.*;
04: import java.util.List;
05: import javax.swing.JButton;
06: import javax.swing.JFrame;
07: import javax.swing.JPanel;
08: import javax.swing.JRootPane;
09: import javax.swing.SwingUtilities;
10:
11: import org.dbbrowser.ui.UIControllerForQueries;
12: import org.dbbrowser.ui.widget.Button;
13:
14: /**
15: * A buttons panel holds a group of buttons
16: * @author amangat
17: *
18: */
19: public class ButtonsPanel extends JPanel {
20: private static final long serialVersionUID = UIControllerForQueries.version;
21: private List listOfButtons = null;
22:
23: /**
24: * Constructer
25: * @param listOfButtons - list of Button widgets
26: */
27: public ButtonsPanel(List listOfButtons) {
28: this .listOfButtons = listOfButtons;
29: this .initialize();
30: }
31:
32: /**
33: * Enable or disable the button with that name
34: * @param buttonName
35: * @param enable
36: */
37: public void enableButton(String buttonName, Boolean enable) {
38: Component[] components = this .getComponents();
39: for (int i = 0; i < components.length; i++) {
40: JButton jButton = (JButton) components[i];
41: String actionCommand = jButton.getActionCommand();
42: if (actionCommand.equals(buttonName)) {
43: jButton.setEnabled(enable.booleanValue());
44: break;
45: }
46: }
47: }
48:
49: private void initialize() {
50: this .setLayout(new FlowLayout(FlowLayout.CENTER));
51: for (int i = 0; i < this .listOfButtons.size(); i++) {
52: Button button = (Button) this .listOfButtons.get(i);
53: JButton jButton = new JButton();
54: jButton.setText(button.getLabel());
55: jButton.addActionListener(button.getListener());
56: jButton.setActionCommand(button.getName());
57: jButton.setIcon(button.getIcon());
58: this .add(jButton);
59: }
60:
61: Dimension d = new Dimension(this .getMaximumSize().width, 50);
62: this.setMaximumSize(d);
63: }
64: }
|