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

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

Introduction

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

Prototype

public Double(double x, double y, double w, double h) 

Source Link

Document

Constructs and initializes an Ellipse2D from the specified coordinates.

Usage

From source file:sim.util.media.chart.ScatterPlotSeriesAttributes.java

static Shape[] buildShapes() {
    Shape[] s = new Shape[7];
    GeneralPath g = null;/*w  ww.j  a va2s  .  com*/

    // Circle
    s[0] = new Ellipse2D.Double(-3, -3, 6, 6);

    // Rectangle
    Rectangle2D.Double r = new Rectangle2D.Double(-3, -3, 6, 6);
    s[1] = r;

    // Diamond
    s[2] = AffineTransform.getRotateInstance(Math.PI / 4.0).createTransformedShape(r);

    // Cross +
    g = new GeneralPath();
    g.moveTo(-0.5f, -3);
    g.lineTo(-0.5f, -0.5f);
    g.lineTo(-3, -0.5f);
    g.lineTo(-3, 0.5f);
    g.lineTo(-0.5f, 0.5f);
    g.lineTo(-0.5f, 3);
    g.lineTo(0.5f, 3);
    g.lineTo(0.5f, 0.5f);
    g.lineTo(3, 0.5f);
    g.lineTo(3, -0.5f);
    g.lineTo(0.5f, -0.5f);
    g.lineTo(0.5f, -3);
    g.closePath();
    s[3] = g;

    // X 
    s[4] = g.createTransformedShape(AffineTransform.getRotateInstance(Math.PI / 4.0));

    // Up Triangle
    g = new GeneralPath();
    g.moveTo(0f, -3);
    g.lineTo(-3, 3);
    g.lineTo(3, 3);
    g.closePath();
    s[5] = g;

    // Down Triangle
    s[6] = g.createTransformedShape(AffineTransform.getRotateInstance(Math.PI));

    return s;
}

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);//  ww w  . j a v  a2 s .c  om
    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);/*from  ww w .  j av  a 2 s  .  co  m*/
    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  w  w  .  ja  v  a 2s  .c o  m*/

    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:DrawingApplet.java

public Shape createEllipse(double x, double y, double w, double h) {
    return new Ellipse2D.Double(x, y, w, h);
}

