Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public class Scheduler

  1. Object
  2. Component
  3. Container
  4. Scheduler

ImplementsAnimation, Editable, Iterable<Component>, StyleListener

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

Nested types

enum Scheduler.ViewThe ways a schedule is shown.

Constructors

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

Methods

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.
public void setToolbarVisible(boolean v)Whether the bar with the title and the buttons is shown.
public boolean isToolbarVisible()
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.
public boolean isCompactToolbar()
public ScheduleModel getModel()
public void setModel(ScheduleModel m)
public void refresh()Reads the model again.
public ScheduleResource getResource(String id)The resource with an id, or null.
public Scheduler.View getView()
public void setView(Scheduler.View v)
public void setViews(Scheduler.View... offered)The views the toolbar offers, in order.
public void setDate(long millis)Shows the day, week or month that an instant is in.
public long getDate()The start of the day the view is anchored on.
public void next()Moves forward by what the view shows: a day, a week, a month.
public void previous()
public void today()Shows the current day, week or month.
public long getVisibleStart()The start of what the view shows, inclusive.
public long getVisibleEnd()The end of what the view shows, exclusive.
public ZoneId getZone()
public void setZone(ZoneId z)The zone the days and hours are those of.
public int getFirstDayOfWeek()
public void setFirstDayOfWeek(int isoDay)The day a week starts on: 1 for Monday, which is the default, to 7 for Sunday.
public WorkCalendar getWorkCalendar()
public void setWorkCalendar(WorkCalendar c)The working hours: time outside them is shaded, and the work week shows the days this calendar works.
public boolean is24Hours()Whether times are written on a 24 hour clock.
public void set24Hours(boolean v)
public int getSnapMinutes()
public void setSnapMinutes(int minutes)What a drag snaps to, in minutes.
public int getDefaultMinutes()
public void setDefaultMinutes(int minutes)The length of a range chosen without dragging, by a long press or a double click.
public int getInitialMinute()
public void setInitialMinute(int minute)The time of day the day and week views open scrolled to, in minutes since midnight.
public int getTimelineDays()
public void setTimelineDays(int days)How many days the resource timeline covers.
public int getAgendaDays()
public void setAgendaDays(int days)How many days the agenda lists.
public boolean isEditable()Checks to see if the component is editable.
public void setEditable(boolean v)Whether items can be dragged and ranges selected.
public boolean isOpenOnTap()
public void setOpenOnTap(boolean v)Whether a single tap opens an item.
public void setDragEdits(boolean v)Whether a plain drag edits: moves the item under it, or selects a range of empty time.
public ScheduleItemRenderer getItemRenderer()
public void setItemRenderer(ScheduleItemRenderer r)
public void setCurrentTime(long millis)Fixes what the scheduler takes the current time to be, for a screenshot or a test.
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.
public ScheduleItem getSelectedItem()
public void setSelectedItem(ScheduleItem item)Selects an item, or nothing when item is null.
public void addSchedulerListener(SchedulerListener l)
public void removeSchedulerListener(SchedulerListener l)
public String formatTime(long millis)The time of day of an instant, as the views write it.
public String formatRange(long start, long end)A start and an end as the views write them: “9:00 AM - 10:30 AM”.
protected void initComponent()Allows subclasses to bind functionality that relies on fully initialized and “ready for action” component state
protected void deinitialize()Invoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy.

Inherited fields

Inherited methods

From Container

