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);
}
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);
}
Aggregations