Java Code Examples for java.awt.Component#setDropTarget()

The following examples show how to use java.awt.Component#setDropTarget() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileOpenDropHandler.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void deinitializeComponents(Component comp) {
	if (comp instanceof CellRendererPane) {
		return;
	}

	if (comp instanceof Container) {
		Container c = (Container) comp;
		c.removeContainerListener(this);
		Component comps[] = c.getComponents();
		for (Component element : comps) {
			deinitializeComponents(element);
		}
	}
	DropTarget dt = comp.getDropTarget();
	if (dt instanceof CascadedDropTarget) {
		CascadedDropTarget target = (CascadedDropTarget) dt;
		DropTarget newTarget = target.removeDropTarget(globalDropTarget);
		comp.setDropTarget(newTarget);
	}
}
 
Example 2
Source File: DropTarget.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Note: this interface is required to permit the safe association
 * of a DropTarget with a Component in one of two ways, either:
 * {@code component.setDropTarget(droptarget);}
 * or {@code droptarget.setComponent(component);}
 * <P>
 * The Component will receive drops only if it is enabled.
 * @param c The new {@code Component} this {@code DropTarget}
 * is to be associated with.
 */

public synchronized void setComponent(Component c) {
    if (component == c || component != null && component.equals(c))
        return;

    final Component old = component;

    if (old  != null) {
        clearAutoscroll();

        component = null;
        removeNotify();
        old.setDropTarget(null);

    }

    if ((component = c) != null) try {
        c.setDropTarget(this);
    } catch (Exception e) { // undo the change
        if (old != null) {
            old.setDropTarget(this);
            addNotify();
        }
    }
}
 
Example 3
Source File: DropTarget.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Note: this interface is required to permit the safe association
 * of a DropTarget with a Component in one of two ways, either:
 * <code> component.setDropTarget(droptarget); </code>
 * or <code> droptarget.setComponent(component); </code>
 * <P>
 * The Component will receive drops only if it is enabled.
 * @param c The new <code>Component</code> this <code>DropTarget</code>
 * is to be associated with.
 */

public synchronized void setComponent(Component c) {
    if (component == c || component != null && component.equals(c))
        return;

    Component     old;
    ComponentPeer oldPeer = null;

    if ((old = component) != null) {
        clearAutoscroll();

        component = null;

        if (componentPeer != null) {
            oldPeer = componentPeer;
            removeNotify(componentPeer);
        }

        old.setDropTarget(null);

    }

    if ((component = c) != null) try {
        c.setDropTarget(this);
    } catch (Exception e) { // undo the change
        if (old != null) {
            old.setDropTarget(this);
            addNotify(oldPeer);
        }
    }
}
 
Example 4
Source File: DropTarget.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new DropTarget given the <code>Component</code>
 * to associate itself with, an <code>int</code> representing
 * the default acceptable action(s) to
 * support, a <code>DropTargetListener</code>
 * to handle event processing, a <code>boolean</code> indicating
 * if the <code>DropTarget</code> is currently accepting drops, and
 * a <code>FlavorMap</code> to use (or null for the default <CODE>FlavorMap</CODE>).
 * <P>
 * The Component will receive drops only if it is enabled.
 * @param c         The <code>Component</code> with which this <code>DropTarget</code> is associated
 * @param ops       The default acceptable actions for this <code>DropTarget</code>
 * @param dtl       The <code>DropTargetListener</code> for this <code>DropTarget</code>
 * @param act       Is the <code>DropTarget</code> accepting drops.
 * @param fm        The <code>FlavorMap</code> to use, or null for the default <CODE>FlavorMap</CODE>
 * @exception HeadlessException if GraphicsEnvironment.isHeadless()
 *            returns true
 * @see java.awt.GraphicsEnvironment#isHeadless
 */
public DropTarget(Component c, int ops, DropTargetListener dtl,
                  boolean act, FlavorMap fm)
    throws HeadlessException
{
    if (GraphicsEnvironment.isHeadless()) {
        throw new HeadlessException();
    }

    component = c;

    setDefaultActions(ops);

    if (dtl != null) try {
        addDropTargetListener(dtl);
    } catch (TooManyListenersException tmle) {
        // do nothing!
    }

    if (c != null) {
        c.setDropTarget(this);
        setActive(act);
    }

    if (fm != null) {
        flavorMap = fm;
    } else {
        flavorMap = SystemFlavorMap.getDefaultFlavorMap();
    }
}
 
