/**
   * Draw labels for picking.
   *
   * @param dc Current draw context.
   * @param pickSupport the PickSupport instance to be used.
   */
  protected void doPick(DrawContext dc, PickSupport pickSupport) {
    GL gl = dc.getGL();

    Angle heading = this.rotation;

    double headingDegrees;
    if (heading != null) headingDegrees = heading.degrees;
    else headingDegrees = 0;

    int x = this.screenPoint.x;
    int y = this.screenPoint.y;

    boolean matrixPushed = false;
    try {
      if (headingDegrees != 0) {
        gl.glPushMatrix();
        matrixPushed = true;

        gl.glTranslated(x, y, 0);
        gl.glRotated(headingDegrees, 0, 0, 1);
        gl.glTranslated(-x, -y, 0);
      }

      for (int i = 0; i < this.lines.length; i++) {
        Rectangle2D bounds = this.lineBounds[i];
        double width = bounds.getWidth();
        double height = bounds.getHeight();

        x = this.screenPoint.x;
        if (this.textAlign.equals(AVKey.CENTER)) x = x - (int) (width / 2.0);
        else if (this.textAlign.equals(AVKey.RIGHT)) x = x - (int) width;
        y -= this.lineHeight;

        Color color = dc.getUniquePickColor();
        int colorCode = color.getRGB();
        PickedObject po = new PickedObject(colorCode, this.getPickedObject(), this.position, false);
        pickSupport.addPickableObject(po);

        // Draw line rectangle
        gl.glColor3ub((byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue());

        try {
          gl.glBegin(GL.GL_POLYGON);
          gl.glVertex3d(x, y, 0);
          gl.glVertex3d(x + width - 1, y, 0);
          gl.glVertex3d(x + width - 1, y + height - 1, 0);
          gl.glVertex3d(x, y + height - 1, 0);
          gl.glVertex3d(x, y, 0);
        } finally {
          gl.glEnd();
        }

        y -= this.lineSpacing;
      }
    } finally {
      if (matrixPushed) {
        gl.glPopMatrix();
      }
    }
  }
Example #2
0
 private boolean contains(double x, double y, double w, double h, Rectangle2D origrect) {
   if (!(contains(x, y) && contains(x + w, y) && contains(x, y + h) && contains(x + w, y + h))) {
     return false;
   }
   // If the shape is convex then we have done all the testing
   // we need.  Only PIE arcs can be concave and then only if
   // the angular extents are greater than 180 degrees.
   if (type != PIE || Math.abs(getAngleExtent()) <= 180.0) {
     return true;
   }
   // For a PIE shape we have an additional test for the case where
   // the angular extents are greater than 180 degrees and all four
   // rectangular corners are inside the shape but one of the
   // rectangle edges spans across the "missing wedge" of the arc.
   // We can test for this case by checking if the rectangle intersects
   // either of the pie angle segments.
   if (origrect == null) {
     origrect = new Rectangle2D.Double(x, y, w, h);
   }
   double halfW = getWidth() / 2.0;
   double halfH = getHeight() / 2.0;
   double xc = getX() + halfW;
   double yc = getY() + halfH;
   double angle = Math.toRadians(-getAngleStart());
   double xe = xc + halfW * Math.cos(angle);
   double ye = yc + halfH * Math.sin(angle);
   if (origrect.intersectsLine(xc, yc, xe, ye)) {
     return false;
   }
   angle += Math.toRadians(-getAngleExtent());
   xe = xc + halfW * Math.cos(angle);
   ye = yc + halfH * Math.sin(angle);
   return !origrect.intersectsLine(xc, yc, xe, ye);
 }
 private Paint decodeGradient6(Shape s) {
   Rectangle2D bounds = s.getBounds2D();
   float x = (float) bounds.getX();
   float y = (float) bounds.getY();
   float w = (float) bounds.getWidth();
   float h = (float) bounds.getHeight();
   return decodeGradient(
       (0.5f * w) + x,
       (0.0f * h) + y,
       (0.5f * w) + x,
       (1.0f * h) + y,
       new float[] {0.0f, 0.03f, 0.06f, 0.33f, 0.6f, 0.65f, 0.7f, 0.825f, 0.95f, 0.975f, 1.0f},
       new Color[] {
         color28,
         decodeColor(color28, color29, 0.5f),
         color29,
         decodeColor(color29, color30, 0.5f),
         color30,
         decodeColor(color30, color30, 0.5f),
         color30,
         decodeColor(color30, color31, 0.5f),
         color31,
         decodeColor(color31, color32, 0.5f),
         color32
       });
 }
 public void paint(Graphics g) {
   Graphics2D g_2d = (Graphics2D) g;
   Ellipse2D ellipse = new Ellipse2D.Double(0, 2, 80, 80);
   Rectangle2D rect = new Rectangle2D.Double(40, 2, 80, 80);
   Area a1 = new Area(ellipse);
   Area a2 = new Area(rect);
   a1.intersect(a2); // "Óë"
   g_2d.fill(a1);
   ellipse.setFrame(130, 2, 80, 80);
   rect.setFrame(170, 2, 80, 80);
   a1 = new Area(ellipse);
   a2 = new Area(rect);
   a1.add(a2); // "»ò"
   g_2d.draw(a1);
   ellipse.setFrame(0, 90, 80, 80);
   rect.setFrame(40, 90, 80, 80);
   a1 = new Area(ellipse);
   a2 = new Area(rect);
   a1.subtract(a2); // "²î"
   g_2d.draw(a1);
   ellipse.setFrame(130, 90, 80, 80);
   rect.setFrame(170, 90, 80, 80);
   a1 = new Area(ellipse);
   a2 = new Area(rect);
   a1.exclusiveOr(a2); // "Òì»ò"
   g_2d.fill(a1);
 }
  /**
   * Compute the bounds of the text, if necessary.
   *
   * @param dc the current DrawContext.
   */
  protected void computeBoundsIfNeeded(DrawContext dc) {
    // Do not compute bounds if they are available. Computing text bounds is expensive, so only do
    // this
    // calculation if necessary.
    if (this.bounds != null) return;

    TextRenderer textRenderer =
        OGLTextRenderer.getOrCreateTextRenderer(dc.getTextRendererCache(), this.getFont());

    int width = 0;
    int maxLineHeight = 0;
    this.lineBounds = new Rectangle2D[this.lines.length];

    for (int i = 0; i < this.lines.length; i++) {
      Rectangle2D lineBounds = textRenderer.getBounds(lines[i]);
      width = (int) Math.max(lineBounds.getWidth(), width);

      double thisLineHeight = Math.abs(lineBounds.getY());
      maxLineHeight = (int) Math.max(thisLineHeight, maxLineHeight);

      this.lineBounds[i] = lineBounds;
    }
    this.lineHeight = maxLineHeight;

    // Compute final height using maxLineHeight and number of lines
    this.bounds =
        new Rectangle(
            this.lines.length,
            maxLineHeight,
            width,
            this.lines.length * maxLineHeight + this.lines.length * this.lineSpacing);
  }
 private Paint decodeGradient10(Shape s) {
   Rectangle2D bounds = s.getBounds2D();
   float x = (float) bounds.getX();
   float y = (float) bounds.getY();
   float w = (float) bounds.getWidth();
   float h = (float) bounds.getHeight();
   return decodeGradient(
       (0.5f * w) + x,
       (0.0f * h) + y,
       (0.5f * w) + x,
       (1.0f * h) + y,
       new float[] {0.0f, 0.024f, 0.06f, 0.276f, 0.6f, 0.65f, 0.7f, 0.856f, 0.96f, 0.98f, 1.0f},
       new Color[] {
         (Color) componentColors[0],
         decodeColor((Color) componentColors[0], (Color) componentColors[1], 0.5f),
         (Color) componentColors[1],
         decodeColor((Color) componentColors[1], (Color) componentColors[2], 0.5f),
         (Color) componentColors[2],
         decodeColor((Color) componentColors[2], (Color) componentColors[2], 0.5f),
         (Color) componentColors[2],
         decodeColor((Color) componentColors[2], (Color) componentColors[3], 0.5f),
         (Color) componentColors[3],
         decodeColor((Color) componentColors[3], (Color) componentColors[3], 0.5f),
         (Color) componentColors[3]
       });
 }
Example #7
0
 public void enlarge(Rectangle2D r) {
   r.add(x0, y0);
   double t = -xcoeff1 / (2 * xcoeff2);
   if (t > 0 && t < 1) {
     r.add(XforT(t), YforT(t));
   }
   r.add(x1, y1);
 }
Example #8
0
 /**
  * Constructs a new arc, initialized to the specified location, size, angular extents, and
  * closure type.
  *
  * @param ellipseBounds The framing rectangle that defines the outer boundary of the full
  *     ellipse of which this arc is a partial section.
  * @param start The starting angle of the arc in degrees.
  * @param extent The angular extent of the arc in degrees.
  * @param type The closure type for the arc: {@link #OPEN}, {@link #CHORD}, or {@link #PIE}.
  * @since 1.2
  */
 public Double(Rectangle2D ellipseBounds, double start, double extent, int type) {
   super(type);
   this.x = ellipseBounds.getX();
   this.y = ellipseBounds.getY();
   this.width = ellipseBounds.getWidth();
   this.height = ellipseBounds.getHeight();
   this.start = start;
   this.extent = extent;
 }
Example #9
0
 /**
  * Constructs a new arc, initialized to the specified location, size, angular extents, and
  * closure type.
  *
  * @param ellipseBounds The framing rectangle that defines the outer boundary of the full
  *     ellipse of which this arc is a partial section.
  * @param start The starting angle of the arc in degrees.
  * @param extent The angular extent of the arc in degrees.
  * @param type The closure type for the arc: {@link #OPEN}, {@link #CHORD}, or {@link #PIE}.
  * @since 1.2
  */
 public Float(Rectangle2D ellipseBounds, float start, float extent, int type) {
   super(type);
   this.x = (float) ellipseBounds.getX();
   this.y = (float) ellipseBounds.getY();
   this.width = (float) ellipseBounds.getWidth();
   this.height = (float) ellipseBounds.getHeight();
   this.start = start;
   this.extent = extent;
 }
Example #10
0
  protected Angle computeIconRadius(DrawContext dc, double regionPixelSize, Sector drawSector) {
    double minCosLat =
        Math.min(drawSector.getMinLatitude().cos(), drawSector.getMaxLatitude().cos());
    if (minCosLat < 0.001) return Angle.POS180;

    Rectangle2D iconDimension = this.computeDrawDimension(regionPixelSize); // Meter
    double dLat = iconDimension.getHeight() / dc.getGlobe().getRadius();
    double dLon = iconDimension.getWidth() / dc.getGlobe().getRadius() / minCosLat;
    return Angle.fromRadians(Math.sqrt(dLat * dLat + dLon * dLon) / 2);
  }
Example #11
0
 /**
  * Gets the page count of this section.
  *
  * @param g2 the graphics context
  * @param pf the page format
  * @return the number of pages needed
  */
 public int getPageCount(Graphics2D g2, PageFormat pf) {
   if (message.equals("")) return 0;
   FontRenderContext context = g2.getFontRenderContext();
   Font f = new Font("Serif", Font.PLAIN, 72);
   Rectangle2D bounds = f.getStringBounds(message, context);
   scale = pf.getImageableHeight() / bounds.getHeight();
   double width = scale * bounds.getWidth();
   int pages = (int) Math.ceil(width / pf.getImageableWidth());
   return pages;
 }
Example #12
0
 public float getPreferredSpan(int axis) {
   switch (axis) {
     case View.X_AXIS:
       return (float) bounds.getWidth();
     case View.Y_AXIS:
       return (float) bounds.getHeight();
     default:
       throw new IllegalArgumentException("Invalid axis: " + axis);
   }
 }
Example #13
0
  /**
   * Gets the bounding rect for the string based on the font
   *
   * @param string
   * @return Rectangle
   */
  public Rectangle2D getBounds(String string) {
    Rectangle2D rect;

    String[] rows = string.split("\n");

    float height = rows.length * this.size;
    float width = this.longestString(rows) * this.size;

    rect = new Rectangle.Float(0, 0, width, height);

    return rect.getBounds2D();
  }
 private Paint decodeGradient10(Shape s) {
   Rectangle2D bounds = s.getBounds2D();
   float x = (float) bounds.getX();
   float y = (float) bounds.getY();
   float w = (float) bounds.getWidth();
   float h = (float) bounds.getHeight();
   return decodeGradient(
       (0.24868421f * w) + x,
       (0.0014705883f * h) + y,
       (0.24868421f * w) + x,
       (1.0f * h) + y,
       new float[] {0.0f, 0.5f, 1.0f},
       new Color[] {color48, decodeColor(color48, color49, 0.5f), color49});
 }
 private Paint decodeGradient9(Shape s) {
   Rectangle2D bounds = s.getBounds2D();
   float x = (float) bounds.getX();
   float y = (float) bounds.getY();
   float w = (float) bounds.getWidth();
   float h = (float) bounds.getHeight();
   return decodeGradient(
       (0.5f * w) + x,
       (0.0f * h) + y,
       (0.5f * w) + x,
       (1.0f * h) + y,
       new float[] {0.09f, 0.52f, 0.95f},
       new Color[] {color39, decodeColor(color39, color40, 0.5f), color40});
 }
 private Paint decodeGradient3(Shape s) {
   Rectangle2D bounds = s.getBounds2D();
   float x = (float) bounds.getX();
   float y = (float) bounds.getY();
   float w = (float) bounds.getWidth();
   float h = (float) bounds.getHeight();
   return decodeGradient(
       (0.5f * w) + x,
       (0.0f * h) + y,
       (0.5f * w) + x,
       (1.0f * h) + y,
       new float[] {0.0f, 0.49573863f, 0.99147725f},
       new Color[] {color8, decodeColor(color8, color9, 0.5f), color9});
 }
 private Paint decodeGradient2(Shape s) {
   Rectangle2D bounds = s.getBounds2D();
   float x = (float) bounds.getX();
   float y = (float) bounds.getY();
   float w = (float) bounds.getWidth();
   float h = (float) bounds.getHeight();
   return decodeGradient(
       (0.25f * w) + x,
       (0.0f * h) + y,
       (0.25441176f * w) + x,
       (1.0016667f * h) + y,
       new float[] {0.0f, 0.5f, 1.0f},
       new Color[] {color3, decodeColor(color3, color2, 0.5f), color2});
 }
 private Paint decodeGradient4(Shape s) {
   Rectangle2D bounds = s.getBounds2D();
   float x = (float) bounds.getX();
   float y = (float) bounds.getY();
   float w = (float) bounds.getWidth();
   float h = (float) bounds.getHeight();
   return decodeGradient(
       (0.5f * w) + x,
       (0.0f * h) + y,
       (0.5f * w) + x,
       (1.0f * h) + y,
       new float[] {0.0f, 0.1684492f, 1.0f},
       new Color[] {color10, decodeColor(color10, color11, 0.5f), color11});
 }
 private Paint decodeGradient13(Shape s) {
   Rectangle2D bounds = s.getBounds2D();
   float x = (float) bounds.getX();
   float y = (float) bounds.getY();
   float w = (float) bounds.getWidth();
   float h = (float) bounds.getHeight();
   return decodeGradient(
       (0.5f * w) + x,
       (0.0f * h) + y,
       (0.5f * w) + x,
       (1.0f * h) + y,
       new float[] {0.26047903f, 0.6302395f, 1.0f},
       new Color[] {color62, decodeColor(color62, color63, 0.5f), color63});
 }
Example #20
0
 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);
 }
