Example usage for java.awt.dnd DropTarget DropTarget

List of usage examples for java.awt.dnd DropTarget DropTarget

Introduction

In this page you can find the example usage for java.awt.dnd DropTarget DropTarget.

Prototype

public DropTarget(Component c, int ops, DropTargetListener dtl, boolean act) throws HeadlessException 

Source Link

Document

Creates a DropTarget given the Component to associate itself with, an int representing the default acceptable action(s) to support, a DropTargetListener to handle event processing, and a boolean indicating if the DropTarget is currently accepting drops.

Usage

From source file:javazoom.jlgui.player.amp.playlist.ui.PlaylistUI.java

public PlaylistUI() {
    super();/*from   w w  w .j  a  va  2  s. c o  m*/
    setDoubleBuffered(true);
    setLayout(new AbsoluteLayout());
    config = Config.getInstance();
    addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            handleMouseClick(e);
        }
    });
    // DnD support.
    DropTargetAdapter dnd = new DropTargetAdapter() {
        public void processDrop(Object data) {
            processDnD(data);
        }
    };
    DropTarget dt = new DropTarget(this, DnDConstants.ACTION_COPY, dnd, true);
}

From source file:javazoom.jlgui.player.amp.equalizer.ui.EqualizerUI.java

public EqualizerUI() {
    super();//from  w  ww  .  j  a va 2  s .co m
    setDoubleBuffered(true);
    config = Config.getInstance();
    eqgains = new int[10];
    setLayout(new AbsoluteLayout());
    int[] vals = config.getLastEqualizer();
    if (vals != null) {
        for (int h = 0; h < vals.length; h++) {
            gainValue[h] = vals[h];
        }
    }
    // DnD support disabled.
    DropTargetAdapter dnd = new DropTargetAdapter() {
        public void processDrop(Object data) {
            return;
        }
    };
    DropTarget dt = new DropTarget(this, DnDConstants.ACTION_COPY, dnd, false);
}

From source file:edu.clemson.cs.nestbed.client.gui.MoteConfigPanel.java

public MoteConfigPanel(MoteTestbedAssignment mtbAssignment, ProgramManager programManager, int projDepConfID,
        MoteManager moteManager, MoteTypeManager moteTypeManager, MoteDeploymentConfigurationManager mdcManager)
        throws RemoteException, NotBoundException, MalformedURLException {

    this.programManager = programManager;
    this.mtbAssignment = mtbAssignment;
    this.projDepConfID = projDepConfID;
    this.mote = moteManager.getMote(mtbAssignment.getMoteID());
    this.moteType = moteTypeManager.getMoteType(mote.getMoteTypeID());
    this.mdcManager = mdcManager;
    this.moteDepConfig = mdcManager.getMoteDeploymentConfiguration(projDepConfID, mote.getID());
    this.radioChangeListener = new RadioChangeListener();
    this.radioSpinner = new JSpinner(
            new SpinnerNumberModel(MAX_RADIO_POWER, MIN_RADIO_POWER, MAX_RADIO_POWER, RADIO_POWER_INCR));

    setIcon(new ImageIcon(moteType.getImage()).getImage());

    if (this.moteDepConfig != null) {
        this.program = programManager.getProgram(moteDepConfig.getProgramID());
        radioSpinner.setValue(moteDepConfig.getRadioPowerLevel());
    } else {/* ww w  .jav a 2 s. co m*/
        radioSpinner.setEnabled(false);
    }
    radioSpinner.setToolTipText("Radio Power Level");

    Dimension labelSize = new Dimension(LABEL_WIDTH, LABEL_HEIGHT);
    JLabel addressLabel = new JLabel("" + mtbAssignment.getMoteAddress());
    addressLabel.setSize(labelSize);
    addressLabel.setPreferredSize(labelSize);

    Dimension spinnerSize = new Dimension(SPINNER_WIDTH, SPINNER_HEIGHT);
    radioSpinner.setSize(spinnerSize);
    radioSpinner.setPreferredSize(spinnerSize);
    radioSpinner.addChangeListener(radioChangeListener);

    setToolTipText(getToolTipString());
    addMouseListener(new MotePanelMouseListener());

    add(addressLabel);
    addressLabel.setLocation(2, 0);

    add(radioSpinner);
    radioSpinner.setLocation(getWidth() - SPINNER_WIDTH - 2, getHeight() - SPINNER_HEIGHT - 2);

    mdcManager.addRemoteObserver(new MoteDeploymentConfigObserver());
    new DropTarget(this, DnDConstants.ACTION_COPY_OR_MOVE, new ProgramDropTarget(), true);
}

