View Javadoc
1 package edu.psu.geovista.app.scatterplot; 2 3 /*** 4 * Title: ScatterPlot 5 * Description: construct a scatterplot 6 * Copyright: Copyright (c) 2001 7 * Company: GeoVISTA Center 8 * @author Xiping Dai 9 * @version 1.0 10 */ 11 import java.lang.*; 12 import java.awt.*; 13 import java.awt.geom.*; 14 import javax.swing.border.*; 15 import java.util.*; 16 import java.io.*; 17 import javax.swing.JPanel; 18 import javax.swing.BorderFactory; 19 import java.awt.event.*; 20 import javax.swing.JFrame; 21 import javax.swing.JLabel; 22 import javax.swing.JTextField; 23 import javax.swing.JButton; 24 import javax.swing.JPopupMenu; 25 import javax.swing.JMenuItem; 26 import javax.swing.JDialog; 27 import javax.swing.event.EventListenerList; 28 import java.awt.event.ActionEvent; 29 import java.awt.event.ActionListener; 30 31 import edu.psu.geovista.symbolization.*; 32 import edu.psu.geovista.classification.BoundaryClassifier; 33 34 import edu.psu.geovista.app.matrix.MatrixElement; 35 import edu.psu.geovista.ui.event.*; 36 import edu.psu.geovista.ui.*; 37 38 39 /*** 40 * put your documentation comment here 41 */ 42 public class ScatterPlot extends JPanel 43 implements ComponentListener, MouseListener, MouseMotionListener, MatrixElement, Serializable, ExcentricLabelClient { 44 45 public static double AXISSPACEPORTION = 1.0/6.0; 46 public static final String COMMAND_POINT_SELECTED = "cmdSel"; 47 public static final String COMMAND_DATARANGE_SET = "cmdset"; 48 private static int RADIUS = 3; //Glyph size 49 transient private int pointSize = RADIUS; 50 transient private int plotOriginX; 51 transient private int plotOriginY; 52 transient private int plotEndX; 53 transient private int plotEndY; 54 transient private Object[] dataObject; 55 transient private double[][] doubleDataArrays; 56 transient private int[] dataIndices; 57 transient private double[] dataX; 58 transient private double[] dataY; 59 transient private int[] exsint; 60 transient private int[] whyint; 61 transient private String[] attributeArrays; 62 transient private String[] observNames; 63 transient private String attributeX; 64 transient private String attributeY; 65 transient private boolean axisOn; 66 transient private Dimension size; 67 transient private Color background; 68 transient private Color foreground; 69 transient private Color selectionColor = Color.blue; 70 private transient boolean selOriginalColorMode = true; 71 transient private Color[] multipleSelectionColors; 72 transient private Color[] colorArrayForObs; 73 transient private DataArray dataArrayX; 74 transient private DataArray dataArrayY; 75 transient private double[] xAxisExtents = new double[2]; 76 transient private double[] yAxisExtents = new double[2]; 77 //private MaxMinCoordinateValue MMexs; 78 //private MaxMinCoordinateValue MMwhy; 79 transient private int selectX = 0; 80 transient private int selectY = 0; 81 transient private int selectWidth = 0; 82 transient private int selectHeight = 0; 83 transient private BasicStroke strokeDashed; 84 transient private Vector selRecords = new Vector();//retiring 85 transient private int[] selections; 86 transient boolean pointSelected = false; 87 transient private int[] conditionArray; 88 transient private int mouseX1, mouseX2, mouseY1, mouseY2; 89 transient private JPopupMenu popup; 90 transient private JTextField xAxisMinField = new JTextField(16); 91 transient private JTextField xAxisMaxField = new JTextField(16); 92 transient private JTextField yAxisMinField = new JTextField(16); 93 transient private JTextField yAxisMaxField = new JTextField(16); 94 transient private EventListenerList listenerListAction = new EventListenerList(); 95 96 //stuff added for colors 97 transient private Color[] pointColors; 98 transient private BivariateColorSymbolClassification bivarColorClasser = 99 new BivariateColorSymbolClassificationSimple(); 100 transient private Histogram histogram = new Histogram(); 101 transient private ExcentricLabels exLabels; 102 transient private BoundaryClassifier xClasser = null; 103 transient private BoundaryClassifier yClasser = null; 104 transient private double[] xBoundaries; 105 transient private double[] yBoundaries; 106 transient private int[] xBoundariesInt; 107 transient private int[] yBoundariesInt; 108 transient private Color[][] classColors; 109 transient int count = 0; 110 111 transient int firstBar; 112 transient int lastBar; 113 transient double yBarDistance; 114 transient double xBarDistance; 115 116 transient private ScatterPlot detailSP; 117 transient private JFrame dummyFrame; 118 transient private JDialog dlgSP; 119 /*** 120 * put your documentation comment here 121 */ 122 public ScatterPlot () { 123 super(); 124 //this.setBorder(BorderFactory.createRaisedBevelBorder()); 125 this.setPreferredSize(new Dimension(300,300)); 126 //...where the GUI is constructed: 127 //Create the popup menu. 128 popup = new JPopupMenu(); 129 JMenuItem menuItem = new JMenuItem("Set Range"); 130 // menuItem.addActionListener(this); 131 popup.add(menuItem); 132 menuItem.addActionListener(new ActionListener() { 133 134 /*** 135 * put your documentation comment here 136 * @param e 137 */ 138 public void actionPerformed (ActionEvent e) { 139 showDialog(400, 400); 140 } 141 }); 142 menuItem = new JMenuItem("Edit"); 143 // menuItem.addActionListener(this); 144 popup.add(menuItem); 145 this.addComponentListener(this); 146 addMouseListener(this); 147 addMouseMotionListener(this); 148 } 149 150 /*** 151 * put your documentation comment here 152 * @param String attributeX 153 * @param String attributeY 154 * @param double[] dataX 155 * @param double[] dataY 156 * @param boolean axisOn 157 */ 158 public ScatterPlot (Object[] dataObject, int[] dataIndices, boolean axisOn, Color c) { 159 //System.out.println("go into scatterplot..."); 160 //this.doubleDataArrays = doubleDataArrays; 161 //this.attributeArrays = (String[])attributeArrays.clone(); 162 this.dataObject = dataObject; 163 this.attributeArrays = (String[])dataObject[0]; 164 int len = attributeArrays.length; 165 if (dataObject[len + 1] == null) { 166 this.observNames = null; 167 } 168 else { 169 this.observNames = (String[])dataObject[len + 1]; 170 } 171 this.dataIndices = (int[])dataIndices; 172 //convert Object array to double arrays. 173 AxisDataSetup (); 174 //initialize(); 175 this.axisOn = axisOn; 176 this.background = c; 177 if (c == Color.black) 178 this.foreground = Color.white; 179 else 180 this.foreground = Color.black; 181 initialize(); 182 } 183 184 /*** 185 * Set up data. 186 * @param data 187 */ 188 public void setDataObject (Object[] data) { 189 if (data == null) 190 System.out.println("data null!"); 191 this.dataObject = data; 192 this.attributeArrays = (String[])dataObject[0]; 193 int len = attributeArrays.length; 194 if (dataObject[len + 1] == null) { 195 this.observNames = null; 196 } 197 else { 198 this.observNames = (String[])dataObject[len + 1]; 199 } 200 this.initExcentricLabels(); 201 } 202 203 /*** 204 * put your documentation comment here 205 * @param doubleDataArrays 206 */ 207 public void setDoubleDataArrays (double[][] doubleDataArrays) { 208 this.doubleDataArrays = doubleDataArrays; 209 } 210 211 /*** 212 * Not used in dataObject version. 213 * @param dataIndices 214 */ 215 public void setDataIndices (int[] dataIndices) { 216 this.dataIndices = (int[])dataIndices.clone(); 217 this.dataX = doubleDataArrays[dataIndices[0]]; 218 this.dataY = doubleDataArrays[dataIndices[1]]; 219 this.attributeX = attributeArrays[dataIndices[0]]; 220 this.attributeY = attributeArrays[dataIndices[1]]; 221 initialize(); 222 } 223 224 /*** 225 * Set up x and y axises in each element by setting the attributes displayed. 226 * @param indices 227 */ 228 public void setElementPosition (int[] indices) { 229 this.dataIndices = (int[])indices; 230 AxisDataSetup (); 231 initialize(); 232 } 233 234 private void AxisDataSetup () { 235 boolean[] dataBoolean; 236 int[] dataInt; 237 int len = 0; 238 if (dataObject[dataIndices[0]] instanceof double[]) { 239 this.dataX = (double[])(dataObject[dataIndices[0]]); 240 len = dataX.length; 241 } 242 else if (dataObject[dataIndices[0]] instanceof int[]) { 243 dataInt = (int[])dataObject[dataIndices[0]]; 244 len = dataInt.length; 245 dataX = new double[len]; 246 for (int i = 0; i < len; i++) { 247 dataX[i] = (double)dataInt[i]; 248 } 249 } 250 else if (dataObject[dataIndices[0]] instanceof boolean[]) { 251 dataBoolean = (boolean[])dataObject[dataIndices[0]]; 252 len = dataBoolean.length; 253 dataX = new double[len]; 254 for (int i = 0; i < len; i++) { 255 if (dataBoolean[i] == true) { 256 dataX[i] = 1; 257 } 258 else 259 dataX[i] = 0; 260 } 261 } 262 if (dataObject[dataIndices[1]] instanceof double[]) { 263 this.dataY = (double[])dataObject[dataIndices[1]]; 264 len = this.dataY.length; 265 } 266 else if (dataObject[dataIndices[1]] instanceof int[]) { 267 dataInt = (int[])dataObject[dataIndices[1]]; 268 len = dataInt.length; 269 dataY = new double[len]; 270 for (int i = 0; i < len; i++) { 271 dataY[i] = (double)dataInt[i]; 272 } 273 } 274 else if (dataObject[dataIndices[1]] instanceof boolean[]) { 275 dataBoolean = (boolean[])dataObject[dataIndices[1]]; 276 len = dataBoolean.length; 277 dataY = new double[len]; 278 for (int i = 0; i < len; i++) { 279 if (dataBoolean[i] == true) { 280 dataY[i] = 1; 281 } 282 else 283 dataY[i] = 0; 284 } 285 } 286 this.attributeX = attributeArrays[dataIndices[0] - 1]; //Minus 1 because dataObject[0] is attribute names. 287 this.attributeY = attributeArrays[dataIndices[1] - 1]; //and real data begin from dataObject[1]. 288 this.selections = new int[len]; 289 this.exsint = new int[len]; 290 this.whyint = new int[len]; 291 } 292 /*** 293 * put your documentation comment here 294 * @return 295 */ 296 public int[] getElementPosition () { 297 return this.dataIndices; 298 } 299 300 /*** 301 * put your documentation comment here 302 * @param attributeArrays 303 */ 304 public void setAttributeArrays (String[] attributeArrays) { 305 this.attributeArrays = attributeArrays; 306 } 307 308 /*** 309 * put your documentation comment here 310 * @param dataX 311 */ 312 public void setX (double[] dataX) { 313 this.dataX = dataX; 314 } 315 316 /*** 317 * put your documentation comment here 318 * @param dataY 319 */ 320 public void setY (double[] dataY) { 321 this.dataY = dataY; 322 } 323 324 // public void setCoordinate (double[][] coordinate){ 325 // this.dataX = coordinate[0][]; 326 // this.dataY = coordinate[1][]; 327 // } 328 public void setAxisOn (boolean axisOn) { 329 this.axisOn = axisOn; 330 } 331 332 /*** 333 * Minimum and maximum values for xAxis. xAxisExtents[0] = min, xAxisExtents[1] = max. 334 * @param xAxisExtents 335 */ 336 public void setXAxisExtents (double[] xAxisExtents) { 337 //System.out.println("set up axis ..." + xAxisExtents[0]); 338 this.xAxisExtents = (double[])xAxisExtents.clone(); 339 //System.out.println("set up axis ..." + xAxisExtents[0]); 340 this.setupDataforDisplay(); 341 repaint(); 342 } 343 344 /*** 345 * put your documentation comment here 346 * @param yAxisExtents 347 */ 348 public void setYAxisExtents (double[] yAxisExtents) { 349 //System.out.println("set up axis ..."); 350 this.yAxisExtents = (double[])yAxisExtents.clone(); 351 this.setupDataforDisplay(); 352 repaint(); 353 } 354 355 /*** 356 * put your documentation comment here 357 * @return 358 */ 359 public double[] getXAxisExtents () { 360 return this.xAxisExtents; 361 } 362 363 /*** 364 * put your documentation comment here 365 * @return 366 */ 367 public double[] getYAxisExtents () { 368 return this.yAxisExtents; 369 } 370 371 /*** 372 * put your documentation comment here 373 * @param conditionArray 374 */ 375 public void setConditionArray (int[] conditionArray) { 376 this.conditionArray = conditionArray; 377 } 378 379 public void setColorArrayForObs(Color[] colorArray){ 380 this.colorArrayForObs = colorArray; 381 } 382 383 /*** 384 * put your documentation comment here 385 * @param c 386 */ 387 public void setBackground (Color c) { 388 if (c == null) 389 return; 390 this.background = c; 391 int colorTotal = c.getRed() + c.getGreen() + c.getBlue(); 392 int greyColor = 128 * 3; 393 if (colorTotal < greyColor) 394 this.foreground = Color.white; 395 else 396 this.foreground = Color.black; 397 this.repaint(); 398 } 399 400 public void setSelectionColor (Color c){ 401 this.selectionColor = c; 402 this.repaint(); 403 } 404 405 public Color getSelectionColor (){ 406 return this.selectionColor; 407 } 408 409 public boolean getSelOriginalColorMode() { 410 return selOriginalColorMode; 411 } 412 413 public void setSelOriginalColorMode(boolean selOriginalColorMode) { 414 this.selOriginalColorMode = selOriginalColorMode; 415 repaint(); 416 } 417 418 public void setPointSelected(boolean pointselected){ 419 this.pointSelected = pointSelected; 420 } 421 422 public void setMultipleSelectionColors (Color[] c){ 423 this.multipleSelectionColors = c; 424 } 425 426 public Color[] getColors(){ 427 return this.pointColors; 428 } 429 430 /*** 431 * Return itself. 432 * @return 433 */ 434 public MatrixElement getThis () { 435 return this; 436 } 437 438 public String getShortDiscription(){ 439 return "XYP"; 440 } 441 /*** 442 * Set up data and axis for drawing the scatter plot. 443 */ 444 private void initialize () { 445 this.setBackground(background); 446 this.dataArrayX = new DataArray(dataX); 447 this.dataArrayY = new DataArray(dataY); 448 this.conditionArray = new int[dataX.length]; 449 this.setBorder(BorderFactory.createLineBorder(Color.gray)); 450 if (axisOn) { 451 xAxisExtents = (double[])this.dataArrayX.getMaxMinCoorValue().clone(); 452 yAxisExtents = (double[])this.dataArrayY.getMaxMinCoorValue().clone(); 453 } 454 else { 455 xAxisExtents[0] = dataArrayX.getExtent()[0]; 456 xAxisExtents[1] = dataArrayX.getExtent()[1]; 457 yAxisExtents[0] = dataArrayY.getExtent()[0]; 458 yAxisExtents[1] = dataArrayY.getExtent()[1]; 459 } 460 461 size = this.getSize(); 462 //added for colors 463 this.makeColors(); 464 this.setupDataforDisplay(); 465 } 466 467 /*** 468 * Set the size of plot area for both axis on and axis off situations. 469 * @param axisOn 470 */ 471 private void setVisibleAxis (boolean axisOn) { 472 if(this.dataArrayX == null){ 473 return; 474 } 475 if (axisOn) { 476 plotOriginX = (int)(this.getWidth()*AXISSPACEPORTION); 477 plotOriginY = (int)(this.getHeight()*(1 - AXISSPACEPORTION)); 478 plotEndX = (int)(this.getSize().getWidth()) - (int)(this.getSize().getWidth()*AXISSPACEPORTION/2); 479 plotEndY = (int)(this.getSize().getHeight()/12); 480 //System.out.println("size width: " + this.getSize().getWidth()); 481 //System.out.println("plot Origin X: " + plotOriginX); 482 } 483 else { 484 plotOriginX = 3; 485 plotOriginY = (int)(this.getSize().getHeight() - 3); 486 plotEndX = (int)(this.getSize().getWidth()) - 3; 487 plotEndY = 3; 488 } 489 490 //set the location of bars and Strings. 491 //firstBar = (int)(yAxisExtents[0]/(this.dataArrayY.getMajorTick())); 492 //lastBar = (int)(yAxisExtents[1]/(this.dataArrayY.getMajorTick())); 493 //double yBarNumber = (yAxisExtents[1] - yAxisExtents[0])/(this.dataArrayY.getMajorTick()); 494 //yBarDistance = ((plotOriginY - plotEndY)/yBarNumber); 495 //double xBarNumber = (xAxisExtents[1] - xAxisExtents[0])/(this.dataArrayX.getMajorTick()); 496 //xBarDistance = ((plotEndX - plotOriginX)/xBarNumber); 497 } 498 499 /*** 500 * Draw the scatter plot. 501 * @param g 502 */ 503 public void paintComponent (Graphics g) { 504 //System.out.println("paint track..." + count ++); 505 // draw a black border and a white background 506 if (this.dataIndices == null) 507 return; 508 g.setColor(background); 509 g.fillRect(0, 0, getSize().width, getSize().height); 510 g.setColor(foreground); 511 this.paintBorder(g); 512 //size = this.getSize(); 513 //setVisibleAxis(axisOn); 514 // if(DefaultBackground == null) DefaultBackground = this.getBackground(); 515 if (axisOn) { 516 drawAxis(g); 517 } 518 drawPlot(g); 519 Graphics2D g2 = (Graphics2D)g; 520 if (exLabels != null && this.axisOn == true) { 521 this.setToolTipText(""); 522 exLabels.paint(g2, getBounds()); 523 } 524 525 } 526 527 /*** 528 * Draw pot (points) on the screen. 529 * @param g 530 */ 531 private void drawPlot (Graphics g) { 532 int plotWidth, plotHeight; 533 plotWidth = (int)this.getWidth(); 534 plotHeight = (int)this.getHeight(); 535 int size; 536 size = (plotWidth < plotHeight) ? plotWidth : plotHeight; 537 this.pointSize = (size < 360) ? size/36 : 10; 538 this.pointSize = (this.pointSize < 3) ? 4 : this.pointSize+1; 539 //System.out.println("attribute equal? " + attributeX.equals(attributeY)); 540 if (this.dataIndices[0] == this.dataIndices[1]) { 541 //draw histogram. 542 histogram.setAxisOn(false); 543 histogram.setVariableName(this.attributeX); 544 histogram.setData(this.dataX); 545 histogram.setXAxisExtents(this.xAxisExtents); 546 histogram.setBackground(background); 547 histogram.setSize(this.getWidth(),this.getHeight()); 548 //histogram.setSelection(this.selRecords); 549 histogram.setSelections(this.selections); 550 histogram.paintComponent(g); 551 Graphics2D g2 = (Graphics2D)g; 552 Color half = new Color(255,255,255,100); 553 g2.setColor(half); 554 g.fillRect(0, 0, getSize().width, getSize().height); 555 g2.setColor(foreground); 556 Font font = new Font("", Font.PLAIN, (int)size/8); 557 g.setFont(font); 558 /*if (attributeX.length()>12){ 559 g.drawString(attributeX, 2, plotHeight/2); 560 }else if (attributeX.length()<=7){ 561 g.drawString(attributeX, plotWidth/4, plotHeight/2); 562 }else { 563 g.drawString(attributeX, plotWidth/8, plotHeight/2); 564 }*/ 565 //font.this.getSize() = (int)plotWidth/12; 566 Font font1 = new Font("", Font.PLAIN, (int)size/12); 567 g.setFont(font1); 568 g.drawLine(0, 0, 5, 5); 569 String maxString = Float.toString((float)(xAxisExtents[1])); 570 g.drawString(maxString, 6, (int)(plotHeight*AXISSPACEPORTION/2) + 2); 571 g.drawLine(0, plotHeight, 5, plotHeight - 5); 572 String minString = Float.toString((float)(xAxisExtents[0])); 573 g.drawString(minString, 6, plotHeight - 5); 574 g.drawLine(plotWidth, plotHeight, plotWidth - 5, plotHeight - 5); 575 g.drawString(maxString, plotWidth - (int)(plotWidth*AXISSPACEPORTION + 5), 576 plotHeight - 5); 577 578 } 579 else { 580 int len = dataArrayX.length(); 581 582 // draw the points 583 if (this.colorArrayForObs != null){ //draw the points with colors getting from setColorArray event. 584 this.drawSlections(g, this.colorArrayForObs, len); 585 586 }else{ //Draw points with colors coming from bivariate color scheme. 587 //Tried to draw background in colors, not working yet. 588 // if (this.xClasser != null){ 589 // //System.out.println("classer is not null"); 590 // for(int i = 0; i < this.classColors.length; i ++){ 591 // for(int j = 0; j < this.classColors[0].length; j ++){ 592 // g.setColor(this.classColors[i][j]); 593 // g.drawRect(this.xBoundariesInt[i], this.yBoundariesInt[j], 594 // this.xBoundariesInt[i+1]-this.xBoundariesInt[i], this.yBoundariesInt[j+1]-this.yBoundariesInt[j]); 595 // } 596 // } 597 // } 598 this.drawSlections(g, this.pointColors, len); 599 } 600 601 Rectangle rec = new Rectangle(selectX, selectY, selectWidth, selectHeight); 602 Graphics2D g2d = (Graphics2D)g; 603 this.drawSelectRectangle(g2d, rec); 604 if (this.multipleSelectionColors != null){ 605 for (int i = 0; i < this.dataX.length; i++) { 606 if (this.multipleSelectionColors[i] != null){ 607 g.setColor(multipleSelectionColors[i]); 608 g.drawOval(exsint[i] - 1, whyint[i] - 1, pointSize, pointSize); 609 g.fillOval(exsint[i] - 1, whyint[i] -1 , pointSize, pointSize); 610 } 611 } 612 } 613 } 614 } 615 616 private void drawSlections(Graphics g, Color[] colorNonSelected, int len){ 617 if (this.pointSelected == false){ //only draw original points. 618 for (int i = 0; i < len; i++) { 619 if ((exsint[i] <= this.plotEndX) && (exsint[i] >= plotOriginX) && (whyint[i] <= plotOriginY) 620 && (whyint[i] >= plotEndY) && (conditionArray[i] > -1)){ 621 622 g.setColor(colorNonSelected[i]); 623 //g.drawOval(exsint[i] - 1, whyint[i] - 1, pointSize, pointSize); 624 g.fillOval(exsint[i] - 2, whyint[i] - 2, pointSize, pointSize); 625 } 626 } 627 }else{ //draw original points and selected points. 628 //according to the color mode, draw selected points and non-selected points. 629 if (this.selOriginalColorMode == false){ 630 for (int i = 0; i < len; i++) { 631 if ((exsint[i] <= this.plotEndX) && (exsint[i] >= plotOriginX) && (whyint[i] <= plotOriginY) 632 && (whyint[i] >= plotEndY) && (conditionArray[i] > -1)){ 633 634 g.setColor(colorNonSelected[i]); 635 //g.drawOval(exsint[i] - 1, whyint[i] - 1, pointSize, pointSize); 636 g.fillOval(exsint[i] - 2, whyint[i] - 2, pointSize, pointSize); 637 } 638 } 639 for (int i = 0; i < len; i++) { 640 g.setColor(this.selectionColor); 641 if ((exsint[i] <= this.plotEndX) && (exsint[i] >= plotOriginX) && (whyint[i] <= plotOriginY) 642 && (whyint[i] >= plotEndY) && (conditionArray[i] > -1)){ 643 644 if (this.selections[i] == 1){ 645 //g.drawOval(exsint[i] - 1, whyint[i] - 1, pointSize, pointSize); 646 g.fillOval(exsint[i] - 2, whyint[i] - 2, pointSize, pointSize); 647 } 648 } 649 } 650 }else{ 651 for (int i = 0; i < len; i++) { 652 if ((exsint[i] <= this.plotEndX) && (exsint[i] >= plotOriginX) && (whyint[i] <= plotOriginY) 653 && (whyint[i] >= plotEndY) && (conditionArray[i] > -1)){ 654 655 g.setColor(colorNonSelected[i]); 656 g.drawOval(exsint[i] - 2, whyint[i] - 2, pointSize-2, pointSize-2); 657 } 658 } 659 for (int i = 0; i < len; i++) { 660 if ((exsint[i] <= this.plotEndX) && (exsint[i] >= plotOriginX) && (whyint[i] <= plotOriginY) 661 && (whyint[i] >= plotEndY) && (conditionArray[i] > -1)){ 662 g.setColor(colorNonSelected[i]); 663 if (this.selections[i] == 1){ 664 //g2.drawOval(exsint[i] - 1, whyint[i] - 1, pointSize, pointSize); 665 g.fillOval(exsint[i] - 2, whyint[i] - 2, pointSize, pointSize); 666 //g2.fillRect(exsint[i] - 1, whyint[i] - 1, pointSize, pointSize); 667 //g.drawOval(exsint[i] - 1, whyint[i] - 1, pointSize+1, pointSize+1); 668 } 669 } 670 } 671 } 672 } 673 } 674 /*** 675 * Draw axises for scatterplot. 676 * @param g 677 */ 678 private void drawAxis (Graphics g) { 679 int plotWidth, plotHeight; 680 plotWidth = (int)this.getWidth(); 681 plotHeight = (int)this.getHeight(); 682 //System.out.println(plotHeight); 683 if (this.dataIndices[0] == this.dataIndices[1]) { 684 /*Font font; 685 if (plotWidth < plotHeight){ 686 font = new Font("", Font.PLAIN, (int)plotWidth/10); 687 }else{ 688 font = new Font("", Font.PLAIN, (int)plotHeight/10); 689 } 690 g.setFont(font); 691 g.drawString(attributeX, plotWidth/3, plotHeight/2);*/ 692 } 693 else { 694 //System.out.println(plotOriginX); 695 // draw the lines 696 g.setColor(foreground); 697 g.drawLine(plotOriginX, plotEndY, plotOriginX, plotOriginY); 698 g.drawLine(plotOriginX, plotOriginY, plotEndX, plotOriginY); 699 // draw tick bars for scales on Y coordinate 700 int fontSize; 701 fontSize = (plotWidth < plotHeight) ? plotWidth : plotHeight; 702 fontSize = ((int)(fontSize/32) < 9) ? 9 : fontSize/32; 703 /*if (plotWidth < plotHeight){ 704 if (plotWidth < 300){ 705 fontSize = 9; 706 } else { 707 fontSize = (int)(plotWidth/32); 708 } 709 }else { 710 if (plotHeight < 300){ 711 fontSize = 9; 712 } else { 713 fontSize = (int)(plotHeight/32); 714 } 715 }*/ 716 Font font = new Font("", Font.PLAIN, fontSize); 717 g.setFont(font); 718 String scaleStringY; 719 int i; 720 int realBarNum = 0; 721 double barNumber = this.dataArrayY.getTickNumber(); 722 int firstBar = (int)(yAxisExtents[0]/(this.dataArrayY.getMajorTick())); 723 int lastBar = (int)(yAxisExtents[1]/(this.dataArrayY.getMajorTick())); 724 //double barNumber = (yAxisExtents[1] - yAxisExtents[0])/(this.dataArrayY.getMajorTick()); 725 double yBarDistance = ((plotOriginY - plotEndY)/barNumber); 726 for (i = firstBar; i <= lastBar + 0.00001; i++) { 727 //for (i = 0; i <= barNumber; i++) { 728 g.drawLine(plotOriginX - 3, plotEndY + (int)(realBarNum*yBarDistance), plotOriginX, 729 plotEndY + (int)(realBarNum*yBarDistance)); 730 if (Math.abs(this.dataArrayY.getMajorTick()) <= 1) { 731 scaleStringY = Float.toString((float)(yAxisExtents[1] - realBarNum*this.dataArrayY.getMajorTick())); 732 } 733 else { 734 scaleStringY = Integer.toString((int)(yAxisExtents[1] - realBarNum*this.dataArrayY.getMajorTick())); 735 } 736 g.drawString(scaleStringY, plotOriginX - (int)(plotWidth*AXISSPACEPORTION/2), 737 plotEndY + (int)(realBarNum*yBarDistance + yBarDistance*1/6)); 738 739 //draw background grid 740 g.setColor(Color.lightGray); 741 g.drawLine(plotOriginX, plotEndY + (int)(realBarNum*yBarDistance), plotEndX, 742 plotEndY + (int)(realBarNum*yBarDistance)); 743 g.setColor(this.foreground); 744 realBarNum ++; 745 } 746 // draw tick bars for scales on X coordinate 747 realBarNum = 0; 748 barNumber = this.dataArrayX.getTickNumber(); 749 //barNumber = (xAxisExtents[1] - xAxisExtents[0])/(this.dataArrayX.getMajorTick()); 750 double xBarDistance = ((plotEndX - plotOriginX)/barNumber); 751 String scaleStringX; 752 for (i = (int)(xAxisExtents[0]/(this.dataArrayX.getMajorTick())); i <= (int)(xAxisExtents[1]/(this.dataArrayX.getMajorTick())) + 0.0001; i++) { 753 //for (i = 0; i <= barNumber; i++) { 754 g.drawLine(plotOriginX + (int)(realBarNum*xBarDistance), plotOriginY, plotOriginX 755 + (int)(realBarNum*xBarDistance), plotOriginY + 3); 756 if (Math.abs(this.dataArrayX.getMajorTick()) <= 1) { 757 scaleStringX = Float.toString((float)(xAxisExtents[0] + realBarNum*this.dataArrayX.getMajorTick())); 758 } 759 else { 760 scaleStringX = Integer.toString((int)(xAxisExtents[0] + realBarNum*this.dataArrayX.getMajorTick())); 761 } 762 Graphics2D g2d = (Graphics2D)g; 763 g2d.rotate(-Math.PI/2, plotOriginX - 2 + (int)(realBarNum*xBarDistance), plotOriginY 764 + plotHeight*AXISSPACEPORTION*2/3); 765 g.drawString(scaleStringX, plotOriginX - 2 + (int)(realBarNum*xBarDistance), 766 plotOriginY + (int)(plotHeight*AXISSPACEPORTION*2/3 - 1)); 767 g2d.rotate(Math.PI/2, plotOriginX - 2 + (int)(realBarNum*xBarDistance), plotOriginY 768 + plotHeight*AXISSPACEPORTION*2/3); 769 //graw background grid 770 g.setColor(Color.lightGray); 771 g.drawLine(plotOriginX + (int)(realBarNum*xBarDistance), plotOriginY, plotOriginX 772 + (int)(realBarNum*xBarDistance), plotEndY); 773 g.setColor(this.foreground); 774 realBarNum ++; 775 } 776 font = new Font("", Font.PLAIN, fontSize + 3); 777 g.setFont(font); 778 //draw X axis attribute string 779 g.drawString(attributeX, plotOriginX + (plotEndX - plotOriginX)/2 - plotWidth/12, 780 plotOriginY + plotHeight/6 - 5); 781 //draw Y axis attribute string. Need rotation for drawing the string vertically. 782 Graphics2D g2d = (Graphics2D)g; 783 g2d.rotate(-Math.PI/2, plotOriginX - plotWidth/9, plotOriginY - (plotOriginY 784 - plotEndY)/3); 785 g2d.drawString(attributeY, plotOriginX - plotWidth/9, plotOriginY - (plotOriginY 786 - plotEndY)/3); 787 g2d.rotate(+Math.PI/2, plotOriginX - plotWidth/9, plotOriginY - (plotOriginY 788 - plotEndY)/3); 789 } 790 } 791 792 /*** 793 * Return selections from this scatterplot. 794 * @return 795 */ 796 public Vector getSelectedObservations () { 797 return selRecords; 798 } 799 800 /*** 801 * Set up selections from other components. 802 * @param selectedObservations 803 */ 804 public void setSelectedObservations (Vector selectedObservations) { 805 selRecords = selectedObservations; 806 } 807 808 public void setSelections (int[] selectedObservations) { 809 System.out.println("in SP setSelections"); 810 if (selections == null || selectedObservations == null){ 811 return; 812 } 813 if (selections.length != selectedObservations.length){ 814 for (int i = 0; i < selections.length; i++){ 815 selections[i] = 0; 816 } 817 for (int i = 0; i < selectedObservations.length; i++){ 818 selections[selectedObservations[i]] = -1; 819 } 820 } else { 821 selections = selectedObservations; 822 } 823 this.pointSelected = false; 824 for (int i = 0; i < selections.length; i++){ 825 if (selections[i] ==1){ 826 this.pointSelected = true; 827 return; 828 } 829 } 830 } 831 832 /*** 833 * Return selections from this scatterplot. 834 * @return 835 */ 836 public int[] getSelections () { 837 return this.selections; 838 } 839 840 public void setIndication(int indication){ 841 //noop 842 } 843 /*** 844 * Calculate scale between real data and integer data for showing up on screen. 845 * @param min 846 * @param max 847 * @param dataMin 848 * @param dataMax 849 * @return scale 850 */ 851 private double getScale (int min, int max, double dataMin, double dataMax) { 852 double scale; 853 scale = (max - min)/(dataMax - dataMin); 854 return scale; 855 } 856 857 /*** 858 * Convert the single value to integer value worked on screen. 859 * @param data 860 * @param scale 861 * @param min 862 * @param dataMin 863 * @return valueScreen 864 */ 865 private int getValueScreen (double data, double scale, int min, double dataMin) { 866 int valueScreen; 867 if (Double.isNaN(data)) { 868 valueScreen = Integer.MIN_VALUE; 869 } 870 else { 871 valueScreen = (int)((data - dataMin)*scale + min); 872 } 873 return valueScreen; 874 } 875 876 /*** 877 * Convert the numeric values of observations to integer value worked on screen. 878 * @param dataArray 879 * @param scale 880 * @param min 881 * @param dataMin 882 * @return valueScreen 883 */ 884 private int[] getValueScreen (double[] dataArray, double scale, int min, double dataMin) { 885 int[] valueScreen = new int[dataArray.length]; 886 for (int i = 0; i < dataArray.length; i++) { 887 if (Double.isNaN(dataArray[i])) { 888 valueScreen[i] = Integer.MIN_VALUE; 889 } 890 else { 891 valueScreen[i] = (int)((dataArray[i] - dataMin)*scale + min); 892 } 893 } 894 return valueScreen; 895 } 896 897 private void setupDataforDisplay(){ 898 //System.out.println("In setup data for display ..." + xAxisExtents[0]); 899 this.setVisibleAxis(axisOn); 900 if (dataArrayX == null) return; 901 int len = dataArrayX.length(); 902 if (len != dataArrayY.length()) 903 return; 904 //exsint = new int[len]; 905 //whyint = new int[len]; 906 //get positions on screen 907 double xScale; 908 double yScale; 909 xScale = getScale(plotOriginX, plotEndX, xAxisExtents[0], xAxisExtents[1]); 910 exsint = getValueScreen(dataX, xScale, plotOriginX, xAxisExtents[0]); 911 yScale = getScale(plotOriginY, plotEndY, yAxisExtents[0], yAxisExtents[1]); 912 whyint = getValueScreen(dataY, yScale, plotOriginY, yAxisExtents[0]); 913 //get class boundaries' positions on screen 914 if(this.xBoundaries != null && this.yBoundaries != null){ 915 System.out.println("x and y boundaries are not null."); 916 this.xBoundariesInt = new int[this.xBoundaries.length]; 917 this.yBoundariesInt = new int[this.yBoundaries.length]; 918 this.xBoundariesInt = getValueScreen(this.xBoundaries, xScale, plotOriginX, xAxisExtents[0]); 919 this.yBoundariesInt = getValueScreen(this.yBoundaries, yScale, plotOriginY, yAxisExtents[0]); 920 } 921 } 922 //start excentric labeling stuff 923 private void initExcentricLabels(){ 924 this.exLabels = new ExcentricLabels(); 925 exLabels.setComponent(this); 926 exLabels.setOpaque(true); 927 Color halfWhite = new Color(255,255,255,123); 928 exLabels.setBackgroundColor(halfWhite); 929 this.addMouseListener(exLabels); 930 931 } 932 public String getObservationLabel(int i){ 933 String[] labels = this.observNames; 934 String label = labels[i]; 935 return label; 936 } 937 938 public Shape getShapeAt(int i){ 939 int x = this.exsint[i]; 940 int y = this.whyint[i]; 941 Ellipse2D circle = new Ellipse2D.Float(x,y,this.pointSize,this.pointSize); 942 943 return circle; 944 } 945 public int[] pickAll(Rectangle2D hitBox){ 946 Vector hits = new Vector(); 947 for (int i = 0; i < dataX.length; i++) { 948 if (hitBox.contains(exsint[i], whyint[i]) && (conditionArray[i] > -1)) { 949 Integer bigI = new Integer(i); 950 hits.add(bigI); 951 } 952 } 953 int[] intHits = new int[hits.size()]; 954 for (int i = 0; i < hits.size(); i++){ 955 956 intHits[i] = ((Integer)hits.get(i)).intValue(); 957 } 958 return intHits; 959 } 960 //end excentric labeling stuff 961 962 public void componentHidden(ComponentEvent e) { 963 964 } 965 966 public void componentMoved(ComponentEvent e) { 967 968 } 969 970 public void componentResized(ComponentEvent e) { 971 //System.out.println("in component resized"); 972 this.setupDataforDisplay(); 973 this.repaint(); 974 } 975 976 public void componentShown(ComponentEvent e) { 977 } 978 979 980 /*** 981 * Begin the drawing of selection region (box). 982 * @param e 983 */ 984 public void mousePressed (MouseEvent e) { 985 if (dataIndices[0] == dataIndices[1]) 986 return; 987 if (e.isPopupTrigger()) 988 maybeShowPopup(e); 989 //selRecords.clear(); 990 mouseX1 = e.getX(); 991 mouseY1 = e.getY(); 992 } 993 994 /*** 995 * Work with mouseDragged to draw a selection region (box) for selection. 996 * @param e 997 */ 998 public void mouseReleased (MouseEvent e) { 999 if (dataIndices[0] == dataIndices[1]) 1000 return; 1001 if (e.isPopupTrigger()) 1002 maybeShowPopup(e); 1003 mouseX2 = e.getX(); 1004 mouseY2 = e.getY(); 1005 if ((Math.abs(mouseX1-mouseX2) < 3) && (Math.abs(mouseY1-mouseY2) < 3)){ 1006 return; 1007 } 1008 //With shift pressed, it will continue to select. 1009 if (!(e.isShiftDown())){ 1010 //selRecords.clear(); 1011 //zero all selection indication to deselect them. 1012 for (int i = 0; i < this.selections.length; i ++){ 1013 this.selections[i] = 0; 1014 } 1015 } 1016 if (mouseX1 <= mouseX2 && mouseY1 <= mouseY2) { 1017 selectX = mouseX1; 1018 selectY = mouseY1; 1019 selectWidth = mouseX2 - mouseX1; 1020 selectHeight = mouseY2 - mouseY1; 1021 } 1022 if (mouseX2 < mouseX1 && mouseY1 <= mouseY2) { 1023 selectX = mouseX2; 1024 selectY = mouseY1; 1025 selectWidth = mouseX1 - mouseX2; 1026 selectHeight = mouseY2 - mouseY1; 1027 } 1028 if (mouseX1 <= mouseX2 && mouseY2 < mouseY1) { 1029 selectX = mouseX1; 1030 selectY = mouseY2; 1031 selectWidth = mouseX2 - mouseX1; 1032 selectHeight = mouseY1 - mouseY2; 1033 } 1034 if (mouseX2 < mouseX1 && mouseY2 < mouseY1) { 1035 selectX = mouseX2; 1036 selectY = mouseY2; 1037 selectWidth = mouseX1 - mouseX2; 1038 selectHeight = mouseY1 - mouseY2; 1039 } 1040 Rectangle rec = new Rectangle(selectX, selectY, selectWidth, selectHeight); 1041 pointSelected = false; 1042 int j = 0; 1043 for (int i = 0; i < dataX.length; i++) { 1044 if (rec.contains(exsint[i], whyint[i]) && (conditionArray[i] > -1)) { 1045 Integer bigI = new Integer(i); 1046 //selRecords.add(bigI); 1047 this.selections[i] = 1;//new selection struction int[] 1048 pointSelected = true; 1049 j++; 1050 } 1051 } 1052 selectWidth = 0; 1053 selectHeight = 0; 1054 //selRecords.trimToSize(); 1055 this.multipleSelectionColors = null; 1056 //this.drawSelectRectangle(rec); 1057 repaint(); 1058 //System.out.println("about to fire mouse released"); 1059 fireActionPerformed(COMMAND_POINT_SELECTED); 1060 } 1061 1062 /*** 1063 * put your documentation comment here 1064 * @param e 1065 */ 1066 public void mouseExited (MouseEvent e) { 1067 //System.out.println("mouse exited: "); 1068 } 1069 1070 /*** 1071 * Work with mouseReleased to draw a selection region (box) for selection. 1072 * @param e 1073 */ 1074 public void mouseDragged (MouseEvent e) { 1075 if (dataIndices[0] == dataIndices[1]) 1076 return; 1077 //if (e.isPopupTrigger()) 1078 // maybeShowPopup(e); 1079 mouseX2 = e.getX(); 1080 mouseY2 = e.getY(); 1081 if ((Math.abs(mouseX1-mouseX2) < 3) && (Math.abs(mouseY1-mouseY2) < 3)){ 1082 return; 1083 } 1084 //System.out.println("mouse released: " + "mouseX2" + mouseX2 + "mouseY2" + mouseY2); 1085 if (mouseX1 <= mouseX2 && mouseY1 <= mouseY2) { 1086 selectX = mouseX1; 1087 selectY = mouseY1; 1088 selectWidth = mouseX2 - mouseX1; 1089 selectHeight = mouseY2 - mouseY1; 1090 } 1091 if (mouseX2 < mouseX1 && mouseY1 <= mouseY2) { 1092 selectX = mouseX2; 1093 selectY = mouseY1; 1094 selectWidth = mouseX1 - mouseX2; 1095 selectHeight = mouseY2 - mouseY1; 1096 } 1097 if (mouseX1 <= mouseX2 && mouseY2 < mouseY1) { 1098 selectX = mouseX1; 1099 selectY = mouseY2; 1100 selectWidth = mouseX2 - mouseX1; 1101 selectHeight = mouseY1 - mouseY2; 1102 } 1103 if (mouseX2 < mouseX1 && mouseY2 < mouseY1) { 1104 selectX = mouseX2; 1105 selectY = mouseY2; 1106 selectWidth = mouseX1 - mouseX2; 1107 selectHeight = mouseY1 - mouseY2; 1108 } 1109 Rectangle rec = new Rectangle(selectX, selectY, selectWidth, selectHeight); 1110 //this.drawSelectRectangle(rec); 1111 repaint(); 1112 } 1113 1114 /*** 1115 * Mouse over, it will show the values for current point by tool tip. 1116 * @param e 1117 */ 1118 public void mouseMoved (MouseEvent e) { 1119 if (e != null&&this.axisOn==false){ 1120 this.makeToolTip(e.getX(),e.getY()); 1121 e.consume(); 1122 } 1123 } 1124 1125 /*** 1126 * put your documentation comment here 1127 * @param e 1128 */ 1129 public void mouseEntered (MouseEvent e) { 1130 } 1131 1132 /*** 1133 * Mouse click for selecting or brushing points (observations). 1134 * @param e 1135 */ 1136 public void mouseClicked (MouseEvent e) { 1137 //System.out.println("mouse clicked: "); 1138 int count = e.getClickCount(); 1139 //moduleBody.selected(true); 1140 int[] mousePos = new int[2]; 1141 mousePos[0] = e.getX(); 1142 mousePos[1] = e.getY(); 1143 //single click, select performed. 1144 Integer bigI; 1145 if (count == 1) { 1146 boolean pointSelected = false; 1147 if (dataIndices[0] != dataIndices[1]) { 1148 for (int i = 0; i < dataX.length; i++) { 1149 if ((exsint[i] - 5 < mousePos[0]) && (mousePos[0] < exsint[i] + 5) && 1150 (whyint[i] - 5 < mousePos[1]) && (mousePos[1] < whyint[i] + 5) && (conditionArray[i] > -1)) { 1151 bigI = new Integer(i); 1152 //selRecords.add(bigI); 1153 this.selections[i] = 1; 1154 pointSelected = true; 1155 } 1156 } 1157 //while (e.isShiftDown()); 1158 fireActionPerformed(COMMAND_POINT_SELECTED); 1159 } 1160 } 1161 //double click, pop up a detail scatter plot. 1162 if (count == 2) // This is a double-click or triple... 1163 { 1164 if (dataIndices[0] != dataIndices[1]) { 1165 //ScatterPlot detailSP = new ScatterPlot(dataObject, 1166 // dataIndices, true, background); 1167 //JFrame f = new JFrame("Detailed Scatter Plot"); 1168 //if (detailSP == null){ 1169 ScatterPlot detailSP = new ScatterPlot(); 1170 detailSP.setDataObject(dataObject); 1171 detailSP.setAxisOn(true); 1172 detailSP.setElementPosition(dataIndices); 1173 dummyFrame = new JFrame("Detailed Scatter Plot"); 1174 dlgSP = new JDialog(dummyFrame, "Detailed Scatter Plot", true); 1175 dlgSP.setLocation(300, 300); 1176 dlgSP.setSize(300, 300); 1177 dlgSP.getContentPane().setLayout(new BorderLayout()); 1178 dlgSP.getContentPane().add(detailSP, BorderLayout.CENTER); 1179 //} 1180 1181 detailSP.setBackground(background); 1182 detailSP.setBivarColorClasser(this.bivarColorClasser, false); 1183 detailSP.setColorArrayForObs(this.colorArrayForObs); 1184 //detailSP.setSelectedObservations(selRecords); 1185 detailSP.setSelectionColor(this.selectionColor); 1186 detailSP.setSelOriginalColorMode(this.selOriginalColorMode); 1187 detailSP.setSelections(this.selections); 1188 detailSP.setXAxisExtents(this.xAxisExtents);//? 1189 detailSP.setYAxisExtents(this.yAxisExtents); 1190 1191 1192 // dummyFrame.setLocation(300, 300); 1193 // dummyFrame.setSize(300, 300); 1194 // dummyFrame.getContentPane().setLayout(new BorderLayout()); 1195 // dummyFrame.getContentPane().add(detailSP, BorderLayout.CENTER); 1196 detailSP.addActionListener(new ActionListener() { 1197 1198 /*** 1199 * put your documentation comment here 1200 * @param e 1201 */ 1202 public void actionPerformed (ActionEvent e) { 1203 //System.out.println("something came from detailed one."); 1204 ScatterPlot detailSP = (ScatterPlot)e.getSource(); 1205 String command = e.getActionCommand(); 1206 if (command.compareTo(ScatterPlot.COMMAND_POINT_SELECTED) == 0) { 1207 //System.out.println("SPMC.plotUnitPanel.actionPerformed(), point selected"); 1208 //Vector selRecords = detailSP.getSelectedObservations(); 1209 int[] selections = detailSP.getSelections(); 1210 // Don't recall the scatterplot which generated the original event 1211 //ScatterPlot.this.setSelectedObservations(selRecords); 1212 ScatterPlot.this.setSelections(selections); 1213 ScatterPlot.this.fireActionPerformed(COMMAND_POINT_SELECTED); 1214 } 1215 else if(command.compareTo(ScatterPlot.COMMAND_DATARANGE_SET)==0){ 1216 double[] dataArrayX = detailSP.getXAxisExtents(); 1217 double[] dataArrayY = detailSP.getYAxisExtents(); 1218 ScatterPlot.this.setXAxisExtents(dataArrayX); 1219 ScatterPlot.this.setYAxisExtents(dataArrayY); 1220 fireActionPerformed(COMMAND_DATARANGE_SET); 1221 } 1222 //System.err.println("Unknown command! = " + command); 1223 } 1224 }); 1225 dlgSP.show(); 1226 } else { 1227 Histogram histogram = new Histogram(); 1228 histogram.setVariableName(this.attributeX); 1229 histogram.setData(this.dataX); 1230 //histogram.setSelections(this.selections); 1231 histogram.setBackground(background); 1232 JFrame dummyFrame = new JFrame(); 1233 JDialog dlgSP = new JDialog(dummyFrame, "Histogram", true); 1234 dlgSP.setLocation(300, 300); 1235 dlgSP.setSize(300, 300); 1236 dlgSP.getContentPane().setLayout(new BorderLayout()); 1237 dlgSP.getContentPane().add(histogram, BorderLayout.CENTER); 1238 histogram.addActionListener(new ActionListener() { 1239 1240 /*** 1241 * put your documentation comment here 1242 * @param e 1243 */ 1244 public void actionPerformed (ActionEvent e) { 1245 Histogram histogram = (Histogram)e.getSource(); 1246 //Vector selRecords = histogram.getSelection(); 1247 int[] selection = histogram.getSelections(); 1248 //ScatterPlot.this.setSelectedObservations(selRecords); 1249 ScatterPlot.this.setSelections(selection); 1250 ScatterPlot.this.fireActionPerformed(COMMAND_POINT_SELECTED); 1251 } 1252 }); 1253 dlgSP.show(); 1254 } 1255 } 1256 } 1257 1258 private void drawSelectRectangle(Graphics2D g2d, Rectangle rec) { 1259 1260 Stroke tempStroke = g2d.getStroke(); 1261 float[] dash = new float[3]; 1262 dash[0] = (float)5.0; 1263 dash[1] = (float)7.0; 1264 dash[2] = (float)5.0; 1265 BasicStroke dashStroke = new BasicStroke((float)1.0, BasicStroke.CAP_SQUARE, 1266 BasicStroke.JOIN_MITER, (float)10.0, dash, 0); 1267 g2d.setStroke(dashStroke); 1268 g2d.setPaintMode(); 1269 g2d.setColor(foreground); 1270 g2d.drawRect(selectX, selectY, selectWidth, selectHeight); 1271 // Draw selected observations. 1272 //if (!selRecords.isEmpty()) { 1273 //g2d.setXORMode(background); 1274 g2d.drawRect(selectX, selectY, selectWidth, selectHeight); 1275 g2d.setStroke(tempStroke); 1276 //g2d.setColor(selectionColor); 1277 //int i = 0; 1278 //for (Enumeration selEnum = selRecords.elements(); selEnum.hasMoreElements();) { 1279 // i = ((Integer)selEnum.nextElement()).intValue(); 1280 // if ((exsint[i] != Integer.MIN_VALUE) && (whyint[i] != Integer.MIN_VALUE) 1281 // && (conditionArray[i] > -1)) { 1282 //g.drawOval(exsint[i] - 1, whyint[i] - 1, pointSize, pointSize); 1283 //g.fillOval(exsint[i] - 1, whyint[i] -1 , pointSize, pointSize); 1284 // } 1285 //} 1286 //g.setColor(foreground); 1287 //} 1288 1289 /* if (g == null) { 1290 return; 1291 } 1292 BasicStroke strokeSave = (BasicStroke) g.getStroke(); 1293 1294 float[] dash = new float[3]; 1295 dash[0] = (float)5.0; 1296 dash[1] = (float)7.0; 1297 dash[2] = (float)5.0; 1298 if (strokeDashed == null) { 1299 // We only need to create this once. We can't do it in our initialize(), since 1300 // we don't have a Graphics2D yet 1301 strokeDashed = new BasicStroke( 1302 strokeSave.getLineWidth(), 1303 strokeSave.getEndCap(), 1304 strokeSave.getLineJoin(), 1305 strokeSave.getMiterLimit(), 1306 dash, 0); 1307 } 1308 1309 // Now, set our stroke to a dashed line 1310 g.setStroke(strokeDashed); 1311 1312 g.setColor(this.foreground); 1313 g.setXORMode(this.background); 1314 1315 // Actually draw the rectangle 1316 g.drawRect(rec.x, rec.y, rec.width, rec.height); 1317 1318 // Restore our original stroke 1319 g.setStroke(strokeSave);*/ 1320 } 1321 1322 private void makeToolTip(int x, int y) { 1323 int arrayIndex = -1; 1324 //boolean pointMove = false; 1325 if (dataIndices == null){ 1326 return; 1327 } 1328 if (exsint == null){ 1329 return; 1330 } 1331 if ((dataIndices[0] != dataIndices[1])&&(exsint != null) && (whyint != null)) { 1332 for (int i = 0; i < dataX.length; i++) { 1333 if ((exsint[i] - 3 < x) && (x < exsint[i] + 3) && 1334 (whyint[i] - 3 < y) && (y < whyint[i] + 3) && (conditionArray[i] > -1)) { 1335 //pointMove = true; 1336 arrayIndex = i; 1337 } 1338 } 1339 } 1340 if (arrayIndex >=0){ 1341 //setting multi-line tool tip 1342 //b.setToolTipText("<html>ToolTip : 1st Line<br>2nd Line<br> 3rd Line </html>"); 1343 String xVal = Double.toString(dataX[arrayIndex]); 1344 String yVal = Double.toString(dataY[arrayIndex]); 1345 String s = "<html> "; 1346 //s = s + "Idx: " + new Integer(arrayIndex).toString() + " "; 1347 if (this.observNames != null) { 1348 s = s + "Name = " 1349 + observNames[arrayIndex] + "<br>"; 1350 } 1351 1352 s = s + attributeX 1353 + " = " + xVal + "<br>" 1354 + attributeY 1355 + " = " + yVal + "</html>"; 1356 1357 this.setToolTipText(s); 1358 } //end if 1359 } 1360 /*** 1361 * New data ranges setup dialog. 1362 * @param x 1363 * @param y 1364 */ 1365 private void showDialog (int x, int y) { 1366 JFrame dummyFrame = new JFrame(); 1367 JDialog dialog = new JDialog(dummyFrame, "Data Range Configuer", true); 1368 JButton actionButton; 1369 JButton resetButton; 1370 dialog.setLocation(x, y); 1371 dialog.setSize(300, 150); 1372 dialog.getContentPane().setLayout(new GridLayout(5, 2)); 1373 xAxisMinField.setText(Double.toString(xAxisExtents[0])); 1374 xAxisMaxField.setText(Double.toString(xAxisExtents[1])); 1375 yAxisMinField.setText(Double.toString(yAxisExtents[0])); 1376 yAxisMaxField.setText(Double.toString(yAxisExtents[1])); 1377 //create buttons for action 1378 actionButton = new JButton("OK"); 1379 actionButton.addActionListener(new java.awt.event.ActionListener() { 1380 1381 /*** 1382 * Button to set up new data ranges shown up in scatter plot. 1383 * @param e 1384 */ 1385 public void actionPerformed (ActionEvent e) { 1386 try { 1387 actionButton_actionPerformed(e); 1388 } catch (Exception exception) {} 1389 } 1390 }); 1391 resetButton = new JButton("Reset"); 1392 resetButton.addActionListener(new java.awt.event.ActionListener() { 1393 1394 /*** 1395 * put your documentation comment here 1396 * @param e 1397 */ 1398 public void actionPerformed (ActionEvent e) { 1399 resetButton_actionPerformed(e); 1400 } 1401 }); 1402 //dialog.getContentPane().add(new JLabel("X Range Min:")); 1403 dialog.getContentPane().add(new JLabel((this.attributeX + " Min"))); 1404 dialog.getContentPane().add(xAxisMinField); 1405 dialog.getContentPane().add(new JLabel((this.attributeX + " Max"))); 1406 dialog.getContentPane().add(xAxisMaxField); 1407 dialog.getContentPane().add(new JLabel((this.attributeY + " Min"))); 1408 dialog.getContentPane().add(yAxisMinField); 1409 dialog.getContentPane().add(new JLabel((this.attributeY + " Max"))); 1410 dialog.getContentPane().add(yAxisMaxField); 1411 dialog.getContentPane().add(actionButton); 1412 dialog.getContentPane().add(resetButton); 1413 dialog.show(); 1414 } 1415 1416 /*** 1417 * put your documentation comment here 1418 * @param e 1419 */ 1420 private void maybeShowPopup (MouseEvent e) { 1421 { 1422 popup.show(e.getComponent(), e.getX(), e.getY()); 1423 } 1424 } 1425 1426 /*** 1427 * Set up new data ranges to show. 1428 * @param e 1429 */ 1430 private void actionButton_actionPerformed (ActionEvent e) { 1431 //get the input data from text field 1432 xAxisExtents[0] = Double.parseDouble(xAxisMinField.getText()); 1433 xAxisExtents[1] = Double.parseDouble(xAxisMaxField.getText()); 1434 yAxisExtents[0] = Double.parseDouble(yAxisMinField.getText()); 1435 yAxisExtents[1] = Double.parseDouble(yAxisMaxField.getText()); 1436 this.dataArrayX.setExtent(xAxisExtents); 1437 this.dataArrayY.setExtent(yAxisExtents); 1438 this.setupDataforDisplay(); 1439 fireActionPerformed(COMMAND_DATARANGE_SET); 1440 //System.out.println("ok, fire event."); 1441 repaint(); 1442 } 1443 1444 /*** 1445 * put your documentation comment here 1446 * @param e 1447 */ 1448 private void resetButton_actionPerformed (ActionEvent e) { 1449 this.dataArrayX.setDataExtent(); 1450 this.dataArrayY.setDataExtent(); 1451 if (axisOn) { 1452 xAxisExtents = (double[])this.dataArrayX.getMaxMinCoorValue().clone(); 1453 yAxisExtents = (double[])this.dataArrayY.getMaxMinCoorValue().clone(); 1454 } 1455 else { 1456 xAxisExtents[0] = dataArrayX.getExtent()[0]; 1457 xAxisExtents[1] = dataArrayX.getExtent()[1]; 1458 yAxisExtents[0] = dataArrayY.getExtent()[0]; 1459 yAxisExtents[1] = dataArrayY.getExtent()[1]; 1460 } 1461 xAxisMinField.setText(Double.toString(xAxisExtents[0])); 1462 xAxisMaxField.setText(Double.toString(xAxisExtents[1])); 1463 yAxisMinField.setText(Double.toString(yAxisExtents[0])); 1464 yAxisMaxField.setText(Double.toString(yAxisExtents[1])); 1465 this.setupDataforDisplay(); 1466 fireActionPerformed(COMMAND_DATARANGE_SET); 1467 repaint(); 1468 } 1469 /*** 1470 * adds an IndicationListener to the button 1471 */ 1472 public void addIndicationListener (IndicationListener l) { 1473 listenerList.add(IndicationListener.class, l); 1474 } 1475 1476 /*** 1477 * removes an IndicationListener from the button 1478 */ 1479 public void removeIndicationListener (IndicationListener l) { 1480 listenerList.remove(IndicationListener.class, l); 1481 } 1482 /*** 1483 * adds an ActionListener to the button 1484 */ 1485 public void addActionListener (ActionListener l) { 1486 listenerListAction.add(ActionListener.class, l); 1487 } 1488 1489 /*** 1490 * removes an ActionListener from the button 1491 */ 1492 public void removeActionListener (ActionListener l) { 1493 listenerListAction.remove(ActionListener.class, l); 1494 } 1495 1496 /*** 1497 * Notify all listeners that have registered interest for 1498 * notification on this event type. The event instance 1499 * is lazily created using the parameters passed into 1500 * the fire method. 1501 * @see EventListenerList 1502 */ 1503 public void fireActionPerformed (String command) { 1504 // Guaranteed to return a non-null array 1505 Object[] listeners = listenerListAction.getListenerList(); 1506 ActionEvent e = null; 1507 // Process the listeners last to first, notifying 1508 // those that are interested in this event 1509 for (int i = listeners.length - 2; i >= 0; i -= 2) { 1510 if (listeners[i] == ActionListener.class) { 1511 // Lazily create the event: 1512 if (e == null) { 1513 e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, command); 1514 } 1515 ((ActionListener)listeners[i + 1]).actionPerformed(e); 1516 } 1517 } 1518 } 1519 1520 /*** 1521 * If AxisOn is true, it will be a detailed version of scatterplot with axises. 1522 * @return 1523 */ 1524 public boolean isAxisOn () { 1525 return axisOn; 1526 } 1527 1528 /*** 1529 * Sets colors for the current data. 1530 */ 1531 public void setBivarColorClasser (BivariateColorSymbolClassification bivarColorClasser, boolean reverseColor) { 1532 this.bivarColorClasser = bivarColorClasser; 1533 this.makeColors(); 1534 classColors = this.bivarColorClasser.getClassColors(); 1535 int numClasses; 1536 1537 try { 1538 xClasser = (BoundaryClassifier)this.bivarColorClasser.getClasserX(); 1539 numClasses = this.bivarColorClasser.getXColorSymbolizer().getNumClasses(); 1540 System.out.println("num classes" + numClasses); 1541 xBoundaries = xClasser.getBoundaries(this.dataX,numClasses); 1542 yClasser = (BoundaryClassifier)this.bivarColorClasser.getClasserY(); 1543 numClasses = this.bivarColorClasser.getYColorSymbolizer().getNumClasses(); 1544 yBoundaries = yClasser.getBoundaries(this.dataY,numClasses); 1545 } 1546 catch (ClassCastException ex) { 1547 1548 } 1549 repaint(); 1550 } 1551 1552 public BivariateColorSymbolClassification getBivarColorClasser(){ 1553 return this.bivarColorClasser; 1554 } 1555 1556 public void makeColors(){ 1557 if (this.dataX != null && this.dataY != null) { 1558 this.pointColors = this.bivarColorClasser.symbolize(dataX,dataY); 1559 } 1560 } 1561 /*** 1562 * Test file. 1563 * @param args 1564 */ 1565 public static void main (String[] args) { 1566 JFrame app = new JFrame(); 1567 ScatterPlot sp = new ScatterPlot(); 1568 app.getContentPane().add(sp); 1569 app.show(); 1570 } 1571 } 1572 1573 1574

This page was automatically generated by Maven