java类javax.swing.tree.DefaultTreeModel的实例源码

AssetTree.java 文件源码 项目:litiengine 阅读 13 收藏 0 点赞 0 评论 0
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());
  });
}
TreeModelEditor.java 文件源码 项目:incubator-netbeans 阅读 15 收藏 0 点赞 0 评论 0
/**
 * 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;
}
RefactoringPanel.java 文件源码 项目:incubator-netbeans 阅读 15 收藏 0 点赞 0 评论 0
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();
        }
    }
ASTBrowserTopComponent.java 文件源码 项目:incubator-netbeans 阅读 24 收藏 0 点赞 0 评论 0
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);
}
TokensBrowserTopComponent.java 文件源码 项目:incubator-netbeans 阅读 22 收藏 0 点赞 0 评论 0
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);
            }
        }
    });
}
JarFileTree.java 文件源码 项目:Recaf 阅读 96 收藏 0 点赞 0 评论 0
/**
 * 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);
}
GeneralPropPane.java 文件源码 项目:featurea 阅读 20 收藏 0 点赞 0 评论 0
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("");
}
HintsPanelLogic.java 文件源码 项目:incubator-netbeans 阅读 21 收藏 0 点赞 0 评论 0
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);

}
EditorDeTipos.java 文件源码 项目:brModelo 阅读 17 收藏 0 点赞 0 评论 0
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);
}
MobileObjectSpy.java 文件源码 项目:Cognizant-Intelligent-Test-Scripter 阅读 13 收藏 0 点赞 0 评论 0
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());
    }

}
PathsCustomizer.java 文件源码 项目:incubator-netbeans 阅读 20 收藏 0 点赞 0 评论 0
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);
}
PathsCustomizer.java 文件源码 项目:incubator-netbeans 阅读 30 收藏 0 点赞 0 评论 0
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);
}
RevertPanel.java 文件源码 项目:incubator-netbeans 阅读 16 收藏 0 点赞 0 评论 0
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
    }
}
OptionsChooserPanel.java 文件源码 项目:incubator-netbeans 阅读 15 收藏 0 点赞 0 评论 0
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();
}
Tab.java 文件源码 项目:incubator-netbeans 阅读 20 收藏 0 点赞 0 评论 0
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);
            }
        }
    });
}
MapPlaces.java 文件源码 项目:geomapapp 阅读 13 收藏 0 点赞 0 评论 0
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);
}
IdeaCurrencyConfigUI.java 文件源码 项目:IdeaCurrency 阅读 19 收藏 0 点赞 0 评论 0
@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();
}
ThreadInfoStorageTree.java 文件源码 项目:AgentWorkbench 阅读 24 收藏 0 点赞 0 评论 0
/**
 * 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;
            }
        }
    }
}
Test8015926.java 文件源码 项目:openjdk-jdk10 阅读 21 收藏 0 点赞 0 评论 0
@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);
}
Test8015926.java 文件源码 项目:jdk8u-jdk 阅读 21 收藏 0 点赞 0 评论 0
@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);
}
ViewResultsFullVisualizer.java 文件源码 项目:jmeter-bzm-plugins 阅读 20 收藏 0 点赞 0 评论 0
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;
}
JTreeUtils.java 文件源码 项目:JAddOn 阅读 20 收藏 0 点赞 0 评论 0
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;
}
XSheet.java 文件源码 项目:OpenJSharp 阅读 22 收藏 0 点赞 0 评论 0
/**
 * 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();
    }
}
FileTree.java 文件源码 项目:QLExpress 阅读 29 收藏 0 点赞 0 评论 0
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();
}
CheckboxTree.java 文件源码 项目:JavaGraph 阅读 24 收藏 0 点赞 0 评论 0
/**
 * 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);
}
FReception.java 文件源码 项目:sbc-qsystem 阅读 17 收藏 0 点赞 0 评论 0
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());
}
LastNodeLowerHalfDrop.java 文件源码 项目:openjdk-jdk10 阅读 22 收藏 0 点赞 0 评论 0
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);
}
DialogEditor.java 文件源码 项目:school-game 阅读 20 收藏 0 点赞 0 评论 0
public void rebuildTree()
{
    buildTree();

    if (treeView != null)
        ((DefaultTreeModel) treeView.getModel()).reload(root);
}
PackagesManager.java 文件源码 项目:automatic-variants 阅读 16 收藏 0 点赞 0 评论 0
public static void reloadPackageList() {
try {
    AVFileVars.importVariants(false);
    AVFileVars.AVPackages.sort();
    tree.setModel(new DefaultTreeModel(AVFileVars.AVPackages));
} catch (IOException ex) {
    SPGlobal.logException(ex);
}
   }
DefaultOutlineCellRendererTest.java 文件源码 项目:incubator-netbeans 阅读 16 收藏 0 点赞 0 评论 0
/**
 * 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());
}


问题


面经


文章

微信
公众号

扫码关注公众号