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 |
* $RCSfile: ClusterBrowser.java,v $ |
2 |
26 Feb 07 |
jari |
* $Revision: 1.8 $ |
2 |
26 Feb 07 |
jari |
* $Date: 2006/02/23 20:59:48 $ |
2 |
26 Feb 07 |
jari |
* $Author: caliente $ |
2 |
26 Feb 07 |
jari |
* $State: Exp $ |
2 |
26 Feb 07 |
jari |
11 |
*/ |
2 |
26 Feb 07 |
jari |
12 |
/* |
2 |
26 Feb 07 |
jari |
* ClusterBrowser.java |
2 |
26 Feb 07 |
jari |
14 |
* |
2 |
26 Feb 07 |
jari |
* Created on August 25, 2003, 11:51 AM |
2 |
26 Feb 07 |
jari |
16 |
*/ |
2 |
26 Feb 07 |
jari |
17 |
package org.tigr.microarray.mev.cluster.gui.helpers; |
2 |
26 Feb 07 |
jari |
18 |
|
2 |
26 Feb 07 |
jari |
19 |
import java.awt.Color; |
2 |
26 Feb 07 |
jari |
20 |
import java.awt.Dimension; |
2 |
26 Feb 07 |
jari |
21 |
import java.awt.Font; |
2 |
26 Feb 07 |
jari |
22 |
import java.awt.GridBagConstraints; |
2 |
26 Feb 07 |
jari |
23 |
import java.awt.GridBagLayout; |
2 |
26 Feb 07 |
jari |
24 |
import java.awt.Insets; |
2 |
26 Feb 07 |
jari |
25 |
import java.awt.event.MouseAdapter; |
2 |
26 Feb 07 |
jari |
26 |
import java.awt.event.MouseEvent; |
2 |
26 Feb 07 |
jari |
27 |
import java.util.Arrays; |
2 |
26 Feb 07 |
jari |
28 |
import java.util.Vector; |
2 |
26 Feb 07 |
jari |
29 |
|
2 |
26 Feb 07 |
jari |
30 |
import javax.swing.BorderFactory; |
2 |
26 Feb 07 |
jari |
31 |
import javax.swing.JLabel; |
2 |
26 Feb 07 |
jari |
32 |
import javax.swing.JPanel; |
2 |
26 Feb 07 |
jari |
33 |
import javax.swing.JScrollPane; |
2 |
26 Feb 07 |
jari |
34 |
import javax.swing.JTable; |
2 |
26 Feb 07 |
jari |
35 |
import javax.swing.JTextArea; |
2 |
26 Feb 07 |
jari |
36 |
import javax.swing.ListSelectionModel; |
2 |
26 Feb 07 |
jari |
37 |
import javax.swing.border.BevelBorder; |
2 |
26 Feb 07 |
jari |
38 |
import javax.swing.border.EtchedBorder; |
2 |
26 Feb 07 |
jari |
39 |
import javax.swing.border.TitledBorder; |
2 |
26 Feb 07 |
jari |
40 |
import javax.swing.event.TableModelEvent; |
2 |
26 Feb 07 |
jari |
41 |
import javax.swing.event.TableModelListener; |
2 |
26 Feb 07 |
jari |
42 |
import javax.swing.table.AbstractTableModel; |
2 |
26 Feb 07 |
jari |
43 |
import javax.swing.table.TableCellRenderer; |
2 |
26 Feb 07 |
jari |
44 |
import javax.swing.table.TableColumn; |
2 |
26 Feb 07 |
jari |
45 |
|
2 |
26 Feb 07 |
jari |
46 |
import org.tigr.graph.GraphCanvas; |
2 |
26 Feb 07 |
jari |
47 |
import org.tigr.graph.GraphLine; |
2 |
26 Feb 07 |
jari |
48 |
import org.tigr.microarray.mev.cluster.clusterUtil.Cluster; |
2 |
26 Feb 07 |
jari |
49 |
import org.tigr.microarray.mev.cluster.clusterUtil.ClusterList; |
2 |
26 Feb 07 |
jari |
50 |
import org.tigr.microarray.mev.cluster.clusterUtil.ClusterRepository; |
2 |
26 Feb 07 |
jari |
51 |
import org.tigr.util.FloatMatrix; |
2 |
26 Feb 07 |
jari |
52 |
|
2 |
26 Feb 07 |
jari |
53 |
/** |
2 |
26 Feb 07 |
jari |
* @author braisted |
2 |
26 Feb 07 |
jari |
55 |
*/ |
2 |
26 Feb 07 |
jari |
56 |
public class ClusterBrowser extends JPanel { |
2 |
26 Feb 07 |
jari |
57 |
|
2 |
26 Feb 07 |
jari |
58 |
JTable table; |
2 |
26 Feb 07 |
jari |
59 |
ClusterRepository repository; |
2 |
26 Feb 07 |
jari |
60 |
JScrollPane pane; |
2 |
26 Feb 07 |
jari |
61 |
String clusterTypeStr = "Gene"; |
2 |
26 Feb 07 |
jari |
62 |
ClusterTableModel model; |
2 |
26 Feb 07 |
jari |
63 |
GraphCanvas profileDisplayPanel; |
2 |
26 Feb 07 |
jari |
64 |
FloatMatrix matrix; |
2 |
26 Feb 07 |
jari |
65 |
|
2 |
26 Feb 07 |
jari |
/** Creates a new instance of ClusterBrowser */ |
2 |
26 Feb 07 |
jari |
67 |
public ClusterBrowser(ClusterRepository repository) { |
2 |
26 Feb 07 |
jari |
68 |
this.repository = repository; |
2 |
26 Feb 07 |
jari |
69 |
|
2 |
26 Feb 07 |
jari |
70 |
if(repository == null){ |
2 |
26 Feb 07 |
jari |
71 |
add(new JLabel("Empty Cluster Repository"), java.awt.BorderLayout.CENTER); |
2 |
26 Feb 07 |
jari |
72 |
return; |
2 |
26 Feb 07 |
jari |
73 |
} |
2 |
26 Feb 07 |
jari |
74 |
|
2 |
26 Feb 07 |
jari |
75 |
if(!repository.isGeneClusterRepository()){ |
2 |
26 Feb 07 |
jari |
76 |
clusterTypeStr = "Sample"; |
2 |
26 Feb 07 |
jari |
77 |
} |
2 |
26 Feb 07 |
jari |
78 |
|
2 |
26 Feb 07 |
jari |
79 |
Font font = new Font("Dialog", Font.BOLD, 12); |
2 |
26 Feb 07 |
jari |
80 |
JPanel tablePanel = new JPanel(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
81 |
tablePanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), clusterTypeStr+" Clusters", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, font, Color.black)); |
2 |
26 Feb 07 |
jari |
82 |
tablePanel.add(initializeTable(), new GridBagConstraints(0,0,1,1,1.0,1.0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,0,0),0,0)); |
2 |
26 Feb 07 |
jari |
83 |
|
2 |
26 Feb 07 |
jari |
84 |
if(table.getRowCount() > 0) |
2 |
26 Feb 07 |
jari |
85 |
table.addRowSelectionInterval(0,0); //select first cluster |
2 |
26 Feb 07 |
jari |
86 |
|
2 |
26 Feb 07 |
jari |
87 |
JPanel insetPanel = new JPanel(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
88 |
insetPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); |
2 |
26 Feb 07 |
jari |
89 |
|
2 |
26 Feb 07 |
jari |
90 |
JPanel graphPanel = new JPanel(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
91 |
graphPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Cluster Graph", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, font, Color.black)); |
2 |
26 Feb 07 |
jari |
92 |
insetPanel.add(initializeGraph(), new GridBagConstraints(0,0,1,1,1.0,1.0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,0,0),0,0)); |
2 |
26 Feb 07 |
jari |
93 |
graphPanel.add(insetPanel, new GridBagConstraints(0,0,1,1,1.0,1.0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,0,0),0,0)); |
2 |
26 Feb 07 |
jari |
94 |
|
2 |
26 Feb 07 |
jari |
95 |
graphPanel.setPreferredSize(new Dimension(100, 175)); |
2 |
26 Feb 07 |
jari |
96 |
graphPanel.setMinimumSize(new Dimension(100, 175)); |
2 |
26 Feb 07 |
jari |
97 |
|
2 |
26 Feb 07 |
jari |
98 |
this.setLayout(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
99 |
this.add(graphPanel, new GridBagConstraints(0,0,1,1,1.0,0.0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,0,0),0,0)); |
2 |
26 Feb 07 |
jari |
100 |
this.add(tablePanel, new GridBagConstraints(0,1,1,1,1.0,1.0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,0,0),0,0)); |
2 |
26 Feb 07 |
jari |
101 |
} |
2 |
26 Feb 07 |
jari |
102 |
|
2 |
26 Feb 07 |
jari |
103 |
public Cluster getSelectedCluster(){ |
2 |
26 Feb 07 |
jari |
104 |
int serialNumber = ((ClusterTableModel)(this.table.getModel())).getClusterSerialNumber(this.table.getSelectedRow()); |
2 |
26 Feb 07 |
jari |
105 |
return this.repository.getCluster(serialNumber); |
2 |
26 Feb 07 |
jari |
106 |
} |
2 |
26 Feb 07 |
jari |
107 |
|
2 |
26 Feb 07 |
jari |
108 |
private void setInitialColumnWidths(){ |
2 |
26 Feb 07 |
jari |
109 |
String [] columnNames = model.getColumnNames(); |
2 |
26 Feb 07 |
jari |
110 |
for(int i = 0; i < columnNames.length; i++){ |
2 |
26 Feb 07 |
jari |
111 |
setColumnWidth(columnNames[i]); |
2 |
26 Feb 07 |
jari |
112 |
} |
2 |
26 Feb 07 |
jari |
113 |
} |
2 |
26 Feb 07 |
jari |
114 |
|
2 |
26 Feb 07 |
jari |
115 |
|
2 |
26 Feb 07 |
jari |
116 |
private void setColumnWidth(String headerName){ |
2 |
26 Feb 07 |
jari |
117 |
TableColumn column; |
2 |
26 Feb 07 |
jari |
118 |
int width = 10; |
2 |
26 Feb 07 |
jari |
119 |
if(headerName.equals("Serial #")){ |
2 |
26 Feb 07 |
jari |
120 |
column = table.getColumn(headerName); |
2 |
26 Feb 07 |
jari |
121 |
width = 50; |
2 |
26 Feb 07 |
jari |
122 |
column.setWidth(width); |
2 |
26 Feb 07 |
jari |
123 |
column.setMaxWidth(width); |
2 |
26 Feb 07 |
jari |
124 |
column.setMinWidth(width); |
2 |
26 Feb 07 |
jari |
125 |
column.setPreferredWidth(width); |
2 |
26 Feb 07 |
jari |
126 |
} else if(headerName.equals("Source")){ |
2 |
26 Feb 07 |
jari |
127 |
column = table.getColumn(headerName); |
2 |
26 Feb 07 |
jari |
128 |
width = 100; |
2 |
26 Feb 07 |
jari |
129 |
column.setWidth(width); |
2 |
26 Feb 07 |
jari |
130 |
column.setPreferredWidth(width); |
2 |
26 Feb 07 |
jari |
131 |
} else if(headerName.equals("Color")){ |
2 |
26 Feb 07 |
jari |
132 |
column = table.getColumn(headerName); |
2 |
26 Feb 07 |
jari |
133 |
width = 60; |
2 |
26 Feb 07 |
jari |
134 |
column.setWidth(width); |
2 |
26 Feb 07 |
jari |
135 |
column.setPreferredWidth(width); |
2 |
26 Feb 07 |
jari |
136 |
} else if(headerName.equals("Size")){ |
2 |
26 Feb 07 |
jari |
137 |
column = table.getColumn(headerName); |
2 |
26 Feb 07 |
jari |
138 |
width = 50; |
2 |
26 Feb 07 |
jari |
139 |
column.setWidth(width); |
2 |
26 Feb 07 |
jari |
140 |
column.setMaxWidth(width); |
2 |
26 Feb 07 |
jari |
141 |
column.setMinWidth(width); |
2 |
26 Feb 07 |
jari |
142 |
column.setPreferredWidth(width); |
2 |
26 Feb 07 |
jari |
143 |
} |
2 |
26 Feb 07 |
jari |
144 |
} |
2 |
26 Feb 07 |
jari |
145 |
|
2 |
26 Feb 07 |
jari |
146 |
private GraphCanvas initializeGraph(){ |
2 |
26 Feb 07 |
jari |
147 |
profileDisplayPanel = new GraphCanvas(); |
2 |
26 Feb 07 |
jari |
148 |
profileDisplayPanel.setGraphBounds(0, 10, -3, 3); //xRange == 10, until refreshGraph sets to proper size |
2 |
26 Feb 07 |
jari |
149 |
profileDisplayPanel.setGraphSpacing(20, 20, 20, 20); |
2 |
26 Feb 07 |
jari |
150 |
profileDisplayPanel.setXAxisValue(0); |
2 |
26 Feb 07 |
jari |
151 |
profileDisplayPanel.setYAxisValue(0); |
2 |
26 Feb 07 |
jari |
152 |
|
2 |
26 Feb 07 |
jari |
153 |
refreshGraph(); |
2 |
26 Feb 07 |
jari |
154 |
return profileDisplayPanel; |
2 |
26 Feb 07 |
jari |
155 |
} |
2 |
26 Feb 07 |
jari |
156 |
|
2 |
26 Feb 07 |
jari |
157 |
|
2 |
26 Feb 07 |
jari |
158 |
private void refreshGraph(){ |
2 |
26 Feb 07 |
jari |
159 |
|
2 |
26 Feb 07 |
jari |
160 |
int index = table.getSelectedRow(); |
2 |
26 Feb 07 |
jari |
161 |
if(index < 0) |
2 |
26 Feb 07 |
jari |
162 |
return; |
2 |
26 Feb 07 |
jari |
163 |
if (table.getRowCount() <= 0) return; |
2 |
26 Feb 07 |
jari |
164 |
int serialNumber = model.getClusterSerialNumber(index); |
2 |
26 Feb 07 |
jari |
165 |
Cluster cluster = repository.getCluster(serialNumber); |
2 |
26 Feb 07 |
jari |
166 |
this.matrix = cluster.getExperiment().getMatrix(); |
2 |
26 Feb 07 |
jari |
167 |
if(this.clusterTypeStr.equals("Sample")) |
2 |
26 Feb 07 |
jari |
168 |
this.matrix = this.matrix.transpose(); |
2 |
26 Feb 07 |
jari |
169 |
|
2 |
26 Feb 07 |
jari |
170 |
int [] indices = cluster.getExperimentIndices(); //get the indices that map to the experiment |
2 |
26 Feb 07 |
jari |
171 |
Color clusterColor = cluster.getClusterColor(); |
2 |
26 Feb 07 |
jari |
172 |
int xRange = matrix.getColumnDimension(); |
2 |
26 Feb 07 |
jari |
173 |
|
2 |
26 Feb 07 |
jari |
174 |
|
2 |
26 Feb 07 |
jari |
175 |
|
2 |
26 Feb 07 |
jari |
//debug |
2 |
26 Feb 07 |
jari |
/*System.out.println("cluster indices"); |
2 |
26 Feb 07 |
jari |
for(int i = 0; i < indices.length; i++) |
2 |
26 Feb 07 |
jari |
System.out.println("cluster index = "+indices[i]); |
2 |
26 Feb 07 |
jari |
180 |
|
2 |
26 Feb 07 |
jari |
int [] expindices = cluster.getExperiment().getRowMappingArrayCopy(); |
2 |
26 Feb 07 |
jari |
System.out.println("\nExp indices indices"); |
2 |
26 Feb 07 |
jari |
for(int i = 0; i < expindices.length; i++) |
2 |
26 Feb 07 |
jari |
System.out.println("exp index = "+expindices[i]); |
2 |
26 Feb 07 |
jari |
185 |
*/ |
2 |
26 Feb 07 |
jari |
186 |
|
2 |
26 Feb 07 |
jari |
187 |
float min = Float.POSITIVE_INFINITY; |
2 |
26 Feb 07 |
jari |
188 |
float max = Float.NEGATIVE_INFINITY; |
2 |
26 Feb 07 |
jari |
189 |
float maxRange; |
2 |
26 Feb 07 |
jari |
190 |
profileDisplayPanel.removeAllGraphElements(); |
2 |
26 Feb 07 |
jari |
191 |
int currIndex; |
2 |
26 Feb 07 |
jari |
192 |
GraphLine gL; |
2 |
26 Feb 07 |
jari |
193 |
|
2 |
26 Feb 07 |
jari |
194 |
for (int j = 0; j < indices.length; j++) { |
2 |
26 Feb 07 |
jari |
195 |
currIndex = indices[j]; |
2 |
26 Feb 07 |
jari |
196 |
|
2 |
26 Feb 07 |
jari |
197 |
max = Math.max(max, getMax(currIndex)); |
2 |
26 Feb 07 |
jari |
198 |
min = Math.min(min, getMin(currIndex)); |
2 |
26 Feb 07 |
jari |
199 |
maxRange = Math.max(max, Math.abs(min)); |
2 |
26 Feb 07 |
jari |
200 |
profileDisplayPanel.setGraphBounds(0, xRange-1, -maxRange, maxRange); |
2 |
26 Feb 07 |
jari |
201 |
|
2 |
26 Feb 07 |
jari |
202 |
for (int i = 0; i < xRange - 1; i++) { |
2 |
26 Feb 07 |
jari |
203 |
if ((Float.isNaN((matrix.get(currIndex,i))))||(Float.isNaN(matrix.get(currIndex, i +1)))) { |
2 |
26 Feb 07 |
jari |
204 |
continue; |
2 |
26 Feb 07 |
jari |
205 |
} |
2 |
26 Feb 07 |
jari |
206 |
gL = new GraphLine(i /*+ 1*/, matrix.get(currIndex,i), |
2 |
26 Feb 07 |
jari |
207 |
i + 1, matrix.get(currIndex, i+1), clusterColor); |
2 |
26 Feb 07 |
jari |
208 |
profileDisplayPanel.addGraphElement(gL); |
2 |
26 Feb 07 |
jari |
209 |
} |
2 |
26 Feb 07 |
jari |
210 |
} |
2 |
26 Feb 07 |
jari |
211 |
/* |
2 |
26 Feb 07 |
jari |
for (int i = 0; i < meanProfile.size(); i++) { |
2 |
26 Feb 07 |
jari |
if (!Float.isNaN(((Float) meanProfile.elementAt(i)).floatValue())) { |
2 |
26 Feb 07 |
jari |
GraphPoint gp = new GraphPoint(i, ((Float) meanProfile.elementAt(i)).floatValue(), Color.red, 5); |
2 |
26 Feb 07 |
jari |
profileDisplayPanel.addGraphElement(gp); |
2 |
26 Feb 07 |
jari |
216 |
} |
2 |
26 Feb 07 |
jari |
217 |
} |
2 |
26 Feb 07 |
jari |
218 |
|
2 |
26 Feb 07 |
jari |
for (int i = 0; i < meanProfile.size() - 1; i++) { |
2 |
26 Feb 07 |
jari |
gL = new GraphLine(i , ((Float) meanProfile.elementAt(i)).floatValue(), |
2 |
26 Feb 07 |
jari |
i + 1, ((Float) meanProfile.elementAt(i + 1)).floatValue(), Color.blue); |
2 |
26 Feb 07 |
jari |
profileDisplayPanel.addGraphElement(gL); |
2 |
26 Feb 07 |
jari |
223 |
} |
2 |
26 Feb 07 |
jari |
224 |
*/ |
2 |
26 Feb 07 |
jari |
225 |
/* |
2 |
26 Feb 07 |
jari |
if(setTemplate){ |
2 |
26 Feb 07 |
jari |
227 |
|
2 |
26 Feb 07 |
jari |
for (int i = 0; i < meanProfile.size() - 1; i++) { |
2 |
26 Feb 07 |
jari |
if ((Float.isNaN(((Float) meanProfile.elementAt(i)).floatValue())) || (Float.isNaN(((Float) meanProfile.elementAt(i+1)).floatValue()))) { |
2 |
26 Feb 07 |
jari |
continue; |
2 |
26 Feb 07 |
jari |
231 |
} |
2 |
26 Feb 07 |
jari |
gL = new GraphLine(i, ((Float) meanProfile.elementAt(i)).floatValue(), |
2 |
26 Feb 07 |
jari |
i + 1, ((Float) meanProfile.elementAt(i + 1)).floatValue(), Color.green); |
2 |
26 Feb 07 |
jari |
profileDisplayPanel.addGraphElement(gL); |
2 |
26 Feb 07 |
jari |
235 |
} |
2 |
26 Feb 07 |
jari |
236 |
} |
2 |
26 Feb 07 |
jari |
237 |
*/ |
2 |
26 Feb 07 |
jari |
238 |
profileDisplayPanel.repaint(); |
2 |
26 Feb 07 |
jari |
239 |
} |
2 |
26 Feb 07 |
jari |
240 |
|
2 |
26 Feb 07 |
jari |
241 |
private float getMax(int index){ |
2 |
26 Feb 07 |
jari |
242 |
float max = Float.NEGATIVE_INFINITY; |
2 |
26 Feb 07 |
jari |
243 |
int cols = matrix.getColumnDimension(); |
2 |
26 Feb 07 |
jari |
244 |
float val; |
2 |
26 Feb 07 |
jari |
245 |
for(int i = 0; i < cols; i++){ |
2 |
26 Feb 07 |
jari |
246 |
val = matrix.get(index, i); |
2 |
26 Feb 07 |
jari |
247 |
if(!Float.isNaN(val)) |
2 |
26 Feb 07 |
jari |
248 |
if(max < val) |
2 |
26 Feb 07 |
jari |
249 |
max = val; |
2 |
26 Feb 07 |
jari |
250 |
} |
2 |
26 Feb 07 |
jari |
251 |
return max; |
2 |
26 Feb 07 |
jari |
252 |
} |
2 |
26 Feb 07 |
jari |
253 |
|
2 |
26 Feb 07 |
jari |
254 |
private float getMin(int index){ |
2 |
26 Feb 07 |
jari |
255 |
float min = Float.POSITIVE_INFINITY; |
2 |
26 Feb 07 |
jari |
256 |
int cols = matrix.getColumnDimension(); |
2 |
26 Feb 07 |
jari |
257 |
float val; |
2 |
26 Feb 07 |
jari |
258 |
for(int i = 0; i < cols; i++){ |
2 |
26 Feb 07 |
jari |
259 |
val = matrix.get(index, i); |
2 |
26 Feb 07 |
jari |
260 |
if(!Float.isNaN(val)) |
2 |
26 Feb 07 |
jari |
261 |
if(min > val) |
2 |
26 Feb 07 |
jari |
262 |
min = val; |
2 |
26 Feb 07 |
jari |
263 |
} |
2 |
26 Feb 07 |
jari |
264 |
return min; |
2 |
26 Feb 07 |
jari |
265 |
} |
2 |
26 Feb 07 |
jari |
266 |
|
2 |
26 Feb 07 |
jari |
267 |
private JScrollPane initializeTable(){ |
2 |
26 Feb 07 |
jari |
268 |
|
2 |
26 Feb 07 |
jari |
269 |
Cluster cluster; |
2 |
26 Feb 07 |
jari |
270 |
ClusterList list; |
2 |
26 Feb 07 |
jari |
271 |
JLabel colorLabel; |
2 |
26 Feb 07 |
jari |
272 |
JTextArea remarksTextArea; |
2 |
26 Feb 07 |
jari |
273 |
|
2 |
26 Feb 07 |
jari |
274 |
Vector headerVector = new Vector(); |
2 |
26 Feb 07 |
jari |
275 |
headerVector.add("Serial #"); |
2 |
26 Feb 07 |
jari |
276 |
headerVector.add("Source"); |
2 |
26 Feb 07 |
jari |
277 |
headerVector.add("Algorithm Node"); |
2 |
26 Feb 07 |
jari |
278 |
headerVector.add("Cluster Node"); |
2 |
26 Feb 07 |
jari |
279 |
headerVector.add("Cluster Label"); |
2 |
26 Feb 07 |
jari |
280 |
headerVector.add("Remarks"); |
2 |
26 Feb 07 |
jari |
281 |
headerVector.add("Size"); |
2 |
26 Feb 07 |
jari |
282 |
headerVector.add("Color"); |
2 |
26 Feb 07 |
jari |
283 |
|
2 |
26 Feb 07 |
jari |
284 |
Vector dataVector = new Vector(); |
2 |
26 Feb 07 |
jari |
285 |
|
2 |
26 Feb 07 |
jari |
286 |
int row = 0; |
2 |
26 Feb 07 |
jari |
287 |
for(int i = 0; i < repository.size(); i++){ |
2 |
26 Feb 07 |
jari |
288 |
list = repository.getClusterList(i); |
2 |
26 Feb 07 |
jari |
289 |
for(int j = 0; j < list.size(); j++){ |
2 |
26 Feb 07 |
jari |
290 |
cluster = list.getClusterAt(j); |
2 |
26 Feb 07 |
jari |
291 |
dataVector.add(new JLabel(String.valueOf(cluster.getSerialNumber()))); |
2 |
26 Feb 07 |
jari |
292 |
dataVector.add(new JLabel(String.valueOf(cluster.getSource()))); |
2 |
26 Feb 07 |
jari |
293 |
dataVector.add(new JLabel(String.valueOf(cluster.getAlgorithmName()))); |
2 |
26 Feb 07 |
jari |
294 |
dataVector.add(new JLabel(String.valueOf(cluster.getClusterID()))); |
2 |
26 Feb 07 |
jari |
295 |
dataVector.add(cluster.getClusterLabel()); |
2 |
26 Feb 07 |
jari |
296 |
dataVector.add(cluster.getClusterDescription()); |
2 |
26 Feb 07 |
jari |
297 |
dataVector.add(new JLabel(String.valueOf(cluster.getSize()))); |
2 |
26 Feb 07 |
jari |
298 |
dataVector.add(cluster.getClusterColor()); |
2 |
26 Feb 07 |
jari |
299 |
row++; |
2 |
26 Feb 07 |
jari |
300 |
} |
2 |
26 Feb 07 |
jari |
301 |
} |
2 |
26 Feb 07 |
jari |
302 |
model = new ClusterTableModel(headerVector, dataVector); |
2 |
26 Feb 07 |
jari |
303 |
table = new JTable(model); |
2 |
26 Feb 07 |
jari |
304 |
ClusterCellRenderer renderer = new ClusterCellRenderer(); |
2 |
26 Feb 07 |
jari |
305 |
table.setDefaultRenderer(Color.class, renderer); |
2 |
26 Feb 07 |
jari |
306 |
table.setDefaultRenderer(JLabel.class, renderer); |
2 |
26 Feb 07 |
jari |
307 |
table.setPreferredScrollableViewportSize(new Dimension(450, 175)); |
2 |
26 Feb 07 |
jari |
308 |
table.addMouseListener(new TableListener()); |
2 |
26 Feb 07 |
jari |
309 |
table.setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
310 |
table.setRowHeight(table.getRowHeight() + 10); |
2 |
26 Feb 07 |
jari |
311 |
|
2 |
26 Feb 07 |
jari |
312 |
table.setRowSelectionAllowed(true); |
2 |
26 Feb 07 |
jari |
313 |
table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
2 |
26 Feb 07 |
jari |
314 |
|
2 |
26 Feb 07 |
jari |
315 |
setInitialColumnWidths(); |
2 |
26 Feb 07 |
jari |
316 |
|
2 |
26 Feb 07 |
jari |
317 |
model.addTableModelListener(new TableListener()); |
2 |
26 Feb 07 |
jari |
318 |
table.setRowHeight(30); |
2 |
26 Feb 07 |
jari |
319 |
pane = new JScrollPane(table); |
2 |
26 Feb 07 |
jari |
320 |
pane.setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
321 |
|
2 |
26 Feb 07 |
jari |
322 |
validate(); |
2 |
26 Feb 07 |
jari |
323 |
return pane; |
2 |
26 Feb 07 |
jari |
324 |
} |
2 |
26 Feb 07 |
jari |
325 |
|
2 |
26 Feb 07 |
jari |
326 |
|
2 |
26 Feb 07 |
jari |
327 |
public class ClusterTableModel extends AbstractTableModel{ |
2 |
26 Feb 07 |
jari |
328 |
|
2 |
26 Feb 07 |
jari |
329 |
private String [] columnNames; |
2 |
26 Feb 07 |
jari |
330 |
private Object [][] rowData; |
2 |
26 Feb 07 |
jari |
331 |
private Row [] rows; |
2 |
26 Feb 07 |
jari |
332 |
private int colToSort = 0; |
2 |
26 Feb 07 |
jari |
333 |
|
2 |
26 Feb 07 |
jari |
334 |
|
2 |
26 Feb 07 |
jari |
335 |
public ClusterTableModel(Vector columnNames, Vector rowData){ |
2 |
26 Feb 07 |
jari |
336 |
initializeHeader(columnNames); |
2 |
26 Feb 07 |
jari |
337 |
initializeData(rowData); |
2 |
26 Feb 07 |
jari |
338 |
rows = new Row[this.rowData.length]; |
2 |
26 Feb 07 |
jari |
339 |
for(int i = 0; i < rows.length; i++){ |
2 |
26 Feb 07 |
jari |
340 |
rows[i] = new Row(); |
2 |
26 Feb 07 |
jari |
341 |
rows[i].index = i; |
2 |
26 Feb 07 |
jari |
342 |
} |
2 |
26 Feb 07 |
jari |
343 |
} |
2 |
26 Feb 07 |
jari |
344 |
|
2 |
26 Feb 07 |
jari |
345 |
private void initializeHeader(Vector headerNames){ |
2 |
26 Feb 07 |
jari |
346 |
columnNames = new String[headerNames.size()]; |
2 |
26 Feb 07 |
jari |
347 |
for(int i = 0; i < headerNames.size(); i++){ |
2 |
26 Feb 07 |
jari |
348 |
columnNames[i] = (String)headerNames.elementAt(i); |
2 |
26 Feb 07 |
jari |
349 |
} |
2 |
26 Feb 07 |
jari |
350 |
} |
2 |
26 Feb 07 |
jari |
351 |
|
2 |
26 Feb 07 |
jari |
352 |
private void initializeData(Vector data){ |
2 |
26 Feb 07 |
jari |
353 |
int cnt = 0; |
2 |
26 Feb 07 |
jari |
354 |
rowData = new Object[(int)(data.size()/columnNames.length)][columnNames.length]; |
2 |
26 Feb 07 |
jari |
355 |
while(cnt < data.size()){ |
2 |
26 Feb 07 |
jari |
356 |
for(int j = 0; j < columnNames.length; j++){ |
2 |
26 Feb 07 |
jari |
357 |
rowData[(int)(cnt/columnNames.length)][j] = data.elementAt(cnt); |
2 |
26 Feb 07 |
jari |
358 |
cnt++; |
2 |
26 Feb 07 |
jari |
359 |
} |
2 |
26 Feb 07 |
jari |
360 |
} |
2 |
26 Feb 07 |
jari |
361 |
} |
2 |
26 Feb 07 |
jari |
362 |
|
2 |
26 Feb 07 |
jari |
363 |
|
2 |
26 Feb 07 |
jari |
364 |
public String getColumnName(int col) { |
2 |
26 Feb 07 |
jari |
365 |
return columnNames[col]; |
2 |
26 Feb 07 |
jari |
366 |
} |
2 |
26 Feb 07 |
jari |
367 |
|
2 |
26 Feb 07 |
jari |
368 |
public int getRowCount() { return rowData.length; } |
2 |
26 Feb 07 |
jari |
369 |
|
2 |
26 Feb 07 |
jari |
370 |
public int getColumnCount() { return columnNames.length; } |
2 |
26 Feb 07 |
jari |
371 |
|
2 |
26 Feb 07 |
jari |
372 |
public Object getValueAt(int row, int col) { |
2 |
26 Feb 07 |
jari |
373 |
return rowData[rows[row].index][col]; |
2 |
26 Feb 07 |
jari |
374 |
} |
2 |
26 Feb 07 |
jari |
375 |
|
2 |
26 Feb 07 |
jari |
376 |
public boolean isCellEditable(int row, int col) { |
2 |
26 Feb 07 |
jari |
377 |
return (col == 7); |
2 |
26 Feb 07 |
jari |
378 |
} |
2 |
26 Feb 07 |
jari |
379 |
|
2 |
26 Feb 07 |
jari |
380 |
public void setValueAt(Object value, int row, int col) { |
2 |
26 Feb 07 |
jari |
381 |
rowData[rows[row].index][col] = value; |
2 |
26 Feb 07 |
jari |
382 |
this.fireTableChanged(new TableModelEvent(this, row, row, col)); |
2 |
26 Feb 07 |
jari |
383 |
} |
2 |
26 Feb 07 |
jari |
384 |
|
2 |
26 Feb 07 |
jari |
385 |
public Class getColumnClass(int col){ |
2 |
26 Feb 07 |
jari |
386 |
if(col == 7) return Color.class; |
2 |
26 Feb 07 |
jari |
387 |
if(col == 4 || col == 5) return String.class; |
2 |
26 Feb 07 |
jari |
388 |
else return JLabel.class; |
2 |
26 Feb 07 |
jari |
389 |
} |
2 |
26 Feb 07 |
jari |
390 |
|
2 |
26 Feb 07 |
jari |
391 |
public int getClusterSerialNumber( int row ){ |
2 |
26 Feb 07 |
jari |
392 |
if(isLegalRow(row)){ |
2 |
26 Feb 07 |
jari |
393 |
return (Integer.parseInt(((JLabel)(getValueAt(row, 0))).getText())); |
2 |
26 Feb 07 |
jari |
394 |
} |
2 |
26 Feb 07 |
jari |
395 |
return -1; |
2 |
26 Feb 07 |
jari |
396 |
} |
2 |
26 Feb 07 |
jari |
397 |
|
2 |
26 Feb 07 |
jari |
398 |
public boolean isLegalRow(int row){ |
2 |
26 Feb 07 |
jari |
399 |
return (row > -1 && row < getRowCount()); |
2 |
26 Feb 07 |
jari |
400 |
} |
2 |
26 Feb 07 |
jari |
401 |
|
2 |
26 Feb 07 |
jari |
402 |
public boolean isLegalColumn(int col){ |
2 |
26 Feb 07 |
jari |
403 |
return (col > -1 && col < getColumnCount()); |
2 |
26 Feb 07 |
jari |
404 |
} |
2 |
26 Feb 07 |
jari |
405 |
|
2 |
26 Feb 07 |
jari |
/** Sorts table rows based on column index. |
2 |
26 Feb 07 |
jari |
* @param c Column to use as sort key when sorting columns |
2 |
26 Feb 07 |
jari |
408 |
*/ |
2 |
26 Feb 07 |
jari |
409 |
public void sort(int c){ |
2 |
26 Feb 07 |
jari |
410 |
colToSort = c; |
2 |
26 Feb 07 |
jari |
411 |
Arrays.sort(rows); |
2 |
26 Feb 07 |
jari |
412 |
table.repaint(); |
2 |
26 Feb 07 |
jari |
413 |
} |
2 |
26 Feb 07 |
jari |
414 |
|
2 |
26 Feb 07 |
jari |
/** Sorts table rows by column header key. |
2 |
26 Feb 07 |
jari |
* @param key <CODE>String</CODE> key to identify sort column. |
2 |
26 Feb 07 |
jari |
417 |
*/ |
2 |
26 Feb 07 |
jari |
418 |
public void sortBy(String key){ |
2 |
26 Feb 07 |
jari |
419 |
int col = getColumnIndex(key); |
2 |
26 Feb 07 |
jari |
420 |
|
2 |
26 Feb 07 |
jari |
421 |
if(col >= 0){ |
2 |
26 Feb 07 |
jari |
422 |
sort(col); |
2 |
26 Feb 07 |
jari |
423 |
colToSort = col; |
2 |
26 Feb 07 |
jari |
424 |
} |
2 |
26 Feb 07 |
jari |
425 |
} |
2 |
26 Feb 07 |
jari |
426 |
|
2 |
26 Feb 07 |
jari |
427 |
private int getColumnIndex(String key){ |
2 |
26 Feb 07 |
jari |
428 |
for(int i = 0; i < columnNames.length; i++){ |
2 |
26 Feb 07 |
jari |
429 |
if(columnNames[i] == key) |
2 |
26 Feb 07 |
jari |
430 |
return i; |
2 |
26 Feb 07 |
jari |
431 |
} |
2 |
26 Feb 07 |
jari |
432 |
return 0; |
2 |
26 Feb 07 |
jari |
433 |
} |
2 |
26 Feb 07 |
jari |
434 |
|
2 |
26 Feb 07 |
jari |
435 |
public String [] getColumnNames(){ return this.columnNames; } |
2 |
26 Feb 07 |
jari |
436 |
|
2 |
26 Feb 07 |
jari |
437 |
public void hide(String columnName){ |
2 |
26 Feb 07 |
jari |
438 |
table.removeColumn(table.getColumn(columnName)); |
2 |
26 Feb 07 |
jari |
439 |
} |
2 |
26 Feb 07 |
jari |
440 |
|
2 |
26 Feb 07 |
jari |
441 |
public void addColumn(String columnName){ |
2 |
26 Feb 07 |
jari |
442 |
table.addColumn( new TableColumn(getColumnIndex(columnName))); |
2 |
26 Feb 07 |
jari |
443 |
moveColumnFromEnd(getColumnIndex(columnName)); |
2 |
26 Feb 07 |
jari |
444 |
} |
2 |
26 Feb 07 |
jari |
445 |
|
2 |
26 Feb 07 |
jari |
446 |
public void addRow(Vector data){ |
2 |
26 Feb 07 |
jari |
447 |
Object [][] newData = new Object[rowData.length+1][rowData[0].length]; |
2 |
26 Feb 07 |
jari |
448 |
for(int i = 0; i < rowData.length; i++){ |
2 |
26 Feb 07 |
jari |
449 |
for(int j = 0; j < rowData[i].length; j++){ |
2 |
26 Feb 07 |
jari |
450 |
newData[i][j] = rowData[i][j]; |
2 |
26 Feb 07 |
jari |
451 |
} |
2 |
26 Feb 07 |
jari |
452 |
} |
2 |
26 Feb 07 |
jari |
453 |
for(int i = 0; i < this.columnNames.length; i++){ |
2 |
26 Feb 07 |
jari |
454 |
newData[newData.length -1][i] = data.elementAt(i); |
2 |
26 Feb 07 |
jari |
455 |
} |
2 |
26 Feb 07 |
jari |
456 |
rowData = newData; |
2 |
26 Feb 07 |
jari |
457 |
|
2 |
26 Feb 07 |
jari |
458 |
Row [] newRows = new Row[this.rowData.length]; |
2 |
26 Feb 07 |
jari |
459 |
|
2 |
26 Feb 07 |
jari |
460 |
for(int i = 0; i < rows.length; i++){ |
2 |
26 Feb 07 |
jari |
461 |
newRows[i] = rows[i]; |
2 |
26 Feb 07 |
jari |
462 |
} |
2 |
26 Feb 07 |
jari |
463 |
newRows[newRows.length-1] = new Row(); |
2 |
26 Feb 07 |
jari |
464 |
newRows[newRows.length-1].index = newRows.length-1; |
2 |
26 Feb 07 |
jari |
465 |
rows = newRows; |
2 |
26 Feb 07 |
jari |
466 |
this.fireTableRowsInserted(rows.length-1, rows.length-1); |
2 |
26 Feb 07 |
jari |
467 |
} |
2 |
26 Feb 07 |
jari |
468 |
|
2 |
26 Feb 07 |
jari |
469 |
public void removeRow(int tableRow){ |
2 |
26 Feb 07 |
jari |
470 |
int row = rows[tableRow].index; |
2 |
26 Feb 07 |
jari |
471 |
Object [][] newData = new Object[rowData.length-1][rowData[0].length]; |
2 |
26 Feb 07 |
jari |
472 |
int currRow = -1; |
2 |
26 Feb 07 |
jari |
473 |
for(int i = 0; i < rowData.length; i++){ |
2 |
26 Feb 07 |
jari |
474 |
if(i != row){ |
2 |
26 Feb 07 |
jari |
475 |
currRow++; |
2 |
26 Feb 07 |
jari |
476 |
for(int j = 0; j < rowData[i].length; j++){ |
2 |
26 Feb 07 |
jari |
477 |
newData[currRow][j] = rowData[i][j]; |
2 |
26 Feb 07 |
jari |
478 |
} |
2 |
26 Feb 07 |
jari |
479 |
} |
2 |
26 Feb 07 |
jari |
480 |
} |
2 |
26 Feb 07 |
jari |
481 |
rowData = newData; |
2 |
26 Feb 07 |
jari |
482 |
Row [] newRows = new Row[this.rowData.length]; |
2 |
26 Feb 07 |
jari |
483 |
currRow = -1; |
2 |
26 Feb 07 |
jari |
484 |
for(int i = 0; i < rows.length; i++){ |
2 |
26 Feb 07 |
jari |
485 |
if(i != row){ |
2 |
26 Feb 07 |
jari |
486 |
currRow++; |
2 |
26 Feb 07 |
jari |
487 |
newRows[currRow] = rows[i]; |
2 |
26 Feb 07 |
jari |
488 |
newRows[currRow].index = currRow; |
2 |
26 Feb 07 |
jari |
489 |
} |
2 |
26 Feb 07 |
jari |
490 |
} |
2 |
26 Feb 07 |
jari |
491 |
rows = newRows; |
2 |
26 Feb 07 |
jari |
492 |
this.fireTableRowsDeleted(row,row); |
2 |
26 Feb 07 |
jari |
493 |
} |
2 |
26 Feb 07 |
jari |
494 |
|
2 |
26 Feb 07 |
jari |
495 |
public void removeAllRows(){ |
2 |
26 Feb 07 |
jari |
496 |
int numRows = rows.length; |
2 |
26 Feb 07 |
jari |
497 |
rowData = new Object[0][0]; |
2 |
26 Feb 07 |
jari |
498 |
rows = new Row[0]; |
2 |
26 Feb 07 |
jari |
499 |
this.fireTableRowsDeleted(0, numRows); |
2 |
26 Feb 07 |
jari |
500 |
} |
2 |
26 Feb 07 |
jari |
501 |
|
2 |
26 Feb 07 |
jari |
502 |
private void moveColumnFromEnd(int finalLocation){ |
2 |
26 Feb 07 |
jari |
503 |
for(int i = table.getColumnCount()-1; i > finalLocation; i--) |
2 |
26 Feb 07 |
jari |
504 |
table.moveColumn(i-1,i); |
2 |
26 Feb 07 |
jari |
505 |
} |
2 |
26 Feb 07 |
jari |
506 |
|
2 |
26 Feb 07 |
jari |
507 |
public int getSerialNumber(int row){ |
2 |
26 Feb 07 |
jari |
508 |
JLabel serialLabel = (JLabel)(rowData[row][0]); |
2 |
26 Feb 07 |
jari |
509 |
return Integer.parseInt(serialLabel.getText()); |
2 |
26 Feb 07 |
jari |
510 |
} |
2 |
26 Feb 07 |
jari |
511 |
|
2 |
26 Feb 07 |
jari |
512 |
public void setClusterColor(int tableRow, Color clusterColor){ |
2 |
26 Feb 07 |
jari |
513 |
int row = rows[tableRow].index; |
2 |
26 Feb 07 |
jari |
514 |
int col = this.getColumnIndex("Color"); |
2 |
26 Feb 07 |
jari |
515 |
setValueAt(clusterColor, row, col); |
2 |
26 Feb 07 |
jari |
516 |
this.fireTableCellUpdated(tableRow, col); |
2 |
26 Feb 07 |
jari |
517 |
} |
2 |
26 Feb 07 |
jari |
518 |
|
2 |
26 Feb 07 |
jari |
519 |
public void setClusterLabel(int tableRow, String clusterLabel){ |
2 |
26 Feb 07 |
jari |
520 |
int row = rows[tableRow].index; |
2 |
26 Feb 07 |
jari |
521 |
int col = this.getColumnIndex("Cluster Label"); |
2 |
26 Feb 07 |
jari |
522 |
setValueAt(clusterLabel, row, col); |
2 |
26 Feb 07 |
jari |
523 |
this.fireTableCellUpdated(tableRow, col); |
2 |
26 Feb 07 |
jari |
524 |
} |
2 |
26 Feb 07 |
jari |
525 |
|
2 |
26 Feb 07 |
jari |
526 |
public void setClusterDescription(int tableRow, String clusterDescription){ |
2 |
26 Feb 07 |
jari |
527 |
int row = rows[tableRow].index; |
2 |
26 Feb 07 |
jari |
528 |
int col = this.getColumnIndex("Remarks"); |
2 |
26 Feb 07 |
jari |
529 |
setValueAt(clusterDescription, row, col); |
2 |
26 Feb 07 |
jari |
530 |
this.fireTableCellUpdated(tableRow, col); |
2 |
26 Feb 07 |
jari |
531 |
} |
2 |
26 Feb 07 |
jari |
532 |
|
2 |
26 Feb 07 |
jari |
533 |
|
2 |
26 Feb 07 |
jari |
534 |
private class Row implements Comparable{ |
2 |
26 Feb 07 |
jari |
535 |
public int index; |
2 |
26 Feb 07 |
jari |
536 |
private String myString, otherString; |
2 |
26 Feb 07 |
jari |
537 |
|
2 |
26 Feb 07 |
jari |
538 |
public int compareTo(Object other){ |
2 |
26 Feb 07 |
jari |
539 |
Row otherRow = (Row)other; |
2 |
26 Feb 07 |
jari |
540 |
Object myObject = rowData[index][colToSort]; |
2 |
26 Feb 07 |
jari |
541 |
Object otherObject = rowData[otherRow.index][colToSort]; |
2 |
26 Feb 07 |
jari |
542 |
if(model.getColumnName(colToSort).equals("Serial #") || |
2 |
26 Feb 07 |
jari |
543 |
model.getColumnName(colToSort).equals("Size")){ |
2 |
26 Feb 07 |
jari |
544 |
Integer i; |
2 |
26 Feb 07 |
jari |
545 |
i = new Integer(((JLabel)rowData[index][colToSort]).getText()); |
2 |
26 Feb 07 |
jari |
546 |
return i.compareTo(new Integer(((JLabel)(otherObject)).getText())); |
2 |
26 Feb 07 |
jari |
547 |
} |
2 |
26 Feb 07 |
jari |
548 |
if( myObject instanceof Comparable ) |
2 |
26 Feb 07 |
jari |
549 |
return ((Comparable)myObject).compareTo(otherObject); |
2 |
26 Feb 07 |
jari |
550 |
if(myObject instanceof JLabel){ |
2 |
26 Feb 07 |
jari |
551 |
myString = ((JLabel)(myObject)).getText(); |
2 |
26 Feb 07 |
jari |
552 |
otherString = ((JLabel)(otherObject)).getText(); |
2 |
26 Feb 07 |
jari |
553 |
return myString.compareTo(otherString); |
2 |
26 Feb 07 |
jari |
554 |
} |
2 |
26 Feb 07 |
jari |
555 |
else return index - otherRow.index; |
2 |
26 Feb 07 |
jari |
556 |
} |
2 |
26 Feb 07 |
jari |
557 |
} |
2 |
26 Feb 07 |
jari |
558 |
} |
2 |
26 Feb 07 |
jari |
559 |
|
2 |
26 Feb 07 |
jari |
560 |
|
2 |
26 Feb 07 |
jari |
561 |
public class ClusterCellRenderer implements TableCellRenderer{ |
2 |
26 Feb 07 |
jari |
562 |
|
2 |
26 Feb 07 |
jari |
563 |
private JPanel colorPanel = new JPanel(); |
2 |
26 Feb 07 |
jari |
564 |
private JLabel label; |
2 |
26 Feb 07 |
jari |
565 |
private JTextArea textArea; |
2 |
26 Feb 07 |
jari |
566 |
|
2 |
26 Feb 07 |
jari |
567 |
public ClusterCellRenderer(){ |
2 |
26 Feb 07 |
jari |
568 |
|
2 |
26 Feb 07 |
jari |
569 |
} |
2 |
26 Feb 07 |
jari |
570 |
|
2 |
26 Feb 07 |
jari |
571 |
public java.awt.Component getTableCellRendererComponent(JTable jTable, Object obj, boolean param, boolean param3, int row, int col) { |
2 |
26 Feb 07 |
jari |
572 |
if(obj instanceof Color){ |
2 |
26 Feb 07 |
jari |
573 |
colorPanel.setBackground((Color)obj); |
2 |
26 Feb 07 |
jari |
574 |
return colorPanel; |
2 |
26 Feb 07 |
jari |
575 |
} else if(obj instanceof JLabel){ |
2 |
26 Feb 07 |
jari |
576 |
label = (JLabel)obj; |
2 |
26 Feb 07 |
jari |
577 |
label.setOpaque(true); |
2 |
26 Feb 07 |
jari |
578 |
label.setFont(new Font("Arial", Font.PLAIN, 12)); |
2 |
26 Feb 07 |
jari |
579 |
label.setBackground(new Color(225, 225, 225)); |
2 |
26 Feb 07 |
jari |
580 |
label.setForeground(Color.black); |
2 |
26 Feb 07 |
jari |
581 |
label.setHorizontalAlignment(JLabel.CENTER); |
2 |
26 Feb 07 |
jari |
582 |
if(table.isRowSelected(row)) |
2 |
26 Feb 07 |
jari |
583 |
label.setBackground(table.getSelectionBackground()); |
2 |
26 Feb 07 |
jari |
584 |
return label; |
2 |
26 Feb 07 |
jari |
585 |
} else if(obj instanceof JTextArea){ |
2 |
26 Feb 07 |
jari |
586 |
textArea = (JTextArea)obj; |
2 |
26 Feb 07 |
jari |
587 |
if(table.isRowSelected(row)) |
2 |
26 Feb 07 |
jari |
588 |
textArea.setBackground(table.getSelectionBackground()); |
2 |
26 Feb 07 |
jari |
589 |
return textArea; |
2 |
26 Feb 07 |
jari |
590 |
} |
2 |
26 Feb 07 |
jari |
591 |
colorPanel.setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
592 |
return colorPanel; |
2 |
26 Feb 07 |
jari |
593 |
} |
2 |
26 Feb 07 |
jari |
594 |
} |
2 |
26 Feb 07 |
jari |
595 |
|
2 |
26 Feb 07 |
jari |
596 |
public class TableListener extends MouseAdapter implements TableModelListener { |
2 |
26 Feb 07 |
jari |
597 |
|
2 |
26 Feb 07 |
jari |
598 |
public void tableChanged(javax.swing.event.TableModelEvent tableModelEvent) { |
2 |
26 Feb 07 |
jari |
599 |
refreshGraph(); |
2 |
26 Feb 07 |
jari |
600 |
} |
2 |
26 Feb 07 |
jari |
601 |
|
2 |
26 Feb 07 |
jari |
602 |
public void mousePressed(MouseEvent evt){ |
2 |
26 Feb 07 |
jari |
603 |
refreshGraph(); |
2 |
26 Feb 07 |
jari |
604 |
} |
2 |
26 Feb 07 |
jari |
605 |
|
2 |
26 Feb 07 |
jari |
606 |
public void mouseReleased(MouseEvent evt){ |
2 |
26 Feb 07 |
jari |
607 |
refreshGraph(); |
2 |
26 Feb 07 |
jari |
608 |
} |
2 |
26 Feb 07 |
jari |
609 |
|
2 |
26 Feb 07 |
jari |
610 |
} |
2 |
26 Feb 07 |
jari |
611 |
|
2 |
26 Feb 07 |
jari |
612 |
} |