/** * Updates all coordinates * * @todo Optimise. Some info can be cached * @todo Handle m:n (leftY/rightY etc) */ public void update() { /* * int leftY = _leftTable.getY() + _leftTable.getColumnY(_leftRole.getColumnMap().getPrimaryKey()); * int rightY; * if (!_leftRole.getRelation().isMany2Many()) { * rightY = _rightTable.getY() + _rightTable.getColumnY(_leftRole.getColumnMap().getForeignKey()); * } * else { * rightY = _rightTable.getY() + _rightTable.getColumnY(_rightRole.getColumnMap().getPrimaryKey()); * } */ int leftY = _leftTable.getY() + _leftColumnY; int rightY = _rightTable.getY() + _rightColumnY; // find out which table is farthest west (and east) JTablePanel westTable; JTablePanel eastTable; int westY; int eastY; Line2D.Float[] westLines; Line2D.Float[] eastLines; int[] westEdgeY; int[] eastEdgeY; _leftIsWest = _leftTable.getX() < _rightTable.getX(); if (_leftIsWest) { westTable = _leftTable; eastTable = _rightTable; westY = leftY; eastY = rightY; westLines = _leftLines; eastLines = _rightLines; westEdgeY = _leftEdgeY; eastEdgeY = _rightEdgeY; } else { westTable = _rightTable; eastTable = _leftTable; westY = rightY; eastY = leftY; westLines = _rightLines; eastLines = _leftLines; westEdgeY = _rightEdgeY; eastEdgeY = _leftEdgeY; } // find out whether the tables are more or less vertically aligned boolean aligned = (eastTable.getX() - westTable.getX()) < eastTable.getWidth() / 2; // TODO: handle different widths int westX; if (aligned) { westX = westTable.getX() - 10; for (int i = 0; i < westEdgeY.length; i++) { westLines[i].setLine(westX, westY, westTable.getX(), westEdgeY[i] + westTable.getY()); } } else { westX = westTable.getX() + westTable.getWidth() + 10; for (int i = 0; i < westEdgeY.length; i++) { westLines[i].setLine( westX, westY, westTable.getX() + westTable.getWidth(), westEdgeY[i] + westTable.getY()); } } int eastX = eastTable.getX() - 10; for (int i = 0; i < eastEdgeY.length; i++) { eastLines[i].setLine(eastX, eastY, eastTable.getX(), eastEdgeY[i] + eastTable.getY()); } _mainLine.setLine(westX, westY, eastX, eastY); setCardinalityPoints(); }
/** * Sets the CardinalityPoints attribute of the RelationLine object * * @todo refactor this duplicate code!!! */ private void setCardinalityPoints() { // compute vector of length 1 _mainLength = Point2D.distance( _mainLine.getX1(), _mainLine.getY1(), _mainLine.getX2(), _mainLine.getY2()); double vx = (_mainLine.getX2() - _mainLine.getX1()) / _mainLength; double vy = (_mainLine.getY2() - _mainLine.getY1()) / _mainLength; double cardx = 20.0 * vx; double cardy = 20.0 * vy; double arrowx = 30.0 * vx; double arrowy = 30.0 * vy; if (_leftIsWest) { _leftArrowPoint.setLocation(_mainLine.getX1() + cardx, _mainLine.getY1() + cardy); _rightArrowPoint.setLocation(_mainLine.getX2() - cardx, _mainLine.getY2() - cardy); // The left-side arrow head _temp.setLocation(_mainLine.getX1() + arrowx, _mainLine.getY1() + arrowy); _arrowTransform.setToRotation(Math.PI / 6, _leftArrowPoint.getX(), _leftArrowPoint.getY()); _arrowTransform.transform(_temp, _leftArrowPoint1); _leftArrowLine1.setLine( _leftArrowPoint.getX(), _leftArrowPoint.getY(), _leftArrowPoint1.getX(), _leftArrowPoint1.getY()); _arrowTransform.setToRotation(-Math.PI / 6, _leftArrowPoint.getX(), _leftArrowPoint.getY()); _arrowTransform.transform(_temp, _leftArrowPoint2); _leftArrowLine2.setLine( _leftArrowPoint.getX(), _leftArrowPoint.getY(), _leftArrowPoint2.getX(), _leftArrowPoint2.getY()); _arrowTransform.setToRotation(Math.PI / 2, _leftArrowPoint.getX(), _leftArrowPoint.getY()); _arrowTransform.transform(_temp, _leftCardinalityPoint); _arrowTransform.setToRotation(-Math.PI / 2, _leftArrowPoint.getX(), _leftArrowPoint.getY()); _arrowTransform.transform(_temp, _leftFkPoint); // The right-side arrow head _temp.setLocation(_mainLine.getX2() - arrowx, _mainLine.getY2() - arrowy); _arrowTransform.setToRotation(Math.PI / 6, _rightArrowPoint.getX(), _rightArrowPoint.getY()); _arrowTransform.transform(_temp, _rightArrowPoint1); _rightArrowLine1.setLine( _rightArrowPoint.getX(), _rightArrowPoint.getY(), _rightArrowPoint1.getX(), _rightArrowPoint1.getY()); _arrowTransform.setToRotation(-Math.PI / 6, _rightArrowPoint.getX(), _rightArrowPoint.getY()); _arrowTransform.transform(_temp, _rightArrowPoint2); _rightArrowLine2.setLine( _rightArrowPoint.getX(), _rightArrowPoint.getY(), _rightArrowPoint2.getX(), _rightArrowPoint2.getY()); _arrowTransform.setToRotation(-Math.PI / 2, _rightArrowPoint.getX(), _rightArrowPoint.getY()); _arrowTransform.transform(_temp, _rightCardinalityPoint); _arrowTransform.setToRotation(Math.PI / 2, _rightArrowPoint.getX(), _rightArrowPoint.getY()); _arrowTransform.transform(_temp, _rightFkPoint); } else { _leftArrowPoint.setLocation(_mainLine.getX2() - cardx, _mainLine.getY2() - cardy); _rightArrowPoint.setLocation(_mainLine.getX1() + cardx, _mainLine.getY1() + cardy); // The left-side arrow head _temp.setLocation(_mainLine.getX2() - arrowx, _mainLine.getY2() - arrowy); _arrowTransform.setToRotation(Math.PI / 6, _leftArrowPoint.getX(), _leftArrowPoint.getY()); _arrowTransform.transform(_temp, _leftArrowPoint1); _leftArrowLine1.setLine( _leftArrowPoint.getX(), _leftArrowPoint.getY(), _leftArrowPoint1.getX(), _leftArrowPoint1.getY()); _arrowTransform.setToRotation(-Math.PI / 6, _leftArrowPoint.getX(), _leftArrowPoint.getY()); _arrowTransform.transform(_temp, _leftArrowPoint2); _leftArrowLine2.setLine( _leftArrowPoint.getX(), _leftArrowPoint.getY(), _leftArrowPoint2.getX(), _leftArrowPoint2.getY()); _arrowTransform.setToRotation(Math.PI / 2, _leftArrowPoint.getX(), _leftArrowPoint.getY()); _arrowTransform.transform(_temp, _leftCardinalityPoint); _arrowTransform.setToRotation(-Math.PI / 2, _leftArrowPoint.getX(), _leftArrowPoint.getY()); _arrowTransform.transform(_temp, _leftFkPoint); // The right-side arrow head _temp.setLocation(_mainLine.getX1() + arrowx, _mainLine.getY1() + arrowy); _arrowTransform.setToRotation(Math.PI / 6, _rightArrowPoint.getX(), _rightArrowPoint.getY()); _arrowTransform.transform(_temp, _rightArrowPoint1); _rightArrowLine1.setLine( _rightArrowPoint.getX(), _rightArrowPoint.getY(), _rightArrowPoint1.getX(), _rightArrowPoint1.getY()); _arrowTransform.setToRotation(-Math.PI / 6, _rightArrowPoint.getX(), _rightArrowPoint.getY()); _arrowTransform.transform(_temp, _rightArrowPoint2); _rightArrowLine2.setLine( _rightArrowPoint.getX(), _rightArrowPoint.getY(), _rightArrowPoint2.getX(), _rightArrowPoint2.getY()); _arrowTransform.setToRotation(-Math.PI / 2, _rightArrowPoint.getX(), _rightArrowPoint.getY()); _arrowTransform.transform(_temp, _rightCardinalityPoint); _arrowTransform.setToRotation(Math.PI / 2, _rightArrowPoint.getX(), _rightArrowPoint.getY()); _arrowTransform.transform(_temp, _rightFkPoint); } }
public void line(float x1, float y1, float x2, float y2) { line.setLine(x1, y1, x2, y2); strokeShape(line); }