00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 package com.meapsoft.visualizer;
00030
00031 import java.awt.Color;
00032 import java.awt.Graphics;
00033 import java.awt.Point;
00034 import java.awt.Rectangle;
00035 import java.awt.event.ActionEvent;
00036 import java.awt.image.BufferedImage;
00037 import java.util.Vector;
00038
00039 import javax.swing.BoxLayout;
00040 import javax.swing.JCheckBox;
00041 import javax.swing.JPanel;
00042
00043 import com.meapsoft.DSP;
00044 import com.meapsoft.EDLFile;
00045 import com.meapsoft.FeatFile;
00046
00052 public class SegmentOrderRenderer extends Renderer
00053 {
00054 JCheckBox thickLines;
00055 JCheckBox multiLines;
00056
00057 boolean thick = false;
00058 boolean multi = false;
00059
00060 int currHeight = 0;
00061 int currWidth = 0;
00062 double currXMulti = 0.0;
00063
00064
00065 double screenPercentage = .25;
00066
00067 public SegmentOrderRenderer(FeatFile featFile, EDLFile eDLFile)
00068 {
00069 super(featFile, eDLFile, "SegmentOrderMapping");
00070 }
00071
00072 public SegmentOrderRenderer(Renderer r)
00073 {
00074 super(r);
00075
00076
00077
00078 updateColorMultipliers();
00079 }
00080
00081 public void draw(BufferedImage image, int width, int height)
00082 {
00083 int numChunks = events.size();
00084
00085
00086 ChunkVisInfo lastChunk = (ChunkVisInfo) events.elementAt(numChunks - 1);
00087 double xMulti = width/(lastStartTime + lastChunk.length);
00088
00089 double scaledHeight = height * screenPercentage;
00090
00091 Graphics graphics = image.getGraphics();
00092 graphics.setColor(Color.white);
00093 graphics.fillRect(0,0,width,height);
00094
00095 int blipHeight = (int)(scaledHeight/numFeatures);
00096
00097 for (int i = 0; i < numChunks; i++)
00098 {
00099 ChunkVisInfo cVI = (ChunkVisInfo) events.elementAt(i);
00100
00101 int index = 0;
00102 for (int j = 0; j < numFeatures; j++)
00103 {
00104 int ndim = elementsPerFeature[j];
00105
00106
00107
00108
00109 for (int k = ndim - 1; k >= 0; k--)
00110 {
00111 int[] featNum = {index};
00112 double featureValue = cVI.getFeatures(featNum)[0];
00113
00114 featureValue -= lowestFeatureValue[j];
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127 double colorIndex = featureValue * colorMultipliers[j];
00128
00129
00130
00131 if (cVI.selected)
00132 {
00133 graphics.setColor(colormap.table[(int)colorIndex]);
00134 }
00135 else
00136 {
00137 Color c = colormap.table[(int)colorIndex].darker().darker().darker();
00138 graphics.setColor(c);
00139 }
00140 int x1 = (int)(cVI.startTime * xMulti);
00141 int blipWidth = (int)((cVI.startTime + cVI.length) * xMulti);
00142 blipWidth = blipWidth - x1;
00143 int y = (int)(j * blipHeight + k*blipHeight/ndim);
00144
00145
00146 int miniBlipHeight = (blipHeight+ndim/2)/ndim;
00147 if (miniBlipHeight < 1)
00148 miniBlipHeight = 1;
00149
00150
00151
00152 graphics.fillRect(x1, y, blipWidth, miniBlipHeight);
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165 if (eDLFile != null)
00166 {
00167 if (cVI.dstTime != -1.0)
00168 {
00169 int x2 = (int)(cVI.dstTime * xMulti);
00170
00171
00172
00173
00174 int y2 = height - j*blipHeight - (ndim-k)*blipHeight/ndim;
00175
00176 graphics.fillRect(x2, y2, blipWidth + 1, miniBlipHeight);
00177
00178
00179
00180
00181
00182 cVI.xEDL = x2;
00183 cVI.yEDL = y2;
00184 }
00185 }
00186
00187 index++;
00188
00189 cVI.xFeat = x1;
00190 cVI.yFeat = y;
00191 cVI.width = blipWidth;
00192 cVI.height = blipHeight;
00193 }
00194 }
00195 }
00196
00197
00198
00199
00200 if (eDLFile != null)
00201 {
00202 for (int i = 0; i < numChunks; i++)
00203 {
00204 ChunkVisInfo cVI = (ChunkVisInfo) events.elementAt(i);
00205
00206 int index = 0;
00207
00208 for (int j = 0; j < numFeatures; j++)
00209 {
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235 int ndim = elementsPerFeature[j];
00236
00237 int[] featNum = DSP.irange(index, index+ndim-1);
00238 double[] features = cVI.getFeatures(featNum);
00239 features = DSP.minus(features, lowestFeatureValue[j]);
00240 double featureValue = DSP.dot(features, features)/Math.sqrt(ndim);
00241
00242 featureValue = features[ndim-1];
00243
00244
00245
00246
00247
00248
00249 double colorIndex = featureValue * colorMultipliers[j];
00250
00251 graphics.setColor(colormap.table[(int)colorIndex]);
00252
00253 int x1 = (int)(cVI.startTime * xMulti);
00254 int blipWidth = (int)((cVI.startTime + cVI.length) * xMulti);
00255 blipWidth = blipWidth - x1;
00256 int y = (int)(j * blipHeight);
00257
00258 if (cVI.dstTime != -1.0)
00259 {
00260 int x2 = (int)(cVI.dstTime * xMulti);
00261
00262
00263 if (cVI.selected)
00264 {
00265
00266 if (multi)
00267 {
00268 graphics.drawLine(x1 + blipWidth/2, y + blipHeight,
00269 x2 + blipWidth/2, (height - y) - blipHeight);
00270 if (thick)
00271 graphics.drawLine((x1 + blipWidth/2)+1, y + blipHeight,
00272 (x2 + blipWidth/2)+1, (height - y) - blipHeight);
00273 }
00274 else
00275 {
00276 if (j == numFeatures - 1)
00277 {
00278 graphics.drawLine(x1 + blipWidth/2, y + blipHeight,
00279 x2 + blipWidth/2, (height - y) - blipHeight);
00280 if (thick)
00281 graphics.drawLine((x1 + blipWidth/2)+1, y + blipHeight,
00282 (x2 + blipWidth/2)+1, (height - y) - blipHeight);
00283 }
00284 }
00285 }
00286 }
00287
00288 index += ndim;
00289
00290 graphics.setColor(Color.black);
00291 y = (blipHeight * j) + blipHeight;
00292 graphics.drawLine(0, y, width, y);
00293 graphics.drawLine(0, height - y, width, height - y);
00294 }
00295 }
00296 }
00297
00298 if (dragRect != null)
00299 {
00300
00301 graphics.setColor(Color.black);
00302 graphics.drawRect(dragRect.x, dragRect.y, dragRect.width, dragRect.height);
00303 }
00304
00305 currHeight = height;
00306 currWidth = width;
00307 currXMulti = xMulti;
00308 }
00309
00310 public Vector getChunkVisInfosForPoint(Point p)
00311 {
00312 Vector chunks = new Vector();
00313
00314 int whichFeature = getFeatureNumberForPoint(p);
00315
00316 if (whichFeature != -1)
00317 {
00318 for (int i = 0; i < events.size(); i++)
00319 {
00320 ChunkVisInfo c = (ChunkVisInfo) events.elementAt(i);
00321 if (p.y >= 0 && p.y <= (currHeight * screenPercentage))
00322 {
00323 if (p.x >= c.xFeat && p.x <= (c.xFeat + c.width))
00324 chunks.add(c);
00325 }
00326 else if (p.y <= currHeight && p.y >= currHeight - (currHeight * screenPercentage))
00327 {
00328 if (p.x >= c.xEDL && p.x <= (c.xEDL + c.width))
00329 chunks.add(c);
00330 }
00331
00332 }
00333 }
00334
00335 return chunks;
00336 }
00337
00338 public int getFeatureNumberForPoint(Point p)
00339 {
00340 int featureNumber = -1;
00341
00342 if (featFile != null)
00343 {
00344 double scaledHeight = currHeight * screenPercentage;
00345 int blipHeight = (int)(scaledHeight/numFeatures);
00346
00347
00348 if (blipHeight == 0)
00349 return featureNumber;
00350
00351 int whichFeature = p.y/blipHeight;
00352
00353
00354 if (whichFeature < numFeatures && whichFeature >= 0)
00355 {
00356 featureNumber = whichFeature;
00357 return featureNumber;
00358 }
00359
00360
00361 whichFeature = (currHeight - p.y)/blipHeight;
00362 if (whichFeature < numFeatures && whichFeature >= 0)
00363 {
00364 featureNumber = whichFeature;
00365 return featureNumber;
00366 }
00367 }
00368
00369 return featureNumber;
00370 }
00371
00372 public String getFeatureNameForPoint(Point p)
00373 {
00374 String featureName = "i don't know!";
00375
00376 int whichFeature = getFeatureNumberForPoint(p);
00377
00378 if (whichFeature != -1)
00379 {
00380 String fullFeatureName = (String) featFile.featureDescriptions.elementAt(whichFeature);
00381
00382 String[] chunks = fullFeatureName.split("\\.");
00383 featureName = chunks[chunks.length-1];
00384 }
00385
00386 return featureName;
00387 }
00388
00389 public double getFeatureValueForPoint(Point p)
00390 {
00391 double value = 0.0;
00392
00393 int whichFeature = getFeatureNumberForPoint(p);
00394
00395 if (whichFeature != -1)
00396 {
00397 for (int i = 0; i < events.size(); i++)
00398 {
00399 ChunkVisInfo cVI = (ChunkVisInfo) events.elementAt(i);
00400
00401 if (p.y >= 0 && p.y <= (currHeight * screenPercentage))
00402 {
00403 if (p.x >= cVI.xFeat && p.x <= cVI.xFeat + cVI.width)
00404 {
00405 int[] featNum = {0};
00406
00407 for (int j = 0; j < whichFeature; j++)
00408 featNum[0] += elementsPerFeature[j];
00409 value = cVI.getFeatures(featNum)[0];
00410 return value;
00411 }
00412 }
00413
00414 else if (p.y <= currHeight && p.y >= currHeight - (currHeight/4))
00415 {
00416 if (p.x >= cVI.xEDL && p.x <= cVI.xEDL + cVI.width)
00417 {
00418 int[] featNum = {0};
00419
00420 for (int j = 0; j < whichFeature; j++)
00421 featNum[0] += elementsPerFeature[j];
00422 value = cVI.getFeatures(featNum)[0];
00423 return value;
00424 }
00425 }
00426
00427 }
00428 }
00429
00430 return value;
00431 }
00432
00433 public void rangeFilterSelectionChanged()
00434 {
00435 }
00436
00437 public void setDragRect(Rectangle r, boolean dS)
00438 {
00439 dragRect = r;
00440 dragShift = dS;
00441
00442 if (!dragShift)
00443 {
00444 selectNone();
00445 }
00446
00447 for (int i = 0; i < events.size(); i++)
00448 {
00449 ChunkVisInfo cVI = (ChunkVisInfo)events.elementAt(i);
00450 Rectangle chunkRect = null;
00451
00452 if (dragRect.y < currHeight/2)
00453 {
00454 chunkRect = new Rectangle(cVI.xFeat, cVI.yFeat, cVI.width, cVI.height);
00455 }
00456 else
00457 {
00458 chunkRect = new Rectangle(cVI.xEDL, cVI.yEDL, cVI.width, cVI.height);
00459 }
00460 if ((dragRect.x >= chunkRect.x &&
00461 dragRect.x <= chunkRect.x + chunkRect.width) ||
00462 (dragRect.x + dragRect.width >= chunkRect.x &&
00463 dragRect.x + dragRect.width <= chunkRect.x + chunkRect.width) ||
00464 (dragRect.x <= chunkRect.x &&
00465 dragRect.x + dragRect.width >= chunkRect.x + chunkRect.width))
00466 cVI.selected = true;
00467 }
00468
00469 dragRect = null;
00470 dragShift = false;
00471
00472 drawingPanel.repaint();
00473 }
00474
00475 public void actionPerformed(ActionEvent arg0)
00476 {
00477 super.actionPerformed(arg0);
00478
00479 Object source = arg0.getSource();
00480
00481 if (source == multiLines)
00482 {
00483 JCheckBox cb = (JCheckBox)source;
00484
00485 multi = cb.isSelected();
00486 }
00487 if (source == thickLines)
00488 {
00489 JCheckBox cb = (JCheckBox)source;
00490
00491 thick = cb.isSelected();
00492 }
00493 }
00494
00495 public JPanel buildGUI(Color bgColor)
00496 {
00497 JPanel panel = super.buildGUI(bgColor);
00498
00499 JPanel linesPanel = new JPanel();
00500 linesPanel.setBackground(bgColor);
00501 linesPanel.setLayout(new BoxLayout(linesPanel, BoxLayout.Y_AXIS));
00502
00503 multiLines = new JCheckBox("multi lines");
00504 multiLines.setBackground(bgColor);
00505 multiLines.addActionListener(this);
00506 linesPanel.add(multiLines);
00507
00508 thickLines = new JCheckBox("thick lines");
00509 thickLines.setBackground(bgColor);
00510 thickLines.addActionListener(this);
00511 linesPanel.add(thickLines);
00512
00513 controlsPanel.add(linesPanel);
00514
00515 return panel;
00516 }
00517
00518
00519 }
00520
00521
00522