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

public class Gantt

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

ImplementsAnimation, Editable, Iterable<Component>, StyleListener

A Gantt chart of a ProjectModel: the tree of tasks in a table on the left, a bar for each against a time axis on the right, the links between them, and under them how much of every resource the plan asks for.

WorkCalendar calendar = new WorkCalendar();
// A duration is working time: a day of it is the calendar's hours.
long day = calendar.getMillisPerDay();
ProjectModel project = new ProjectModel(calendar, System.currentTimeMillis());
GanttTask design = new GanttTask("design", "Design", 5 * day);
GanttTask build = new GanttTask("build", "Build", 10 * day);
project.addTask(design).addTask(build);
project.link(design, build);
project.update();

Form form = new Form("Plan", new BorderLayout());
form.add(BorderLayout.CENTER, new Gantt(project));
form.show();

A Gantt chart with its critical path

The chart draws its rows and keeps no component for each, so a plan of thousands of tasks scrolls as one of ten does. Time zooms with a pinch, with the wheel and the control key held, or with zoomIn, zoomOut and zoomToFit.

Editing

A bar is dragged to move it and by its end to change its duration. With a mouse that is a plain drag; on a touch screen a drag scrolls, so a long press picks the bar up. The selected task shows a marker under its bar, dragged to set how much of it is done, and a dot after its end, dragged onto another bar to make that one depend on it.

A task the project schedules is not placed by a drag: the drag sets a “start no earlier than” constraint, and the task then starts there or later if its predecessors say so. A manually scheduled task is given the dates as they are. Every change is offered to the listeners first, which may refuse it, and then the project is scheduled again and the bars slide to where they now are. A summary task follows its children and is not dragged. The table is not edited in place: a double tap is reported to GanttListener#taskOpened, for an application’s own editor.

Under a mouse the bar the pointer is over lights up together with the links into and out of it, the row is marked in the table and in the chart, the cursor says what a drag would do and a tooltip gives the task’s dates and progress. A bar that is picked up lifts over a shadow.

A bar moved and the tasks after it following, as four stopped frames

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

Resources

setLoadVisible(true) shows the load of every resource under the chart. A stretch over the resource’s capacity is drawn in GanttOverload. level() delays tasks until no resource is asked for more than it has, as far as that can be done.

The load of each resource under the chart

Styling

GanttRow is a row, with its selected style the selected one, and GanttSummaryRow the row of a summary task; GanttHeader the time axis and the titles of the table. The bars are GanttBar, with GanttBarProgress the part done, GanttBarCritical, GanttSummaryBar and GanttMilestone; GanttBaseline is the plan as it was captured. GanttLink and GanttLinkCritical give the links their foreground colour, GanttLoad and GanttOverload the resource load. A task that names a UIID or a colour of its own is painted with that.

Nested types

enum Gantt.ColumnThe columns the table can show after the name of a task.

Constructors

