Example usage for java.awt.geom Line2D.Double Line2D.Double

List of usage examples for java.awt.geom Line2D.Double Line2D.Double

Introduction

In this page you can find the example usage for java.awt.geom Line2D.Double Line2D.Double.

Prototype

public Double(double x1, double y1, double x2, double y2) 

Source Link

Document

Constructs and initializes a Line2D from the specified coordinates.

Usage

From source file:dataminning2.Graphplot.java

protected void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    int w = getWidth();
    int h = getHeight();
    // Draw ordinate.
    g2.draw(new Line2D.Double(PAD, PAD, PAD, h - PAD));
    // Draw abcissa.
    g2.draw(new Line2D.Double(PAD, h - PAD, w - PAD, h - PAD));
    double xInc = (double) (w - 2 * PAD) / (data.length - 1);
    double scale = (double) (h - 2 * PAD) / 88;
    // Mark data points.
    g2.setPaint(Color.red);//from  w  w w .j a  v a2 s  . c  o  m
    int length1 = 0;
    int length2 = data.length / 3;
    for (int i = 0; i < length2; i++) {
        double x = PAD + i * dataX[i];
        double y = h - PAD - scale * dataY[i];
        g2.fill(new Ellipse2D.Double(x - 2, y - 2, 4, 4));
    }
    g2.setPaint(Color.BLUE);
    int lengthnew = length1 + length2;
    length2 = length2 + lengthnew;
    for (int i = lengthnew; i < length2; i++) {
        double x = PAD + i * dataX[i];
        double y = h - PAD - scale * dataY[i];
        g2.fill(new Ellipse2D.Double(x - 2, y - 2, 4, 4));
    }
    g2.setPaint(Color.YELLOW);
    lengthnew = lengthnew + lengthnew;
    for (int i = length2; i < data.length; i++) {
        double x = PAD + i * dataX[i];
        double y = h - PAD - scale * dataY[i];
        g2.fill(new Ellipse2D.Double(x - 2, y - 2, 4, 4));
    }
}

From source file:dataminning2.DBScanGraphplot.java

protected void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    int w = getWidth();
    int h = getHeight();
    // Draw ordinate.
    g2.draw(new Line2D.Double(PAD, PAD, PAD, h - PAD));
    // Draw abcissa.
    g2.draw(new Line2D.Double(PAD, h - PAD, w - PAD, h - PAD));
    double xInc = (double) (w - 2 * PAD) / (data.length - 1);
    double scale = (double) (h - 2 * PAD) / 88;
    // Mark data points.
    g2.setPaint(Color.red);/* w w w  .j  a  v  a  2 s.c om*/
    int length1 = 0;
    int length2 = data.length / 3;
    for (int i = 0; i < data.length; i++) {
        double x = PAD + i * dataX[i];
        double y = h - PAD - scale * dataY[i];
        g2.fill(new Ellipse2D.Double(x - 2, y - 2, 4, 4));
    }

}

From source file:dataminning2.KmeanGraphplot.java

protected void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    int w = getWidth();
    int h = getHeight();
    // Draw ordinate.
    g2.draw(new Line2D.Double(PAD, PAD, PAD, h - PAD));
    // Draw abcissa.
    g2.draw(new Line2D.Double(PAD, h - PAD, w - PAD, h - PAD));
    double xInc = (double) (w - 2 * PAD) / (data.length - 1);
    double scale = (double) (h - 2 * PAD) / 88;
    // Mark data points.

    g2.setPaint(Color.red);// w ww .j a  v  a 2s .  com

    for (int i = 0; i < cluster0.length; i++) {
        double x = PAD + i * dataX[i];
        double y = h - PAD - scale * dataY[i];
        g2.fill(new Ellipse2D.Double(x - 2, y - 2, 4, 4));
    }

    g2.setPaint(Color.BLUE);

    for (int i = 0; i < cluster1.length; i++) {
        double x = PAD + i * dataX[i];
        double y = h - PAD - scale * dataY[i];
        g2.fill(new Ellipse2D.Double(x - 2, y - 2, 4, 4));
    }
    g2.setPaint(Color.YELLOW);

    for (int i = 0; i < cluster2.length; i++) {
        double x = PAD + i * dataX[i];
        double y = h - PAD - scale * dataY[i];
        g2.fill(new Ellipse2D.Double(x - 2, y - 2, 4, 4));
    }
}

