Java Code Examples for javax.swing.tree.DefaultMutableTreeNode

The following examples show how to use javax.swing.tree.DefaultMutableTreeNode. These examples are extracted from open source projects. 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 Project: consulo   Source File: ScopeTreeViewPanel.java    License: Apache License 2.0 6 votes vote down vote up
private void processNodeCreation(final PsiElement psiElement) {
  if (psiElement instanceof PsiFile && !isInjected((PsiFile)psiElement)) {
    final PackageDependenciesNode rootToReload = myBuilder.addFileNode((PsiFile)psiElement);
    if (rootToReload != null) {
      reload(rootToReload);
    }
  }
  else if (psiElement instanceof PsiDirectory) {
    final PsiElement[] children = psiElement.getChildren();
    if (children.length > 0) {
      for (PsiElement child : children) {
        processNodeCreation(child);
      }
    }
    else {
      final PackageDependenciesNode node = myBuilder.addDirNode((PsiDirectory)psiElement);
      if (node != null) {
        reload((DefaultMutableTreeNode)node.getParent());
      }
    }
  }
}
 
Example 2
Source Project: opensim-gui   Source File: MoveExcitationHandler.java    License: Apache License 2.0 6 votes vote down vote up
protected void exportDone(JComponent source, Transferable data, int action) {
    if(source instanceof JTree) {
        JTree tree = (JTree) source;
        DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
        TreePath currentPath = tree.getSelectionPath();
        ///System.out.println("Destination node="+currentPath.getLastPathComponent().toString());
        if(currentPath != null) { // Into a subnode
            //System.out.println("addNodes");
            DefaultMutableTreeNode targetNode = (DefaultMutableTreeNode) currentPath.getLastPathComponent();
            // Allow insertion only into columns
            if (!(targetNode.getUserObject() instanceof ExcitationColumnJPanel))
                return;
            addNodes(currentPath, model, data);
            //handlePathMove(currentPath, model, data);
        } else {    // Same parent ok
            //System.out.println("insertNodes");
            insertNodes(tree, model, data);
            //Point location = ((TreeDropTarget) tree.getDropTarget()).getMostRecentDragLocation();
            //TreePath path = tree.getClosestPathForLocation(location.x, location.y);
            //handlePathRearrange(path, model, data);
       }
    }
    super.exportDone(source, data, action);
}
 
Example 3
Source Project: consulo   Source File: NamedItemsListEditor.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
protected UnnamedConfigurable getItemConfigurable(final T item) {
  final Ref<UnnamedConfigurable> result = new Ref<UnnamedConfigurable>();
  TreeUtil.traverse((TreeNode)myTree.getModel().getRoot(), new TreeUtil.Traverse() {
    @Override
    public boolean accept(Object node) {
      final NamedConfigurable configurable = (NamedConfigurable)((DefaultMutableTreeNode)node).getUserObject();
      if (configurable.getEditableObject() == item) {
        result.set(((ItemConfigurable)configurable).myConfigurable);
        return false;
      }
      else {
        return true;
      }
    }
  });
  return result.get();
}
 
Example 4
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded,
	boolean leaf, int row, boolean focus)
{

	super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, focus);
	Object campaignObj = ((DefaultMutableTreeNode) value).getUserObject();
	if (campaignObj instanceof Campaign)
	{
		Campaign campaign = (Campaign) campaignObj;
		List<Campaign> testCampaigns = selectedCampaigns.getContents();
		testCampaigns.add(campaign);
		if (!FacadeFactory.passesPrereqs(testCampaigns))
		{
			setForeground(ColorUtilty.colorToAWTColor(UIPropertyContext.getNotQualifiedColor()));
		}
	}
	return this;
}
 
Example 5
Source Project: aion-germany   Source File: ProtocolTab.java    License: GNU General Public License v3.0 6 votes vote down vote up
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded,
	boolean leaf, int row, boolean hasFocus) {

	super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
	if (value instanceof DefaultMutableTreeNode) {
		value = ((DefaultMutableTreeNode) value).getUserObject();
	}
	if (value instanceof ProtocolNode) {
		if (value instanceof PacketFormat) {
			setIcon(packetIcon);
		}
		else if (value instanceof PacketFamilly) {
			setIcon(packetGroupIcon);
		}
	}
	return this;
}
 
