java.awt.geom.Line2D#setLine ( )源码实例Demo

下面列出了java.awt.geom.Line2D#setLine ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openstock   文件: XYDifferenceRendererTest.java
/**
 * Confirm that cloning works.
 */
@Test
public void testCloning() throws CloneNotSupportedException {
    XYDifferenceRenderer r1 = new XYDifferenceRenderer(Color.red,
            Color.blue, false);
    XYDifferenceRenderer r2 = (XYDifferenceRenderer) r1.clone();
    assertTrue(r1 != r2);
    assertTrue(r1.getClass() == r2.getClass());
    assertTrue(r1.equals(r2));

    // check independence
    Shape s = r1.getLegendLine();
    if (s instanceof Line2D) {
        Line2D l = (Line2D) s;
        l.setLine(1.0, 2.0, 3.0, 4.0);
        assertFalse(r1.equals(r2));
    }
}
 
源代码2 项目: buffer_bci   文件: LineNeedle.java
/**
 * 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) {

    Line2D shape = new Line2D.Double();

    double x = plotArea.getMinX() + (plotArea.getWidth() / 2);
    shape.setLine(x, plotArea.getMinY(), x, plotArea.getMaxY());

    Shape s = shape;

    if ((rotate != null) && (angle != 0)) {
        /// we have rotation
        getTransform().setToRotation(angle, rotate.getX(), rotate.getY());
        s = getTransform().createTransformedShape(s);
    }

    defaultDisplay(g2, s);

}
 
源代码3 项目: openstock   文件: LineNeedle.java
/**
 * 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) {

    Line2D shape = new Line2D.Double();

    double x = plotArea.getMinX() + (plotArea.getWidth() / 2);
    shape.setLine(x, plotArea.getMinY(), x, plotArea.getMaxY());

    Shape s = shape;

    if ((rotate != null) && (angle != 0)) {
        /// we have rotation
        getTransform().setToRotation(angle, rotate.getX(), rotate.getY());
        s = getTransform().createTransformedShape(s);
    }

    defaultDisplay(g2, s);

}
 
源代码4 项目: netbeans   文件: DropGlassPane.java
/** Check the bounds of given line with the bounds of this pane. Optionally
 * calculate the new bounds in current pane's boundary.
 * @param line a line for check
 * @return  a line with bounds inside the pane's boundary */
private Line2D checkLineBounds(Line2D line) {
    Rectangle bounds = getBounds();
    double startPointX;
    double startPointY;
    double endPointX;
    double endPointY;

    // check start point
    startPointX = Math.max(line.getX1(), bounds.x + MIN_X);
    startPointY = Math.max(line.getY1(), bounds.y + MIN_Y);

    // check end point
    endPointX = Math.min(line.getX2(), (bounds.x + bounds.width) - MIN_WIDTH);
    endPointY = Math.min(line.getY2(), (bounds.y + bounds.height) - MIN_HEIGTH);

    // set new bounds
    line.setLine(startPointX, startPointY, endPointX, endPointY);

    return line;
}
 
源代码5 项目: tracker   文件: ProtractorFootprint.java
/**
 * Gets the icon.
 *
 * @param w width of the icon
 * @param h height of the icon
 * @return the icon
 */
public Icon getIcon(int w, int h) {
  int scale = FontSizer.getIntegerFactor();
  w *= scale;
  h *= scale;
  transform.setToScale(scale, scale);
  Shape shape = transform.createTransformedShape(circle);
	if (stroke==null || stroke.getLineWidth()!=scale*baseStroke.getLineWidth()) {
		stroke = new BasicStroke(scale*baseStroke.getLineWidth());
		arcStroke = new BasicStroke(scale);
    arcAdjustStroke = new BasicStroke(stroke.getLineWidth(),
        BasicStroke.CAP_BUTT,
        BasicStroke.JOIN_MITER,
        8,
        DOTTED_LINE,
        stroke.getDashPhase());  
	}
	shape = stroke.createStrokedShape(shape);
  Area area = new Area(shape);
  double x0 = scale*(radius+2)-w;
  double y0 = h-scale*(radius+2);
  double d = Math.sqrt(x0*x0+y0*y0);
  double x1 = x0*scale*radius/d;
  double y1 = y0*scale*radius/d;
  Line2D line = new Line2D.Double(x0, y0, x1, y1);
  area.add(new Area(stroke.createStrokedShape(line)));
  line.setLine(x0, y0, radius-2, y0);
  area.add(new Area(stroke.createStrokedShape(line)));
  ShapeIcon icon = new ShapeIcon(area, w, h);
  icon.setColor(color);
  return icon;
}
 
