use of javax.swing.tree.DefaultMutableTreeNode in project languagetool by languagetool-org.
the class ConfigurationDialog method getMouseAdapter.
@NotNull
private MouseAdapter getMouseAdapter() {
return new MouseAdapter() {
private void handlePopupEvent(MouseEvent e) {
JTree tree = (JTree) e.getSource();
TreePath path = tree.getPathForLocation(e.getX(), e.getY());
if (path == null) {
return;
}
DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
TreePath[] paths = tree.getSelectionPaths();
boolean isSelected = false;
if (paths != null) {
for (TreePath selectionPath : paths) {
if (selectionPath.equals(path)) {
isSelected = true;
}
}
}
if (!isSelected) {
tree.setSelectionPath(path);
}
if (node.isLeaf()) {
JPopupMenu popup = new JPopupMenu();
JMenuItem aboutRuleMenuItem = new JMenuItem(messages.getString("guiAboutRuleMenu"));
aboutRuleMenuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
RuleNode node = (RuleNode) tree.getSelectionPath().getLastPathComponent();
Rule rule = node.getRule();
Language lang = config.getLanguage();
if (lang == null) {
lang = Languages.getLanguageForLocale(Locale.getDefault());
}
Tools.showRuleInfoDialog(tree, messages.getString("guiAboutRuleTitle"), rule.getDescription(), rule, messages, lang.getShortCodeWithCountryAndVariant());
}
});
popup.add(aboutRuleMenuItem);
popup.show(tree, e.getX(), e.getY());
}
}
@Override
public void mousePressed(MouseEvent e) {
if (e.isPopupTrigger()) {
handlePopupEvent(e);
}
}
@Override
public void mouseReleased(MouseEvent e) {
if (e.isPopupTrigger()) {
handlePopupEvent(e);
}
}
};
}
use of javax.swing.tree.DefaultMutableTreeNode in project smile by haifengl.
the class SmileDemo method valueChanged.
/** Required by TreeSelectionListener interface. */
@Override
public void valueChanged(TreeSelectionEvent e) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
if (node != null && node.isLeaf()) {
int pos = workspace.getDividerLocation();
workspace.setTopComponent((JPanel) node.getUserObject());
workspace.setDividerLocation(pos);
}
}
use of javax.swing.tree.DefaultMutableTreeNode in project binnavi by google.
the class CRootTagTreeNode method refreshTree.
/**
* Rebuilds the entire tree from scratch by filtering over all elements in the graph. This is
* pretty damn slow for any reasonably-sized graph, and should hence be done only rarely.
* @deprecated
*/
@Deprecated
@Override
public void refreshTree(final ITreeNode<CTag> tag) {
final List<DefaultMutableTreeNode> lastNodes = TreeHelpers.getLastExpandedNodes(m_tagsTree);
final List<Integer> lastNodeIds = new ArrayList<Integer>();
if ((tag != null) && (tag.getParent() != null)) {
lastNodeIds.add(tag.getParent().getObject().getId());
}
for (final DefaultMutableTreeNode lastNode : lastNodes) {
if (lastNode.getUserObject() instanceof Integer) {
final int tagId = (Integer) lastNode.getUserObject();
lastNodeIds.add(tagId);
}
}
deleteChildren();
createChildren();
final Enumeration<?> bfn = breadthFirstEnumeration();
while (bfn.hasMoreElements()) {
final Object node = bfn.nextElement();
int tagId = -1;
TreePath path = null;
if (node instanceof CRootTagTreeNode) {
final CRootTagTreeNode rootNode = (CRootTagTreeNode) node;
tagId = m_rootTag.getObject().getId();
path = new TreePath(rootNode.getPath());
} else if (node instanceof CTagTreeNode) {
final CTagTreeNode treeNode = (CTagTreeNode) node;
tagId = treeNode.getTag().getObject().getId();
path = new TreePath(treeNode.getPath());
} else if (node instanceof CTaggedGraphNodesContainerNode) {
final CTaggedGraphNodesContainerNode containerNode = (CTaggedGraphNodesContainerNode) node;
tagId = -containerNode.getTag().getObject().getId();
path = new TreePath(containerNode.getPath());
}
if (lastNodeIds.contains(tagId)) {
m_tagsTree.expandPath(path);
}
}
}
use of javax.swing.tree.DefaultMutableTreeNode in project binnavi by google.
the class AbstractTreeTransferHandler method drop.
@Override
public final void drop(final DropTargetDropEvent dtde) {
if (drawImage) {
clearImage();
}
final int action = dtde.getDropAction();
final Transferable transferable = dtde.getTransferable();
final Point pt = dtde.getLocation();
if (transferable.isDataFlavorSupported(TransferableNode.NODE_FLAVOR) && canPerformAction(tree, draggedNode, action, pt)) {
boolean gotData = false;
DefaultMutableTreeNode node = null;
try {
node = (DefaultMutableTreeNode) transferable.getTransferData(TransferableNode.NODE_FLAVOR);
gotData = true;
} catch (final IOException e) {
// TODO: This should be properly logged
System.out.println(e);
} catch (final UnsupportedFlavorException e) {
// TODO: This should be properly logged
System.out.println(e);
}
if (gotData) {
final TreePath pathTarget = tree.getPathForLocation(pt.x, pt.y);
final DefaultMutableTreeNode newParentNode = (DefaultMutableTreeNode) pathTarget.getLastPathComponent();
if (executeDrop(tree, node, newParentNode, action)) {
dtde.acceptDrop(action);
dtde.dropComplete(true);
return;
}
}
} else if (canPerformAction(tree, dtde.getCurrentDataFlavors()[0], dtde.getTransferable(), action, pt)) {
final TreePath pathTarget = tree.getPathForLocation(pt.x, pt.y);
final DefaultMutableTreeNode newParentNode = (DefaultMutableTreeNode) pathTarget.getLastPathComponent();
if (executeDrop(tree, dtde.getTransferable(), newParentNode, action)) {
dtde.acceptDrop(action);
dtde.dropComplete(true);
return;
}
}
dtde.rejectDrop();
dtde.dropComplete(false);
}
use of javax.swing.tree.DefaultMutableTreeNode in project binnavi by google.
the class CProjectTree method showPopupMenu.
/**
* Shows a popup menu that depends on the node that was clicked.
*
* @param event The event to handle.
*/
private void showPopupMenu(final MouseEvent event) {
final IProjectTreeNode selectedNode = (IProjectTreeNode) TreeHelpers.getNodeAt(this, event.getX(), event.getY());
if (selectedNode == null) {
// Show the default menu
m_popup.show(this, event.getX(), event.getY());
} else {
setSelectionPath(new TreePath(((DefaultMutableTreeNode) selectedNode).getPath()));
final JPopupMenu menu = selectedNode.getPopupMenu();
if (menu != null) {
menu.show(this, event.getX(), event.getY());
}
}
}
Aggregations