Example #21
0
 public void paint(Graphics g, Shape a) {
   Graphics2D g2 = (Graphics2D) g;
   Rectangle2D abounds = a.getBounds2D();
   AffineTransform saveTransform = g2.getTransform();
   Paint savePaint = g2.getPaint();
   try {
     g2.translate(abounds.getX() - bounds.getX(), abounds.getY() - bounds.getY());
     g2.setPaint(Color.BLACK); // FIXME
     p.paint(g2);
   } finally {
     g2.setTransform(saveTransform);
     g2.setPaint(savePaint);
   }
 }
 private Paint decodeGradient5(Shape s) {
   Rectangle2D bounds = s.getBounds2D();
   float x = (float) bounds.getX();
   float y = (float) bounds.getY();
   float w = (float) bounds.getWidth();
   float h = (float) bounds.getHeight();
   return decodeGradient(
       (0.5f * w) + x,
       (0.0f * h) + y,
       (0.5f * w) + x,
       (1.0f * h) + y,
       new float[] {0.1f, 0.49999997f, 0.9f},
       new Color[] {color7, decodeColor(color7, color8, 0.5f), color8});
 }
Example #23
0
 /**
  * Helper method, which calculates the top-left co-ordinate of a rectangle given the rectangle's
  * alignment.
  */
 protected static void getAlignedPoint(Point2D p, Rectangle2D r, int xAlign, int yAlign) {
   double x = r.getX(), y = r.getY(), w = r.getWidth(), h = r.getHeight();
   if (xAlign == Constants.CENTER) {
     x = x + (w / 2);
   } else if (xAlign == Constants.RIGHT) {
     x = x + w;
   }
   if (yAlign == Constants.CENTER) {
     y = y + (h / 2);
   } else if (yAlign == Constants.BOTTOM) {
     y = y + h;
   }
   p.setLocation(x, y);
 }
