Example usage for java.awt.dnd DragSource createDefaultDragGestureRecognizer

List of usage examples for java.awt.dnd DragSource createDefaultDragGestureRecognizer

Introduction

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

Prototype


public DragGestureRecognizer createDefaultDragGestureRecognizer(Component c, int actions,
        DragGestureListener dgl) 

Source Link

Document

Creates a new DragGestureRecognizer that implements the default abstract subclass of DragGestureRecognizer for this DragSource , and sets the specified Component and DragGestureListener on the newly created object.

Usage

From source file:DragGesture.java

public DragGesture() {
    setTitle("Drag Gesture");
    JLabel left = new JLabel("text");
    DragSource ds = new DragSource();
    ds.createDefaultDragGestureRecognizer(left, DnDConstants.ACTION_COPY, this);
    add(left);//from  w  ww  . j ava  2 s . c  om
    pack();
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setVisible(true);
}

From source file:ComplexExample.java

public ComplexExample() {
    JPanel left = new JPanel();
    left.setBackground(Color.red);

    JPanel right = new JPanel();
    right.setBackground(Color.white);

    new MyDropTargetListener(right);

    DragSource ds = new DragSource();
    ds.createDefaultDragGestureRecognizer(left, DnDConstants.ACTION_COPY, this);

    setLayout(new FlowLayout());
    add(left);//  ww w. j a v a  2  s .  c  o m
    add(right);

    setSize(40, 50);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLocationRelativeTo(null);
    setVisible(true);
}

From source file:JLabelDragSource.java

public JLabelDragSource(JLabel label) {
    this.label = label;

    // Use the default DragSource
    DragSource dragSource = DragSource.getDefaultDragSource();

    // Create a DragGestureRecognizer and
    // register as the listener
    dragSource.createDefaultDragGestureRecognizer(label, DnDConstants.ACTION_COPY_OR_MOVE, this);
}

From source file:TreeTester.java

public DndTree() {
    DragSource dragSource = DragSource.getDefaultDragSource();
    dragSource.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY_OR_MOVE,
            new TreeDragGestureListener());
    DropTarget dropTarget = new DropTarget(this, new TreeDropTargetListener());
}

From source file:TreeTester.java

public DndTree(TreeModel model) {
    super(model);
    DragSource dragSource = DragSource.getDefaultDragSource();
    dragSource.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY_OR_MOVE,
            new TreeDragGestureListener());
    DropTarget dropTarget = new DropTarget(this, new TreeDropTargetListener());
}

From source file:FileTreeDragSource.java

public FileTreeDragSource(FileTree tree) {
    this.tree = tree;

    // Use the default DragSource
    DragSource dragSource = DragSource.getDefaultDragSource();

    // Create a DragGestureRecognizer and
    // register as the listener
    dragSource.createDefaultDragGestureRecognizer(tree, DnDConstants.ACTION_COPY_OR_MOVE, this);
}

From source file:TransferableScribblePane.java

public TransferableScribblePane() {
    setPreferredSize(new Dimension(450, 200)); // We need a default size
    setBorder(normalBorder); // and a border.
    lines = new ArrayList(); // Start with an empty list of lines

    // Register interest in mouse button and mouse motion events.
    enableEvents(AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK);

    // Enable drag-and-drop by specifying a listener that will be
    // notified when a drag begins. dragGestureListener is defined later.
    DragSource dragSource = DragSource.getDefaultDragSource();
    dragSource.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY_OR_MOVE, dragGestureListener);

    // Enable drops on this component by registering a listener to
    // be notified when something is dragged or dropped over us.
    this.setDropTarget(new DropTarget(this, dropTargetListener));

    // Check whether the system allows us to drag an image of the line
    canDragImage = dragSource.isDragImageSupported();
}

From source file:be.ugent.maf.cellmissy.gui.controller.load.generic.DragAndDropController.java

/**
 * Initialize the DnD/*from  ww  w .j a  va 2s. co m*/
 */
private void initDnD() {
    // create a new Drag Source
    DragSource ds = new DragSource();
    // get the directory tree from the parent controller
    JTree directoryTree = genericImagedPlateController.getLoadFromGenericInputPlatePanel().getDirectoryTree();
    // get the JPanel from the parent controller
    ImagedPlatePanel imagedPlatePanel = genericImagedPlateController.getImagedPlatePanel();
    // the DRAG gesture (source -- JTree) -- needs a DragGestureListener to notify
    ds.createDefaultDragGestureRecognizer(directoryTree, DnDConstants.ACTION_COPY,
            new JTreeDragGestureListener());
    // the DROP action onto the target
    JPanelDropTargetListener jPanelDropTargetListener = new JPanelDropTargetListener(imagedPlatePanel);
}

From source file:ca.phon.app.project.ProjectWindow.java

