Example usage for java.awt.dnd DragSource getDefaultDragSource

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

Introduction

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

Prototype

public static DragSource getDefaultDragSource() 

Source Link

Document

Gets the DragSource object associated with the underlying platform.

Usage

From source file:de.tor.tribes.ui.windows.TribeTribeAttackFrame.java

/**
 * Creates new form TribeTribeAttackFrame
 *///w  ww  .  j  a  v a2  s .c  o  m
public TribeTribeAttackFrame() {
    initComponents();
    centerPanel = new GenericTestPanel();
    jMainPanel.add(centerPanel, BorderLayout.CENTER);
    centerPanel.setChildComponent(jxAttackPlanerPanel);
    buildMenu();
    capabilityInfoPanel1.addActionListener(this, jSourcesTable);
    capabilityInfoPanel2.addActionListener(this, jResultsTable);

    KeyStroke copy = KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK, false);
    KeyStroke bbCopy = KeyStroke.getKeyStroke(KeyEvent.VK_B, ActionEvent.CTRL_MASK, false);
    KeyStroke paste = KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.CTRL_MASK, false);
    KeyStroke cut = KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK, false);
    KeyStroke delete = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0, false);
    jSourcesTable.registerKeyboardAction(TribeTribeAttackFrame.this, "Copy", copy,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jVictimTable.registerKeyboardAction(TribeTribeAttackFrame.this, "Copy", copy,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jResultsTable.registerKeyboardAction(TribeTribeAttackFrame.this, "Copy", copy,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jSourcesTable.registerKeyboardAction(TribeTribeAttackFrame.this, "Paste", paste,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jVictimTable.registerKeyboardAction(TribeTribeAttackFrame.this, "Paste", paste,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jSourcesTable.registerKeyboardAction(TribeTribeAttackFrame.this, "Cut", cut,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jVictimTable.registerKeyboardAction(TribeTribeAttackFrame.this, "Cut", cut,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jSourcesTable.registerKeyboardAction(TribeTribeAttackFrame.this, "Delete", delete,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jVictimTable.registerKeyboardAction(TribeTribeAttackFrame.this, "Delete", delete,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jResultsTable.registerKeyboardAction(TribeTribeAttackFrame.this, "Delete", delete,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    jResultsTable.registerKeyboardAction(TribeTribeAttackFrame.this, "BBCopy", bbCopy,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    Action noFind = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            //no find
        }
    };
    jSourcesTable.getActionMap().put("find", noFind);
    jVictimTable.getActionMap().put("find", noFind);
    jResultsTable.getActionMap().put("find", noFind);

    jSourcesTable.getSelectionModel().addListSelectionListener(TribeTribeAttackFrame.this);
    jVictimTable.getSelectionModel().addListSelectionListener(TribeTribeAttackFrame.this);
    jResultsTable.getSelectionModel().addListSelectionListener(TribeTribeAttackFrame.this);

    jideTabbedPane1.setTabShape(JideTabbedPane.SHAPE_OFFICE2003);
    jideTabbedPane1.setTabColorProvider(JideTabbedPane.ONENOTE_COLOR_PROVIDER);
    jideTabbedPane1.setBoldActiveTab(true);
    TagManager.getSingleton().addManagerListener(TribeTribeAttackFrame.this);
    logPanel = new AlgorithmLogPanel();
    mLogFrame = new JFrame("Informationen zur Berechnung");
    mLogFrame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
    mLogFrame.setLayout(new BorderLayout());
    mLogFrame.add(logPanel);
    mLogFrame.pack();
    mTroopSplitDialog = new TroopSplitDialog(TribeTribeAttackFrame.this, true);
    mSettingsPanel = new SettingsPanel(this);
    jSettingsContentPanel.add(mSettingsPanel, BorderLayout.CENTER);
    jAttackResultDetailsFrame.pack();
    jTargetResultDetailsFrame.pack();
    dragSource = DragSource.getDefaultDragSource();
    dragSource.createDefaultDragGestureRecognizer(TribeTribeAttackFrame.this, DnDConstants.ACTION_COPY_OR_MOVE,
            TribeTribeAttackFrame.this);
    new DropTarget(jSourcesTable, TribeTribeAttackFrame.this);
    new DropTarget(jVictimTable, TribeTribeAttackFrame.this);
    for (MouseListener l : jAllTargetsComboBox.getMouseListeners()) {
        jAllTargetsComboBox.removeMouseListener(l);
    }
    jAllTargetsComboBox.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            fireAddFilteredTargetVillages();
        }
    });

    filterDialog = new TroopFilterDialog(this, true);

    // <editor-fold defaultstate="collapsed" desc="Add selection listeners">
    jVillageGroupList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                fireFilterSourceVillagesByGroupEvent();
            }
        }
    });
    jSourceContinentList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                fireFilterSourceContinentEvent();
            }
        }
    });
    jTargetTribeList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                fireFilterTargetByTribeEvent();
            }
        }
    });
    jTargetContinentList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                fireFilterTargetByContinentEvent();
            }
        }
    });

    jTargetAllyList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                fireFilterTargetByAllyEvent();
            }
        }
    });
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc=" Init HelpSystem ">
    if (!Constants.DEBUG) {
        GlobalOptions.getHelpBroker().enableHelp(jSourcePanel, "pages.attack_planer_source",
                GlobalOptions.getHelpBroker().getHelpSet());
        GlobalOptions.getHelpBroker().enableHelp(jTargetPanel, "pages.attack_planer_target",
                GlobalOptions.getHelpBroker().getHelpSet());
        GlobalOptions.getHelpBroker().enableHelp(mSettingsPanel, "pages.attack_planer_settings",
                GlobalOptions.getHelpBroker().getHelpSet());
        GlobalOptions.getHelpBroker().enableHelpKey(jResultFrame.getRootPane(), "pages.attack_planer_results",
                GlobalOptions.getHelpBroker().getHelpSet());
        GlobalOptions.getHelpBroker().enableHelpKey(jTargetResultDetailsFrame.getRootPane(),
                "pages.attack_planer_results_details_targets", GlobalOptions.getHelpBroker().getHelpSet());
        GlobalOptions.getHelpBroker().enableHelpKey(jAttackResultDetailsFrame.getRootPane(),
                "pages.attack_planer_results_details_sources", GlobalOptions.getHelpBroker().getHelpSet());
        GlobalOptions.getHelpBroker().enableHelpKey(getRootPane(), "pages.attack_planer",
                GlobalOptions.getHelpBroker().getHelpSet());
    }
    // </editor-fold>
}

