/** * Element.java 1.00 96/10/07 Merlin Hughes * * Copyright (c) 1996 Prominence Dot Com, Inc. All Rights Reserved. * * Permission to use, copy, modify, and distribute this software * for non-commercial purposes and without fee is hereby granted * provided that this copyright notice appears in all copies. * * http://prominence.com/ merlin@prominence.com */ import java.awt.*; import java.util.*; import java.net.*; public class Element { Page parent; URL url; String name, comment; boolean open, selected; Element sibling, offspring; public Element (URL url, String name, String comment, Page parent) { this.parent = parent; this.url = url; this.name = name; this.comment = comment; } int myHeight () { int h = (offspring == null) ? parent.docH : (open) ? parent.openH : parent.dirH; return (parent.textH > h) ? parent.textH : h + 1; } public int getHeight () { int h = myHeight (); if (open && (offspring != null)) h += offspring.getHeight (); if (sibling != null) return h + sibling.getHeight (); else return h; } Element locate (int mX, int mY, Point xy) { int x = xy.x, y = xy.y, h = myHeight (), w = (offspring == null) ? parent.docW : (open) ? parent.openW : parent.dirW; if ((mX >= x) && (mY >= y) && (mY < y + h) && (mX < x + w + 4 + parent.getFontMetrics (parent.getFont ()).stringWidth (name))) return this; xy.translate (0, h); if (open && (offspring != null)) { xy.translate (w + 4, 0); Element l = offspring.locate (mX, mY, xy); if (l != null) return l; xy.translate (-(w + 4), 0); } if (sibling != null) return sibling.locate (mX, mY, xy); else return null; } void paint (Graphics g, int oX, int oY, Point xy) { int x = xy.x, y = xy.y, h = myHeight (), w = (offspring == null) ? parent.docW : (open) ? parent.openW : parent.dirW; xy.translate (0, h); if ((oY < parent.size ().height) && (y + h / 2 > 0)) g.drawLine (oX, oY, oX, y + h / 2); if ((y < parent.size ().height) && (y + h > 0)) { g.drawLine (oX, y + h / 2, x + w / 2, y + h / 2); Color c = g.getColor (); if (selected) g.setColor (Color.red); g.drawString (name, x + w + 4, y + (h - parent.textH) / 2 + parent.textA); if (selected) g.setColor (c); } if (open && (offspring != null)) { xy.translate (w + 4, 0); offspring.paint (g, x + w / 2, y + h / 2, xy); xy.translate (-(w + 4), 0); } if ((y < parent.size ().height) && (y + h > 0)) { if (offspring == null) g.drawImage (parent.doc, x, y + (h - parent.docH) / 2, parent); else if (open) g.drawImage (parent.open, x, y + (h - parent.openH) / 2, parent); else g.drawImage (parent.dir, x, y + (h - parent.dirH) / 2, parent); } if (sibling != null) sibling.paint (g, oX, y + h / 2, xy); } }