@Override public void selectAll() { checkBoxTree.getCheckBoxTreeSelectionModel().setSelectionPath(new TreePath(checkBoxTree.getModel().getRoot())); }
/** * Gets the cell renderer with check box. * * @return CheckBoxTree's own cell renderer which has the check box. The actual cell renderer you set by * setCellRenderer() can be accessed by using {@link #getActualCellRenderer()}. */ @Override public TreeCellRenderer getCellRenderer() { TreeCellRenderer cellRenderer = getActualCellRenderer(); if (cellRenderer == null) { cellRenderer = getDefaultRenderer(); } if (_treeCellRenderer == null) { _treeCellRenderer = createCellRenderer(cellRenderer); } else { _treeCellRenderer.setActualTreeRenderer(cellRenderer); } return _treeCellRenderer; }
private void updateLayerTreeSelection(Layer selectedLayer) { if (selectedLayer != null) { Layer[] layerPath = LayerUtils.getLayerPath(layerTreeModel.getRootLayer(), selectedLayer); if (layerPath.length > 0) { layerTree.setSelectionPath(new TreePath(layerPath)); } else { layerTree.clearSelection(); } } else { layerTree.clearSelection(); } }
/** * 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 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; }
checkBoxTree = new CheckBoxTree(treeModel); checkBoxTree.getCheckBoxTreeSelectionModel().setSelectionPaths(selectedPaths.toArray(new TreePath[selectedPaths.size()])); checkBoxTree.setRootVisible(false); checkBoxTree.setShowsRootHandles(true); checkBoxTree.getCheckBoxTreeSelectionModel().addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { final DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) checkBoxTree.getActualCellRenderer(); renderer.setFont(SMALL_ITALIC_FONT); renderer.setLeafIcon(null); renderer.setClosedIcon(null); Color color = new Color(240, 240, 240); checkBoxTree.setBackground(color); renderer.setBackgroundSelectionColor(color); renderer.setBackgroundNonSelectionColor(color);
tree.setModel(dtm); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); tree.setRootVisible(false); tree.getCheckBoxTreeSelectionModel().addSelectionPath(new TreePath(root.getPath())); JScrollPane jsp = (JScrollPane) tree.getParent().getParent(); JViewport jv = jsp.getViewport(); size = tree.getPreferredScrollableViewportSize(); size = jv.getViewSize(); jsp.setPreferredSize(new Dimension(550, 300)); size = tree.getPreferredScrollableViewportSize(); size = jv.getViewSize();
public CheckBoxTreeSelectionModel getCheckBoxTreeSelectionModel() { return tree.getCheckBoxTreeSelectionModel(); }
/** * Initialize the CheckBoxTree. */ protected void init() { _checkBoxTreeSelectionModel = createCheckBoxTreeSelectionModel(getModel()); _checkBoxTreeSelectionModel.setTree(this); Handler handler = createHandler(); JideSwingUtilities.insertMouseListener(this, handler, 0); addKeyListener(handler); _checkBoxTreeSelectionModel.addTreeSelectionListener(handler); if (_modelChangeListener == null) { _modelChangeListener = new ModelPropertyChangeListener(); } addPropertyChangeListener(JTree.SELECTION_MODEL_PROPERTY, _modelChangeListener); addPropertyChangeListener("model", _modelChangeListener); updateRowMapper(); }
private void toggleSelections(TreePath[] treePaths) { if (treePaths == null || treePaths.length == 0 || !_tree.isEnabled()) { return; CheckBoxTreeSelectionModel selectionModel = _tree.getCheckBoxTreeSelectionModel(); List<TreePath> pathToAdded = new ArrayList<TreePath>(); List<TreePath> pathToRemoved = new ArrayList<TreePath>(); for (TreePath treePath : treePaths) { if (!_tree.isCheckBoxEnabled(treePath)) { continue; if (!_tree.isSelectPartialOnToggling() && selectionModel.isPartiallySelected(treePath)) { TreePath[] selectionPaths = selectionModel.getSelectionPaths(); if (selectionPaths != null) { _tree.treeDidChange();
CheckBoxTreeSelectionModel selectionModel = ((CheckBoxTree) tree).getCheckBoxTreeSelectionModel(); if (selectionModel != null) { boolean enabled = tree.isEnabled() && ((CheckBoxTree) tree).isCheckBoxEnabled() && ((CheckBoxTree) tree).isCheckBoxEnabled(path); if (!enabled && !selected) { if (getBackground() != null) { setBorder(border); treeCellRendererComponent.setBorder(BorderFactory.createEmptyBorder()); if (path == null || !(tree instanceof CheckBoxTree) || ((CheckBoxTree) tree).isCheckBoxVisible(path)) { remove(_emptyBox); add(_checkBox, BorderLayout.BEFORE_LINE_BEGINS);
public void expandAndSelectAll(boolean expand) { TreeNode root = (TreeNode) tree.getModel().getRoot(); // Traverse tree from root expandAndSelectAll(new TreePath(root), expand); }
/** * RowMapper is necessary for contiguous selection. */ private void updateRowMapper() { _checkBoxTreeSelectionModel.setRowMapper(getSelectionModel().getRowMapper()); }
@Override public void stateChanged(ChangeEvent e) { TreePath path = layerTree.getSelectionPath(); if (path != null) { Layer layer = getLayer(path); adjusting = true; layer.setTransparency(transparencySlider.getValue() / 255.0); adjusting = false; } } }
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; }
checkBoxTree = new CheckBoxTree(treeModel); checkBoxTree.getCheckBoxTreeSelectionModel().setSelectionPaths(selectedPaths.toArray(new TreePath[selectedPaths.size()])); checkBoxTree.setRootVisible(false); checkBoxTree.setShowsRootHandles(true); checkBoxTree.getCheckBoxTreeSelectionModel().addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { final DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) checkBoxTree.getActualCellRenderer(); renderer.setFont(SMALL_ITALIC_FONT); renderer.setLeafIcon(null); renderer.setClosedIcon(null); Color color = new Color(240, 240, 240); checkBoxTree.setBackground(color); renderer.setBackgroundSelectionColor(color); renderer.setBackgroundNonSelectionColor(color);
/** * 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 selectRasterDataNodes(String[] nodeNames) { DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) checkBoxTree.getModel().getRoot(); selectRasterDataNodes(rootNode, nodeNames); }
@Override public void stateChanged(ChangeEvent e) { TreePath path = layerTree.getSelectionPath(); if (path != null) { Layer layer = getLayer(path); adjusting = true; layer.setTransparency(transparencySlider.getValue() / 255.0); adjusting = false; } } }
@Override public void selectAll() { checkBoxTree.getCheckBoxTreeSelectionModel().setSelectionPath(new TreePath(checkBoxTree.getModel().getRoot())); }