From source file:org.orbisgis.core.ui.plugins.views.geocatalog.Catalog.java

public Catalog() {
    menuTree = new org.orbisgis.core.ui.pluginSystem.menu.MenuTree();
    lstSources = new OGList();
    lstSources.addMouseListener(new MouseAdapter() {

        @Override//from w w  w.  jav  a 2s  .  c o m
        public void mousePressed(MouseEvent e) {
            showPopup(e);
        }

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

        private void showPopup(MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON3) {
                int path = -1;
                for (int i = 0; i < listModel.getSize(); i++) {
                    if (lstSources.getCellBounds(i, i).contains(e.getPoint())) {
                        path = i;
                        break;
                    }
                }
                int[] selectionPaths = lstSources.getSelectedIndices();
                if ((selectionPaths != null) && (path != -1)) {
                    if (!CollectionUtils.contains(selectionPaths, path)) {
                        if (e.isControlDown()) {
                            lstSources.addSelectionInterval(path, path);
                        } else {
                            lstSources.setSelectionInterval(path, path);
                        }
                    }
                } else if (path == -1) {
                    lstSources.clearSelection();
                } else {
                }
            }
            if (e.isPopupTrigger()) {
                JPopupMenu popup = getPopup();
                if (popup != null) {
                    popup.show(e.getComponent(), e.getX(), e.getY());
                }
            }
        }
    });
    listModel = new SourceListModel();
    lstSources.setModel(listModel);

    this.setLayout(new BorderLayout());
    this.add(new JScrollPane(lstSources), BorderLayout.CENTER);
    this.add(getNorthPanel(), BorderLayout.NORTH);
    SourceListRenderer cellRenderer = new SourceListRenderer(this);
    cellRenderer.setRenderers(new SourceRenderer[0]);
    lstSources.setCellRenderer(cellRenderer);

    dragSource = DragSource.getDefaultDragSource();
    dragSource.createDefaultDragGestureRecognizer(lstSources, DnDConstants.ACTION_COPY_OR_MOVE, this);
    editingSources = new HashMap<String, EditableSource>();

    //Init the file drop system
    FileDrop fileDrop = new FileDrop(this, new FileDrop.Listener() {

        @Override
        public void filesDropped(java.io.File[] files) {
            DataManager dm = (DataManager) Services.getService(DataManager.class);
            SourceManager sourceManager = dm.getSourceManager();
            for (File file : files) {
                // For each file, we ensure that we have a driver
                // that can be used to read it. If we don't, we don't
                // open the file.
                if (OrbisConfiguration.isFileEligible(file)) {
                    try {
                        String name = sourceManager
                                .getUniqueName(FilenameUtils.removeExtension(file.getName()));
                        sourceManager.register(name, file);
                    } catch (SourceAlreadyExistsException e) {
                        ErrorMessages.error(ErrorMessages.SourceAlreadyRegistered + ": ", e);
                    }
                }
            }

        }
    });

}

