7 private Rectangle[] rectangles;
8 private Point[] points;
11 public Imap(String filename) {
14 fr=new FileReader(filename);
17 } catch (IOException e) {
18 System.out.println(e);
22 static class Rectangle {
25 public Rectangle(String label, int x1,int y1, int x2, int y2) {
34 String parseclick(int x,int y) {
35 System.out.println(x+","+y);
36 for(int i=0;i<rectangles.length;i++) {
37 Rectangle r=rectangles[i];
38 if ((r.x1<=x)&&(r.y1>=y)&&
42 long mindistance=Long.MAX_VALUE;
44 for(int i=0;i<points.length;i++) {
48 if ((dx*dx+dy*dy)<mindistance) {
49 mindistance=dx*dx+dy*dy;
53 if (mindistance>THRESHOLD)
56 return points[minindex].label;
62 public Point(String label, int x,int y) {
69 void parseFile(FileReader fr) {
71 ArrayList rectangles=new ArrayList();
72 ArrayList points=new ArrayList();
76 } catch (Exception e) {
86 while(firstchar!='\n') {
89 } catch (IOException e) {
98 String label=nexttoken(fr,false);
99 String x1=nexttoken(fr,true);
100 String y1=nexttoken(fr,true);
101 String x2=nexttoken(fr,true);
102 String y2=nexttoken(fr,true);
103 Rectangle r=new Rectangle(label,Integer.parseInt(x1),Integer.parseInt(y1),
104 Integer.parseInt(x2),Integer.parseInt(y2));
111 String label=nexttoken(fr,false);
112 String x=nexttoken(fr,true);
113 String y=nexttoken(fr,true);
114 Point p=new Point(label,Integer.parseInt(x),Integer.parseInt(y));
120 this.rectangles=(Rectangle[]) rectangles.toArray(new Rectangle[rectangles.size()]);
121 this.points=(Point[]) points.toArray(new Point[points.size()]);
124 String nexttoken(java.io.InputStreamReader isr,boolean commas) {
127 boolean looped=false;
131 } catch (IOException e) {
135 if ((c==' ')||(c=='\n')||(commas&&c==',')) {
142 string=string+new String(new char[]{(char)c});