List of usage examples for java.util Hashtable entrySet
Set entrySet
To view the source code for java.util Hashtable entrySet.
Click Source Link
From source file:com.crushpaper.Servlet.java
/** * Helper method. Adds the HTML for an entry to a tree. */// www.j a v a 2 s . c o m private int addEntryHtmlToTree(Entry entry, StringBuilder result, List<EntryInfo> entryInfoList, int levelsOfChildrenToInclude, boolean onlyChildren, String idOfEntryToSkip, boolean includeRootInEntryInfoList, boolean showCheckboxes) throws IOException { if (!onlyChildren) { result.append("<div class=\"subtree\">"); result.append("<div class=\"alone " + entry.getId() + "\" id=\"alone_" + entry.getId() + "\" ondragover=\"onDragOverAloneEl(event)\" ondrop=\"onDropAloneEl(event)\">"); result.append( "<table class=\"nopadding alonetd\"><tr><td onmousedown=\"triangleOnMouseDown(event); return false;\" class=\"triTd justDrag\">" + "<div></div></td><td>" + "<table class=\"nopadding\"><tr><td class=\"nowords\"><img onmouseover=\"plusOnMouseOver(event);\" onmouseout=\"plusOnMouseOut(event);\" alt=\"plus\" title=\"" + servletText.plusTooltip() + "\" class=\"justDrag plusOrMinus\" onmousedown=\"plusOnMouseDown(event); return false;\" src=\"/images/plus.png\"></td></tr>" + "<tr><td class=\"nowords\"><img onmouseover=\"minusOnMouseOver(event);\" onmouseout=\"minusOnMouseOut(event);\" alt=\"minus\" title=\"" + servletText.minusTooltip() + "\" class=\"justDrag plusOrMinus\" onmousedown=\"minusOnMouseDown(event); return false;\" src=\"/images/minus.png\"></td></tr></table>" + "</td>"); if (showCheckboxes) { result.append( "<td><input type=\"checkbox\" class=\"justDrag aloneCheckbox mousetrap\" onclick=\"checkboxOnClick(event); return true;\"></td>"); } result.append("<td class=\"content\">"); if (entry.hasQuotation()) { result.append("<div class=\"quotation\">"); result.append(getQuotationHtml(entry, true)); result.append("</div><br>"); } String noteHtml = getNoteHtml(entry, false, entry.hasQuotation(), true); if (!noteHtml.isEmpty()) { result.append("<div class=\"note mousetrap\">"); result.append(noteHtml); result.append("</div>"); } result.append("<span class=\"entryDaytime\">" + servletText.fragmentLastModified() + " " + "<span class=\"modTime\">" + formatDateAndTime(entry.getModTime()) + "<span class=\"rawDateTime\">" + entry.getModTime() + "</span></span></span>"); final Entry source = dbLogic.getEntryById(entry.getSourceId()); if (source != null) { addSourceHtml(source, result, SourceEmbedContext.InQuotation, null, -1, null); } // Good for debugging. if (false) { result.append("<br>id: " + entry.getId()); result.append("<br>parent: " + entry.getParentId("")); result.append("<br>first child: " + entry.getFirstChildId("")); result.append("<br>last child: " + entry.getLastChildId("")); result.append("<br>previous sibling: " + entry.getPreviousSiblingId("")); result.append("<br>next sibling: " + entry.getNextSiblingId("")); } result.append("</td></tr></table></div>"); result.append("<div class=\"justchildren\">"); } if (includeRootInEntryInfoList) { addEntryToInfoList(entry, entryInfoList); } int indexOfEntryToSkip = -1; if (levelsOfChildrenToInclude > 0) { --levelsOfChildrenToInclude; final Hashtable<String, Entry> children = new Hashtable<String, Entry>(); Entry first = null; for (final Object childObject : dbLogic.getEntriesByParentId(entry.getId())) { final Entry child = (Entry) childObject; children.put(child.getId(), child); if (!child.hasPreviousSiblingId()) { first = child; } } if (first != null) { // This is the code path if there is no DB corruption. Entry child = first; for (int i = 0; i < children.size(); ++i) { if (child == null) { break; } if (idOfEntryToSkip != null && idOfEntryToSkip.equals(child.getId())) { indexOfEntryToSkip = i; } else { addEntryHtmlToTree(child, result, entryInfoList, levelsOfChildrenToInclude, false, null, true, showCheckboxes); } if (!child.hasNextSiblingId()) { break; } final String nextId = child.getNextSiblingId(); child = children.get(nextId); } } else { // This is an error code path. It should only happen if there is // DB corruption. final Iterator<Map.Entry<String, Entry>> iterator = children.entrySet().iterator(); int i = 0; while (iterator.hasNext()) { final Map.Entry<String, Entry> mapEntry = iterator.next(); final Entry child = mapEntry.getValue(); if (idOfEntryToSkip != null && idOfEntryToSkip.equals(child.getId())) { indexOfEntryToSkip = i; } else { addEntryHtmlToTree(child, result, entryInfoList, levelsOfChildrenToInclude, false, null, true, showCheckboxes); } ++i; } } } if (!onlyChildren) { result.append("</div>"); result.append("</div>"); } return indexOfEntryToSkip; }
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;/* ww w . j av a 2 s . c o 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 .j a v a 2s. co m*/ 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:org.unitime.timetable.solver.course.ui.ClassInfoModel.java
protected Vector<ClassRoomInfo> findRooms(ClassTimeInfo period, int minRoomSize, int maxRoomSize, String filter, boolean allowConflicts, RoomBase showAllRooms) { Vector<ClassRoomInfo> rooms = new Vector<ClassRoomInfo>(); Class_ clazz = getClazz().getClazz(Class_DAO.getInstance().getSession()); int nrRooms = (clazz.getNbrRooms() == null ? 1 : clazz.getNbrRooms().intValue()); iRoomPreferences.clear();//from w w w .jav a 2 s .c o m Set groupPrefs = clazz.effectivePreferences(RoomGroupPref.class); Set roomPrefs = clazz.effectivePreferences(RoomPref.class); Set bldgPrefs = clazz.effectivePreferences(BuildingPref.class); Set featurePrefs = clazz.effectivePreferences(RoomFeaturePref.class); if (nrRooms > 0) { int minClassLimit = clazz.getExpectedCapacity().intValue(); int maxClassLimit = clazz.getMaxExpectedCapacity().intValue(); if (maxClassLimit < minClassLimit) maxClassLimit = minClassLimit; float room2limitRatio = clazz.getRoomRatio().floatValue(); int roomCapacity = Math.round(minClassLimit <= 0 ? room2limitRatio : room2limitRatio * minClassLimit); //TODO: Use parameters from the default solver configuration int discouragedCapacity = (int) Math.round(0.99 * roomCapacity); int stronglyDiscouragedCapacity = (int) Math.round(0.98 * roomCapacity); Calendar cal = Calendar.getInstance(Locale.US); cal.setTime(new Date()); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); Date today = cal.getTime(); Date[] bounds = DatePattern.getBounds(clazz.getSessionId()); Set availRooms = clazz.getAvailableRooms(); rooms: for (Iterator i1 = availRooms.iterator(); i1.hasNext();) { Location room = (Location) i1.next(); if (iForm.getRoomTypes() != null && iForm.getRoomTypes().length > 0) { boolean ok = false; for (int i = 0; i < iForm.getRoomTypes().length; i++) if (room.getRoomType().getUniqueId().equals(iForm.getRoomTypes()[i])) { ok = true; break; } if (!ok) { i1.remove(); continue rooms; } } if (iForm.getRoomFeatures() != null && iForm.getRoomFeatures().length > 0) { for (int i = 0; i < iForm.getRoomFeatures().length; i++) if (!room.hasFeature(iForm.getRoomFeatures()[i])) { i1.remove(); continue rooms; } } if (iForm.getRoomGroups() != null && iForm.getRoomGroups().length > 0) { for (int i = 0; i < iForm.getRoomGroups().length; i++) if (room.hasGroup(iForm.getRoomGroups()[i])) continue rooms; i1.remove(); } } Set allRooms = availRooms; if (showAllRooms != RoomBase.Departmental) { allRooms = new TreeSet(availRooms); allRooms.addAll( findAllRooms(getClazz().getClazz().getSessionId(), showAllRooms == RoomBase.Timetabling)); } Long departmentId = getClazz().getClazz().getManagingDept().getUniqueId(); Hashtable<Location, Integer> filteredRooms = new Hashtable(); Set<Long> permIds = new HashSet(); rooms: for (Iterator i1 = allRooms.iterator(); i1.hasNext();) { Location room = (Location) i1.next(); boolean add = true; if (minRoomSize >= 0 && room.getCapacity() < minRoomSize) continue; if (maxRoomSize >= 0 && room.getCapacity() > maxRoomSize) continue; if (!match(room.getLabel(), filter)) continue; PreferenceCombination pref = new SumPreferenceCombination(); if (showAllRooms != RoomBase.Departmental && !availRooms.contains(room)) pref.addPreferenceProlog(PreferenceLevel.sProhibited); RoomSharingModel sharingModel = room.getRoomSharingModel(); if (sharingModel != null) { sharing: for (int d = 0; d < Constants.NR_DAYS; d++) { if ((Constants.DAY_CODES[d] & period.getDayCode()) == 0) continue; int startTime = period.getStartSlot(); int endTime = (period.getStartSlot() + period.getLength() - 1); for (int t = startTime; t <= endTime; t++) { Long px = Long.valueOf(sharingModel.getPreference(d, t)); if (px.equals(RoomSharingModel.sNotAvailablePref)) { if (showAllRooms != RoomBase.Departmental) { pref.addPreferenceProlog(PreferenceLevel.sProhibited); break sharing; } else { if (room.getLabel().equals(filter)) iForm.setMessage("Room " + room.getLabel() + " is not available for " + period.getLongName() + " due to the room sharing preferences."); continue rooms; } } if (px.equals(RoomSharingModel.sFreeForAllPref)) continue; if (departmentId != null && !departmentId.equals(px)) { if (showAllRooms != RoomBase.Departmental) { pref.addPreferenceProlog(PreferenceLevel.sProhibited); break sharing; } else { if (room.getLabel().equals(filter)) iForm.setMessage("Room " + room.getLabel() + " is not available for " + period.getLongName() + " due to the room sharing preferences."); continue rooms; } } } } } // --- group preference ---------- PreferenceCombination groupPref = PreferenceCombination.getDefault(); boolean reqGroup = false; for (Iterator i2 = groupPrefs.iterator(); i2.hasNext();) { RoomGroupPref p = (RoomGroupPref) i2.next(); if (p.getPrefLevel().getPrefProlog().equals(PreferenceLevel.sRequired)) reqGroup = true; if (p.getRoomGroup().getRooms().contains(room)) groupPref.addPreferenceProlog(p.getPrefLevel().getPrefProlog()); } if (reqGroup) { if (!PreferenceLevel.sRequired.equals(groupPref.getPreferenceProlog())) pref.addPreferenceProlog(PreferenceLevel.sProhibited); } else { pref.addPreferenceProlog(groupPref.getPreferenceProlog()); } // --- room preference ------------ String roomPref = null; PreferenceLevel roomPreference = getRoomPreference(clazz.getManagingDept(), room.getUniqueId()); if (roomPreference != null) { roomPref = roomPreference.getPrefProlog(); } boolean reqRoom = false; for (Iterator i2 = roomPrefs.iterator(); i2.hasNext();) { RoomPref p = (RoomPref) i2.next(); if (p.getPrefLevel().getPrefProlog().equals(PreferenceLevel.sRequired)) reqRoom = true; if (room.equals(p.getRoom())) roomPref = p.getPrefLevel().getPrefProlog(); } if (reqRoom) { if (!PreferenceLevel.sRequired.equals(roomPref)) pref.addPreferenceProlog(PreferenceLevel.sProhibited); } else if (roomPref != null) { pref.addPreferenceProlog(roomPref); } // --- building preference ------------ Building bldg = (room instanceof Room ? ((Room) room).getBuilding() : null); boolean reqBldg = false; String bldgPref = null; for (Iterator i2 = bldgPrefs.iterator(); i2.hasNext();) { BuildingPref p = (BuildingPref) i2.next(); if (p.getPrefLevel().getPrefProlog().equals(PreferenceLevel.sRequired)) reqBldg = true; if (bldg != null && bldg.equals(p.getBuilding())) bldgPref = p.getPrefLevel().getPrefProlog(); } if (reqBldg) { if (!PreferenceLevel.sRequired.equals(bldgPref)) pref.addPreferenceProlog(PreferenceLevel.sProhibited); } else if (bldgPref != null) { pref.addPreferenceProlog(bldgPref); } // --- room features preference -------- boolean acceptableFeatures = true; PreferenceCombination featurePref = new MinMaxPreferenceCombination(); for (Iterator i2 = featurePrefs.iterator(); i2.hasNext();) { RoomFeaturePref roomFeaturePref = (RoomFeaturePref) i2.next(); RoomFeature feature = roomFeaturePref.getRoomFeature(); String p = roomFeaturePref.getPrefLevel().getPrefProlog(); boolean hasFeature = feature.getRooms().contains(room); if (p.equals(PreferenceLevel.sProhibited) && hasFeature) { acceptableFeatures = false; } if (p.equals(PreferenceLevel.sRequired) && !hasFeature) { acceptableFeatures = false; } if (p != null && hasFeature && !p.equals(PreferenceLevel.sProhibited) && !p.equals(PreferenceLevel.sRequired)) featurePref.addPreferenceProlog(p); } pref.addPreferenceInt(featurePref.getPreferenceInt()); if (!acceptableFeatures) pref.addPreferenceProlog(PreferenceLevel.sProhibited); // --- room size ----------------- if (room.getCapacity().intValue() < stronglyDiscouragedCapacity) { pref.addPreferenceInt(1000); } else if (room.getCapacity().intValue() < discouragedCapacity) { pref.addPreferenceProlog(PreferenceLevel.sStronglyDiscouraged); } else if (room.getCapacity().intValue() < roomCapacity) { pref.addPreferenceProlog(PreferenceLevel.sDiscouraged); } int prefInt = pref.getPreferenceInt(); if (!add) continue; filteredRooms.put(room, prefInt); permIds.add(room.getPermanentId()); } boolean changePast = ApplicationProperty.ClassAssignmentChangePastMeetings.isTrue(); boolean ignorePast = ApplicationProperty.ClassAssignmentIgnorePastMeetings.isTrue(); List<Date> datesToCheck = null; if (ignorePast || !changePast) { datesToCheck = new ArrayList<Date>(); for (Date aDate : period.getDates()) { if (aDate.compareTo(today) > 0) datesToCheck.add(aDate); } } else { datesToCheck = period.getDates(); } Hashtable<Long, Set<Long>> room2classIds = Location.findClassLocationTable(clazz.getSessionId(), permIds, period.getStartSlot(), period.getLength(), changePast ? period.getDates() : datesToCheck); Hashtable<Long, Set<Event>> room2events = null; if (RoomAvailability.getInstance() != null && RoomAvailability.getInstance() instanceof DefaultRoomAvailabilityService) { room2events = Location.findEventTable(clazz.getSessionId(), permIds, period.getStartSlot(), period.getLength(), datesToCheck); } rooms: for (Map.Entry<Location, Integer> entry : filteredRooms.entrySet()) { Location room = entry.getKey(); int prefInt = entry.getValue(); String note = null; Set<Long> classIds = room2classIds.get(room.getPermanentId()); if (classIds == null) classIds = new HashSet(); // Fix the location table with the current assignment if (getClassAssignment() != null && getClassAssignment().hasRoom(room.getUniqueId()) && getClassAssignment().getTime().overlaps(period)) classIds.remove(getClassAssignment().getClassId()); if (iChange != null) { for (ClassAssignment conflict : iChange.getConflicts()) { if (conflict.hasRoom(room.getUniqueId()) && conflict.getTime().overlaps(period)) classIds.remove(conflict.getClassId()); } for (ClassAssignment current : iChange.getAssignments()) { ClassAssignment initial = iChange.getInitial(current); if (initial != null && initial.hasRoom(room.getUniqueId()) && initial.getTime().overlaps(period)) classIds.remove(initial.getClassId()); } for (ClassAssignment current : iChange.getAssignments()) { if (!getClazz().getClassId().equals(current.getClassId()) && current.hasRoom(room.getUniqueId()) && current.getTime().overlaps(period)) classIds.add(current.getClassId()); } } if (!allowConflicts && classIds != null && !classIds.isEmpty()) { for (Long classId : classIds) { if (!clazz.canShareRoom(classId)) { if (room.getLabel().equals(filter)) iForm.setMessage("Room " + room.getLabel() + " is not available for " + period.getLongName() + " due to the class " + Class_DAO.getInstance().get(classId).getClassLabel() + "."); continue rooms; } } } if (allowConflicts && classIds != null && !classIds.isEmpty()) { for (Long classId : classIds) { if (!clazz.canShareRoom(classId)) { prefInt += 10000; note = "Conflicts with " + Class_DAO.getInstance().get(classId).getClassLabel(); break; } } } if (classIds != null && iChange != null) { for (Long classId : classIds) { if (iChange.getCurrent(classId) != null && !clazz.canShareRoom(classId)) { if (room.getLabel().equals(filter)) iForm.setMessage("Room " + room.getLabel() + " is not available for " + period.getLongName() + " due to the class " + Class_DAO.getInstance().get(classId).getClassLabel() + "."); continue rooms; } } } if (room2events != null) { Set<Event> conflicts = room2events.get(room.getPermanentId()); if (conflicts != null && !conflicts.isEmpty()) { if (room.getLabel().equals(filter)) iForm.setMessage("Room " + room.getLabel() + " is not available for " + period.getLongName() + " due to " + conflicts); sLog.info("Room " + room.getLabel() + " is not available for " + period.getLongName() + " due to " + conflicts); continue rooms; } } else if (RoomAvailability.getInstance() != null) { Collection<TimeBlock> times = RoomAvailability.getInstance().getRoomAvailability( room.getUniqueId(), bounds[0], bounds[1], RoomAvailabilityInterface.sClassType); if (times != null && !times.isEmpty()) { Collection<TimeBlock> timesToCheck = null; if (!changePast || ignorePast) { timesToCheck = new Vector(); for (TimeBlock time : times) { if (!time.getEndTime().before(today)) timesToCheck.add(time); } } else { timesToCheck = times; } TimeBlock time = period.overlaps(timesToCheck); if (time != null) { if (room.getLabel().equals(filter)) iForm.setMessage("Room " + room.getLabel() + " is not available for " + period.getLongName() + " due to " + time); sLog.info("Room " + room.getLabel() + " is not available for " + period.getLongName() + " due to " + time); continue rooms; } } } rooms.addElement(new ClassRoomInfo(room, prefInt, note)); } } return rooms; }
From source file:org.adl.sequencer.impl.ADLSequencer.java
/** * Initiates deterministic rollup from the target activity and any other * activities that may have been affected. <br> * <b>Internal Sequencing Process</b><br> * <br>//w ww . j a v a 2 s. c o m * * @param ioTarget * Identifies the activity where rollup is applied. * * @param iWriteObjIDs * Identifies the set of objective IDs that are affected by this * invokation; or <code>null</code> if none. */ private void invokeRollup(SeqActivity ioTarget, List<String> iWriteObjIDs) { if (_Debug) { System.out.println(" :: ADLSequencer --> BEGIN - invokeRollup"); System.out.println(" ::--> Start: " + ioTarget.getID()); } Hashtable<String, Integer> rollupSet = new Hashtable<String, Integer>(); // Case #1 -- Rollup applies along the active path if (ioTarget == mSeqTree.getCurrentActivity()) { if (_Debug) { System.out.println(" ::--> CASE #1 Rollup"); } SeqActivity walk = ioTarget; // Walk from the target to the root, apply rollup rules at each step while (walk != null) { if (_Debug) { System.out.println(" ::--> Adding :: " + walk.getID()); } rollupSet.put(walk.getID(), Integer.valueOf(walk.getDepth())); List<String> writeObjIDs = walk.getObjIDs(null, false); if (writeObjIDs != null) { for (int i = 0; i < writeObjIDs.size(); i++) { String objID = writeObjIDs.get(i); if (_Debug) { System.out.println(" ::--> Rolling up Obj -- " + objID); } // Need to identify all activity's that 'read' this // objective // into their primary objective -- those activities need // to be // included in the rollup set List<String> acts = mSeqTree.getObjMap(objID); if (_Debug) { System.out.println(" ACTS == " + acts); } if (acts != null) { for (int j = 0; j < acts.size(); j++) { SeqActivity act = getActivity(acts.get(j)); if (_Debug) { System.out.println(" *+> " + j + " <+* :: " + act.getID()); } // Only rollup at the parent of the affected // activity act = act.getParent(); if (act != null) { // Only add if the activity is selected if (act.getIsSelected()) { if (_Debug) { System.out.println(" ::--> Adding :: " + act.getID()); } rollupSet.put(act.getID(), Integer.valueOf(act.getDepth())); } } } } } } walk = walk.getParent(); } // Remove the Current Activity from the rollup set rollupSet.remove(ioTarget.getID()); } // Case #2 -- Rollup applies when the state of a global shared objective // is written to... if (iWriteObjIDs != null) { if (_Debug) { System.out.println(" ::--> CASE #2 Rollup"); } for (int i = 0; i < iWriteObjIDs.size(); i++) { String objID = iWriteObjIDs.get(i); if (_Debug) { System.out.println(" ::--> Rolling up Obj -- " + objID); } // Need to identify all activity's that 'read' this objective // into their primary objective -- those activities need to be // included in the rollup set List<String> acts = mSeqTree.getObjMap(objID); if (_Debug) { System.out.println(" ACTS == " + acts); } if (acts != null) { for (int j = 0; j < acts.size(); j++) { SeqActivity act = getActivity(acts.get(j)); if (_Debug) { System.out.println(" *+> " + j + " <+* :: " + act.getID()); } // Only rollup at the parent of the affected activity act = act.getParent(); if (act != null) { // Only add if the activity is selected if (act.getIsSelected()) { if (_Debug) { System.out.println(" ::--> Adding :: " + act.getID()); } rollupSet.put(act.getID(), Integer.valueOf(act.getDepth())); } } } } } } // Perform the deterministic rollup extension while (rollupSet.size() != 0) { if (_Debug) { System.out.println(" ::--> Rollup Set Size == " + rollupSet.size()); for (Entry<String, Integer> entry : rollupSet.entrySet()) { System.out.println(" ::--> " + entry.getKey() + " // " + entry.getValue()); } } // Find the deepest activity SeqActivity deepest = null; int depth = -1; for (Entry<String, Integer> entry : rollupSet.entrySet()) { String key = entry.getKey(); int thisDepth = entry.getValue(); if (depth == -1) { depth = thisDepth; deepest = getActivity(key); } else if (thisDepth > depth) { depth = thisDepth; deepest = getActivity(key); } } if (deepest != null) { doOverallRollup(deepest, rollupSet); // If rollup was performed on the root, set the course's status if (deepest == mSeqTree.getRoot()) { @SuppressWarnings("unused") String completed = "unknown"; if (deepest.getObjStatus(false)) { completed = (deepest.getObjSatisfied(false)) ? "satisfied" : "notSatisfied"; } if (deepest.getObjMeasureStatus(false)) { completed = (new Double(deepest.getObjMeasure(false))).toString(); } if (deepest.getProgressStatus(false)) { completed = (deepest.getAttemptCompleted(false)) ? "completed" : "incomplete"; } //ADLSeqUtilities.setCourseStatus(mSeqTree.getCourseID(), // mSeqTree.getLearnerID(), satisfied, measure, // completed); } } else { if (_Debug) { System.out.println(" :: ERROR :: No activity found"); } } } if (_Debug) { System.out.println(" :: ADLSequencer --> END - invokeRollup"); } }
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);/* w w w. j a va 2 s.co 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)); } }