Example 5
Source File: DropTarget.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Note: this interface is required to permit the safe association
 * of a DropTarget with a Component in one of two ways, either:
 * <code> component.setDropTarget(droptarget); </code>
 * or <code> droptarget.setComponent(component); </code>
 * <P>
 * The Component will receive drops only if it is enabled.
 * @param c The new <code>Component</code> this <code>DropTarget</code>
 * is to be associated with.
 */

public synchronized void setComponent(Component c) {
    if (component == c || component != null && component.equals(c))
        return;

    Component     old;
    ComponentPeer oldPeer = null;

    if ((old = component) != null) {
        clearAutoscroll();

        component = null;

        if (componentPeer != null) {
            oldPeer = componentPeer;
            removeNotify(componentPeer);
        }

        old.setDropTarget(null);

    }

    if ((component = c) != null) try {
        c.setDropTarget(this);
    } catch (Exception e) { // undo the change
        if (old != null) {
            old.setDropTarget(this);
            addNotify(oldPeer);
        }
    }
}
 
Example 6
Source File: DropTarget.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Note: this interface is required to permit the safe association
 * of a DropTarget with a Component in one of two ways, either:
 * <code> component.setDropTarget(droptarget); </code>
 * or <code> droptarget.setComponent(component); </code>
 * <P>
 * The Component will receive drops only if it is enabled.
 * @param c The new <code>Component</code> this <code>DropTarget</code>
 * is to be associated with.
 */

public synchronized void setComponent(Component c) {
    if (component == c || component != null && component.equals(c))
        return;

    Component     old;
    ComponentPeer oldPeer = null;

    if ((old = component) != null) {
        clearAutoscroll();

        component = null;

        if (componentPeer != null) {
            oldPeer = componentPeer;
            removeNotify(componentPeer);
        }

        old.setDropTarget(null);

    }

    if ((component = c) != null) try {
        c.setDropTarget(this);
    } catch (Exception e) { // undo the change
        if (old != null) {
            old.setDropTarget(this);
            addNotify(oldPeer);
        }
    }
}
 
Example 7
Source File: DropTarget.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new DropTarget given the <code>Component</code>
 * to associate itself with, an <code>int</code> representing
 * the default acceptable action(s) to
 * support, a <code>DropTargetListener</code>
 * to handle event processing, a <code>boolean</code> indicating
 * if the <code>DropTarget</code> is currently accepting drops, and
 * a <code>FlavorMap</code> to use (or null for the default <CODE>FlavorMap</CODE>).
 * <P>
 * The Component will receive drops only if it is enabled.
 * @param c         The <code>Component</code> with which this <code>DropTarget</code> is associated
 * @param ops       The default acceptable actions for this <code>DropTarget</code>
 * @param dtl       The <code>DropTargetListener</code> for this <code>DropTarget</code>
 * @param act       Is the <code>DropTarget</code> accepting drops.
 * @param fm        The <code>FlavorMap</code> to use, or null for the default <CODE>FlavorMap</CODE>
 * @exception HeadlessException if GraphicsEnvironment.isHeadless()
 *            returns true
 * @see java.awt.GraphicsEnvironment#isHeadless
 */
public DropTarget(Component c, int ops, DropTargetListener dtl,
                  boolean act, FlavorMap fm)
    throws HeadlessException
{
    if (GraphicsEnvironment.isHeadless()) {
        throw new HeadlessException();
    }

    component = c;

    setDefaultActions(ops);

    if (dtl != null) try {
        addDropTargetListener(dtl);
    } catch (TooManyListenersException tmle) {
        // do nothing!
    }

    if (c != null) {
        c.setDropTarget(this);
        setActive(act);
    }

    if (fm != null) {
        flavorMap = fm;
    } else {
        flavorMap = SystemFlavorMap.getDefaultFlavorMap();
    }
}
 
Example 8
Source File: DropTarget.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Note: this interface is required to permit the safe association
 * of a DropTarget with a Component in one of two ways, either:
 * <code> component.setDropTarget(droptarget); </code>
 * or <code> droptarget.setComponent(component); </code>
 * <P>
 * The Component will receive drops only if it is enabled.
 * @param c The new <code>Component</code> this <code>DropTarget</code>
 * is to be associated with.
 */

public synchronized void setComponent(Component c) {
    if (component == c || component != null && component.equals(c))
        return;

    Component     old;
    ComponentPeer oldPeer = null;

    if ((old = component) != null) {
        clearAutoscroll();

        component = null;

        if (componentPeer != null) {
            oldPeer = componentPeer;
            removeNotify(componentPeer);
        }

        old.setDropTarget(null);

    }

    if ((component = c) != null) try {
        c.setDropTarget(this);
    } catch (Exception e) { // undo the change
        if (old != null) {
            old.setDropTarget(this);
            addNotify(oldPeer);
        }
    }
}
 
