Java 类javax.swing.tree.DefaultTreeModel 实例源码

项目:litiengine    文件:AssetTree.java   
public AssetTree() {
  this.nodeRoot = new DefaultMutableTreeNode(new IconTreeListItem(Resources.get("assettree_assets"), ASSET_ICON));
  this.nodeSpritesheets = new DefaultMutableTreeNode(new IconTreeListItem(Resources.get("assettree_spritesheets"), SPRITESHEET_ICON));
  this.nodeSpriteProps = new DefaultMutableTreeNode(new IconTreeListItem(Resources.get("assettree_spritesheets_props"), PROP_ICON));
  this.nodeSpriteMisc = new DefaultMutableTreeNode(new IconTreeListItem(Resources.get("assettree_spritesheets_misc"), MISC_ICON));
  this.nodeSpritesheets.add(this.nodeSpriteProps);
  this.nodeSpritesheets.add(this.nodeSpriteMisc);

  this.nodeRoot.add(nodeSpritesheets);

  this.entitiesTreeModel = new DefaultTreeModel(this.nodeRoot);

  this.setModel(this.entitiesTreeModel);
  this.setCellRenderer(new IconTreeListRenderer());
  this.setMaximumSize(new Dimension(0, 250));
  for (int i = 0; i < this.getRowCount(); i++) {
    this.expandRow(i);
  }

  this.addTreeSelectionListener(e -> {
    loadAssetsOfCurrentSelection(e.getPath());
  });
}
项目:incubator-netbeans    文件:TreeModelEditor.java   
/**
 * Returns textual representation of the tree model.
 * 
 * @return textual representation of the tree model.
 */
String getCodeValue() {
    Object value = getValue();
    if (value instanceof DefaultTreeModel) {
        DefaultTreeModel model = (DefaultTreeModel)value;
        Object root = model.getRoot();
        if (root instanceof DefaultMutableTreeNode) {
            DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode)root;
            Object userObject = rootNode.getUserObject();
            if (userObject instanceof CodeUserObject) {
                CodeUserObject code = (CodeUserObject)userObject;
                return code.code;
            }
        }
    }
    return null;
}
项目:incubator-netbeans    文件:RefactoringPanel.java   
void setRefactoringEnabled(boolean enabled, boolean isRefreshing) {
        checkEventThread();
        if (tree != null) {
            if (!enabled) {
                CheckNode c = (CheckNode) tree.getModel().getRoot();
                if (!isRefreshing) {
                    c.setNeedsRefresh();
                } else {
                    c.setDisabled();
                }
                tree.setModel(new DefaultTreeModel(c, false));
            }
//            tree.validate();
            tree.setEnabled(enabled);
            if (refactorButton != null) {
                refactorButton.setEnabled(enabled);
            }
        }
        if (refactorButton != null) {
            refactorButton.requestFocusInWindow();
        } else if (tree != null) {
            tree.requestFocusInWindow();
        }
    }
项目:incubator-netbeans    文件:ASTBrowserTopComponent.java   
public void caretUpdate (CaretEvent e) {
    if (rootNode == null) return;
    ASTPath path = rootNode.findPath (e.getDot ());
    if (path == null) return;
    TreeNode tNode = (TreeNode) tree.getModel ().getRoot ();
    List<TreeNode> treePath = new ArrayList<TreeNode> ();
    Iterator it = path.listIterator ();
    if (!it.hasNext ()) return;
    it.next ();
    treePath.add (tNode);
    while (tNode instanceof TNode && it.hasNext ()) {
        tNode = ((TNode) tNode).getTreeNode (it.next ());
        if (tNode == null) throw new NullPointerException ();
        treePath.add (tNode);
    }
    TreePath treePath2 = new TreePath (treePath.toArray ());
    DefaultTreeModel model = new DefaultTreeModel ((TreeNode) tree.getModel ().getRoot ());
    tree.setModel (model);
    tree.setSelectionPath (treePath2);
    tree.scrollPathToVisible (treePath2);
}
项目:incubator-netbeans    文件:TokensBrowserTopComponent.java   
private void refresh () {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            AbstractDocument doc = getCurrentDocument ();
            TokenSequence ts = null;
            if (doc != null)
                try {
                    doc.readLock ();
                    TokenHierarchy tokenHierarchy = TokenHierarchy.get (doc);
                    if (tokenHierarchy == null) return;
                    ts = tokenHierarchy.tokenSequence ();
                } finally {
                    doc.readUnlock ();
                }
            if (ts == null)
                tree.setModel (new DefaultTreeModel (new DefaultMutableTreeNode ()));
            else
                tree.setModel (new DefaultTreeModel (new TSNode (null, ts, null, 0, 0)));
            JEditorPane editor = getCurrentEditor ();
            if (editor != null) {
                int position = getCurrentEditor ().getCaret ().getDot ();
                selectPath (position);
            }
        }
    });
}
项目:Recaf    文件:JarFileTree.java   
/**
 * Updates the JTree with class files loaded from the current jar.
 */
