예제 #1
0
파일: AirportModel.java 프로젝트: bily/fsxp
 public void addStationToParking(TaxiwayParkingModel model) {
   Rectangle2D square = ((java.awt.geom.Ellipse2D.Float) model.getParkingCircle()).getBounds2D();
   SceneryModel sceneryModel = new SceneryModel();
   sceneryModel.setShouldNotify(false);
   sceneryModel.setName("{0da416ee-c523-4d81-a562-9ce503f28468}");
   sceneryModel.setHeading(model.getHeading());
   java.awt.geom.Point2D.Float point =
       new java.awt.geom.Point2D.Float(
           (float) (square.getX() + square.getWidth() / 2D),
           (float) (square.getY() + square.getHeight() / 2D));
   java.awt.geom.Point2D.Float sceneryPoint =
       Utilities.rotatePoint(
           point,
           new java.awt.geom.Point2D.Float(
               (float) (square.getX() + square.getWidth() / 2D),
               (float) (square.getY() - 27.5D * (double) scale)),
           model.getHeading());
   sceneryModel.setLatLon(
       Utilities.getLatLonForPixel(
           model.getCenterPoint().getLat(),
           model.getCenterPoint().getLon(),
           sceneryPoint.getX(),
           sceneryPoint.getY(),
           scale));
   sceneryModel.setShouldNotify(true);
   addSceneryModel(sceneryModel);
 }
예제 #2
0
  public void paintComponent(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    String message = "Hello, World!";

    Font f = new Font("Serif", Font.BOLD, 36);
    g2.setFont(f);

    FontRenderContext context = g2.getFontRenderContext();
    Rectangle2D bounds = f.getStringBounds(message, context);

    double x = (getWidth() - bounds.getWidth()) / 2;
    double y = (getHeight() - bounds.getHeight()) / 2;

    double ascent = -bounds.getY();
    double baseY = y + ascent;

    g2.drawString(message, (int) x, (int) baseY);

    g2.setPaint(Color.LIGHT_GRAY);

    g2.draw(new Line2D.Double(x, baseY, x + bounds.getWidth(), baseY));
    Rectangle2D rect = new Rectangle2D.Double(x, y, bounds.getWidth(), bounds.getHeight());
    g2.draw(rect);
  }
예제 #3
0
  /**
   * Draws the background to the specified graphics device. If the dial frame specifies a window,
   * the clipping region will already have been set to this window before this method is called.
   *
   * @param g2 the graphics device (<code>null</code> not permitted).
   * @param plot the plot (ignored here).
   * @param frame the dial frame (ignored here).
   * @param view the view rectangle (<code>null</code> not permitted).
   */
  @Override
  public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) {

    // work out the anchor point
    Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius, this.radius);
    Arc2D arc = new Arc2D.Double(f, this.angle, 0.0, Arc2D.OPEN);
    Point2D pt = arc.getStartPoint();

    // the indicator bounds is calculated from the templateValue (which
    // determines the minimum size), the maxTemplateValue (which, if
    // specified, provides a maximum size) and the actual value
    FontMetrics fm = g2.getFontMetrics(this.font);
    double value = plot.getValue(this.datasetIndex);
    String valueStr = this.formatter.format(value);
    Rectangle2D valueBounds = TextUtilities.getTextBounds(valueStr, g2, fm);

    // calculate the bounds of the template value
    String s = this.formatter.format(this.templateValue);
    Rectangle2D tb = TextUtilities.getTextBounds(s, g2, fm);
    double minW = tb.getWidth();
    double minH = tb.getHeight();

    double maxW = Double.MAX_VALUE;
    double maxH = Double.MAX_VALUE;
    if (this.maxTemplateValue != null) {
      s = this.formatter.format(this.maxTemplateValue);
      tb = TextUtilities.getTextBounds(s, g2, fm);
      maxW = Math.max(tb.getWidth(), minW);
      maxH = Math.max(tb.getHeight(), minH);
    }
    double w = fixToRange(valueBounds.getWidth(), minW, maxW);
    double h = fixToRange(valueBounds.getHeight(), minH, maxH);

    // align this rectangle to the frameAnchor
    Rectangle2D bounds =
        RectangleAnchor.createRectangle(new Size2D(w, h), pt.getX(), pt.getY(), this.frameAnchor);

    // add the insets
    Rectangle2D fb = this.insets.createOutsetRectangle(bounds);

    // draw the background
    g2.setPaint(this.backgroundPaint);
    g2.fill(fb);

    // draw the border
    g2.setStroke(this.outlineStroke);
    g2.setPaint(this.outlinePaint);
    g2.draw(fb);

    // now find the text anchor point
    Shape savedClip = g2.getClip();
    g2.clip(fb);

    Point2D pt2 = RectangleAnchor.coordinates(bounds, this.valueAnchor);
    g2.setPaint(this.paint);
    g2.setFont(this.font);
    TextUtilities.drawAlignedString(
        valueStr, g2, (float) pt2.getX(), (float) pt2.getY(), this.textAnchor);
    g2.setClip(savedClip);
  }
  // TODO misleading name - is centered around point and scaled font but not scale center point
  // (probably :)
  public void drawAntialiasedTextCenteredNoScale(
      Graphics2D g2,
      String text,
      int fontSize,
      Position pos,
      ImmutablePoint center,
      Color fgColor,
      Color bgColor) {
    Color original = g2.getColor();
    FontRenderContext frc = g2.getFontRenderContext();
    TextLayout tl = new TextLayout(text, getFont(fontSize), frc);
    Rectangle2D bounds = tl.getBounds();

    center = center.translate((int) (bounds.getWidth() / -2), (int) (bounds.getHeight() / -2));

    if (bgColor != null) {
      g2.setColor(bgColor);
      g2.fillRect(
          getOffsetX(pos) + center.getX() - 6,
          getOffsetY(pos) + center.getY() - 5,
          12 + (int) bounds.getWidth(),
          10 + (int) bounds.getHeight());
    }

    g2.setColor(fgColor);
    tl.draw(
        g2,
        getOffsetX(pos) + center.getX(),
        getOffsetY(pos) + center.getY() + (int) bounds.getHeight());
    g2.setColor(original);
  }