Example 9
Source File: DropTarget.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new DropTarget given the <code>Component</code>
 * to associate itself with, an <code>int</code> representing
 * the default acceptable action(s) to
 * support, a <code>DropTargetListener</code>
 * to handle event processing, a <code>boolean</code> indicating
 * if the <code>DropTarget</code> is currently accepting drops, and
 * a <code>FlavorMap</code> to use (or null for the default <CODE>FlavorMap</CODE>).
 * <P>
 * The Component will receive drops only if it is enabled.
 * @param c         The <code>Component</code> with which this <code>DropTarget</code> is associated
 * @param ops       The default acceptable actions for this <code>DropTarget</code>
 * @param dtl       The <code>DropTargetListener</code> for this <code>DropTarget</code>
 * @param act       Is the <code>DropTarget</code> accepting drops.
 * @param fm        The <code>FlavorMap</code> to use, or null for the default <CODE>FlavorMap</CODE>
 * @exception HeadlessException if GraphicsEnvironment.isHeadless()
 *            returns true
 * @see java.awt.GraphicsEnvironment#isHeadless
 */
public DropTarget(Component c, int ops, DropTargetListener dtl,
                  boolean act, FlavorMap fm)
    throws HeadlessException
{
    if (GraphicsEnvironment.isHeadless()) {
        throw new HeadlessException();
    }

    component = c;

    setDefaultActions(ops);

    if (dtl != null) try {
        addDropTargetListener(dtl);
    } catch (TooManyListenersException tmle) {
        // do nothing!
    }

    if (c != null) {
        c.setDropTarget(this);
        setActive(act);
    }

    if (fm != null) {
        flavorMap = fm;
    } else {
        flavorMap = SystemFlavorMap.getDefaultFlavorMap();
    }
}
 
Example 10
Source File: DropTarget.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new DropTarget given the <code>Component</code>
 * to associate itself with, an <code>int</code> representing
 * the default acceptable action(s) to
 * support, a <code>DropTargetListener</code>
 * to handle event processing, a <code>boolean</code> indicating
 * if the <code>DropTarget</code> is currently accepting drops, and
 * a <code>FlavorMap</code> to use (or null for the default <CODE>FlavorMap</CODE>).
 * <P>
 * The Component will receive drops only if it is enabled.
 * @param c         The <code>Component</code> with which this <code>DropTarget</code> is associated
 * @param ops       The default acceptable actions for this <code>DropTarget</code>
 * @param dtl       The <code>DropTargetListener</code> for this <code>DropTarget</code>
 * @param act       Is the <code>DropTarget</code> accepting drops.
 * @param fm        The <code>FlavorMap</code> to use, or null for the default <CODE>FlavorMap</CODE>
 * @exception HeadlessException if GraphicsEnvironment.isHeadless()
 *            returns true
 * @see java.awt.GraphicsEnvironment#isHeadless
 */
public DropTarget(Component c, int ops, DropTargetListener dtl,
                  boolean act, FlavorMap fm)
    throws HeadlessException
{
    if (GraphicsEnvironment.isHeadless()) {
        throw new HeadlessException();
    }

    component = c;

    setDefaultActions(ops);

    if (dtl != null) try {
        addDropTargetListener(dtl);
    } catch (TooManyListenersException tmle) {
        // do nothing!
    }

    if (c != null) {
        c.setDropTarget(this);
        setActive(act);
    }

    if (fm != null) {
        flavorMap = fm;
    } else {
        flavorMap = SystemFlavorMap.getDefaultFlavorMap();
    }
}
 
Example 11
Source File: DropTarget.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new DropTarget given the <code>Component</code>
 * to associate itself with, an <code>int</code> representing
 * the default acceptable action(s) to
 * support, a <code>DropTargetListener</code>
 * to handle event processing, a <code>boolean</code> indicating
 * if the <code>DropTarget</code> is currently accepting drops, and
 * a <code>FlavorMap</code> to use (or null for the default <CODE>FlavorMap</CODE>).
 * <P>
 * The Component will receive drops only if it is enabled.
 * @param c         The <code>Component</code> with which this <code>DropTarget</code> is associated
 * @param ops       The default acceptable actions for this <code>DropTarget</code>
 * @param dtl       The <code>DropTargetListener</code> for this <code>DropTarget</code>
 * @param act       Is the <code>DropTarget</code> accepting drops.
 * @param fm        The <code>FlavorMap</code> to use, or null for the default <CODE>FlavorMap</CODE>
 * @exception HeadlessException if GraphicsEnvironment.isHeadless()
 *            returns true
 * @see java.awt.GraphicsEnvironment#isHeadless
 */