Example 6
Source Project: opensim-gui   Source File: ClassifyDataJPanel.java    License: Apache License 2.0 6 votes vote down vote up
public void setAmotion(AnnotatedMotion amotion) {
     this.amotion = amotion;
     DefaultMutableTreeNode root=new DefaultMutableTreeNode("Lab Frame");
     treeModel = new ExperimentalDataTreeModel(root);
     jDataTree.setModel(treeModel);
     // Get "classified" labels and use them to populate jListAvailable
     final Vector<ExperimentalDataObject> classified = amotion.getClassified();
     final ArrayStr labels = amotion.getColumnLabels();
     int labelIndex=1;   // Since time is 0
     for(int i=0; i<classified.size(); i++){
         DefaultMutableTreeNode nextChild=new DefaultMutableTreeNode(classified.get(i).toString());
         nextChild.setUserObject(classified.get(i));
         treeModel.appendChild(nextChild, root);
         labelIndex+= classified.get(i).getObjectType().getNumberOfColumns();
     }
     displayer=MotionControlJPanel.getInstance().getMasterMotion().getDisplayer(amotion);
     // get existing rotations
     double[] rots = amotion.getCurrentRotations();
     XSpinner.setValue(rots[0]);
     YSpinner.setValue(rots[1]);
     ZSpinner.setValue(rots[2]);
}
 
Example 7
private void setPublicModifierToSourceTypeDeclaration() {
    InheritanceTree tree = null;
    if (typeCheckElimination.getExistingInheritanceTree() != null) {
        tree = typeCheckElimination.getExistingInheritanceTree();
    } else if (typeCheckElimination.getInheritanceTreeMatchingWithStaticTypes() != null) {
        tree = typeCheckElimination.getInheritanceTreeMatchingWithStaticTypes();
    }

    String abstractClassName = null;
    if (tree != null) {
        DefaultMutableTreeNode root = tree.getRootNode();
        abstractClassName = (String) root.getUserObject();
    }
    String sourcePackageName = PsiUtil.getPackageName(sourceTypeDeclaration);
    if (sourcePackageName != null && abstractClassName != null && abstractClassName.contains(".")) {
        String targetPackageName = abstractClassName.substring(0, abstractClassName.lastIndexOf("."));
        if (!sourcePackageName.equals(targetPackageName)) {
            PsiUtil.setModifierProperty(sourceTypeDeclaration, PsiModifier.PUBLIC, true);
        }
    }
}
 
Example 8
Source Project: TencentKona-8   Source File: Test4631471.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static TreeNode getRoot() {
    DefaultMutableTreeNode node = new DefaultMutableTreeNode("root");
    DefaultMutableTreeNode first = new DefaultMutableTreeNode("first");
    DefaultMutableTreeNode second = new DefaultMutableTreeNode("second");
    DefaultMutableTreeNode third = new DefaultMutableTreeNode("third");

    first.add(new DefaultMutableTreeNode("1.1"));
    first.add(new DefaultMutableTreeNode("1.2"));
    first.add(new DefaultMutableTreeNode("1.3"));

    second.add(new DefaultMutableTreeNode("2.1"));
    second.add(new DefaultMutableTreeNode("2.2"));
    second.add(new DefaultMutableTreeNode("2.3"));

    third.add(new DefaultMutableTreeNode("3.1"));
    third.add(new DefaultMutableTreeNode("3.2"));
    third.add(new DefaultMutableTreeNode("3.3"));

    node.add(first);
    node.add(second);
    node.add(third);

    return node;
}
 
Example 9
Source Project: yGuard   Source File: YGuardLogParser.java    License: MIT License 6 votes vote down vote up
private int calcChildIndex(DefaultMutableTreeNode cn, DefaultMutableTreeNode child) {
  int left = 0;
  int right = cn.getChildCount() - 1;
  Object userObject = child.getUserObject();
  while (right >= left) {
    int test = (left + right) /2;
    Object testObject = ((DefaultMutableTreeNode)cn.getChildAt(test)).getUserObject();
    int cmp = compare(userObject, testObject);
    if (cmp == 0) {
      return test;
    } else {
      if (cmp < 0) {
        right = test - 1;
      } else {
        left = test + 1;
      }
    }
  }
  return left;
}
 
