public CheckBoxTreeSelectionModel getCheckBoxTreeSelectionModel() { return tree.getCheckBoxTreeSelectionModel(); }
/** * Gets the dig-in mode. If the CheckBoxTree is in dig-in mode, checking the parent node will check all the * children. Correspondingly, getSelectionPaths() will only return the parent tree path. If not in dig-in mode, each * tree node can be checked or unchecked independently * * @return true or false. */ public boolean isDigIn() { return getCheckBoxTreeSelectionModel().isDigIn(); }
@Override public void selectNone() { checkBoxTree.getCheckBoxTreeSelectionModel().clearSelection(); }
@Override public void selectNone() { checkBoxTree.getCheckBoxTreeSelectionModel().clearSelection(); }
@Override public boolean atLeastOneBandSelected() { return checkBoxTree.getCheckBoxTreeSelectionModel().getSelectionPaths() != null; }
@Override public boolean atLeastOneBandSelected() { return checkBoxTree.getCheckBoxTreeSelectionModel().getSelectionPaths() != null; }
@Override public void selectAll() { checkBoxTree.getCheckBoxTreeSelectionModel().setSelectionPath(new TreePath(checkBoxTree.getModel().getRoot())); }
@Override public void selectAll() { checkBoxTree.getCheckBoxTreeSelectionModel().setSelectionPath(new TreePath(checkBoxTree.getModel().getRoot())); }
private void selectRasterDataNodes(DefaultMutableTreeNode node, String[] nodeNames) { int childCount = node.getChildCount(); if(childCount != 0) { for(int i = 0; i < childCount; i++) { selectRasterDataNodes((DefaultMutableTreeNode)node.getChildAt(i), nodeNames); } } else { for (String nodeName : nodeNames) { if (nodeName.equals(((String) node.getUserObject()).split(" ")[0].trim())) { List<TreeNode> pathList = new ArrayList<>(); TreeNode currentNode = node; while(currentNode != null) { pathList.add(0, currentNode); currentNode = currentNode.getParent(); } TreePath path = new TreePath(pathList.toArray(new TreeNode[pathList.size()])); checkBoxTree.getCheckBoxTreeSelectionModel().addSelectionPath(path); } } } }
private void selectRasterDataNodes(DefaultMutableTreeNode node, String[] nodeNames) { int childCount = node.getChildCount(); if(childCount != 0) { for(int i = 0; i < childCount; i++) { selectRasterDataNodes((DefaultMutableTreeNode)node.getChildAt(i), nodeNames); } } else { for (String nodeName : nodeNames) { if (nodeName.equals(((String) node.getUserObject()).split(" ")[0].trim())) { List<TreeNode> pathList = new ArrayList<>(); TreeNode currentNode = node; while(currentNode != null) { pathList.add(0, currentNode); currentNode = currentNode.getParent(); } TreePath path = new TreePath(pathList.toArray(new TreeNode[pathList.size()])); checkBoxTree.getCheckBoxTreeSelectionModel().addSelectionPath(path); } } } }
@Override public TiePointGrid[] getSelectedTiePointGrids() { List<TiePointGrid> selectedGridList = new ArrayList<>(); final TreePath[] selectionPaths = checkBoxTree.getCheckBoxTreeSelectionModel().getSelectionPaths(); TreePath rootPath = new TreePath(checkBoxTree.getModel().getRoot()); for (TreePath selectionPath : selectionPaths) { if (selectionPath.equals(rootPath)) { return allGridsMap.keySet().toArray(new TiePointGrid[allGridsMap.size()]); } final DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) selectionPath.getLastPathComponent(); if (selectedNode.isLeaf()) { RasterDataNode key = getKey(selectedNode.getUserObject().toString(), allGridsMap); if (key != null) { selectedGridList.add((TiePointGrid) key); } } else { for (int i = 0; i < selectedNode.getChildCount(); i++) { final DefaultMutableTreeNode child = (DefaultMutableTreeNode) selectedNode.getChildAt(i); RasterDataNode key = getKey(child.getUserObject().toString(), allGridsMap); if (key != null) { selectedGridList.add((TiePointGrid) key); } selectedGridList.add((TiePointGrid) key); } } } return selectedGridList.toArray(new TiePointGrid[selectedGridList.size()]); }
@Override public Band[] getSelectedBands() { List<Band> selectedBandList = new ArrayList<>(); final TreePath[] selectionPaths = checkBoxTree.getCheckBoxTreeSelectionModel().getSelectionPaths(); TreePath rootPath = new TreePath(checkBoxTree.getModel().getRoot()); for (TreePath selectionPath : selectionPaths) { if (selectionPath.equals(rootPath)) { return allBandsMap.keySet().toArray(new Band[allBandsMap.size()]); } final DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) selectionPath.getLastPathComponent(); if (selectedNode.isLeaf()) { RasterDataNode key = getKey(selectedNode.getUserObject().toString(), allBandsMap); if (key != null) { selectedBandList.add((Band) key); } } else { for (int i = 0; i < selectedNode.getChildCount(); i++) { final DefaultMutableTreeNode child = (DefaultMutableTreeNode) selectedNode.getChildAt(i); RasterDataNode key = getKey(child.getUserObject().toString(), allBandsMap); if (key != null) { selectedBandList.add((Band) key); } } } } return selectedBandList.toArray(new Band[selectedBandList.size()]); }
@Override public TiePointGrid[] getSelectedTiePointGrids() { List<TiePointGrid> selectedGridList = new ArrayList<>(); final TreePath[] selectionPaths = checkBoxTree.getCheckBoxTreeSelectionModel().getSelectionPaths(); TreePath rootPath = new TreePath(checkBoxTree.getModel().getRoot()); for (TreePath selectionPath : selectionPaths) { if (selectionPath.equals(rootPath)) { return allGridsMap.keySet().toArray(new TiePointGrid[allGridsMap.size()]); } final DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) selectionPath.getLastPathComponent(); if (selectedNode.isLeaf()) { RasterDataNode key = getKey(selectedNode.getUserObject().toString(), allGridsMap); if (key != null) { selectedGridList.add((TiePointGrid) key); } } else { for (int i = 0; i < selectedNode.getChildCount(); i++) { final DefaultMutableTreeNode child = (DefaultMutableTreeNode) selectedNode.getChildAt(i); RasterDataNode key = getKey(child.getUserObject().toString(), allGridsMap); if (key != null) { selectedGridList.add((TiePointGrid) key); } selectedGridList.add((TiePointGrid) key); } } } return selectedGridList.toArray(new TiePointGrid[selectedGridList.size()]); }
@Override public Band[] getSelectedBands() { List<Band> selectedBandList = new ArrayList<>(); final TreePath[] selectionPaths = checkBoxTree.getCheckBoxTreeSelectionModel().getSelectionPaths(); TreePath rootPath = new TreePath(checkBoxTree.getModel().getRoot()); for (TreePath selectionPath : selectionPaths) { if (selectionPath.equals(rootPath)) { return allBandsMap.keySet().toArray(new Band[allBandsMap.size()]); } final DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) selectionPath.getLastPathComponent(); if (selectedNode.isLeaf()) { RasterDataNode key = getKey(selectedNode.getUserObject().toString(), allBandsMap); if (key != null) { selectedBandList.add((Band) key); } } else { for (int i = 0; i < selectedNode.getChildCount(); i++) { final DefaultMutableTreeNode child = (DefaultMutableTreeNode) selectedNode.getChildAt(i); RasterDataNode key = getKey(child.getUserObject().toString(), allBandsMap); if (key != null) { selectedBandList.add((Band) key); } } } } return selectedBandList.toArray(new Band[selectedBandList.size()]); }
public void updateCheckBoxStates() { final TreePath[] selectionPaths = checkBoxTree.getCheckBoxTreeSelectionModel().getSelectionPaths(); if (selectionPaths == null || selectionPaths.length == 0) { selectAllCheckBox.setSelected(false); selectAllCheckBox.setEnabled(true); selectAllCheckBox.updateUI(); selectNoneCheckBox.setSelected(true); selectNoneCheckBox.setEnabled(false); selectNoneCheckBox.updateUI(); } else { final TreePath rootPath = new TreePath(checkBoxTree.getModel().getRoot()); boolean allSelected = false; for (TreePath selectionPath : selectionPaths) { if (selectionPath.equals(rootPath)) { allSelected = true; } selectAllCheckBox.setSelected(allSelected); selectAllCheckBox.setEnabled(!allSelected); selectAllCheckBox.updateUI(); selectNoneCheckBox.setSelected(false); selectNoneCheckBox.setEnabled(true); selectNoneCheckBox.updateUI(); } } }
public void updateCheckBoxStates() { final TreePath[] selectionPaths = checkBoxTree.getCheckBoxTreeSelectionModel().getSelectionPaths(); if (selectionPaths == null || selectionPaths.length == 0) { selectAllCheckBox.setSelected(false); selectAllCheckBox.setEnabled(true); selectAllCheckBox.updateUI(); selectNoneCheckBox.setSelected(true); selectNoneCheckBox.setEnabled(false); selectNoneCheckBox.updateUI(); } else { final TreePath rootPath = new TreePath(checkBoxTree.getModel().getRoot()); boolean allSelected = false; for (TreePath selectionPath : selectionPaths) { if (selectionPath.equals(rootPath)) { allSelected = true; } selectAllCheckBox.setSelected(allSelected); selectAllCheckBox.setEnabled(!allSelected); selectAllCheckBox.updateUI(); selectNoneCheckBox.setSelected(false); selectNoneCheckBox.setEnabled(true); selectNoneCheckBox.updateUI(); } } }
/** * Sets the dig-in mode. If the CheckBoxTree is in dig-in mode, checking the parent node will check all the * children. Correspondingly, getSelectionPaths() will only return the parent tree path. If not in dig-in mode, each * tree node can be checked or unchecked independently * * @param digIn the new digIn mode. */ public void setDigIn(boolean digIn) { boolean old = isDigIn(); if (old != digIn) { getCheckBoxTreeSelectionModel().setDigIn(digIn); firePropertyChange(PROPERTY_DIG_IN, old, digIn); } }
private void updateLayerTreeVisibility(Layer layer) { CheckBoxTreeSelectionModel checkBoxTreeSelectionModel = layerTree.getCheckBoxTreeSelectionModel(); Layer[] layerPath = LayerUtils.getLayerPath(layerTreeModel.getRootLayer(), layer); if (layerPath.length > 0) { if (layer.isVisible()) { checkBoxTreeSelectionModel.addSelectionPath(new TreePath(layerPath)); } else { checkBoxTreeSelectionModel.removeSelectionPath(new TreePath(layerPath)); } final List<Layer> children = layer.getChildren(); if (!children.isEmpty()) { for (Layer child : children) { updateLayerTreeVisibility(child); } } } }
private void updateLayerTreeVisibility(Layer layer) { CheckBoxTreeSelectionModel checkBoxTreeSelectionModel = layerTree.getCheckBoxTreeSelectionModel(); Layer[] layerPath = LayerUtils.getLayerPath(layerTreeModel.getRootLayer(), layer); if (layerPath.length > 0) { if (layer.isVisible()) { checkBoxTreeSelectionModel.addSelectionPath(new TreePath(layerPath)); } else { checkBoxTreeSelectionModel.removeSelectionPath(new TreePath(layerPath)); } final List<Layer> children = layer.getChildren(); if (!children.isEmpty()) { for (Layer child : children) { updateLayerTreeVisibility(child); } } } }
private CheckBoxTree createCheckBoxTree(LayerTreeModel treeModel) { final CheckBoxTree checkBoxTree = new CheckBoxTree(treeModel) { @Override public boolean isPathEditable(TreePath path) { Layer layer = getLayer(path); if (layer != null) { return isLayerNameEditable(layer); } return false; } }; checkBoxTree.setRootVisible(false); checkBoxTree.setShowsRootHandles(true); checkBoxTree.setDigIn(false); checkBoxTree.setEditable(true); checkBoxTree.setDragEnabled(true); checkBoxTree.setDropMode(DropMode.ON_OR_INSERT); checkBoxTree.setTransferHandler(new LayerTreeTransferHandler(view, checkBoxTree)); checkBoxTree.getSelectionModel().addTreeSelectionListener(new LayerSelectionListener()); final CheckBoxTreeSelectionModel checkBoxSelectionModel = checkBoxTree.getCheckBoxTreeSelectionModel(); checkBoxSelectionModel.addTreeSelectionListener(new CheckBoxTreeSelectionListener()); final DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) checkBoxTree.getActualCellRenderer(); renderer.setLeafIcon(null); renderer.setClosedIcon(null); renderer.setOpenIcon(null); return checkBoxTree; }