From source file:javazoom.jlgui.player.amp.PlayerUI.java

/**
 * Load main player.//w w w  .  j a  v a  2s  .  c o m
 * @param loader
 */
public void loadUI(Loader loader) {
    this.loader = loader;
    setLayout(new AbsoluteLayout());
    config = Config.getInstance();
    ui.setConfig(config);
    playlistUI = new PlaylistUI();
    playlistUI.setSkin(ui);
    playlistUI.setPlayer(this);
    equalizerUI = new EqualizerUI();
    equalizerUI.setSkin(ui);
    loadSkin();
    // DnD support.
    DropTargetAdapter dnd = new DropTargetAdapter() {
        public void processDrop(Object data) {
            processDnD(data);
        }
    };
    DropTarget dt = new DropTarget(this, DnDConstants.ACTION_COPY, dnd, true);
}

From source file:edu.clemson.cs.nestbed.client.gui.ConfigManagerFrame.java

public ConfigManagerFrame(Testbed testbed, Project project, ProjectDeploymentConfiguration config)
        throws RemoteException, NotBoundException, MalformedURLException, ClassNotFoundException {
    super(testbed.getName() + " Deployment Configuration Manager");

    this.testbed = testbed;
    this.project = project;
    this.config = config;

    lookupRemoteManagers();//from  w  ww .  j  a  v  a 2  s .c  o m
    // TODO:  We need to deregister listeners
    programCompileManager.addRemoteObserver(new ProgramCompileObserver());
    programManager.addRemoteObserver(new ProgramObserver());
    progProfManager.addRemoteObserver(new ProgramProfilingSymbolObserver());
    progProfMsgSymManager.addRemoteObserver(new ProgramProfilingMessageSymbolObserver());

    createComponents();
    programTree.addMouseListener(new ProgramTreeMouseListener());
    programTree.setCellRenderer(new ProgramTreeCellRenderer());
    programTree.setRootVisible(false);
    programTree.setShowsRootHandles(true);
    programTree.setDragEnabled(true);
    programTree.setTransferHandler(new ProgramTreeTransferHandler());
    programTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

    profilingSymbolTable.addMouseListener(new ProfilingSymbolTableMouseListener());
    profilingSymbolTable.setModel(new ProfilingSymbolTableModel());
    profilingSymbolTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    new DropTarget(profilingSymbolTable, DnDConstants.ACTION_COPY_OR_MOVE, new ProgramSymbolDropTarget(), true);

    profilingMsgTable.addMouseListener(new ProfilingMessageTableMouseListener());
    profilingMsgTable.setModel(new ProfilingMessageSymbolTableModel());
    profilingMsgTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    new DropTarget(profilingMsgTable, DnDConstants.ACTION_COPY_OR_MOVE, new ProgramMessageSymbolDropTarget(),
            true);

    setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
    setJMenuBar(buildMenuBar());

    Container c = getContentPane();
    c.setLayout(new BorderLayout());

    JSplitPane top = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, buildLeftPanel(), buildMoteGridPanel());

    JSplitPane panel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, top, buildBottomPanel());

    c.add(panel, BorderLayout.CENTER);
}

From source file:javazoom.jlgui.player.amp.Player.java

/**
 * Constructor./*from   w  w  w .  j a  v a  2  s  . c  o m*/
 */
