Java Code Examples for javax.swing.tree.DefaultMutableTreeNode#getChildAfter()

The following examples show how to use javax.swing.tree.DefaultMutableTreeNode#getChildAfter() . 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: DefaultModulesPanel.java    From opt4j with MIT License 6 votes vote down vote up
/**
 * Removes empty categories. This method can create some new empty
 * categories!
 * 
 * @param current
 *            the current node
 * @return true if an empty category was removed
 */
private boolean removeEmptyCategories(DefaultMutableTreeNode current) {
	if (!current.children().hasMoreElements()) {
		return false;
	}

	TreeNode node = current.getFirstChild();
	boolean removed = false;
	while (node != null) {
		DefaultMutableTreeNode n = (DefaultMutableTreeNode) node;
		node = current.getChildAfter(n);

		if (n.isLeaf()) {
			if (n instanceof CategoryTreeNode && n.getChildCount() == 0) {
				DefaultMutableTreeNode parent = (DefaultMutableTreeNode) n.getParent();
				parent.remove(n);
				removed = true;
			}
		} else {
			removed = removed || removeEmptyCategories(n);
		}
	}
	return removed;
}
 
Example 2
Source File: HigherPlayer.java    From HubPlayer with GNU General Public License v3.0 6 votes vote down vote up
public void next() {
	DefaultMutableTreeNode list = (DefaultMutableTreeNode) playingSong
			.getParent();
	SongNode songNode = null;

	if (!IsPlayNextSong) {
		songNode = (SongNode) list.getChildBefore(playingSong);

	} else {
		songNode = (SongNode) list.getChildAfter(playingSong);
	}
	if (songNode == null) {
		IsPause = false;

		return;
	}
	// 在当前所在的歌曲列表路径中加入待播放的歌曲 形成待播放歌曲的路径
	TreePath songPath = currentListPath.pathByAddingChild(songNode);
	tree.setSelectionPath(songPath);

	if (songNode.getHTTPFlag())
		load(songNode, songNode.getDataURL());
	else
		load(songNode);
}
 
Example 3
Source File: HigherPlayer.java    From HubPlayer with GNU General Public License v3.0 6 votes vote down vote up
private void cycle() {
	DefaultMutableTreeNode list = (DefaultMutableTreeNode) playingSong
			.getParent();
	SongNode songNode = null;

	songNode = (SongNode) list.getChildAfter(playingSong);

	if (songNode == null) {
		songNode = (SongNode) list.getFirstChild();
	}

	// 在当前所在的歌曲列表路径中加入待播放的歌曲 形成待播放歌曲的路径
	TreePath songPath = currentListPath.pathByAddingChild(songNode);
	tree.setSelectionPath(songPath);

	if (songNode.getHTTPFlag())
		load(songNode, songNode.getDataURL());
	else
		load(songNode);

}
 
Example 4
Source File: TemplateListPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void removeRows() {
  TreeNode toSelect = null;

  TreePath[] paths = myTree.getSelectionPaths();
  if (paths == null) return;

  for (TreePath path : paths) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent();
    Object o = node.getUserObject();
    if (o instanceof TemplateGroup) {
      //noinspection SuspiciousMethodCalls
      myTemplateGroups.remove(o);
      removeNodeFromParent(node);
    } else if (o instanceof TemplateImpl) {
      TemplateImpl template = (TemplateImpl)o;
      TemplateGroup templateGroup = getTemplateGroup(template.getGroupName());
      if (templateGroup != null) {
        templateGroup.removeElement(template);
        DefaultMutableTreeNode parent = (DefaultMutableTreeNode)node.getParent();

        if (templateGroup.getElements().isEmpty()) {
          myTemplateGroups.remove(templateGroup);
          removeNodeFromParent(parent);
        } else {
          toSelect = parent.getChildAfter(node);
          removeNodeFromParent(node);
        }
      }
    }
  }

  if (toSelect instanceof DefaultMutableTreeNode) {
    setSelectedNode((DefaultMutableTreeNode)toSelect);
  }
}
 
Example 5
Source File: TemplateListPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static int getIndexToInsert(DefaultMutableTreeNode parent, String key) {
  if (parent.getChildCount() == 0) return 0;

  int res = 0;
  for (DefaultMutableTreeNode child = (DefaultMutableTreeNode)parent.getFirstChild();
       child != null;
       child = (DefaultMutableTreeNode)parent.getChildAfter(child)) {
    Object o = child.getUserObject();
    String key1 = o instanceof TemplateImpl ? ((TemplateImpl)o).getKey() : ((TemplateGroup)o).getName();
    if (key1.compareToIgnoreCase(key) > 0) return res;
    res++;
  }
  return res;
}