예제 #5
0
  /** {@inheritDoc} */
  public boolean setBounds(
      final double x, final double y, final double width, final double height) {
    if (lineShape == null || !super.setBounds(x, y, width, height)) {
      return false;
    }

    final Rectangle2D lineBounds = lineShape.getBounds2D();
    final Rectangle2D lineStrokeBounds = getLineBoundsWithStroke();
    final double strokeOutset =
        Math.max(
            lineStrokeBounds.getWidth() - lineBounds.getWidth(),
            lineStrokeBounds.getHeight() - lineBounds.getHeight());

    double adjustedX = x + strokeOutset / 2;
    double adjustedY = y + strokeOutset / 2;
    double adjustedWidth = width - strokeOutset;
    double adjustedHeight = height - strokeOutset;

    TEMP_TRANSFORM.setToIdentity();
    TEMP_TRANSFORM.translate(adjustedX, adjustedY);
    TEMP_TRANSFORM.scale(
        adjustedWidth / lineBounds.getWidth(), adjustedHeight / lineBounds.getHeight());
    TEMP_TRANSFORM.translate(-lineBounds.getX(), -lineBounds.getY());
    lineShape.transformPoints(TEMP_TRANSFORM);

    return true;
  }
    public void drawTextEdge(ModelImpl objectModel) {
      Renderable renderable = objectModel.getObj();
      TextDataImpl textData = (TextDataImpl) renderable.getTextData();
      if (textData != null) {
        model.colorMode.textColor(this, textData, objectModel);
        model.sizeMode.setSizeFactor2d(model.edgeSizeFactor, textData, objectModel);
        if (edgeRefresh) {
          builder.buildEdgeText((EdgeData) renderable, textData, model, currentTimeInterval);
        }
        if (textData.getSizeFactor() * renderer.getCharWidth('a') < PIXEL_LIMIT) {
          return;
        }
        String txt = textData.getLine().getText();
        Rectangle2D r = renderer.getBounds(txt);
        float posX =
            renderable.getModel().getViewportX()
                + (float) r.getWidth() / -2 * textData.getSizeFactor();
        float posY =
            renderable.getModel().getViewportY()
                + (float) r.getHeight() / -2 * textData.getSizeFactor();
        r.setRect(
            0,
            0,
            r.getWidth() / drawable.getDraggingMarkerX(),
            r.getHeight() / drawable.getDraggingMarkerY());
        textData.getLine().setBounds(r);

        renderer.draw3D(txt, posX, posY, 0, textData.getSizeFactor());
      }
    }
예제 #7
0
  /**
   * Method draws component`s content.
   *
   * @param g - Graphics instance to use for draw.
   */
  public void paintComponent(Graphics g) {
    // prepare double buffer
    Graphics bufg = prepareForPaint();

    // preparing variables
    String level = this.getSettings().getLevel().toString();

    // fill rectangle with scores
    Graphics2D g2 = (Graphics2D) bufg;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    bufg.setColor(Color.yellow);
    bufg.setFont(this.getSettings().getFont());
    FontMetrics fm = bufg.getFontMetrics();
    Rectangle2D area = fm.getStringBounds(level, bufg);
    bufg.drawString(
        level,
        (int) (getWidth() - area.getWidth()) / 2,
        (int) (getHeight() + area.getHeight()) / 5 * 3);
    area = fm.getStringBounds(getSettings().getString("LEVEL"), bufg);
    bufg.drawString(
        getSettings().getString("LEVEL"),
        (int) (getWidth() - area.getWidth()) / 2,
        (int) (getHeight() + area.getHeight()) / 5 * 2);

    // draw it at right upper corner
    g.drawImage(this.getBuf(), 0, 0, this);
  }