public Player(String Skin, Frame top) {
    super(top);
    topFrame = top;

    // Config feature.
    config = Config.getInstance();
    config.load(initConfig);
    OrigineX = config.getXLocation();
    OrigineY = config.getYLocation();

    // Get screen size
    try {
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Dimension dimension = toolkit.getScreenSize();
        screenWidth = dimension.width;
        screenHeight = dimension.height;
    } catch (Exception e) {
    }

    // Minimize/Maximize/Icon features.
    topFrame.addWindowListener(this);
    topFrame.setLocation(OrigineX, OrigineY);
    topFrame.setSize(0, 0);
    // Polis : Comment out to fix a bug under XWindow
    //topFrame.setResizable(false);
    ClassLoader cl = this.getClass().getClassLoader();
    URL iconURL = cl.getResource("javazoom/jlgui/player/amp/jlguiicon.gif");
    if (iconURL != null) {
        ImageIcon jlguiIcon = new ImageIcon(iconURL);
        topFrame.setIconImage(jlguiIcon.getImage());
    }
    topFrame.show();

    // DnD feature.
    DropTarget dt = new DropTarget(this, DnDConstants.ACTION_COPY, this, true);

    // Playlist feature.
    boolean playlistfound = false;
    if ((initSong != null) && (!initSong.equals("")))
        playlistfound = loadPlaylist(initSong);
    else
        playlistfound = loadPlaylist(config.getPlaylistFilename());

    // Load skin specified in args
    if (Skin != null) {
        thePath = Skin;
        log.info("Load default skin from " + thePath);
        loadSkin(thePath);
        config.setDefaultSkin(thePath);
    }
    // Load skin specified in jlgui.ini
    else if ((config.getDefaultSkin() != null) && (!config.getDefaultSkin().trim().equals(""))) {
        log.info("Load default skin from " + config.getDefaultSkin());
        loadSkin(config.getDefaultSkin());
    }
    // Default included skin
    else {
        //ClassLoader cl = this.getClass().getClassLoader();
        InputStream sis = cl.getResourceAsStream("javazoom/jlgui/player/amp/metrix.wsz");
        log.info("Load default skin for JAR");
        loadSkin(sis);
    }

    // Go to playlist begining if needed.
    if ((playlist != null) && (playlistfound == true)) {
        if (playlist.getPlaylistSize() > 0)
            acNext.fireEvent();
    }

    // Display the whole
    hide();
    show();
    repaint();
}

From source file:javazoom.jlgui.player.amp.PlayerApplet.java

/**
 * Init player applet./*w w w . ja va  2 s . c om*/
 */
public void initPlayer(String Skin) {
    // Config feature.
    config = Config.getInstance();
    config.load(initConfig);
    OrigineX = config.getXLocation();
    OrigineY = config.getYLocation();

    // Get screen size
    try {
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Dimension dimension = toolkit.getScreenSize();
        screenWidth = dimension.width;
        screenHeight = dimension.height;
    } catch (Exception e) {
    }

    // Minimize/Maximize/Icon features.
    //topFrame.addWindowListener(this);
    topFrame.setLocation(OrigineX, OrigineY);
    topFrame.setSize(0, 0);
    // Polis : Comment out to fix a bug under XWindow
    //topFrame.setResizable(false);
    ClassLoader cl = this.getClass().getClassLoader();
    URL iconURL = cl.getResource("javazoom/jlgui/player/amp/jlguiicon.gif");
    if (iconURL != null) {
        ImageIcon jlguiIcon = new ImageIcon(iconURL);
        //topFrame.setIconImage(jlguiIcon.getImage());
    }
    topFrame.show();

    // DnD feature.
    DropTarget dt = new DropTarget(this, DnDConstants.ACTION_COPY, this, true);

    // Playlist feature.
    boolean playlistfound = false;
    if ((initSong != null) && (!initSong.equals("")))
        playlistfound = loadPlaylist(initSong);
    else
        playlistfound = loadPlaylist(config.getPlaylistFilename());

    // Load skin specified in args
    if (Skin != null) {
        thePath = Skin;
        log.info("Load default skin from " + thePath);
        loadSkin(thePath);
        config.setDefaultSkin(thePath);
    }
    // Load skin specified in jlgui.ini
    else if ((config.getDefaultSkin() != null) && (!config.getDefaultSkin().trim().equals(""))) {
        log.info("Load default skin from " + config.getDefaultSkin());
        loadSkin(config.getDefaultSkin());
    }
    // Default included skin
    else {
        //ClassLoader cl = this.getClass().getClassLoader();
        InputStream sis = cl.getResourceAsStream("javazoom/jlgui/player/amp/metrix.wsz");
        log.info("Load default skin for JAR");
        loadSkin(sis);
    }

    // Go to playlist begining if needed.
    if ((playlist != null) && (playlistfound == true)) {
        if (playlist.getPlaylistSize() > 0)
            acNext.fireEvent();
    }

    // Display the whole
    hide();
    show();
    repaint();
}