public void refresh() {
    JarData jar = Recaf.INSTANCE.jarData;
    if (jar == null) {
        return;
    }
    // TODO: Expand new tree model to match the original
    // Root node
    String jarName = (jar.jar != null) ? jar.jar.getName() : "?";
    ASMTreeNode root = new ASMTreeNode(jarName, null);
    DefaultTreeModel model = new DefaultTreeModel(root);
    tree.setModel(model);
    // Iterate classes
    List<String> names = Streams.sortedNameList(jar.classes.keySet());
    for (String className : names) {
        if (!jar.classes.containsKey(className)) {
            continue;
        }
        ClassNode node = jar.classes.get(className);
        // Create directory path based on current node name.
        ArrayList<String> dirPath = new ArrayList<String>(Arrays.asList(node.name.split("/")));
        // Create directory of nodes
        Swing.generateTreePath(root, dirPath, node, model);
    }
    model.setRoot(root);
}
项目:featurea    文件:GeneralPropPane.java   
void clear() {
    this.txtClassName.setText("");
    this.txtSuperClassName.setText("");
    this.txtMagicNumber.setText("");
    this.txtMajorVersion.setText("");
    this.txtMinorVersion.setText("");
    this.chkFinal.setSelected(false);
    this.chkPublic.setSelected(false);
    this.chkSuper.setSelected(false);
    this.chkInterface.setSelected(false);
    this.chkAbstract.setSelected(false);
    this.interfacesRootNode.removeAllChildren();
    this.treeInterfaces.setModel(new DefaultTreeModel(this.interfacesRootNode));
    this.txtNewInterfaceName.setText("");
    this.txtConstPoolIndex.setText("");
}
项目:incubator-netbeans    文件:HintsPanelLogic.java   
void connect( JTree errorTree, DefaultTreeModel errModel, JComboBox severityComboBox, 
              JCheckBox tasklistCheckBox, JPanel customizerPanel,
              JEditorPane descriptionTextArea) {

    this.errorTree = errorTree;
    this.errModel = errModel;
    this.severityComboBox = severityComboBox;
    this.tasklistCheckBox = tasklistCheckBox;
    this.customizerPanel = customizerPanel;
    this.descriptionTextArea = descriptionTextArea;        

    valueChanged( null );

    errorTree.addKeyListener(this);
    errorTree.addMouseListener(this);
    errorTree.getSelectionModel().addTreeSelectionListener(this);

    severityComboBox.addActionListener(this);
    tasklistCheckBox.addChangeListener(this);

}
项目:brModelo    文件:EditorDeTipos.java   
public void SelecioneByDiagramaSelecionado() {
    DefaultTreeModel df = (DefaultTreeModel) tree.getModel();
    if (df.getRoot() instanceof TreeItem) {
        TreeItem root = (TreeItem) df.getRoot();
        TreePath pt = new TreePath(root);
        if (diagrama.getSelecionado() == null || !(diagrama.getSelecionado() instanceof Forma)) {
            return;
        }

        for (int i = 0; i < root.getChildCount(); i++) {
            TreeItem item = (TreeItem) root.getChildAt(i);
            if (item.getId() == diagrama.getSelecionado().getID()) {
                tree.setSelectionPath(pt.pathByAddingChild(item));
                break;
            }
        }
    }
    btnOK.setText("OK");
    btnFechar.setVisible(false);
}
项目:Cognizant-Intelligent-Test-Scripter    文件:MobileObjectSpy.java   
private void saveObjectToGroup(ObjectGroup<MobileORObject> group, MobileTreeNode mobileNode) {
    MobileORObject dupObj = null;
    MobileORObject dummyObject = getDummyObject(mobileNode);
    for (MobileORObject object : group.getObjects()) {
        if (object.isEqualOf(dummyObject)) {
            dupObj = object;
        }
    }
    if (dupObj == null) {
        String objName = dummyObject.getName();
        int i = 1;
        while (group.getObjectByName(objName) != null) {
            objName = dummyObject.getName() + i++;
        }
        MobileORObject newObj = group.addObject(objName);
        dummyObject.clone(newObj);
        LOG.log(Level.INFO, "Object Added : {0}", objName);
        ((DefaultTreeModel) objectTree.getTree().getModel()).nodesWereInserted(group, new int[]{group.getChildCount() - 1});
        if (group.getChildCount() == 2) {
            ((DefaultTreeModel) objectTree.getTree().getModel()).reload(group.getParent());
        }
    } else {
        LOG.log(Level.WARNING, "Object Similar To\nObject : {0}", dupObj.getName());
    }

}
项目:incubator-netbeans    文件:PathsCustomizer.java   
public void setModels(final DefaultListModel mpModel, final DefaultListModel cpModel) {
    this.model = new JoinModel(mpModel, cpModel);
    this.list.setModel(this.model);
    DefaultTreeModel mpTreeModel = toTreeModel(mpModel, MODULEPATH);
    DefaultTreeModel cpTreeModel = toTreeModel(cpModel, CLASSPATH);
    mpModel.addListDataListener(new ListModelListener(mpModel, mpTreeModel, mpTree));
    cpModel.addListDataListener(new ListModelListener(cpModel, cpTreeModel, cpTree));
    mpTree.setModel(mpTreeModel);
    cpTree.setModel(cpTreeModel);
    SelectionModel mpTreeSelectionModel = new SelectionModel();
    SelectionModel cpTreeSelectionModel = new SelectionModel();
    mpTreeSelectionModel.addTreeSelectionListener(new SelectionListener(mpTreeModel, this.list, null, cpTreeSelectionModel));
    cpTreeSelectionModel.addTreeSelectionListener(new SelectionListener(cpTreeModel, this.list, mpModel, mpTreeSelectionModel));
    mpTree.setSelectionModel(mpTreeSelectionModel);
    cpTree.setSelectionModel(cpTreeSelectionModel);
}
项目:incubator-netbeans    文件:PathsCustomizer.java   
public void setModels(final DefaultListModel mpModel, final DefaultListModel cpModel) {
    this.model = new JoinModel(mpModel, cpModel);
    this.list.setModel(this.model);
    DefaultTreeModel mpTreeModel = toTreeModel(mpModel, MODULEPATH);
    DefaultTreeModel cpTreeModel = toTreeModel(cpModel, CLASSPATH);
    mpModel.addListDataListener(new ListModelListener(mpModel, mpTreeModel, mpTree));
    cpModel.addListDataListener(new ListModelListener(cpModel, cpTreeModel, cpTree));
    mpTree.setModel(mpTreeModel);
    cpTree.setModel(cpTreeModel);
    SelectionModel mpTreeSelectionModel = new SelectionModel();
    SelectionModel cpTreeSelectionModel = new SelectionModel();
    mpTreeSelectionModel.addTreeSelectionListener(new SelectionListener(mpTreeModel, this.list, null, cpTreeSelectionModel));
    cpTreeSelectionModel.addTreeSelectionListener(new SelectionListener(cpTreeModel, this.list, mpModel, mpTreeSelectionModel));
    mpTree.setSelectionModel(mpTreeSelectionModel);
    cpTree.setSelectionModel(cpTreeSelectionModel);
}
项目:incubator-netbeans    文件:RevertPanel.java   
void setRootNode(final TreeNode root) {
    if(root != null) {
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                tree.setModel(new DefaultTreeModel(root));
                for (int i = 0; i < tree.getRowCount(); i++) {
                    tree.expandRow(i);
                }
                listScrollPane.setVisible(true);
                titleLabel.setVisible(true);
                initPanel.setVisible(false);
            }
        });
    } else {
        messageLabel.setText(NbBundle.getMessage(RevertDeletedAction.class, "MSG_NO_FILES")); // NOI18N
    }
}
项目:incubator-netbeans    文件:OptionsChooserPanel.java   
public void setSelected(Object node, Boolean selected) {
    Object userObject = ((DefaultMutableTreeNode) node).getUserObject();
    if (((DefaultMutableTreeNode) node).isRoot()) {
        getOptionsExportModel().setState(OptionsExportModel.State.valueOf(selected));
    } else if (userObject instanceof OptionsExportModel.Category) {
        ((OptionsExportModel.Category) userObject).setState(OptionsExportModel.State.valueOf(selected));
    } else if (userObject instanceof OptionsExportModel.Item) {
        ((OptionsExportModel.Item) userObject).setEnabled(selected);
        // update parent category
        Object parent = ((TreeNode) node).getParent();
        updateCategoryNode((DefaultMutableTreeNode) parent);
    }
    // fire an event to refresh parent or child nodes
    ((DefaultTreeModel) treeModel).nodeChanged((TreeNode) node);
    dialogDescriptor.setValid(isPanelValid());
    scrollPaneOptions.repaint();
}
项目:incubator-netbeans    文件:Tab.java   
private void scrollNodeToVisible( final Node n ) {
    EventQueue.invokeLater(new Runnable() {

        @Override
        public void run() {
            TreeNode tn = Visualizer.findVisualizer(n);
            if (tn == null) {
                return;
            }
            TreeModel model = tree.getModel();
            if (!(model instanceof DefaultTreeModel)) {
                return;
            }
            TreePath path = new TreePath(((DefaultTreeModel) model).getPathToRoot(tn));
            if( null == path )
                return;
            Rectangle r = tree.getPathBounds(path);
            if (r != null) {
                tree.scrollRectToVisible(r);
            }
        }
    });
}
项目:geomapapp    文件:MapPlaces.java   
public MapPlacesViewer(MapPlaces places,
        MapPlace root,
        boolean topFrame,
        int xPos, int yPos) {
    this.places = places;
    this.topFrame = topFrame;

    this.rootPlace = root;
    this.rootNode = createTreeNodes(root);

    treeModel= new DefaultTreeModel(rootNode);
    bookmarkTree = new JTree(treeModel);

    this.initialXPos = xPos;
    this.initialYPos = yPos;

    initBookmarkFrame();
    MapPlacesViewer.mapViewers.add(this);
}
项目:IdeaCurrency    文件:IdeaCurrencyConfigUI.java   
@Override
public void apply() throws ConfigurationException {
    Set<SelectedExchangeCurrencyPair> selectedExchangeCurrencyPairs = Sets.newHashSet();
    DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
    Enumeration rootEnum = root.children();
    while (rootEnum.hasMoreElements()) {
        DefaultMutableTreeNode rootEnumObject = (DefaultMutableTreeNode) rootEnum.nextElement();
        String exchangeName = rootEnumObject.getUserObject().toString();
        Enumeration childEnum = rootEnumObject.children();
        Set<CurrencyPair> currencyPairs = Sets.newHashSet();
        while (childEnum.hasMoreElements()) {
            CheckedTreeNode childEnumObject = (CheckedTreeNode) childEnum.nextElement();
            if (childEnumObject.isChecked()) {
                currencyPairs.add(new CurrencyPair(childEnumObject.getUserObject().toString()));
            }
        }
        SelectedExchangeCurrencyPair selectedExchangeCurrencyPair = new SelectedExchangeCurrencyPair(exchangeName, currencyPairs);
        selectedExchangeCurrencyPairs.add(selectedExchangeCurrencyPair);
    }
    IdeaCurrencyConfig.getInstance().setSelectedExchangeCurrencyPairs(selectedExchangeCurrencyPairs);
    IdeaCurrencyConfig.getInstance().setReloadInterval(reloadIntervalSlider.getValue());
    IdeaCurrencyConfig.getInstance().setActive(activeCheckBox.isSelected());
    isModified = false;
    triggerConfigChange();
}
项目:AgentWorkbench    文件:ThreadInfoStorageTree.java   
/**
 * Sort nodes descending.
 *
 * @param node the node
 * @param treeModel the tree model
 */