public DropTarget(Component c, int ops, DropTargetListener dtl,
                  boolean act, FlavorMap fm)
    throws HeadlessException
{
    if (GraphicsEnvironment.isHeadless()) {
        throw new HeadlessException();
    }

    component = c;

    setDefaultActions(ops);

    if (dtl != null) try {
        addDropTargetListener(dtl);
    } catch (TooManyListenersException tmle) {
        // do nothing!
    }

    if (c != null) {
        c.setDropTarget(this);
        setActive(act);
    }

    if (fm != null) {
        flavorMap = fm;
    } else {
        flavorMap = SystemFlavorMap.getDefaultFlavorMap();
    }
}
 
Example 12
Source File: DropTarget.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new DropTarget given the <code>Component</code>
 * to associate itself with, an <code>int</code> representing
 * the default acceptable action(s) to
 * support, a <code>DropTargetListener</code>
 * to handle event processing, a <code>boolean</code> indicating
 * if the <code>DropTarget</code> is currently accepting drops, and
 * a <code>FlavorMap</code> to use (or null for the default <CODE>FlavorMap</CODE>).
 * <P>
 * The Component will receive drops only if it is enabled.
 * @param c         The <code>Component</code> with which this <code>DropTarget</code> is associated
 * @param ops       The default acceptable actions for this <code>DropTarget</code>
 * @param dtl       The <code>DropTargetListener</code> for this <code>DropTarget</code>
 * @param act       Is the <code>DropTarget</code> accepting drops.
 * @param fm        The <code>FlavorMap</code> to use, or null for the default <CODE>FlavorMap</CODE>
 * @exception HeadlessException if GraphicsEnvironment.isHeadless()
 *            returns true
 * @see java.awt.GraphicsEnvironment#isHeadless
 */
public DropTarget(Component c, int ops, DropTargetListener dtl,
                  boolean act, FlavorMap fm)
    throws HeadlessException
{
    if (GraphicsEnvironment.isHeadless()) {
        throw new HeadlessException();
    }

    component = c;

    setDefaultActions(ops);

    if (dtl != null) try {
        addDropTargetListener(dtl);
    } catch (TooManyListenersException tmle) {
        // do nothing!
    }

    if (c != null) {
        c.setDropTarget(this);
        setActive(act);
    }

    if (fm != null) {
        flavorMap = fm;
    } else {
        flavorMap = SystemFlavorMap.getDefaultFlavorMap();
    }
}
 
Example 13
Source File: DropTarget.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new DropTarget given the <code>Component</code>
 * to associate itself with, an <code>int</code> representing
 * the default acceptable action(s) to
 * support, a <code>DropTargetListener</code>
 * to handle event processing, a <code>boolean</code> indicating
 * if the <code>DropTarget</code> is currently accepting drops, and
 * a <code>FlavorMap</code> to use (or null for the default <CODE>FlavorMap</CODE>).
 * <P>
 * The Component will receive drops only if it is enabled.
 * @param c         The <code>Component</code> with which this <code>DropTarget</code> is associated
 * @param ops       The default acceptable actions for this <code>DropTarget</code>
 * @param dtl       The <code>DropTargetListener</code> for this <code>DropTarget</code>
 * @param act       Is the <code>DropTarget</code> accepting drops.
 * @param fm        The <code>FlavorMap</code> to use, or null for the default <CODE>FlavorMap</CODE>
 * @exception HeadlessException if GraphicsEnvironment.isHeadless()
 *            returns true
 * @see java.awt.GraphicsEnvironment#isHeadless
 */
public DropTarget(Component c, int ops, DropTargetListener dtl,
                  boolean act, FlavorMap fm)
    throws HeadlessException
{
    if (GraphicsEnvironment.isHeadless()) {
        throw new HeadlessException();
    }

    component = c;

    setDefaultActions(ops);

    if (dtl != null) try {
        addDropTargetListener(dtl);
    } catch (TooManyListenersException tmle) {
        // do nothing!
    }

    if (c != null) {
        c.setDropTarget(this);
        setActive(act);
    }

    if (fm != null) {
        flavorMap = fm;
    } else {
        flavorMap = SystemFlavorMap.getDefaultFlavorMap();
    }
}
 