From source file:org.jets3t.apps.uploader.Uploader.java

/**
 * Initialise the application's File drop targets for drag and drop copying of local files
 * to S3./*from   ww  w.j  a  v a2  s  .  c  o m*/
 *
 * @param dropTargetComponents
 * the components files can be dropped on to transfer them to S3
 */
private void initDropTarget(Component[] dropTargetComponents) {
    DropTargetListener dropTargetListener = new DropTargetListener() {

        private Border originalBorder = appContentPanel.getBorder();
        private Border dragOverBorder = BorderFactory.createBevelBorder(1);

        private boolean checkValidDrag(DropTargetDragEvent dtde) {
            if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)
                    && (DnDConstants.ACTION_COPY == dtde.getDropAction()
                            || DnDConstants.ACTION_MOVE == dtde.getDropAction())) {
                dtde.acceptDrag(dtde.getDropAction());
                return true;
            } else {
                dtde.rejectDrag();
                return false;
            }
        }

        public void dragEnter(DropTargetDragEvent dtde) {
            if (checkValidDrag(dtde)) {
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        appContentPanel.setBorder(dragOverBorder);
                    };
                });
            }
        }

        public void dragOver(DropTargetDragEvent dtde) {
            checkValidDrag(dtde);
        }

        public void dropActionChanged(DropTargetDragEvent dtde) {
            checkValidDrag(dtde);
        }

        public void dragExit(DropTargetEvent dte) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    appContentPanel.setBorder(originalBorder);
                };
            });
        }

        public void drop(DropTargetDropEvent dtde) {
            if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)
                    && (DnDConstants.ACTION_COPY == dtde.getDropAction()
                            || DnDConstants.ACTION_MOVE == dtde.getDropAction())) {
                dtde.acceptDrop(dtde.getDropAction());
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        appContentPanel.setBorder(originalBorder);
                    };
                });

                try {
                    final List fileList = (List) dtde.getTransferable()
                            .getTransferData(DataFlavor.javaFileListFlavor);
                    if (fileList != null && fileList.size() > 0) {
                        if (checkProposedUploadFiles(fileList)) {
                            wizardStepForward();
                        }
                    }
                } catch (Exception e) {
                    String errorMessage = "Unable to accept dropped item";
                    log.error(errorMessage, e);
                    ErrorDialog.showDialog(ownerFrame, null, uploaderProperties.getProperties(), errorMessage,
                            e);
                }
            } else {
                dtde.rejectDrop();
            }
        }
    };

    // Attach drop target listener to each target component.
    for (int i = 0; i < dropTargetComponents.length; i++) {
        new DropTarget(dropTargetComponents[i], DnDConstants.ACTION_COPY, dropTargetListener, true);
    }
}

From source file:org.jets3t.apps.cockpit.Cockpit.java

/**
 * Initialise the application's File drop targets for drag and drop copying of local files
 * to S3./*from  w  w w  . j a va2  s . c om*/
 *
 * @param dropTargetComponents
 * the components files can be dropped on to transfer them to S3
 */
