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

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

Introduction

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

Prototype

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

Source Link

Document

Constructs and initializes a Rectangle2D from the specified double coordinates.

Usage

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

private void showSelection() {
    thePlot.clearAnnotations();//from  w ww . j  a  va 2 s  .c  o  m
    if (selected_peaks.size() > 0) {
        double width = screenToDataX(6.);
        double height = screenToDataY(6.);
        double margin = screenToDataY(8.);
        for (Peak p : selected_peaks) {
            // add annotation
            Shape shape = new Rectangle2D.Double(p.getMZ() - width / 2., p.getIntensity() - height / 2., width,
                    height);
            if (p.equals(current_peak)) {
                thePlot.addAnnotation(new XYShapeAnnotation(shape, new BasicStroke(2.f), Color.black));
                thePlot.addAnnotation(
                        new XYTextAnnotation(new java.text.DecimalFormat("0.0000").format(p.getMZ()), p.getMZ(),
                                p.getIntensity() + margin));
            } else
                thePlot.addAnnotation(new XYShapeAnnotation(shape, new BasicStroke(1.f), Color.black));
        }
    }
}

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

private void showSelection() {
    thePlot.clearAnnotations();//from ww w  .j a va 2s . co m
    if (selected_peaks.size() > 0) {
        double width = screenToDataX(6.);
        double height = screenToDataY(6.);
        double margin = screenToDataY(8.);
        for (Peak p : selected_peaks) {
            // add annotation
            Shape shape = new Rectangle2D.Double(p.getMZ() - width / 2., p.getIntensity() - height / 2., width,
                    height);
            if (p.equals(current_peak)) {
                thePlot.addAnnotation(new XYShapeAnnotation(shape, new BasicStroke(2.f), Color.blue));
                thePlot.addAnnotation(
                        new XYTextAnnotation(new java.text.DecimalFormat("0.0000").format(p.getMZ()), p.getMZ(),
                                p.getIntensity() + margin));
            } else
                thePlot.addAnnotation(new XYShapeAnnotation(shape, new BasicStroke(1.f), Color.black));
        }
    }
}

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

public void mouseDragged(MouseEvent e) {
    if (mouse_start_point != null && theDocument.size() > 0) {
        if (is_moving) {
            // moving
            double mz_delta = screenToDataX(mouse_start_point.getX() - e.getPoint().getX());
            if (mz_delta > 0.) {
                double old_upper_bound = thePlot.getDomainAxis().getUpperBound();
                double old_lower_bound = thePlot.getDomainAxis().getLowerBound();
                double new_upper_bound = Math.min(old_upper_bound + mz_delta, theDocument.getMaxMZ());
                double new_lower_bound = old_lower_bound + new_upper_bound - old_upper_bound;

                thePlot.getDomainAxis().setRange(new Range(new_lower_bound, new_upper_bound));
            } else {
                double old_upper_bound = thePlot.getDomainAxis().getUpperBound();
                double old_lower_bound = thePlot.getDomainAxis().getLowerBound();
                double new_lower_bound = Math.max(old_lower_bound + mz_delta, theDocument.getMinMZ());
                double new_upper_bound = old_upper_bound + new_lower_bound - old_lower_bound;

                thePlot.getDomainAxis().setRange(new Range(new_lower_bound, new_upper_bound));
            }//w w w.  j a v  a  2  s.c o m

            mouse_start_point = e.getPoint();
        } else {
            // zooming                
            Graphics2D g2 = (Graphics2D) theChartPanel.getGraphics();
            g2.setXORMode(java.awt.Color.gray);

            // delete old rectangle
            if (zoom_rectangle != null)
                g2.draw(zoom_rectangle);

            // create new rectangle
            double start_x = Math.min(e.getX(), mouse_start_point.getX());
            double end_x = Math.max(e.getX(), mouse_start_point.getX());

            Rectangle2D data_area = theChartPanel.getScreenDataArea((int) start_x,
                    (int) mouse_start_point.getY());
            double xmax = Math.min(end_x, data_area.getMaxX());
            zoom_rectangle = new Rectangle2D.Double(start_x, data_area.getMinY(), xmax - start_x,
                    data_area.getHeight());

            // draw new rectangle
            g2.draw(zoom_rectangle);
            g2.dispose();
        }
    }
}

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

public void mouseDragged(MouseEvent e) {
    if (mouse_start_point != null && theDocument.getNoScans() > 0) {
        if (is_moving) {
            // moving
            double mz_delta = screenToDataX(mouse_start_point.getX() - e.getPoint().getX());
            if (mz_delta > 0.) {
                double old_upper_bound = thePlot.getDomainAxis().getUpperBound();
                double old_lower_bound = thePlot.getDomainAxis().getLowerBound();
                double new_upper_bound = Math.min(old_upper_bound + mz_delta,
                        theDocument.getPeakDataAt(current_ind).getMaxMZ());
                double new_lower_bound = old_lower_bound + new_upper_bound - old_upper_bound;

                thePlot.getDomainAxis().setRange(new Range(new_lower_bound, new_upper_bound));
            } else {
                double old_upper_bound = thePlot.getDomainAxis().getUpperBound();
                double old_lower_bound = thePlot.getDomainAxis().getLowerBound();
                double new_lower_bound = Math.max(old_lower_bound + mz_delta,
                        theDocument.getPeakDataAt(current_ind).getMinMZ());
                double new_upper_bound = old_upper_bound + new_lower_bound - old_lower_bound;

                thePlot.getDomainAxis().setRange(new Range(new_lower_bound, new_upper_bound));
            }/* www. j a v a  2s  . c o m*/

            mouse_start_point = e.getPoint();
        } else {
            // zooming                
            Graphics2D g2 = (Graphics2D) theChartPanel.getGraphics();
            g2.setXORMode(java.awt.Color.gray);

            // delete old rectangle
            if (zoom_rectangle != null)
                g2.draw(zoom_rectangle);

            // create new rectangle
            double start_x = Math.min(e.getX(), mouse_start_point.getX());
            double end_x = Math.max(e.getX(), mouse_start_point.getX());

            Rectangle2D data_area = theChartPanel.getScreenDataArea((int) start_x,
                    (int) mouse_start_point.getY());
            double xmax = Math.min(end_x, data_area.getMaxX());
            zoom_rectangle = new Rectangle2D.Double(start_x, data_area.getMinY(), xmax - start_x,
                    data_area.getHeight());

            // draw new rectangle
            g2.draw(zoom_rectangle);
            g2.dispose();
        }
    }
}