Class Scheduler

All Implemented Interfaces:
Animation, Editable, StyleListener, Iterable<Component>

public class Scheduler extends Container

A schedule on screen: the items of a ScheduleModel by day, week, month, as an agenda, or by resource.

long start = System.currentTimeMillis();
DefaultScheduleModel model = new DefaultScheduleModel();
model.addItem(new ScheduleItem("1", "Design review", start, start + TimeMath.HOUR));
Scheduler scheduler = new Scheduler(model);
scheduler.setView(Scheduler.View.WEEK);

Form form = new Form("Schedule", new BorderLayout());
form.add(BorderLayout.CENTER, scheduler);
form.show();

A week of a schedule

The same items by the day, by the month and against the people they are booked for:

The day view The month view The resource timeline

The views draw their items and keep no component for each, so a schedule of thousands of items scrolls as one of ten does. Time zooms with a pinch or with the wheel and the control key held.

Editing

With a mouse an item is dragged to move it and by its edge to resize it, and a drag across empty time selects a range. On a touch screen a drag scrolls, so a long press picks an item up or starts a range, and the selected item has handles to resize it by. Every change is offered to the listeners first, then made through ScheduleModel#updateItem, and either may refuse. setEditable(false) makes the scheduler read only.

Pointer and motion

Under a mouse the item the pointer is over lights up, free time shows the slot a drag would start in, the cursor says what a drag would do, and a tooltip gives the item's title and time. An item that is picked up lifts: a shadow comes up under it and the place it left dims. Let go, it glides from where it was dropped to where it belongs. Each takes under a quarter of a second.

An item picked up, carried and dropped, as five stopped frames

setAnimationTime stops the clock these run by, for a screenshot or a test of a moment in the middle of one.

Styling

SchedulerGrid is the background, with its foreground the colour of the lines; SchedulerOffHours shades the time outside a WorkCalendar; SchedulerHeader, SchedulerHeaderToday and SchedulerTimeLabel are the headings; SchedulerItem, SchedulerBackgroundItem and SchedulerBlocked the items by kind; SchedulerNow the current time and SchedulerSelection a range being dragged out. The bar above the views is SchedulerToolbar, SchedulerTitle and SchedulerViewButton. An item that names a UIID of its own is painted with that one.