Example 10
Source Project: HiJson   Source File: MainView.java    License: Apache License 2.0 6 votes vote down vote up
private void findTreeChildValue(String findText,List<TreePath> treePathLst) {
        JTree tree = getTree();
        DefaultMutableTreeNode root = (DefaultMutableTreeNode)tree.getModel().getRoot();
        Enumeration e = root.depthFirstEnumeration();
        treePathLst.clear();
        curPos = 0;
        while (e.hasMoreElements()) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement();
            if (node.isLeaf()) {
                String str = node.toString();
                if (str.substring(2).indexOf(findText) >= 0) {
                    tree.expandPath(new TreePath(node.getPath()));
                    TreePath tp = expandTreeNode(tree,node.getPath(), true);
                    treePathLst.add(tp);
                }
            }
        }
        if(!treePathLst.isEmpty()){
            tree.setSelectionPath(treePathLst.get(0));
            tree.scrollPathToVisible(treePathLst.get(0));
        }
//        return treePathLst;
    }
 
Example 11
Source Project: HubPlayer   Source File: LibraryOperation.java    License: GNU General Public License v3.0 6 votes vote down vote up
public void removeSongNodeInTreeList(JTree tree, int index) {
	DefaultMutableTreeNode root = (DefaultMutableTreeNode) tree
			.getModel().getRoot();
	DefaultMutableTreeNode list = (DefaultMutableTreeNode) root
			.getChildAt(index);

	list.remove(songNode);

	// 列表名更新
	String listName = (String) list.getUserObject();
	listName = listName.substring(0, listName.lastIndexOf("[")) + "["
			+ list.getChildCount() + "]";
	list.setUserObject(listName);

	// 如果这里不更新树的话 会不正确显示
	tree.updateUI();

}
 
Example 12
Source Project: consulo   Source File: LibraryRootsComponent.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
private static Object getPathElement(final TreePath selectionPath) {
  if (selectionPath == null) {
    return null;
  }
  final DefaultMutableTreeNode lastPathComponent = (DefaultMutableTreeNode)selectionPath.getLastPathComponent();
  if (lastPathComponent == null) {
    return null;
  }
  final Object userObject = lastPathComponent.getUserObject();
  if (!(userObject instanceof NodeDescriptor)) {
    return null;
  }
  final Object element = ((NodeDescriptor)userObject).getElement();
  if (!(element instanceof LibraryTableTreeContentElement)) {
    return null;
  }
  return element;
}
 
Example 13
Source Project: consulo   Source File: ProjectTreeBuilder.java    License: Apache License 2.0 6 votes vote down vote up
private void updateNodesContaining(@Nonnull Collection<VirtualFile> filesToRefresh, @Nonnull DefaultMutableTreeNode rootNode) {
  if (!(rootNode.getUserObject() instanceof ProjectViewNode)) return;
  ProjectViewNode node = (ProjectViewNode)rootNode.getUserObject();
  Collection<VirtualFile> containingFiles = null;
  for (VirtualFile virtualFile : filesToRefresh) {
    if (!virtualFile.isValid()) {
      addSubtreeToUpdate(rootNode); // file must be deleted
      return;
    }
    if (node.contains(virtualFile)) {
      if (containingFiles == null) containingFiles = new SmartList<>();
      containingFiles.add(virtualFile);
    }
  }
  if (containingFiles != null) {
    updateNode(rootNode);
    Enumeration children = rootNode.children();
    while (children.hasMoreElements()) {
      DefaultMutableTreeNode child = (DefaultMutableTreeNode)children.nextElement();
      updateNodesContaining(containingFiles, child);
    }
  }
}
 
Example 14
@SuppressWarnings("SameReturnValue")
private static boolean exportCell(TableModel model, StringBuilder csv, boolean firstCell, int i, int j) {
    if (!firstCell) {
        csv.append(EXPORT_CELL_DELIMITER);
    }
    Object t = model.getValueAt(i, j);
    if (Tree.class.isAssignableFrom(t.getClass())) {
        Tree tt = (Tree) t;
        TreeModel tm = tt.getModel();
        try {
            csv.append(convertToCsv(((DefaultMutableTreeNode) tm.getRoot()).getUserObject()));
        } catch (Exception e) {
            // skipping non-convertible nodes
        }
    } else {
        csv.append(t.toString());
    }
    return false;
}
 
