示例#1
0
  public void draw(Graphics2D g2, float x, float y) {
    AffineTransform transf = g2.getTransform();
    Stroke oldStroke = g2.getStroke();

    final double sx = transf.getScaleX();
    final double sy = transf.getScaleY();
    double s = 1;
    if (sx == sy) {
      // There are rounding problems due to scale factor: lines could have different
      // spacing...
      // So the increment (space+thickness) is done in using integer.
      s = sx;
      AffineTransform t = (AffineTransform) transf.clone();
      t.scale(1 / sx, 1 / sy);
      g2.setTransform(t);
    }

    g2.setStroke(
        new BasicStroke((float) (s * thickness), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
    float th = thickness / 2.f;
    final Line2D.Float line = new Line2D.Float();
    float xx = x + space;
    xx = (float) (xx * s + (space / 2.f) * s);
    final int inc = (int) Math.round((space + thickness) * s);

    for (int i = 0; i < N; i++) {
      line.setLine(xx + th * s, (y - height) * s, xx + th * s, y * s);
      g2.draw(line);
      xx += inc;
    }

    if (strike) {

      line.setLine(
          (x + space) * s, (y - height / 2.f) * s, xx - s * space / 2, (y - height / 2.f) * s);
      g2.draw(line);
    }

    g2.setTransform(transf);
    g2.setStroke(oldStroke);
  }
  /**
   * 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);
    }
  }
  /**
   * 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();
  }
示例#4
0
  @Override
  public void draw(GameState state, Graphics2D gr, Scene scene) {
    float radius = 200.0f;

    Vec2 upper = new Vec2(fov.x, fov.y);
    Vec2 lower = new Vec2(fov.x, -fov.y);

    Vec2 upperRotated = upper.rotate(direction);
    Vec2 lowerRotated = lower.rotate(direction);

    /*
    Vec2 towards = target.sub( origin );
    float ut = upperRotated.cross( towards );
    float lt = lowerRotated.cross( towards );

    boolean view = (ut <= 0 && lt >= 0 ) || (fov.x < 0.0f && ((ut >= 0 && lt >= 0) || (ut <= 0 && lt <= 0)));

    boolean circleInView = SteerMath.isCircleInView( origin, direction, fov, circlePos, circleRadius, circleEntirely );
    */

    gr.setColor(Color.orange);
    line.setLine(
        origin.x, origin.y, origin.x + upperRotated.x * radius, origin.y + upperRotated.y * radius);
    gr.draw(line);
    line.setLine(
        origin.x, origin.y, origin.x + lowerRotated.x * radius, origin.y + lowerRotated.y * radius);
    gr.draw(line);

    drawCircle(gr, upperRotated.mul(radius).addi(origin), 5, Color.orange);
    drawCircle(gr, direction.mul(radius).addi(origin), 5, Color.gray);
    drawCircle(gr, origin, 5, Color.white);
    drawCircle(gr, target, 5, Color.red);
    drawCircle(gr, circlePos, circleRadius, Color.yellow);

    /*
    gr.drawString( String.format( "fov: {%.2f,%.2f}", fov.x, fov.y ), 2, 12 );
    gr.drawString( String.format( "origin.distanceSq(target): %.2f", origin.distanceSq( target ) ), 2, 24 );
    gr.drawString( String.format( "direction.dot(towards): %.2f", direction.dot(towards) ), 2, 36 );
    gr.drawString( String.format( "in view: %s", view ), 2, 48 );
    gr.drawString( String.format( "upperRotated.cross( towards ): %.2f", upperRotated.cross( towards ) ), 2, 60 );
    gr.drawString( String.format( "lowerRotated.cross( towards ): %.2f", lowerRotated.cross( towards ) ), 2, 72 );
    gr.drawString( String.format( "isCircleInView(entirely=%s): %s", circleEntirely, circleInView ), 2, 84 );
    */

    Vec2 _V = circlePos.sub(origin);
    double _a = _V.dot(direction); // how far along the direction the sphere's center is
    double _b = _a * Math.tan(fovAngle); // radius of the cone at _a
    double _c =
        Math.sqrt(_V.lengthSq() - _a * _a); // distance from center of sphere to axis of the cone
    double _d = _c - _b; // distance from center of sphere to the surface of the cone
    double _e =
        _d
            * Math.cos(
                fovAngle); // shortest distance from center of the sphere to the surface of the cone

    boolean _inview = false;

    if (_e >= circleRadius) {
      // cull
    } else if (_e <= -circleRadius) {
      // totally
      _inview = true;
    } else {
      // partially
      if (!circleEntirely) {
        _inview = true;
      }
    }

    Vec2 farAlong =
        SteerMath.closest(origin, direction.mul(radius).addi(origin), circlePos, new Vec2());
    line.setLine(origin.x, origin.y, farAlong.x, farAlong.y);
    gr.draw(line);
    line.setLine(
        farAlong.x + direction.y * _a,
        farAlong.y - direction.x * _a,
        farAlong.x - direction.y * _a,
        farAlong.y + direction.x * _a);
    gr.draw(line);
    line.setLine(farAlong.x, farAlong.y, circlePos.x, circlePos.y);
    gr.setColor(Color.blue);
    gr.draw(line);

    int textY = 0;
    gr.setColor(Color.white);
    gr.drawString(
        String.format("how far along: %.2f (expected=%.2f)", _a, farAlong.distance(origin)),
        2,
        textY += 12);
    gr.drawString(String.format("radius of cone: %.2f", _b), 2, textY += 12);
    gr.drawString(
        String.format(
            "circle->axis of cone: %.2f (expected=%.2f)", _c, farAlong.distance(circlePos)),
        2,
        textY += 12);
    gr.drawString(String.format("circle->surface of cone: %.2f", _d), 2, textY += 12);
    gr.drawString(String.format("shortest distance: %.2f", _e), 2, textY += 12);
    gr.drawString(
        String.format("inview(entirely=%s): %s", circleEntirely, _inview), 2, textY += 12);
    gr.drawString(
        String.format(
            "fov: {%.2f,%.2f}: %.2f (%.2f)", fov.x, fov.y, fovAngle, Math.toDegrees(fovAngle)),
        2,
        textY += 12);
    gr.drawString(
        String.format(
            "isCircleInView: %s",
            SteerMath.isCircleInView(
                origin,
                direction,
                Math.tan(fovAngle),
                Math.cos(fovAngle),
                circlePos,
                circleRadius,
                circleEntirely)),
        2,
        textY += 12);
  }
示例#5
0
  public void drawLUT(Graphics2D g2, Rectangle bound, float midfontHeight) {
    ByteLut lut = (ByteLut) view2DPane.getActionValue(ActionW.LUT.cmd());
    if (lut != null && bound.height > 350) {

      if (lut.getLutTable() == null) {
        lut = ByteLut.grayLUT;
      }
      byte[][] table =
          (Boolean) view2DPane.getActionValue(ActionW.INVERSELUT.cmd())
              ? lut.getInvertedLutTable()
              : lut.getLutTable();
      float length = table[0].length;
      float x = bound.width - 30f;
      float y = bound.height / 2f - length / 2f;

      g2.setPaint(Color.black);
      Rectangle2D.Float rect = new Rectangle2D.Float(x - 11f, y - 2f, 12f, 2f);
      g2.draw(rect);
      int separation = 4;
      float step = length / separation;
      for (int i = 1; i < separation; i++) {
        float posY = y + i * step;
        rect.setRect(x - 6f, posY - 1f, 7f, 2f);
        g2.draw(rect);
      }
      rect.setRect(x - 11f, y + length, 12f, 2f);
      g2.draw(rect);
      rect.setRect(x - 2f, y - 2f, 23f, length + 4f);
      g2.draw(rect);

      g2.setPaint(Color.white);
      Line2D.Float line = new Line2D.Float(x - 10f, y - 1f, x - 1f, y - 1f);
      g2.draw(line);
      float stepWindow = (Float) view2DPane.getActionValue(ActionW.WINDOW.cmd()) / separation;
      float firstlevel = (Float) view2DPane.getActionValue(ActionW.LEVEL.cmd()) - stepWindow * 2f;
      String str = "" + (int) firstlevel; // $NON-NLS-1$
      GraphicLabel.paintFontOutline(
          g2, str, x - g2.getFontMetrics().stringWidth(str) - 12f, y + midfontHeight);
      for (int i = 1; i < separation; i++) {
        float posY = y + i * step;
        line.setLine(x - 5f, posY, x - 1f, posY);
        g2.draw(line);
        str = "" + (int) (firstlevel + i * stepWindow); // $NON-NLS-1$
        GraphicLabel.paintFontOutline(
            g2, str, x - g2.getFontMetrics().stringWidth(str) - 7, posY + midfontHeight);
      }

      line.setLine(x - 10f, y + length + 1f, x - 1f, y + length + 1f);
      g2.draw(line);
      str = "" + (int) (firstlevel + 4 * stepWindow); // $NON-NLS-1$
      GraphicLabel.paintFontOutline(
          g2, str, x - g2.getFontMetrics().stringWidth(str) - 12, y + length + midfontHeight);
      rect.setRect(x - 1f, y - 1f, 21f, length + 2f);
      g2.draw(rect);

      for (int k = 0; k < length; k++) {
        g2.setPaint(new Color(table[0][k] & 0xff, table[1][k] & 0xff, table[2][k] & 0xff));
        rect.setRect(x, y + k, 19f, 1f);
        g2.draw(rect);
      }
    }
  }
 public void line(float x1, float y1, float x2, float y2) {
   line.setLine(x1, y1, x2, y2);
   strokeShape(line);
 }