From source file:com.controlj.addon.gwttree.server.OpaqueBarRenderer3D.java

/**<!====== drawItem ======================================================>
   Draws a 3D bar to represent one data item.
   <!      Name       Description>
   @param  g2         the graphics device.
   @param  state      the renderer state.
   @param  dataArea   the area for plotting the data.
   @param  plot       the plot.//from   www  .j  a v a 2s .c  o  m
   @param  domainAxis the domain axis.
   @param  rangeAxis  the range axis.
   @param  dataset    the dataset.
   @param  row        the row index (zero-based).
   @param  column     the column index (zero-based).
   @param  pass       the pass index.
<!=======================================================================>*/
@Override
public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot,
        CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) {

    // check the value we are plotting...
    Number dataValue = dataset.getValue(row, column);
    if (dataValue == null) {
        return;
    }

    g2.setStroke(new BasicStroke(1));
    double value = dataValue.doubleValue();

    Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(), dataArea.getY() + getYOffset(),
            dataArea.getWidth() - getXOffset(), dataArea.getHeight() - getYOffset());

    PlotOrientation orientation = plot.getOrientation();

    double barW0 = calculateBarW0(plot, orientation, adjusted, domainAxis, state, row, column);
    double[] barL0L1 = calculateBarL0L1(value);
    if (barL0L1 == null) {
        return; // the bar is not visible
    }

    RectangleEdge edge = plot.getRangeAxisEdge();
    double transL0 = rangeAxis.valueToJava2D(barL0L1[0], adjusted, edge);
    double transL1 = rangeAxis.valueToJava2D(barL0L1[1], adjusted, edge);
    double barL0 = Math.min(transL0, transL1);
    double barLength = Math.abs(transL1 - transL0);

    // draw the bar...
    Rectangle2D bar = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        bar = new Rectangle2D.Double(barL0, barW0, barLength, state.getBarWidth());
    } else {
        bar = new Rectangle2D.Double(barW0, barL0, state.getBarWidth(), barLength);
    }
    Paint itemPaint = getItemPaint(row, column);
    if (itemPaint instanceof Color) {
        Color endColor = getFrontDark((Color) itemPaint);
        Color startColor = (Color) itemPaint;
        Paint paint = new GradientPaint((float) bar.getX(), (float) bar.getY(), startColor,
                (float) (bar.getX()), (float) (bar.getY() + bar.getHeight()), endColor);
        g2.setPaint(paint);
    }
    g2.fill(bar);

    double x0 = bar.getMinX(); // left
    double x1 = x0 + getXOffset(); // offset left
    double x2 = bar.getMaxX(); // right
    double x3 = x2 + getXOffset(); // offset right

    double y0 = bar.getMinY() - getYOffset(); // offset top
    double y1 = bar.getMinY(); // bar top
    double y2 = bar.getMaxY() - getYOffset(); // offset bottom
    double y3 = bar.getMaxY(); // bottom

    //Rectangle2D.Double line = new Rectangle2D.Double(x2, y1, 2, bar.getHeight());

    Line2D.Double line = new Line2D.Double(x2, y1, x2, y3);
    g2.draw(line);

    GeneralPath bar3dRight = null;
    GeneralPath bar3dTop = null;
    g2.setPaint(itemPaint);

    // Draw the right side
    if (barLength > 0.0) {
        bar3dRight = new GeneralPath();
        bar3dRight.moveTo((float) x2, (float) y3);
        bar3dRight.lineTo((float) x2, (float) y1);
        bar3dRight.lineTo((float) x3, (float) y0);
        bar3dRight.lineTo((float) x3, (float) y2);
        bar3dRight.closePath();

        if (itemPaint instanceof Color) {
            Color startColor = getSideLight((Color) itemPaint);
            Color endColor = getSideDark((Color) itemPaint);
            Paint paint = new GradientPaint((float) x3, (float) y0, startColor, (float) x2, (float) y3,
                    endColor);
            g2.setPaint(paint);
        }
        g2.fill(bar3dRight);
    }

    // Draw the top
    bar3dTop = new GeneralPath();
    bar3dTop.moveTo((float) x0, (float) y1); // bottom left
    bar3dTop.lineTo((float) x1, (float) y0); // top left
    bar3dTop.lineTo((float) x3, (float) y0); // top right
    bar3dTop.lineTo((float) x2, (float) y1); // bottom right
    bar3dTop.closePath();
    if (itemPaint instanceof Color) {
        Color endColor = getTopDark((Color) itemPaint);
        Color startColor = getTopLight((Color) itemPaint);
        //Paint paint = new GradientPaint((float)x2, (float)y0, startColor, (float)x0, (float)(y1), endColor);
        Point2D.Double topRight = new Point2D.Double(x3, y0);
        Point2D.Double bottomLeft = new Point2D.Double(x0, y1);
        //Point2D.Double darkEnd = getTargetPoint(bottomLeft, topRight, ((y0-y1)/(x3-x2)));
        Point2D.Double darkEnd = new Point2D.Double(x1, y0 - (x3 - x1) * ((y0 - y1) / (x3 - x2)));
        Paint paint = new GradientPaint((float) topRight.getX(), (float) topRight.getY(), startColor,
                (float) darkEnd.getX(), (float) darkEnd.getY(), endColor);
        g2.setPaint(paint);
        //drawMarker(topRight, g2, startColor);
    }
    g2.fill(bar3dTop);
    g2.setPaint(itemPaint);

    if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
        g2.setStroke(getItemOutlineStroke(row, column));
        g2.setPaint(getItemOutlinePaint(row, column));
        g2.draw(bar);
        if (bar3dRight != null) {
            g2.draw(bar3dRight);
        }
        if (bar3dTop != null) {
            g2.draw(bar3dTop);
        }
    }

    CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
    if (generator != null && isItemLabelVisible(row, column)) {
        drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0));
    }

    // add an item entity, if this information is being collected
    EntityCollection entities = state.getEntityCollection();
    if (entities != null) {
        GeneralPath barOutline = new GeneralPath();
        barOutline.moveTo((float) x0, (float) y3);
        barOutline.lineTo((float) x0, (float) y1);
        barOutline.lineTo((float) x1, (float) y0);
        barOutline.lineTo((float) x3, (float) y0);
        barOutline.lineTo((float) x3, (float) y2);
        barOutline.lineTo((float) x2, (float) y3);
        barOutline.closePath();
        addItemEntity(entities, dataset, row, column, barOutline);
    }

}

