Main Page   Packages   Class Hierarchy   Compound List   File List   Compound Members  

ScatterPlotRenderer.java

00001 /*
00002  *  Copyright 2006-2007 Columbia University.
00003  *
00004  *  This file is part of MEAPsoft.
00005  *
00006  *  MEAPsoft is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License version 2 as
00008  *  published by the Free Software Foundation.
00009  *
00010  *  MEAPsoft is distributed in the hope that it will be useful, but
00011  *  WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  *  General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with MEAPsoft; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
00018  *  02110-1301 USA
00019  *
00020  *  See the file "COPYING" for the text of the license.
00021  */
00022 
00023 /*
00024  * Created on Nov 15, 2006
00025  *
00026  * various ways of viewing EDL files
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.JComboBox;
00041 import javax.swing.JLabel;
00042 import javax.swing.JPanel;
00043 
00044 import com.meapsoft.EDLFile;
00045 import com.meapsoft.FeatFile;
00046 
00047 
00053 public class ScatterPlotRenderer extends Renderer
00054 {       
00055         JPanel dataMappingControlsPanel;
00056 
00057         JComboBox xOptions;
00058         JComboBox yOptions;
00059         JComboBox hOptions;
00060         JComboBox wOptions;
00061         JComboBox cOptions;
00062         JComboBox sOptions;
00063 
00064         boolean ovals = false;
00065         
00066         int currWidth = 0;
00067         int currHeight = 0;
00068         double currXMulti = 0.0;
00069         double currYMulti = 0.0;
00070         
00071         // 1/20 of the screen
00072         double maxBlobSize = 0.05;
00073         
00074         
00075         public ScatterPlotRenderer(FeatFile featFile, EDLFile eDLFile)
00076         {
00077                 super(featFile, eDLFile, "ScatterPlot");
00078         }
00079 
00080         public ScatterPlotRenderer(Renderer r)
00081         {
00082                 super(r);
00083         }
00084 
00085         public void parseFiles()
00086         {
00087                 super.parseFiles();
00088                 updateOptionBoxes();    
00089         }
00090         
00091         public void draw(BufferedImage image, int width, int height)
00092         {       
00093                 int numChunks = events.size();
00094                 
00095                 /*
00096                  * set up scaling factors
00097                  */
00098                  
00099                 double xMulti = 0.0;
00100                 double yMulti = 0.0;
00101                 double wMulti = 0.0;
00102                 double hMulti = 0.0;
00103                 
00104                 //have to do width and height first so that we can use them
00105                 //to calculate x and y correctly!
00106                 
00107                 int wSelection = this.wOptions.getSelectedIndex();
00108                 
00109                 if (wSelection == 0)
00110                 {
00111                         double multi = width * maxBlobSize;
00112                         
00113                         wMulti = multi/lastStartTime;
00114                 }
00115                 else if (wSelection == 1)
00116                 {
00117                         double multi = width * maxBlobSize;
00118                         
00119                         wMulti = multi/lastStartTime;
00120                 }
00121                 else if (wSelection == 2)
00122                 {
00123                         double multi = width * maxBlobSize;
00124                         
00125                         wMulti = multi/longestChunk;
00126                 }
00127                 else if (wSelection >= 3)
00128                 {
00129                         double multi = width * maxBlobSize;
00130                         int which = wSelection - 3;
00131                         
00132                         wMulti = multi/highestFeatureValue[which];
00133                 }
00134                 
00135                 int hSelection = this.hOptions.getSelectedIndex();
00136                 
00137                 if (hSelection == 0)
00138                 {
00139                         double multi = height * maxBlobSize;
00140                         
00141                         hMulti = multi/lastStartTime;
00142                 }
00143                 else if (hSelection == 1)
00144                 {
00145                         double multi = height * maxBlobSize;
00146                         
00147                         hMulti = multi/lastStartTime;
00148                 }
00149                 else if (hSelection == 2)
00150                 {
00151                         double multi = height * maxBlobSize;
00152                         
00153                         hMulti = multi/longestChunk;
00154                 }
00155                 else if (hSelection >= 3)
00156                 {
00157                         double multi = height * maxBlobSize;
00158                         int which = hSelection - 3;
00159                         
00160                         hMulti = multi/highestFeatureValue[which];
00161                 }
00162                 
00163                 int xSelection = this.xOptions.getSelectedIndex();
00164                 
00165                 if (xSelection == 0)
00166                 {
00167                         //can we really assume that the last chunk in the Vector is the last chunk in time???
00168                         ChunkVisInfo lastChunk = (ChunkVisInfo) events.elementAt(numChunks - 1);
00169                         
00170                         int adjWidth = width;
00171                         
00172                         if (wSelection == 0 || wSelection == 1)
00173                                 adjWidth = width - (int)(Math.round(wMulti * lastChunk.startTime));
00174                         if (wSelection == 2)
00175                                 adjWidth = width - (int)(Math.round(wMulti * lastChunk.length));
00176                         if (wSelection >= 3)
00177                         {
00178                                 int whichW = wSelection - 3;
00179                                 adjWidth = width - (int)(Math.round(wMulti * highestFeatureValue[whichW]));
00180                         }
00181                                                         
00182                         xMulti = adjWidth/lastStartTime;
00183                 }
00184                 else if (xSelection == 1)
00185                 {
00186                         //can we really assume that the last chunk in the Vector is the last chunk in time???
00187                         ChunkVisInfo lastChunk = (ChunkVisInfo) events.elementAt(numChunks - 1);
00188                         
00189                         int adjWidth = width;
00190                         
00191                         if (wSelection == 0 || wSelection == 1)//wST.isSelected())
00192                                 adjWidth = width - (int)(Math.round(wMulti * lastChunk.startTime));
00193                         if (wSelection == 2)//wL.isSelected())
00194                                 adjWidth = width - (int)(Math.round(wMulti * lastChunk.length));
00195                         if (wSelection >= 3)//wFV.isSelected())
00196                         {
00197                                 int whichW = wSelection - 3;
00198                                 adjWidth = width - (int)(Math.round(wMulti * highestFeatureValue[whichW]));
00199                         }
00200                                                         
00201                         xMulti = adjWidth/lastStartTime;
00202                 }
00203                 else if (xSelection == 2)
00204                 {
00205                         int adjWidth = width;
00206                         
00207                         if (wSelection == 0 || wSelection == 1)//wST.isSelected())
00208                                 adjWidth = width - (int)(Math.round(wMulti * lastStartTime));
00209                         if (wSelection == 2)//wL.isSelected())
00210                                 adjWidth = width - (int)(Math.round(wMulti * longestChunk));
00211                         if (wSelection >= 3)//wFV.isSelected())
00212                         {
00213                                 int whichW = wSelection - 3;
00214                                 adjWidth = width - (int)(Math.round(wMulti * highestFeatureValue[whichW]));
00215                         }
00216                                 
00217                         xMulti = adjWidth/(longestChunk - shortestChunk);
00218                 }
00219                 else if (xSelection >= 3)//xFV.isSelected())
00220                 {
00221                         int adjWidth = width;
00222                         int which = xSelection - 3;
00223                         
00224                         if (wSelection == 0 || wSelection == 1)//wST.isSelected())
00225                                 adjWidth = width - (int)(Math.round(wMulti * lastStartTime));
00226                         if (wSelection == 2)//wL.isSelected())
00227                                 adjWidth = width - (int)(Math.round(wMulti * longestChunk));
00228                         if (wSelection >= 3)//wFV.isSelected())
00229                         {
00230                                 int whichW = wSelection - 3;
00231                                 adjWidth = width - (int)(Math.round(wMulti * highestFeatureValue[whichW]));
00232                         }
00233                         
00234                         xMulti = adjWidth/
00235                                 (highestFeatureValue[which] - lowestFeatureValue[which]);
00236                 }
00237 
00238                 int ySelection = this.yOptions.getSelectedIndex();
00239                 
00240                 if (ySelection == 0)//yST.isSelected())
00241                 {
00242                         //can we really assume that the last chunk in the Vector is the last chunk in time???
00243                         ChunkVisInfo lastChunk = (ChunkVisInfo) events.elementAt(numChunks - 1);
00244                         
00245                         int adjHeight = height;
00246                         
00247                         if (hSelection == 0 || hSelection == 1)//hST.isSelected())
00248                                 adjHeight = height - (int)(Math.round(hMulti * lastChunk.startTime));
00249                         if (hSelection == 2)//hL.isSelected())
00250                                 adjHeight = height - (int)(Math.round(hMulti * lastChunk.length));
00251                         if (hSelection >= 3)//hFV.isSelected())
00252                         {
00253                                 int whichH = hSelection - 3;
00254                                 adjHeight = height - (int)(Math.round(hMulti * highestFeatureValue[whichH]));
00255                         }
00256                                                 
00257                         yMulti = adjHeight/lastStartTime;
00258                 }
00259                 else if (ySelection == 1)//yDT.isSelected())
00260                 {
00261                         //can we really assume that the last chunk in the Vector is the last chunk in time???
00262                         ChunkVisInfo lastChunk = (ChunkVisInfo) events.elementAt(numChunks - 1);
00263                         
00264                         int adjHeight = height;
00265                         
00266                         if (hSelection == 0 || hSelection == 1)//hST.isSelected())
00267                                 adjHeight = height - (int)(Math.round(hMulti * lastChunk.startTime));
00268                         if (hSelection == 2)//hL.isSelected())
00269                                 adjHeight = height - (int)(Math.round(hMulti * lastChunk.length));
00270                         if (hSelection >= 3)//hFV.isSelected())
00271                         {
00272                                 int whichH = hSelection - 3;
00273                                 adjHeight = height - (int)(Math.round(hMulti * highestFeatureValue[whichH]));
00274                         }
00275                                                                                 
00276                         yMulti = adjHeight/lastStartTime;
00277                 }
00278                 else if (ySelection == 2)//yL.isSelected())
00279                 {
00280                         int adjHeight = height;
00281                         
00282                         if (hSelection == 0 || hSelection == 1)//hST.isSelected())
00283                                 adjHeight = height - (int)(Math.round(hMulti * lastStartTime));
00284                         if (hSelection == 2)//hL.isSelected())
00285                                 adjHeight = height - (int)(Math.round(hMulti * longestChunk));
00286                         if (hSelection >= 3)//hFV.isSelected())
00287                         {
00288                                 int whichH = hSelection - 3;
00289                                 adjHeight = height - (int)(Math.round(hMulti * highestFeatureValue[whichH]));
00290                         }
00291                                 
00292                         yMulti = adjHeight/(longestChunk - shortestChunk);
00293                         
00294                         //yMulti = height/(longestChunk + longestChunk);
00295                 }
00296                 else if (ySelection >= 3)//xFV.isSelected())
00297                 {
00298                         int adjHeight = height;
00299                         int which = ySelection - 3;
00300                         
00301                         if (hSelection == 0 || hSelection == 1)//wST.isSelected())
00302                                 adjHeight = height - (int)(Math.round(hMulti * lastStartTime));
00303                         if (hSelection == 2)//wL.isSelected())
00304                                 adjHeight = height - (int)(Math.round(hMulti * longestChunk));
00305                         if (hSelection >= 3)//wFV.isSelected())
00306                         {
00307                                 int whichH = hSelection - 3;
00308                                 adjHeight = height - (int)(Math.round(hMulti * highestFeatureValue[whichH]));
00309                         }
00310                         
00311                         yMulti = adjHeight/
00312                                 (highestFeatureValue[which] - lowestFeatureValue[which]);
00313                 }
00314                 
00315                 /*
00316                  * clear screen
00317                  */
00318                 
00319                 Graphics graphics = image.getGraphics();
00320                 graphics.setColor(Color.white);
00321                 graphics.fillRect(0,0,width,height);
00322                 
00323                 
00324                 /*
00325                  * do each chunk
00326                  */
00327                  
00328                 for (int i = 0; i < numChunks; i++)
00329                 {
00330                         ChunkVisInfo cVI = (ChunkVisInfo) events.elementAt(i);
00331                         
00332                         /*
00333                          * get color info
00334                          */
00335                          
00336                         int whichFeature = cOptions.getSelectedIndex();
00337                         double featureValue = 0.0;
00338                         int[] featNum = {0};
00339                         
00340                         if (whichFeature == 0)                  
00341                                 featureValue = cVI.startTime;
00342                         else if (whichFeature == 1)
00343                                 featureValue = cVI.dstTime;
00344                         else if (whichFeature == 2)
00345                                 featureValue = cVI.length;
00346                         else if (whichFeature >= 3)
00347                         {
00348                                 int which = whichFeature - 3;
00349                                                                 
00350                                 for (int j = 0; j < which; j++)
00351                                         featNum[0] += elementsPerFeature[j];
00352                                                                         
00353                                 double features[] = cVI.getFeatures(featNum);
00354                                 featureValue = features[0] - lowestFeatureValue[which];
00355                         }
00356                         
00357                                 /*
00358                                  * TOO COMPLICATED RIGHT NOW, MY HEAD HURTS!!!
00359                                  * We need to do all possible combos of mappings...
00360                                  */
00361                                 /*
00362                                 if (colorMapType == SQRT)
00363                                 {
00364                                         featureValue -= lowestFeatureValue[0];//j];
00365                                         featureValue = Math.sqrt(featureValue);
00366                                 }
00367                                 else if (colorMapType == SQUARE)
00368                                 {
00369                                         featureValue -= lowestFeatureValue[0];//j];
00370                                         featureValue *= featureValue;
00371                                 }
00372                                 else
00373                                         featureValue -= lowestFeatureValue[0];//j];
00374                                 */
00375                         
00376                         int colorIndex = (int)(Math.round(featureValue * colorMultipliers[0]));//j]);
00377                         
00378                         Color borderColor;
00379                         Color featureColor;
00380                         //graphics.setColor(colormap.table[colorIndex]);
00381                         
00382                         if (cVI.selected)
00383                         {
00384                                 borderColor = Color.black;//colormap.table[(int)colorIndex].brighter().brighter();
00385                                 featureColor = colormap.table[(int)colorIndex];
00386                                 
00387                                 //graphics.setColor(borderColor);
00388                         }
00389                         else
00390                         {
00391                                 borderColor = colormap.table[(int)colorIndex].darker().darker().darker();
00392                                 featureColor = colormap.table[(int)colorIndex].darker().darker().darker();
00393                                 //graphics.setColor(c);
00394                         }
00395                         
00396                         /*
00397                          * find location
00398                          */
00399                         int x = 0;
00400                         int y = 0;
00401                         int w = 0;
00402                         int h = 0;
00403                 
00404                         if (xSelection == 0)
00405                                 x = (int)(Math.round(cVI.startTime * xMulti));
00406                         else if (xSelection == 1)
00407                                 x = (int)(Math.round(cVI.dstTime * xMulti));
00408                         else if (xSelection == 2)
00409                                 x = (int)(Math.round((cVI.length - shortestChunk) * xMulti));
00410                         else if (xSelection >= 3)
00411                         {
00412                                 whichFeature = xSelection - 3;
00413                                 featNum[0] = 0;
00414                                                 
00415                                 for (int j = 0; j < whichFeature; j++)
00416                                         featNum[0] += elementsPerFeature[j];
00417                                                         
00418                                 double features[] = cVI.getFeatures(featNum);
00419                                 double value = features[0] - lowestFeatureValue[whichFeature];
00420                                 x = (int)(Math.round(value * xMulti));  
00421                         }
00422 
00423                         if (ySelection == 0)
00424                                 y = (int)(Math.round(cVI.startTime * yMulti));
00425                         else if (ySelection == 1)
00426                                 y = (int)(Math.round(cVI.dstTime * yMulti));
00427                         else if (ySelection == 2)
00428                                 y = (int)(Math.round((cVI.length - shortestChunk) * yMulti));
00429                         else if (ySelection >= 3)
00430                         {
00431                                 whichFeature = ySelection - 3;
00432                                 featNum[0] = 0;
00433                                 
00434                                 for (int j = 0; j < whichFeature; j++)
00435                                         featNum[0] += elementsPerFeature[j];
00436                                         
00437                                 double features[] = cVI.getFeatures(featNum);
00438                                 double value = features[0] - lowestFeatureValue[whichFeature];
00439                                 y = (int)(Math.round(value * yMulti));                  
00440                         }
00441 
00442                         if (hSelection == 0)
00443                                 h = (int)(Math.round(cVI.startTime * hMulti));
00444                         else if (hSelection == 1)
00445                                 h = (int)(Math.round(cVI.dstTime * hMulti));
00446                         else if (hSelection == 2)
00447                                 h = (int)(Math.round(cVI.length * hMulti));
00448                         else if (hSelection >= 3)
00449                         {
00450                                 whichFeature = hSelection - 3;
00451                                 featNum[0] = 0;
00452                                 
00453                                 for (int j = 0; j < whichFeature; j++)
00454                                         featNum[0] += elementsPerFeature[j];
00455                                         
00456                                 double features[] = cVI.getFeatures(featNum);
00457                                 double value = features[0] - lowestFeatureValue[whichFeature];
00458                                 h = (int)(Math.round(value * hMulti));                                                  
00459                         }
00460                                 
00461                         if (wSelection == 0)
00462                                 w = (int)(Math.round(cVI.startTime * wMulti));
00463                         else if (wSelection == 1)
00464                                 w = (int)(Math.round(cVI.dstTime * wMulti));
00465                         else if (wSelection == 2)
00466                                 w = (int)(Math.round(cVI.length * wMulti));
00467                         else if (wSelection >= 3)
00468                         {
00469                                 whichFeature = wSelection - 3;
00470                                 featNum[0] = 0;
00471                                 
00472                                 for (int j = 0; j < whichFeature; j++)
00473                                         featNum[0] += elementsPerFeature[j];
00474                                         
00475                                 double features[] = cVI.getFeatures(featNum);
00476                                 double value = features[0] - lowestFeatureValue[whichFeature];
00477                                 w = (int)(Math.round(value * wMulti));                                                  
00478                         }
00479                         
00480                         if (h == 0)
00481                                 h = 1;
00482                         if (w == 0)
00483                                 w = 1;
00484 
00485                         //System.out.println("x: " + x + " y: " + y + " h: " + h + " w: " + w);
00486                         
00487                         whichFeature = cOptions.getSelectedIndex();
00488                         
00489                         int wInset = w - 4;
00490                         if (wInset < 1)
00491                                 wInset = 1;
00492                                         
00493                         int hInset = h - 4;
00494                         if (hInset < 1)
00495                                 hInset = 1;
00496                                 
00497                         //special drawing routine for multi-dimensional features
00498                         if (whichFeature >= 3 && 
00499                                 elementsPerFeature[whichFeature - 3] > 1)
00500                         {
00501                                 if (cVI.selected)
00502                                 {
00503                                         graphics.setColor(borderColor);
00504                                         graphics.fillRect(x, y, w, h);
00505                                         kludgyMultiDimensionalDraw(x+2,y+2,wInset,hInset,cVI, cOptions.getSelectedIndex() - 3, graphics);
00506                                 }
00507                                 else
00508                                         kludgyMultiDimensionalDraw(x,y,w,h,cVI, cOptions.getSelectedIndex() - 3, graphics);
00509 
00510                         }
00511                         //regular drawing routines
00512                         else
00513                         {
00514                                 graphics.setColor(borderColor);
00515                                 
00516                                 if (ovals)
00517                                         graphics.fillOval(x, y, w, h);                  
00518                                 else
00519                                         graphics.fillRect(x, y, w, h);  
00520                                         
00521                                 graphics.setColor(featureColor);
00522                                         
00523                                 if (ovals)
00524                                         graphics.fillOval(x+2, y+2, wInset, hInset);                    
00525                                 else
00526                                         graphics.fillRect(x+2, y+2, wInset, hInset);                                            
00527                         }
00528                         //else
00529                         //{
00530                         //      if (ovals)
00531                         //              graphics.drawOval(x, y, w, h);                  
00532                         //      else
00533                         //              graphics.drawRect(x, y, w, h);
00534                         //}
00535                         
00536                         cVI.xFeat = x;
00537                         cVI.yFeat = y;
00538                         cVI.width = w;
00539                         cVI.height = h;
00540                 }
00541                 
00542                 if (dragRect != null)
00543                 {
00544                         //System.out.println("drawing: " + dragRect.toString());
00545                         graphics.setColor(Color.black);
00546                         graphics.drawRect(dragRect.x, dragRect.y, dragRect.width, dragRect.height);
00547                 }
00548         }
00549         
00550         public void kludgyMultiDimensionalDraw(int x, int y, int w, int h, 
00551                 ChunkVisInfo cVI, int featNum, Graphics graphics)
00552         {                       
00553                 int numElements = elementsPerFeature[featNum];
00554 
00555                 int elementNum = numElements - 1;
00556                 
00557                 for (int i = 0; i < featNum; i++)
00558                 {
00559                         elementNum += elementsPerFeature[i];
00560                 }
00561                 
00562                 //int bottom = (elementNum - numElements) + 1;
00563                 
00564                 double yIncr = (double)h/numElements;
00565                 
00566                 //System.out.println("x: " + x + " Oy: " + y + " w: " + w + " h: " + h +
00567                 //      " featNum: " + featNum + " numElements: " + numElements + 
00568                 //      " elementNum: " + elementNum + " bottom: " + bottom + " yIncr: " + yIncr);
00569                 
00570                 //for (; elementNum >= bottom; elementNum--)
00571                 for (int i = 0; i < elementNum; i++)
00572                 {
00573                         int[] fN = {i};
00574                         double featureValue = cVI.getFeatures(fN)[0];
00575 
00576                         featureValue -= lowestFeatureValue[featNum];
00577 
00578                         double colorIndex = featureValue * colorMultipliers[featNum];
00579 
00580                         Color c = colormap.table[(int)colorIndex];
00581                         
00582                         if (!cVI.selected)
00583                                 c = c.darker().darker().darker();
00584                                 
00585                         graphics.setColor(c);
00586                 
00587                         //int n = numElements - i;
00588                         
00589                         int yLocal = (int)((y + h) - (i * yIncr));
00590         
00591                         int miniBlipHeight = (int)(Math.round(yIncr));
00592                         if (miniBlipHeight == 0)
00593                                 miniBlipHeight = 1;
00594                         
00595                         //System.out.println("eN: " + elementNum + " n: " + n + " x: " + x + " yLocal: " + yLocal + " w: " + w + " miniBlipHeight: " + miniBlipHeight);
00596                         
00597                         graphics.fillRect(x, yLocal, w, miniBlipHeight);
00598                         
00599                 }
00600                 
00601         }
00602 
00603         public Vector getChunkVisInfosForPoint(Point p)
00604         {       
00605                 Vector chunks = new Vector();
00606                 
00607                 for (int i = 0; i < events.size(); i++)
00608                 {
00609                         ChunkVisInfo c = (ChunkVisInfo) events.elementAt(i);
00610 
00611                         if (p.x >= c.xFeat && p.x <= (c.xFeat + c.width))
00612                         {
00613                                 if (p.y >= c.yFeat && p.y <= (c.yFeat + c.height))
00614                                 {
00615                                         chunks.add(c);
00616                                 }
00617                         }
00618                 }
00619 
00620                 return chunks;
00621         }
00622         
00623         //doesn't make sense for scatter plot...
00624         //well, it sort of makes sense...
00625         //we return -1,-2,-3 for start time, dst time, length
00626         public int getFeatureNumberForPoint(Point p)
00627         {       
00628                 int which = cOptions.getSelectedIndex();
00629                 
00630                 //kludge!!! 
00631                 if (which < 3)
00632                         which = -1 - which;
00633                 else
00634                         which -= 3;
00635                 
00636                 return which;
00637         }
00638         
00639         public String getFeatureNameForPoint(Point p)
00640         {       
00641                 int whichFeature = getFeatureNumberForPoint(p);
00642                 
00643                 if (whichFeature == -1)
00644                         return optionBoxStrings[0];
00645                 else if (whichFeature == -2)
00646                         return optionBoxStrings[1];
00647                 else if (whichFeature == -3)
00648                         return optionBoxStrings[2];
00649                 else if (whichFeature >= 0)
00650                         return optionBoxStrings[whichFeature + 3];
00651                 else
00652                         return "i don't know!"; 
00653         }
00654 
00655         public double getFeatureValueForPoint(Point p)
00656         {
00657                 double value = 0.0;
00658                 
00659                 for (int i = 0; i < events.size(); i++)
00660                 {
00661                         ChunkVisInfo cVI = (ChunkVisInfo) events.elementAt(i);
00662 
00663                         if (p.x >= cVI.xFeat && p.x <= (cVI.xFeat + cVI.width))
00664                         {
00665                                 if (p.y >= cVI.yFeat && p.y <= (cVI.yFeat + cVI.height))
00666                                 {
00667                                         int whichFeature = cOptions.getSelectedIndex();
00668                                         
00669                                         if (whichFeature == 0)
00670                                                 return cVI.startTime;
00671                                         else if (whichFeature == 1)
00672                                                 return cVI.dstTime;
00673                                         else if (whichFeature == 2)
00674                                                 return cVI.length;
00675                                         else if (whichFeature >= 3)
00676                                         {
00677                                                 int which = whichFeature - 3;
00678                                                 int[] featNum = {0};
00679                                         
00680                                                 for (int j = 0; j < which; j++)
00681                                                         featNum[0] += elementsPerFeature[j];
00682                                                 value = cVI.getFeatures(featNum)[0];
00683                                                 return value;
00684                                         }
00685                                 }
00686                         }
00687                 }
00688                 
00689                 return value;
00690         }
00691 
00692         public void rangeFilterSelectionChanged()
00693         {
00694                 cOptions.setSelectedIndex(featureSelector.getSelectedIndex());  
00695         }
00696         
00697         public void setDragRect(Rectangle r, boolean dS)
00698         {
00699                 dragRect = r;
00700                 dragShift = dS;
00701                 
00702                 if (!dragShift)
00703                 {
00704                         selectNone();
00705                 }
00706                 
00707                 for (int i = 0; i < events.size(); i++)
00708                 {
00709                         ChunkVisInfo cVI = (ChunkVisInfo)events.elementAt(i);
00710                         Rectangle chunkRect = new Rectangle(cVI.xFeat, cVI.yFeat, cVI.width, cVI.height);
00711                         
00712                         if (dragRect.intersects(chunkRect))
00713                                 cVI.selected = true;
00714                 }
00715                 
00716                 dragRect = null;
00717                 dragShift = false;
00718                 
00719                 drawingPanel.repaint(); 
00720         }
00721         
00722         public void actionPerformed(ActionEvent arg0)
00723         {
00724                 super.actionPerformed(arg0);
00725                 
00726                 String command = arg0.getActionCommand();
00727 
00728                 if (command.equals("sOptions"))
00729                 {
00730                         if (sOptions.getSelectedIndex() == 0)
00731                                 ovals = false;
00732                         else
00733                                 ovals = true;
00734                 }
00735                 else if (command.equals("cOptions"))
00736                 {
00737                         //have to avoid a loop!
00738                         if (featureSelector.getSelectedIndex() != cOptions.getSelectedIndex())
00739                                 featureSelector.setSelectedIndex(cOptions.getSelectedIndex());
00740                         updateColorMultipliers();
00741                 }
00742         }
00743 
00744         public void updateOptionBoxes()
00745         {               
00746                 xOptions.removeAllItems();
00747 
00748                 for (int i = 0; i < optionBoxStrings.length; i++)
00749                         xOptions.addItem(optionBoxStrings[i]);
00750                         
00751                 yOptions.removeAllItems();
00752 
00753                 for (int i = 0; i < optionBoxStrings.length; i++)
00754                         yOptions.addItem(optionBoxStrings[i]);
00755                         
00756                 cOptions.removeAllItems();
00757 
00758                 for (int i = 0; i < optionBoxStrings.length; i++)
00759                         cOptions.addItem(optionBoxStrings[i]);
00760                         
00761                 hOptions.removeAllItems();
00762 
00763                 for (int i = 0; i < optionBoxStrings.length; i++)
00764                         hOptions.addItem(optionBoxStrings[i]);
00765                         
00766                 wOptions.removeAllItems();
00767 
00768                 for (int i = 0; i < optionBoxStrings.length; i++)
00769                         wOptions.addItem(optionBoxStrings[i]);
00770                         
00771                 cOptions.removeAllItems();
00772 
00773                 for (int i = 0; i < optionBoxStrings.length; i++)
00774                         cOptions.addItem(optionBoxStrings[i]);
00775         }
00776 
00777         
00778         public void updateColorMultipliers()
00779         {
00780                 super.updateColorMultipliers();
00781                 
00782                 int whichOption;//cOptions.getSelectedIndex();
00783                 
00784                 //first time through we don't have a gui yet...
00785                 if (cOptions == null)
00786                 {
00787                         whichOption = 3;
00788                 }
00789                 else
00790                         whichOption = cOptions.getSelectedIndex();
00791                 
00792                 if (whichOption == 0)
00793                 {
00794                         for (int i = 0; i < numFeatures; i++)
00795                         {
00796                                 colorMultipliers[i] = (numColors - 1.0)/lastStartTime;
00797                         }
00798                 }
00799                 else if (whichOption == 1)
00800                 {
00801                         for (int i = 0; i < numFeatures; i++)
00802                         {
00803                                 colorMultipliers[i] = (numColors - 1.0)/lastStartTime;
00804                         }
00805                 }
00806                 else if (whichOption == 2)
00807                 {
00808                         for (int i = 0; i < numFeatures; i++)
00809                         {
00810                                 colorMultipliers[i] = (numColors - 1.0)/longestChunk;
00811                         }
00812                 }
00813                 else if (whichOption >= 3)
00814                 {
00815                         int wO = whichOption - 3;
00816                         
00817                         for (int i = 0; i < numFeatures; i++)
00818                         {
00819                                 double lowValue = lowestFeatureValue[wO] - lowestFeatureValue[wO];
00820                                 double highValue = highestFeatureValue[wO] - lowestFeatureValue[wO];
00821                                 
00822                                 featureValueSpan[i] = highValue - lowValue;
00823                                 colorMultipliers[i] = (numColors - 1.0)/featureValueSpan[i];
00824                         }
00825                         
00826                 }
00827 
00828         }
00829         
00830         public JPanel buildGUI(Color bgColor)
00831         {
00832                 JPanel panel = super.buildGUI(bgColor);
00833                 
00834                 //dataMappingControlsPanel = new JPanel();
00835                 //dataMappingControlsPanel.setBackground(bgColor);
00836                 
00837                 JPanel xYPanel = new JPanel();
00838                 xYPanel.setBackground(bgColor);
00839                 xYPanel.setLayout(new BoxLayout(xYPanel, BoxLayout.Y_AXIS));
00840                 
00841                 JLabel xCL = new JLabel("x axis: ");
00842                 xCL.setBackground(bgColor);
00843                 xYPanel.add(xCL);
00844                 
00845                 updateOptionBoxStrings();
00846                 
00847                 xOptions = new JComboBox(optionBoxStrings);
00848                 xOptions.setBackground(bgColor);
00849                 xOptions.setActionCommand("xOptions");
00850                 xOptions.addActionListener(this);
00851                 xYPanel.add(xOptions);
00852                 
00853                 JLabel yCL = new JLabel("y axis: ");
00854                 yCL.setBackground(bgColor);
00855                 xYPanel.add(yCL);
00856                 
00857                 yOptions = new JComboBox(optionBoxStrings);
00858                 yOptions.setSelectedIndex(1);
00859                 yOptions.setBackground(bgColor);
00860                 yOptions.setActionCommand("yOptions");
00861                 yOptions.addActionListener(this);
00862                 xYPanel.add(yOptions);
00863                 
00864                 //dataMappingControlsPanel.add(xYPanel);
00865                 controlsPanel.add(xYPanel);
00866                 
00867                 JPanel hwPanel = new JPanel();
00868                 hwPanel.setBackground(bgColor);
00869                 hwPanel.setLayout(new BoxLayout(hwPanel, BoxLayout.Y_AXIS));
00870                 
00871                 JLabel hCL = new JLabel("height: ");
00872                 hCL.setBackground(bgColor);
00873                 hwPanel.add(hCL);
00874                 
00875                 hOptions = new JComboBox(optionBoxStrings);
00876                 hOptions.setSelectedIndex(2);
00877                 hOptions.setBackground(bgColor);
00878                 hOptions.setActionCommand("hOptions");
00879                 hOptions.addActionListener(this);
00880                 hwPanel.add(hOptions);
00881                 
00882                 JLabel wCL = new JLabel("width: ");
00883                 wCL.setBackground(bgColor);
00884                 hwPanel.add(wCL);
00885                 
00886                 wOptions = new JComboBox(optionBoxStrings);
00887                 wOptions.setSelectedIndex(2);
00888                 wOptions.setBackground(bgColor);
00889                 wOptions.setActionCommand("wOptions");
00890                 wOptions.addActionListener(this);
00891                 hwPanel.add(wOptions);
00892                 
00893                 //dataMappingControlsPanel.add(hwPanel);
00894                 controlsPanel.add(hwPanel);
00895                 
00896                 JPanel cPanel = new JPanel();
00897                 cPanel.setBackground(bgColor);
00898                 cPanel.setLayout(new BoxLayout(cPanel, BoxLayout.Y_AXIS));
00899                 
00900                 JLabel cCL = new JLabel("color:");
00901                 cCL.setBackground(bgColor);
00902                 cPanel.add(cCL);
00903                 
00904                 updateOptionBoxStrings();
00905                 cOptions = new JComboBox(optionBoxStrings);
00906                 //start with color = 1st feature
00907                 cOptions.setSelectedIndex(3);
00908                 cOptions.setBackground(bgColor);
00909                 cOptions.setActionCommand("cOptions");
00910                 cOptions.addActionListener(this);
00911                 cPanel.add(cOptions);
00912                 
00913                 JLabel sCL = new JLabel("shape:");
00914                 sCL.setBackground(bgColor);
00915                 cPanel.add(sCL);
00916                 
00917                 String[] shapes = {"rects", "ovals"};
00918                 sOptions = new JComboBox(shapes);
00919                 sOptions.setBackground(bgColor);
00920                 sOptions.setActionCommand("sOptions");
00921                 sOptions.addActionListener(this);
00922                 cPanel.add(sOptions);
00923                 
00924                 /*
00925                 ovalBoxes = new JCheckBox("ovals");
00926                 ovalBoxes.setBackground(bgColor);
00927                 ovalBoxes.setActionCommand("ovals");
00928                 ovalBoxes.addActionListener(this);
00929                 cPanel.add(ovalBoxes);
00930                 */
00931                 //dataMappingControlsPanel.add(cPanel);
00932                 controlsPanel.add(cPanel);
00933                 
00934                 //controlsPanel.add(dataMappingControlsPanel);
00935 
00936                 return panel;
00937         }
00938 }

Generated on Tue Feb 6 19:02:27 2007 for MEAPsoft by doxygen1.2.18