Creating a simple applet using Rogue Wave JViews beans

To create a simple Rogue Wave® JViews applet using Rogue Wave JViews Framework beans, no coding is necessary. The applet you create is a simple Swing applet that displays a butterfly with a toolbar allowing you to zoom and pan the content of the view.
For information on the concepts that underlie JavaBeans, refer to the website: http://java.sun.com/products/javabeans. You are assumed to be familiar with the manipulation of JavaBeans inside your IDE.
Note
 The Swing beans that you will use have the letter “J” in the prefix of the bean name. You could also create the same type of application using only AWT controls. To do so, you would simply use the IlvScrollManagerView bean that is an AWT control instead of the IlvJScrollManagerView bean.
The following example is carried out using a typical IDE procedure. It comprises the following stages:
  1. Create the manager view
  2. Set the properties of the manager view
  3. Create a manager and display its content in a view
  4. Load an .ivl file into the manager
  5. Add a control toolbar bean
  6. Configure the toolbar
  7. Test the result

Create the manager view

To create the manager view:
  1. Create a new project as a Swing applet or application.
  2. Display the Rogue Wave JViews beans on the toolbar by selecting that package.
  3. From the toolbar, click the IlvJScrollManagerView bean icon IlvJScrollManagerViewColor16.gif and drag it inside the form designer of your IDE.
    Warning
    There are two of these icons on the toolbar. Make sure you are using IlvJScrollManagerView and not IlvScrollManagerView.
  4. Drag the handles of your IlvJScrollManagerView bean until it appears as in the following figure.
    IlvJScrollManagerView
bean being dragged
    IlvJScrollManagerView Object Selected in the Form Designer
  5. Click the IlvManagerView bean icon IlvManagerViewColor16.gif on the toolbar and drag it inside the IlvJScrollManagerView bean.
    The result is fairly similar to what you obtained previously, except that you can now select the manager view. See IlvJScrollManagerView Object with a Selected IlvManagerView Object Inside.
    Note
     If you were to compile and run the project at this point, you would see that the IlvJScrollManagerView allows you to scroll through the content of the IlvManagerView bean.
    IlvJScrollManagerView
with selected IlvmanagerView Bean in it
    IlvJScrollManagerView Object with a Selected IlvManagerView Object Inside
The next step is to change a manager view property of the bean, which is done in the following property sheet. This property sheet is active because the IlvManagerView object is presently selected in the form designer. The property to change is the background property.
Property
sheet
Property Sheet for IlvManagerView Object

Set the properties of the manager view

To set the properties of the manager view:
  1. Click the value field of the Background property and change the background of the view to white :
    Setting
the Background property
    Setting the Background property of a View
  2. Change the KeepingAspectRatio property to true .
    This will make sure that the zoom level remains the same along the x and y axis.
You can now create an IlvManager bean. The IlvManager bean provides the data structure that contains the graphic objects you want to display.

Create a manager and display its content in a view

To create the IlvManager bean and display its content in a view:
  1. Click the IlvManager bean icon IlvManagerColor16.gif on the toolbar.
  2. Drag it into the form designer.
    The class IlvManager is not a graphical bean, so it is not managed the same way by the different IDEs. The image below shows the manager as a small object inside the form designer.
    How the
Ilvmanager bean appears in the form designer
    The IlvManager bean in the Form Designer
    You must now associate the view with the manager. This is done by setting the manager property of the IlvManagerView bean to the new manager bean.
  3. Select the IlvManagerView object so that its property sheet is active.
  4. Set the value of its Manager property to ilvManager1 as shown in the following figure.
    Setting
the Manager property
    Setting the Manager property of a View
The IlvManagerView will now display the content of the IlvManager bean. You can create several IlvManagerView objects and associate them with the same IlvManager bean. This allows you to have several views of the same data.

Load an .ivl file into the manager

To load an .ivl file into the IlvManager bean:
  1. Select IlvManager1 so that its property sheet is active.
  2. Click in the value field of the FileName property and then click the ellipsis button that appears.
  3. Click the ellipsis button in the FileName Editor window that appears.
  4. Browse to the lou.ivl file located in the data directory of JViews Framework and open it.
  5. Click OK in the FileName Editor dialog box.
The file is automatically displayed in the IlvManagerView bean.
A file
being loaded into the manager
Loading a file into the Manager
The next step is to add a toolbar that allows the user to control the zoom level of the view and to pan the view.

Add a control toolbar bean

To add a control toolbar bean:
  1. Click the IlvJManagerViewControlBar icon IlvJManagerViewControlBarColor16.gif on the Rogue Wave JViews beans toolbar.
  2. Drag it into the form designer.
    step7.gif
    The Control toolbar in the form designer
    You must now associate the toolbar with the view by setting the View property of the toolbar.
  3. Verify that the IlvJManagerViewControlBar object is selected so that its property sheet is active.
  4. Select ilvManagerView1 in the value field of the View property as seen in the following figure.
    Setting
the View property
    Associating the toolbar with the View
You may configure the toolbar in different ways. You can:
  • Hide some of the predefined button icons of the toolbar by setting the corresponding properties: PanButtonAvailable, SelectButtonAvailable, and so on
  • Add your own button icons to the toolbar, as you can with any Swing toolbar
  • Modify the default interactors that are used in the toolbar
For example, the toolbar has a selectInteractor property that allows you to change the selection interactor used when the user clicks on the Select button icon. You can modify the properties of the selection interactor bean to define the type of selection you need. For example, you may want to disable the editing capability.

Configure the toolbar

To configure the toolbar:
  1. Click an IlvSelectInteractor bean IlvSelectInteractorColor16.gif on the toolbar and drag it into the form designer.
    The selection
interactor selected
    Selecting the Selection Interactor
  2. Set its EditionAllowed property to false as seen below.
    Allowing
editing
    Customizing the Selection Interactor
    You are now going to replace the default selection interactor used in the toolbar by setting the SelectInteractor property of ilvJManagerViewControlBar1.
  3. Select the ilvJManagerViewControlBar1 object so that its property sheet is active.
  4. Change the value of the SelectInteractor property to ilvSelectInteractor1 .
    Setting
the selection interactor
    Replacing the default selection interactor
  5. Compile the project.
You have created a Java application without writing a single line of code.
Note
 In this example, you have added interaction to the view by means of the control toolbar. You could also directly set an interactor bean such as the IlvSelectInteractor on the manager view by using the interactor property of the IlvManagerView.

Test the result

To test the result:
  1. Execute the applet. The resulting application should be as follows:
    Resulting
application
    Final application
  2. Use the scroll bars and the following toolbar icons to manipulate the image displayed in the manager view:
    • The Pan icon pan.gif to pan the content of a view
    • The Select arrow icon selectarrow.gif to select objects in the view
    • The Interactive zoom icon interactivezoom.gif to drag a rectangle over an area that you want to zoom
    • The Zoom-in icon zoomin.gif and the zoom-out icon zoomout.gif
    • The Fit to view icon fittocontent.gif to make sure that the content of the manager is fully displayed
This concludes the example. For information on how to save your project and to know what type of files are generated when saving, refer to the documentation of your IDE.