예제 #8
0
  /**
   * returns the skew transform
   *
   * @param svgHandle a svg handle
   * @param bounds the bounds of the area to transform
   * @param firstPoint the first clicked point by the user
   * @param currentPoint the current point of the drag action by the user
   * @param item the selection item
   * @return the skew transform
   */
  protected AffineTransform getSkewTransform(
      SVGHandle svgHandle,
      Rectangle2D bounds,
      Point2D firstPoint,
      Point2D currentPoint,
      SelectionItem item) {

    // getting the skew factor
    double skewX = 0, skewY = 0;
    boolean isHorizontal =
        (item.getType() == SelectionItem.NORTH || item.getType() == SelectionItem.SOUTH);

    if (bounds.getWidth() > 0 && bounds.getHeight() > 0) {

      if (isHorizontal) {

        skewX = (currentPoint.getX() - firstPoint.getX()) / bounds.getHeight();

      } else {

        skewY = (currentPoint.getY() - firstPoint.getY()) / bounds.getWidth();
      }
    }

    // getting the center point
    Point2D centerPoint = getRotationSkewCenterPoint(svgHandle, bounds);

    // creating the affine transform
    AffineTransform af =
        AffineTransform.getTranslateInstance(-centerPoint.getX(), -centerPoint.getY());
    af.preConcatenate(AffineTransform.getShearInstance(skewX, skewY));
    af.preConcatenate(AffineTransform.getTranslateInstance(centerPoint.getX(), centerPoint.getY()));

    return af;
  }
 /**
  * Draws the waferedge, including the notch.
  *
  * @param g2 the graphics device.
  * @param plotArea the plot area.
  */
 protected void drawWaferEdge(Graphics2D g2, Rectangle2D plotArea) {
   // draw the wafer
   Ellipse2D waferEdge = getWaferEdge(plotArea);
   g2.setColor(Color.black);
   g2.draw(waferEdge);
   // calculate and draw the notch
   // horizontal orientation is considered notch right
   // vertical orientation is considered notch down
   Arc2D notch;
   Rectangle2D waferFrame = waferEdge.getFrame();
   double notchDiameter = waferFrame.getWidth() * 0.04;
   if (this.orientation == PlotOrientation.HORIZONTAL) {
     Rectangle2D notchFrame =
         new Rectangle2D.Double(
             waferFrame.getX() + waferFrame.getWidth() - (notchDiameter / 2),
             waferFrame.getY() + (waferFrame.getHeight() / 2) - (notchDiameter / 2),
             notchDiameter,
             notchDiameter);
     notch = new Arc2D.Double(notchFrame, 90d, 180d, Arc2D.OPEN);
   } else {
     Rectangle2D notchFrame =
         new Rectangle2D.Double(
             waferFrame.getX() + (waferFrame.getWidth() / 2) - (notchDiameter / 2),
             waferFrame.getY() + waferFrame.getHeight() - (notchDiameter / 2),
             notchDiameter,
             notchDiameter);
     notch = new Arc2D.Double(notchFrame, 0d, 180d, Arc2D.OPEN);
   }
   g2.setColor(Color.white);
   g2.fill(notch);
   g2.setColor(Color.black);
   g2.draw(notch);
 }
예제 #10
0
 protected void invalidate() {
   // Retrieve current bounds and set local vars
   Rectangle2D tmp = graph.getCellBounds(vertex.getCell());
   if (tmp != null) {
     tmp = (Rectangle2D) tmp.clone();
     graph.toScreen(tmp);
     int handlesize = graph.getHandleSize();
     int s2 = 2 * handlesize;
     double left = tmp.getX() - handlesize;
     double top = tmp.getY() - handlesize;
     double w2 = tmp.getX() + (tmp.getWidth() / 2) - handlesize;
     double h2 = tmp.getY() + (tmp.getHeight() / 2) - handlesize;
     double right = tmp.getX() + tmp.getWidth() - handlesize;
     double bottom = tmp.getY() + tmp.getHeight() - handlesize;
     // Update control point positions
     r[0].setFrame(left, top, s2, s2);
     r[1].setFrame(w2, top, s2, s2);
     r[2].setFrame(right, top, s2, s2);
     r[3].setFrame(left, h2, s2, s2);
     r[4].setFrame(right, h2, s2, s2);
     r[5].setFrame(left, bottom, s2, s2);
     r[6].setFrame(w2, bottom, s2, s2);
     r[7].setFrame(right, bottom, s2, s2);
   }
 }
예제 #11
0
  @Override
  public void mouseDragged(MouseEvent e) {
    Canvas c = context.getTabbedPaneController().getCurrentTabContent();
    SelectionModel selectionModel = c.getSelectionModel();
    if (!selectionModel.prepareForMove()) {
      moved = false;
      return;
    }
    Point thisCoord = e.getPoint();
    int dx = thisCoord.x - previousPosition.x;
    int dy = thisCoord.y - previousPosition.y;
    if (selectionRec == null) {
      selectionRec = selectionModel.getSelectionBounds();
    }
    selectionRec.setRect(
        selectionRec.getX() + dx,
        selectionRec.getY() + dy,
        selectionRec.getWidth(),
        selectionRec.getHeight());
    c.setSelectionRectangleBounds(
        selectionRec.getX(),
        selectionRec.getY(),
        selectionRec.getWidth(),
        selectionRec.getHeight());

    c.setShowSelectionRectangle(true);

    c.repaint();
    previousPosition = (Point) thisCoord.clone();
    moved = true;
  }