Example 14
Source File: DropTarget.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new DropTarget given the <code>Component</code>
 * to associate itself with, an <code>int</code> representing
 * the default acceptable action(s) to
 * support, a <code>DropTargetListener</code>
 * to handle event processing, a <code>boolean</code> indicating
 * if the <code>DropTarget</code> is currently accepting drops, and
 * a <code>FlavorMap</code> to use (or null for the default <CODE>FlavorMap</CODE>).
 * <P>
 * The Component will receive drops only if it is enabled.
 * @param c         The <code>Component</code> with which this <code>DropTarget</code> is associated
 * @param ops       The default acceptable actions for this <code>DropTarget</code>
 * @param dtl       The <code>DropTargetListener</code> for this <code>DropTarget</code>
 * @param act       Is the <code>DropTarget</code> accepting drops.
 * @param fm        The <code>FlavorMap</code> to use, or null for the default <CODE>FlavorMap</CODE>
 * @exception HeadlessException if GraphicsEnvironment.isHeadless()
 *            returns true
 * @see java.awt.GraphicsEnvironment#isHeadless
 */
public DropTarget(Component c, int ops, DropTargetListener dtl,
                  boolean act, FlavorMap fm)
    throws HeadlessException
{
    if (GraphicsEnvironment.isHeadless()) {
        throw new HeadlessException();
    }

    component = c;

    setDefaultActions(ops);

    if (dtl != null) try {
        addDropTargetListener(dtl);
    } catch (TooManyListenersException tmle) {
        // do nothing!
    }

    if (c != null) {
        c.setDropTarget(this);
        setActive(act);
    }

    if (fm != null) {
        flavorMap = fm;
    } else {
        flavorMap = SystemFlavorMap.getDefaultFlavorMap();
    }
}
 
Example 15
Source File: DropTarget.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new DropTarget given the <code>Component</code>
 * to associate itself with, an <code>int</code> representing
 * the default acceptable action(s) to
 * support, a <code>DropTargetListener</code>
 * to handle event processing, a <code>boolean</code> indicating
 * if the <code>DropTarget</code> is currently accepting drops, and
 * a <code>FlavorMap</code> to use (or null for the default <CODE>FlavorMap</CODE>).
 * <P>
 * The Component will receive drops only if it is enabled.
 * @param c         The <code>Component</code> with which this <code>DropTarget</code> is associated
 * @param ops       The default acceptable actions for this <code>DropTarget</code>
 * @param dtl       The <code>DropTargetListener</code> for this <code>DropTarget</code>
 * @param act       Is the <code>DropTarget</code> accepting drops.
 * @param fm        The <code>FlavorMap</code> to use, or null for the default <CODE>FlavorMap</CODE>
 * @exception HeadlessException if GraphicsEnvironment.isHeadless()
 *            returns true
 * @see java.awt.GraphicsEnvironment#isHeadless
 */
public DropTarget(Component c, int ops, DropTargetListener dtl,
                  boolean act, FlavorMap fm)
    throws HeadlessException
{
    if (GraphicsEnvironment.isHeadless()) {
        throw new HeadlessException();
    }

    component = c;

    setDefaultActions(ops);

    if (dtl != null) try {
        addDropTargetListener(dtl);
    } catch (TooManyListenersException tmle) {
        // do nothing!
    }

    if (c != null) {
        c.setDropTarget(this);
        setActive(act);
    }

    if (fm != null) {
        flavorMap = fm;
    } else {
        flavorMap = SystemFlavorMap.getDefaultFlavorMap();
    }
}
 
Example 16
Source File: DropTarget.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Note: this interface is required to permit the safe association
 * of a DropTarget with a Component in one of two ways, either:
 * <code> component.setDropTarget(droptarget); </code>
 * or <code> droptarget.setComponent(component); </code>
 * <P>
 * The Component will receive drops only if it is enabled.
 * @param c The new <code>Component</code> this <code>DropTarget</code>
 * is to be associated with.
 */

public synchronized void setComponent(Component c) {
    if (component == c || component != null && component.equals(c))
        return;

    Component     old;
    ComponentPeer oldPeer = null;

    if ((old = component) != null) {
        clearAutoscroll();

        component = null;

        if (componentPeer != null) {
            oldPeer = componentPeer;
            removeNotify(componentPeer);
        }

        old.setDropTarget(null);

    }

    if ((component = c) != null) try {
        c.setDropTarget(this);
    } catch (Exception e) { // undo the change
        if (old != null) {
            old.setDropTarget(this);
            addNotify(oldPeer);
        }
    }
}
 
