From 9bbb5e8f58fa0b91eccd9b6aa4be475af85d54f3 Mon Sep 17 00:00:00 2001 From: mdb Date: Tue, 14 Aug 2001 00:05:03 +0000 Subject: [PATCH] Added support for rendering a particular page of the visualization and made viz panel return a preferred size that makes sense (it preferrs to be one page size as rendered to the screen: which is 72 dpi, but I should look into whether or not I can avoid hard coding that). git-svn-id: https://samskivert.googlecode.com/svn/trunk@260 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../java/com/samskivert/viztool/VizPanel.java | 45 ++++++++++++++++++- .../hierarchy/HierarchyVisualizer.java | 17 ++++++- 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/projects/viztool/src/java/com/samskivert/viztool/VizPanel.java b/projects/viztool/src/java/com/samskivert/viztool/VizPanel.java index d6c77819..6fe475cd 100644 --- a/projects/viztool/src/java/com/samskivert/viztool/VizPanel.java +++ b/projects/viztool/src/java/com/samskivert/viztool/VizPanel.java @@ -1,5 +1,5 @@ // -// $Id: VizPanel.java,v 1.4 2001/08/13 23:43:09 mdb Exp $ +// $Id: VizPanel.java,v 1.5 2001/08/14 00:05:03 mdb Exp $ // // viztool - a tool for visualizing collections of java classes // Copyright (C) 2001 Michael Bayne @@ -31,6 +31,9 @@ import com.samskivert.viztool.viz.HierarchyVisualizer; */ public class VizPanel extends JPanel { + /** + * Constructs a panel for displaying a particular visualization. + */ public VizPanel (HierarchyVisualizer viz) { _viz = viz; @@ -47,8 +50,46 @@ public class VizPanel extends JPanel Graphics2D gfx = (Graphics2D)g; Rectangle2D bounds = getBounds(); _viz.layout(gfx, 0, 0, bounds.getWidth(), bounds.getHeight()); - _viz.paint(gfx, 0); + _viz.paint(gfx, _currentPage); + } + + public Dimension getPreferredSize () + { + return new Dimension(PAGE_WIDTH, PAGE_HEIGHT); + } + + /** + * Returns the number of pages in our current visualization. This is + * only valid after we've been rendered at least once because we + * needed the rendering graphics to realize the visualization. + */ + public int getPageCount () + { + return _viz.getPageCount(); + } + + /** + * Requests that the panel display the specified page number (indexed + * from zero). Requests to display invalid page numbers will be + * ignored. + */ + public void setPage (int pageno) + { + if (pageno < _viz.getPageCount()) { + _currentPage = pageno; + repaint(); + + } else { + Log.warning("Requested to display invalid page " + + "[pageno=" + pageno + + ", pages=" + _viz.getPageCount() + "]."); + } } protected HierarchyVisualizer _viz; + protected int _currentPage = 0; + + // our preferred size is one page at 72 pixels per inch + protected static final int PAGE_WIDTH = (int)(72 * 8.5); + protected static final int PAGE_HEIGHT = (int)(72 * 11); } diff --git a/projects/viztool/src/java/com/samskivert/viztool/hierarchy/HierarchyVisualizer.java b/projects/viztool/src/java/com/samskivert/viztool/hierarchy/HierarchyVisualizer.java index 72a84bf3..e44b1687 100644 --- a/projects/viztool/src/java/com/samskivert/viztool/hierarchy/HierarchyVisualizer.java +++ b/projects/viztool/src/java/com/samskivert/viztool/hierarchy/HierarchyVisualizer.java @@ -1,5 +1,5 @@ // -// $Id: HierarchyVisualizer.java,v 1.12 2001/08/13 23:42:43 mdb Exp $ +// $Id: HierarchyVisualizer.java,v 1.13 2001/08/14 00:05:03 mdb Exp $ // // viztool - a tool for visualizing collections of java classes // Copyright (C) 2001 Michael Bayne @@ -171,6 +171,9 @@ public class HierarchyVisualizer implements Printable // increment our y location y += (bounds.getHeight() + GAP); } + + // our page count is one more than the highest page number + _pageCount = pageno+1; } public void paint (Graphics2D gfx, int pageIndex) @@ -189,11 +192,23 @@ public class HierarchyVisualizer implements Printable } } + /** + * Returns the number of pages occupied by this visualization. This is + * only valid after a call to {@link #layout}. + * + * @return the page count or -1 if we've not yet been laid out. + */ + public int getPageCount () + { + return _pageCount; + } + protected String _pkgroot; protected ArrayList _classes = new ArrayList(); protected String[] _packages; protected ArrayList _groups; + protected int _pageCount = -1; protected PageFormat _format;