Search in sources :

Example 1 with TreePath

use of javax.swing.tree.TreePath in project antlrworks by antlr.

the class XJTree method dragOver.

public void dragOver(DropTargetDragEvent event) {
    int x = event.getLocation().x;
    int y = event.getLocation().y;
    TreePath p = getClosestPathForLocation(x, y);
    if (p != lastPath) {
        lastPath = p;
        autoExpandTimer.restart();
    }
    if (p == null || event.getDropAction() != getDelegateConstants()) {
        cleanUpAfterDrag();
        event.rejectDrag();
    } else {
        event.acceptDrag(getDelegateConstants());
        Graphics2D g2d = (Graphics2D) getGraphics();
        Rectangle rpath = getPathBounds(lastPath);
        Rectangle oldCueLine = (Rectangle) cueLine.clone();
        if (y < rpath.y + rpath.height / 2) {
            if (getRowForPath(lastPath) == 0) {
                cueLine.setRect(0, rpath.y, getWidth(), 2);
            } else {
                cueLine.setRect(0, rpath.y - 1, getWidth(), 2);
            }
            dropLocation = DROP_ABOVE;
        } else {
            cueLine.setRect(0, rpath.y + rpath.height - 1, getWidth(), 2);
            dropLocation = DROP_BELOW;
        }
        if (!oldCueLine.equals(cueLine)) {
            paintImmediately(oldCueLine);
        }
        g2d.setColor(Color.black);
        g2d.fill(cueLine);
    }
}
Also used : TreePath(javax.swing.tree.TreePath)

Example 2 with TreePath

use of javax.swing.tree.TreePath in project antlrworks by antlr.

the class XJTree method createDragImage.

public void createDragImage(DragGestureEvent event) {
    Point dragOrigin = event.getDragOrigin();
    TreePath path = getPathForLocation(dragOrigin.x, dragOrigin.y);
    Rectangle r = getPathBounds(path);
    dragImageOffset.setLocation(dragOrigin.x - r.x, dragOrigin.y - r.y);
    JLabel label = (JLabel) getCellRenderer().getTreeCellRendererComponent(this, path.getLastPathComponent(), false, isExpanded(path), getModel().isLeaf(path.getLastPathComponent()), 0, false);
    label.setSize(r.width, r.height);
    dragImage = new BufferedImage(r.width, r.height, BufferedImage.TYPE_INT_ARGB_PRE);
    Graphics2D g2d = dragImage.createGraphics();
    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, 0.5f));
    label.paint(g2d);
    g2d.dispose();
}
Also used : TreePath(javax.swing.tree.TreePath) BufferedImage(java.awt.image.BufferedImage)

Example 3 with TreePath

use of javax.swing.tree.TreePath in project zookeeper by apache.

the class ZooInspectorTreeViewer method getSelectedNodes.

/**
     * @return {@link List} of the currently selected nodes
     */
public List<String> getSelectedNodes() {
    TreePath[] paths = tree.getSelectionPaths();
    List<String> selectedNodes = new ArrayList<String>();
    if (paths != null) {
        for (TreePath path : paths) {
            StringBuilder sb = new StringBuilder();
            Object[] pathArray = path.getPath();
            for (Object o : pathArray) {
                String nodeName = o.toString();
                if (nodeName.length() > 0) {
                    sb.append("/");
                    sb.append(o.toString());
                }
            }
            selectedNodes.add(sb.toString());
        }
    }
    return selectedNodes;
}
Also used : TreePath(javax.swing.tree.TreePath) ArrayList(java.util.ArrayList)

Example 4 with TreePath

use of javax.swing.tree.TreePath in project darkFunction-Editor by darkFunction.

the class SpritesheetController method refreshSpriteInfoPanel.

private void refreshSpriteInfoPanel() {
    spriteInfoPanel.setSprite(" ", null, null);
    TreePath[] parentPaths = nameTree.getSelectionPaths();
    CustomNode selectedNode = null;
    if (parentPaths != null) {
        for (int i = 0; i < parentPaths.length; ++i) {
            TreePath parentPath = parentPaths[i];
            selectedNode = (CustomNode) (parentPath.getLastPathComponent());
            if (selectedNode.isLeaf() && parentPaths.length == 1) {
                SelectionBox spriteArea = (SelectionBox) selectedNode.getCustomObject();
                SpriteGraphic graphic = new SpriteGraphic(viewPanel.getImage(), new java.awt.Point(0, 0), spriteArea.getRect());
                spriteInfoPanel.setSprite(selectedNode.getFullPathName(), spriteArea.getRect(), graphic);
            }
        }
    }
}
Also used : TreePath(javax.swing.tree.TreePath)

Example 5 with TreePath

use of javax.swing.tree.TreePath in project darkFunction-Editor by darkFunction.

the class SpritesheetController method nameTreeValueChanged.

private void nameTreeValueChanged(javax.swing.event.TreeSelectionEvent evt) {
    refreshSpriteInfoPanel();
    ArrayList<GraphicObject> nowSelected = new ArrayList<GraphicObject>();
    TreePath[] parentPaths = nameTree.getSelectionPaths();
    CustomNode selectedNode = null;
    if (parentPaths != null) {
        for (int i = 0; i < parentPaths.length; ++i) {
            TreePath parentPath = parentPaths[i];
            selectedNode = (CustomNode) (parentPath.getLastPathComponent());
            if (selectedNode.isLeaf()) {
                GraphicObject selectedGraphic = (GraphicObject) selectedNode.getCustomObject();
                if (selectedGraphic != null) {
                    selectedGraphic.setSelected(true);
                    viewPanel.bringGraphicToFront(selectedGraphic);
                    nowSelected.add(selectedGraphic);
                }
            } else {
                _lastSelectedDirNode = (CustomNode) nameTree.getSelectedNodeDir();
            }
        }
        removeSpriteButton.setEnabled(true);
        addSpriteButton.setEnabled(true);
        addFolderButton.setEnabled(true);
    } else {
        addSpriteButton.setEnabled(false);
        addFolderButton.setEnabled(false);
        removeSpriteButton.setEnabled(false);
    }
    ArrayList<GraphicObject> graphics = viewPanel.selectedGraphics();
    for (int i = 0; i < graphics.size(); ++i) {
        GraphicObject go = graphics.get(i);
        if (!nowSelected.contains(go))
            go.setSelected(false);
    }
    viewPanel.repaint();
}
Also used : TreePath(javax.swing.tree.TreePath) ArrayList(java.util.ArrayList)

Aggregations

TreePath (javax.swing.tree.TreePath)539 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)177 ArrayList (java.util.ArrayList)58 TreeNode (javax.swing.tree.TreeNode)56 Nullable (org.jetbrains.annotations.Nullable)49 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)46 JTree (javax.swing.JTree)34 NotNull (org.jetbrains.annotations.NotNull)32 Test (org.junit.Test)22 Tree (com.intellij.ui.treeStructure.Tree)21 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)21 TreeSelectionListener (javax.swing.event.TreeSelectionListener)21 MouseEvent (java.awt.event.MouseEvent)18 Point (java.awt.Point)17 ActionEvent (java.awt.event.ActionEvent)15 KeyEvent (java.awt.event.KeyEvent)12 EVTask (net.sourceforge.processdash.ev.EVTask)12 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 KeyAdapter (java.awt.event.KeyAdapter)11 List (java.util.List)11