public GroupedBandChoosingStrategy(Band[] allBands, Band[] selectedBands, TiePointGrid[] allTiePointGrids, TiePointGrid[] selectedTiePointGrids, Product.AutoGrouping autoGrouping, boolean multipleProducts) { allBandsMap = createBandMap(allBands); selectedBandsMap = createBandMap(selectedBands); allGridsMap = createTiepointGridMap(allTiePointGrids); selectedGridsMap = createTiepointGridMap(selectedTiePointGrids); this.autoGrouping = autoGrouping; this.multipleProducts = multipleProducts; }
private Map<TiePointGrid, String> createTiepointGridMap(TiePointGrid[] grids) { final Map<TiePointGrid, String> gridMap = new TreeMap<>(new Comparator<TiePointGrid>() { @Override public int compare(TiePointGrid grid1, TiePointGrid grid2) { return grid1.getName().compareTo(grid2.getName()); } }); if (grids != null) { for (TiePointGrid grid : grids) { gridMap.put(grid, getDisplayDescription(grid)); } } return gridMap; }
private Map<String, Integer> initGrouping(DefaultMutableTreeNode root) { Map<String, Integer> groupNodeMap = new HashMap<>(); if (autoGrouping != null) { for (String[] groupNames : autoGrouping) { final String groupName = groupNames[0]; if (!hasChild(root, groupName)) { DefaultMutableTreeNode groupNode = new DefaultMutableTreeNode(groupName); groupNodeMap.put(groupNode.getUserObject().toString(), root.getChildCount()); root.add(groupNode); } } } return groupNodeMap; }
public JPanel createCheckersPane() { DefaultMutableTreeNode root = new DefaultMutableTreeNode(); Map<String, Integer> groupNodeMap = initGrouping(root); List<TreePath> selectedPaths = new ArrayList<>(); addBandCheckBoxes(root, selectedPaths, groupNodeMap); addTiePointGridCheckBoxes(root, selectedPaths, groupNodeMap); removeEmptyGroups(root, groupNodeMap);
private void addTiePointGridCheckBoxes(DefaultMutableTreeNode root, List<TreePath> selectedPaths, Map<String, Integer> groupNodeMap) { final Set<Map.Entry<TiePointGrid, String>> allGrids = allGridsMap.entrySet(); for (Map.Entry<TiePointGrid, String> gridEntry : allGrids) { final TiePointGrid grid = gridEntry.getKey(); if (autoGrouping != null) { final int gridIndex = autoGrouping.indexOf(grid.getName()); if (gridIndex >= 0) { final String groupName = autoGrouping.get(gridIndex)[0]; final Integer index = groupNodeMap.get(groupName); final DefaultMutableTreeNode groupNode = (DefaultMutableTreeNode) root.getChildAt(index); final DefaultMutableTreeNode groupChild = new DefaultMutableTreeNode(gridEntry.getValue()); if (selectedGridsMap.containsKey(grid)) { selectedPaths.add(new TreePath(new Object[]{root, groupNode, groupChild})); } groupNode.add(groupChild); } else { addToRoot(root, selectedPaths, gridEntry, grid); } } else { addToRoot(root, selectedPaths, gridEntry, grid); } } }
@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()]); }
public BandChooser(Window parent, String title, String helpID, Band[] allBands, Band[] selectedBands, Product.AutoGrouping autoGrouping, boolean addLoadSaveConfigurationButtons) { super(parent, title, ModalDialog.ID_OK_CANCEL, helpID); this.addLoadSaveConfigurationButtons = addLoadSaveConfigurationButtons; boolean multipleProducts = bandsAndGridsFromMoreThanOneProduct(allBands, null); strategy = new GroupedBandChoosingStrategy(allBands, selectedBands, null, null, autoGrouping, multipleProducts); selectAtLeastOneBand = false; initUI(); }
private void addBandCheckBoxes(DefaultMutableTreeNode root, List<TreePath> selectedPaths, Map<String, Integer> groupNodeMap) { final Set<Map.Entry<Band, String>> allBands = allBandsMap.entrySet(); for (Map.Entry<Band, String> bandEntry : allBands) { final Band band = bandEntry.getKey(); if (autoGrouping != null) { final int bandIndex = autoGrouping.indexOf(band.getName()); if (bandIndex >= 0) { final String groupName = autoGrouping.get(bandIndex)[0]; final Integer index = groupNodeMap.get(groupName); final DefaultMutableTreeNode groupNode = (DefaultMutableTreeNode) root.getChildAt(index); final DefaultMutableTreeNode groupChild = new DefaultMutableTreeNode(bandEntry.getValue()); if (selectedBandsMap.containsValue(bandEntry.getValue())) { selectedPaths.add(new TreePath(new Object[]{root, groupNode, groupChild})); } groupNode.add(groupChild); } else { addToRoot(root, selectedPaths, bandEntry, band); } } else { addToRoot(root, selectedPaths, bandEntry, band); } } }
@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()]); }
private Map<Band, String> createBandMap(Band[] bands) { final Map<Band, String> bandMap = new TreeMap<>(BandSorter.createComparator()); if (bands != null) { for (Band band : bands) { bandMap.put(band, getDisplayDescription(band)); } } return bandMap; }