private void sortNodesDescending(DefaultMutableTreeNode node, DefaultTreeModel treeModel) {
    boolean unsorted = true;

    while (unsorted) {
        unsorted = false;
        for (int i = 0; i < node.getChildCount() - 1; i++) {
            ThreadInfoStorageAgent tiaFirst = (ThreadInfoStorageAgent) ((DefaultMutableTreeNode) node.getChildAt(i)).getUserObject();
            ThreadInfoStorageAgent tiaSecond = (ThreadInfoStorageAgent) ((DefaultMutableTreeNode) node.getChildAt(i+1)).getUserObject();

            if (tiaFirst.getXYSeriesMap().get("TOTAL_CPU_SYSTEM_TIME").getMaxY() < tiaSecond.getXYSeriesMap().get("TOTAL_CPU_SYSTEM_TIME").getMaxY()) {
                treeModel.insertNodeInto((MutableTreeNode) node.getChildAt(i+1), node, i);
                unsorted = true;
            }
        }
    }
}
项目:openjdk-jdk10    文件:Test8015926.java   
@Override
public void run() {
    Thread.currentThread().setUncaughtExceptionHandler(this);

    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child");
    DefaultTreeModel model = new DefaultTreeModel(root);

    this.tree = new JTree();
    this.tree.setModel(model);

    JFrame frame = new JFrame(getClass().getSimpleName());
    frame.add(this.tree);

    model.addTreeModelListener(this); // frame is not visible yet
    model.insertNodeInto(child, root, root.getChildCount());
    model.removeNodeFromParent(child);

    frame.setSize(640, 480);
    frame.setLocationRelativeTo(null);
    frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    frame.setVisible(true);
}
项目:jdk8u-jdk    文件:Test8015926.java   
@Override
public void run() {
    Thread.currentThread().setUncaughtExceptionHandler(this);

    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child");
    DefaultTreeModel model = new DefaultTreeModel(root);

    this.tree = new JTree();
    this.tree.setModel(model);

    JFrame frame = new JFrame(getClass().getSimpleName());
    frame.add(this.tree);

    model.addTreeModelListener(this); // frame is not visible yet
    model.insertNodeInto(child, root, root.getChildCount());
    model.removeNodeFromParent(child);

    frame.setSize(640, 480);
    frame.setLocationRelativeTo(null);
    frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    frame.setVisible(true);
}
项目:jmeter-bzm-plugins    文件:ViewResultsFullVisualizer.java   
private synchronized Component createLeftPanel() {
    SampleResult rootSampleResult = new SampleResult();
    rootSampleResult.setSampleLabel("Root");
    rootSampleResult.setSuccessful(true);
    root = new SearchableTreeNode(rootSampleResult, null);

    treeModel = new DefaultTreeModel(root);
    jTree = new JTree(treeModel);
    jTree.setCellRenderer(new ResultsNodeRenderer());
    jTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    jTree.addTreeSelectionListener(this);
    jTree.setRootVisible(false);
    jTree.setShowsRootHandles(true);
    JScrollPane treePane = new JScrollPane(jTree);
    treePane.setPreferredSize(new Dimension(200, 300));

    VerticalPanel leftPane = new VerticalPanel();
    leftPane.add(treePane, BorderLayout.CENTER);
    leftPane.add(createComboRender(), BorderLayout.NORTH);
    autoScrollCB = new JCheckBox(JMeterUtils.getResString("view_results_autoscroll")); // $NON-NLS-1$
    autoScrollCB.setSelected(false);
    autoScrollCB.addItemListener(this);
    leftPane.add(autoScrollCB, BorderLayout.SOUTH);
    return leftPane;
}
项目:JAddOn    文件:JTreeUtils.java   
public static JTree updateJTree(JTree tree, TreeArrayList<?> data, ExpandedPaths ep) {
    ArrayList<String> expanded_paths = null;
    TreePath[] paths = null;
    if(ep != null) {
        expanded_paths = ep.getExpandedPaths(tree);
        paths = tree.getSelectionPaths();
    }
    DefaultMutableTreeNode top = getDefaultMutableTreeNodeOfHashMap(data);
    DefaultTreeModel model = new DefaultTreeModel(top);
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
    model.reload(root);
    tree.setModel(model);
    if(ep != null) {
        ep.expandPaths(tree, expanded_paths);
        tree.setSelectionPaths(paths);
    }
    return tree;
}
项目:OpenJSharp    文件:XSheet.java   
/**
 * Update the label of the supplied MBean tree node.
 */
