javax.swing.tree.DefaultMutableTreeNode Java Examples

The following examples show how to use javax.swing.tree.DefaultMutableTreeNode. 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: TreeFileChooserDialog.java    From consulo with 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 #2
Source File: NamedItemsListEditor.java    From consulo with 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 #3
Source File: AdvancedSourceSelectionPanel.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
@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 #4
Source File: ProtocolTab.java    From aion-germany with 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 #5
Source File: ReplaceConditionalWithPolymorphism.java    From IntelliJDeodorant with MIT License 6 votes vote down vote up
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 #6
Source File: Test4631471.java    From TencentKona-8 with 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 #7
Source File: MoveExcitationHandler.java    From opensim-gui with 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 #8
Source File: ClassifyDataJPanel.java    From opensim-gui with 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 #9
Source File: YGuardLogParser.java    From yGuard with 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 File: MainView.java    From HiJson with 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 File: LibraryOperation.java    From HubPlayer with 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 File: LibraryRootsComponent.java    From consulo with 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 File: ProjectTreeBuilder.java    From consulo with 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
Source File: HierarchyBrowserBase.java    From consulo with 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 #15
Source File: ScopeTreeViewPanel.java    From consulo with 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 #16
Source File: PropertiesPanel.java    From ontopia with 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 #17
Source File: FmtSpaces.java    From netbeans with 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 #18
Source File: TutorialTreeCellRenderer.java    From Open-Realms-of-Stars with GNU General Public License v2.0 6 votes vote down vote up
@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 #19
Source File: OptionsChooserPanel.java    From netbeans with 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 #20
Source File: AbstractTreeViewPanel.java    From openAGV with 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 #21
Source File: NotificationsConfigurablePanel.java    From consulo with 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 #22
Source File: RandomArmyDialog.java    From megamek with 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 #23
Source File: ConceptDetailPanel.java    From freecol with 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 #24
Source File: ContentsWorker.java    From raccoon4 with 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 #25
Source File: FmtSpaces.java    From netbeans with 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 #26
Source File: SerialisationHelper.java    From jetbrains-plugin-graph-database-support with Apache License 2.0 6 votes vote down vote up
@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 #27
Source File: Chunk_tRNS.java    From freeinternals with Apache License 2.0 5 votes vote down vote up
@Override
protected void generateTreeNodeChunkData(DefaultMutableTreeNode parent) {
    int start = this.startPos + 4 + 4;

    // Color type 0 - Gray Scale
    if (this.Gray != -1) {
        parent.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
                start,
                2,
                String.format("Gray = %d", this.Gray))));
    }

    // Color Type 2 - True Color
    if (this.Red != -1) {
        parent.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
                start,
                2,
                String.format("Red = %d", this.Red))));
        parent.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
                start += 2,
                2,
                String.format("Green = %d", this.Green))));
        parent.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
                start += 2,
                2,
                String.format("Blue = %d", this.Blue))));
    }

    // Color Type 3 - Indexed Color
    if (this.Alpha != null) {
        for (int i = 0; i < this.Alpha.length; i++) {
            parent.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
                    start,
                    1,
                    String.format("Alpha[%d] = %d", i, this.Alpha[i]))));
            start++;
        }
    }
}
 
Example #28
Source File: WizardryScenarioDisk.java    From DiskBrowser with GNU General Public License v3.0 5 votes vote down vote up
private void extractMonsters (DefaultMutableTreeNode node, List<DiskAddress> sectors)
// ---------------------------------------------------------------------------------//
{
  List<DiskAddress> nodeSectors = new ArrayList<> ();
  ScenarioData sd = scenarioHeader.data.get (Header.MONSTER_AREA);
  monsters = new ArrayList<> (sd.total);
  int max = sd.totalBlocks / 2;

  for (int i = 0; i < max; i++)
  {
    List<DiskAddress> blocks = getTwoBlocks (sd, i, sectors);
    nodeSectors.addAll (blocks);
    byte[] buffer = disk.readBlocks (blocks);
    addMonsters (buffer, blocks, node);
  }

  StringBuilder text = new StringBuilder ();
  for (int block = 0; block < 4; block++)
  {
    text.append (" ID    Name\n");
    text.append ("--- ---------------");
    for (int i = 0; i < 24; i++)
      text.append (" --");
    text.append ("\n");
    for (Monster m : monsters)
      text.append (m.getDump (block) + "\n");
    text.append ("\n");
  }
  DefaultAppleFileSource afs = (DefaultAppleFileSource) node.getUserObject ();
  afs.setSectors (nodeSectors);
  DefaultDataSource dds = (DefaultDataSource) afs.getDataSource ();
  dds.text = text.toString ();
}
 
Example #29
Source File: DNDTree.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
/** Rebuilds the entire tree, from the given node downward. */
public void rebuild(final DefaultMutableTreeNode node, final boolean repaint) {
	if (null == node) return;
	if (0 != node.getChildCount()) node.removeAllChildren();
	final Thing thing = (Thing)node.getUserObject();
	final ArrayList<? extends Thing> al_children = thing.getChildren();
	if (null == al_children) return;
	for (Iterator<? extends Thing> it = al_children.iterator(); it.hasNext(); ) {
		Thing child = it.next();
		DefaultMutableTreeNode childnode = new DefaultMutableTreeNode(child);
		node.add(childnode);
		rebuild(childnode, false);
	}
	if (repaint) updateUILater();
}
 
Example #30
Source File: FilteredTree.java    From swing_library with MIT License 5 votes vote down vote up
/**
 * 
 * @param text
 */
private void filterTree(String text) {
	filteredText = text;
	// get a copy
	DefaultMutableTreeNode filteredRoot = copyNode(originalRoot);

	if (text.trim().toString().equals("")) {

		// reset with the original root
		originalTreeModel.setRoot(originalRoot);

		tree.setModel(originalTreeModel);
		tree.updateUI();
		scrollpane.getViewport().setView(tree);

		for (int i = 0; i < tree.getRowCount(); i++) {
			tree.expandRow(i);
		}

		return;
	} else {

		TreeNodeBuilder b = new TreeNodeBuilder(text);
		filteredRoot = b.prune((DefaultMutableTreeNode) filteredRoot.getRoot());

		originalTreeModel.setRoot(filteredRoot);

		tree.setModel(originalTreeModel);
		tree.updateUI();
		scrollpane.getViewport().setView(tree);
	}

	for (int i = 0; i < tree.getRowCount(); i++) {
		tree.expandRow(i);
	}
}