Class KanbanBoard

All Implemented Interfaces:
Animation, Editable, StyleListener

public class KanbanBoard extends ScrollSurface

A Kanban board: columns of cards, dragged from one stage to the next.

DefaultKanbanModel model = new DefaultKanbanModel();
model.addColumn(new KanbanColumn("todo", "To do"));
model.addColumn(new KanbanColumn("doing", "Doing").setWipLimit(3));
model.addColumn(new KanbanColumn("done", "Done"));
model.addCard("todo", new KanbanCard("c1", "Write the release notes").addTag("docs"));

Form form = new Form("Board", new BorderLayout());
KanbanBoard board = new KanbanBoard(model);
form.add(BorderLayout.CENTER, board);
form.show();

The whole board scrolls as one surface, both ways, under column titles that stay in view. A card is dragged with a mouse, or after a long press with a finger, which leaves a plain drag free to scroll; the other cards make room where it would land. Column titles are dragged the same way to reorder the columns, and the mark at the end of a title folds the column to a strip. With KanbanLanes in the model the board has swimlanes, each under a title that folds it.

A column shows how many cards it holds, against its limit when it has one, and is marked when it is over. A model that enforces its limits (DefaultKanbanModel.setEnforceWipLimits) shows the refusal while the card is still held over the column.

On a narrow screen setColumnSnap brings scrolling to rest on a column. A KanbanCardFactory puts a component in each card; it is drawn with the card, and a tap on it reaches it.

The row under the cards of a column adds a card, typed in place, and a double tap renames one. Every edit is offered to the KanbanListeners and then to the model, and with setUndoHistory can be undone. With a keyboard, Delete removes the selected card, and with Control or Command, C, X, V and D copy, cut, paste and duplicate it, Z undoes and Shift-Z redoes.

Styling