源代码6 项目: ECG-Viewer   文件: PaletteSample.java
/**
 * Draws the sample.
 *
 * @param g  the graphics device.
 */
@Override
public void paintComponent(Graphics g) {

    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 
            RenderingHints.VALUE_ANTIALIAS_OFF);
    Dimension size = getSize();
    Insets insets = getInsets();
    double ww = size.getWidth() - insets.left - insets.right;
    double hh = size.getHeight() - insets.top - insets.bottom;

    g2.setStroke(new BasicStroke(1.0f));

    double y1 = insets.top;
    double y2 = y1 + hh;
    double xx = insets.left;
    Line2D line = new Line2D.Double();
    int count = 0;
    while (xx <= insets.left + ww) {
        count++;
        line.setLine(xx, y1, xx, y2);
        g2.setPaint(this.palette.getColor(count));
        g2.draw(line);
        xx += 1;
    }
}
 
源代码7 项目: ccu-historian   文件: PaletteSample.java
/**
 * Draws the sample.
 *
 * @param g  the graphics device.
 */
@Override
public void paintComponent(Graphics g) {

    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 
            RenderingHints.VALUE_ANTIALIAS_OFF);
    Dimension size = getSize();
    Insets insets = getInsets();
    double ww = size.getWidth() - insets.left - insets.right;
    double hh = size.getHeight() - insets.top - insets.bottom;

    g2.setStroke(new BasicStroke(1.0f));

    double y1 = insets.top;
    double y2 = y1 + hh;
    double xx = insets.left;
    Line2D line = new Line2D.Double();
    int count = 0;
    while (xx <= insets.left + ww) {
        count++;
        line.setLine(xx, y1, xx, y2);
        g2.setPaint(this.palette.getColor(count));
        g2.draw(line);
        xx += 1;
    }
}
 
源代码8 项目: netbeans   文件: OutlineViewDropSupport.java
/** Converts line's bounds by the bounds of the root pane. Drop glass pane
 * is over this root pane. After covert a given line is set to drop glass pane.
 * @param line line for show in drop glass pane */
private void convertBoundsAndSetDropLine(final Line2D line) {
    int x1 = (int) line.getX1();
    int x2 = (int) line.getX2();
    int y1 = (int) line.getY1();
    int y2 = (int) line.getY2();
    Point p1 = SwingUtilities.convertPoint(table, x1, y1, table.getRootPane());
    Point p2 = SwingUtilities.convertPoint(table, x2, y2, table.getRootPane());
    line.setLine(p1, p2);
    dropPane.setDropLine(line);
}
 
源代码9 项目: opensim-gui   文件: PaletteSample.java
/**
 * Draws the sample.
 *
 * @param g  the graphics device.
 */
public void paintComponent(Graphics g) {

    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(
        RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF
    );
    Dimension size = getSize();
    Insets insets = getInsets();
    double ww = size.getWidth() - insets.left - insets.right;
    double hh = size.getHeight() - insets.top - insets.bottom;

    g2.setStroke(new BasicStroke(1.0f));

    double y1 = insets.top;
    double y2 = y1 + hh;
    double xx = insets.left;
    Line2D line = new Line2D.Double();
    int count = 0;
    while (xx <= insets.left + ww) {
        count++;
        line.setLine(xx, y1, xx, y2);
        g2.setPaint(this.palette.getColor(count));
        g2.draw(line);
        xx += 1;
    }
}
 
源代码10 项目: astor   文件: ArrowNeedle.java
/**
 * Draws the needle.
 *
 * @param g2  the graphics device.
 * @param plotArea  the plot area.
 * @param rotate  the rotation point.
 * @param angle  the angle.
 */
protected void drawNeedle(Graphics2D g2, Rectangle2D plotArea,
                          Point2D rotate, double angle) {

    Line2D shape = new Line2D.Float();
    Shape d = null;

    float x = (float) (plotArea.getMinX() +  (plotArea.getWidth() / 2));
    float minY = (float) plotArea.getMinY();
    float maxY = (float) plotArea.getMaxY();
    shape.setLine(x, minY, x, maxY);

    GeneralPath shape1 = new GeneralPath();
    if (this.isArrowAtTop) {
        shape1.moveTo(x, minY);
        minY += 4 * getSize();
    }
    else {
        shape1.moveTo(x, maxY);
        minY = maxY - 4 * getSize();
    }
    shape1.lineTo(x + getSize(), minY);
    shape1.lineTo(x - getSize(), minY);
    shape1.closePath();

    if ((rotate != null) && (angle != 0)) {
        getTransform().setToRotation(angle, rotate.getX(), rotate.getY());
        d = getTransform().createTransformedShape(shape);
    }
    else {
        d = shape;
    }
    defaultDisplay(g2, d);

    if ((rotate != null) && (angle != 0)) {
        d = getTransform().createTransformedShape(shape1);
    }
    else {
        d = shape1;
    }
    defaultDisplay(g2, d);

}
 
