Programming with JViews Maps > Creating a Map Application Using the API > Using the GUI Beans > The Toolbar

The Toolbar Bean is represented by the IlvJMapsManagerViewControlBar class. This is a subclass of the framework class IlvJManagerViewControlBar.

An example of the Toolbar is shown in Figure 3.19.

toolbar.png

Figure 3.19 Toolbar

Including the Bean in an Application

To include the Toolbar Bean in your application, write the following lines of code:

IlvJMapsManagerViewControlBar toolbar = new IlvJMapsManagerViewControlBar();
toolbar.setView(view);

Adding the Bean to a Swing Container

These lines create a standard ILOG JViews interactor toolbar that you need to integrate into your Swing GUI:

panel.add(toolbar, BorderLayout.NORTH);

Customizing the Toolbar

For JViews Maps use, you may want to add more interactors or buttons to this toolbar.

Replacing an Interactor

You can replace standard interactors with better-tailored interactors, such as the IlvMapZoomInteractor, with lines of code such as:

IlvMapZoomInteractor zi = new IlvMapZoomInteractor();
// chose the way the rectangle is drawn when rotation exists
zi.setRotationAllowed(true);
// when zoom is selected, it stays, contrary to default JViews.
zi.setPermanent(true);
//to change from default zoom interactor
toolbar.setZoomViewInteractor(zi);
Adding a New Interactor

You may want to add a completely new interactor:

IlvManagerViewInteractor interactor = ...;
JToggleButton interactorButton = new JToggleButton(interactorIcon);

You have to add a listener to set or pop this interactor when the toggle button is selected:

interactorButton.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {
        if(interactorButton.isSelected()){
          // set the interactor
          view.setInteractor(interactor);
          // and make sure the view has focus, in case the interactor manages keyboard accelerators
          view.requestFocus();
        } else if (view.getInteractor()==interactor){
          // pop the interactor
          view.popInteractor();
        }
  }
});

You also need to pop this interactor when another one is selected:

InteractorListener interactorListener = new InteractorListener() {
  public void interactorChanged(InteractorChangedEvent event) {
        boolean isMyInteractor = (event.getNewValue() == interactor);
        if (interactorButton.isSelected() != isMyInteractor) {
          interactorButton.setSelected(isMyInteractor);
        }
  }
};
view.addInteractorListener(interactorListener);

Then, you can add the interactor button to the toolbar:

toolbar.add(interactorButton);