当前位置: 首页>>代码示例>>Java>>正文


Java Line2D类代码示例

本文整理汇总了Java中java.awt.geom.Line2D的典型用法代码示例。如果您正苦于以下问题:Java Line2D类的具体用法?Java Line2D怎么用?Java Line2D使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Line2D类属于java.awt.geom包,在下文中一共展示了Line2D类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: drawNeedle

import java.awt.geom.Line2D; //导入依赖的package包/类
/**
 * 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.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);

}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:28,代码来源:LineNeedle.java

示例2: drawHorizontalLine

import java.awt.geom.Line2D; //导入依赖的package包/类
/**
 * Utility method for drawing a horizontal line across the data area of the plot.
 *
 * @param g2  the graphics device.
 * @param dataArea  the data area.
 * @param value  the coordinate, where to draw the line.
 * @param stroke  the stroke to use.
 * @param paint  the paint to use.
 */
protected void drawHorizontalLine(Graphics2D g2, Rectangle2D dataArea,
                                  double value, Stroke stroke, Paint paint) {

    ValueAxis axis = getRangeAxis();  
    if (getOrientation() == PlotOrientation.HORIZONTAL) {
        axis = getDomainAxis();   
    }
    if (axis.getRange().contains(value)) {
        double yy = axis.valueToJava2D(value, dataArea, RectangleEdge.LEFT);
        Line2D line = new Line2D.Double(dataArea.getMinX(), yy, dataArea.getMaxX(), yy);
        g2.setStroke(stroke);
        g2.setPaint(paint);
        g2.draw(line);
    }

}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:26,代码来源:XYPlot.java

示例3: drawHorizontalAxisTrace

import java.awt.geom.Line2D; //导入依赖的package包/类
/**
 * Draws a vertical line used to trace the mouse position to the horizontal axis.
 *
 * @param x  the x-coordinate of the trace line.
 */
private void drawHorizontalAxisTrace(int x) {

    Graphics2D g2 = (Graphics2D) getGraphics();
    Rectangle2D dataArea = getScaledDataArea();

    g2.setXORMode(java.awt.Color.orange);
    if (((int) dataArea.getMinX() < x) && (x < (int) dataArea.getMaxX())) {

        if (this.verticalTraceLine != null) {
            g2.draw(this.verticalTraceLine);
            this.verticalTraceLine.setLine(
                x, (int) dataArea.getMinY(), x, (int) dataArea.getMaxY()
            );
        }
        else {
            this.verticalTraceLine = new Line2D.Float(
                x, (int) dataArea.getMinY(), x, (int) dataArea.getMaxY()
            );
        }
        g2.draw(this.verticalTraceLine);
    }

}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:29,代码来源:ChartPanel.java

示例4: addRemoveControlPoint

import java.awt.geom.Line2D; //导入依赖的package包/类
/**
 * Adds or removes a control point on a specified location
 * @param widget the connection widget
 * @param localLocation the local location
 */
