Class Gantt
- All Implemented Interfaces:
Animation, Editable, StyleListener, Iterable<Component>
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();

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.

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.

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 Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe columns the table can show after the name of a task. -
Field Summary
Fields inherited from class Component
BASELINE, BOTTOM, BRB_CENTER_OFFSET, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_OTHER, CENTER, CROSSHAIR_CURSOR, DEFAULT_CURSOR, DRAG_REGION_IMMEDIATELY_DRAG_X, DRAG_REGION_IMMEDIATELY_DRAG_XY, DRAG_REGION_IMMEDIATELY_DRAG_Y, DRAG_REGION_LIKELY_DRAG_X, DRAG_REGION_LIKELY_DRAG_XY, DRAG_REGION_LIKELY_DRAG_Y, DRAG_REGION_NOT_DRAGGABLE, DRAG_REGION_POSSIBLE_DRAG_X, DRAG_REGION_POSSIBLE_DRAG_XY, DRAG_REGION_POSSIBLE_DRAG_Y, E_RESIZE_CURSOR, HAND_CURSOR, LEFT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NW_RESIZE_CURSOR, RIGHT, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, TOP, W_RESIZE_CURSOR, WAIT_CURSOR -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidprotected voidInvoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy.voidintThe ISO day weeks start on in the time axis: 1 is Monday.getModel()protected voidAllows subclasses to bind functionality that relies on fully initialized and "ready for action" component statebooleanbooleanisCollapsed(GanttTask task) Whether the children of a summary task are hidden.booleanWhether bars can be dragged, progress set and links made.booleanWhether the load of the resources is shown under the chart.booleanWhether the captured baseline of every task is drawn under its bar.booleanWhether the tasks and links with no slack are drawn as critical.booleanWhether the links between tasks are drawn.booleanWhether the table of tasks is shown beside the chart.booleanWhether the bar of zoom buttons and options is shown above the chart.voidThe bar is a row where there is room for one, and two rows on a screen as narrow as a phone's.level()Delays tasks until no resource is asked for more than its capacity, as far as the plan allows, and schedules the project again.voidrefresh()Draws the project again, for a model changed in a way it could not report itself.voidvoidscrollToDate(long time) voidscrollToTask(GanttTask task) Brings a task's row and the start of its bar into view, opening the summary tasks it is under.voidset24Hours(boolean v) voidsetAnimationTime(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.voidvoidsetCollapsed(GanttTask task, boolean v) voidsetColumns(Gantt.Column... c) The columns of the table after the name, in order.voidsetCurrentTime(long millis) Fixes what the chart takes the current time to be, for a screenshot or a test.voidsetDragEdits(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.voidsetEditable(boolean v) voidsetFirstDayOfWeek(int isoDay) voidsetLoadVisible(boolean v) voidShows another project, or none whenmis null.voidsetSelectedTask(GanttTask task) Selects a task, or nothing whentaskis null.voidsetShowBaseline(boolean v) voidsetShowCriticalPath(boolean v) voidsetShowLinks(boolean v) voidsetTableVisible(boolean v) voidsetToolbarVisible(boolean v) voidzoomIn()voidzoomOut()voidShows the whole project in the width there is.Methods inherited from class Container
add, add, add, add, add, add, addAll, addComponent, addComponent, addComponent, addComponent, animateHierarchy, animateHierarchyAndWait, animateHierarchyFade, animateHierarchyFadeAndWait, animateLayout, animateLayoutAndWait, animateLayoutFade, animateLayoutFadeAndWait, animateUnlayout, animateUnlayoutAndWait, applyRTL, calcPreferredSize, cancelRepaints, clearClientProperties, constrainHeightWhenScrollable, constrainWidthWhenScrollable, contains, createAnimateHierarchy, createAnimateHierarchyFade, createAnimateLayout, createAnimateLayoutFade, createAnimateLayoutFadeAndWait, createAnimateMotion, createAnimateUnlayout, createReplaceTransition, dragInitiated, drop, encloseIn, encloseIn, findDropTargetAt, findFirstFocusable, fireClicked, flushReplace, forceRevalidate, getBottomGap, getChildrenAsList, getClosestComponentTo, getComponentAt, getComponentAt, getComponentCount, getComponentIndex, getGridPosX, getGridPosY, getLayout, getLayoutHeight, getLayoutWidth, getLeadComponent, getLeadParent, getResponderAt, getSafeAreaRoot, getScrollIncrement, getSideGap, getUIManager, initLaf, invalidate, isEnabled, isSafeArea, isSafeAreaRoot, isScrollableX, isScrollableY, isSelectableInteraction, isSurface, iterator, iterator, keyPressed, keyReleased, morph, morphAndWait, paint, paintComponentBackground, paintGlass, paramString, pointerPressed, refreshTheme, removeAll, removeComponent, replace, replace, replaceAndWait, replaceAndWait, replaceAndWait, revalidate, revalidateLater, revalidateWithAnimationSafety, scrollComponentToVisible, setCellRenderer, setEnabled, setLayout, setLeadComponent, setSafeArea, setSafeAreaRoot, setScrollable, setScrollableX, setScrollableY, setScrollIncrement, setShouldCalcPreferredSize, setShouldLayout, setUIManager, updateTabIndicesMethods inherited from class Component
accessibilityChanged, accessibilityChanged, addContextMenuListener, addDragFinishedListener, addDragOverListener, addDropListener, addFocusListener, addLongPressListener, addMouseWheelListener, addNativeDragOverListener, addNativeDropListener, addPointerDraggedListener, addPointerPressedListener, addPointerReleasedListener, addPullToRefresh, addScrollListener, addStateChangeListener, addStylusListener, animate, announceForAccessibility, bindProperty, blocksSideSwipe, calcScrollSize, canAcceptNativeDrop, consumesRawTextInput, contains, containsOrOwns, createNativeDragOperation, createStyleAnimation, deinitializeCustomStyle, deregisterFromAnimation, dragEnter, dragExit, dragFinished, draggingOver, drawDraggedImage, focusGained, focusLost, getAbsoluteX, getAbsoluteY, getAcceptedDropActions, getAcceptedDropMimeTypes, getAccessibilityNode, getAccessibilityText, getAllStyles, getAnimationManager, getBaseline, getBaselineResizeBehavior, getBindablePropertyNames, getBindablePropertyTypes, getBorder, getBoundPropertyValue, getBounds, getBounds, getClientProperty, getCloudBoundProperty, getCloudDestinationProperty, getComponentForm, getComponentState, getContextMenuCommands, getCursor, getDefaultDragTransparency, getDirtyRegion, getDisabledStyle, getDraggedx, getDraggedy, getDragImage, getDragRegionStatus, getDragSpeed, getDragTransparency, getEditingDelegate, getHeight, getHoverStyle, getInlineAllStyles, getInlineDisabledStyles, getInlinePressedStyles, getInlineSelectedStyles, getInlineStylesTheme, getInlineUnselectedStyles, getInnerHeight, getInnerPreferredH, getInnerPreferredW, getInnerWidth, getInnerX, getInnerY, getLabelForComponent, getName, getNativeDragOperation, getNativeOverlay, getNextFocusDown, getNextFocusLeft, getNextFocusRight, getNextFocusUp, getOuterHeight, getOuterPreferredH, getOuterPreferredW, getOuterWidth, getOuterX, getOuterY, getOwner, getParent, getPreferredH, getPreferredSize, getPreferredSizeStr, getPreferredTabIndex, getPreferredW, getPressedStyle, getPropertyNames, getPropertyTypeNames, getPropertyTypes, getPropertyValue, getSameHeight, getSameWidth, getScrollable, getScrollAnimationSpeed, getScrollDimension, getScrollOpacity, getScrollOpacityChangeSpeed, getScrollX, getScrollY, getSelectCommandText, getSelectedRect, getSelectedStyle, getSemantics, getStyle, getTabIndex, getTensileLength, getTextSelectionSupport, getTooltip, getTopLevelContainer, getUIID, getUnselectedStyle, getVisibleBounds, getVisibleBounds, getWidth, getX, getY, growShrink, handlesInput, hasFixedPreferredSize, hasFocus, hideNativeOverlay, initCustomStyle, initDisabledStyle, initPressedStyle, initSelectedStyle, initUnselectedStyle, installDefaultPainter, isAlwaysTensile, isBlockLead, isCellRenderer, isChildOf, isDragActivated, isDragAndDropOperation, isDraggable, isDragRegion, isDropTarget, isEditing, isFlatten, isFocusable, isGrabsPointerEvents, isHidden, isHidden, isHideInLandscape, isHideInPortrait, isHovered, isHScrollThumbGrabbed, isHScrollThumbHover, isIgnorePointerEvents, isInClippingRegion, isInitialized, isNativeDragSource, isNativeDropTarget, isOpaque, isOwnedBy, isPinchBlocksDragAndDrop, isRippleEffect, isRTL, isScrollable, isScrollVisible, isSetCursorSupported, isSmoothScrolling, isSnapToGrid, isStickyDrag, isTactileTouch, isTactileTouch, isTensileDragEnabled, isTraversable, isVisible, isVScrollThumbGrabbed, isVScrollThumbHover, keyRepeated, laidOut, longKeyPress, longPointerPress, mouseWheel, nativeDragEnter, nativeDragExit, nativeDragOver, nativeDrop, onScrollX, onScrollY, onSetFocusable, paintBackground, paintBackgrounds, paintBorder, paintBorderBackground, paintComponent, paintComponent, paintIntersectingComponentsAbove, paintLock, paintLockRelease, paintRippleOverlay, paintScrollbars, paintScrollbarX, paintScrollbarY, paintShadows, parsePreferredSize, pinch, pinch, pinchReleased, pointerDragged, pointerDragged, pointerHover, pointerHoverPressed, pointerHoverReleased, pointerPressed, pointerReleased, pointerReleased, putClientProperty, refreshTheme, refreshTheme, registerForAnimation, remove, removeContextMenuListener, removeDragFinishedListener, removeDragOverListener, removeDropListener, removeFocusListener, removeLongPressListener, removeMouseWheelListener, removeNativeDragOverListener, removeNativeDropListener, removePointerDraggedListener, removePointerPressedListener, removePointerReleasedListener, removeScrollListener, removeStateChangeListener, removeStylusListener, repaint, repaint, requestFocus, resetFocusable, respondsToPointerEvents, rotation, scrollRectToVisible, scrollRectToVisible, setAcceptedDropActions, setAcceptedDropMimeTypes, setAccessibilityText, setAlwaysTensile, setBlockLead, setBoundPropertyValue, setCloudBoundProperty, setCloudDestinationProperty, setComponentState, setContextMenuCommands, setCursor, setDefaultDragTransparency, setDirtyRegion, setDisabledStyle, setDraggable, setDragTransparency, setDropTarget, setEditingDelegate, setFlatten, setFocus, setFocusable, setGrabsPointerEvents, setHandlesInput, setHeight, setHidden, setHidden, setHideInLandscape, setHideInPortrait, setHorizontalScrollBounds, setHovered, setHoverStyle, setIgnorePointerEvents, setInitialized, setInlineAllStyles, setInlineDisabledStyles, setInlinePressedStyles, setInlineSelectedStyles, setInlineStylesTheme, setInlineUnselectedStyles, setIsScrollVisible, setLabelForComponent, setName, setNativeDragOperation, setNativeDragSource, setNativeDropTarget, setNextFocusDown, setNextFocusLeft, setNextFocusRight, setNextFocusUp, setOpaque, setOwner, setPinchBlocksDragAndDrop, setPreferredH, setPreferredSize, setPreferredSizeStr, setPreferredTabIndex, setPreferredW, setPressedStyle, setPropertyValue, setPullToRefresh, setRippleEffect, setRTL, setSameHeight, setSameSize, setSameWidth, setScrollAnimationSpeed, setScrollOpacityChangeSpeed, setScrollSize, setScrollVisible, setScrollX, setScrollY, setSelectCommandText, setSelectedStyle, setSize, setSmoothScrolling, setSnapToGrid, setTabIndex, setTactileTouch, setTensileDragEnabled, setTensileLength, setTooltip, setTraversable, setUIID, setUIID, setUIIDFinal, setUnselectedStyle, setVerticalScrollBounds, setVisible, setWidth, setX, setY, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, shouldRenderComponentSelection, showNativeOverlay, startEditingAsync, stopEditing, stopScrollMomentum, stripMarginAndPadding, styleChanged, toImage, toString, unbindProperty, updateNativeOverlay, visibleBoundsContainsMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Iterable
forEach, spliterator
-
Constructor Details
-
Gantt
public Gantt()A chart with no project yet. -
Gantt
-
-
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:
layoutContainerin classContainer
-
isToolbarVisible
public boolean isToolbarVisible()Whether the bar of zoom buttons and options is shown above the chart. -
setToolbarVisible
public void setToolbarVisible(boolean v) -
getModel
-
setModel
Shows another project, or none whenmis 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()Description copied from class:ComponentAllows subclasses to bind functionality that relies on fully initialized and "ready for action" component state- Overrides:
initComponentin classComponent
-
deinitialize
protected void deinitialize()Description copied from class:ComponentInvoked 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:
deinitializein classComponent
-
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.- Specified by:
isEditablein interfaceEditable- Overrides:
isEditablein classComponent
-
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
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
-
setBarRenderer
-
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.setAnimationTime(1000); // nothing has started // ... press, drag, release ... gantt.setAnimationTime(1100); // 100 milliseconds into what followed -
isCollapsed
Whether the children of a summary task are hidden. -
setCollapsed
-
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
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
-
setSelectedTask
Selects a task, or nothing whentaskis null. The listeners are not told: this is the application's own doing. -
addGanttListener
-
removeGanttListener
-