/** * Creates a new Outline object. * * @param djvuBean the DjVuBean to navigate. * @throws ArrayIndexOutOfBoundsException if the document has less than 2 pages. */ public Outline(final DjVuBean djvuBean) { this.djvuBean = djvuBean; if (djvuBean.getDocument().size() < 2) { throw new ArrayIndexOutOfBoundsException("Can not navigate documents with only one page."); } final MouseListener mouseListener = new MouseAdapter() { public void mouseClicked(final MouseEvent e) { try { clickLocation(e.getX(), e.getY()); } catch (final Throwable exp) { exp.printStackTrace(DjVuOptions.err); System.gc(); } } }; addMouseListener(mouseListener); final Document document = djvuBean.getDocument(); final Bookmark bookmark = (Bookmark) document.getBookmark(); bookmark.setDjVmDir(document.getDjVmDir()); setFirstBookmark(bookmark); final Properties properties = djvuBean.properties; properties.put("addOn.NavPane", "Outline," + properties.getProperty("addOn.NavPane", "None")); djvuBean.addPropertyChangeListener(this); }
/** * Called when the user clicks the mouse on an outline item. If the check box is checked, the * checked value will be toggled. If the name is clicked, the bookmark page will be displayed. * * @param x position along the X axis clicked. * @param y position along the Y axis clicked. */ public void clickLocation(final int x, final int y) { final int item = getRow(y); final Bookmark bookmark = getBookmark(item); if (bookmark != null) { Rectangle bounds = getCheckboxBounds(item, bookmark, getDepthMap().get(bookmark)); if ((x >= bounds.x) && (y > bounds.y) && (x < (bounds.x + bounds.width)) && (y < (bounds.y + bounds.height))) { setCheckedItem(item, !isCheckedItem(item)); } else { bounds = getTextBounds(item, bookmark, getDepthMap().get(bookmark)); if ((x >= bounds.x) && (y > bounds.y) && (x < (bounds.x + bounds.width)) && (y < (bounds.y + bounds.height))) { final int pageno = bookmark.getPageno() + 1; if (pageno > 0) { djvuBean.setPage(pageno); } } } } }
/** * Called to change the visibility of the outline. * * @param value true if visible. */ public void setVisible(final boolean value) { if (value != isVisible()) { super.setVisible(value); Container parent = getParent(); if ((parent != null) && (parent.getComponentCount() == 1)) { parent.setVisible(value); } invalidate(); try { for (; parent != null; parent = parent.getParent()) { try { parent.getClass().getMethod("resetToPreferredSizes", null).invoke(parent, null); visibleArgs[0] = new Integer(value ? 10 : 0); parent.getClass().getMethod("setDividerSize", visibleParms).invoke(parent, visibleArgs); break; } catch (final Throwable ignored) { } } } catch (final Throwable ignored) { } djvuBean.recursiveRevalidate(); } }
/** * Called to paint the outline. * * @param g graphics object to paint. */ public void paint(final Graphics g) { final FontMetrics fontMetrics = getFontMetrics(getFont()); setFontWidth(fontMetrics.stringWidth("_")); setFontHeight(fontMetrics.getHeight()); if (firstTime) { firstTime = false; setVisible("Outline".equalsIgnoreCase(djvuBean.properties.getProperty("navpane"))); } if (!isVisible()) { getParent().setVisible(false); invalidate(); djvuBean.recursiveRevalidate(); } else { synchronized (activeVector) { paintItem(0, g, getBookmark(0)); paintCheckbox(0, g, getBookmark(0)); } } }