Example 15
Source Project: consulo   Source File: HierarchyBrowserBase.java    License: Apache License 2.0 6 votes vote down vote up
public PsiElement[] getAvailableElements() {
  final JTree tree = getCurrentTree();
  if (tree == null) {
    return PsiElement.EMPTY_ARRAY;
  }
  final TreeModel model = tree.getModel();
  final Object root = model.getRoot();
  if (!(root instanceof DefaultMutableTreeNode)) {
    return PsiElement.EMPTY_ARRAY;
  }
  final DefaultMutableTreeNode node = (DefaultMutableTreeNode)root;
  final HierarchyNodeDescriptor descriptor = getDescriptor(node);
  final Set<PsiElement> result = new HashSet<>();
  collectElements(descriptor, result);
  return result.toArray(PsiElement.EMPTY_ARRAY);
}
 
Example 16
Source Project: netbeans   Source File: FmtSpaces.java    License: Apache License 2.0 6 votes vote down vote up
/** Creates new form FmtSpaces */
private FmtSpaces() {
    initComponents();
    model = createModel();
    cfgTree.setModel(model);
    cfgTree.setRootVisible(false);
    cfgTree.setShowsRootHandles(true);
    cfgTree.setCellRenderer(this);
    cfgTree.setEditable(false);
    cfgTree.addMouseListener(this);
    cfgTree.addKeyListener(this);

    dr.setIcon(null);
    dr.setOpenIcon(null);
    dr.setClosedIcon(null);

    DefaultMutableTreeNode root = (DefaultMutableTreeNode)model.getRoot();
    for( int i = root.getChildCount(); i >= 0; i-- ) {
        cfgTree.expandRow(i);
    }

    Dimension dimension = new Dimension((int) cfgTree.getPreferredSize().getWidth() + Utils.POSSIBLE_SCROLL_BAR_WIDTH, (int) jScrollPane1.getMinimumSize().getHeight());
    jScrollPane1.setMinimumSize(dimension);
}
 
Example 17
Source Project: raccoon4   Source File: ContentsWorker.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected TreeNode doInBackground() throws Exception {
	ZipFile zip = new ZipFile(zipfile);
	Enumeration<? extends ZipEntry> entries = zip.entries();
	DefaultMutableTreeNode root = new DefaultMutableTreeNode(zipfile.getName());
	Vector<String> names = new Vector<String>();
	while (entries.hasMoreElements()) {
		names.add(entries.nextElement().getName());
	}
	zip.close();
	Collections.sort(names);
	for (String name : names) {
		String[] elements = name.split("/");
		DefaultMutableTreeNode tmp = root;
		for (String element : elements) {
			tmp = getNode(tmp, element);
		}
	}
	return root;
}
 
Example 18
Source Project: freecol   Source File: ConceptDetailPanel.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void addSubTrees(DefaultMutableTreeNode root) {
    DefaultMutableTreeNode node
        = new DefaultMutableTreeNode(new ColopediaTreeItem(this, id,
                getName(), null));
    List<DefaultMutableTreeNode> nodes = new ArrayList<>(concepts.length);
    for (String concept : concepts) {
        String nodeId = "colopedia.concepts." + concept;
        String nodeName = Messages.getName(nodeId);
        nodes.add(new DefaultMutableTreeNode(new ColopediaTreeItem(this,
                    nodeId, nodeName, null)));
    }
    Collections.sort(nodes, nodeComparator);
    for (DefaultMutableTreeNode n : nodes) {
        node.add(n);
    }
    root.add(node);
}
 
Example 19
Source Project: megamek   Source File: RandomArmyDialog.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void updateRATs() {
    Iterator<String> rats = rug.getRatList();
    if (null == rats) {
        return;
    }  
    
    RandomUnitGenerator.RatTreeNode ratTree = rug.getRatTree();
    DefaultMutableTreeNode root = new DefaultMutableTreeNode(ratTree.name);
    createRatTreeNodes(root, ratTree);
    m_treeRAT.setModel(new DefaultTreeModel(root));
    
    String selectedRATPath = 
            GUIPreferences.getInstance().getRATSelectedRAT();
    if (!selectedRATPath.equals("")) {
        String[] nodes = selectedRATPath.replace('[', ' ')
                .replace(']', ' ').split(",");
        TreePath path = findPathByName(nodes);
        m_treeRAT.setSelectionPath(path);
    }
}
 
