There are 1 code examples for java.awt.geom.Line2D.Double.

The API names are highlighted below. You can use suckoo button to vote the code example(s) you like. The best code example will be ranked first next time. Thanks a lot for your feedback.

Project Name: jFreeChart Package: org.jfree.chart.plot

Source Code: MeterPlot.java (Click to view .java file)

Method Code:
vote
like

/** 
 * Draws a tick on the dial.
 * @param g2  the graphics device.
 * @param meterArea  the meter area.
 * @param value  the tick value.
 * @param label  a flag that controls whether or not a value label is drawn.
 */
protected void drawTick(Graphics2D g2,Rectangle2D meterArea,double value,boolean label){
  double valueAngle=valueToAngle(value);
  double meterMiddleX=meterArea.getCenterX();
  double meterMiddleY=meterArea.getCenterY();
  g2.setPaint(this.tickPaint);
  g2.setStroke(new BasicStroke(2.0f));
  double valueP2X=0;
  double valueP2Y=0;
  double radius=(meterArea.getWidth() / 2) + DEFAULT_BORDER_SIZE;
  double radius1=radius - 15;
  double valueP1X=meterMiddleX + (radius * Math.cos(Math.PI * (valueAngle / 180)));
  double valueP1Y=meterMiddleY - (radius * Math.sin(Math.PI * (valueAngle / 180)));
  valueP2X=meterMiddleX + (radius1 * Math.cos(Math.PI * (valueAngle / 180)));
  valueP2Y=meterMiddleY - (radius1 * Math.sin(Math.PI * (valueAngle / 180)));
  Line2D.Double line=new Line2D.Double(valueP1X,valueP1Y,valueP2X,valueP2Y);
  g2.draw(line);
  if (this.tickLabelsVisible && label) {
    String tickLabel=this.tickLabelFormat.format(value);
    g2.setFont(this.tickLabelFont);
    g2.setPaint(this.tickLabelPaint);
    FontMetrics fm=g2.getFontMetrics();
    Rectangle2D tickLabelBounds=TextUtilities.getTextBounds(tickLabel,g2,fm);
    double x=valueP2X;
    double y=valueP2Y;
    if (valueAngle == 90 || valueAngle == 270) {
      x=x - tickLabelBounds.getWidth() / 2;
    }
 else     if (valueAngle < 90 || valueAngle > 270) {
      x=x - tickLabelBounds.getWidth();
    }
    if ((valueAngle > 135 && valueAngle < 225) || valueAngle > 315 || valueAngle < 45) {
      y=y - tickLabelBounds.getHeight() / 2;
    }
 else {
      y=y + tickLabelBounds.getHeight() / 2;
    }
    g2.drawString(tickLabel,(float)x,(float)y);
  }
}