예제 #12
0
  public void drawStuff(Graphics2D g2) {

    g2.setColor(Color.BLACK);
    g2.fillRect(0, 0, 650, 450);
    g2.setColor(Color.BLACK);
    g2.drawRect(0, 0, 650, 450);

    for (int i = 0; i < blocks.size(); i++) {

      if (blocks.get(i).isOnMagnet()) continue;
      Shape curShape = blocks.get(i).getFrame();
      Rectangle2D boundingBox = (Rectangle2D) curShape;

      g2.setColor(Color.WHITE);
      g2.fillRect(
          (int) boundingBox.getX(), (int) boundingBox.getY(),
          (int) boundingBox.getWidth(), (int) boundingBox.getHeight());

      g2.setColor(Color.BLUE);
      g2.drawRect(
          (int) boundingBox.getX(), (int) boundingBox.getY(),
          (int) boundingBox.getWidth(), (int) boundingBox.getHeight());
    }

    g2.setColor(Color.GRAY);
    g2.fillRect(0, 380, 650, 70);
    g2.setColor(Color.BLACK);
    g2.drawRect(0, 380, 650, 70);
  }
예제 #13
0
  protected void drawToolTip(
      DrawContext dc,
      java.awt.Rectangle viewport,
      String text,
      int x,
      int y,
      ToolTipAttributes attributes) {
    java.awt.geom.Rectangle2D textBounds = this.computeTextBounds(dc, text, attributes.getFont());
    java.awt.geom.Rectangle2D bgBounds =
        this.computeBackgroundBounds(
            dc, textBounds.getWidth(), textBounds.getHeight(), attributes.getInsets());

    java.awt.Point screenPoint = this.adjustDrawPointToViewport(x, y, bgBounds, viewport);
    java.awt.geom.Point2D textTranslation =
        this.computeTextTranslation(dc, textBounds, attributes.getInsets());

    GL2 gl = dc.getGL();
    OGLStackHandler stackHandler = new OGLStackHandler();

    stackHandler.pushModelview(gl);
    try {
      gl.glTranslated(
          screenPoint.getX() + bgBounds.getX(), screenPoint.getY() + bgBounds.getY(), 0);
      this.drawToolTipInterior(dc, bgBounds.getWidth(), bgBounds.getHeight(), attributes);
      this.drawToolTipOutline(dc, bgBounds.getWidth(), bgBounds.getHeight(), attributes);

      gl.glTranslated(textTranslation.getX(), textTranslation.getY(), 0);
      this.drawToolTipText(dc, text, 0, 0, attributes);
    } finally {
      stackHandler.pop(gl);
    }
  }
예제 #14
0
 /**
  * Get the bounding box of the shape when stroked. This method takes account of the thickness of
  * the stroke.
  */
 public Rectangle2D getBounds() {
   // FIXME: these bounds REALLY need to be cached.  But it's
   // painful because of the public members.
   if (stroke == null) {
     return shape.getBounds2D();
   } else if (stroke instanceof BasicStroke) {
     // For some reason (antialiasing?) the bounds returned by
     // BasicStroke is off by one.  This code works around it.
     // if all we want is the bounds, then we don't need to actually
     // stroke the shape.  We've had reports that this is no longer
     // necessary with JDK1.3.
     Rectangle2D rect = shape.getBounds2D();
     int width = (int) ((BasicStroke) stroke).getLineWidth() + 2;
     return new Rectangle2D.Double(
         rect.getX() - width,
         rect.getY() - width,
         rect.getWidth() + width + width,
         rect.getHeight() + width + width);
   } else {
     // For some reason (antialiasing?) the bounds returned by
     // BasicStroke is off by one.  This code works around it.
     // We've had reports that this is no longer
     // necessary with JDK1.3.
     Rectangle2D rect = stroke.createStrokedShape(shape).getBounds2D();
     return new Rectangle2D.Double(
         rect.getX() - 1, rect.getY() - 1, rect.getWidth() + 2, rect.getHeight() + 2);
   }
 }
예제 #15
0
  /**
   * Created an entity for the axis.
   *
   * @param cursor the initial cursor value.
   * @param state the axis state after completion of the drawing with a possibly updated cursor
   *     position.
   * @param dataArea the data area.
   * @param edge the edge.
   * @param plotState the PlotRenderingInfo from which a reference to the entity collection can be
   *     obtained.
   * @since 1.0.13
   */
  protected void createAndAddEntity(
      double cursor,
      AxisState state,
      Rectangle2D dataArea,
      RectangleEdge edge,
      PlotRenderingInfo plotState) {

    if (plotState == null || plotState.getOwner() == null) {
      return; // no need to create entity if we can´t save it anyways...
    }
    Rectangle2D hotspot = null;
    if (edge.equals(RectangleEdge.TOP)) {
      hotspot =
          new Rectangle2D.Double(
              dataArea.getX(), state.getCursor(), dataArea.getWidth(), cursor - state.getCursor());
    } else if (edge.equals(RectangleEdge.BOTTOM)) {
      hotspot =
          new Rectangle2D.Double(
              dataArea.getX(), cursor, dataArea.getWidth(), state.getCursor() - cursor);
    } else if (edge.equals(RectangleEdge.LEFT)) {
      hotspot =
          new Rectangle2D.Double(
              state.getCursor(), dataArea.getY(), cursor - state.getCursor(), dataArea.getHeight());
    } else if (edge.equals(RectangleEdge.RIGHT)) {
      hotspot =
          new Rectangle2D.Double(
              cursor, dataArea.getY(), state.getCursor() - cursor, dataArea.getHeight());
    }
    EntityCollection e = plotState.getOwner().getEntityCollection();
    if (e != null) {
      e.add(new AxisEntity(hotspot, this));
    }
  }
