1 | package com.framsticks.gui.table; |
---|
2 | |
---|
3 | import java.awt.Component; |
---|
4 | import java.awt.event.ActionEvent; |
---|
5 | import java.awt.event.ActionListener; |
---|
6 | |
---|
7 | import javax.swing.DefaultCellEditor; |
---|
8 | import javax.swing.JButton; |
---|
9 | import javax.swing.JCheckBox; |
---|
10 | import javax.swing.JTable; |
---|
11 | |
---|
12 | import com.framsticks.params.types.ProcedureParam; |
---|
13 | import com.framsticks.util.lang.Casting; |
---|
14 | |
---|
15 | @SuppressWarnings("serial") |
---|
16 | public class ProcedureEditor extends DefaultCellEditor { |
---|
17 | |
---|
18 | protected JButton button; |
---|
19 | |
---|
20 | private ProcedureParam procedure; |
---|
21 | |
---|
22 | private boolean isPushed; |
---|
23 | |
---|
24 | public ProcedureEditor(JCheckBox checkBox) { |
---|
25 | super(checkBox); |
---|
26 | button = new JButton(); |
---|
27 | button.setOpaque(true); |
---|
28 | button.addActionListener(new ActionListener() { |
---|
29 | public void actionPerformed(ActionEvent e) { |
---|
30 | fireEditingStopped(); |
---|
31 | } |
---|
32 | }); |
---|
33 | } |
---|
34 | |
---|
35 | public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { |
---|
36 | TableModel.transferCellAppeariance(table, button, isSelected); |
---|
37 | procedure = Casting.assertCast(ProcedureParam.class, value); |
---|
38 | button.setText(procedure.getName()); |
---|
39 | isPushed = true; |
---|
40 | return button; |
---|
41 | } |
---|
42 | |
---|
43 | public Object getCellEditorValue() { |
---|
44 | if (isPushed) { |
---|
45 | // |
---|
46 | // |
---|
47 | // JOptionPane.showMessageDialog(button, label + ": Ouch!"); |
---|
48 | // System.out.println(label + ": Ouch!"); |
---|
49 | } |
---|
50 | isPushed = false; |
---|
51 | return procedure; |
---|
52 | } |
---|
53 | |
---|
54 | public boolean stopCellEditing() { |
---|
55 | isPushed = false; |
---|
56 | return super.stopCellEditing(); |
---|
57 | } |
---|
58 | |
---|
59 | protected void fireEditingStopped() { |
---|
60 | super.fireEditingStopped(); |
---|
61 | } |
---|
62 | |
---|
63 | } |
---|