/******************************************************************* 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. ********************************************************************/ import java.awt.*; import java.awt.geom.*; import java.awt.event.*; import javax.swing.*; import java.util.*; import java.util.List; import apprisant.diagram.*; import apprisant.diagram.env.*; import apprisant.diagram.awtext.AGGradientPaint; /* This program demonstrates the toolkit's selection modes. */ public class Selection extends JApplet { DefaultDiagramSelectionModel selectionModel; public Selection() { super(); } /** Applet initialization method builds the main window. */ public void init () { setLayout(new BorderLayout()); Diagram diagram = null; try { // Properties file has the rendering hints AGEnvironment.loadProperties("selection.properties"); // Create and configure the diagram. // Use a BasicModel because we have no data. BasicModel model = new BasicModel(); diagram = new Diagram("Selection", model); diagram.setBackgroundGradient (new AGGradientPaint (0, 0, new Color(250,250,250), 100, 100, new Color(120,120,120), false, AGGradientPaint.Units.PERCENT)); ViewManager vm = diagram.getViewManager(); vm.setScale(new Point2D.Float(1.3f,1.3f)); vm.setMargin(new Dimension(20, 20)); selectionModel = (DefaultDiagramSelectionModel) diagram.getSelectionModel(); // Display elements model.add(createElements()); // Renderers diagram.readRenderers("selection.rdr"); } catch (AGException ae) { AGLog.log("Selection", "initialize", AGLog.ERROR, ae); return; } // Add the diagram to the applet add(diagram, BorderLayout.CENTER); // Button panel JPanel buttonPanel = buildButtonPanel(); add(buttonPanel, BorderLayout.EAST); } List createElements() { List elements = new ArrayList(10); elements.add(new GeneralElement("A0", 180, 50)); elements.add(new GeneralElement("A1", 50, 30)); elements.add(new GeneralElement("A2", 80, 80)); elements.add(new GeneralElement("A3", 140, 100)); elements.add(new GeneralElement("A4", 150, 110)); elements.add(new GeneralElement("A5", 200, 60)); elements.add(new GeneralElement("A6", 60, 100)); elements.add(new GeneralElement("A7", 220, 120)); elements.add(new GeneralElement("A8", 160, 120)); return elements; } JPanel buildButtonPanel() { JRadioButton rb; JPanel buttonPanel = new JPanel(new GridLayout(7, 1, 4, 4)); buttonPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); ButtonGroup group = new ButtonGroup(); rb = new JRadioButton("NONE"); group.add(rb); buttonPanel.add(rb); rb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { selectionModel.setSelectionMode(SelectionParams.NO_SELECTION); } }); rb = new JRadioButton("SINGLE"); group.add(rb); buttonPanel.add(rb); rb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { selectionModel.setSelectionMode(SelectionParams.SINGLE); } }); rb = new JRadioButton("SINGLE_ALWAYS_ONE"); group.add(rb); buttonPanel.add(rb); rb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { selectionModel.setSelectionMode (SelectionParams.SINGLE_ALWAYS_ONE); } }); rb = new JRadioButton("MULTIPLE_ADD, shallow"); group.add(rb); buttonPanel.add(rb); rb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { selectionModel.setSelectionMode(SelectionParams.MULTI_ADD); } }); rb = new JRadioButton("MULTIPLE_REPLACE, shallow"); group.add(rb); buttonPanel.add(rb); rb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { selectionModel.setSelectionMode (SelectionParams.MULTI_REPLACE); } }); rb.setSelected(true); rb = new JRadioButton("MULTIPLE_ADD, deep"); group.add(rb); buttonPanel.add(rb); rb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { selectionModel.setSelectionMode (SelectionParams.MULTI_ADD); selectionModel.setDepth(SelectionParams.DEEP); } }); rb = new JRadioButton("MULTIPLE_REPLACE, deep"); group.add(rb); buttonPanel.add(rb); rb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { selectionModel.setSelectionMode (SelectionParams.MULTI_REPLACE); selectionModel.setDepth(SelectionParams.DEEP); } }); return buttonPanel; } /* main runs the applet as a standalone application. */ public static void main (String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { JApplet applet = new Selection(); applet.init(); JFrame frame = new JFrame("Selection Demo"); frame.setLocation(100, 100); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(applet, BorderLayout.CENTER); frame.pack(); frame.setVisible (true); } }); } }