Example 17
Source File: FileDropDecorator.java    From MtgDesktopCompanion with GNU General Public License v3.0 5 votes vote down vote up
public static boolean remove( Component c, boolean recursive )
{ 
        c.setDropTarget( null );
        if( recursive && ( c instanceof Container ) )
        {   Component[] comps = ((Container)c).getComponents();
            for( int i = 0; i < comps.length; i++ )
                remove( comps[i], recursive );
            return true;
        } 
        else 
    	{
        	return false;
    	}
}
 
Example 18
Source File: DropTarget.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Note: this interface is required to permit the safe association
 * of a DropTarget with a Component in one of two ways, either:
 * <code> component.setDropTarget(droptarget); </code>
 * or <code> droptarget.setComponent(component); </code>
 * <P>
 * The Component will receive drops only if it is enabled.
 * @param c The new <code>Component</code> this <code>DropTarget</code>
 * is to be associated with.
 */

public synchronized void setComponent(Component c) {
    if (component == c || component != null && component.equals(c))
        return;

    Component     old;
    ComponentPeer oldPeer = null;

    if ((old = component) != null) {
        clearAutoscroll();

        component = null;

        if (componentPeer != null) {
            oldPeer = componentPeer;
            removeNotify(componentPeer);
        }

        old.setDropTarget(null);

    }

    if ((component = c) != null) try {
        c.setDropTarget(this);
    } catch (Exception e) { // undo the change
        if (old != null) {
            old.setDropTarget(this);
            addNotify(oldPeer);
        }
    }
}
 
Example 19
Source File: DropTarget.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new DropTarget given the <code>Component</code>
 * to associate itself with, an <code>int</code> representing
 * the default acceptable action(s) to
 * support, a <code>DropTargetListener</code>
 * to handle event processing, a <code>boolean</code> indicating
 * if the <code>DropTarget</code> is currently accepting drops, and
 * a <code>FlavorMap</code> to use (or null for the default <CODE>FlavorMap</CODE>).
 * <P>
 * The Component will receive drops only if it is enabled.
 * @param c         The <code>Component</code> with which this <code>DropTarget</code> is associated
 * @param ops       The default acceptable actions for this <code>DropTarget</code>
 * @param dtl       The <code>DropTargetListener</code> for this <code>DropTarget</code>
 * @param act       Is the <code>DropTarget</code> accepting drops.
 * @param fm        The <code>FlavorMap</code> to use, or null for the default <CODE>FlavorMap</CODE>
 * @exception HeadlessException if GraphicsEnvironment.isHeadless()
 *            returns true
 * @see java.awt.GraphicsEnvironment#isHeadless
 */
public DropTarget(Component c, int ops, DropTargetListener dtl,
                  boolean act, FlavorMap fm)
    throws HeadlessException
{
    if (GraphicsEnvironment.isHeadless()) {
        throw new HeadlessException();
    }

    component = c;

    setDefaultActions(ops);

    if (dtl != null) try {
        addDropTargetListener(dtl);
    } catch (TooManyListenersException tmle) {
        // do nothing!
    }

    if (c != null) {
        c.setDropTarget(this);
        setActive(act);
    }

    if (fm != null) {
        flavorMap = fm;
    } else {
        flavorMap = SystemFlavorMap.getDefaultFlavorMap();
    }
}
 
Example 20
Source File: DropTarget.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Note: this interface is required to permit the safe association
 * of a DropTarget with a Component in one of two ways, either:
 * <code> component.setDropTarget(droptarget); </code>
 * or <code> droptarget.setComponent(component); </code>
 * <P>
 * The Component will receive drops only if it is enabled.
 * @param c The new <code>Component</code> this <code>DropTarget</code>
 * is to be associated with.
 */

public synchronized void setComponent(Component c) {
    if (component == c || component != null && component.equals(c))
        return;

    Component     old;
    ComponentPeer oldPeer = null;

    if ((old = component) != null) {
        clearAutoscroll();

        component = null;

        if (componentPeer != null) {
            oldPeer = componentPeer;
            removeNotify(componentPeer);
        }

        old.setDropTarget(null);

    }

    if ((component = c) != null) try {
        c.setDropTarget(this);
    } catch (Exception e) { // undo the change
        if (old != null) {
            old.setDropTarget(this);
            addNotify(oldPeer);
        }
    }
}