Example #24
0
  /**
   * Render the View to the given graphic context. This implementation render the interior first,
   * then the outline.
   */
  public void paint(Graphics2D g, Rectangle2D a) {
    if (!a.intersects(getBounds())) return;
    if (image != null) { // paint bitmap
      g.drawImage(image, text2ModelTr, null);
      // debug:
      g.setPaint(Color.red);
      g.draw(this.bounds);
      super.paint(g, a); // possibly paint framebox if non-null
    } else { // paint textlayout
      super.paint(g, a); // possibly paint framebox if non-null

      AffineTransform oldAT = g.getTransform();
      // paint text in black
      g.setPaint(Color.black);
      // from now on, we work in Y-direct (<0) coordinates to avoid inextricable problems with font
      // being mirrored...
      g.transform(text2ModelTr); // also include rotation
      textLayout.draw(g, 0.0f, 0.0f);
      // [pending] ajouter un cadre si areDimensionsComputed (wysiwyg du pauvre)
      // get back to previous transform
      g.setTransform(oldAT);
      if (DEBUG) {
        g.setPaint(Color.red);
        g.draw(bounds);
      }
    }
  }
Example #25
0
 /** @see prefuse.render.Renderer#setBounds(prefuse.visual.VisualItem) */
 @Override
 public void setBounds(VisualItem item) {
   if (!m_manageBounds) {
     return;
   }
   Shape shape = getShape(item);
   if (shape == null) {
     item.setBounds(item.getX(), item.getY(), 0, 0);
   } else if (shape == m_line) {
     GraphicsLib.setBounds(item, shape, getStroke(item));
   } else {
     m_box.add(m_line.getX1(), m_line.getY1());
     m_box.add(m_line.getX2(), m_line.getY2());
     item.setBounds(m_box.getMinX(), m_box.getMinY(), m_box.getWidth(), m_box.getHeight());
   }
 }