A schedule restyled from CSS

  • Constructor Details

    • Scheduler

      public Scheduler()
      A scheduler with nothing in it yet.
    • Scheduler

      public Scheduler(ScheduleModel model)
  • Method Details

    • layoutContainer

      public void layoutContainer()
      The bar is a row where there is room for one, and two rows on a screen as narrow as a phone's. It is decided here because this is the first place the width is known.
      Overrides:
      layoutContainer in class Container
    • setToolbarVisible

      public void setToolbarVisible(boolean v)
      Whether the bar with the title and the buttons is shown. An application with navigation of its own hides it and calls next, previous, today and setView itself.
    • isToolbarVisible

      public boolean isToolbarVisible()
    • setCompactToolbar

      public void setCompactToolbar(boolean v)
      Whether the views are picked from one button with a menu, as on a phone, or each has a button of its own.
    • isCompactToolbar

      public boolean isCompactToolbar()
    • getModel

      public ScheduleModel getModel()
    • setModel

      public void setModel(ScheduleModel m)
    • refresh

      public void refresh()
      Reads the model again. A model that fires its change listeners needs no call to this.
    • getResource

      public ScheduleResource getResource(String id)
      The resource with an id, or null.
    • getView

      public Scheduler.View getView()
    • setView

      public void setView(Scheduler.View v)
    • setViews

      public void setViews(Scheduler.View... offered)
      The views the toolbar offers, in order. The default is day, week, month and agenda; a schedule with resources adds the two resource views.
    • setDate

      public void setDate(long millis)
      Shows the day, week or month that an instant is in.
    • getDate

      public long getDate()
      The start of the day the view is anchored on.
    • next

      public void next()
      Moves forward by what the view shows: a day, a week, a month.
    • previous

      public void previous()
    • today

      public void today()
      Shows the current day, week or month.
    • getVisibleStart

      public long getVisibleStart()
      The start of what the view shows, inclusive.
    • getVisibleEnd

      public long getVisibleEnd()
      The end of what the view shows, exclusive.
    • getZone

      public ZoneId getZone()
    • setZone

      public void setZone(ZoneId z)
      The zone the days and hours are those of. The default is the device's.
    • getFirstDayOfWeek

      public int getFirstDayOfWeek()
    • setFirstDayOfWeek

      public void setFirstDayOfWeek(int isoDay)
      The day a week starts on: 1 for Monday, which is the default, to 7 for Sunday.
    • getWorkCalendar

      public WorkCalendar getWorkCalendar()
    • setWorkCalendar

      public void setWorkCalendar(WorkCalendar c)
      The working hours: time outside them is shaded, and the work week shows the days this calendar works. A resource with a calendar of its own is shaded by that one. Null, the default, shades nothing.
    • is24Hours

      public boolean is24Hours()
      Whether times are written on a 24 hour clock. The default follows the device's locale.
    • set24Hours

      public void set24Hours(boolean v)
    • getSnapMinutes

      public int getSnapMinutes()
    • setSnapMinutes

      public void setSnapMinutes(int minutes)
      What a drag snaps to, in minutes. The default is 15.
    • getDefaultMinutes

      public int getDefaultMinutes()
    • setDefaultMinutes

      public void setDefaultMinutes(int minutes)
      The length of a range chosen without dragging, by a long press or a double click. The default is 60.
    • getInitialMinute

      public int getInitialMinute()
    • setInitialMinute

      public void setInitialMinute(int minute)
      The time of day the day and week views open scrolled to, in minutes since midnight. The default is 07:00.
    • getTimelineDays

      public int getTimelineDays()
    • setTimelineDays

      public void setTimelineDays(int days)
      How many days the resource timeline covers. The default is 7.
    • getAgendaDays

      public int getAgendaDays()
    • setAgendaDays

      public void setAgendaDays(int days)
      How many days the agenda lists. The default is 30.
    • isEditable

      public boolean isEditable()
      Description copied from class: Component

      Checks to see if the component is editable. This is used for next/previous focus traversal on forms.

      See also
      • #getEditingDelegate()

      • #setEditingDelegate(com.codename1.ui.Editable)

      • #isEditing()

      • #startEditingAsync()

      • #stopEditing(java.lang.Runnable)

      Specified by:
      isEditable in interface Editable
      Overrides:
      isEditable in class Component
    • setEditable

      public void setEditable(boolean v)
      Whether items can be dragged and ranges selected. Selecting and opening an item work either way.
    • isOpenOnTap

      public boolean isOpenOnTap()
    • setOpenOnTap

      public void setOpenOnTap(boolean v)
      Whether a single tap opens an item. The default is true on a touch screen and false where there is a mouse, which double clicks to open.
    • setDragEdits

      public void setDragEdits(boolean v)
      Whether a plain drag edits: moves the item under it, or selects a range of empty time. The default is true where there is a mouse and false on a touch screen, where a drag scrolls and a long press edits.
    • getItemRenderer

      public ScheduleItemRenderer getItemRenderer()
    • setItemRenderer

      public void setItemRenderer(ScheduleItemRenderer r)
    • setCurrentTime

      public void setCurrentTime(long millis)
      Fixes what the scheduler takes the current time to be, for a screenshot or a test. A negative value returns to the clock.
    • setAnimationTime

      public void setAnimationTime(long millis)

      Stops the clock the scheduler animates by at a time, for a screenshot of an animation or a test of one: the light of a hover, the rise of an item that is picked up and the travel of one that was dropped are drawn as far along as that time makes them. A negative value returns to the clock.

      scheduler.setAnimationTime(1000);  // nothing has started
      // ... press, drag, release ...
      scheduler.setAnimationTime(1100);  // 100 milliseconds into what followed
      
    • getSelectedItem

      public ScheduleItem getSelectedItem()
    • setSelectedItem

      public void setSelectedItem(ScheduleItem item)
      Selects an item, or nothing when item is null. The listeners are not told: this is the application's own doing.
    • addSchedulerListener

      public void addSchedulerListener(SchedulerListener l)
    • removeSchedulerListener

      public void removeSchedulerListener(SchedulerListener l)
    • formatTime

      public String formatTime(long millis)
      The time of day of an instant, as the views write it.
    • formatRange

      public String formatRange(long start, long end)
      A start and an end as the views write them: "9:00 AM - 10:30 AM".
    • initComponent

      protected void initComponent()
      Description copied from class: Component
      Allows subclasses to bind functionality that relies on fully initialized and "ready for action" component state
      Overrides:
      initComponent in class Component
    • deinitialize

      protected void deinitialize()
      Description copied from class: Component
      Invoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy. This allows the component to deregister animators and cleanup after itself. This method is the opposite of the initComponent() method.
      Overrides:
      deinitialize in class Component