本文整理汇总了Java中javax.swing.tree.DefaultMutableTreeNode.getIndex方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultMutableTreeNode.getIndex方法的具体用法?Java DefaultMutableTreeNode.getIndex怎么用?Java DefaultMutableTreeNode.getIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.tree.DefaultMutableTreeNode
的用法示例。
在下文中一共展示了DefaultMutableTreeNode.getIndex方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: childIndex
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
/**
* Returns the index of a child of a given node, provided its string value.
*
* @param node The node to search its children.
* @param childValue The value of the child to compare with.
* @return The index.
*/
private int childIndex(final DefaultMutableTreeNode node, final String childValue) {
@SuppressWarnings("unchecked")
Enumeration<DefaultMutableTreeNode> children = node.children();
DefaultMutableTreeNode child = null;
int index = -1;
while (children.hasMoreElements() && index < 0) {
child = children.nextElement();
if (child.getUserObject() != null && childValue.equals(child.getUserObject())) {
index = node.getIndex(child);
}
}
return index;
}
示例2: refreshStates
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
/**
* Refreshes the rendering of the states in a given set.
*/
private void refreshStates(Set<GraphState> refreshables) {
for (GraphState state : refreshables) {
StateTreeNode node = getStateNode(state);
DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
int index = parent.getIndex(node);
node.removeFromParent();
StateTreeNode newNode = createStateNode(state);
parent.insert(newNode, index);
getModel().reload(parent);
setStateExpanded(newNode);
}
}
示例3: 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);
}
示例4: 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;
}
示例5: 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);
}