private Node replaceNormalNode( Node normalNode, GKInstance diseaseEntity, Boolean needDashedBorder) { Node diseaseNode = normalToDiseaseNode.get(normalNode); if (diseaseNode != null) return diseaseNode; try { // If a node exists already, it should use for (Renderable r : diseaseComps) { if (diseaseEntity.getDBID().equals(r.getReactomeId()) && r instanceof Node) { // This is rather arbitrary: if two nodes are very close, // use the existing one. int dx = Math.abs(r.getPosition().x - normalNode.getPosition().x); int dy = Math.abs(r.getPosition().y - normalNode.getPosition().y); if (dx < 10 && dy < 10) { // We don't need to create a new Node if it exists already normalToDiseaseNode.put(normalNode, (Node) r); overlaidObjects.add(r); // Add it to overlaid object to cover edges return (Node) r; } } } diseaseNode = normalNode.getClass().newInstance(); RenderUtility.copyRenderInfo(normalNode, diseaseNode); // The following should NOT be called since NodeAttachment is // related to disease entity only. // TODO: Need to support this. Currently it is not supported!!! See example // in PI3/AKT cancer pathway. // diseaseNode.setNodeAttachmentsLocally(node.getNodeAttachments()); diseaseNode.setDisplayName(diseaseEntity.getDisplayName()); diseaseNode.setReactomeId(diseaseEntity.getDBID()); diseaseNode.invalidateBounds(); diseaseNode.setRenderer(normalNode.getRenderer()); diseaseNode.setLineColor(DefaultRenderConstants.DEFAULT_DISEASE_BACKGROUND); diseaseNode.setNeedDashedBorder(needDashedBorder); RenderUtility.hideCompartmentInNodeName(diseaseNode); overlaidObjects.add(diseaseNode); displayedObject.addComponent(diseaseNode); normalToDiseaseNode.put(normalNode, diseaseNode); return diseaseNode; } catch (Exception e) { e.printStackTrace(); } return null; }