// Call on EDT
private void updateNotificationsNodeLabel(
        DefaultMutableTreeNode node, String label) {
    synchronized (mbeansTab.getTree()) {
        invalidate();
        XNodeInfo oldUserObject = (XNodeInfo) node.getUserObject();
        XNodeInfo newUserObject = new XNodeInfo(
                oldUserObject.getType(), oldUserObject.getData(),
                label, oldUserObject.getToolTipText());
        node.setUserObject(newUserObject);
        DefaultTreeModel model =
                (DefaultTreeModel) mbeansTab.getTree().getModel();
        model.nodeChanged(node);
        validate();
        repaint();
    }
}
项目:QLExpress    文件:FileTree.java   
public void initData(String  rootPath){
        File f=new File(rootPath);
        PathNode root=new PathNode(f.getName(), rootPath,f.isDirectory());
        File[] files=f.listFiles();
        for(int i=0;i<files.length;i++){
            if(files[i].isDirectory() || files[i].getName().endsWith(".ql")){
                PathNode node=new PathNode(files[i].getName(), files[i].getAbsolutePath(),files[i].isDirectory());
                root.add(node);
            }
        }
        model=new DefaultTreeModel(root);
        this.setModel(model);
        FileTreeRenderer renderer=new FileTreeRenderer();
        this.setCellRenderer(renderer);
        this.repaint();
}
项目:JavaGraph    文件:CheckboxTree.java   
/**
 * Constructs a tree, with cell renderer and editor set by
 * {@link #createRenderer()} and {@link #createEditor()}.
 */
