Example usage for java.awt.geom Line2D getBounds

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

Introduction

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

Prototype

public Rectangle getBounds() 

Source Link

Usage

From source file:simulador.controle.GeradorGraficos.java

private Map<Float, Float> obterValoresCelulasRadial(Point pontoInicial, Point pontoFinal) {

    if (DEBUG) {//from w  w w .j  av a2 s.  c  om
        System.out.println("GeradorGraficos.obterValoresCelulasRadial");
    }

    // System.out.println("pontoInicial: ("+pontoInicial.x+", "+pontoInicial.y+")");
    // System.out.println("pontoFinal: ("+pontoFinal.x+", "+pontoFinal.y+")");
    float distanciaMaxPixels = (float) new Point(0, 0)
            .distance(new Point(painelDesign.getImagem().getWidth(), painelDesign.getImagem().getHeight()));
    float distanciaMaxMetros = (float) new Point2D.Float(0, 0)
            .distance(new Point2D.Float(ambiente.getLargura(), ambiente.getComprimento()));

    Map<Float, Float> valoresCelulasRadial = new HashMap();

    Line2D radial = new Line2D.Float(pontoInicial, pontoFinal);
    Rectangle boxRadial = radial.getBounds();

    int[] celRadialIncial = painelDesign.buscarCelula(new Point(boxRadial.x, boxRadial.y));
    int[] celRadialFinal = painelDesign
            .buscarCelula(new Point((int) boxRadial.getMaxX(), (int) boxRadial.getMaxY()));

    // System.out.println("celRadialInicial["+celRadialIncial[0]+"]["+celRadialIncial[1]+"]");
    // System.out.println("celRadialFinal["+celRadialFinal[0]+"]["+celRadialFinal[1]+"]");

    int linIncialRadial = celRadialIncial[0];
    int colIncialRadial = celRadialIncial[1];
    int linFinalRadial = celRadialFinal[0];
    int colFinalRadial = celRadialFinal[1];

    int[] coordCelPontoInicial = painelDesign.buscarCelula(pontoInicial);
    PainelDesign.Celula celPontoInicial = painelDesign.getMatrizCelulas().get(coordCelPontoInicial[0])
            .get(coordCelPontoInicial[1]);

    for (int i = linIncialRadial; i <= linFinalRadial; i++) {
        for (int j = colIncialRadial; j <= colFinalRadial; j++) {

            PainelDesign.Celula cel = painelDesign.getMatrizCelulas().get(i).get(j);

            //System.out.println("cel["+i+"]["+j+"]  interceptada ?");

            if (radial.intersects(cel)) {

                float distanciaPontosPixels = (float) new Point(celPontoInicial.x, celPontoInicial.y)
                        .distance(new Point(cel.x, cel.y));
                float distanciaPontosMetros = (float) ControladorDesign
                        .converterCoordenadas(distanciaPontosPixels, distanciaMaxPixels, distanciaMaxMetros);

                //System.out.println("sim");
                // System.out.println("potencia: "+cel.obterValor("potencia"));
                // System.out.println("distancia: "+distanciaPontosMetros);

                //cel.setCorFundoRGB(Color.BLUE.getRGB());

                valoresCelulasRadial.put(distanciaPontosMetros, //cel.obterValor("distancia"),
                        cel.obterValor("potencia"));

            }

        }
    }

    return valoresCelulasRadial;

}

From source file:com.att.aro.ui.view.diagnostictab.CreateBarPlot.java

public XYPlot drawYIntervalPlot() {
    // Create the plot renderer
    YIntervalRenderer renderer = new YIntervalRenderer() {
        private static final long serialVersionUID = 1L;

        public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea,
                PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis,
                XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) {

            // setup for collecting optional entity info...
            Shape entityArea = null;
            EntityCollection entities = null;
            if (info != null) {
                entities = info.getOwner().getEntityCollection();
            }/*from  w  w  w . ja  v a 2s.  c  om*/

            IntervalXYDataset intervalDataset = (IntervalXYDataset) dataset;

            double x = intervalDataset.getXValue(series, item);
            double yLow = intervalDataset.getStartYValue(series, item);
            double yHigh = intervalDataset.getEndYValue(series, item);

            RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
            RectangleEdge yAxisLocation = plot.getRangeAxisEdge();

            double xx = domainAxis.valueToJava2D(x, dataArea, xAxisLocation);
            double yyLow = rangeAxis.valueToJava2D(yLow, dataArea, yAxisLocation);
            double yyHigh = rangeAxis.valueToJava2D(yHigh, dataArea, yAxisLocation);

            Paint p = getItemPaint(series, item);
            Stroke s = getItemStroke(series, item);

            Line2D line = null;
            PlotOrientation orientation = plot.getOrientation();
            if (orientation == PlotOrientation.HORIZONTAL) {
                line = new Line2D.Double(yyLow, xx, yyHigh, xx);
            } else if (orientation == PlotOrientation.VERTICAL) {
                line = new Line2D.Double(xx, yyLow, xx, yyHigh);
            }
            g2.setPaint(p);
            g2.setStroke(s);
            g2.draw(line);

            // add an entity for the item...
            if (entities != null && line != null) {
                if (entityArea == null) {
                    entityArea = line.getBounds();
                }
                String tip = null;
                XYToolTipGenerator generator = getToolTipGenerator(series, item);
                if (generator != null) {
                    tip = generator.generateToolTip(dataset, series, item);
                }
                XYItemEntity entity = new XYItemEntity(entityArea, dataset, series, item, tip, null);
                entities.add(entity);
            }

        }

    };
    renderer.setAdditionalItemLabelGenerator(null);
    renderer.setBaseShape(new Rectangle());
    renderer.setAutoPopulateSeriesShape(false);
    renderer.setAutoPopulateSeriesPaint(false);
    renderer.setBasePaint(Color.GRAY);

    // Create the plot
    XYPlot plot = new XYPlot(null, null, new NumberAxis(), renderer);
    plot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);
    plot.getRangeAxis().setVisible(false);

    return plot;
}

