当前位置: 首页>>代码示例>>Java>>正文


Java DefaultMutableTreeNode.getParent方法代码示例

本文整理汇总了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);
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:20,代码来源:ProjectWindow.java

示例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;

}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:28,代码来源:DynFormBase.java

示例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();
	
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:32,代码来源:DynForm.java

示例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());
              }
          }
  }
	}
}
 
开发者ID:guilhebl,项目名称:routerapp,代码行数:27,代码来源:NavigationView.java

示例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;
  }
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:24,代码来源:ConfigureTree.java

示例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();
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:16,代码来源:DynamicTree.java

示例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;
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:15,代码来源:ExtensionTree.java

示例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;
  }
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:38,代码来源:ExtensionTree.java

示例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;
  }
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:28,代码来源:ConfigureTree.java

示例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);
            }
        }
    }
}
 
开发者ID:dmitrykolesnikovich,项目名称:featurea,代码行数:44,代码来源:SimulationTreePanel.java

示例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);
            }
        }
    }
}
 
开发者ID:dmitrykolesnikovich,项目名称:featurea,代码行数:37,代码来源:SimulationTreePanel.java

示例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);
    }
}
 
开发者ID:hykes,项目名称:CodeGen,代码行数:10,代码来源:TemplateRemoveAction.java

示例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);
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:11,代码来源:DynTableJPanel.java

示例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;
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:77,代码来源:DynForm.java

示例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);
	
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:47,代码来源:DynForm.java


注:本文中的javax.swing.tree.DefaultMutableTreeNode.getParent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。