skip to main content
Maps > Developing with design tools > Using the Designer > Writing an application > Creating a JViews Diagrammer application
 
Creating a JViews Diagrammer application
Describes the various ways to create a JViews Diagrammer application, from simple to more complex.
*Creating an application instance
*Explains how to create an instance of IlvDiagrammerApplication.
*Customizing the predefined application
*Describes which parts of the predefined IlvDiagrammerApplication you can customize.
*Creating a basic application from JViews Diagrammer beans
*Explains how to create an application by combining JavaBeans™.
*Adding further components
*Explains how to create more complex applications.
*An editing application created from JViews Diagrammer beans
*Describes an example of a more complex application provided with JViews Diagrammer.
Creating an application instance
The Designer is used with sample data that contains only enough information to specify the drawing style.
The class IlvDiagrammerApplication is a ready-to-use application to display or edit diagrams in diagram components (instances of IlvDiagrammer.).
To create an instance of an application, the CLASSPATH environment variable must contain the JViews Diagrammer JAR files, as well as the palette JAR files that contain the symbols used in the projects.
To create an IlvDiagrammerApplication instance:
*Launch the application from the command line, passing it the style sheet created in the Designer as the style argument, as in the following example.
Example 3 –  
 
java ilog.views.diagrammer.application.IlvDiagrammerApplication -style example.css
You can pass further command-line arguments to control which components are visible, to allow editing of the diagram, and so on. See the reference documentation for IlvDiagrammerApplication for a list of the possible command-line arguments.
To modify the data source of the application in order to display your own data:
1. Retrieve the current diagrammer,
IlvDiagrammerApplication.getCurrentDiagrammer()
2. Modify its data source as explained in the section 'Specifying a different data source' of Next steps after the Designer.
Customizing the predefined application
You can customize the ready-to-use application by subclassing IlvDiagrammerApplication. In the subclass, you can customize the following aspects of the application:
*Working area: can be single-document (default) or multidocument with JDesktopPane and internal frames
*Menu bar: default contents File, Edit, View, Options, Help
*Edit toolbar: by default horizontally above the working area
*View toolbar: by default vertically to the left of the working area
*Palette toolbar (optional)
*Tree showing data model (optional)
*Property Sheet (optional)
*Overview showing the whole of a (large) diagram (optional)
Runtime flags govern what is displayed at startup.
Creating a basic application from JViews Diagrammer beans
An alternative to using the predefined IlvDiagrammerApplication class is to combine the JViews Diagrammer beans yourself. You can do this either using an Integrated Development Environment (IDE), or directly in your Java™ code.
To create a very simple JViews Diagrammer application containing one diagram component ( IlvDiagrammer instance) and a view toolbar (IlvDiagrammerViewBar instance):
*Write the following code
Example 4 – A basic application that extends JFrame
 
/**
 * This is a very simple application based on a diagram component,
 *
 * This application displays a diagram component in a frame.
 * A simple data file is loaded and displayed using a
 * basic style sheet. A predefined toolbar is also used.
 */
public class BasicDiagrammerApplication extends JFrame
{
  // Create the main frame.
  //
  public BasicDiagrammerApplication()
  {
    // Set up the frame.
    //
    super("Basic Diagrammer Application");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLocation(100, 100);
    setSize(400, 300);
    // Create the IlvDiagrammer instance.
    //
    IlvDiagrammer diagrammer = new IlvDiagrammer();
    // Allow selection.
    //
    diagrammer.setSelectMode(true);
    // Add the IlvDiagrammer instance.
    //
    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(diagrammer, BorderLayout.CENTER);
    // Add a predefined toolbar for controlling the view
    // north of the frame.
    //
     getContentPane().add(new IlvDiagrammerViewBar(), BorderLayout.NORTH);
    try {
    // Load a project file.
    //
    diagrammer.setDataFile(new URL("file:data/basic.idpr"));
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  /**
   * The main method of the application.
   */
  public static void main(String[] args)
  {
    // Create an instance of the application, and
    // show it.
    //
    new BasicDiagrammerApplication().setVisible(true);
  }
}
This sample is available at <installdir>/jviews-diagrammer/codefragments/basic/srchtml/BasicDiagrammerApplication.java.html.
Adding further components
You can build more complex applications by adding further JViews Diagrammer beans to the Swing GUI of a basic application.
JViews Diagrammer beans are connected automatically to the currently active IlvDiagrammer instance of the GUI.
To add a bean:
1. Create the bean.
2. Add it to your Swing GUI.
No call is necessary to connect the bean to the IlvDiagrammer instance.
 
For example, you can make the basic application in A basic application that extends JFrame more complete by adding a menu bar to the frame, and an overview to the right of the panel, as shown in the following code example:
 
setJMenuBar(new IlvDiagrammerMenuBar());
getContentPane().add(new IlvDiagrammerOverview(), BorderLayout.EAST);
An editing application created from JViews Diagrammer beans
For an example of a more complex application, see the Editor sample, which is available at <installdir>/jviews-diagrammer/codefragments/editor/srchtml/DiagramEditor.java.html.
This sample is a simple multidocument diagram editor based on the diagram component with the following elements:
*A horizontal toolbar for editing the diagram.
*Palette icons in the toolbar to create nodes and links in the diagram.
*A vertical toolbar to control the diagram view.

Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.