Flowcharts and Kanban boards in Java

Show a business user their process as a flowchart and they understand it in ten seconds. Show them the same process as a table of states and they ask for a meeting. That’s why every serious business app ends up needing a diagram: an approval flow, an org chart, a network map, a pipeline of deals. And in almost every framework, that diagram is a third party extension, a commercial license, or a web view running a JavaScript library inside your native app.

That’s backwards. The baseline for a business app moved, and a framework that stops at buttons and lists stops short of what your users expect. So this week Codename One ships two new core components: NodeGraph for diagrams and node editors, and KanbanBoard.

A diagram in six lines

DefaultGraphModel model = new DefaultGraphModel();
model.addNode(new GraphNode("web", "Web app"));
model.addNode(new GraphNode("api", "API gateway"));
model.addEdge("web", "api");
NodeGraph graph = new NodeGraph(model);
graph.arrange(new LayeredArrangement(), false);

You don’t place anything. The graph lays itself out. LayeredArrangement is for flows, TreeArrangement for hierarchies, RadialArrangement for something at the center, and ForceArrangement for networks, and it can run live while the user drags. Pin a node and the layout flows around it.

A service architecture laid out automatically
Layered layout.
A tree laid out automatically
Tree layout.
A radial layout
Radial layout.
A force directed network layout
Force layout.

Like our DataGrid and Gantt chart, NodeGraph paints its nodes instead of making a component for each one, so thousands of nodes pan and zoom smoothly on a phone. Zoom far out and nodes become plain cards, the way a map drops street names.

Flowcharts with swim lanes

Flowchart shapes, swim lanes, edge labels and line styles are built in:

model.addGroup(GraphGroup.lane("shop", "Shop", true, 0, 0, 620, 150));
GraphNode paid = new GraphNode("paid", "Paid?", 220, 40, 110, 70)
        .setShape(GraphShapes.DECISION);
paid.setGroupId("shop");
model.addNode(paid);
model.addEdge("paid", "cancel").setLabel("no");
model.addEdge("paid", "pick").setLabel("yes");

NodeGraph graph = new NodeGraph(model);
graph.setEdgeStyle(NodeGraph.EDGE_ORTHOGONAL);
graph.setEditingEnabled(true);

A flowchart with swim lanes for the shop and the warehouse

Turn editing on and the user can draw their own: a palette of shapes to drag in, resize handles, a minimap, undo and redo, and copy and paste. GraphJson saves the diagram and loads it back, so the flowchart a manager drew on an iPad goes to your server and opens on a colleague’s desktop.

Node editors, like the ones in game engines

The second mode is the one you know from shader editors and automation tools. Nodes have typed ports, and the user wires outputs to inputs:

model.addNode(new GraphNode("noise", "Noise", 0, 0, 160, 90)
        .addOutput("out", "Value", "float"));
model.addNode(new GraphNode("color", "Color ramp", 240, 0, 160, 90)
        .addInput("in", "Factor", "float")
        .addOutput("out", "Color", "color"));
NodeGraph graph = new NodeGraph(model);
graph.setEditingEnabled(true);
graph.setEdgeStyle(NodeGraph.EDGE_CURVED);

A ConnectionValidator refuses a wire from a color into a number, setMaxConnections caps a port, and setAllowCycles(false) keeps the graph acyclic. Nodes can hold real components, a slider or a text field inside a node that scales with the zoom. That’s the building block for a workflow builder, an IoT rule engine, a visual query designer or a no-code tool inside your product.

A port based node editor with typed connections
A node editor with typed ports.
Nodes containing live components
Real components inside nodes.

Kanban, with the rules teams actually use

DefaultKanbanModel model = new DefaultKanbanModel();
model.addColumn(new KanbanColumn("todo", "To do"));
model.addColumn(new KanbanColumn("doing", "Doing").setWipLimit(2));
model.addColumn(new KanbanColumn("done", "Done").setCollapsed(true));
model.setEnforceWipLimits(true);
model.addLane(new KanbanLane("app", "App"));
model.addCard("todo", new KanbanCard("c1", "Dark mode").setLaneId("app").addTag("ui"));
KanbanBoard board = new KanbanBoard(model);

Cards carry tags, badges, and descriptions. Swim lanes split the board by team or customer. A WIP limit is either a warning or a hard rule. Cards and whole columns drag, a long press lifts a card on a touch screen, and on a phone setColumnSnap(true) makes the board page one column at a time instead of shrinking into something unreadable. Undo and redo come built in.

A Kanban board with tagged cards
The board.
A Kanban board with swim lanes and a WIP limit
Swim lanes and WIP limits.

A Kanban board isn’t only for software teams. It’s a sales pipeline, a hiring funnel, a repair shop’s queue of devices, a content calendar. Any process where things move through stages is a board, and now it’s one constructor away.

Remix them

Put a Kanban board of service tickets next to Fieldline’s dispatch map. Let an operations manager draw the approval flow as a diagram, save it with GraphJson, and have your backend execute it. Attach the spreadsheet each stage produces and the PDF it ends in. Every one of these exists somewhere. Getting all of them in one framework, tested together on every platform, is the hard part.

Tomorrow: Brickyard, a game platform with its own studio, plus portable shaders and 3D audio.