Class Gantt

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

public class Gantt extends Container

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.

  • 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.
      Overrides:
      layoutContainer in class Container
    • 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()
      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
    • 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.
      Specified by:
      isEditable in interface Editable
      Overrides:
      isEditable in class Component
    • 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.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)