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.convert.datacase;
025:
026: import jacareto.convert.Converter;
027: import jacareto.dataset.DataCase;
028: import jacareto.struct.MouseClick;
029: import jacareto.struct.StructureElement;
030: import jacareto.system.Environment;
031:
032: /**
033: * A converter which is able to convert a {@link jacareto.struct.MouseClick} to a data case, and
034: * vice versa.
035: *
036: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
037: * @version 1.02
038: */
039: public class DCMouseClickConverter extends Converter {
040: /**
041: * Creates a new datacase event converter.
042: *
043: * @param env the environment
044: */
045: public DCMouseClickConverter(Environment env) {
046: super (env);
047: }
048:
049: /**
050: * Returns whether this converter is able to transform the specified object to a data case.
051: * This converter is responsible for the given object if it is of type
052: * <code>MouseClick</code>.
053: *
054: * @param element the structure element
055: *
056: * @return true if this converter is responsible for this structure element; otherwise false.
057: */
058: public boolean handlesElement(StructureElement element) {
059: return (element != null) && (element instanceof MouseClick);
060: }
061:
062: /**
063: * Converts the specified element to a data case, if this converter is responsible for it. For
064: * responsibility see {@link #handlesElement(StructureElement)}.
065: *
066: * @param element the object to convert
067: *
068: * @return the record object
069: */
070: public Object convertElement(StructureElement element) {
071: MouseClick click = (MouseClick) element;
072:
073: Object[] values = new Object[8];
074: values[0] = new Integer(click.getX());
075: values[1] = new Integer(click.getY());
076: values[2] = new Integer(click.getRootX());
077: values[3] = new Integer(click.getRootY());
078: values[4] = new Integer(click.getClickCount());
079: values[5] = click.getSourceName();
080: values[6] = click.getRootName();
081: values[7] = new Integer(click.getModifiers());
082:
083: String[] valueNames = new String[8];
084: valueNames[0] = language
085: .getString("Events.MouseEvent.XPosition");
086: valueNames[1] = language
087: .getString("Events.MouseEvent.YPosition");
088: valueNames[2] = language
089: .getString("Events.MouseEvent.RootXPosition");
090: valueNames[3] = language
091: .getString("Events.MouseEvent.RootYPosition");
092: valueNames[4] = language
093: .getString("Events.MouseEvent.ClickCount");
094: valueNames[5] = language.getString("Events.Event.Source");
095: valueNames[6] = language
096: .getString("Events.ComponentEvent.Root");
097: valueNames[7] = language
098: .getString("Events.InputEvent.Modifiers");
099:
100: return new DataCase(env, values, valueNames);
101: }
102:
103: /**
104: * Returns <code>false</code> (This converter just converts in one direction at at the moment).
105: *
106: * @param other DOCUMENT ME!
107: *
108: * @return DOCUMENT ME!
109: */
110: public boolean handlesOther(Object other) {
111: return false;
112: }
113:
114: /**
115: * Returns <code>null</code> (This converter just converts in one direction at at the moment).
116: *
117: * @param other DOCUMENT ME!
118: *
119: * @return DOCUMENT ME!
120: */
121: public StructureElement convertOther(Object other) {
122: return null;
123: }
124: }
|