The list below describes recent changes and additions to JDiagram:
New in version 4.8
ItemLabel image
New Image property added to ItemLabel lets you display icons along a link's geometry, or add more images to a ShapeNode. If a label contains both Text and Image, their relative position is specified by ImageAlign property (by default the image is placed on left side of text), and distance by ContentPadding. The image is rendered using intrinsic size reported by java.awt.Image, unless you override it by setting ImageSize property. You can treat label images as clickable icons by handling linkClicked or nodeClicked events and checking Label argument passed to their handlers.
Customize node action icons
The Renderers class lets you customize the appearance of nodes' fold, scroll and collapse icons, by providing Graphics2D drawing callbacks, bitmap images or SVG drawings:
Miscellaneous
- Label argument now provided with click and double click events.
- Locked property added to ItemLabel. It lets you prevent users from editing label's text, and moving it when Behavior is set to MoveLabels.
- SVG rendering improvements.
- JSON serialization fixes and improvements.
API changes
New in version 4.7.3
- Improved render quality of bitmaps assigned to node's Image property.
- Improved render quality of Overview control.
- The Brush property of pens is now serialized in binary and XML formats.
New in version 4.7.2
Support for custom in-place edit controls
Handle the
createEditControl event to display a custom Java Swing component for users to edit item's content. This event is raised when entering in-place editing mode, either interactively by users or by calling the
beginEdit method. You could handle the event to return a composite control for editing many of the item's properties, and not only text. When leaving in-place editing mode, the
Diagram raises
destroyEditControl to let you copy to the item any values entered by the user and close the custom editor.
Miscellaneous
New in version 4.7.1
Drag-and-drop improvements
Miscellaneous
- The Opacity property lets you create translucent DiagramItem by applying it to the alpha channel of all colors in the item.
- TableNode copy constructor fixes.
- Improved in-place editing of ItemLabels.
New in version 4.7
Spatial index
Set the
EnableSpatialIndex property of
Diagram to create an index of item positions for faster hit-testing and viewport clipping queries. This should greatly improve user interaction and rendering speed for diagrams containing tens of thousands or more items.
Java
Copy Code
|
---|
// it will take some time to populate the diagram with a million nodes, // but subsequent redraws and hit-tests should be very fast Diagram diagram = new Diagram(); diagram.setAutoResize(AutoResize.None); diagram.setDefaultShape(Shape.fromId("Rectangle")); diagram.setValidityChecks(false); diagram.setSelectAfterCreate(false);
for (int c = 0; c < 1000; c++) { for (int r = 0; r < 1000; r++) { ShapeNode node = diagram.getFactory().createShapeNode( 20 + c * 40, 20 + r * 40, 25, 25); node.setText( Integer.toString( diagram.getNodes().size())); } } diagram.resizeToFitItems(20); diagram.setEnableSpatialIndex(true);
diagramView.setDiagram(diagram); |
Note that rendering speed improves only when showing a smaller part of the diagram inside DiagramView's viewport. Rendering a lot of items at small zoom levels or in overview's fit-all mode will still need a lot of processing, so you might want to apply constraints on minimal zoom level of diagram view and overview controls for large diagrams.
Pattern router
New PatternRouter class routes links by applying patterns of segment and turn sequences and accepting them when resulting paths do not cross nodes. A path is accepted if its final segment ends in target point and is orthogonal to respective side of target node. If there are several possible paths, the router selects the shortest one. The MinimumDistance property specifies minimum allowed distance of link segments from nodes. The PreferredDistance property specifies distance of first or last link bend from associated node. PatternRouter includes several predefined patterns designed to create consistent-looking paths, and allows creation of custom patterns. Custom patterns can be defined as sequence of RouteStep objects specifying whether the path advances by relative or absolute distance, or changes direction:
Java
Copy Code
|
---|
RoutePattern rightZigzag = new RoutePattern(); rightZigzag.getSteps().add( new RouteStep(RouteStepKind.AdvanceRelative, 0.5f)); rightZigzag.getSteps().add( new RouteStep(RouteStepKind.TurnRight)); rightZigzag.getSteps().add( new RouteStep(RouteStepKind.AdvanceRelative, 1)); rightZigzag.getSteps().add( new RouteStep(RouteStepKind.TurnLeft)); rightZigzag.getSteps().add( new RouteStep(RouteStepKind.AdvanceRelative, 0.5f)); router.getPatterns().add(rightZigzag);
// this can be defined in shorter form using a pattern string // RoutePattern rightZigzag2 = new RoutePattern( // "ADR0.5 TRR ADR1 TRL ADR0.5"); |
Composite router
The
CompositeRouter class lets you chain link routers (objects implementing
LinkRouter interface) so that a link passes through the sequence until it gets routed successfully.
Diagram's default router is now set to a
CompositeRouter instance containing a
PatternRouter and
GridRouter sequence. This applies the several standard pattern paths when possible, and otherwise routes links using the cost minimizing heuristics-based grid router.
Miscellaneous
API changes