encloseIn, encloseIn, initLaf, getUIManager, setUIManager, isSurface, add, addAll, add, add, add, add, add, getLeadComponent, setLeadComponent, getLeadParent, keyPressed, keyReleased, getLayout, setLayout, invalidate, setShouldLayout, setShouldCalcPreferredSize, getLayoutWidth, getLayoutHeight, applyRTL, constrainWidthWhenScrollable, constrainHeightWhenScrollable, addComponent, addComponent, addComponent, addComponent, replaceAndWait, replaceAndWait, replace, replaceAndWait, replace, createReplaceTransition, isEnabled, setEnabled, removeComponent, cancelRepaints, flushReplace, removeAll, revalidateWithAnimationSafety, revalidate, revalidateLater, forceRevalidate, clearClientProperties, paint, paintGlass, isSafeArea, setSafeArea, isSafeAreaRoot, getSafeAreaRoot, setSafeAreaRoot, getComponentCount, getComponentAt, getComponentIndex, contains, scrollComponentToVisible, getClosestComponentTo, getResponderAt, getComponentAt, findDropTargetAt, pointerPressed, calcPreferredSize, paramString, refreshTheme, isScrollableX, setScrollableX, isScrollableY, setScrollableY, getSideGap, getBottomGap, setScrollable, setCellRenderer, getScrollIncrement, setScrollIncrement, findFirstFocusable, dragInitiated, fireClicked, isSelectableInteraction, getGridPosY, paintComponentBackground, getGridPosX, animateHierarchyAndWait, createAnimateHierarchy, animateHierarchy, animateHierarchyFadeAndWait, createAnimateHierarchyFade, animateHierarchyFade, animateLayoutFadeAndWait, createAnimateLayoutFadeAndWait, animateLayoutFade, createAnimateLayoutFade, animateLayoutAndWait, animateLayout, updateTabIndices, createAnimateLayout, drop, createAnimateMotion, morph, morphAndWait, animateUnlayout, animateUnlayoutAndWait, createAnimateUnlayout, getChildrenAsList, iterator, iterator

From Component

