2 |
26 Feb 07 |
jari |
1 |
/* |
2 |
26 Feb 07 |
jari |
Copyright @ 1999-2004, The Institute for Genomic Research (TIGR). |
2 |
26 Feb 07 |
jari |
All rights reserved. |
2 |
26 Feb 07 |
jari |
4 |
*/ |
2 |
26 Feb 07 |
jari |
5 |
/* |
2 |
26 Feb 07 |
jari |
* $RCSfile: TerrainViewer.java,v $ |
2 |
26 Feb 07 |
jari |
* $Revision: 1.11 $ |
2 |
26 Feb 07 |
jari |
* $Date: 2006/05/02 16:57:36 $ |
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.terrain; |
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.Component; |
2 |
26 Feb 07 |
jari |
16 |
import java.awt.Dimension; |
2 |
26 Feb 07 |
jari |
17 |
import java.awt.Font; |
2 |
26 Feb 07 |
jari |
18 |
import java.awt.Frame; |
2 |
26 Feb 07 |
jari |
19 |
import java.awt.GraphicsConfiguration; |
2 |
26 Feb 07 |
jari |
20 |
import java.awt.Point; |
2 |
26 Feb 07 |
jari |
21 |
import java.awt.event.ActionEvent; |
2 |
26 Feb 07 |
jari |
22 |
import java.awt.event.ActionListener; |
2 |
26 Feb 07 |
jari |
23 |
import java.awt.event.KeyEvent; |
2 |
26 Feb 07 |
jari |
24 |
import java.awt.event.KeyListener; |
2 |
26 Feb 07 |
jari |
25 |
import java.awt.event.MouseAdapter; |
2 |
26 Feb 07 |
jari |
26 |
import java.awt.event.MouseEvent; |
2 |
26 Feb 07 |
jari |
27 |
import java.awt.event.MouseMotionListener; |
2 |
26 Feb 07 |
jari |
28 |
import java.awt.image.BufferedImage; |
2 |
26 Feb 07 |
jari |
29 |
import java.beans.Expression; |
2 |
26 Feb 07 |
jari |
30 |
import java.util.ArrayList; |
2 |
26 Feb 07 |
jari |
31 |
|
2 |
26 Feb 07 |
jari |
32 |
import javax.media.j3d.AmbientLight; |
2 |
26 Feb 07 |
jari |
33 |
import javax.media.j3d.Appearance; |
2 |
26 Feb 07 |
jari |
34 |
import javax.media.j3d.Background; |
2 |
26 Feb 07 |
jari |
35 |
import javax.media.j3d.Behavior; |
2 |
26 Feb 07 |
jari |
36 |
import javax.media.j3d.Billboard; |
2 |
26 Feb 07 |
jari |
37 |
import javax.media.j3d.BoundingLeaf; |
2 |
26 Feb 07 |
jari |
38 |
import javax.media.j3d.BoundingSphere; |
2 |
26 Feb 07 |
jari |
39 |
import javax.media.j3d.Bounds; |
2 |
26 Feb 07 |
jari |
40 |
import javax.media.j3d.BranchGroup; |
2 |
26 Feb 07 |
jari |
41 |
import javax.media.j3d.Canvas3D; |
2 |
26 Feb 07 |
jari |
42 |
import javax.media.j3d.ColoringAttributes; |
2 |
26 Feb 07 |
jari |
43 |
import javax.media.j3d.DirectionalLight; |
2 |
26 Feb 07 |
jari |
44 |
import javax.media.j3d.Geometry; |
2 |
26 Feb 07 |
jari |
45 |
import javax.media.j3d.GeometryArray; |
2 |
26 Feb 07 |
jari |
46 |
import javax.media.j3d.Group; |
2 |
26 Feb 07 |
jari |
47 |
import javax.media.j3d.ImageComponent; |
2 |
26 Feb 07 |
jari |
48 |
import javax.media.j3d.ImageComponent2D; |
2 |
26 Feb 07 |
jari |
49 |
import javax.media.j3d.Light; |
2 |
26 Feb 07 |
jari |
50 |
import javax.media.j3d.Node; |
2 |
26 Feb 07 |
jari |
51 |
import javax.media.j3d.PickCone; |
2 |
26 Feb 07 |
jari |
52 |
import javax.media.j3d.PointLight; |
2 |
26 Feb 07 |
jari |
53 |
import javax.media.j3d.PolygonAttributes; |
2 |
26 Feb 07 |
jari |
54 |
import javax.media.j3d.Screen3D; |
2 |
26 Feb 07 |
jari |
55 |
import javax.media.j3d.Shape3D; |
2 |
26 Feb 07 |
jari |
56 |
import javax.media.j3d.Transform3D; |
2 |
26 Feb 07 |
jari |
57 |
import javax.media.j3d.TransformGroup; |
2 |
26 Feb 07 |
jari |
58 |
import javax.swing.ButtonGroup; |
2 |
26 Feb 07 |
jari |
59 |
import javax.swing.JCheckBoxMenuItem; |
2 |
26 Feb 07 |
jari |
60 |
import javax.swing.JComponent; |
2 |
26 Feb 07 |
jari |
61 |
import javax.swing.JMenu; |
2 |
26 Feb 07 |
jari |
62 |
import javax.swing.JMenuItem; |
2 |
26 Feb 07 |
jari |
63 |
import javax.swing.JOptionPane; |
2 |
26 Feb 07 |
jari |
64 |
import javax.swing.JPanel; |
2 |
26 Feb 07 |
jari |
65 |
import javax.swing.JPopupMenu; |
2 |
26 Feb 07 |
jari |
66 |
import javax.swing.JRadioButtonMenuItem; |
2 |
26 Feb 07 |
jari |
67 |
import javax.swing.JToolTip; |
2 |
26 Feb 07 |
jari |
68 |
import javax.swing.JWindow; |
2 |
26 Feb 07 |
jari |
69 |
import javax.swing.SwingUtilities; |
2 |
26 Feb 07 |
jari |
70 |
import javax.swing.Timer; |
2 |
26 Feb 07 |
jari |
71 |
import javax.swing.undo.AbstractUndoableEdit; |
2 |
26 Feb 07 |
jari |
72 |
import javax.swing.undo.CannotRedoException; |
2 |
26 Feb 07 |
jari |
73 |
import javax.swing.undo.CannotUndoException; |
2 |
26 Feb 07 |
jari |
74 |
import javax.swing.undo.UndoManager; |
2 |
26 Feb 07 |
jari |
75 |
import javax.vecmath.Color3f; |
2 |
26 Feb 07 |
jari |
76 |
import javax.vecmath.Point2f; |
2 |
26 Feb 07 |
jari |
77 |
import javax.vecmath.Point3d; |
2 |
26 Feb 07 |
jari |
78 |
import javax.vecmath.Point3f; |
2 |
26 Feb 07 |
jari |
79 |
import javax.vecmath.Vector3d; |
2 |
26 Feb 07 |
jari |
80 |
import javax.vecmath.Vector3f; |
2 |
26 Feb 07 |
jari |
81 |
|
2 |
26 Feb 07 |
jari |
82 |
import org.tigr.microarray.mev.cluster.clusterUtil.Cluster; |
2 |
26 Feb 07 |
jari |
83 |
import org.tigr.microarray.mev.cluster.gui.Experiment; |
2 |
26 Feb 07 |
jari |
84 |
import org.tigr.microarray.mev.cluster.gui.IData; |
2 |
26 Feb 07 |
jari |
85 |
import org.tigr.microarray.mev.cluster.gui.IDisplayMenu; |
2 |
26 Feb 07 |
jari |
86 |
import org.tigr.microarray.mev.cluster.gui.IFramework; |
2 |
26 Feb 07 |
jari |
87 |
import org.tigr.microarray.mev.cluster.gui.IViewer; |
2 |
26 Feb 07 |
jari |
88 |
import org.tigr.microarray.mev.cluster.gui.impl.dialogs.ListDialog; |
2 |
26 Feb 07 |
jari |
89 |
import org.tigr.microarray.mev.cluster.gui.impl.util.IntArray; |
2 |
26 Feb 07 |
jari |
90 |
|
2 |
26 Feb 07 |
jari |
91 |
import com.sun.j3d.utils.geometry.Sphere; |
2 |
26 Feb 07 |
jari |
92 |
import com.sun.j3d.utils.geometry.Text2D; |
2 |
26 Feb 07 |
jari |
93 |
import com.sun.j3d.utils.picking.PickCanvas; |
2 |
26 Feb 07 |
jari |
94 |
import com.sun.j3d.utils.picking.PickIntersection; |
2 |
26 Feb 07 |
jari |
95 |
import com.sun.j3d.utils.picking.PickResult; |
2 |
26 Feb 07 |
jari |
96 |
import com.sun.j3d.utils.universe.PlatformGeometry; |
2 |
26 Feb 07 |
jari |
97 |
import com.sun.j3d.utils.universe.SimpleUniverse; |
2 |
26 Feb 07 |
jari |
98 |
|
2 |
26 Feb 07 |
jari |
99 |
public class TerrainViewer extends JPanel implements IViewer { |
2 |
26 Feb 07 |
jari |
100 |
|
2 |
26 Feb 07 |
jari |
101 |
|
2 |
26 Feb 07 |
jari |
102 |
private IData data; |
2 |
26 Feb 07 |
jari |
103 |
private IFramework framework; |
2 |
26 Feb 07 |
jari |
104 |
private int labelIndex = -1; |
2 |
26 Feb 07 |
jari |
105 |
|
2 |
26 Feb 07 |
jari |
106 |
private boolean isGenes = true; |
2 |
26 Feb 07 |
jari |
107 |
private int[][] clusters; |
2 |
26 Feb 07 |
jari |
108 |
private float[][] weights; |
2 |
26 Feb 07 |
jari |
109 |
private float[][] locations; |
2 |
26 Feb 07 |
jari |
110 |
private float sigma; |
2 |
26 Feb 07 |
jari |
111 |
private int grid_size = 65; |
2 |
26 Feb 07 |
jari |
112 |
private boolean isBillboard = false; |
2 |
26 Feb 07 |
jari |
113 |
|
2 |
26 Feb 07 |
jari |
114 |
private final Color3f BLACK_COLOR = new Color3f(0f, 0f, 0f); |
2 |
26 Feb 07 |
jari |
115 |
private final Color3f WHITE_COLOR = new Color3f(1f, 1f, 1f); |
2 |
26 Feb 07 |
jari |
116 |
private static final BoundingSphere BILLBOARD_BOUNDS = new BoundingSphere(new Point3d(), 100d); |
2 |
26 Feb 07 |
jari |
117 |
private static final Point3f BILLBOARD_P3F = new Point3f(-0.008f, 0.0008f, 0); |
2 |
26 Feb 07 |
jari |
118 |
|
2 |
26 Feb 07 |
jari |
// menu commands |
2 |
26 Feb 07 |
jari |
120 |
private static final String FILL_POLYGON_CMD = "fill-polygone-cmd"; |
2 |
26 Feb 07 |
jari |
121 |
private static final String ZOOM_IN_CMD = "zoom-in-cmd"; |
2 |
26 Feb 07 |
jari |
122 |
private static final String UNDO_CMD = "undo-cmd"; |
2 |
26 Feb 07 |
jari |
123 |
private static final String SHOW_ALL_CMD = "show-all-cmd"; |
2 |
26 Feb 07 |
jari |
124 |
private static final String POINTS_SHAPE_CMD = "points-shape-cmd"; |
2 |
26 Feb 07 |
jari |
125 |
private static final String CUBES_SHAPE_CMD = "cubes-shape-cmd"; |
2 |
26 Feb 07 |
jari |
126 |
private static final String SPHERES_SHAPE_CMD = "spheres-shape-cmd"; |
2 |
26 Feb 07 |
jari |
127 |
private static final String GRID_SIZE_CMD = "grid-size-cmd"; |
2 |
26 Feb 07 |
jari |
128 |
private static final String SHOW_ELEMENTS_CMD = "show-elements-cmd"; |
2 |
26 Feb 07 |
jari |
129 |
private static final String DESELECT_CMD = "deselect-cmd"; |
2 |
26 Feb 07 |
jari |
130 |
private static final String SHOW_CONTROLS_CMD = "show-controls-cmd"; |
2 |
26 Feb 07 |
jari |
131 |
private static final String DRIFT_DIALOG_CMD = "drift-dialog-cmd"; |
2 |
26 Feb 07 |
jari |
132 |
private static final String LAUNCH_SESSION_CMD = "launch-session-cmd"; |
2 |
26 Feb 07 |
jari |
133 |
private static final String SET_CLUSTER_CMD = "set-cluster-cmd"; |
2 |
26 Feb 07 |
jari |
134 |
private static final String SHOW_LINKS_CMD = "show-links-cmd"; |
2 |
26 Feb 07 |
jari |
135 |
private static final String LINKS_THRESHOLD_CMD = "links-threshold-cmd"; |
2 |
26 Feb 07 |
jari |
136 |
private static final String LINKS_WIDTH_CMD = "links-width-cmd"; |
2 |
26 Feb 07 |
jari |
137 |
private static final String HIDE_LABELS_CMD = "hide-labels-cmd"; |
2 |
26 Feb 07 |
jari |
138 |
private static final String USE_BILLBOARD_CMD = "use-billboard-cmd"; |
2 |
26 Feb 07 |
jari |
139 |
static { |
2 |
26 Feb 07 |
jari |
140 |
JPopupMenu.setDefaultLightWeightPopupEnabled(false); |
2 |
26 Feb 07 |
jari |
141 |
} |
2 |
26 Feb 07 |
jari |
142 |
private JPopupMenu popup; |
2 |
26 Feb 07 |
jari |
143 |
private JWindow tipWindow; |
2 |
26 Feb 07 |
jari |
144 |
private ControlPanel controlPanel; |
2 |
26 Feb 07 |
jari |
145 |
|
2 |
26 Feb 07 |
jari |
// 3D scene and its elements |
2 |
26 Feb 07 |
jari |
147 |
private SimpleUniverse universe; |
2 |
26 Feb 07 |
jari |
148 |
private Canvas3D onScreenCanvas; |
2 |
26 Feb 07 |
jari |
149 |
private Canvas3D offScreenCanvas; |
2 |
26 Feb 07 |
jari |
150 |
private TransformGroup view_tg; |
2 |
26 Feb 07 |
jari |
151 |
private GenesShape genesShape; |
2 |
26 Feb 07 |
jari |
152 |
private BranchGroup sceneGroup; |
2 |
26 Feb 07 |
jari |
153 |
private Landscape landscape; |
2 |
26 Feb 07 |
jari |
154 |
private LinksShape linksShape; |
2 |
26 Feb 07 |
jari |
155 |
private SelectionShape selectionShape; |
2 |
26 Feb 07 |
jari |
156 |
private BranchGroup labelsGroup; |
2 |
26 Feb 07 |
jari |
157 |
private KeyMotionBehavior keyMotionBehavior; |
2 |
26 Feb 07 |
jari |
158 |
private DriftInterpolator driftInterpolator; |
2 |
26 Feb 07 |
jari |
159 |
private PickBehavior pickBehavior; |
2 |
26 Feb 07 |
jari |
// zooming variables |
2 |
26 Feb 07 |
jari |
161 |
private Point2f up_left_point = new Point2f(0f, 0f); |
2 |
26 Feb 07 |
jari |
162 |
private Point2f bottom_right_point = new Point2f(1f, 1f); |
2 |
26 Feb 07 |
jari |
// undo zoom operation support |
2 |
26 Feb 07 |
jari |
164 |
private UndoManager undoManager = new UndoManager(); |
2 |
26 Feb 07 |
jari |
165 |
private Experiment experiment; |
2 |
26 Feb 07 |
jari |
166 |
private int exptID = 0; |
2 |
26 Feb 07 |
jari |
167 |
|
2 |
26 Feb 07 |
jari |
168 |
public Expression getExpression(){ |
2 |
26 Feb 07 |
jari |
169 |
return new Expression(this, this.getClass(), "new", |
2 |
26 Feb 07 |
jari |
170 |
new Object[]{new Boolean(isGenes), this.experiment, this.clusters, this.weights, this.locations, new Float(this.sigma), new Integer(this.labelIndex)}); |
2 |
26 Feb 07 |
jari |
171 |
} |
2 |
26 Feb 07 |
jari |
172 |
public TerrainViewer(Boolean isGenes, Experiment experiment, int[][] clusters, float[][] weights, float[][] locations, Float sigma, Integer labelIndex) { |
2 |
26 Feb 07 |
jari |
173 |
this(isGenes.booleanValue(), experiment, clusters, weights, locations, sigma.floatValue(), labelIndex.intValue()); |
2 |
26 Feb 07 |
jari |
174 |
} |
2 |
26 Feb 07 |
jari |
175 |
public TerrainViewer(boolean isGenes, Experiment experiment, int[][] clusters, float[][] weights, float[][] locations, float sigma, int labelIndex) { |
2 |
26 Feb 07 |
jari |
176 |
this.isGenes = isGenes; |
2 |
26 Feb 07 |
jari |
177 |
this.experiment = experiment; |
2 |
26 Feb 07 |
jari |
178 |
this.exptID = experiment.getId(); |
2 |
26 Feb 07 |
jari |
179 |
this.clusters = clusters; |
2 |
26 Feb 07 |
jari |
180 |
this.weights = weights; |
2 |
26 Feb 07 |
jari |
181 |
this.locations = locations; |
2 |
26 Feb 07 |
jari |
182 |
this.sigma = sigma; |
2 |
26 Feb 07 |
jari |
183 |
setPreferredSize(new Dimension(10, 10)); |
2 |
26 Feb 07 |
jari |
184 |
Listener listener = new Listener(); |
2 |
26 Feb 07 |
jari |
// create the universe |
2 |
26 Feb 07 |
jari |
186 |
GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); |
2 |
26 Feb 07 |
jari |
187 |
this.onScreenCanvas = new Canvas3D(config); |
2 |
26 Feb 07 |
jari |
188 |
this.universe = new SimpleUniverse(this.onScreenCanvas); |
2 |
26 Feb 07 |
jari |
189 |
|
2 |
26 Feb 07 |
jari |
190 |
this.offScreenCanvas = new Canvas3D(config, true); |
2 |
26 Feb 07 |
jari |
191 |
Screen3D sOn = onScreenCanvas.getScreen3D(); |
2 |
26 Feb 07 |
jari |
192 |
Screen3D sOff = offScreenCanvas.getScreen3D(); |
2 |
26 Feb 07 |
jari |
193 |
sOff.setSize(sOn.getSize()); |
2 |
26 Feb 07 |
jari |
194 |
sOff.setPhysicalScreenWidth(sOn.getPhysicalScreenWidth()); |
2 |
26 Feb 07 |
jari |
195 |
sOff.setPhysicalScreenHeight(sOn.getPhysicalScreenHeight()); |
2 |
26 Feb 07 |
jari |
// attach the offscreen canvas to the view |
2 |
26 Feb 07 |
jari |
197 |
this.universe.getViewer().getView().addCanvas3D(this.offScreenCanvas); |
2 |
26 Feb 07 |
jari |
// set its bounds |
2 |
26 Feb 07 |
jari |
199 |
BoundingLeaf boundingLeaf = new BoundingLeaf(new BoundingSphere(new Point3d(), 100d)); |
2 |
26 Feb 07 |
jari |
200 |
boundingLeaf.setCapability(BoundingLeaf.ALLOW_REGION_READ); |
2 |
26 Feb 07 |
jari |
201 |
PlatformGeometry platformGeometry = new PlatformGeometry(); |
2 |
26 Feb 07 |
jari |
202 |
platformGeometry.addChild(boundingLeaf); |
2 |
26 Feb 07 |
jari |
203 |
platformGeometry.compile(); |
2 |
26 Feb 07 |
jari |
204 |
this.universe.getViewingPlatform().setPlatformGeometry(platformGeometry); |
2 |
26 Feb 07 |
jari |
// set distances |
2 |
26 Feb 07 |
jari |
206 |
this.universe.getViewer().getView().setFrontClipDistance(0.001); |
2 |
26 Feb 07 |
jari |
207 |
this.universe.getViewer().getView().setBackClipDistance(0.5); |
2 |
26 Feb 07 |
jari |
// basis point |
2 |
26 Feb 07 |
jari |
209 |
Point3d basis = new Point3d(0.5, 0, 0.5); |
2 |
26 Feb 07 |
jari |
210 |
this.view_tg = universe.getViewingPlatform().getViewPlatformTransform(); |
2 |
26 Feb 07 |
jari |
// set initilal view point |
2 |
26 Feb 07 |
jari |
212 |
setInitialViewPoint(view_tg, basis); |
2 |
26 Feb 07 |
jari |
// drifting |
2 |
26 Feb 07 |
jari |
214 |
this.driftInterpolator = new DriftInterpolator(this.view_tg, boundingLeaf); |
2 |
26 Feb 07 |
jari |
// create heights |
2 |
26 Feb 07 |
jari |
216 |
float[][] heights = DomainUtil.getHeights(this.locations, this.grid_size, this.sigma); |
2 |
26 Feb 07 |
jari |
// selection shape |
2 |
26 Feb 07 |
jari |
218 |
this.selectionShape = new SelectionShape(); |
2 |
26 Feb 07 |
jari |
// the landscape |
2 |
26 Feb 07 |
jari |
220 |
this.landscape = new Landscape(heights); |
2 |
26 Feb 07 |
jari |
221 |
this.landscape.setPoligonMode(PolygonAttributes.POLYGON_FILL); |
2 |
26 Feb 07 |
jari |
222 |
TransformGroup landTransform = new TransformGroup(); |
2 |
26 Feb 07 |
jari |
223 |
landTransform.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); |
2 |
26 Feb 07 |
jari |
224 |
landTransform.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); |
2 |
26 Feb 07 |
jari |
225 |
landTransform.addChild(this.landscape); |
2 |
26 Feb 07 |
jari |
// links shape |
2 |
26 Feb 07 |
jari |
227 |
this.linksShape = new LinksShape(clusters, weights, locations); |
2 |
26 Feb 07 |
jari |
// keyboard support |
2 |
26 Feb 07 |
jari |
229 |
this.keyMotionBehavior = createKeyMotionBehavior(this.view_tg, basis, boundingLeaf); |
2 |
26 Feb 07 |
jari |
// control panel |
2 |
26 Feb 07 |
jari |
231 |
this.controlPanel = new ControlPanel(landTransform, this.keyMotionBehavior, boundingLeaf); |
2 |
26 Feb 07 |
jari |
//this.controlPanel.setVisible(false); |
2 |
26 Feb 07 |
jari |
233 |
Behavior sliderBehavior = this.controlPanel.getSliderBehavior(); |
2 |
26 Feb 07 |
jari |
// add gene shapes |
2 |
26 Feb 07 |
jari |
235 |
this.genesShape = new GenesShape(GenesShape.POINTS, this.locations, this.up_left_point, this.bottom_right_point); |
2 |
26 Feb 07 |
jari |
236 |
this.genesShape.setBounds(boundingLeaf.getRegion()); |
2 |
26 Feb 07 |
jari |
// add labels |
2 |
26 Feb 07 |
jari |
238 |
this.labelIndex = labelIndex; |
2 |
26 Feb 07 |
jari |
// create scene |
2 |
26 Feb 07 |
jari |
240 |
Node[] nodes = new Node[] {this.selectionShape, landTransform, sliderBehavior, this.keyMotionBehavior, this.driftInterpolator, this.genesShape, this.linksShape}; |
2 |
26 Feb 07 |
jari |
241 |
this.sceneGroup = createSceneGraph(nodes, boundingLeaf); |
2 |
26 Feb 07 |
jari |
242 |
|
2 |
26 Feb 07 |
jari |
243 |
this.pickBehavior = new PickBehavior(this.sceneGroup, this.onScreenCanvas, boundingLeaf.getRegion()); |
2 |
26 Feb 07 |
jari |
244 |
this.pickBehavior.setPickListener(listener); |
2 |
26 Feb 07 |
jari |
245 |
this.sceneGroup.addChild(this.pickBehavior); |
2 |
26 Feb 07 |
jari |
246 |
|
2 |
26 Feb 07 |
jari |
247 |
this.sceneGroup.compile(); |
2 |
26 Feb 07 |
jari |
// add the canvas to this panel |
2 |
26 Feb 07 |
jari |
249 |
setLayout(new BorderLayout()); |
2 |
26 Feb 07 |
jari |
250 |
add(this.onScreenCanvas, BorderLayout.CENTER); |
2 |
26 Feb 07 |
jari |
// control panel |
2 |
26 Feb 07 |
jari |
252 |
add(this.controlPanel, BorderLayout.SOUTH); |
2 |
26 Feb 07 |
jari |
253 |
|
2 |
26 Feb 07 |
jari |
254 |
this.popup = createJPopupMenu(listener); |
2 |
26 Feb 07 |
jari |
255 |
this.onScreenCanvas.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
256 |
this.onScreenCanvas.addMouseMotionListener(listener); |
2 |
26 Feb 07 |
jari |
257 |
this.onScreenCanvas.addKeyListener(listener); |
2 |
26 Feb 07 |
jari |
258 |
} |
2 |
26 Feb 07 |
jari |
259 |
|
2 |
26 Feb 07 |
jari |
260 |
|
2 |
26 Feb 07 |
jari |
261 |
/** |
2 |
26 Feb 07 |
jari |
* @see org.tigr.microarray.mev.cluster.gui.IViewer#setExperiment(org.tigr.microarray.mev.cluster.gui.Experiment) |
2 |
26 Feb 07 |
jari |
263 |
*/ |
2 |
26 Feb 07 |
jari |
264 |
public void setExperiment(Experiment e) { |
2 |
26 Feb 07 |
jari |
265 |
this.experiment = e; |
2 |
26 Feb 07 |
jari |
266 |
} |
2 |
26 Feb 07 |
jari |
267 |
|
2 |
26 Feb 07 |
jari |
// IViewer implementation |
2 |
26 Feb 07 |
jari |
269 |
public JComponent getContentComponent() { |
2 |
26 Feb 07 |
jari |
270 |
return this; |
2 |
26 Feb 07 |
jari |
271 |
} |
2 |
26 Feb 07 |
jari |
272 |
|
2 |
26 Feb 07 |
jari |
273 |
public JComponent getHeaderComponent() { |
2 |
26 Feb 07 |
jari |
274 |
return null; |
2 |
26 Feb 07 |
jari |
275 |
} |
2 |
26 Feb 07 |
jari |
276 |
|
2 |
26 Feb 07 |
jari |
277 |
public void onSelected(IFramework framework) { |
2 |
26 Feb 07 |
jari |
278 |
this.framework = framework; |
2 |
26 Feb 07 |
jari |
279 |
if(this.tipWindow == null) |
2 |
26 Feb 07 |
jari |
280 |
this.tipWindow = new JWindow(framework.getFrame()); |
2 |
26 Feb 07 |
jari |
281 |
|
2 |
26 Feb 07 |
jari |
282 |
this.universe.addBranchGraph(this.sceneGroup); |
2 |
26 Feb 07 |
jari |
283 |
this.data = framework.getData(); |
2 |
26 Feb 07 |
jari |
284 |
onDataChanged(this.data); |
2 |
26 Feb 07 |
jari |
285 |
onMenuChanged(framework.getDisplayMenu()); |
2 |
26 Feb 07 |
jari |
286 |
} |
2 |
26 Feb 07 |
jari |
287 |
|
2 |
26 Feb 07 |
jari |
288 |
public void onDataChanged(IData data) { |
2 |
26 Feb 07 |
jari |
289 |
this.data = data; |
2 |
26 Feb 07 |
jari |
290 |
if (isGenes) |
2 |
26 Feb 07 |
jari |
291 |
this.genesShape.updateColors(this.data.getColorIndices(), this.data.getColors()); |
2 |
26 Feb 07 |
jari |
292 |
else |
2 |
26 Feb 07 |
jari |
293 |
this.genesShape.updateColors(this.data.getExperimentColorIndices(), this.data.getExperimentColors()); |
2 |
26 Feb 07 |
jari |
294 |
|
2 |
26 Feb 07 |
jari |
295 |
} |
2 |
26 Feb 07 |
jari |
296 |
|
2 |
26 Feb 07 |
jari |
297 |
public void onMenuChanged(IDisplayMenu menu) { |
2 |
26 Feb 07 |
jari |
298 |
if (this.labelIndex == menu.getLabelIndex()) |
2 |
26 Feb 07 |
jari |
299 |
return; |
2 |
26 Feb 07 |
jari |
300 |
this.labelIndex = menu.getLabelIndex(); |
2 |
26 Feb 07 |
jari |
301 |
updateLabelsGroup(); |
2 |
26 Feb 07 |
jari |
302 |
} |
2 |
26 Feb 07 |
jari |
303 |
|
2 |
26 Feb 07 |
jari |
304 |
public void onDeselected() { |
2 |
26 Feb 07 |
jari |
305 |
this.sceneGroup.detach(); |
2 |
26 Feb 07 |
jari |
306 |
} |
2 |
26 Feb 07 |
jari |
307 |
|
2 |
26 Feb 07 |
jari |
308 |
public void onClosed() { |
2 |
26 Feb 07 |
jari |
309 |
} |
2 |
26 Feb 07 |
jari |
310 |
|
2 |
26 Feb 07 |
jari |
311 |
public BufferedImage getImage() { |
2 |
26 Feb 07 |
jari |
312 |
ImageComponent2D buffer = new ImageComponent2D(ImageComponent.FORMAT_RGB, new BufferedImage(onScreenCanvas.getWidth(), onScreenCanvas.getHeight(), BufferedImage.TYPE_3BYTE_BGR)); |
2 |
26 Feb 07 |
jari |
313 |
offScreenCanvas.setOffScreenLocation(onScreenCanvas.getLocationOnScreen()); |
2 |
26 Feb 07 |
jari |
314 |
offScreenCanvas.setOffScreenBuffer(buffer); |
2 |
26 Feb 07 |
jari |
315 |
offScreenCanvas.renderOffScreenBuffer(); |
2 |
26 Feb 07 |
jari |
316 |
offScreenCanvas.waitForOffScreenRendering(); |
2 |
26 Feb 07 |
jari |
317 |
BufferedImage offImage = offScreenCanvas.getOffScreenBuffer().getImage(); |
2 |
26 Feb 07 |
jari |
318 |
BufferedImage image = new BufferedImage(offImage.getWidth(), offImage.getHeight(), BufferedImage.TYPE_3BYTE_BGR); |
2 |
26 Feb 07 |
jari |
319 |
image.setData(offImage.getData()); |
2 |
26 Feb 07 |
jari |
320 |
return image; |
2 |
26 Feb 07 |
jari |
321 |
} |
2 |
26 Feb 07 |
jari |
// end IViewer implementation |
2 |
26 Feb 07 |
jari |
323 |
|
2 |
26 Feb 07 |
jari |
324 |
private void setInitialViewPoint(TransformGroup tg, Point3d basis) { |
2 |
26 Feb 07 |
jari |
325 |
Transform3D t3d = new Transform3D(); |
2 |
26 Feb 07 |
jari |
326 |
t3d.lookAt(new Point3d(1.42, 1.0, 1.42), basis, new Vector3d(0, 1, 0)); |
2 |
26 Feb 07 |
jari |
327 |
t3d.invert(); |
2 |
26 Feb 07 |
jari |
328 |
tg.setTransform(t3d); |
2 |
26 Feb 07 |
jari |
329 |
} |
2 |
26 Feb 07 |
jari |
330 |
|
2 |
26 Feb 07 |
jari |
331 |
private BranchGroup createSceneGraph(Node[] nodes, BoundingLeaf boundingLeaf) { |
2 |
26 Feb 07 |
jari |
332 |
BranchGroup objRoot = new BranchGroup(); |
2 |
26 Feb 07 |
jari |
333 |
objRoot.setCapability(BranchGroup.ALLOW_DETACH); |
2 |
26 Feb 07 |
jari |
334 |
objRoot.setCapability(Group.ALLOW_CHILDREN_EXTEND); |
2 |
26 Feb 07 |
jari |
335 |
objRoot.setCapability(Group.ALLOW_CHILDREN_WRITE); |
2 |
26 Feb 07 |
jari |
336 |
|
2 |
26 Feb 07 |
jari |
337 |
Background bg = new Background(BLACK_COLOR); |
2 |
26 Feb 07 |
jari |
338 |
bg.setApplicationBoundingLeaf(boundingLeaf); |
2 |
26 Feb 07 |
jari |
339 |
|
2 |
26 Feb 07 |
jari |
340 |
objRoot.addChild(bg); |
2 |
26 Feb 07 |
jari |
341 |
objRoot.addChild(createAmbientLight(boundingLeaf)); |
2 |
26 Feb 07 |
jari |
342 |
objRoot.addChild(createPointLight(new Point3f(1.5f, 0.5f, 0.5f), boundingLeaf)); |
2 |
26 Feb 07 |
jari |
343 |
objRoot.addChild(createPointLight(new Point3f(0.5f, 0.5f, 1.5f), boundingLeaf)); |
2 |
26 Feb 07 |
jari |
344 |
|
2 |
26 Feb 07 |
jari |
345 |
for (int i=0; i<nodes.length; i++) |
2 |
26 Feb 07 |
jari |
346 |
objRoot.addChild(nodes[i]); |
2 |
26 Feb 07 |
jari |
347 |
|
2 |
26 Feb 07 |
jari |
348 |
return objRoot; |
2 |
26 Feb 07 |
jari |
349 |
} |
2 |
26 Feb 07 |
jari |
350 |
|
2 |
26 Feb 07 |
jari |
351 |
private TransformGroup createLight(Bounds bounds, Vector3d vector) { |
2 |
26 Feb 07 |
jari |
352 |
Transform3D t = new Transform3D(); |
2 |
26 Feb 07 |
jari |
353 |
t.set(vector); |
2 |
26 Feb 07 |
jari |
354 |
TransformGroup lightGroup = new TransformGroup(t); |
2 |
26 Feb 07 |
jari |
355 |
lightGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); |
2 |
26 Feb 07 |
jari |
356 |
lightGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); |
2 |
26 Feb 07 |
jari |
357 |
lightGroup.setCapability(TransformGroup.ENABLE_PICK_REPORTING); |
2 |
26 Feb 07 |
jari |
358 |
|
2 |
26 Feb 07 |
jari |
359 |
ColoringAttributes attr = new ColoringAttributes(); |
2 |
26 Feb 07 |
jari |
360 |
Color3f color = new Color3f(1f, 1f, 1f); |
2 |
26 Feb 07 |
jari |
361 |
attr.setColor(color); |
2 |
26 Feb 07 |
jari |
362 |
Appearance appearance = new Appearance(); |
2 |
26 Feb 07 |
jari |
363 |
appearance.setColoringAttributes(attr); |
2 |
26 Feb 07 |
jari |
364 |
lightGroup.addChild(new Sphere(0.01f, Sphere.GENERATE_NORMALS, 15, appearance)); |
2 |
26 Feb 07 |
jari |
365 |
Light light = new PointLight(color, new Point3f(0.0f, 0.0f, 0.0f), new Point3f(1.0f, 0.0f, 0.0f)); |
2 |
26 Feb 07 |
jari |
366 |
light.setInfluencingBounds(bounds); |
2 |
26 Feb 07 |
jari |
367 |
lightGroup.addChild(light); |
2 |
26 Feb 07 |
jari |
368 |
return lightGroup; |
2 |
26 Feb 07 |
jari |
369 |
} |
2 |
26 Feb 07 |
jari |
370 |
|
2 |
26 Feb 07 |
jari |
371 |
private Billboard createLabelBillboard(TransformGroup label_tg) { |
2 |
26 Feb 07 |
jari |
372 |
label_tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); |
2 |
26 Feb 07 |
jari |
373 |
Billboard billboard = new TerrainBillboard(label_tg, Billboard.ROTATE_ABOUT_POINT, BILLBOARD_P3F, this.view_tg); |
2 |
26 Feb 07 |
jari |
374 |
billboard.setSchedulingBounds(BILLBOARD_BOUNDS); |
2 |
26 Feb 07 |
jari |
375 |
return billboard; |
2 |
26 Feb 07 |
jari |
376 |
} |
2 |
26 Feb 07 |
jari |
377 |
|
2 |
26 Feb 07 |
jari |
378 |
private BranchGroup createLabelsGroup(int labelIndex, float[][] locations, Point2f start, Point2f end) { |
2 |
26 Feb 07 |
jari |
379 |
PolygonAttributes pa = new PolygonAttributes(); |
2 |
26 Feb 07 |
jari |
380 |
pa.setCullFace(PolygonAttributes.CULL_NONE); |
2 |
26 Feb 07 |
jari |
381 |
|
2 |
26 Feb 07 |
jari |
382 |
BranchGroup labels = new BranchGroup(); |
2 |
26 Feb 07 |
jari |
383 |
labels.setCapability(BranchGroup.ALLOW_DETACH); |
2 |
26 Feb 07 |
jari |
384 |
if (this.isGenes && labelIndex < 0) |
2 |
26 Feb 07 |
jari |
385 |
return labels; |
2 |
26 Feb 07 |
jari |
386 |
|
2 |
26 Feb 07 |
jari |
387 |
Transform3D transform = new Transform3D(); |
2 |
26 Feb 07 |
jari |
388 |
Vector3f vector3f = new Vector3f(); |
2 |
26 Feb 07 |
jari |
389 |
TransformGroup position_tg; |
2 |
26 Feb 07 |
jari |
390 |
TransformGroup label_tg; |
2 |
26 Feb 07 |
jari |
391 |
float scale = Math.max(Math.abs(start.x-end.x), Math.abs(start.y-end.y)); |
2 |
26 Feb 07 |
jari |
392 |
for (int i=0; i<locations.length; i++) { |
2 |
26 Feb 07 |
jari |
393 |
float x = locations[i][0]; |
2 |
26 Feb 07 |
jari |
394 |
float y = locations[i][1]; |
2 |
26 Feb 07 |
jari |
395 |
if (x >= start.x && x <= start.x+scale && y >= start.y && y <= start.y+scale) { |
2 |
26 Feb 07 |
jari |
396 |
vector3f.set((x-start.x)/scale+0.008f, -0.008f, (y-start.y)/scale); |
2 |
26 Feb 07 |
jari |
397 |
transform.set(vector3f); |
2 |
26 Feb 07 |
jari |
398 |
position_tg = new TransformGroup(transform); |
2 |
26 Feb 07 |
jari |
399 |
label_tg = new TransformGroup(); |
2 |
26 Feb 07 |
jari |
400 |
String label = this.isGenes ? this.data.getElementAttribute(i, labelIndex) : this.data.getSampleName(i); |
2 |
26 Feb 07 |
jari |
401 |
label_tg.addChild(createText2D(label, WHITE_COLOR, pa)); |
2 |
26 Feb 07 |
jari |
402 |
position_tg.addChild(label_tg); |
2 |
26 Feb 07 |
jari |
403 |
labels.addChild(position_tg); |
2 |
26 Feb 07 |
jari |
404 |
if (this.isBillboard) { |
2 |
26 Feb 07 |
jari |
405 |
Billboard billboard = createLabelBillboard(label_tg); |
2 |
26 Feb 07 |
jari |
406 |
labels.addChild(billboard); |
2 |
26 Feb 07 |
jari |
407 |
} |
2 |
26 Feb 07 |
jari |
408 |
} |
2 |
26 Feb 07 |
jari |
409 |
} |
2 |
26 Feb 07 |
jari |
410 |
labels.compile(); |
2 |
26 Feb 07 |
jari |
411 |
return labels; |
2 |
26 Feb 07 |
jari |
412 |
} |
2 |
26 Feb 07 |
jari |
413 |
|
2 |
26 Feb 07 |
jari |
414 |
private BranchGroup createViewBehavior(TransformGroup tg, Point3d basis, BoundingLeaf boundingLeaf) { |
2 |
26 Feb 07 |
jari |
415 |
BranchGroup behRoot = new BranchGroup(); |
2 |
26 Feb 07 |
jari |
416 |
behRoot.setCapability(BranchGroup.ALLOW_DETACH); |
2 |
26 Feb 07 |
jari |
417 |
behRoot.addChild(createKeyMotionBehavior(tg, basis, boundingLeaf)); |
2 |
26 Feb 07 |
jari |
418 |
return behRoot; |
2 |
26 Feb 07 |
jari |
419 |
} |
2 |
26 Feb 07 |
jari |
420 |
|
2 |
26 Feb 07 |
jari |
421 |
private KeyMotionBehavior createKeyMotionBehavior(TransformGroup tg, Point3d basis, BoundingLeaf boundingLeaf) { |
2 |
26 Feb 07 |
jari |
422 |
KeyMotionBehavior key = new KeyMotionBehavior(tg); |
2 |
26 Feb 07 |
jari |
423 |
key.setSchedulingBoundingLeaf(boundingLeaf); |
2 |
26 Feb 07 |
jari |
424 |
key.setBasis(basis); |
2 |
26 Feb 07 |
jari |
425 |
return key; |
2 |
26 Feb 07 |
jari |
426 |
} |
2 |
26 Feb 07 |
jari |
427 |
|
2 |
26 Feb 07 |
jari |
428 |
private AmbientLight createAmbientLight(BoundingLeaf boundingLeaf) { |
2 |
26 Feb 07 |
jari |
429 |
AmbientLight light = new AmbientLight(); |
2 |
26 Feb 07 |
jari |
430 |
light.setInfluencingBoundingLeaf(boundingLeaf); |
2 |
26 Feb 07 |
jari |
431 |
return light; |
2 |
26 Feb 07 |
jari |
432 |
} |
2 |
26 Feb 07 |
jari |
433 |
|
2 |
26 Feb 07 |
jari |
434 |
private Light createDirectionLight(BoundingLeaf boundingLeaf) { |
2 |
26 Feb 07 |
jari |
435 |
DirectionalLight light = new DirectionalLight(WHITE_COLOR, new Vector3f(-1, 0, -1)); |
2 |
26 Feb 07 |
jari |
436 |
light.setInfluencingBoundingLeaf(boundingLeaf); |
2 |
26 Feb 07 |
jari |
437 |
return light; |
2 |
26 Feb 07 |
jari |
438 |
} |
2 |
26 Feb 07 |
jari |
439 |
|
2 |
26 Feb 07 |
jari |
440 |
private PointLight createPointLight(Point3f position, BoundingLeaf boundingLeaf) { |
2 |
26 Feb 07 |
jari |
441 |
PointLight light = new PointLight(WHITE_COLOR, position, new Point3f(1f, 0f, 0f)); |
2 |
26 Feb 07 |
jari |
442 |
light.setInfluencingBoundingLeaf(boundingLeaf); |
2 |
26 Feb 07 |
jari |
443 |
return light; |
2 |
26 Feb 07 |
jari |
444 |
} |
2 |
26 Feb 07 |
jari |
445 |
|
2 |
26 Feb 07 |
jari |
446 |
private Node createTransformGroup(Transform3D transform, Node node) { |
2 |
26 Feb 07 |
jari |
447 |
TransformGroup tg = new TransformGroup(transform); |
2 |
26 Feb 07 |
jari |
448 |
tg.addChild(node); |
2 |
26 Feb 07 |
jari |
449 |
return tg; |
2 |
26 Feb 07 |
jari |
450 |
} |
2 |
26 Feb 07 |
jari |
451 |
|
2 |
26 Feb 07 |
jari |
452 |
private Text2D createText2D(String text, Color3f color, PolygonAttributes pa) { |
2 |
26 Feb 07 |
jari |
453 |
Text2D text2D = new Text2D("", color, "Arial", 12, Font.BOLD); |
2 |
26 Feb 07 |
jari |
454 |
text2D.setRectangleScaleFactor(0.001f); |
2 |
26 Feb 07 |
jari |
455 |
text2D.setString(text); |
2 |
26 Feb 07 |
jari |
456 |
text2D.getAppearance().setPolygonAttributes(pa); |
2 |
26 Feb 07 |
jari |
457 |
text2D.setCapability(Shape3D.ALLOW_GEOMETRY_READ); |
2 |
26 Feb 07 |
jari |
458 |
text2D.getGeometry().setCapability(Geometry.ALLOW_INTERSECT); |
2 |
26 Feb 07 |
jari |
459 |
text2D.getGeometry().setCapability(GeometryArray.ALLOW_COUNT_READ); |
2 |
26 Feb 07 |
jari |
460 |
text2D.getGeometry().setCapability(GeometryArray.ALLOW_FORMAT_READ); |
2 |
26 Feb 07 |
jari |
461 |
text2D.getGeometry().setCapability(GeometryArray.ALLOW_COORDINATE_READ); |
2 |
26 Feb 07 |
jari |
462 |
return text2D; |
2 |
26 Feb 07 |
jari |
463 |
} |
2 |
26 Feb 07 |
jari |
464 |
|
2 |
26 Feb 07 |
jari |
465 |
private JPopupMenu createJPopupMenu(Listener listener) { |
2 |
26 Feb 07 |
jari |
466 |
JPopupMenu menu = new JPopupMenu(); |
2 |
26 Feb 07 |
jari |
467 |
JMenuItem menuItem; |
2 |
26 Feb 07 |
jari |
468 |
|
2 |
26 Feb 07 |
jari |
469 |
menuItem = new JCheckBoxMenuItem("Control Panel"); |
2 |
26 Feb 07 |
jari |
470 |
menuItem.setSelected(true); |
2 |
26 Feb 07 |
jari |
471 |
menuItem.setActionCommand(SHOW_CONTROLS_CMD); |
2 |
26 Feb 07 |
jari |
472 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
473 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
474 |
|
2 |
26 Feb 07 |
jari |
475 |
menu.addSeparator(); |
2 |
26 Feb 07 |
jari |
476 |
|
2 |
26 Feb 07 |
jari |
477 |
menuItem = new JMenuItem("Grid..."); |
2 |
26 Feb 07 |
jari |
478 |
menuItem.setActionCommand(GRID_SIZE_CMD); |
2 |
26 Feb 07 |
jari |
479 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
480 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
481 |
|
2 |
26 Feb 07 |
jari |
482 |
menuItem = new JCheckBoxMenuItem("Fill Polygon"); |
2 |
26 Feb 07 |
jari |
483 |
menuItem.setSelected(true); |
2 |
26 Feb 07 |
jari |
484 |
menuItem.setActionCommand(FILL_POLYGON_CMD); |
2 |
26 Feb 07 |
jari |
485 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
486 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
487 |
|
2 |
26 Feb 07 |
jari |
488 |
menu.addSeparator(); |
2 |
26 Feb 07 |
jari |
489 |
JMenu shape_menu = new JMenu("Element Shape"); |
2 |
26 Feb 07 |
jari |
490 |
ButtonGroup buttonGroup = new ButtonGroup(); |
2 |
26 Feb 07 |
jari |
491 |
|
2 |
26 Feb 07 |
jari |
492 |
menuItem = new JRadioButtonMenuItem("Point"); |
2 |
26 Feb 07 |
jari |
493 |
menuItem.setSelected(true); |
2 |
26 Feb 07 |
jari |
494 |
menuItem.setActionCommand(POINTS_SHAPE_CMD); |
2 |
26 Feb 07 |
jari |
495 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
496 |
buttonGroup.add(menuItem); |
2 |
26 Feb 07 |
jari |
497 |
shape_menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
498 |
|
2 |
26 Feb 07 |
jari |
499 |
menuItem = new JRadioButtonMenuItem("Cube"); |
2 |
26 Feb 07 |
jari |
500 |
menuItem.setActionCommand(CUBES_SHAPE_CMD); |
2 |
26 Feb 07 |
jari |
501 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
502 |
buttonGroup.add(menuItem); |
2 |
26 Feb 07 |
jari |
503 |
shape_menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
504 |
|
2 |
26 Feb 07 |
jari |
505 |
menuItem = new JRadioButtonMenuItem("Sphere"); |
2 |
26 Feb 07 |
jari |
506 |
menuItem.setActionCommand(SPHERES_SHAPE_CMD); |
2 |
26 Feb 07 |
jari |
507 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
508 |
buttonGroup.add(menuItem); |
2 |
26 Feb 07 |
jari |
509 |
shape_menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
510 |
|
2 |
26 Feb 07 |
jari |
511 |
menu.add(shape_menu); |
2 |
26 Feb 07 |
jari |
512 |
|
2 |
26 Feb 07 |
jari |
513 |
JMenu labels_menu = new JMenu("Labels"); |
2 |
26 Feb 07 |
jari |
514 |
menuItem = new JCheckBoxMenuItem("Hide"); |
2 |
26 Feb 07 |
jari |
515 |
menuItem.setSelected(true); |
2 |
26 Feb 07 |
jari |
516 |
menuItem.setActionCommand(HIDE_LABELS_CMD); |
2 |
26 Feb 07 |
jari |
517 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
518 |
labels_menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
519 |
|
2 |
26 Feb 07 |
jari |
520 |
menuItem = new JCheckBoxMenuItem("Billboard"); |
2 |
26 Feb 07 |
jari |
521 |
menuItem.setSelected(false); |
2 |
26 Feb 07 |
jari |
522 |
menuItem.setActionCommand(USE_BILLBOARD_CMD); |
2 |
26 Feb 07 |
jari |
523 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
524 |
labels_menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
525 |
|
2 |
26 Feb 07 |
jari |
526 |
menu.add(labels_menu); |
2 |
26 Feb 07 |
jari |
527 |
|
2 |
26 Feb 07 |
jari |
528 |
menu.addSeparator(); |
2 |
26 Feb 07 |
jari |
529 |
|
2 |
26 Feb 07 |
jari |
530 |
JMenu zoom_menu = new JMenu("Zoom"); |
2 |
26 Feb 07 |
jari |
531 |
|
2 |
26 Feb 07 |
jari |
532 |
menuItem = new JMenuItem("In"); |
2 |
26 Feb 07 |
jari |
533 |
menuItem.setActionCommand(ZOOM_IN_CMD); |
2 |
26 Feb 07 |
jari |
534 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
535 |
zoom_menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
536 |
|
2 |
26 Feb 07 |
jari |
537 |
menuItem = new JMenuItem("Undo"); |
2 |
26 Feb 07 |
jari |
538 |
menuItem.setActionCommand(UNDO_CMD); |
2 |
26 Feb 07 |
jari |
539 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
540 |
zoom_menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
541 |
|
2 |
26 Feb 07 |
jari |
542 |
menuItem = new JMenuItem("Show All"); |
2 |
26 Feb 07 |
jari |
543 |
menuItem.setActionCommand(SHOW_ALL_CMD); |
2 |
26 Feb 07 |
jari |
544 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
545 |
zoom_menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
546 |
|
2 |
26 Feb 07 |
jari |
547 |
menu.add(zoom_menu); |
2 |
26 Feb 07 |
jari |
548 |
|
2 |
26 Feb 07 |
jari |
549 |
menu.addSeparator(); |
2 |
26 Feb 07 |
jari |
550 |
|
2 |
26 Feb 07 |
jari |
551 |
JMenu links_menu = new JMenu("Links"); |
2 |
26 Feb 07 |
jari |
552 |
|
2 |
26 Feb 07 |
jari |
553 |
menuItem = new JCheckBoxMenuItem("Show"); |
2 |
26 Feb 07 |
jari |
554 |
menuItem.setSelected(false); |
2 |
26 Feb 07 |
jari |
555 |
menuItem.setActionCommand(SHOW_LINKS_CMD); |
2 |
26 Feb 07 |
jari |
556 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
557 |
links_menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
558 |
|
2 |
26 Feb 07 |
jari |
559 |
menuItem = new JMenuItem("Threshold..."); |
2 |
26 Feb 07 |
jari |
560 |
menuItem.setActionCommand(LINKS_THRESHOLD_CMD); |
2 |
26 Feb 07 |
jari |
561 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
562 |
links_menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
563 |
|
2 |
26 Feb 07 |
jari |
564 |
menuItem = new JMenuItem("Thickness..."); |
2 |
26 Feb 07 |
jari |
565 |
menuItem.setActionCommand(LINKS_WIDTH_CMD); |
2 |
26 Feb 07 |
jari |
566 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
567 |
links_menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
568 |
|
2 |
26 Feb 07 |
jari |
569 |
menu.add(links_menu); |
2 |
26 Feb 07 |
jari |
570 |
|
2 |
26 Feb 07 |
jari |
571 |
menu.addSeparator(); |
2 |
26 Feb 07 |
jari |
572 |
|
2 |
26 Feb 07 |
jari |
573 |
menuItem = new JMenuItem("Store cluster"); |
2 |
26 Feb 07 |
jari |
574 |
menuItem.setActionCommand(SET_CLUSTER_CMD); |
2 |
26 Feb 07 |
jari |
575 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
576 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
577 |
|
2 |
26 Feb 07 |
jari |
578 |
menuItem = new JMenuItem("Launch New Session"); |
2 |
26 Feb 07 |
jari |
579 |
menuItem.setActionCommand(LAUNCH_SESSION_CMD); |
2 |
26 Feb 07 |
jari |
580 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
581 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
582 |
|
2 |
26 Feb 07 |
jari |
583 |
menuItem = new JMenuItem("Deselect"); |
2 |
26 Feb 07 |
jari |
584 |
menuItem.setActionCommand(DESELECT_CMD); |
2 |
26 Feb 07 |
jari |
585 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
586 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
587 |
|
2 |
26 Feb 07 |
jari |
588 |
menuItem = new JMenuItem("Show Elements"); |
2 |
26 Feb 07 |
jari |
589 |
menuItem.setActionCommand(SHOW_ELEMENTS_CMD); |
2 |
26 Feb 07 |
jari |
590 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
591 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
592 |
|
2 |
26 Feb 07 |
jari |
593 |
menuItem = new JMenuItem("Drift..."); |
2 |
26 Feb 07 |
jari |
594 |
menuItem.setActionCommand(DRIFT_DIALOG_CMD); |
2 |
26 Feb 07 |
jari |
595 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
596 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
597 |
|
2 |
26 Feb 07 |
jari |
598 |
|
2 |
26 Feb 07 |
jari |
599 |
return menu; |
2 |
26 Feb 07 |
jari |
600 |
} |
2 |
26 Feb 07 |
jari |
601 |
|
2 |
26 Feb 07 |
jari |
602 |
/** |
2 |
26 Feb 07 |
jari |
* Returns a menu item by specified action command. |
2 |
26 Feb 07 |
jari |
604 |
*/ |
2 |
26 Feb 07 |
jari |
605 |
private JMenuItem getJMenuItem(JPopupMenu menu, String command) { |
2 |
26 Feb 07 |
jari |
606 |
Component[] components = menu.getComponents(); |
2 |
26 Feb 07 |
jari |
607 |
for (int i=0; i<components.length; i++) { |
2 |
26 Feb 07 |
jari |
608 |
if (components[i] instanceof JMenu) { |
2 |
26 Feb 07 |
jari |
609 |
JMenuItem item = getJMenuItem(((JMenu)components[i]).getPopupMenu(), command); |
2 |
26 Feb 07 |
jari |
610 |
if (item != null) |
2 |
26 Feb 07 |
jari |
611 |
return item; |
2 |
26 Feb 07 |
jari |
612 |
} |
2 |
26 Feb 07 |
jari |
613 |
if (components[i] instanceof JMenuItem) { |
2 |
26 Feb 07 |
jari |
614 |
if (((JMenuItem)components[i]).getActionCommand().equals(command)) |
2 |
26 Feb 07 |
jari |
615 |
return(JMenuItem)components[i]; |
2 |
26 Feb 07 |
jari |
616 |
} |
2 |
26 Feb 07 |
jari |
617 |
} |
2 |
26 Feb 07 |
jari |
618 |
return null; |
2 |
26 Feb 07 |
jari |
619 |
} |
2 |
26 Feb 07 |
jari |
620 |
|
2 |
26 Feb 07 |
jari |
621 |
/** |
2 |
26 Feb 07 |
jari |
* Sets a menu item state. |
2 |
26 Feb 07 |
jari |
623 |
*/ |
2 |
26 Feb 07 |
jari |
624 |
private void setEnableMenuItem(String command, boolean enable) { |
2 |
26 Feb 07 |
jari |
625 |
JMenuItem item = getJMenuItem(this.popup, command); |
2 |
26 Feb 07 |
jari |
626 |
if (item == null) { |
2 |
26 Feb 07 |
jari |
627 |
return; |
2 |
26 Feb 07 |
jari |
628 |
} |
2 |
26 Feb 07 |
jari |
629 |
item.setEnabled(enable); |
2 |
26 Feb 07 |
jari |
630 |
} |
2 |
26 Feb 07 |
jari |
631 |
|
2 |
26 Feb 07 |
jari |
632 |
private void onPicked(MouseEvent event, PickCanvas canvas) { |
2 |
26 Feb 07 |
jari |
633 |
canvas.setShapeLocation(event); |
2 |
26 Feb 07 |
jari |
634 |
PickResult pickResult = canvas.pickClosest(); |
2 |
26 Feb 07 |
jari |
635 |
if (pickResult != null && pickResult.getObject() == this.genesShape) { |
2 |
26 Feb 07 |
jari |
636 |
PickIntersection pi = pickResult.getClosestIntersection(canvas.getStartPosition()); |
2 |
26 Feb 07 |
jari |
637 |
int[] indices = pi.getPrimitiveVertexIndices(); |
2 |
26 Feb 07 |
jari |
638 |
final int index = this.genesShape.getShapeIndex(indices[0]); |
2 |
26 Feb 07 |
jari |
639 |
if (index < 0) |
2 |
26 Feb 07 |
jari |
640 |
return; |
2 |
26 Feb 07 |
jari |
641 |
SwingUtilities.invokeLater(new Runnable() { |
2 |
26 Feb 07 |
jari |
642 |
public void run() { |
2 |
26 Feb 07 |
jari |
643 |
onPicked(index); |
2 |
26 Feb 07 |
jari |
644 |
} |
2 |
26 Feb 07 |
jari |
645 |
}); |
2 |
26 Feb 07 |
jari |
646 |
} |
2 |
26 Feb 07 |
jari |
647 |
} |
2 |
26 Feb 07 |
jari |
648 |
|
2 |
26 Feb 07 |
jari |
649 |
private void onPicked(int shapeIndex) { |
2 |
26 Feb 07 |
jari |
650 |
if (isGenes) |
2 |
26 Feb 07 |
jari |
651 |
this.framework.displaySlideElementInfo(0, shapeIndex); |
2 |
26 Feb 07 |
jari |
652 |
else |
2 |
26 Feb 07 |
jari |
653 |
this.framework.displaySingleArrayViewer(shapeIndex); |
2 |
26 Feb 07 |
jari |
654 |
} |
2 |
26 Feb 07 |
jari |
655 |
|
2 |
26 Feb 07 |
jari |
656 |
private void onCtrlPicked(MouseEvent event, PickCanvas canvas) { |
2 |
26 Feb 07 |
jari |
657 |
canvas.setShapeLocation(event); |
2 |
26 Feb 07 |
jari |
658 |
PickResult pickResult = canvas.pickClosest(); |
2 |
26 Feb 07 |
jari |
659 |
if (pickResult != null) { |
2 |
26 Feb 07 |
jari |
660 |
if (pickResult.getObject() == this.genesShape) { |
2 |
26 Feb 07 |
jari |
661 |
PickIntersection pi = pickResult.getClosestIntersection(canvas.getStartPosition()); |
2 |
26 Feb 07 |
jari |
662 |
int[] indices = pi.getPrimitiveVertexIndices(); |
2 |
26 Feb 07 |
jari |
663 |
int index = this.genesShape.getShapeIndex(indices[0]); |
2 |
26 Feb 07 |
jari |
664 |
if (index < 0) { |
2 |
26 Feb 07 |
jari |
665 |
return; |
2 |
26 Feb 07 |
jari |
666 |
} |
2 |
26 Feb 07 |
jari |
667 |
float scale = Math.max(Math.abs(this.up_left_point.x-this.bottom_right_point.x), Math.abs(this.up_left_point.y-this.bottom_right_point.y)); |
2 |
26 Feb 07 |
jari |
668 |
float x = (locations[index][0]-this.up_left_point.x)/scale; |
2 |
26 Feb 07 |
jari |
669 |
float y = (locations[index][1]-this.up_left_point.y)/scale; |
2 |
26 Feb 07 |
jari |
670 |
this.driftInterpolator.drift(new Point3d(x, 0, y), new Vector3f(0, 0, 1)); |
2 |
26 Feb 07 |
jari |
671 |
} else if (pickResult.getObject() == this.landscape) { |
2 |
26 Feb 07 |
jari |
672 |
PickIntersection pi = pickResult.getClosestIntersection(canvas.getStartPosition()); |
2 |
26 Feb 07 |
jari |
673 |
Point3d point = pi.getPointCoordinates(); |
2 |
26 Feb 07 |
jari |
674 |
point.y += this.controlPanel.getSliderValue(); |
2 |
26 Feb 07 |
jari |
675 |
Vector3f normal = pi.getPointNormal(); |
2 |
26 Feb 07 |
jari |
676 |
this.driftInterpolator.drift(point, normal); |
2 |
26 Feb 07 |
jari |
677 |
} |
2 |
26 Feb 07 |
jari |
678 |
} |
2 |
26 Feb 07 |
jari |
679 |
} |
2 |
26 Feb 07 |
jari |
680 |
|
2 |
26 Feb 07 |
jari |
681 |
private void onSetCluster() { |
2 |
26 Feb 07 |
jari |
682 |
|
2 |
26 Feb 07 |
jari |
683 |
float scale = Math.max(Math.abs(this.up_left_point.x-this.bottom_right_point.x), Math.abs(this.up_left_point.y-this.bottom_right_point.y)); |
2 |
26 Feb 07 |
jari |
684 |
Point2f start = this.selectionShape.getStartCoords(); |
2 |
26 Feb 07 |
jari |
685 |
Point2f end = this.selectionShape.getEndCoords(); |
2 |
26 Feb 07 |
jari |
686 |
start.scale(scale); |
2 |
26 Feb 07 |
jari |
687 |
end.scale(scale); |
2 |
26 Feb 07 |
jari |
688 |
start.add(this.up_left_point); |
2 |
26 Feb 07 |
jari |
689 |
end.add(this.up_left_point); |
2 |
26 Feb 07 |
jari |
690 |
IntArray ids = new IntArray(); |
2 |
26 Feb 07 |
jari |
691 |
for (int i=0; i<this.locations.length; i++) { |
2 |
26 Feb 07 |
jari |
692 |
float x = this.locations[i][0]; |
2 |
26 Feb 07 |
jari |
693 |
float y = this.locations[i][1]; |
2 |
26 Feb 07 |
jari |
694 |
if (x>start.x && x<end.x && y>start.y && y<end.y) |
2 |
26 Feb 07 |
jari |
695 |
ids.add(i); |
2 |
26 Feb 07 |
jari |
696 |
} |
2 |
26 Feb 07 |
jari |
697 |
|
2 |
26 Feb 07 |
jari |
698 |
if (isGenes) { |
2 |
26 Feb 07 |
jari |
699 |
framework.storeSubCluster(ids.toArray(), this.experiment, Cluster.GENE_CLUSTER); |
2 |
26 Feb 07 |
jari |
700 |
this.genesShape.updateColors(this.data.getColorIndices(), this.data.getColors()); |
2 |
26 Feb 07 |
jari |
701 |
} else { |
2 |
26 Feb 07 |
jari |
702 |
framework.storeSubCluster(ids.toArray(), this.experiment, Cluster.EXPERIMENT_CLUSTER); |
2 |
26 Feb 07 |
jari |
703 |
this.genesShape.updateColors(this.data.getExperimentColorIndices(), this.data.getExperimentColors()); |
2 |
26 Feb 07 |
jari |
704 |
} |
2 |
26 Feb 07 |
jari |
705 |
this.selectionShape.clearSelection(); |
2 |
26 Feb 07 |
jari |
706 |
} |
2 |
26 Feb 07 |
jari |
707 |
|
2 |
26 Feb 07 |
jari |
708 |
|
2 |
26 Feb 07 |
jari |
709 |
private void onLaunchNewSession() { |
2 |
26 Feb 07 |
jari |
710 |
|
2 |
26 Feb 07 |
jari |
711 |
float scale = Math.max(Math.abs(this.up_left_point.x-this.bottom_right_point.x), Math.abs(this.up_left_point.y-this.bottom_right_point.y)); |
2 |
26 Feb 07 |
jari |
712 |
Point2f start = this.selectionShape.getStartCoords(); |
2 |
26 Feb 07 |
jari |
713 |
Point2f end = this.selectionShape.getEndCoords(); |
2 |
26 Feb 07 |
jari |
714 |
start.scale(scale); |
2 |
26 Feb 07 |
jari |
715 |
end.scale(scale); |
2 |
26 Feb 07 |
jari |
716 |
start.add(this.up_left_point); |
2 |
26 Feb 07 |
jari |
717 |
end.add(this.up_left_point); |
2 |
26 Feb 07 |
jari |
718 |
IntArray ids = new IntArray(); |
2 |
26 Feb 07 |
jari |
719 |
for (int i=0; i<this.locations.length; i++) { |
2 |
26 Feb 07 |
jari |
720 |
float x = this.locations[i][0]; |
2 |
26 Feb 07 |
jari |
721 |
float y = this.locations[i][1]; |
2 |
26 Feb 07 |
jari |
722 |
if (x>start.x && x<end.x && y>start.y && y<end.y) |
2 |
26 Feb 07 |
jari |
723 |
ids.add(i); |
2 |
26 Feb 07 |
jari |
724 |
} |
2 |
26 Feb 07 |
jari |
725 |
|
2 |
26 Feb 07 |
jari |
// int [] indices = ids.toArray(); |
2 |
26 Feb 07 |
jari |
// if(indices.length > 0) { |
2 |
26 Feb 07 |
jari |
728 |
if (isGenes) { |
2 |
26 Feb 07 |
jari |
729 |
framework.launchNewMAV(ids.toArray(), this.experiment, "Multiple Experiment Viewer - Cluster Viewer", Cluster.GENE_CLUSTER); |
2 |
26 Feb 07 |
jari |
730 |
|
2 |
26 Feb 07 |
jari |
731 |
} else { |
2 |
26 Feb 07 |
jari |
732 |
framework.launchNewMAV(ids.toArray(), this.experiment, "Multiple Experiment Viewer - Cluster Viewer", Cluster.EXPERIMENT_CLUSTER); |
2 |
26 Feb 07 |
jari |
733 |
|
2 |
26 Feb 07 |
jari |
734 |
} |
2 |
26 Feb 07 |
jari |
735 |
// } |
2 |
26 Feb 07 |
jari |
736 |
this.selectionShape.clearSelection(); |
2 |
26 Feb 07 |
jari |
737 |
|
2 |
26 Feb 07 |
jari |
738 |
} |
2 |
26 Feb 07 |
jari |
739 |
|
2 |
26 Feb 07 |
jari |
740 |
|
2 |
26 Feb 07 |
jari |
741 |
/** |
2 |
26 Feb 07 |
jari |
* Converts cluster indicies from the experiment to IData rows which could be different |
2 |
26 Feb 07 |
jari |
743 |
*/ |
2 |
26 Feb 07 |
jari |
744 |
private int [] getIDataRowIndices(int [] expIndices){ |
2 |
26 Feb 07 |
jari |
745 |
int [] dataIndices = new int[expIndices.length]; |
2 |
26 Feb 07 |
jari |
746 |
for(int i = 0; i < expIndices.length; i++){ |
2 |
26 Feb 07 |
jari |
747 |
dataIndices[i] = this.experiment.getGeneIndexMappedToData(i); |
2 |
26 Feb 07 |
jari |
748 |
} |
2 |
26 Feb 07 |
jari |
749 |
return dataIndices; |
2 |
26 Feb 07 |
jari |
750 |
} |
2 |
26 Feb 07 |
jari |
751 |
|
2 |
26 Feb 07 |
jari |
752 |
|
2 |
26 Feb 07 |
jari |
753 |
private void onFillPolygon() { |
2 |
26 Feb 07 |
jari |
754 |
JMenuItem item = getJMenuItem(this.popup, FILL_POLYGON_CMD); |
2 |
26 Feb 07 |
jari |
755 |
if (item.isSelected()) { |
2 |
26 Feb 07 |
jari |
756 |
this.landscape.setPoligonMode(PolygonAttributes.POLYGON_FILL); |
2 |
26 Feb 07 |
jari |
757 |
} else { |
2 |
26 Feb 07 |
jari |
758 |
this.landscape.setPoligonMode(PolygonAttributes.POLYGON_LINE); |
2 |
26 Feb 07 |
jari |
759 |
} |
2 |
26 Feb 07 |
jari |
760 |
} |
2 |
26 Feb 07 |
jari |
761 |
|
2 |
26 Feb 07 |
jari |
762 |
private void onShowControls() { |
2 |
26 Feb 07 |
jari |
763 |
JMenuItem item = getJMenuItem(this.popup, SHOW_CONTROLS_CMD); |
2 |
26 Feb 07 |
jari |
764 |
if (item.isSelected()) { |
2 |
26 Feb 07 |
jari |
765 |
this.controlPanel.setVisible(true); |
2 |
26 Feb 07 |
jari |
766 |
} else { |
2 |
26 Feb 07 |
jari |
767 |
this.controlPanel.setVisible(false); |
2 |
26 Feb 07 |
jari |
768 |
} |
2 |
26 Feb 07 |
jari |
769 |
} |
2 |
26 Feb 07 |
jari |
770 |
|
2 |
26 Feb 07 |
jari |
771 |
/** |
2 |
26 Feb 07 |
jari |
* Returns intersection point the view ray and x-z flat. |
2 |
26 Feb 07 |
jari |
773 |
*/ |
2 |
26 Feb 07 |
jari |
774 |
private Point3d getIntersectionPoint(MouseEvent event, PickCanvas canvas) { |
2 |
26 Feb 07 |
jari |
775 |
float tolerance = canvas.getTolerance(); |
2 |
26 Feb 07 |
jari |
776 |
canvas.setTolerance(2f); |
2 |
26 Feb 07 |
jari |
777 |
Point3d o3d = new Point3d(); |
2 |
26 Feb 07 |
jari |
778 |
Vector3d d3d = new Vector3d(); |
2 |
26 Feb 07 |
jari |
779 |
canvas.setShapeLocation(event); |
2 |
26 Feb 07 |
jari |
780 |
PickCone ps = (PickCone)canvas.getPickShape(); |
2 |
26 Feb 07 |
jari |
781 |
canvas.setTolerance(tolerance); // restore tolerance |
2 |
26 Feb 07 |
jari |
782 |
ps.getOrigin(o3d); |
2 |
26 Feb 07 |
jari |
783 |
ps.getDirection(d3d); |
2 |
26 Feb 07 |
jari |
784 |
double x0 = o3d.x - o3d.y*d3d.x/d3d.y; |
2 |
26 Feb 07 |
jari |
785 |
double z0 = o3d.z - o3d.y*d3d.z/d3d.y; |
2 |
26 Feb 07 |
jari |
786 |
if (o3d.y < 0 || x0 < 0 || z0 < 0 || x0 > 1 || z0 > 1) |
2 |
26 Feb 07 |
jari |
787 |
return null; |
2 |
26 Feb 07 |
jari |
788 |
return new Point3d(x0, 0, z0); |
2 |
26 Feb 07 |
jari |
789 |
} |
2 |
26 Feb 07 |
jari |
790 |
|
2 |
26 Feb 07 |
jari |
791 |
private void onStartSelection(MouseEvent event, PickCanvas canvas) { |
2 |
26 Feb 07 |
jari |
792 |
this.selectionShape.startSelection(getIntersectionPoint(event, canvas)); |
2 |
26 Feb 07 |
jari |
793 |
} |
2 |
26 Feb 07 |
jari |
794 |
|
2 |
26 Feb 07 |
jari |
795 |
private void onDragSelection(MouseEvent event, PickCanvas canvas) { |
2 |
26 Feb 07 |
jari |
796 |
this.selectionShape.dragSelection(getIntersectionPoint(event, canvas)); |
2 |
26 Feb 07 |
jari |
797 |
} |
2 |
26 Feb 07 |
jari |
798 |
|
2 |
26 Feb 07 |
jari |
799 |
private void onReleaseSelection() { |
2 |
26 Feb 07 |
jari |
800 |
} |
2 |
26 Feb 07 |
jari |
801 |
|
2 |
26 Feb 07 |
jari |
802 |
private void onDeselect() { |
2 |
26 Feb 07 |
jari |
803 |
this.selectionShape.clearSelection(); |
2 |
26 Feb 07 |
jari |
804 |
} |
2 |
26 Feb 07 |
jari |
805 |
|
2 |
26 Feb 07 |
jari |
806 |
private void onShowAll() { |
2 |
26 Feb 07 |
jari |
807 |
doZoom(new Point2f(0f, 0f), new Point2f(1f, 1f)); |
2 |
26 Feb 07 |
jari |
808 |
} |
2 |
26 Feb 07 |
jari |
809 |
|
2 |
26 Feb 07 |
jari |
810 |
private void onZoom() { |
2 |
26 Feb 07 |
jari |
811 |
this.undoManager.addEdit(new ZoomUndoable(this.up_left_point, this.bottom_right_point)); |
2 |
26 Feb 07 |
jari |
812 |
|
2 |
26 Feb 07 |
jari |
813 |
Point2f start = this.selectionShape.getStartCoords(); |
2 |
26 Feb 07 |
jari |
814 |
Point2f end = this.selectionShape.getEndCoords(); |
2 |
26 Feb 07 |
jari |
815 |
float minSide = Math.min(end.x-start.x, end.y-start.y); |
2 |
26 Feb 07 |
jari |
816 |
end.set(start.x+minSide, start.y+minSide); |
2 |
26 Feb 07 |
jari |
817 |
float scale = Math.max(Math.abs(this.up_left_point.x-this.bottom_right_point.x), Math.abs(this.up_left_point.y-this.bottom_right_point.y)); |
2 |
26 Feb 07 |
jari |
818 |
start.scale(scale); |
2 |
26 Feb 07 |
jari |
819 |
end.scale(scale); |
2 |
26 Feb 07 |
jari |
820 |
start.add(this.up_left_point); |
2 |
26 Feb 07 |
jari |
821 |
end.add(this.up_left_point); |
2 |
26 Feb 07 |
jari |
822 |
doZoom(start, end); |
2 |
26 Feb 07 |
jari |
823 |
} |
2 |
26 Feb 07 |
jari |
824 |
|
2 |
26 Feb 07 |
jari |
825 |
private void doZoom(Point2f start, Point2f end) { |
2 |
26 Feb 07 |
jari |
826 |
this.up_left_point.set(start); |
2 |
26 Feb 07 |
jari |
827 |
this.bottom_right_point.set(end); |
2 |
26 Feb 07 |
jari |
828 |
float scale = Math.max(Math.abs(this.up_left_point.x-this.bottom_right_point.x), Math.abs(this.up_left_point.y-this.bottom_right_point.y)); |
2 |
26 Feb 07 |
jari |
829 |
float[][] heights = DomainUtil.getHeights(this.locations, this.grid_size, this.sigma*scale, this.up_left_point, this.bottom_right_point); |
2 |
26 Feb 07 |
jari |
830 |
this.landscape.setHeights(heights); |
2 |
26 Feb 07 |
jari |
831 |
this.genesShape.setZoom(this.up_left_point, this.bottom_right_point); |
2 |
26 Feb 07 |
jari |
832 |
this.linksShape.setZoom(this.up_left_point, this.bottom_right_point); |
2 |
26 Feb 07 |
jari |
833 |
this.selectionShape.clearSelection(); |
2 |
26 Feb 07 |
jari |
834 |
updateLabelsGroup(); |
2 |
26 Feb 07 |
jari |
835 |
} |
2 |
26 Feb 07 |
jari |
836 |
|
2 |
26 Feb 07 |
jari |
837 |
private void onUndo() { |
2 |
26 Feb 07 |
jari |
838 |
this.undoManager.undo(); |
2 |
26 Feb 07 |
jari |
839 |
} |
2 |
26 Feb 07 |
jari |
840 |
|
2 |
26 Feb 07 |
jari |
841 |
private void onPointsShape() { |
2 |
26 Feb 07 |
jari |
842 |
this.pickBehavior.setTolerance(1f); |
2 |
26 Feb 07 |
jari |
843 |
this.genesShape.setType(GenesShape.POINTS); |
2 |
26 Feb 07 |
jari |
844 |
} |
2 |
26 Feb 07 |
jari |
845 |
|
2 |
26 Feb 07 |
jari |
846 |
private void onSpheresShape() { |
2 |
26 Feb 07 |
jari |
847 |
this.pickBehavior.setTolerance(0f); |
2 |
26 Feb 07 |
jari |
848 |
this.genesShape.setType(GenesShape.SPHERES); |
2 |
26 Feb 07 |
jari |
849 |
} |
2 |
26 Feb 07 |
jari |
850 |
|
2 |
26 Feb 07 |
jari |
851 |
private void onCubesShape() { |
2 |
26 Feb 07 |
jari |
852 |
this.pickBehavior.setTolerance(0f); |
2 |
26 Feb 07 |
jari |
853 |
this.genesShape.setType(GenesShape.CUBES); |
2 |
26 Feb 07 |
jari |
854 |
} |
2 |
26 Feb 07 |
jari |
855 |
|
2 |
26 Feb 07 |
jari |
856 |
private void onGridSize() { |
2 |
26 Feb 07 |
jari |
857 |
String value = (String)JOptionPane.showInputDialog(this, "Enter in a number of the grid cells per side.", "Input", JOptionPane.OK_CANCEL_OPTION, null, null, String.valueOf(this.grid_size-1)); |
2 |
26 Feb 07 |
jari |
858 |
if (value == null || value.equals("")) |
2 |
26 Feb 07 |
jari |
859 |
return; |
2 |
26 Feb 07 |
jari |
860 |
try { |
2 |
26 Feb 07 |
jari |
861 |
int size = Integer.parseInt(value); |
2 |
26 Feb 07 |
jari |
862 |
if (size <= 2 || size >= 500) { |
2 |
26 Feb 07 |
jari |
863 |
throw new NumberFormatException("value must be more than 2 and less than 500."); |
2 |
26 Feb 07 |
jari |
864 |
} |
2 |
26 Feb 07 |
jari |
865 |
this.grid_size = size+1; |
2 |
26 Feb 07 |
jari |
866 |
float scale = Math.max(Math.abs(this.up_left_point.x-this.bottom_right_point.x), Math.abs(this.up_left_point.y-this.bottom_right_point.y)); |
2 |
26 Feb 07 |
jari |
867 |
float[][] heights = DomainUtil.getHeights(this.locations, this.grid_size, this.sigma*scale, this.up_left_point, this.bottom_right_point); |
2 |
26 Feb 07 |
jari |
868 |
this.landscape.setHeights(heights); |
2 |
26 Feb 07 |
jari |
869 |
} catch (NumberFormatException e) { |
2 |
26 Feb 07 |
jari |
870 |
JOptionPane.showMessageDialog(this, "Illegal number: "+e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); |
2 |
26 Feb 07 |
jari |
871 |
} |
2 |
26 Feb 07 |
jari |
872 |
} |
2 |
26 Feb 07 |
jari |
873 |
|
2 |
26 Feb 07 |
jari |
874 |
private void onDriftDialog() { |
2 |
26 Feb 07 |
jari |
875 |
String value = (String)JOptionPane.showInputDialog(this, "Enter in a minimal distance.", "Input", JOptionPane.OK_CANCEL_OPTION, null, null, String.valueOf(this.driftInterpolator.getMinDistance())); |
2 |
26 Feb 07 |
jari |
876 |
if (value == null || value.equals("")) |
2 |
26 Feb 07 |
jari |
877 |
return; |
2 |
26 Feb 07 |
jari |
878 |
try { |
2 |
26 Feb 07 |
jari |
879 |
float distance = Float.parseFloat(value); |
2 |
26 Feb 07 |
jari |
880 |
if (distance <= 0f || distance >= 1f) |
2 |
26 Feb 07 |
jari |
881 |
throw new NumberFormatException("value must be more than 0 and less than 1."); |
2 |
26 Feb 07 |
jari |
882 |
this.driftInterpolator.setMinDistance(distance); |
2 |
26 Feb 07 |
jari |
883 |
} catch (NumberFormatException e) { |
2 |
26 Feb 07 |
jari |
884 |
JOptionPane.showMessageDialog(this, "Illegal number: "+e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); |
2 |
26 Feb 07 |
jari |
885 |
} |
2 |
26 Feb 07 |
jari |
886 |
} |
2 |
26 Feb 07 |
jari |
887 |
|
2 |
26 Feb 07 |
jari |
888 |
private void onShowLinks() { |
2 |
26 Feb 07 |
jari |
889 |
JMenuItem item = getJMenuItem(this.popup, SHOW_LINKS_CMD); |
2 |
26 Feb 07 |
jari |
890 |
if (item.isSelected()) |
2 |
26 Feb 07 |
jari |
891 |
this.linksShape.setVisible(true); |
2 |
26 Feb 07 |
jari |
892 |
else |
2 |
26 Feb 07 |
jari |
893 |
this.linksShape.setVisible(false); |
2 |
26 Feb 07 |
jari |
894 |
} |
2 |
26 Feb 07 |
jari |
895 |
|
2 |
26 Feb 07 |
jari |
896 |
private void onLinksThreshold() { |
2 |
26 Feb 07 |
jari |
897 |
String value = (String)JOptionPane.showInputDialog(this, "Enter in links threshold (between 0 and 1).", "Input", JOptionPane.OK_CANCEL_OPTION, null, null, String.valueOf(this.linksShape.getThreshold())); |
2 |
26 Feb 07 |
jari |
898 |
if (value == null || value.equals("")) |
2 |
26 Feb 07 |
jari |
899 |
return; |
2 |
26 Feb 07 |
jari |
900 |
try { |
2 |
26 Feb 07 |
jari |
901 |
float threshold = Float.parseFloat(value); |
2 |
26 Feb 07 |
jari |
902 |
if (threshold < 0f || threshold > 1f) |
2 |
26 Feb 07 |
jari |
903 |
throw new NumberFormatException("value must be between 0 and 1."); |
2 |
26 Feb 07 |
jari |
904 |
this.linksShape.setThreshold(threshold); |
2 |
26 Feb 07 |
jari |
905 |
} catch (NumberFormatException e) { |
2 |
26 Feb 07 |
jari |
906 |
JOptionPane.showMessageDialog(this, "Illegal number: "+e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); |
2 |
26 Feb 07 |
jari |
907 |
} |
2 |
26 Feb 07 |
jari |
908 |
} |
2 |
26 Feb 07 |
jari |
909 |
|
2 |
26 Feb 07 |
jari |
910 |
private void onLinksWidth() { |
2 |
26 Feb 07 |
jari |
911 |
String value = (String)JOptionPane.showInputDialog(this, "Enter in links thickness (between 1 and 10).", "Input", JOptionPane.OK_CANCEL_OPTION, null, null, String.valueOf(this.linksShape.getLinksWidth())); |
2 |
26 Feb 07 |
jari |
912 |
if (value == null || value.equals("")) |
2 |
26 Feb 07 |
jari |
913 |
return; |
2 |
26 Feb 07 |
jari |
914 |
try { |
2 |
26 Feb 07 |
jari |
915 |
float thickness = Float.parseFloat(value); |
2 |
26 Feb 07 |
jari |
916 |
if (thickness < 1f || thickness > 10f) |
2 |
26 Feb 07 |
jari |
917 |
throw new NumberFormatException("value must be between 1 and 10."); |
2 |
26 Feb 07 |
jari |
918 |
this.linksShape.setLinksWidth(thickness); |
2 |
26 Feb 07 |
jari |
919 |
} catch (NumberFormatException e) { |
2 |
26 Feb 07 |
jari |
920 |
JOptionPane.showMessageDialog(this, "Illegal number: "+e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); |
2 |
26 Feb 07 |
jari |
921 |
} |
2 |
26 Feb 07 |
jari |
922 |
} |
2 |
26 Feb 07 |
jari |
923 |
|
2 |
26 Feb 07 |
jari |
924 |
private void onHideLabels() { |
2 |
26 Feb 07 |
jari |
925 |
JMenuItem item = getJMenuItem(this.popup, HIDE_LABELS_CMD); |
2 |
26 Feb 07 |
jari |
926 |
if (!item.isSelected()) { |
2 |
26 Feb 07 |
jari |
927 |
this.labelsGroup = createLabelsGroup(this.labelIndex, this.locations, this.up_left_point, this.bottom_right_point); |
2 |
26 Feb 07 |
jari |
928 |
this.sceneGroup.addChild(this.labelsGroup); |
2 |
26 Feb 07 |
jari |
929 |
} else { |
2 |
26 Feb 07 |
jari |
930 |
this.labelsGroup.detach(); |
2 |
26 Feb 07 |
jari |
931 |
this.labelsGroup = null; |
2 |
26 Feb 07 |
jari |
932 |
} |
2 |
26 Feb 07 |
jari |
933 |
} |
2 |
26 Feb 07 |
jari |
934 |
|
2 |
26 Feb 07 |
jari |
935 |
private void onUseBillboard() { |
2 |
26 Feb 07 |
jari |
936 |
JMenuItem bill_item = getJMenuItem(this.popup, USE_BILLBOARD_CMD); |
2 |
26 Feb 07 |
jari |
937 |
this.isBillboard = bill_item.isSelected(); |
2 |
26 Feb 07 |
jari |
938 |
if (this.labelsGroup != null) { |
2 |
26 Feb 07 |
jari |
939 |
this.labelsGroup.detach(); |
2 |
26 Feb 07 |
jari |
940 |
} |
2 |
26 Feb 07 |
jari |
941 |
JMenuItem hide_item = getJMenuItem(this.popup, HIDE_LABELS_CMD); |
2 |
26 Feb 07 |
jari |
942 |
if (!hide_item.isSelected()) { |
2 |
26 Feb 07 |
jari |
943 |
this.labelsGroup = createLabelsGroup(this.labelIndex, this.locations, this.up_left_point, this.bottom_right_point); |
2 |
26 Feb 07 |
jari |
944 |
this.sceneGroup.addChild(this.labelsGroup); |
2 |
26 Feb 07 |
jari |
945 |
} |
2 |
26 Feb 07 |
jari |
946 |
} |
2 |
26 Feb 07 |
jari |
947 |
|
2 |
26 Feb 07 |
jari |
948 |
private void onShowElements() { |
2 |
26 Feb 07 |
jari |
949 |
float scale = Math.max(Math.abs(this.up_left_point.x-this.bottom_right_point.x), Math.abs(this.up_left_point.y-this.bottom_right_point.y)); |
2 |
26 Feb 07 |
jari |
950 |
Point2f start = this.selectionShape.getStartCoords(); |
2 |
26 Feb 07 |
jari |
951 |
Point2f end = this.selectionShape.getEndCoords(); |
2 |
26 Feb 07 |
jari |
952 |
start.scale(scale); |
2 |
26 Feb 07 |
jari |
953 |
end.scale(scale); |
2 |
26 Feb 07 |
jari |
954 |
start.add(this.up_left_point); |
2 |
26 Feb 07 |
jari |
955 |
end.add(this.up_left_point); |
2 |
26 Feb 07 |
jari |
956 |
|
2 |
26 Feb 07 |
jari |
957 |
|
2 |
26 Feb 07 |
jari |
958 |
|
2 |
26 Feb 07 |
jari |
959 |
ArrayList info = new ArrayList(); |
2 |
26 Feb 07 |
jari |
960 |
for (int i=0; i<locations.length; i++) { |
2 |
26 Feb 07 |
jari |
961 |
float x = locations[i][0]; |
2 |
26 Feb 07 |
jari |
962 |
float y = locations[i][1]; |
2 |
26 Feb 07 |
jari |
963 |
if (x >= start.x && x <= end.x && y >= start.y && y <= end.y) { |
2 |
26 Feb 07 |
jari |
964 |
info.add(new String("Element["+String.valueOf(i)+1+"]: "+(isGenes ? this.data.getElementAttribute(this.experiment.getGeneIndexMappedToData(i), labelIndex) : this.data.getSampleName(i) ))); |
2 |
26 Feb 07 |
jari |
965 |
} |
2 |
26 Feb 07 |
jari |
966 |
} |
2 |
26 Feb 07 |
jari |
967 |
Frame frame = JOptionPane.getFrameForComponent(getContentComponent()); |
2 |
26 Feb 07 |
jari |
968 |
String title = "Selected Elements"; |
2 |
26 Feb 07 |
jari |
969 |
ListDialog list = new ListDialog(frame, title, info.toArray(new String[info.size()])); |
2 |
26 Feb 07 |
jari |
970 |
list.showModal(); |
2 |
26 Feb 07 |
jari |
971 |
} |
2 |
26 Feb 07 |
jari |
972 |
|
2 |
26 Feb 07 |
jari |
973 |
private void updateLabelsGroup() { |
2 |
26 Feb 07 |
jari |
974 |
if (this.labelsGroup != null) { |
2 |
26 Feb 07 |
jari |
975 |
this.labelsGroup.detach(); |
2 |
26 Feb 07 |
jari |
976 |
this.labelsGroup = null; |
2 |
26 Feb 07 |
jari |
977 |
} |
2 |
26 Feb 07 |
jari |
978 |
JMenuItem item = getJMenuItem(this.popup, HIDE_LABELS_CMD); |
2 |
26 Feb 07 |
jari |
979 |
if (!item.isSelected()) { |
2 |
26 Feb 07 |
jari |
980 |
this.labelsGroup = createLabelsGroup(this.labelIndex, this.locations, this.up_left_point, this.bottom_right_point); |
2 |
26 Feb 07 |
jari |
981 |
this.sceneGroup.addChild(this.labelsGroup); |
2 |
26 Feb 07 |
jari |
982 |
} |
2 |
26 Feb 07 |
jari |
983 |
} |
2 |
26 Feb 07 |
jari |
984 |
|
2 |
26 Feb 07 |
jari |
985 |
private void showElementTip(int x, int y) { |
2 |
26 Feb 07 |
jari |
986 |
if (isGenes && this.labelIndex < 0) |
2 |
26 Feb 07 |
jari |
987 |
return; |
2 |
26 Feb 07 |
jari |
988 |
PickCanvas canvas = new PickCanvas(this.onScreenCanvas, this.sceneGroup); |
2 |
26 Feb 07 |
jari |
989 |
canvas.setTolerance(this.pickBehavior.getTolerance()); |
2 |
26 Feb 07 |
jari |
990 |
canvas.setShapeLocation(x, y); |
2 |
26 Feb 07 |
jari |
991 |
PickResult[] pickResult = canvas.pickAllSorted(); |
2 |
26 Feb 07 |
jari |
992 |
if (pickResult == null) |
2 |
26 Feb 07 |
jari |
993 |
return; |
2 |
26 Feb 07 |
jari |
994 |
for (int i=0; i<pickResult.length; i++) |
2 |
26 Feb 07 |
jari |
995 |
if (pickResult[i].getObject() == this.genesShape) { |
2 |
26 Feb 07 |
jari |
996 |
PickIntersection pi = pickResult[i].getClosestIntersection(canvas.getStartPosition()); |
2 |
26 Feb 07 |
jari |
997 |
if (pi == null) |
2 |
26 Feb 07 |
jari |
998 |
return; |
2 |
26 Feb 07 |
jari |
999 |
int[] indices = pi.getPrimitiveVertexIndices(); |
2 |
26 Feb 07 |
jari |
1000 |
final int index = this.genesShape.getShapeIndex(indices[0]); |
2 |
26 Feb 07 |
jari |
1001 |
if (index < 0) |
2 |
26 Feb 07 |
jari |
1002 |
return; |
2 |
26 Feb 07 |
jari |
1003 |
String text = this.isGenes ? this.data.getElementAttribute(index, this.labelIndex) : this.data.getSampleName(index); |
2 |
26 Feb 07 |
jari |
1004 |
|
2 |
26 Feb 07 |
jari |
1005 |
JToolTip tooltip = new JToolTip(); |
2 |
26 Feb 07 |
jari |
1006 |
tooltip.setTipText(text); |
2 |
26 Feb 07 |
jari |
1007 |
Dimension size = tooltip.getPreferredSize(); |
2 |
26 Feb 07 |
jari |
1008 |
|
2 |
26 Feb 07 |
jari |
1009 |
Point screenLocation = this.onScreenCanvas.getLocationOnScreen(); |
2 |
26 Feb 07 |
jari |
1010 |
|
2 |
26 Feb 07 |
jari |
1011 |
this.tipWindow.getContentPane().add(tooltip, BorderLayout.CENTER); |
2 |
26 Feb 07 |
jari |
1012 |
this.tipWindow.setLocation((int)(screenLocation.x+x), (int)(screenLocation.y+y+20)); |
2 |
26 Feb 07 |
jari |
1013 |
this.tipWindow.pack(); |
2 |
26 Feb 07 |
jari |
1014 |
this.tipWindow.setVisible(true); |
2 |
26 Feb 07 |
jari |
1015 |
return; |
2 |
26 Feb 07 |
jari |
1016 |
} |
2 |
26 Feb 07 |
jari |
1017 |
} |
2 |
26 Feb 07 |
jari |
1018 |
|
2 |
26 Feb 07 |
jari |
1019 |
private void hideElementTip() { |
2 |
26 Feb 07 |
jari |
1020 |
this.tipWindow.getContentPane().removeAll(); |
2 |
26 Feb 07 |
jari |
1021 |
this.tipWindow.setVisible(false); |
2 |
26 Feb 07 |
jari |
1022 |
} |
2 |
26 Feb 07 |
jari |
1023 |
|
2 |
26 Feb 07 |
jari |
/** Returns a component to be inserted into the scroll pane row header |
2 |
26 Feb 07 |
jari |
1025 |
*/ |
2 |
26 Feb 07 |
jari |
1026 |
public JComponent getRowHeaderComponent() { |
2 |
26 Feb 07 |
jari |
1027 |
return null; |
2 |
26 Feb 07 |
jari |
1028 |
} |
2 |
26 Feb 07 |
jari |
1029 |
|
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 |
1032 |
*/ |
2 |
26 Feb 07 |
jari |
1033 |
public JComponent getCornerComponent(int cornerIndex) { |
2 |
26 Feb 07 |
jari |
1034 |
return null; |
2 |
26 Feb 07 |
jari |
1035 |
} |
2 |
26 Feb 07 |
jari |
1036 |
|
2 |
26 Feb 07 |
jari |
/** Returns the viewer's clusters or null |
2 |
26 Feb 07 |
jari |
1038 |
*/ |
2 |
26 Feb 07 |
jari |
1039 |
public int[][] getClusters() { |
2 |
26 Feb 07 |
jari |
1040 |
return this.clusters; |
2 |
26 Feb 07 |
jari |
1041 |
} |
2 |
26 Feb 07 |
jari |
1042 |
|
2 |
26 Feb 07 |
jari |
/** Returns the viewer's experiment or null |
2 |
26 Feb 07 |
jari |
1044 |
*/ |
2 |
26 Feb 07 |
jari |
1045 |
public Experiment getExperiment() { |
2 |
26 Feb 07 |
jari |
1046 |
return this.experiment; |
2 |
26 Feb 07 |
jari |
1047 |
} |
2 |
26 Feb 07 |
jari |
1048 |
|
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 |
1051 |
*/ |
2 |
26 Feb 07 |
jari |
1052 |
public int getViewerType() { |
2 |
26 Feb 07 |
jari |
1053 |
return -1; |
2 |
26 Feb 07 |
jari |
1054 |
} |
2 |
26 Feb 07 |
jari |
1055 |
|
2 |
26 Feb 07 |
jari |
1056 |
/** |
2 |
26 Feb 07 |
jari |
* The listener to listen to menu, mouse and keyboard events. |
2 |
26 Feb 07 |
jari |
1058 |
*/ |
2 |
26 Feb 07 |
jari |
1059 |
private class Listener extends MouseAdapter implements ActionListener, MouseMotionListener, KeyListener, PickListener { |
2 |
26 Feb 07 |
jari |
1060 |
public void actionPerformed(ActionEvent event) { |
2 |
26 Feb 07 |
jari |
1061 |
if (event.getSource() == this.timer) { |
2 |
26 Feb 07 |
jari |
1062 |
onTimerEvent(); |
2 |
26 Feb 07 |
jari |
1063 |
return; |
2 |
26 Feb 07 |
jari |
1064 |
} |
2 |
26 Feb 07 |
jari |
1065 |
String command = event.getActionCommand(); |
2 |
26 Feb 07 |
jari |
1066 |
if (command.equals(SET_CLUSTER_CMD)) { |
2 |
26 Feb 07 |
jari |
1067 |
TerrainViewer.this.onSetCluster(); |
2 |
26 Feb 07 |
jari |
1068 |
} else if (command.equals(SHOW_ELEMENTS_CMD)) { |
2 |
26 Feb 07 |
jari |
1069 |
TerrainViewer.this.onShowElements(); |
2 |
26 Feb 07 |
jari |
1070 |
} else if (command.equals(FILL_POLYGON_CMD)) { |
2 |
26 Feb 07 |
jari |
1071 |
TerrainViewer.this.onFillPolygon(); |
2 |
26 Feb 07 |
jari |
1072 |
} else if (command.equals(SHOW_CONTROLS_CMD)) { |
2 |
26 Feb 07 |
jari |
1073 |
TerrainViewer.this.onShowControls(); |
2 |
26 Feb 07 |
jari |
1074 |
} else if (command.equals(ZOOM_IN_CMD)) { |
2 |
26 Feb 07 |
jari |
1075 |
TerrainViewer.this.onZoom(); |
2 |
26 Feb 07 |
jari |
1076 |
} else if (command.equals(UNDO_CMD)) { |
2 |
26 Feb 07 |
jari |
1077 |
TerrainViewer.this.onUndo(); |
2 |
26 Feb 07 |
jari |
1078 |
} else if (command.equals(DESELECT_CMD)) { |
2 |
26 Feb 07 |
jari |
1079 |
TerrainViewer.this.onDeselect(); |
2 |
26 Feb 07 |
jari |
1080 |
} else if (command.equals(SHOW_ALL_CMD)) { |
2 |
26 Feb 07 |
jari |
1081 |
TerrainViewer.this.onShowAll(); |
2 |
26 Feb 07 |
jari |
1082 |
} else if (command.equals(POINTS_SHAPE_CMD)) { |
2 |
26 Feb 07 |
jari |
1083 |
TerrainViewer.this.onPointsShape(); |
2 |
26 Feb 07 |
jari |
1084 |
} else if (command.equals(SPHERES_SHAPE_CMD)) { |
2 |
26 Feb 07 |
jari |
1085 |
TerrainViewer.this.onSpheresShape(); |
2 |
26 Feb 07 |
jari |
1086 |
} else if (command.equals(CUBES_SHAPE_CMD)) { |
2 |
26 Feb 07 |
jari |
1087 |
TerrainViewer.this.onCubesShape(); |
2 |
26 Feb 07 |
jari |
1088 |
} else if (command.equals(GRID_SIZE_CMD)) { |
2 |
26 Feb 07 |
jari |
1089 |
TerrainViewer.this.onGridSize(); |
2 |
26 Feb 07 |
jari |
1090 |
} else if (command.equals(DRIFT_DIALOG_CMD)) { |
2 |
26 Feb 07 |
jari |
1091 |
TerrainViewer.this.onDriftDialog(); |
2 |
26 Feb 07 |
jari |
1092 |
} else if (command.equals(SHOW_LINKS_CMD)) { |
2 |
26 Feb 07 |
jari |
1093 |
TerrainViewer.this.onShowLinks(); |
2 |
26 Feb 07 |
jari |
1094 |
} else if (command.equals(HIDE_LABELS_CMD)) { |
2 |
26 Feb 07 |
jari |
1095 |
TerrainViewer.this.onHideLabels(); |
2 |
26 Feb 07 |
jari |
1096 |
} else if (command.equals(USE_BILLBOARD_CMD)) { |
2 |
26 Feb 07 |
jari |
1097 |
TerrainViewer.this.onUseBillboard(); |
2 |
26 Feb 07 |
jari |
1098 |
} else if (command.equals(LINKS_THRESHOLD_CMD)) { |
2 |
26 Feb 07 |
jari |
1099 |
TerrainViewer.this.onLinksThreshold(); |
2 |
26 Feb 07 |
jari |
1100 |
} else if (command.equals(LINKS_WIDTH_CMD)) { |
2 |
26 Feb 07 |
jari |
1101 |
TerrainViewer.this.onLinksWidth(); |
2 |
26 Feb 07 |
jari |
1102 |
} else if (command.equals(LAUNCH_SESSION_CMD)) { |
2 |
26 Feb 07 |
jari |
1103 |
TerrainViewer.this.onLaunchNewSession(); |
2 |
26 Feb 07 |
jari |
1104 |
} |
2 |
26 Feb 07 |
jari |
1105 |
} |
2 |
26 Feb 07 |
jari |
1106 |
|
2 |
26 Feb 07 |
jari |
1107 |
public void mouseReleased(MouseEvent e) { |
2 |
26 Feb 07 |
jari |
1108 |
if (e.isPopupTrigger()) { |
2 |
26 Feb 07 |
jari |
1109 |
setEnableMenuItem(ZOOM_IN_CMD, TerrainViewer.this.selectionShape.hasSelection()); |
2 |
26 Feb 07 |
jari |
1110 |
setEnableMenuItem(DESELECT_CMD, TerrainViewer.this.selectionShape.hasSelection()); |
2 |
26 Feb 07 |
jari |
1111 |
setEnableMenuItem(SET_CLUSTER_CMD, TerrainViewer.this.selectionShape.hasSelection()); |
2 |
26 Feb 07 |
jari |
1112 |
setEnableMenuItem(SHOW_ELEMENTS_CMD, TerrainViewer.this.selectionShape.hasSelection()); |
2 |
26 Feb 07 |
jari |
1113 |
setEnableMenuItem(UNDO_CMD, TerrainViewer.this.undoManager.canUndo()); |
2 |
26 Feb 07 |
jari |
1114 |
TerrainViewer.this.popup.show(e.getComponent(), e.getX(), e.getY()); |
2 |
26 Feb 07 |
jari |
1115 |
} |
2 |
26 Feb 07 |
jari |
1116 |
} |
2 |
26 Feb 07 |
jari |
1117 |
|
2 |
26 Feb 07 |
jari |
1118 |
public void onMousePressed(MouseEvent event, PickCanvas canvas) { |
2 |
26 Feb 07 |
jari |
1119 |
TerrainViewer.this.hideElementTip(); |
2 |
26 Feb 07 |
jari |
1120 |
if (event.isMetaDown() || event.isAltDown()) |
2 |
26 Feb 07 |
jari |
1121 |
return; |
2 |
26 Feb 07 |
jari |
1122 |
if (event.isShiftDown()) { |
2 |
26 Feb 07 |
jari |
// selection |
2 |
26 Feb 07 |
jari |
1124 |
TerrainViewer.this.onStartSelection(event, canvas); |
2 |
26 Feb 07 |
jari |
1125 |
} else { |
2 |
26 Feb 07 |
jari |
1126 |
if (event.isControlDown()) |
2 |
26 Feb 07 |
jari |
1127 |
TerrainViewer.this.onCtrlPicked(event, canvas); |
2 |
26 Feb 07 |
jari |
1128 |
else |
2 |
26 Feb 07 |
jari |
1129 |
TerrainViewer.this.onPicked(event, canvas); |
2 |
26 Feb 07 |
jari |
1130 |
} |
2 |
26 Feb 07 |
jari |
1131 |
} |
2 |
26 Feb 07 |
jari |
1132 |
|
2 |
26 Feb 07 |
jari |
1133 |
public void onMouseDragged(MouseEvent event, PickCanvas canvas) { |
2 |
26 Feb 07 |
jari |
1134 |
if (event.isShiftDown()) |
2 |
26 Feb 07 |
jari |
1135 |
TerrainViewer.this.onDragSelection(event, canvas); |
2 |
26 Feb 07 |
jari |
1136 |
} |
2 |
26 Feb 07 |
jari |
1137 |
|
2 |
26 Feb 07 |
jari |
1138 |
public void onMouseReleased(MouseEvent event, PickCanvas canvas) { |
2 |
26 Feb 07 |
jari |
1139 |
TerrainViewer.this.onReleaseSelection(); |
2 |
26 Feb 07 |
jari |
1140 |
} |
2 |
26 Feb 07 |
jari |
1141 |
|
2 |
26 Feb 07 |
jari |
1142 |
private PickResult[] getPickSortedResult(MouseEvent event, PickCanvas canvas) { |
2 |
26 Feb 07 |
jari |
1143 |
canvas.setShapeLocation(event); |
2 |
26 Feb 07 |
jari |
1144 |
return canvas.pickAllSorted(); |
2 |
26 Feb 07 |
jari |
1145 |
} |
2 |
26 Feb 07 |
jari |
1146 |
|
2 |
26 Feb 07 |
jari |
1147 |
private PickResult[] getPickAllResult(MouseEvent event, PickCanvas canvas) { |
2 |
26 Feb 07 |
jari |
1148 |
canvas.setShapeLocation(event); |
2 |
26 Feb 07 |
jari |
1149 |
return canvas.pickAll(); |
2 |
26 Feb 07 |
jari |
1150 |
} |
2 |
26 Feb 07 |
jari |
1151 |
|
2 |
26 Feb 07 |
jari |
1152 |
public void keyTyped(KeyEvent e) {} |
2 |
26 Feb 07 |
jari |
1153 |
public void keyPressed(KeyEvent e) { |
2 |
26 Feb 07 |
jari |
// awt canvas events have to be used because of J3D bug |
2 |
26 Feb 07 |
jari |
1155 |
TerrainViewer.this.keyMotionBehavior.onKeyEvent(e); |
2 |
26 Feb 07 |
jari |
1156 |
} |
2 |
26 Feb 07 |
jari |
1157 |
public void keyReleased(KeyEvent e) {} |
2 |
26 Feb 07 |
jari |
1158 |
|
2 |
26 Feb 07 |
jari |
// tips monitoring |
2 |
26 Feb 07 |
jari |
1160 |
private Timer timer; |
2 |
26 Feb 07 |
jari |
1161 |
private int x = 0, y = 0; |
2 |
26 Feb 07 |
jari |
1162 |
|
2 |
26 Feb 07 |
jari |
1163 |
public Listener() { |
2 |
26 Feb 07 |
jari |
1164 |
this.timer = new Timer(1000, this); |
2 |
26 Feb 07 |
jari |
1165 |
this.timer.setRepeats(false); |
2 |
26 Feb 07 |
jari |
1166 |
} |
2 |
26 Feb 07 |
jari |
1167 |
|
2 |
26 Feb 07 |
jari |
1168 |
public void mouseEntered(MouseEvent e) { |
2 |
26 Feb 07 |
jari |
1169 |
this.timer.start(); |
2 |
26 Feb 07 |
jari |
1170 |
} |
2 |
26 Feb 07 |
jari |
1171 |
|
2 |
26 Feb 07 |
jari |
1172 |
public void mouseExited(MouseEvent e) { |
2 |
26 Feb 07 |
jari |
1173 |
this.timer.stop(); |
2 |
26 Feb 07 |
jari |
1174 |
} |
2 |
26 Feb 07 |
jari |
1175 |
|
2 |
26 Feb 07 |
jari |
1176 |
public void mouseMoved(MouseEvent e) { |
2 |
26 Feb 07 |
jari |
1177 |
this.x = e.getX(); |
2 |
26 Feb 07 |
jari |
1178 |
this.y = e.getY(); |
2 |
26 Feb 07 |
jari |
1179 |
TerrainViewer.this.hideElementTip(); |
2 |
26 Feb 07 |
jari |
1180 |
this.timer.restart(); |
2 |
26 Feb 07 |
jari |
1181 |
} |
2 |
26 Feb 07 |
jari |
1182 |
|
2 |
26 Feb 07 |
jari |
1183 |
private void onTimerEvent() { |
2 |
26 Feb 07 |
jari |
1184 |
TerrainViewer.this.showElementTip(this.x, this.y); |
2 |
26 Feb 07 |
jari |
1185 |
} |
2 |
26 Feb 07 |
jari |
1186 |
|
2 |
26 Feb 07 |
jari |
1187 |
public void mouseDragged(MouseEvent e) { |
2 |
26 Feb 07 |
jari |
1188 |
} |
2 |
26 Feb 07 |
jari |
1189 |
} |
2 |
26 Feb 07 |
jari |
1190 |
|
2 |
26 Feb 07 |
jari |
// Undo commands |
2 |
26 Feb 07 |
jari |
1192 |
private class ZoomUndoable extends AbstractUndoableEdit { |
2 |
26 Feb 07 |
jari |
1193 |
|
2 |
26 Feb 07 |
jari |
1194 |
private Point2f start; |
2 |
26 Feb 07 |
jari |
1195 |
private Point2f end; |
2 |
26 Feb 07 |
jari |
1196 |
|
2 |
26 Feb 07 |
jari |
1197 |
public ZoomUndoable(Point2f start, Point2f end) { |
2 |
26 Feb 07 |
jari |
1198 |
this.start = new Point2f(start); |
2 |
26 Feb 07 |
jari |
1199 |
this.end = new Point2f(end); |
2 |
26 Feb 07 |
jari |
1200 |
} |
2 |
26 Feb 07 |
jari |
1201 |
|
2 |
26 Feb 07 |
jari |
1202 |
public void undo() throws CannotUndoException { |
2 |
26 Feb 07 |
jari |
1203 |
TerrainViewer.this.doZoom(this.start, this.end); |
2 |
26 Feb 07 |
jari |
1204 |
} |
2 |
26 Feb 07 |
jari |
1205 |
|
2 |
26 Feb 07 |
jari |
1206 |
public void redo() throws CannotRedoException { |
2 |
26 Feb 07 |
jari |
1207 |
} |
2 |
26 Feb 07 |
jari |
1208 |
|
2 |
26 Feb 07 |
jari |
1209 |
public String getPresentationName() { |
2 |
26 Feb 07 |
jari |
1210 |
return "Zoom"; |
2 |
26 Feb 07 |
jari |
1211 |
} |
2 |
26 Feb 07 |
jari |
1212 |
} |
2 |
26 Feb 07 |
jari |
1213 |
|
2 |
26 Feb 07 |
jari |
1214 |
|
2 |
26 Feb 07 |
jari |
1215 |
|
2 |
26 Feb 07 |
jari |
/* (non-Javadoc) |
2 |
26 Feb 07 |
jari |
* @see org.tigr.microarray.mev.cluster.gui.IViewer#getExperimentID() |
2 |
26 Feb 07 |
jari |
1218 |
*/ |
2 |
26 Feb 07 |
jari |
1219 |
public int getExperimentID() { |
2 |
26 Feb 07 |
jari |
1220 |
return this.exptID; |
2 |
26 Feb 07 |
jari |
1221 |
} |
2 |
26 Feb 07 |
jari |
1222 |
|
2 |
26 Feb 07 |
jari |
/* (non-Javadoc) |
2 |
26 Feb 07 |
jari |
* @see org.tigr.microarray.mev.cluster.gui.IViewer#setExperimentID(int) |
2 |
26 Feb 07 |
jari |
1225 |
*/ |
2 |
26 Feb 07 |
jari |
1226 |
public void setExperimentID(int id) { |
2 |
26 Feb 07 |
jari |
1227 |
this.exptID = id; |
2 |
26 Feb 07 |
jari |
1228 |
} |
2 |
26 Feb 07 |
jari |
1229 |
|
2 |
26 Feb 07 |
jari |
1230 |
} |