Search in sources :

Example 6 with DefaultMutableTreeTableNode

use of org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode in project GsonFormat by zzz40500.

the class CheckTreeCellProvider method format.

@Override
protected void format(CellContext arg0) {
    //  从CellContext获取tree中的文字和图标
    JTree tree = (JTree) arg0.getComponent();
    DefaultMutableTreeTableNode node = (DefaultMutableTreeTableNode) arg0.getValue();
    Object obj = node.getUserObject();
    if (obj instanceof FieldEntity) {
        _label.setText(((FieldEntity) obj).getKey());
        _checkBox.setSelector((FieldEntity) obj);
    } else if (obj instanceof ClassEntity) {
        _label.setText(((ClassEntity) obj).getClassName());
        _checkBox.setSelector((ClassEntity) obj);
    }
    //        _label.setIcon(arg0.getIcon());
    //  根据selectionModel中的状态来绘制TristateCheckBox的外观
    TreePath path = tree.getPathForRow(arg0.getRow());
    if (path != null) {
        if (selectionModel.isPathSelected(path, true)) {
            _checkBox.setState(Boolean.TRUE);
        } else if (selectionModel.isPartiallySelected(path)) {
            //  注意“部分选中”状态的API
            _checkBox.setState(null);
        } else {
            _checkBox.setState(Boolean.FALSE);
        }
    }
    //  使用BorderLayout布局,依次放置TristateCheckBox和JLabel
    rendererComponent.setLayout(new BorderLayout());
    rendererComponent.add(_checkBox);
    rendererComponent.add(_label, BorderLayout.LINE_END);
}
Also used : ClassEntity(org.gsonformat.intellij.entity.ClassEntity) JTree(javax.swing.JTree) TreePath(javax.swing.tree.TreePath) BorderLayout(java.awt.BorderLayout) FieldEntity(org.gsonformat.intellij.entity.FieldEntity) DefaultMutableTreeTableNode(org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode)

Example 7 with DefaultMutableTreeTableNode

use of org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode in project GsonFormat by zzz40500.

the class CheckTreeSelectionModel method addPathsByNodes.

public void addPathsByNodes(List selectedNodes) {
    int num = selectedNodes.size();
    TreePath[] tps = new TreePath[num];
    for (int i = 0; i < num; i++) {
        DefaultMutableTreeTableNode node = (DefaultMutableTreeTableNode) selectedNodes.get(i);
        tps[i] = new TreePath(getPathToRoot(node));
    }
    this.addSelectionPaths(tps);
}
Also used : TreePath(javax.swing.tree.TreePath) DefaultMutableTreeTableNode(org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode)

Aggregations

DefaultMutableTreeTableNode (org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode)7 TreePath (javax.swing.tree.TreePath)2 ClassEntity (org.gsonformat.intellij.entity.ClassEntity)2 FieldEntity (org.gsonformat.intellij.entity.FieldEntity)2 CellProvider (org.jdesktop.swingx.ux.CellProvider)2 FiledTreeTableModel (cn.vearn.checktreetable.FiledTreeTableModel)1 BorderLayout (java.awt.BorderLayout)1 JTree (javax.swing.JTree)1 ListSelectionEvent (javax.swing.event.ListSelectionEvent)1 ListSelectionListener (javax.swing.event.ListSelectionListener)1 JXTreeTable (org.jdesktop.swingx.JXTreeTable)1 CheckTreeTableManager (org.jdesktop.swingx.ux.CheckTreeTableManager)1