From source file:umontreal.iro.lecuyer.charts.XYLineChart.java

/**
 * Displays bar chart on the screen using Swing.
 *    This method creates an application containing a bar chart panel displaying
 *    the chart.  The created frame is positioned on-screen, and displayed before
 *    it is returned. The <TT>width</TT> and the <TT>height</TT>
 *    of the chart are measured in pixels.
 * /*from   www.j a  va 2s.co  m*/
 * @param width frame width in pixels.
 * 
 *    @param height frame height in pixels.
 * 
 *    @return frame containing the bar chart.;
 * 
 */
public JFrame viewBar(int width, int height) {
    JFrame myFrame;
    if (chart.getTitle() != null)
        myFrame = new JFrame("XYLineChart from SSJ: " + chart.getTitle().getText());
    else
        myFrame = new JFrame("XYLineChart from SSJ");

    XYPlot plot = (XYPlot) chart.getPlot();

    //Create the bar
    plot.setDataset(0, dataset.getSeriesCollection());
    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, true);
    renderer.setSeriesPaint(0, Color.ORANGE);
    renderer.setSeriesShape(0, new Line2D.Double(0, 0, 0, 1000));
    plot.setRenderer(0, renderer);

    //Create the points
    plot.setDataset(1, dataset.getSeriesCollection());
    final XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(false, true);
    renderer2.setSeriesPaint(0, Color.ORANGE);
    renderer2.setSeriesShape(0, new Ellipse2D.Double(-2.0, -2.0, 4.0, 4.0));
    plot.setRenderer(1, renderer2);

    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(width, height));
    myFrame.setContentPane(chartPanel);
    myFrame.pack();
    myFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    myFrame.setLocationRelativeTo(null);
    myFrame.setVisible(true);
    return myFrame;
}