예제 #16
0
  private void downloadSample(File file, Rectangle2D bbox) throws IOException {
    final double max = 0.25;
    int xMul = (int) Math.ceil(bbox.getWidth() / max);
    int yMul = (int) Math.ceil(bbox.getHeight() / max);
    for (int x = 0; x < xMul; x++) {
      for (int y = 0; y < yMul; y++) {
        File f = new File(file.getAbsolutePath() + ".part" + x + y);

        double xPos = bbox.getX() + x * max;
        double yPos = bbox.getY() + y * max;
        String b = "" + xPos;
        b += "," + yPos;
        b += "," + (xPos + Math.min(max, bbox.getWidth() - max * x));
        b += "," + (yPos + Math.min(max, bbox.getHeight() - max * y));

        URL downloadUrl = new URL("http://api.openstreetmap.org/api/0.6/map?bbox=" + b);

        byte[] buffer = new byte[4096];
        try (InputStream in = downloadUrl.openStream();
            OutputStream out = new FileOutputStream(f); ) {
          int len = 0;
          do {
            out.write(buffer, 0, len);
            len = in.read(buffer);
          } while (len > 0);
        }
      }
    }
  }
예제 #17
0
  /**
   * Reserve some space on each axis side because we draw a centered label at each extremity.
   *
   * @param g2 the graphics device.
   * @param plot the plot.
   * @param plotArea the plot area.
   * @param edge the edge.
   * @param space the space already reserved.
   * @return The reserved space.
   */
  public AxisSpace reserveSpace(
      Graphics2D g2, Plot plot, Rectangle2D plotArea, RectangleEdge edge, AxisSpace space) {

    this.internalMarkerCycleBoundTick = null;
    AxisSpace ret = super.reserveSpace(g2, plot, plotArea, edge, space);
    if (this.internalMarkerCycleBoundTick == null) {
      return ret;
    }

    FontMetrics fm = g2.getFontMetrics(getTickLabelFont());
    Rectangle2D r =
        TextUtilities.getTextBounds(this.internalMarkerCycleBoundTick.getText(), g2, fm);

    if (RectangleEdge.isTopOrBottom(edge)) {
      if (isVerticalTickLabels()) {
        space.add(r.getHeight() / 2, RectangleEdge.RIGHT);
      } else {
        space.add(r.getWidth() / 2, RectangleEdge.RIGHT);
      }
    } else if (RectangleEdge.isLeftOrRight(edge)) {
      if (isVerticalTickLabels()) {
        space.add(r.getWidth() / 2, RectangleEdge.TOP);
      } else {
        space.add(r.getHeight() / 2, RectangleEdge.TOP);
      }
    }

    return ret;
  }
예제 #18
0
  /**
   * Draws the needle.
   *
   * @param g2 the graphics device.
   * @param plotArea the plot area.
   * @param rotate the rotation point.
   * @param angle the angle.
   */
  @Override
  protected void drawNeedle(Graphics2D g2, Rectangle2D plotArea, Point2D rotate, double angle) {

    Area shape;
    GeneralPath pointer = new GeneralPath();

    int minY = (int) (plotArea.getMinY());
    // int maxX = (int) (plotArea.getMaxX());
    int maxY = (int) (plotArea.getMaxY());
    int midX = (int) (plotArea.getMinX() + (plotArea.getWidth() / 2));
    // int midY = (int) (plotArea.getMinY() + (plotArea.getHeight() / 2));
    int lenX = (int) (plotArea.getWidth() / 10);
    if (lenX < 2) {
      lenX = 2;
    }

    pointer.moveTo(midX - lenX, maxY - lenX);
    pointer.lineTo(midX + lenX, maxY - lenX);
    pointer.lineTo(midX, minY + lenX);
    pointer.closePath();

    lenX = 4 * lenX;
    Ellipse2D circle = new Ellipse2D.Double(midX - lenX / 2, plotArea.getMaxY() - lenX, lenX, lenX);

    shape = new Area(circle);
    shape.add(new Area(pointer));
    if ((rotate != null) && (angle != 0)) {
      /// we have rotation
      getTransform().setToRotation(angle, rotate.getX(), rotate.getY());
      shape.transform(getTransform());
    }

    defaultDisplay(g2, shape);
  }
