List of usage examples for java.awt.dnd DragSource DragSource
public DragSource() throws HeadlessException
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 .ja va 2s . c o m*/ pack(); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); }
From source file:Main.java
public DraggableComponent() { dragSource = new DragSource(); dragSource.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY_OR_MOVE, this); }
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);// w ww . j a v a2s .co m add(right); setSize(40, 50); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLocationRelativeTo(null); setVisible(true); }
From source file:GestureTest.java
public GestureTest() { super("Gesture Test"); setSize(200, 150);//ww w .j a v a2 s .c om addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { System.exit(0); } }); jl = new JList(items); jl.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); getContentPane().add(new JScrollPane(jl), BorderLayout.CENTER); ds = new DragSource(); DragGestureRecognizer dgr = ds.createDefaultDragGestureRecognizer(jl, DnDConstants.ACTION_COPY, this); setVisible(true); }
From source file:DragTest.java
public DragTest() { super("Drag Test"); setSize(200, 150);//from w ww. j a va 2 s .c om addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { System.exit(0); } }); jl = new JList(items); jl.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); getContentPane().add(new JScrollPane(jl), BorderLayout.CENTER); ds = new DragSource(); DragGestureRecognizer dgr = ds.createDefaultDragGestureRecognizer(jl, DnDConstants.ACTION_COPY, this); setVisible(true); }
From source file:DNDList.java
/** * constructor - initializes the DropTarget and DragSource. */// w w w . ja v a 2 s . c o m public DNDList(ListModel dataModel) { super(dataModel); dropTarget = new DropTarget(this, this); dragSource = new DragSource(); dragSource.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_MOVE, this); }
From source file:be.ugent.maf.cellmissy.gui.controller.load.generic.DragAndDropController.java
/** * Initialize the DnD/* www . j a v a2 s. c om*/ */ 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:TreeDragTest.java
public TreeDragSource(JTree tree, int actions) { sourceTree = tree;//from ww w. ja v a2 s . co m source = new DragSource(); recognizer = source.createDefaultDragGestureRecognizer(sourceTree, actions, this); }
From source file:com.qspin.qtaste.ui.TestCaseTree.java
public TestCaseTree(TestCasePane testCasePn) { super();/*from w w w .j av a2 s . c om*/ mTestCaseTree = this; this.setCellRenderer(new TestCaseTreeCellRenderer()); testCasePane = testCasePn; testCasePane.setTestCaseTree(this); ToolTipManager.sharedInstance().registerComponent(this); FileNode rootFileNode = createRootFileNode(); TCTreeNode rootNode = new TCTreeNode(rootFileNode, true); DefaultTreeModel tm = new DefaultTreeModel(rootNode); setModel(tm); generateScriptsTree(rootFileNode); TCTreeListener listener = new TCTreeListener(); this.addMouseListener(listener); addTreeWillExpandListener(listener); addTreeSelectionListener(listener); TreeSelectionModel selModel = this.getSelectionModel(); selModel.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); // drag drop initialization ds = new DragSource(); dt = new DropTarget(); ds.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY, this); try { dt.setComponent(this); dt.addDropTargetListener(this); } catch (java.util.TooManyListenersException e) { logger.error(e.getMessage()); } }
From source file:ca.phon.app.project.ProjectWindow.java
private void init() { /* Layout *///from ww w . ja v a 2s .co m 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); }); } }