ilog.views
Class IlvAccelerator

java.lang.Object
  extended by ilog.views.IlvAccelerator
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
IlvDeleteSelectionAccelerator, IlvDuplicateSelectionAccelerator, IlvFitToSizeAccelerator, IlvIdentityAccelerator, IlvRotateAccelerator, IlvScrollDownAccelerator, IlvScrollLeftAccelerator, IlvScrollRightAccelerator, IlvScrollUpAccelerator, IlvSelectAllAccelerator, IlvZoomInAccelerator, IlvZoomOutAccelerator

public abstract class IlvAccelerator
extends Object
implements Serializable

IlvAccelerator is the abstract base class for classes that define for a manager specific actions triggered by a specific keyboard event.

Overview

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.

Example

The following code example shows how to do the following:

 // 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;
     }
 });   
 

About Interactors and Accelerators

For information about how to treat events in a manager, see Handling Events. The following code examples show how to handle user events:

See Also:
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

IlvAccelerator

public IlvAccelerator(int type,
                      int key,
                      int modifiers)
Creates a new accelerator.

Parameters:
type - the type of the AWT event.
key - the code of the key.
modifiers - the modifiers.
Method Detail

getEventType

public int getEventType()
Returns the type of the AWT event as provided in the constructor.


getKeyCode

public int getKeyCode()
Returns the code of the key event as provided in the constructor.


getModifier

public int getModifier()
Returns the modifier of the event as provided in the constructor.


CtrlChar

public static char CtrlChar(char c)
Returns the key code corresponding to the Ctrl+char event. IlvAccelerator.CtrlChar('a') will return the key code for Ctrl+a.


handleEvent

protected abstract boolean handleEvent(IlvManagerView view)
Handles the accelerator.

Parameters:
view - the view of the manager.


Copyright © 1996-2007 ILOG S.A. All rights reserved.   Documentation homepage.   . All Rights Reserved.