예제 #19
0
 private Rectangle2D getLabelBB() {
   Rectangle2D bb = getContentsBoundingBox();
   return new Rectangle2D.Double(
       bb.getMaxX() - labelBB.getWidth(),
       bb.getMinY() - labelBB.getHeight(),
       labelBB.getWidth(),
       labelBB.getHeight());
 }
예제 #20
0
파일: AirportModel.java 프로젝트: bily/fsxp
  public void addTriggerToParking(TaxiwayParkingModel model) {
    Rectangle2D square = ((java.awt.geom.Ellipse2D.Float) model.getParkingCircle()).getBounds2D();
    square.setFrame(
        square.getX() - (double) (20F * scale),
        square.getY() - (double) (20F * scale),
        square.getWidth() + (double) (40F * scale),
        square.getHeight() + (double) (40F * scale));
    TriggerModel triggerModel = new TriggerModel();
    triggerModel.setShouldNotify(false);
    triggerModel.setType73("YES");
    triggerModel.setTypeJet("YES");
    triggerModel.setShouldNotify(true);
    java.awt.geom.Point2D.Float point =
        new java.awt.geom.Point2D.Float(
            (float) (square.getX() + square.getWidth() / 2D),
            (float) (square.getY() + square.getHeight() / 2D));
    java.awt.geom.Point2D.Float vertexPoints[] = new java.awt.geom.Point2D.Float[4];
    vertexPoints[0] =
        Utilities.rotatePoint(
            point,
            new java.awt.geom.Point2D.Float((float) square.getX(), (float) square.getY()),
            model.getHeading());
    vertexPoints[1] =
        Utilities.rotatePoint(
            point,
            new java.awt.geom.Point2D.Float(
                (float) square.getX(), (float) (square.getY() + square.getHeight())),
            model.getHeading());
    vertexPoints[2] =
        Utilities.rotatePoint(
            point,
            new java.awt.geom.Point2D.Float(
                (float) (square.getX() + square.getWidth()),
                (float) (square.getY() + square.getHeight())),
            model.getHeading());
    vertexPoints[3] =
        Utilities.rotatePoint(
            point,
            new java.awt.geom.Point2D.Float(
                (float) (square.getX() + square.getWidth()), (float) square.getY()),
            model.getHeading());
    for (int i = 0; i < 4; i++) {
      VertexModel vertexModel = new VertexModel();
      vertexModel.setShouldNotify(false);
      vertexModel.setLatLon(
          Utilities.getLatLonForPixel(
              model.getCenterPoint().getLat(),
              model.getCenterPoint().getLon(),
              vertexPoints[i].getX(),
              vertexPoints[i].getY(),
              scale));
      vertexModel.setShouldNotify(true);
      triggerModel.addVertexModel(vertexModel);
    }

    addTriggerModel(triggerModel);
  }
예제 #21
0
 public Rectangle2D evaluate(Rectangle2D v0, Rectangle2D v1, float fraction) {
   double x = v0.getX() + ((v1.getX() - v0.getX()) * fraction);
   double y = v0.getY() + ((v1.getY() - v0.getY()) * fraction);
   double w = v0.getWidth() + ((v1.getWidth() - v0.getWidth()) * fraction);
   double h = v0.getHeight() + ((v1.getHeight() - v0.getHeight()) * fraction);
   Rectangle2D value = (Rectangle2D) v0.clone();
   value.setRect(x, y, w, h);
   return value;
 }
예제 #22
0
  /**
   * Calculates the axis space required.
   *
   * @param g2 the graphics device.
   * @param plotArea the plot area.
   * @return The space.
   */
  protected AxisSpace calculateAxisSpace(Graphics2D g2, Rectangle2D plotArea) {

    AxisSpace space = new AxisSpace();
    PlotOrientation orientation = getOrientation();

    // work out the space required by the domain axis...
    AxisSpace fixed = getFixedDomainAxisSpace();
    if (fixed != null) {
      if (orientation == PlotOrientation.HORIZONTAL) {
        space.setLeft(fixed.getLeft());
        space.setRight(fixed.getRight());
      } else if (orientation == PlotOrientation.VERTICAL) {
        space.setTop(fixed.getTop());
        space.setBottom(fixed.getBottom());
      }
    } else {
      ValueAxis xAxis = getDomainAxis();
      RectangleEdge xEdge = Plot.resolveDomainAxisLocation(getDomainAxisLocation(), orientation);
      if (xAxis != null) {
        space = xAxis.reserveSpace(g2, this, plotArea, xEdge, space);
      }
    }

    Rectangle2D adjustedPlotArea = space.shrink(plotArea, null);

    // work out the maximum height or width of the non-shared axes...
    int n = this.subplots.size();
    this.subplotAreas = new Rectangle2D[n];
    double x = adjustedPlotArea.getX();
    double y = adjustedPlotArea.getY();
    double usableSize = 0.0;
    if (orientation == PlotOrientation.HORIZONTAL) {
      usableSize = adjustedPlotArea.getWidth() - this.gap * (n - 1);
    } else if (orientation == PlotOrientation.VERTICAL) {
      usableSize = adjustedPlotArea.getHeight() - this.gap * (n - 1);
    }

    for (int i = 0; i < n; i++) {
      XYPlot plot = (XYPlot) this.subplots.get(i);

      // calculate sub-plot area
      if (orientation == PlotOrientation.HORIZONTAL) {
        double w = usableSize * plot.getWeight() / this.totalWeight;
        this.subplotAreas[i] = new Rectangle2D.Double(x, y, w, adjustedPlotArea.getHeight());
        x = x + w + this.gap;
      } else if (orientation == PlotOrientation.VERTICAL) {
        double h = usableSize * plot.getWeight() / this.totalWeight;
        this.subplotAreas[i] = new Rectangle2D.Double(x, y, adjustedPlotArea.getWidth(), h);
        y = y + h + this.gap;
      }

      AxisSpace subSpace = plot.calculateRangeAxisSpace(g2, this.subplotAreas[i], null);
      space.ensureAtLeast(subSpace);
    }

    return space;
  }