public CheckboxTree() {
    setCellRenderer(createRenderer());
    setCellEditor(createEditor());
    setEditable(true);
    setRootVisible(false);
    setShowsRootHandles(true);
    // make sure the checkbox never selects the label
    // note that the BasicTreeUI may not be what is used in the current LAF,
    // but I don't know any other way to modify the selection behaviour
    BasicTreeUI ui = new BasicTreeUI() {
        @Override
        protected void selectPathForEvent(TreePath path, MouseEvent event) {
            if (!isOverCheckBox(path, event.getPoint().x)) {
                super.selectPathForEvent(path, event);
            }
        }
    };
    setUI(ui);
    // initialise the tree model
    this.topNode = new DefaultMutableTreeNode();
    this.treeModel = new DefaultTreeModel(this.topNode);
    setModel(this.treeModel);
    // set selection mode
    getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
}
项目:sbc-qsystem    文件:FReception.java   
private void setModelForComboBoxServices(DefaultTreeModel model) {
    comboBoxServices = new JTreeComboBox(model);
    panelTreeCmbx.removeAll();
    panelTreeCmbx.setLayout(new GridLayout(1, 1));
    panelTreeCmbx.add(comboBoxServices);

    comboBoxServices.addItemListener((ItemEvent e) -> {
        if (((QService) e.getItem()).isLeaf()) {
            lastSelected = (QService) e.getItem();
            preRegChange(false);
        } else {
            comboBoxServices.setSelectedItem(lastSelected);
        }
    });
    comboBoxServices.setSelectedItem(model.getRoot());
}
项目:openjdk-jdk10    文件:LastNodeLowerHalfDrop.java   
protected static TreeModel getTreeModel() {
    root = new DefaultMutableTreeNode("Root");

    a = new DefaultMutableTreeNode("A");
    root.add(a);
    a1 = new DefaultMutableTreeNode("a1");
    a.add(a1);

    b = new DefaultMutableTreeNode("B");
    root.add(b);
    b1 = new DefaultMutableTreeNode("b1");
    b.add(b1);
    b2 = new DefaultMutableTreeNode("b2");
    b.add(b2);

    c = new DefaultMutableTreeNode("C");
    root.add(c);
    c1 = new DefaultMutableTreeNode("c1");
    c.add(c1);
    return new DefaultTreeModel(root);
}
项目:school-game    文件:DialogEditor.java   
public void rebuildTree()
{
    buildTree();

    if (treeView != null)
        ((DefaultTreeModel) treeView.getModel()).reload(root);
}
项目:automatic-variants    文件:PackagesManager.java   
public static void reloadPackageList() {
try {
    AVFileVars.importVariants(false);
    AVFileVars.AVPackages.sort();
    tree.setModel(new DefaultTreeModel(AVFileVars.AVPackages));
} catch (IOException ex) {
    SPGlobal.logException(ex);
}
   }