From source file:PointingMap.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, java.io.IOException {

    Connection conn = null;// w  w  w .jav  a  2  s  .  c o  m
    Statement stmt = null;
    ResultSet rs = null;
    ResultSetMetaData rsm = null;

    OutputStream out = response.getOutputStream();
    try {

        String dbHost = request.getParameter("dbHost");
        String dbName = request.getParameter("dbName");

        conn = connect(dbHost, dbName);

        // get & plot target catalog
        String targetCatQuery = "select " + "ra2000Hours, dec2000Deg " + "from TargetCat limit 200";

        stmt = conn.createStatement();
        rs = stmt.executeQuery(targetCatQuery);
        rsm = rs.getMetaData();
        //int colCount = rsm.getColumnCount();

        XYSeries series = new XYSeries("Target Catalog");
        int raColIndex = 1;
        int decColIndex = 2;
        while (rs.next()) {
            series.add(rs.getDouble(raColIndex), rs.getDouble(decColIndex));
        }

        XYDataset data = new XYSeriesCollection(series);
        stmt.close();

        // Get latest primary beam pointing position
        String latestPointingQuery = "select " + "actId, ts, " + "raHours, decDeg " + "from TscopePointReq "
                + "where atabeam = 'primary' " + "order by actId desc limit 1";

        stmt = conn.createStatement();
        rs = stmt.executeQuery(latestPointingQuery);
        rsm = rs.getMetaData();
        //int colCount = rsm.getColumnCount();

        int actId = -1;
        String timeString = "";
        double pointingRaHours = -1;
        double pointingDecDeg = -1;

        int actIdIndex = 1;
        int timeIndex = 2;
        raColIndex = 3;
        decColIndex = 4;

        while (rs.next()) {
            actId = rs.getInt(actIdIndex);
            timeString = rs.getString(timeIndex);
            pointingRaHours = rs.getDouble(raColIndex);
            pointingDecDeg = rs.getDouble(decColIndex);
        }

        String plotTitle = "ATA Primary Pointing" + " (Act Id: " + actId + ")" + " " + timeString;

        JFreeChart chart = ChartFactory.createScatterPlot(plotTitle, "RA (Hours)", // x-axis label
                "Dec (Deg)", // y axis label
                data, PlotOrientation.VERTICAL, false, // legend 
                true, // tooltips
                false // urls
        );

        // plot RA hours with higher values to the left
        //chart.getXYPlot().getDomainAxis().setInverted(true);
        chart.getXYPlot().getDomainAxis().setLowerBound(-1);
        chart.getXYPlot().getDomainAxis().setUpperBound(25);

        // increase axis label fonts for better readability
        Font axisFont = new Font("Serif", Font.BOLD, 14);
        chart.getXYPlot().getDomainAxis().setLabelFont(axisFont);
        chart.getXYPlot().getDomainAxis().setTickLabelFont(axisFont);
        chart.getXYPlot().getRangeAxis().setLabelFont(axisFont);
        chart.getXYPlot().getRangeAxis().setTickLabelFont(axisFont);

        // show current pointing as crosshairs
        chart.getXYPlot().setDomainCrosshairValue(pointingRaHours);
        chart.getXYPlot().setRangeCrosshairValue(pointingDecDeg);
        chart.getXYPlot().setDomainCrosshairVisible(true);
        chart.getXYPlot().setRangeCrosshairVisible(true);
        chart.getXYPlot().setDomainCrosshairPaint(Color.BLACK);
        chart.getXYPlot().setRangeCrosshairPaint(Color.BLACK);

        Stroke stroke = new BasicStroke(2);
        chart.getXYPlot().setDomainCrosshairStroke(stroke);
        chart.getXYPlot().setRangeCrosshairStroke(stroke);

        // set hat creek dec range
        chart.getXYPlot().getRangeAxis().setLowerBound(-40);
        chart.getXYPlot().getRangeAxis().setUpperBound(90);

        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) chart.getXYPlot().getRenderer();
        int seriesIndex = 0;
        renderer.setSeriesPaint(seriesIndex, Color.BLUE);

        Shape circularShape = new Ellipse2D.Double(-1.0, -1.0, 1.2, 1.2);
        renderer.setSeriesShape(seriesIndex, circularShape);

        // Default shape [0-9]: 0=square 1=circle 2=uptriangle 3=diamond...
        //renderer.setShape(DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE[1]);
        response.setContentType("image/png");
        int width = 800;
        int height = 600;
        ChartUtilities.writeChartAsPNG(out, chart, width, height);

    } catch (Exception e) {
        throw new ServletException(e);
    } finally {

        try {
            if (stmt != null) {
                stmt.close();
            }

            if (conn != null) {
                conn.close();
            }

        } catch (SQLException sql) {
        }

    }

}

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

