2 |
26 Feb 07 |
jari |
1 |
/* |
2 |
26 Feb 07 |
jari |
Copyright @ 1999-2003, 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: RelevanceNetworkViewer.java,v $ |
2 |
26 Feb 07 |
jari |
* $Revision: 1.11 $ |
2 |
26 Feb 07 |
jari |
* $Date: 2006/05/02 16:57:04 $ |
2 |
26 Feb 07 |
jari |
* $Author: eleanorahowe $ |
2 |
26 Feb 07 |
jari |
* $State: Exp $ |
2 |
26 Feb 07 |
jari |
11 |
*/ |
2 |
26 Feb 07 |
jari |
12 |
package org.tigr.microarray.mev.cluster.gui.impl.rn; |
2 |
26 Feb 07 |
jari |
13 |
|
2 |
26 Feb 07 |
jari |
14 |
import java.awt.BorderLayout; |
2 |
26 Feb 07 |
jari |
15 |
import java.awt.Color; |
2 |
26 Feb 07 |
jari |
16 |
import java.awt.Component; |
2 |
26 Feb 07 |
jari |
17 |
import java.awt.Dimension; |
2 |
26 Feb 07 |
jari |
18 |
import java.awt.Font; |
2 |
26 Feb 07 |
jari |
19 |
import java.awt.FontMetrics; |
2 |
26 Feb 07 |
jari |
20 |
import java.awt.Frame; |
2 |
26 Feb 07 |
jari |
21 |
import java.awt.GradientPaint; |
2 |
26 Feb 07 |
jari |
22 |
import java.awt.Graphics; |
2 |
26 Feb 07 |
jari |
23 |
import java.awt.Graphics2D; |
2 |
26 Feb 07 |
jari |
24 |
import java.awt.Insets; |
2 |
26 Feb 07 |
jari |
25 |
import java.awt.Point; |
2 |
26 Feb 07 |
jari |
26 |
import java.awt.Rectangle; |
2 |
26 Feb 07 |
jari |
27 |
import java.awt.RenderingHints; |
2 |
26 Feb 07 |
jari |
28 |
import java.awt.event.ActionEvent; |
2 |
26 Feb 07 |
jari |
29 |
import java.awt.event.ActionListener; |
2 |
26 Feb 07 |
jari |
30 |
import java.awt.event.MouseAdapter; |
2 |
26 Feb 07 |
jari |
31 |
import java.awt.event.MouseEvent; |
2 |
26 Feb 07 |
jari |
32 |
import java.awt.event.MouseMotionListener; |
2 |
26 Feb 07 |
jari |
33 |
import java.awt.geom.Rectangle2D; |
2 |
26 Feb 07 |
jari |
34 |
import java.awt.image.BufferedImage; |
2 |
26 Feb 07 |
jari |
35 |
import java.beans.Expression; |
2 |
26 Feb 07 |
jari |
36 |
import java.io.IOException; |
2 |
26 Feb 07 |
jari |
37 |
import java.io.ObjectInputStream; |
2 |
26 Feb 07 |
jari |
38 |
import java.io.ObjectOutputStream; |
2 |
26 Feb 07 |
jari |
39 |
import java.util.ArrayList; |
2 |
26 Feb 07 |
jari |
40 |
import java.util.Arrays; |
2 |
26 Feb 07 |
jari |
41 |
|
2 |
26 Feb 07 |
jari |
42 |
import javax.swing.ButtonGroup; |
2 |
26 Feb 07 |
jari |
43 |
import javax.swing.JCheckBoxMenuItem; |
2 |
26 Feb 07 |
jari |
44 |
import javax.swing.JColorChooser; |
2 |
26 Feb 07 |
jari |
45 |
import javax.swing.JComponent; |
2 |
26 Feb 07 |
jari |
46 |
import javax.swing.JMenu; |
2 |
26 Feb 07 |
jari |
47 |
import javax.swing.JMenuItem; |
2 |
26 Feb 07 |
jari |
48 |
import javax.swing.JOptionPane; |
2 |
26 Feb 07 |
jari |
49 |
import javax.swing.JPanel; |
2 |
26 Feb 07 |
jari |
50 |
import javax.swing.JPopupMenu; |
2 |
26 Feb 07 |
jari |
51 |
import javax.swing.JRadioButtonMenuItem; |
2 |
26 Feb 07 |
jari |
52 |
import javax.swing.JToolTip; |
2 |
26 Feb 07 |
jari |
53 |
import javax.swing.JViewport; |
2 |
26 Feb 07 |
jari |
54 |
import javax.swing.JWindow; |
2 |
26 Feb 07 |
jari |
55 |
import javax.swing.Scrollable; |
2 |
26 Feb 07 |
jari |
56 |
import javax.swing.SwingConstants; |
2 |
26 Feb 07 |
jari |
57 |
import javax.swing.SwingUtilities; |
2 |
26 Feb 07 |
jari |
58 |
|
2 |
26 Feb 07 |
jari |
59 |
import org.tigr.microarray.mev.cluster.clusterUtil.Cluster; |
2 |
26 Feb 07 |
jari |
60 |
import org.tigr.microarray.mev.cluster.gui.Experiment; |
2 |
26 Feb 07 |
jari |
61 |
import org.tigr.microarray.mev.cluster.gui.IData; |
2 |
26 Feb 07 |
jari |
62 |
import org.tigr.microarray.mev.cluster.gui.IDisplayMenu; |
2 |
26 Feb 07 |
jari |
63 |
import org.tigr.microarray.mev.cluster.gui.IFramework; |
2 |
26 Feb 07 |
jari |
64 |
import org.tigr.microarray.mev.cluster.gui.IViewer; |
2 |
26 Feb 07 |
jari |
65 |
import org.tigr.microarray.mev.cluster.gui.impl.GUIFactory; |
2 |
26 Feb 07 |
jari |
66 |
|
2 |
26 Feb 07 |
jari |
67 |
public class RelevanceNetworkViewer extends JPanel implements IViewer, Scrollable { |
2 |
26 Feb 07 |
jari |
68 |
|
2 |
26 Feb 07 |
jari |
69 |
private static final String ZOOM_IN_CMD = "zoom-in-cmd"; |
2 |
26 Feb 07 |
jari |
70 |
private static final String ZOOM_OUT_CMD = "zoom-out-cmd"; |
2 |
26 Feb 07 |
jari |
71 |
private static final String SHOW_ALL_CMD = "show-all-cmd"; |
2 |
26 Feb 07 |
jari |
72 |
private static final String SELECT_BY_DEGREE_CMD = "select-by-degree-cmd"; |
2 |
26 Feb 07 |
jari |
73 |
private static final String SELECT_BY_GENE_ID_CMD = "select-by-gene-id-cmd"; |
2 |
26 Feb 07 |
jari |
74 |
private static final String LINKS_COLOR_CMD = "links-color-cmd"; |
2 |
26 Feb 07 |
jari |
75 |
private static final String LINKS_THRESHOLD_CMD = "links-threshold-cmd"; |
2 |
26 Feb 07 |
jari |
76 |
private static final String DESELECT_CMD = "deselect-cmd"; |
2 |
26 Feb 07 |
jari |
77 |
private static final String SET_PUBLIC_CLUSTER_CMD = "set-public-cluster"; |
2 |
26 Feb 07 |
jari |
78 |
private static final String RANDOM_LAYOUT_CMD = "random-layout-cmd"; |
2 |
26 Feb 07 |
jari |
79 |
private static final String CIRCULAR_LAYOUT_CMD = "circular-layout-cmd"; |
2 |
26 Feb 07 |
jari |
80 |
private static final String DEBUG_LAYOUT_CMD = "debug-layout-cmd"; |
2 |
26 Feb 07 |
jari |
81 |
private static final String SET_LABEL_COLOR_CMD = "set-label-color-cmd"; |
2 |
26 Feb 07 |
jari |
82 |
private static final String SET_SELECTION_COLOR_CMD = "set-selection-color-cmd"; |
2 |
26 Feb 07 |
jari |
83 |
private static final String SET_BACKGROUND_COLOR_CMD = "set-background-color-cmd"; |
2 |
26 Feb 07 |
jari |
84 |
private static final String SHAPE_RECT_CMD = "shape-rect-cmd"; |
2 |
26 Feb 07 |
jari |
85 |
private static final String SHAPE_OVAL_CMD = "shape-oval-cmd"; |
2 |
26 Feb 07 |
jari |
86 |
private static final String FIND_CLUSTER_CMD = "find-cluster-cmd"; |
2 |
26 Feb 07 |
jari |
87 |
|
2 |
26 Feb 07 |
jari |
88 |
private static final int SHAPE_RECT = 0; |
2 |
26 Feb 07 |
jari |
89 |
private static final int SHAPE_OVAL = 1; |
2 |
26 Feb 07 |
jari |
90 |
|
2 |
26 Feb 07 |
jari |
91 |
private static final int MAX_CONTENT_SIZE = Integer.MAX_VALUE-1; |
2 |
26 Feb 07 |
jari |
92 |
private static final float ZOOM_COEFFICIENT = 2.0f; |
2 |
26 Feb 07 |
jari |
93 |
private Rectangle prevZoomRect = new Rectangle(); |
2 |
26 Feb 07 |
jari |
94 |
|
2 |
26 Feb 07 |
jari |
95 |
private Experiment experiment; |
2 |
26 Feb 07 |
jari |
96 |
private IData data; |
2 |
26 Feb 07 |
jari |
97 |
private IFramework framework; |
2 |
26 Feb 07 |
jari |
98 |
private boolean isGenes; |
2 |
26 Feb 07 |
jari |
99 |
private int[][] clusters; |
2 |
26 Feb 07 |
jari |
100 |
private float[][] weights; |
2 |
26 Feb 07 |
jari |
101 |
private int[] indices; |
2 |
26 Feb 07 |
jari |
102 |
private float[][] coords; // x, y coordinaties |
2 |
26 Feb 07 |
jari |
103 |
private boolean[] selected; |
2 |
26 Feb 07 |
jari |
104 |
private boolean[] draw; // used to prevent multiple drawing of a same spot |
2 |
26 Feb 07 |
jari |
105 |
private float links_threshold = 0f; |
2 |
26 Feb 07 |
jari |
106 |
private boolean isLinksColor = true; // use colors for the links? |
2 |
26 Feb 07 |
jari |
107 |
private static final int COLORS_DEEP = 100; // number of links palette colors |
2 |
26 Feb 07 |
jari |
108 |
private Color[] LINKS_PALETTE = createPalette(Color.blue, Color.red, COLORS_DEEP); |
2 |
26 Feb 07 |
jari |
109 |
private float weight_min = 0f; |
2 |
26 Feb 07 |
jari |
110 |
private float weight_scale; // scale to select color from the links palette |
2 |
26 Feb 07 |
jari |
111 |
|
2 |
26 Feb 07 |
jari |
112 |
private Color selectionColor = Color.green; |
2 |
26 Feb 07 |
jari |
113 |
private Color labelColor = Color.black; |
2 |
26 Feb 07 |
jari |
114 |
private Insets insets = new Insets(10, 10, 10, 10); |
2 |
26 Feb 07 |
jari |
115 |
private boolean isDrawBorders; |
2 |
26 Feb 07 |
jari |
116 |
private boolean isAntiAliasing = true; |
2 |
26 Feb 07 |
jari |
117 |
private Dimension elementSize = new Dimension(20, 5); |
2 |
26 Feb 07 |
jari |
118 |
private int labelIndex = -1; |
2 |
26 Feb 07 |
jari |
119 |
private String status; |
2 |
26 Feb 07 |
jari |
120 |
private int shape_type = SHAPE_RECT; |
2 |
26 Feb 07 |
jari |
121 |
private int exptID; |
2 |
26 Feb 07 |
jari |
122 |
|
2 |
26 Feb 07 |
jari |
123 |
private int subnetIndex = 0; |
2 |
26 Feb 07 |
jari |
124 |
|
2 |
26 Feb 07 |
jari |
125 |
private JPopupMenu popup; |
2 |
26 Feb 07 |
jari |
126 |
private JWindow tipWindow; |
2 |
26 Feb 07 |
jari |
127 |
|
2 |
26 Feb 07 |
jari |
128 |
/** |
2 |
26 Feb 07 |
jari |
* Constructs a <code>RelevanceNetworkViewer</code> for specified experiment, |
2 |
26 Feb 07 |
jari |
* clusters, weights and sorted indices. |
2 |
26 Feb 07 |
jari |
131 |
*/ |
2 |
26 Feb 07 |
jari |
132 |
public RelevanceNetworkViewer(boolean isGenes, Experiment experiment, int[][] clusters, float[][] weights, int[] indices) { |
2 |
26 Feb 07 |
jari |
133 |
setLayout(null); |
2 |
26 Feb 07 |
jari |
134 |
setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
135 |
setFont(new Font("monospaced", Font.BOLD, this.elementSize.height)); |
2 |
26 Feb 07 |
jari |
136 |
Listener listener = new Listener(); |
2 |
26 Feb 07 |
jari |
137 |
this.popup = createJPopupMenu(listener); |
2 |
26 Feb 07 |
jari |
138 |
this.tipWindow = createTipWindow(); |
2 |
26 Feb 07 |
jari |
139 |
getContentComponent().addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
140 |
getContentComponent().addMouseMotionListener(listener); |
2 |
26 Feb 07 |
jari |
141 |
|
2 |
26 Feb 07 |
jari |
142 |
this.isGenes = isGenes; |
2 |
26 Feb 07 |
jari |
143 |
this.experiment = experiment; |
2 |
26 Feb 07 |
jari |
144 |
this.clusters = clusters; |
2 |
26 Feb 07 |
jari |
145 |
this.weights = weights; |
2 |
26 Feb 07 |
jari |
146 |
this.weight_min = getWeightsMinValue(weights); |
2 |
26 Feb 07 |
jari |
147 |
this.weight_scale = COLORS_DEEP/(getWeightsMaxValue(weights)-this.weight_min); |
2 |
26 Feb 07 |
jari |
148 |
this.indices = indices; |
2 |
26 Feb 07 |
jari |
149 |
RelevanceNetworkLayout layout = new RelevanceNetworkLayout(); |
2 |
26 Feb 07 |
jari |
150 |
this.coords = layout.doLayout(clusters, weights, RelevanceNetworkLayout.CIRCULAR_LAYOUT); |
2 |
26 Feb 07 |
jari |
151 |
this.selected = createSelected(clusters); |
2 |
26 Feb 07 |
jari |
152 |
this.draw = new boolean[clusters.length]; |
2 |
26 Feb 07 |
jari |
153 |
setPreferredSize(new Dimension(300, 300)); |
2 |
26 Feb 07 |
jari |
154 |
this.exptID = experiment.getId(); |
2 |
26 Feb 07 |
jari |
155 |
} |
2 |
26 Feb 07 |
jari |
156 |
public Expression getExpression(){ |
2 |
26 Feb 07 |
jari |
157 |
return new Expression(this, this.getClass(), "new", |
2 |
26 Feb 07 |
jari |
158 |
new Object[]{new Boolean(this.isGenes), this.experiment, this.clusters, this.weights, this.indices}); |
2 |
26 Feb 07 |
jari |
159 |
} |
2 |
26 Feb 07 |
jari |
160 |
public Color[] createPalette(Color color1, Color color2, int deep) { |
2 |
26 Feb 07 |
jari |
//BufferedImage image = new BufferedImage(deep, 1, BufferedImage.TYPE_3BYTE_BGR); |
2 |
26 Feb 07 |
jari |
//BufferedImage image = (BufferedImage)this.createImage(deep, 1); |
2 |
26 Feb 07 |
jari |
163 |
BufferedImage image = (BufferedImage)java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().createCompatibleImage(deep,1); |
2 |
26 Feb 07 |
jari |
164 |
|
2 |
26 Feb 07 |
jari |
165 |
Graphics2D graphics = image.createGraphics(); |
2 |
26 Feb 07 |
jari |
166 |
GradientPaint gp = new GradientPaint(0, 0, color1, deep-1, 0, color2); |
2 |
26 Feb 07 |
jari |
167 |
graphics.setPaint(gp); |
2 |
26 Feb 07 |
jari |
168 |
graphics.drawRect(0, 0, deep-1, 1); |
2 |
26 Feb 07 |
jari |
169 |
Color[] colors = new Color[deep]; |
2 |
26 Feb 07 |
jari |
170 |
for (int i=0; i<deep; i++) |
2 |
26 Feb 07 |
jari |
171 |
colors[i] = new Color(image.getRGB(i, 0)); |
2 |
26 Feb 07 |
jari |
172 |
return colors; |
2 |
26 Feb 07 |
jari |
173 |
} |
2 |
26 Feb 07 |
jari |
174 |
|
2 |
26 Feb 07 |
jari |
175 |
public static float getWeightsMinValue(float[][] array) { |
2 |
26 Feb 07 |
jari |
176 |
if (array == null || array.length == 0) |
2 |
26 Feb 07 |
jari |
177 |
return Float.NaN; |
2 |
26 Feb 07 |
jari |
178 |
float min = Float.MAX_VALUE; |
2 |
26 Feb 07 |
jari |
179 |
for (int i=0; i<array.length; i++) |
2 |
26 Feb 07 |
jari |
180 |
for (int j=1; j<array[i].length; j++) |
2 |
26 Feb 07 |
jari |
181 |
min = Math.min(min, array[i][j]); |
2 |
26 Feb 07 |
jari |
182 |
return min; |
2 |
26 Feb 07 |
jari |
183 |
} |
2 |
26 Feb 07 |
jari |
184 |
|
2 |
26 Feb 07 |
jari |
185 |
public static float getWeightsMaxValue(float[][] array) { |
2 |
26 Feb 07 |
jari |
186 |
if (array == null || array.length == 0) |
2 |
26 Feb 07 |
jari |
187 |
return Float.NaN; |
2 |
26 Feb 07 |
jari |
188 |
float max = -Float.MAX_VALUE; |
2 |
26 Feb 07 |
jari |
189 |
for (int i=0; i<array.length; i++) |
2 |
26 Feb 07 |
jari |
190 |
for (int j=1; j<array[i].length; j++) |
2 |
26 Feb 07 |
jari |
191 |
max = Math.max(max, array[i][j]); |
2 |
26 Feb 07 |
jari |
192 |
return max; |
2 |
26 Feb 07 |
jari |
193 |
} |
2 |
26 Feb 07 |
jari |
194 |
|
2 |
26 Feb 07 |
jari |
195 |
|
2 |
26 Feb 07 |
jari |
196 |
/** |
2 |
26 Feb 07 |
jari |
* Prepares an array of false values. |
2 |
26 Feb 07 |
jari |
198 |
*/ |
2 |
26 Feb 07 |
jari |
199 |
private boolean[] createSelected(int[][] cluster) { |
2 |
26 Feb 07 |
jari |
200 |
boolean[] selected = new boolean[cluster.length]; |
2 |
26 Feb 07 |
jari |
201 |
clearSelected(selected); |
2 |
26 Feb 07 |
jari |
202 |
return selected; |
2 |
26 Feb 07 |
jari |
203 |
} |
2 |
26 Feb 07 |
jari |
204 |
|
2 |
26 Feb 07 |
jari |
205 |
/** |
2 |
26 Feb 07 |
jari |
* Fills in an array with false values. |
2 |
26 Feb 07 |
jari |
207 |
*/ |
2 |
26 Feb 07 |
jari |
208 |
private void clearSelected(boolean[] selected) { |
2 |
26 Feb 07 |
jari |
209 |
Arrays.fill(selected, false); |
2 |
26 Feb 07 |
jari |
210 |
} |
2 |
26 Feb 07 |
jari |
211 |
|
2 |
26 Feb 07 |
jari |
212 |
/** |
2 |
26 Feb 07 |
jari |
* Overriden to have a focus. (deprecated as of 1.4, use isFocusable()) |
2 |
26 Feb 07 |
jari |
214 |
*/ |
2 |
26 Feb 07 |
jari |
/* public boolean isFocusTraversable() { |
2 |
26 Feb 07 |
jari |
return true; |
2 |
26 Feb 07 |
jari |
217 |
} |
2 |
26 Feb 07 |
jari |
218 |
*/ |
2 |
26 Feb 07 |
jari |
219 |
/** |
2 |
26 Feb 07 |
jari |
* Overriden to have a focus. (deprecated as of 1.4, use isFocusable()) |
2 |
26 Feb 07 |
jari |
221 |
*/ |
2 |
26 Feb 07 |
jari |
222 |
public boolean isFocusable() { |
2 |
26 Feb 07 |
jari |
223 |
return true; |
2 |
26 Feb 07 |
jari |
224 |
} |
2 |
26 Feb 07 |
jari |
225 |
|
2 |
26 Feb 07 |
jari |
226 |
/** |
2 |
26 Feb 07 |
jari |
* Paints relevance network into specified graphics. |
2 |
26 Feb 07 |
jari |
228 |
*/ |
2 |
26 Feb 07 |
jari |
229 |
public void paint(Graphics g1D) { |
2 |
26 Feb 07 |
jari |
230 |
super.paint(g1D); |
2 |
26 Feb 07 |
jari |
231 |
Graphics2D g = (Graphics2D)g1D; |
2 |
26 Feb 07 |
jari |
232 |
if (this.isAntiAliasing) {//Anti-aliasing is on |
2 |
26 Feb 07 |
jari |
233 |
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); |
2 |
26 Feb 07 |
jari |
234 |
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); |
2 |
26 Feb 07 |
jari |
235 |
} |
2 |
26 Feb 07 |
jari |
236 |
Rectangle bounds = g.getClipBounds(); |
2 |
26 Feb 07 |
jari |
237 |
float scale = getScale(); |
2 |
26 Feb 07 |
jari |
238 |
drawLines(g, bounds, scale); |
2 |
26 Feb 07 |
jari |
239 |
drawLabels(g, bounds, scale); |
2 |
26 Feb 07 |
jari |
240 |
drawShapes(g, bounds, scale); |
2 |
26 Feb 07 |
jari |
241 |
} |
2 |
26 Feb 07 |
jari |
242 |
|
2 |
26 Feb 07 |
jari |
243 |
/** |
2 |
26 Feb 07 |
jari |
* Calculates the viewer scale. |
2 |
26 Feb 07 |
jari |
245 |
*/ |
2 |
26 Feb 07 |
jari |
246 |
private final float getScale() { |
2 |
26 Feb 07 |
jari |
247 |
return Math.min(getPreferredSize().width-insets.left-insets.right, getPreferredSize().height-insets.top-insets.bottom); |
2 |
26 Feb 07 |
jari |
248 |
} |
2 |
26 Feb 07 |
jari |
249 |
|
2 |
26 Feb 07 |
jari |
250 |
/** |
2 |
26 Feb 07 |
jari |
* Checkes if a rectangle intersects with specified bounds. |
2 |
26 Feb 07 |
jari |
252 |
*/ |
2 |
26 Feb 07 |
jari |
253 |
private final boolean isRectIntersects(Rectangle rect, int x1, int y1, int x2, int y2) { |
2 |
26 Feb 07 |
jari |
254 |
if (x1 < rect.x && x2 < rect.x) { |
2 |
26 Feb 07 |
jari |
255 |
return false; |
2 |
26 Feb 07 |
jari |
256 |
} |
2 |
26 Feb 07 |
jari |
257 |
if (x1 > rect.x+rect.width && x2 > rect.x+rect.width) { |
2 |
26 Feb 07 |
jari |
258 |
return false; |
2 |
26 Feb 07 |
jari |
259 |
} |
2 |
26 Feb 07 |
jari |
260 |
if (y1 < rect.y && y2 < rect.y) { |
2 |
26 Feb 07 |
jari |
261 |
return false; |
2 |
26 Feb 07 |
jari |
262 |
} |
2 |
26 Feb 07 |
jari |
263 |
if (y1 > rect.y+rect.height && y2 > rect.y+rect.height) { |
2 |
26 Feb 07 |
jari |
264 |
return false; |
2 |
26 Feb 07 |
jari |
265 |
} |
2 |
26 Feb 07 |
jari |
266 |
return true; |
2 |
26 Feb 07 |
jari |
267 |
} |
2 |
26 Feb 07 |
jari |
268 |
|
2 |
26 Feb 07 |
jari |
269 |
/** |
2 |
26 Feb 07 |
jari |
* Checkes if (p1, p2) line intersects with vertical (x, y1, y2) one. |
2 |
26 Feb 07 |
jari |
* @return point the intersection coordinate. |
2 |
26 Feb 07 |
jari |
272 |
*/ |
2 |
26 Feb 07 |
jari |
273 |
private final boolean isIntersectVerticalLine(Point p1, Point p2, int x, int y1, int y2, Point point) { |
2 |
26 Feb 07 |
jari |
274 |
if ((p1.x < x && p2.x < x) || ((p1.x > x && p2.x > x))) { |
2 |
26 Feb 07 |
jari |
275 |
return false; |
2 |
26 Feb 07 |
jari |
276 |
} |
2 |
26 Feb 07 |
jari |
277 |
float tan = (float)(p2.y - p1.y)/(float)(p2.x - p1.x); |
2 |
26 Feb 07 |
jari |
278 |
float delta = tan*(float)(x - p1.x); |
2 |
26 Feb 07 |
jari |
279 |
float y = p1.y + delta; |
2 |
26 Feb 07 |
jari |
280 |
point.y = p1.y + Math.round(delta); |
2 |
26 Feb 07 |
jari |
281 |
point.x = x; |
2 |
26 Feb 07 |
jari |
282 |
return y > Math.min(y1, y2) && y < Math.max(y1, y2); |
2 |
26 Feb 07 |
jari |
283 |
} |
2 |
26 Feb 07 |
jari |
284 |
|
2 |
26 Feb 07 |
jari |
285 |
/** |
2 |
26 Feb 07 |
jari |
* Checkes if (p1, p2) line intersects with horizontal (y, x1, x2) one. |
2 |
26 Feb 07 |
jari |
* @return point the intersection coordinate. |
2 |
26 Feb 07 |
jari |
288 |
*/ |
2 |
26 Feb 07 |
jari |
289 |
private final boolean isIntersectHorizontalLine(Point p1, Point p2, int y, int x1, int x2, Point point) { |
2 |
26 Feb 07 |
jari |
290 |
if ((p1.y < y && p2.y < y) || ((p1.y > y && p2.y > y))) { |
2 |
26 Feb 07 |
jari |
291 |
return false; |
2 |
26 Feb 07 |
jari |
292 |
} |
2 |
26 Feb 07 |
jari |
293 |
float tan = (float)(p2.y - p1.y)/(float)(p2.x - p1.x); |
2 |
26 Feb 07 |
jari |
294 |
float delta = (float)(y - p1.y)/tan; |
2 |
26 Feb 07 |
jari |
295 |
float x = p1.x + delta; |
2 |
26 Feb 07 |
jari |
296 |
point.x = p1.x + Math.round(delta); |
2 |
26 Feb 07 |
jari |
297 |
point.y = y; |
2 |
26 Feb 07 |
jari |
298 |
return x > Math.min(x1, x2) && x < Math.max(x1, x2); |
2 |
26 Feb 07 |
jari |
299 |
} |
2 |
26 Feb 07 |
jari |
300 |
|
2 |
26 Feb 07 |
jari |
301 |
/** |
2 |
26 Feb 07 |
jari |
* Checkes if points p1 or p2 are an internal point of a rect. |
2 |
26 Feb 07 |
jari |
* @return n the coordinaties of an internal point. |
2 |
26 Feb 07 |
jari |
304 |
*/ |
2 |
26 Feb 07 |
jari |
305 |
private final boolean isInternalPoint(Rectangle rect, Point p1, Point p2, Point n) { |
2 |
26 Feb 07 |
jari |
306 |
boolean p1b = rect.contains(p1); |
2 |
26 Feb 07 |
jari |
307 |
boolean p2b = rect.contains(p2); |
2 |
26 Feb 07 |
jari |
308 |
if (p1b) { |
2 |
26 Feb 07 |
jari |
309 |
n.setLocation(p1); |
2 |
26 Feb 07 |
jari |
310 |
return true; |
2 |
26 Feb 07 |
jari |
311 |
} |
2 |
26 Feb 07 |
jari |
312 |
if (p2b) { |
2 |
26 Feb 07 |
jari |
313 |
n.setLocation(p2); |
2 |
26 Feb 07 |
jari |
314 |
return true; |
2 |
26 Feb 07 |
jari |
315 |
} |
2 |
26 Feb 07 |
jari |
316 |
return false; |
2 |
26 Feb 07 |
jari |
317 |
} |
2 |
26 Feb 07 |
jari |
318 |
|
2 |
26 Feb 07 |
jari |
319 |
/** |
2 |
26 Feb 07 |
jari |
* Checkes if (p1, p2) line intersects rect. |
2 |
26 Feb 07 |
jari |
* @return n1, n2 points which is intersection of the line and the rect. |
2 |
26 Feb 07 |
jari |
322 |
*/ |
2 |
26 Feb 07 |
jari |
323 |
private final boolean isLineIntersects(Rectangle rect, Point p1, Point p2, Point n1, Point n2) { |
2 |
26 Feb 07 |
jari |
324 |
n1.setLocation(p1); |
2 |
26 Feb 07 |
jari |
325 |
n2.setLocation(p2); |
2 |
26 Feb 07 |
jari |
326 |
if (rect.contains(p1) && rect.contains(p2)) { |
2 |
26 Feb 07 |
jari |
327 |
return true; |
2 |
26 Feb 07 |
jari |
328 |
} |
2 |
26 Feb 07 |
jari |
329 |
if (p1.x < rect.x && p2.x < rect.x) { |
2 |
26 Feb 07 |
jari |
330 |
return false; |
2 |
26 Feb 07 |
jari |
331 |
} |
2 |
26 Feb 07 |
jari |
332 |
if (p1.y < rect.y && p2.y < rect.y) { |
2 |
26 Feb 07 |
jari |
333 |
return false; |
2 |
26 Feb 07 |
jari |
334 |
} |
2 |
26 Feb 07 |
jari |
335 |
if (p1.x > rect.x+rect.width && p2.x > rect.x+rect.width) { |
2 |
26 Feb 07 |
jari |
336 |
return false; |
2 |
26 Feb 07 |
jari |
337 |
} |
2 |
26 Feb 07 |
jari |
338 |
if (p1.y > rect.y+rect.height && p2.y > rect.y+rect.height) { |
2 |
26 Feb 07 |
jari |
339 |
return false; |
2 |
26 Feb 07 |
jari |
340 |
} |
2 |
26 Feb 07 |
jari |
341 |
if (p1.x == p2.x) { |
2 |
26 Feb 07 |
jari |
// vertical line |
2 |
26 Feb 07 |
jari |
343 |
if (p1.y < rect.y) { |
2 |
26 Feb 07 |
jari |
344 |
n1.y = rect.y; |
2 |
26 Feb 07 |
jari |
345 |
} else if (p1.y > rect.y+rect.height) { |
2 |
26 Feb 07 |
jari |
346 |
n1.y = rect.y+rect.height; |
2 |
26 Feb 07 |
jari |
347 |
} |
2 |
26 Feb 07 |
jari |
348 |
if (p2.y < rect.y) { |
2 |
26 Feb 07 |
jari |
349 |
n2.y = rect.y; |
2 |
26 Feb 07 |
jari |
350 |
} else if (p2.y > rect.y+rect.height) { |
2 |
26 Feb 07 |
jari |
351 |
n2.y = rect.y+rect.height; |
2 |
26 Feb 07 |
jari |
352 |
} |
2 |
26 Feb 07 |
jari |
353 |
return true; |
2 |
26 Feb 07 |
jari |
354 |
} |
2 |
26 Feb 07 |
jari |
355 |
if (p1.y == p2.y) { |
2 |
26 Feb 07 |
jari |
// horizontal line |
2 |
26 Feb 07 |
jari |
357 |
if (p1.x < rect.x) { |
2 |
26 Feb 07 |
jari |
358 |
n1.x = rect.x; |
2 |
26 Feb 07 |
jari |
359 |
} else if (p1.x > rect.x+rect.width) { |
2 |
26 Feb 07 |
jari |
360 |
n1.x = rect.x+rect.width; |
2 |
26 Feb 07 |
jari |
361 |
} |
2 |
26 Feb 07 |
jari |
362 |
if (p2.x < rect.x) { |
2 |
26 Feb 07 |
jari |
363 |
n2.x = rect.x; |
2 |
26 Feb 07 |
jari |
364 |
} else if (p2.x > rect.x+rect.width) { |
2 |
26 Feb 07 |
jari |
365 |
n2.x = rect.x+rect.width; |
2 |
26 Feb 07 |
jari |
366 |
} |
2 |
26 Feb 07 |
jari |
367 |
return true; |
2 |
26 Feb 07 |
jari |
368 |
} |
2 |
26 Feb 07 |
jari |
369 |
if (isIntersectVerticalLine(p1, p2, rect.x, rect.y, rect.y+rect.height, n1)) { |
2 |
26 Feb 07 |
jari |
370 |
if (isIntersectVerticalLine(p1, p2, rect.x+rect.width, rect.y, rect.y+rect.height, n2)) { |
2 |
26 Feb 07 |
jari |
371 |
} else if (isIntersectHorizontalLine(p1, p2, rect.y, rect.x, rect.x+rect.width, n2)) { |
2 |
26 Feb 07 |
jari |
372 |
} else if (isIntersectHorizontalLine(p1, p2, rect.y+rect.height, rect.x, rect.x+rect.width, n2)) { |
2 |
26 Feb 07 |
jari |
373 |
} else if (isInternalPoint(rect, p1, p2, n2)) { |
2 |
26 Feb 07 |
jari |
374 |
} else { |
2 |
26 Feb 07 |
jari |
375 |
return false; |
2 |
26 Feb 07 |
jari |
376 |
} |
2 |
26 Feb 07 |
jari |
377 |
return true; |
2 |
26 Feb 07 |
jari |
378 |
} else if (isIntersectVerticalLine(p1, p2, rect.x+rect.width, rect.y, rect.y+rect.height, n1)) { |
2 |
26 Feb 07 |
jari |
379 |
if (isIntersectHorizontalLine(p1, p2, rect.y+rect.height, rect.x, rect.x+rect.width, n2)) { |
2 |
26 Feb 07 |
jari |
380 |
} else if (isIntersectHorizontalLine(p1, p2, rect.y, rect.x, rect.x+rect.width, n2)) { |
2 |
26 Feb 07 |
jari |
381 |
} else if (isInternalPoint(rect, p1, p2, n2)) { |
2 |
26 Feb 07 |
jari |
382 |
} else { |
2 |
26 Feb 07 |
jari |
383 |
return false; |
2 |
26 Feb 07 |
jari |
384 |
} |
2 |
26 Feb 07 |
jari |
385 |
return true; |
2 |
26 Feb 07 |
jari |
386 |
} else if (isIntersectHorizontalLine(p1, p2, rect.y, rect.x, rect.x+rect.width, n1)) { |
2 |
26 Feb 07 |
jari |
387 |
if (isIntersectHorizontalLine(p1, p2, rect.y+rect.height, rect.x, rect.x+rect.width, n2)) { |
2 |
26 Feb 07 |
jari |
388 |
} else if (isInternalPoint(rect, p1, p2, n2)) { |
2 |
26 Feb 07 |
jari |
389 |
} else { |
2 |
26 Feb 07 |
jari |
390 |
return false; |
2 |
26 Feb 07 |
jari |
391 |
} |
2 |
26 Feb 07 |
jari |
392 |
return true; |
2 |
26 Feb 07 |
jari |
393 |
} else if (isIntersectHorizontalLine(p1, p2, rect.y+rect.height, rect.x, rect.x+rect.width, n1)) { |
2 |
26 Feb 07 |
jari |
394 |
if (isInternalPoint(rect, p1, p2, n2)) { |
2 |
26 Feb 07 |
jari |
395 |
} else { |
2 |
26 Feb 07 |
jari |
396 |
return false; |
2 |
26 Feb 07 |
jari |
397 |
} |
2 |
26 Feb 07 |
jari |
398 |
return true; |
2 |
26 Feb 07 |
jari |
399 |
} |
2 |
26 Feb 07 |
jari |
400 |
return false; |
2 |
26 Feb 07 |
jari |
401 |
} |
2 |
26 Feb 07 |
jari |
402 |
|
2 |
26 Feb 07 |
jari |
403 |
/** |
2 |
26 Feb 07 |
jari |
* Draws a network links with specified bounds. |
2 |
26 Feb 07 |
jari |
405 |
*/ |
2 |
26 Feb 07 |
jari |
406 |
private final void drawLines(Graphics2D g, Rectangle bounds, float scale) { |
2 |
26 Feb 07 |
jari |
407 |
float x1, y1, x2, y2; |
2 |
26 Feb 07 |
jari |
408 |
Point p1 = new Point(); |
2 |
26 Feb 07 |
jari |
409 |
Point p2 = new Point(); |
2 |
26 Feb 07 |
jari |
410 |
Point n1 = new Point(); |
2 |
26 Feb 07 |
jari |
411 |
Point n2 = new Point(); |
2 |
26 Feb 07 |
jari |
412 |
g.setColor(Color.black); |
2 |
26 Feb 07 |
jari |
413 |
int spot_root, spot_child; |
2 |
26 Feb 07 |
jari |
414 |
Arrays.fill(this.draw, true); |
2 |
26 Feb 07 |
jari |
415 |
for (int i=0; i<this.clusters.length; i++) { |
2 |
26 Feb 07 |
jari |
416 |
if (this.clusters[i].length > 1) { |
2 |
26 Feb 07 |
jari |
417 |
spot_root = this.clusters[i][0]; |
2 |
26 Feb 07 |
jari |
418 |
this.draw[spot_root] = false; |
2 |
26 Feb 07 |
jari |
419 |
x1 = (this.coords[spot_root][0])*scale+insets.left; |
2 |
26 Feb 07 |
jari |
420 |
y1 = (this.coords[spot_root][1])*scale+insets.top; |
2 |
26 Feb 07 |
jari |
421 |
for (int j=1; j<this.clusters[i].length; j++) { |
2 |
26 Feb 07 |
jari |
422 |
if (this.weights != null && this.weights[i][j] < this.links_threshold) |
2 |
26 Feb 07 |
jari |
423 |
continue; |
2 |
26 Feb 07 |
jari |
424 |
if (this.isLinksColor) |
2 |
26 Feb 07 |
jari |
425 |
g.setColor(LINKS_PALETTE[(int)((this.weights[i][j]-this.weight_min)*this.weight_scale-0.001f)]); |
2 |
26 Feb 07 |
jari |
426 |
|
2 |
26 Feb 07 |
jari |
427 |
spot_child = this.clusters[i][j]; |
2 |
26 Feb 07 |
jari |
428 |
if (this.draw[spot_child]) { |
2 |
26 Feb 07 |
jari |
429 |
x2 = (this.coords[spot_child][0])*scale+insets.left; |
2 |
26 Feb 07 |
jari |
430 |
y2 = (this.coords[spot_child][1])*scale+insets.top; |
2 |
26 Feb 07 |
jari |
431 |
p1.move((int)x1, (int)y1); |
2 |
26 Feb 07 |
jari |
432 |
p2.move((int)x2, (int)y2); |
2 |
26 Feb 07 |
jari |
433 |
if (isLineIntersects(bounds, p1, p2, n1, n2)) { |
2 |
26 Feb 07 |
jari |
434 |
g.drawLine(n1.x, n1.y, n2.x, n2.y); |
2 |
26 Feb 07 |
jari |
435 |
} |
2 |
26 Feb 07 |
jari |
436 |
} |
2 |
26 Feb 07 |
jari |
437 |
} |
2 |
26 Feb 07 |
jari |
438 |
} |
2 |
26 Feb 07 |
jari |
439 |
} |
2 |
26 Feb 07 |
jari |
440 |
} |
2 |
26 Feb 07 |
jari |
441 |
|
2 |
26 Feb 07 |
jari |
442 |
/** |
2 |
26 Feb 07 |
jari |
* Checkes if an element with x and y coordinaties intersects a rect. |
2 |
26 Feb 07 |
jari |
444 |
*/ |
2 |
26 Feb 07 |
jari |
445 |
private final boolean isElementIntersects(Rectangle rect, int x, int y) { |
2 |
26 Feb 07 |
jari |
446 |
int X1 = x-this.elementSize.width/2; |
2 |
26 Feb 07 |
jari |
447 |
int Y1 = y-this.elementSize.height/2; |
2 |
26 Feb 07 |
jari |
448 |
int X2 = x+this.elementSize.width/2; |
2 |
26 Feb 07 |
jari |
449 |
int Y2 = y+this.elementSize.height/2; |
2 |
26 Feb 07 |
jari |
450 |
return isRectIntersects(rect, X1, Y1, X2, Y2); |
2 |
26 Feb 07 |
jari |
451 |
} |
2 |
26 Feb 07 |
jari |
452 |
|
2 |
26 Feb 07 |
jari |
453 |
/** |
2 |
26 Feb 07 |
jari |
* Fills in a shape with specified coordinaties. |
2 |
26 Feb 07 |
jari |
455 |
*/ |
2 |
26 Feb 07 |
jari |
456 |
private final void fillShape(Graphics g, int x, int y) { |
2 |
26 Feb 07 |
jari |
457 |
if (this.shape_type == SHAPE_RECT) { |
2 |
26 Feb 07 |
jari |
458 |
g.fillRect(x, y, this.elementSize.width, this.elementSize.height); |
2 |
26 Feb 07 |
jari |
459 |
} else { |
2 |
26 Feb 07 |
jari |
460 |
g.fillOval(x, y, this.elementSize.width, this.elementSize.height); |
2 |
26 Feb 07 |
jari |
461 |
} |
2 |
26 Feb 07 |
jari |
462 |
} |
2 |
26 Feb 07 |
jari |
463 |
|
2 |
26 Feb 07 |
jari |
464 |
/** |
2 |
26 Feb 07 |
jari |
* Draws a shape with specified coordinaties. |
2 |
26 Feb 07 |
jari |
466 |
*/ |
2 |
26 Feb 07 |
jari |
467 |
private final void drawShape(Graphics g, int x, int y) { |
2 |
26 Feb 07 |
jari |
468 |
drawShape(g, x, y, this.elementSize.width-1, this.elementSize.height-1); |
2 |
26 Feb 07 |
jari |
469 |
} |
2 |
26 Feb 07 |
jari |
470 |
|
2 |
26 Feb 07 |
jari |
471 |
/** |
2 |
26 Feb 07 |
jari |
* Draws a shape with specified bounds. |
2 |
26 Feb 07 |
jari |
473 |
*/ |
2 |
26 Feb 07 |
jari |
474 |
private final void drawShape(Graphics g, int x, int y, int width, int height) { |
2 |
26 Feb 07 |
jari |
475 |
if (this.shape_type == SHAPE_RECT) { |
2 |
26 Feb 07 |
jari |
476 |
g.drawRect(x, y, width, height); |
2 |
26 Feb 07 |
jari |
477 |
} else { |
2 |
26 Feb 07 |
jari |
478 |
g.drawOval(x, y, width, height); |
2 |
26 Feb 07 |
jari |
479 |
} |
2 |
26 Feb 07 |
jari |
480 |
} |
2 |
26 Feb 07 |
jari |
481 |
|
2 |
26 Feb 07 |
jari |
482 |
/** |
2 |
26 Feb 07 |
jari |
* Draws a node with specified index and coordinaties. |
2 |
26 Feb 07 |
jari |
484 |
*/ |
2 |
26 Feb 07 |
jari |
485 |
private final void drawNode(Graphics g, int index, int x, int y) { |
2 |
26 Feb 07 |
jari |
486 |
if (this.selected[index]) { |
2 |
26 Feb 07 |
jari |
487 |
g.setColor(this.selectionColor); |
2 |
26 Feb 07 |
jari |
488 |
} else { |
2 |
26 Feb 07 |
jari |
489 |
g.setColor(getProbeColor(index)); |
2 |
26 Feb 07 |
jari |
490 |
} |
2 |
26 Feb 07 |
jari |
491 |
fillShape(g, x, y); |
2 |
26 Feb 07 |
jari |
492 |
if (this.isDrawBorders) { |
2 |
26 Feb 07 |
jari |
493 |
g.setColor(Color.black); |
2 |
26 Feb 07 |
jari |
494 |
drawShape(g, x, y); |
2 |
26 Feb 07 |
jari |
495 |
} |
2 |
26 Feb 07 |
jari |
496 |
} |
2 |
26 Feb 07 |
jari |
497 |
|
2 |
26 Feb 07 |
jari |
498 |
/** |
2 |
26 Feb 07 |
jari |
* Draws a network nodes with specified canvas bounds. |
2 |
26 Feb 07 |
jari |
500 |
*/ |
2 |
26 Feb 07 |
jari |
501 |
private final void drawShapes(Graphics2D g, Rectangle bounds, float scale) { |
2 |
26 Feb 07 |
jari |
502 |
float x, y; |
2 |
26 Feb 07 |
jari |
503 |
int spot; |
2 |
26 Feb 07 |
jari |
504 |
Arrays.fill(this.draw, true); |
2 |
26 Feb 07 |
jari |
505 |
for (int i=0; i<this.clusters.length; i++) { |
2 |
26 Feb 07 |
jari |
506 |
if (this.clusters[i].length > 1) { |
2 |
26 Feb 07 |
jari |
507 |
for (int j=0; j<this.clusters[i].length; j++) { |
2 |
26 Feb 07 |
jari |
508 |
spot = this.clusters[i][j]; |
2 |
26 Feb 07 |
jari |
509 |
if (this.draw[spot]) { |
2 |
26 Feb 07 |
jari |
510 |
this.draw[spot] = false; |
2 |
26 Feb 07 |
jari |
511 |
x = this.coords[spot][0]*scale+insets.left; |
2 |
26 Feb 07 |
jari |
512 |
y = this.coords[spot][1]*scale+insets.top; |
2 |
26 Feb 07 |
jari |
513 |
if (isElementIntersects(bounds, (int)x, (int)y)) { |
2 |
26 Feb 07 |
jari |
514 |
drawNode(g, spot, (int)x-this.elementSize.width/2, (int)y-this.elementSize.height/2); |
2 |
26 Feb 07 |
jari |
515 |
} |
2 |
26 Feb 07 |
jari |
516 |
} |
2 |
26 Feb 07 |
jari |
517 |
} |
2 |
26 Feb 07 |
jari |
518 |
|
2 |
26 Feb 07 |
jari |
519 |
} |
2 |
26 Feb 07 |
jari |
520 |
} |
2 |
26 Feb 07 |
jari |
521 |
} |
2 |
26 Feb 07 |
jari |
522 |
|
2 |
26 Feb 07 |
jari |
523 |
/** |
2 |
26 Feb 07 |
jari |
* Draws a node with specified index. |
2 |
26 Feb 07 |
jari |
525 |
*/ |
2 |
26 Feb 07 |
jari |
526 |
private final void drawSpot(Graphics g, int index) { |
2 |
26 Feb 07 |
jari |
527 |
float scale = getScale(); |
2 |
26 Feb 07 |
jari |
528 |
float x = this.coords[index][0]*scale+insets.left; |
2 |
26 Feb 07 |
jari |
529 |
float y = this.coords[index][1]*scale+insets.top; |
2 |
26 Feb 07 |
jari |
530 |
drawNode(g, index, (int)x-this.elementSize.width/2, (int)y-this.elementSize.height/2); |
2 |
26 Feb 07 |
jari |
531 |
} |
2 |
26 Feb 07 |
jari |
532 |
|
2 |
26 Feb 07 |
jari |
533 |
/** |
2 |
26 Feb 07 |
jari |
* Draws a selected node with specified index. |
2 |
26 Feb 07 |
jari |
535 |
*/ |
2 |
26 Feb 07 |
jari |
536 |
private final void drawSelectedSpot(Graphics g, int index) { |
2 |
26 Feb 07 |
jari |
537 |
float scale = getScale(); |
2 |
26 Feb 07 |
jari |
538 |
float x = this.coords[index][0]*scale+insets.left; |
2 |
26 Feb 07 |
jari |
539 |
float y = this.coords[index][1]*scale+insets.top; |
2 |
26 Feb 07 |
jari |
540 |
drawNode(g, index, (int)x-this.elementSize.width/2, (int)y-this.elementSize.height/2); |
2 |
26 Feb 07 |
jari |
541 |
g.setColor(Color.white); |
2 |
26 Feb 07 |
jari |
542 |
drawShape(g, (int)x-this.elementSize.width/2+1, (int)y-this.elementSize.height/2+1, this.elementSize.width-3, this.elementSize.height-3); |
2 |
26 Feb 07 |
jari |
543 |
} |
2 |
26 Feb 07 |
jari |
544 |
|
2 |
26 Feb 07 |
jari |
// store view port image |
2 |
26 Feb 07 |
jari |
546 |
private void onStartDrawZoom() { |
2 |
26 Feb 07 |
jari |
547 |
prevZoomRect.setBounds(0, 0, 0, 0); |
2 |
26 Feb 07 |
jari |
548 |
} |
2 |
26 Feb 07 |
jari |
549 |
|
2 |
26 Feb 07 |
jari |
550 |
/** |
2 |
26 Feb 07 |
jari |
* Draws zoom rectangle. |
2 |
26 Feb 07 |
jari |
552 |
*/ |
2 |
26 Feb 07 |
jari |
553 |
private void drawZoomRect(Rectangle rect) { |
2 |
26 Feb 07 |
jari |
554 |
Graphics2D g = (Graphics2D)getGraphics(); |
2 |
26 Feb 07 |
jari |
555 |
g.setColor(Color.black); |
2 |
26 Feb 07 |
jari |
556 |
g.setXORMode(getBackground()); |
2 |
26 Feb 07 |
jari |
557 |
g.drawRect(prevZoomRect.x, prevZoomRect.y, prevZoomRect.width-1, prevZoomRect.height-1); |
2 |
26 Feb 07 |
jari |
558 |
prevZoomRect.setBounds(rect); |
2 |
26 Feb 07 |
jari |
559 |
g.drawRect(rect.x, rect.y, rect.width-1, rect.height-1); |
2 |
26 Feb 07 |
jari |
560 |
g.setPaintMode(); |
2 |
26 Feb 07 |
jari |
561 |
g.dispose(); |
2 |
26 Feb 07 |
jari |
562 |
} |
2 |
26 Feb 07 |
jari |
563 |
|
2 |
26 Feb 07 |
jari |
564 |
/** |
2 |
26 Feb 07 |
jari |
* Checkes if a string intersects specified rectangle. |
2 |
26 Feb 07 |
jari |
566 |
*/ |
2 |
26 Feb 07 |
jari |
567 |
private final boolean isLabelIntersects(FontMetrics fm, Rectangle rect, String str, int x, int y) { |
2 |
26 Feb 07 |
jari |
568 |
int width = fm.stringWidth(str); |
2 |
26 Feb 07 |
jari |
569 |
int height = fm.getHeight(); |
2 |
26 Feb 07 |
jari |
570 |
return isRectIntersects(rect, x, y, x+width, y+height); |
2 |
26 Feb 07 |
jari |
571 |
} |
2 |
26 Feb 07 |
jari |
572 |
|
2 |
26 Feb 07 |
jari |
573 |
/** |
2 |
26 Feb 07 |
jari |
* Calculates max label width. |
2 |
26 Feb 07 |
jari |
575 |
*/ |
2 |
26 Feb 07 |
jari |
576 |
private int getMaxLabelWidth() { |
2 |
26 Feb 07 |
jari |
577 |
if (this.isGenes && this.labelIndex < 0) |
2 |
26 Feb 07 |
jari |
578 |
return 0; |
2 |
26 Feb 07 |
jari |
579 |
Graphics2D g = (Graphics2D)getGraphics(); |
2 |
26 Feb 07 |
jari |
580 |
if (this.isAntiAliasing) {//Anti-aliasing is on |
2 |
26 Feb 07 |
jari |
581 |
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); |
2 |
26 Feb 07 |
jari |
582 |
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); |
2 |
26 Feb 07 |
jari |
583 |
} |
2 |
26 Feb 07 |
jari |
584 |
FontMetrics fm = g.getFontMetrics(); |
2 |
26 Feb 07 |
jari |
585 |
String str; |
2 |
26 Feb 07 |
jari |
586 |
int max = 0; |
2 |
26 Feb 07 |
jari |
587 |
for (int i=0; i<this.clusters.length; i++) { |
2 |
26 Feb 07 |
jari |
588 |
if (this.clusters[i].length > 1) { |
2 |
26 Feb 07 |
jari |
589 |
for (int j=0; j<this.clusters[i].length; j++) { |
2 |
26 Feb 07 |
jari |
590 |
str = isGenes ? this.data.getElementAttribute(this.clusters[i][j], this.labelIndex) : this.data.getSampleName(this.clusters[i][j]); |
2 |
26 Feb 07 |
jari |
591 |
if (str != null) { |
2 |
26 Feb 07 |
jari |
592 |
max = Math.max(max, fm.stringWidth(str)); |
2 |
26 Feb 07 |
jari |
593 |
} |
2 |
26 Feb 07 |
jari |
594 |
} |
2 |
26 Feb 07 |
jari |
595 |
} |
2 |
26 Feb 07 |
jari |
596 |
} |
2 |
26 Feb 07 |
jari |
597 |
return max; |
2 |
26 Feb 07 |
jari |
598 |
} |
2 |
26 Feb 07 |
jari |
599 |
|
2 |
26 Feb 07 |
jari |
600 |
/** |
2 |
26 Feb 07 |
jari |
* Draws nodes labels. |
2 |
26 Feb 07 |
jari |
602 |
*/ |
2 |
26 Feb 07 |
jari |
603 |
private final void drawLabels(Graphics2D g, Rectangle bounds, float scale) { |
2 |
26 Feb 07 |
jari |
604 |
if (this.isGenes && this.labelIndex < 0) |
2 |
26 Feb 07 |
jari |
605 |
return; |
2 |
26 Feb 07 |
jari |
606 |
float x, y; |
2 |
26 Feb 07 |
jari |
607 |
String str; |
2 |
26 Feb 07 |
jari |
608 |
g.setColor(this.labelColor); |
2 |
26 Feb 07 |
jari |
609 |
FontMetrics fm = g.getFontMetrics(); |
2 |
26 Feb 07 |
jari |
610 |
int spot; |
2 |
26 Feb 07 |
jari |
611 |
Arrays.fill(this.draw, true); |
2 |
26 Feb 07 |
jari |
612 |
for (int i=0; i<this.clusters.length; i++) { |
2 |
26 Feb 07 |
jari |
613 |
if (this.clusters[i].length > 1) { |
2 |
26 Feb 07 |
jari |
614 |
for (int j=0; j<this.clusters[i].length; j++) { |
2 |
26 Feb 07 |
jari |
615 |
spot = this.clusters[i][j]; |
2 |
26 Feb 07 |
jari |
616 |
if (this.draw[spot]) { |
2 |
26 Feb 07 |
jari |
617 |
this.draw[spot] = false; |
2 |
26 Feb 07 |
jari |
618 |
x = (this.coords[spot][0])*scale+this.insets.left+this.elementSize.width/2+10; |
2 |
26 Feb 07 |
jari |
619 |
y = (this.coords[spot][1])*scale+this.insets.top+this.elementSize.height/2; |
2 |
26 Feb 07 |
jari |
//EH fix submitted by angier@imima.fr |
2 |
26 Feb 07 |
jari |
//str = isGenes ? this.data.getElementAttribute(spot, this.labelIndex) : this.data.getSampleName(spot); |
2 |
26 Feb 07 |
jari |
622 |
str = isGenes ? this.data.getElementAttribute(experiment.getGeneIndexMappedToData(spot), this.labelIndex) : this.data.getSampleName(spot); |
2 |
26 Feb 07 |
jari |
623 |
if (isLabelIntersects(fm, bounds, str, (int)x, (int)y)) |
2 |
26 Feb 07 |
jari |
624 |
g.drawString(str, (int)x, (int)y); |
2 |
26 Feb 07 |
jari |
625 |
} |
2 |
26 Feb 07 |
jari |
626 |
} |
2 |
26 Feb 07 |
jari |
627 |
|
2 |
26 Feb 07 |
jari |
628 |
} |
2 |
26 Feb 07 |
jari |
629 |
} |
2 |
26 Feb 07 |
jari |
630 |
} |
2 |
26 Feb 07 |
jari |
631 |
|
2 |
26 Feb 07 |
jari |
632 |
/** |
2 |
26 Feb 07 |
jari |
* @return a color for a specified probe. |
2 |
26 Feb 07 |
jari |
634 |
*/ |
2 |
26 Feb 07 |
jari |
635 |
private final Color getProbeColor(int probe) { |
2 |
26 Feb 07 |
jari |
636 |
Color color = isGenes ? this.data.getProbeColor(probe) : this.data.getExperimentColor(probe); |
2 |
26 Feb 07 |
jari |
637 |
return color == null ? Color.gray : color; |
2 |
26 Feb 07 |
jari |
638 |
} |
2 |
26 Feb 07 |
jari |
639 |
|
2 |
26 Feb 07 |
jari |
640 |
/** |
2 |
26 Feb 07 |
jari |
* @return this component. |
2 |
26 Feb 07 |
jari |
642 |
*/ |
2 |
26 Feb 07 |
jari |
643 |
public JComponent getContentComponent() { |
2 |
26 Feb 07 |
jari |
644 |
return this; |
2 |
26 Feb 07 |
jari |
645 |
} |
2 |
26 Feb 07 |
jari |
646 |
|
2 |
26 Feb 07 |
jari |
647 |
/** |
2 |
26 Feb 07 |
jari |
* @return null. |
2 |
26 Feb 07 |
jari |
649 |
*/ |
2 |
26 Feb 07 |
jari |
650 |
public JComponent getHeaderComponent() { |
2 |
26 Feb 07 |
jari |
651 |
return null; |
2 |
26 Feb 07 |
jari |
652 |
} |
2 |
26 Feb 07 |
jari |
653 |
|
2 |
26 Feb 07 |
jari |
654 |
/** |
2 |
26 Feb 07 |
jari |
* Updates some attributies when the viewer is selected. |
2 |
26 Feb 07 |
jari |
656 |
*/ |
2 |
26 Feb 07 |
jari |
657 |
public void onSelected(IFramework framework) { |
2 |
26 Feb 07 |
jari |
658 |
this.framework = framework; |
2 |
26 Feb 07 |
jari |
659 |
this.data = framework.getData(); |
2 |
26 Feb 07 |
jari |
660 |
|
2 |
26 Feb 07 |
jari |
661 |
|
2 |
26 Feb 07 |
jari |
662 |
/* |
2 |
26 Feb 07 |
jari |
//jcb to make it select cluser index |
2 |
26 Feb 07 |
jari |
Object userObj = framework.getUserObject(); |
2 |
26 Feb 07 |
jari |
// if(userObj != null) { |
2 |
26 Feb 07 |
jari |
subnetIndex = 0; //Integer.parseInt(userObj); |
2 |
26 Feb 07 |
jari |
667 |
|
2 |
26 Feb 07 |
jari |
this.indices = clusters[subnetIndex]; |
2 |
26 Feb 07 |
jari |
int [][] selCluster = new int[1][]; |
2 |
26 Feb 07 |
jari |
float [][] selWeights = new float[1][]; |
2 |
26 Feb 07 |
jari |
671 |
|
2 |
26 Feb 07 |
jari |
selCluster[0] = indices; |
2 |
26 Feb 07 |
jari |
selWeights[0] = weights[0]; |
2 |
26 Feb 07 |
jari |
674 |
|
2 |
26 Feb 07 |
jari |
RelevanceNetworkLayout layout = new RelevanceNetworkLayout(); |
2 |
26 Feb 07 |
jari |
this.coords = layout.doLayout(selCluster, selWeights, RelevanceNetworkLayout.CIRCULAR_LAYOUT); |
2 |
26 Feb 07 |
jari |
this.selected = createSelected(selCluster); |
2 |
26 Feb 07 |
jari |
this.draw = new boolean[selCluster.length]; |
2 |
26 Feb 07 |
jari |
679 |
|
2 |
26 Feb 07 |
jari |
680 |
// } |
2 |
26 Feb 07 |
jari |
681 |
*/ |
2 |
26 Feb 07 |
jari |
682 |
|
2 |
26 Feb 07 |
jari |
683 |
|
2 |
26 Feb 07 |
jari |
684 |
IDisplayMenu menu = framework.getDisplayMenu(); |
2 |
26 Feb 07 |
jari |
685 |
this.isDrawBorders = menu.isDrawingBorder(); |
2 |
26 Feb 07 |
jari |
686 |
this.isAntiAliasing = menu.isAntiAliasing(); |
2 |
26 Feb 07 |
jari |
687 |
this.labelIndex = menu.getLabelIndex(); |
2 |
26 Feb 07 |
jari |
688 |
setElementSize(menu.getElementSize()); |
2 |
26 Feb 07 |
jari |
689 |
updateSize(); |
2 |
26 Feb 07 |
jari |
690 |
} |
2 |
26 Feb 07 |
jari |
691 |
|
2 |
26 Feb 07 |
jari |
692 |
/** |
2 |
26 Feb 07 |
jari |
* Sets the viewer data. |
2 |
26 Feb 07 |
jari |
694 |
*/ |
2 |
26 Feb 07 |
jari |
695 |
public void onDataChanged(IData data) { |
2 |
26 Feb 07 |
jari |
696 |
this.data = data; |
2 |
26 Feb 07 |
jari |
697 |
} |
2 |
26 Feb 07 |
jari |
698 |
|
2 |
26 Feb 07 |
jari |
699 |
/** |
2 |
26 Feb 07 |
jari |
* Updates some attributies when the display menu is changed. |
2 |
26 Feb 07 |
jari |
701 |
*/ |
2 |
26 Feb 07 |
jari |
702 |
public void onMenuChanged(IDisplayMenu menu) { |
2 |
26 Feb 07 |
jari |
703 |
this.isDrawBorders = menu.isDrawingBorder(); |
2 |
26 Feb 07 |
jari |
704 |
this.isAntiAliasing = menu.isAntiAliasing(); |
2 |
26 Feb 07 |
jari |
705 |
this.labelIndex = menu.getLabelIndex(); |
2 |
26 Feb 07 |
jari |
706 |
setElementSize(menu.getElementSize()); |
2 |
26 Feb 07 |
jari |
707 |
updateSize(); |
2 |
26 Feb 07 |
jari |
708 |
} |
2 |
26 Feb 07 |
jari |
709 |
|
2 |
26 Feb 07 |
jari |
710 |
/** |
2 |
26 Feb 07 |
jari |
* Updates the viewer sizes. |
2 |
26 Feb 07 |
jari |
712 |
*/ |
2 |
26 Feb 07 |
jari |
713 |
private void updateSize() { |
2 |
26 Feb 07 |
jari |
714 |
int oldWidth = getPreferredSize().width - this.insets.right-this.insets.left; |
2 |
26 Feb 07 |
jari |
715 |
int oldHeight = getPreferredSize().height - this.insets.top-this.insets.bottom; |
2 |
26 Feb 07 |
jari |
716 |
this.insets.left = this.elementSize.width/2+10; |
2 |
26 Feb 07 |
jari |
717 |
this.insets.right = getMaxLabelWidth()+this.elementSize.width/2+10; |
2 |
26 Feb 07 |
jari |
718 |
this.insets.top = this.insets.bottom = this.elementSize.height/2+10; |
2 |
26 Feb 07 |
jari |
719 |
setSizes(oldWidth+this.insets.left+this.insets.right, oldHeight+this.insets.top+this.insets.bottom); |
2 |
26 Feb 07 |
jari |
720 |
} |
2 |
26 Feb 07 |
jari |
721 |
|
2 |
26 Feb 07 |
jari |
722 |
public void onDeselected() {} |
2 |
26 Feb 07 |
jari |
723 |
public void onClosed() {} |
2 |
26 Feb 07 |
jari |
724 |
|
2 |
26 Feb 07 |
jari |
725 |
/** |
2 |
26 Feb 07 |
jari |
* Sets a node size. |
2 |
26 Feb 07 |
jari |
727 |
*/ |
2 |
26 Feb 07 |
jari |
728 |
private void setElementSize(Dimension newSize) { |
2 |
26 Feb 07 |
jari |
729 |
if (newSize.equals(this.elementSize)) { |
2 |
26 Feb 07 |
jari |
730 |
return; |
2 |
26 Feb 07 |
jari |
731 |
} |
2 |
26 Feb 07 |
jari |
732 |
this.elementSize = new Dimension(newSize); |
2 |
26 Feb 07 |
jari |
733 |
setFont(new Font("monospaced", Font.BOLD, newSize.height)); |
2 |
26 Feb 07 |
jari |
734 |
} |
2 |
26 Feb 07 |
jari |
735 |
|
2 |
26 Feb 07 |
jari |
736 |
/** |
2 |
26 Feb 07 |
jari |
* @return null. |
2 |
26 Feb 07 |
jari |
738 |
*/ |
2 |
26 Feb 07 |
jari |
739 |
public BufferedImage getImage() { |
2 |
26 Feb 07 |
jari |
740 |
return null; |
2 |
26 Feb 07 |
jari |
741 |
} |
2 |
26 Feb 07 |
jari |
742 |
|
2 |
26 Feb 07 |
jari |
743 |
/** |
2 |
26 Feb 07 |
jari |
* Creates a popup menu. |
2 |
26 Feb 07 |
jari |
745 |
*/ |
2 |
26 Feb 07 |
jari |
746 |
private JPopupMenu createJPopupMenu(Listener listener) { |
2 |
26 Feb 07 |
jari |
747 |
JPopupMenu popup = new JPopupMenu(); |
2 |
26 Feb 07 |
jari |
748 |
addMenuItems(popup, listener); |
2 |
26 Feb 07 |
jari |
749 |
return popup; |
2 |
26 Feb 07 |
jari |
750 |
} |
2 |
26 Feb 07 |
jari |
751 |
|
2 |
26 Feb 07 |
jari |
752 |
/** |
2 |
26 Feb 07 |
jari |
* Adds the viewer specific menu items. |
2 |
26 Feb 07 |
jari |
754 |
*/ |
2 |
26 Feb 07 |
jari |
755 |
private void addMenuItems(JPopupMenu menu, Listener listener) { |
2 |
26 Feb 07 |
jari |
756 |
JMenuItem menuItem; |
2 |
26 Feb 07 |
jari |
757 |
menuItem = new JMenuItem("Zoom in", GUIFactory.getIcon("zoom_in.gif")); |
2 |
26 Feb 07 |
jari |
758 |
menuItem.setActionCommand(ZOOM_IN_CMD); |
2 |
26 Feb 07 |
jari |
759 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
760 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
761 |
|
2 |
26 Feb 07 |
jari |
762 |
menuItem = new JMenuItem("Zoom out", GUIFactory.getIcon("zoom_out.gif")); |
2 |
26 Feb 07 |
jari |
763 |
menuItem.setActionCommand(ZOOM_OUT_CMD); |
2 |
26 Feb 07 |
jari |
764 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
765 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
766 |
|
2 |
26 Feb 07 |
jari |
767 |
menuItem = new JMenuItem("Show all", GUIFactory.getIcon("show_all.gif")); |
2 |
26 Feb 07 |
jari |
768 |
menuItem.setActionCommand(SHOW_ALL_CMD); |
2 |
26 Feb 07 |
jari |
769 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
770 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
771 |
|
2 |
26 Feb 07 |
jari |
772 |
menu.addSeparator(); |
2 |
26 Feb 07 |
jari |
773 |
|
2 |
26 Feb 07 |
jari |
774 |
JMenu select_menu = new JMenu("Select"); |
2 |
26 Feb 07 |
jari |
775 |
|
2 |
26 Feb 07 |
jari |
776 |
menuItem = new JMenuItem("Feature Degree..."); |
2 |
26 Feb 07 |
jari |
777 |
menuItem.setActionCommand(SELECT_BY_DEGREE_CMD); |
2 |
26 Feb 07 |
jari |
778 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
779 |
select_menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
780 |
|
2 |
26 Feb 07 |
jari |
781 |
menuItem = new JMenuItem("Element ID..."); |
2 |
26 Feb 07 |
jari |
782 |
menuItem.setActionCommand(SELECT_BY_GENE_ID_CMD); |
2 |
26 Feb 07 |
jari |
783 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
784 |
select_menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
785 |
|
2 |
26 Feb 07 |
jari |
786 |
menu.add(select_menu); |
2 |
26 Feb 07 |
jari |
787 |
|
2 |
26 Feb 07 |
jari |
788 |
JMenu links_menu = new JMenu("Links"); |
2 |
26 Feb 07 |
jari |
789 |
|
2 |
26 Feb 07 |
jari |
790 |
menuItem = new JMenuItem("Threshold..."); |
2 |
26 Feb 07 |
jari |
791 |
menuItem.setActionCommand(LINKS_THRESHOLD_CMD); |
2 |
26 Feb 07 |
jari |
792 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
793 |
links_menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
794 |
|
2 |
26 Feb 07 |
jari |
795 |
menuItem = new JCheckBoxMenuItem("Color"); |
2 |
26 Feb 07 |
jari |
796 |
menuItem.setSelected(true); |
2 |
26 Feb 07 |
jari |
797 |
menuItem.setActionCommand(LINKS_COLOR_CMD); |
2 |
26 Feb 07 |
jari |
798 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
799 |
links_menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
800 |
|
2 |
26 Feb 07 |
jari |
801 |
menu.add(links_menu); |
2 |
26 Feb 07 |
jari |
802 |
|
2 |
26 Feb 07 |
jari |
803 |
menuItem = new JMenuItem("Deselect"); |
2 |
26 Feb 07 |
jari |
804 |
menuItem.setActionCommand(DESELECT_CMD); |
2 |
26 Feb 07 |
jari |
805 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
806 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
807 |
|
2 |
26 Feb 07 |
jari |
808 |
menuItem = new JMenuItem("Set Public Cluster..."); |
2 |
26 Feb 07 |
jari |
809 |
menuItem.setActionCommand(SET_PUBLIC_CLUSTER_CMD); |
2 |
26 Feb 07 |
jari |
810 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
811 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
812 |
|
2 |
26 Feb 07 |
jari |
813 |
menuItem = new JMenuItem("Find Clusters"); |
2 |
26 Feb 07 |
jari |
814 |
menuItem.setActionCommand(FIND_CLUSTER_CMD); |
2 |
26 Feb 07 |
jari |
815 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
816 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
817 |
|
2 |
26 Feb 07 |
jari |
818 |
menu.addSeparator(); |
2 |
26 Feb 07 |
jari |
819 |
|
2 |
26 Feb 07 |
jari |
820 |
JMenu shape_menu = new JMenu("Shape"); |
2 |
26 Feb 07 |
jari |
821 |
ButtonGroup group = new ButtonGroup(); |
2 |
26 Feb 07 |
jari |
822 |
|
2 |
26 Feb 07 |
jari |
823 |
menuItem = new JRadioButtonMenuItem("Rectangle"); |
2 |
26 Feb 07 |
jari |
824 |
menuItem.setSelected(true); |
2 |
26 Feb 07 |
jari |
825 |
menuItem.setActionCommand(SHAPE_RECT_CMD); |
2 |
26 Feb 07 |
jari |
826 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
827 |
shape_menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
828 |
group.add(menuItem); |
2 |
26 Feb 07 |
jari |
829 |
|
2 |
26 Feb 07 |
jari |
830 |
menuItem = new JRadioButtonMenuItem("Oval"); |
2 |
26 Feb 07 |
jari |
831 |
menuItem.setActionCommand(SHAPE_OVAL_CMD); |
2 |
26 Feb 07 |
jari |
832 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
833 |
shape_menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
834 |
group.add(menuItem); |
2 |
26 Feb 07 |
jari |
835 |
|
2 |
26 Feb 07 |
jari |
836 |
menu.add(shape_menu); |
2 |
26 Feb 07 |
jari |
837 |
|
2 |
26 Feb 07 |
jari |
838 |
/* |
2 |
26 Feb 07 |
jari |
menuItem = new JMenuItem("Circular Layout"); |
2 |
26 Feb 07 |
jari |
menuItem.setActionCommand(CIRCULAR_LAYOUT_CMD); |
2 |
26 Feb 07 |
jari |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
843 |
|
2 |
26 Feb 07 |
jari |
menuItem = new JMenuItem("Random Layout"); |
2 |
26 Feb 07 |
jari |
menuItem.setActionCommand(RANDOM_LAYOUT_CMD); |
2 |
26 Feb 07 |
jari |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
848 |
|
2 |
26 Feb 07 |
jari |
menuItem = new JMenuItem("Debug Layout"); |
2 |
26 Feb 07 |
jari |
menuItem.setActionCommand(DEBUG_LAYOUT_CMD); |
2 |
26 Feb 07 |
jari |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
menu.add(menuItem);*/ |
2 |
26 Feb 07 |
jari |
853 |
|
2 |
26 Feb 07 |
jari |
854 |
menu.addSeparator(); |
2 |
26 Feb 07 |
jari |
855 |
|
2 |
26 Feb 07 |
jari |
856 |
menuItem = new JMenuItem("Set selection..."); |
2 |
26 Feb 07 |
jari |
857 |
menuItem.setActionCommand(SET_SELECTION_COLOR_CMD); |
2 |
26 Feb 07 |
jari |
858 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
859 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
860 |
|
2 |
26 Feb 07 |
jari |
861 |
menuItem = new JMenuItem("Set labels..."); |
2 |
26 Feb 07 |
jari |
862 |
menuItem.setActionCommand(SET_LABEL_COLOR_CMD); |
2 |
26 Feb 07 |
jari |
863 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
864 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
865 |
|
2 |
26 Feb 07 |
jari |
866 |
menuItem = new JMenuItem("Set background..."); |
2 |
26 Feb 07 |
jari |
867 |
menuItem.setActionCommand(SET_BACKGROUND_COLOR_CMD); |
2 |
26 Feb 07 |
jari |
868 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
869 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
870 |
} |
2 |
26 Feb 07 |
jari |
871 |
|
2 |
26 Feb 07 |
jari |
872 |
/** |
2 |
26 Feb 07 |
jari |
* Returns a menu item by specified action command. |
2 |
26 Feb 07 |
jari |
* @return null if no one item was found. |
2 |
26 Feb 07 |
jari |
875 |
*/ |
2 |
26 Feb 07 |
jari |
876 |
private JMenuItem getJMenuItem(JPopupMenu menu, String command) { |
2 |
26 Feb 07 |
jari |
877 |
Component[] components = menu.getComponents(); |
2 |
26 Feb 07 |
jari |
878 |
for (int i=0; i<components.length; i++) { |
2 |
26 Feb 07 |
jari |
879 |
if (components[i] instanceof JMenu) { |
2 |
26 Feb 07 |
jari |
880 |
JMenuItem item = getJMenuItem(((JMenu)components[i]).getPopupMenu(), command); |
2 |
26 Feb 07 |
jari |
881 |
if (item != null) |
2 |
26 Feb 07 |
jari |
882 |
return item; |
2 |
26 Feb 07 |
jari |
883 |
} |
2 |
26 Feb 07 |
jari |
884 |
if (components[i] instanceof JMenuItem) { |
2 |
26 Feb 07 |
jari |
885 |
if (((JMenuItem)components[i]).getActionCommand().equals(command)) |
2 |
26 Feb 07 |
jari |
886 |
return(JMenuItem)components[i]; |
2 |
26 Feb 07 |
jari |
887 |
} |
2 |
26 Feb 07 |
jari |
888 |
} |
2 |
26 Feb 07 |
jari |
889 |
return null; |
2 |
26 Feb 07 |
jari |
890 |
} |
2 |
26 Feb 07 |
jari |
891 |
|
2 |
26 Feb 07 |
jari |
892 |
/** |
2 |
26 Feb 07 |
jari |
* Sets a menu item state. |
2 |
26 Feb 07 |
jari |
894 |
*/ |
2 |
26 Feb 07 |
jari |
895 |
private void setEnableMenuItem(String command, boolean enable) { |
2 |
26 Feb 07 |
jari |
896 |
JMenuItem item = getJMenuItem(this.popup, command); |
2 |
26 Feb 07 |
jari |
897 |
if (item == null) { |
2 |
26 Feb 07 |
jari |
898 |
return; |
2 |
26 Feb 07 |
jari |
899 |
} |
2 |
26 Feb 07 |
jari |
900 |
item.setEnabled(enable); |
2 |
26 Feb 07 |
jari |
901 |
} |
2 |
26 Feb 07 |
jari |
902 |
|
2 |
26 Feb 07 |
jari |
903 |
/** |
2 |
26 Feb 07 |
jari |
* Shows all network nodes. |
2 |
26 Feb 07 |
jari |
905 |
*/ |
2 |
26 Feb 07 |
jari |
906 |
private void onShowAll() { |
2 |
26 Feb 07 |
jari |
907 |
setSizes(300+insets.left+insets.right, 300+insets.top+insets.bottom); |
2 |
26 Feb 07 |
jari |
908 |
revalidate(); |
2 |
26 Feb 07 |
jari |
909 |
} |
2 |
26 Feb 07 |
jari |
910 |
|
2 |
26 Feb 07 |
jari |
911 |
/** |
2 |
26 Feb 07 |
jari |
* Zoom in a network |
2 |
26 Feb 07 |
jari |
913 |
*/ |
2 |
26 Feb 07 |
jari |
914 |
private void onZoomIn() { |
2 |
26 Feb 07 |
jari |
915 |
zoom(ZOOM_COEFFICIENT); |
2 |
26 Feb 07 |
jari |
916 |
} |
2 |
26 Feb 07 |
jari |
917 |
|
2 |
26 Feb 07 |
jari |
918 |
/** |
2 |
26 Feb 07 |
jari |
* Zoom out a network |
2 |
26 Feb 07 |
jari |
920 |
*/ |
2 |
26 Feb 07 |
jari |
921 |
private void onZoomOut() { |
2 |
26 Feb 07 |
jari |
922 |
zoom(1/ZOOM_COEFFICIENT); |
2 |
26 Feb 07 |
jari |
923 |
if (getPreferredSize().width < getWidth() || getPreferredSize().height < getHeight()) { |
2 |
26 Feb 07 |
jari |
924 |
repaint(); |
2 |
26 Feb 07 |
jari |
925 |
} |
2 |
26 Feb 07 |
jari |
926 |
} |
2 |
26 Feb 07 |
jari |
927 |
|
2 |
26 Feb 07 |
jari |
928 |
/** |
2 |
26 Feb 07 |
jari |
* Zoom a network with specified coefficient. |
2 |
26 Feb 07 |
jari |
930 |
*/ |
2 |
26 Feb 07 |
jari |
931 |
private void zoom(float coefficient) { |
2 |
26 Feb 07 |
jari |
932 |
int newAreaWidth = (int)((getPreferredSize().width-insets.left-insets.right)*coefficient); |
2 |
26 Feb 07 |
jari |
933 |
int newAreaHeight = (int)((getPreferredSize().height-insets.top-insets.bottom)*coefficient); |
2 |
26 Feb 07 |
jari |
934 |
int viewWidth = getParent().getWidth(); |
2 |
26 Feb 07 |
jari |
935 |
int viewHeight = getParent().getHeight(); |
2 |
26 Feb 07 |
jari |
936 |
int x = Math.abs(getX())-insets.left+(int)((float)viewWidth*(coefficient-1)/(coefficient*2f)); |
2 |
26 Feb 07 |
jari |
937 |
int y = Math.abs(getY())-insets.top+(int)((float)viewHeight*(coefficient-1)/(coefficient*2f)); |
2 |
26 Feb 07 |
jari |
938 |
setSizes(newAreaWidth+insets.left+insets.right, newAreaHeight+insets.top+insets.bottom); |
2 |
26 Feb 07 |
jari |
939 |
framework.setContentLocation((int)((float)x*coefficient+insets.left), (int)((float)y*coefficient+insets.top)); |
2 |
26 Feb 07 |
jari |
940 |
} |
2 |
26 Feb 07 |
jari |
941 |
|
2 |
26 Feb 07 |
jari |
942 |
/** |
2 |
26 Feb 07 |
jari |
* Zoom a network to specified rectangle. |
2 |
26 Feb 07 |
jari |
944 |
*/ |
2 |
26 Feb 07 |
jari |
945 |
private void zoom(Rectangle rect) { |
2 |
26 Feb 07 |
jari |
946 |
if (rect == null || rect.width < 10 || rect.height < 10) { |
2 |
26 Feb 07 |
jari |
947 |
drawZoomRect(new Rectangle()); |
2 |
26 Feb 07 |
jari |
948 |
return; |
2 |
26 Feb 07 |
jari |
949 |
} |
2 |
26 Feb 07 |
jari |
950 |
int viewWidth = getParent().getWidth(); |
2 |
26 Feb 07 |
jari |
951 |
int viewHeight = getParent().getHeight(); |
2 |
26 Feb 07 |
jari |
952 |
float coefficient = Math.min((float)viewWidth/(float)rect.width, (float)viewHeight/(float)rect.height); |
2 |
26 Feb 07 |
jari |
953 |
float width = (getPreferredSize().width-insets.left-insets.right)*coefficient; |
2 |
26 Feb 07 |
jari |
954 |
float height = (getPreferredSize().height-insets.top-insets.bottom)*coefficient; |
2 |
26 Feb 07 |
jari |
955 |
if (width > MAX_CONTENT_SIZE || height > MAX_CONTENT_SIZE) { |
2 |
26 Feb 07 |
jari |
956 |
drawZoomRect(new Rectangle()); |
2 |
26 Feb 07 |
jari |
957 |
return; |
2 |
26 Feb 07 |
jari |
958 |
} |
2 |
26 Feb 07 |
jari |
959 |
int newAreaWidth = (int)width; |
2 |
26 Feb 07 |
jari |
960 |
int newAreaHeight = (int)height; |
2 |
26 Feb 07 |
jari |
961 |
float x = rect.x-insets.left; |
2 |
26 Feb 07 |
jari |
962 |
float y = rect.y-insets.top; |
2 |
26 Feb 07 |
jari |
963 |
setSizes((int)(newAreaWidth+insets.left+insets.right), (int)(newAreaHeight+insets.top+insets.bottom)); |
2 |
26 Feb 07 |
jari |
964 |
framework.setContentLocation((int)(x*coefficient+insets.left), (int)(y*coefficient+insets.top)); |
2 |
26 Feb 07 |
jari |
965 |
} |
2 |
26 Feb 07 |
jari |
966 |
|
2 |
26 Feb 07 |
jari |
967 |
/** |
2 |
26 Feb 07 |
jari |
* Sets the viewer sizes. |
2 |
26 Feb 07 |
jari |
969 |
*/ |
2 |
26 Feb 07 |
jari |
970 |
private void setSizes(int width, int height) { |
2 |
26 Feb 07 |
jari |
971 |
setSize(width, height); |
2 |
26 Feb 07 |
jari |
972 |
setPreferredSize(new Dimension(width, height)); |
2 |
26 Feb 07 |
jari |
973 |
revalidate(); |
2 |
26 Feb 07 |
jari |
974 |
} |
2 |
26 Feb 07 |
jari |
975 |
|
2 |
26 Feb 07 |
jari |
976 |
/** |
2 |
26 Feb 07 |
jari |
* Selects nodes with specified degrees. |
2 |
26 Feb 07 |
jari |
978 |
*/ |
2 |
26 Feb 07 |
jari |
979 |
private void selectByDegree(String condition, int min_degree, int max_degree) { |
2 |
26 Feb 07 |
jari |
980 |
clearSelected(this.selected); |
2 |
26 Feb 07 |
jari |
981 |
int cond = 0; |
2 |
26 Feb 07 |
jari |
982 |
if (condition.equals(RelNetSelectionDlg.CONDITION_EQUAL_TO)) { |
2 |
26 Feb 07 |
jari |
983 |
cond = 1; |
2 |
26 Feb 07 |
jari |
984 |
} else if (condition.equals(RelNetSelectionDlg.CONDITION_LESS_THAN)) { |
2 |
26 Feb 07 |
jari |
985 |
cond = 2; |
2 |
26 Feb 07 |
jari |
986 |
} else if (condition.equals(RelNetSelectionDlg.CONDITION_BETWEEN)) { |
2 |
26 Feb 07 |
jari |
987 |
cond = 3; |
2 |
26 Feb 07 |
jari |
988 |
} |
2 |
26 Feb 07 |
jari |
989 |
for (int i=0; i<this.clusters.length; i++) { |
2 |
26 Feb 07 |
jari |
990 |
switch (cond) { |
2 |
26 Feb 07 |
jari |
991 |
case 0: |
2 |
26 Feb 07 |
jari |
992 |
if (this.clusters[i].length-1 > max_degree) { |
2 |
26 Feb 07 |
jari |
993 |
this.selected[this.clusters[i][0]] = true; |
2 |
26 Feb 07 |
jari |
994 |
} |
2 |
26 Feb 07 |
jari |
995 |
break; |
2 |
26 Feb 07 |
jari |
996 |
case 1: |
2 |
26 Feb 07 |
jari |
997 |
if (this.clusters[i].length-1 == max_degree) { |
2 |
26 Feb 07 |
jari |
998 |
this.selected[this.clusters[i][0]] = true; |
2 |
26 Feb 07 |
jari |
999 |
} |
2 |
26 Feb 07 |
jari |
1000 |
break; |
2 |
26 Feb 07 |
jari |
1001 |
case 2: |
2 |
26 Feb 07 |
jari |
1002 |
if (this.clusters[i].length-1 < min_degree) { |
2 |
26 Feb 07 |
jari |
1003 |
this.selected[this.clusters[i][0]] = true; |
2 |
26 Feb 07 |
jari |
1004 |
} |
2 |
26 Feb 07 |
jari |
1005 |
break; |
2 |
26 Feb 07 |
jari |
1006 |
case 3: |
2 |
26 Feb 07 |
jari |
1007 |
int value = this.clusters[i].length-1; |
2 |
26 Feb 07 |
jari |
1008 |
if (value < max_degree && value > min_degree) { |
2 |
26 Feb 07 |
jari |
1009 |
this.selected[this.clusters[i][0]] = true; |
2 |
26 Feb 07 |
jari |
1010 |
} |
2 |
26 Feb 07 |
jari |
1011 |
break; |
2 |
26 Feb 07 |
jari |
1012 |
} |
2 |
26 Feb 07 |
jari |
1013 |
} |
2 |
26 Feb 07 |
jari |
1014 |
repaint(); |
2 |
26 Feb 07 |
jari |
1015 |
} |
2 |
26 Feb 07 |
jari |
1016 |
|
2 |
26 Feb 07 |
jari |
1017 |
/** |
2 |
26 Feb 07 |
jari |
* Selects nodes with specified gene id. |
2 |
26 Feb 07 |
jari |
1019 |
*/ |
2 |
26 Feb 07 |
jari |
1020 |
private void selectByGeneID(String condition, String ID) { |
2 |
26 Feb 07 |
jari |
1021 |
clearSelected(this.selected); |
2 |
26 Feb 07 |
jari |
1022 |
boolean like = condition.equals(RelNetSelectionDlg.CONDITION_LIKE); |
2 |
26 Feb 07 |
jari |
1023 |
String str; |
2 |
26 Feb 07 |
jari |
1024 |
boolean value; |
2 |
26 Feb 07 |
jari |
1025 |
for (int i=0; i<this.clusters.length; i++) { |
2 |
26 Feb 07 |
jari |
1026 |
if (this.clusters[i].length > 1) { |
2 |
26 Feb 07 |
jari |
1027 |
for (int j=0; j<this.clusters[i].length; j++) { |
2 |
26 Feb 07 |
jari |
1028 |
str = isGenes ? this.data.getUniqueId(this.clusters[i][j]) : this.data.getSampleName(this.clusters[i][j]); |
2 |
26 Feb 07 |
jari |
1029 |
if (str != null) { |
2 |
26 Feb 07 |
jari |
1030 |
if (like) { |
2 |
26 Feb 07 |
jari |
1031 |
value = str.indexOf(ID) != -1; |
2 |
26 Feb 07 |
jari |
1032 |
} else { |
2 |
26 Feb 07 |
jari |
1033 |
value = str.equals(ID); |
2 |
26 Feb 07 |
jari |
1034 |
} |
2 |
26 Feb 07 |
jari |
1035 |
this.selected[this.clusters[i][j]] = value; |
2 |
26 Feb 07 |
jari |
1036 |
} |
2 |
26 Feb 07 |
jari |
1037 |
} |
2 |
26 Feb 07 |
jari |
1038 |
} |
2 |
26 Feb 07 |
jari |
1039 |
} |
2 |
26 Feb 07 |
jari |
1040 |
repaint(); |
2 |
26 Feb 07 |
jari |
1041 |
} |
2 |
26 Feb 07 |
jari |
1042 |
|
2 |
26 Feb 07 |
jari |
/*private void onCircularLayout() { |
2 |
26 Feb 07 |
jari |
this.coords = RelevanceNetworkLayout.doLayout(clusters, null, RelevanceNetworkLayout.CIRCULAR_LAYOUT); |
2 |
26 Feb 07 |
jari |
repaint(); |
2 |
26 Feb 07 |
jari |
1046 |
} |
2 |
26 Feb 07 |
jari |
1047 |
|
2 |
26 Feb 07 |
jari |
private void onRandomLayout() { |
2 |
26 Feb 07 |
jari |
this.coords = RelevanceNetworkLayout.doLayout(clusters, null, RelevanceNetworkLayout.RANDOM_LAYOUT); |
2 |
26 Feb 07 |
jari |
repaint(); |
2 |
26 Feb 07 |
jari |
1051 |
} |
2 |
26 Feb 07 |
jari |
1052 |
|
2 |
26 Feb 07 |
jari |
private void onDebugLayout() { |
2 |
26 Feb 07 |
jari |
this.coords = RelevanceNetworkLayout.doLayout(clusters, null, RelevanceNetworkLayout.DEBUG_LAYOUT); |
2 |
26 Feb 07 |
jari |
repaint(); |
2 |
26 Feb 07 |
jari |
1056 |
}*/ |
2 |
26 Feb 07 |
jari |
1057 |
|
2 |
26 Feb 07 |
jari |
1058 |
/** |
2 |
26 Feb 07 |
jari |
* Sets a background color. |
2 |
26 Feb 07 |
jari |
1060 |
*/ |
2 |
26 Feb 07 |
jari |
1061 |
private void onSetBackgroundColor() { |
2 |
26 Feb 07 |
jari |
1062 |
Frame frame = JOptionPane.getFrameForComponent(getContentComponent()); |
2 |
26 Feb 07 |
jari |
1063 |
Color newColor = JColorChooser.showDialog(frame, "Choose color", getBackground()); |
2 |
26 Feb 07 |
jari |
1064 |
if (newColor != null) { |
2 |
26 Feb 07 |
jari |
1065 |
setBackground(newColor); |
2 |
26 Feb 07 |
jari |
1066 |
} |
2 |
26 Feb 07 |
jari |
1067 |
} |
2 |
26 Feb 07 |
jari |
1068 |
|
2 |
26 Feb 07 |
jari |
1069 |
/** |
2 |
26 Feb 07 |
jari |
* Sets a selection color. |
2 |
26 Feb 07 |
jari |
1071 |
*/ |
2 |
26 Feb 07 |
jari |
1072 |
private void setSelectionColor(Color color) { |
2 |
26 Feb 07 |
jari |
1073 |
this.selectionColor = color; |
2 |
26 Feb 07 |
jari |
1074 |
repaint(); |
2 |
26 Feb 07 |
jari |
1075 |
} |
2 |
26 Feb 07 |
jari |
1076 |
|
2 |
26 Feb 07 |
jari |
1077 |
/** |
2 |
26 Feb 07 |
jari |
* Sets labels color. |
2 |
26 Feb 07 |
jari |
1079 |
*/ |
2 |
26 Feb 07 |
jari |
1080 |
private void setLabelColor(Color color) { |
2 |
26 Feb 07 |
jari |
1081 |
this.labelColor = color; |
2 |
26 Feb 07 |
jari |
1082 |
repaint(); |
2 |
26 Feb 07 |
jari |
1083 |
} |
2 |
26 Feb 07 |
jari |
1084 |
|
2 |
26 Feb 07 |
jari |
1085 |
/** |
2 |
26 Feb 07 |
jari |
* Sets a selection color. |
2 |
26 Feb 07 |
jari |
1087 |
*/ |
2 |
26 Feb 07 |
jari |
1088 |
private void onSetSelectionColor() { |
2 |
26 Feb 07 |
jari |
1089 |
Frame frame = JOptionPane.getFrameForComponent(getContentComponent()); |
2 |
26 Feb 07 |
jari |
1090 |
Color newColor = JColorChooser.showDialog(frame, "Choose selection color", getBackground()); |
2 |
26 Feb 07 |
jari |
1091 |
if (newColor != null) { |
2 |
26 Feb 07 |
jari |
1092 |
setSelectionColor(newColor); |
2 |
26 Feb 07 |
jari |
1093 |
} |
2 |
26 Feb 07 |
jari |
1094 |
} |
2 |
26 Feb 07 |
jari |
1095 |
|
2 |
26 Feb 07 |
jari |
1096 |
/** |
2 |
26 Feb 07 |
jari |
* Sets labels color. |
2 |
26 Feb 07 |
jari |
1098 |
*/ |
2 |
26 Feb 07 |
jari |
1099 |
private void onSetLabelColor() { |
2 |
26 Feb 07 |
jari |
1100 |
Frame frame = JOptionPane.getFrameForComponent(getContentComponent()); |
2 |
26 Feb 07 |
jari |
1101 |
Color newColor = JColorChooser.showDialog(frame, "Choose label color", getBackground()); |
2 |
26 Feb 07 |
jari |
1102 |
if (newColor != null) { |
2 |
26 Feb 07 |
jari |
1103 |
setLabelColor(newColor); |
2 |
26 Feb 07 |
jari |
1104 |
} |
2 |
26 Feb 07 |
jari |
1105 |
} |
2 |
26 Feb 07 |
jari |
1106 |
|
2 |
26 Feb 07 |
jari |
1107 |
/** |
2 |
26 Feb 07 |
jari |
* Selects nodes with the user defined degrees. |
2 |
26 Feb 07 |
jari |
1109 |
*/ |
2 |
26 Feb 07 |
jari |
1110 |
private void onDegreeSelection() { |
2 |
26 Feb 07 |
jari |
1111 |
Frame frame = JOptionPane.getFrameForComponent(getContentComponent()); |
2 |
26 Feb 07 |
jari |
1112 |
RelNetSelectionDlg dialog = new RelNetSelectionDlg(frame, RelNetSelectionDlg.DEGREE_TYPE); |
2 |
26 Feb 07 |
jari |
1113 |
if (dialog.showModal() == JOptionPane.OK_OPTION) { |
2 |
26 Feb 07 |
jari |
1114 |
selectByDegree(dialog.getCondition(), dialog.getMinDegree(), dialog.getMaxDegree()); |
2 |
26 Feb 07 |
jari |
1115 |
} |
2 |
26 Feb 07 |
jari |
1116 |
} |
2 |
26 Feb 07 |
jari |
1117 |
|
2 |
26 Feb 07 |
jari |
1118 |
/** |
2 |
26 Feb 07 |
jari |
* Selects nodes with the user defined gene id. |
2 |
26 Feb 07 |
jari |
1120 |
*/ |
2 |
26 Feb 07 |
jari |
1121 |
private void onGeneIDSelection() { |
2 |
26 Feb 07 |
jari |
1122 |
Frame frame = JOptionPane.getFrameForComponent(getContentComponent()); |
2 |
26 Feb 07 |
jari |
1123 |
RelNetSelectionDlg dialog = new RelNetSelectionDlg(frame, RelNetSelectionDlg.GENEID_TYPE); |
2 |
26 Feb 07 |
jari |
1124 |
if (dialog.showModal() == JOptionPane.OK_OPTION) { |
2 |
26 Feb 07 |
jari |
1125 |
selectByGeneID(dialog.getCondition(), dialog.getGeneID()); |
2 |
26 Feb 07 |
jari |
1126 |
} |
2 |
26 Feb 07 |
jari |
1127 |
} |
2 |
26 Feb 07 |
jari |
1128 |
|
2 |
26 Feb 07 |
jari |
1129 |
/** |
2 |
26 Feb 07 |
jari |
* Shows links with the user specified threshold. |
2 |
26 Feb 07 |
jari |
1131 |
*/ |
2 |
26 Feb 07 |
jari |
1132 |
private void onLinksThreshold() { |
2 |
26 Feb 07 |
jari |
1133 |
Frame frame = JOptionPane.getFrameForComponent(getContentComponent()); |
2 |
26 Feb 07 |
jari |
1134 |
String value = (String)JOptionPane.showInputDialog(frame, "Enter in links threshold (from 0 to 1).", "Input", JOptionPane.OK_CANCEL_OPTION, null, null, String.valueOf(this.links_threshold)); |
2 |
26 Feb 07 |
jari |
1135 |
if (value == null || value.equals("")) |
2 |
26 Feb 07 |
jari |
1136 |
return; |
2 |
26 Feb 07 |
jari |
1137 |
try { |
2 |
26 Feb 07 |
jari |
1138 |
float threshold = Float.parseFloat(value); |
2 |
26 Feb 07 |
jari |
1139 |
if (threshold < 0 || threshold > 1) |
2 |
26 Feb 07 |
jari |
1140 |
throw new NumberFormatException("value must be between 0 and 1."); |
2 |
26 Feb 07 |
jari |
1141 |
this.links_threshold = threshold; |
2 |
26 Feb 07 |
jari |
1142 |
repaint(); |
2 |
26 Feb 07 |
jari |
1143 |
} catch (NumberFormatException e) { |
2 |
26 Feb 07 |
jari |
1144 |
JOptionPane.showMessageDialog(frame, "Illegal number: "+e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); |
2 |
26 Feb 07 |
jari |
1145 |
} |
2 |
26 Feb 07 |
jari |
1146 |
} |
2 |
26 Feb 07 |
jari |
1147 |
|
2 |
26 Feb 07 |
jari |
1148 |
private void onLinksColor() { |
2 |
26 Feb 07 |
jari |
1149 |
JMenuItem item = getJMenuItem(this.popup, LINKS_COLOR_CMD); |
2 |
26 Feb 07 |
jari |
1150 |
this.isLinksColor = item.isSelected(); |
2 |
26 Feb 07 |
jari |
1151 |
repaint(); |
2 |
26 Feb 07 |
jari |
1152 |
} |
2 |
26 Feb 07 |
jari |
1153 |
|
2 |
26 Feb 07 |
jari |
1154 |
/** |
2 |
26 Feb 07 |
jari |
* Deselects all nodes. |
2 |
26 Feb 07 |
jari |
1156 |
*/ |
2 |
26 Feb 07 |
jari |
1157 |
private void onDeselect() { |
2 |
26 Feb 07 |
jari |
1158 |
clearSelected(this.selected); |
2 |
26 Feb 07 |
jari |
1159 |
repaint(); |
2 |
26 Feb 07 |
jari |
1160 |
} |
2 |
26 Feb 07 |
jari |
1161 |
|
2 |
26 Feb 07 |
jari |
// Scrollable interface implementation. |
2 |
26 Feb 07 |
jari |
1163 |
|
2 |
26 Feb 07 |
jari |
1164 |
public Dimension getPreferredScrollableViewportSize() { |
2 |
26 Feb 07 |
jari |
1165 |
return getPreferredSize(); |
2 |
26 Feb 07 |
jari |
1166 |
} |
2 |
26 Feb 07 |
jari |
1167 |
|
2 |
26 Feb 07 |
jari |
1168 |
public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) { |
2 |
26 Feb 07 |
jari |
1169 |
if (orientation == SwingConstants.VERTICAL) { |
2 |
26 Feb 07 |
jari |
1170 |
return this.elementSize.height; |
2 |
26 Feb 07 |
jari |
1171 |
} else { |
2 |
26 Feb 07 |
jari |
1172 |
return this.elementSize.width; |
2 |
26 Feb 07 |
jari |
1173 |
} |
2 |
26 Feb 07 |
jari |
1174 |
} |
2 |
26 Feb 07 |
jari |
1175 |
|
2 |
26 Feb 07 |
jari |
1176 |
public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) { |
2 |
26 Feb 07 |
jari |
1177 |
if (orientation == SwingConstants.VERTICAL) { |
2 |
26 Feb 07 |
jari |
1178 |
return visibleRect.height; |
2 |
26 Feb 07 |
jari |
1179 |
} else { |
2 |
26 Feb 07 |
jari |
1180 |
return visibleRect.width; |
2 |
26 Feb 07 |
jari |
1181 |
} |
2 |
26 Feb 07 |
jari |
1182 |
} |
2 |
26 Feb 07 |
jari |
1183 |
|
2 |
26 Feb 07 |
jari |
1184 |
public boolean getScrollableTracksViewportWidth() { |
2 |
26 Feb 07 |
jari |
1185 |
if (getParent() instanceof JViewport) { |
2 |
26 Feb 07 |
jari |
1186 |
return(((JViewport)getParent()).getWidth() > getPreferredSize().width); |
2 |
26 Feb 07 |
jari |
1187 |
} |
2 |
26 Feb 07 |
jari |
1188 |
return false; |
2 |
26 Feb 07 |
jari |
1189 |
} |
2 |
26 Feb 07 |
jari |
1190 |
|
2 |
26 Feb 07 |
jari |
1191 |
public boolean getScrollableTracksViewportHeight() { |
2 |
26 Feb 07 |
jari |
1192 |
if (getParent() instanceof JViewport) { |
2 |
26 Feb 07 |
jari |
1193 |
return(((JViewport)getParent()).getHeight() > getPreferredSize().height); |
2 |
26 Feb 07 |
jari |
1194 |
} |
2 |
26 Feb 07 |
jari |
1195 |
return false; |
2 |
26 Feb 07 |
jari |
1196 |
} |
2 |
26 Feb 07 |
jari |
1197 |
|
2 |
26 Feb 07 |
jari |
1198 |
/** |
2 |
26 Feb 07 |
jari |
* Searches a node index by specified coordinaties. |
2 |
26 Feb 07 |
jari |
* @return -1 if no one node was found. |
2 |
26 Feb 07 |
jari |
1201 |
*/ |
2 |
26 Feb 07 |
jari |
1202 |
private int findSpot(float X, float Y, Rectangle2D.Float rect) { |
2 |
26 Feb 07 |
jari |
1203 |
float scale = getScale(); |
2 |
26 Feb 07 |
jari |
// element rect |
2 |
26 Feb 07 |
jari |
1205 |
float rectWidth = (float)elementSize.getWidth()/scale; |
2 |
26 Feb 07 |
jari |
1206 |
float rectHeight = (float)elementSize.getHeight()/scale; |
2 |
26 Feb 07 |
jari |
1207 |
for (int i=0; i<this.clusters.length; i++) { |
2 |
26 Feb 07 |
jari |
1208 |
if (this.clusters[i].length > 1) { |
2 |
26 Feb 07 |
jari |
1209 |
for (int j=0; j<this.clusters[i].length; j++) { |
2 |
26 Feb 07 |
jari |
1210 |
rect.setRect(coords[this.clusters[i][j]][0]-rectWidth/2f, coords[this.clusters[i][j]][1]-rectHeight/2f, rectWidth, rectHeight); |
2 |
26 Feb 07 |
jari |
1211 |
if (rect.contains(X, Y)) { |
2 |
26 Feb 07 |
jari |
1212 |
return this.clusters[i][j]; |
2 |
26 Feb 07 |
jari |
1213 |
} |
2 |
26 Feb 07 |
jari |
1214 |
} |
2 |
26 Feb 07 |
jari |
1215 |
} |
2 |
26 Feb 07 |
jari |
1216 |
} |
2 |
26 Feb 07 |
jari |
1217 |
return -1; |
2 |
26 Feb 07 |
jari |
1218 |
} |
2 |
26 Feb 07 |
jari |
1219 |
|
2 |
26 Feb 07 |
jari |
1220 |
/** |
2 |
26 Feb 07 |
jari |
* Deselects a specified node. |
2 |
26 Feb 07 |
jari |
1222 |
*/ |
2 |
26 Feb 07 |
jari |
1223 |
private void unselectSpot(int spotIndex) { |
2 |
26 Feb 07 |
jari |
// restore status text |
2 |
26 Feb 07 |
jari |
1225 |
this.framework.setStatusText(this.status); |
2 |
26 Feb 07 |
jari |
1226 |
Graphics g = getContentComponent().getGraphics(); |
2 |
26 Feb 07 |
jari |
1227 |
drawSpot(g, spotIndex); |
2 |
26 Feb 07 |
jari |
1228 |
g.dispose(); |
2 |
26 Feb 07 |
jari |
1229 |
hideTipWindow(); |
2 |
26 Feb 07 |
jari |
1230 |
} |
2 |
26 Feb 07 |
jari |
1231 |
|
2 |
26 Feb 07 |
jari |
1232 |
/** |
2 |
26 Feb 07 |
jari |
* Selects a specified node. |
2 |
26 Feb 07 |
jari |
1234 |
*/ |
2 |
26 Feb 07 |
jari |
1235 |
private void selectSpot(int spotIndex) { |
2 |
26 Feb 07 |
jari |
1236 |
this.status = framework.getStatusText(); // remember original status |
2 |
26 Feb 07 |
jari |
1237 |
if (this.isGenes) |
2 |
26 Feb 07 |
jari |
1238 |
this.framework.setStatusText("Gene Id: "+data.getUniqueId(spotIndex)+" Gene Name: "+data.getGeneName(spotIndex)); |
2 |
26 Feb 07 |
jari |
1239 |
else |
2 |
26 Feb 07 |
jari |
1240 |
this.framework.setStatusText("Sample: "+data.getSampleName(spotIndex)); |
2 |
26 Feb 07 |
jari |
1241 |
Graphics g = getContentComponent().getGraphics(); |
2 |
26 Feb 07 |
jari |
1242 |
drawSelectedSpot(g, spotIndex); |
2 |
26 Feb 07 |
jari |
1243 |
g.dispose(); |
2 |
26 Feb 07 |
jari |
1244 |
showTipWindow(spotIndex); |
2 |
26 Feb 07 |
jari |
1245 |
} |
2 |
26 Feb 07 |
jari |
1246 |
|
2 |
26 Feb 07 |
jari |
1247 |
private void showTipWindow(int spot) { |
2 |
26 Feb 07 |
jari |
1248 |
if (this.isGenes && this.labelIndex < 0) |
2 |
26 Feb 07 |
jari |
1249 |
return; |
2 |
26 Feb 07 |
jari |
1250 |
Component content = getContentComponent(); |
2 |
26 Feb 07 |
jari |
1251 |
String text = this.isGenes ? this.data.getElementAttribute(spot, this.labelIndex) : data.getSampleName(spot); |
2 |
26 Feb 07 |
jari |
1252 |
|
2 |
26 Feb 07 |
jari |
1253 |
JToolTip tooltip = new JToolTip(); |
2 |
26 Feb 07 |
jari |
1254 |
tooltip.setTipText(text); |
2 |
26 Feb 07 |
jari |
1255 |
Dimension size = tooltip.getPreferredSize(); |
2 |
26 Feb 07 |
jari |
1256 |
|
2 |
26 Feb 07 |
jari |
1257 |
float scale = getScale(); |
2 |
26 Feb 07 |
jari |
1258 |
float x = (this.coords[spot][0])*scale+this.insets.left+this.elementSize.width/2+10; |
2 |
26 Feb 07 |
jari |
1259 |
float y = (this.coords[spot][1])*scale+this.insets.top+(float)(this.elementSize.height-size.getHeight())/2; |
2 |
26 Feb 07 |
jari |
1260 |
|
2 |
26 Feb 07 |
jari |
1261 |
Point screenLocation = content.getLocationOnScreen(); |
2 |
26 Feb 07 |
jari |
1262 |
|
2 |
26 Feb 07 |
jari |
1263 |
this.tipWindow.getContentPane().add(tooltip, BorderLayout.CENTER); |
2 |
26 Feb 07 |
jari |
1264 |
this.tipWindow.setLocation((int)(screenLocation.x+x), (int)(screenLocation.y+y)); |
2 |
26 Feb 07 |
jari |
1265 |
this.tipWindow.pack(); |
2 |
26 Feb 07 |
jari |
1266 |
this.tipWindow.setVisible(true); |
2 |
26 Feb 07 |
jari |
1267 |
} |
2 |
26 Feb 07 |
jari |
1268 |
|
2 |
26 Feb 07 |
jari |
1269 |
private void hideTipWindow() { |
2 |
26 Feb 07 |
jari |
1270 |
this.tipWindow.getContentPane().removeAll(); |
2 |
26 Feb 07 |
jari |
1271 |
this.tipWindow.setVisible(false); |
2 |
26 Feb 07 |
jari |
1272 |
} |
2 |
26 Feb 07 |
jari |
1273 |
|
2 |
26 Feb 07 |
jari |
1274 |
private JWindow createTipWindow() { |
2 |
26 Feb 07 |
jari |
1275 |
return new JWindow(JOptionPane.getFrameForComponent(getContentComponent()) ); |
2 |
26 Feb 07 |
jari |
1276 |
} |
2 |
26 Feb 07 |
jari |
1277 |
|
2 |
26 Feb 07 |
jari |
1278 |
/** |
2 |
26 Feb 07 |
jari |
* Sets rectangle shape type. |
2 |
26 Feb 07 |
jari |
1280 |
*/ |
2 |
26 Feb 07 |
jari |
1281 |
private void onShapeRect() { |
2 |
26 Feb 07 |
jari |
1282 |
setShapeType(SHAPE_RECT); |
2 |
26 Feb 07 |
jari |
1283 |
} |
2 |
26 Feb 07 |
jari |
1284 |
|
2 |
26 Feb 07 |
jari |
1285 |
/** |
2 |
26 Feb 07 |
jari |
* Sets oval shape type. |
2 |
26 Feb 07 |
jari |
1287 |
*/ |
2 |
26 Feb 07 |
jari |
1288 |
private void onShapeOval() { |
2 |
26 Feb 07 |
jari |
1289 |
setShapeType(SHAPE_OVAL); |
2 |
26 Feb 07 |
jari |
1290 |
} |
2 |
26 Feb 07 |
jari |
1291 |
|
2 |
26 Feb 07 |
jari |
1292 |
/** |
2 |
26 Feb 07 |
jari |
* Sets specified shape type. |
2 |
26 Feb 07 |
jari |
1294 |
*/ |
2 |
26 Feb 07 |
jari |
1295 |
private void setShapeType(int type) { |
2 |
26 Feb 07 |
jari |
1296 |
this.shape_type = type; |
2 |
26 Feb 07 |
jari |
1297 |
repaint(); |
2 |
26 Feb 07 |
jari |
1298 |
} |
2 |
26 Feb 07 |
jari |
1299 |
|
2 |
26 Feb 07 |
jari |
1300 |
/** |
2 |
26 Feb 07 |
jari |
* @return true, if there is a selected node. |
2 |
26 Feb 07 |
jari |
1302 |
*/ |
2 |
26 Feb 07 |
jari |
1303 |
private boolean hasSelected() { |
2 |
26 Feb 07 |
jari |
1304 |
for (int i=0; i<this.selected.length; i++) { |
2 |
26 Feb 07 |
jari |
1305 |
if (this.selected[i]) { |
2 |
26 Feb 07 |
jari |
1306 |
return true; |
2 |
26 Feb 07 |
jari |
1307 |
} |
2 |
26 Feb 07 |
jari |
1308 |
} |
2 |
26 Feb 07 |
jari |
1309 |
return false; |
2 |
26 Feb 07 |
jari |
1310 |
} |
2 |
26 Feb 07 |
jari |
1311 |
|
2 |
26 Feb 07 |
jari |
1312 |
/** |
2 |
26 Feb 07 |
jari |
* Sets the user defined public color for selected nodes. |
2 |
26 Feb 07 |
jari |
1314 |
*/ |
2 |
26 Feb 07 |
jari |
1315 |
private void onSetPublicCluster() { |
2 |
26 Feb 07 |
jari |
1316 |
Frame frame = JOptionPane.getFrameForComponent(getContentComponent()); |
2 |
26 Feb 07 |
jari |
1317 |
Color color = JColorChooser.showDialog(frame, "Choose color", Color.green); |
2 |
26 Feb 07 |
jari |
1318 |
if (color == null) { |
2 |
26 Feb 07 |
jari |
1319 |
return; |
2 |
26 Feb 07 |
jari |
1320 |
} |
2 |
26 Feb 07 |
jari |
1321 |
int count = 0; |
2 |
26 Feb 07 |
jari |
1322 |
for (int i=0; i<this.selected.length; i++) { |
2 |
26 Feb 07 |
jari |
1323 |
if (this.selected[i]) { |
2 |
26 Feb 07 |
jari |
1324 |
count++; |
2 |
26 Feb 07 |
jari |
1325 |
} |
2 |
26 Feb 07 |
jari |
1326 |
} |
2 |
26 Feb 07 |
jari |
1327 |
if (count == 0) { |
2 |
26 Feb 07 |
jari |
1328 |
return; |
2 |
26 Feb 07 |
jari |
1329 |
} |
2 |
26 Feb 07 |
jari |
1330 |
int[] probes = new int[count]; |
2 |
26 Feb 07 |
jari |
1331 |
int pos = 0; |
2 |
26 Feb 07 |
jari |
1332 |
for (int i=0; i<this.selected.length; i++) { |
2 |
26 Feb 07 |
jari |
1333 |
if (this.selected[i]) { |
2 |
26 Feb 07 |
jari |
1334 |
probes[pos] = i; |
2 |
26 Feb 07 |
jari |
1335 |
pos++; |
2 |
26 Feb 07 |
jari |
1336 |
} |
2 |
26 Feb 07 |
jari |
1337 |
} |
2 |
26 Feb 07 |
jari |
1338 |
if (this.isGenes) |
2 |
26 Feb 07 |
jari |
1339 |
this.data.setProbesColor(probes, color); |
2 |
26 Feb 07 |
jari |
1340 |
else |
2 |
26 Feb 07 |
jari |
1341 |
this.data.setExperimentColor(probes, color); |
2 |
26 Feb 07 |
jari |
1342 |
|
2 |
26 Feb 07 |
jari |
1343 |
clearSelected(this.selected); |
2 |
26 Feb 07 |
jari |
1344 |
repaint(); |
2 |
26 Feb 07 |
jari |
1345 |
} |
2 |
26 Feb 07 |
jari |
1346 |
|
2 |
26 Feb 07 |
jari |
1347 |
/** |
2 |
26 Feb 07 |
jari |
* Shows list of clusters for specified node. |
2 |
26 Feb 07 |
jari |
1349 |
*/ |
2 |
26 Feb 07 |
jari |
1350 |
private void onFindCluster(int index) { |
2 |
26 Feb 07 |
jari |
1351 |
ArrayList info = new ArrayList(); |
2 |
26 Feb 07 |
jari |
1352 |
for (int i=0; i<this.clusters.length; i++) { |
2 |
26 Feb 07 |
jari |
1353 |
if (this.clusters[indices[i]].length > 1) { |
2 |
26 Feb 07 |
jari |
1354 |
for (int j=0; j<this.clusters[indices[i]].length; j++) { |
2 |
26 Feb 07 |
jari |
1355 |
if (index == this.clusters[indices[i]][j]) { |
2 |
26 Feb 07 |
jari |
1356 |
info.add(new String("Cluster "+String.valueOf(indices[i]+1)+" ("+clusters[indices[i]].length+")")); |
2 |
26 Feb 07 |
jari |
1357 |
continue; |
2 |
26 Feb 07 |
jari |
1358 |
} |
2 |
26 Feb 07 |
jari |
1359 |
} |
2 |
26 Feb 07 |
jari |
1360 |
} |
2 |
26 Feb 07 |
jari |
1361 |
} |
2 |
26 Feb 07 |
jari |
1362 |
Frame frame = JOptionPane.getFrameForComponent(getContentComponent()); |
2 |
26 Feb 07 |
jari |
1363 |
String nodeName = this.isGenes ? (this.data.getUniqueId(index)+ " ("+this.data.getGeneName(index)+")") : this.data.getSampleName(index); |
2 |
26 Feb 07 |
jari |
1364 |
String title = "Clusters for node: "+nodeName; |
2 |
26 Feb 07 |
jari |
1365 |
RelNetClusterList list = new RelNetClusterList(frame, title, info.toArray(new String[info.size()])); |
2 |
26 Feb 07 |
jari |
1366 |
list.showModal(); |
2 |
26 Feb 07 |
jari |
1367 |
} |
2 |
26 Feb 07 |
jari |
1368 |
|
2 |
26 Feb 07 |
jari |
/** Returns a component to be inserted into the scroll pane row header |
2 |
26 Feb 07 |
jari |
1370 |
*/ |
2 |
26 Feb 07 |
jari |
1371 |
public JComponent getRowHeaderComponent() { |
2 |
26 Feb 07 |
jari |
1372 |
return null; |
2 |
26 Feb 07 |
jari |
1373 |
} |
2 |
26 Feb 07 |
jari |
1374 |
|
2 |
26 Feb 07 |
jari |
/** Returns the corner component corresponding to the indicated corner, |
2 |
26 Feb 07 |
jari |
* posibly null |
2 |
26 Feb 07 |
jari |
1377 |
*/ |
2 |
26 Feb 07 |
jari |
1378 |
public JComponent getCornerComponent(int cornerIndex) { |
2 |
26 Feb 07 |
jari |
1379 |
return null; |
2 |
26 Feb 07 |
jari |
1380 |
} |
2 |
26 Feb 07 |
jari |
1381 |
|
2 |
26 Feb 07 |
jari |
1382 |
|
2 |
26 Feb 07 |
jari |
1383 |
public void setExperiment(Experiment e){ |
2 |
26 Feb 07 |
jari |
1384 |
this.experiment = e; |
2 |
26 Feb 07 |
jari |
1385 |
this.exptID = e.getId(); |
2 |
26 Feb 07 |
jari |
1386 |
} |
2 |
26 Feb 07 |
jari |
1387 |
|
2 |
26 Feb 07 |
jari |
//EH begin added methods for state-saving |
2 |
26 Feb 07 |
jari |
1389 |
public int getExperimentID(){ |
2 |
26 Feb 07 |
jari |
1390 |
return exptID; |
2 |
26 Feb 07 |
jari |
1391 |
} |
2 |
26 Feb 07 |
jari |
1392 |
public void setExperimentID(int i){ |
2 |
26 Feb 07 |
jari |
1393 |
this.exptID = i; |
2 |
26 Feb 07 |
jari |
1394 |
} |
2 |
26 Feb 07 |
jari |
//EH end added methods for state-saving |
2 |
26 Feb 07 |
jari |
1396 |
|
2 |
26 Feb 07 |
jari |
1397 |
public int[][] getClusters() { |
2 |
26 Feb 07 |
jari |
// return null; |
2 |
26 Feb 07 |
jari |
1399 |
return clusters; |
2 |
26 Feb 07 |
jari |
1400 |
} |
2 |
26 Feb 07 |
jari |
1401 |
|
2 |
26 Feb 07 |
jari |
1402 |
public Experiment getExperiment() { |
2 |
26 Feb 07 |
jari |
//EH return null; |
2 |
26 Feb 07 |
jari |
1404 |
return experiment; |
2 |
26 Feb 07 |
jari |
1405 |
} |
2 |
26 Feb 07 |
jari |
1406 |
|
2 |
26 Feb 07 |
jari |
/** Returns int value indicating viewer type |
2 |
26 Feb 07 |
jari |
* Cluster.GENE_CLUSTER, Cluster.EXPERIMENT_CLUSTER, or -1 for both or unspecified |
2 |
26 Feb 07 |
jari |
1409 |
*/ |
2 |
26 Feb 07 |
jari |
1410 |
public int getViewerType() { |
2 |
26 Feb 07 |
jari |
1411 |
if(this.isGenes) |
2 |
26 Feb 07 |
jari |
1412 |
return Cluster.GENE_CLUSTER; |
2 |
26 Feb 07 |
jari |
1413 |
return Cluster.EXPERIMENT_CLUSTER; |
2 |
26 Feb 07 |
jari |
1414 |
} |
2 |
26 Feb 07 |
jari |
1415 |
|
2 |
26 Feb 07 |
jari |
1416 |
/** |
2 |
26 Feb 07 |
jari |
* The class to listen to mouse and menu actions events. |
2 |
26 Feb 07 |
jari |
1418 |
*/ |
2 |
26 Feb 07 |
jari |
1419 |
private class Listener extends MouseAdapter implements ActionListener, MouseMotionListener { |
2 |
26 Feb 07 |
jari |
1420 |
|
2 |
26 Feb 07 |
jari |
1421 |
private boolean isSpotSelected = false; |
2 |
26 Feb 07 |
jari |
1422 |
private int spotIndex = -1; |
2 |
26 Feb 07 |
jari |
1423 |
private Rectangle2D.Float spotRect = new Rectangle2D.Float(); |
2 |
26 Feb 07 |
jari |
1424 |
|
2 |
26 Feb 07 |
jari |
1425 |
private boolean isZoomStarted = false; |
2 |
26 Feb 07 |
jari |
1426 |
private Rectangle zoomRect = new Rectangle(); |
2 |
26 Feb 07 |
jari |
1427 |
private Point zoomPoint = new Point(); // starting point to draw zoom rect |
2 |
26 Feb 07 |
jari |
1428 |
|
2 |
26 Feb 07 |
jari |
1429 |
public void actionPerformed(ActionEvent e) { |
2 |
26 Feb 07 |
jari |
1430 |
String command = e.getActionCommand(); |
2 |
26 Feb 07 |
jari |
1431 |
if (command.equals(SET_BACKGROUND_COLOR_CMD)) { |
2 |
26 Feb 07 |
jari |
1432 |
onSetBackgroundColor(); |
2 |
26 Feb 07 |
jari |
1433 |
} else if (command.equals(SET_SELECTION_COLOR_CMD)) { |
2 |
26 Feb 07 |
jari |
1434 |
onSetSelectionColor(); |
2 |
26 Feb 07 |
jari |
1435 |
} else if (command.equals(SET_LABEL_COLOR_CMD)) { |
2 |
26 Feb 07 |
jari |
1436 |
onSetLabelColor(); |
2 |
26 Feb 07 |
jari |
1437 |
} else if (command.equals(ZOOM_IN_CMD)) { |
2 |
26 Feb 07 |
jari |
1438 |
onZoomIn(); |
2 |
26 Feb 07 |
jari |
1439 |
} else if (command.equals(ZOOM_OUT_CMD)) { |
2 |
26 Feb 07 |
jari |
1440 |
onZoomOut(); |
2 |
26 Feb 07 |
jari |
1441 |
} else if (command.equals(SHOW_ALL_CMD)) { |
2 |
26 Feb 07 |
jari |
1442 |
onShowAll(); |
2 |
26 Feb 07 |
jari |
1443 |
} else if (command.equals(CIRCULAR_LAYOUT_CMD)) { |
2 |
26 Feb 07 |
jari |
//onCircularLayout(); |
2 |
26 Feb 07 |
jari |
1445 |
} else if (command.equals(RANDOM_LAYOUT_CMD)) { |
2 |
26 Feb 07 |
jari |
//onRandomLayout(); |
2 |
26 Feb 07 |
jari |
1447 |
} else if (command.equals(DEBUG_LAYOUT_CMD)) { |
2 |
26 Feb 07 |
jari |
//onDebugLayout(); |
2 |
26 Feb 07 |
jari |
1449 |
} else if (command.equals(SELECT_BY_DEGREE_CMD)) { |
2 |
26 Feb 07 |
jari |
1450 |
onDegreeSelection(); |
2 |
26 Feb 07 |
jari |
1451 |
} else if (command.equals(SELECT_BY_GENE_ID_CMD)) { |
2 |
26 Feb 07 |
jari |
1452 |
onGeneIDSelection(); |
2 |
26 Feb 07 |
jari |
1453 |
} else if (command.equals(LINKS_THRESHOLD_CMD)) { |
2 |
26 Feb 07 |
jari |
1454 |
onLinksThreshold(); |
2 |
26 Feb 07 |
jari |
1455 |
} else if (command.equals(LINKS_COLOR_CMD)) { |
2 |
26 Feb 07 |
jari |
1456 |
onLinksColor(); |
2 |
26 Feb 07 |
jari |
1457 |
} else if (command.equals(DESELECT_CMD)) { |
2 |
26 Feb 07 |
jari |
1458 |
onDeselect(); |
2 |
26 Feb 07 |
jari |
1459 |
} else if (command.equals(SHAPE_OVAL_CMD)) { |
2 |
26 Feb 07 |
jari |
1460 |
onShapeOval(); |
2 |
26 Feb 07 |
jari |
1461 |
} else if (command.equals(SHAPE_RECT_CMD)) { |
2 |
26 Feb 07 |
jari |
1462 |
onShapeRect(); |
2 |
26 Feb 07 |
jari |
1463 |
} else if (command.equals(SET_PUBLIC_CLUSTER_CMD)) { |
2 |
26 Feb 07 |
jari |
1464 |
onSetPublicCluster(); |
2 |
26 Feb 07 |
jari |
1465 |
} else if (command.equals(FIND_CLUSTER_CMD)) { |
2 |
26 Feb 07 |
jari |
1466 |
onFindCluster(spotIndex); |
2 |
26 Feb 07 |
jari |
1467 |
} |
2 |
26 Feb 07 |
jari |
1468 |
} |
2 |
26 Feb 07 |
jari |
1469 |
|
2 |
26 Feb 07 |
jari |
1470 |
public void mouseDragged(MouseEvent e) { |
2 |
26 Feb 07 |
jari |
1471 |
if (SwingUtilities.isRightMouseButton(e)) { |
2 |
26 Feb 07 |
jari |
1472 |
return; |
2 |
26 Feb 07 |
jari |
1473 |
} |
2 |
26 Feb 07 |
jari |
1474 |
if (isZoomStarted) { |
2 |
26 Feb 07 |
jari |
1475 |
processDrawZoom(e.getX(), e.getY()); |
2 |
26 Feb 07 |
jari |
1476 |
} else { |
2 |
26 Feb 07 |
jari |
1477 |
startDrawZoom(e.getX(), e.getY()); |
2 |
26 Feb 07 |
jari |
1478 |
} |
2 |
26 Feb 07 |
jari |
1479 |
} |
2 |
26 Feb 07 |
jari |
1480 |
|
2 |
26 Feb 07 |
jari |
1481 |
private void startDrawZoom(int x, int y) { |
2 |
26 Feb 07 |
jari |
1482 |
isZoomStarted = true; |
2 |
26 Feb 07 |
jari |
1483 |
zoomPoint.setLocation(x, y); |
2 |
26 Feb 07 |
jari |
1484 |
onStartDrawZoom(); |
2 |
26 Feb 07 |
jari |
1485 |
} |
2 |
26 Feb 07 |
jari |
1486 |
|
2 |
26 Feb 07 |
jari |
1487 |
private void processDrawZoom(int x, int y) { |
2 |
26 Feb 07 |
jari |
1488 |
int X = x; |
2 |
26 Feb 07 |
jari |
1489 |
if (x > zoomPoint.x) { |
2 |
26 Feb 07 |
jari |
1490 |
X = zoomPoint.x; |
2 |
26 Feb 07 |
jari |
1491 |
} |
2 |
26 Feb 07 |
jari |
1492 |
int Y = y; |
2 |
26 Feb 07 |
jari |
1493 |
if (y > zoomPoint.y) { |
2 |
26 Feb 07 |
jari |
1494 |
Y = zoomPoint.y; |
2 |
26 Feb 07 |
jari |
1495 |
} |
2 |
26 Feb 07 |
jari |
1496 |
zoomRect.setBounds(X, Y, Math.abs(x-zoomPoint.x), Math.abs(y-zoomPoint.y)); |
2 |
26 Feb 07 |
jari |
1497 |
drawZoomRect(zoomRect); |
2 |
26 Feb 07 |
jari |
1498 |
} |
2 |
26 Feb 07 |
jari |
1499 |
|
2 |
26 Feb 07 |
jari |
1500 |
private void stopDrawZoom() { |
2 |
26 Feb 07 |
jari |
1501 |
isZoomStarted = false; |
2 |
26 Feb 07 |
jari |
1502 |
zoom(zoomRect); |
2 |
26 Feb 07 |
jari |
1503 |
} |
2 |
26 Feb 07 |
jari |
1504 |
|
2 |
26 Feb 07 |
jari |
1505 |
public void mouseMoved(MouseEvent e) { |
2 |
26 Feb 07 |
jari |
1506 |
if (popup.isVisible()) { |
2 |
26 Feb 07 |
jari |
1507 |
return; |
2 |
26 Feb 07 |
jari |
1508 |
} |
2 |
26 Feb 07 |
jari |
1509 |
float scale = getScale(); |
2 |
26 Feb 07 |
jari |
1510 |
float X = (float)(e.getX()-insets.left)/scale; |
2 |
26 Feb 07 |
jari |
1511 |
float Y = (float)(e.getY()-insets.top)/scale; |
2 |
26 Feb 07 |
jari |
1512 |
if (isSpotSelected) { |
2 |
26 Feb 07 |
jari |
1513 |
if (spotRect.contains(X, Y)) { |
2 |
26 Feb 07 |
jari |
1514 |
return; |
2 |
26 Feb 07 |
jari |
1515 |
} else { |
2 |
26 Feb 07 |
jari |
1516 |
isSpotSelected = false; |
2 |
26 Feb 07 |
jari |
1517 |
unselectSpot(spotIndex); |
2 |
26 Feb 07 |
jari |
1518 |
spotIndex = -1; |
2 |
26 Feb 07 |
jari |
1519 |
} |
2 |
26 Feb 07 |
jari |
1520 |
} |
2 |
26 Feb 07 |
jari |
1521 |
if ((spotIndex = findSpot(X, Y, spotRect)) != -1) { |
2 |
26 Feb 07 |
jari |
1522 |
selectSpot(spotIndex); |
2 |
26 Feb 07 |
jari |
1523 |
isSpotSelected = true; |
2 |
26 Feb 07 |
jari |
1524 |
} |
2 |
26 Feb 07 |
jari |
1525 |
} |
2 |
26 Feb 07 |
jari |
1526 |
|
2 |
26 Feb 07 |
jari |
1527 |
public void mouseClicked(MouseEvent event) { |
2 |
26 Feb 07 |
jari |
1528 |
if (SwingUtilities.isRightMouseButton(event)) { |
2 |
26 Feb 07 |
jari |
1529 |
return; |
2 |
26 Feb 07 |
jari |
1530 |
} |
2 |
26 Feb 07 |
jari |
1531 |
if (event.isShiftDown()) { |
2 |
26 Feb 07 |
jari |
// zooming process |
2 |
26 Feb 07 |
jari |
1533 |
} else { |
2 |
26 Feb 07 |
jari |
// clickable spot feature |
2 |
26 Feb 07 |
jari |
1535 |
if (isSpotSelected) { |
2 |
26 Feb 07 |
jari |
1536 |
if (RelevanceNetworkViewer.this.isGenes) |
2 |
26 Feb 07 |
jari |
1537 |
framework.displaySlideElementInfo(0, spotIndex); |
2 |
26 Feb 07 |
jari |
1538 |
else |
2 |
26 Feb 07 |
jari |
1539 |
framework.displaySingleArrayViewer(spotIndex); |
2 |
26 Feb 07 |
jari |
1540 |
} |
2 |
26 Feb 07 |
jari |
1541 |
} |
2 |
26 Feb 07 |
jari |
1542 |
} |
2 |
26 Feb 07 |
jari |
1543 |
|
2 |
26 Feb 07 |
jari |
1544 |
public void mouseReleased(MouseEvent event) { |
2 |
26 Feb 07 |
jari |
1545 |
if (SwingUtilities.isRightMouseButton(event)) { |
2 |
26 Feb 07 |
jari |
1546 |
maybeShowPopup(event); |
2 |
26 Feb 07 |
jari |
1547 |
} else { |
2 |
26 Feb 07 |
jari |
1548 |
if (isZoomStarted) { |
2 |
26 Feb 07 |
jari |
1549 |
stopDrawZoom(); |
2 |
26 Feb 07 |
jari |
1550 |
} |
2 |
26 Feb 07 |
jari |
1551 |
} |
2 |
26 Feb 07 |
jari |
1552 |
} |
2 |
26 Feb 07 |
jari |
1553 |
|
2 |
26 Feb 07 |
jari |
1554 |
private void maybeShowPopup(MouseEvent e) { |
2 |
26 Feb 07 |
jari |
1555 |
if (!e.isPopupTrigger()) { |
2 |
26 Feb 07 |
jari |
1556 |
return; |
2 |
26 Feb 07 |
jari |
1557 |
} |
2 |
26 Feb 07 |
jari |
1558 |
setEnableMenuItem(ZOOM_OUT_CMD, getPreferredSize().width-insets.left-insets.right >= 300 || getPreferredSize().height-insets.top-insets.bottom >= 300); |
2 |
26 Feb 07 |
jari |
1559 |
setEnableMenuItem(ZOOM_IN_CMD, Math.max(getWidth()+insets.left+insets.right, getHeight()+insets.top+insets.bottom) < MAX_CONTENT_SIZE/ZOOM_COEFFICIENT-1); |
2 |
26 Feb 07 |
jari |
1560 |
setEnableMenuItem(SET_PUBLIC_CLUSTER_CMD, hasSelected()); |
2 |
26 Feb 07 |
jari |
1561 |
setEnableMenuItem(FIND_CLUSTER_CMD, isSpotSelected); |
2 |
26 Feb 07 |
jari |
1562 |
popup.show(e.getComponent(), e.getX(), e.getY()); |
2 |
26 Feb 07 |
jari |
1563 |
} |
2 |
26 Feb 07 |
jari |
1564 |
} |
2 |
26 Feb 07 |
jari |
1565 |
} |