2 |
26 Feb 07 |
jari |
1 |
package org.tigr.microarray.mev; |
2 |
26 Feb 07 |
jari |
2 |
|
2 |
26 Feb 07 |
jari |
3 |
import java.awt.Color; |
2 |
26 Feb 07 |
jari |
4 |
import java.awt.Graphics2D; |
2 |
26 Feb 07 |
jari |
5 |
import java.awt.GridBagLayout; |
2 |
26 Feb 07 |
jari |
6 |
import java.awt.RenderingHints; |
2 |
26 Feb 07 |
jari |
7 |
import java.awt.event.ActionEvent; |
2 |
26 Feb 07 |
jari |
8 |
import java.awt.event.ActionListener; |
2 |
26 Feb 07 |
jari |
9 |
|
2 |
26 Feb 07 |
jari |
10 |
import javax.swing.JButton; |
2 |
26 Feb 07 |
jari |
11 |
import javax.swing.JFrame; |
2 |
26 Feb 07 |
jari |
12 |
import javax.swing.JPanel; |
2 |
26 Feb 07 |
jari |
13 |
|
2 |
26 Feb 07 |
jari |
14 |
import org.tigr.graph.GraphBar; |
2 |
26 Feb 07 |
jari |
15 |
import org.tigr.graph.GraphElement; |
2 |
26 Feb 07 |
jari |
16 |
import org.tigr.graph.GraphLine; |
2 |
26 Feb 07 |
jari |
17 |
import org.tigr.graph.GraphPoint; |
2 |
26 Feb 07 |
jari |
18 |
import org.tigr.graph.GraphTick; |
2 |
26 Feb 07 |
jari |
19 |
import org.tigr.graph.GraphViewer; |
2 |
26 Feb 07 |
jari |
20 |
import org.tigr.util.awt.GBA; |
2 |
26 Feb 07 |
jari |
21 |
|
2 |
26 Feb 07 |
jari |
22 |
public class BlockGraphViewer extends GraphViewer { |
2 |
26 Feb 07 |
jari |
23 |
|
2 |
26 Feb 07 |
jari |
24 |
public int maxRows; |
2 |
26 Feb 07 |
jari |
25 |
public int maxColumns; |
2 |
26 Feb 07 |
jari |
26 |
|
2 |
26 Feb 07 |
jari |
27 |
public JPanel buttonPanel; |
2 |
26 Feb 07 |
jari |
28 |
public JButton button; |
2 |
26 Feb 07 |
jari |
29 |
|
2 |
26 Feb 07 |
jari |
30 |
public JButton allButton; |
2 |
26 Feb 07 |
jari |
31 |
public JButton noneButton; |
2 |
26 Feb 07 |
jari |
32 |
|
2 |
26 Feb 07 |
jari |
33 |
private boolean[] visibles; |
2 |
26 Feb 07 |
jari |
34 |
private Color[] colors = {Color.black, Color.blue, Color.red, Color.yellow, Color.orange, Color.magenta, |
2 |
26 Feb 07 |
jari |
35 |
Color.cyan, Color.pink, Color.green, Color.gray, Color.lightGray, Color.darkGray}; |
2 |
26 Feb 07 |
jari |
36 |
|
2 |
26 Feb 07 |
jari |
37 |
public BlockGraphViewer(JFrame frame, int maxRows, int maxColumns, int startx, int stopx, int starty, int stopy, double graphstartx, double graphstopx, double graphstarty, double graphstopy, int preXSpacing, int postXSpacing, int preYSpacing, int postYSpacing, String title, String xLabel, String yLabel) { |
2 |
26 Feb 07 |
jari |
38 |
|
2 |
26 Feb 07 |
jari |
39 |
super(frame, startx, stopx, starty, stopy, graphstartx, graphstopx, graphstarty, graphstopy, |
2 |
26 Feb 07 |
jari |
40 |
preXSpacing, postXSpacing, preYSpacing, postYSpacing, title, xLabel, yLabel); |
2 |
26 Feb 07 |
jari |
41 |
|
2 |
26 Feb 07 |
jari |
42 |
this.maxRows = maxRows; |
2 |
26 Feb 07 |
jari |
43 |
this.maxColumns = maxColumns; |
2 |
26 Feb 07 |
jari |
44 |
|
2 |
26 Feb 07 |
jari |
45 |
generatePalette(); |
2 |
26 Feb 07 |
jari |
46 |
|
2 |
26 Feb 07 |
jari |
47 |
visibles = new boolean[maxRows * maxColumns]; |
2 |
26 Feb 07 |
jari |
48 |
for (int i = 0; i < visibles.length; i++) { |
2 |
26 Feb 07 |
jari |
49 |
visibles[i] = true; |
2 |
26 Feb 07 |
jari |
50 |
} |
2 |
26 Feb 07 |
jari |
51 |
|
2 |
26 Feb 07 |
jari |
52 |
buttonPanel = new JPanel(); |
2 |
26 Feb 07 |
jari |
53 |
buttonPanel.setLayout(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
54 |
|
2 |
26 Feb 07 |
jari |
55 |
allButton = new JButton("All"); |
2 |
26 Feb 07 |
jari |
56 |
allButton.addActionListener(new ActionListener() { |
2 |
26 Feb 07 |
jari |
57 |
public void actionPerformed(ActionEvent event) { |
2 |
26 Feb 07 |
jari |
58 |
for (int i = 0; i < visibles.length; i++) { |
2 |
26 Feb 07 |
jari |
59 |
visibles[i] = true; |
2 |
26 Feb 07 |
jari |
60 |
} |
2 |
26 Feb 07 |
jari |
61 |
repaint(); |
2 |
26 Feb 07 |
jari |
62 |
} |
2 |
26 Feb 07 |
jari |
63 |
}); |
2 |
26 Feb 07 |
jari |
64 |
gba.add(buttonPanel, allButton, 0, 0, 1, 1, 1, 1, GBA.B, GBA.C); |
2 |
26 Feb 07 |
jari |
65 |
|
2 |
26 Feb 07 |
jari |
66 |
noneButton = new JButton("None"); |
2 |
26 Feb 07 |
jari |
67 |
noneButton.addActionListener(new ActionListener() { |
2 |
26 Feb 07 |
jari |
68 |
public void actionPerformed(ActionEvent event) { |
2 |
26 Feb 07 |
jari |
69 |
for (int i = 0; i < visibles.length; i++) { |
2 |
26 Feb 07 |
jari |
70 |
visibles[i] = false; |
2 |
26 Feb 07 |
jari |
71 |
} |
2 |
26 Feb 07 |
jari |
72 |
repaint(); |
2 |
26 Feb 07 |
jari |
73 |
} |
2 |
26 Feb 07 |
jari |
74 |
}); |
2 |
26 Feb 07 |
jari |
75 |
gba.add(buttonPanel, noneButton, 1, 0, 1, 1, 1, 1, GBA.B, GBA.C); |
2 |
26 Feb 07 |
jari |
76 |
|
2 |
26 Feb 07 |
jari |
77 |
for (int i = 0; i < maxRows; i++) { |
2 |
26 Feb 07 |
jari |
78 |
for (int j = 0; j < maxColumns; j++) { |
2 |
26 Feb 07 |
jari |
79 |
button = new JButton((j + 1) + ", " + (i + 1)); |
2 |
26 Feb 07 |
jari |
80 |
final int location = (maxColumns * i + j); |
2 |
26 Feb 07 |
jari |
81 |
if(i == 0 && j == 0) |
2 |
26 Feb 07 |
jari |
82 |
button.setForeground(Color.white); |
2 |
26 Feb 07 |
jari |
83 |
button.setBackground(colors[location]); |
2 |
26 Feb 07 |
jari |
84 |
button.addActionListener(new ActionListener() { |
2 |
26 Feb 07 |
jari |
85 |
public void actionPerformed(ActionEvent event) { |
2 |
26 Feb 07 |
jari |
86 |
visibles[location] = (! visibles[location]); |
2 |
26 Feb 07 |
jari |
87 |
repaint(); |
2 |
26 Feb 07 |
jari |
88 |
} |
2 |
26 Feb 07 |
jari |
89 |
}); |
2 |
26 Feb 07 |
jari |
90 |
|
2 |
26 Feb 07 |
jari |
91 |
gba.add(buttonPanel, button, j, i + 1, 1, 1, 1, 1, GBA.B, GBA.C); |
2 |
26 Feb 07 |
jari |
92 |
} |
2 |
26 Feb 07 |
jari |
93 |
} |
2 |
26 Feb 07 |
jari |
94 |
|
2 |
26 Feb 07 |
jari |
95 |
frame.getContentPane().add(buttonPanel); |
2 |
26 Feb 07 |
jari |
96 |
} |
2 |
26 Feb 07 |
jari |
97 |
|
2 |
26 Feb 07 |
jari |
98 |
public void generatePalette() { |
2 |
26 Feb 07 |
jari |
99 |
|
2 |
26 Feb 07 |
jari |
100 |
int elements = maxColumns * maxRows; |
2 |
26 Feb 07 |
jari |
101 |
int strata; |
2 |
26 Feb 07 |
jari |
102 |
|
2 |
26 Feb 07 |
jari |
103 |
if (elements != 12) { |
2 |
26 Feb 07 |
jari |
104 |
for (strata = 0; (strata * strata * strata) < elements; strata++) {;} |
2 |
26 Feb 07 |
jari |
105 |
colors = new Color[strata * strata * strata]; |
2 |
26 Feb 07 |
jari |
106 |
for (int r = strata - 1; r >= 0; r--) { |
2 |
26 Feb 07 |
jari |
107 |
for (int g = strata - 1; g >= 0; g--) { |
2 |
26 Feb 07 |
jari |
108 |
for (int b = strata - 1; b >= 0; b--) { |
2 |
26 Feb 07 |
jari |
// for (int r = 0; r < strata; r++) { |
2 |
26 Feb 07 |
jari |
// for (int g = 0; g < strata; g++) { |
2 |
26 Feb 07 |
jari |
// for (int b = 0; b < strata; b++) { |
2 |
26 Feb 07 |
jari |
112 |
colors[(r * strata * strata) + (g * strata) + b] = new Color((int) ((double) r * 255 / (strata - 1)), |
2 |
26 Feb 07 |
jari |
113 |
(int) ((double) g * 255 / (strata - 1)), |
2 |
26 Feb 07 |
jari |
114 |
(int) ((double) b * 255 / (strata - 1))); |
2 |
26 Feb 07 |
jari |
115 |
} |
2 |
26 Feb 07 |
jari |
116 |
} |
2 |
26 Feb 07 |
jari |
117 |
} |
2 |
26 Feb 07 |
jari |
118 |
} |
2 |
26 Feb 07 |
jari |
119 |
} |
2 |
26 Feb 07 |
jari |
120 |
|
2 |
26 Feb 07 |
jari |
121 |
public Color[] getColors() {return this.colors;} |
2 |
26 Feb 07 |
jari |
122 |
public boolean[] getVisibles() {return this.visibles;} |
2 |
26 Feb 07 |
jari |
123 |
|
2 |
26 Feb 07 |
jari |
124 |
public void drawGraph(Graphics2D g) { |
2 |
26 Feb 07 |
jari |
125 |
|
2 |
26 Feb 07 |
jari |
126 |
GraphElement e; |
2 |
26 Feb 07 |
jari |
127 |
|
2 |
26 Feb 07 |
jari |
128 |
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF); |
2 |
26 Feb 07 |
jari |
129 |
|
2 |
26 Feb 07 |
jari |
130 |
drawSystem(g, SYSTEM_BOUNDS); |
2 |
26 Feb 07 |
jari |
131 |
for (int i = 0; i < graphElements.size(); i++) { |
2 |
26 Feb 07 |
jari |
132 |
e = (GraphElement) graphElements.elementAt(i); |
2 |
26 Feb 07 |
jari |
133 |
if (e instanceof GraphPoint) { |
2 |
26 Feb 07 |
jari |
134 |
for (int j = 0; j < visibles.length; j++) { |
2 |
26 Feb 07 |
jari |
135 |
if ((visibles[j] == true) && (((GraphPoint) e).getColor() == colors[j])) { |
2 |
26 Feb 07 |
jari |
136 |
drawPoint(g, (GraphPoint) e); |
2 |
26 Feb 07 |
jari |
137 |
} |
2 |
26 Feb 07 |
jari |
138 |
} |
2 |
26 Feb 07 |
jari |
139 |
} else if (e instanceof GraphBar) { |
2 |
26 Feb 07 |
jari |
140 |
drawBar(g, (GraphBar) e); |
2 |
26 Feb 07 |
jari |
141 |
} else if (e instanceof GraphTick) { |
2 |
26 Feb 07 |
jari |
142 |
drawTick(g, (GraphTick) e); |
2 |
26 Feb 07 |
jari |
143 |
} else if (e instanceof GraphLine) { |
2 |
26 Feb 07 |
jari |
144 |
drawLine(g, (GraphLine) e); |
2 |
26 Feb 07 |
jari |
145 |
} |
2 |
26 Feb 07 |
jari |
146 |
} |
2 |
26 Feb 07 |
jari |
147 |
|
2 |
26 Feb 07 |
jari |
148 |
if (referenceLinesOn) { //Grid tracing is active |
2 |
26 Feb 07 |
jari |
149 |
int x = getXOldEvent(); |
2 |
26 Feb 07 |
jari |
150 |
int y = getYOldEvent(); |
2 |
26 Feb 07 |
jari |
151 |
|
2 |
26 Feb 07 |
jari |
152 |
if ((x <= convertX(graphstopx)) && (x >= convertX(graphstartx))) { |
2 |
26 Feb 07 |
jari |
153 |
g.setColor(Color.magenta); |
2 |
26 Feb 07 |
jari |
154 |
g.drawLine(x, convertY(graphstarty), x, convertY(graphstopy)); |
2 |
26 Feb 07 |
jari |
155 |
} |
2 |
26 Feb 07 |
jari |
156 |
if ((y >= convertY(graphstopy)) && (y <= convertY(graphstarty))) { |
2 |
26 Feb 07 |
jari |
157 |
g.setColor(Color.magenta); |
2 |
26 Feb 07 |
jari |
158 |
g.drawLine(convertX(graphstartx), y, convertX(graphstopx), y); |
2 |
26 Feb 07 |
jari |
159 |
} |
2 |
26 Feb 07 |
jari |
160 |
} |
2 |
26 Feb 07 |
jari |
161 |
|
2 |
26 Feb 07 |
jari |
162 |
drawXLabel(g, xLabel, Color.black); |
2 |
26 Feb 07 |
jari |
163 |
drawYLabel(g, yLabel, Color.black); |
2 |
26 Feb 07 |
jari |
164 |
drawTitle(g, title, Color.black); |
2 |
26 Feb 07 |
jari |
165 |
} |
2 |
26 Feb 07 |
jari |
166 |
} |