當前位置: 首頁>>代碼示例>>Java>>正文


Java MutableTreeNode.getChildCount方法代碼示例

本文整理匯總了Java中javax.swing.tree.MutableTreeNode.getChildCount方法的典型用法代碼示例。如果您正苦於以下問題:Java MutableTreeNode.getChildCount方法的具體用法?Java MutableTreeNode.getChildCount怎麽用?Java MutableTreeNode.getChildCount使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.swing.tree.MutableTreeNode的用法示例。


在下文中一共展示了MutableTreeNode.getChildCount方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: refresh

import javax.swing.tree.MutableTreeNode; //導入方法依賴的package包/類
private void refresh(DefaultTreeModel m,
                     ServerStatus.ModuleSummary[] modules) {
  final MutableTreeNode root = (MutableTreeNode) m.getRoot();
  totalPlayers = 0;

  while (root.getChildCount() > 0) {
    m.removeNodeFromParent((MutableTreeNode) root.getChildAt(0));
  }

  if (modules.length == 0) {
    final DefaultMutableTreeNode n = new DefaultMutableTreeNode(
      Resources.getString("Chat.no_connections")); //$NON-NLS-1$
    n.setAllowsChildren(false);
  }
  else {
    for (ServerStatus.ModuleSummary s : modules) {
      m.insertNodeInto(createNode(s), root, root.getChildCount());
    }
  }

  // append total number of players on server to root node
  root.setUserObject(
    Resources.getString(Resources.VASSAL) + " (" + totalPlayers + ")");
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:25,代碼來源:ServerStatusView.java

示例2: removeAllChildren

import javax.swing.tree.MutableTreeNode; //導入方法依賴的package包/類
protected void removeAllChildren(MutableTreeNode parentNode,
			     DefaultTreeModel tree)
   {
Enumeration<?> enm = parentNode.children();
MutableTreeNode[] toRemove =
    new MutableTreeNode[parentNode.getChildCount()];

int i = 0;
while(enm.hasMoreElements()) {
    toRemove[i++] =
	(MutableTreeNode)enm.nextElement();
}
for(i = 0; i < toRemove.length; i++) {
	tree.removeNodeFromParent(toRemove[i]);
	toRemove[i] = null;
}
toRemove = null;
   }
 
開發者ID:nomencurator,項目名稱:taxonaut,代碼行數:19,代碼來源:UnitedNameTreeModel.java

示例3: findIndexFor

import javax.swing.tree.MutableTreeNode; //導入方法依賴的package包/類
private static int findIndexFor(MutableTreeNode child, MutableTreeNode parent) {
  int childCount = parent.getChildCount();
  if (childCount == 0) {
    return 0;
  }
  if (childCount == 1) {
    return NODE_COMPARATOR.compare(child, parent.getChildAt(0)) <= 0 ? 0 : 1;
  }
  return findIndexFor(child, parent, 0, childCount - 1);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:11,代碼來源:ExternalSystemTasksTreeModel.java

示例4: insertNodeInto

import javax.swing.tree.MutableTreeNode; //導入方法依賴的package包/類
public void insertNodeInto(AbstractODKTreeNode newChild, MutableTreeNode parent, int index)
{
	if(index==-1) index = 0;
	
	log.debug("Inserting new child in parent node at index "+index);
	
	try{
		DefaultMutableTreeNode node = (DefaultMutableTreeNode) newChild;
		
		ODKFieldInterface obj = (ODKFieldInterface) node.getUserObject();
		
		if(obj.getTridasClass() == TridasSample.class && parent!=sampleGroup)
		{
			super.insertNodeInto((MutableTreeNode) newChild, sampleGroup, sampleGroup.getChildCount());
			return;
		}
	} catch (Exception e)
	{
		log.debug("exception caught");
		
	}
	
	if(index<=parent.getChildCount()-1)
	{
		super.insertNodeInto((MutableTreeNode)newChild, parent, index);
	}
	else
	{
		super.insertNodeInto((MutableTreeNode)newChild, parent, parent.getChildCount());
	}
}
 
開發者ID:ltrr-arizona-edu,項目名稱:tellervo,代碼行數:32,代碼來源:ODKTreeModel.java

示例5: clipboardTreeElementAdded

import javax.swing.tree.MutableTreeNode; //導入方法依賴的package包/類
private void clipboardTreeElementAdded(ClipboardItem item) {
		if (logger.getEffectiveLevel().equals(Level.DEBUG))
			logger.debug("Adding clipboard item " + item.getName());

		DefaultTreeModel cTreeModel = (DefaultTreeModel) AIBenchJTreeManager.this.clipboardTree.getModel();
		MutableTreeNode cRootNode = (MutableTreeNode) cTreeModel.getRoot();
		for (ClipboardItem item2 : Core.getInstance().getClipboard().getRootItems()) {
			if (item2 == item) {
				DefaultMutableTreeNode newNode = this.createClipNode(item, null, false);
				
				if (newNode != null) {
					DefaultMutableTreeNode parentNode = null;
					if (Boolean.parseBoolean(Workbench.CONFIG.getProperty("clipboardtree.organizebyclass", "true"))) {
						parentNode = AIBenchJTreeManager.locateClassNode(AIBenchJTreeManager.this.clipboardTree, item.getUserData().getClass());//classNodes.get(item.getUserData().getClass());
						if (parentNode == null) {
							String name = item.getUserData().getClass().getSimpleName();
							
							Datatype datatypeAnnot = item.getUserData().getClass().getAnnotation(Datatype.class);
							if(datatypeAnnot!= null && !datatypeAnnot.clipboardClassName().equals("")) {
								name = datatypeAnnot.clipboardClassName();
							}
							
							parentNode = new ClassTreeNode(name, item.getUserData().getClass());
//							classNodes.put(item.getUserData().getClass(), classNode);
							
							// Alphabetic order
							int order = 0;
							while (order < cRootNode.getChildCount() && name.compareTo(cRootNode.getChildAt(order).toString()) > 0) {
								order++;
							}
							cTreeModel.insertNodeInto(parentNode, cRootNode, order);
						}
					} else {
						parentNode = (DefaultMutableTreeNode) cTreeModel.getRoot();
					}
					
					if (parentNode != null) {
						cTreeModel.insertNodeInto(newNode, parentNode, parentNode.getChildCount());
						
						clipboardTree.expandPath(new TreePath(newNode.getPath()));
						clipboardTree.scrollPathToVisible(new TreePath(newNode.getPath()));
						clipboardTree.setSelectionPath(new TreePath(newNode.getPath()));
					}
				}
				
				return;
			}
		}
	}
 
開發者ID:sing-group,項目名稱:aibench-project,代碼行數:50,代碼來源:AIBenchJTreeManager.java

示例6: moveNode

import javax.swing.tree.MutableTreeNode; //導入方法依賴的package包/類
/**
 * Move a node to another node, used to respond to internal drag and drop
 * events corresponding to re-arrangements of this collection structure.
 * Behaviour depends on the relative depths (in t2reference terms where a
 * leaf node has depth 0) of the source and target nodes
 * <ol>
 * <li>If the target is the same depth as the source then this is
 * interpreted as a request to move the source to become a sibling of the
 * target positioned immediately after it in the target's parent's child
 * list.</li>
 * <li>If the target is a lower depth than the source then the target node
 * is re-written to be the node on the target's path to the root with the
 * same depth as the source and treated as above.</li>
 * <li>If the target is at a higher depth than the source by exactly one
 * then this is interpreted as a request to insert the source node at the
 * start of the target's child list.</li>
 * <li>If the target is at a higher depth by more than one the target node
 * is rewritten to be the first child of the target node. If the target node
 * has no children a new node is created, inserted into the target and set
 * as the target for this method, which is called recursively</li>
 * </ol>
 * This method is called before any nodes are modified, and causes the
 * modifications to take place.
 */
public synchronized void moveNode(MutableTreeNode source,
		MutableTreeNode target) {
	// Check that we're not dragging onto ourselves!
	if (source.equals(target))
		return;
	int targetDepth = getNodeDepth(target);
	int sourceDepth = getNodeDepth(source);
	// Handle drag onto a future sibling
	if (sourceDepth == targetDepth) {
		/*
		 * Move the source from wherever it currently is and add it as a
		 * sibling of the target node at an index one higher.
		 */
		removeNodeFromParent(source);
		// Capture the index of the target in its parent
		int targetIndex = getIndexOfChild(target.getParent(), target);
		/*
		 * Insert the source node into the target's parent at the
		 * appropriate index
		 */
		insertNodeInto(source, (MutableTreeNode) target.getParent(),
				targetIndex + 1);
	}
	// Traverse up to find a potential sibling node
	else if (targetDepth < sourceDepth)
		moveNode(source, (MutableTreeNode) target.getParent());
	// Check for a move to an immediate future parent
	else if (targetDepth == sourceDepth + 1) {
		/*
		 * Insert at index 0 in the target, removing from our old parent
		 * first
		 */
		removeNodeFromParent(source);
		insertNodeInto(source, target, 0);
	}
	/*
	 * Otherwise traverse, picking the child at index 0 every time and
	 * creating a new one if required
	 */
	else if (targetDepth > sourceDepth) {
		// Create a new non-leaf node first if needed
		if (target.getChildCount() == 0)
			insertNodeInto(new DefaultMutableTreeNode(null), target, 0);
		/*
		 * Recursively try to move the source to the target's child list at
		 * position 0
		 */
		moveNode(source, (MutableTreeNode) target.getChildAt(0));
	}
}
 
開發者ID:apache,項目名稱:incubator-taverna-workbench,代碼行數:75,代碼來源:PreRegistrationTreeModel.java


注:本文中的javax.swing.tree.MutableTreeNode.getChildCount方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。