⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 openstrategy.java

📁 jfa2ce 源码帮助开发人员更好的理解运用
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************* * Copyright (c) 2000, 2006 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: *     IBM Corporation - initial API and implementation *******************************************************************************/package org.eclipse.jface.util;import org.eclipse.core.runtime.ListenerList;import org.eclipse.swt.SWT;import org.eclipse.swt.custom.TableTree;import org.eclipse.swt.custom.TableTreeItem;import org.eclipse.swt.events.SelectionEvent;import org.eclipse.swt.events.SelectionListener;import org.eclipse.swt.graphics.Point;import org.eclipse.swt.widgets.Control;import org.eclipse.swt.widgets.Display;import org.eclipse.swt.widgets.Event;import org.eclipse.swt.widgets.Listener;import org.eclipse.swt.widgets.Table;import org.eclipse.swt.widgets.TableItem;import org.eclipse.swt.widgets.Tree;import org.eclipse.swt.widgets.TreeItem;import org.eclipse.swt.widgets.Widget;/** * Implementation of single-click and double-click strategies. * <p> * Usage: * <pre> *	OpenStrategy handler = new OpenStrategy(control); *	handler.addOpenListener(new IOpenEventListener() { *		public void handleOpen(SelectionEvent e) { *			... // code to handle the open event. *		} *	}); * </pre> * </p> */public class OpenStrategy {    /**      * Default behavior. Double click to open the item.     */    public static final int DOUBLE_CLICK = 0;    /**      * Single click will open the item.     */    public static final int SINGLE_CLICK = 1;    /**      * Hover will select the item.     */    public static final int SELECT_ON_HOVER = 1 << 1;    /**     * Open item when using arrow keys     */    public static final int ARROW_KEYS_OPEN = 1 << 2;    /** A single click will generate     * an open event but key arrows will not do anything.     *      * @deprecated     */    public static final int NO_TIMER = SINGLE_CLICK;    /** A single click will generate an open     * event and key arrows will generate an open event after a     * small time.     *      * @deprecated     */    public static final int FILE_EXPLORER = SINGLE_CLICK | ARROW_KEYS_OPEN;    /** Pointing to an item will change the selection     * and a single click will gererate an open event     *      * @deprecated     */    public static final int ACTIVE_DESKTOP = SINGLE_CLICK | SELECT_ON_HOVER;    // Time used in FILE_EXPLORER and ACTIVE_DESKTOP    private static final int TIME = 500;    /* SINGLE_CLICK or DOUBLE_CLICK;     * In case of SINGLE_CLICK, the bits SELECT_ON_HOVER and ARROW_KEYS_OPEN     * my be set as well. */    private static int CURRENT_METHOD = DOUBLE_CLICK;    private Listener eventHandler;    private ListenerList openEventListeners = new ListenerList();    private ListenerList selectionEventListeners = new ListenerList();    private ListenerList postSelectionEventListeners = new ListenerList();    public OpenStrategy(Control control) {        initializeHandler(control.getDisplay());        addListener(control);    }    /**     * Adds an IOpenEventListener to the collection of openEventListeners     */    public void addOpenListener(IOpenEventListener listener) {        openEventListeners.add(listener);    }    /**     * Removes an IOpenEventListener to the collection of openEventListeners     */    public void removeOpenListener(IOpenEventListener listener) {        openEventListeners.remove(listener);    }    /**     * Adds an SelectionListener to the collection of selectionEventListeners     */    public void addSelectionListener(SelectionListener listener) {        selectionEventListeners.add(listener);    }    /**     * Removes an SelectionListener to the collection of selectionEventListeners     */    public void removeSelectionListener(SelectionListener listener) {        selectionEventListeners.remove(listener);    }    /**     * Adds an SelectionListener to the collection of selectionEventListeners     */    public void addPostSelectionListener(SelectionListener listener) {        postSelectionEventListeners.add(listener);    }    /**     * Removes an SelectionListener to the collection of selectionEventListeners     */    public void removePostSelectionListener(SelectionListener listener) {        postSelectionEventListeners.remove(listener);    }    /**     * Returns the current used single/double-click method     *      * This method is internal to the framework; it should not be implemented outside     * the framework.     */    public static int getOpenMethod() {        return CURRENT_METHOD;    }    /**     * Set the current used single/double-click method.     *      * This method is internal to the framework; it should not be implemented outside     * the framework.     */    public static void setOpenMethod(int method) {        if (method == DOUBLE_CLICK) {            CURRENT_METHOD = method;            return;        }        if ((method & SINGLE_CLICK) == 0) {			throw new IllegalArgumentException("Invalid open mode"); //$NON-NLS-1$		}        if ((method & (SINGLE_CLICK | SELECT_ON_HOVER | ARROW_KEYS_OPEN)) == 0) {			throw new IllegalArgumentException("Invalid open mode"); //$NON-NLS-1$		}        CURRENT_METHOD = method;    }    /**     * Return true if editors should be activated when opened.     */    public static boolean activateOnOpen() {        return getOpenMethod() == DOUBLE_CLICK;    }    /*     * Adds all needed listener to the control in order to implement     * single-click/double-click strategies.     */    private void addListener(Control c) {        c.addListener(SWT.MouseEnter, eventHandler);        c.addListener(SWT.MouseExit, eventHandler);        c.addListener(SWT.MouseMove, eventHandler);        c.addListener(SWT.MouseDown, eventHandler);        c.addListener(SWT.MouseUp, eventHandler);        c.addListener(SWT.KeyDown, eventHandler);        c.addListener(SWT.Selection, eventHandler);        c.addListener(SWT.DefaultSelection, eventHandler);        c.addListener(SWT.Collapse, eventHandler);        c.addListener(SWT.Expand, eventHandler);    }    /*     * Fire the selection event to all selectionEventListeners     */    private void fireSelectionEvent(SelectionEvent e) {        if (e.item != null && e.item.isDisposed()) {			return;		}        Object l[] = selectionEventListeners.getListeners();        for (int i = 0; i < l.length; i++) {            ((SelectionListener) l[i]).widgetSelected(e);        }    }    /*     * Fire the default selection event to all selectionEventListeners     */    private void fireDefaultSelectionEvent(SelectionEvent e) {        Object l[] = selectionEventListeners.getListeners();        for (int i = 0; i < l.length; i++) {            ((SelectionListener) l[i]).widgetDefaultSelected(e);        }    }    /*     * Fire the post selection event to all postSelectionEventListeners     */    private void firePostSelectionEvent(SelectionEvent e) {        if (e.item != null && e.item.isDisposed()) {			return;		}        Object l[] = postSelectionEventListeners.getListeners();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -