/** * Called to create a map the parent of each bookmark. * * @param parent top level bookmark. * @param parentMap map to add children to. * @param pagenoVector vector of page numbers. * @param depth object indicating bookmark depth. */ protected void mapChildren( final Bookmark parent, final Hashtable parentMap, final Vector pagenoVector, final Number depth) { getDepthMap().put(parent, depth); final int pageno = parent.getPageno(); if (pageno >= 0) { while (pageno >= pagenoVector.size()) { pagenoVector.addElement(null); } pagenoVector.setElementAt(parent, pageno); } final Enumeration e = parent.elements(); if (e.hasMoreElements()) { final Number childDepth = new Integer(depth.intValue() + 1); do { final Bookmark child = (Bookmark) e.nextElement(); parentMap.put(child, parent); mapChildren(child, parentMap, pagenoVector, childDepth); } while (e.hasMoreElements()); } }
/** * Called to recursively paint the check box for the specified item. * * @param item row number * @param g graphics object to paint. * @param bookmark to check selected value. * @return the next row number to paint. */ public int paintCheckbox(final int item, final Graphics g, final Bookmark bookmark) { int nextItem = item + 1; if (bookmark != null) { final Rectangle checkboxBounds = getCheckboxBounds(item, bookmark, getDepthMap().get(bookmark)); final int yCheckboxMidPoint = checkboxBounds.y + (checkboxBounds.height / 2); final int xCheckboxMidPoint = checkboxBounds.x + (checkboxBounds.width / 2); final Enumeration e = bookmark.elements(); if (e.hasMoreElements()) { // clear any lines crossing through the checkbox. g.clearRect( checkboxBounds.x, checkboxBounds.y, checkboxBounds.width, checkboxBounds.height); // draw box around checkbox g.drawRect(checkboxBounds.x, checkboxBounds.y, checkboxBounds.width, checkboxBounds.height); // draw dash inside checkbox g.drawLine( checkboxBounds.x + 2, yCheckboxMidPoint, (checkboxBounds.x + checkboxBounds.width) - 2, yCheckboxMidPoint); boolean drawPlus = true; do { final Bookmark child = (Bookmark) e.nextElement(); final Bookmark next = getBookmark(nextItem); if (child != next) { break; } drawPlus = false; nextItem = paintCheckbox(nextItem, g, child); } while (e.hasMoreElements()); if (drawPlus) { g.drawLine( xCheckboxMidPoint, checkboxBounds.y + 2, xCheckboxMidPoint, (checkboxBounds.y + checkboxBounds.height) - 2); } } } return nextItem; }
/** * Query the maximum image size allowed. * * @return the maximum image size allowed. */ public Dimension getMaximumSize() { final Dimension retval = new Dimension(); final Hashtable depthMap = getDepthMap(); int item = 0; synchronized (getActiveVector()) { final Enumeration keys = getDepthMap().keys(); while (keys.hasMoreElements()) { final Bookmark bookmark = (Bookmark) keys.nextElement(); final Rectangle bounds = getTextBounds(item++, bookmark, depthMap.get(bookmark)); final int width = bounds.x + bounds.width; if (width > retval.width) { retval.width = width; } retval.height = bounds.y + bounds.height; } } retval.width += (2 * getFontMetrics(getFont()).getMaxAdvance()); retval.height += (2 * getFontHeight()); return retval; }
/** * Called to recursively paint text and lines for the specified item. * * @param item row number * @param g graphics object to paint. * @param bookmark to check selected value. * @return the next row number to paint. */ public int paintItem(final int item, final Graphics g, final Bookmark bookmark) { int nextItem = item + 1; if (bookmark != null) { final Rectangle textBounds = getTextBounds(item, bookmark, getDepthMap().get(bookmark)); final int yTextMidPoint = textBounds.y + (textBounds.height / 2); final Enumeration e = bookmark.elements(); final String displayName = bookmark.getDisplayName(); if (displayName != null) { g.drawString(displayName, textBounds.x, textBounds.y + textBounds.height); } if (e.hasMoreElements()) { // draw line from checkbox to text g.drawLine(textBounds.x - getFontWidth(), yTextMidPoint, textBounds.x - 2, yTextMidPoint); final int xLineToChildren = textBounds.x - (getFontWidth() / 2); int southLine = yTextMidPoint; do { final Bookmark child = (Bookmark) e.nextElement(); final Bookmark next = getBookmark(nextItem); if (child != next) { break; } southLine = (((2 * nextItem) + 1) * getFontHeight()) / 2; g.drawLine(xLineToChildren, southLine, textBounds.x - 2, southLine); nextItem = paintItem(nextItem, g, child); } while (e.hasMoreElements()); if (southLine > yTextMidPoint) { g.drawLine(xLineToChildren, yTextMidPoint, xLineToChildren, southLine); } } else if (displayName != null) { g.drawLine(textBounds.x - getFontWidth(), yTextMidPoint, textBounds.x - 2, yTextMidPoint); } } return nextItem; }
/** * Check bookmark at the specified row number. * * @param item row number. * @param checked true if checked. * @param activeVector vector of active bookmarks. */ protected void setCheckedItem(final int item, final boolean checked, final Vector activeVector) { final Bookmark bookmark = getBookmark(item); if (bookmark.size() > 0) { final Enumeration e = bookmark.elements(); int i = item + 1; if (e.hasMoreElements()) { if (checked) { do { final Bookmark child = (Bookmark) e.nextElement(); final Bookmark next = getBookmark(i); if (next == child) { break; } activeVector.insertElementAt(child, i++); } while (e.hasMoreElements()); } else { do { final Bookmark child = (Bookmark) e.nextElement(); final Bookmark next = getBookmark(i); if (next != child) { break; } setCheckedItem(i, false); activeVector.removeElementAt(i); } while (e.hasMoreElements()); } } repaint(20L); } }