| Programming with JViews Maps > Creating a Map Application Using the API > Using the GUI Beans > The Toolbar |
The Toolbar |
INDEX
PREVIOUS
NEXT
|
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.
To include the Toolbar Bean in your application, write the following lines of code:
IlvJMapsManagerViewControlBar toolbar = new IlvJMapsManagerViewControlBar(); toolbar.setView(view);
These lines create a standard ILOG JViews interactor toolbar that you need to integrate into your Swing GUI:
panel.add(toolbar, BorderLayout.NORTH);
For JViews Maps use, you may want to add more interactors or buttons to this toolbar.
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);
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);
| Copyright © 1987-2007 ILOG S.A. All rights reserved. Documentation homepage. Legal terms. | PREVIOUS NEXT |