예제 #23
0
  /*
   * (non-Javadoc)
   *
   * @see br.arca.morcego.Component#paint(java.awt.Graphics)
   */
  public void paint(Graphics g) {
    // TODO: paint a fancy textbox with description of node

    Graphics2D graphic = (Graphics2D) g;

    TextArea textArea = new TextArea(text);

    textArea.setLocation(0, 0);
    textArea.setVisible(true);

    Font font = new Font(null, Font.PLAIN, 10);

    FontRenderContext frc = new FontRenderContext(null, false, false);

    TextLayout l = new TextLayout(text, font, frc);

    Rectangle2D textBounds = l.getBounds();

    int margin = Config.getInteger(Config.descriptionMargin);
    int border = 1;
    int distX = 5;
    int distY = 5;

    int width = (int) textBounds.getWidth() + 2 * margin + 2 * border;
    int height = (int) textBounds.getHeight() + 2 * margin + 2 * border;

    int cornerX = originX - width - distX;
    int cornerY = originY - height - distY;

    if (cornerX < 0) {
      cornerX = 0;
    }
    if (cornerY < 0) {
      cornerY = 0;
    }

    graphic.setColor(Config.getColor(Config.descriptionBorder));
    graphic.fillRect(
        cornerX - margin - border,
        cornerY - margin - border,
        (int) textBounds.getWidth() + 2 * margin + 2 * border,
        (int) textBounds.getHeight() + 2 * margin + 2 * border);

    graphic.setColor(Config.getColor(Config.descriptionBackground));

    graphic.fillRect(
        cornerX - margin,
        cornerY - margin,
        (int) textBounds.getWidth() + 2 * margin,
        (int) textBounds.getHeight() + 2 * margin);

    graphic.setColor(Config.getColor(Config.descriptionColor));
    textArea.paint(g);

    l.draw(graphic, cornerX, cornerY + (int) textBounds.getHeight());
  }
 public void layout(IAtomContainer atomContainer, Rectangle2D canvas) {
   atomLayout(atomContainer);
   double canvasWidth = canvas.getWidth();
   double canvasHeight = canvas.getHeight();
   Rectangle2D molBounds = GeometryTools.getRectangle2D(atomContainer);
   double molWidth = molBounds.getWidth();
   double molHeight = molBounds.getHeight();
   double scaleFactor = Math.min(canvasWidth / molWidth, canvasHeight / molHeight);
   Point2d center = new Point2d(canvas.getCenterX(), canvas.getCenterY());
   scaleAndCenter(atomContainer, scaleFactor, center);
 }
