javax.swing.tree.DefaultTreeCellEditor Java Examples
The following examples show how to use
javax.swing.tree.DefaultTreeCellEditor.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProgramTreePlugin1Test.java From ghidra with Apache License 2.0 | 6 votes |
@Test public void testCreateFolderDuplicate() throws Exception { setSelectionPath(root.getTreePath()); final String newName = tree.getNewFolderName(); final DockingActionIf createFolderAction = getAction("Create Folder"); final JTextField[] newFolderTextField = new JTextField[1]; runSwing(() -> { createFolderAction.actionPerformed(new ActionContext()); program.flushEvents(); int row = tree.getRowForPath(tree.getEditingPath()); DefaultTreeCellEditor cellEditor = (DefaultTreeCellEditor) tree.getCellEditor(); Container container = (Container) cellEditor.getTreeCellEditorComponent(tree, tree.getEditingPath().getLastPathComponent(), true, true, true, row); newFolderTextField[0] = (JTextField) container.getComponent(0); newFolderTextField[0].setText("test1"); tree.stopEditing(); }); final String[] text = new String[1]; runSwing(() -> text[0] = newFolderTextField[0].getText()); assertEquals(newName, text[0]); }
Example #2
Source File: ProgramTreePlugin1Test.java From ghidra with Apache License 2.0 | 6 votes |
@Test public void testCreateFragmentDuplicate() throws Exception { setSelectionPath(root.getTreePath()); final String newName = tree.getNewFragmentName(); final DockingActionIf createFragmentAction = getAction("Create Fragment"); final JTextField[] newFragmentTextField = new JTextField[1]; runSwing(() -> { createFragmentAction.actionPerformed(new ActionContext()); program.flushEvents(); int row = tree.getRowForPath(tree.getEditingPath()); DefaultTreeCellEditor cellEditor = (DefaultTreeCellEditor) tree.getCellEditor(); Container container = (Container) cellEditor.getTreeCellEditorComponent(tree, tree.getEditingPath().getLastPathComponent(), true, true, true, row); newFragmentTextField[0] = (JTextField) container.getComponent(0); newFragmentTextField[0].setText("test1"); tree.stopEditing(); }); final String[] text = new String[1]; runSwing(() -> text[0] = newFragmentTextField[0].getText()); assertEquals(newName, text[0]); }
Example #3
Source File: FrontEndPluginActionsTest.java From ghidra with Apache License 2.0 | 6 votes |
@Test public void testRenameFile() throws Exception { final GTreeNode npNode = rootNode.getChild("notepad"); setSelectionPath(npNode.getTreePath()); DockingActionIf renameAction = getAction("Rename"); performAction(renameAction, getDomainFileActionContext(), true); waitForTree(); // select "Rename" action SwingUtilities.invokeAndWait(() -> { int row = tree.getRowForPath(npNode.getTreePath()); DefaultTreeCellEditor cellEditor = (DefaultTreeCellEditor) tree.getCellEditor(); JTree jTree = (JTree) getInstanceField("tree", tree); Container container = (Container) cellEditor.getTreeCellEditorComponent(jTree, npNode, true, true, false, row); JTextField textField = (JTextField) container.getComponent(0); textField.setText("My_notepad"); tree.stopEditing(); }); waitForSwing(); assertNotNull(rootNode.getChild("My_notepad")); assertNull(rootNode.getChild("notepad")); }
Example #4
Source File: SymbolTreePlugin1Test.java From ghidra with Apache License 2.0 | 6 votes |
@Test public void testCreateNamespace() throws Exception { showSymbolTree(); GTreeNode newNsNode = createNewNamespace(); // // Also, check the editors contents // TreePath path = newNsNode.getTreePath(); int row = tree.getRowForPath(path); DefaultTreeCellEditor cellEditor = (DefaultTreeCellEditor) tree.getCellEditor(); JTree jTree = (JTree) AbstractGenericTest.getInstanceField("tree", tree); Container container = (Container) cellEditor.getTreeCellEditorComponent(jTree, newNsNode, true, true, true, row); JTextField textField = (JTextField) container.getComponent(0); assertEquals("NewNamespace", textField.getText()); }
Example #5
Source File: SymbolTreePlugin1Test.java From ghidra with Apache License 2.0 | 6 votes |
private void setEditorText(final TreePath path, final GTreeNode nsNode, final String newName) throws InterruptedException, InvocationTargetException { SwingUtilities.invokeAndWait(() -> { int row = tree.getRowForPath(path); DefaultTreeCellEditor cellEditor = (DefaultTreeCellEditor) tree.getCellEditor(); JTree jTree = (JTree) AbstractGenericTest.getInstanceField("tree", tree); Container container = (Container) cellEditor.getTreeCellEditorComponent(jTree, nsNode, true, true, true, row); JTextField textField = (JTextField) container.getComponent(0); textField.setText(newName); tree.stopEditing(); }); flushAndWaitForTree(); }
Example #6
Source File: SynthTreeUI.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
/** * {@inheritDoc} */ @Override protected TreeCellEditor createDefaultCellEditor() { TreeCellRenderer renderer = tree.getCellRenderer(); DefaultTreeCellEditor editor; if(renderer != null && (renderer instanceof DefaultTreeCellRenderer)) { editor = new SynthTreeCellEditor(tree, (DefaultTreeCellRenderer) renderer); } else { editor = new SynthTreeCellEditor(tree, null); } return editor; }
Example #7
Source File: SynthTreeUI.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * {@inheritDoc} */ @Override protected TreeCellEditor createDefaultCellEditor() { TreeCellRenderer renderer = tree.getCellRenderer(); DefaultTreeCellEditor editor; if(renderer != null && (renderer instanceof DefaultTreeCellRenderer)) { editor = new SynthTreeCellEditor(tree, (DefaultTreeCellRenderer) renderer); } else { editor = new SynthTreeCellEditor(tree, null); } return editor; }
Example #8
Source File: SynthTreeUI.java From Bytecoder with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override protected TreeCellEditor createDefaultCellEditor() { TreeCellRenderer renderer = tree.getCellRenderer(); DefaultTreeCellEditor editor; if(renderer != null && (renderer instanceof DefaultTreeCellRenderer)) { editor = new SynthTreeCellEditor(tree, (DefaultTreeCellRenderer) renderer); } else { editor = new SynthTreeCellEditor(tree, null); } return editor; }
Example #9
Source File: SynthTreeUI.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * {@inheritDoc} */ @Override protected TreeCellEditor createDefaultCellEditor() { TreeCellRenderer renderer = tree.getCellRenderer(); DefaultTreeCellEditor editor; if(renderer != null && (renderer instanceof DefaultTreeCellRenderer)) { editor = new SynthTreeCellEditor(tree, (DefaultTreeCellRenderer) renderer); } else { editor = new SynthTreeCellEditor(tree, null); } return editor; }
Example #10
Source File: SynthTreeUI.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * {@inheritDoc} */ @Override protected TreeCellEditor createDefaultCellEditor() { TreeCellRenderer renderer = tree.getCellRenderer(); DefaultTreeCellEditor editor; if(renderer != null && (renderer instanceof DefaultTreeCellRenderer)) { editor = new SynthTreeCellEditor(tree, (DefaultTreeCellRenderer) renderer); } else { editor = new SynthTreeCellEditor(tree, null); } return editor; }
Example #11
Source File: SynthTreeUI.java From Java8CN with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override protected TreeCellEditor createDefaultCellEditor() { TreeCellRenderer renderer = tree.getCellRenderer(); DefaultTreeCellEditor editor; if(renderer != null && (renderer instanceof DefaultTreeCellRenderer)) { editor = new SynthTreeCellEditor(tree, (DefaultTreeCellRenderer) renderer); } else { editor = new SynthTreeCellEditor(tree, null); } return editor; }
Example #12
Source File: SynthTreeUI.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * {@inheritDoc} */ @Override protected TreeCellEditor createDefaultCellEditor() { TreeCellRenderer renderer = tree.getCellRenderer(); DefaultTreeCellEditor editor; if(renderer != null && (renderer instanceof DefaultTreeCellRenderer)) { editor = new SynthTreeCellEditor(tree, (DefaultTreeCellRenderer) renderer); } else { editor = new SynthTreeCellEditor(tree, null); } return editor; }
Example #13
Source File: SynthTreeUI.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * {@inheritDoc} */ @Override protected TreeCellEditor createDefaultCellEditor() { TreeCellRenderer renderer = tree.getCellRenderer(); DefaultTreeCellEditor editor; if(renderer != null && (renderer instanceof DefaultTreeCellRenderer)) { editor = new SynthTreeCellEditor(tree, (DefaultTreeCellRenderer) renderer); } else { editor = new SynthTreeCellEditor(tree, null); } return editor; }
Example #14
Source File: SynthTreeUI.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * {@inheritDoc} */ @Override protected TreeCellEditor createDefaultCellEditor() { TreeCellRenderer renderer = tree.getCellRenderer(); DefaultTreeCellEditor editor; if(renderer != null && (renderer instanceof DefaultTreeCellRenderer)) { editor = new SynthTreeCellEditor(tree, (DefaultTreeCellRenderer) renderer); } else { editor = new SynthTreeCellEditor(tree, null); } return editor; }
Example #15
Source File: SynthTreeUI.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * {@inheritDoc} */ @Override protected TreeCellEditor createDefaultCellEditor() { TreeCellRenderer renderer = tree.getCellRenderer(); DefaultTreeCellEditor editor; if(renderer != null && (renderer instanceof DefaultTreeCellRenderer)) { editor = new SynthTreeCellEditor(tree, (DefaultTreeCellRenderer) renderer); } else { editor = new SynthTreeCellEditor(tree, null); } return editor; }
Example #16
Source File: ProjectTree.java From mzmine2 with GNU General Public License v2.0 | 5 votes |
/** * Constructor */ public ProjectTree() { ProjectTreeRenderer renderer = new ProjectTreeRenderer(); setCellRenderer(renderer); DefaultTreeCellEditor editor = new DefaultTreeCellEditor(this, renderer, new ProjectTreeEditor(this)); setCellEditor(editor); setEditable(true); setInvokesStopCellEditing(true); setRootVisible(true); setShowsRootHandles(false); setToggleClickCount(-1); // Activate drag&drop ProjectTreeDnDHandler dndHandler = new ProjectTreeDnDHandler(); setTransferHandler(dndHandler); setDropMode(DropMode.INSERT); setDragEnabled(true); // Attach a handler for handling popup menus and double clicks ProjectTreeMouseHandler popupHandler = new ProjectTreeMouseHandler(this); addMouseListener(popupHandler); }
Example #17
Source File: SynthTreeUI.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * {@inheritDoc} */ @Override protected TreeCellEditor createDefaultCellEditor() { TreeCellRenderer renderer = tree.getCellRenderer(); DefaultTreeCellEditor editor; if(renderer != null && (renderer instanceof DefaultTreeCellRenderer)) { editor = new SynthTreeCellEditor(tree, (DefaultTreeCellRenderer) renderer); } else { editor = new SynthTreeCellEditor(tree, null); } return editor; }
Example #18
Source File: SeaGlassTreeUI.java From seaglass with Apache License 2.0 | 5 votes |
/** * @inheritDoc */ @Override protected TreeCellEditor createDefaultCellEditor() { TreeCellRenderer renderer = tree.getCellRenderer(); DefaultTreeCellEditor editor; if (renderer != null && (renderer instanceof DefaultTreeCellRenderer)) { editor = new SynthTreeCellEditor(tree, (DefaultTreeCellRenderer) renderer); } else { editor = new SynthTreeCellEditor(tree, null); } return editor; }
Example #19
Source File: SynthTreeUI.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
/** * {@inheritDoc} */ @Override protected TreeCellEditor createDefaultCellEditor() { TreeCellRenderer renderer = tree.getCellRenderer(); DefaultTreeCellEditor editor; if(renderer != null && (renderer instanceof DefaultTreeCellRenderer)) { editor = new SynthTreeCellEditor(tree, (DefaultTreeCellRenderer) renderer); } else { editor = new SynthTreeCellEditor(tree, null); } return editor; }
Example #20
Source File: MainPanel.java From java-swing-tips with MIT License | 5 votes |
private static TreeCellEditor makeLeafTreeCellEditor(JTree tree) { return new DefaultTreeCellEditor(tree, (DefaultTreeCellRenderer) tree.getCellRenderer()) { @Override public boolean isCellEditable(EventObject e) { Object o = tree.getLastSelectedPathComponent(); return super.isCellEditable(e) && o instanceof TreeNode && ((TreeNode) o).isLeaf(); } }; }
Example #21
Source File: MainPanel.java From java-swing-tips with MIT License | 5 votes |
private MainPanel() { super(new BorderLayout()); JTree tree = new JTree(); // UIManager.put("PopupMenu.consumeEventOnClose", Boolean.FALSE); // tree.addMouseListener(new MouseAdapter() { // @Override public void mousePressed(MouseEvent e) { // JTree tree = (JTree) e.getSource(); // TreePath path = tree.getPathForLocation(e.getX(), e.getY()); // if (!tree.getSelectionModel().isPathSelected(path)) { // tree.getSelectionModel().setSelectionPath(path); // } // } // }); tree.setCellEditor(new DefaultTreeCellEditor(tree, (DefaultTreeCellRenderer) tree.getCellRenderer()) { // @Override protected boolean shouldStartEditingTimer(EventObject e) { // return false; // } // @Override protected boolean canEditImmediately(EventObject e) { // // ((MouseEvent) e).getClickCount() - 2 >= 0 // return !(e instanceof MouseEvent) && super.canEditImmediately(e); // } @Override public boolean isCellEditable(EventObject e) { return !(e instanceof MouseEvent) && super.isCellEditable(e); } }); tree.setEditable(true); tree.setComponentPopupMenu(new TreePopupMenu()); add(new JScrollPane(tree)); setPreferredSize(new Dimension(320, 240)); }
Example #22
Source File: SynthTreeUI.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * {@inheritDoc} */ @Override protected TreeCellEditor createDefaultCellEditor() { TreeCellRenderer renderer = tree.getCellRenderer(); DefaultTreeCellEditor editor; if(renderer != null && (renderer instanceof DefaultTreeCellRenderer)) { editor = new SynthTreeCellEditor(tree, (DefaultTreeCellRenderer) renderer); } else { editor = new SynthTreeCellEditor(tree, null); } return editor; }
Example #23
Source File: SynthTreeUI.java From JDKSourceCode1.8 with MIT License | 5 votes |
/** * {@inheritDoc} */ @Override protected TreeCellEditor createDefaultCellEditor() { TreeCellRenderer renderer = tree.getCellRenderer(); DefaultTreeCellEditor editor; if(renderer != null && (renderer instanceof DefaultTreeCellRenderer)) { editor = new SynthTreeCellEditor(tree, (DefaultTreeCellRenderer) renderer); } else { editor = new SynthTreeCellEditor(tree, null); } return editor; }
Example #24
Source File: SynthTreeUI.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override protected TreeCellEditor createDefaultCellEditor() { TreeCellRenderer renderer = tree.getCellRenderer(); DefaultTreeCellEditor editor; if(renderer != null && (renderer instanceof DefaultTreeCellRenderer)) { editor = new SynthTreeCellEditor(tree, (DefaultTreeCellRenderer) renderer); } else { editor = new SynthTreeCellEditor(tree, null); } return editor; }
Example #25
Source File: SynthTreeUI.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * {@inheritDoc} */ @Override protected TreeCellEditor createDefaultCellEditor() { TreeCellRenderer renderer = tree.getCellRenderer(); DefaultTreeCellEditor editor; if(renderer != null && (renderer instanceof DefaultTreeCellRenderer)) { editor = new SynthTreeCellEditor(tree, (DefaultTreeCellRenderer) renderer); } else { editor = new SynthTreeCellEditor(tree, null); } return editor; }
Example #26
Source File: FrontEndPluginActionsTest.java From ghidra with Apache License 2.0 | 5 votes |
@Test public void testRenameFolder() throws Exception { rootFolder.createFolder("myFolder"); waitForSwing(); final GTreeNode myNode = rootNode.getChild("myFolder"); setSelectionPath(myNode.getTreePath()); DockingActionIf renameAction = getAction("Rename"); performAction(renameAction, getDomainFileActionContext(), true); waitForTree(); // select "Rename" action SwingUtilities.invokeAndWait(() -> { int row = tree.getRowForPath(myNode.getTreePath()); JTree jTree = (JTree) getInstanceField("tree", tree); DefaultTreeCellEditor cellEditor = (DefaultTreeCellEditor) tree.getCellEditor(); Container container = (Container) cellEditor.getTreeCellEditorComponent(jTree, myNode, true, true, false, row); JTextField textField = (JTextField) container.getComponent(0); textField.setText("MyNewFolder"); tree.stopEditing(); }); waitForSwing(); assertNotNull(rootNode.getChild("MyNewFolder")); assertNull(rootNode.getChild("myFolder")); }
Example #27
Source File: FrontEndPluginActionsTest.java From ghidra with Apache License 2.0 | 5 votes |
@Test public void testNewFolderBlankName() throws Exception { // try entering a blank name final DockingActionIf newFolderAction = getAction("New Folder"); setSelectionPaths(new TreePath[] { rootNode.getTreePath() }); performAction(newFolderAction, getDomainFileActionContext(), true); waitForTree(); SwingUtilities.invokeLater(() -> { GTreeNode node = rootNode.getChild("NewFolder"); int row = tree.getRowForPath(node.getTreePath()); DefaultTreeCellEditor cellEditor = (DefaultTreeCellEditor) tree.getCellEditor(); JTree jTree = (JTree) getInstanceField("tree", tree); Container container = (Container) cellEditor.getTreeCellEditorComponent(jTree, node, true, true, false, row); JTextField textField = (JTextField) container.getComponent(0); textField.setText(""); tree.stopEditing(); }); waitForSwing(); OptionDialog d = waitForDialogComponent(OptionDialog.class); assertNotNull(d); assertEquals("Rename Failed", d.getTitle()); pressButtonByText(d.getComponent(), "OK"); }
Example #28
Source File: SymbolTreeTestUtils.java From ghidra with Apache License 2.0 | 5 votes |
void rename(GTreeNode node, final String newName) throws Exception { selectNode(node); final TreePath path = node.getTreePath(); assertTrue(tree.isPathSelected(path)); final GTreeNode nsNode = node; assertTrue(renameAction.isEnabledForContext(getSymbolTreeContext())); runSwing(() -> renameAction.actionPerformed(getSymbolTreeContext())); waitForTree(); runSwing(() -> { int row = tree.getRowForPath(path); JTree jTree = (JTree) getInstanceField("tree", tree); DefaultTreeCellEditor cellEditor = (DefaultTreeCellEditor) tree.getCellEditor(); Container container = (Container) cellEditor.getTreeCellEditorComponent(jTree, nsNode, true, true, true, row); JTextField textField = (JTextField) container.getComponent(0); textField.setText(newName); tree.stopEditing(); }); program.flushEvents(); waitForSwing(); waitForTree(); }
Example #29
Source File: SymbolTreePlugin1Test.java From ghidra with Apache License 2.0 | 5 votes |
@Test public void testCreateClass() throws Exception { showSymbolTree(); util.selectNode(rootNode.getChild("Classes")); performAction(createClassAction, util.getSymbolTreeContext(), true); GTreeNode cnode = rootNode.getChild(4); util.expandNode(cnode); // wait until NewClass gets added GTreeNode newNode = waitForValue(() -> cnode.getChild(0)); assertNotNull(newNode); Symbol s = ((SymbolNode) newNode).getSymbol(); assertEquals("NewClass", s.getName()); TreePath path = newNode.getTreePath(); int row = tree.getRowForPath(path); JTree jTree = (JTree) AbstractGenericTest.getInstanceField("tree", tree); JTextField tf = runSwing(() -> { DefaultTreeCellEditor cellEditor = (DefaultTreeCellEditor) tree.getCellEditor(); Container container = (Container) cellEditor.getTreeCellEditorComponent(jTree, newNode, true, true, true, row); JTextField textField = (JTextField) container.getComponent(0); return textField; }); assertEquals("NewClass", tf.getText()); }
Example #30
Source File: DataTypeManagerPluginTest.java From ghidra with Apache License 2.0 | 5 votes |
@Test public void testRenameCategoryDuplicate() throws Exception { expandNode(programNode); String miscNodeName = "MISC"; final CategoryNode miscNode = (CategoryNode) programNode.getChild(miscNodeName); assertNotNull(miscNode); expandNode(miscNode); selectNode(miscNode); final DockingActionIf action = getAction(plugin, "Rename"); assertTrue(action.isEnabledForContext(treeContext)); DataTypeTestUtils.performAction(action, tree); waitForTree(); SwingUtilities.invokeLater(() -> { TreePath editingPath = jTree.getEditingPath(); GTreeNode editingNode = (GTreeNode) editingPath.getLastPathComponent(); int rowForPath = jTree.getRowForPath(editingPath); DefaultTreeCellEditor cellEditor = (DefaultTreeCellEditor) tree.getCellEditor(); Container container = (Container) cellEditor.getTreeCellEditorComponent(jTree, editingNode, true, true, true, rowForPath); JTextField textField = (JTextField) container.getComponent(0); textField.setText("Category1"); jTree.stopEditing(); }); final OptionDialog d = waitForDialogComponent(OptionDialog.class); runSwing(() -> d.close()); waitForSwing(); assertTrue(!jTree.isEditing()); }