源代码11 项目: ECG-Viewer   文件: LineUtilities.java
/**
 * Clips the specified line to the given rectangle.
 *
 * @param line  the line (<code>null</code> not permitted).
 * @param rect  the clipping rectangle (<code>null</code> not permitted).
 *
 * @return <code>true</code> if the clipped line is visible, and
 *     <code>false</code> otherwise.
 */
public static boolean clipLine(Line2D line, Rectangle2D rect) {

    double x1 = line.getX1();
    double y1 = line.getY1();
    double x2 = line.getX2();
    double y2 = line.getY2();

    double minX = rect.getMinX();
    double maxX = rect.getMaxX();
    double minY = rect.getMinY();
    double maxY = rect.getMaxY();

    int f1 = rect.outcode(x1, y1);
    int f2 = rect.outcode(x2, y2);

    while ((f1 | f2) != 0) {
        if ((f1 & f2) != 0) {
            return false;
        }
        double dx = (x2 - x1);
        double dy = (y2 - y1);
        // update (x1, y1), (x2, y2) and f1 and f2 using intersections
        // then recheck
        if (f1 != 0) {
            // first point is outside, so we update it against one of the
            // four sides then continue
            if ((f1 & Rectangle2D.OUT_LEFT) == Rectangle2D.OUT_LEFT
                    && dx != 0.0) {
                y1 = y1 + (minX - x1) * dy / dx;
                x1 = minX;
            }
            else if ((f1 & Rectangle2D.OUT_RIGHT) == Rectangle2D.OUT_RIGHT
                    && dx != 0.0) {
                y1 = y1 + (maxX - x1) * dy / dx;
                x1 = maxX;
            }
            else if ((f1 & Rectangle2D.OUT_BOTTOM) == Rectangle2D.OUT_BOTTOM
                    && dy != 0.0) {
                x1 = x1 + (maxY - y1) * dx / dy;
                y1 = maxY;
            }
            else if ((f1 & Rectangle2D.OUT_TOP) == Rectangle2D.OUT_TOP
                    && dy != 0.0) {
                x1 = x1 + (minY - y1) * dx / dy;
                y1 = minY;
            }
            f1 = rect.outcode(x1, y1);
        }
        else if (f2 != 0) {
            // second point is outside, so we update it against one of the
            // four sides then continue
            if ((f2 & Rectangle2D.OUT_LEFT) == Rectangle2D.OUT_LEFT
                    && dx != 0.0) {
                y2 = y2 + (minX - x2) * dy / dx;
                x2 = minX;
            }
            else if ((f2 & Rectangle2D.OUT_RIGHT) == Rectangle2D.OUT_RIGHT
                    && dx != 0.0) {
                y2 = y2 + (maxX - x2) * dy / dx;
                x2 = maxX;
            }
            else if ((f2 & Rectangle2D.OUT_BOTTOM) == Rectangle2D.OUT_BOTTOM
                    && dy != 0.0) {
                x2 = x2 + (maxY - y2) * dx / dy;
                y2 = maxY;
            }
            else if ((f2 & Rectangle2D.OUT_TOP) == Rectangle2D.OUT_TOP
                    && dy != 0.0) {
                x2 = x2 + (minY - y2) * dx / dy;
                y2 = minY;
            }
            f2 = rect.outcode(x2, y2);
        }
    }

    line.setLine(x1, y1, x2, y2);
    return true;  // the line is visible - if it wasn't, we'd have
                  // returned false from within the while loop above

}
 
源代码12 项目: openstock   文件: BarRenderer3D.java
/**
 * Draws the background for the plot.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the area inside the axes.
 */