From source file:com.att.aro.main.PacketPlots.java

/**
 * The utility method that creates the packet plots from a packet series map
 *//*from   w w w  .  j a va2  s  .c  om*/
private XYPlot createPlot() {

    // Create the plot renderer
    YIntervalRenderer renderer = new YIntervalRenderer() {
        private static final long serialVersionUID = 1L;

        public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea,
                PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis,
                XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) {

            // setup for collecting optional entity info...
            Shape entityArea = null;
            EntityCollection entities = null;
            if (info != null) {
                entities = info.getOwner().getEntityCollection();
            }

            IntervalXYDataset intervalDataset = (IntervalXYDataset) dataset;

            double x = intervalDataset.getXValue(series, item);
            double yLow = intervalDataset.getStartYValue(series, item);
            double yHigh = intervalDataset.getEndYValue(series, item);

            RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
            RectangleEdge yAxisLocation = plot.getRangeAxisEdge();

            double xx = domainAxis.valueToJava2D(x, dataArea, xAxisLocation);
            double yyLow = rangeAxis.valueToJava2D(yLow, dataArea, yAxisLocation);
            double yyHigh = rangeAxis.valueToJava2D(yHigh, dataArea, yAxisLocation);

            Paint p = getItemPaint(series, item);
            Stroke s = getItemStroke(series, item);

            Line2D line = null;
            PlotOrientation orientation = plot.getOrientation();
            if (orientation == PlotOrientation.HORIZONTAL) {
                line = new Line2D.Double(yyLow, xx, yyHigh, xx);
            } else if (orientation == PlotOrientation.VERTICAL) {
                line = new Line2D.Double(xx, yyLow, xx, yyHigh);
            }
            g2.setPaint(p);
            g2.setStroke(s);
            g2.draw(line);

            // add an entity for the item...
            if (entities != null) {
                if (entityArea == null) {
                    entityArea = line.getBounds();
                }
                String tip = null;
                XYToolTipGenerator generator = getToolTipGenerator(series, item);
                if (generator != null) {
                    tip = generator.generateToolTip(dataset, series, item);
                }
                XYItemEntity entity = new XYItemEntity(entityArea, dataset, series, item, tip, null);
                entities.add(entity);
            }

        }

    };
    renderer.setAdditionalItemLabelGenerator(null);
    renderer.setBaseShape(new Rectangle());
    renderer.setAutoPopulateSeriesShape(false);
    renderer.setAutoPopulateSeriesPaint(false);
    renderer.setBasePaint(Color.GRAY);

    // Create the plot
    XYPlot plot = new XYPlot(null, null, new NumberAxis(), renderer);
    plot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);
    plot.getRangeAxis().setVisible(false);

    return plot;
}

From source file:net.itransformers.topologyviewer.gui.GraphViewerPanel.java

public void EdgeAnimator(Pair edge) {

    Layout<String, String> layout = vv.getGraphLayout();
    String first = (String) edge.getFirst();
    String second = (String) edge.getSecond();
    Point2D q = layout.transform(first);
    Point2D y = layout.transform(second);
    Line2D line = new Line2D.Double(q.getX(), q.getY(), y.getX(), y.getY());

    Point2D lvc = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(vv.getCenter());
    final double dx = (lvc.getX() - line.getBounds().getCenterX()) / 10;
    final double dy = (lvc.getY() - line.getBounds().getCenterY()) / 10;
    Runnable edgeAnimator = new Runnable() {

        public void run() {
            for (int i = 0; i < 10; i++) {
                vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).translate(dx, dy);

                try {
                    Thread.sleep(100);
                } catch (InterruptedException ex) {
                }//ww  w.  jav a 2 s. c  o  m
            }
        }
    };
    Thread thread = new Thread(edgeAnimator);
    thread.start();
}