private void init() {
    /* Layout *//*from   w ww . ja  va 2s .c om*/
    setLayout(new BorderLayout());

    final ProjectDataTransferHandler transferHandler = new ProjectDataTransferHandler(this);

    /* Create components */
    newCorpusButton = createNewCorpusButton();
    createCorpusButton = createCorpusButton();

    corpusList = new JList<String>();
    corpusModel = new CorpusListModel(getProject());
    corpusList.setModel(corpusModel);
    corpusList.setCellRenderer(new CorpusListCellRenderer());
    corpusList.setVisibleRowCount(20);
    corpusList.addListSelectionListener(e -> {
        if (getSelectedCorpus() != null) {
            String corpus = getSelectedCorpus();
            sessionModel.setCorpus(corpus);
            sessionList.clearSelection();
            corpusDetails.setCorpus(corpus);

            if (getProject().getCorpusSessions(corpus).size() == 0) {
                onSwapNewAndCreateSession(newSessionButton);
            } else {
                onSwapNewAndCreateSession(createSessionButton);
            }
        }
    });
    corpusList.addMouseListener(new MouseInputAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            doPopup(e);
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            doPopup(e);
        }

        public void doPopup(MouseEvent e) {
            if (e.isPopupTrigger()) {
                int clickedIdx = corpusList.locationToIndex(e.getPoint());
                if (clickedIdx >= 0 && Arrays.binarySearch(corpusList.getSelectedIndices(), clickedIdx) < 0) {
                    corpusList.setSelectedIndex(clickedIdx);
                }
                showCorpusListContextMenu(e.getPoint());
            }
        }
    });

    final DragSource corpusDragSource = new DragSource();
    corpusDragSource.createDefaultDragGestureRecognizer(corpusList, DnDConstants.ACTION_COPY, (event) -> {
        final List<ProjectPath> paths = new ArrayList<>();
        for (String corpus : getSelectedCorpora()) {
            final ProjectPath corpusPath = new ProjectPath(getProject(), corpus, null);
            paths.add(corpusPath);
        }
        final ProjectPathTransferable transferable = new ProjectPathTransferable(paths);
        event.startDrag(DragSource.DefaultCopyDrop, transferable);
    });

    corpusList.setDragEnabled(true);
    corpusList.setTransferHandler(transferHandler);

    corpusDetails = new CorpusDetailsPane(getProject());
    corpusDetails.setWrapStyleWord(true);
    corpusDetails.setRows(6);
    corpusDetails.setLineWrap(true);
    corpusDetails.setBackground(Color.white);
    corpusDetails.setOpaque(true);
    JScrollPane corpusDetailsScroller = new JScrollPane(corpusDetails);

    sessionList = new JList<String>();
    newSessionButton = createNewSessionButton();
    createSessionButton = createSessionButton();
    sessionModel = new SessionListModel(getProject());
    sessionList.setModel(sessionModel);
    sessionList.setCellRenderer(new SessionListCellRenderer());
    sessionList.setVisibleRowCount(20);
    sessionList.addListSelectionListener(e -> {
        if (sessionList.getSelectedValue() != null && !e.getValueIsAdjusting()) {
            String corpus = getSelectedCorpus();
            String session = getSelectedSessionName();

            sessionDetails.setSession(corpus, session);
        }
    });
    sessionList.addMouseListener(new MouseInputAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2 && e.getButton() == 1) {
                // get the clicked item
                int clickedItem = sessionList.locationToIndex(e.getPoint());
                if (sessionList.getModel().getElementAt(clickedItem) == null)
                    return;

                final String session = sessionList.getModel().getElementAt(clickedItem).toString();
                final String corpus = ((SessionListModel) sessionList.getModel()).getCorpus();

                msgPanel.reset();
                msgPanel.setMessageLabel("Opening '" + corpus + "." + session + "'");
                msgPanel.setIndeterminate(true);
                msgPanel.repaint();

                SwingUtilities.invokeLater(() -> {
                    final ActionEvent ae = new ActionEvent(sessionList, -1, "openSession");
                    (new OpenSessionAction(ProjectWindow.this, corpus, session)).actionPerformed(ae);

                    msgPanel.setIndeterminate(false);
                });
            }
        }

        @Override
        public void mousePressed(MouseEvent e) {
            doPopup(e);
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            doPopup(e);
        }

        public void doPopup(MouseEvent e) {
            if (e.isPopupTrigger()) {
                int clickedIdx = sessionList.locationToIndex(e.getPoint());
                if (clickedIdx >= 0 && Arrays.binarySearch(sessionList.getSelectedIndices(), clickedIdx) < 0) {
                    sessionList.setSelectedIndex(clickedIdx);
                }
                showSessionListContextMenu(e.getPoint());
            }
        }
    });

    sessionList.setDragEnabled(true);
    sessionList.setTransferHandler(transferHandler);

    final DragSource sessionDragSource = new DragSource();
    sessionDragSource.createDefaultDragGestureRecognizer(sessionList, DnDConstants.ACTION_COPY, (event) -> {
        final List<ProjectPath> paths = new ArrayList<>();
        final String corpus = getSelectedCorpus();
        if (corpus == null)
            return;
        for (String session : getSelectedSessionNames()) {
            final ProjectPath sessionPath = new ProjectPath(getProject(), corpus, session);
            paths.add(sessionPath);
        }
        final ProjectPathTransferable transferable = new ProjectPathTransferable(paths);
        event.startDrag(DragSource.DefaultCopyDrop, transferable);
    });

    sessionDetails = new SessionDetailsPane(getProject());
    sessionDetails.setLineWrap(true);
    sessionDetails.setRows(6);
    sessionDetails.setWrapStyleWord(true);
    sessionDetails.setBackground(Color.white);
    sessionDetails.setOpaque(true);
    JScrollPane sessionDetailsScroller = new JScrollPane(sessionDetails);

    JScrollPane corpusScroller = new JScrollPane(corpusList);
    JScrollPane sessionScroller = new JScrollPane(sessionList);

    blindModeBox = new JCheckBox("Blind transcription");
    blindModeBox.setSelected(false);

    msgPanel = new StatusPanel();

    corpusPanel = new JPanel(new BorderLayout());
    corpusPanel.add(newCorpusButton, BorderLayout.NORTH);
    corpusPanel.add(corpusScroller, BorderLayout.CENTER);
    corpusPanel.add(corpusDetailsScroller, BorderLayout.SOUTH);

    sessionPanel = new JPanel(new BorderLayout());
    sessionPanel.add(newSessionButton, BorderLayout.NORTH);
    sessionPanel.add(sessionScroller, BorderLayout.CENTER);
    sessionPanel.add(sessionDetailsScroller, BorderLayout.SOUTH);

    final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    splitPane.setLeftComponent(corpusPanel);
    splitPane.setRightComponent(sessionPanel);
    splitPane.setResizeWeight(0.5);

    // invoke later
    SwingUtilities.invokeLater(() -> {
        splitPane.setDividerLocation(0.5);
    });

    // the frame layout
    String projectName = null;
    projectName = getProject().getName();

    DialogHeader header = new DialogHeader(projectName, StringUtils.abbreviate(projectLoadPath, 80));

    add(header, BorderLayout.NORTH);

    CellConstraints cc = new CellConstraints();
    final JPanel topPanel = new JPanel(new FormLayout("pref, fill:pref:grow, right:pref", "pref"));
    topPanel.add(msgPanel, cc.xy(1, 1));
    topPanel.add(blindModeBox, cc.xy(3, 1));

    add(splitPane, BorderLayout.CENTER);
    add(topPanel, BorderLayout.SOUTH);

    // if no corpora are currently available, 'prompt' the user to create a new one
    if (getProject().getCorpora().size() == 0) {
        SwingUtilities.invokeLater(() -> {
            onSwapNewAndCreateCorpus(newCorpusButton);
        });
    } else {
        SwingUtilities.invokeLater(() -> {
            corpusList.setSelectedIndex(0);
        });
    }
}

