Added a whole UI for browsing the visualizations on the screen.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@263 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -0,0 +1,94 @@
|
|||||||
|
//
|
||||||
|
// $Id: VizController.java,v 1.1 2001/08/14 00:45:56 mdb Exp $
|
||||||
|
|
||||||
|
package com.samskivert.viztool;
|
||||||
|
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.print.*;
|
||||||
|
|
||||||
|
import com.samskivert.swing.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The viz controller manages the user interface and effects actions that
|
||||||
|
* are requested by the user (like moving forward or backward a page).
|
||||||
|
*/
|
||||||
|
public class VizController extends Controller
|
||||||
|
{
|
||||||
|
/** The action command for moving forward one page. */
|
||||||
|
public static final String FORWARD_PAGE = "forward_page";
|
||||||
|
|
||||||
|
/** The action command for moving backward one page. */
|
||||||
|
public static final String BACKWARD_PAGE = "backward_page";
|
||||||
|
|
||||||
|
/** The action command for printing. */
|
||||||
|
public static final String PRINT = "print";
|
||||||
|
|
||||||
|
/** The action command for quitting. */
|
||||||
|
public static final String QUIT = "quit";
|
||||||
|
|
||||||
|
public VizController (VizPanel vpanel)
|
||||||
|
{
|
||||||
|
_vpanel = vpanel;
|
||||||
|
|
||||||
|
// create a print job in case we need to print
|
||||||
|
_job = PrinterJob.getPrinterJob();
|
||||||
|
_format = _job.defaultPage();
|
||||||
|
|
||||||
|
// use sensible margins
|
||||||
|
Paper paper = new Paper();
|
||||||
|
paper.setImageableArea(
|
||||||
|
LEFT_MARGIN, TOP_MARGIN, PAGE_WIDTH, PAGE_HEIGHT);
|
||||||
|
_format.setPaper(paper);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean handleAction (ActionEvent action)
|
||||||
|
{
|
||||||
|
String cmd = action.getActionCommand();
|
||||||
|
|
||||||
|
if (cmd.equals(FORWARD_PAGE)) {
|
||||||
|
int pno = _vpanel.getPage();
|
||||||
|
if (pno < _vpanel.getPageCount()-1) {
|
||||||
|
_vpanel.setPage(pno+1);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
|
||||||
|
} else if (cmd.equals(BACKWARD_PAGE)) {
|
||||||
|
int pno = _vpanel.getPage();
|
||||||
|
if (pno > 0) {
|
||||||
|
_vpanel.setPage(pno-1);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
|
||||||
|
} else if (cmd.equals(PRINT)) {
|
||||||
|
// tell the job to print our visualizer with the format we set
|
||||||
|
// up earlier
|
||||||
|
_job.setPrintable(_vpanel.getVisualizer(), _format);
|
||||||
|
|
||||||
|
// pop up a dialog to control printing
|
||||||
|
if (_job.printDialog()) {
|
||||||
|
try {
|
||||||
|
// invoke the printing process
|
||||||
|
_job.print();
|
||||||
|
} catch (PrinterException pe) {
|
||||||
|
pe.printStackTrace(System.err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
|
||||||
|
} else if (cmd.equals(QUIT)) {
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected VizPanel _vpanel;
|
||||||
|
protected PrinterJob _job;
|
||||||
|
protected PageFormat _format;
|
||||||
|
|
||||||
|
// these should be configurable...
|
||||||
|
protected static final double LEFT_MARGIN = 72*0.5;
|
||||||
|
protected static final double TOP_MARGIN = 72*0.5;
|
||||||
|
protected static final double PAGE_WIDTH = 72*7.5;
|
||||||
|
protected static final double PAGE_HEIGHT = 72*10;
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: VizFrame.java,v 1.4 2001/08/14 00:04:08 mdb Exp $
|
// $Id: VizFrame.java,v 1.5 2001/08/14 00:45:56 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
|
||||||
@@ -23,6 +23,7 @@ package com.samskivert.viztool;
|
|||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
|
import com.samskivert.swing.*;
|
||||||
import com.samskivert.viztool.viz.HierarchyVisualizer;
|
import com.samskivert.viztool.viz.HierarchyVisualizer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -37,17 +38,63 @@ public class VizFrame extends JFrame
|
|||||||
// quit if we're closed
|
// quit if we're closed
|
||||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||||
|
|
||||||
JPanel content = new JPanel();
|
// create our controller and panel for displaying visualizations
|
||||||
|
VizPanel vpanel = new VizPanel(viz);
|
||||||
|
VizController vctrl = new VizController(vpanel);
|
||||||
|
|
||||||
// put a border around everything
|
// create some control buttons
|
||||||
|
GroupLayout gl = new HGroupLayout(GroupLayout.NONE);
|
||||||
|
gl.setJustification(GroupLayout.RIGHT);
|
||||||
|
JPanel bpanel = new JPanel(gl);
|
||||||
|
JButton btn;
|
||||||
|
|
||||||
|
btn = new JButton("Print");
|
||||||
|
btn.setActionCommand(VizController.PRINT);
|
||||||
|
btn.addActionListener(VizController.DISPATCHER);
|
||||||
|
bpanel.add(btn);
|
||||||
|
|
||||||
|
btn = new JButton("Previous page");
|
||||||
|
btn.setActionCommand(VizController.BACKWARD_PAGE);
|
||||||
|
btn.addActionListener(VizController.DISPATCHER);
|
||||||
|
bpanel.add(btn);
|
||||||
|
|
||||||
|
btn = new JButton("Next page");
|
||||||
|
btn.setActionCommand(VizController.FORWARD_PAGE);
|
||||||
|
btn.addActionListener(VizController.DISPATCHER);
|
||||||
|
bpanel.add(btn);
|
||||||
|
|
||||||
|
btn = new JButton("Quit");
|
||||||
|
btn.setActionCommand(VizController.QUIT);
|
||||||
|
btn.addActionListener(VizController.DISPATCHER);
|
||||||
|
bpanel.add(btn);
|
||||||
|
|
||||||
|
// create a content pane to contain everything
|
||||||
|
JPanel content = new ContentPanel(vctrl);
|
||||||
|
gl = new VGroupLayout(GroupLayout.STRETCH);
|
||||||
|
content.setLayout(gl);
|
||||||
content.setBorder(BorderFactory.createEmptyBorder(
|
content.setBorder(BorderFactory.createEmptyBorder(
|
||||||
BORDER, BORDER, BORDER, BORDER));
|
BORDER, BORDER, BORDER, BORDER));
|
||||||
|
content.add(vpanel);
|
||||||
VizPanel panel = new VizPanel(viz);
|
content.add(bpanel, GroupLayout.FIXED);
|
||||||
content.add(panel, BorderLayout.CENTER);
|
|
||||||
|
|
||||||
setContentPane(content);
|
setContentPane(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static final class ContentPanel
|
||||||
|
extends JPanel
|
||||||
|
implements ControllerProvider
|
||||||
|
{
|
||||||
|
public ContentPanel (VizController ctrl)
|
||||||
|
{
|
||||||
|
_ctrl = ctrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Controller getController ()
|
||||||
|
{
|
||||||
|
return _ctrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Controller _ctrl;
|
||||||
|
}
|
||||||
|
|
||||||
protected static final int BORDER = 5; // pixels
|
protected static final int BORDER = 5; // pixels
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: VizPanel.java,v 1.5 2001/08/14 00:05:03 mdb Exp $
|
// $Id: VizPanel.java,v 1.6 2001/08/14 00:45:56 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
|
||||||
@@ -36,6 +36,7 @@ public class VizPanel extends JPanel
|
|||||||
*/
|
*/
|
||||||
public VizPanel (HierarchyVisualizer viz)
|
public VizPanel (HierarchyVisualizer viz)
|
||||||
{
|
{
|
||||||
|
// we'll need these later
|
||||||
_viz = viz;
|
_viz = viz;
|
||||||
|
|
||||||
// set the font
|
// set the font
|
||||||
@@ -86,6 +87,22 @@ public class VizPanel extends JPanel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the index of the page that we're currently displaying.
|
||||||
|
*/
|
||||||
|
public int getPage ()
|
||||||
|
{
|
||||||
|
return _currentPage;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the visualizer we're currently displaying.
|
||||||
|
*/
|
||||||
|
public HierarchyVisualizer getVisualizer ()
|
||||||
|
{
|
||||||
|
return _viz;
|
||||||
|
}
|
||||||
|
|
||||||
protected HierarchyVisualizer _viz;
|
protected HierarchyVisualizer _viz;
|
||||||
protected int _currentPage = 0;
|
protected int _currentPage = 0;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user