项目:incubator-netbeans    文件:DefaultOutlineCellRendererTest.java   
/**
 * Test of getTableCellRendererComponent method, of class
 * DefaultOutlineCellRenderer.
 */
public void testGetTableCellRendererComponent() {
    System.out.println("getTableCellRendererComponent");
    UIManager.put("Table.alternateRowColor", Color.red);
    final DefaultMutableTreeNode node1 = new DefaultMutableTreeNode();
    final DefaultMutableTreeNode node2 = new DefaultMutableTreeNode();
    final Object[][] values = new Object[][]{{node1, "01"}, {node2, "11"}};
    final String[] names = new String[]{"col1", "col2"};
    TreeModel treeModel = new DefaultTreeModel(new DefaultMutableTreeNode());
    DefaultTableModel tableModel = new DefaultTableModel(values, names);
    OutlineModel model = new DefaultOutlineModel(treeModel, tableModel, false, "Col1") {
    };
    final Outline outline = new Outline(model);
    ColorRenderDataProvider rdp = new ColorRenderDataProvider();
    outline.setRenderDataProvider(rdp);
    DefaultOutlineCellRenderer instance = new DefaultOutlineCellRenderer();
    Component result = instance.getTableCellRendererComponent(outline, node1, false, false, 0, 0);
    assertEquals("First line backgroundColor defaults to", outline.getBackground(), result.getBackground());
    assertEquals("Foreground defaults to", outline.getForeground(), result.getForeground());
    result = instance.getTableCellRendererComponent(outline, node2, false, false, 1, 0);
    assertEquals("Second line backgroundColor defaults to", Color.red, result.getBackground());
    assertEquals("Foreground defaults to", outline.getForeground(), result.getForeground());

    rdp.backgroundColor = Color.BLUE; // Custom background color
    rdp.foregroundColor = Color.GREEN; // Custom foreground color

    result = instance.getTableCellRendererComponent(outline, node1, false, false, 0, 0);
    assertEquals("First line backgroundColor is set as", Color.BLUE, result.getBackground());
    assertEquals("Foreground is set as", Color.GREEN, result.getForeground());
    result = instance.getTableCellRendererComponent(outline, node2, false, false, 1, 0);
    assertEquals("Second line backgroundColor is set as", Color.BLUE, result.getBackground());
    assertEquals("Foreground is set as", Color.GREEN, result.getForeground());
}
项目:incubator-netbeans    文件:CreateLibraryPanel.java   
@Messages("NAME_Library=Library Name")
CreateLibraryPanel(DependencyNode root) {
    initComponents();
    DefaultComboBoxModel mdl = new DefaultComboBoxModel();
    SwingValidationGroup.setComponentName(txtName, NAME_Library());

    for (LibraryManager manager : LibraryManager.getOpenManagers()) {
        mdl.addElement(manager);
    }
    comManager.setModel(mdl);
    comManager.addActionListener(new ActionListener() {
        public @Override void actionPerformed(ActionEvent e) {
            if (vg != null) {
                vg.performValidation();
            }
        }

    });
    comManager.setRenderer(new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            LibraryManager man = (LibraryManager) value;
            return super.getListCellRendererComponent(list, man.getDisplayName(), index, isSelected, cellHasFocus);
        }

    });
    trDeps.setCellRenderer(new CheckRenderer(false));
    CheckNodeListener l = new CheckNodeListener(false);
    trDeps.addMouseListener(l);
    trDeps.addKeyListener(l);
    trDeps.setToggleClickCount(0);
    trDeps.setRootVisible(false);
    trDeps.setModel(new DefaultTreeModel(new DefaultMutableTreeNode()));
    rootnode = root;
    trDeps.setModel(new DefaultTreeModel(createDependenciesList()));
    setLibraryName();
}
项目:incubator-netbeans    文件:ExcludeDependencyPanel.java   
private void trTransValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_trTransValueChanged
    TreeNode tn = (TreeNode) evt.getPath().getLastPathComponent();
    if (tn instanceof CheckNode) {
        setReferenceTree((CheckNode)tn);
    } else {
        trRef.setModel(new DefaultTreeModel(new DefaultMutableTreeNode()));
    }

}
项目:featurea    文件:GeneralPropPane.java   
private void refreshInterfaceList() {
    this.interfacesRootNode.removeAllChildren();
    int i = this.currClassFile.interfaces.getInterfacesCount();
    for (int j = 0; j < i; j++) {
        String str = this.currClassFile.interfaces.getInterfaceName(j);
        DefaultMutableTreeNode localDefaultMutableTreeNode = new DefaultMutableTreeNode(str);
        localDefaultMutableTreeNode.setUserObject(str);
        this.interfacesRootNode.add(localDefaultMutableTreeNode);
    }
    this.treeInterfaces.setModel(new DefaultTreeModel(this.interfacesRootNode));
}
项目:incubator-netbeans    文件:GsfHintsManager.java   
private void initHints() {
    DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode();
    hintsTreeModel = new DefaultTreeModel( rootNode );
    FileObject folder = FileUtil.getConfigFile( RULES_FOLDER + mimeType + HINTS ); // NOI18N
    List<Pair<Rule,FileObject>> rules = readRules(folder);
    categorizeAstRules( rules, hints, folder, rootNode );
}
项目:Logisim    文件:ComponentSelector.java   
public ComponentSelector(Model logModel) {
    DefaultTreeModel model = new DefaultTreeModel(null);
    model.setAsksAllowsChildren(false);
    setModel(model);
    setRootVisible(false);
    setLogModel(logModel);
    setCellRenderer(new MyCellRenderer());
}
项目:incubator-netbeans    文件:DirectoryChooserUI.java   
private void expandNode(final JFileChooser fileChooser, final TreePath path) {

    RequestProcessor.getDefault().post(new Runnable() {
        DirectoryNode node;

        @Override
        public void run() {
            if (!EventQueue.isDispatchThread()) {
                // first pass, out of EQ thread, loads data
                markStartTime();
                setCursor(fileChooser, Cursor.WAIT_CURSOR);
                node = (DirectoryNode) path.getLastPathComponent();
                node.loadChildren(fileChooser, true);
                // send to second pass
                EventQueue.invokeLater(this);
            } else {
                // second pass, in EQ thread
                ((DefaultTreeModel) tree.getModel()).nodeStructureChanged(node);
              /*
               * This happens when the add new directory action is called
               * and the node is not loaded.  Furthermore, it ensures that
               * adding a new directory execute after the UI has finished
               * displaying the children of the expanded node.
               */
                if(addNewDirectory) {
                    addNewDirectory(path);
                    addNewDirectory = false;
                }
                setCursor(fileChooser, Cursor.DEFAULT_CURSOR);
                checkUpdate();
            }
        }
    });
}
项目:incubator-netbeans    文件:DirectoryChooserUI.java   
@Override
public void valueForPathChanged(TreePath path, Object newValue) {
    boolean refreshTree = false;
    if (path == null) {
        // no idea
        return;
    }
    DirectoryNode node = (DirectoryNode)path.getLastPathComponent();
    File f = node.getFile();
    File newFile = getFileChooser().getFileSystemView().createFileObject(f.getParentFile(), (String)newValue);

    if(f.renameTo(newFile)) {
        // fix bug #97521, #96960
        if(tree.isExpanded(path)) {
            tree.collapsePath(path);
            refreshTree = true;
        }

        node.setFile(newFile);
        node.removeAllChildren();

        ((DefaultTreeModel) tree.getModel()).nodeStructureChanged(node);
        if(refreshTree) {
            tree.expandPath(path);
        }
    }
}
项目:incubator-netbeans    文件:HintsPanel.java   
private void setModel(DefaultTreeModel errorTreeModel) {
    if (optionsFilter!=null) {
        optionsFilter.installFilteringModel(errorTree, errorTreeModel, new AcceptorImpl());
    } else {
        errorTree.setModel(errorTreeModel);
    }
}
项目:incubator-netbeans    文件:PathsCustomizer.java   
private static DefaultTreeModel toTreeModel(final DefaultListModel lm, final String rootName) {
    DefaultMutableTreeNode root = new DefaultMutableTreeNode(rootName);
    for (int i = 0; i < lm.getSize(); i++) {
        Object obj = lm.getElementAt(i);
        if (obj instanceof ClassPathSupport.Item) {
            root.add(toTreeNode(obj));
        }
    }
    return new DefaultTreeModel(root);
}
项目:incubator-netbeans    文件:PathsCustomizer.java   
private static DefaultTreeModel toTreeModel(final DefaultListModel lm, final String rootName) {
    DefaultMutableTreeNode root = new DefaultMutableTreeNode(rootName);
    for (int i = 0; i < lm.getSize(); i++) {
        Object obj = lm.getElementAt(i);
        if (obj instanceof ClassPathSupport.Item) {
            root.add(toTreeNode(obj));
        }
    }
    return new DefaultTreeModel(root);
}