Example #26
0
    /** @see prefuse.render.AbstractShapeRenderer#getRawShape(prefuse.visual.VisualItem) */
    @Override
    protected Shape getRawShape(VisualItem item) {
      double x1 = item.getDouble(VisualItem.X);
      double y1 = item.getDouble(VisualItem.Y);
      double x2 = item.getDouble(VisualItem.X2);
      double y2 = item.getDouble(VisualItem.Y2);
      boolean isX = item.getBoolean(DocumentGridAxisLayout.IS_X);
      double midPoint = item.getDouble(DocumentGridAxisLayout.MID_POINT);
      // horizontal or vertical coords should be manually held constant so that fisheye works
      // properly
      if (isX) {
        // vertical line
        m_line.setLine(x1, y1, x1, y2);
      } else {
        // horizontal line
        m_line.setLine(x1, y1, x2, y1);
      }

      if (!item.canGetString(VisualItem.LABEL)) {
        return m_line;
      }

      String label = item.getString(VisualItem.LABEL);
      if (label == null) {
        return m_line;
      }

      FontMetrics fm = DEFAULT_GRAPHICS.getFontMetrics(item.getFont());
      m_ascent = fm.getAscent();
      int h = fm.getHeight();
      int w = fm.stringWidth(label);

      double tx, ty;

      int labelOffset = 10;
      if (isX) {
        // vertical axis
        // get text x-coord, center at midPoint
        //            tx = x1 + (x2-x1)/2 - w/2;
        //            tx = midPoint + (x1+midPoint)/2 - w/2;
        //            tx = x1 + midPoint/2 - w/2;
        // simpler approach: just add a fixed distance
        tx = x1 + labelOffset;
        // get text y-coord
        ty = y2 - h;
      } else {
        // horiz axis
        // get text x-coord
        tx = x1 - w - 2;
        // get text y-coord, center at midPoint
        //            ty = y1 + (y2-y1)/2 - h/2;
        //            ty = y1 + midPoint/2 - h/2;
        // simpler approach: just add a fixed distance
        ty = y1 + labelOffset;
      }

      m_box.setFrame(tx, ty, w, h);
      return m_box;
    }
 private Rectangle2D decodeRect1() {
   rect.setRect(
       decodeX(0.0f), // x
       decodeY(0.0f), // y
       decodeX(3.0f) - decodeX(0.0f), // width
       decodeY(3.0f) - decodeY(0.0f)); // height
   return rect;
 }
 private Rectangle2D decodeRect11() {
   rect.setRect(
       decodeX(0.6f), // x
       decodeY(2.4f), // y
       decodeX(2.4f) - decodeX(0.6f), // width
       decodeY(2.6f) - decodeY(2.4f)); // height
   return rect;
 }
 private Rectangle2D decodeRect6() {
   rect.setRect(
       decodeX(2.0f), // x
       decodeY(1.0f), // y
       decodeX(2.3333333f) - decodeX(2.0f), // width
       decodeY(2.0f) - decodeY(1.0f)); // height
   return rect;
 }
 private Rectangle2D decodeRect10() {
   rect.setRect(
       decodeX(1.7918661f), // x
       decodeY(1.7752526f), // y
       decodeX(1.8349283f) - decodeX(1.7918661f), // width
       decodeY(1.4217172f) - decodeY(1.7752526f)); // height
   return rect;
 }