001: /*
002: * Jacareto Copyright (c) 2002-2005
003: * Applied Computer Science Research Group, Darmstadt University of
004: * Technology, Institute of Mathematics & Computer Science,
005: * Ludwigsburg University of Education, and Computer Based
006: * Learning Research Group, Aachen University. All rights reserved.
007: *
008: * Jacareto is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation; either
011: * version 2 of the License, or (at your option) any later version.
012: *
013: * Jacareto is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public
019: * License along with Jacareto; if not, write to the Free
020: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021: *
022: */
023:
024: package jacareto.record;
025:
026: import jacareto.comp.Components;
027: import jacareto.system.Environment;
028: import jacareto.toolkit.StringToolkit;
029:
030: import java.awt.Component;
031:
032: import javax.swing.JTabbedPane;
033: import javax.swing.event.ChangeEvent;
034:
035: /**
036: * This class represents change in the source component.
037: *
038: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
039: * @version 1.0
040: */
041: public class ChangeEventRecordable extends EventObjectRecordable {
042: /** Additional information about the change event. */
043: private String additionalInformation;
044:
045: /**
046: * Creates a new change event recordable with the specified values.
047: *
048: * @param env the env object
049: * @param sourceName the name of the events source
050: * @param sourceClass the classname of the source
051: * @param duration the duration
052: * @param procTime the processing time
053: * @param additionalInformation the additional information
054: */
055: public ChangeEventRecordable(Environment env, String sourceName,
056: String sourceClass, long duration, long procTime,
057: String additionalInformation) {
058: super (env, sourceName, sourceClass, duration, procTime);
059: setAdditionalInformation(additionalInformation);
060: }
061:
062: /**
063: * Creates a ChangeEventRecordable with default values and no environment. The environment
064: * should be defined with the method {@link
065: * jacareto.system.EnvironmentMember#setEnvironment(Environment)} before environment instances
066: * will be accessed.
067: */
068: public ChangeEventRecordable() {
069: this (null, "", "", 0, 0, "");
070: }
071:
072: /**
073: * Creates a ChangeEventRecordable with the valued of the given change event.
074: *
075: * @param env the environment
076: * @param event the list selection event
077: * @param components the components
078: * @param duration the duration
079: * @param procTime the processing time (replay time)
080: */
081: public ChangeEventRecordable(Environment env, ChangeEvent event,
082: Components components, long duration, long procTime) {
083: this (env, components.getName((Component) event.getSource()),
084: Components.getClassName(event.getSource()), duration,
085: procTime, "");
086:
087: Object source = event.getSource();
088:
089: if (source instanceof JTabbedPane) {
090: JTabbedPane tabbedPane = (JTabbedPane) source;
091: int selectedIndex = tabbedPane.getSelectedIndex();
092: String title = tabbedPane.getTitleAt(selectedIndex);
093:
094: if (StringToolkit.isDefined(title)) {
095: setAdditionalInformation(title);
096: } else {
097: setAdditionalInformation("" + selectedIndex);
098: }
099: }
100: }
101:
102: /**
103: * Sets the additional information of the change event. For example, if the event has been
104: * dispatched on a tabbed pane, the title of the tab is additional information.
105: *
106: * @param additionalInformation the additional information.
107: */
108: public void setAdditionalInformation(String additionalInformation) {
109: this .additionalInformation = additionalInformation;
110: fireValuesChanged();
111: }
112:
113: /**
114: * Returns the additional information.
115: *
116: * @return additionalInformation the additional information
117: */
118: public String getAdditionalInformation() {
119: return additionalInformation;
120: }
121:
122: /**
123: * Returns the name of the key event recordable
124: *
125: * @return the name
126: */
127: public String getElementName() {
128: return getLanguage().getString(
129: "Recordables.ChangeEventRecordable.Name");
130: }
131:
132: /**
133: * Returns a description of the recordable.
134: *
135: * @return the description
136: */
137: public String getElementDescription() {
138: return getLanguage().getString(
139: "Recordables.ChangeEventRecordable.Description");
140: }
141:
142: /**
143: * Returns a String which describes the content of the recordable shortly.
144: *
145: * @return a string with a short description of the object
146: */
147: public String toShortString() {
148: return getElementName();
149: }
150:
151: /**
152: * Returns a string representation of the recordable.
153: *
154: * @return the string representation
155: */
156: public String toString() {
157: return "ChangeEventRecordable[" + getSourceName() + ","
158: + getDuration() + "]";
159: }
160:
161: public boolean hasProcTime() {
162: return true;
163: }
164: }
|