Example 20
Source Project: consulo   Source File: NotificationsConfigurablePanel.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void setValueAt(Object value, Object node, int column) {
  SettingsWrapper wrapper = (SettingsWrapper)((DefaultMutableTreeNode)node).getUserObject();

  switch (column) {
    case NotificationsTreeTable.DISPLAY_TYPE_COLUMN:
      wrapper.myVersion = wrapper.myVersion.withDisplayType((NotificationDisplayType)value);
      break;
    case NotificationsTreeTable.LOG_COLUMN:
      wrapper.myVersion = wrapper.myVersion.withShouldLog((Boolean)value);
      break;
    case NotificationsTreeTable.READ_ALOUD_COLUMN:
      wrapper.myVersion = wrapper.myVersion.withShouldReadAloud((Boolean)value);
      break;
  }
}
 
Example 21
Source Project: openAGV   Source File: AbstractTreeViewPanel.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Traversiert den gesamten Baum, um alle Knoten zu finden, die das übergebene
 * Datenobjekt in ihrem UserObject halten.
 *
 * @param dataObject
 * @return
 */
private List<DefaultMutableTreeNode> findAll(Object dataObject) {
  List<DefaultMutableTreeNode> searchNodes = new ArrayList<>();

  @SuppressWarnings("unchecked")
  Enumeration<DefaultMutableTreeNode> e = fRootNode.preorderEnumeration();

  while (e.hasMoreElements()) {
    DefaultMutableTreeNode node = e.nextElement();
    UserObject userObject = (UserObject) node.getUserObject();

    if (dataObject.equals(userObject.getModelComponent())) {
      searchNodes.add(node);
    }
  }

  return searchNodes;
}
 
Example 22
Source Project: netbeans   Source File: OptionsChooserPanel.java    License: Apache License 2.0 6 votes vote down vote up
/** Disabled for not applicable items. */
public boolean isCheckEnabled(Object node) {
    if (node == null) {
        return true;
    }
    Object userObject = ((DefaultMutableTreeNode) node).getUserObject();
    if (userObject instanceof OptionsExportModel.Category) {
        if (!((OptionsExportModel.Category) userObject).isApplicable()) {
            return false;
        }
    } else if (userObject instanceof OptionsExportModel.Item) {
        if (!((OptionsExportModel.Item) userObject).isApplicable()) {
            return false;
        }
    }
    return true;
}
 
Example 23
@Override
public Component getTreeCellRendererComponent(final JTree tree,
    final Object value, final boolean selected, final boolean expanded,
    final boolean leaf, final int row, final boolean hasFocus) {
  JLabel renderer = (JLabel) defaultRenderer.getTreeCellRendererComponent(
      tree, value, selected, expanded, leaf, row, hasFocus);
  if (value != null && value instanceof DefaultMutableTreeNode) {
    Object object = ((DefaultMutableTreeNode) value)
        .getUserObject();
    if (object instanceof String) {
      String str = (String) object;
      renderer.setText(str);
    }
    if (object instanceof HelpLine) {
      HelpLine line = (HelpLine) object;
      renderer.setText(line.getTitle());
    }
  }
  return renderer;
}
 
Example 24
Source Project: netbeans   Source File: FmtSpaces.java    License: Apache License 2.0 6 votes vote down vote up
/** Creates new form FmtSpaces */
private FmtSpaces() {
    initComponents();
    model = createModel();
    cfgTree.setModel(model);
    cfgTree.setRootVisible(false);
    cfgTree.setShowsRootHandles(true);
    cfgTree.setCellRenderer(this);
    cfgTree.setEditable(false);
    cfgTree.addMouseListener(this);
    cfgTree.addKeyListener(this);

    dr.setIcon(null);
    dr.setOpenIcon(null);
    dr.setClosedIcon(null);

    DefaultMutableTreeNode root = (DefaultMutableTreeNode)model.getRoot();
    for( int i = root.getChildCount(); i >= 0; i-- ) {
        cfgTree.expandRow(i);
    }

    Dimension dimension = new Dimension((int) cfgTree.getPreferredSize().getWidth() + Utils.POSSIBLE_SCROLL_BAR_WIDTH, (int) jScrollPane1.getMinimumSize().getHeight());
    jScrollPane1.setMinimumSize(dimension);
}
 
Example 25
Source Project: ontopia   Source File: PropertiesPanel.java    License: Apache License 2.0 6 votes vote down vote up
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);
  }
}
 
