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

📄 dragsource.java

📁 JAVA基本类源代码,大家可以学习学习!
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    /**     * Adds the specified <code>DragSourceMotionListener</code> to this     * <code>DragSource</code> to receive drag motion events during drag     * operations intiated with this <code>DragSource</code>.     * If a <code>null</code> listener is specified, no action is taken and no     * exception is thrown.     *     * @param dsml the <code>DragSourceMotionListener</code> to add     *     * @see      #removeDragSourceMotionListener     * @see      #getDragSourceMotionListeners     * @since 1.4     */    public void addDragSourceMotionListener(DragSourceMotionListener dsml) {	if (dsml != null) {            synchronized (this) {                motionListener = DnDEventMulticaster.add(motionListener, dsml);            }        }    }    /**     * Removes the specified <code>DragSourceMotionListener</code> from this     * <code>DragSource</code>.      * If a <code>null</code> listener is specified, no action is taken and no     * exception is thrown.     * If the listener specified by the argument was not previously added to     * this <code>DragSource</code>, no action is taken and no exception     * is thrown.     *      * @param dsml the <code>DragSourceMotionListener</code> to remove     *     * @see      #addDragSourceMotionListener     * @see      #getDragSourceMotionListeners     * @since 1.4     */    public void removeDragSourceMotionListener(DragSourceMotionListener dsml) {        if (dsml != null) {            synchronized (this) {                motionListener = DnDEventMulticaster.remove(motionListener, dsml);            }        }    }    /**     * Gets all of the  <code>DragSourceMotionListener</code>s     * registered with this <code>DragSource</code>.     *     * @return all of this <code>DragSource</code>'s     *         <code>DragSourceMotionListener</code>s or an empty array if no     *         such listeners are currently registered     *     * @see      #addDragSourceMotionListener     * @see      #removeDragSourceMotionListener     * @since    1.4     */    public DragSourceMotionListener[] getDragSourceMotionListeners() {        return (DragSourceMotionListener[])            getListeners(DragSourceMotionListener.class);     }    /**     * Gets all the objects currently registered as     * <code><em>Foo</em>Listener</code>s upon this <code>DragSource</code>.     * <code><em>Foo</em>Listener</code>s are registered using the     * <code>add<em>Foo</em>Listener</code> method.     *     * @param listenerType the type of listeners requested; this parameter     *          should specify an interface that descends from     *          <code>java.util.EventListener</code>     * @return an array of all objects registered as     *          <code><em>Foo</em>Listener</code>s on this     *          <code>DragSource</code>, or an empty array if no such listeners     *          have been added      * @exception <code>ClassCastException</code> if <code>listenerType</code>     *          doesn't specify a class or interface that implements     *          <code>java.util.EventListener</code>     *     * @see #getDragSourceListeners     * @see #getDragSourceMotionListeners     * @since 1.4     */    public EventListener[] getListeners(Class listenerType) {         EventListener l = null;         if (listenerType == DragSourceListener.class) {             l = listener;        } else if (listenerType == DragSourceMotionListener.class) {            l = motionListener;        }        return DnDEventMulticaster.getListeners(l, listenerType);    }    /**     * This method calls <code>dragEnter</code> on the     * <code>DragSourceListener</code>s registered with this     * <code>DragSource</code>, and passes them the specified     * <code>DragSourceDragEvent</code>.     *     * @param dsde the <code>DragSourceDragEvent</code>     */    void processDragEnter(DragSourceDragEvent dsde) {        DragSourceListener dsl = listener;        if (dsl != null) {            dsl.dragEnter(dsde);        }    }    /**     * This method calls <code>dragOver</code> on the     * <code>DragSourceListener</code>s registered with this     * <code>DragSource</code>, and passes them the specified     * <code>DragSourceDragEvent</code>.     *     * @param dsde the <code>DragSourceDragEvent</code>     */    void processDragOver(DragSourceDragEvent dsde) {        DragSourceListener dsl = listener;        if (dsl != null) {            dsl.dragOver(dsde);        }    }    /**     * This method calls <code>dropActionChanged</code> on the     * <code>DragSourceListener</code>s registered with this     * <code>DragSource</code>, and passes them the specified     * <code>DragSourceDragEvent</code>.     *     * @param dsde the <code>DragSourceDragEvent</code>     */    void processDropActionChanged(DragSourceDragEvent dsde) {        DragSourceListener dsl = listener;        if (dsl != null) {            dsl.dropActionChanged(dsde);        }    }    /**     * This method calls <code>dragExit</code> on the     * <code>DragSourceListener</code>s registered with this     * <code>DragSource</code>, and passes them the specified     * <code>DragSourceEvent</code>.     *     * @param dse the <code>DragSourceEvent</code>     */    void processDragExit(DragSourceEvent dse) {        DragSourceListener dsl = listener;        if (dsl != null) {            dsl.dragExit(dse);        }    }    /**     * This method calls <code>dragDropEnd</code> on the     * <code>DragSourceListener</code>s registered with this     * <code>DragSource</code>, and passes them the specified     * <code>DragSourceDropEvent</code>.     *     * @param dsde the <code>DragSourceEvent</code>     */    void processDragDropEnd(DragSourceDropEvent dsde) {        DragSourceListener dsl = listener;        if (dsl != null) {            dsl.dragDropEnd(dsde);        }    }    /**     * This method calls <code>dragMouseMoved</code> on the     * <code>DragSourceMotionListener</code>s registered with this     * <code>DragSource</code>, and passes them the specified     * <code>DragSourceDragEvent</code>.     *     * @param dsde the <code>DragSourceEvent</code>     */    void processDragMouseMoved(DragSourceDragEvent dsde) {        DragSourceMotionListener dsml = motionListener;        if (dsml != null) {            dsml.dragMouseMoved(dsde);        }    }    /**     * Serializes this <code>DragSource</code>. This method first performs     * default serialization. Next, it writes out this object's     * <code>FlavorMap</code> if and only if it can be serialized. If not,     * <code>null</code> is written instead. Next, it writes out     * <code>Serializable</code> listeners registered with this     * object. Listeners are written in a <code>null</code>-terminated sequence     * of 0 or more pairs. The pair consists of a <code>String</code> and an     * <code>Object</code>; the <code>String</code> indicates the type of the     * <code>Object</code> and is one of the following:     * <ul>     * <li><code>dragSourceListenerK</code> indicating a     *     <code>DragSourceListener</code> object;     * <li><code>dragSourceMotionListenerK</code> indicating a     *     <code>DragSourceMotionListener</code> object.     * </ul>     *     * @serialData Either a <code>FlavorMap</code> instance, or     *      <code>null</code>, followed by a <code>null</code>-terminated     *      sequence of 0 or more pairs; the pair consists of a     *      <code>String</code> and an <code>Object</code>; the     *      <code>String</code> indicates the type of the <code>Object</code>     *      and is one of the following:     *      <ul>     *      <li><code>dragSourceListenerK</code> indicating a     *          <code>DragSourceListener</code> object;     *      <li><code>dragSourceMotionListenerK</code> indicating a     *          <code>DragSourceMotionListener</code> object.     *      </ul>.     * @since 1.4     */    private void writeObject(ObjectOutputStream s) throws IOException {        s.defaultWriteObject();        s.writeObject(SerializationTester.test(flavorMap) ? flavorMap : null);        DnDEventMulticaster.save(s, dragSourceListenerK, listener);        DnDEventMulticaster.save(s, dragSourceMotionListenerK, motionListener);        s.writeObject(null);    }    /**     * Deserializes this <code>DragSource</code>. This method first performs     * default deserialization. Next, this object's <code>FlavorMap</code> is      * deserialized by using the next object in the stream.     * If the resulting <code>FlavorMap</code> is <code>null</code>, this     * object's <code>FlavorMap</code> is set to the default FlavorMap for     * this thread's <code>ClassLoader</code>.     * Next, this object's listeners are deserialized by reading a     * <code>null</code>-terminated sequence of 0 or more key/value pairs     * from the stream:      * <ul>     * <li>If a key object is a <code>String</code> equal to     * <code>dragSourceListenerK</code>, a <code>DragSourceListener</code> is      * deserialized using the corresponding value object and added to this     * <code>DragSource</code>.      * <li>If a key object is a <code>String</code> equal to     * <code>dragSourceMotionListenerK</code>, a     * <code>DragSourceMotionListener</code> is deserialized using the     * corresponding value object and added to this <code>DragSource</code>.     * <li>Otherwise, the key/value pair is skipped.     * </ul>     *     * @see java.awt.datatransfer.SystemFlavorMap#getDefaultFlavorMap     * @since 1.4     */    private void readObject(ObjectInputStream s)       throws ClassNotFoundException, IOException {        s.defaultReadObject();        // 'flavorMap' was written explicitly        flavorMap = (FlavorMap)s.readObject();        // Implementation assumes 'flavorMap' is never null.        if (flavorMap == null) {            flavorMap = SystemFlavorMap.getDefaultFlavorMap();        }        Object keyOrNull;        while (null != (keyOrNull = s.readObject())) {            String key = ((String)keyOrNull).intern();            if (dragSourceListenerK == key) {                addDragSourceListener((DragSourceListener)(s.readObject()));            } else if (dragSourceMotionListenerK == key) {                addDragSourceMotionListener(                    (DragSourceMotionListener)(s.readObject()));            } else {                 // skip value for unrecognized key                s.readObject();            }        }    }    /*     * fields     */    private transient FlavorMap flavorMap = SystemFlavorMap.getDefaultFlavorMap();    private transient DragSourceListener listener;    private transient DragSourceMotionListener motionListener;}

⌨️ 快捷键说明

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