From source file:com.eviware.soapui.SoapUI.java

private void buildUI() {
    // display used java version
    log.info("Used java version: " + System.getProperty("java.version"));
    frame.addWindowListener(new MainFrameWindowListener());
    UISupport.setMainFrame(frame);// w  w  w.  ja v a2  s  . c o  m

    navigator = new Navigator(workspace);
    navigator.addNavigatorListener(new InternalNavigatorListener());

    desktopPanelsList = new JDesktopPanelsList(desktop);

    mainInspector = JInspectorPanelFactory.build(buildContentPanel(), SwingConstants.LEFT);
    mainInspector.addInspector(
            new JComponentInspector<JComponent>(buildMainPanel(), "Navigator", "The soapUI Navigator", true));
    mainInspector.setCurrentInspector("Navigator");

    frame.setJMenuBar(buildMainMenu());
    frame.getContentPane().add(buildToolbar(), BorderLayout.NORTH);
    frame.getContentPane().add(mainInspector.getComponent(), BorderLayout.CENTER);
    frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    frame.setSize(1000, 750);

    mainInspector.setDividerLocation(250);
    mainInspector.setResizeWeight(0.1);
    navigator.selectModelItem(workspace);

    desktop.addDesktopListener(internalDesktopListener);

    ToolTipManager.sharedInstance().setInitialDelay(200);

    JTree mainTree = navigator.getMainTree();
    DragSource dragSource = DragSource.getDefaultDragSource();
    SoapUIDragAndDropHandler navigatorDragAndDropHandler = new SoapUIDragAndDropHandler(
            new NavigatorDragAndDropable(mainTree), DropType.ON + DropType.AFTER);

    dragSource.createDefaultDragGestureRecognizer(mainTree, DnDConstants.ACTION_COPY_OR_MOVE,
            navigatorDragAndDropHandler);

    desktop.init();
}