/******************************************************************* 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 staffsched; import java.awt.*; import java.util.*; import javax.swing.*; import apprisant.diagram.*; import apprisant.diagram.env.*; import apprisant.resourcechart.*; import staffsched.StaffData.Staff; // enum class /* The main class of the Staff Schedule demo. This class assembles the user interface. This demo uses the toolkit's Resource Chart package to build the chart and generate the annotations. Default values are used for the layout parameters. The custom display element class, ApptElement, extends the toolkit's ResourceElement class to provide access to the data values in the required format. The ResourceElement class constructs the rectangles to represent the appointments. The StaffData and Appointment classes represent the data model and data objects respectively; however the data could be configured on the display elements without the use of a data model. The renderer file staffsched.rdr defines the style for displaying the appointments, annotation and frame. */ public class StaffSchedule extends JApplet { static final String[] CHART_TITLES = {"Monday", "Tuesday", "Wednesday"}; Diagram diagram; ResourceModel model; StaffData dataModel = new StaffData(); /* Applet initialization method assembles the user interface. */ public void init() { /* Instantiate and configure the element model. */ model = new ResourceModel(); model.setChartTitles(CHART_TITLES); String[] names = new String[StaffData.NUM_STAFF]; int i = 0; for (Staff s : Staff.values()) { names[i++] = s.name(); } model.setResourceNames(names); String[] hourLabels = new String[StaffData.HOUR_END - StaffData.HOUR_START + 1]; for (int h = StaffData.HOUR_START; h <= StaffData.HOUR_END; h++) { hourLabels[h - StaffData.HOUR_START] = String.valueOf(((h-1) % 12) + 1); } model.setIntervalLabels(hourLabels); /* Set a factory to instantiate our element class for each data object. */ model.setElementFactory(new ApptElement.Factory()); try { // Properties file sets the rendering hints AGEnvironment.loadProperties("staffsched/staffsched.properties"); // Create the diagram diagram = new Diagram("Staff Schedule", model); diagram.setBackground(new Color(255,253,252)); diagram.getViewManager().setMargin(new Dimension(20,20)); // Renderers diagram.readRenderers("staffsched/staffsched.rdr"); } catch (AGException ae) { AGLog.log("StaffSched", "initializing", AGLog.ERROR, ae); return; } // Data model diagram.setDataModel(dataModel); // Add the diagram to the Swing parent setLayout(new BorderLayout()); add(new JScrollPane(diagram), BorderLayout.CENTER); } public static void main (String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { JApplet applet = new StaffSchedule(); applet.init(); JFrame frame = new JFrame("Staff Schedule"); frame.setLocation(100, 100); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(applet, BorderLayout.CENTER); frame.pack(); frame.setVisible (true); } }); } }