private void initDropTarget(JComponent[] dropTargetComponents) {
    DropTargetListener dropTargetListener = new DropTargetListener() {

        private boolean checkValidDrag(DropTargetDragEvent dtde) {
            if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)
                    && (DnDConstants.ACTION_COPY == dtde.getDropAction()
                            || DnDConstants.ACTION_MOVE == dtde.getDropAction())) {
                dtde.acceptDrag(dtde.getDropAction());
                return true;
            } else {
                dtde.rejectDrag();
                return false;
            }
        }

        public void dragEnter(DropTargetDragEvent dtde) {
            if (checkValidDrag(dtde)) {
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        objectsTable.requestFocusInWindow();
                    };
                });
            }
        }

        public void dragOver(DropTargetDragEvent dtde) {
            checkValidDrag(dtde);
        }

        public void dropActionChanged(DropTargetDragEvent dtde) {
            if (checkValidDrag(dtde)) {
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        objectsTable.requestFocusInWindow();
                    };
                });
            } else {
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        ownerFrame.requestFocusInWindow();
                    };
                });
            }
        }

        public void dragExit(DropTargetEvent dte) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    ownerFrame.requestFocusInWindow();
                };
            });
        }

        public void drop(DropTargetDropEvent dtde) {
            if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)
                    && (DnDConstants.ACTION_COPY == dtde.getDropAction()
                            || DnDConstants.ACTION_MOVE == dtde.getDropAction())) {
                dtde.acceptDrop(dtde.getDropAction());
                try {
                    final List fileList = (List) dtde.getTransferable()
                            .getTransferData(DataFlavor.javaFileListFlavor);
                    if (fileList != null && fileList.size() > 0) {
                        uploadFiles((File[]) fileList.toArray(new File[fileList.size()]));
                    }
                } catch (Exception e) {
                    String message = "Unable to start accept dropped items";
                    log.error(message, e);
                    ErrorDialog.showDialog(ownerFrame, null, message, e);
                }
            } else {
                dtde.rejectDrop();
            }
        }
    };

    // Attach drop target listener to each target component.
    for (int i = 0; i < dropTargetComponents.length; i++) {
        new DropTarget(dropTargetComponents[i], DnDConstants.ACTION_COPY, dropTargetListener, true);
    }
}

From source file:org.jets3t.apps.cockpitlite.CockpitLite.java

/**
 * Initialise the application's File drop targets for drag and drop copying of local files
 * to S3.//from w  ww  .  j a  v  a  2 s  . c o m
 *
 * @param dropTargetComponents
 * the components files can be dropped on to transfer them to S3
 */
private void initDropTarget(JComponent[] dropTargetComponents) {
    DropTargetListener dropTargetListener = new DropTargetListener() {

        private boolean checkValidDrag(DropTargetDragEvent dtde) {
            if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)
                    && (DnDConstants.ACTION_COPY == dtde.getDropAction()
                            || DnDConstants.ACTION_MOVE == dtde.getDropAction())) {
                dtde.acceptDrag(dtde.getDropAction());
                return true;
            } else {
                dtde.rejectDrag();
                return false;
            }
        }

        public void dragEnter(DropTargetDragEvent dtde) {
            if (checkValidDrag(dtde)) {
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        objectsTable.requestFocusInWindow();
                    };
                });
            }
        }

        public void dragOver(DropTargetDragEvent dtde) {
            checkValidDrag(dtde);
        }

        public void dropActionChanged(DropTargetDragEvent dtde) {
            if (checkValidDrag(dtde)) {
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        objectsTable.requestFocusInWindow();
                    };
                });
            } else {
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        ownerFrame.requestFocusInWindow();
                    };
                });
            }
        }

        public void dragExit(DropTargetEvent dte) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    ownerFrame.requestFocusInWindow();
                };
            });
        }

        public void drop(DropTargetDropEvent dtde) {
            if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)
                    && (DnDConstants.ACTION_COPY == dtde.getDropAction()
                            || DnDConstants.ACTION_MOVE == dtde.getDropAction())) {
                dtde.acceptDrop(dtde.getDropAction());
                try {
                    final List fileList = (List) dtde.getTransferable()
                            .getTransferData(DataFlavor.javaFileListFlavor);
                    if (fileList != null && fileList.size() > 0) {
                        new Thread() {
                            @Override
                            public void run() {
                                prepareForFilesUpload((File[]) fileList.toArray(new File[fileList.size()]));
                            }
                        }.start();
                    }
                } catch (Exception e) {
                    String message = "Unable to start accept dropped item(s)";
                    log.error(message, e);
                    ErrorDialog.showDialog(ownerFrame, null, cockpitLiteProperties.getProperties(), message, e);
                }
            } else {
                dtde.rejectDrop();
            }
        }
    };

    // Attach drop target listener to each target component.
    for (int i = 0; i < dropTargetComponents.length; i++) {
        new DropTarget(dropTargetComponents[i], DnDConstants.ACTION_COPY, dropTargetListener, true);
    }
}