Dev Direct Solution Center

For more information and to buy this product...

Java Staff Schedule Example using the Apprisant Toolkit

  For a copy of the sample project please click here to download and install the product evaluation.

Introduction

This example shows a staff appointment schedule built using the Apprisant toolkit's Gantt chart package.

Detail

The following clip is from the image generated by the example program. Layout is done by our Gantt Chart package while rendering style for the appointments and annotation is defined in an XML file to suit your application and your data.

The Java code to (minimally) configure the Gantt model is:


    model = new GanttModel();
    model.setCharts(StaffData.NUM_DAYS);
    model.setResources(StaffData.NUM_STAFF);
    model.setIntervals(StaffData.HOUR_END - StaffData.HOUR_START);

    model.setChartTitles(CHART_TITLES);

    String[] names = ...
    model.setResourceNames(names);

    String[] hourLabels = ...
    model.setIntervalLabels(hourLabels);
    model.updateChart();

    /* Set a factory to instantiate our element class for each
       data object. */
    model.setElementFactory(new ElementFactory() {
        public ApptElement createElement (Object key, Object data) {
    	    return new ApptElement(key, data);
        }
    });

The code to create the diagram:


    // 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.rdr");

    // Data model
    diagram.setDataModel(dataModel);

The custom element class has 3 get methods to makes the data available to the Gantt model in the appropriate form. Here is one of them:


    public double getStart() {
	Appointment d = (Appointment) getDataObject();
	return d.getStartTime() - StaffData.HOUR_START;
    }

The example uses its own data object classes to represent the appointment information.

Here are two snippets from the XML renderer file. The first sets the style for the day titles and the frames created by the Gantt model. The second is for the rectangles representing the appointments. g1 is a gradient defined earlier in the file.


    <text id="day" text="@gantt_chart_title" 
	alignment="baseline_left" x="-40" y="-6"
	fill="rgb(80,90,130)" 
	font-size="12" font-weight="bold" font-style="italic" />

    <shape id="frame" shape="@gantt_chart_frame" position="origin"
	stroke-width="1" stroke="rgb(140,140,140)" fill="none"  />

    <shape id="appointment" shape="@gantt_rectangle" fill="g1" />

As the Gantt chart module uses our general-purpose diagramming component, you have full API access and flexibility to configure rendering style and view parameters, and to implement custom data access if necessary. The toolkit includes a detailed Developers' Guide, many examples, and complete API documentation.

In addition, the example code is fully applicable to our upcoming JavaServer Faces release.

Download the entire (runnable and configurable) demo from: http://www.apprisant.com/staffsched/apprisant_staffsched.zip

Visit Apprisant Technologies Inc. for more information and more samples.