// Job: Jay's Own Browser, a web browser written in Java by Jay Skeer // Copyright (C) 1996 Jay Skeer, Jay Prime Positive // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // import java.util.Vector; import HtmlDocumentArea; public class HtmlDocumentAreaVector extends Vector { public void add(HtmlDocumentArea a) { addElement((Object) a); } public HtmlDocumentArea getElementAt(int pos) { return (HtmlDocumentArea)super.elementAt(pos); } public HtmlDocumentArea findArea(int look_x, int look_y) { int size= this.size(); HtmlDocumentArea best_area= null; HtmlDocumentArea this_area= null; for (int index= 0; (index < size) && (null == best_area); index++) { this_area= getElementAt(index); if (null != this_area) { if (this_area.inside(look_x, look_y)) { best_area= this_area; } } } return best_area; } public HtmlDocumentArea findAreaRight(int look_x, int look_y) { int size= this.size(); HtmlDocumentArea best_area= null; HtmlDocumentArea this_area= null; int best_area_x= 999; int best_area_y= 999; for (int index= 0; index < size; index++) { this_area= getElementAt(index); if (null != this_area) { int this_area_x= this_area.getX(); int this_area_y= this_area.getY(); if ((look_x <= this_area_x) && (look_y == this_area_y)) { if (this_area_x < best_area_x) { best_area= this_area; best_area_x= this_area_x; best_area_y= this_area_y; } } } } return best_area; } public HtmlDocumentArea findAreaBelow(int look_x, int look_y) { Jdb.enter("HDAV.findAreaBelow("+look_x+", "+look_y+")"); int size= this.size(); //Jdb.trace("vector has "+size+" elts"); HtmlDocumentArea best_area= null; HtmlDocumentArea this_area= null; int best_area_x= 999; int best_area_y= 999; for (int index= 0; (index < size); index++) { this_area= getElementAt(index); if (null != this_area) { int this_area_x= this_area.getX(); int this_area_y= this_area.getY(); //Jdb.trace("Non null elt#"+index+" is at ("+ //this_area_x+", "+this_area_y+")"); if (look_y < this_area_y) { if ( (this_area_y < best_area_y) || ( (this_area_y == best_area_y) && (this_area_x < best_area_x))) { best_area= this_area; best_area_x= this_area_x; best_area_y= this_area_y; } } } } Jdb.exit("HDAV.findAreaBelow("+look_x+", "+look_y+") => " + best_area); return best_area; } public HtmlDocumentArea findAreaInRightBelow(int look_x, int look_y) { Jdb.enter("HDAV.findAreaInRightBelow("+look_x+", "+look_y+")"); int size= this.size(); //Jdb.trace("vector has "+size+" elts"); HtmlDocumentArea best_area= null; HtmlDocumentArea this_area= null; int best_area_x= 999; int best_area_y= 999; for (int index= 0; (index < size); index++) { this_area= getElementAt(index); if (null != this_area) { int this_area_x= this_area.getX(); int this_area_y= this_area.getY(); //Jdb.trace("Non null elt#"+index+" is at ("+ //this_area_x+", "+this_area_y+")"); if (this_area.inside(look_x, look_y)) { if ( (this_area_y < best_area_y) || ( (this_area_y == best_area_y) && (this_area_x < best_area_x))) { best_area= this_area; best_area_x= this_area_x; best_area_y= this_area_y; } } else if ((look_x <= this_area_x) && (look_y <= this_area_y)) { if ( (this_area_y < best_area_y) || ( (this_area_y == best_area_y) && (this_area_x < best_area_x))) { best_area= this_area; best_area_x= this_area_x; best_area_y= this_area_y; } } } } Jdb.exit("HDAV.findAreaInRightBelow("+look_x+", "+look_y+") => " + best_area); return best_area; } public String jtoString() { int index= 0; int siz= size(); StringBuffer rv= new StringBuffer(); rv.append("HDAVector["); HtmlDocumentArea elt; if (index < siz) { elt= getElementAt(index); if (null != elt) { rv.append(elt.toString()); } else { rv.append("NULL"); } index++; } while (index < siz) { rv.append(", "); elt= getElementAt(index); if (null != elt) { rv.append(elt.toString()); } else { rv.append("NULL"); } index++; } rv.append("]="+siz); return rv.toString(); } }