The createInteractorButtons method will create three buttons (Select, -, and +) that will be stored in the selectButton, zoomButton, and unZoomButton fields of the object.
void createInteractorButtons() {
Panel buttons = new Panel();
selectButton = new Button("Select");
selectButton.setBackground(Color.gray);
selectButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (selectInteractor == null)
selectInteractor = new IlvSelectInteractor();
if (mgrview.getInteractor() != selectInteractor)
mgrview.setInteractor(selectInteractor);
}
}
});
buttons.add(selectButton);
unZoomButton = new Button("-");
unZoomButton.setBackground(Color.gray);
unZoomButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (unZoomInteractor == null)
unZoomInteractor = new IlvUnZoomViewInteractor();
if (mgrview.getInteractor() != unZoomInteractor)
mgrview.setInteractor(unZoomInteractor);
}
});
buttons.add(unZoomButton);
zoomButton = new Button("+");
zoomButton.setBackground(Color.gray);
zoomButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (zoomInteractor == null)
zoomInteractor = new IlvZoomViewInteractor();
if (mgrview.getInteractor() != zoomInteractor)
mgrview.setInteractor(zoomInteractor);
}
});
buttons.add(zoomButton);
getContentPane().add(buttons, BorderLayout.SOUTH);
}
|
Code Sample 2.1 Creating Interactor Buttons
As we now have three possible interactors, the action performed when clicking on a button removes the previously installed interactor and installs the new one by calling the setInteractor method of the IlvManagerView class.