2 |
26 Feb 07 |
jari |
1 |
/* |
2 |
26 Feb 07 |
jari |
Copyright @ 1999-2004, The Institute for Genomic Research (TIGR). |
2 |
26 Feb 07 |
jari |
All rights reserved. |
2 |
26 Feb 07 |
jari |
4 |
*/ |
2 |
26 Feb 07 |
jari |
5 |
/* |
2 |
26 Feb 07 |
jari |
* ExperimentLabelEditor.java |
2 |
26 Feb 07 |
jari |
7 |
* |
2 |
26 Feb 07 |
jari |
* Created on May 10, 2004, 10:50 PM |
2 |
26 Feb 07 |
jari |
9 |
*/ |
2 |
26 Feb 07 |
jari |
10 |
|
2 |
26 Feb 07 |
jari |
11 |
package org.tigr.microarray.mev; |
2 |
26 Feb 07 |
jari |
12 |
|
2 |
26 Feb 07 |
jari |
13 |
import java.awt.Color; |
2 |
26 Feb 07 |
jari |
14 |
import java.awt.Component; |
2 |
26 Feb 07 |
jari |
15 |
import java.awt.Dimension; |
2 |
26 Feb 07 |
jari |
16 |
import java.awt.Font; |
2 |
26 Feb 07 |
jari |
17 |
import java.awt.GridBagConstraints; |
2 |
26 Feb 07 |
jari |
18 |
import java.awt.GridBagLayout; |
2 |
26 Feb 07 |
jari |
19 |
import java.awt.Insets; |
2 |
26 Feb 07 |
jari |
20 |
import java.awt.Toolkit; |
2 |
26 Feb 07 |
jari |
21 |
import java.awt.event.ActionEvent; |
2 |
26 Feb 07 |
jari |
22 |
import java.awt.event.ActionListener; |
2 |
26 Feb 07 |
jari |
23 |
import java.awt.event.MouseAdapter; |
2 |
26 Feb 07 |
jari |
24 |
import java.awt.event.MouseEvent; |
2 |
26 Feb 07 |
jari |
25 |
import java.util.Arrays; |
2 |
26 Feb 07 |
jari |
26 |
import java.util.Vector; |
2 |
26 Feb 07 |
jari |
27 |
|
2 |
26 Feb 07 |
jari |
28 |
import javax.swing.AbstractCellEditor; |
2 |
26 Feb 07 |
jari |
29 |
import javax.swing.DefaultCellEditor; |
2 |
26 Feb 07 |
jari |
30 |
import javax.swing.JCheckBoxMenuItem; |
2 |
26 Feb 07 |
jari |
31 |
import javax.swing.JFrame; |
2 |
26 Feb 07 |
jari |
32 |
import javax.swing.JLabel; |
2 |
26 Feb 07 |
jari |
33 |
import javax.swing.JList; |
2 |
26 Feb 07 |
jari |
34 |
import javax.swing.JMenu; |
2 |
26 Feb 07 |
jari |
35 |
import javax.swing.JMenuBar; |
2 |
26 Feb 07 |
jari |
36 |
import javax.swing.JMenuItem; |
2 |
26 Feb 07 |
jari |
37 |
import javax.swing.JOptionPane; |
2 |
26 Feb 07 |
jari |
38 |
import javax.swing.JPanel; |
2 |
26 Feb 07 |
jari |
39 |
import javax.swing.JPopupMenu; |
2 |
26 Feb 07 |
jari |
40 |
import javax.swing.JScrollPane; |
2 |
26 Feb 07 |
jari |
41 |
import javax.swing.JTable; |
2 |
26 Feb 07 |
jari |
42 |
import javax.swing.JTextField; |
2 |
26 Feb 07 |
jari |
43 |
import javax.swing.event.TableModelEvent; |
2 |
26 Feb 07 |
jari |
44 |
import javax.swing.table.AbstractTableModel; |
2 |
26 Feb 07 |
jari |
45 |
import javax.swing.table.DefaultTableCellRenderer; |
2 |
26 Feb 07 |
jari |
46 |
import javax.swing.table.TableCellEditor; |
2 |
26 Feb 07 |
jari |
47 |
|
2 |
26 Feb 07 |
jari |
48 |
import org.tigr.microarray.mev.cluster.gui.IData; |
2 |
26 Feb 07 |
jari |
49 |
import org.tigr.microarray.mev.cluster.gui.impl.dialogs.AlgorithmDialog; |
2 |
26 Feb 07 |
jari |
50 |
import org.tigr.microarray.mev.cluster.gui.impl.dialogs.ListOrderDialog; |
2 |
26 Feb 07 |
jari |
51 |
import org.tigr.microarray.mev.cluster.gui.impl.dialogs.ParameterPanel; |
2 |
26 Feb 07 |
jari |
52 |
import org.tigr.microarray.mev.cluster.gui.impl.dialogs.dialogHelpUtil.HelpWindow; |
2 |
26 Feb 07 |
jari |
53 |
|
2 |
26 Feb 07 |
jari |
54 |
|
2 |
26 Feb 07 |
jari |
55 |
/** |
2 |
26 Feb 07 |
jari |
56 |
* |
2 |
26 Feb 07 |
jari |
* @author braisted |
2 |
26 Feb 07 |
jari |
58 |
*/ |
2 |
26 Feb 07 |
jari |
59 |
public class ExperimentLabelEditor extends AlgorithmDialog { |
2 |
26 Feb 07 |
jari |
60 |
|
2 |
26 Feb 07 |
jari |
61 |
JTable table; |
2 |
26 Feb 07 |
jari |
62 |
DefaultViewerTableModel model; |
2 |
26 Feb 07 |
jari |
63 |
CellEditor cellEditor; |
2 |
26 Feb 07 |
jari |
64 |
int result = JOptionPane.OK_OPTION; |
2 |
26 Feb 07 |
jari |
65 |
JPopupMenu popup; |
2 |
26 Feb 07 |
jari |
66 |
|
2 |
26 Feb 07 |
jari |
67 |
JMenuItem mergeRowsPopItem; |
2 |
26 Feb 07 |
jari |
68 |
JMenuItem mergeRowsItem; |
2 |
26 Feb 07 |
jari |
69 |
JMenuItem delRowsPopItem; |
2 |
26 Feb 07 |
jari |
70 |
JMenuItem delRowsItem; |
2 |
26 Feb 07 |
jari |
71 |
JCheckBoxMenuItem enableReorderItem; |
2 |
26 Feb 07 |
jari |
72 |
JCheckBoxMenuItem enableReorderPopItem; |
2 |
26 Feb 07 |
jari |
73 |
|
2 |
26 Feb 07 |
jari |
74 |
boolean allowReordering = false; |
2 |
26 Feb 07 |
jari |
75 |
JFrame parent; |
2 |
26 Feb 07 |
jari |
76 |
|
2 |
26 Feb 07 |
jari |
/** Creates a new instance of ExperimentLabelEditor */ |
2 |
26 Feb 07 |
jari |
78 |
public ExperimentLabelEditor(JFrame parent, Vector keys, IData data, boolean permitReorder) { |
2 |
26 Feb 07 |
jari |
79 |
super(parent, "Sample Label Editor", true); |
2 |
26 Feb 07 |
jari |
80 |
this.parent = parent; |
2 |
26 Feb 07 |
jari |
81 |
Listener listener= new Listener(); |
2 |
26 Feb 07 |
jari |
82 |
allowReordering = permitReorder; |
2 |
26 Feb 07 |
jari |
83 |
model = new DefaultViewerTableModel(keys, data); |
2 |
26 Feb 07 |
jari |
84 |
table = new JTable(model); |
2 |
26 Feb 07 |
jari |
85 |
table.setDefaultRenderer(String.class, new CellRenderer()); |
2 |
26 Feb 07 |
jari |
//table.setDefaultRenderer(JLabel.class, new CellRenderer()); |
2 |
26 Feb 07 |
jari |
87 |
table.setDefaultRenderer(JTextField.class, new CellRenderer()); |
2 |
26 Feb 07 |
jari |
88 |
table.setDefaultRenderer(Object.class, new CellRenderer()); |
2 |
26 Feb 07 |
jari |
89 |
|
2 |
26 Feb 07 |
jari |
90 |
|
2 |
26 Feb 07 |
jari |
91 |
|
2 |
26 Feb 07 |
jari |
//table.setCellSelectionEnabled(true); |
2 |
26 Feb 07 |
jari |
93 |
table.setRowSelectionAllowed(true); |
2 |
26 Feb 07 |
jari |
94 |
|
2 |
26 Feb 07 |
jari |
95 |
|
2 |
26 Feb 07 |
jari |
96 |
|
2 |
26 Feb 07 |
jari |
97 |
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); |
2 |
26 Feb 07 |
jari |
98 |
table.getColumn("Label Key").setMinWidth(130); |
2 |
26 Feb 07 |
jari |
99 |
for(int i = 1; i < table.getColumnCount(); i++) { |
2 |
26 Feb 07 |
jari |
100 |
table.getColumn(String.valueOf(i)).setMinWidth(100); |
2 |
26 Feb 07 |
jari |
101 |
} |
2 |
26 Feb 07 |
jari |
102 |
table.setDefaultEditor(JTextField.class, new DefaultCellEditor(new JTextField())); |
2 |
26 Feb 07 |
jari |
103 |
table.setRowHeight(25); |
2 |
26 Feb 07 |
jari |
104 |
JScrollPane pane = new JScrollPane(table); |
2 |
26 Feb 07 |
jari |
105 |
pane.setColumnHeaderView(table.getTableHeader()); |
2 |
26 Feb 07 |
jari |
106 |
table.setPreferredScrollableViewportSize(new Dimension(500, 150)); |
2 |
26 Feb 07 |
jari |
107 |
ParameterPanel panel = new ParameterPanel("Sample Labels"); |
2 |
26 Feb 07 |
jari |
108 |
panel.setLayout(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
109 |
panel.add(pane, new GridBagConstraints(0,0,1,1,1.0,1.0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5,5,5,5),0,0)); |
2 |
26 Feb 07 |
jari |
110 |
JMenuBar menuBar = createMenuBar(listener); |
2 |
26 Feb 07 |
jari |
111 |
this.setJMenuBar(menuBar); |
2 |
26 Feb 07 |
jari |
112 |
popup = createPopupMenu(listener); |
2 |
26 Feb 07 |
jari |
113 |
addContent(panel); |
2 |
26 Feb 07 |
jari |
114 |
int w = (this.getToolkit().getScreenSize().width); |
2 |
26 Feb 07 |
jari |
115 |
int dataWidth = (130 + 100*(table.getColumnCount()-1))-50; |
2 |
26 Feb 07 |
jari |
116 |
if(w > 100) { |
2 |
26 Feb 07 |
jari |
117 |
w = (int)(w*0.8); |
2 |
26 Feb 07 |
jari |
118 |
setSize(Math.min(w, dataWidth), 300); |
2 |
26 Feb 07 |
jari |
119 |
} else |
2 |
26 Feb 07 |
jari |
120 |
setSize(700, 300); |
2 |
26 Feb 07 |
jari |
121 |
table.addMouseListener(listener); //table actions |
2 |
26 Feb 07 |
jari |
122 |
setActionListeners(listener); //listens for button hits, method in AlgorithmDialog |
2 |
26 Feb 07 |
jari |
123 |
} |
2 |
26 Feb 07 |
jari |
124 |
|
2 |
26 Feb 07 |
jari |
125 |
/** |
2 |
26 Feb 07 |
jari |
* Shows the dialog. |
2 |
26 Feb 07 |
jari |
127 |
*/ |
2 |
26 Feb 07 |
jari |
128 |
public int showModal() { |
2 |
26 Feb 07 |
jari |
129 |
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
2 |
26 Feb 07 |
jari |
130 |
setLocation((screenSize.width - getSize().width)/2, (screenSize.height - getSize().height)/2); |
2 |
26 Feb 07 |
jari |
131 |
show(); |
2 |
26 Feb 07 |
jari |
132 |
return result; |
2 |
26 Feb 07 |
jari |
133 |
} |
2 |
26 Feb 07 |
jari |
134 |
|
2 |
26 Feb 07 |
jari |
135 |
public String getNewLabel() { |
2 |
26 Feb 07 |
jari |
136 |
return "TestLabel"; |
2 |
26 Feb 07 |
jari |
137 |
} |
2 |
26 Feb 07 |
jari |
138 |
|
2 |
26 Feb 07 |
jari |
139 |
public String [] getLabelValues() { |
2 |
26 Feb 07 |
jari |
140 |
String [] labels = new String[10]; |
2 |
26 Feb 07 |
jari |
141 |
for(int i = 0; i < labels.length; i++) { |
2 |
26 Feb 07 |
jari |
142 |
labels[i] = "Test Label "+String.valueOf(i); |
2 |
26 Feb 07 |
jari |
143 |
} |
2 |
26 Feb 07 |
jari |
144 |
return labels; |
2 |
26 Feb 07 |
jari |
145 |
} |
2 |
26 Feb 07 |
jari |
146 |
|
2 |
26 Feb 07 |
jari |
147 |
public String [][] getLableData() { |
2 |
26 Feb 07 |
jari |
148 |
String [][] data = new String [table.getRowCount()][table.getColumnCount()]; |
2 |
26 Feb 07 |
jari |
149 |
for(int i = 0; i < data.length; i++) { |
2 |
26 Feb 07 |
jari |
150 |
for(int j = 0; j < data[i].length; j++) { |
2 |
26 Feb 07 |
jari |
151 |
data[i][j] = (String)(model.getValueAt(i,j)); |
2 |
26 Feb 07 |
jari |
152 |
} |
2 |
26 Feb 07 |
jari |
153 |
} |
2 |
26 Feb 07 |
jari |
154 |
|
2 |
26 Feb 07 |
jari |
155 |
return data; |
2 |
26 Feb 07 |
jari |
156 |
} |
2 |
26 Feb 07 |
jari |
157 |
|
2 |
26 Feb 07 |
jari |
158 |
public String [][] getLabelDataWithoutKeys() { |
2 |
26 Feb 07 |
jari |
159 |
String [][] data = new String [table.getRowCount()][table.getColumnCount()-1]; |
2 |
26 Feb 07 |
jari |
160 |
for(int i = 0; i < data.length; i++) { |
2 |
26 Feb 07 |
jari |
161 |
for(int j = 0; j < data[i].length; j++) { |
2 |
26 Feb 07 |
jari |
162 |
data[i][j] = (String)(model.getValueAt(i,j+1)); |
2 |
26 Feb 07 |
jari |
163 |
} |
2 |
26 Feb 07 |
jari |
164 |
} |
2 |
26 Feb 07 |
jari |
165 |
return data; |
2 |
26 Feb 07 |
jari |
166 |
} |
2 |
26 Feb 07 |
jari |
167 |
|
2 |
26 Feb 07 |
jari |
168 |
|
2 |
26 Feb 07 |
jari |
169 |
public String[] getLabelKeys() { |
2 |
26 Feb 07 |
jari |
170 |
String [] keys = new String[table.getRowCount()]; |
2 |
26 Feb 07 |
jari |
171 |
for(int i = 0; i < keys.length; i++) { |
2 |
26 Feb 07 |
jari |
172 |
keys[i] = (String)(model.getValueAt(i,0)); //just get the keys |
2 |
26 Feb 07 |
jari |
173 |
} |
2 |
26 Feb 07 |
jari |
174 |
return keys; |
2 |
26 Feb 07 |
jari |
175 |
} |
2 |
26 Feb 07 |
jari |
176 |
|
2 |
26 Feb 07 |
jari |
177 |
|
2 |
26 Feb 07 |
jari |
178 |
public String [] getExperimentNamesInOriginalOrder() { |
2 |
26 Feb 07 |
jari |
179 |
String [] expNames = new String[table.getColumnCount()-1]; |
2 |
26 Feb 07 |
jari |
180 |
for(int i = 0; i < expNames.length; i++) { |
2 |
26 Feb 07 |
jari |
181 |
expNames[i] = (String)(model.getValueAt(0, i+1)); |
2 |
26 Feb 07 |
jari |
182 |
} |
2 |
26 Feb 07 |
jari |
183 |
return expNames; |
2 |
26 Feb 07 |
jari |
184 |
} |
2 |
26 Feb 07 |
jari |
185 |
|
2 |
26 Feb 07 |
jari |
186 |
|
2 |
26 Feb 07 |
jari |
187 |
|
2 |
26 Feb 07 |
jari |
188 |
public String [] getExperimentNamesInTableOrder() { |
2 |
26 Feb 07 |
jari |
189 |
String [] expNames = new String[table.getColumnCount()-1]; |
2 |
26 Feb 07 |
jari |
190 |
for(int i = 0; i < expNames.length; i++) { |
2 |
26 Feb 07 |
jari |
191 |
expNames[i] = (String)(table.getValueAt(0, i+1)); |
2 |
26 Feb 07 |
jari |
192 |
} |
2 |
26 Feb 07 |
jari |
193 |
return expNames; |
2 |
26 Feb 07 |
jari |
194 |
} |
2 |
26 Feb 07 |
jari |
195 |
|
2 |
26 Feb 07 |
jari |
196 |
public int [] getNewOrderScheme() { |
2 |
26 Feb 07 |
jari |
197 |
String [] origOrder = this.getExperimentNamesInOriginalOrder(); |
2 |
26 Feb 07 |
jari |
198 |
String [] newOrder = this.getExperimentNamesInTableOrder(); |
2 |
26 Feb 07 |
jari |
199 |
int [] order = new int[origOrder.length]; |
2 |
26 Feb 07 |
jari |
200 |
for(int i = 0; i < origOrder.length; i++) { |
2 |
26 Feb 07 |
jari |
201 |
for(int j = 0; j < newOrder.length; j++) { |
2 |
26 Feb 07 |
jari |
202 |
if(origOrder[i].equals(newOrder[j])) |
2 |
26 Feb 07 |
jari |
203 |
order[j] = i; |
2 |
26 Feb 07 |
jari |
204 |
} |
2 |
26 Feb 07 |
jari |
205 |
} |
2 |
26 Feb 07 |
jari |
206 |
return order; |
2 |
26 Feb 07 |
jari |
207 |
} |
2 |
26 Feb 07 |
jari |
208 |
|
2 |
26 Feb 07 |
jari |
209 |
|
2 |
26 Feb 07 |
jari |
210 |
public boolean isReorderedSelected() { |
2 |
26 Feb 07 |
jari |
211 |
return (this.allowReordering && (this.enableReorderItem.isSelected() || this.enableReorderPopItem.isSelected())); |
2 |
26 Feb 07 |
jari |
212 |
} |
2 |
26 Feb 07 |
jari |
213 |
|
2 |
26 Feb 07 |
jari |
214 |
|
2 |
26 Feb 07 |
jari |
215 |
private JMenuBar createMenuBar(Listener listener) { |
2 |
26 Feb 07 |
jari |
216 |
JMenuBar bar = new JMenuBar(); |
2 |
26 Feb 07 |
jari |
217 |
JMenu editMenu = new JMenu("Edit"); |
2 |
26 Feb 07 |
jari |
218 |
editMenu.setMnemonic('E'); |
2 |
26 Feb 07 |
jari |
219 |
|
2 |
26 Feb 07 |
jari |
220 |
JMenuItem addRowItem = new JMenuItem("Add New Sample Label"); |
2 |
26 Feb 07 |
jari |
221 |
addRowItem.setActionCommand("add-row-command"); |
2 |
26 Feb 07 |
jari |
222 |
addRowItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
223 |
|
2 |
26 Feb 07 |
jari |
224 |
mergeRowsItem = new JMenuItem("Merge Selected Rows"); |
2 |
26 Feb 07 |
jari |
225 |
mergeRowsItem.setActionCommand("merge-rows-command"); |
2 |
26 Feb 07 |
jari |
226 |
mergeRowsItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
227 |
|
2 |
26 Feb 07 |
jari |
228 |
delRowsItem = new JMenuItem("Delete Selected Rows"); |
2 |
26 Feb 07 |
jari |
229 |
delRowsItem.setActionCommand("del-rows-command"); |
2 |
26 Feb 07 |
jari |
230 |
delRowsItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
231 |
|
2 |
26 Feb 07 |
jari |
232 |
enableReorderItem = new JCheckBoxMenuItem("Enable Sample Reordering", false); |
2 |
26 Feb 07 |
jari |
233 |
enableReorderItem.setActionCommand("reorder-command"); |
2 |
26 Feb 07 |
jari |
234 |
enableReorderItem.setEnabled(allowReordering); |
2 |
26 Feb 07 |
jari |
235 |
enableReorderItem.setToolTipText("forces samples to reorder to match table, hit info button"); |
2 |
26 Feb 07 |
jari |
236 |
enableReorderItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
237 |
|
2 |
26 Feb 07 |
jari |
238 |
editMenu.add(addRowItem); |
2 |
26 Feb 07 |
jari |
239 |
editMenu.add(mergeRowsItem); |
2 |
26 Feb 07 |
jari |
240 |
editMenu.add(delRowsItem); |
2 |
26 Feb 07 |
jari |
241 |
editMenu.add(new javax.swing.JSeparator()); |
2 |
26 Feb 07 |
jari |
242 |
editMenu.add(enableReorderItem); |
2 |
26 Feb 07 |
jari |
243 |
|
2 |
26 Feb 07 |
jari |
244 |
bar.add(editMenu); |
2 |
26 Feb 07 |
jari |
245 |
|
2 |
26 Feb 07 |
jari |
246 |
return bar; |
2 |
26 Feb 07 |
jari |
247 |
} |
2 |
26 Feb 07 |
jari |
248 |
|
2 |
26 Feb 07 |
jari |
249 |
|
2 |
26 Feb 07 |
jari |
250 |
private JPopupMenu createPopupMenu(Listener listener) { |
2 |
26 Feb 07 |
jari |
251 |
JPopupMenu popup = new JPopupMenu(); |
2 |
26 Feb 07 |
jari |
252 |
JMenuItem addRowPopItem = new JMenuItem("Add New Sample Label"); |
2 |
26 Feb 07 |
jari |
253 |
addRowPopItem.setActionCommand("add-row-command"); |
2 |
26 Feb 07 |
jari |
254 |
addRowPopItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
255 |
|
2 |
26 Feb 07 |
jari |
256 |
mergeRowsPopItem = new JMenuItem("Merge Selected Rows"); |
2 |
26 Feb 07 |
jari |
257 |
mergeRowsPopItem.setActionCommand("merge-rows-command"); |
2 |
26 Feb 07 |
jari |
258 |
mergeRowsPopItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
259 |
|
2 |
26 Feb 07 |
jari |
260 |
delRowsPopItem = new JMenuItem("Delete Selected Rows"); |
2 |
26 Feb 07 |
jari |
261 |
delRowsPopItem.setActionCommand("del-rows-command"); |
2 |
26 Feb 07 |
jari |
262 |
delRowsPopItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
263 |
|
2 |
26 Feb 07 |
jari |
264 |
enableReorderPopItem = new JCheckBoxMenuItem("Enable Sample Reordering", false); |
2 |
26 Feb 07 |
jari |
265 |
enableReorderPopItem.setActionCommand("reorder-command"); |
2 |
26 Feb 07 |
jari |
266 |
enableReorderPopItem.setEnabled(allowReordering); |
2 |
26 Feb 07 |
jari |
267 |
enableReorderPopItem.setToolTipText("forces samples to reorder to match table, hit info button"); |
2 |
26 Feb 07 |
jari |
268 |
enableReorderPopItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
269 |
|
2 |
26 Feb 07 |
jari |
270 |
popup.add(addRowPopItem); |
2 |
26 Feb 07 |
jari |
271 |
popup.add(mergeRowsPopItem); |
2 |
26 Feb 07 |
jari |
272 |
popup.add(delRowsPopItem); |
2 |
26 Feb 07 |
jari |
273 |
popup.addSeparator(); |
2 |
26 Feb 07 |
jari |
274 |
popup.add(enableReorderPopItem); |
2 |
26 Feb 07 |
jari |
275 |
|
2 |
26 Feb 07 |
jari |
276 |
return popup; |
2 |
26 Feb 07 |
jari |
277 |
} |
2 |
26 Feb 07 |
jari |
278 |
|
2 |
26 Feb 07 |
jari |
279 |
|
2 |
26 Feb 07 |
jari |
280 |
/** |
2 |
26 Feb 07 |
jari |
* Internal Classes |
2 |
26 Feb 07 |
jari |
282 |
* |
2 |
26 Feb 07 |
jari |
283 |
*/ |
2 |
26 Feb 07 |
jari |
284 |
public class DefaultViewerTableModel extends AbstractTableModel implements java.io.Serializable { |
2 |
26 Feb 07 |
jari |
285 |
boolean [] numerical; |
2 |
26 Feb 07 |
jari |
286 |
Row [] rows; |
2 |
26 Feb 07 |
jari |
287 |
int colToSort = 0; |
2 |
26 Feb 07 |
jari |
288 |
boolean ascending = false; |
2 |
26 Feb 07 |
jari |
289 |
int columnCount; |
2 |
26 Feb 07 |
jari |
290 |
IData data; |
2 |
26 Feb 07 |
jari |
291 |
ISlideData slideData; |
2 |
26 Feb 07 |
jari |
292 |
String currKey; |
2 |
26 Feb 07 |
jari |
293 |
String [] columnNames; |
2 |
26 Feb 07 |
jari |
294 |
String [][] dataObject; |
2 |
26 Feb 07 |
jari |
295 |
Vector keys; |
2 |
26 Feb 07 |
jari |
296 |
|
2 |
26 Feb 07 |
jari |
297 |
JTextField valueObject; |
2 |
26 Feb 07 |
jari |
298 |
JLabel label; |
2 |
26 Feb 07 |
jari |
/** This inner class is used to support basic manipulation of the table. |
2 |
26 Feb 07 |
jari |
* The table helps to support ascending and descending row sorting based |
2 |
26 Feb 07 |
jari |
* on numerical or alphabetical column contents. |
2 |
26 Feb 07 |
jari |
* @param headerNames header names |
2 |
26 Feb 07 |
jari |
* @param data data matrix |
2 |
26 Feb 07 |
jari |
304 |
*/ |
2 |
26 Feb 07 |
jari |
305 |
public DefaultViewerTableModel(Vector keys, IData data){ |
2 |
26 Feb 07 |
jari |
306 |
this.data = data; |
2 |
26 Feb 07 |
jari |
307 |
this.keys = keys; |
2 |
26 Feb 07 |
jari |
308 |
columnCount = data.getFeaturesCount() + 1; |
2 |
26 Feb 07 |
jari |
309 |
columnNames = new String[columnCount]; |
2 |
26 Feb 07 |
jari |
310 |
|
2 |
26 Feb 07 |
jari |
//header |
2 |
26 Feb 07 |
jari |
312 |
for(int i = 0; i < columnNames.length; i++) { |
2 |
26 Feb 07 |
jari |
313 |
if(i == 0) |
2 |
26 Feb 07 |
jari |
314 |
columnNames[i] = "Label Key"; |
2 |
26 Feb 07 |
jari |
315 |
else |
2 |
26 Feb 07 |
jari |
316 |
columnNames[i] = String.valueOf(i); |
2 |
26 Feb 07 |
jari |
317 |
} |
2 |
26 Feb 07 |
jari |
318 |
|
2 |
26 Feb 07 |
jari |
//data |
2 |
26 Feb 07 |
jari |
320 |
int sampleCount = data.getFeaturesCount(); |
2 |
26 Feb 07 |
jari |
321 |
int attrCount = keys.size(); |
2 |
26 Feb 07 |
jari |
322 |
String key; |
2 |
26 Feb 07 |
jari |
323 |
String value; |
2 |
26 Feb 07 |
jari |
324 |
dataObject = new String[attrCount][sampleCount+1]; |
2 |
26 Feb 07 |
jari |
325 |
|
2 |
26 Feb 07 |
jari |
326 |
for(int i = 0; i < sampleCount+1; i++) { |
2 |
26 Feb 07 |
jari |
327 |
value = null; |
2 |
26 Feb 07 |
jari |
328 |
for(int j = 0; j < attrCount; j++) { |
2 |
26 Feb 07 |
jari |
329 |
key = (String)(keys.elementAt(j)); |
2 |
26 Feb 07 |
jari |
330 |
if(i == 0) |
2 |
26 Feb 07 |
jari |
331 |
dataObject[j][i] = key; |
2 |
26 Feb 07 |
jari |
332 |
else { |
2 |
26 Feb 07 |
jari |
333 |
slideData = data.getFeature(i-1); |
2 |
26 Feb 07 |
jari |
334 |
value = (String)(slideData.getSlideDataLabels().get(key)); |
2 |
26 Feb 07 |
jari |
335 |
if(value != null) |
2 |
26 Feb 07 |
jari |
336 |
dataObject[j][i] = value; |
2 |
26 Feb 07 |
jari |
337 |
else |
2 |
26 Feb 07 |
jari |
338 |
dataObject[j][i] = " "; |
2 |
26 Feb 07 |
jari |
339 |
} |
2 |
26 Feb 07 |
jari |
340 |
} |
2 |
26 Feb 07 |
jari |
341 |
} |
2 |
26 Feb 07 |
jari |
342 |
rows = new Row[keys.size()]; |
2 |
26 Feb 07 |
jari |
343 |
for(int i = 0; i < rows.length; i++){ |
2 |
26 Feb 07 |
jari |
344 |
rows[i] = new Row(); |
2 |
26 Feb 07 |
jari |
345 |
rows[i].index = i; |
2 |
26 Feb 07 |
jari |
346 |
} |
2 |
26 Feb 07 |
jari |
347 |
valueObject = new JTextField(); |
2 |
26 Feb 07 |
jari |
348 |
valueObject.setOpaque(true); |
2 |
26 Feb 07 |
jari |
349 |
label = new JLabel(); |
2 |
26 Feb 07 |
jari |
350 |
label.setOpaque(true); |
2 |
26 Feb 07 |
jari |
351 |
} |
2 |
26 Feb 07 |
jari |
352 |
|
2 |
26 Feb 07 |
jari |
353 |
public void initializeRows(int rowCount) { |
2 |
26 Feb 07 |
jari |
354 |
rows = new Row[rowCount]; |
2 |
26 Feb 07 |
jari |
355 |
for(int i = 0; i < rows.length; i++){ |
2 |
26 Feb 07 |
jari |
356 |
rows[i] = new Row(); |
2 |
26 Feb 07 |
jari |
357 |
rows[i].index = i; |
2 |
26 Feb 07 |
jari |
358 |
} |
2 |
26 Feb 07 |
jari |
359 |
} |
2 |
26 Feb 07 |
jari |
360 |
|
2 |
26 Feb 07 |
jari |
/** Sets column as numerical for sorting. |
2 |
26 Feb 07 |
jari |
* @param col column index |
2 |
26 Feb 07 |
jari |
* @param numericalBool sets as numerical or not numerical |
2 |
26 Feb 07 |
jari |
364 |
*/ |
2 |
26 Feb 07 |
jari |
365 |
public void setNumerical(int col, boolean numericalBool){ |
2 |
26 Feb 07 |
jari |
366 |
if(col > -1 && col < numerical.length) |
2 |
26 Feb 07 |
jari |
367 |
numerical[col] = numericalBool; |
2 |
26 Feb 07 |
jari |
368 |
} |
2 |
26 Feb 07 |
jari |
369 |
|
2 |
26 Feb 07 |
jari |
370 |
public int getColumnCount() { |
2 |
26 Feb 07 |
jari |
371 |
return columnCount; |
2 |
26 Feb 07 |
jari |
372 |
} |
2 |
26 Feb 07 |
jari |
373 |
|
2 |
26 Feb 07 |
jari |
374 |
public int getRowCount() { |
2 |
26 Feb 07 |
jari |
375 |
return rows.length; |
2 |
26 Feb 07 |
jari |
376 |
} |
2 |
26 Feb 07 |
jari |
377 |
|
2 |
26 Feb 07 |
jari |
378 |
public Object getValueAt(int param, int param1) { |
2 |
26 Feb 07 |
jari |
379 |
return dataObject[param][param1]; |
2 |
26 Feb 07 |
jari |
380 |
} |
2 |
26 Feb 07 |
jari |
381 |
|
2 |
26 Feb 07 |
jari |
382 |
|
2 |
26 Feb 07 |
jari |
383 |
public void setValueAt(Object value, int row, int col) { |
2 |
26 Feb 07 |
jari |
384 |
dataObject[row][col] = (String)value; |
2 |
26 Feb 07 |
jari |
385 |
this.fireTableChanged(new TableModelEvent(this, row, row, col)); |
2 |
26 Feb 07 |
jari |
386 |
} |
2 |
26 Feb 07 |
jari |
387 |
|
2 |
26 Feb 07 |
jari |
388 |
public String getColumnName(int index){ |
2 |
26 Feb 07 |
jari |
389 |
return columnNames[index]; |
2 |
26 Feb 07 |
jari |
390 |
} |
2 |
26 Feb 07 |
jari |
391 |
|
2 |
26 Feb 07 |
jari |
392 |
private boolean isNumerical(int col){ |
2 |
26 Feb 07 |
jari |
393 |
return numerical[col]; |
2 |
26 Feb 07 |
jari |
394 |
} |
2 |
26 Feb 07 |
jari |
395 |
|
2 |
26 Feb 07 |
jari |
396 |
public void sort(int col){ |
2 |
26 Feb 07 |
jari |
397 |
ascending = !ascending; |
2 |
26 Feb 07 |
jari |
398 |
colToSort = col; |
2 |
26 Feb 07 |
jari |
399 |
Arrays.sort(rows); |
2 |
26 Feb 07 |
jari |
400 |
fireTableDataChanged(); |
2 |
26 Feb 07 |
jari |
401 |
} |
2 |
26 Feb 07 |
jari |
402 |
|
2 |
26 Feb 07 |
jari |
403 |
public int getRow(int tableRow){ |
2 |
26 Feb 07 |
jari |
404 |
return rows[tableRow].index; |
2 |
26 Feb 07 |
jari |
405 |
} |
2 |
26 Feb 07 |
jari |
406 |
|
2 |
26 Feb 07 |
jari |
407 |
public boolean isCellEditable(int row, int col) { |
2 |
26 Feb 07 |
jari |
408 |
return (row > 0); |
2 |
26 Feb 07 |
jari |
409 |
} |
2 |
26 Feb 07 |
jari |
410 |
|
2 |
26 Feb 07 |
jari |
411 |
private class Row implements Comparable, java.io.Serializable { |
2 |
26 Feb 07 |
jari |
412 |
public int index; |
2 |
26 Feb 07 |
jari |
413 |
private String myString, otherString; |
2 |
26 Feb 07 |
jari |
414 |
|
2 |
26 Feb 07 |
jari |
415 |
public int compareTo(Object other){ |
2 |
26 Feb 07 |
jari |
416 |
if(ascending) |
2 |
26 Feb 07 |
jari |
417 |
return compareToOther(other); |
2 |
26 Feb 07 |
jari |
418 |
return compareToOther(other)*(-1); |
2 |
26 Feb 07 |
jari |
419 |
} |
2 |
26 Feb 07 |
jari |
420 |
|
2 |
26 Feb 07 |
jari |
421 |
public int compareToOther(Object other){ |
2 |
26 Feb 07 |
jari |
422 |
Row otherRow = (Row)other; |
2 |
26 Feb 07 |
jari |
423 |
Object myObject = getValueAt(index, colToSort); |
2 |
26 Feb 07 |
jari |
424 |
Object otherObject = getValueAt(otherRow.index, colToSort); |
2 |
26 Feb 07 |
jari |
425 |
if( myObject instanceof Comparable ) { |
2 |
26 Feb 07 |
jari |
426 |
if(isNumerical(colToSort)){ //catch string designation of a number |
2 |
26 Feb 07 |
jari |
427 |
if(myObject instanceof String){ |
2 |
26 Feb 07 |
jari |
428 |
Float myFloat = new Float((String)myObject); |
2 |
26 Feb 07 |
jari |
429 |
Float otherFloat = new Float((String)otherObject); |
2 |
26 Feb 07 |
jari |
430 |
return myFloat.compareTo(otherFloat); |
2 |
26 Feb 07 |
jari |
431 |
} |
2 |
26 Feb 07 |
jari |
432 |
} |
2 |
26 Feb 07 |
jari |
433 |
return ((Comparable)myObject).compareTo(otherObject); |
2 |
26 Feb 07 |
jari |
434 |
} |
2 |
26 Feb 07 |
jari |
435 |
if(myObject instanceof JLabel){ |
2 |
26 Feb 07 |
jari |
436 |
myString = ((JLabel)(myObject)).getText(); |
2 |
26 Feb 07 |
jari |
437 |
otherString = ((JLabel)(otherObject)).getText(); |
2 |
26 Feb 07 |
jari |
438 |
return myString.compareTo(otherString); |
2 |
26 Feb 07 |
jari |
439 |
} |
2 |
26 Feb 07 |
jari |
440 |
else return index - otherRow.index; |
2 |
26 Feb 07 |
jari |
441 |
} |
2 |
26 Feb 07 |
jari |
442 |
} |
2 |
26 Feb 07 |
jari |
443 |
|
2 |
26 Feb 07 |
jari |
444 |
public void addNewRow() { |
2 |
26 Feb 07 |
jari |
445 |
String [][] newData = new String[dataObject.length+1][columnCount]; |
2 |
26 Feb 07 |
jari |
446 |
for(int i = 0; i < newData.length-1; i++) { |
2 |
26 Feb 07 |
jari |
447 |
newData[i] = dataObject[i]; |
2 |
26 Feb 07 |
jari |
448 |
} |
2 |
26 Feb 07 |
jari |
//might have to fill row data with " " ? |
2 |
26 Feb 07 |
jari |
450 |
dataObject = newData; |
2 |
26 Feb 07 |
jari |
451 |
initializeRows(dataObject.length); |
2 |
26 Feb 07 |
jari |
452 |
for(int i = 0; i < columnCount; i++) { |
2 |
26 Feb 07 |
jari |
453 |
dataObject[dataObject.length-1][i] = ""; |
2 |
26 Feb 07 |
jari |
454 |
} |
2 |
26 Feb 07 |
jari |
//fireTableDataChanged(); |
2 |
26 Feb 07 |
jari |
456 |
fireTableRowsInserted(dataObject.length-1, dataObject.length-1); |
2 |
26 Feb 07 |
jari |
457 |
} |
2 |
26 Feb 07 |
jari |
458 |
|
2 |
26 Feb 07 |
jari |
459 |
public void addNewRow(String [] newRow) { |
2 |
26 Feb 07 |
jari |
460 |
String [][] newData = new String[dataObject.length+1][columnCount]; |
2 |
26 Feb 07 |
jari |
461 |
for(int i = 0; i < newData.length-1; i++) { |
2 |
26 Feb 07 |
jari |
462 |
newData[i] = dataObject[i]; |
2 |
26 Feb 07 |
jari |
463 |
} |
2 |
26 Feb 07 |
jari |
//might have to fill row data with " " ? |
2 |
26 Feb 07 |
jari |
465 |
dataObject = newData; |
2 |
26 Feb 07 |
jari |
466 |
initializeRows(dataObject.length); |
2 |
26 Feb 07 |
jari |
467 |
|
2 |
26 Feb 07 |
jari |
//set new data |
2 |
26 Feb 07 |
jari |
469 |
dataObject[dataObject.length-1] = newRow; |
2 |
26 Feb 07 |
jari |
470 |
|
2 |
26 Feb 07 |
jari |
//fireTableDataChanged(); |
2 |
26 Feb 07 |
jari |
472 |
fireTableRowsInserted(dataObject.length-1, dataObject.length-1); |
2 |
26 Feb 07 |
jari |
473 |
} |
2 |
26 Feb 07 |
jari |
474 |
|
2 |
26 Feb 07 |
jari |
475 |
|
2 |
26 Feb 07 |
jari |
476 |
public void mergeRows(int [] rowsToMerge) { |
2 |
26 Feb 07 |
jari |
//get keys |
2 |
26 Feb 07 |
jari |
478 |
Vector keysToMerge = new Vector(); |
2 |
26 Feb 07 |
jari |
479 |
for(int i = 0; i < rowsToMerge.length; i++) { |
2 |
26 Feb 07 |
jari |
480 |
keysToMerge.addElement(dataObject[rowsToMerge[i]][0]); |
2 |
26 Feb 07 |
jari |
481 |
} |
2 |
26 Feb 07 |
jari |
482 |
|
2 |
26 Feb 07 |
jari |
//present keys in list to order |
2 |
26 Feb 07 |
jari |
484 |
JList keyOrderList = new JList(keysToMerge); |
2 |
26 Feb 07 |
jari |
485 |
keyOrderList.setSelectedIndex(0); |
2 |
26 Feb 07 |
jari |
486 |
|
2 |
26 Feb 07 |
jari |
487 |
ListOrderDialog dialog = new ListOrderDialog(parent, keyOrderList, keysToMerge, "Sample Label Keys", " "); |
2 |
26 Feb 07 |
jari |
488 |
|
2 |
26 Feb 07 |
jari |
489 |
if(dialog.showModal() != JOptionPane.OK_OPTION) |
2 |
26 Feb 07 |
jari |
490 |
return; |
2 |
26 Feb 07 |
jari |
491 |
|
2 |
26 Feb 07 |
jari |
492 |
keysToMerge = dialog.getSortedVector(); |
2 |
26 Feb 07 |
jari |
493 |
|
2 |
26 Feb 07 |
jari |
//merge data in order within the new row data |
2 |
26 Feb 07 |
jari |
495 |
String [] newRow = new String[table.getColumnCount()]; |
2 |
26 Feb 07 |
jari |
496 |
|
2 |
26 Feb 07 |
jari |
497 |
for(int i=0; i < newRow.length; i++) { |
2 |
26 Feb 07 |
jari |
498 |
newRow[i] = (String)(getMergedData(keysToMerge, i)); |
2 |
26 Feb 07 |
jari |
499 |
} |
2 |
26 Feb 07 |
jari |
//append row |
2 |
26 Feb 07 |
jari |
501 |
addNewRow(newRow); |
2 |
26 Feb 07 |
jari |
502 |
} |
2 |
26 Feb 07 |
jari |
503 |
|
2 |
26 Feb 07 |
jari |
504 |
public Object getMergedData(Vector keys, int col) { |
2 |
26 Feb 07 |
jari |
505 |
String mergedData = ""; |
2 |
26 Feb 07 |
jari |
506 |
for(int i = 0 ; i < keys.size(); i++) { |
2 |
26 Feb 07 |
jari |
507 |
if(i == 0) |
2 |
26 Feb 07 |
jari |
508 |
mergedData += getDataForKey((String)(keys.elementAt(i)), col); |
2 |
26 Feb 07 |
jari |
509 |
else |
2 |
26 Feb 07 |
jari |
510 |
mergedData += "-"+getDataForKey((String)(keys.elementAt(i)), col); |
2 |
26 Feb 07 |
jari |
511 |
} |
2 |
26 Feb 07 |
jari |
512 |
return mergedData; |
2 |
26 Feb 07 |
jari |
513 |
} |
2 |
26 Feb 07 |
jari |
514 |
|
2 |
26 Feb 07 |
jari |
515 |
public Object getDataForKey(String key, int col) { |
2 |
26 Feb 07 |
jari |
516 |
for(int i = 0 ; i < dataObject.length; i++) { |
2 |
26 Feb 07 |
jari |
517 |
if(dataObject[i][0].equals(key)) |
2 |
26 Feb 07 |
jari |
518 |
return dataObject[i][col]; |
2 |
26 Feb 07 |
jari |
519 |
} |
2 |
26 Feb 07 |
jari |
520 |
return " "; |
2 |
26 Feb 07 |
jari |
521 |
} |
2 |
26 Feb 07 |
jari |
522 |
|
2 |
26 Feb 07 |
jari |
523 |
public void deleteRows(int [] selectedRows) { |
2 |
26 Feb 07 |
jari |
524 |
boolean [] delRows = new boolean[dataObject.length]; |
2 |
26 Feb 07 |
jari |
525 |
int rowsToDelete = 0; |
2 |
26 Feb 07 |
jari |
526 |
|
2 |
26 Feb 07 |
jari |
527 |
for(int i = 0 ; i < selectedRows.length; i++) { |
2 |
26 Feb 07 |
jari |
528 |
if(selectedRows[i] != 0) { //protect the primary label |
2 |
26 Feb 07 |
jari |
529 |
delRows[selectedRows[i]] = true; |
2 |
26 Feb 07 |
jari |
530 |
rowsToDelete++; |
2 |
26 Feb 07 |
jari |
531 |
} |
2 |
26 Feb 07 |
jari |
532 |
} |
2 |
26 Feb 07 |
jari |
533 |
|
2 |
26 Feb 07 |
jari |
534 |
String [][] newData = new String[dataObject.length-rowsToDelete][]; |
2 |
26 Feb 07 |
jari |
535 |
int newRowCnt = 0; |
2 |
26 Feb 07 |
jari |
536 |
for(int i = 0; i < dataObject.length; i++) { |
2 |
26 Feb 07 |
jari |
537 |
if(delRows[i] == false) { |
2 |
26 Feb 07 |
jari |
538 |
newData[newRowCnt] = dataObject[i]; |
2 |
26 Feb 07 |
jari |
539 |
newRowCnt++; |
2 |
26 Feb 07 |
jari |
540 |
} |
2 |
26 Feb 07 |
jari |
541 |
} |
2 |
26 Feb 07 |
jari |
542 |
initializeRows(newData.length); |
2 |
26 Feb 07 |
jari |
543 |
dataObject = newData; |
2 |
26 Feb 07 |
jari |
544 |
fireTableDataChanged(); |
2 |
26 Feb 07 |
jari |
545 |
} |
2 |
26 Feb 07 |
jari |
546 |
|
2 |
26 Feb 07 |
jari |
547 |
|
2 |
26 Feb 07 |
jari |
548 |
} |
2 |
26 Feb 07 |
jari |
549 |
|
2 |
26 Feb 07 |
jari |
550 |
public class CellRenderer extends DefaultTableCellRenderer { |
2 |
26 Feb 07 |
jari |
551 |
|
2 |
26 Feb 07 |
jari |
552 |
JPanel colorPanel; |
2 |
26 Feb 07 |
jari |
553 |
JLabel label; |
2 |
26 Feb 07 |
jari |
554 |
JTextField textField; |
2 |
26 Feb 07 |
jari |
555 |
|
2 |
26 Feb 07 |
jari |
556 |
public CellRenderer() { |
2 |
26 Feb 07 |
jari |
557 |
textField = new JTextField(); |
2 |
26 Feb 07 |
jari |
558 |
textField.setOpaque(true); |
2 |
26 Feb 07 |
jari |
559 |
colorPanel = new JPanel(); |
2 |
26 Feb 07 |
jari |
560 |
} |
2 |
26 Feb 07 |
jari |
561 |
|
2 |
26 Feb 07 |
jari |
/** Renders basic data input types JLabel, Color, |
2 |
26 Feb 07 |
jari |
563 |
*/ |
2 |
26 Feb 07 |
jari |
564 |
public Component getTableCellRendererComponent(JTable jTable, Object obj, boolean param, boolean param3, int row, int col) { |
2 |
26 Feb 07 |
jari |
565 |
if(obj instanceof Color){ |
2 |
26 Feb 07 |
jari |
566 |
colorPanel.setBackground((Color)obj); |
2 |
26 Feb 07 |
jari |
567 |
return colorPanel; |
2 |
26 Feb 07 |
jari |
568 |
} else if(obj instanceof JLabel){ |
2 |
26 Feb 07 |
jari |
569 |
label = (JLabel)obj; |
2 |
26 Feb 07 |
jari |
570 |
label.setOpaque(true); |
2 |
26 Feb 07 |
jari |
571 |
label.setFont(new Font("Arial", Font.PLAIN, 12)); |
2 |
26 Feb 07 |
jari |
572 |
if(row == 0 || col == 0) |
2 |
26 Feb 07 |
jari |
573 |
label.setBackground(Color.lightGray); |
2 |
26 Feb 07 |
jari |
574 |
else |
2 |
26 Feb 07 |
jari |
575 |
label.setBackground(new Color(225, 225, 225)); |
2 |
26 Feb 07 |
jari |
576 |
|
2 |
26 Feb 07 |
jari |
577 |
label.setForeground(Color.black); |
2 |
26 Feb 07 |
jari |
578 |
label.setHorizontalAlignment(JLabel.CENTER); |
2 |
26 Feb 07 |
jari |
579 |
if(table.isRowSelected(row) && row != 0) |
2 |
26 Feb 07 |
jari |
580 |
label.setBackground(table.getSelectionBackground()); |
2 |
26 Feb 07 |
jari |
581 |
return label; |
2 |
26 Feb 07 |
jari |
582 |
} else if(obj instanceof JTextField){ |
2 |
26 Feb 07 |
jari |
583 |
textField = (JTextField)obj; |
2 |
26 Feb 07 |
jari |
584 |
|
2 |
26 Feb 07 |
jari |
585 |
if(row == 0) { |
2 |
26 Feb 07 |
jari |
586 |
textField.setEditable(false); |
2 |
26 Feb 07 |
jari |
587 |
textField.setBackground(Color.lightGray); |
2 |
26 Feb 07 |
jari |
588 |
} else if(col == 0) { |
2 |
26 Feb 07 |
jari |
589 |
textField.setEditable(true); |
2 |
26 Feb 07 |
jari |
590 |
textField.setBackground(new Color(255,255,155)); |
2 |
26 Feb 07 |
jari |
591 |
} else { |
2 |
26 Feb 07 |
jari |
592 |
textField.setEditable(true); |
2 |
26 Feb 07 |
jari |
593 |
textField.setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
594 |
} |
2 |
26 Feb 07 |
jari |
595 |
if(table.isRowSelected(row) && row != 0) |
2 |
26 Feb 07 |
jari |
596 |
textField.setBackground(table.getSelectionBackground()); |
2 |
26 Feb 07 |
jari |
597 |
|
2 |
26 Feb 07 |
jari |
598 |
return textField; |
2 |
26 Feb 07 |
jari |
599 |
|
2 |
26 Feb 07 |
jari |
600 |
} else if(obj instanceof String) { |
2 |
26 Feb 07 |
jari |
601 |
textField.setText((String)obj); |
2 |
26 Feb 07 |
jari |
602 |
if(row == 0) { |
2 |
26 Feb 07 |
jari |
603 |
textField.setEditable(false); |
2 |
26 Feb 07 |
jari |
604 |
textField.setBackground(Color.lightGray); |
2 |
26 Feb 07 |
jari |
605 |
} else if(col == 0) { |
2 |
26 Feb 07 |
jari |
606 |
textField.setEditable(true); |
2 |
26 Feb 07 |
jari |
607 |
textField.setBackground(new Color(255,255,155)); |
2 |
26 Feb 07 |
jari |
608 |
} else { |
2 |
26 Feb 07 |
jari |
609 |
textField.setEditable(true); |
2 |
26 Feb 07 |
jari |
610 |
textField.setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
611 |
} |
2 |
26 Feb 07 |
jari |
612 |
|
2 |
26 Feb 07 |
jari |
613 |
if(table.isRowSelected(row) && row != 0) |
2 |
26 Feb 07 |
jari |
614 |
textField.setBackground(table.getSelectionBackground()); |
2 |
26 Feb 07 |
jari |
615 |
|
2 |
26 Feb 07 |
jari |
616 |
return textField; |
2 |
26 Feb 07 |
jari |
617 |
} |
2 |
26 Feb 07 |
jari |
618 |
colorPanel.setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
619 |
return colorPanel; |
2 |
26 Feb 07 |
jari |
620 |
} |
2 |
26 Feb 07 |
jari |
621 |
} |
2 |
26 Feb 07 |
jari |
622 |
|
2 |
26 Feb 07 |
jari |
623 |
public class CellEditor extends AbstractCellEditor implements TableCellEditor, ActionListener { |
2 |
26 Feb 07 |
jari |
624 |
|
2 |
26 Feb 07 |
jari |
625 |
JTextField field; |
2 |
26 Feb 07 |
jari |
626 |
String value; |
2 |
26 Feb 07 |
jari |
627 |
public CellEditor() { |
2 |
26 Feb 07 |
jari |
628 |
field = new JTextField(); |
2 |
26 Feb 07 |
jari |
629 |
field.setBackground(new Color(222,222,222)); |
2 |
26 Feb 07 |
jari |
630 |
} |
2 |
26 Feb 07 |
jari |
631 |
|
2 |
26 Feb 07 |
jari |
632 |
public Object getCellEditorValue() { |
2 |
26 Feb 07 |
jari |
633 |
return field; |
2 |
26 Feb 07 |
jari |
634 |
} |
2 |
26 Feb 07 |
jari |
635 |
|
2 |
26 Feb 07 |
jari |
636 |
public void actionPerformed(java.awt.event.ActionEvent actionEvent) { |
2 |
26 Feb 07 |
jari |
637 |
value = field.getText(); |
2 |
26 Feb 07 |
jari |
638 |
this.fireEditingStopped(); |
2 |
26 Feb 07 |
jari |
639 |
} |
2 |
26 Feb 07 |
jari |
640 |
|
2 |
26 Feb 07 |
jari |
641 |
public java.awt.Component getTableCellEditorComponent(javax.swing.JTable jTable, Object obj, boolean selected, int row, int col) { |
2 |
26 Feb 07 |
jari |
642 |
field = (JTextField)obj; |
2 |
26 Feb 07 |
jari |
643 |
return (JTextField)obj; |
2 |
26 Feb 07 |
jari |
644 |
} |
2 |
26 Feb 07 |
jari |
645 |
|
2 |
26 Feb 07 |
jari |
646 |
} |
2 |
26 Feb 07 |
jari |
647 |
|
2 |
26 Feb 07 |
jari |
648 |
private class Listener extends MouseAdapter implements ActionListener { |
2 |
26 Feb 07 |
jari |
649 |
|
2 |
26 Feb 07 |
jari |
650 |
public void actionPerformed(ActionEvent ae) { |
2 |
26 Feb 07 |
jari |
651 |
String command = ae.getActionCommand(); |
2 |
26 Feb 07 |
jari |
//menu actions |
2 |
26 Feb 07 |
jari |
653 |
if(command.equals("add-row-command")) { |
2 |
26 Feb 07 |
jari |
654 |
model.addNewRow(); |
2 |
26 Feb 07 |
jari |
655 |
} else if(command.equals("merge-rows-command")) { |
2 |
26 Feb 07 |
jari |
656 |
int [] selectedRows = table.getSelectedRows(); |
2 |
26 Feb 07 |
jari |
657 |
if(selectedRows.length < 2) |
2 |
26 Feb 07 |
jari |
658 |
return; |
2 |
26 Feb 07 |
jari |
659 |
model.mergeRows(selectedRows); |
2 |
26 Feb 07 |
jari |
660 |
} else if(command.equals("del-rows-command")) { |
2 |
26 Feb 07 |
jari |
661 |
int [] selectedRows = table.getSelectedRows(); |
2 |
26 Feb 07 |
jari |
662 |
if(selectedRows.length < 1) |
2 |
26 Feb 07 |
jari |
663 |
return; |
2 |
26 Feb 07 |
jari |
664 |
model.deleteRows(selectedRows); |
2 |
26 Feb 07 |
jari |
665 |
} else if( allowReordering && command.equals("reorder-command")) { |
2 |
26 Feb 07 |
jari |
666 |
if(ae.getSource() == enableReorderItem) |
2 |
26 Feb 07 |
jari |
667 |
enableReorderPopItem.setSelected(enableReorderItem.isSelected()); |
2 |
26 Feb 07 |
jari |
668 |
else |
2 |
26 Feb 07 |
jari |
669 |
enableReorderItem.setSelected(enableReorderPopItem.isSelected()); |
2 |
26 Feb 07 |
jari |
670 |
} |
2 |
26 Feb 07 |
jari |
671 |
|
2 |
26 Feb 07 |
jari |
//Dialog level commands |
2 |
26 Feb 07 |
jari |
673 |
else if(command.equals("ok-command")) { |
2 |
26 Feb 07 |
jari |
674 |
if(table.isEditing()) { |
2 |
26 Feb 07 |
jari |
675 |
String value = ((JTextField)table.getEditorComponent()).getText(); |
2 |
26 Feb 07 |
jari |
676 |
table.setValueAt(value, table.getEditingRow(), table.getEditingColumn()); |
2 |
26 Feb 07 |
jari |
677 |
} |
2 |
26 Feb 07 |
jari |
678 |
result = JOptionPane.OK_OPTION; |
2 |
26 Feb 07 |
jari |
679 |
dispose(); |
2 |
26 Feb 07 |
jari |
680 |
} else if(command.equals("cancel-command")) { |
2 |
26 Feb 07 |
jari |
681 |
result = JOptionPane.CANCEL_OPTION; |
2 |
26 Feb 07 |
jari |
682 |
dispose(); |
2 |
26 Feb 07 |
jari |
683 |
} else if(command.equals("info-command")) { |
2 |
26 Feb 07 |
jari |
684 |
HelpWindow hw = new HelpWindow(ExperimentLabelEditor.this, "Experiment Label Editor"); |
2 |
26 Feb 07 |
jari |
685 |
result = JOptionPane.CANCEL_OPTION; |
2 |
26 Feb 07 |
jari |
686 |
if(hw.getWindowContent()){ |
2 |
26 Feb 07 |
jari |
687 |
hw.setSize(550,600); |
2 |
26 Feb 07 |
jari |
688 |
hw.setLocation(); |
2 |
26 Feb 07 |
jari |
689 |
hw.show(); |
2 |
26 Feb 07 |
jari |
690 |
} |
2 |
26 Feb 07 |
jari |
691 |
else { |
2 |
26 Feb 07 |
jari |
692 |
hw.setVisible(false); |
2 |
26 Feb 07 |
jari |
693 |
hw.dispose(); |
2 |
26 Feb 07 |
jari |
694 |
} |
2 |
26 Feb 07 |
jari |
695 |
} |
2 |
26 Feb 07 |
jari |
696 |
|
2 |
26 Feb 07 |
jari |
697 |
} |
2 |
26 Feb 07 |
jari |
698 |
|
2 |
26 Feb 07 |
jari |
699 |
public void mousePressed(MouseEvent me) { |
2 |
26 Feb 07 |
jari |
700 |
if(me.isPopupTrigger()) { |
2 |
26 Feb 07 |
jari |
701 |
popup.show(table, me.getX(), me.getY()); |
2 |
26 Feb 07 |
jari |
702 |
return; |
2 |
26 Feb 07 |
jari |
703 |
} |
2 |
26 Feb 07 |
jari |
704 |
|
2 |
26 Feb 07 |
jari |
//table.getSelectedRows(); |
2 |
26 Feb 07 |
jari |
//table.getSelected |
2 |
26 Feb 07 |
jari |
707 |
|
2 |
26 Feb 07 |
jari |
708 |
|
2 |
26 Feb 07 |
jari |
709 |
} |
2 |
26 Feb 07 |
jari |
710 |
|
2 |
26 Feb 07 |
jari |
711 |
public void mouseReleased(MouseEvent me) { |
2 |
26 Feb 07 |
jari |
712 |
if(me.isPopupTrigger()) { |
2 |
26 Feb 07 |
jari |
713 |
popup.show(table, me.getX(), me.getY()); |
2 |
26 Feb 07 |
jari |
714 |
return; |
2 |
26 Feb 07 |
jari |
715 |
} |
2 |
26 Feb 07 |
jari |
716 |
if(table.getSelectedRowCount() > 1) { |
2 |
26 Feb 07 |
jari |
717 |
mergeRowsItem.setEnabled(true); |
2 |
26 Feb 07 |
jari |
718 |
mergeRowsPopItem.setEnabled(true); |
2 |
26 Feb 07 |
jari |
719 |
} else { |
2 |
26 Feb 07 |
jari |
720 |
mergeRowsItem.setEnabled(false); |
2 |
26 Feb 07 |
jari |
721 |
mergeRowsPopItem.setEnabled(false); |
2 |
26 Feb 07 |
jari |
722 |
} |
2 |
26 Feb 07 |
jari |
723 |
if(table.getSelectedRowCount() > 0) { |
2 |
26 Feb 07 |
jari |
724 |
delRowsItem.setEnabled(true); |
2 |
26 Feb 07 |
jari |
725 |
delRowsPopItem.setEnabled(true); |
2 |
26 Feb 07 |
jari |
726 |
} else { |
2 |
26 Feb 07 |
jari |
727 |
delRowsItem.setEnabled(false); |
2 |
26 Feb 07 |
jari |
728 |
delRowsPopItem.setEnabled(false); |
2 |
26 Feb 07 |
jari |
729 |
} |
2 |
26 Feb 07 |
jari |
730 |
} |
2 |
26 Feb 07 |
jari |
731 |
|
2 |
26 Feb 07 |
jari |
732 |
} |
2 |
26 Feb 07 |
jari |
733 |
/* |
2 |
26 Feb 07 |
jari |
private class CellEditor implements javax.swing.table.TableCellEditor { |
2 |
26 Feb 07 |
jari |
735 |
|
2 |
26 Feb 07 |
jari |
public void addCellEditorListener(javax.swing.event.CellEditorListener cellEditorListener) { |
2 |
26 Feb 07 |
jari |
737 |
} |
2 |
26 Feb 07 |
jari |
738 |
|
2 |
26 Feb 07 |
jari |
public void cancelCellEditing() { |
2 |
26 Feb 07 |
jari |
740 |
} |
2 |
26 Feb 07 |
jari |
741 |
|
2 |
26 Feb 07 |
jari |
public Object getCellEditorValue() { |
2 |
26 Feb 07 |
jari |
743 |
} |
2 |
26 Feb 07 |
jari |
744 |
|
2 |
26 Feb 07 |
jari |
public java.awt.Component getTableCellEditorComponent(javax.swing.JTable jTable, Object obj, boolean param, int param3, int param4) { |
2 |
26 Feb 07 |
jari |
746 |
} |
2 |
26 Feb 07 |
jari |
747 |
|
2 |
26 Feb 07 |
jari |
public boolean isCellEditable(java.util.EventObject eventObject) { |
2 |
26 Feb 07 |
jari |
749 |
} |
2 |
26 Feb 07 |
jari |
750 |
|
2 |
26 Feb 07 |
jari |
public void removeCellEditorListener(javax.swing.event.CellEditorListener cellEditorListener) { |
2 |
26 Feb 07 |
jari |
752 |
} |
2 |
26 Feb 07 |
jari |
753 |
|
2 |
26 Feb 07 |
jari |
public boolean shouldSelectCell(java.util.EventObject eventObject) { |
2 |
26 Feb 07 |
jari |
755 |
} |
2 |
26 Feb 07 |
jari |
756 |
|
2 |
26 Feb 07 |
jari |
public boolean stopCellEditing() { |
2 |
26 Feb 07 |
jari |
758 |
} |
2 |
26 Feb 07 |
jari |
759 |
|
2 |
26 Feb 07 |
jari |
760 |
} |
2 |
26 Feb 07 |
jari |
761 |
**/ |
2 |
26 Feb 07 |
jari |
762 |
|
2 |
26 Feb 07 |
jari |
763 |
} |