/******************************************************************* 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 schedule; import java.awt.*; import java.awt.event.*; import java.util.*; import javax.swing.*; import apprisant.diagram.*; import apprisant.diagram.event.*; import apprisant.diagram.env.*; import apprisant.diagram.awtext.Dimension2D; /* The main class of the Schedule demo. This class assembles the user interface. The background image shows a blank schedule. This demo has its own element class, ScheduleElement, to calculate display parameters based on the booking information. The display element for each booking is created automatically by the KeyModel using the element factory in the ScheduleElement class. */ public class Schedule extends JApplet { Diagram diagram; ScheduleData dataModel; DiagramSelectionModel selectionModel; /* Applet initialization method assembles the user interface. */ public void init() { setLayout(new BorderLayout()); // Create the diagram diagram = new Diagram("Schedule"); ViewManager viewMgr = diagram.getViewManager(); viewMgr.setScrollIncrements(new Dimension2D.Float (ScheduleElement.SCROLL_X, ScheduleElement.SCROLL_Y)); selectionModel = diagram.getSelectionModel(); try { // Properties file turns on text-antialiasing AGEnvironment.loadProperties("schedule/schedule.properties"); // Background image diagram.setBackgroundImagePath("schedule/week.png"); // Renderers diagram.readRenderers("schedule/schedule.rdr"); } catch (AGException ae) { AGLog.log("Schedule", "initializing", AGLog.ERROR, ae); return; } // Set an ElementFactory to instantiate our element class KeyModel model = (KeyModel) diagram.getModel(); model.setElementFactory(new ScheduleElement.Factory()); // Data model dataModel = new ScheduleData(); dataModel.initBookings(); diagram.setDataModel(dataModel); // Add the diagram to the parent add(new JScrollPane(diagram), BorderLayout.CENTER); // Button panel Box buttonPanel = buildButtonPanel(); add(buttonPanel, BorderLayout.SOUTH); } Box buildButtonPanel() { Box buttonPanel = new Box(BoxLayout.X_AXIS); JButton addButton = new JButton("Add"); buttonPanel.add(Box.createGlue()); buttonPanel.add(addButton); buttonPanel.add(Box.createHorizontalStrut(5)); addButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { dataModel.addBooking(); } }); JButton removeButton = new JButton("Remove"); buttonPanel.add(removeButton); buttonPanel.add(Box.createHorizontalStrut(5)); removeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { Set keys = selectionModel.getSelection(); dataModel.removeBookings(keys); } }); JButton changeButton = new JButton("Change"); buttonPanel.add(changeButton); buttonPanel.add(Box.createGlue()); changeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { dataModel.changeBookings(); } }); return buttonPanel; } public static void main (String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { JApplet applet = new Schedule(); applet.init(); JFrame frame = new JFrame("Schedule Demo"); frame.setLocation(100, 100); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(applet, BorderLayout.CENTER); frame.pack(); frame.setVisible (true); } }); } }