[1] | 1 | package genius.gui.panels;
|
---|
| 2 |
|
---|
| 3 | import java.awt.BorderLayout;
|
---|
| 4 | import java.awt.event.ActionEvent;
|
---|
| 5 | import java.awt.event.ActionListener;
|
---|
| 6 | import java.awt.event.ItemEvent;
|
---|
| 7 | import java.awt.event.ItemListener;
|
---|
| 8 | import java.awt.event.MouseEvent;
|
---|
| 9 | import java.awt.event.MouseListener;
|
---|
| 10 |
|
---|
| 11 | import javax.swing.JButton;
|
---|
| 12 | import javax.swing.JLabel;
|
---|
| 13 | import javax.swing.JPanel;
|
---|
| 14 | import javax.swing.JRadioButton;
|
---|
| 15 | import javax.swing.event.ChangeEvent;
|
---|
| 16 | import javax.swing.event.ChangeListener;
|
---|
| 17 |
|
---|
| 18 | import genius.core.listener.Listener;
|
---|
| 19 |
|
---|
| 20 | /**
|
---|
| 21 | * Panel showing a checkbox with a title and value. This panel supports a
|
---|
| 22 | * BooleanModel (you can't with the default {@link Checkbox}).
|
---|
| 23 | */
|
---|
| 24 | @SuppressWarnings("serial")
|
---|
| 25 | public class ButtonPanel extends JPanel{
|
---|
| 26 |
|
---|
| 27 | private JButton button;
|
---|
| 28 | private BooleanModel model;
|
---|
| 29 |
|
---|
| 30 | /**
|
---|
| 31 | *
|
---|
| 32 | * @param text
|
---|
| 33 | * the text for the label
|
---|
| 34 | * @param boolModel
|
---|
| 35 | * the boolean model
|
---|
| 36 | */
|
---|
| 37 | public ButtonPanel(final String text, final BooleanModel boolModel) {
|
---|
| 38 | this.model = boolModel;
|
---|
| 39 |
|
---|
| 40 | setLayout(new BorderLayout());
|
---|
| 41 | button = new JButton(text);
|
---|
| 42 | enable1();
|
---|
| 43 |
|
---|
| 44 | // connect the box to the model,
|
---|
| 45 |
|
---|
| 46 | add(button, BorderLayout.CENTER);
|
---|
| 47 |
|
---|
| 48 | button.addMouseListener(new MouseListener() {
|
---|
| 49 |
|
---|
| 50 | @Override
|
---|
| 51 | public void mouseClicked(MouseEvent arg0) {
|
---|
| 52 | model.setValue(true);
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 |
|
---|
| 56 | @Override
|
---|
| 57 | public void mouseEntered(MouseEvent arg0) {
|
---|
| 58 | // TODO Auto-generated method stub
|
---|
| 59 |
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | @Override
|
---|
| 63 | public void mouseExited(MouseEvent arg0) {
|
---|
| 64 | // TODO Auto-generated method stub
|
---|
| 65 |
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | @Override
|
---|
| 69 | public void mousePressed(MouseEvent arg0) {
|
---|
| 70 | // TODO Auto-generated method stub
|
---|
| 71 |
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | @Override
|
---|
| 75 | public void mouseReleased(MouseEvent arg0) {
|
---|
| 76 | // TODO Auto-generated method stub
|
---|
| 77 |
|
---|
| 78 | }
|
---|
| 79 | });
|
---|
| 80 |
|
---|
| 81 | model.addListener(new Listener<Boolean>() {
|
---|
| 82 |
|
---|
| 83 | @Override
|
---|
| 84 | public void notifyChange(Boolean data) {
|
---|
| 85 | button.setSelected(data);
|
---|
| 86 | enable1();
|
---|
| 87 | }
|
---|
| 88 | });
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | /**
|
---|
| 92 | * Update enabled-ness of panel. Just calling enable() doesn nothing?
|
---|
| 93 | */
|
---|
| 94 | private void enable1() {
|
---|
| 95 | boolean enabled = !model.isLocked();
|
---|
| 96 | button.setEnabled(enabled);
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | public JButton getButton() {
|
---|
| 100 | return button;
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | }
|
---|