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);
}
}
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();
}
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;
}
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);
}
}
}
}
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();
}
Aggregations