home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-03-18 | 11.4 KB | 359 lines |
- /*
- * Copyright (c) 1997 Krumel & Associates, Inc. All Rights Reserved.
- *
- * www.krumel.com - controls@krumel.com
- *
- * Permission is given to the buyer of this package for one software
- * developer to use this software on one CPU (one workstation) and to make
- * one backup copy. You may uitilize and/or modify this class for use in your
- * projects. You may distribute or sell any executable which results from
- * using this code in yur application, except a utility or class of similar
- * nature to this product. You may distribute this product in compiled
- * form only, but soley to be used with your cmpiled executable product
- * for the puposes of dynamic loading. You may NOT redistribute the source
- * code in any form or make it accessible through a network or other
- * distribution media to others. Please refer to the file "copyright.html"
- * for further important copyright and licensing information.
- *
- * The source code is the confidential and proprietary information
- * of Krumel & Associates, Inc. ("Confidential Information"). You shall
- * not disclose such Confidential Information and shall use it only in
- * accordance with the terms of the license agreement you entered into
- * with Krumel & Associates, Inc..
-
- * KRUMEL & ASSOCIATES MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE
- * SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT
- * NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. KRUMEL & ASSOCIATES SHALL NOT
- * BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING,
- * MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
- */
-
-
- package symantec.itools.db.awt.event;
-
- import java.awt.*;
- import symantec.itools.db.awt.*;
- import java.awt.event.*;
-
- /**
- * Event type generated by a TableView when the user interacts with a cell, whether
- * the cell is a heading or in the view proper. The original AWT event that caused
- * a cell event is maintained internally so it can be inspected to determine
- * the what caused the cell event and allow for very specific customization of the
- * the table view's response to cell interactions. All cell events are routed to the
- * TableView's event handler, the data source, and finally any registered objects.
- */
- public class CellEvent extends AWTEvent {
- TableCell cell;
- TableView view;
- int id;
-
- int x, y;
- AWTEvent event;
-
-
- /**
- * Base cell level event ID
- */
- public final static int CELL_EVENT = 50;
- /**
- * Cell level event for when cell is button an pushed down
- */
- public final static int BUTTON_DOWN_EVENT = CELL_EVENT;
- /**
- * Cell level event for when cell is button a mouse is released over button
- */
- public final static int BUTTON_UP_EVENT = CELL_EVENT + 1;
- /**
- * Button depressed but mouse moved off button then back on
- */
- public final static int BUTTON_FLICKER_DOWN_EVENT = CELL_EVENT + 2;
- /**
- * Button depressed but mouse moved off button
- */
- public final static int BUTTON_FLICKER_UP_EVENT = CELL_EVENT + 3;
- /**
- * User requested the most recent changes to be undone and the latest
- * committed data be reset
- */
- public final static int UNDO_CELL_EVENT = CELL_EVENT + 4;
- /**
- * Cell level event for when cell gets focus
- */
- public final static int GOT_FOCUS = CELL_EVENT + 5;
- /**
- * Cell level event for when cell loses focus
- */
- public final static int LOST_FOCUS = CELL_EVENT + 6;
- /**
- * User performed action to change contents of a cell (like a key press)
- */
- public final static int CELL_CONTENT_CHANGE = CELL_EVENT + 7;
- /**
- * Cell level event for when key is pressed in cell
- */
- public final static int KEY_PRESSED = CELL_EVENT + 8;
- /**
- * Cell level event for when key is released in cell
- */
- public final static int KEY_RELEASED = CELL_EVENT + 9;
- /**
- * Cell level event for when mouse is released in cell
- */
- public final static int MOUSE_RELEASED = CELL_EVENT + 10;
- /**
- * Cell level event for when mouse is pushed down in cell
- */
- public final static int MOUSE_PRESSED = CELL_EVENT + 11;
- /**
- * Cell level event for when mouse is dragged in cell
- */
- public final static int MOUSE_DRAGGED = CELL_EVENT + 12;
- /**
- * Double click within cell
- */
- public final static int MOUSE_DOUBLE = CELL_EVENT + 13;
- /**
- * User cell level event ID
- */
- public final static int USER_CELL_EVENT = CELL_EVENT +14;
-
- /**
- * Constructs a cell event using an AWTEvent as a basis. If the AWTEvent
- * is an instance of MouseEvent, the x and y coordinates are obtained and
- * translated to cell relative.
- */
- public CellEvent(TableView v, TableCell c, AWTEvent e, int id) {
- super(v, id);
- view = v;
- cell = c;
- event = e;
- this.id = id;
-
- if (e instanceof MouseEvent) {
- setXandY((MouseEvent)e, true);
- }
- }
-
- /**
- * Gets whether the left mouse button is pushed for when the CellEvent
- * contains a MouseEvent.
- */
- public boolean isLeftMouseButtonDown() {
- if (event instanceof InputEvent) {
- MouseEvent me = (MouseEvent)event;
- return !me.isMetaDown() && (me.getModifiers() & me.ALT_MASK)==0;
- }
-
- return false;
- }
-
- /**
- * Gets whether the middle mouse button is pushed for when the CellEvent
- * contains a MouseEvent.
- */
- public boolean isMiddleMouseButtonDown() {
- if (event instanceof InputEvent) {
- MouseEvent me = (MouseEvent)event;
- return (me.getModifiers() & me.ALT_MASK)!=0;
- }
-
- return false;
- }
-
- /**
- * Gets whether the right mouse button is pushed for when the CellEvent
- * contains a MouseEvent.
- */
- public boolean isRightMouseButtonDown() {
- if (event instanceof InputEvent) {
- MouseEvent me = (MouseEvent)event;
- return me.isMetaDown();
- }
-
- return false;
- }
-
- /**
- * Gets whether the shift key is pushed for when the CellEvent
- * contains a InputEvent.
- */
- public boolean isShiftDown() {
- if (event instanceof InputEvent) {
- return ((InputEvent)event).isShiftDown();
- }
-
- return false;
- }
-
- /**
- * Gets whether the control key is pushed for when the CellEvent
- * contains a InputEvent.
- */
- public boolean isControlDown() {
- if (event instanceof InputEvent) {
- return ((InputEvent)event).isControlDown();
- }
-
- return false;
- }
-
- /**
- * Gets whether the modifiers for when the CellEvent contains a InputEvent.
- */
- public int getModifiers() {
- if (event instanceof InputEvent) {
- return ((InputEvent)event).getModifiers();
- }
-
- return 0;
- }
-
- /**
- * Inherited from java.awt.AWTEvent.
- */
- public int getID() { return id; }
-
- /**
- * Sets the ID for the event.
- */
- public void setID(int id) {
- this.id = id;
- }
-
- /**
- * Gets the Object that generated the event. This is usually a TableView object.
- */
- public TableView getView() { return view; }
-
- /**
- * Gets the TableCell that the event occurred upon.
- */
- public TableCell getCell() { return cell; }
-
- /**
- * Sets the target for the cell that the user interacted with to trigger the
- * event.
- */
- public void setCell(TableCell target) { cell = target; }
-
- /**
- * Gets whether the target cell is a column heading.
- */
- public boolean isTargetColumnHeading() { return view.colHeadingCell(cell); }
-
- /**
- * Gets whether the target cell is a row heading.
- */
- public boolean isTargetRowHeading() { return view.rowHeadingCell(cell); }
-
- /**
- * Gets whether the target cell is corner cell.
- */
- public boolean isTargetCornerCell() { return view.cornerCell(cell); }
-
- /**
- * Sets the x and y coordinates for the event using a mouse event object.
- * @param e The mouse event to get the event coordinates from.
- * @param translate Determines if coordinates should be translated from
- * view relative to cell relative.
- */
- public void setXandY(MouseEvent e, boolean translate) {
- setXandY(e.getX(), e.getY(), translate);
- }
-
- /**
- * Sets the x and y coordinates for the event. Usually set for mouse events
- * only.
- * @param x The x coordinate.
- * @param y The y coordinate.
- * @param translate Determines if coordinates should be translated from
- * view relative to cell relative.
- */
- public void setXandY(int x, int y, boolean translate) {
- this.x = x;
- this.y = y;
- if (translate) {
- translateToCell();
- }
- }
-
- /**
- * Gets the x coordinate for the event. Usually on set for mouse events and it has
- * been translated to be relative to upper-left corner of cell.
- */
- public int getX() { return x; }
-
- /**
- * Gets the y coordinate for the event. Usually on set for mouse events and it has
- * been translated to be relative to upper-left corner of cell.
- */
- public int getY() { return y; }
-
- /**
- * Returns the integer key-code associated with the key in this event. For KEY_TYPED
- * events, keyCode is VK_UNDEFINED.
- */
- public int getKeyCode() {
- if (event instanceof KeyEvent) {
- return ((KeyEvent)event).getKeyCode();
- }
-
- return KeyEvent.VK_UNDEFINED;
- }
-
- /**
- * The CellEvent class stores a reference to the actual event sent to the TableView.
- * This method attempts to cast that reference to a KeyEvent type and return it.
- * The event object is stored as an AWTEvent internally.
- */
- public KeyEvent getAsKeyEvent() {
- return (KeyEvent)event;
- }
-
- /**
- * The CellEvent class stores a reference to the actual event sent to the TableView.
- * This method attempts to cast that reference to a MouseEvent type and return it.
- * The event object is stored as an AWTEvent internally. The x and y coordinates
- * stored by this mouse event are relative to the TableView, NOT the cell.
- */
- public MouseEvent getAsMouseEvent() {
- return (MouseEvent)event;
- }
-
- /**
- * The CellEvent class stores a reference to the actual event sent to the TableView.
- * The event object is stored as an AWTEvent internally.
- */
- public AWTEvent getAsAWTEvent() {
- return event;
- }
-
- void translateToCell() {
- Rectangle b = view.getCellBounds(cell, null);
-
- x -= b.x;
- y -= b.y;
- }
-
- /**
- * Creates a cell event based on a view's mouse event.
- */
- public static void
- generateMouseEvent(TableView v, TableCell c, MouseEvent e, int id) {
- CellEvent event = new CellEvent(v, c, e, id);
- c.mouseEvent(event);
- }
-
- /**
- * Creates a cell event based on a view's mouse event.
- */
- public static void
- generateKeyEvent(TableView v, TableCell c, KeyEvent e, int id) {
- CellEvent event = new CellEvent(v, c, e, id);
- c.keyEvent(event);
- }
-
- }
-