d39d74e760ddd9e8c734ed7bedd3e2637d723d59
[jalview.git] / srcjar / fr / orsay / lri / varna / components / BaseSpecialColorEditor.java
1
2 package fr.orsay.lri.varna.components;
3
4
5 import java.awt.Color;
6 import java.awt.Component;
7
8 import javax.swing.AbstractCellEditor;
9 import javax.swing.JButton;
10 import javax.swing.JColorChooser;
11 import javax.swing.JDialog;
12 import javax.swing.JTable;
13 import javax.swing.table.TableCellEditor;
14
15 import fr.orsay.lri.varna.controlers.ControleurBaseSpecialColorEditor;
16 import fr.orsay.lri.varna.views.VueBases;
17
18 public class BaseSpecialColorEditor extends AbstractCellEditor implements
19                 TableCellEditor {
20         /**
21          * 
22          */
23         private static final long serialVersionUID = 1L;
24         private Color currentColor;
25         private JButton button;
26         private JColorChooser colorChooser;
27         private JDialog dialog;
28         protected static final String EDIT = "edit";
29         private VueBases _vueBases;
30         private ControleurBaseSpecialColorEditor _controleurSpecialColorEditor;
31
32         public BaseSpecialColorEditor(VueBases vueBases) {
33                 // Set up the editor (from the table's point of view),
34                 // which is a button.
35                 // This button brings up the color chooser dialog,
36                 // which is the editor from the user's point of view.
37                 button = new JButton();
38                 button.setActionCommand(EDIT);
39                 _controleurSpecialColorEditor = new ControleurBaseSpecialColorEditor(this);
40                 button.addActionListener(_controleurSpecialColorEditor);
41                 button.setBorderPainted(false);
42                 fireEditingStopped();
43                 _vueBases = vueBases;
44
45                 // Set up the dialog that the button brings up.
46                 colorChooser = new JColorChooser();
47                 dialog = JColorChooser.createDialog(button, "Pick a Color", true, // modal
48                                 colorChooser, _controleurSpecialColorEditor, // OK button
49                                 // handler
50                                 null); // no CANCEL button handler
51         }
52
53         // Implement the one CellEditor method that AbstractCellEditor doesn't.
54         public Object getCellEditorValue() {
55                 return currentColor;
56         }
57
58         // Implement the one method defined by TableCellEditor.
59         public Component getTableCellEditorComponent(JTable table, Object value,
60                         boolean isSelected, int row, int column) {
61                 currentColor = (Color) value;
62                 return button;
63         }
64
65         public static long getSerialVersionUID() {
66                 return serialVersionUID;
67         }
68
69         public Color getCurrentColor() {
70                 return currentColor;
71         }
72
73         public JButton getButton() {
74                 return button;
75         }
76
77         public JColorChooser getColorChooser() {
78                 return colorChooser;
79         }
80
81         public JDialog getDialog() {
82                 return dialog;
83         }
84
85         public static String getEDIT() {
86                 return EDIT;
87         }
88
89         public VueBases get_vueBases() {
90                 return _vueBases;
91         }
92
93         public ControleurBaseSpecialColorEditor get_controleurSpecialColorEditor() {
94                 return _controleurSpecialColorEditor;
95         }
96
97         public void setCurrentColor(Color currentColor) {
98                 this.currentColor = currentColor;
99         }
100
101         public void callFireEditingStopped() {
102                 fireEditingStopped();
103         }
104 }