List of usage examples for java.util Vector contains
public boolean contains(Object o)
From source file:gov.nih.nci.evs.browser.utils.DataUtils.java
public HashMap getRelationshipHashMap(String scheme, String version, String code, String sab) { // EVSApplicationService lbSvc = new // RemoteServerUtil().createLexBIGService(); LexBIGService lbSvc = RemoteServerUtil.createLexBIGService(); CodingSchemeVersionOrTag csvt = new CodingSchemeVersionOrTag(); if (version != null) csvt.setVersion(version);/*from ww w .j a va 2 s . co m*/ // Perform the query ... ResolvedConceptReferenceList matches = null; //List list = new ArrayList();// getSupportedRoleNames(lbSvc, scheme, // version); ArrayList roleList = new ArrayList(); ArrayList associationList = new ArrayList(); ArrayList superconceptList = new ArrayList(); ArrayList siblingList = new ArrayList(); ArrayList subconceptList = new ArrayList(); ArrayList btList = new ArrayList(); ArrayList ntList = new ArrayList(); Vector parent_asso_vec = new Vector(Arrays.asList(_hierAssocToParentNodes)); Vector child_asso_vec = new Vector(Arrays.asList(_hierAssocToChildNodes)); Vector sibling_asso_vec = new Vector(Arrays.asList(_assocToSiblingNodes)); Vector bt_vec = new Vector(Arrays.asList(_assocToBTNodes)); Vector nt_vec = new Vector(Arrays.asList(_assocToNTNodes)); HashMap map = new HashMap(); try { // LexBIGServiceConvenienceMethods lbscm = // createLexBIGServiceConvenienceMethods(lbSvc); /* * LexBIGServiceConvenienceMethods lbscm = * (LexBIGServiceConvenienceMethods) lbSvc * .getGenericExtension("LexBIGServiceConvenienceMethods"); * lbscm.setLexBIGService(lbSvc); */ CodedNodeGraph cng = lbSvc.getNodeGraph(scheme, csvt, null); if (sab != null) { cng = cng.restrictToAssociations(null, Constructors.createNameAndValueList(sab, SOURCE)); } int maxToReturn = NCImBrowserProperties.get_maxToReturn(); matches = cng.resolveAsList(ConvenienceMethods.createConceptReference(code, scheme), true, false, 1, 1, _noopList, null, null, null, maxToReturn, false); if (matches.getResolvedConceptReferenceCount() > 0) { Enumeration<ResolvedConceptReference> refEnum = (Enumeration<ResolvedConceptReference>) matches .enumerateResolvedConceptReference(); while (refEnum.hasMoreElements()) { ResolvedConceptReference ref = refEnum.nextElement(); AssociationList sourceof = ref.getSourceOf(); Association[] associations = sourceof.getAssociation(); for (int i = 0; i < associations.length; i++) { Association assoc = associations[i]; String associationName = assoc.getAssociationName(); // String associationName = // lbscm.getAssociationNameFromAssociationCode(scheme, // csvt, assoc.getAssociationName()); AssociatedConcept[] acl = assoc.getAssociatedConcepts().getAssociatedConcept(); for (int j = 0; j < acl.length; j++) { AssociatedConcept ac = acl[j]; EntityDescription ed = ac.getEntityDescription(); String name = "No Description"; if (ed != null) name = ed.getContent(); String pt = name; if (associationName.compareToIgnoreCase("equivalentClass") != 0) { String s = associationName + "|" + pt + "|" + ac.getConceptCode(); if (!parent_asso_vec.contains(associationName) && !child_asso_vec.contains(associationName)) { if (sibling_asso_vec.contains(associationName)) { siblingList.add(s); } else if (bt_vec.contains(associationName)) { btList.add(s); } else if (nt_vec.contains(associationName)) { ntList.add(s); } else { associationList.add(s); } } } } } } } if (roleList.size() > 0) { SortUtils.quickSort(roleList); } if (associationList.size() > 0) { // KLO, 052909 associationList = removeRedundantRelationships(associationList, "RO"); SortUtils.quickSort(associationList); } if (siblingList.size() > 0) { SortUtils.quickSort(siblingList); } if (btList.size() > 0) { SortUtils.quickSort(btList); } if (ntList.size() > 0) { SortUtils.quickSort(ntList); } map.put(TYPE_ROLE, roleList); map.put(TYPE_ASSOCIATION, associationList); map.put(TYPE_SIBLINGCONCEPT, siblingList); map.put(TYPE_BROADERCONCEPT, btList); map.put(TYPE_NARROWERCONCEPT, ntList); Vector superconcept_vec = getSuperconcepts(scheme, version, code); for (int i = 0; i < superconcept_vec.size(); i++) { Entity c = (Entity) superconcept_vec.elementAt(i); // String pt = getPreferredName(c); String pt = c.getEntityDescription().getContent(); superconceptList.add(pt + "|" + c.getEntityCode()); } SortUtils.quickSort(superconceptList); map.put(TYPE_SUPERCONCEPT, superconceptList); Vector subconcept_vec = getSubconcepts(scheme, version, code); for (int i = 0; i < subconcept_vec.size(); i++) { Entity c = (Entity) subconcept_vec.elementAt(i); // String pt = getPreferredName(c); String pt = c.getEntityDescription().getContent(); subconceptList.add(pt + "|" + c.getEntityCode()); } SortUtils.quickSort(subconceptList); map.put(TYPE_SUBCONCEPT, subconceptList); } catch (Exception ex) { ex.printStackTrace(); } return map; }
From source file:app.RunApp.java
/** * Select n top co-ocurrence labels/*from ww w. j a v a2s . co m*/ * * @param n Number of labels to select * @param selectInTable Indicates if the rows are selected in the table * @return List with the names of the selected labels */ public ArrayList<String> selectTopCoocurrenceLabels(int n, boolean selectInTable) { ArrayList<String> pairsString = new ArrayList<>(); ArrayList<LabelsPairValue> pairs = new ArrayList<>(); for (int i = 0; i < coocurrenceCoefficients.length; i++) { for (int j = 0; j < coocurrenceCoefficients.length; j++) { if (coocurrenceCoefficients[i][j] >= 0) { pairs.add(new LabelsPairValue(i, j, coocurrenceCoefficients[i][j])); } } } Collections.sort(pairs, Collections.reverseOrder()); int numLabels = n; int currentSelectedLabels = 0; Vector<Integer> selectedLabels = new Vector<>(); do { if (!selectedLabels.contains(pairs.get(0).label1)) { selectedLabels.add(pairs.get(0).label1); currentSelectedLabels++; } if (currentSelectedLabels < numLabels) { if (!selectedLabels.contains(pairs.get(0).label2)) { selectedLabels.add(pairs.get(0).label2); currentSelectedLabels++; } } pairs.remove(pairs.get(0)); } while ((pairs.size() > 0) && (currentSelectedLabels < numLabels)); String s = new String(); for (int i = 0; i < selectedLabels.size(); i++) { s = jTableCoocurrences.getColumnName(selectedLabels.get(i)); if (s != null) { pairsString.add(s); } } if (selectInTable) { tableCoOcurrenceLeft.clearSelection(); String labelName; for (int i = 0; i < selectedLabels.size(); i++) { labelName = dataset.getLabelNames()[selectedLabels.get(i)]; for (int r = 0; r < tableCoOcurrenceLeft.getRowCount(); r++) { if (tableCoOcurrenceLeft.getValueAt(r, 0).equals(labelName)) { tableCoOcurrenceLeft.addRowSelectionInterval(r, r); } } } } return pairsString; }
From source file:app.RunApp.java
/** * Select n top heatmap labels//from w w w . j ava 2s . c o m * * @param n Number of labels to select * @param selectInTable Indicates if the rows are selected in the table * @return List with the names of the selected labels */ public ArrayList<String> selectTopHeatmapLabels(int n, boolean selectInTable) { ArrayList<String> pairsString = new ArrayList<>(); ArrayList<LabelsPairValue> pairs = new ArrayList<>(); for (int i = 0; i < heatmapCoefficients.length; i++) { for (int j = 0; j < heatmapCoefficients.length; j++) { if (heatmapCoefficients[i][j] >= 0) { pairs.add(new LabelsPairValue(i, j, heatmapCoefficients[i][j])); } } } Collections.sort(pairs, Collections.reverseOrder()); int numLabels = n; int currentSelectedLabels = 0; Vector<Integer> selectedLabels = new Vector<>(); do { if (!selectedLabels.contains(pairs.get(0).label1)) { selectedLabels.add(pairs.get(0).label1); currentSelectedLabels++; } if (currentSelectedLabels < numLabels) { if (!selectedLabels.contains(pairs.get(0).label2)) { selectedLabels.add(pairs.get(0).label2); currentSelectedLabels++; } } pairs.remove(pairs.get(0)); } while ((pairs.size() > 0) && (currentSelectedLabels < numLabels)); String s; for (int i = 0; i < selectedLabels.size(); i++) { s = jTableHeatmap.getColumnName(selectedLabels.get(i)); if (s != null) { pairsString.add(s); } } if (selectInTable) { tableHeatmapLeft.clearSelection(); String labelName; for (int i = 0; i < selectedLabels.size(); i++) { //Get label name labelName = dataset.getLabelNames()[selectedLabels.get(i)]; for (int r = 0; r < tableHeatmapLeft.getRowCount(); r++) { if (tableHeatmapLeft.getValueAt(r, 0).equals(labelName)) { tableHeatmapLeft.addRowSelectionInterval(r, r); } } } } return pairsString; }
From source file:app.RunApp.java
/** * Get top n related labels for heatmap//from w w w .java2 s .co m * * @param n Number of labels to select * @return Selected label indices */ public int[] getTopRelatedHeatmap(int n) { ArrayList<LabelsPairValue> pairs = new ArrayList<>(); for (int i = 0; i < heatmapCoefficients.length; i++) { for (int j = 0; j < heatmapCoefficients.length; j++) { if (heatmapCoefficients[i][j] > 0) { pairs.add(new LabelsPairValue(i, j, heatmapCoefficients[i][j])); } } } Collections.sort(pairs, Collections.reverseOrder()); int numLabels = n; int currentSelectedLabels = 0; Vector<Integer> selectedLabels = new Vector<>(); do { if (!selectedLabels.contains(pairs.get(0).label1)) { selectedLabels.add(pairs.get(0).label1); currentSelectedLabels++; } if (currentSelectedLabels < numLabels) { if (!selectedLabels.contains(pairs.get(0).label2)) { selectedLabels.add(pairs.get(0).label2); currentSelectedLabels++; } } pairs.remove(pairs.get(0)); } while ((pairs.size() > 0) && (currentSelectedLabels < numLabels)); int[] labelIndices = new int[n]; String s; if (selectedLabels.size() < n) { int[] selectedsFreq = new int[dataset.getNumLabels()]; for (int i = 0; i < selectedsFreq.length; i++) { selectedsFreq[i] = i; } int i = 0; do { if (!selectedLabels.contains((int) selectedsFreq[i])) { selectedLabels.add(selectedsFreq[i]); } i++; } while (selectedLabels.size() < n); } for (int i = 0; i < selectedLabels.size(); i++) { s = jTableHeatmap.getColumnName(selectedLabels.get(i)); if (s != null) { labelIndices[i] = selectedLabels.get(i); } } return labelIndices; }
From source file:gov.nih.nci.evs.browser.utils.DataUtils.java
public HashMap getAssociationTargetHashMap(String CUI, Vector sort_option) { Debug.println("(*) DataUtils getAssociationTargetHashMap "); long ms, delay = 0; String action = null;/*from w w w . java 2 s. c om*/ ms = System.currentTimeMillis(); action = "Initializing member variables"; List<String> par_chd_assoc_list = new ArrayList(); par_chd_assoc_list.add("CHD"); par_chd_assoc_list.add("RB"); Vector parent_asso_vec = new Vector(Arrays.asList(_hierAssocToParentNodes)); Vector child_asso_vec = new Vector(Arrays.asList(_hierAssocToChildNodes)); Vector sibling_asso_vec = new Vector(Arrays.asList(_assocToSiblingNodes)); Vector bt_vec = new Vector(Arrays.asList(_assocToBTNodes)); Vector nt_vec = new Vector(Arrays.asList(_assocToNTNodes)); Vector category_vec = new Vector(Arrays.asList(_relationshipCategories)); HashMap rel_hmap = new HashMap(); for (int k = 0; k < category_vec.size(); k++) { String category = (String) category_vec.elementAt(k); HashSet hset = new HashSet(); rel_hmap.put(category, hset); } HashSet w = new HashSet(); Map<String, List<RelationshipTabResults>> map = null; Map<String, List<RelationshipTabResults>> map2 = null; LexBIGService lbs = RemoteServerUtil.createLexBIGService(); MetaBrowserService mbs = null; delay = System.currentTimeMillis() - ms; Debug.println("Run time (ms) for " + action + " " + delay); DBG.debugDetails(delay, action, "getAssociationTargetHashMap"); try { mbs = (MetaBrowserService) lbs.getGenericExtension("metabrowser-extension"); if (mbs == null) { _logger.error("Error! metabrowser-extension is null!"); return null; } ms = System.currentTimeMillis(); action = "Retrieving " + SOURCE_OF; ms = System.currentTimeMillis(); //_logger.info("CUI: " + CUI); //_logger.info("Direction: " + Direction.SOURCEOF); map = mbs.getRelationshipsDisplay(CUI, null, Direction.SOURCEOF); //_logger.info("Done !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! getRelationshipsDisplay !!!!"); delay = System.currentTimeMillis() - ms; Debug.println("Run time (ms) for " + action + " " + delay); DBG.debugDetails(delay, action, "getAssociationTargetHashMap"); ms = System.currentTimeMillis(); action = "Retrieving " + TARGET_OF; ms = System.currentTimeMillis(); map2 = mbs.getRelationshipsDisplay(CUI, par_chd_assoc_list, Direction.TARGETOF); delay = System.currentTimeMillis() - ms; Debug.println("Run time (ms) for " + action + " " + delay); DBG.debugDetails(delay, action, "getAssociationTargetHashMap"); } catch (Exception ex) { ex.printStackTrace(); return null; } // Categorize relationships into six categories and find association // source data ms = System.currentTimeMillis(); action = "Categorizing relationships into six categories; finding source data for each relationship"; Iterator rel_it = map.entrySet().iterator(); while (rel_it.hasNext()) { Entry thisEntry = (Entry) rel_it.next(); String rel = (String) thisEntry.getKey(); List<RelationshipTabResults> relations = (List<RelationshipTabResults>) thisEntry.getValue(); //for (String rel : map.keySet()) { //List<RelationshipTabResults> relations = map.get(rel); if (rel.compareTo(INCOMPLETE) != 0) { String category = "Other"; /* * if (parent_asso_vec.contains(rel)) category = "Parent"; else * if (child_asso_vec.contains(rel)) category = "Child"; else if * (bt_vec.contains(rel)) category = "Broader"; else if * (nt_vec.contains(rel)) category = "Narrower"; */ if (parent_asso_vec.contains(rel)) category = "Child"; else if (child_asso_vec.contains(rel)) category = "Parent"; else if (bt_vec.contains(rel)) category = "Narrower"; else if (nt_vec.contains(rel)) category = "Broader"; else if (sibling_asso_vec.contains(rel)) category = "Sibling"; for (RelationshipTabResults result : relations) { String code = result.getCui(); if (code.compareTo(CUI) != 0 && code.indexOf("@") == -1) { String rela = result.getRela(); String source = result.getSource(); String name = result.getName(); w = (HashSet) rel_hmap.get(category); if (w == null) { w = new HashSet(); } String str = rela + "|" + name + "|" + code + "|" + source; if (!w.contains(str)) { w.add(str); rel_hmap.put(category, w); } } } } } Iterator rel_it2 = map2.entrySet().iterator(); while (rel_it2.hasNext()) { Entry thisEntry = (Entry) rel_it2.next(); String rel = (String) thisEntry.getKey(); List<RelationshipTabResults> relations = (List<RelationshipTabResults>) thisEntry.getValue(); //for (String rel : map2.keySet()) { //List<RelationshipTabResults> relations = map2.get(rel); if (rel.compareTo(INCOMPLETE) != 0) { String category = "Other"; /* * if (parent_asso_vec.contains(rel)) category = "Parent"; else * if (child_asso_vec.contains(rel)) category = "Child"; else if * (bt_vec.contains(rel)) category = "Broader"; else if * (nt_vec.contains(rel)) category = "Narrower"; */ if (parent_asso_vec.contains(rel)) category = "Child"; else if (child_asso_vec.contains(rel)) category = "Parent"; else if (bt_vec.contains(rel)) category = "Narrower"; else if (nt_vec.contains(rel)) category = "Broader"; else if (sibling_asso_vec.contains(rel)) category = "Sibling"; for (RelationshipTabResults result : relations) { String code = result.getCui(); if (code.compareTo(CUI) != 0 && code.indexOf("@") == -1) { String rela = result.getRela(); String source = result.getSource(); String name = result.getName(); w = (HashSet) rel_hmap.get(category); if (w == null) { w = new HashSet(); } String str = rela + "|" + name + "|" + code + "|" + source; if (!w.contains(str)) { w.add(str); rel_hmap.put(category, w); } } } } } delay = System.currentTimeMillis() - ms; Debug.println("Run time (ms) for " + action + " " + delay); DBG.debugDetails(delay, action, "getAssociationTargetHashMap"); // Remove redundant RO relationships ms = System.currentTimeMillis(); action = "Removing redundant RO and CHD relationships"; HashSet other_hset = new HashSet(); HashSet w2 = (HashSet) rel_hmap.get("Other"); Iterator it = w2.iterator(); while (it.hasNext()) { String s = (String) it.next(); Vector ret_vec = parseData(s, "|"); String rel = (String) ret_vec.elementAt(0); String name = (String) ret_vec.elementAt(1); String target_code = (String) ret_vec.elementAt(2); String src = (String) ret_vec.elementAt(3); String t = name + "|" + target_code + "|" + src; if (rel.compareTo("RO") != 0 && !other_hset.contains(t)) { other_hset.add(t); } } HashSet w3 = new HashSet(); w2 = (HashSet) rel_hmap.get("Other"); it = w2.iterator(); while (it.hasNext()) { String s = (String) it.next(); Vector ret_vec = parseData(s, "|"); String rel = (String) ret_vec.elementAt(0); String name = (String) ret_vec.elementAt(1); String target_code = (String) ret_vec.elementAt(2); String src = (String) ret_vec.elementAt(3); if (rel.compareTo("RO") != 0) { w3.add(s); } else { // RO String t = name + "|" + target_code + "|" + src; if (!other_hset.contains(t)) { w3.add(s); } } } rel_hmap.put("Other", w3); other_hset = new HashSet(); w2 = (HashSet) rel_hmap.get("Child"); it = w2.iterator(); while (it.hasNext()) { String s = (String) it.next(); Vector ret_vec = parseData(s, "|"); String rel = (String) ret_vec.elementAt(0); String name = (String) ret_vec.elementAt(1); String target_code = (String) ret_vec.elementAt(2); String src = (String) ret_vec.elementAt(3); String t = name + "|" + target_code + "|" + src; if (rel.compareTo("CHD") != 0 && !other_hset.contains(t)) { other_hset.add(t); } } w3 = new HashSet(); w2 = (HashSet) rel_hmap.get("Child"); it = w2.iterator(); while (it.hasNext()) { String s = (String) it.next(); Vector ret_vec = parseData(s, "|"); String rel = (String) ret_vec.elementAt(0); String name = (String) ret_vec.elementAt(1); String target_code = (String) ret_vec.elementAt(2); String src = (String) ret_vec.elementAt(3); if (rel.compareTo("CHD") != 0) { w3.add(s); } else { String t = name + "|" + target_code + "|" + src; if (!other_hset.contains(t)) { w3.add(s); } } } rel_hmap.put("Child", w3); delay = System.currentTimeMillis() - ms; Debug.println("Run time (ms) for " + action + " " + delay); DBG.debugDetails(delay, action, "getAssociationTargetHashMap"); ms = System.currentTimeMillis(); action = "Sorting relationships by sort options (columns)"; HashMap new_rel_hmap = new HashMap(); // Sort relationships by sort options (columns) if (sort_option == null) { for (int k = 0; k < category_vec.size(); k++) { String category = (String) category_vec.elementAt(k); w = (HashSet) rel_hmap.get(category); Vector rel_v = hashSet2Vector(w); SortUtils.quickSort(rel_v); new_rel_hmap.put(category, rel_v); } } else { for (int k = 0; k < category_vec.size(); k++) { String category = (String) category_vec.elementAt(k); w = (HashSet) rel_hmap.get(category); Vector rel_v = hashSet2Vector(w); String sortOption = (String) sort_option.elementAt(k); rel_v = sortRelationshipData(rel_v, sortOption); new_rel_hmap.put(category, rel_v); } } delay = System.currentTimeMillis() - ms; Debug.println("Run time (ms) for " + action + " " + delay); DBG.debugDetails(delay, action, "getAssociationTargetHashMap"); // KLO, testing Vector sibling_vector = getSiblings(CUI); if (sort_option != null) { sibling_vector = sortRelationshipData(sibling_vector, (String) sort_option.elementAt(4)); } //new_rel_hmap.put("Sibling", getSiblings(CUI)); new_rel_hmap.put("Sibling", sibling_vector); removeRedundantRecords(new_rel_hmap); String incomplete = (String) new_rel_hmap.get(INCOMPLETE); if (incomplete != null) { new_rel_hmap.put(INCOMPLETE, incomplete); } return new_rel_hmap; }
From source file:lu.fisch.unimozer.Diagram.java
private Point getCons(MyClass thisClass, MyClass otherClass, Hashtable<MyClass, Vector<MyClass>> classUsings) { int otherDIR, thisDIR, otherCON, thisCON; if (otherClass.getPosition().y + otherClass.getHeight() / 2 < thisClass.getPosition().y + thisClass.getHeight() / 2) { // top thisDIR = 1;//from w w w . j ava2 s . co m } else { // bottom thisDIR = -1; } if (otherClass.getPosition().x + otherClass.getWidth() / 2 < thisClass.getPosition().x + thisClass.getWidth() / 2) { // left otherDIR = 1; } else { // right otherDIR = -1; } // create an empty list Vector<MyClass> otherUsers = new Vector<MyClass>(); /* // iterate through all usages Set<MyClass> set = classUsings.keySet(); Iterator<MyClass> itr = set.iterator(); while (itr.hasNext()) { // get the actual class ... MyClass actual = itr.next(); // ... and the list of classes it uses Vector<MyClass> actualUses = classUsings.get(actual); // iterate through that list for(MyClass used : actualUses) { // add the actual class if // - it usesd the "otherClass" // - and the actual class has not yet been captured if(used==otherClass && !otherUsers.contains(actual)) otherUsers.add(actual); } } */ /* let's try this one ... */ for (Entry<MyClass, Vector<MyClass>> entry : classUsings.entrySet()) { // get the actual class ... MyClass actual = entry.getKey(); // ... and the list of classes it uses Vector<MyClass> actualUses = classUsings.get(actual); // iterate through that list for (MyClass used : actualUses) { // add the actual class if // - it usesd the "otherClass" // - and the actual class has not yet been captured if (used == otherClass && !otherUsers.contains(actual)) otherUsers.add(actual); } } if (otherDIR == -1 && thisDIR == 1) // Q1 (top-right) { Vector<MyClass> others = classUsings.get(thisClass); thisCON = 1; for (MyClass other : others) { if ((other.getPosition().y + other.getHeight() / 2 < thisClass.getPosition().y + thisClass.getHeight() / 2) && (other.getPosition().x + other.getWidth() / 2 >= thisClass.getPosition().x + thisClass.getWidth() / 2) && (other.getPosition().y + other.getHeight() / 2 < otherClass.getPosition().y + otherClass.getHeight() / 2)) thisCON++; } thisCON *= 12; // other Q3 otherCON = 1; for (MyClass other : otherUsers) { if ((other.getPosition().y + other.getHeight() / 2 >= otherClass.getPosition().y + otherClass.getHeight() / 2) && (other.getPosition().x + other.getWidth() / 2 < otherClass.getPosition().x + otherClass.getWidth() / 2) && (other.getPosition().x + other.getWidth() / 2 < thisClass.getPosition().x + thisClass.getWidth() / 2)) otherCON++; } otherCON *= 12; } else if (otherDIR == 1 && thisDIR == 1) // Q2 (top-left) { Vector<MyClass> others = classUsings.get(thisClass); thisCON = 1; for (MyClass other : others) { if ((other.getPosition().y + other.getHeight() / 2 < thisClass.getPosition().y + thisClass.getHeight() / 2) && (other.getPosition().x + other.getWidth() / 2 < thisClass.getPosition().x + thisClass.getWidth() / 2) && (other.getPosition().y + other.getHeight() / 2 < otherClass.getPosition().y + otherClass.getHeight() / 2)) thisCON++; } thisCON *= -12; // other Q4 otherCON = 1; for (MyClass other : otherUsers) { if ((other.getPosition().y + other.getHeight() / 2 >= otherClass.getPosition().y + otherClass.getHeight() / 2) && (other.getPosition().x + other.getWidth() / 2 >= otherClass.getPosition().x + otherClass.getWidth() / 2) && (other.getPosition().x + other.getWidth() / 2 > thisClass.getPosition().x + thisClass.getWidth() / 2)) otherCON++; } otherCON *= 12; } else if (otherDIR == 1 && thisDIR == -1) // Q3 (bottom-left) { Vector<MyClass> others = classUsings.get(thisClass); thisCON = 1; for (MyClass other : others) { if ((other.getPosition().y + other.getHeight() / 2 >= thisClass.getPosition().y + thisClass.getHeight() / 2) && (other.getPosition().x + other.getWidth() / 2 < thisClass.getPosition().x + thisClass.getWidth() / 2) && (other.getPosition().y + other.getHeight() / 2 > otherClass.getPosition().y + otherClass.getHeight() / 2)) thisCON++; } thisCON *= -12; // other Q1 otherCON = 1; for (MyClass other : otherUsers) { if ((other.getPosition().y + other.getHeight() / 2 < otherClass.getPosition().y + otherClass.getHeight() / 2) && (other.getPosition().x + other.getWidth() / 2 >= otherClass.getPosition().x + otherClass.getWidth() / 2) && (other.getPosition().x + other.getWidth() / 2 > thisClass.getPosition().x + thisClass.getWidth() / 2)) otherCON++; } otherCON *= -12; } else // Q4 (bottom-right) { Vector<MyClass> others = classUsings.get(thisClass); thisCON = 1; for (MyClass other : others) { if ((other.getPosition().y + other.getHeight() / 2 >= thisClass.getPosition().y + thisClass.getHeight() / 2) && (other.getPosition().x + other.getWidth() / 2 >= thisClass.getPosition().x + thisClass.getWidth() / 2) && (other.getPosition().y + other.getHeight() / 2 > otherClass.getPosition().y + otherClass.getHeight() / 2)) thisCON++; } thisCON *= 12; // other Q2 otherCON = 1; for (MyClass other : otherUsers) { if ((other.getPosition().y + other.getHeight() / 2 < otherClass.getPosition().y + otherClass.getHeight() / 2) && (other.getPosition().x + other.getWidth() / 2 < otherClass.getPosition().x + otherClass.getWidth() / 2) && (other.getPosition().x + other.getWidth() / 2 < thisClass.getPosition().x + thisClass.getWidth() / 2)) otherCON++; } otherCON *= -12; } /* int topRight = 0; int topLeft = 0; int bottomLeft = 0; int bottomRight = 0; Vector<MyClass> others = classUsings.get(thisClass); for(MyClass other : otherUsers) { if ( (other.getPosition().y+other.getHeight()/2 >= otherClass.getPosition().y+otherClass.getHeight()/2) && (other.getPosition().x+other.getWidth()/2 < otherClass.getPosition().x+otherClass.getWidth()/2) && (other.getPosition().x+other.getWidth()/2 < thisClass.getPosition().x+thisClass.getWidth()/2) ) topRight++; else if ( (other.getPosition().y+other.getHeight()/2 >= otherClass.getPosition().y+otherClass.getHeight()/2) && (other.getPosition().x+other.getWidth()/2 >= otherClass.getPosition().x+otherClass.getWidth()/2) && (other.getPosition().x+other.getWidth()/2 > thisClass.getPosition().x+thisClass.getWidth()/2) ) topLeft++; else if ( (other.getPosition().y+other.getHeight()/2 < otherClass.getPosition().y+otherClass.getHeight()/2) && (other.getPosition().x+other.getWidth()/2 >= otherClass.getPosition().x+otherClass.getWidth()/2) && (other.getPosition().x+other.getWidth()/2 > thisClass.getPosition().x+thisClass.getWidth()/2) ) bottomLeft++; else bottomRight++; } int DIST = 12; if (otherDIR==-1 && thisDIR==1) // Q1 (top-right) { //if(bottomRight==0 && topRight!=0) topRight--; otherCON=topRight*DIST; } else if(otherDIR==1 && thisDIR==1) // Q2 (top-left) { //if(bottomLeft==0 && topLeft!=0) topLeft--; otherCON=topLeft*DIST; } else if(otherDIR==1 && thisDIR==-1) // Q3 (bottom-left) { //if(topLeft==0 && bottomLeft!=0) bottomLeft--; otherCON=-bottomLeft*DIST; } else // Q4 /Bottom-right) { //if(topRight==0 && bottomRight!=0) bottomRight--; otherCON=-bottomRight*DIST; } */ // adjust into the middle thisCON -= (thisCON / Math.abs(thisCON)) * 6; otherCON -= (otherCON / Math.abs(otherCON)) * 6; return new Point(thisCON, otherCON); }
From source file:lu.fisch.unimozer.Diagram.java
private void drawCompoAggregation2(Graphics2D g, MyClass thisClass, MyClass otherClass, Hashtable<MyClass, Vector<MyClass>> classUsings, boolean isComposition) { if (thisClass != otherClass) { Point thisTop = new Point(thisClass.getX() + thisClass.getWidth() / 2, thisClass.getY()); Point thisBottom = new Point(thisClass.getX() + thisClass.getWidth() / 2, thisClass.getY() + thisClass.getHeight()); Point thisLeft = new Point(thisClass.getX(), thisClass.getY() + thisClass.getHeight() / 2); Point thisRight = new Point(thisClass.getX() + thisClass.getWidth(), thisClass.getY() + thisClass.getHeight() / 2); Point[] thisPoints = { thisTop, thisBottom, thisLeft, thisRight }; Point otherTop = new Point(otherClass.getX() + otherClass.getWidth() / 2, otherClass.getY()); Point otherBottom = new Point(otherClass.getX() + otherClass.getWidth() / 2, otherClass.getY() + otherClass.getHeight()); Point otherLeft = new Point(otherClass.getX(), otherClass.getY() + otherClass.getHeight() / 2); Point otherRight = new Point(otherClass.getX() + otherClass.getWidth(), otherClass.getY() + otherClass.getHeight() / 2); Point[] otherPoints = { otherTop, otherBottom, otherLeft, otherRight }; double min = Double.MAX_VALUE; Point thisPoint = null;/*from w w w .ja v a 2 s. c om*/ Point otherPoint = null; double thisMin; // determine closest middelst for (int i = 0; i < thisPoints.length; i++) for (int j = 0; j < otherPoints.length; j++) { thisMin = thisPoints[i].distance(otherPoints[j]); if (thisMin < min) { min = thisMin; thisPoint = thisPoints[i]; otherPoint = otherPoints[j]; } } //Vector<MyClass> others = classUsings.get(thisClass); Vector<MyClass> usingsThisClass = classUsings.get(thisClass); // iterate through all usages /*Set<MyClass> set = classUsings.keySet(); Iterator<MyClass> itr = set.iterator(); while (itr.hasNext()) { // get the actual class ... MyClass actual = itr.next(); // ... and the list of classes it uses Vector<MyClass> actualUses = classUsings.get(actual); // iterate through that list for(MyClass used : actualUses) { // add the actual class if // - it usesd the "otherClass" // - and the actual class has not yet been captured if(used==thisClass && !usingsThisClass.contains(actual)) usingsThisClass.add(actual); } }*/ /* let's try this one ... */ for (Entry<MyClass, Vector<MyClass>> entry : classUsings.entrySet()) { // get the actual class ... MyClass actual = entry.getKey(); // ... and the list of classes it uses Vector<MyClass> actualUses = classUsings.get(actual); // iterate through that list for (MyClass used : actualUses) { // add the actual class if // - it usesd the "otherClass" // - and the actual class has not yet been captured if (used == thisClass && !usingsThisClass.contains(actual)) usingsThisClass.add(actual); } } Stroke oldStroke = g.getStroke(); if (thisPoint == thisTop) { // init number of connectionx int thisCon = 1; // init the direction into which to move int thisDir = 1; if (thisPoint.x > otherPoint.x) thisDir = -1; // loop through others to determine position for (MyClass other : usingsThisClass) { // check goto right if ((other.getCenter().y < thisClass.getCenter().y) && (other.getCenter().x >= thisClass.getCenter().x) && (other.getCenter().y > otherClass.getCenter().y) && (thisDir == 1)) thisCon++; // check goto left if ((other.getCenter().y < thisClass.getCenter().y) && (other.getCenter().x < thisClass.getCenter().x) && (other.getCenter().y > otherClass.getCenter().y) && (thisDir == -1)) thisCon++; } int con = thisCon; thisCon = (int) ((thisCon - 0.5) * (12 * thisDir)); Polygon p = new Polygon(); p.addPoint(thisCon + thisClass.getPosition().x + thisClass.getWidth() / 2, thisClass.getPosition().y); p.addPoint(thisCon + thisClass.getPosition().x + thisClass.getWidth() / 2 - 4, thisClass.getPosition().y - 8); p.addPoint(thisCon + thisClass.getPosition().x + thisClass.getWidth() / 2, thisClass.getPosition().y - 16); p.addPoint(thisCon + thisClass.getPosition().x + thisClass.getWidth() / 2 + 4, thisClass.getPosition().y - 8); if (isComposition) g.fillPolygon(p); else g.drawPolygon(p); thisPoint.y -= 15; thisPoint.x += thisCon; Point movePoint = new Point(thisPoint); movePoint.y -= (usingsThisClass.size() - con) * 8; g.setStroke(dashed); drawLine(g, thisPoint, movePoint); thisPoint = movePoint; } else if (thisPoint == thisBottom) { // init number of connectionx int thisCon = 1; // init the direction into which to move int thisDir = 1; if (thisPoint.x > otherPoint.x) thisDir = -1; // loop through others to determine position for (MyClass other : usingsThisClass) { // check goto right if ((other.getCenter().y >= thisClass.getCenter().y) && (other.getCenter().x >= thisClass.getCenter().x) && (other.getCenter().y > otherClass.getCenter().y) && (thisDir == 1)) thisCon++; // check goto left if ((other.getCenter().y >= thisClass.getCenter().y) && (other.getCenter().x < thisClass.getCenter().x) && (other.getCenter().y > otherClass.getCenter().y) && (thisDir == -1)) thisCon++; } int con = thisCon; thisCon = (int) ((thisCon - 0.5) * (12 * thisDir)); // bottom Polygon p = new Polygon(); p.addPoint(thisCon + thisClass.getPosition().x + thisClass.getWidth() / 2, thisClass.getPosition().y + thisClass.getHeight()); p.addPoint(thisCon + thisClass.getPosition().x + thisClass.getWidth() / 2 - 4, thisClass.getPosition().y + thisClass.getHeight() + 8); p.addPoint(thisCon + thisClass.getPosition().x + thisClass.getWidth() / 2, thisClass.getPosition().y + thisClass.getHeight() + 16); p.addPoint(thisCon + thisClass.getPosition().x + thisClass.getWidth() / 2 + 4, thisClass.getPosition().y + thisClass.getHeight() + 8); if (isComposition) g.fillPolygon(p); else g.drawPolygon(p); thisPoint.y += 15; thisPoint.x += thisCon; Point movePoint = new Point(thisPoint); movePoint.y += (usingsThisClass.size() - con) * 8; g.setStroke(dashed); drawLine(g, thisPoint, movePoint); thisPoint = movePoint; } else if (thisPoint == thisRight) { // init number of connectionx int thisCon = 1; // init the direction into which to move int thisDir = 1; if (thisPoint.y > otherPoint.y) thisDir = -1; // loop through others to determine position for (MyClass other : usingsThisClass) { // check goto up if ((other.getCenter().x >= thisClass.getCenter().x) && (other.getCenter().y >= thisClass.getCenter().y) && (other.getCenter().x > otherClass.getCenter().x) && (thisDir == 1)) thisCon++; // check goto down if ((other.getCenter().x >= thisClass.getCenter().x) && (other.getCenter().y < thisClass.getCenter().y) && (other.getCenter().x > otherClass.getCenter().x) && (thisDir == -1)) thisCon++; } int con = thisCon; thisCon = (int) ((thisCon - 0.5) * (12 * thisDir)); // right Polygon p = new Polygon(); //thisCON = thisClass.getConnector().getNewBottom(otherDIR); p.addPoint(thisClass.getPosition().x + thisClass.getWidth(), thisCon + thisClass.getPosition().y + thisClass.getHeight() / 2); p.addPoint(thisClass.getPosition().x + thisClass.getWidth() + 8, thisCon + thisClass.getPosition().y + thisClass.getHeight() / 2 - 4); p.addPoint(thisClass.getPosition().x + thisClass.getWidth() + 16, thisCon + thisClass.getPosition().y + thisClass.getHeight() / 2); p.addPoint(thisClass.getPosition().x + thisClass.getWidth() + 8, thisCon + thisClass.getPosition().y + thisClass.getHeight() / 2 + 4); if (isComposition) g.fillPolygon(p); else g.drawPolygon(p); thisPoint.x += 15; thisPoint.y += thisCon; Point movePoint = new Point(thisPoint); movePoint.x += (usingsThisClass.size() - con) * 8; g.setStroke(dashed); drawLine(g, thisPoint, movePoint); thisPoint = movePoint; } else // left { // init number of connectionx int thisCon = 1; // init the direction into which to move int thisDir = 1; if (thisPoint.y > otherPoint.y) thisDir = -1; // loop through others to determine position for (MyClass other : usingsThisClass) { // check goto up if ((other.getCenter().x < thisClass.getCenter().x) && (other.getCenter().y >= thisClass.getCenter().y) && (other.getCenter().x > otherClass.getCenter().x) && (thisDir == 1)) thisCon++; // check goto down if ((other.getCenter().x < thisClass.getCenter().x) && (other.getCenter().y < thisClass.getCenter().y) && (other.getCenter().x > otherClass.getCenter().x) && (thisDir == -1)) thisCon++; } int con = thisCon; thisCon = (int) ((thisCon - 0.5) * (12 * thisDir)); Polygon p = new Polygon(); p.addPoint(thisClass.getPosition().x, thisCon + thisClass.getPosition().y + thisClass.getHeight() / 2); p.addPoint(thisClass.getPosition().x - 8, thisCon + thisClass.getPosition().y + thisClass.getHeight() / 2 - 4); p.addPoint(thisClass.getPosition().x - 16, thisCon + thisClass.getPosition().y + thisClass.getHeight() / 2); p.addPoint(thisClass.getPosition().x - 8, thisCon + thisClass.getPosition().y + thisClass.getHeight() / 2 + 4); if (isComposition) g.fillPolygon(p); else g.drawPolygon(p); thisPoint.y += thisCon; thisPoint.x -= 15; Point movePoint = new Point(thisPoint); movePoint.x -= (usingsThisClass.size() - con) * 8; g.setStroke(dashed); drawLine(g, thisPoint, movePoint); thisPoint = movePoint; } //Vector<MyClass> others = classUsings.get(otherClass); Vector<MyClass> usingsOtherClass = classUsings.get(otherClass); /* // iterate through all usages set = classUsings.keySet(); itr = set.iterator(); while (itr.hasNext()) { // get the actual class ... MyClass actual = itr.next(); // ... and the list of classes it uses Vector<MyClass> actualUses = classUsings.get(actual); // iterate through that list for(MyClass used : actualUses) { // add the actual class if // - it usesd the "otherClass" // - and the actual class has not yet been captured if(used==otherClass && !usingsOtherClass.contains(actual)) usingsOtherClass.add(actual); } } */ /* let's try this one ... */ for (Entry<MyClass, Vector<MyClass>> entry : classUsings.entrySet()) { // get the actual class ... MyClass actual = entry.getKey(); // ... and the list of classes it uses Vector<MyClass> actualUses = classUsings.get(actual); // iterate through that list for (MyClass used : actualUses) { // add the actual class if // - it usesd the "otherClass" // - and the actual class has not yet been captured if (used == otherClass && !usingsOtherClass.contains(actual)) usingsOtherClass.add(actual); } } Point stopUp; Point stopDown; Point stopOut; Point step; Point start = thisPoint; Point stop; if (otherPoint == otherTop) { // init number of connectionx int otherCon = 1; // init the direction into which to move int otherDir = 1; if (otherPoint.x > thisPoint.x) otherDir = -1; // loop through others to determine position for (MyClass other : usingsOtherClass) { // check goto right if ((other.getCenter().y < otherClass.getCenter().y) && (other.getCenter().x >= otherClass.getCenter().x) && (other.getCenter().y < thisClass.getCenter().y) && (otherDir == 1)) otherCon++; // check goto left if ((other.getCenter().y < otherClass.getCenter().y) && (other.getCenter().x < otherClass.getCenter().x) && (other.getCenter().y < thisClass.getCenter().y) && (otherDir == -1)) otherCon++; } otherCon = (int) ((otherCon - 0.5) * (12 * otherDir)); otherPoint.x += otherCon; stopUp = new Point(otherPoint.x - 4, otherPoint.y - 8); stopDown = new Point(otherPoint.x + 4, otherPoint.y - 8); stopOut = new Point(otherPoint.x, otherPoint.y - 8); stop = stopOut; step = new Point(stop.x, start.y); } else if (otherPoint == otherBottom) { // init number of connectionx int otherCon = 1; // init the direction into which to move int otherDir = 1; if (otherPoint.x > thisPoint.x) otherDir = -1; // loop through others to determine position for (MyClass other : usingsOtherClass) { // check goto right if ((other.getCenter().y >= otherClass.getCenter().y) && (other.getCenter().x >= otherClass.getCenter().x) && (other.getCenter().y > thisClass.getCenter().y) && (otherDir == 1)) otherCon++; // check goto left if ((other.getCenter().y >= otherClass.getCenter().y) && (other.getCenter().x < otherClass.getCenter().x) && (other.getCenter().y > thisClass.getCenter().y) && (otherDir == -1)) otherCon++; } otherCon = (int) ((otherCon - 0.5) * (12 * otherDir)); otherPoint.x += otherCon; stopUp = new Point(otherPoint.x - 4, otherPoint.y + 8); stopDown = new Point(otherPoint.x + 4, otherPoint.y + 8); stopOut = new Point(otherPoint.x, otherPoint.y + 8); stop = stopOut; step = new Point(stop.x, start.y); } else if (otherPoint == otherRight) { // init number of connectionx int otherCon = 1; // init the direction into which to move int otherDir = 1; if (otherPoint.y > thisPoint.y) otherDir = -1; // loop through others to determine position for (MyClass other : usingsOtherClass) { // check goto up if ((other.getCenter().x >= otherClass.getCenter().x) && (other.getCenter().y >= otherClass.getCenter().y) && (other.getCenter().x > thisClass.getCenter().x) && (otherDir == 1)) otherCon++; // check goto down if ((other.getCenter().x >= otherClass.getCenter().x) && (other.getCenter().y < otherClass.getCenter().y) && (other.getCenter().x > thisClass.getCenter().x) && (otherDir == -1)) otherCon++; } otherCon = (int) ((otherCon - 0.5) * (12 * otherDir)); otherPoint.y += otherCon; stopUp = new Point(otherPoint.x + 8, otherPoint.y - 4); stopDown = new Point(otherPoint.x + 8, otherPoint.y + 4); stopOut = new Point(otherPoint.x + 8, otherPoint.y); stop = stopOut; step = new Point(start.x, stop.y); } else // left { // init number of connectionx int otherCon = 1; // init the direction into which to move int otherDir = 1; if (otherPoint.y > thisPoint.y) otherDir = -1; // loop through others to determine position for (MyClass other : usingsOtherClass) { // check goto up if ((other.getCenter().x < otherClass.getCenter().x) && (other.getCenter().y >= otherClass.getCenter().y) && (other.getCenter().x < thisClass.getCenter().x) && (otherDir == 1)) otherCon++; // check goto down if ((other.getCenter().x < otherClass.getCenter().x) && (other.getCenter().y < otherClass.getCenter().y) && (other.getCenter().x < thisClass.getCenter().x) && (otherDir == -1)) otherCon++; } otherCon = (int) ((otherCon - 0.5) * (12 * otherDir)); otherPoint.y += otherCon; stopUp = new Point(otherPoint.x - 8, otherPoint.y - 4); stopDown = new Point(otherPoint.x - 8, otherPoint.y + 4); stopOut = new Point(otherPoint.x + 8, otherPoint.y); stop = stopOut; step = new Point(start.x, stop.y); } // drawLine(g,thisPoint,otherPoint); boolean inter = false; /* if(otherClass.getPosition().y+otherClass.getHeight()/2 < thisClass.getPosition().y+thisClass.getHeight()/2) { // top if(stop.y>start.y) { step = new Point(start.x,thisClass.getPosition().y); inter = true; } else { step = new Point(start.x,stop.y); } } else { // bottom if(stop.y<thisClass.getPosition().y+thisClass.getHeight() || thisClass==otherClass) { step = new Point(start.x, thisClass.getPosition().y+thisClass.getHeight()); inter = true; } else { step = new Point(start.x,stop.y); } } drawLine(g,start,step); if(inter==true) { int middle; if(thisClass==otherClass) { middle = otherClass.getPosition().x+otherClass.getWidth()+16;//-otherCON; } else if(otherClass.getPosition().x+otherClass.getWidth()/2 > thisClass.getPosition().x+thisClass.getWidth()/2) { // left middle = (-(thisClass.getPosition().x+thisClass.getWidth())+(otherClass.getPosition().x))/2+thisClass.getPosition().x+thisClass.getWidth(); } else { // right middle = (-(otherClass.getPosition().x+otherClass.getWidth())+(thisClass.getPosition().x))/2+otherClass.getPosition().x+otherClass.getWidth(); } Point next = new Point(middle,step.y); drawLine(g,step,next); step = new Point(middle,stop.y); drawLine(g,step,next); } */ /* g.setColor(Color.red); drawLine(g,start,step); drawLine(g,step,stop); g.setColor(Color.blue); step = new Point(stop.x,start.y); drawLine(g,start,step); drawLine(g,step,stop); g.setColor(Color.orange); drawLine(g,start, new Point(start.x,(start.y+stop.y)/2)); drawLine(g,new Point(start.x,(start.y+stop.y)/2), new Point((start.x+stop.y)/2,(start.y+stop.y)/2)); drawLine(g,new Point((start.x+stop.y)/2,(start.y+stop.y)/2), new Point((start.x+stop.y)/2,stop.y)); drawLine(g,new Point((start.x+stop.y)/2,stop.y), stop); g.setColor(Color.black);/**/ drawLine(g, start, step); drawLine(g, step, stop); drawLine(g, otherPoint, stop); g.setStroke(oldStroke); drawLine(g, stopUp, otherPoint); drawLine(g, stopDown, otherPoint); } }
From source file:gov.nih.nci.evs.browser.utils.DataUtils.java
public Vector getNeighborhoodSynonyms(String CUI, String sab) { Debug.println("(*) getNeighborhoodSynonyms ..." + sab); List<String> par_chd_assoc_list = new ArrayList(); par_chd_assoc_list.add("CHD"); par_chd_assoc_list.add("RB"); // par_chd_assoc_list.add("RN"); //Vector ret_vec = new Vector(); Vector parent_asso_vec = new Vector(Arrays.asList(_hierAssocToParentNodes)); Vector child_asso_vec = new Vector(Arrays.asList(_hierAssocToChildNodes)); Vector sibling_asso_vec = new Vector(Arrays.asList(_assocToSiblingNodes)); Vector bt_vec = new Vector(Arrays.asList(_assocToBTNodes)); Vector nt_vec = new Vector(Arrays.asList(_assocToNTNodes)); Vector w = new Vector(); //HashSet hset = new HashSet(); HashSet rel_hset = new HashSet(); HashSet hasSubtype_hset = new HashSet(); long ms_categorization_delay = 0; long ms_categorization; long ms_find_highest_rank_atom_delay = 0; long ms_find_highest_rank_atom; long ms_remove_RO_delay = 0; long ms_remove_RO; long ms_all_delay = 0; long ms_all;/*from w w w.jav a 2 s. c o m*/ String action_overall = "By source delay (total time)"; ms_all = System.currentTimeMillis(); long ms = System.currentTimeMillis(), delay = 0; String action = null;// "Retrieving distance-one relationships from the server"; // HashMap hmap = getAssociatedConceptsHashMap(scheme, version, code, // sab); // HashMap hmap = getRelatedConceptsHashMap(scheme, version, code, sab); Map<String, List<BySourceTabResults>> map = null; Map<String, List<BySourceTabResults>> map2 = null; LexBIGService lbs = RemoteServerUtil.createLexBIGService(); MetaBrowserService mbs = null; try { action = "Retrieve data from browser extension"; ms = System.currentTimeMillis(); mbs = (MetaBrowserService) lbs.getGenericExtension("metabrowser-extension"); // String actionTmp = "Getting " + SOURCE_OF; // long msTmp = System.currentTimeMillis(); map = mbs.getBySourceTabDisplay(CUI, sab, null, Direction.SOURCEOF); // Debug.println("Run time (ms) " + actionTmp + " " + // (System.currentTimeMillis() - msTmp)); // actionTmp = "Getting " + TARGET_OF; // msTmp = System.currentTimeMillis(); // to be modified: BT and PAR only??? map2 = mbs.getBySourceTabDisplay(CUI, sab, par_chd_assoc_list, Direction.TARGETOF); // Debug.println("Run time (ms) " + actionTmp + " " + // (System.currentTimeMillis() - msTmp)); delay = System.currentTimeMillis() - ms; Debug.println("Run time (ms) for " + action + " " + delay); DBG.debugDetails(delay, action, "getNeighborhoodSynonyms"); } catch (Exception ex) { ex.printStackTrace(); } action = "Sort synonyms by CUI"; ms = System.currentTimeMillis(); Vector u = new Vector(); HashMap cui2SynonymsMap = createCUI2SynonymsHahMap(map, map2); delay = System.currentTimeMillis() - ms; Debug.println("Run time (ms) for " + action + " " + delay); DBG.debugDetails(delay, action, "getNeighborhoodSynonyms"); HashSet CUI_hashset = new HashSet(); ms = System.currentTimeMillis(); action = "Categorizing relationships into six categories; finding source data for each relationship"; ms_find_highest_rank_atom_delay = 0; String t = null; if (map != null) { Iterator it = map.entrySet().iterator(); while (it.hasNext()) { Entry thisEntry = (Entry) it.next(); String rel = (String) thisEntry.getKey(); List<BySourceTabResults> relations = (List<BySourceTabResults>) thisEntry.getValue(); //or (String rel : map.keySet()) { //List<BySourceTabResults> relations = map.get(rel); if (rel.compareTo(INCOMPLETE) != 0) { String category = "Other"; /* * if (parent_asso_vec.contains(rel)) category = "Parent"; else * if (child_asso_vec.contains(rel)) category = "Child"; else if * (bt_vec.contains(rel)) category = "Broader"; else if * (nt_vec.contains(rel)) category = "Narrower"; */ if (parent_asso_vec.contains(rel)) category = "Child"; else if (child_asso_vec.contains(rel)) category = "Parent"; else if (bt_vec.contains(rel)) category = "Narrower"; else if (nt_vec.contains(rel)) category = "Broader"; else if (sibling_asso_vec.contains(rel)) category = "Sibling"; for (BySourceTabResults result : relations) { String code = result.getCui(); if (code.compareTo(CUI) != 0 && code.indexOf("@") == -1) { // check CUI_hashmap containsKey(rel$code)??? if (!CUI_hashset.contains(rel + "$" + code)) { String rela = result.getRela(); if (rela == null || rela.compareTo("null") == 0) { rela = " "; } Vector v = (Vector) cui2SynonymsMap.get(code); ms_find_highest_rank_atom = System.currentTimeMillis(); BySourceTabResults top_atom = findHighestRankedAtom(v, sab); ms_find_highest_rank_atom_delay = ms_find_highest_rank_atom_delay + (System.currentTimeMillis() - ms_find_highest_rank_atom); /* * if (top_atom == null) { Concept c = * getConceptByCode("NCI Metathesaurus", null, null, * code); t = c.getEntityDescription().getContent() * + "|" + Constants.EXTERNAL_TERM_TYPE + "|" + * Constants.EXTERNAL_TERM_SOURCE + "|" + * Constants.EXTERNAL_TERM_SOURCE_CODE; } else { t = * top_atom.getTerm() + "|" + top_atom.getType() + * "|" + top_atom.getSource() + "|" + * top_atom.getCode(); } t = t + "|" + code + "|" + * rela + "|" + category; * * w.add(t); */ if (top_atom == null) { for (int k = 0; k < v.size(); k++) { top_atom = (BySourceTabResults) v.elementAt(k); t = top_atom.getTerm() + "|" + top_atom.getType() + "|" + top_atom.getSource() + "|" + top_atom.getCode(); t = t + "|" + code + "|" + top_atom.getRela() + "|" + category; w.add(t); } } else { t = top_atom.getTerm() + "|" + top_atom.getType() + "|" + top_atom.getSource() + "|" + top_atom.getCode(); t = t + "|" + code + "|" + rela + "|" + category; w.add(t); } CUI_hashset.add(rel + "$" + code); // Temporarily save non-RO other relationships if (category.compareTo("Other") == 0 && rela.compareTo("RO") != 0) { if (!rel_hset.contains(code)) { rel_hset.add(code); } } if (category.compareTo("Child") == 0 && rela.compareTo("CHD") != 0) { if (!hasSubtype_hset.contains(code)) { hasSubtype_hset.add(code); } } } } } } } } // *** do the same for map2 if (map2 != null) { Iterator it = map2.entrySet().iterator(); while (it.hasNext()) { Entry thisEntry = (Entry) it.next(); String rel = (String) thisEntry.getKey(); List<BySourceTabResults> relations = (List<BySourceTabResults>) thisEntry.getValue(); //for (String rel : map2.keySet()) { //List<BySourceTabResults> relations = map2.get(rel); if (rel.compareTo(INCOMPLETE) != 0) { String category = "Other"; /* * if (parent_asso_vec.contains(rel)) category = "Parent"; else * if (child_asso_vec.contains(rel)) category = "Child"; else if * (bt_vec.contains(rel)) category = "Broader"; else if * (nt_vec.contains(rel)) category = "Narrower"; */ if (parent_asso_vec.contains(rel)) category = "Child"; else if (child_asso_vec.contains(rel)) category = "Parent"; else if (bt_vec.contains(rel)) category = "Narrower"; else if (nt_vec.contains(rel)) category = "Broader"; else if (sibling_asso_vec.contains(rel)) category = "Sibling"; for (BySourceTabResults result : relations) { String code = result.getCui(); if (code.compareTo(CUI) != 0 && code.indexOf("@") == -1) { if (!CUI_hashset.contains(rel + "$" + code)) { String rela = result.getRela(); if (rela == null || rela.compareTo("null") == 0) { rela = " "; } Vector v = (Vector) cui2SynonymsMap.get(code); ms_find_highest_rank_atom = System.currentTimeMillis(); BySourceTabResults top_atom = findHighestRankedAtom(v, sab); ms_find_highest_rank_atom_delay = ms_find_highest_rank_atom_delay + (System.currentTimeMillis() - ms_find_highest_rank_atom); /* * if (top_atom == null) { Concept c = * getConceptByCode("NCI Metathesaurus", null, null, * code); t = c.getEntityDescription().getContent() * + "|" + Constants.EXTERNAL_TERM_TYPE + "|" + * Constants.EXTERNAL_TERM_SOURCE + "|" + * Constants.EXTERNAL_TERM_SOURCE_CODE; } else { t = * top_atom.getTerm() + "|" + top_atom.getType() + * "|" + top_atom.getSource() + "|" + * top_atom.getCode(); } */ if (top_atom == null) { for (int k = 0; k < v.size(); k++) { top_atom = (BySourceTabResults) v.elementAt(k); t = top_atom.getTerm() + "|" + top_atom.getType() + "|" + top_atom.getSource() + "|" + top_atom.getCode(); t = t + "|" + code + "|" + top_atom.getRela() + "|" + category; w.add(t); } } else { t = top_atom.getTerm() + "|" + top_atom.getType() + "|" + top_atom.getSource() + "|" + top_atom.getCode(); t = t + "|" + code + "|" + rela + "|" + category; w.add(t); } // w.add(t); CUI_hashset.add(rel + "$" + code); // Temporarily save non-RO other relationships if (category.compareTo("Other") == 0 && rela.compareTo("RO") != 0) { if (!rel_hset.contains(code)) { rel_hset.add(code); } } if (category.compareTo("Child") == 0 && rela.compareTo("CHD") != 0) { if (!hasSubtype_hset.contains(code)) { hasSubtype_hset.add(code); } } } } } } } } long total_categorization_delay = System.currentTimeMillis() - ms; String action_atom = "Find highest rank atom delay"; Debug.println("Run time (ms) for " + action_atom + " " + ms_find_highest_rank_atom_delay); DBG.debugDetails(ms_find_highest_rank_atom_delay, action_atom, "getNeighborhoodSynonyms"); long absolute_categorization_delay = total_categorization_delay - ms_find_highest_rank_atom_delay; Debug.println("Run time (ms) for " + action + " " + absolute_categorization_delay); DBG.debugDetails(absolute_categorization_delay, action, "getNeighborhoodSynonyms"); ms_remove_RO_delay = System.currentTimeMillis(); action = "Remove redundant relationships"; for (int i = 0; i < w.size(); i++) { String s = (String) w.elementAt(i); int j = i + 1; Vector<String> v = parseData(s, "|"); if (v.size() == 7) { String rel = (String) v.elementAt(6); if (rel.compareTo("Child") != 0 && rel.compareTo("Other") != 0) { u.add(s); } else if (rel.compareTo("Child") == 0) { String rela = (String) v.elementAt(5); if (rela.compareTo("CHD") != 0) { u.add(s); } else { String code = (String) v.elementAt(4); if (!hasSubtype_hset.contains(code)) { u.add(s); } } } else if (rel.compareTo("Other") == 0) { String rela = (String) v.elementAt(5); if (rela.compareTo("RO") != 0) { u.add(s); } else { String code = (String) v.elementAt(4); if (!rel_hset.contains(code)) { u.add(s); } } } } else { // Debug.println("(" + j + ") ??? " + s); } } delay = System.currentTimeMillis() - ms_remove_RO_delay; Debug.println("Run time (ms) for " + action + " " + delay); DBG.debugDetails(delay, action, "getNeighborhoodSynonyms"); long ms_sort_delay = System.currentTimeMillis(); u = removeRedundantRecords(u); SortUtils.quickSort(u); action = "Initial sorting"; delay = System.currentTimeMillis() - ms_sort_delay; Debug.println("Run time (ms) for " + action + " " + delay); DBG.debugDetails(delay, action, "getNeighborhoodSynonyms"); // DBG.debugDetails("Max Return", NCImBrowserProperties.maxToReturn); delay = System.currentTimeMillis() - ms_all; Debug.println("Run time (ms) for " + action_overall + " " + delay); DBG.debugDetails(delay, action_overall, "getNeighborhoodSynonyms"); return u; }
From source file:lu.fisch.unimozer.Diagram.java
@Override public void paint(Graphics graphics) { super.paint(graphics); Graphics2D g = (Graphics2D) graphics; // set anti-aliasing rendering ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setFont(new Font(g.getFont().getFontName(), Font.PLAIN, Unimozer.DRAW_FONT_SIZE)); // clear background g.setColor(Color.WHITE);//from w w w . j a va2 s .c o m g.fillRect(0, 0, getWidth() + 1, getHeight() + 1); g.setColor(Color.BLACK); /*Set<String> set; Iterator<String> itr; // draw classes a first time for(MyClass clas : classes.values()) { clas.setEnabled(this.isEnabled()); clas.draw(graphics,showFields,showMethods); }*/ /* let's try this one ... */ for (Entry<String, MyClass> entry : classes.entrySet()) { // get the actual class ... MyClass clas = entry.getValue(); clas.setEnabled(this.isEnabled()); clas.draw(graphics, showFields, showMethods); } // draw packages packages.clear(); for (MyClass myClass : classes.values()) { if (myClass.isDisplayUML()) { Package myPackage = null; if (!packages.containsKey(myClass.getPackagename())) { myPackage = new Package(myClass.getPackagename(), myClass.getPosition().y, myClass.getPosition().x, myClass.getWidth(), myClass.getHeight()); packages.put(myPackage.getName(), myPackage); } else myPackage = packages.get(myClass.getPackagename()); if (myClass.getPosition().x + myClass.getWidth() > myPackage.getRight()) myPackage.setRight(myClass.getPosition().x + myClass.getWidth()); if (myClass.getPosition().y + myClass.getHeight() > myPackage.getBottom()) myPackage.setBottom(myClass.getPosition().y + myClass.getHeight()); if (myClass.getPosition().x < myPackage.getLeft()) myPackage.setLeft(myClass.getPosition().x); if (myClass.getPosition().y < myPackage.getTop()) myPackage.setTop(myClass.getPosition().y); } } // draw classes /* set = classes.keySet(); itr = set.iterator(); while (itr.hasNext()) { String str = itr.next(); classes.get(str).draw(graphics); }/**/ mostRight = 0; mostBottom = 0; // ?? /* set = classes.keySet(); itr = set.iterator(); while (itr.hasNext()) { String str = itr.next(); MyClass thisClass = classes.get(str); } */ // init topLeft & bottomRight topLeft = new Point(this.getWidth(), this.getHeight()); bottomRight = new Point(0, 0); // draw packages if (packages.size() > 0) if ((packages.size() == 1 && packages.get(Package.DEFAULT) == null) || packages.size() > 1) for (Package pack : packages.values()) { pack.draw(graphics); // push outer box if (pack.getTopAbs() < topLeft.y) topLeft.y = pack.getTopAbs(); if (pack.getLeftAbs() < topLeft.x) topLeft.x = pack.getLeftAbs(); if (pack.getBottomAbs() > bottomRight.y) bottomRight.y = pack.getBottomAbs(); if (pack.getRightAbs() > bottomRight.x) bottomRight.x = pack.getRightAbs(); } // draw implmementations if (isShowHeritage()) { Stroke oldStroke = g.getStroke(); g.setStroke(dashed); /*itr = set.iterator(); while (itr.hasNext()) { String str = itr.next(); */ /* let's try this one ... */ for (Entry<String, MyClass> entry : classes.entrySet()) { // get the actual class ... String str = entry.getKey(); MyClass thisClass = classes.get(str); if (thisClass.getPosition().x + thisClass.getWidth() > mostRight) mostRight = thisClass.getPosition().x + thisClass.getWidth(); if (thisClass.getPosition().y + thisClass.getHeight() > mostBottom) mostBottom = thisClass.getPosition().y + thisClass.getHeight(); if (thisClass.getImplements().size() > 0) for (String extendsClass : thisClass.getImplements()) { MyClass otherClass = classes.get(extendsClass); if (otherClass == null) otherClass = findByShortName(extendsClass); //if(otherClass==null) System.err.println(extendsClass+" not found (1)"); //if (otherClass==null) otherClass=findByShortName(extendsClass); //if(otherClass==null) System.err.println(extendsClass+" not found (2)"); if (otherClass != null && thisClass.isDisplayUML() && otherClass.isDisplayUML()) { thisClass.setExtendsMyClass(otherClass); // draw arrow from thisClass to otherClass // get the center point of each class Point fromP = new Point(thisClass.getPosition().x + thisClass.getWidth() / 2, thisClass.getPosition().y + thisClass.getHeight() / 2); Point toP = new Point(otherClass.getPosition().x + otherClass.getWidth() / 2, otherClass.getPosition().y + otherClass.getHeight() / 2); // get the corner 4 points of the desstination class // (outer margin = 4) Point toP1 = new Point(otherClass.getPosition().x - 4, otherClass.getPosition().y - 4); Point toP2 = new Point(otherClass.getPosition().x + otherClass.getWidth() + 4, otherClass.getPosition().y - 4); Point toP3 = new Point(otherClass.getPosition().x + otherClass.getWidth() + 4, otherClass.getPosition().y + otherClass.getHeight() + 4); Point toP4 = new Point(otherClass.getPosition().x - 4, otherClass.getPosition().y + otherClass.getHeight() + 4); // get the intersection with the center line an one of the // sedis of the destination class Point2D toDraw = getIntersection(fromP, toP, toP1, toP2); if (toDraw == null) toDraw = getIntersection(fromP, toP, toP2, toP3); if (toDraw == null) toDraw = getIntersection(fromP, toP, toP3, toP4); if (toDraw == null) toDraw = getIntersection(fromP, toP, toP4, toP1); // draw the arrowed line if (toDraw != null) drawExtends(g, fromP, new Point((int) toDraw.getX(), (int) toDraw.getY())); } } } g.setStroke(oldStroke); } // draw inheritance if (isShowHeritage()) { /*itr = set.iterator(); while (itr.hasNext()) { String str = itr.next(); */ /* let's try this one ... */ for (Entry<String, MyClass> entry : classes.entrySet()) { // get the actual class ... String str = entry.getKey(); MyClass thisClass = classes.get(str); if (thisClass.getPosition().x + thisClass.getWidth() > mostRight) mostRight = thisClass.getPosition().x + thisClass.getWidth(); if (thisClass.getPosition().y + thisClass.getHeight() > mostBottom) mostBottom = thisClass.getPosition().y + thisClass.getHeight(); String extendsClass = thisClass.getExtendsClass(); //System.out.println(thisClass.getFullName()+" extends "+extendsClass); if (!extendsClass.equals("") && thisClass.isDisplayUML()) { MyClass otherClass = classes.get(extendsClass); if (otherClass == null) otherClass = findByShortName(extendsClass); //if(otherClass==null) System.err.println(extendsClass+" not found (1)"); //if (otherClass==null) otherClass=findByShortName(extendsClass); //if(otherClass==null) System.err.println(extendsClass+" not found (2)"); if (otherClass != null) { if (otherClass != thisClass) { thisClass.setExtendsMyClass(otherClass); // draw arrow from thisClass to otherClass // get the center point of each class Point fromP = new Point(thisClass.getPosition().x + thisClass.getWidth() / 2, thisClass.getPosition().y + thisClass.getHeight() / 2); Point toP = new Point(otherClass.getPosition().x + otherClass.getWidth() / 2, otherClass.getPosition().y + otherClass.getHeight() / 2); // get the corner 4 points of the desstination class // (outer margin = 4) Point toP1 = new Point(otherClass.getPosition().x - 4, otherClass.getPosition().y - 4); Point toP2 = new Point(otherClass.getPosition().x + otherClass.getWidth() + 4, otherClass.getPosition().y - 4); Point toP3 = new Point(otherClass.getPosition().x + otherClass.getWidth() + 4, otherClass.getPosition().y + otherClass.getHeight() + 4); Point toP4 = new Point(otherClass.getPosition().x - 4, otherClass.getPosition().y + otherClass.getHeight() + 4); // get the intersection with the center line an one of the // sedis of the destination class Point2D toDraw = getIntersection(fromP, toP, toP1, toP2); if (toDraw == null) toDraw = getIntersection(fromP, toP, toP2, toP3); if (toDraw == null) toDraw = getIntersection(fromP, toP, toP3, toP4); if (toDraw == null) toDraw = getIntersection(fromP, toP, toP4, toP1); // draw in red if there is a cclic inheritance problem if (thisClass.hasCyclicInheritance()) { ((Graphics2D) graphics).setStroke(new BasicStroke(2)); graphics.setColor(Color.RED); } // draw the arrowed line if (toDraw != null) drawExtends((Graphics2D) graphics, fromP, new Point((int) toDraw.getX(), (int) toDraw.getY())); } else { ((Graphics2D) graphics).setStroke(new BasicStroke(2)); graphics.setColor(Color.RED); // line graphics.drawLine(thisClass.getPosition().x + thisClass.getWidth() / 2, thisClass.getPosition().y, thisClass.getPosition().x + thisClass.getWidth() / 2, thisClass.getPosition().y - 32); graphics.drawLine(thisClass.getPosition().x + thisClass.getWidth() / 2, thisClass.getPosition().y - 32, thisClass.getPosition().x + thisClass.getWidth() + 32, thisClass.getPosition().y - 32); graphics.drawLine(thisClass.getPosition().x + thisClass.getWidth() + 32, thisClass.getPosition().y - 32, thisClass.getPosition().x + thisClass.getWidth() + 32, thisClass.getPosition().y + thisClass.getHeight() + 32); graphics.drawLine(thisClass.getPosition().x + thisClass.getWidth() + 32, thisClass.getPosition().y + thisClass.getHeight() + 32, thisClass.getPosition().x + thisClass.getWidth() / 2, thisClass.getPosition().y + thisClass.getHeight() + 32); drawExtends((Graphics2D) graphics, new Point(thisClass.getPosition().x + thisClass.getWidth() / 2, thisClass.getPosition().y + thisClass.getHeight() + 32), new Point(thisClass.getPosition().x + thisClass.getWidth() / 2, thisClass.getPosition().y + thisClass.getHeight())); } // reset the stroke and the color ((Graphics2D) graphics).setStroke(new BasicStroke(1)); graphics.setColor(Color.BLACK); } } } } // setup a hastable to store the relations //Hashtable<String,StringList> classUsage = new Hashtable<String,StringList>(); // store compositions Hashtable<MyClass, Vector<MyClass>> classCompositions = new Hashtable<MyClass, Vector<MyClass>>(); // store aggregations Hashtable<MyClass, Vector<MyClass>> classAggregations = new Hashtable<MyClass, Vector<MyClass>>(); // store all relations Hashtable<MyClass, Vector<MyClass>> classUsings = new Hashtable<MyClass, Vector<MyClass>>(); /* // iterate through all classes to find compositions itr = set.iterator(); while (itr.hasNext()) { // get the actual classname String str = itr.next(); */ /* let's try this one ... */ for (Entry<String, MyClass> entry : classes.entrySet()) { // get the actual class ... String str = entry.getKey(); // get the corresponding "MyClass" object MyClass thisClass = classes.get(str); // setup a list to store the relations with this class Vector<MyClass> theseCompositions = new Vector<MyClass>(); // get all fields of this class StringList uses = thisClass.getFieldTypes(); for (int u = 0; u < uses.count(); u++) { // try to find the other (used) class MyClass otherClass = classes.get(uses.get(u)); if (otherClass == null) otherClass = findByShortName(uses.get(u)); if (otherClass != null) // means this class uses the other ones { // add the other class to the list theseCompositions.add(otherClass); } } // add the list of used classes to the MyClass object thisClass.setUsesMyClass(theseCompositions); // store the composition in the general list classCompositions.put(thisClass, theseCompositions); // store the compositions int eh global relation list classUsings.put(thisClass, new Vector<MyClass>(theseCompositions)); // ^^^^^^^^^^^^^^^^^^^^ // important !! => create a new vector, otherwise the list // are the same ... } /* // iterate through all classes to find aggregations itr = set.iterator(); while (itr.hasNext()) { // get the actual class String str = itr.next(); */ /* let's try this one ... */ for (Entry<String, MyClass> entry : classes.entrySet()) { // get the actual class ... String str = entry.getKey(); // get the corresponding "MyClass" object MyClass thisClass = classes.get(str); // we need a list to store the aggragations with this class Vector<MyClass> theseAggregations = new Vector<MyClass>(); // try to get the list of compositions for this class // init if not present Vector<MyClass> theseCompositions = classCompositions.get(thisClass); if (theseCompositions == null) theseCompositions = new Vector<MyClass>(); // try to get the list of all relations for this class // init if not present Vector<MyClass> theseClasses = classUsings.get(thisClass); if (theseClasses == null) theseClasses = new Vector<MyClass>(); // get the names of the classes that thisclass uses StringList foundUsage = thisClass.getUsesWho(); // go through the list an check to find a corresponding MyClass for (int f = 0; f < foundUsage.count(); f++) { // get the name of the used class String usedClass = foundUsage.get(f); MyClass otherClass = classes.get(usedClass); if (otherClass == null) otherClass = findByShortName(usedClass); if (otherClass != null && thisClass != otherClass) // meanint "otherClass" is a class used by thisClass { if (!theseCompositions.contains(otherClass)) theseAggregations.add(otherClass); if (!theseClasses.contains(otherClass)) theseClasses.add(otherClass); } } // get all method types of this class StringList uses = thisClass.getMethodTypes(); for (int u = 0; u < uses.count(); u++) { // try to find the other (used) class MyClass otherClass = classes.get(uses.get(u)); if (otherClass == null) otherClass = findByShortName(uses.get(u)); if (otherClass != null) // means this class uses the other ones { // add the other class to the list theseAggregations.add(otherClass); } } // store the relations to the class thisClass.setUsesMyClass(theseClasses); // store the aggregation to the global list classAggregations.put(thisClass, theseAggregations); // store all relations to the global list classUsings.put(thisClass, theseClasses); } if (isShowComposition()) { /*Set<MyClass> set2 = classCompositions.keySet(); Iterator<MyClass> itr2 = set2.iterator(); while (itr2.hasNext()) { MyClass thisClass = itr2.next(); */ /* let's try this one ... */ for (Entry<MyClass, Vector<MyClass>> entry : classCompositions.entrySet()) { // get the actual class ... MyClass thisClass = entry.getKey(); if (thisClass.isDisplayUML()) { Vector<MyClass> otherClasses = classCompositions.get(thisClass); for (MyClass otherClass : otherClasses) drawComposition(g, thisClass, otherClass, classUsings); } } } if (isShowAggregation()) { /*Set<MyClass> set2 = classAggregations.keySet(); Iterator<MyClass> itr2 = set2.iterator(); while (itr2.hasNext()) { MyClass thisClass = itr2.next(); */ /* let's try this one ... */ for (Entry<MyClass, Vector<MyClass>> entry : classAggregations.entrySet()) { // get the actual class ... MyClass thisClass = entry.getKey(); if (thisClass.isDisplayUML()) { Vector<MyClass> otherClasses = classAggregations.get(thisClass); for (MyClass otherClass : otherClasses) drawAggregation(g, thisClass, otherClass, classUsings); } } } // draw classes again to put them on top // of the arrows /*set = classes.keySet(); itr = set.iterator(); while (itr.hasNext()) { String str = itr.next(); */ /* let's try this one ... */ for (Entry<String, MyClass> entry : classes.entrySet()) { // get the actual class ... String str = entry.getKey(); classes.get(str).setEnabled(this.isEnabled()); classes.get(str).draw(graphics, showFields, showMethods); // push outer box MyClass thisClass = classes.get(str); if (thisClass.getPosition().y < topLeft.y) topLeft.y = thisClass.getPosition().y; if (thisClass.getPosition().x < topLeft.x) topLeft.x = thisClass.getPosition().x; if (thisClass.getPosition().y + thisClass.getHeight() > bottomRight.y) bottomRight.y = thisClass.getPosition().y + thisClass.getHeight(); if (thisClass.getPosition().x + thisClass.getWidth() > bottomRight.x) bottomRight.x = thisClass.getPosition().x + thisClass.getWidth(); } // comments if (commentString != null) { String fontName = g.getFont().getName(); g.setFont(new Font("Courier", g.getFont().getStyle(), Unimozer.DRAW_FONT_SIZE)); if (!commentString.trim().equals("")) { String myCommentString = new String(commentString); Point myCommentPoint = new Point(commentPoint); //System.out.println(myCommentString); // adjust comment myCommentString = myCommentString.trim(); // adjust position myCommentPoint.y = myCommentPoint.y + 16; // explode comment StringList sl = StringList.explode(myCommentString, "\n"); // calculate totals int totalHeight = 0; int totalWidth = 0; for (int i = 0; i < sl.count(); i++) { String line = sl.get(i).trim(); int h = (int) g.getFont().getStringBounds(line, g.getFontRenderContext()).getHeight(); int w = (int) g.getFont().getStringBounds(line, g.getFontRenderContext()).getWidth(); totalHeight += h; totalWidth = Math.max(totalWidth, w); } // get comment size // draw background g.setColor(new Color(255, 255, 128, 255)); g.fillRoundRect(myCommentPoint.x, myCommentPoint.y, totalWidth + 8, totalHeight + 8, 4, 4); // draw border g.setColor(Color.BLACK); g.drawRoundRect(myCommentPoint.x, myCommentPoint.y, totalWidth + 8, totalHeight + 8, 4, 4); // draw text totalHeight = 0; for (int i = 0; i < sl.count(); i++) { String line = sl.get(i).trim(); int h = (int) g.getFont().getStringBounds(myCommentString, g.getFontRenderContext()) .getHeight(); g.drawString(line, myCommentPoint.x + 4, myCommentPoint.y + h + 2 + totalHeight); totalHeight += h; } } g.setFont(new Font(fontName, Font.PLAIN, Unimozer.DRAW_FONT_SIZE)); } /* if(!isEnabled()) { g.setColor(new Color(128,128,128,128)); g.fillRect(0,0,getWidth(),getHeight()); } */ this.setPreferredSize(new Dimension(mostRight + 32, mostBottom + 32)); // THE NEXT LINE MAKES ALL DIALOGUES DISAPEAR!! //this.setSize(mostRight+32, mostBottom+32); this.validate(); ((JScrollPane) this.getParent().getParent()).revalidate(); if (mode == MODE_EXTENDS && extendsFrom != null && extendsDragPoint != null) { graphics.setColor(Color.BLUE); ((Graphics2D) graphics).setStroke(new BasicStroke(2)); drawExtends(g, new Point(extendsFrom.getPosition().x + extendsFrom.getWidth() / 2, extendsFrom.getPosition().y + extendsFrom.getHeight() / 2), extendsDragPoint); graphics.setColor(Color.BLACK); ((Graphics2D) graphics).setStroke(new BasicStroke(1)); } }
From source file:org.sakaiproject.site.tool.SiteAction.java
/** * update the selected tool list//from www . jav a 2 s .c o m * * @param params * The ParameterParser object * @param updateConfigVariables * Need to update configuration variables */ private void updateSelectedToolList(SessionState state, ParameterParser params, boolean updateConfigVariables) { if (params.getStrings("selectedTools") != null) { // read entries for multiple tool customization List selectedTools = new ArrayList(Arrays.asList(params.getStrings("selectedTools"))); HashMap<String, String> toolTitles = state.getAttribute(STATE_TOOL_REGISTRATION_TITLE_LIST) != null ? (HashMap<String, String>) state.getAttribute(STATE_TOOL_REGISTRATION_TITLE_LIST) : new HashMap<String, String>(); Set multipleToolIdSet = (Set) state.getAttribute(STATE_MULTIPLE_TOOL_ID_SET); Map multipleToolIdTitleMap = state.getAttribute(STATE_MULTIPLE_TOOL_ID_TITLE_MAP) != null ? (Map) state.getAttribute(STATE_MULTIPLE_TOOL_ID_TITLE_MAP) : new HashMap(); HashMap<String, HashMap<String, String>> multipleToolConfiguration = state .getAttribute(STATE_MULTIPLE_TOOL_CONFIGURATION) != null ? (HashMap<String, HashMap<String, String>>) state .getAttribute(STATE_MULTIPLE_TOOL_CONFIGURATION) : new HashMap<String, HashMap<String, String>>(); Vector<String> idSelected = (Vector<String>) state .getAttribute(STATE_TOOL_REGISTRATION_OLD_SELECTED_LIST); boolean has_home = false; String emailId = state.getAttribute(STATE_TOOL_EMAIL_ADDRESS) != null ? (String) state.getAttribute(STATE_TOOL_EMAIL_ADDRESS) : null; for (int i = 0; i < selectedTools.size(); i++) { String id = (String) selectedTools.get(i); if (id.equalsIgnoreCase(TOOL_ID_HOME)) { has_home = true; } else if (id.equalsIgnoreCase("sakai.mailbox")) { // read email id emailId = StringUtils.trimToNull(params.getString("emailId")); state.setAttribute(STATE_TOOL_EMAIL_ADDRESS, emailId); if (updateConfigVariables) { // if Email archive tool is selected, check the email alias String siteId = (String) state.getAttribute(STATE_SITE_INSTANCE_ID); String channelReference = mailArchiveChannelReference(siteId); if (emailId == null) { addAlert(state, rb.getString("java.emailarchive") + " "); } else { if (!Validator.checkEmailLocal(emailId)) { addAlert(state, rb.getString("java.theemail")); } else if (!aliasService.allowSetAlias(emailId, channelReference)) { addAlert(state, rb.getString("java.addalias")); } else { // check to see whether the alias has been used by // other sites try { String target = aliasService.getTarget(emailId); if (target != null) { if (siteId != null) { if (!target.equals(channelReference)) { // the email alias is not used by // current site addAlert(state, rb.getString("java.emailinuse") + " "); } } else { addAlert(state, rb.getString("java.emailinuse") + " "); } } } catch (IdUnusedException ee) { } } } } } else if (isMultipleInstancesAllowed(findOriginalToolId(state, id)) && (idSelected != null && !idSelected.contains(id) || idSelected == null)) { // newly added mutliple instances String title = StringUtils.trimToNull(params.getString("title_" + id)); if (title != null) { // truncate the title to maxlength as defined if (title.length() > MAX_TOOL_TITLE_LENGTH) { title = title.substring(0, MAX_TOOL_TITLE_LENGTH); } // save the titles entered multipleToolIdTitleMap.put(id, title); } toolTitles.put(id, title); // get the attribute input HashMap<String, String> attributes = multipleToolConfiguration.get(id); if (attributes == null) { // if missing, get the default setting for original id attributes = multipleToolConfiguration.get(findOriginalToolId(state, id)); } if (attributes != null) { for (Iterator<String> e = attributes.keySet().iterator(); e.hasNext();) { String attribute = e.next(); String attributeInput = StringUtils.trimToNull(params.getString(attribute + "_" + id)); if (attributeInput != null) { // save the attribute input if valid, otherwise generate alert if (FormattedText.validateURL(attributeInput)) attributes.put(attribute, attributeInput); else addAlert(state, rb.getString("java.invurl")); } } multipleToolConfiguration.put(id, attributes); } } } // update the state objects state.setAttribute(STATE_MULTIPLE_TOOL_ID_TITLE_MAP, multipleToolIdTitleMap); state.setAttribute(STATE_MULTIPLE_TOOL_CONFIGURATION, multipleToolConfiguration); state.setAttribute(STATE_TOOL_HOME_SELECTED, Boolean.valueOf(has_home)); state.setAttribute(STATE_TOOL_REGISTRATION_TITLE_LIST, toolTitles); } // read in the input for external tool list updateSelectedExternalToolList(state, params); }