@Override
public void drawBackground(Graphics2D g2, CategoryPlot plot,
        Rectangle2D dataArea) {

    float x0 = (float) dataArea.getX();
    float x1 = x0 + (float) Math.abs(this.xOffset);
    float x3 = (float) dataArea.getMaxX();
    float x2 = x3 - (float) Math.abs(this.xOffset);

    float y0 = (float) dataArea.getMaxY();
    float y1 = y0 - (float) Math.abs(this.yOffset);
    float y3 = (float) dataArea.getMinY();
    float y2 = y3 + (float) Math.abs(this.yOffset);

    GeneralPath clip = new GeneralPath();
    clip.moveTo(x0, y0);
    clip.lineTo(x0, y2);
    clip.lineTo(x1, y3);
    clip.lineTo(x3, y3);
    clip.lineTo(x3, y1);
    clip.lineTo(x2, y0);
    clip.closePath();

    Composite originalComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
            plot.getBackgroundAlpha()));

    // fill background...
    Paint backgroundPaint = plot.getBackgroundPaint();
    if (backgroundPaint != null) {
        g2.setPaint(backgroundPaint);
        g2.fill(clip);
    }

    GeneralPath leftWall = new GeneralPath();
    leftWall.moveTo(x0, y0);
    leftWall.lineTo(x0, y2);
    leftWall.lineTo(x1, y3);
    leftWall.lineTo(x1, y1);
    leftWall.closePath();
    g2.setPaint(getWallPaint());
    g2.fill(leftWall);

    GeneralPath bottomWall = new GeneralPath();
    bottomWall.moveTo(x0, y0);
    bottomWall.lineTo(x1, y1);
    bottomWall.lineTo(x3, y1);
    bottomWall.lineTo(x2, y0);
    bottomWall.closePath();
    g2.setPaint(getWallPaint());
    g2.fill(bottomWall);

    // highlight the background corners...
    g2.setPaint(Color.lightGray);
    Line2D corner = new Line2D.Double(x0, y0, x1, y1);
    g2.draw(corner);
    corner.setLine(x1, y1, x1, y3);
    g2.draw(corner);
    corner.setLine(x1, y1, x3, y1);
    g2.draw(corner);

    // draw background image, if there is one...
    Image backgroundImage = plot.getBackgroundImage();
    if (backgroundImage != null) {
        Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX()
                + getXOffset(), dataArea.getY(),
                dataArea.getWidth() - getXOffset(),
                dataArea.getHeight() - getYOffset());
        plot.drawBackgroundImage(g2, adjusted);
    }

    g2.setComposite(originalComposite);

}
 
源代码13 项目: buffer_bci   文件: LineUtilities.java
/**
 * Clips the specified line to the given rectangle.
 *
 * @param line  the line (<code>null</code> not permitted).
 * @param rect  the clipping rectangle (<code>null</code> not permitted).
 *
 * @return <code>true</code> if the clipped line is visible, and
 *     <code>false</code> otherwise.
 */
public static boolean clipLine(Line2D line, Rectangle2D rect) {

    double x1 = line.getX1();
    double y1 = line.getY1();
    double x2 = line.getX2();
    double y2 = line.getY2();

    double minX = rect.getMinX();
    double maxX = rect.getMaxX();
    double minY = rect.getMinY();
    double maxY = rect.getMaxY();

    int f1 = rect.outcode(x1, y1);
    int f2 = rect.outcode(x2, y2);

    while ((f1 | f2) != 0) {
        if ((f1 & f2) != 0) {
            return false;
        }
        double dx = (x2 - x1);
        double dy = (y2 - y1);
        // update (x1, y1), (x2, y2) and f1 and f2 using intersections
        // then recheck
        if (f1 != 0) {
            // first point is outside, so we update it against one of the
            // four sides then continue
            if ((f1 & Rectangle2D.OUT_LEFT) == Rectangle2D.OUT_LEFT
                    && dx != 0.0) {
                y1 = y1 + (minX - x1) * dy / dx;
                x1 = minX;
            }
            else if ((f1 & Rectangle2D.OUT_RIGHT) == Rectangle2D.OUT_RIGHT
                    && dx != 0.0) {
                y1 = y1 + (maxX - x1) * dy / dx;
                x1 = maxX;
            }
            else if ((f1 & Rectangle2D.OUT_BOTTOM) == Rectangle2D.OUT_BOTTOM
                    && dy != 0.0) {
                x1 = x1 + (maxY - y1) * dx / dy;
                y1 = maxY;
            }
            else if ((f1 & Rectangle2D.OUT_TOP) == Rectangle2D.OUT_TOP
                    && dy != 0.0) {
                x1 = x1 + (minY - y1) * dx / dy;
                y1 = minY;
            }
            f1 = rect.outcode(x1, y1);
        }
        else if (f2 != 0) {
            // second point is outside, so we update it against one of the
            // four sides then continue
            if ((f2 & Rectangle2D.OUT_LEFT) == Rectangle2D.OUT_LEFT
                    && dx != 0.0) {
                y2 = y2 + (minX - x2) * dy / dx;
                x2 = minX;
            }
            else if ((f2 & Rectangle2D.OUT_RIGHT) == Rectangle2D.OUT_RIGHT
                    && dx != 0.0) {
                y2 = y2 + (maxX - x2) * dy / dx;
                x2 = maxX;
            }
            else if ((f2 & Rectangle2D.OUT_BOTTOM) == Rectangle2D.OUT_BOTTOM
                    && dy != 0.0) {
                x2 = x2 + (maxY - y2) * dx / dy;
                y2 = maxY;
            }
            else if ((f2 & Rectangle2D.OUT_TOP) == Rectangle2D.OUT_TOP
                    && dy != 0.0) {
                x2 = x2 + (minY - y2) * dx / dy;
                y2 = minY;
            }
            f2 = rect.outcode(x2, y2);
        }
    }

    line.setLine(x1, y1, x2, y2);
    return true;  // the line is visible - if it wasn't, we'd have
                  // returned false from within the while loop above

}
 
