001: /*
002:
003: Licensed to the Apache Software Foundation (ASF) under one or more
004: contributor license agreements. See the NOTICE file distributed with
005: this work for additional information regarding copyright ownership.
006: The ASF licenses this file to You under the Apache License, Version 2.0
007: (the "License"); you may not use this file except in compliance with
008: the License. You may obtain a copy of the License at
009:
010: http://www.apache.org/licenses/LICENSE-2.0
011:
012: Unless required by applicable law or agreed to in writing, software
013: distributed under the License is distributed on an "AS IS" BASIS,
014: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: See the License for the specific language governing permissions and
016: limitations under the License.
017:
018: */
019: package org.apache.batik.dom.events;
020:
021: import java.util.ArrayList;
022: import java.util.List;
023:
024: import org.apache.batik.xml.XMLUtilities;
025:
026: import org.w3c.dom.events.UIEvent;
027: import org.w3c.dom.views.AbstractView;
028:
029: /**
030: * The UIEvent class provides specific contextual information
031: * associated with User Interface events.
032: *
033: * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
034: * @version $Id: DOMUIEvent.java 498740 2007-01-22 18:35:57Z dvholten $
035: */
036: public class DOMUIEvent extends AbstractEvent implements UIEvent {
037:
038: private AbstractView view;
039: private int detail;
040:
041: /**
042: * DOM: The <code>view</code> attribute identifies the
043: * <code>AbstractView</code> from which the event was generated.
044: */
045: public AbstractView getView() {
046: return view;
047: }
048:
049: /**
050: * DOM: Specifies some detail information about the
051: * <code>Event</code>, depending on the type of event.
052: */
053: public int getDetail() {
054: return detail;
055: }
056:
057: /**
058: * DOM: The <code>initUIEvent</code> method is used to initialize
059: * the value of a <code>UIEvent</code> created through the
060: * <code>DocumentEvent</code> interface. This method may only be
061: * called before the <code>UIEvent</code> has been dispatched via
062: * the <code>dispatchEvent</code> method, though it may be called
063: * multiple times during that phase if necessary. If called
064: * multiple times, the final invocation takes precedence.
065: *
066: * @param typeArg Specifies the event type.
067: * @param canBubbleArg Specifies whether or not the event can bubble.
068: * @param cancelableArg Specifies whether or not the event's default
069: * action can be prevented.
070: * @param viewArg Specifies the <code>Event</code>'s
071: * <code>AbstractView</code>.
072: * @param detailArg Specifies the <code>Event</code>'s detail.
073: */
074: public void initUIEvent(String typeArg, boolean canBubbleArg,
075: boolean cancelableArg, AbstractView viewArg, int detailArg) {
076: initEvent(typeArg, canBubbleArg, cancelableArg);
077: this .view = viewArg;
078: this .detail = detailArg;
079: }
080:
081: /**
082: * <b>DOM</b>: Initializes this event object.
083: */
084: public void initUIEventNS(String namespaceURIArg, String typeArg,
085: boolean canBubbleArg, boolean cancelableArg,
086: AbstractView viewArg, int detailArg) {
087: initEventNS(namespaceURIArg, typeArg, canBubbleArg,
088: cancelableArg);
089: this .view = viewArg;
090: this .detail = detailArg;
091: }
092:
093: /**
094: * Splits a whitespace separated string into tokens.
095: */
096: protected String[] split(String s) {
097: List a = new ArrayList(8);
098: StringBuffer sb;
099: int i = 0;
100: int len = s.length();
101: while (i < len) {
102: char c = s.charAt(i++);
103: if (XMLUtilities.isXMLSpace(c)) {
104: continue;
105: }
106: sb = new StringBuffer();
107: sb.append(c);
108: while (i < len) {
109: c = s.charAt(i++);
110: if (XMLUtilities.isXMLSpace(c)) {
111: a.add(sb.toString());
112: break;
113: }
114: sb.append(c);
115: }
116: if (i == len) {
117: a.add(sb.toString());
118: }
119: }
120: return (String[]) a.toArray(new String[a.size()]);
121: }
122: }
|