The UIIDs are KanbanBoard, KanbanColumn, KanbanColumnHeader, KanbanColumnOverLimit, KanbanCard, KanbanCardSelected, KanbanCardTag, KanbanLane, KanbanAddCard and KanbanDropSlot. A theme that defines none of them gets defaults that follow its light or dark mode.

  • Constructor Details

    • KanbanBoard

      public KanbanBoard()
      An empty board backed by a new DefaultKanbanModel.
    • KanbanBoard

      public KanbanBoard(KanbanModel model)
      A board showing model.
  • Method Details

    • getModel

      public KanbanModel getModel()
      The model shown.
    • setModel

      public void setModel(KanbanModel model)
      Shows another model. An edit under way ends, and the undo history is cleared: its steps belong to the model that was shown. That is the whole history, the steps of another component sharing it included.
    • modelChanged

      public void modelChanged()

      The model changed: the board is laid out again before it is next painted or asked where something is. Called by the model's listener, and by an application that changed a card behind the model's back, such as its tags.

      Nothing is measured here, so filling a model a card at a time while a board shows it costs one layout and not one per card.

    • getCardRenderer

      public KanbanCardRenderer getCardRenderer()
      Paints the cards. Never null.
    • setCardRenderer

      public void setCardRenderer(KanbanCardRenderer renderer)
      Sets the renderer of the cards.
    • getCardFactory

      public KanbanCardFactory getCardFactory()
      Makes the components inside the cards, or null.
    • setCardFactory

      public void setCardFactory(KanbanCardFactory cardFactory)
      Puts a real component inside each card; null, the default, for cards that are only painted.
    • getCardComponent

      public Component getCardComponent(KanbanCard card)
      The component the factory made for a card, or null.
    • getCardComponentHeight

      public int getCardComponentHeight(KanbanCard card)
      The height, in pixels, the component of a card takes at the bottom of it; 0 for a card without one.
    • addKanbanListener

      public void addKanbanListener(KanbanListener l)
      Adds a listener.
    • removeKanbanListener

      public void removeKanbanListener(KanbanListener l)
      Removes a listener.
    • isEditingEnabled

      public boolean isEditingEnabled()
      True when the user can move, add, rename and remove cards.
    • setEditingEnabled

      public void setEditingEnabled(boolean editable)
      Lets the user edit the board, the default, or only look at it. A board that is not editable still folds its columns and lanes.
    • isColumnReorderEnabled

      public boolean isColumnReorderEnabled()
      True when the columns can be dragged into another order.
    • setColumnReorderEnabled

      public void setColumnReorderEnabled(boolean columnReorder)
      Lets the user drag a column by its title to another place; on by default.
    • isInlineAdd

      public boolean isInlineAdd()
      True when every column ends in a row that adds a card.
    • setInlineAdd

      public void setInlineAdd(boolean inlineAdd)
      Shows a row under the cards of each column that adds a card typed in place; on by default.
    • isInlineEditing

      public boolean isInlineEditing()
      True when a double tap renames a card in place.
    • setInlineEditing

      public void setInlineEditing(boolean inlineEditing)
      Makes a double tap on a card rename it in place, the default, or only tell the listeners the card was opened.
    • isColumnSnap

      public boolean isColumnSnap()
      True when scrolling comes to rest on a column.
    • setColumnSnap

      public void setColumnSnap(boolean columnSnap)
      Makes scrolling across the board come to rest with a column at its leading edge, so a narrow screen shows one whole column at a time and not the halves of two. Off by default.
    • getAddCardText

      public String getAddCardText()
      The text of the row that adds a card.
    • setAddCardText

      public void setAddCardText(String addCardText)
      Sets the text of the row that adds a card, for another language.
    • getColumnWidth

      public float getColumnWidth()
      The width of a column, in millimetres.
    • setColumnWidth

      public void setColumnWidth(float millimetres)
      Sets the width of a column, in millimetres; 42 by default. On a screen narrower than that a column takes the screen, less a strip that shows there is a next one.
    • getSelectedCard

      public KanbanCard getSelectedCard()
      The selected card, or null.
    • select

      public void select(KanbanCard card)
      Selects a card, or with null none.
    • scrollToColumn

      public void scrollToColumn(KanbanColumn column)
      Scrolls so a column is at the leading edge of the view.
    • scrollToCard

      public void scrollToCard(KanbanCard card)
      Scrolls so a card is in view.
    • getUndoHistory

      public UndoHistory getUndoHistory()
      The history edits are recorded in, or null.
    • setUndoHistory

      public void setUndoHistory(UndoHistory undoHistory)
      Records every edit the user makes in a history, so it can be undone. The application's history, UndoHistory.getGlobal(), by default; null records nothing. An undone or redone step brings the board back into view (ComponentEdit). Changes the application makes to the model directly are not recorded.
    • undo

      public boolean undo()

      Takes back the last edit in the history.

      Returns

      false when there is no history, nothing to undo, editing is off, or a card or column is being dragged

    • redo

      public boolean redo()

      Makes the last undone edit again.

      Returns

      false when there is no history, nothing to redo, editing is off, or a card or column is being dragged

    • moveCard

      public boolean moveCard(KanbanCard card, KanbanColumn column, KanbanLane lane, int index)

      Moves a card to an index of a cell, as a drop there does: offered to the listeners, then to the model, and recorded for undo. lane is null on a board without lanes. The index counts the cell without the card.

      Returns

      false when a listener or the model refused

    • moveColumn

      public boolean moveColumn(KanbanColumn column, int index)

      Moves a column to an index, counted without it, as dragging its title does.

      Returns

      false when a listener or the model refused

    • addCard

      public KanbanCard addCard(KanbanColumn column, KanbanLane lane, String title)

      Adds a card with a title at the end of a cell, as typing it into the row under the column does: offered to the listeners, then to the model, recorded for undo and selected. lane is null on a board without lanes.

      Returns

      the card, or null when it was refused

    • renameCard

      public boolean renameCard(KanbanCard card, String title)

      Gives a card another title, as renaming it in place does.

      Returns

      false when a listener or the model refused

    • removeCard

      public boolean removeCard(KanbanCard card)

      Removes a card, as Delete on it does.

      Returns

      false when a listener or the model refused

    • duplicateSelection

      public boolean duplicateSelection()

      Adds a copy of the selected card under it.

      Returns

      false when no card is selected or the copy was refused

    • setUserDataCodec

      public void setUserDataCodec(KanbanJson.UserDataCodec codec)
      Writes the user data of a copied card to the clipboard and reads it back on paste; without one, a pasted card has no user data.
    • copySelection

      public boolean copySelection()

      Puts the selected card on the clipboard, as JSON.

      Returns

      false when no card is selected

    • cutSelection

      public boolean cutSelection()

      Copies the selected card and removes it.

      Returns

      false when no card is selected or it could not be removed

    • paste

      public boolean paste()

      Adds the card on the clipboard under the selected card, or at the end of the first column when none is selected.

      Returns

      false when the clipboard holds no card or it was refused

    • isEditing

      public boolean isEditing()
      True while a title is being typed in place.
      Specified by:
      isEditing in interface Editable
      Overrides:
      isEditing in class Component
    • startCardEdit

      public void startCardEdit(KanbanCard card)
      Renames a card in place, in a text field over it; the title goes to renameCard when editing ends.
    • startAddCard

      public void startAddCard(KanbanColumn column, KanbanLane lane)
      Opens the row that adds a card to a cell for typing; the card is added by addCard when editing ends with a title in it.
    • finishEditing

      public void finishEditing()
      Ends the typing of a title and applies it.
    • getCardBounds

      public int[] getCardBounds(KanbanCard card)
      The rectangle of a card in the board's own coordinates, as it is laid out now, or null when it is not shown. For a popup placed by a card, and for tests.
    • getColumnHeaderBounds

      public int[] getColumnHeaderBounds(KanbanColumn column)
      The rectangle of a column's title in the board's own coordinates, or null for a column that is not in the model.
    • toImage

      public Image toImage(int maxWidth, int maxHeight)
      Paints the whole board, every column and card of it, into a new image no larger than the given size, without the selection. For a thumbnail, a share sheet or a printout.
    • layoutSurface

      protected void layoutSurface(int width, int height)
      Description copied from class: ScrollSurface
      Lays the surface out for a size: sets the header sizes and whatever the content's size depends on. Called before every paint and every pointer event, so it has to return at once when nothing has changed.
      Specified by:
      layoutSurface in class ScrollSurface
    • getContentWidth

      protected int getContentWidth()
      Description copied from class: ScrollSurface
      The width of what scrolls, in pixels, without the left header.
      Specified by:
      getContentWidth in class ScrollSurface
    • getContentHeight

      protected int getContentHeight()
      Description copied from class: ScrollSurface
      The height of what scrolls, in pixels, without the top header.
      Specified by:
      getContentHeight in class ScrollSurface
    • paintContent

      protected void paintContent(Graphics g, int x, int y)
      Description copied from class: ScrollSurface
      Paints what scrolls. x and y are where the content's own origin is on screen, which is off screen once it has scrolled. The graphics is clipped to the content region.
      Specified by:
      paintContent in class ScrollSurface
    • paintTopHeader

      protected void paintTopHeader(Graphics g, int x, int y)
      Description copied from class: ScrollSurface
      Paints the pinned top row. x is where the content's origin is; y is the top of the row.
      Overrides:
      paintTopHeader in class ScrollSurface
    • paintOverlay

      protected void paintOverlay(Graphics g, int x, int y)
      Description copied from class: ScrollSurface
      Paints over everything, in the component's own bounds, whose top left is x, y. Not painted on a printed page: it is for what a gesture in progress shows.
      Overrides:
      paintOverlay in class ScrollSurface
    • calcPreferredSize

      protected Dimension calcPreferredSize()
      Description copied from class: Component

      Calculates the preferred size based on component content. This method is invoked lazily by getPreferred size.

      Returns

      the calculated preferred size based on component content

      Overrides:
      calcPreferredSize in class ScrollSurface
    • scrollChanged

      protected void scrollChanged()
      Description copied from class: ScrollSurface
      The scroll position changed.
      Overrides:
      scrollChanged in class ScrollSurface
    • pointerReleased

      public void pointerReleased(int x, int y)
      Description copied from class: Component

      If this Component is focused, the pointer released event will call this method

      Parameters
      • x: the pointer x coordinate

      • y: the pointer y coordinate

      Overrides:
      pointerReleased in class ScrollSurface
    • pressStarted

      protected void pressStarted(int x, int y)
      Description copied from class: ScrollSurface
      The pointer went down at a point, in the component's coordinates. Whatever it turns into -- a tap, a drag, a long press -- follows.
      Overrides:
      pressStarted in class ScrollSurface
    • editStarted

      protected boolean editStarted(int x, int y, ScrollSurface.EditTrigger trigger)
      Description copied from class: ScrollSurface

      Asked when a drag or a long press begins, at the point where the pointer went down, in the component's coordinates.

      Parameters
      • trigger: what kind of gesture it is
      Returns

      true when an edit has begun and the drag belongs to it; false to pan

      Overrides:
      editStarted in class ScrollSurface
    • editMoved

      protected void editMoved(int x, int y)
      Description copied from class: ScrollSurface
      The pointer of an edit moved, or the surface scrolled under it.
      Overrides:
      editMoved in class ScrollSurface
    • editEnded

      protected void editEnded(boolean committed)
      Description copied from class: ScrollSurface
      The edit is over. committed is false when it was cancelled: by cancelEdit, a second finger, or the surface leaving the form.
      Overrides:
      editEnded in class ScrollSurface
    • tapped

      protected void tapped(int x, int y, boolean doubleTap)
      Description copied from class: ScrollSurface
      A tap that was not a drag or a long press.
      Overrides:
      tapped in class ScrollSurface
    • animateSurface

      protected boolean animateSurface()
      Description copied from class: ScrollSurface

      Advances the view's own motion. Called every frame while the surface animates; call requestAnimation to start the frames.

      Returns

      true while the view still has something moving

      Overrides:
      animateSurface in class ScrollSurface
    • 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 ScrollSurface
    • keyPressed

      public void keyPressed(int keyCode)
      Description copied from class: Component

      If this Component is focused, the key pressed event will call this method

      Parameters
      • keyCode: the key code value to indicate a physical key.
      Overrides:
      keyPressed in class Component