源代码14 项目: SIMVA-SoS   文件: LineUtilitiesTest.java
@Test
public void testClipLine() {
    Rectangle2D rect = new Rectangle2D.Double(1.0, 1.0, 1.0, 1.0);
    Line2D line = new Line2D.Double();

    assertFalse(LineUtilities.clipLine(line, rect));
    assertTrue(lineEquals(line, 0.0, 0.0, 0.0, 0.0));

    line.setLine(0.5, 0.5, 0.6, 0.6);
    assertFalse(LineUtilities.clipLine(line, rect));
    assertTrue(lineEquals(line, 0.5, 0.5, 0.6, 0.6));

    line.setLine(0.5, 0.5, 1.6, 0.6);
    assertFalse(LineUtilities.clipLine(line, rect));
    assertTrue(lineEquals(line, 0.5, 0.5, 1.6, 0.6));

    line.setLine(0.5, 0.5, 2.6, 0.6);
    assertFalse(LineUtilities.clipLine(line, rect));
    assertTrue(lineEquals(line, 0.5, 0.5, 2.6, 0.6));

    line.setLine(0.5, 0.5, 0.6, 1.6);
    assertFalse(LineUtilities.clipLine(line, rect));
    assertTrue(lineEquals(line, 0.5, 0.5, 0.6, 1.6));

    line.setLine(0.5, 0.5, 1.6, 1.6);
    assertTrue(LineUtilities.clipLine(line, rect));
    assertTrue(lineEquals(line, 1.0, 1.0, 1.6, 1.6));

    line.setLine(0.5, 0.5, 2.6, 1.6);
    assertTrue(LineUtilities.clipLine(line, rect));
    assertTrue(lineEquals(line, 1.4545454545454546, 1.0, 2.0,
            1.2857142857142858));

    line.setLine(0.5, 0.5, 0.5, 2.6);
    assertFalse(LineUtilities.clipLine(line, rect));
    assertTrue(lineEquals(line, 0.5, 0.5, 0.5, 2.6));

    line.setLine(0.5, 0.5, 1.5, 2.6);
    assertTrue(LineUtilities.clipLine(line, rect));
    assertTrue(lineEquals(line, 1.0, 1.55, 1.2142857142857142, 2.0));

    line.setLine(0.5, 0.5, 2.5, 2.6);
    assertTrue(LineUtilities.clipLine(line, rect));
    assertTrue(lineEquals(line, 1.0, 1.025, 1.9285714285714284, 2.0));

    line.setLine(0.5, 0.5, 1.5, 1.5);
    assertTrue(LineUtilities.clipLine(line, rect));
    assertTrue(lineEquals(line, 1.0, 1.0, 1.5, 1.5));

    line.setLine(2.5, 1.0, 1.5, 1.5);
    assertTrue(LineUtilities.clipLine(line, rect));
    assertTrue(lineEquals(line, 2.0, 1.25, 1.5, 1.5));

    line.setLine(1.5, 1.5, 2.5, 1.0);
    assertTrue(LineUtilities.clipLine(line, rect));
    assertTrue(lineEquals(line, 1.5, 1.5, 2.0, 1.25));
}
 
源代码15 项目: buffer_bci   文件: LineBorder.java
/**
 * Draws the border by filling in the reserved space (in black).
 *
 * @param g2  the graphics device.
 * @param area  the area.
 */
