# MindFusionDoc Documentation Map This is a unified documentation resource optimized for LLMs. The high-level guides, architectural overviews, and tutorials are inlined directly below in Section 1. All class references are merged into single files per class/struct and linked in Section 2. # Section 1: High-Level Guides and Overviews ## Untitled Topic -1 ## Introduction MindFusion.Diagramming for Java Swing (JDiagram for short) is a Java class library that that lets you create and display various types of diagrams and charts. The library includes model classes that describe the structure and appearance of a flow diagram, and view classes that can be integrated into any application that targets the Java Swing framework. By providing your software with ready to use capabilities for visualizing and editing relational data, JDiagram saves you from hundreds of hours of coding and debugging efforts. JDiagram can give graphical representation to: - Workflow processes - Class relationships - Graphs and networks - Entity-relationship / database diagrams - IVR systems - Industrial automation processes - Genealogy trees - Algorithms and flowcharts - Mind maps - Organizational charts - XML documents - Classification hierarchies - Data mappings JDiagram provides intuitive user-interaction model for creating or editing diagrams. In addition, its programmatic interface places at your disposal many useful functions, ranging from printing, XML serialization, exporting to PDF and SVG to path-finding and automatic layout algorithms. The control has been tested with the most popular Java development environments, and is used by companies from all around the world to create applications in Java. ## General Information ### The JDiagram Library - Redistribution is royalty free - Can be purchased with source code - Is written in Java - Implements the Document/View architecture - Includes applet class for use in Web pages ### User Interaction - Several user interaction modes - Free-form drawing - Scrolling and zooming - Copy and paste to/from the system clipboard - Panning - Automatic scrolling while dragging items with the mouse - Alignment to grid - Node alignment guides - Multiple selection - Tool-tips - Docking points can be defined for nodes - Magnifier tool - Undo / redo support - Rotate and flip shapes ### Programming - Programmatic access to the diagram elements - Builder classes for fluent API - Numerous properties for customizing appearance and behavior - Numerous utility methods - Path finding and cycle detection - Rich event set - The applet fires events that can be handled using JavaScript ### Store and Retrieve Diagrams into/from - Files on disk - Java streams - ASCII strings - XML documents - JSON strings ### Output - To display through Java Swing - Printing and print preview - To a browser using HTML image maps ### Export and Import - Export Portable Document Format (PDF) files - Export Scalable Vector Graphics (SVG) files - Export images in jpeg, gif, tiff, and png formats - Export Visio 2013 drawing (.vsdx) documents - Export Excel Open XML Format (XLSX) files - Import OpenOffice Draw documents - Import Visio 2013 drawing (.vsdx) documents ### Diagram Elements - More than 100 predefined node shapes - Each diagram item can display multiple labels and icons - Display SVG drawings in nodes - Ability to define custom shapes and shape libraries - Rotation of shapes at arbitrary angles - Use any Java Swing component as a diagram node - Container nodes - Display hierarchical data in TreeView nodes - Support for custom node and link types - Assign diagram items to layers - Tables with unlimited number of rows and columns - Table cells can span several columns and rows - Sections of table rows can be expanded or collapsed - Links can comprise multiple segments - Link segments can be straight lines or curves ### Automatic Layout - Spring-Embedder graph layout - Directional tree layout - Radial tree layout - Fractal tree layout - Layered graph layout - Grid layout - Simulated Annealing graph layout - One-way graph layout - Orthogonal graph layout - Circular graph layout - Orthogonal link router - Source code flowchart layout - Decision flowchart layout - Triangular graph layout - Hierarchical graph layout - Cascading graph layout - Tree map layout - Process diagrams layout - Automatic link routing ### Appearance - Styles and themes - Nodes can display images and text - Multiple text labels per item - Various text alignment styles - Text can be laid out in polygonal areas - Glass visual effects - Styled HTML-like text formatting - Customizable fonts and colors - Custom painting of nodes - Shadows - User-assigned mouse cursors - Z-order - Rich choice of pen and brush styles - Transparent nodes - Invisible nodes - A background swimlane grid ### Behavior - Lock diagram elements - Read-only mode supported - Tables can be scrolled - Collapse and expand hierarchy branches - In-place text editing - Dynamic positioning of links relative to connected nodes ### Link Diagram Items - Nodes to nodes - Table rows to table rows - Nodes to table rows - Unconnected links ### Hierarchical Grouping - Attaching nodes to other nodes - Attaching nodes to link control points - Attaching nodes to link segments ### Auxiliary Controls - Overview control - Ruler control - Shapes listbox - Node list control - Layer list control - Zoom control - Item list control - Palette control ## Getting Started The following topics describe how to integrate the Diagramming for Java Swing API into your project, and create an instance of the (Markdown/T_com_mindfusion_diagramming_DiagramView.md) control. ## Add Diagramming Library You can add diagram library's JAR file to your project either from the (#add-from-maven-central) repository, or from (#add-local-jar) installed distribution. ## Add From Maven Central You can install the MindFusion.Diagramming library from Maven Central. After integrating it by following any of the following steps, you should be able to import (#commindfusiondiagramming) classes and add controls from the library to your UI ((Markdown/T_com_mindfusion_diagramming_DiagramView.md), (Markdown/T_com_mindfusion_diagramming_NodeListView.md), (Markdown/T_com_mindfusion_diagramming_Overview.md), etc).### IntelliJ IDE In order to integrate Diagramming for Java Swing into your IntelliJ project, select the Project Structure command from File menu, open Modules -> Dependencies page, click the + button and select Library -> From Maven command: On the Download Library from Maven screen, search for "mindfusion:diagramming", select latest version of the package and click OK: On Configure Library screen, select the library level and click OK: ### Eclipse IDE From Maven-based project's context menu, select Maven -> Add Dependency command: On Add Dependency screen, search for "diagramming", select the latest version and click OK: ### Maven Projects In any Maven-based project, you can list eu.mindfusion.diagramming package as dependency in pom.xml and let the build system take care of downloading and integrating the jar file: ```     eu.mindfusion     diagramming     4.5.1 ``` ### Gradle Projects In any Gradle-based project, you can list eu.mindfusion.diagramming package as dependency in build.gradle and let the build system take care of downloading and integrating the jar file: ``` dependencies {     implementation 'eu.mindfusion:diagramming:4.5.1' } ``` ## Add Local JAR You can use the diagram library archive (JDiagram.jar) from locally installed distribution. After adding it to your project's dependencies, you should be able to import (#commindfusiondiagramming) classes and add controls from the library to your UI ((Markdown/T_com_mindfusion_diagramming_DiagramView.md), (Markdown/T_com_mindfusion_diagramming_NodeListView.md), (Markdown/T_com_mindfusion_diagramming_Overview.md), etc). ### IntelliJ IDE In order to integrate Diagramming for Java Swing into your IntelliJ project, select the Project Structure command from File menu, open Modules -> Dependencies page, click the + button and select the JARs or Directories command: On the Attach Files screen, browse to the location where you have unarchived JDiagram.zip and select JDiagram.jar. Press OK to confirm all dialogs. ### Eclipse IDE In order to integrate Diagramming for Java Swing into your Eclipse project, select the Build Path -> Add External Archives command from project's context menu: On JAR Selection screen, browse to the location where you have unarchived JDiagram.zip and select JDiagram.jar. ## Create DiagramView Instance Once you have added a JDiagram reference to your project, you can access the public classes defined in JDiagram packages. The most important classes are (Markdown/T_com_mindfusion_diagramming_Diagram.md), which represents the diagram data, and (Markdown/T_com_mindfusion_diagramming_DiagramView.md), which is a Swing component that displays the diagram. You usually create and initialize a new instances of the (Markdown/T_com_mindfusion_diagramming_Diagram.md) and (Markdown/T_com_mindfusion_diagramming_DiagramView.md) classes in the same place where you create and initialize the rest of the user interface of your application. Associate the diagram to be displayed by this view by calling the (Markdown/T_com_mindfusion_diagramming_DiagramView.md#setdiagram) method. To let users scroll the diagram, add the (Markdown/T_com_mindfusion_diagramming_DiagramView.md) object to a JScrollPane container. Thus, a minimal application containing a scrollable diagram that can be used to draw flowcharts looks like this: ```java package flowcharter; import java.awt.Dimension; import java.awt.Toolkit; import javax.swing.JFrame; import javax.swing.JScrollPane; import com.mindfusion.diagramming.*; public class MainWindow     extends JFrame {     public MainWindow()     {         diagram = new Diagram();         diagramView = new DiagramView();         diagramView.setDiagram(diagram);            JScrollPane scrollPane = new JScrollPane(diagramView);         getContentPane().add(scrollPane);            Dimension size = Toolkit.getDefaultToolkit().getScreenSize();         setSize(size);     }       public static void main(String[] args)     {         MainWindow window = new MainWindow();         window.setVisible(true);     }         private DiagramView diagramView;     private Diagram diagram; } ``` The initialization of the JDiagram control can be very different depending on what you will use it for, but there are certain properties you will most likely need to adjust in all cases. Here they are: - Choose a (Markdown/T_com_mindfusion_diagramming_Behavior_0.md) for the control, which defines how JDiagram must interpret actions done with the mouse by users of your application. The default value, (Markdown/T_com_mindfusion_diagramming_Behavior_0.md) specifies that users can draw diagram nodes and connect them with diagram links. Another value, (Markdown/T_com_mindfusion_diagramming_Behavior_0.md) allows drawing tables and relationships between them. The (Markdown/T_com_mindfusion_diagramming_Behavior_0.md) behavior allows panning the view by dragging the mouse. Modify bans users from drawing new items, but allows them to modify existing ones. Call the (Markdown/T_com_mindfusion_diagramming_DiagramView.md#setbehavior) method of the (Markdown/T_com_mindfusion_diagramming_DiagramView.md) class to adjust the control's behavior. - There are other methods of the (Markdown/T_com_mindfusion_diagramming_DiagramView.md) class for customizing the behavior of the diagram and its items - take a look at (Markdown/T_com_mindfusion_diagramming_DiagramView.md#getcustombehavior) and (Markdown/T_com_mindfusion_diagramming_DiagramView.md#setcustombehavior), (Markdown/T_com_mindfusion_diagramming_DiagramView.md#getcustomlinktype) and (Markdown/T_com_mindfusion_diagramming_DiagramView.md#setcustomlinktype), (Markdown/T_com_mindfusion_diagramming_DiagramView.md#getcustomnodetype) and (Markdown/T_com_mindfusion_diagramming_DiagramView.md#setcustomnodetype). - There are various methods that let you customize the general appearance of your diagram, such as (Markdown/T_com_mindfusion_diagramming_Diagram.md#setbackbrush), (Markdown/T_com_mindfusion_diagramming_Diagram.md#setbackgroundimage), (Markdown/T_com_mindfusion_diagramming_Diagram.md#setboundspen), (Markdown/T_com_mindfusion_diagramming_Diagram.md#setgridcolor) and so on. - There is a set of methods that let you specify default attributes for diagram items. The names of these methods usually correspond to the name of the attribute they provide a default value for, prefixed by the name of the appropriate item class. For example, the method that lets you specify  the text of the link's label is called (Markdown/T_com_mindfusion_diagramming_DiagramLink.md#settext), while the default value for new links can be set through (Markdown/T_com_mindfusion_diagramming_Diagram.md#setlinktext). Once you have initialized JDiagram, you usually use the (Markdown/T_com_mindfusion_diagramming_DiagramListener.md#diagramlistener-members) to handle various events, such as (Markdown/T_com_mindfusion_diagramming_DiagramListener.md#linkcreated) and (Markdown/T_com_mindfusion_diagramming_DiagramListener.md#linkmodified). These events let you take specific actions when diagram items are created or modified, such as updating the internal state of your application. Browse the other sections of this help file to learn more about the functionality provided by the MindFusion.Diagramming classes, methods and properties. Follow the (#tutorials) to learn how to populate the diagram model programmatically or create custom item types. ## User Interaction Most likely an application would use JDiagram to enable users to interactively create diagrams, flowcharts and other kinds of presentation documents. A user composes or edits a diagram by drawing its elements on the JDiagram canvas area. With the help of a mouse or another pointing device users draw shapes, tables and links, possibly connecting them in complex hierarchies, graphs, trees or other structures they might need. ### Creating New Items New items can be created by drawing them with the mouse. While a user drags the mouse, the view of the control is updated to show what the new item would look like at the pointer location. If the operation cannot be completed at the current mouse position, the cursor changes to a crossed out circle. When the user releases the button, the item is created. The control does not let users create very tiny nodes which would be hard to select and modify. By default, links can be drawn only between nodes, unless the (Markdown/T_com_mindfusion_diagramming_Diagram.md#setallowunconnectedlinks) attribute is enabled. Users can cancel item creation by pressing the right mouse button while drawing. ### Modifying Items A user modifies an item by dragging its adjustment handles. The (Markdown/T_com_mindfusion_diagramming_DiagramView.md#setmodificationstart) method specifies when these handles appear. The first option, (Markdown/T_com_mindfusion_diagramming_ModificationStart_0.md), makes the handles appear when the mouse hovers over an item; modification of the item can start immediately by pointing it and dragging a handle. The second option is (Markdown/T_com_mindfusion_diagramming_ModificationStart_0.md): in order to be modified, an item should first be selected. Adjustment handles appear around the item to indicate that now it can be moved or resized. The number and functionality of the handles depend on the item type and the value specified through the (Markdown/T_com_mindfusion_diagramming_DiagramNode.md#sethandlesstyle) method. ### Modifying a Node Usually nodes have nine adjustment handles. The one at the center can be used to move the node. When dragged, each corner handle resizes the node by moving the two edges adjacent to the corresponding corner. The edge handles placed at the center of each side can be used to resize a node either horizontally or vertically. Shape nodes can be rotated using an additional round handle drawn above them. Each handle can be enabled or disabled by setting or clearing the respective bit through the (Markdown/T_com_mindfusion_diagramming_DiagramNode.md#setenabledhandles) method. ### Modifying a Link Variety and behavior of link adjustment handles depend on the link's Style and (Markdown/T_com_mindfusion_diagramming_DiagramLink.md#setsegmentcount). Control-points stay at both ends of each segment that constitutes a link. JDiagram offers three link styles. The following sections discuss how to modify links of each style. - The first style called Polyline defines links, which consist of a series of straight segments, drawn between control-points. There are no restrictions as to the number of segments. Dragging a control-point modifies each segment adjacent to the point. If the (Markdown/T_com_mindfusion_diagramming_Diagram.md#setallowsplitlinks) method is called, users are allowed to insert new control points or to remove existing ones. Inserting a control point is done by pressing the left mouse button over a segment and dragging. The new point appears at the mouse location and splits the pointed segment in two. - If link's style is set to Bezier, each segment has 4 manipulation handles that define a curve. Each curve goes through the end-points, which are shaped as circles. Bend of the curve is defined by the middle two points shaped as rectangles. If a user drags an end-point modification handle, the adjacent control points will be moved with same translation vector as that of the end-point. If a bend control point is dragged, the symmetric control point of the neighboring curve is also moved to ensure the two stay on the same line with the end-point and on the same distance from it. - Cascading links consist of straight horizontal and vertical segments, each one orthogonal to its neighbors. If a control-point is dragged, the segments adjacent to it are moved and resized preserving their orthogonal orientation to each other. If the (Markdown/T_com_mindfusion_diagramming_Diagram.md#setallowsplitlinks) method is called, users are allowed to insert new control points to Cascading links or remove existing ones. The orientation of the link segments can be changed if LinkCascadeOrientation is set to Auto. ### Modifying a Table By default, table modification handles are drawn as dotted lines over its borders. To move a table, drag its caption bar. To resize a table, drag any of its borders or corners. ### Selecting Items Multiple items are selected by dragging while CTRL key is down. Selection can also be toggled with CTRL + clicking an item. A rectangle appears around selected items, allowing a user to move all of them at once. ### Scrolling and Panning The (Markdown/T_com_mindfusion_diagramming_DiagramView.md) can be scrolled if its placed inside a JScrollPane. Users scroll the view by dragging the scrollpane's scrollbars, which appear when the diagram area is larger than the view. The user could also pan the diagram view by pressing the left mouse button and dragging while the ALT key is down. ### Interpreting Users Actions Mouse operations can be interpreted in different ways depending on the value of the Behavior property. It defines whether for example dragging the mouse creates a node or selects existing items. Check the property description for more information on the built-in input modes. You can also create a custom mouse input controller by deriving from the (Markdown/T_com_mindfusion_diagramming_BehaviorBase.md) class and calling the (Markdown/T_com_mindfusion_diagramming_DiagramView.md#setcustombehavior) method of (Markdown/T_com_mindfusion_diagramming_DiagramView.md). A custom controller could implement only the higher-level (Markdown/T_com_mindfusion_diagramming_BehaviorBase.md#startdraw) method to specify what kind of operation should start when the user begins to drag the mouse, or the (Markdown/T_com_mindfusion_diagramming_LinkNodesBehavior.md#createnode) method to create an instance of a custom node class. Alternatively, override the lower-level (Markdown/T_com_mindfusion_diagramming_BehaviorBase.md#pointerdown), (Markdown/T_com_mindfusion_diagramming_BehaviorBase.md#pointermove) and (Markdown/T_com_mindfusion_diagramming_BehaviorBase.md#pointerup) methods to completely overhaul user interaction. A custom (Markdown/T_com_mindfusion_diagramming_BehaviorBase.md)-derived class is demonstrated in the Fishbone sample project. ## Programming Interface Overview The next few chapters give you an overview of all JDiagram features, grouped by functionality. Hyperlinks refer to the detailed description of methods and classes. ## Document-View Architecture JDiagram implements the Model-View-Controller (MVC) architectural pattern. The MVC design pattern as applied to JDiagram separates the diagram data (model) from its representation to the user (view) and controlling it by the user (controller). ### Single Diagram Canvas The (Markdown/T_com_mindfusion_diagramming_Diagram.md) class represents the diagram data model and provides operations to process the data. It exposes properties and methods for adding new diagram elements, finding and accessing existing elements, or removing them. The (Markdown/T_com_mindfusion_diagramming_DiagramView.md) class presents the relevant data from the (Markdown/T_com_mindfusion_diagramming_Diagram.md) class by drawing on the screen using the Java Graphics2D API. When the diagram is changed, the view automatically redraws the affected part of the image to reflect the changes. Multiple views can display the same diagram. Perform the (Markdown/T_com_mindfusion_diagramming_DiagramView.md#setdiagram) method of the (Markdown/T_com_mindfusion_diagramming_DiagramView.md) class to specify the diagram displayed by the view. Each view can have a different zoom level and scroll position. Controllers responding to user interactions are represented by (Markdown/T_com_mindfusion_diagramming_BehaviorBase.md) objects. The (Markdown/T_com_mindfusion_diagramming_DiagramView.md#setbehavior) property of (Markdown/T_com_mindfusion_diagramming_DiagramView.md) and respective (Markdown/T_com_mindfusion_diagramming_Behavior_0.md) let you switch between different controllers, specifying how GUI actions should be interpreted to manipulate the diagram elements, or scroll / zoom the view itself. ### Multiple Diagram Pages The (Markdown/T_com_mindfusion_diagramming_DiagramDocument.md) class represents a collection of diagram pages or sheets, represented by (Markdown/T_com_mindfusion_diagramming_DiagramPage.md) objects. Document's pages are stored in its (Markdown/T_com_mindfusion_diagramming_DiagramDocument.md#getpages) collection. The saveTo* methods of (Markdown/T_com_mindfusion_diagramming_DiagramDocument.md) save all pages in a single file, and respectively the loadFrom* methods load all pages from the file. (Markdown/T_com_mindfusion_diagramming_DiagramPage.md) is derived from (Markdown/T_com_mindfusion_diagramming_Diagram.md) and only adds a few properties, so any code that processes (Markdown/T_com_mindfusion_diagramming_Diagram.md) objects will work with (Markdown/T_com_mindfusion_diagramming_DiagramPage.md) objects too. A diagram document forwards each event raised by its pages, giving you a chance to use the same listener for events raised by different pages. If a page should implement distinct user interaction or validation logic, it is also possible to attach handlers to the (Markdown/T_com_mindfusion_diagramming_Diagram.md) events inherited by (Markdown/T_com_mindfusion_diagramming_DiagramPage.md). A single (Markdown/T_com_mindfusion_diagramming_DiagramPage.md) could be assigned to the (Markdown/T_com_mindfusion_diagramming_DiagramView.md#setdiagram) property of (Markdown/T_com_mindfusion_diagramming_DiagramView.md), and that lets you create your own user interface for presenting a list of pages to the user and selecting a current page. The library includes the (Markdown/T_com_mindfusion_diagramming_TabbedScrollPane.md) and (Markdown/T_com_mindfusion_diagramming_DocumentView.md) classes, which work together to present all pages of a document in a tabbed user interface, with each tab corresponding to a page. The page displayed in the active tab is exposed through the (Markdown/T_com_mindfusion_diagramming_DocumentView.md#getcurrentpage) property of (Markdown/T_com_mindfusion_diagramming_DocumentView.md). Users can switch between pages by activating the corresponding tab. New pages can be added to and existing pages removed from the document using buttons in the tab strip, and pages can be rearranged by dragging their corresponding tabs with the mouse. ## User Interface Components ### DiagramView (Markdown/T_com_mindfusion_diagramming_DiagramView.md) renders the contents of a (Markdown/T_com_mindfusion_diagramming_Diagram.md) and allows users to create new items or modify existing ones using a mouse or other pointing devices. The (Markdown/T_com_mindfusion_diagramming_DiagramView.md#setbehavior) property defines how the control interprets user actions. Additional properties control scrolling and zooming of the view. ### Palette The (Markdown/T_com_mindfusion_diagramming_Palette.md) control represents a tool palette that displays (Markdown/T_com_mindfusion_diagramming_DiagramItem.md) objects grouped into categories. It implements (Markdown/T_com_mindfusion_common_Accordion.md) user interface that displays (Markdown/T_com_mindfusion_diagramming_ItemListView.md) components as its child panels, and category icon, title and collapse/expand button in pane headers. Each child (Markdown/T_com_mindfusion_diagramming_ItemListView.md) displays the items added to its corresponding category. Call the (Markdown/T_com_mindfusion_diagramming_Palette.md#addcategory) method to define a category and create its respective accordion pane. Call (Markdown/T_com_mindfusion_diagramming_Palette.md#additem) to add an item to specified category. The control can also be configured by setting its (Markdown/T_com_mindfusion_diagramming_Palette.md#setmodel) to an object implementing (Markdown/T_com_mindfusion_diagramming_PaletteModel.md) interface. (Markdown/T_com_mindfusion_diagramming_Palette.md) provides same behavior and appearance properties as the (Markdown/T_com_mindfusion_diagramming_ItemListView.md) class. ### ItemListView (Markdown/T_com_mindfusion_diagramming_ItemListView.md) represents a tool palette that contains uncategorized list of diagram items. Items can be added by calling (Markdown/T_com_mindfusion_diagramming_ItemListView.md#additem) method, and removed by calling (Markdown/T_com_mindfusion_diagramming_ItemListView.md#removeitemat). Drag-and-drop operations from (Markdown/T_com_mindfusion_diagramming_ItemListView.md) to (Markdown/T_com_mindfusion_diagramming_DiagramView.md) create a copy of the dragged item, and set its size to (Markdown/T_com_mindfusion_diagramming_ItemListView.md#setnewinstancesize). ### Overview (Markdown/T_com_mindfusion_diagramming_Overview.md) provides a scaled-down view of a target (Markdown/T_com_mindfusion_diagramming_DiagramView.md), helping users work with larger diagrams. A tracker rectangle shows current viewport of the main (Markdown/T_com_mindfusion_diagramming_DiagramView.md), and by dragging it users can change the scroll position. It can also be resized to zoom the target view. ### ZoomControl (Markdown/T_com_mindfusion_diagramming_ZoomControl.md) lets users change the zoom level of a target (Markdown/T_com_mindfusion_diagramming_DiagramView.md) by dragging a slider. It also includes arrow buttons for scrolling the view. ### Ruler The (Markdown/T_com_mindfusion_diagramming_Ruler.md) control displays horizontal and vertical scales that let users measure and align diagram nodes. ## Diagram Structure ## Standard Item Types (Markdown/T_com_mindfusion_diagramming_Diagram.md) elements in JDiagram are represented by (Markdown/T_com_mindfusion_diagramming_ShapeNode.md), (Markdown/T_com_mindfusion_diagramming_TableNode.md), (Markdown/T_com_mindfusion_diagramming_ContainerNode.md) and (Markdown/T_com_mindfusion_diagramming_DiagramLink.md) instances. Combined and linked together, they can form complex data structures such as process or entity-relationship diagrams, class hierarchies, networks and graphs. Each of their rich features can be customized through numerous methods and properties. JDiagram also offers intuitive user interface for drawing and editing diagram items interactively. ### Shape Nodes Shape nodes can represent geometric shapes, flowchart elements, icons in network diagrams, and so on. They can hold both graphics and text in different fonts, sizes and colors. There are more than 100 predefined shapes and apart from them, JDiagram offers an easy way to define custom shapes. Shape nodes can be rotated, either interactively using the round selection handle drawn above them, or programmatically using the (Markdown/T_com_mindfusion_diagramming_DiagramNode.md#setrotationangle) method. The (Markdown/T_com_mindfusion_diagramming_ShapeNode.md) appearance can be customized further using several types of custom painting. The first type gives you full control over the painting. With the second one your painting code is performed additionally to the basic painting. The third one performs standard drawing of shape nodes and custom drawing of their shadows. Shape nodes can display background images and graphics. The file formats supported are GIF, JPEG and PNG.### SVG Nodes The (Markdown/T_com_mindfusion_diagramming_SvgNode.md) class represents nodes that can display SVG drawings in addition to the rendering provided by its base (Markdown/T_com_mindfusion_diagramming_ShapeNode.md) class. SVG elements are rendered after the associated bitmap (Markdown/T_com_mindfusion_diagramming_ShapeNode.md#getimage) and just before the (Markdown/T_com_mindfusion_diagramming_DiagramListener.md#drawnode) event is raised for (Markdown/T_com_mindfusion_diagramming_CustomDraw_0.md) custom drawing. SVG elements are parsed and associated with the node through a (Markdown/T_com_mindfusion_svg_SvgContent.md) object, which should be initialized and then assigned to the (Markdown/T_com_mindfusion_diagramming_SvgNode.md#setcontent) property. ### Table Nodes Table nodes can be used to represent table schemas in database diagrams or classes in class-hierarchies. A table contains cells arranged in a grid, and every cell can display text and/or image. Cells can span several rows and columns as set through the (Markdown/T_com_mindfusion_diagramming_Cell.md#setrowspan) and (Markdown/T_com_mindfusion_diagramming_Cell.md#setcolumnspan) methods. Cells, columns and rows can be customized in various ways - there are appropriate methods available for setting their extents ((Markdown/T_com_mindfusion_diagramming_TableNode.md#setcaptionheight), (Markdown/T_com_mindfusion_diagramming_TableNode.md#setrowheight), (Markdown/T_com_mindfusion_diagramming_TableNode.md#setcolumnwidth)), frame style ((Markdown/T_com_mindfusion_diagramming_TableNode.md#setcellframestyle)), image ((Markdown/T_com_mindfusion_diagramming_TableNode.md#setimagealign), (Markdown/T_com_mindfusion_diagramming_Cell.md#setimagealign)) and text format and alignment((Markdown/T_com_mindfusion_diagramming_Cell.md#settextformat), (Markdown/T_com_mindfusion_diagramming_TableNode.md#setcaptionformat), (Markdown/T_com_mindfusion_diagramming_Diagram.md#setenablestyledtext)). Tables' dimensions can be programmatically changed. Inserting ((Markdown/T_com_mindfusion_diagramming_TableNode.md#insertrow), (Markdown/T_com_mindfusion_diagramming_TableNode.md#insertcolumn)), appending ((Markdown/T_com_mindfusion_diagramming_TableNode.md#addrow), (Markdown/T_com_mindfusion_diagramming_TableNode.md#addcolumn)) or deleting rows and columns ((Markdown/T_com_mindfusion_diagramming_TableNode.md#deletecolumn), (Markdown/T_com_mindfusion_diagramming_TableNode.md#deleterow)) can be done in a very comprehensive, intuitive way whenever you might need it. Tables can also display background images and graphics. The file formats supported are GIF, JPEG and PNG.### Free-form Nodes A (Markdown/T_com_mindfusion_diagramming_FreeFormNode.md) collects all points from users' mouse or touch input and displays them as node's outline. To let users draw free-form nodes interactively, set (Markdown/T_com_mindfusion_diagramming_DiagramView.md#setbehavior) to (Markdown/T_com_mindfusion_diagramming_Behavior_0.md). Use the (Markdown/T_com_mindfusion_diagramming_FreeFormNode.md#getpoints) property of (Markdown/T_com_mindfusion_diagramming_FreeFormNode.md) to get or set outline points programmatically. If the (Markdown/T_com_mindfusion_diagramming_FreeFormNode.md#setclosed) property is set, the node is drawn as a closed shape and its interior filled, or otherwise the node is drawn as a poly-line. If the distance between first and last points drawn by user is shorter than (Markdown/T_com_mindfusion_diagramming_Diagram.md#getautoclosedistance), the node gets closed automatically.### Control Hosts A (Markdown/T_com_mindfusion_diagramming_ControlNode.md) can host any Java Swing control - instance of a java.awt.Component -derived class. The hosted control might be any of the standard component types such as JTable or JButton; custom controls are also supported. A (Markdown/T_com_mindfusion_diagramming_ControlNode.md) can be connected with links to any other nodes - control hosts, shapes or tables.### Container Nodes A (Markdown/T_com_mindfusion_diagramming_ContainerNode.md) can contain other diagram nodes. When a container is moved, its child nodes move too. Containers can be folded to hide the contained nodes, and unfolded back to show them again. Nodes inside a container can be linked to nodes both inside and outside of it. When a container is folded, the links connected to contained nodes point to the container outlines. Containers can be nested within each other to unlimited depth. ### TreeView Nodes The (Markdown/T_com_mindfusion_diagramming_TreeViewNode.md) class represents nodes that can display hierarchical data. The root items displayed in the node can be accessed through the (Markdown/T_com_mindfusion_diagramming_TreeViewNode.md#getrootitems) method. New items can be added to and removed from the returned collection. The root items can have child items on their own and so on. For more information, refer to the (Markdown/T_com_mindfusion_diagramming_TreeViewItem.md) class. ### Links (Markdown/T_com_mindfusion_diagramming_DiagramLink.md) represent various types of connections and relations in diagrams. JDiagram  offers three basic link types: - polyline links composed of straight-line segments (choose Polyline link style) - curved links composed of Bezier-spline segments - links composed of horizontal and vertical segments, alternating their orientation so that every segment is orthogonal to its neighbor A link can be connected to a node at each of the link's ends. It is also possible to have unconnected links - having one or both of their ends not connected to nodes. Some customizable link's attributes are: arrowheads ((Markdown/T_com_mindfusion_diagramming_DiagramLink.md#setheadshape), (Markdown/T_com_mindfusion_diagramming_DiagramLink.md#setheadshapesize), (Markdown/T_com_mindfusion_diagramming_DiagramLink.md#setheadpen)), shape ((Markdown/T_com_mindfusion_diagramming_DiagramLink.md#setshape), (Markdown/T_com_mindfusion_diagramming_DiagramLink.md#setcascadeorientation)), color ((Markdown/T_com_mindfusion_diagramming_DiagramItem.md#settextbrush)), text ((Markdown/T_com_mindfusion_diagramming_DiagramLink.md#settext), (Markdown/T_com_mindfusion_diagramming_DiagramLink.md#settextstyle)), pen width and style, modification behavior ((Markdown/T_com_mindfusion_diagramming_DiagramLink.md#setallowmovestart), (Markdown/T_com_mindfusion_diagramming_DiagramLink.md#setautoroute), (Markdown/T_com_mindfusion_diagramming_DiagramLink.md#setallowmoveend), (Markdown/T_com_mindfusion_diagramming_DiagramLink.md#setdynamic)) and number of segments ((Markdown/T_com_mindfusion_diagramming_DiagramLink.md#setsegmentcount)). ### See Also (#text-formatting) (#custom-item-types) ## Custom Item Types You can create your own item types by deriving the (Markdown/T_com_mindfusion_diagramming_DiagramNode.md) and (Markdown/T_com_mindfusion_diagramming_DiagramLink.md) classes or their successors such as (Markdown/T_com_mindfusion_diagramming_TableNode.md), (Markdown/T_com_mindfusion_diagramming_ContainerNode.md) and so on. Thus, you can add custom data fields to the diagram items, and implement custom visualization and interaction functionality. ### Serialization If you add custom fields to your item class, you will probably want their values saved when saving diagram files, and restored when loading files. To enable this, override the (Markdown/T_com_mindfusion_diagramming_DiagramItem.md#writeexternal) and (Markdown/T_com_mindfusion_diagramming_DiagramItem.md#readexternal) methods of the (Markdown/T_com_mindfusion_diagramming_DiagramItem.md) class, which let you use ObjectOutputStream and ObjectInputStream objects to implement binary serialization. To implement XML serialization, you must override the (Markdown/T_com_mindfusion_diagramming_DiagramItem.md#savetoxml) and (Markdown/T_com_mindfusion_diagramming_DiagramItem.md#loadfromxml) methods, and use the (Markdown/T_com_mindfusion_diagramming_Diagram.md#registeritemclass) method to associate an element name with your class. ### Clipboard operations You must implement the (Markdown/T_com_mindfusion_diagramming_DiagramItemList.md#clone) method in order to enable (Markdown/T_com_mindfusion_diagramming_DiagramView.md#copytoclipboard) and (Markdown/T_com_mindfusion_diagramming_DiagramView.md#pastefromclipboard) to work with your custom item type. If (Markdown/T_com_mindfusion_diagramming_DiagramItemList.md#clone) is not implemented, you will get an instance of the base class created for the pasted item, and this could lead to an exception when the base class deserialization code tries to load the item state from a data stream created by the derived class. If your class has any custom fields, it must also implement the (Markdown/T_com_mindfusion_diagramming_DiagramItem.md#writeexternal) and (Markdown/T_com_mindfusion_diagramming_DiagramItem.md#readexternal) methods for proper serialization. ### Rendering If you need to provide custom rendering for your items, override the (Markdown/T_com_mindfusion_diagramming_DiagramNode.md#drawlocal) and (Markdown/T_com_mindfusion_diagramming_DiagramNode.md#drawshadowlocal) methods. They receive as an argument a Graphics2D object, which provides methods for drawing vector graphics, text and images. The specified Graphics2D in (Markdown/T_com_mindfusion_diagramming_ShapeNode.md#drawlocal) has a rotation transform applied to it to match the node's (Markdown/T_com_mindfusion_diagramming_DiagramNode.md#setrotationangle), and a translation transform to match the node's position, so that the coordinate system origin (0,0) is at the node's top-left corner. Alternatively, override the (Markdown/T_com_mindfusion_diagramming_DiagramItem.md#draw) method to receive a Graphics2D without any local transformations applied to it. Apart from drawing on screen via Java's Graphics2D objects, JDiagram provides (Markdown/T_com_mindfusion_pdf_PdfGraphics2D_0.md) and (Markdown/T_com_mindfusion_svg_SvgGraphics2D_0.md) implementations of that interface, which are used when exporting to PDF and to SVG. That lets you use the same code regardless of where the item should draw itself. ### User interaction To allow the user to draw items from a custom class, set the (Markdown/T_com_mindfusion_diagramming_DiagramView.md#setbehavior) of the diagram view to (Markdown/T_com_mindfusion_diagramming_Behavior_0.md), and call the (Markdown/T_com_mindfusion_diagramming_DiagramView.md#setcustomnodetype) and/or (Markdown/T_com_mindfusion_diagramming_DiagramView.md#setcustomlinktype) method with the Class object that corresponds to your type. If you need to change how items handle user interaction while they are being initially created, implement the (Markdown/T_com_mindfusion_diagramming_DiagramItem.md#startcreate), (Markdown/T_com_mindfusion_diagramming_DiagramItem.md#updatecreate) and (Markdown/T_com_mindfusion_diagramming_DiagramItem.md#completecreate) methods. In order to change how items respond to user interaction while they are being modified, implement the (Markdown/T_com_mindfusion_diagramming_DiagramItem.md#startmodify), (Markdown/T_com_mindfusion_diagramming_DiagramItem.md#updatemodify) and (Markdown/T_com_mindfusion_diagramming_DiagramItem.md#completemodify) methods. ## Creating and Deleting Items ### Creating Items Programmatically In order to add a new node or link to a diagram, create an instance of the item class by calling the new operator and add it to the diagram's (Markdown/T_com_mindfusion_diagramming_Diagram.md#getnodes) or (Markdown/T_com_mindfusion_diagramming_Diagram.md#getlinks) collection. This works the same way for adding both items from your custom class or ones from the predefined JDiagram types. There are several shortcut methods provided for creating instances of the predefined node and link types. The methods are members of the diagram's (Markdown/T_com_mindfusion_diagramming_Diagram.md#getfactory) object: - The (Markdown/T_com_mindfusion_diagramming_Factory.md#createshapenode) method creates a (Markdown/T_com_mindfusion_diagramming_ShapeNode.md) at the specified position with the specified dimensions and shape. - The (Markdown/T_com_mindfusion_diagramming_Factory.md#createtablenode) method creates a (Markdown/T_com_mindfusion_diagramming_TableNode.md) at a specified position. Tables have a method that connects them with other tables called (Markdown/T_com_mindfusion_diagramming_TableNode.md#addrelation). - The (Markdown/T_com_mindfusion_diagramming_Factory.md#createcontainernode) method creates a (Markdown/T_com_mindfusion_diagramming_ContainerNode.md) at the specified position. - There are several overloads of the (Markdown/T_com_mindfusion_diagramming_Factory.md#creatediagramlink) method that allow connecting two nodes of the same type or of different types. ### Drawing New Items Users can draw diagram elements with the mouse. Call (Markdown/T_com_mindfusion_diagramming_DiagramView.md#setbehavior) to specify what type of elements should be created when a user starts drawing. While items are being drawn, the control raises the validation events (Markdown/T_com_mindfusion_diagramming_DiagramListener.md#nodecreating) and (Markdown/T_com_mindfusion_diagramming_DiagramListener.md#linkcreating) to let you validate the operation and prevent creating items at a specific location. When the user releases the mouse button, the item is added to the collection that contains items from the same type (for example, the collections returned by the (Markdown/T_com_mindfusion_diagramming_Diagram.md#getnodes)). Users can create diagram elements by drawing them on the touch screen. Use the (Markdown/T_com_mindfusion_diagramming_DiagramView.md#setbehavior) method to specify what type of elements should be created when a user starts drawing. While items are being drawn, the control raises the validation events (Markdown/T_com_mindfusion_diagramming_DiagramListener.md#nodecreating) and (Markdown/T_com_mindfusion_diagramming_DiagramListener.md#linkcreating) to let you validate the operation and prevent creating items at a specific location. When the user lifts their finger from the touch screen, the item is added to the collection that contains items from the same type (for example, the collections returned by the (Markdown/T_com_mindfusion_diagramming_Diagram.md#getnodes)). ### Deleting Items Call the remove method of the collection returned by the (Markdown/T_com_mindfusion_diagramming_Diagram.md#getitems) method to delete an object from the diagram. The (Markdown/T_com_mindfusion_diagramming_Diagram.md#clearall) method clears diagram contents by deleting all objects. By default, deleting a node also removes its links. Set the (Markdown/T_com_mindfusion_diagramming_Diagram.md#setautodeletelinks) property to false to prevent that, and disconnect the links instead. ## Accessing Items One of the most common tasks when using the component is iterating over all items in the document or navigating through the connections between items - from a node to the incoming or outgoing links, or from a link to its origin and destination nodes. To enumerate items of a diagram, use the collections returned by the following methods: (Markdown/T_com_mindfusion_diagramming_Diagram.md#getitems), (Markdown/T_com_mindfusion_diagramming_Diagram.md#getlinks), and (Markdown/T_com_mindfusion_diagramming_Diagram.md#getnodes). The nodes connected through a link are returned by the link's (Markdown/T_com_mindfusion_diagramming_DiagramLink.md#getdestination) and (Markdown/T_com_mindfusion_diagramming_DiagramLink.md#getorigin) methods. To access the links connected to a node, use its (Markdown/T_com_mindfusion_diagramming_DiagramNode.md#getincominglinks) and (Markdown/T_com_mindfusion_diagramming_DiagramNode.md#getoutgoinglinks) methods. The first collection contains references to all links pointing to the node, the second - to the links that start from it. Links can connect to rows of a table; to find such links, use the table’s (Markdown/T_com_mindfusion_diagramming_TableNode.md#getrows) method and the (Markdown/T_com_mindfusion_diagramming_Row.md#getincominglinks) and (Markdown/T_com_mindfusion_diagramming_Row.md#getoutgoinglinks) methods. ### Selected Items If only one chart object is selected, it is considered the active object and can be accessed with the (Markdown/T_com_mindfusion_diagramming_Diagram.md#getactiveitem) method. Multiple objects can be selected when clicking or dragging with the Ctrl key pressed at the same time. Multiple- selection can be accessed through the (Markdown/T_com_mindfusion_diagramming_Diagram.md#getselection) method of the (Markdown/T_com_mindfusion_diagramming_Diagram.md) class. The (Markdown/T_com_mindfusion_diagramming_Selection.md) object provides methods to access the selected items: (Markdown/T_com_mindfusion_diagramming_Diagram.md#getitems), (Markdown/T_com_mindfusion_diagramming_Diagram.md#getlinks), (Markdown/T_com_mindfusion_diagramming_Diagram.md#getnodes). ### Finding Items You can search for chart objects by their tag using the (Markdown/T_com_mindfusion_diagramming_Diagram.md#findlink), (Markdown/T_com_mindfusion_diagramming_Diagram.md#findnode), (Markdown/T_com_mindfusion_diagramming_Diagram.md#findgroup) methods. Tag objects are compared by calling the equals method of the java.lang.Object class. If there are more objects with the same tag, the first one will be returned. If no object with the specified tag exists, null object reference will be returned. Groups can also be searched by tag using (Markdown/T_com_mindfusion_diagramming_Diagram.md#findgroup). ### Relationship Queries The (Markdown/T_com_mindfusion_diagramming_DiagramItem.md#query) method traverses the graph by following node/link connections and group's parent/child relationships to find items in specific relation to the current one. The method receives a string argument consisting of selectors and optional predicates. The query is executed in several steps. In each step the result set is constructed from the previous result set by following the relationship specified by the current selector. If a predicate is specified after the selector identifier, the result set is filtered to include only items for which the predicate evaluates to true. ## Attaching and Grouping Items JDiagram allows attaching a node to another diagram element, establishing a subordinate - master relationship between the two items. The easiest way to attach nodes is to call the (Markdown/T_com_mindfusion_diagramming_DiagramNode.md#attachto) method. When a master element is moved or resized, any subordinated node follows it, so that the initial distance between the two items stays constant. This happens both when a user moves the master item around, and when the item position is changed using a method. Recent versions of the API include (Markdown/T_com_mindfusion_diagramming_NodeLabel.md) and (Markdown/T_com_mindfusion_diagramming_LinkLabel.md) classes, which address several of the scenarios described below. We recommend using these classes when appropriate, as they offer a more lightweight and easily configurable alternative to attached nodes. ### Possible Uses - Attach a transparent shape node to another item and set its text by calling the (Markdown/T_com_mindfusion_diagramming_ShapeNode.md#settext) method, so that the shape node acts as an additional label assigned to the main item (to make a shape node transparent, call its (Markdown/T_com_mindfusion_diagramming_ShapeNode.md#settransparent) method). - Attach a shape node to another item and set the node's image by calling its (Markdown/T_com_mindfusion_diagramming_ShapeNode.md#setimage) method, so that it acts as an additional icon displayed inside or near the main item. - Attach a shape node or a table to another item and handle the (Markdown/T_com_mindfusion_diagramming_DiagramListener.md#nodeclicked) or (Markdown/T_com_mindfusion_diagramming_DiagramListener.md#cellclicked) event to perform some action on the main item. This makes the subordinated node act as a button or another type of UI element attached to the main item. - In all previous cases, the attached nodes can be locked by a call to their (Markdown/T_com_mindfusion_diagramming_DiagramItem.md#setlocked) method in order to use them only as a decorations embellishing the main item. That prevents users from selecting, modifying or drawing links to the subordinates. - Attach child elements in a tree branch to the branch root, so that when a user moves a tree node, the node's children moves simultaneously with it. Modifying an item in such hierarchical group makes the modification propagate through all dependant subordinated items. ### Hierarchical Grouping An unit of attached items is represented by an instance of the (Markdown/T_com_mindfusion_diagramming_Group.md) class. To create a group, call the (Markdown/T_com_mindfusion_diagramming_Factory.md#creategroup) method passing the master object as argument, and use the (Markdown/T_com_mindfusion_diagramming_Group.md#group-methods) methods to attach items. The (Markdown/T_com_mindfusion_diagramming_DiagramNode.md#attachto) method of nodes is a shortcut to creating a group and attaching an item to it. Every member of a group can be the master object of another group, that is, an item can be subordinate in one group and meanwhile be another group's master. JDiagram doesn't impose any limits to the depth and width of group hierarchies built that way. However, it is not possible to put an item as a subordinate in more than one groups because the hierarchy relations would become ambiguous. ### Unions It is possible to create such groups, where modifying any item in the hierarchy causes updating of all other items. This can be done by putting the items in circular chain of dependencies - that is, item1 is attached to item2, item2 to item3 … itemN to item1. If any of these items is modified, the change will propagate through the chain until it reaches its originator. ### Attaching Items to a Group Links cannot be attached to groups but can be master items of groups. If a group's master item is a link, nodes can be attached to the control points or segments of the link. See the (Markdown/T_com_mindfusion_diagramming_Group.md#attachtolinkpoint) and (Markdown/T_com_mindfusion_diagramming_Group.md#attachtolinksegment) methods for details. If the master item is a node, other nodes can be attached to any of its corners, or to an area specified as percent of master-node's bounding rectangle. Check (Markdown/T_com_mindfusion_diagramming_Group.md#attachtocorner) and (Markdown/T_com_mindfusion_diagramming_Group.md#attachproportional) for details. A shortcut to creating (Markdown/T_com_mindfusion_diagramming_Group.md) instance and calling the appropriate (Markdown/T_com_mindfusion_diagramming_DiagramNode.md#attachto) method of the (Markdown/T_com_mindfusion_diagramming_DiagramNode.md) class. ### Accessing Group Items The master item of a group can be accessed through its (Markdown/T_com_mindfusion_diagramming_Group.md#getmainitem) method and the subordinate items are returned by the (Markdown/T_com_mindfusion_diagramming_Group.md#getattachednodes) method. To get the groups in which an item participates, use its (Markdown/T_com_mindfusion_diagramming_DiagramItem.md#getmastergroup) and (Markdown/T_com_mindfusion_diagramming_DiagramItem.md#getsubordinategroup) methods. ### Destroying Groups If a user deletes the master item of a group, the group is destroyed automatically. If (Markdown/T_com_mindfusion_diagramming_Group.md#getautodeleteitems) returns true, subordinated items in the group are deleted too. If (Markdown/T_com_mindfusion_diagramming_Group.md#getautodeleteitems) returns false, subordinated items are just detached from their master and remain intact. Groups can be destroyed programmatically using the (Markdown/T_com_mindfusion_diagramming_Diagram.md#destroygroup) method. ## Layers ### Layers Items can be assigned to layers, and layers can be hidden, locked or moved up/down in the Z order as a group. (Markdown/T_com_mindfusion_diagramming_Layer.md) objects provide (Markdown/T_com_mindfusion_diagramming_Layer.md#setvisible), (Markdown/T_com_mindfusion_diagramming_Layer.md#setlocked) and (Markdown/T_com_mindfusion_diagramming_Layer.md#setzindex) properties, which will affect all items in the respective layer. Layers also expose a (Markdown/T_com_mindfusion_diagramming_Layer.md#settitle) property shown in the (Markdown/T_com_mindfusion_diagramming_LayerListView.md) control. Newly drawn items are added to the layer specified via (Markdown/T_com_mindfusion_diagramming_Diagram.md#setactivelayer). Call the (Markdown/T_com_mindfusion_diagramming_DiagramItem.md#setlayerindex) method of items to associate them with layers in the (Markdown/T_com_mindfusion_diagramming_Diagram.md#getlayers) collection. If (Markdown/T_com_mindfusion_diagramming_DiagramItem.md#getlayerindex) has the default value of -1, the item is not associated with any layer and its visibility depends only on the item's own (Markdown/T_com_mindfusion_diagramming_DiagramItem.md#setvisible) property. ### Layer list control The (Markdown/T_com_mindfusion_diagramming_LayerListView.md) control provides user interface for working with (Markdown/T_com_mindfusion_diagramming_Layer.md) objects. The control presents a list of the specified (Markdown/T_com_mindfusion_diagramming_LayerListView.md#setdiagram)'s layers, showing their title and an overview image of the objects in each layer, and also allows editing of layer's (Markdown/T_com_mindfusion_diagramming_Layer.md#setvisible) and (Markdown/T_com_mindfusion_diagramming_Layer.md#setlocked) properties and choosing the Diagram's currently active layer. New layers can be added to the Diagram by clicking the + button and removed by clicking the - button. The image below illustrates a (Markdown/T_com_mindfusion_diagramming_LayerListView.md) with several layers. ## Collapsing and Expanding Tree Branches If your chart represents a tree structure, you might want to collapse a sub-tree starting from a node or expand a sub-tree that was previously collapsed. Use the (Markdown/T_com_mindfusion_diagramming_DiagramNode.md#setexpanded) method of a node to do this programmatically. You can also invoke the (Markdown/T_com_mindfusion_diagramming_DiagramNode.md#setexpandable) method to show a +/- button beside the node; using this button the user will be able to collapse and expand the sub-tree, which has the specified node as root. To check if a sub-tree is expanded or collapsed call the (Markdown/T_com_mindfusion_diagramming_DiagramNode.md#getexpanded) method. ### Displaying Expand/Collapse Button If the (Markdown/T_com_mindfusion_diagramming_DiagramNode.md#setexpandable) attribute of a node is set to true, there is a [±] button displayed beside the node to allow users to collapse or expand the tree branch starting there. The button location can be customized through the diagram's (Markdown/T_com_mindfusion_diagramming_Diagram.md#setexpandbuttonposition) method. The appearance of the collapse / expand icon can be customized by setting (Markdown/T_com_mindfusion_diagramming_Renderers.md#setexpandiconrenderer). By default, pressing that button automatically collapses or expands the tree branch and raises the (Markdown/T_com_mindfusion_diagramming_DiagramListener.md#treeexpanded) or (Markdown/T_com_mindfusion_diagramming_DiagramListener.md#treecollapsed) events. ### Defining Tree Direction A node can be connected to other nodes through outgoing and incoming links. You can call the (Markdown/T_com_mindfusion_diagramming_Diagram.md#setexpandonincoming) method to specify which items connected to a node will be regarded as its descendants. If you pass false (default value) then each node will be regarded as a parent of its outgoing links and the items attached to them. If you pass true, the node' incoming links will define its children. Thus this property specifies the parent-children relationship between chart items and respectively the overall direction in which collapsing / expanding is done. ### Expanding a Branch Recursively Use the (Markdown/T_com_mindfusion_diagramming_Diagram.md#setrecursiveexpand) method to specify whether the whole sub-tree starting from a node will be shown when expanding, or only the first level of descendants. ### Custom Expand/Collapse Functionality The (Markdown/T_com_mindfusion_diagramming_Diagram.md#setexpandbuttonaction) method lets you override the standard functionality of the [±] button. Set this property to (Markdown/T_com_mindfusion_diagramming_ExpandButtonAction_0.md) and handle the (Markdown/T_com_mindfusion_diagramming_DiagramListener.md#expandbuttonclicked) event if you need to implement your own expand/collapse logic. ## Multiple Diagram Pages The (Markdown/T_com_mindfusion_diagramming_DiagramDocument.md) class represents a collection of diagram pages or sheets, represented by (Markdown/T_com_mindfusion_diagramming_DiagramPage.md) objects. New pages can be added to the document and existing pages can be removed and reordered via the (Markdown/T_com_mindfusion_diagramming_DiagramDocument.md#getpages) collection. The (Markdown/T_com_mindfusion_diagramming_DiagramDocument.md#savetoxml) and (Markdown/T_com_mindfusion_diagramming_DiagramDocument.md#saveto) methods of (Markdown/T_com_mindfusion_diagramming_DiagramDocument.md) save all pages in a single file, and respectively the (Markdown/T_com_mindfusion_diagramming_DiagramDocument.md#loadfromxml) and (Markdown/T_com_mindfusion_diagramming_DiagramDocument.md#loadfrom) methods load all pages from the file. (Markdown/T_com_mindfusion_diagramming_DiagramDocument.md) can also load files created by the serialization methods of (Markdown/T_com_mindfusion_diagramming_Diagram.md), and will show them in a single page. Note that the opposite is not true: (Markdown/T_com_mindfusion_diagramming_Diagram.md) cannot load directly a (Markdown/T_com_mindfusion_diagramming_DiagramDocument.md) file. (Markdown/T_com_mindfusion_diagramming_DiagramPage.md) is derived from (Markdown/T_com_mindfusion_diagramming_Diagram.md) and only adds a (Markdown/T_com_mindfusion_diagramming_DiagramPage.md#settitle) property, so any code that processes (Markdown/T_com_mindfusion_diagramming_Diagram.md) objects will work with (Markdown/T_com_mindfusion_diagramming_DiagramPage.md) objects too. A diagram document forwards each event raised by its pages, giving you a chance to use the same handler for events raised by different pages. If a page should implement distinct user interaction or validation logic, it is also possible to attach handlers to the (Markdown/T_com_mindfusion_diagramming_DiagramListener.md) inherited by (Markdown/T_com_mindfusion_diagramming_DiagramPage.md). A (Markdown/T_com_mindfusion_diagramming_DiagramDocument.md) can be exported to PDF using the new overloads available in the (Markdown/T_com_mindfusion_diagramming_export_PdfExporter.md). Other export classes do not support multi-page export at this time, but still can be used to export individual pages via their Export(Diagram) method. A single (Markdown/T_com_mindfusion_diagramming_DiagramPage.md) could be assigned to the (Markdown/T_com_mindfusion_diagramming_DiagramView.md#setdiagram) property of (Markdown/T_com_mindfusion_diagramming_DiagramView.md), and that lets you create your own user interface for presenting a list of pages to the user and selecting a current page. The package also includes a (Markdown/T_com_mindfusion_diagramming_DocumentView.md) and (Markdown/T_com_mindfusion_diagramming_TabbedScrollPane.md) classes that presents all pages of a document in a tabbed user interface where each tab corresponds to a page. The page displayed in the active tab is exposed by the (Markdown/T_com_mindfusion_diagramming_DocumentView.md#getcurrentpage) property of (Markdown/T_com_mindfusion_diagramming_DocumentView.md). The active page can be changed interactively by activating its associated tab. New pages can be added and removed to/from the document through buttons in the tab tray and the pages can be rearranged by dragging their associated tabs. ## Components The following topics are discussed in more details: (#using-components) General information on components and how to use them in diagram nodes. (#standard-component-types) A complete list and information about the standard JDiagram components, such as (Markdown/T_com_mindfusion_diagramming_components_ButtonComponent.md), (Markdown/T_com_mindfusion_diagramming_components_TextComponent.md) and (Markdown/T_com_mindfusion_diagramming_components_ShapeComponent.md). (#components-and-xml) How to define components hierarchies in XML and how to load those hierarchies. (#creating-custom-components) Information on how to implement and use custom components. ## Using Components The components in JDiagram are used through an instance of the (Markdown/T_com_mindfusion_diagramming_CompositeNode.md) class or a class deriving from (Markdown/T_com_mindfusion_diagramming_CompositeNode.md). Simply create concrete component instances and add them to the (Markdown/T_com_mindfusion_diagramming_CompositeNode.md#getcomponents) collection of the (Markdown/T_com_mindfusion_diagramming_CompositeNode.md). ### Arranging Components By default the composite node arranges its child components on top of each other, in the order they were added to the (Markdown/T_com_mindfusion_diagramming_CompositeNode.md#getcomponents) collection. To apply custom arrangement, the children should be organized in a component hierarchy using the appropriate panel components. For example, to arrange children horizontally, in a row, you can use the (Markdown/T_com_mindfusion_diagramming_components_StackPanel.md) with (Markdown/T_com_mindfusion_diagramming_components_StackPanel.md#setorientation) set to (Markdown/T_com_mindfusion_common_Orientation.md). Here is an example on how to do this in code: ```java StackPanel panel = new StackPanel(); panel.setOrientation(     com.mindfusion.common.Orientation.Horizontal); panel.setSpacing(1); TextComponent text = new TextComponent(); text.setText("Hello world!"); panel.getComponents().add(text); ButtonComponent button = new ButtonComponent(); TextComponent buttonContent = new TextComponent(); buttonContent.setText("Click me!"); button.setContent(buttonContent); panel.getComponents().add(button); node.getComponents().add(panel); ``` It is possible to create custom panel classes by deriving from (Markdown/T_com_mindfusion_diagramming_components_ContentComponent.md) and overriding the (Markdown/T_com_mindfusion_diagramming_components_ContentComponent.md#arrangecomponents) method. For an example on how to implement custom panel classes, check the (#creating-custom-components) topic. Another way to arrange child components is by deriving from (Markdown/T_com_mindfusion_diagramming_CompositeNode.md) and overriding the (Markdown/T_com_mindfusion_diagramming_CompositeNode.md#arrangecomponents) method. Then, you can manually assign the position of individual nodes through their (Markdown/T_com_mindfusion_diagramming_components_ComponentBase.md#setbounds) property. ### Finding Components The (Markdown/T_com_mindfusion_diagramming_CompositeNode.md#findcomponent) method of the (Markdown/T_com_mindfusion_diagramming_CompositeNode.md) class can be used to search for components by their (Markdown/T_com_mindfusion_diagramming_components_ComponentBase.md#getname). This method performs a recursive search of all components in the (Markdown/T_com_mindfusion_diagramming_CompositeNode.md#getcomponents) collection and returns a reference to the first component with the specified name. This is particularly useful when the component hierarchy is defined through XML and you need to obtain a reference to a specific component in the hierarchy for additional processing. For more information on how to define components in XML check (#components-and-xml). ### Hit-testing Components To retrieve the topmost component at a specific location, use the (Markdown/T_com_mindfusion_diagramming_CompositeNode.md#getcomponentat) method of the (Markdown/T_com_mindfusion_diagramming_CompositeNode.md) class. This method ignores components with any of the following properties set to false: (Markdown/T_com_mindfusion_diagramming_components_ComponentBase.md#getisenabled), (Markdown/T_com_mindfusion_diagramming_components_ComponentBase.md#getishittestvisible). ## Standard Component Types The following image illustrates the standard components using the default appearance settings. Additional information about the individual components can be found below. ### Border Components The border components can adorn a single component with a border and a background. To nest a more complicated structure within a border, use one of the panel components as a parent. The border component exposes few properties. The (Markdown/T_com_mindfusion_diagramming_components_BorderComponent.md#setbackground) and (Markdown/T_com_mindfusion_diagramming_components_BorderComponent.md#setpen) can be used to define the border appearance. The derived (Markdown/T_com_mindfusion_diagramming_components_ContentComponent.md#setpadding) property can be used to specify the distance between the border sides and the child component. The border child can be assigned through the (Markdown/T_com_mindfusion_diagramming_components_ContentComponent.md#setcontent) property. ### Button Components The button components represent a clickable button. The button components, similar to the border components, can host a single child component - usually a (Markdown/T_com_mindfusion_diagramming_components_TextComponent.md). The default button appearance is controlled through a set of brush and pen properties - (Markdown/T_com_mindfusion_diagramming_components_ButtonComponent.md#setbrush), (Markdown/T_com_mindfusion_diagramming_components_ButtonComponent.md#setbrushhovered), (Markdown/T_com_mindfusion_diagramming_components_ButtonComponent.md#setbrushpressed), (Markdown/T_com_mindfusion_diagramming_components_ButtonComponent.md#setpen), (Markdown/T_com_mindfusion_diagramming_components_ButtonComponent.md#setpenhovered) and (Markdown/T_com_mindfusion_diagramming_components_ButtonComponent.md#setpenpressed). These properties define the appearance of the button in its different states. An alternative way to define the button appearance is through images by using the (Markdown/T_com_mindfusion_diagramming_components_ButtonComponent.md#setimagelist) property. In addition the buttons can be custom drawn by handling the (Markdown/T_com_mindfusion_diagramming_components_ButtonComponentListener.md#customdraw) event. When a button component is clicked, the (Markdown/T_com_mindfusion_diagramming_components_ComponentMouseEventListener.md#mouseclicked) event is raised. ### CheckBox Components The check box components represent specialized buttons with an additional state - checked. The appearance of the check box in its checked state can be customized through the (Markdown/T_com_mindfusion_diagramming_components_CheckBoxComponent.md#setcheckedimagelist). The state can be programmatically get or set through the (Markdown/T_com_mindfusion_diagramming_components_CheckBoxComponent.md#ischecked) property. ### Text Components Text components can display static text. Text components expose an array of properties for customizing the appearance of the displayed text, including (Markdown/T_com_mindfusion_diagramming_components_TextComponent.md#setfont), (Markdown/T_com_mindfusion_diagramming_components_TextComponent.md#settextcolor), (Markdown/T_com_mindfusion_diagramming_components_TextComponent.md#settextformat) and (Markdown/T_com_mindfusion_diagramming_components_TextComponent.md#setbackground). The text of the text components can be specified through the (Markdown/T_com_mindfusion_diagramming_components_TextComponent.md#settext) property. ### Edit Components The edit components display editable text content and are analogous to the WinForms text boxes. The following properties define the appearance of the text within the component - (Markdown/T_com_mindfusion_diagramming_components_EditComponent.md#setfont), (Markdown/T_com_mindfusion_diagramming_components_EditComponent.md#settextcolor), (Markdown/T_com_mindfusion_diagramming_components_EditComponent.md#settextwrapping). In order to edit the text in an edit component, the component has to have keyboard input. This is achieved by setting (Markdown/T_com_mindfusion_diagramming_components_ComponentBase.md#setisfocused) to true. The user can focus an edit component by clicking on it with the left mouse button. To enable single line edit mode set (Markdown/T_com_mindfusion_diagramming_components_EditComponent.md#setacceptsreturn) to false. The edit components expose several events, most notably - (Markdown/T_com_mindfusion_diagramming_components_EditComponentListener.md#textchanging) and (Markdown/T_com_mindfusion_diagramming_components_EditComponentListener.md#textchanged). ### Selection The current selection of the edit component is defined through the (Markdown/T_com_mindfusion_diagramming_components_EditComponent.md#setselectionstart) and (Markdown/T_com_mindfusion_diagramming_components_EditComponent.md#setselectionlength) properties. The appearance of the selection is defined through the (Markdown/T_com_mindfusion_diagramming_components_EditComponent.md#setselectioncolor), (Markdown/T_com_mindfusion_diagramming_components_EditComponent.md#setinactiveselectioncolor) and (Markdown/T_com_mindfusion_diagramming_components_EditComponent.md#sethideselection) properties. ### Undo/Redo The edit components implement undo and redo internally. To undo the most recent changes press CTRL+Z while the edit component has the input focus. To redo the changes, press CTRL+Y. ### Clipboard All standard Clipboard operations are supported and can be accessed through the usual keyboard shortcuts: Copy - CTRL+C, Cut - CTRL+X, Paste - CTRL+V. ### NumericEdit Components The numeric edit components are similar to the generic edit components. The main difference is that the numeric edits (as the name suggests) allow only numeric input. In addition to the standard edit events, the numeric edits also expose the more specialized (Markdown/T_com_mindfusion_diagramming_components_NumericEditComponentListener.md#validatevalue) and (Markdown/T_com_mindfusion_diagramming_components_NumericEditComponentListener.md#valuechanged) events. The numeric components support undo, redo and clipboard as well. ### Image Components The image components display an image in different alignment modes. The image and alignment can be specified through the (Markdown/T_com_mindfusion_diagramming_components_ImageComponent.md#setimage) and (Markdown/T_com_mindfusion_diagramming_components_ImageComponent.md#setimagealign) properties respectively. ### Shape Components The shape components can display arbitrary geometrical shapes. Any shape defined through a (Markdown/T_com_mindfusion_diagramming_Shape.md) object can be used, including all (#table-of-predefined-shapes). The shape components can also be initialized using the specialized geometry syntax when defined in XML. For more information regarding this, check (#components). The appearance of the displayed shape is specified through the (Markdown/T_com_mindfusion_diagramming_components_ShapeComponent.md#setbrush) and (Markdown/T_com_mindfusion_diagramming_components_ShapeComponent.md#setpen) properties and the shape itself is assigned through the (Markdown/T_com_mindfusion_diagramming_components_ShapeComponent.md#setshape) property. ### Slider Components The slider components provide a way to interactively select a single numeric value or a range of numeric values from within a fixed interval, by dragging one or more thumbs along a horizontal rail. In addition the slider component provides two buttons which can be used to adjust the value more precisely. The type of the slider component can be specified through the (Markdown/T_com_mindfusion_diagramming_components_SliderComponent.md#settype) property. The interval of available values can be set through the (Markdown/T_com_mindfusion_diagramming_components_SliderComponent.md#setminimum) and (Markdown/T_com_mindfusion_diagramming_components_SliderComponent.md#setmaximum) properties. The selected values can be get or set through the (Markdown/T_com_mindfusion_diagramming_components_SliderComponent.md#setvalue), (Markdown/T_com_mindfusion_diagramming_components_SliderComponent.md#setstartvalue) and (Markdown/T_com_mindfusion_diagramming_components_SliderComponent.md#setendvalue) properties respectively depending on the type of the slider. The components expose a set of events, which are raised when the slider values are changed interactively. These events are (Markdown/T_com_mindfusion_diagramming_components_SliderListener.md#batchvaluechanged), (Markdown/T_com_mindfusion_diagramming_components_SliderListener.md#endvaluechanged), (Markdown/T_com_mindfusion_diagramming_components_SliderListener.md#startvaluechanged), and (Markdown/T_com_mindfusion_diagramming_components_SliderRailListener.md#valuechanged). ### Spinner Components The spinner components represent a composition of a numeric edit box and two buttons. In addition to the core functionality provided by the numeric edit, the value can also be adjusted through the buttons or by pressing the Up, Down, PageUp and PageDown keys while the edit has the input focus. The interval in which the value can vary is specified through the (Markdown/T_com_mindfusion_diagramming_components_SpinnerComponent.md#setminimum) and (Markdown/T_com_mindfusion_diagramming_components_SpinnerComponent.md#setmaximum) properties. The current value can be accessed through the (Markdown/T_com_mindfusion_diagramming_components_SpinnerComponent.md#setvalue) property. The events that are raised when the value is changed are (Markdown/T_com_mindfusion_diagramming_components_SpinnerComponentListener.md#valuechanged) and (Markdown/T_com_mindfusion_diagramming_components_SpinnerComponentListener.md#batchvaluechanged). ### Simple Panels The most basic of all three built-in panels. Simple panels arrange their child components on top of each other, in the order they were added in the (Markdown/T_com_mindfusion_diagramming_components_ContainerComponent.md#getcomponents) collection. The children are positioned within the available space according to their (Markdown/T_com_mindfusion_diagramming_components_ComponentBase.md#sethorizontalalignment), (Markdown/T_com_mindfusion_diagramming_components_ComponentBase.md#setverticalalignment), (Markdown/T_com_mindfusion_diagramming_components_ComponentBase.md#setwidth) and (Markdown/T_com_mindfusion_diagramming_components_ComponentBase.md#setheight). ### Stack Panels Stack panels arrange their children in a vertical or horizontal row, according to the value of the (Markdown/T_com_mindfusion_diagramming_components_StackPanel.md#setorientation) property. ### Grid Panels Grid panels arrange their children in a table. The rows and columns of this table are defined through GridRow and GridColumn objects which are added to the (Markdown/T_com_mindfusion_diagramming_components_GridPanel.md#getrows) and (Markdown/T_com_mindfusion_diagramming_components_GridPanel.md#getcolumns) collection of the (Markdown/T_com_mindfusion_diagramming_components_GridPanel.md) respectively. Each grid panel needs to define at least one column and row in order to be effective. The destination row and column of individual child components depends on the value of their (Markdown/T_com_mindfusion_diagramming_components_ComponentBase.md#setgridrow) and (Markdown/T_com_mindfusion_diagramming_components_ComponentBase.md#setgridcolumn) properties. ## Components and XML As described in the (#using-components) topic, to use components in JDiagram you need to instantiate them and add them to the (Markdown/T_com_mindfusion_diagramming_CompositeNode.md#getcomponents) collection of a (Markdown/T_com_mindfusion_diagramming_CompositeNode.md). JDiagram provides a more convenient method for defining component hierarchies - through XML. ### Definition Each node in the source XML represents a component or an object. The child nodes in the XML represent child components. The XML attributes represent either property assignments or event handler attachments. A simple component hierarchy defined in XML is illustrated below: ```                                                                                                             ``` Because the XML documents have a single root, the component hierarchies defined through XML can have a single root too. In the case when a hierarchy needs to have more than one root each root can be defined in its own XML or all the root components can be grouped under a single component container. As is observed in the sample above the components can be specified through shortcut names. The following table lists all available shortcuts: | **Component ** | **Shortcut Name ** | (Markdown/T_com_mindfusion_diagramming_components_BorderComponent.md) | Border | (Markdown/T_com_mindfusion_diagramming_components_ButtonComponent.md) | Button | (Markdown/T_com_mindfusion_diagramming_components_CheckBoxComponent.md) | CheckBox | (Markdown/T_com_mindfusion_diagramming_components_EditComponent.md) | Edit | (Markdown/T_com_mindfusion_diagramming_components_ImageComponent.md) | Image | (Markdown/T_com_mindfusion_diagramming_components_ShapeComponent.md) | Shape | (Markdown/T_com_mindfusion_diagramming_components_TextComponent.md) | Text | (Markdown/T_com_mindfusion_diagramming_components_NumericEditComponent.md) | NumericEdit | (Markdown/T_com_mindfusion_diagramming_components_SliderComponent.md) | Slider | (Markdown/T_com_mindfusion_diagramming_components_SpinnerComponent.md) | Spinner The components can also be defined using their full names. ### Composite Properties Some properties have too complex values and cannot be represented with attributes. Consider for example the collection properties, such as the (Markdown/T_com_mindfusion_diagramming_components_GridPanel.md#getcolumns) and (Markdown/T_com_mindfusion_diagramming_components_GridPanel.md#getrows) properties of the (Markdown/T_com_mindfusion_diagramming_components_GridPanel.md). These properties can be defined as child nodes using the specialized syntax illustrated below: ```         ``` For example, to define (Markdown/T_com_mindfusion_diagramming_components_ContentComponent.md#setcontent) of a (Markdown/T_com_mindfusion_diagramming_components_ButtonComponent.md), you can use the following syntax: ``` ``` ### Images Images can be defined in XML using Bitmap objects and string paths. Here is an example: ```       Images/MyImage.png   ``` In the example above "Images/MyImage.png" will be interpreted as an image path and the loader will attempt to create a new java.awt.Image instance by passing the file path to the Toolkit.getImage method. ### Shapes The (Markdown/T_com_mindfusion_diagramming_components_ShapeComponent.md#setshape) of shape components can be defined in XML by either specifying the name of a (#table-of-predefined-shapes) or by using the specialized syntax for graphical paths. The example below defines two (Markdown/T_com_mindfusion_diagramming_components_ShapeComponent.md) instances in a (Markdown/T_com_mindfusion_diagramming_components_StackPanel.md). The first shape component uses the predefined Ellipse shape and the second uses a custom arrow shape: ```     ``` The specialized graphical path syntax supports the following subset of operations: | **Command ** | **Description ** | MX,Y | Moves to point (X, Y). | LX,Y | Draws a line from the current point to point (X, Y). | CX1,Y1 X2,Y2 X3,Y3 | Draws a curve from the current point to (X3, Y3) using points (X1, Y1) and (X2, Y2) as control points. | AW,H R A D X,Y | Draws an arc with size (W, H) using rotation R and an end point (X, Y). A specifies whether to draw the large arc (1 - large arc, 0 - small arc) and D specifies direction - (1 - positive angle, 0 - negative). | z | Closes the figure. ### Loading XML Component hierarchies defined in XML can be loaded using the (Markdown/T_com_mindfusion_diagramming_components_XmlLoader.md) class. The class provides several static (Markdown/T_com_mindfusion_diagramming_components_XmlLoader.md#load) method overloads for loading XML from different sources - a content string, Stream or XML Document. Each of the Load methods returns a (Markdown/T_com_mindfusion_diagramming_components_ComponentBase.md) representing the root of the loaded hierarchy. This component can then be added to a (Markdown/T_com_mindfusion_diagramming_CompositeNode.md) or as a child of another component. The following example illustrates how to use the (Markdown/T_com_mindfusion_diagramming_components_XmlLoader.md): ```csharp CompositeNode node = new CompositeNode(); node.getComponents().add(XmlLoader.load("")); ``` ### Handling Events Unlike MindFusion.Diagramming libraries for other platforms, Java version cannot attach handlers to events by names specified in XML. Instead, you will have to add an event listener explicitly after loading a template: ```