|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectilog.views.IlvAccelerator
public abstract class IlvAccelerator
IlvAccelerator is the abstract base class for classes that
define for a manager specific actions triggered by a specific keyboard event.
An accelerator defines the action to be performed when a predefined keyboard
event occurs, such as the pressing of a specific key sequence. Accelerators
are attached to a manager by calling to
IlvManager.addAccelerator(IlvAccelerator).
The ilog.views.accelerator package provides ready made accelerators
that handle zoom, rotation, scrolling, duplication and deletion actions.
Subclass IlvAccelerator to make your own custom accelerators.
The following code example shows how to do the following:
IlvAccelerator subclass
// Create the manager:
manager = new IlvManager();
// Create the view associated to the manager:
mgrview = new IlvManagerView(manager);
mgrview.setBackground(Color.white);
IlvGraphic obj;
obj = new IlvRectangle(new IlvRect(60, 30, 50, 50), false, true);
manager.addObject(obj, false);
obj = new IlvRectangle(new IlvRect(140, 50, 50, 50), false, true);
manager.addObject(obj, false);
// Install zoom accelerators.
// Press CTRL and + to zoom in, CTRL and - to zoom out.
manager.addAccelerator(
new IlvZoomOutAccelerator(KeyEvent.KEY_PRESSED, KeyEvent.VK_MINUS, KeyEvent.CTRL_MASK));
manager.addAccelerator(
new IlvZoomInAccelerator(KeyEvent.KEY_PRESSED, KeyEvent.VK_PLUS, KeyEvent.CTRL_MASK));
// Install the select interactor on the view.
// This is used to select graphic objects with the mouse that can then be
// deleted using the custom delete interactor.
IlvSelectInteractor inter = new IlvSelectInteractor();
inter.setOpaqueMove(true);
mgrview.setInteractor(inter);
// Add the delete selection accelerator.
// Press DEL to delete the selected objects.
manager.addAccelerator(
new IlvDeleteSelectionAccelerator(KeyEvent.KEY_PRESSED, KeyEvent.VK_DELETE, 0));
// Add your own custom accelerator.
// Press SPACE to print the number of objects in the manager
//
manager.addAccelerator(
new IlvAccelerator(KeyEvent.KEY_PRESSED, KeyEvent.VK_BACK_SPACE, 0) {
protected boolean handleEvent(IlvManagerView v)
{
int n = v.getManager().getCardinal();
System.out.println("Number of objects: " + n);
return true;
}
});
For information about how to treat events in a manager, see Handling Events. The following code examples show how to handle user events:
IlvManager.addAccelerator(IlvAccelerator),
Serialized Form| Constructor Summary | |
|---|---|
IlvAccelerator(int type,
int key,
int modifiers)
Creates a new accelerator. |
|
| Method Summary | |
|---|---|
static char |
CtrlChar(char c)
Returns the key code corresponding to the Ctrl+char event. |
int |
getEventType()
Returns the type of the AWT event as provided in the constructor. |
int |
getKeyCode()
Returns the code of the key event as provided in the constructor. |
int |
getModifier()
Returns the modifier of the event as provided in the constructor. |
protected abstract boolean |
handleEvent(IlvManagerView view)
Handles the accelerator. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public IlvAccelerator(int type,
int key,
int modifiers)
type - the type of the AWT event.key - the code of the key.modifiers - the modifiers.| Method Detail |
|---|
public int getEventType()
public int getKeyCode()
public int getModifier()
public static char CtrlChar(char c)
IlvAccelerator.CtrlChar('a') will return the
key code for Ctrl+a.
protected abstract boolean handleEvent(IlvManagerView view)
view - the view of the manager.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||