@Override
public void draw(Graphics2D g2, Rectangle2D area) {
    double w = area.getWidth();
    double h = area.getHeight();
    // if the area has zero height or width, we shouldn't draw anything
    if (w <= 0.0 || h <= 0.0) {
        return;
    }
    double t = this.insets.calculateTopInset(h);
    double b = this.insets.calculateBottomInset(h);
    double l = this.insets.calculateLeftInset(w);
    double r = this.insets.calculateRightInset(w);
    double x = area.getX();
    double y = area.getY();
    double x0 = x + l / 2.0;
    double x1 = x + w - r / 2.0;
    double y0 = y + h - b / 2.0;
    double y1 = y + t / 2.0;
    g2.setPaint(getPaint());
    g2.setStroke(getStroke());
    Object saved = g2.getRenderingHint(RenderingHints.KEY_STROKE_CONTROL);
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, 
            RenderingHints.VALUE_STROKE_NORMALIZE);
    Line2D line = new Line2D.Double();
    if (t > 0.0) {
        line.setLine(x0, y1, x1, y1);
        g2.draw(line);
    }
    if (b > 0.0) {
        line.setLine(x0, y0, x1, y0);
        g2.draw(line);
    }
    if (l > 0.0) {
        line.setLine(x0, y0, x0, y1);
        g2.draw(line);
    }
    if (r > 0.0) {
        line.setLine(x1, y0, x1, y1);
        g2.draw(line);
    }
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, saved);
}
 
源代码16 项目: openstock   文件: ArrowNeedle.java
/**
 * 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) {

    Line2D shape = new Line2D.Float();
    Shape d;

    float x = (float) (plotArea.getMinX() +  (plotArea.getWidth() / 2));
    float minY = (float) plotArea.getMinY();
    float maxY = (float) plotArea.getMaxY();
    shape.setLine(x, minY, x, maxY);

    GeneralPath shape1 = new GeneralPath();
    if (this.isArrowAtTop) {
        shape1.moveTo(x, minY);
        minY += 4 * getSize();
    }
    else {
        shape1.moveTo(x, maxY);
        minY = maxY - 4 * getSize();
    }
    shape1.lineTo(x + getSize(), minY);
    shape1.lineTo(x - getSize(), minY);
    shape1.closePath();

    if ((rotate != null) && (angle != 0)) {
        getTransform().setToRotation(angle, rotate.getX(), rotate.getY());
        d = getTransform().createTransformedShape(shape);
    }
    else {
        d = shape;
    }
    defaultDisplay(g2, d);

    if ((rotate != null) && (angle != 0)) {
        d = getTransform().createTransformedShape(shape1);
    }
    else {
        d = shape1;
    }
    defaultDisplay(g2, d);

}
 
源代码17 项目: SIMVA-SoS   文件: StandardDialScale.java
/**
 * Draws the scale on the dial plot.
 *
 * @param g2  the graphics target (<code>null</code> not permitted).
 * @param plot  the dial plot (<code>null</code> not permitted).
 * @param frame  the reference frame that is used to construct the
 *     geometry of the plot (<code>null</code> not permitted).
 * @param view  the visible part of the plot (<code>null</code> not
 *     permitted).
 */
@Override
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame,
        Rectangle2D view) {

    Rectangle2D arcRect = DialPlot.rectangleByRadius(frame,
            this.tickRadius, this.tickRadius);
    Rectangle2D arcRectMajor = DialPlot.rectangleByRadius(frame,
            this.tickRadius - this.majorTickLength,
            this.tickRadius - this.majorTickLength);
    Rectangle2D arcRectMinor = arcRect;
    if (this.minorTickCount > 0 && this.minorTickLength > 0.0) {
        arcRectMinor = DialPlot.rectangleByRadius(frame,
                this.tickRadius - this.minorTickLength,
                this.tickRadius - this.minorTickLength);
    }
    Rectangle2D arcRectForLabels = DialPlot.rectangleByRadius(frame,
            this.tickRadius - this.tickLabelOffset,
            this.tickRadius - this.tickLabelOffset);

    boolean firstLabel = true;

    Arc2D arc = new Arc2D.Double();
    Line2D workingLine = new Line2D.Double();
    for (double v = this.lowerBound; v <= this.upperBound;
            v += this.majorTickIncrement) {
        arc.setArc(arcRect, this.startAngle, valueToAngle(v)
                - this.startAngle, Arc2D.OPEN);
        Point2D pt0 = arc.getEndPoint();
        arc.setArc(arcRectMajor, this.startAngle, valueToAngle(v)
                - this.startAngle, Arc2D.OPEN);
        Point2D pt1 = arc.getEndPoint();
        g2.setPaint(this.majorTickPaint);
        g2.setStroke(this.majorTickStroke);
        workingLine.setLine(pt0, pt1);
        g2.draw(workingLine);
        arc.setArc(arcRectForLabels, this.startAngle, valueToAngle(v)
                - this.startAngle, Arc2D.OPEN);
        Point2D pt2 = arc.getEndPoint();

        if (this.tickLabelsVisible) {
            if (!firstLabel || this.firstTickLabelVisible) {
                g2.setFont(this.tickLabelFont);
                g2.setPaint(this.tickLabelPaint);
                TextUtilities.drawAlignedString(
                        this.tickLabelFormatter.format(v), g2,
                        (float) pt2.getX(), (float) pt2.getY(),
                        TextAnchor.CENTER);
            }
        }
        firstLabel = false;

        // now do the minor tick marks
        if (this.minorTickCount > 0 && this.minorTickLength > 0.0) {
            double minorTickIncrement = this.majorTickIncrement
                    / (this.minorTickCount + 1);
            for (int i = 0; i < this.minorTickCount; i++) {
                double vv = v + ((i + 1) * minorTickIncrement);
                if (vv >= this.upperBound) {
                    break;
                }
                double angle = valueToAngle(vv);

                arc.setArc(arcRect, this.startAngle, angle
                        - this.startAngle, Arc2D.OPEN);
                pt0 = arc.getEndPoint();
                arc.setArc(arcRectMinor, this.startAngle, angle
                        - this.startAngle, Arc2D.OPEN);
                Point2D pt3 = arc.getEndPoint();
                g2.setStroke(this.minorTickStroke);
                g2.setPaint(this.minorTickPaint);
                workingLine.setLine(pt0, pt3);
                g2.draw(workingLine);
            }
        }

    }
}
 
