/** * 参数条件树上增加节点 * * @param conditionNodeObj */ private TreeNode addParaTreNode(IStatisticCaliber aCal) { // 得到父节点 DefaultTreeModel treeModel = (DefaultTreeModel) treWhere.getModel(); DefaultMutableTreeNode root = (DefaultMutableTreeNode) treeModel.getRoot(); // 判断增加的父节点是否已存在,默认父节点不存在 boolean sFlag = false; IStatisticCaliber curCal = null; DefaultMutableTreeNode curNode = null; int iChildCount = root.getChildCount(); // 得到根节点下的子节点 for (int i = 0; i < iChildCount; i++) { curNode = (DefaultMutableTreeNode) root.getChildAt(i); curCal = ((Caliber) curNode.getUserObject()).getACal(); if (aCal.getSourceID().equals(curCal.getSourceID())) { sFlag = true; break; } } DefaultMutableTreeNode ANode = null; if (!sFlag) { // 父节点不存在 // 增加父节点 ICustomStatisticCaliber parCal = new MySummaryStatisticCaliberImpl(); parCal.setSourceID(aCal.getSourceID()); // 数据源名称 String sDataSourceName = dataSourceCbx.getRefModel().getNameByValue(aCal.getSourceID()); parCal.setValue(sDataSourceName); ANode = new DefaultMutableTreeNode(new Caliber(parCal)); treeModel.insertNodeInto(ANode, root, root.getChildCount()); curNode = (DefaultMutableTreeNode) root.getLastChild(); } ANode = new DefaultMutableTreeNode(new Caliber(aCal)); treeModel.insertNodeInto(ANode, curNode, curNode.getChildCount()); return ANode; }
/** * Draw all primitives in this layer but do not draw modified ones (they are drawn by the edit * layer). Draw nodes last to overlap the ways they belong to. */ @SuppressWarnings("unchecked") @Override public void paint(final Graphics2D g, final MapView mv, Bounds bounds) { updateCount = Main.map.validatorDialog.tree.getUpdateCount(); DefaultMutableTreeNode root = Main.map.validatorDialog.tree.getRoot(); if (root == null || root.getChildCount() == 0) return; PaintVisitor paintVisitor = new PaintVisitor(g, mv); DefaultMutableTreeNode severity = (DefaultMutableTreeNode) root.getLastChild(); while (severity != null) { Enumeration<DefaultMutableTreeNode> errorMessages = severity.breadthFirstEnumeration(); while (errorMessages.hasMoreElements()) { Object tn = errorMessages.nextElement().getUserObject(); if (tn instanceof TestError) { paintVisitor.visit(((TestError) tn)); } } // Severities in inverse order severity = severity.getPreviousSibling(); } paintVisitor.clearPaintedObjects(); }
/** * Gets the insert position for newGeo to insert it in alphabetical order in parent node. Note: * all children of parent must have instances of GeoElement as user objects. * * @param mode */ public static final int getInsertPosition( DefaultMutableTreeNode parent, GeoElement newGeo, SortMode mode) { // label of inserted geo // String newLabel = newGeo.getLabel(); // standard case: binary search int left = 0; int right = parent.getChildCount(); if (right == 0) return right; // bigger then last? DefaultMutableTreeNode node = (DefaultMutableTreeNode) parent.getLastChild(); // String nodeLabel = ((GeoElement) node.getUserObject()).getLabel(); GeoElement geo2 = ((GeoElement) node.getUserObject()); if (compare(newGeo, geo2, mode)) return right; // binary search while (right > left) { int middle = (left + right) / 2; node = (DefaultMutableTreeNode) parent.getChildAt(middle); // nodeLabel = ((GeoElement) node.getUserObject()).getLabel(); geo2 = ((GeoElement) node.getUserObject()); if (!compare(newGeo, geo2, mode)) { right = middle; } else { left = middle + 1; } } // insert at correct position return right; }