1 /* -------------------------------------------------------------------
2 GeoVISTA Center (Penn State, Dept. of Geography)
3 Java source file for the class LayerPolygon
4 Copyright (c), 2002, GeoVISTA Center
5 All Rights Reserved.
6 Original Author: Frank Hardisty
7 $Author: hardisty $
8 $Id: LayerPolygon.java,v 1.2 2003/04/25 17:23:47 hardisty Exp $
9 $Date: 2003/04/25 17:23:47 $
10 Reference: Document no:
11 ___ ___
12 ------------------------------------------------------------------- *
13 */
14
15
16 package edu.psu.geovista.app.map;
17 import java.awt.*;
18 import java.awt.geom.*;
19 import java.util.*;
20
21 /***
22 * put your documentation comment here
23 */
24 public class LayerPolygon extends LayerShape {
25
26 /*
27 * SelectionX1 is expected to be less than selectionX2, same with Y1 and y2.
28 * Selected observations should be rendered with the color "colorSelection".
29 */
30 public void findSelection (int selectionX1, int selectionX2, int selectionY1,
31 int selectionY2) {
32 Rectangle selBox = new Rectangle(selectionX1,selectionY1,selectionX2-selectionX1,selectionY2-selectionY1);
33
34 Vector selObs = new Vector();
35 for (int i = 0; i < this.spatialData.length; i++) {
36 Rectangle shpBox = this.spatialData[i].getBounds();
37 Rectangle2D r2 = null;
38 if (selBox.intersects(shpBox)) {
39 if (this.spatialData[i].contains(selBox) || this.spatialData[i].intersects(selBox)) {
40 selObs.add(new Integer(i));
41 }//end if really intersects
42 }//end if rough intersects
43 }//next
44 this.selectedObservations = new int[selObs.size()];
45 int j = 0;
46 for (Enumeration e = selObs.elements() ; e.hasMoreElements() ;) {
47 Integer anInt = (Integer)e.nextElement();
48 this.selectedObservations[j] = anInt.intValue();
49 j++;
50 }
51 }
52
53 /*
54 * selectionX1 is expected to be less than selectionX2, same with Y1 and y2
55 */
56 public void findSelectionShift (int selectionX1, int selectionX2, int selectionY1,
57 int selectionY2) {
58 Rectangle selBox = new Rectangle(selectionX1,selectionY1,selectionX2-selectionX1,selectionY2-selectionY1);
59
60 Vector selObs = new Vector();
61 Arrays.sort(this.selectedObservations);//have to do this for the searching
62 for (int i = 0; i < this.spatialData.length; i++) {
63 Rectangle shpBox = this.spatialData[i].getBounds();
64 if (selBox.intersects(shpBox)) {
65 if (Arrays.binarySearch(this.selectedObservations,i) < 0){
66 selObs.add(new Integer(i));
67 }
68 }
69 }
70 int[] selectedObserCp = new int[this.selectedObservations.length];
71 selectedObserCp = (int[]) (this.selectedObservations.clone());
72 this.selectedObservations = new int[selectedObserCp.length + selObs.size()];
73 int j = 0;
74 for (j=0; j < selectedObserCp.length; j ++) {
75 this.selectedObservations[j] = selectedObserCp[j];
76 }
77 for (Enumeration e = selObs.elements() ; e.hasMoreElements() ;) {
78 Integer anInt = (Integer)e.nextElement();
79 this.selectedObservations[j] = anInt.intValue();
80 j++;
81 }
82
83 }
84
85 public int findIndication(int x, int y) {
86 for (int i = 0; i < this.spatialData.length; i++) {
87 Rectangle shpBox = this.spatialData[i].getBounds();
88 Rectangle2D r2 = null;
89 if (shpBox.contains(x,y)) {
90 if (this.spatialData[i].contains(x,y)){
91 return i;
92
93 }//end if really intersects
94 }//end if rough intersects
95 }//next
96 //couldn't find anything, so
97 return Integer.MIN_VALUE;
98 }
99
100
101
102 }
This page was automatically generated by Maven