public Gantt()A chart with no project yet.
public Gantt(ProjectModel 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 boolean isToolbarVisible()Whether the bar of zoom buttons and options is shown above the chart.
public void setToolbarVisible(boolean v)
public ProjectModel getModel()
public void setModel(ProjectModel m)Shows another project, or none when m is null.
public void refresh()Draws the project again, for a model changed in a way it could not report itself.
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.
public LevelingResult level()Delays tasks until no resource is asked for more than its capacity, as far as the plan allows, and schedules the project again.
public boolean isShowCriticalPath()Whether the tasks and links with no slack are drawn as critical.
public void setShowCriticalPath(boolean v)
public boolean isShowBaseline()Whether the captured baseline of every task is drawn under its bar.
public void setShowBaseline(boolean v)
public boolean isShowLinks()Whether the links between tasks are drawn.
public void setShowLinks(boolean v)
public boolean isEditable()Whether bars can be dragged, progress set and links made.
public void setEditable(boolean v)
public void setDragEdits(boolean v)Whether a bar is moved by a plain drag, as with a mouse, or only after a long press, which leaves a plain drag to scroll.
public boolean isLoadVisible()Whether the load of the resources is shown under the chart.
public void setLoadVisible(boolean v)
public boolean isTableVisible()Whether the table of tasks is shown beside the chart.
public void setTableVisible(boolean v)
public void setColumns(Gantt.Column... c)The columns of the table after the name, in order.
public boolean is24Hours()
public void set24Hours(boolean v)
public int getFirstDayOfWeek()The ISO day weeks start on in the time axis: 1 is Monday.
public void setFirstDayOfWeek(int isoDay)
public GanttBarRenderer getBarRenderer()
public void setBarRenderer(GanttBarRenderer r)
public void setCurrentTime(long millis)Fixes what the chart takes the current time to be, for a screenshot or a test.
public void setAnimationTime(long millis)Stops the clock the chart 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 slide of the bars to their new dates are drawn as far along as that time makes them.
public boolean isCollapsed(GanttTask task)Whether the children of a summary task are hidden.
public void setCollapsed(GanttTask task, boolean v)
public void expandAll()
public void collapseAll()
public void zoomIn()
public void zoomOut()
public void zoomToFit()Shows the whole project in the width there is.
public void scrollToTask(GanttTask task)Brings a task’s row and the start of its bar into view, opening the summary tasks it is under.
public void scrollToDate(long time)
public GanttTask getSelectedTask()
public void setSelectedTask(GanttTask task)Selects a task, or nothing when task is null.
public void addGanttListener(GanttListener l)
public void removeGanttListener(GanttListener l)

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

Gantt

public Gantt()
A chart with no project yet.

Gantt

public Gantt(ProjectModel 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.

isToolbarVisible

public boolean isToolbarVisible()
Whether the bar of zoom buttons and options is shown above the chart.

setToolbarVisible

public void setToolbarVisible(boolean v)

getModel

public ProjectModel getModel()

setModel

public void setModel(ProjectModel m)
Shows another project, or none when m is null.

refresh

public void refresh()
Draws the project again, for a model changed in a way it could not report itself.

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.

level

public LevelingResult level()
Delays tasks until no resource is asked for more than its capacity, as far as the plan allows, and schedules the project again. What could not be resolved is in the result, as is the finish of the project before and after. Returns null when there is no project.

isShowCriticalPath

public boolean isShowCriticalPath()
Whether the tasks and links with no slack are drawn as critical.

setShowCriticalPath

public void setShowCriticalPath(boolean v)

isShowBaseline

public boolean isShowBaseline()
Whether the captured baseline of every task is drawn under its bar.

setShowBaseline

public void setShowBaseline(boolean v)

isShowLinks

public boolean isShowLinks()
Whether the links between tasks are drawn. They are by default.

setShowLinks

public void setShowLinks(boolean v)

isEditable

public boolean isEditable()
Whether bars can be dragged, progress set and links made.

setEditable

public void setEditable(boolean v)

setDragEdits

public void setDragEdits(boolean v)
Whether a bar is moved by a plain drag, as with a mouse, or only after a long press, which leaves a plain drag to scroll. The default follows the device.

isLoadVisible

public boolean isLoadVisible()
Whether the load of the resources is shown under the chart.

setLoadVisible

public void setLoadVisible(boolean v)

isTableVisible

public boolean isTableVisible()
Whether the table of tasks is shown beside the chart.

setTableVisible

public void setTableVisible(boolean v)

setColumns

public void setColumns(Gantt.Column... c)
The columns of the table after the name, in order.

is24Hours

public boolean is24Hours()

set24Hours

public void set24Hours(boolean v)

getFirstDayOfWeek

public int getFirstDayOfWeek()
The ISO day weeks start on in the time axis: 1 is Monday.

setFirstDayOfWeek

public void setFirstDayOfWeek(int isoDay)

getBarRenderer

public GanttBarRenderer getBarRenderer()

setBarRenderer

public void setBarRenderer(GanttBarRenderer r)

setCurrentTime

public void setCurrentTime(long millis)
Fixes what the chart 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 chart 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 slide of the bars to their new dates are drawn as far along as that time makes them. A negative value returns to the clock.

Gantt gantt = new Gantt();
gantt.setAnimationTime(1000);  // nothing has started
// ... press, drag, release ...
gantt.setAnimationTime(1100);  // 100 milliseconds into what followed

isCollapsed

public boolean isCollapsed(GanttTask task)
Whether the children of a summary task are hidden.

setCollapsed

public void setCollapsed(GanttTask task, boolean v)

expandAll

public void expandAll()

collapseAll

public void collapseAll()

zoomIn

public void zoomIn()

zoomOut

public void zoomOut()

zoomToFit

public void zoomToFit()
Shows the whole project in the width there is.

scrollToTask

public void scrollToTask(GanttTask task)
Brings a task’s row and the start of its bar into view, opening the summary tasks it is under.

scrollToDate

public void scrollToDate(long time)

getSelectedTask

public GanttTask getSelectedTask()

setSelectedTask

public void setSelectedTask(GanttTask task)
Selects a task, or nothing when task is null. The listeners are not told: this is the application’s own doing.

addGanttListener

public void addGanttListener(GanttListener l)

removeGanttListener

public void removeGanttListener(GanttListener l)