Package org.onemind.swingweb.mapinput.peerdelegate.javax.swing

Source Code of org.onemind.swingweb.mapinput.peerdelegate.javax.swing.AbstractButtonInputDelegate$ButtonClick

/*
* Copyright (C) 2004 TiongHiang Lee
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not,  write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*
* Email: thlee@onemindsoft.org
*/

package org.onemind.swingweb.mapinput.peerdelegate.javax.swing;

import java.awt.AWTEvent;
import java.awt.ActiveEvent;
import java.util.Map;
import javax.swing.AbstractButton;
import javax.swing.JTable;
import org.onemind.awtbridge.event.BridgeEventQueue;
import org.onemind.awtbridge.input.BridgeInputContext;
import org.onemind.awtbridge.input.InputException;
import org.onemind.awtbridge.peer.BridgeComponentPeer;
import org.onemind.awtbridge.peer.BridgePeer;
import org.onemind.swingweb.mapinput.peerdelegate.MapInputDelegate;
/**
* The abstract button input delegate
* @author TiongHiang Lee (thlee@onemindsoft.org)
*
*/
public class AbstractButtonInputDelegate extends JComponentInputDelegate
{

    /** event for simulating event click **/
    protected static class ButtonClick extends AWTEvent implements ActiveEvent
    {

        public ButtonClick(Object source)
        {
            super(source, -1);
        }

        public void dispatch()
        {
            ((AbstractButton) getSource()).doClick(0);
        }
    }

    /** the instance **/
    public static MapInputDelegate INSTANCE = new AbstractButtonInputDelegate();

    /**
     * {@inheritDoc}
     */
    public void processInput(BridgeComponentPeer peer, BridgeInputContext context, Map inputForm) throws InputException
    {
        //the checking
        if (hasEvent(peer, inputForm))
        {
            AbstractButton btn = (AbstractButton) peer.getComponentObject();
            createEvent(context, peer, btn);
        }
    }

    /**
     * Create event for the button
     * @param context the context
     * @param peer the peer
     * @param btn the button
     */
    protected void createEvent(BridgeInputContext context, BridgePeer peer, AbstractButton btn)
    {
        //TODO: a hack to ensure that the table editing is working correctly
        if (((AbstractButton) peer.getComponentObject()).getParent() instanceof JTable)
        {
            ((AbstractButton) peer.getComponentObject()).doClick(0);
        } else
        {
            postEvent(context, new ButtonClick(peer.getComponentObject()), BridgeEventQueue.LOW_PRIORITY);
        }
    }

    /**
     * {@inheritDoc}
     */
    public boolean hasEvent(BridgePeer peer, Map form)
    {
        Object obj = form.get(peer.getId());
        return (obj != null && ("1".equals(obj) || "true".equals(obj)));
    }
}
TOP

Related Classes of org.onemind.swingweb.mapinput.peerdelegate.javax.swing.AbstractButtonInputDelegate$ButtonClick

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.