001: /*_############################################################################
002: _##
003: _## SNMP4J-Agent - MOTableModelEvent.java
004: _##
005: _## Copyright (C) 2005-2007 Frank Fock (SNMP4J.org)
006: _##
007: _## Licensed under the Apache License, Version 2.0 (the "License");
008: _## you may not use this file except in compliance with the License.
009: _## You may obtain a copy of the License at
010: _##
011: _## http://www.apache.org/licenses/LICENSE-2.0
012: _##
013: _## Unless required by applicable law or agreed to in writing, software
014: _## distributed under the License is distributed on an "AS IS" BASIS,
015: _## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: _## See the License for the specific language governing permissions and
017: _## limitations under the License.
018: _##
019: _##########################################################################*/
020:
021: package org.snmp4j.agent.mo;
022:
023: import java.util.EventObject;
024:
025: /**
026: * The <code>MOTableModelEvent</code> event object describes events that change
027: * a table model. Such events include adding, removing, and changing of rows
028: * as well as clearing a whole model.
029: *
030: * @author Frank Fock
031: * @version 1.0
032: */
033: public class MOTableModelEvent extends EventObject {
034:
035: private static final long serialVersionUID = -2260159403182301993L;
036:
037: public static final int ROW_CHANGED = 0;
038: public static final int ROW_ADDED = 1;
039: public static final int ROW_REMOVED = 2;
040: public static final int TABLE_CLEAR = 3;
041:
042: private int type;
043: private MOTableRow affectedRow;
044: private int columnIndex = -1;
045:
046: /**
047: * Creates a model event associated with a single row and column.
048: * @param source
049: * the event source.
050: * @param type
051: * the event type as defined by the ROW_* constants of this object.
052: * @param affectedRow
053: * the row that is associated with this event.
054: * @param columnIndex
055: * the column index associated with this event.
056: */
057: public MOTableModelEvent(Object source, int type,
058: MOTableRow affectedRow, int columnIndex) {
059: super (source);
060: this .type = type;
061: this .affectedRow = affectedRow;
062: this .columnIndex = columnIndex;
063: }
064:
065: /**
066: * Creates a model event associated with a single row.
067: * @param source
068: * the event source.
069: * @param type
070: * the event type as defined by the ROW_* constants of this object.
071: * @param affectedRow
072: * the row that is associated with this event.
073: */
074: public MOTableModelEvent(Object source, int type,
075: MOTableRow affectedRow) {
076: this (source, type, affectedRow, -1);
077: }
078:
079: /**
080: * Creates the model wide event.
081: * @param source
082: * the event source.
083: * @param type
084: * the event type as defined by the constants of this object.
085: */
086: public MOTableModelEvent(Object source, int type) {
087: this (source, type, null);
088: }
089:
090: /**
091: * Returns the type of event.
092: * @return
093: * one of the event type constants defined by this object.
094: */
095: public int getType() {
096: return type;
097: }
098:
099: /**
100: * Gets the affected row (if a single row is affected by the event).
101: * @return
102: * the <code>MOTableRow</code> instance associated with this event, or
103: * <code>null</code> if the whole model is affected.
104: */
105: public MOTableRow getAffectedRow() {
106: return affectedRow;
107: }
108:
109: /**
110: * Returns the column index associated with this event.
111: * @return
112: * a column index >= 0 if a column is associated with this event or -1
113: * if not.
114: */
115: public int getColumnIndex() {
116: return columnIndex;
117: }
118:
119: public String toString() {
120: return MOTableModelEvent.class.getName() + "[type=" + type
121: + ",affectedRow=" + affectedRow + ",columnIndex="
122: + columnIndex + "]";
123: }
124: }
|