本文整理汇总了Java中javax.swing.tree.DefaultMutableTreeNode.getParent方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultMutableTreeNode.getParent方法的具体用法?Java DefaultMutableTreeNode.getParent怎么用?Java DefaultMutableTreeNode.getParent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.tree.DefaultMutableTreeNode
的用法示例。
在下文中一共展示了DefaultMutableTreeNode.getParent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: removeProjectTab
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
@Override
public void removeProjectTab(ProjectWindowTab projectWindowTab) {
DefaultMutableTreeNode node = this.getTreeNode(projectWindowTab.getTitle());
if (node != null) {
DefaultMutableTreeNode pareNode = (DefaultMutableTreeNode) node.getParent();
pareNode.remove(node);
}
JComponent component = projectWindowTab.getJComponentForVisualization();
Container container = component.getParent();
if (container != null) {
container.remove(component);
}
this.tabVector.remove(projectWindowTab);
this.getTreeModel().reload();
this.projectTreeExpand2Level(3, true);
}
示例2: getMultipleNodesAvailable
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
/**
* Provides the Vector of all currently available nodes of the same kind as the current node.
*
* @param currNode The current node of the object structure
* @return the multiple nodes available
*/
private Vector<DefaultMutableTreeNode> getMultipleNodesAvailable(DefaultMutableTreeNode currNode) {
// --- The result vector of all needed nodes ------------------------------------
Vector<DefaultMutableTreeNode> nodesFound = new Vector<DefaultMutableTreeNode>();
// --- Can we find the number of similar nodes to the current one? --------------
DynType currDT = (DynType) currNode.getUserObject();
// --- The current parentNode and the position of the current node --------------
DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) currNode.getParent();
// --- Search for all similar nodes ---------------------------------------------
for (int i = 0; i < parentNode.getChildCount(); i++) {
DefaultMutableTreeNode checkNode = (DefaultMutableTreeNode) parentNode.getChildAt(i);
DynType checkDT = (DynType) checkNode.getUserObject();
if (checkDT.equals(currDT)) {
nodesFound.add(checkNode);
}
}
return nodesFound;
}
示例3: removeMultiple
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
@Override
protected void removeMultiple(DefaultMutableTreeNode node){
// --- Remind all needed informations -------------------------------------------
DefaultMutableTreeNode previousNode = node.getPreviousNode();
DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) node.getParent();
DynType dt = (DynType) node.getUserObject();
JPanel deletePanel = dt.getPanel();
JPanel parentPanel = (JPanel) deletePanel.getParent();
int movement = (deletePanel.getHeight() + 2) * (-1);
// --- Remove node from the parent node and panel -------------------------------
DynType dyntype = (DynType) node.getUserObject();
node.setUserObject(null);
parentNode.remove(node);
this.getTreeNodesByDynType().remove(dyntype);
// --- remove the panel from the parent -----------------------------------------
parentPanel.remove(deletePanel);
parentPanel.validate();
this.setPanelBounds(parentPanel);
// --- Now move the rest of the elements on the form ----------------------------
this.moveAfterAddOrRemove(movement, previousNode);
// --- refresh the GUI ----------------------------------------------------------
this.adjustPreferredSize();
}
示例4: itemSelected
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
/**
* @param e
*/
protected void itemSelected(MouseEvent e) {
if (e.getClickCount() == 2) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
if (node != null) {
if (node.isLeaf())
if (node.getParent() != null) {
if (node.getParent().toString().equals("graphs")) {
for (int i=0 ; i<observers.size() ; i++)
(observers.get(i)).graphSelected(node.toString());
}
else if (node.getParent().toString().equals("animations")) {
for (int i=0 ; i<observers.size() ; i++)
(observers.get(i)).animationSelected(node.toString());
}
else if (node.getParent().toString().equals("algorithms")) {
for (int i=0 ; i<observers.size() ; i++)
(observers.get(i)).algorithmSelected(node.toString());
}
}
}
}
}
示例5: buildDeleteAction
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
protected Action buildDeleteAction(final Configurable target) {
final DefaultMutableTreeNode targetNode = getTreeNode(target);
final Configurable parent = getParent(targetNode);
if (targetNode.getParent() != null) {
return new AbstractAction(deleteCmd) {
private static final long serialVersionUID = 1L;
public void actionPerformed(ActionEvent evt) {
int row = selectedRow;
remove(parent, target);
if (row < getRowCount()) {
setSelectionRow(row);
}
else {
setSelectionRow(row - 1);
}
}
};
}
else {
return null;
}
}
示例6: removeCurrentNode
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
/** Remove the currently selected node. */
public void removeCurrentNode() {
TreePath currentSelection = tree.getSelectionPath();
if (currentSelection != null) {
DefaultMutableTreeNode currentNode = (DefaultMutableTreeNode) (currentSelection.getLastPathComponent());
MutableTreeNode parent = (MutableTreeNode) (currentNode.getParent());
if (parent != null) {
treeModel.removeNodeFromParent(currentNode);
return;
}
}
// Either there was no selection, or the root was selected.
toolkit.beep();
}
示例7: isEditable
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
private boolean isEditable(DefaultMutableTreeNode node) {
if (node != null) {
for (ExtensionElement el :
extension.getComponentsOf(ExtensionElement.class)) {
if (el.getExtension() == node.getUserObject()) {
return true;
}
}
if (node.getParent() instanceof DefaultMutableTreeNode) {
return isEditable((DefaultMutableTreeNode) node.getParent());
}
}
return false;
}
示例8: buildCloneAction
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
protected Action buildCloneAction(final Configurable target) {
final DefaultMutableTreeNode targetNode = getTreeNode(target);
final DefaultMutableTreeNode parentNode =
(DefaultMutableTreeNode) targetNode.getParent();
if (isEditable(parentNode)) {
return super.buildCloneAction(target);
}
if (parentNode != null) {
return new AbstractAction("Clone") {
private static final long serialVersionUID = 1L;
public void actionPerformed(ActionEvent evt) {
Configurable clone = null;
try {
clone = target.getClass().getConstructor().newInstance();
}
catch (Throwable t) {
ReflectionUtils.handleNewInstanceFailure(t, target.getClass());
}
if (clone != null) {
clone.build(target.getBuildElement(Builder.createNewDocument()));
if (insert((Configurable) parentNode.getUserObject(),
clone, parentNode.getChildCount())) {
extension.add(new ExtensionElement(clone, getPath(parentNode)));
}
}
}
};
}
else {
return null;
}
}
示例9: buildCloneAction
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
protected Action buildCloneAction(final Configurable target) {
final DefaultMutableTreeNode targetNode = getTreeNode(target);
if (targetNode.getParent() != null) {
return new AbstractAction("Clone") {
private static final long serialVersionUID = 1L;
public void actionPerformed(ActionEvent evt) {
Configurable clone = null;
try {
clone = target.getClass().getConstructor().newInstance();
}
catch (Throwable t) {
ReflectionUtils.handleNewInstanceFailure(t, target.getClass());
}
if (clone != null) {
clone.build(target.getBuildElement(Builder.createNewDocument()));
insert(getParent(targetNode), clone,
targetNode.getParent().getIndex(targetNode) + 1);
}
}
};
}
else {
return null;
}
}
示例10: removeFixtureAction
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
/**
* Shows a confirmation dialog asking the user if they really want to perform the action.
* <p>
* If the user clicks yes, then the selected fixture is deleted.
*/
private void removeFixtureAction() {
// getProperty the currently selected body
TreePath path = this.tree.getSelectionPath();
// make sure something is selected
if (path != null) {
// getProperty the selected node
DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
// make sure its a body that is selected
if (node.getUserObject() instanceof BodyFixture) {
// getProperty the parent node (a body)
DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
// getProperty the body from the parent node
SandboxBody body = (SandboxBody) parent.getUserObject();
// getProperty the fixture from the node
BodyFixture fixture = (BodyFixture) node.getUserObject();
// make sure they are sure
int choice = JOptionPane.showConfirmDialog(ControlUtilities.getParentWindow(this), MessageFormat
.format(Messages.getString("menu.resources.fixture.remove.warning"), fixture.getUserData(), body.getName()),
Messages.getString("menu.resources.fixture.remove.warning.title"),
JOptionPane.YES_NO_CANCEL_OPTION);
// check the user's choice
if (choice == JOptionPane.YES_OPTION) {
// remove the body from the world
synchronized (Simulation.LOCK) {
// remove the fixture
body.removeFixture(fixture);
// check if the mass is set explicitly or not
if (!body.isMassExplicit()) {
// reset the mass using the type it was before
body.updateMass();
}
}
// remove the node from the tree
this.model.removeNodeFromParent(node);
}
}
}
}
示例11: editFixtureAction
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
/**
* Shows a dialog with fixture options that can be changed.
*/
private void editFixtureAction() {
// getProperty the currently selected body
TreePath path = this.tree.getSelectionPath();
// make sure something is selected
if (path != null) {
// getProperty the selected node
DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
// make sure its a body that is selected
if (node.getUserObject() instanceof BodyFixture) {
// getProperty the parent node (a body)
DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
// getProperty the body from the parent node
SandboxBody body = (SandboxBody) parent.getUserObject();
// getProperty the fixture from the node
BodyFixture fixture = (BodyFixture) node.getUserObject();
// show the edit dialog
synchronized (Simulation.LOCK) {
Convex convex = fixture.getShape();
Image icon;
if (convex instanceof Circle) {
icon = Icons.EDIT_CIRCLE.getImage();
} else if (convex instanceof Rectangle) {
icon = Icons.EDIT_RECTANGLE.getImage();
} else if (convex instanceof Segment) {
icon = Icons.EDIT_SEGMENT.getImage();
} else {
icon = Icons.EDIT_POLYGON.getImage();
}
EditFixtureDialog.show(ControlUtilities.getParentWindow(this), icon, body, fixture);
}
}
}
}
示例12: run
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
@Override
public void run(AnActionButton button) {
DefaultMutableTreeNode selectedNode = getSelectedNode();
if (selectedNode != null && selectedNode.getParent() != null) {
// 删除指定节点
DefaultTreeModel model = (DefaultTreeModel) this.templateTree.getModel();
model.removeNodeFromParent(selectedNode);
}
}
示例13: getStartArgumentIndex
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
/**
* Gets the start argument index of the current {@link DynType}.
* @param dynType the DynType
* @return the start argument index
*/
private int getStartArgumentIndex(DynType dynType) {
DefaultMutableTreeNode child = this.dynForm.getTreeNodeByDynType(dynType);
DefaultMutableTreeNode parent= (DefaultMutableTreeNode) child.getParent();
return parent.getIndex(child);
}
示例14: addSingleMultipleNode
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
@Override
protected DefaultMutableTreeNode addSingleMultipleNode(DefaultMutableTreeNode node, boolean isInnerClass){
// --- Get all needed information about the node, which has to be copied --------
DynType dt = (DynType) node.getUserObject();
String clazz = dt.getClassName();
OntologySingleClassSlotDescription oscsd = dt.getOntologySingleClassSlotDescription();
JPanel oldPanel = dt.getPanel();
JPanel parentPanel = (JPanel) oldPanel.getParent();
// --- Get parent node ----------------------------------------------------------
DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) node.getParent();
int depth2WorkOn = parentNode.getLevel()-1;
// --- Create the panel/node as needed as a copy of the current node ------------
JPanel blindPanel = new JPanel();
blindPanel.setLayout(null);
DefaultMutableTreeNode newNode = null;
if (isInnerClass==true) {
newNode = this.createInnerElements(oscsd, clazz, depth2WorkOn+1, blindPanel, parentNode, true);
if (oldPanel.isVisible()==false) {
// --- Case special class: set invisible and small ------------
this.setJPanelInvisibleAndSmall(newNode);
}
} else {
newNode = this.createOuterElements(oscsd, depth2WorkOn, blindPanel, parentNode, true);
}
// --- Place the node at the right position in the tree -------------------------
newNode.removeFromParent();
int nodeIndexPos = parentNode.getIndex(node)+1;
objectTree.insertNodeInto(newNode, parentNode, nodeIndexPos);
// --- Set the size of the new Panel --------------------------------------------
DynType dtNew = (DynType) newNode.getUserObject();
JPanel newPanel = dtNew.getPanel();
// --- Layout the new panel -----------------------------------------------------
if (oldPanel.isVisible()==true) {
// ----------------------------------------------------------------
// --- The normal case for visible classes ------------------------
// ----------------------------------------------------------------
this.setPanelBounds(newPanel);
newPanel.setPreferredSize(newPanel.getSize());
// --- Now place the new sub panel on the right super panel -------
int movement = oldPanel.getHeight() + 2;
int xPos = oldPanel.getX();
int yPos = oldPanel.getY() + movement;
newPanel.setBounds(xPos, yPos, newPanel.getWidth(), newPanel.getHeight());
// --- Add to parent panel ----------------------------------------
parentPanel.add(newPanel);
parentPanel.validate();
this.setPanelBounds(parentPanel);
// --- Now move the rest of the elements on the form ----------------------------
this.moveAfterAddOrRemove(movement, newNode);
} else {
// ----------------------------------------------------------------
// --- The case for special classes, that have to be invisible ----
// ----------------------------------------------------------------
newPanel.setVisible(false);
newPanel.setBounds(oldPanel.getBounds());
}
// --- refresh the GUI ----------------------------------------------------------
this.adjustPreferredSize();
return newNode;
}
示例15: moveAfterAddOrRemove
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
/**
* Move all elements which are available after the node given by the parameter node.
*
* @param movement the movement
* @param node the node
*/
private void moveAfterAddOrRemove(int movement, DefaultMutableTreeNode node) {
if (node==this.getRootNode()) return;
DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) node.getParent();
JPanel parentPanel = null;
if (parentNode.getUserObject() instanceof DynType) {
DynType dynType = (DynType) parentNode.getUserObject();
parentPanel = dynType.getPanel();
}
int numOfChilds = parentNode.getChildCount();
int indexOfNextNode = parentNode.getIndex(node) + 1;
for (int i = indexOfNextNode; i < numOfChilds; i++) {
DefaultMutableTreeNode currNode = (DefaultMutableTreeNode) parentNode.getChildAt(i);
DynType dt = (DynType) currNode.getUserObject();
JPanel movePanel = dt.getPanel();
movePanel.setBounds(movePanel.getX(), movePanel.getY()+movement, movePanel.getWidth(), movePanel.getHeight());
JComponent parentComp = (JComponent) movePanel.getParent();
parentComp.validate();
if (parentComp instanceof JPanel) {
this.setPanelBounds((JPanel) parentComp);
}
}
// --- Configure size of parent panel -----------------------
if (parentPanel!=null) {
parentPanel.validate();
this.setPanelBounds(parentPanel);
}
// --- do the same at the parent node -----------------------
this.moveAfterAddOrRemove(movement, parentNode);
}