Search in sources :

Example 1 with DragSourceAdapter

use of java.awt.dnd.DragSourceAdapter in project airavata by apache.

the class ComponentSelector method initGUI.

private void initGUI() {
    this.treeModel = new ComponentTreeModel(new ComponentTreeNode("Components"));
    this.tree = new JTree(this.treeModel);
    // Add a tool tip.
    ToolTipManager.sharedInstance().registerComponent(this.tree);
    DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer() {

        @Override
        public java.awt.Component getTreeCellRendererComponent(JTree t, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean focus) {
            super.getTreeCellRendererComponent(t, value, sel, expanded, leaf, row, focus);
            ComponentTreeNode node = (ComponentTreeNode) value;
            if (node.getComponentReference() == null) {
                setToolTipText(null);
            } else {
                setToolTipText("Drag a component to the composer to add");
            }
            return this;
        }
    };
    // Change icons
    try {
        renderer.setOpenIcon(SwingUtil.createImageIcon("opened.gif"));
        renderer.setClosedIcon(SwingUtil.createImageIcon("closed.gif"));
        renderer.setLeafIcon(SwingUtil.createImageIcon("leaf.gif"));
    } catch (RuntimeException e) {
        logger.warn("Failed to load image icons.  " + "It will use the default icons instead.", e);
    }
    this.tree.setCellRenderer(renderer);
    this.tree.setShowsRootHandles(true);
    this.tree.setEditable(false);
    this.tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    this.tree.addTreeSelectionListener(new TreeSelectionListener() {

        public void valueChanged(TreeSelectionEvent event) {
            // update.
            if (event.isAddedPath()) {
                TreePath path = event.getPath();
                select(path);
            }
        }
    });
    // Drag and dtop
    DragGestureListener dragGestureListener = new DragGestureListener() {

        public void dragGestureRecognized(DragGestureEvent event) {
            ComponentSelector.this.dragGestureRecognized(event);
        }
    };
    DragSource dragSource = DragSource.getDefaultDragSource();
    dragSource.createDefaultDragGestureRecognizer(this.tree, DnDConstants.ACTION_COPY_OR_MOVE, dragGestureListener);
    this.dragSourceListener = new DragSourceAdapter() {
    };
    // Popup
    this.tree.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent event) {
            if (event.isPopupTrigger()) {
                showPopupIfNecessary(event);
            }
        }
    });
    createNodePopupMenu();
}
Also used : DragSourceAdapter(java.awt.dnd.DragSourceAdapter) MouseEvent(java.awt.event.MouseEvent) DragGestureEvent(java.awt.dnd.DragGestureEvent) DragGestureListener(java.awt.dnd.DragGestureListener) MouseAdapter(java.awt.event.MouseAdapter) TreeSelectionListener(javax.swing.event.TreeSelectionListener) DragSource(java.awt.dnd.DragSource) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer) JTree(javax.swing.JTree) WorkflowRuntimeException(org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException) TreePath(javax.swing.tree.TreePath) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Aggregations

DragGestureEvent (java.awt.dnd.DragGestureEvent)1 DragGestureListener (java.awt.dnd.DragGestureListener)1 DragSource (java.awt.dnd.DragSource)1 DragSourceAdapter (java.awt.dnd.DragSourceAdapter)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 JTree (javax.swing.JTree)1 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)1 TreeSelectionListener (javax.swing.event.TreeSelectionListener)1 DefaultTreeCellRenderer (javax.swing.tree.DefaultTreeCellRenderer)1 TreePath (javax.swing.tree.TreePath)1 WorkflowRuntimeException (org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException)1