View Javadoc
1 /* ------------------------------------------------------------------- 2 GeoVISTA Center (Penn State, Dept. of Geography) 3 Java source file for the class MapMatrixElement 4 Copyright (c), 2002, GeoVISTA Center 5 All Rights Reserved. 6 Original Author: Frank Hardisty 7 $Author: xpdai $ 8 $Id: MapMatrixElement.java,v 1.10 2003/09/05 13:02:10 xpdai Exp $ 9 $Date: 2003/09/05 13:02:10 $ 10 Reference: Document no: 11 ___ ___ 12 ------------------------------------------------------------------- * 13 14 */ 15 package edu.psu.geovista.app.map; 16 17 import edu.psu.geovista.app.matrix.*; 18 import edu.psu.geovista.classification.Classifier; 19 import edu.psu.geovista.symbolization.*; 20 import edu.psu.geovista.app.scatterplot.Histogram; 21 import edu.psu.geovista.app.scatterplot.ScatterPlot; 22 import edu.psu.geovista.data.geog.DataSetForApps; 23 24 import java.awt.*; 25 import java.awt.event.*; 26 import java.awt.font.*; 27 import java.awt.geom.*; 28 import java.awt.image.*; 29 30 import java.util.*; 31 32 import javax.swing.*; 33 34 35 public class MapMatrixElement extends MapCanvas implements MatrixElement { 36 //the following are required for returning to matrix 37 private int[] elementPosition; 38 private double[] xAxisExtents; 39 private double[] yAxisExtents; 40 transient private Object[] data; 41 transient private DataSetForApps dataSet; 42 String attributeX; 43 double[] dataX; 44 45 46 private Color selectionColor; 47 transient private Histogram histogram = new Histogram(); 48 49 public MapMatrixElement() { 50 super(); 51 this.autofit = true; 52 this.setBorder(BorderFactory.createLineBorder(Color.gray)); 53 54 55 //super.exLabels = null; 56 //super.fisheyes = new edu.psu.geovista.ui.Fisheyes(); 57 super.setMode(MapCanvas.MODE_SELECT); 58 } 59 public void setSelOriginalColorMode(boolean selOriginalColorMode) { 60 super.setSelOriginalColorMode(selOriginalColorMode); 61 } 62 63 public void setDataObject(Object[] data) { 64 this.data = data; 65 this.dataSet = new DataSetForApps(); 66 dataSet.setDataObject(data); 67 super.setDataSet(data); 68 this.setHistogramData(); 69 70 //super.tickleColors(); 71 } 72 73 public void setElementPosition(int[] dataIndices) { 74 this.elementPosition = (int[]) dataIndices.clone(); 75 super.setCurrColorColumnX(this.elementPosition[0]); 76 super.setCurrColorColumnY(this.elementPosition[1]); 77 this.setHistogramData(); 78 } 79 80 public int[] getElementPosition() { 81 return this.elementPosition; 82 } 83 84 //For axes of scatter plot. 85 //a noop for this class 86 public void setAxisOn(boolean axisOn) { 87 } 88 89 //public void setConditionArray (int[] conditionArray){ } 90 //Set min and max for axes. xAxisExtents[0] = min, [1] = max. 91 public void setXAxisExtents(double[] xAxisExtents) { 92 //histogram.setXAxisExtents(xAxisExtents); 93 } 94 95 public void setYAxisExtents(double[] yAxisExtents) { 96 97 98 } 99 100 public double[] getXAxisExtents() { 101 return this.xAxisExtents; 102 } 103 104 public double[] getYAxisExtents() { 105 return this.yAxisExtents; 106 } 107 108 public String getShortDiscription() { 109 return "MAP"; 110 } 111 112 public void setSelectionColor(Color c) { 113 this.selectionColor = c; 114 super.setColorSelection(c); 115 } 116 117 public Color getSelectionColor() { 118 return this.selectionColor; 119 } 120 121 public void setMultipleSelectionColors(Color[] c) { 122 } 123 124 public void setBivarColorClasser(BivariateColorSymbolClassification biColorClasser, boolean reverseColor) { 125 if ((biColorClasser == null) || (this.data == null)) { 126 return; 127 } 128 129 BivariateColorSymbolClassificationSimple biColor = 130 (BivariateColorSymbolClassificationSimple) biColorClasser; 131 132 BivariateColorSymbolClassificationSimple biColor2 = 133 new BivariateColorSymbolClassificationSimple(); 134 ColorSymbolizer xSym = biColor.getColorerX(); 135 ColorSymbolizer ySym = biColor.getColorerY(); 136 //reverse the color scheme for two variables to compromise the color match between maps and scatterplots in BiPlotMatrix. 137 if (reverseColor == true){ 138 biColor2.setColorerX(ySym); 139 biColor2.setColorerY(xSym); 140 }else{ 141 biColor2.setColorerX(xSym); 142 biColor2.setColorerY(ySym); 143 } 144 super.setBivarColorClasser(biColor2); 145 } 146 147 public BivariateColorSymbolClassification getBivarColorClasser() { 148 return super.bivarColorClasser; 149 } 150 151 public void setColorArrayForObs(Color[] colorArrays) { 152 } 153 private void setHistogramData(){ 154 if (this.data == null|| this.elementPosition == null){ 155 return; 156 } 157 String[] atts = (String[])this.data[0]; 158 159 this.attributeX= atts[elementPosition[0]-1]; 160 int index = this.elementPosition[0]; 161 //XXX getNumericDataAsDouble has changed... 162 dataX = dataSet.getNumericDataAsDouble(index-1); 163 double[] extent = histogram.getXAxisExtents(); 164 165 extent = new double[2]; 166 extent[0] = edu.psu.geovista.data.DescriptiveStatistics.min(dataX); 167 extent[1] = edu.psu.geovista.data.DescriptiveStatistics.max(dataX); 168 this.xAxisExtents = extent; 169 170 } 171 private void drawHistogram(Graphics g) { 172 173 Color foreground = Color.white; 174 int plotWidth = (int)this.getWidth(); 175 int plotHeight = (int)this.getHeight(); 176 int size; 177 size = (plotWidth < plotHeight) ? plotWidth : plotHeight; 178 179 // //System.out.println("In scatterplot, draw histogram..." + dataIndices[0]); 180 histogram.setAxisOn(false); 181 histogram.setVariableName(attributeX); 182 if (dataX == null){ 183 this.setHistogramData(); 184 } 185 histogram.setData(dataX); 186 histogram.setXAxisExtents(this.xAxisExtents); 187 histogram.setBackground(this.getBackground()); 188 histogram.setSize(this.getWidth(), this.getHeight()); 189 190 191 //histogram.setSelection(this.selRecords); 192 if (this.getSelections() != null){ 193 histogram.setSelections(this.getSelections()); 194 } 195 histogram.paintComponent(g); 196 197 Graphics2D g2 = (Graphics2D) g; 198 Color half = new Color(255, 255, 255, 100); 199 g2.setColor(half); 200 g.fillRect(0, 0, getSize().width, getSize().height); 201 g2.setColor(foreground); 202 203 Font font = new Font("", Font.PLAIN, (int) size / 8); 204 g.setFont(font); 205 206 // if (attributeX.length() > 12) { 207 // g.drawString(attributeX, 2, plotHeight / 2); 208 // } else if (attributeX.length() <= 7) { 209 // g.drawString(attributeX, plotWidth / 4, plotHeight / 2); 210 // } else { 211 // g.drawString(attributeX, plotWidth / 8, plotHeight / 2); 212 // } 213 214 //font.this.getSize() = (int)plotWidth/12; 215 Font font1 = new Font("", Font.PLAIN, (int) size / 12); 216 g.setFont(font1); 217 g.drawLine(0, 0, 5, 5); 218 219 String maxString = Float.toString((float) (xAxisExtents[1])); 220 g.drawString(maxString, 6, (int) (plotHeight * ScatterPlot.AXISSPACEPORTION / 2) + 2); 221 g.drawLine(0, plotHeight, 5, plotHeight - 5); 222 223 String minString = Float.toString((float) (xAxisExtents[0])); 224 g.drawString(minString, 6, plotHeight - 5); 225 g.drawLine(plotWidth, plotHeight, plotWidth - 5, plotHeight - 5); 226 g.drawString(maxString, 227 plotWidth - (int) (plotWidth * ScatterPlot.AXISSPACEPORTION + 5), 228 plotHeight - 5); 229 } 230 231 /*** 232 * This method only paints the current contents of the drawingBuff. 233 * @param g 234 */ 235 public void paintComponent(Graphics g) { 236 if (this.elementPosition == null){ 237 return; 238 } 239 if (this.elementPosition[0] != this.elementPosition[1]) { 240 super.paintComponent(g); 241 } 242 243 if (this.elementPosition == null) { 244 return; 245 } 246 247 if (this.elementPosition[0] == this.elementPosition[1]) { 248 super.paintComponent(g); 249 //this.drawHistogram(g); 250 251 } 252 } 253 }

This page was automatically generated by Maven