From source file:org.rdv.ui.ChannelListPanel.java

/**
 * Create the channel tree panel.//from  w w  w.ja  v a2 s . c  o m
 * 
 * @return  the component containing the channel tree
 */
private JComponent createTreePanel() {
    treeModel = new ChannelTreeModel();
    treeModel.addPropertyChangeListener(new FilterPropertyChangeListener());

    tree = new JTree(treeModel);
    tree.setRootVisible(false);
    tree.setShowsRootHandles(true);
    tree.setExpandsSelectedPaths(true);
    tree.setCellRenderer(new ChannelTreeCellRenderer());
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    tree.addTreeSelectionListener(new ChannelTreeSelectionListener());
    tree.addMouseListener(new ChannelTreeMouseListener());
    tree.setBorder(new EmptyBorder(0, 5, 5, 5));

    JScrollPane treeView = new JScrollPane(tree);
    treeView.setBorder(null);
    treeView.setViewportBorder(null);

    tree.setDragEnabled(true);
    tree.setTransferHandler(new ChannelTransferHandler());

    DragSource dragSource = DragSource.getDefaultDragSource();
    dragSource.createDefaultDragGestureRecognizer(tree, DnDConstants.ACTION_LINK,
            new ChannelDragGestureListener());

    return treeView;
}

From source file:org.rdv.ui.DataPanelContainer.java

/**
 * Add a data panel UI component to this container.
 * /*w  ww.j a v  a 2 s .com*/
 * @param component  the UI component to add
 * @since            1.1
 */
public void addDataPanel(JComponent component) {
    Integer position = previousPositions.get(component);
    if (position == null || position < 0 || position > dataPanels.size()) {
        dataPanels.add(component);
    } else {
        dataPanels.add(position, component);
    }

    DragSource dragSource = DragSource.getDefaultDragSource();
    DragGestureRecognizer dragGesture = dragSource.createDefaultDragGestureRecognizer(component,
            DnDConstants.ACTION_MOVE, this);
    dragGestures.put(component, dragGesture);

    layoutDataPanels();

    log.info("Added data panel to container (total=" + dataPanels.size() + ").");
}

From source file:ro.nextreports.designer.querybuilder.DBBrowserTree.java

/**
 * Constructor//ww  w  .j  a v a  2  s .  co  m
 *
 * @param typeRoot            is used to create the tree starting from a specific type node
 * @param registerDoubleClick register mouse double click on tree
 */
public DBBrowserTree(byte typeRoot, boolean registerDoubleClick) {
    super();
    this.typeRoot = typeRoot;
    populateTree(typeRoot);

    setCellRenderer(new DBBrowserTreeRenderer());
    getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    setRolloverEnabled(true);
    addHighlighter(new ColorHighlighter(HighlightPredicate.ROLLOVER_ROW, null, Color.RED));

    DragGestureRecognizer dgr = DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer(this,
            DnDConstants.ACTION_COPY_OR_MOVE, new DBBrowserTreeDragGestureListener());

    DBBrowserTreeDropListener dropListener = new DBBrowserTreeDropListener();
    addTreeSelectionListener(dropListener);
    setDropTarget(new DropTarget(this, dropListener));

    if (registerDoubleClick) {
        addMouseDoubleClickListener();
    }

    instance = this;

    // single data source autoconnect
    DataSourceManager manager = DefaultDataSourceManager.getInstance();
    List<DataSource> sources = manager.getDataSources();
    if (sources.size() == 1) {
        if (Globals.singleSourceAutoConnect()) {
            DataSource ds = manager.getConnectedDataSource();
            if (ds == null) {
                connectToDataSource(sources.get(0).getName());
            }
        }
    } else {
        String dataSourceName = Globals.getSystemDataSource();
        DataSource ds = manager.getDataSource(dataSourceName);
        if (ds != null) {
            connectToDataSource(dataSourceName);
        }
    }
}

From source file:unikn.dbis.univis.explorer.VExplorer.java

License:asdf

private void initDragAndDrop() {
    DragSource dragSource = DragSource.getDefaultDragSource();
    dragSource.addDragSourceListener(tree);
    dragSource.createDefaultDragGestureRecognizer(tree, DnDConstants.ACTION_COPY, tree);
}