private void drawMarker(Point2D.Double point, Graphics2D g2, Color color) {
    Stroke oldStroke = g2.getStroke();
    Paint oldPaint = g2.getPaint();
    g2.setPaint(color);//from w ww  .  j av a 2s .  c  o m
    //Shape line = new Line2D.Double(point, point);
    Shape marker = new Ellipse2D.Double(point.getX() - 1.5, point.getY() - 1.5, 3, 3);
    g2.fill(marker);
    g2.setPaint(oldPaint);
}

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.
 * /* w  w  w.  ja v a2 s.c  o  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;
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.PeakListChartPanel.java

public void addIsotopeCurves(TreeMap<Peak, Collection<Annotation>> annotations) {

    if (theDocument.size() == 0)
        return;//from  w w w.j a  v a2  s  .  co  m

    // remove old curves
    removeIsotopeCurves();

    // add curves
    if (annotations != null) {

        // set renderer
        if (show_all_isotopes) {
            thePlot.setRenderer(1, new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES));
            thePlot.getRenderer(1).setShape(new Ellipse2D.Double(0, 0, 7, 7));
        } else
            thePlot.setRenderer(1, new StandardXYItemRenderer(StandardXYItemRenderer.LINES));

        MSUtils.IsotopeList isotope_list = new MSUtils.IsotopeList(show_all_isotopes);
        for (Map.Entry<Peak, Collection<Annotation>> pa : annotations.entrySet()) {
            Peak p = pa.getKey();

            // get compositions
            HashSet<Molecule> compositions = new HashSet<Molecule>();
            for (Annotation a : pa.getValue()) {
                try {
                    compositions.add(a.getFragmentEntry().fragment.computeIon());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            // collect curves for this peak
            HashMap<String, double[][]> all_curves = new HashMap<String, double[][]>();
            for (Molecule m : compositions) {
                try {
                    double[][] data = MSUtils.getIsotopesCurve(1, m, show_all_isotopes);
                    // overlay the distribution with the existing list of isotopes
                    isotope_list.adjust(data, p.getMZ(), p.getIntensity());

                    all_curves.put(m.toString(), data);
                } catch (Exception e) {
                    LogUtils.report(e);
                }
            }

            // add average curve for this peak
            if (all_curves.size() > 1) {
                double[][] data = MSUtils.average(all_curves.values(), show_all_isotopes);
                // add the average to the chart
                String name = "average-" + p.getMZ();
                theIsotopesDataset.addSeries(name, data);
                thePlot.getRenderer(1).setSeriesPaint(theIsotopesDataset.indexOf(name), Color.magenta);
                thePlot.getRenderer(1).setSeriesStroke(theIsotopesDataset.indexOf(name), new BasicStroke(2));

                // add the average to the isotope list
                isotope_list.add(data, false);
            } else if (all_curves.size() == 1) {
                // add the only curve to the isotope list
                isotope_list.add(all_curves.values().iterator().next(), false);
            }

            // add the other curves
            for (Map.Entry<String, double[][]> e : all_curves.entrySet()) {
                String name = e.getKey() + "-" + p.getMZ();
                theIsotopesDataset.addSeries(name, e.getValue());
                thePlot.getRenderer(1).setSeriesPaint(theIsotopesDataset.indexOf(name), Color.blue);
            }
        }
    }
    updateIntensityAxis();
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.SpectraPanel.java

public void addIsotopeCurves(TreeMap<Peak, Collection<Annotation>> annotations) {

    if (theDocument.size() == 0)
        return;/*from   ww  w  .  ja v  a  2s  .com*/

    // remove old curves
    removeIsotopeCurves();

    // add curves
    if (annotations != null) {

        // set renderer
        if (show_all_isotopes) {
            thePlot.setRenderer(1, new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES));
            thePlot.getRenderer(1).setShape(new Ellipse2D.Double(0, 0, 7, 7));
        } else
            thePlot.setRenderer(1, new StandardXYItemRenderer(StandardXYItemRenderer.LINES));

        MSUtils.IsotopeList isotope_list = new MSUtils.IsotopeList(show_all_isotopes);
        for (Map.Entry<Peak, Collection<Annotation>> pa : annotations.entrySet()) {
            Peak p = pa.getKey();
            double[] best_peak = theDocument.getPeakDataAt(current_ind).findNearestPeak(p.getMZ());

            // get compositions
            HashSet<Molecule> compositions = new HashSet<Molecule>();
            for (Annotation a : pa.getValue()) {
                try {
                    compositions.add(a.getFragmentEntry().fragment.computeIon());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            // collect curves for this peak
            HashMap<String, double[][]> all_curves = new HashMap<String, double[][]>();
            for (Molecule m : compositions) {
                try {
                    double[][] data = MSUtils.getIsotopesCurve(1, m, show_all_isotopes);

                    // overlay the distribution with the existing list of isotopes
                    isotope_list.adjust(data, best_peak[0], best_peak[1]);

                    all_curves.put(m.toString(), data);
                } catch (Exception e) {
                    LogUtils.report(e);
                }
            }

            // add average curve for this peak
            if (all_curves.size() > 1) {
                double[][] data = MSUtils.average(all_curves.values(), show_all_isotopes);

                // add the average to the chart
                String name = "average-" + p.getMZ();
                theIsotopesDataset.addSeries(name, data);
                thePlot.getRenderer(1).setSeriesPaint(theIsotopesDataset.indexOf(name), Color.magenta);
                thePlot.getRenderer(1).setSeriesStroke(theIsotopesDataset.indexOf(name), new BasicStroke(2));

                // add the average to the isotope list
                isotope_list.add(data, false);
            } else if (all_curves.size() == 1) {
                // add the only curve to the isotope list
                isotope_list.add(all_curves.values().iterator().next(), false);
            }

            // add the other curves
            for (Map.Entry<String, double[][]> e : all_curves.entrySet()) {
                String name = e.getKey() + "-" + p.getMZ();
                theIsotopesDataset.addSeries(name, e.getValue());
                thePlot.getRenderer(1).setSeriesPaint(theIsotopesDataset.indexOf(name), Color.blue);
            }
        }

    }
    updateIntensityAxis();
}