All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.batik.dom.events.DOMUIEvent Maven / Gradle / Ivy

The newest version!
/*

   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for additional information regarding copyright ownership.
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

 */
package org.apache.batik.dom.events;

import java.util.ArrayList;
import java.util.List;

import org.apache.batik.xml.XMLUtilities;

import org.w3c.dom.events.UIEvent;
import org.w3c.dom.views.AbstractView;

/**
 * The UIEvent class provides specific contextual information
 * associated with User Interface events.
 *
 * @author Stephane Hillion
 * @version $Id$
 */
public class DOMUIEvent extends AbstractEvent implements UIEvent {

    private AbstractView view;
    private int detail;

    /**
     * DOM: The view attribute identifies the
     * AbstractView from which the event was generated.
     */
    public AbstractView getView() {
        return view;
    }

    /**
     * DOM: Specifies some detail information about the
     * Event, depending on the type of event.
     */
    public int getDetail() {
        return detail;
    }

    /**
     * DOM: The initUIEvent method is used to initialize
     * the value of a UIEvent created through the
     * DocumentEvent interface.  This method may only be
     * called before the UIEvent has been dispatched via
     * the dispatchEvent method, though it may be called
     * multiple times during that phase if necessary.  If called
     * multiple times, the final invocation takes precedence.
     *
     * @param typeArg Specifies the event type.
     * @param canBubbleArg Specifies whether or not the event can bubble.
     * @param cancelableArg Specifies whether or not the event's default
     *   action can be prevented.
     * @param viewArg Specifies the Event's
     *   AbstractView.
     * @param detailArg Specifies the Event's detail.
     */
    public void initUIEvent(String typeArg,
                            boolean canBubbleArg,
                            boolean cancelableArg,
                            AbstractView viewArg,
                            int detailArg) {
        initEvent(typeArg, canBubbleArg, cancelableArg);
        this.view = viewArg;
        this.detail = detailArg;
    }

    /**
     * DOM: Initializes this event object.
     */
    public void initUIEventNS(String namespaceURIArg,
                              String typeArg,
                              boolean canBubbleArg,
                              boolean cancelableArg,
                              AbstractView viewArg,
                              int detailArg) {
        initEventNS(namespaceURIArg, typeArg, canBubbleArg, cancelableArg);
        this.view = viewArg;
        this.detail = detailArg;
    }

    /**
     * Splits a whitespace separated string into tokens.
     */
    protected String[] split(String s) {
        List a = new ArrayList(8);
        StringBuffer sb;
        int i = 0;
        int len = s.length();
        while (i < len) {
            char c = s.charAt(i++);
            if (XMLUtilities.isXMLSpace(c)) {
                continue;
            }
            sb = new StringBuffer();
            sb.append(c);
            while (i < len) {
                c = s.charAt(i++);
                if (XMLUtilities.isXMLSpace(c)) {
                    a.add(sb.toString());
                    break;
                }
                sb.append(c);
            }
            if (i == len) {
                a.add(sb.toString());
            }
        }
        return (String[]) a.toArray(new String[a.size()]);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy