コード例 #1
0
ファイル: TextBlock.java プロジェクト: ti-cortex-m4/jtstand
  /**
   * Draws the text block, aligning it with the specified anchor point and rotating it about the
   * specified rotation point.
   *
   * @param g2 the graphics device.
   * @param anchorX the x-coordinate for the anchor point.
   * @param anchorY the y-coordinate for the anchor point.
   * @param anchor the point on the text block that is aligned to the anchor point.
   * @param rotateX the x-coordinate for the rotation point.
   * @param rotateY the x-coordinate for the rotation point.
   * @param angle the rotation (in radians).
   */
  public void draw(
      final Graphics2D g2,
      final float anchorX,
      final float anchorY,
      final TextBlockAnchor anchor,
      final float rotateX,
      final float rotateY,
      final double angle) {

    final Size2D d = calculateDimensions(g2);
    final float[] offsets = calculateOffsets(anchor, d.getWidth(), d.getHeight());
    final Iterator iterator = this.lines.iterator();
    float yCursor = 0.0f;
    while (iterator.hasNext()) {
      TextLine line = (TextLine) iterator.next();
      Size2D dimension = line.calculateDimensions(g2);
      float lineOffset = 0.0f;
      if (this.lineAlignment == HorizontalAlignment.CENTER) {
        lineOffset = (float) (d.getWidth() - dimension.getWidth()) / 2.0f;
      } else if (this.lineAlignment == HorizontalAlignment.RIGHT) {
        lineOffset = (float) (d.getWidth() - dimension.getWidth());
      }
      line.draw(
          g2,
          anchorX + offsets[0] + lineOffset,
          anchorY + offsets[1] + yCursor,
          TextAnchor.TOP_LEFT,
          rotateX,
          rotateY,
          angle);
      yCursor = yCursor + (float) dimension.getHeight();
    }
  }
コード例 #2
0
ファイル: DataSet.java プロジェクト: dustyeric/CalculatorTest
  /**
   * Draw a legend for this data set
   *
   * @param g Graphics context
   * @param w Data Window
   */
  protected void draw_legend(Graphics g, Rectangle w) {
    Color c = g.getColor();
    Markers m = null;

    if (legend_text == null) return;
    if (legend_text.isNull()) return;

    if (legend_ix == 0 && legend_iy == 0) {
      legend_ix = (int) (w.x + ((legend_dx - xmin) / xrange) * w.width);
      legend_iy = (int) (w.y + (1.0 - (legend_dy - ymin) / yrange) * w.height);
    }

    if (linestyle != DataSet.NOLINE) {
      if (linecolor != null) g.setColor(linecolor);
      g.drawLine(legend_ix, legend_iy, legend_ix + legend_length, legend_iy);
    }

    if (marker > 0) {
      m = g2d.getMarkers();
      if (m != null) {
        if (markercolor != null) g.setColor(markercolor);
        else g.setColor(c);

        m.draw(g, marker, 1.0, legend_ix + legend_length / 2, legend_iy);
      }
    }

    legend_text.draw(
        g,
        legend_ix + legend_length + legend_text.charWidth(g, ' '),
        legend_iy + legend_text.getAscent(g) / 3);

    g.setColor(c);
  }