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
This commit is contained in:
@@ -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
|
// viztool - a tool for visualizing collections of java classes
|
||||||
// Copyright (C) 2001 Michael Bayne
|
// Copyright (C) 2001 Michael Bayne
|
||||||
@@ -31,6 +31,9 @@ import com.samskivert.viztool.viz.HierarchyVisualizer;
|
|||||||
*/
|
*/
|
||||||
public class VizPanel extends JPanel
|
public class VizPanel extends JPanel
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Constructs a panel for displaying a particular visualization.
|
||||||
|
*/
|
||||||
public VizPanel (HierarchyVisualizer viz)
|
public VizPanel (HierarchyVisualizer viz)
|
||||||
{
|
{
|
||||||
_viz = viz;
|
_viz = viz;
|
||||||
@@ -47,8 +50,46 @@ public class VizPanel extends JPanel
|
|||||||
Graphics2D gfx = (Graphics2D)g;
|
Graphics2D gfx = (Graphics2D)g;
|
||||||
Rectangle2D bounds = getBounds();
|
Rectangle2D bounds = getBounds();
|
||||||
_viz.layout(gfx, 0, 0, bounds.getWidth(), bounds.getHeight());
|
_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 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);
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-1
@@ -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
|
// viztool - a tool for visualizing collections of java classes
|
||||||
// Copyright (C) 2001 Michael Bayne
|
// Copyright (C) 2001 Michael Bayne
|
||||||
@@ -171,6 +171,9 @@ public class HierarchyVisualizer implements Printable
|
|||||||
// increment our y location
|
// increment our y location
|
||||||
y += (bounds.getHeight() + GAP);
|
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)
|
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 String _pkgroot;
|
||||||
protected ArrayList _classes = new ArrayList();
|
protected ArrayList _classes = new ArrayList();
|
||||||
|
|
||||||
protected String[] _packages;
|
protected String[] _packages;
|
||||||
protected ArrayList _groups;
|
protected ArrayList _groups;
|
||||||
|
protected int _pageCount = -1;
|
||||||
|
|
||||||
protected PageFormat _format;
|
protected PageFormat _format;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user