/******************************************************************* Copyright (c) 2001-2010 Apprisant Technologies Inc. All rights reserved. Apprisant Technologies permits non-exclusive royalty free use, copying and modification of this demo program source code for the purposes of evaluating the Apprisant Toolkit or building applications that use it. This software and documentation is provided "AS IS". APPRISANT TECHNOLOGIES DISCLAIMS ANY REPRESENTATIONS AND WARRANTIES, INCLUDING BUT NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY AND FITNESS OF THIS PRODUCT FOR ANY PARTICULAR PURPOSE. APPRISANT TECHNOLOGIES SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY ANY PARTY, INCLUDING LOST PROFITS, ARISING FROM THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ITS DERIVATIONS. ********************************************************************/ package orgchart; import java.awt.*; import java.awt.image.BufferedImage; import java.io.FileOutputStream; import javax.imageio.ImageIO; import javax.swing.*; import apprisant.diagram.*; import apprisant.treelayout.*; import apprisant.diagram.env.*; import apprisant.diagram.render.AGRenderer; /** Organizational chart demo that uses the TreeLayout package to lay out the nodes in a hierarchy and defines display style for the nodes in a renderer file. The diagram's default element model (KeyModel) creates elements for the data objects. The TreeLayout and its TreeElements position the nodes recursively and generate the links joining them. The renderer file defines the appearance of the nodes and lines and references the data attributes for the text in the nodes. */ public class Orgchart extends JFrame { private Diagram diagram; Orgchart() { super("Orgchart Demo"); try { // The properties file sets rendering hints AGEnvironment.loadProperties("orgchart/orgchart.properties"); // Instantiate and configure a diagram diagram = new Diagram("Orgchart"); diagram.setBackground(Color.white); // Set a margin around the diagram contents, and set the // alignment so the tree doesn't jump around as subtrees // are opened and closed. ViewManager vm = diagram.getViewManager(); vm.setMargin(new Dimension(10, 10)); vm.setAlignment(AGAlignment.NORTH); // Read the renderers and get the renderer whose bounds // determine the node's dimensions for layout. diagram.readRenderers("orgchart/orgchartH.rdr"); AGRenderer nodeRen = diagram.getRenderManager().getRenderer("outline"); // Configure the TreeLayout. (Use Geo or the Orgchart web // demo to experiment with the parameters.) TreeLayout layout = new TreeLayout(); layout.setNodeRenderer(nodeRen); layout.setInlineChildOffset(30); layout.setInlineSpacing(7); layout.setInlineLinkOffsetRatio(0.7); layout.setInlineLinkChildHeightRatio(0.3); layout.setTierHorizontalSpacing(20); layout.setTierVerticalSpacing(30); layout.setTierLinkOffsetRatio(.7); // Set the layout manager and its element factory ElementModel model = diagram.getModel(); model.setLayout(layout); model.setElementFactory(new TreeElement.Factory()); // Enable the TreeLayout's tag listener for the open/close handles layout.enableStateListener(true); // Data model OrgchartData dataModel = new OrgchartData(); diagram.setDataModel(dataModel); } catch (Exception e) { AGLog.log("Orgchart", "configuring", AGLog.ERROR, e); } add(new JScrollPane(diagram), BorderLayout.CENTER); } /* Writes the orgchart to an image file, disabled below. */ void writeImage() { // Write the image file int imageType = BufferedImage.TYPE_INT_RGB; BufferedImage image = diagram.paintImage(0, 0, imageType); try { ImageIO.write(image, "png", new FileOutputStream("orgchart.png")); } catch (Exception e) { AGLog.log("Orgchart", "writing image", AGLog.ERROR, e); } } //**************************************************************** public static void main (final String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { Orgchart frame = new Orgchart(); frame.setLocation(100, 100); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); //frame.writeImage(); } }); } }