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.image.BufferedImage;
00036 import java.util.Vector;
00037
00038 import javax.swing.BoxLayout;
00039 import javax.swing.JComboBox;
00040 import javax.swing.JLabel;
00041 import javax.swing.JPanel;
00042
00043 import com.meapsoft.EDLFile;
00044 import com.meapsoft.FeatFile;
00045
00046
00052 public class BarGraphRenderer extends Renderer
00053 {
00054 JComboBox hOptions;
00055 JComboBox sOptions;
00056
00057 double currXMulti = 0.0;
00058 double currHeight = 0.0;
00059
00060 public BarGraphRenderer(FeatFile featFile, EDLFile eDLFile)
00061 {
00062 super(featFile, eDLFile, "BarGraph");
00063 }
00064
00065 public BarGraphRenderer(Renderer r)
00066 {
00067 super(r);
00068
00069
00070 updateColorMultipliers();
00071 }
00072
00073 public void draw(BufferedImage image, int width, int height)
00074 {
00075
00076 int numChunks = events.size();
00077
00078
00079 ChunkVisInfo lastChunk = (ChunkVisInfo) events.elementAt(numChunks - 1);
00080 double xMulti = width/(lastStartTime + lastChunk.length);
00081
00082 Graphics graphics = image.getGraphics();
00083 graphics.setColor(Color.white);
00084 graphics.fillRect(0,0,width,height);
00085
00086 for (int i = 0; i < numChunks; i++)
00087 {
00088 ChunkVisInfo cVI = (ChunkVisInfo) events.elementAt(i);
00089
00090 int[] featNum = {0};
00091
00092 for (int j = 0; j < numFeatures; j++)
00093 {
00094 double features[] = cVI.getFeatures(featNum);
00095 double featureValue = features[0] - lowestFeatureValue[j];
00096
00097 featNum[0] += elementsPerFeature[j];
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 double colorIndex = featureValue * colorMultipliers[j];
00115 Color extraColor;
00116 Color featureColor;
00117
00118 if (cVI.selected)
00119 {
00120 extraColor = Color.white;
00121 featureColor = colormap.table[(int)colorIndex];
00122 }
00123 else
00124 {
00125 extraColor = Color.DARK_GRAY;
00126 featureColor = colormap.table[(int)colorIndex].darker().darker().darker();
00127 }
00128
00129 int blipHeight = 0;
00130 double yMulti = 0.0;
00131
00132 int which = hOptions.getSelectedIndex();
00133
00134 if (which == 0)
00135 {
00136 yMulti = (height/lastStartTime)/numFeatures;
00137 blipHeight = (int)(Math.round(cVI.startTime * yMulti));
00138 }
00139 else if (which == 1)
00140 {
00141 yMulti = (height/lastStartTime)/numFeatures;
00142 blipHeight = (int)(Math.round(cVI.dstTime * yMulti));
00143 }
00144 else if (which == 2)
00145 {
00146 yMulti = (height/longestChunk)/numFeatures;
00147 blipHeight = (int)(Math.round(cVI.length * yMulti));
00148 }
00149 else if (which == 3)
00150 {
00151 yMulti = (height/(featureValueSpan[j]))/numFeatures;
00152 blipHeight = (int)(Math.round(featureValue * yMulti));
00153 }
00154
00155
00156 int blipWidth = (int)(cVI.length * xMulti) + 1;
00157
00158
00159 int x1 = (int)(Math.round(cVI.startTime * xMulti));
00160
00161 if (sOptions.getSelectedIndex() == 1)
00162 x1 = (int)(Math.round(cVI.dstTime * xMulti));
00163
00164 int yOffset = Math.round((height/numFeatures) * j);
00165 int yTop = (height - yOffset) - (height/numFeatures);
00166 int yFeatStart = (height - yOffset) - blipHeight;
00167
00168
00169 if (elementsPerFeature[j] > 1)
00170 {
00171
00172 graphics.setColor(extraColor);
00173 graphics.fillRect(x1, yTop, blipWidth, height/numFeatures);
00174
00175 if (which == 3)
00176 {
00177 blipHeight = Math.round(height/numFeatures);
00178 kludgyMultiDimensionalDraw(x1, yTop,blipWidth,blipHeight,cVI, j, graphics);
00179 }
00180 else
00181 kludgyMultiDimensionalDraw(x1, yFeatStart,blipWidth,blipHeight,cVI, j, graphics);
00182 }
00183 else
00184 {
00185
00186 graphics.setColor(extraColor);
00187 graphics.fillRect(x1, yTop, blipWidth, height/numFeatures);
00188
00189 graphics.setColor(featureColor);
00190 graphics.fillRect(x1, yFeatStart, blipWidth, blipHeight);
00191 }
00192
00193 if (sOptions.getSelectedIndex() == 0)
00194 cVI.xFeat = x1;
00195 else
00196 cVI.xEDL = x1;
00197
00198 cVI.width = blipWidth;
00199 }
00200 cVI.height = height;
00201 }
00202
00203 if (dragRect != null)
00204 {
00205
00206 graphics.setColor(Color.black);
00207 graphics.drawRect(dragRect.x, dragRect.y, dragRect.width, dragRect.height);
00208 }
00209
00210 currXMulti = xMulti;
00211 currHeight = height;
00212 }
00213
00214 public void kludgyMultiDimensionalDraw(int x, int y, int w, int h,
00215 ChunkVisInfo cVI, int featNum, Graphics graphics)
00216 {
00217 int numElements = elementsPerFeature[featNum];
00218
00219 int startElement = 0;
00220
00221 for (int i = 0; i < featNum; i++)
00222 startElement += elementsPerFeature[i];
00223
00224 double yIncr = (double)h/numElements;
00225
00226
00227
00228
00229
00230 for (int i = startElement; i < startElement + numElements; i++)
00231 {
00232 int[] fN = {i};
00233 double featureValue = cVI.getFeatures(fN)[0];
00234
00235 featureValue -= lowestFeatureValue[featNum];
00236
00237 double colorIndex = featureValue * colorMultipliers[featNum];
00238
00239 Color c = colormap.table[(int)colorIndex];
00240
00241 if (!cVI.selected)
00242 c = c.darker().darker().darker();
00243
00244 graphics.setColor(c);
00245
00246 int yLocal = (int)(Math.round((y + h) - (i * yIncr)));
00247
00248 int miniBlipHeight = (int)(Math.round(yIncr));
00249 if (miniBlipHeight == 0)
00250 miniBlipHeight = 1;
00251
00252
00253
00254 graphics.fillRect(x, yLocal, w, miniBlipHeight);
00255 }
00256
00257 }
00258
00259 public Vector getChunkVisInfosForPoint(Point p)
00260 {
00261 Vector chunks = new Vector();
00262
00263 for (int i = 0; i < events.size(); i++)
00264 {
00265 ChunkVisInfo c = (ChunkVisInfo) events.elementAt(i);
00266 if (sOptions.getSelectedIndex() == 0)
00267 {
00268 if (p.x >= c.xFeat && p.x <= (c.xFeat + c.width))
00269 {
00270 chunks.add(c);
00271 }
00272 }
00273 else
00274 {
00275 if (p.x >= c.xEDL && p.x <= (c.xEDL + c.width))
00276 {
00277 chunks.add(c);
00278 }
00279 }
00280 }
00281
00282 return chunks;
00283 }
00284
00285 public int getFeatureNumberForPoint(Point p)
00286 {
00287 int featureNumber = -1;
00288
00289 if (featFile != null)
00290 {
00291 int graphHeight = (int)(currHeight/numFeatures);
00292
00293 for (int i = 0; i < numFeatures; i++)
00294 {
00295 int low = (int)(currHeight - (i * graphHeight)) - graphHeight;
00296 int high = (int)(currHeight - (i * graphHeight));
00297 if (p.y >= low && p.y <= high)
00298 featureNumber = i;
00299 }
00300 }
00301 return featureNumber;
00302 }
00303
00304 public String getFeatureNameForPoint(Point p)
00305 {
00306 String featureName = "i don't know!";
00307
00308 int whichFeature = getFeatureNumberForPoint(p);
00309
00310 if (whichFeature != -1)
00311 {
00312 String fullFeatureName = (String) featFile.featureDescriptions.elementAt(whichFeature);
00313
00314 String[] chunks = fullFeatureName.split("\\.");
00315 featureName = chunks[chunks.length-1];
00316 }
00317
00318 return featureName;
00319 }
00320
00321 public double getFeatureValueForPoint(Point p)
00322 {
00323 double value = 0.0;
00324
00325 int whichFeature = getFeatureNumberForPoint(p);
00326
00327 if (whichFeature != -1)
00328 {
00329 for (int i = 0; i < events.size(); i++)
00330 {
00331 ChunkVisInfo cVI = (ChunkVisInfo) events.elementAt(i);
00332
00333 if (sOptions.getSelectedIndex() == 0)
00334 {
00335 if (p.x >= cVI.xFeat && p.x <= (cVI.xFeat + cVI.width))
00336 {
00337 int[] featNum = {0};
00338
00339 for (int j = 0; j < whichFeature; j++)
00340 featNum[0] += elementsPerFeature[j];
00341 value = cVI.getFeatures(featNum)[0];
00342 return value;
00343 }
00344 }
00345 else
00346 {
00347 if (p.x >= cVI.xEDL && p.x <= (cVI.xEDL + cVI.width))
00348 {
00349 int[] featNum = {0};
00350
00351 for (int j = 0; j < whichFeature; j++)
00352 featNum[0] += elementsPerFeature[j];
00353 value = cVI.getFeatures(featNum)[0];
00354 return value;
00355 }
00356 }
00357 }
00358 }
00359
00360 return value;
00361 }
00362
00363 public void rangeFilterSelectionChanged()
00364 {
00365 }
00366
00367 public void setDragRect(Rectangle r, boolean dS)
00368 {
00369 dragRect = r;
00370 dragShift = dS;
00371
00372 if (!dragShift)
00373 {
00374 selectNone();
00375 }
00376
00377 for (int i = 0; i < events.size(); i++)
00378 {
00379 ChunkVisInfo cVI = (ChunkVisInfo)events.elementAt(i);
00380 Rectangle chunkRect = null;
00381
00382 if (sOptions.getSelectedIndex() == 0)
00383 {
00384 chunkRect = new Rectangle(cVI.xFeat, cVI.yFeat, cVI.width, cVI.height);
00385 }
00386 else
00387 {
00388 chunkRect = new Rectangle(cVI.xEDL, cVI.yEDL, cVI.width, cVI.height);
00389 }
00390 if ((dragRect.x >= chunkRect.x &&
00391 dragRect.x <= chunkRect.x + chunkRect.width) ||
00392 (dragRect.x + dragRect.width >= chunkRect.x &&
00393 dragRect.x + dragRect.width <= chunkRect.x + chunkRect.width) ||
00394 (dragRect.x <= chunkRect.x &&
00395 dragRect.x + dragRect.width >= chunkRect.x + chunkRect.width))
00396 cVI.selected = true;
00397 }
00398
00399 dragRect = null;
00400 dragShift = false;
00401
00402 drawingPanel.repaint();
00403 }
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413 public JPanel buildGUI(Color bgColor)
00414 {
00415
00416 JPanel panel = super.buildGUI(bgColor);
00417
00418 JPanel hSPanel = new JPanel();
00419 hSPanel.setBackground(bgColor);
00420 hSPanel.setLayout(new BoxLayout(hSPanel, BoxLayout.Y_AXIS));
00421
00422 JLabel hCL = new JLabel("height: ");
00423 hCL.setBackground(bgColor);
00424 hSPanel.add(hCL);
00425
00426 String[] heightOptions = {"start time", "dest time", "length", "feature value"};
00427
00428 hOptions = new JComboBox(heightOptions);
00429 hOptions.setBackground(bgColor);
00430 hOptions.setActionCommand("hOptions");
00431 hOptions.setSelectedIndex(2);
00432 hOptions.addActionListener(this);
00433 hSPanel.add(hOptions);
00434
00435 JLabel sCL = new JLabel("show: ");
00436 sCL.setBackground(bgColor);
00437 hSPanel.add(sCL);
00438
00439 String[] showOptions = {"feat file", "EDL file"};
00440
00441 sOptions = new JComboBox(showOptions);
00442 sOptions.setBackground(bgColor);
00443 sOptions.setActionCommand("sOptions");
00444 sOptions.addActionListener(this);
00445 hSPanel.add(sOptions);
00446
00447 controlsPanel.add(hSPanel);
00448
00449 return panel;
00450 }
00451
00452
00453 }
00454
00455
00456