/******************************************************************* Copyright (c) 2001-2007 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 examples; import java.awt.*; import java.awt.geom.Rectangle2D; import javax.swing.*; import apprisant.diagram.*; import apprisant.diagram.env.*; import apprisant.diagram.render.*; /** This example demonstrates bounds alignment. The program is similar to BasicEx except for the converter for the MEDALS element attribute, and the renderer plugin which creates rectangles sized to match the medal count. Elements are read from medals.elt and renderers from align.rdr. */ public class AlignmentEx extends JFrame { static final String MEDALS = "medals"; Diagram diagram; //**************************************************************** AlignmentEx() { super("Alignment Example"); // Instantiate and configure a diagram diagram = new Diagram("Alignment"); diagram.setBackground(new Color(250,250,255)); diagram.getViewManager().setMargin(new Dimension(20, 20)); try { // Read the renderers diagram.readRenderers("align.rdr"); // Read the elements diagram.readElements("medals.elt"); } catch (Exception e) { AGLog.log("AlignmentEx", null, AGLog.ERROR, e); System.exit(1); } add(new JScrollPane(diagram), BorderLayout.CENTER); } //**************************************************************** /** Renderer plugin for the Shape renderer to instantiate rectangles of the appropriate size for each element. */ public static class RenPlugin implements RendererPlugin { Color cLeft = new Color(160,180,200); Color cRight = new Color(245,250,255); public void setup (RenderingContext ctx, AGRenderer ren) { GeneralElement e = ctx.getElement(); Integer medals = (Integer) e.getAttribute(MEDALS); int rectLength = medals * 10; Rectangle2D rect = new Rectangle2D.Double(0, 0, rectLength, 20); GradientPaint gp = new GradientPaint(0, 0, cLeft, rectLength, 0, cRight); ShapeRenderer sren = (ShapeRenderer) ren; sren.setShape(rect); sren.setFill(gp); } } //**************************************************************** public static void main (final String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { JFrame frame = new AlignmentEx(); frame.setLocation(100, 100); if (args.length == 0 || ! args[0].equals(Runner.NAME)) { frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } frame.pack(); frame.setVisible(true); } }); } }