001: /*
002: * @(#)RegistrationEvent.java 11/28/2005
003: *
004: * Copyright 2002 - 2005 JIDE Software Inc. All rights reserved.
005: */
006:
007: package com.jidesoft.converter;
008:
009: import java.awt.*;
010: import java.util.EventObject;
011:
012: /**
013: * An <code>AWTEvent</code> that adds support for
014: * registration objects as the event source.
015: */
016: public class RegistrationEvent extends EventObject {
017: /**
018: * The first number in the range of IDs used for <code>DockableFrame</code> events.
019: */
020: public static final int REGISTRATION_EVENT_FIRST = AWTEvent.RESERVED_ID_MAX + 4100;
021:
022: /**
023: * The last number in the range of IDs used for <code>DockableFrame</code> events.
024: */
025: public static final int REGISTRATION_EVENT_LAST = REGISTRATION_EVENT_FIRST + 3;
026:
027: /**
028: * This event is delivered when the
029: * a new object is registered.
030: */
031: public static final int REGISTRATION_ADDED = REGISTRATION_EVENT_FIRST;
032:
033: /**
034: * This event is delivered when
035: * the registered object is removed.
036: */
037: public static final int REGISTRATION_REMOVED = 1 + REGISTRATION_EVENT_FIRST;
038:
039: /**
040: * This event is delivered when
041: * the whole regisration is cleared
042: */
043: public static final int REGISTRATION_CLEARED = 2 + REGISTRATION_EVENT_FIRST;
044:
045: private int _id;
046: private Object _object;
047: private Object _context;
048: private Object _key;
049:
050: /**
051: * Create a REGISTRATION_CLEARED event.
052: *
053: * @param source
054: * @param id must be equal to REGISTRATION_CLEARED.
055: */
056: public RegistrationEvent(Object source, int id) {
057: super (source);
058: if (id != REGISTRATION_CLEARED) {
059: throw new IllegalArgumentException(
060: "This constructor is only for REGISTRATION_CLEARED event.");
061: }
062: _id = id;
063: }
064:
065: /**
066: * Constructs an <code>RegistrationEvent</code> object.
067: *
068: * @param source the <code>Registration</code> object that originated the event
069: * @param id an integer indicating the type of event
070: */
071: public RegistrationEvent(Object source, int id, Object object,
072: Object key, Object context) {
073: super (source);
074: _id = id;
075: _object = object;
076: _context = context;
077: _key = key;
078: }
079:
080: public Object getKey() {
081: return _key;
082: }
083:
084: public Object getContext() {
085: return _context;
086: }
087:
088: public Object getObject() {
089: return _object;
090: }
091:
092: public int getId() {
093: return _id;
094: }
095:
096: @Override
097: public String toString() {
098: String action;
099: switch (getId()) {
100: case REGISTRATION_ADDED:
101: action = "ADDED ";
102: break;
103: case REGISTRATION_REMOVED:
104: action = "REMOVED ";
105: break;
106: case REGISTRATION_CLEARED:
107: action = "CLEARED ";
108: break;
109: default:
110: action = "UNKNOWN " + getId() + " ";
111: break;
112: }
113: return action + "{key = " + getKey() + "; context = "
114: + getContext() + "; object = " + getObject();
115: }
116: }
|