/******************************************************************* 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 camp; import java.awt.*; import java.awt.geom.*; import java.awt.event.*; import java.util.*; import java.util.List; import javax.swing.*; import apprisant.diagram.*; import apprisant.diagram.env.*; import apprisant.diagram.io.*; /* Main class for the Camp demo. Assembles the user interface and the diagram components. Data objects are in the CampData class. CampData uses a different set of data objects for each reservation date. The background image is a map of the campground. There is a display element for each campsite, read from the camp.elt file, which was created by positioning the campsites in Geo. Renderers are read from the camp.rdr file, and are defined so that the bounds of the elements remain constant across reservation dates. Because of this, the demo can set KeyModel's elementBoundsPolicy to indicate that the elements' bounds do not need to be recalculated when the data objects change, gaining a performance advantage. */ public class Camp extends JApplet { Diagram diagram; DiagramSelectionModel selectionModel; CampData campData; public Camp() { super(); } public void init() { setLayout(new BorderLayout()); try { // The properties sets rendering hints. AGEnvironment.loadProperties("camp/camp.properties"); // Create a diagram diagram = new Diagram("Camp"); diagram.setBackground(new Color(110,130,110)); diagram.getViewManager().setMargin(new Dimension(10, 10)); selectionModel = diagram.getSelectionModel(); // Background image diagram.setBackgroundImagePath("camp/campground.png"); // Renderers diagram.readRenderers("camp/camp.rdr"); // Element model KeyModel model = (KeyModel) diagram.getModel(); model.setElementBoundsPolicy (KeyModel.ElementBoundsPolicy.DATA_INDEPENDENT); diagram.readElements("camp/camp.elt"); } catch (Exception ae) { AGLog.log("Camp", "init", AGLog.ERROR, ae); return; } // Data model campData = new CampData(); diagram.setDataModel(campData); // Add the diagram to the applet add(new JScrollPane(diagram), BorderLayout.CENTER); // Button panel add(buildButtonPanel(), BorderLayout.SOUTH); } Box buildButtonPanel() { Box buttonPanel = new Box(BoxLayout.X_AXIS); ButtonGroup group = new ButtonGroup(); // July 3 button JRadioButton july3 = new JRadioButton("July 3-6"); july3.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { campData.setJul3Data(); } }); group.add(july3); buttonPanel.add(Box.createGlue()); buttonPanel.add(july3); buttonPanel.add(Box.createHorizontalStrut(5)); // July 10 button JRadioButton july10 = new JRadioButton("July 10-12"); july10.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { campData.setJul10Data(); } }); group.add(july10); buttonPanel.add(july10); buttonPanel.add(Box.createGlue()); // Reserve button JButton reserve = new JButton("Reserve"); reserve.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { Set keys = selectionModel.getSelection(); campData.reserve(keys); } }); buttonPanel.add(Box.createGlue()); buttonPanel.add(reserve); buttonPanel.add(Box.createHorizontalStrut(5)); // Cancel button JButton cancel = new JButton("Cancel"); cancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { Set keys = selectionModel.getSelection(); campData.cancel(keys); } }); buttonPanel.add(cancel); buttonPanel.add(Box.createGlue()); july3.setSelected(true); return buttonPanel; } public static void main (String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { JApplet applet = new Camp(); applet.init(); JFrame frame = new JFrame("Camp Demo"); frame.setLocation(100, 100); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(applet, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); } }); } }