// 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.awt.*; public class HtmlDocumentArea { /** space occumpied by this area */ Rectangle area; /** hotitem associated with this area */ HotItem hot_item; /** text==string for this area */ String text; /** base line of this area (for text areas) */ int base_line; /** font for this area */ Font font; /** color for this area */ Color color; private static Font appH1Font= null; private static Font appH2Font= null; private static Font appH3Font= null; private static Font appH4Font= null; private static Font appH5Font= null; private static Font appBoldFont= null; private static Font appTypeFont= null; private static Font appBodyFont= null; private static int avgHeight= 0; public static void initFonts (Font h1, Font h2, Font h3, Font h4, Font h5, Font body, Font bold, Font type) { appH1Font= h1; appH2Font= h2; appH3Font= h3; appH4Font= h4; appH5Font= h5; appBodyFont= body; appBoldFont= bold; appTypeFont= type; } public static Font getFont(String font_name) { Font font; if (null != font_name) { if (font_name.equalsIgnoreCase("h1")) { font= HtmlDocumentArea.appH1Font; } else if (font_name.equalsIgnoreCase("h2")) { font= HtmlDocumentArea.appH2Font; } else if (font_name.equalsIgnoreCase("h3")) { font= HtmlDocumentArea.appH3Font; } else if (font_name.equalsIgnoreCase("h4")) { font= HtmlDocumentArea.appH4Font; } else if (font_name.equalsIgnoreCase("h5")) { font= HtmlDocumentArea.appH5Font; } else if (font_name.equalsIgnoreCase("bold")) { font= HtmlDocumentArea.appBoldFont; } else if (font_name.equalsIgnoreCase("type")) { font= HtmlDocumentArea.appTypeFont; } else // if (font_name.equalsIgnoreCase("body")) { font= HtmlDocumentArea.appBodyFont; } } else { // null name, use default; font= HtmlDocumentArea.appBodyFont; } return font; } public HtmlDocumentArea(HotText ht) { text= ht.getText(); hot_item= ht.getHotItem(); area= new Rectangle(); if (null != hot_item) { color= Color.blue; } else { color= Color.black; } } public HtmlDocumentArea(String s, HotItem hi) { text= s; hot_item= hi; area= new Rectangle(); if (null != hot_item) { color= Color.blue; } else { color= Color.black; } } public HtmlDocumentArea(String s) { text= s; area= new Rectangle(); hot_item= null; color= Color.black; } public HtmlDocumentArea() { text= null; area= new Rectangle(); hot_item= null; color= Color.black; } public Font getFont() { return this.font; } public void setFont(Font font) { this.font= font; } public void setFont(String font_name) { setFont(HtmlDocumentArea.getFont(font_name)); } public int getWidth() { return area.width; } public int getHeight() { return area.height; } public int getX() { return area.x; } public int getY() { return area.y; } public String getText() { return text; } public void setText(String s) { text= s; } public int getBaseLine() { return base_line; } public void setBaseLine(int bl) { base_line= bl; } public void setArea(int x1, int y1, int x2, int y2) { area= new Rectangle(Math.min(x1,x2), Math.min(y1,y2), Math.abs(x2 - x1), Math.abs(y2 - y1)); } public void setArea(int x1, int y1, int x2, int y2, int bl) { setArea(x1, y1, x2, y2); base_line= bl; } public Rectangle getArea() { return area; } public boolean inside(int x, int y) { return area.inside(x, y); } public HotItem getHotItem() { return hot_item; } public void setHotItem(String s) { hot_item= new HotItem(s); } public void setHotHref(String s) { hot_item= new HotHref(s); } public void setHotName(String s) { hot_item= new HotName(s); } public void paint(Graphics g, int xoff, int yoff) { //Jdb.enter("HDA.paint(g"+g+", "+xoff+","+yoff); if ((null != text) && (null != area)) { g.setFont(font); g.setColor(color); g.drawString(text, area.x - xoff, base_line - yoff); //Jdb.trace("g.drawString(\""+text+"\", "+ // (area.x-xoff)+", "+(base_line-yoff)+")"); } //Jdb.exit("HDA.paint(g"+g+", "+xoff+","+yoff); } public String toString() { StringBuffer rv= new StringBuffer(); rv.append("area["); if (null != this.area) { rv.append("("+this.area.x+"-"+this.area.width); rv.append(","+this.area.y+"-"+this.area.height); } else { rv.append("(NULL rectangle"); } rv.append("), font"); rv.append(font); rv.append(", hot"); if (null != hot_item) { rv.append(hot_item.toString()); } else { rv.append("NULL"); } rv.append(", base"+base_line); rv.append(", text"); if (null == this.text) { rv.append("NULL"); } else { rv.append("\""); int maxlen= 24; int tlen= this.text.length(); if (maxlen < tlen) { int len= Math.min(maxlen-3, tlen); rv.append(this.text.substring(0, len)); rv.append("..."); } else { rv.append(this.text); } rv.append("\""); } rv.append("]"); return rv.toString(); } }