Java 类javax.swing.JTree.DynamicUtilTreeNode 实例源码

项目:PSD2html    文件:PsdView.java   
private TreeModel createTreeModel(List<Layer> layers) {
    NamedVector<Object> currLevel = new NamedVector<Object>();
    Queue<NamedVector<Object>> levelQueue = new LinkedList<NamedVector<Object>>();
    for (Layer l : layers) {
        if (l.getType() == LayerType.HIDDEN) {
            levelQueue.add(currLevel);
            currLevel = new NamedVector<Object>();
        }
        else if (l.getType() == LayerType.FOLDER) {
            currLevel.setName(l.toString());
            Vector<Object> prevLevel = currLevel;
            if (l.getLayersCount() > 0) {
                List<Layer> ls = getLayers(l);
                createTreeModel(ls);
            }
            currLevel.add(0, prevLevel);
        }
        else {
            currLevel.add(0, new NamedPsdLayer(l));
        }
    }
    DefaultMutableTreeNode root = new DefaultMutableTreeNode("root");
    DynamicUtilTreeNode.createChildren(root, currLevel);
    return new DefaultTreeModel(root);
}
项目:ontopia    文件:PropertiesPanel.java   
private void addSubjectTreeNodeTo(DefaultMutableTreeNode parent) {
  LocatorIF subject = (LocatorIF)CollectionUtils.getFirst(target.getSubjectLocators()); // NOTE: gets only the first one

  if (subject == null)
    return;

  String subjectAddress = subject.getAddress();

  if (subjectAddress != null) {
    DefaultMutableTreeNode root = new DefaultMutableTreeNode(Messages
        .getString("Viz.PropertiesSubject"));

    root.add(new DynamicUtilTreeNode(subjectAddress, null));
    parent.add(root);
  }
}
项目:ontopia    文件:PropertiesPanel.java   
private void addTopicNamesTreeNodeTo(DefaultMutableTreeNode parent) {
  Iterator baseNames = target.getTopicNames().iterator();
  if (baseNames.hasNext()) {

    DefaultMutableTreeNode root = new DefaultMutableTreeNode(Messages
        .getString("Viz.PropertiesTopicNames"));

    while (baseNames.hasNext()) {
      TopicNameIF name = (TopicNameIF) baseNames.next();
      StringBuilder buff = new StringBuilder();
      buff.append(name.getValue());
      if (!name.getScope().isEmpty()) {
        buff.append(" - ");
        boolean first = true;
        for (Iterator iter = name.getScope().iterator(); iter.hasNext();) {
          if (!first) buff.append(" : ");
          buff.append(controller.getStringifier().toString(iter.next()));
          first = false;
        }
      }
      root.add(new DynamicUtilTreeNode(buff.toString(), null));
    }
    parent.add(root);
  }
}
项目:cn1    文件:JTree_DynamicUtilTreeNodeTest.java   
public void testLoadChildren() throws Exception {
    Object[] children = new Object[] { "1", "2" };
    DynamicUtilTreeNode node = new DynamicUtilTreeNode("value", children);
    assertFalse(node.loadedChildren);
    assertEquals(children, node.childValue);
    assertEquals("value", node.getUserObject());
    node.loadChildren();
    assertTrue(node.loadedChildren);
    assertEquals(2, node.getChildCount());
    node.childValue = "any";
    node.loadChildren();
    assertEquals(2, node.getChildCount());
    assertEquals("value", node.getUserObject());
    node.childValue = new Object[] { "3", "4", "5" };
    node.loadChildren();
    assertTrue(node.loadedChildren);
    assertEquals(5, node.getChildCount());
    assertEquals("5", ((DefaultMutableTreeNode) node.getChildAt(4)).getUserObject());
    node.childValue = new Object[] { "6" };
    assertEquals(5, node.getChildCount());
    node.loadedChildren = false;
    assertEquals(6, node.getChildCount());
}
项目:freeVM    文件:JTree_DynamicUtilTreeNodeTest.java   
public void testLoadChildren() throws Exception {
    Object[] children = new Object[] { "1", "2" };
    DynamicUtilTreeNode node = new DynamicUtilTreeNode("value", children);
    assertFalse(node.loadedChildren);
    assertEquals(children, node.childValue);
    assertEquals("value", node.getUserObject());
    node.loadChildren();
    assertTrue(node.loadedChildren);
    assertEquals(2, node.getChildCount());
    node.childValue = "any";
    node.loadChildren();
    assertEquals(2, node.getChildCount());
    assertEquals("value", node.getUserObject());
    node.childValue = new Object[] { "3", "4", "5" };
    node.loadChildren();
    assertTrue(node.loadedChildren);
    assertEquals(5, node.getChildCount());
    assertEquals("5", ((DefaultMutableTreeNode) node.getChildAt(4)).getUserObject());
    node.childValue = new Object[] { "6" };
    assertEquals(5, node.getChildCount());
    node.loadedChildren = false;
    assertEquals(6, node.getChildCount());
}
项目:freeVM    文件:JTree_DynamicUtilTreeNodeTest.java   
public void testLoadChildren() throws Exception {
    Object[] children = new Object[] { "1", "2" };
    DynamicUtilTreeNode node = new DynamicUtilTreeNode("value", children);
    assertFalse(node.loadedChildren);
    assertEquals(children, node.childValue);
    assertEquals("value", node.getUserObject());
    node.loadChildren();
    assertTrue(node.loadedChildren);
    assertEquals(2, node.getChildCount());
    node.childValue = "any";
    node.loadChildren();
    assertEquals(2, node.getChildCount());
    assertEquals("value", node.getUserObject());
    node.childValue = new Object[] { "3", "4", "5" };
    node.loadChildren();
    assertTrue(node.loadedChildren);
    assertEquals(5, node.getChildCount());
    assertEquals("5", ((DefaultMutableTreeNode) node.getChildAt(4)).getUserObject());
    node.childValue = new Object[] { "6" };
    assertEquals(5, node.getChildCount());
    node.loadedChildren = false;
    assertEquals(6, node.getChildCount());
}
项目:ontopia    文件:PropertiesPanel.java   
private void addSubjectIdentifiersTreeNodeTo(DefaultMutableTreeNode parent) {
  Iterator subjInds = target.getSubjectIdentifiers().iterator();
  if (subjInds.hasNext()) {

    DefaultMutableTreeNode root = new DefaultMutableTreeNode(Messages
        .getString("Viz.PropertiesSubjectIndicators"));

    while (subjInds.hasNext()) {
      root.add(new DynamicUtilTreeNode(((LocatorIF) subjInds.next())
          .getAddress(), null));
    }
    parent.add(root);
  }
}
项目:ontopia    文件:PropertiesPanel.java   
private void addTypesTreeNodeTo(DefaultMutableTreeNode parent) {
  Iterator types = target.getTypes().iterator();
  if (types.hasNext()) {

    DefaultMutableTreeNode root = new DefaultMutableTreeNode(Messages
        .getString("Viz.PropertiesTypes"));

    while (types.hasNext()) {
      root.add(new DynamicUtilTreeNode(controller.getStringifier()
          .toString(types.next()), null));
    }
    parent.add(root);
  }
}
项目:cn1    文件:JTree_DynamicUtilTreeNodeTest.java   
public void testIsLeaf() throws Exception {
    DynamicUtilTreeNode node = new DynamicUtilTreeNode("value", null);
    assertFalse(node.getAllowsChildren());
    assertTrue(node.isLeaf());
    node.setAllowsChildren(true);
    assertFalse(node.isLeaf());
}
项目:cn1    文件:JTree_DynamicUtilTreeNodeTest.java   
public void testChildren() throws Exception {
    DynamicUtilTreeNode node = new DynamicUtilTreeNode("value", new Object[] { "1", "2" });
    assertFalse(node.loadedChildren);
    Enumeration<?> children = node.children();
    assertTrue(node.loadedChildren);
    assertEquals("1", ((DefaultMutableTreeNode) children.nextElement()).getUserObject());
    assertEquals("2", ((DefaultMutableTreeNode) children.nextElement()).getUserObject());
}
项目:freeVM    文件:JTree_DynamicUtilTreeNodeTest.java   
public void testIsLeaf() throws Exception {
    DynamicUtilTreeNode node = new DynamicUtilTreeNode("value", null);
    assertFalse(node.getAllowsChildren());
    assertTrue(node.isLeaf());
    node.setAllowsChildren(true);
    assertFalse(node.isLeaf());
}
项目:freeVM    文件:JTree_DynamicUtilTreeNodeTest.java   
public void testChildren() throws Exception {
    DynamicUtilTreeNode node = new DynamicUtilTreeNode("value", new Object[] { "1", "2" });
    assertFalse(node.loadedChildren);
    Enumeration<?> children = node.children();
    assertTrue(node.loadedChildren);
    assertEquals("1", ((DefaultMutableTreeNode) children.nextElement()).getUserObject());
    assertEquals("2", ((DefaultMutableTreeNode) children.nextElement()).getUserObject());
}
项目:freeVM    文件:JTree_DynamicUtilTreeNodeTest.java   
public void testIsLeaf() throws Exception {
    DynamicUtilTreeNode node = new DynamicUtilTreeNode("value", null);
    assertFalse(node.getAllowsChildren());
    assertTrue(node.isLeaf());
    node.setAllowsChildren(true);
    assertFalse(node.isLeaf());
}
项目:freeVM    文件:JTree_DynamicUtilTreeNodeTest.java   
public void testChildren() throws Exception {
    DynamicUtilTreeNode node = new DynamicUtilTreeNode("value", new Object[] { "1", "2" });
    assertFalse(node.loadedChildren);
    Enumeration<?> children = node.children();
    assertTrue(node.loadedChildren);
    assertEquals("1", ((DefaultMutableTreeNode) children.nextElement()).getUserObject());
    assertEquals("2", ((DefaultMutableTreeNode) children.nextElement()).getUserObject());
}
项目:cn1    文件:JTree_DynamicUtilTreeNodeTest.java   
@Override
protected void setUp() throws Exception {
    node = new DynamicUtilTreeNode("value", null);
}
项目:cn1    文件:JTree_DynamicUtilTreeNodeTest.java   
public void testCreateChildren() throws Exception {
    DynamicUtilTreeNode.createChildren(null, "any");
    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    DynamicUtilTreeNode.createChildren(root, "any");
    assertEquals(0, root.getChildCount());
    assertTrue(root.isLeaf());
    int[] privitiveArrayChildren = new int[] { 1, 2, 3 };
    DynamicUtilTreeNode.createChildren(root, privitiveArrayChildren);
    assertEquals(0, root.getChildCount());
    assertTrue(root.isLeaf());
    assertTrue(root.getAllowsChildren());
    Object[] objectArrayChildren = new Object[] { "a", "b", "c" };
    DynamicUtilTreeNode.createChildren(root, objectArrayChildren);
    assertEquals(3, root.getChildCount());
    assertTrue(root.getChildAt(0) instanceof JTree.DynamicUtilTreeNode);
    assertFalse(root.isLeaf());
    assertEquals("a", ((DefaultMutableTreeNode) root.getChildAt(0)).getUserObject());
    Vector<String> vectorChildren = new Vector<String>();
    vectorChildren.add("1");
    vectorChildren.add("2");
    DynamicUtilTreeNode.createChildren(root, vectorChildren);
    assertEquals(5, root.getChildCount());
    assertTrue(root.getChildAt(4) instanceof JTree.DynamicUtilTreeNode);
    assertTrue(root.getChildAt(4).isLeaf());
    assertFalse(root.getChildAt(4).getAllowsChildren());
    assertEquals("1", ((DefaultMutableTreeNode) root.getChildAt(3)).getUserObject());
    Hashtable<String, String> hashChildren = new Hashtable<String, String>();
    hashChildren.put("key1", "value1");
    hashChildren.put("key2", "value2");
    DynamicUtilTreeNode.createChildren(root, hashChildren);
    assertEquals(7, root.getChildCount());
    assertTrue(root.getChildAt(5) instanceof JTree.DynamicUtilTreeNode);
    assertEquals(hashChildren.keys().nextElement(), ((DefaultMutableTreeNode) root
            .getChildAt(5)).getUserObject());
    assertEquals(0, root.getChildAt(5).getChildCount());
    root = new DefaultMutableTreeNode();
    Hashtable<String, String> subSubChildren = new Hashtable<String, String>();
    subSubChildren.put("221", "any");
    subSubChildren.put("222", "any");
    Vector<Serializable> subChildren = new Vector<Serializable>();
    subChildren.add("21");
    subChildren.add(subSubChildren);
    subChildren.add("23");
    Object[] complexChildren = new Object[] { "1", subChildren, "3" };
    DynamicUtilTreeNode.createChildren(root, complexChildren);
    assertEquals(3, root.getChildCount());
    DynamicUtilTreeNode child1 = (DynamicUtilTreeNode) root.getChildAt(0);
    assertFalse(child1.getAllowsChildren());
    assertEquals(0, child1.getChildCount());
    assertEquals("1", child1.getUserObject());
    assertEquals("1", child1.childValue);
    assertTrue(child1.loadedChildren);
    DynamicUtilTreeNode child2 = (DynamicUtilTreeNode) root.getChildAt(1);
    assertTrue(child2.getAllowsChildren());
    assertEquals(3, child2.getChildCount());
    assertEquals(subChildren, child2.getUserObject());
    assertSame(subChildren, child2.childValue);
    assertTrue(child2.loadedChildren);
    assertEquals(0, root.getChildAt(2).getChildCount());
    assertEquals("3", ((DefaultMutableTreeNode) root.getChildAt(2)).getUserObject());
    assertEquals(3, child2.getChildCount());
    assertEquals(0, child2.getChildAt(0).getChildCount());
    assertEquals(2, child2.getChildAt(1).getChildCount());
    assertEquals(0, child2.getChildAt(2).getChildCount());
}
项目:cn1    文件:JTree_DynamicUtilTreeNodeTest.java   
public void testGetChildCount() throws Exception {
    DynamicUtilTreeNode node = new DynamicUtilTreeNode("value", new Object[] { "1", "2" });
    assertFalse(node.loadedChildren);
    assertEquals(2, node.getChildCount());
    assertTrue(node.loadedChildren);
}
项目:cn1    文件:JTree_DynamicUtilTreeNodeTest.java   
public void testGetChildAt() throws Exception {
    DynamicUtilTreeNode node = new DynamicUtilTreeNode("value", new Object[] { "1", "2" });
    assertFalse(node.loadedChildren);
    assertEquals("1", ((DynamicUtilTreeNode) node.getChildAt(0)).getUserObject());
    assertTrue(node.loadedChildren);
}
项目:cn1    文件:JTree_DynamicUtilTreeNodeTest.java   
public void testClone() {
    Object obj = new Object();
    DynamicUtilTreeNode t = new DynamicUtilTreeNode(obj, obj);
    Object cl = t.clone();
    assertEquals(t.getClass(), cl.getClass());
}
项目:freeVM    文件:JTree_DynamicUtilTreeNodeTest.java   
@Override
protected void setUp() throws Exception {
    node = new DynamicUtilTreeNode("value", null);
}
项目:freeVM    文件:JTree_DynamicUtilTreeNodeTest.java   
public void testCreateChildren() throws Exception {
    DynamicUtilTreeNode.createChildren(null, "any");
    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    DynamicUtilTreeNode.createChildren(root, "any");
    assertEquals(0, root.getChildCount());
    assertTrue(root.isLeaf());
    int[] privitiveArrayChildren = new int[] { 1, 2, 3 };
    DynamicUtilTreeNode.createChildren(root, privitiveArrayChildren);
    assertEquals(0, root.getChildCount());
    assertTrue(root.isLeaf());
    assertTrue(root.getAllowsChildren());
    Object[] objectArrayChildren = new Object[] { "a", "b", "c" };
    DynamicUtilTreeNode.createChildren(root, objectArrayChildren);
    assertEquals(3, root.getChildCount());
    assertTrue(root.getChildAt(0) instanceof JTree.DynamicUtilTreeNode);
    assertFalse(root.isLeaf());
    assertEquals("a", ((DefaultMutableTreeNode) root.getChildAt(0)).getUserObject());
    Vector<String> vectorChildren = new Vector<String>();
    vectorChildren.add("1");
    vectorChildren.add("2");
    DynamicUtilTreeNode.createChildren(root, vectorChildren);
    assertEquals(5, root.getChildCount());
    assertTrue(root.getChildAt(4) instanceof JTree.DynamicUtilTreeNode);
    assertTrue(root.getChildAt(4).isLeaf());
    assertFalse(root.getChildAt(4).getAllowsChildren());
    assertEquals("1", ((DefaultMutableTreeNode) root.getChildAt(3)).getUserObject());
    Hashtable<String, String> hashChildren = new Hashtable<String, String>();
    hashChildren.put("key1", "value1");
    hashChildren.put("key2", "value2");
    DynamicUtilTreeNode.createChildren(root, hashChildren);
    assertEquals(7, root.getChildCount());
    assertTrue(root.getChildAt(5) instanceof JTree.DynamicUtilTreeNode);
    assertEquals(hashChildren.keys().nextElement(), ((DefaultMutableTreeNode) root
            .getChildAt(5)).getUserObject());
    assertEquals(0, root.getChildAt(5).getChildCount());
    root = new DefaultMutableTreeNode();
    Hashtable<String, String> subSubChildren = new Hashtable<String, String>();
    subSubChildren.put("221", "any");
    subSubChildren.put("222", "any");
    Vector<Serializable> subChildren = new Vector<Serializable>();
    subChildren.add("21");
    subChildren.add(subSubChildren);
    subChildren.add("23");
    Object[] complexChildren = new Object[] { "1", subChildren, "3" };
    DynamicUtilTreeNode.createChildren(root, complexChildren);
    assertEquals(3, root.getChildCount());
    DynamicUtilTreeNode child1 = (DynamicUtilTreeNode) root.getChildAt(0);
    assertFalse(child1.getAllowsChildren());
    assertEquals(0, child1.getChildCount());
    assertEquals("1", child1.getUserObject());
    assertEquals("1", child1.childValue);
    assertTrue(child1.loadedChildren);
    DynamicUtilTreeNode child2 = (DynamicUtilTreeNode) root.getChildAt(1);
    assertTrue(child2.getAllowsChildren());
    assertEquals(3, child2.getChildCount());
    assertEquals(subChildren, child2.getUserObject());
    assertSame(subChildren, child2.childValue);
    assertTrue(child2.loadedChildren);
    assertEquals(0, root.getChildAt(2).getChildCount());
    assertEquals("3", ((DefaultMutableTreeNode) root.getChildAt(2)).getUserObject());
    assertEquals(3, child2.getChildCount());
    assertEquals(0, child2.getChildAt(0).getChildCount());
    assertEquals(2, child2.getChildAt(1).getChildCount());
    assertEquals(0, child2.getChildAt(2).getChildCount());
}
项目:freeVM    文件:JTree_DynamicUtilTreeNodeTest.java   
public void testGetChildCount() throws Exception {
    DynamicUtilTreeNode node = new DynamicUtilTreeNode("value", new Object[] { "1", "2" });
    assertFalse(node.loadedChildren);
    assertEquals(2, node.getChildCount());
    assertTrue(node.loadedChildren);
}
项目:freeVM    文件:JTree_DynamicUtilTreeNodeTest.java   
public void testGetChildAt() throws Exception {
    DynamicUtilTreeNode node = new DynamicUtilTreeNode("value", new Object[] { "1", "2" });
    assertFalse(node.loadedChildren);
    assertEquals("1", ((DynamicUtilTreeNode) node.getChildAt(0)).getUserObject());
    assertTrue(node.loadedChildren);
}
项目:freeVM    文件:JTree_DynamicUtilTreeNodeTest.java   
@Override
protected void setUp() throws Exception {
    node = new DynamicUtilTreeNode("value", null);
}
项目:freeVM    文件:JTree_DynamicUtilTreeNodeTest.java   
public void testCreateChildren() throws Exception {
    DynamicUtilTreeNode.createChildren(null, "any");
    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    DynamicUtilTreeNode.createChildren(root, "any");
    assertEquals(0, root.getChildCount());
    assertTrue(root.isLeaf());
    int[] privitiveArrayChildren = new int[] { 1, 2, 3 };
    DynamicUtilTreeNode.createChildren(root, privitiveArrayChildren);
    assertEquals(0, root.getChildCount());
    assertTrue(root.isLeaf());
    assertTrue(root.getAllowsChildren());
    Object[] objectArrayChildren = new Object[] { "a", "b", "c" };
    DynamicUtilTreeNode.createChildren(root, objectArrayChildren);
    assertEquals(3, root.getChildCount());
    assertTrue(root.getChildAt(0) instanceof JTree.DynamicUtilTreeNode);
    assertFalse(root.isLeaf());
    assertEquals("a", ((DefaultMutableTreeNode) root.getChildAt(0)).getUserObject());
    Vector<String> vectorChildren = new Vector<String>();
    vectorChildren.add("1");
    vectorChildren.add("2");
    DynamicUtilTreeNode.createChildren(root, vectorChildren);
    assertEquals(5, root.getChildCount());
    assertTrue(root.getChildAt(4) instanceof JTree.DynamicUtilTreeNode);
    assertTrue(root.getChildAt(4).isLeaf());
    assertFalse(root.getChildAt(4).getAllowsChildren());
    assertEquals("1", ((DefaultMutableTreeNode) root.getChildAt(3)).getUserObject());
    Hashtable<String, String> hashChildren = new Hashtable<String, String>();
    hashChildren.put("key1", "value1");
    hashChildren.put("key2", "value2");
    DynamicUtilTreeNode.createChildren(root, hashChildren);
    assertEquals(7, root.getChildCount());
    assertTrue(root.getChildAt(5) instanceof JTree.DynamicUtilTreeNode);
    assertEquals(hashChildren.keys().nextElement(), ((DefaultMutableTreeNode) root
            .getChildAt(5)).getUserObject());
    assertEquals(0, root.getChildAt(5).getChildCount());
    root = new DefaultMutableTreeNode();
    Hashtable<String, String> subSubChildren = new Hashtable<String, String>();
    subSubChildren.put("221", "any");
    subSubChildren.put("222", "any");
    Vector<Serializable> subChildren = new Vector<Serializable>();
    subChildren.add("21");
    subChildren.add(subSubChildren);
    subChildren.add("23");
    Object[] complexChildren = new Object[] { "1", subChildren, "3" };
    DynamicUtilTreeNode.createChildren(root, complexChildren);
    assertEquals(3, root.getChildCount());
    DynamicUtilTreeNode child1 = (DynamicUtilTreeNode) root.getChildAt(0);
    assertFalse(child1.getAllowsChildren());
    assertEquals(0, child1.getChildCount());
    assertEquals("1", child1.getUserObject());
    assertEquals("1", child1.childValue);
    assertTrue(child1.loadedChildren);
    DynamicUtilTreeNode child2 = (DynamicUtilTreeNode) root.getChildAt(1);
    assertTrue(child2.getAllowsChildren());
    assertEquals(3, child2.getChildCount());
    assertEquals(subChildren, child2.getUserObject());
    assertSame(subChildren, child2.childValue);
    assertTrue(child2.loadedChildren);
    assertEquals(0, root.getChildAt(2).getChildCount());
    assertEquals("3", ((DefaultMutableTreeNode) root.getChildAt(2)).getUserObject());
    assertEquals(3, child2.getChildCount());
    assertEquals(0, child2.getChildAt(0).getChildCount());
    assertEquals(2, child2.getChildAt(1).getChildCount());
    assertEquals(0, child2.getChildAt(2).getChildCount());
}
项目:freeVM    文件:JTree_DynamicUtilTreeNodeTest.java   
public void testGetChildCount() throws Exception {
    DynamicUtilTreeNode node = new DynamicUtilTreeNode("value", new Object[] { "1", "2" });
    assertFalse(node.loadedChildren);
    assertEquals(2, node.getChildCount());
    assertTrue(node.loadedChildren);
}
项目:freeVM    文件:JTree_DynamicUtilTreeNodeTest.java   
public void testGetChildAt() throws Exception {
    DynamicUtilTreeNode node = new DynamicUtilTreeNode("value", new Object[] { "1", "2" });
    assertFalse(node.loadedChildren);
    assertEquals("1", ((DynamicUtilTreeNode) node.getChildAt(0)).getUserObject());
    assertTrue(node.loadedChildren);
}
项目:freeVM    文件:JTree_DynamicUtilTreeNodeTest.java   
public void testClone() {
    Object obj = new Object();
    DynamicUtilTreeNode t = new DynamicUtilTreeNode(obj, obj);
    Object cl = t.clone();
    assertEquals(t.getClass(), cl.getClass());
}