List of usage examples for java.awt Point Point
public Point(int x, int y)
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 a v a 2s. com } 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 ww w.j a va 2 s . c o 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:ca.phon.ipamap.IpaMap.java
public void onGoto(PhonActionEvent pae) { JComponent comp = (JComponent) pae.getData(); scrollPane.getViewport().setViewPosition(new Point(comp.getBounds().x, comp.getBounds().y)); }
From source file:com.munch.exchange.ExchangeChartComposite.java
/** * Zooms in on a selected region.// w w w .j ava2 s .co m * * @param selection the selected region. */ public void zoom(Rectangle selection) { // get the origin of the zoom selection in the Java2D space used for // drawing the chart (that is, before any scaling to fit the panel) Point2D selectOrigin = translateScreenToJava2D(new Point(selection.x, selection.y)); PlotRenderingInfo plotInfo = this.info.getPlotInfo(); Rectangle scaledDataArea = getScreenDataArea((selection.x + selection.width / 2), (selection.y + selection.height / 2)); if ((selection.height > 0) && (selection.width > 0)) { double hLower = (selection.x - scaledDataArea.x) / (double) scaledDataArea.width; double hUpper = (selection.x + selection.width - scaledDataArea.x) / (double) scaledDataArea.width; double vLower = (scaledDataArea.y + scaledDataArea.height - selection.y - selection.height) / (double) scaledDataArea.height; double vUpper = (scaledDataArea.y + scaledDataArea.height - selection.y) / (double) scaledDataArea.height; Plot p = this.chart.getPlot(); if (p instanceof Zoomable) { Zoomable z = (Zoomable) p; if (z.getOrientation() == PlotOrientation.HORIZONTAL) { z.zoomDomainAxes(vLower, vUpper, plotInfo, selectOrigin); z.zoomRangeAxes(hLower, hUpper, plotInfo, selectOrigin); } else { z.zoomDomainAxes(hLower, hUpper, plotInfo, selectOrigin); z.zoomRangeAxes(vLower, vUpper, plotInfo, selectOrigin); } } } }