Example 26
Source Project: consulo   Source File: TreeFileChooserDialog.java    License: Apache License 2.0 6 votes vote down vote up
private PsiFile calcSelectedClass() {
  if (myTabbedPane.getSelectedIndex() == 1) {
    return (PsiFile)myGotoByNamePanel.getChosenElement();
  }
  else {
    final TreePath path = myTree.getSelectionPath();
    if (path == null) return null;
    final DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent();
    final Object userObject = node.getUserObject();
    if (!(userObject instanceof ProjectViewNode)) return null;
    ProjectViewNode pvNode = (ProjectViewNode) userObject;
    VirtualFile vFile = pvNode.getVirtualFile();
    if (vFile != null && !vFile.isDirectory()) {
      return PsiManager.getInstance(myProject).findFile(vFile);
    }

    return null;
  }
}
 
Example 27
Source Project: openjdk-8   Source File: bug8023474.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static void createAndShowGUI() {
    try {
        UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    DefaultMutableTreeNode root = new DefaultMutableTreeNode("root");
    DefaultMutableTreeNode item = new DefaultMutableTreeNode("item");
    DefaultMutableTreeNode subItem = new DefaultMutableTreeNode("subItem");

    root.add(item);
    item.add(subItem);

    DefaultTreeModel model = new DefaultTreeModel(root);
    tree = new JTree(model);

    tree.setCellEditor(new Editor());
    tree.setEditable(true);
    tree.setRowHeight(30);
    tree.setCellRenderer(new CheckboxCellRenderer());

    JFrame frame = new JFrame("bug8023474");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(new JScrollPane(tree));
    frame.setSize(400, 300);
    frame.setVisible(true);
}
 
Example 28
Source Project: freeinternals   Source File: TreeNodeGenerator.java    License: Apache License 2.0 5 votes vote down vote up
private void generateProtoIds() {
    if (this.dexFile.proto_ids == null || this.dexFile.proto_ids.length < 1) {
        return;
    }

    int size = this.dexFile.proto_ids.length;
    DefaultMutableTreeNode nodeTemp;

    DefaultMutableTreeNode node = new DefaultMutableTreeNode(new JTreeNodeFileComponent(
            this.dexFile.header.proto_ids_off.intValue(),
            size * ProtoIdItem.LENGTH,
            "proto_ids"));
    this.rootNode.add(node);

    for (int i = 0; i < size; i++) {
        ProtoIdItem item = this.dexFile.proto_ids[i];
        int startPos = item.getStartPos();
        DefaultMutableTreeNode itemNode = new DefaultMutableTreeNode(new JTreeNodeFileComponent(
                startPos,
                item.getLength(),
                "proto_id_item[" + String.format("%,d", i) + "]"));
        node.add(itemNode);

        nodeTemp = this.addNode(itemNode, startPos, Dex_uint.LENGTH, "shorty_idx", item.shorty_idx);
        startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1();
        this.addNode(nodeTemp, 0, 0, "Value", this.dexFile.getString(item.shorty_idx.intValue()));

        nodeTemp = this.addNode(itemNode, startPos, Dex_uint.LENGTH, "return_type_idx", item.return_type_idx);
        startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1();
        this.addNode(nodeTemp, 0, 0, "Value", this.dexFile.getTypeDescriptor(item.return_type_idx.intValue()));
    }
}
 
Example 29
Source Project: jenetics   Source File: TreeTestBase.java    License: Apache License 2.0 5 votes vote down vote up
AccessorMethod(
	final String name,
	final Function<T, Object> method1,
	final Function<DefaultMutableTreeNode, Object> method2
) {
	_name = requireNonNull(name);
	_method1 = requireNonNull(method1);
	_method2 = requireNonNull(method2);
}
 
Example 30
Source Project: binnavi   Source File: TypesTreeModel.java    License: Apache License 2.0 5 votes vote down vote up
private List<DefaultMutableTreeNode> collectSubtreeNodes(final DefaultMutableTreeNode node) {
  final List<DefaultMutableTreeNode> nodes = new ArrayList<DefaultMutableTreeNode>();
  for (final Enumeration<?> e = node.breadthFirstEnumeration(); e.hasMoreElements();) {
    nodes.add((DefaultMutableTreeNode) e.nextElement());
  }
  return nodes;
}