源代码18 项目: astor   文件: LineRenderer3D.java
/**
 * Draws the background for the plot.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the area inside the axes.
 */
public void drawBackground(Graphics2D g2, CategoryPlot plot,
                           Rectangle2D dataArea) {

    float x0 = (float) dataArea.getX();
    float x1 = x0 + (float) Math.abs(this.xOffset);
    float x3 = (float) dataArea.getMaxX();
    float x2 = x3 - (float) Math.abs(this.xOffset);

    float y0 = (float) dataArea.getMaxY();
    float y1 = y0 - (float) Math.abs(this.yOffset);
    float y3 = (float) dataArea.getMinY();
    float y2 = y3 + (float) Math.abs(this.yOffset);

    GeneralPath clip = new GeneralPath();
    clip.moveTo(x0, y0);
    clip.lineTo(x0, y2);
    clip.lineTo(x1, y3);
    clip.lineTo(x3, y3);
    clip.lineTo(x3, y1);
    clip.lineTo(x2, y0);
    clip.closePath();

    Composite originalComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
            plot.getBackgroundAlpha()));

    // fill background...
    Paint backgroundPaint = plot.getBackgroundPaint();
    if (backgroundPaint != null) {
        g2.setPaint(backgroundPaint);
        g2.fill(clip);
    }

    GeneralPath leftWall = new GeneralPath();
    leftWall.moveTo(x0, y0);
    leftWall.lineTo(x0, y2);
    leftWall.lineTo(x1, y3);
    leftWall.lineTo(x1, y1);
    leftWall.closePath();
    g2.setPaint(getWallPaint());
    g2.fill(leftWall);

    GeneralPath bottomWall = new GeneralPath();
    bottomWall.moveTo(x0, y0);
    bottomWall.lineTo(x1, y1);
    bottomWall.lineTo(x3, y1);
    bottomWall.lineTo(x2, y0);
    bottomWall.closePath();
    g2.setPaint(getWallPaint());
    g2.fill(bottomWall);

    // higlight the background corners...
    g2.setPaint(Color.lightGray);
    Line2D corner = new Line2D.Double(x0, y0, x1, y1);
    g2.draw(corner);
    corner.setLine(x1, y1, x1, y3);
    g2.draw(corner);
    corner.setLine(x1, y1, x3, y1);
    g2.draw(corner);

    // draw background image, if there is one...
    Image backgroundImage = plot.getBackgroundImage();
    if (backgroundImage != null) {
        Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX()
                + getXOffset(), dataArea.getY(),
                dataArea.getWidth() - getXOffset(),
                dataArea.getHeight() - getYOffset());
        plot.drawBackgroundImage(g2, adjusted);
    }

    g2.setComposite(originalComposite);

}
 
源代码19 项目: SIMVA-SoS   文件: BarRenderer3D.java
/**
 * Draws the background for the plot.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the area inside the axes.
 */