예제 #25
0
 /**
  * @param g2
  * @param string
  */
 protected void drawText(Graphics2D g2, String text) {
   g2.setColor(getActiveColor());
   g2.setFont(new Font("Arial", Font.BOLD, 10));
   String tt = text;
   Rectangle2D sB1 = g2.getFontMetrics().getStringBounds(tt, g2);
   double sw0 = 10.0 / sB1.getWidth();
   double sh0 = 10.0 / sB1.getHeight();
   g2.translate(5, 5);
   g2.scale(sw0, sh0);
   g2.drawString(text, (int) (-sB1.getWidth() / 2.0), (int) (sB1.getHeight() / 2.0));
 }
  /**
   * Creates a temporary list of ticks that can be used when drawing the axis.
   *
   * @param g2 the graphics device (used to get font measurements).
   * @param state the axis state.
   * @param dataArea the area inside the axes.
   * @param edge the location of the axis.
   * @return A list of ticks.
   */
  @Override
  public List<CategoryTick> refreshTicks(
      Graphics2D g2, AxisState state, Rectangle2D dataArea, RectangleEdge edge) {

    List<CategoryTick> ticks = new java.util.ArrayList<CategoryTick>();

    // sanity check for data area...
    if (dataArea.getHeight() <= 0.0 || dataArea.getWidth() < 0.0) {
      return ticks;
    }

    CategoryPlot plot = (CategoryPlot) getPlot();
    List<Comparable> categories = plot.getCategoriesForAxis(this);
    double max = 0.0;

    if (categories != null) {
      CategoryLabelPosition position = this.categoryLabelPositions.getLabelPosition(edge);
      float r = this.maximumCategoryLabelWidthRatio;
      if (r <= 0.0) {
        r = position.getWidthRatio();
      }

      float l;
      if (position.getWidthType() == CategoryLabelWidthType.CATEGORY) {
        l = (float) calculateCategorySize(categories.size(), dataArea, edge);
      } else {
        if (RectangleEdge.isLeftOrRight(edge)) {
          l = (float) dataArea.getWidth();
        } else {
          l = (float) dataArea.getHeight();
        }
      }
      int categoryIndex = 0;
      for (Comparable category : categories) {
        g2.setFont(getTickLabelFont(category));
        TextBlock label = createLabel(category, l * r, edge, g2);
        if (edge == RectangleEdge.TOP || edge == RectangleEdge.BOTTOM) {
          max = Math.max(max, calculateTextBlockHeight(label, position, g2));
        } else if (edge == RectangleEdge.LEFT || edge == RectangleEdge.RIGHT) {
          max = Math.max(max, calculateTextBlockWidth(label, position, g2));
        }
        ticks.add(
            new CategoryTick(
                category,
                label,
                position.getLabelAnchor(),
                position.getRotationAnchor(),
                position.getAngle()));
        categoryIndex = categoryIndex + 1;
      }
    }
    state.setMax(max);
    return ticks;
  }
  public VoronoiCore(Rectangle2D rectangle) {
    PolygonSimple poly = new PolygonSimple(4);
    poly.add(rectangle.getMinX(), rectangle.getMinY());
    poly.add(rectangle.getMinX() + rectangle.getWidth(), rectangle.getMinY());
    poly.add(
        rectangle.getMinX() + rectangle.getWidth(), rectangle.getMinY() + rectangle.getHeight());
    poly.add(rectangle.getMinX(), rectangle.getMinY() + rectangle.getHeight());

    this.clipPolygon = poly;
    init();
    diagram.setClipPoly(poly);
  }
예제 #28
0
  public Point textExtent(String text) {

    String[] lines = text.split(Const.CR);
    int maxWidth = 0;
    for (String line : lines) {
      Rectangle2D bounds = TextUtilities.getTextBounds(line, gc, gc.getFontMetrics());
      if (bounds.getWidth() > maxWidth) maxWidth = (int) bounds.getWidth();
    }
    int height = gc.getFontMetrics().getHeight() * lines.length;

    return new Point((int) maxWidth, (int) height);
  }
예제 #29
0
 void drawCenteredString(Graphics2D g2d, String string, int x0, int y0, float angle) {
   FontRenderContext frc = g2d.getFontRenderContext();
   Rectangle2D bounds = g2d.getFont().getStringBounds(string, frc);
   LineMetrics metrics = g2d.getFont().getLineMetrics(string, frc);
   if (angle == 0) {
     g2d.drawString(string, x0 - (float) bounds.getWidth() / 2, y0 + metrics.getHeight() / 2);
   } else {
     g2d.rotate(angle, x0, y0);
     g2d.drawString(string, x0 - (float) bounds.getWidth() / 2, y0 + metrics.getHeight() / 2);
     g2d.rotate(-angle, x0, y0);
   }
 }
  public static Map<NodesPositionState, Point2D> computeNPSOffsets(
      Collection<NodesPositionState> npss) {
    Map<NodesPositionState, Point2D> results = new HashMap<NodesPositionState, Point2D>();

    LinkedList<NodesPositionState> notOrderedByHeight = new LinkedList<NodesPositionState>();

    double totalArea = 0;

    for (NodesPositionState nps : npss) {
      Rectangle2D bb = nps.getBoundingBox();
      double curArea = bb.getWidth() * bb.getHeight();
      if (curArea == 0) {
        curArea = 0.1 * (double) nps.getNodeIds().size();
      }
      totalArea += curArea;

      // Just stick them in any order
      notOrderedByHeight.add(nps);
    }

    // Suggested maximum height of the layout of the bounding boxes
    double maxHeight = Math.sqrt(totalArea) * 0.9;
    double buffer = maxHeight * 0.03;

    double xoffset = 0;
    double yoffset = 0;
    double maxXOffsetRow = 0;

    for (NodesPositionState nps : notOrderedByHeight) {
      Rectangle2D bb = nps.getBoundingBox();
      // Set the offsets for this nps in the results table.
      results.put(nps, new Point2D.Double(xoffset, yoffset));

      // First, check to see if the width of this nps is larger than the maxXOffsetRow
      // (This is used to determine how far the xoffset needs to change when moving to the
      // next column)
      if (bb.getWidth() >= maxXOffsetRow) {
        maxXOffsetRow = bb.getWidth() + buffer;
      }

      // Increment the yoffset by the height of this bounding box, then see if it goes over the
      // maxHeight limit
      yoffset += bb.getHeight() + buffer;
      if (yoffset > maxHeight) {
        // Need to adjust the x offset and reset the max offset for the new column
        xoffset += maxXOffsetRow + buffer;
        maxXOffsetRow = 0;
        yoffset = 0;
      }
    }

    return results;
  }