setSameSize, isSetCursorSupported, parsePreferredSize, getDefaultDragTransparency, setDefaultDragTransparency, getEditingDelegate, setEditingDelegate, getCursor, setCursor, showNativeOverlay, hideNativeOverlay, updateNativeOverlay, getNativeOverlay, getAllStyles, getSameWidth, setSameWidth, getSameHeight, setSameHeight, getX, setX, getOuterX, getInnerX, getY, setY, getOuterY, getInnerY, isVisible, setVisible, getClientProperty, stripMarginAndPadding, putClientProperty, getDirtyRegion, setDirtyRegion, isOpaque, setOpaque, getWidth, setWidth, getOuterWidth, getInnerWidth, getHeight, setHeight, getOuterHeight, getInnerHeight, isDragRegion, getDragRegionStatus, getBaseline, getBaselineResizeBehavior, getPreferredSizeStr, setPreferredSizeStr, getPreferredSize, setPreferredSize, getScrollDimension, calcScrollSize, setScrollSize, getPreferredW, setPreferredW, getPreferredH, setPreferredH, getOuterPreferredH, getInnerPreferredH, getOuterPreferredW, getInnerPreferredW, setSize, getUIID, setUIID, setUIIDFinal, setUIID, getInlineAllStyles, setInlineAllStyles, getInlineSelectedStyles, setInlineSelectedStyles, getInlineUnselectedStyles, setInlineUnselectedStyles, getInlineDisabledStyles, setInlineDisabledStyles, getInlinePressedStyles, setInlinePressedStyles, remove, getParent, getOwner, setOwner, isOwnedBy, containsOrOwns, addFocusListener, removeFocusListener, addScrollListener, removeScrollListener, getSelectCommandText, setSelectCommandText, getLabelForComponent, setLabelForComponent, focusGained, focusLost, paintBackgrounds, paintShadows, getAbsoluteX, getAbsoluteY, isInClippingRegion, paintIntersectingComponentsAbove, paintScrollbars, paintScrollbarX, getScrollOpacity, getSelectedRect, paintScrollbarY, paintComponent, paintComponent, getBorder, getScrollable, paintBackground, isScrollable, getScrollX, setScrollX, getScrollY, setScrollY, onScrollX, onScrollY, getDraggedx, getDraggedy, contains, visibleBoundsContains, hasFixedPreferredSize, getBounds, getBounds, getVisibleBounds, getVisibleBounds, isFocusable, setFocusable, onSetFocusable, resetFocusable, getTabIndex, setTabIndex, getPreferredTabIndex, setPreferredTabIndex, isTraversable, setTraversable, handlesInput, setHandlesInput, consumesRawTextInput, hasFocus, setFocus, getComponentForm, getTopLevelContainer, repaint, repaint, longKeyPress, keyRepeated, registerForAnimation, deregisterFromAnimation, getAnimationManager, getScrollAnimationSpeed, setScrollAnimationSpeed, isBlockLead, setBlockLead, isIgnorePointerEvents, setIgnorePointerEvents, isRippleEffect, setRippleEffect, getInlineStylesTheme, setInlineStylesTheme, shouldRenderComponentSelection, isHideInLandscape, setHideInLandscape, createStyleAnimation, isSmoothScrolling, setSmoothScrolling, pointerHover, stopScrollMomentum, pointerHoverReleased, pointerHoverPressed, pinch, pinchReleased, pinch, rotation, isPinchBlocksDragAndDrop, setPinchBlocksDragAndDrop, pointerDragged, getDragImage, getDragTransparency, setDragTransparency, toImage, drawDraggedImage, draggingOver, dragEnter, dragExit, addPullToRefresh, setPullToRefresh, respondsToPointerEvents, pointerDragged, isStickyDrag, pointerPressed, isDragAndDropOperation, pointerReleased, longPointerPress, pointerReleased, setVerticalScrollBounds, setHorizontalScrollBounds, isVScrollThumbGrabbed, isHScrollThumbGrabbed, isVScrollThumbHover, isHScrollThumbHover, isTensileDragEnabled, setTensileDragEnabled, getTextSelectionSupport, addDropListener, removeDropListener, addDragOverListener, removeDragOverListener, isNativeDragSource, setNativeDragSource, getNativeDragOperation, setNativeDragOperation, createNativeDragOperation, isNativeDropTarget, setNativeDropTarget, getAcceptedDropMimeTypes, setAcceptedDropMimeTypes, getAcceptedDropActions, setAcceptedDropActions, canAcceptNativeDrop, nativeDragEnter, nativeDragOver, nativeDragExit, nativeDrop, addNativeDropListener, removeNativeDropListener, addNativeDragOverListener, removeNativeDragOverListener, dragFinished, addDragFinishedListener, addStateChangeListener, removeStateChangeListener, addPointerPressedListener, addLongPressListener, addContextMenuListener, removeContextMenuListener, addMouseWheelListener, removeMouseWheelListener, addStylusListener, removeStylusListener, getContextMenuCommands, setContextMenuCommands, mouseWheel, paintRippleOverlay, removePointerPressedListener, removeLongPressListener, removeDragFinishedListener, addPointerReleasedListener, removePointerReleasedListener, addPointerDraggedListener, removePointerDraggedListener, getDragSpeed, getStyle, getPressedStyle, getHoverStyle, setHoverStyle, isHovered, setHovered, setPressedStyle, initUnselectedStyle, initPressedStyle, initDisabledStyle, initSelectedStyle, getUnselectedStyle, setUnselectedStyle, getSelectedStyle, setSelectedStyle, getDisabledStyle, setDisabledStyle, installDefaultPainter, requestFocus, toString, refreshTheme, refreshTheme, isDragActivated, animate, scrollRectToVisible, scrollRectToVisible, paintBorder, paintBorderBackground, isCellRenderer, isScrollVisible, setScrollVisible, setIsScrollVisible, startEditingAsync, stopEditing, isEditing, laidOut, isInitialized, setInitialized, styleChanged, getNextFocusDown, setNextFocusDown, getNextFocusUp, setNextFocusUp, getNextFocusLeft, setNextFocusLeft, getNextFocusRight, setNextFocusRight, getName, setName, initCustomStyle, deinitializeCustomStyle, isRTL, setRTL, isTactileTouch, isTactileTouch, setTactileTouch, getPropertyNames, getPropertyTypes, getPropertyTypeNames, getPropertyValue, setPropertyValue, paintLockRelease, paintLock, isSnapToGrid, setSnapToGrid, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, blocksSideSwipe, isFlatten, setFlatten, getTensileLength, setTensileLength, isGrabsPointerEvents, setGrabsPointerEvents, getScrollOpacityChangeSpeed, setScrollOpacityChangeSpeed, growShrink, isAlwaysTensile, setAlwaysTensile, isDraggable, setDraggable, isDropTarget, setDropTarget, isChildOf, isHideInPortrait, setHideInPortrait, getBindablePropertyNames, getBindablePropertyTypes, bindProperty, unbindProperty, getBoundPropertyValue, setBoundPropertyValue, getCloudBoundProperty, setCloudBoundProperty, getCloudDestinationProperty, setCloudDestinationProperty, getComponentState, setComponentState, setHidden, isHidden, setHidden, isHidden, announceForAccessibility, getAccessibilityText, setAccessibilityText, getSemantics, getAccessibilityNode, accessibilityChanged, accessibilityChanged, getTooltip, setTooltip

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.

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()
Checks to see if the component is editable. This is used for next/previous focus traversal on forms.

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 scheduler = new Scheduler();
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()
Allows subclasses to bind functionality that relies on fully initialized and “ready for action” component state

deinitialize

protected void deinitialize()
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.