private void addRemoveControlPoint (ConnectionWidget widget, Point localLocation) {
    ArrayList<Point> list = new ArrayList<Point> (widget.getControlPoints ());
    if (!removeControlPoint (localLocation, list, deleteSensitivity)) {
        Point exPoint = null;
        int index = 0;
        for (Point elem : list) {
            if (exPoint != null) {
                Line2D l2d = new Line2D.Double (exPoint, elem);
                if (l2d.ptSegDist (localLocation) < createSensitivity) {
                    list.add (index, localLocation);
                    break;
                }
            }
            exPoint = elem;
            index++;
        }
    }
    if (routingPolicy != null)
        widget.setRoutingPolicy (routingPolicy);
    widget.setControlPoints (list, false);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:AddRemoveControlPointAction.java

示例5: isParallel

import java.awt.geom.Line2D; //导入依赖的package包/类
/**
 * 
 * @param line1
 * @param line2
 * @return
 */
public static boolean isParallel(Line2D line1, Line2D line2) {
    float x1 = (float) line1.getX1();
    float y1 = (float) line1.getY1();
    float x2 = (float) line1.getX2();
    float y2 = (float) line1.getY2();
    float dx = x2 - x1;
    float dy = y1 - y2;
    float d = (float) Math.sqrt((double) (dx * dx + dy * dy));

    float slope1 = Math.abs(dx / d);


    x1 = (float) line2.getX1();
    y1 = (float) line2.getY1();
    x2 = (float) line2.getX2();
    y2 = (float) line2.getY2();
    dx = x2 - x1;
    dy = y1 - y2;
    d = (float) Math.sqrt((double) (dx * dx + dy * dy));

    float slope2 = Math.abs(dx / d);

    return (slope1 == slope2);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:31,代码来源:GeometryUtils.java

示例6: isHitAt

import java.awt.geom.Line2D; //导入依赖的package包/类
/**
 * Returns whether a specified local location is a part of the connection widget. It checks whether the location is
 * close to the control-points-based path (up to 4px from the line),
 * close to the anchors (defined by AnchorShape) or
 * close to the control points (PointShape).
 * @param localLocation the local locaytion
 * @return true, if the location is a part of the connection widget
 */
public boolean isHitAt (Point localLocation) {
    if (! super.isHitAt (localLocation))
            return false;

    List<Point> controlPoints = getControlPoints ();
    for (int i = 0; i < controlPoints.size () - 1; i++) {
        Point point1 = controlPoints.get (i);
        Point point2 = controlPoints.get (i + 1);
        double dist = Line2D.ptSegDistSq (point1.x, point1.y, point2.x, point2.y, localLocation.x, localLocation.y);
        if (dist < HIT_DISTANCE_SQUARE)
            return true;
    }

    return getControlPointHitAt (localLocation) >= 0;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:ConnectionWidget.java

示例7: drawVerticalAxisTrace

import java.awt.geom.Line2D; //导入依赖的package包/类
/**
 * Draws a horizontal line used to trace the mouse position to the vertical axis.
 * 
 * @param g2
 *            the graphics device.
 * @param y
 *            the y-coordinate of the trace line.
 */
private void drawVerticalAxisTrace(Graphics2D g2, int y) {

	Rectangle2D dataArea = getScreenDataArea();

	g2.setXORMode(Color.orange);
	if ((int) dataArea.getMinY() < y && y < (int) dataArea.getMaxY()) {

		if (this.horizontalTraceLine != null) {
			g2.draw(this.horizontalTraceLine);
			this.horizontalTraceLine.setLine((int) dataArea.getMinX(), y, (int) dataArea.getMaxX(), y);
		} else {
			this.horizontalTraceLine = new Line2D.Float((int) dataArea.getMinX(), y, (int) dataArea.getMaxX(), y);
		}
		g2.draw(this.horizontalTraceLine);
	}

	// Reset to the default 'overwrite' mode
	g2.setPaintMode();
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:28,代码来源:AbstractChartPanel.java

示例8: drawRangeLine

import java.awt.geom.Line2D; //导入依赖的package包/类
/**
 * Utility method for drawing a line perpendicular to the range axis (used
 * for crosshairs).
 *
 * @param g2  the graphics device.
 * @param dataArea  the area defined by the axes.
 * @param value  the data value.
 * @param stroke  the line stroke (<code>null</code> not permitted).
 * @param paint  the line paint (<code>null</code> not permitted).
 */
protected void drawRangeLine(Graphics2D g2, Rectangle2D dataArea,
        double value, Stroke stroke, Paint paint) {

    double java2D = getRangeAxis().valueToJava2D(value, dataArea, 
            getRangeAxisEdge());
    Line2D line = null;
    if (this.orientation == PlotOrientation.HORIZONTAL) {
        line = new Line2D.Double(java2D, dataArea.getMinY(), java2D, 
                dataArea.getMaxY());
    }
    else if (this.orientation == PlotOrientation.VERTICAL) {
        line = new Line2D.Double(dataArea.getMinX(), java2D, 
                dataArea.getMaxX(), java2D);
    }
    g2.setStroke(stroke);
    g2.setPaint(paint);
    g2.draw(line);

}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:30,代码来源:CategoryPlot.java

示例9: drawAxisLine

import java.awt.geom.Line2D; //导入依赖的package包/类
/**
 * Draws an axis line at the current cursor position and edge.
 * 
 * @param g2  the graphics device.
 * @param cursor  the cursor position.
 * @param dataArea  the data area.
 * @param edge  the edge.
 */
protected void drawAxisLine(Graphics2D g2, double cursor,
        Rectangle2D dataArea, RectangleEdge edge) {
    
    Line2D axisLine = null;
    if (edge == RectangleEdge.TOP) {
        axisLine = new Line2D.Double(dataArea.getX(), cursor, dataArea.getMaxX(), cursor);  
    }
    else if (edge == RectangleEdge.BOTTOM) {
        axisLine = new Line2D.Double(dataArea.getX(), cursor, dataArea.getMaxX(), cursor);  
    }
    else if (edge == RectangleEdge.LEFT) {
        axisLine = new Line2D.Double(cursor, dataArea.getY(), cursor, dataArea.getMaxY());  
    }
    else if (edge == RectangleEdge.RIGHT) {
        axisLine = new Line2D.Double(cursor, dataArea.getY(), cursor, dataArea.getMaxY());  
    }
    g2.setPaint(this.axisLinePaint);
    g2.setStroke(this.axisLineStroke);
    g2.draw(axisLine);
    
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:30,代码来源:Axis.java

示例10: drawLeftLabel

import java.awt.geom.Line2D; //导入依赖的package包/类
/**
 * Draws a section label on the left side of the pie chart.
 * 
 * @param g2  the graphics device.
 * @param state  the state.
 * @param record  the label record.
 */
protected void drawLeftLabel(Graphics2D g2, PiePlotState state, PieLabelRecord record) {
    double theta = record.getAngle();
    double linkX = state.getPieCenterX() 
                   + Math.cos(theta) * state.getPieWRadius() * record.getLinkPercent();
    double linkY = state.getPieCenterY() 
                   - Math.sin(theta) * state.getPieHRadius() * record.getLinkPercent();
    double elbowX = state.getPieCenterX() 
                    + Math.cos(theta) * state.getLinkArea().getWidth() / 2.0;
    double elbowY = state.getPieCenterY() 
                    - Math.sin(theta) * state.getLinkArea().getHeight() / 2.0;
    double anchorX = state.getLinkArea().getMinX();
    double anchorY = elbowY;
    double targetX = anchorX - record.getGap();
    double targetY = record.getAllocatedY();
    g2.setPaint(this.labelLinkPaint);
    g2.setStroke(this.labelLinkStroke);
    g2.draw(new Line2D.Double(linkX, linkY, elbowX, elbowY));
    g2.draw(new Line2D.Double(anchorX, anchorY, elbowX, elbowY));
    g2.draw(new Line2D.Double(anchorX, anchorY, targetX, targetY));
    TextBox tb = record.getLabel();
    tb.draw(g2, (float) targetX, (float) targetY, RectangleAnchor.RIGHT);
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:30,代码来源:PiePlot.java

示例11: drawDomainGridlines

import java.awt.geom.Line2D; //导入依赖的package包/类
/**
 * Draws the gridlines for the plot, if they are visible.
 *
 * @param g2  the graphics device.
 * @param dataArea  the data area.
 * @param ticks  the ticks.
 */
protected void drawDomainGridlines(Graphics2D g2, Rectangle2D dataArea, 
                                   List ticks) {

    // draw the domain grid lines, if the flag says they're visible...
    if (isDomainGridlinesVisible()) {
        Iterator iterator = ticks.iterator();
        while (iterator.hasNext()) {
            ValueTick tick = (ValueTick) iterator.next();
            double v = this.domainAxis.valueToJava2D(tick.getValue(), 
                    dataArea, RectangleEdge.BOTTOM);
            Line2D line = new Line2D.Double(v, dataArea.getMinY(), v, 
                    dataArea.getMaxY());
            g2.setPaint(getDomainGridlinePaint());
            g2.setStroke(getDomainGridlineStroke());
            g2.draw(line);                
        }
    }
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:26,代码来源:FastScatterPlot.java

示例12: testEquals

import java.awt.geom.Line2D; //导入依赖的package包/类
/**
 * Confirm that the equals method can distinguish all the required fields.
 */
public void testEquals() {
    
    LegendItemCollection c1 = new LegendItemCollection();
    LegendItemCollection c2 = new LegendItemCollection();
    assertTrue(c1.equals(c2));
    assertTrue(c2.equals(c1));

    LegendItem item1 = new LegendItem("Label", "Description", 
            "ToolTip", "URL", true,  
            new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), true, Color.red, 
            true, Color.blue, new BasicStroke(1.2f), true, 
            new Line2D.Double(1.0, 2.0, 3.0, 4.0), 
            new BasicStroke(2.1f), Color.green);
    LegendItem item2 = new LegendItem("Label", "Description", 
            "ToolTip", "URL", true, 
            new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), 
            true, Color.red, true, Color.blue, new BasicStroke(1.2f), true, 
            new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f), 
            Color.green);
    c1.add(item1);
    c2.add(item2);
    assertTrue(c1.equals(c2));
    
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:28,代码来源:LegendItemCollectionTests.java

示例13: drawRangeLine

import java.awt.geom.Line2D; //导入依赖的package包/类
/**
 * Utility method for drawing a line perpendicular to the range axis (used for crosshairs).
 *
 * @param g2  the graphics device.
 * @param dataArea  the area defined by the axes.
 * @param value  the data value.
 * @param stroke  the line stroke.
 * @param paint  the line paint.
 */
protected void drawRangeLine(Graphics2D g2,
                             Rectangle2D dataArea,
                             double value, Stroke stroke, Paint paint) {

    double java2D = getRangeAxis().valueToJava2D(value, dataArea, getRangeAxisEdge());
    Line2D line = null;
    if (this.orientation == PlotOrientation.HORIZONTAL) {
        line = new Line2D.Double(java2D, dataArea.getMinY(), java2D, dataArea.getMaxY());
    }
    else if (this.orientation == PlotOrientation.VERTICAL) {
        line = new Line2D.Double(dataArea.getMinX(), java2D, dataArea.getMaxX(), java2D);
    }
    g2.setStroke(stroke);
    g2.setPaint(paint);
    g2.draw(line);

}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:27,代码来源:CategoryPlot.java

示例14: paint

import java.awt.geom.Line2D; //导入依赖的package包/类
public void paint(Graphics g) {
	 	Dimension d = this.getSize();
        super.paint(g);  // fixes the immediate problem.
        Graphics2D g2 = (Graphics2D) g;
        horizontalLine1 = new Line2D.Float(45, d.height-290, d.width - 45, d.height-290);
        verticalLine1 = new Line2D.Float(d.width/3+10, 100 , d.width/3+10, d.height - 325);
        verticalLine2 = new Line2D.Float((2*d.width)/3-10, 100 , (2*d.width)/3-10, d.height - 325);
        verticalLine3 = new Line2D.Float(d.width/3+10, 350 , d.width/3+10, d.height - 50);
        verticalLine4 = new Line2D.Float((2*d.width)/3-10, 350 , (2*d.width)/3-10, d.height - 50);

        //System.out.println("Height: "+d.height+"\tWidth: "+d.width);
        // (45, 267, 129, 20)
        //g2.setColor(Color.DARK_GRAY);
        g2.draw(horizontalLine1);
        g2.draw(verticalLine1);
        g2.draw(verticalLine2);
        g2.draw(verticalLine3);
        g2.draw(verticalLine4);
}
 
开发者ID:kevingilboy,项目名称:COE1186,代码行数:20,代码来源:TrainModelNewGUI.java

示例15: drawPolyline

import java.awt.geom.Line2D; //导入依赖的package包/类
/**
 * Draws a sequence of connected lines defined by
 * arrays of <i>x</i> and <i>y</i> coordinates.
 * Each pair of (<i>x</i>,&nbsp;<i>y</i>) coordinates defines a point.
 * The figure is not closed if the first point
 * differs from the last point.
 * @param       xPoints an array of <i>x</i> points
 * @param       yPoints an array of <i>y</i> points
 * @param       nPoints the total number of points
 * @see         java.awt.Graphics#drawPolygon(int[], int[], int)
 * @since       JDK1.1
 */
public void drawPolyline(int xPoints[], int yPoints[],
                         int nPoints) {
    float fromX;
    float fromY;
    float toX;
    float toY;

    if (nPoints > 0) {
        fromX = xPoints[0];
        fromY = yPoints[0];
        for(int i = 1; i < nPoints; i++) {
            toX = xPoints[i];
            toY = yPoints[i];
            draw(new Line2D.Float(fromX, fromY, toX, toY));
            fromX = toX;
            fromY = toY;
        }
    }

}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:33,代码来源:PathGraphics.java


注:本文中的java.awt.geom.Line2D类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。