@Override
public void drawBackground(Graphics2D g2, CategoryPlot plot,
        Rectangle2D dataArea) {

    float x0 = (float) dataArea.getX();
    float x1 = x0 + (float) Math.abs(this.xOffset);
    float x3 = (float) dataArea.getMaxX();
    float x2 = x3 - (float) Math.abs(this.xOffset);

    float y0 = (float) dataArea.getMaxY();
    float y1 = y0 - (float) Math.abs(this.yOffset);
    float y3 = (float) dataArea.getMinY();
    float y2 = y3 + (float) Math.abs(this.yOffset);

    GeneralPath clip = new GeneralPath();
    clip.moveTo(x0, y0);
    clip.lineTo(x0, y2);
    clip.lineTo(x1, y3);
    clip.lineTo(x3, y3);
    clip.lineTo(x3, y1);
    clip.lineTo(x2, y0);
    clip.closePath();

    Composite originalComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
            plot.getBackgroundAlpha()));

    // fill background...
    Paint backgroundPaint = plot.getBackgroundPaint();
    if (backgroundPaint != null) {
        g2.setPaint(backgroundPaint);
        g2.fill(clip);
    }

    GeneralPath leftWall = new GeneralPath();
    leftWall.moveTo(x0, y0);
    leftWall.lineTo(x0, y2);
    leftWall.lineTo(x1, y3);
    leftWall.lineTo(x1, y1);
    leftWall.closePath();
    g2.setPaint(getWallPaint());
    g2.fill(leftWall);

    GeneralPath bottomWall = new GeneralPath();
    bottomWall.moveTo(x0, y0);
    bottomWall.lineTo(x1, y1);
    bottomWall.lineTo(x3, y1);
    bottomWall.lineTo(x2, y0);
    bottomWall.closePath();
    g2.setPaint(getWallPaint());
    g2.fill(bottomWall);

    // highlight the background corners...
    g2.setPaint(Color.lightGray);
    Line2D corner = new Line2D.Double(x0, y0, x1, y1);
    g2.draw(corner);
    corner.setLine(x1, y1, x1, y3);
    g2.draw(corner);
    corner.setLine(x1, y1, x3, y1);
    g2.draw(corner);

    // draw background image, if there is one...
    Image backgroundImage = plot.getBackgroundImage();
    if (backgroundImage != null) {
        Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX()
                + getXOffset(), dataArea.getY(),
                dataArea.getWidth() - getXOffset(),
                dataArea.getHeight() - getYOffset());
        plot.drawBackgroundImage(g2, adjusted);
    }

    g2.setComposite(originalComposite);

}
 
源代码20 项目: astor   文件: BarRenderer3D.java
/**
 * Draws the background for the plot.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the area inside the axes.
 */
public void drawBackground(Graphics2D g2, CategoryPlot plot, 
                           Rectangle2D dataArea) {

    float x0 = (float) dataArea.getX();
    float x1 = x0 + (float) Math.abs(this.xOffset);
    float x3 = (float) dataArea.getMaxX();
    float x2 = x3 - (float) Math.abs(this.xOffset);

    float y0 = (float) dataArea.getMaxY();
    float y1 = y0 - (float) Math.abs(this.yOffset);
    float y3 = (float) dataArea.getMinY();
    float y2 = y3 + (float) Math.abs(this.yOffset);

    GeneralPath clip = new GeneralPath();
    clip.moveTo(x0, y0);
    clip.lineTo(x0, y2);
    clip.lineTo(x1, y3);
    clip.lineTo(x3, y3);
    clip.lineTo(x3, y1);
    clip.lineTo(x2, y0);
    clip.closePath();

    Composite originalComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
            plot.getBackgroundAlpha()));
    
    // fill background...
    Paint backgroundPaint = plot.getBackgroundPaint();
    if (backgroundPaint != null) {
        g2.setPaint(backgroundPaint);
        g2.fill(clip);
    }

    GeneralPath leftWall = new GeneralPath();
    leftWall.moveTo(x0, y0);
    leftWall.lineTo(x0, y2);
    leftWall.lineTo(x1, y3);
    leftWall.lineTo(x1, y1);
    leftWall.closePath();
    g2.setPaint(getWallPaint());
    g2.fill(leftWall);

    GeneralPath bottomWall = new GeneralPath();
    bottomWall.moveTo(x0, y0);
    bottomWall.lineTo(x1, y1);
    bottomWall.lineTo(x3, y1);
    bottomWall.lineTo(x2, y0);
    bottomWall.closePath();
    g2.setPaint(getWallPaint());
    g2.fill(bottomWall);

    // highlight the background corners...
    g2.setPaint(Color.lightGray);
    Line2D corner = new Line2D.Double(x0, y0, x1, y1);
    g2.draw(corner);
    corner.setLine(x1, y1, x1, y3);
    g2.draw(corner);
    corner.setLine(x1, y1, x3, y1);
    g2.draw(corner);
            
    // draw background image, if there is one...
    Image backgroundImage = plot.getBackgroundImage();
    if (backgroundImage != null) {
        Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX() 
                + getXOffset(), dataArea.getY(), 
                dataArea.getWidth() - getXOffset(), 
                dataArea.getHeight() - getYOffset());
        plot.drawBackgroundImage(g2, adjusted);
    }
    
    g2.setComposite(originalComposite);

}