Example usage for java.awt Graphics2D setTransform

List of usage examples for java.awt Graphics2D setTransform

Introduction

In this page you can find the example usage for java.awt Graphics2D setTransform.

Prototype

public abstract void setTransform(AffineTransform Tx);

Source Link

Document

Overwrites the Transform in the Graphics2D context.

Usage

From source file:org.nekorp.workflow.desktop.servicio.reporte.orden.servicio.OrdenServicioDataFactory.java

private void generaImagenDamage(ShapeView fondo, List<DamageDetailsVB> danios, File outputfile, int width,
        int height) {
    try {//from w ww.ja  v a2s.  c  om
        Point contexto = new Point((width - fondo.getShapeWidth()) / 2, (height - fondo.getShapeHeight()) / 2);
        BufferedImage off_Image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = off_Image.createGraphics();
        g2.setColor(Color.WHITE);
        g2.fillRect(0, 0, width, height);
        AffineTransform saveXform = g2.getTransform();
        AffineTransform toCenterAt = new AffineTransform();
        toCenterAt.translate(contexto.getX(), contexto.getY());
        g2.transform(toCenterAt);
        fondo.paint(g2);
        g2.setTransform(saveXform);
        for (DamageDetailsVB x : danios) {
            DamageDetailGraphicsView obj = new DamageDetailGraphicsView();
            obj.setPosicion(new Point(x.getX(), x.getY()));
            obj.setContexto(contexto);
            if (x.getX() <= fondo.getShapeWidth() / 2) {
                if (x.getY() <= fondo.getShapeHeight() / 2) {
                    obj.setOrientacion(DamageDetailGraphicsView.SuperiorIzquierda);
                } else {
                    obj.setOrientacion(DamageDetailGraphicsView.InferiorIzquierda);
                }
            } else {
                if (x.getY() <= fondo.getShapeHeight() / 2) {
                    obj.setOrientacion(DamageDetailGraphicsView.SuperiorDerecha);
                } else {
                    obj.setOrientacion(DamageDetailGraphicsView.InferiorDerecha);
                }
            }
            obj.setCategoria(x.getCategoria());
            obj.setCaracteristica(x.getCaracteristica());
            obj.paint(g2);
        }
        saveJPG(off_Image, outputfile);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:WorldMapGraphDemo.java

/**
 * create an instance of a simple graph with controls to
 * demo the zoom features./*from w w  w .j ava 2 s.  co  m*/
 * 
 */
public WorldMapGraphDemo() {
    setLayout(new BorderLayout());

    map.put("TYO", new String[] { "35 40 N", "139 45 E" });
    map.put("PEK", new String[] { "39 55 N", "116 26 E" });
    map.put("MOW", new String[] { "55 45 N", "37 42 E" });
    map.put("JRS", new String[] { "31 47 N", "35 13 E" });
    map.put("CAI", new String[] { "30 03 N", "31 15 E" });
    map.put("CPT", new String[] { "33 55 S", "18 22 E" });
    map.put("PAR", new String[] { "48 52 N", "2 20 E" });
    map.put("LHR", new String[] { "51 30 N", "0 10 W" });
    map.put("HNL", new String[] { "21 18 N", "157 51 W" });
    map.put("NYC", new String[] { "40 77 N", "73 98 W" });
    map.put("SFO", new String[] { "37 62 N", "122 38 W" });
    map.put("AKL", new String[] { "36 55 S", "174 47 E" });
    map.put("BNE", new String[] { "27 28 S", "153 02 E" });
    map.put("HKG", new String[] { "22 15 N", "114 10 E" });
    map.put("KTM", new String[] { "27 42 N", "85 19 E" });
    map.put("IST", new String[] { "41 01 N", "28 58 E" });
    map.put("STO", new String[] { "59 20 N", "18 03 E" });
    map.put("RIO", new String[] { "22 54 S", "43 14 W" });
    map.put("LIM", new String[] { "12 03 S", "77 03 W" });
    map.put("YTO", new String[] { "43 39 N", "79 23 W" });

    cityList = new ArrayList<String>(map.keySet());

    // create a simple graph for the demo
    graph = new DirectedSparseMultigraph<String, Number>();
    createVertices();
    createEdges();

    ImageIcon mapIcon = null;
    String imageLocation = "/images/political_world_map.jpg";
    try {
        mapIcon = new ImageIcon(getClass().getResource(imageLocation));
    } catch (Exception ex) {
        System.err.println("Can't load \"" + imageLocation + "\"");
    }
    final ImageIcon icon = mapIcon;

    Dimension layoutSize = new Dimension(2000, 1000);

    Layout<String, Number> layout = new StaticLayout<String, Number>(graph,
            new ChainedTransformer(new Transformer[] { new CityTransformer(map),
                    new LatLonPixelTransformer(new Dimension(2000, 1000)) }));

    layout.setSize(layoutSize);
    vv = new VisualizationViewer<String, Number>(layout, new Dimension(800, 400));

    if (icon != null) {
        vv.addPreRenderPaintable(new VisualizationViewer.Paintable() {
            public void paint(Graphics g) {
                Graphics2D g2d = (Graphics2D) g;
                AffineTransform oldXform = g2d.getTransform();
                AffineTransform lat = vv.getRenderContext().getMultiLayerTransformer()
                        .getTransformer(Layer.LAYOUT).getTransform();
                AffineTransform vat = vv.getRenderContext().getMultiLayerTransformer()
                        .getTransformer(Layer.VIEW).getTransform();
                AffineTransform at = new AffineTransform();
                at.concatenate(g2d.getTransform());
                at.concatenate(vat);
                at.concatenate(lat);
                g2d.setTransform(at);
                g.drawImage(icon.getImage(), 0, 0, icon.getIconWidth(), icon.getIconHeight(), vv);
                g2d.setTransform(oldXform);
            }

            public boolean useTransform() {
                return false;
            }
        });
    }

    vv.getRenderer().setVertexRenderer(new GradientVertexRenderer<String, Number>(Color.white, Color.red,
            Color.white, Color.blue, vv.getPickedVertexState(), false));

    // add my listeners for ToolTips
    vv.setVertexToolTipTransformer(new ToStringLabeller());
    vv.setEdgeToolTipTransformer(new Transformer<Number, String>() {
        public String transform(Number edge) {
            return "E" + graph.getEndpoints(edge).toString();
        }
    });

    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
    vv.getRenderer().getVertexLabelRenderer().setPositioner(new InsidePositioner());
    vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.AUTO);

    final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv);
    add(panel);
    final AbstractModalGraphMouse graphMouse = new DefaultModalGraphMouse();
    vv.setGraphMouse(graphMouse);

    vv.addKeyListener(graphMouse.getModeKeyListener());
    vv.setToolTipText("<html><center>Type 'p' for Pick mode<p>Type 't' for Transform mode");

    final ScalingControl scaler = new CrossoverScalingControl();

    //        vv.scaleToLayout(scaler);

    JButton plus = new JButton("+");
    plus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1.1f, vv.getCenter());
        }
    });
    JButton minus = new JButton("-");
    minus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1 / 1.1f, vv.getCenter());
        }
    });

    JButton reset = new JButton("reset");
    reset.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).setToIdentity();
            vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW).setToIdentity();
        }
    });

    JPanel controls = new JPanel();
    controls.add(plus);
    controls.add(minus);
    controls.add(reset);
    add(controls, BorderLayout.SOUTH);
}

From source file:GrafosTroleBus.java

public GrafosTroleBus() {
    setLayout(new BorderLayout());

    //definir puntos de trolebus (latitude y longitude) @autor sa

    map.put("RECREO", new String[] { "-0.2516682", "-78.521524" }); //Recreo                       
    map.put("P14", new String[] { "-0.2445098", "-78.51902" }); //Villaflora
    map.put("P15", new String[] { "-0.2396436", "-78.51698" }); //Chimbacalle N-S                      
    map.put("P16", new String[] { "-0.2378458", "-78.515976" }); //Chimbacalle S-N
    map.put("P17", new String[] { "-0.2356805", "-78.514816" }); //Colina
    map.put("P18", new String[] { "-0.234052", "-78.514237" }); //Jefferson Perez
    map.put("P19", new String[] { "-0.2312856", "-78.513627" }); //Recoleta N-S        
    map.put("P20", new String[] { "-0.2307005", "-78.513051" }); //Recoleta S-N
    map.put("P21", new String[] { "-0.2263919", "-78.513011" }); //P21 Cumanda N-S
    map.put("P22", new String[] { "-0.226424", "-78.512803" }); //P22 Cumanda S-N
    map.put("P23", new String[] { "-0.2234658", "-78.512542" }); //P23 Santo Domingo
    map.put("P24", new String[] { "-0.2185857", "-78.508601" }); //P24 Plaza del Teatro N-S
    map.put("P25", new String[] { "-0.219605", "-78.50813" }); //P25 Plaza del Teatro S-N        
    map.put("P26", new String[] { "-0.2177808", "-78.505977" }); //P26 Hermano Miguel
    map.put("P27", new String[] { "-0.2169088", "-78.50521" }); //P27 Banco Central
    map.put("P28", new String[] { "-0.214267", "-78.502999" }); //P28 La Alameda S-N
    map.put("P29", new String[] { "-0.2137705", "-78.50293" }); //P29 La Alameda N-S                       
    map.put("P30", new String[] { "-0.2084939", "-78.500255" }); //P30 Ejido N-S
    map.put("P31", new String[] { "-0.2088076", "-78.500032" }); //P31 Ejido S-N
    map.put("P32", new String[] { "-0.2047989", "-78.4988" }); //P32 La Mariscal N-S
    map.put("P33", new String[] { "-0.2041972", "-78.498491" }); //P33 La Mariscal S-N
    map.put("P34", new String[] { "-0.2009718", "-78.49715" }); //P34 Santa Clara S-N
    map.put("P35", new String[] { "-0.201056", "-78.496979" }); //P35 Santa Clara N-S
    map.put("P36", new String[] { "-0.1986325", "-78.496141" }); //P36 La Colon S-N
    map.put("P37", new String[] { "-0.1978432", "-78.495563" }); //P37 La Colon N-S
    map.put("P38", new String[] { "-0.1921587", "-78.493445" }); //P38 Cuero y Caicedo S-N
    map.put("P39", new String[] { "-0.1915098", "-78.493001" }); //P39 Cuero y Caicedo N-S                        
    map.put("P40", new String[] { "-0.1889467", "-78.492149" }); //P40 Mariana de Jess S-N
    map.put("P41", new String[] { "-0.1875567", "-78.491303" }); //P41 Mariana de Jesus N-S
    map.put("P42", new String[] { "-0.1853693", "-78.490878" }); //P42 El Floron S-N
    map.put("P43", new String[] { "-0.1846687", "-78.490403" }); //P43 El Floron N-S        
    map.put("P44", new String[] { "-0.1817679", "-78.489808" }); //P44 Carolina S-N
    map.put("P45", new String[] { "-0.1810849", "-78.489336" }); //P45 Carolina N-S
    map.put("P46", new String[] { "-0.1787274", "-78.488954" }); //P46 Estadio S-N
    map.put("P47", new String[] { "-0.1780172", "-78.488621" }); //P47 Estadio N-S
    map.put("P48", new String[] { "-0.172087", "-78.487589" }); //P48 La Y S-N
    map.put("P49", new String[] { "-0.1713146", "-78.487277" }); //P49 La Y N-S        
    map.put("LA Y", new String[] { "-0.1635504", "-78.485374" }); //Estacin La Y                              

    nodoList = new ArrayList<String>(map.keySet());

    // create a simple graph for the demo        
    graph = new DirectedSparseMultigraph<String, Number>();
    createVertices();// w  w w.  j  ava  2  s . co  m
    createEdges();

    ImageIcon mapIcon = null;
    String imageLocation = "/mapa_quito.png";

    try {
        mapIcon = new ImageIcon(getClass().getResource(imageLocation));

        ImageWidth = mapIcon.getIconWidth();
        ImageHeight = mapIcon.getIconHeight();

    } catch (Exception ex) {
        System.err.println("Can't load \"" + imageLocation + "\"");
    }

    final ImageIcon icon = mapIcon;

    Dimension layoutSize = new Dimension(ImageWidth, ImageHeight);

    Layout<String, Number> layout = new StaticLayout<String, Number>(graph,
            new ChainedTransformer<String, Point2D>(new Transformer[] { new CityTransformer(map),
                    new LatLonPixelTransformer(new Dimension(ImageWidth, ImageHeight)) }));

    layout.setSize(layoutSize);
    vv = new VisualizationViewer<String, Number>(layout, new Dimension(MonitorWidth, MonitorHeight));

    if (icon != null) {
        vv.addPreRenderPaintable(new VisualizationViewer.Paintable() {
            public void paint(Graphics g) {
                Graphics2D g2d = (Graphics2D) g;
                AffineTransform oldXform = g2d.getTransform();
                AffineTransform lat = vv.getRenderContext().getMultiLayerTransformer()
                        .getTransformer(Layer.LAYOUT).getTransform();
                AffineTransform vat = vv.getRenderContext().getMultiLayerTransformer()
                        .getTransformer(Layer.VIEW).getTransform();
                AffineTransform at = new AffineTransform();
                at.concatenate(g2d.getTransform());
                at.concatenate(vat);
                at.concatenate(lat);
                g2d.setTransform(at);
                g.drawImage(icon.getImage(), 0, 0, icon.getIconWidth(), icon.getIconHeight(), vv);
                g2d.setTransform(oldXform);
            }

            public boolean useTransform() {
                return false;
            }
        });
    }

    vv.getRenderer().setVertexRenderer(new GradientVertexRenderer<String, Number>(Color.white, Color.red,
            Color.white, Color.blue, vv.getPickedVertexState(), false));

    // add my listeners for ToolTips
    vv.setVertexToolTipTransformer(new ToStringLabeller<String>());
    vv.setEdgeToolTipTransformer(new Transformer<Number, String>() {
        public String transform(Number edge) {
            return "E" + graph.getEndpoints(edge).toString();
        }
    });

    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<String>());
    vv.getRenderer().getVertexLabelRenderer().setPositioner(new InsidePositioner());
    vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.AUTO);

    final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv);
    add(panel);
    final AbstractModalGraphMouse graphMouse = new DefaultModalGraphMouse<Object, Object>();
    vv.setGraphMouse(graphMouse);

    vv.addKeyListener(graphMouse.getModeKeyListener());
    vv.setToolTipText("<html><center>Type 'p' for Pick mode<p>Type 't' for Transform mode");

    final ScalingControl scaler = new CrossoverScalingControl();

    vv.scaleToLayout(scaler);

    JButton plus = new JButton("+");
    plus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1.1f, vv.getCenter());
        }
    });
    JButton minus = new JButton("-");
    minus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1 / 1.1f, vv.getCenter());
        }
    });

    JButton reset = new JButton("reset");
    reset.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).setToIdentity();
            vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW).setToIdentity();
        }
    });

    JPanel controls = new JPanel();
    controls.add(plus);
    controls.add(minus);
    controls.add(reset);
    add(controls, BorderLayout.SOUTH);
}

From source file:HelloUniverse.java

private void drawZPip(Graphics2D g2, float zAngle) {
    AffineTransform trans = new AffineTransform();
    Color origColor = g2.getColor();

    trans.translate(margin, margin);/*from  w w  w.  j  a  v  a 2s.c  o  m*/
    trans.rotate(zAngle, diameter / 2, diameter / 2);

    g2.setXORMode(getBackground());
    g2.setTransform(trans);
    g2.setColor(Color.red);
    g2.fillPolygon(zPip);

    // Reset graphics context
    trans.setToIdentity();
    g2.setTransform(trans);
    g2.setColor(origColor);
    g2.setPaintMode();
}

From source file:com.net2plan.gui.utils.topologyPane.jung.JUNGCanvas.java

public void updateBackgroundImage(final ImageIcon icon, final int x, final int y) {
    if (paintableAssociatedToBackgroundImage != null)
        vv.removePreRenderPaintable(paintableAssociatedToBackgroundImage);
    paintableAssociatedToBackgroundImage = null;
    if (icon != null) {
        this.paintableAssociatedToBackgroundImage = new VisualizationViewer.Paintable() {
            public void paint(Graphics g) {
                Graphics2D g2d = (Graphics2D) g;
                AffineTransform oldXform = g2d.getTransform();
                AffineTransform lat = vv.getRenderContext().getMultiLayerTransformer()
                        .getTransformer(Layer.LAYOUT).getTransform();
                AffineTransform vat = vv.getRenderContext().getMultiLayerTransformer()
                        .getTransformer(Layer.VIEW).getTransform();
                AffineTransform at = new AffineTransform();
                at.concatenate(g2d.getTransform());
                at.concatenate(vat);/*from   w w w .  j ava 2s  . c om*/
                at.concatenate(lat);
                g2d.setTransform(at);
                g.drawImage(icon.getImage(), x, y, icon.getIconWidth(), icon.getIconHeight(), vv);
                g2d.setTransform(oldXform);
            }

            public boolean useTransform() {
                return false;
            }
        };
        vv.addPreRenderPaintable(paintableAssociatedToBackgroundImage);
    }
}

From source file:com.liusoft.dlog4j.action.PhotoAction.java

/**
 * //ww  w . jav a 2  s  .c  o m
 * @param ctx
 * @param imgURL
 * @param orient
 * @return
 * @throws IOException
 */
protected boolean rotate(HttpContext ctx, String imgURL, int orient) throws IOException {
    PhotoSaver saver = this.getPhotoSaver();
    InputStream inImg = saver.read(ctx, imgURL);
    BufferedImage old_img = (BufferedImage) ImageIO.read(inImg);
    int width = old_img.getWidth();
    int height = old_img.getHeight();
    BufferedImage new_img = new BufferedImage(height, width, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = new_img.createGraphics();

    AffineTransform origXform = g2d.getTransform();
    AffineTransform newXform = (AffineTransform) (origXform.clone());
    // center of rotation is center of the panel
    double radian = 0;
    double xRot = 0;
    double yRot = 0;
    switch (orient) {
    case 3:
        radian = 180.0;
        xRot = width / 2.0;
        yRot = height / 2.0;
    case 6:
        radian = 90.0;
        xRot = height / 2.0;
        yRot = xRot;
        break;
    case 8:
        radian = 270.0;
        xRot = width / 2.0;
        yRot = xRot;
        break;
    default:
        return false;
    }
    newXform.rotate(Math.toRadians(radian), xRot, yRot);

    g2d.setTransform(newXform);
    // draw image centered in panel
    g2d.drawImage(old_img, 0, 0, null);
    // Reset to Original
    g2d.setTransform(origXform);
    OutputStream out = saver.write(ctx, imgURL);
    try {
        ImageIO.write(new_img, "JPG", out);
    } finally {
        out.close();
    }
    return true;
}

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.link_and_brush.LinkAndBrushChartPanel.java

@Override
public void paintComponent(Graphics g) {
    super.paintComponent(g);
    if (getChart() == null) {
        return;/*from   w  ww . ja  v  a  2  s  . co  m*/
    }
    Graphics2D g2 = (Graphics2D) g.create();

    // first determine the size of the chart rendering area...
    Dimension size = getSize();
    Insets insets = getInsets();
    Rectangle2D available = new Rectangle2D.Double(insets.left, insets.top,
            size.getWidth() - insets.left - insets.right, size.getHeight() - insets.top - insets.bottom);

    // work out if scaling is required...
    boolean scale = false;
    double drawWidth = available.getWidth();
    double drawHeight = available.getHeight();
    setChartFieldValue(getChartFieldByName("scaleX"), 1.0);
    // this.scaleX = 1.0;
    setChartFieldValue(getChartFieldByName("scaleY"), 1.0);
    // this.scaleY = 1.0;

    if (drawWidth < getMinimumDrawWidth()) {
        setChartFieldValue(getChartFieldByName("scaleX"), drawWidth / getMinimumDrawWidth());
        // this.scaleX = drawWidth / getMinimumDrawWidth();
        drawWidth = getMinimumDrawWidth();
        scale = true;
    } else if (drawWidth > getMaximumDrawWidth()) {
        setChartFieldValue(getChartFieldByName("scaleX"), drawWidth / getMaximumDrawWidth());
        // this.scaleX = drawWidth / getMaximumDrawWidth();
        drawWidth = getMaximumDrawWidth();
        scale = true;
    }

    if (drawHeight < getMinimumDrawHeight()) {
        setChartFieldValue(getChartFieldByName("scaleY"), drawHeight / getMinimumDrawHeight());
        // this.scaleY = drawHeight / getMinimumDrawHeight();
        drawHeight = getMinimumDrawHeight();
        scale = true;
    } else if (drawHeight > getMaximumDrawHeight()) {
        setChartFieldValue(getChartFieldByName("scaleY"), drawHeight / getMaximumDrawHeight());
        // this.scaleY = drawHeight / getMaximumDrawHeight();
        drawHeight = getMaximumDrawHeight();
        scale = true;
    }

    Rectangle2D chartArea = new Rectangle2D.Double(0.0, 0.0, drawWidth, drawHeight);

    // are we using the chart buffer?
    if ((Boolean) getChartFieldValueByName("useBuffer")) {

        // do we need to resize the buffer?
        if ((getChartFieldValueByName("chartBuffer") == null)
                || ((Integer) getChartFieldValueByName("chartBufferWidth") != available.getWidth())
                || ((Integer) getChartFieldValueByName("chartBufferHeight") != available.getHeight())) {
            setChartFieldValue(getChartFieldByName("chartBufferWidth"), (int) available.getWidth());
            // this.chartBufferWidth = (int) available.getWidth();
            setChartFieldValue(getChartFieldByName("chartBufferHeight"), (int) available.getHeight());
            // this.chartBufferHeight = (int) available.getHeight();
            GraphicsConfiguration gc = g2.getDeviceConfiguration();
            setChartFieldValue(getChartFieldByName("chartBuffer"),
                    gc.createCompatibleImage((Integer) getChartFieldValueByName("chartBufferWidth"),
                            (Integer) getChartFieldValueByName("chartBufferHeight"), Transparency.TRANSLUCENT));
            // this.chartBuffer = gc.createCompatibleImage(this.chartBufferWidth,
            // this.chartBufferHeight, Transparency.TRANSLUCENT);
            setRefreshBuffer(true);
        }

        // do we need to redraw the buffer?
        if (getRefreshBuffer()) {

            setRefreshBuffer(false); // clear the flag

            Rectangle2D bufferArea = new Rectangle2D.Double(0, 0,
                    (Integer) getChartFieldValueByName("chartBufferWidth"),
                    (Integer) getChartFieldValueByName("chartBufferHeight"));

            Graphics2D bufferG2 = (Graphics2D) ((Image) getChartFieldValueByName("chartBuffer")).getGraphics();
            Rectangle r = new Rectangle(0, 0, (Integer) getChartFieldValueByName("chartBufferWidth"),
                    (Integer) getChartFieldValueByName("chartBufferHeight"));
            bufferG2.setPaint(getBackground());
            bufferG2.fill(r);
            if (scale) {
                AffineTransform saved = bufferG2.getTransform();
                AffineTransform st = AffineTransform.getScaleInstance(
                        (Double) getChartFieldValueByName("scaleX"),
                        (Double) getChartFieldValueByName("scaleY"));
                bufferG2.transform(st);
                getChart().draw(bufferG2, chartArea, getAnchor(), getChartRenderingInfo());
                bufferG2.setTransform(saved);
            } else {
                getChart().draw(bufferG2, bufferArea, getAnchor(), getChartRenderingInfo());
            }

        }

        // zap the buffer onto the panel...
        g2.drawImage((Image) getChartFieldValueByName("chartBuffer"), insets.left, insets.top, this);

    }

    // or redrawing the chart every time...
    else {

        AffineTransform saved = g2.getTransform();
        g2.translate(insets.left, insets.top);
        if (scale) {
            AffineTransform st = AffineTransform.getScaleInstance((Double) getChartFieldValueByName("scaleX"),
                    (Double) getChartFieldValueByName("scaleY"));
            g2.transform(st);
        }
        getChart().draw(g2, chartArea, getAnchor(), getChartRenderingInfo());
        g2.setTransform(saved);

    }

    Iterator iterator = ((List) getChartFieldValueByName("overlays")).iterator();
    while (iterator.hasNext()) {
        Overlay overlay = (Overlay) iterator.next();
        overlay.paintOverlay(g2, this);
    }

    // redraw the zoom rectangle (if present) - if useBuffer is false,
    // we use XOR so we can XOR the rectangle away again without redrawing
    // the chart
    drawZoomRectangle(g2, !(Boolean) getChartFieldValueByName("useBuffer"));

    g2.dispose();

    setAnchor(null);
    setVerticalTraceLine(null);
    setHorizontalTraceLine(null);
}

From source file:com.epiq.bitshark.ui.FrequencyDomainMouseMarker.java

/**
 * Draws the annotation.//ww  w .j  a  v a2  s .co m
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param rendererIndex  the renderer index.
 * @param info  if supplied, this info object will be populated with
 *              entity information.
 */
@Override
public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis,
        int rendererIndex, PlotRenderingInfo info) {

    if (!visible) {
        return;
    }

    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(plot.getDomainAxisLocation(), orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(plot.getRangeAxisLocation(), orientation);
    float j2DX = (float) domainAxis.valueToJava2D(this.x, dataArea, domainEdge);
    float j2DY = (float) rangeAxis.valueToJava2D(this.y, dataArea, rangeEdge);
    Rectangle2D displayArea = new Rectangle2D.Double(j2DX - this.displayWidth / 2.0,
            j2DY - this.displayHeight / 2.0, this.displayWidth, this.displayHeight);

    // here we change the AffineTransform so we can draw the annotation
    // to a larger area and scale it down into the display area
    // afterwards, the original transform is restored
    AffineTransform savedTransform = g2.getTransform();
    Rectangle2D drawArea = new Rectangle2D.Double(0.0, 0.0, this.displayWidth * this.drawScaleFactor,
            this.displayHeight * this.drawScaleFactor);

    g2.scale(1 / this.drawScaleFactor, 1 / this.drawScaleFactor);
    g2.translate((j2DX - this.displayWidth / 2.0) * this.drawScaleFactor,
            (j2DY - this.displayHeight / 2.0) * this.drawScaleFactor);
    draw(g2, drawArea);
    g2.setTransform(savedTransform);
    String toolTip = getToolTipText();
    String url = getURL();
    if (toolTip != null || url != null) {
        addEntity(info, displayArea, rendererIndex, toolTip, url);
    }

}

From source file:HelloUniverse.java

private void drawXPip(Graphics2D g2, float angle) {
    AffineTransform trans = new AffineTransform();
    int y;/*from w w w.j  av  a 2  s  .  com*/
    int xOrig = margin + diameter + space;
    int yOrig = margin;
    Color origColor = g2.getColor();

    if (angle <= Math.PI) {
        y = yOrig + diameter - (int) ((Math.abs(angle - Math.PI / 2) / (Math.PI / 2)) * diameter / 2);
    } else
        y = yOrig + (int) ((Math.abs((angle - Math.PI * 1.5)) / (Math.PI / 2)) * diameter / 2);

    if (angle < Math.PI / 2 || angle > Math.PI * 1.5)
        g2.setColor(Color.red); // Infront of wheel
    else {
        g2.setColor(Color.black); // Behind Wheel
        g2.setClip(xBackClip);
    }

    g2.setXORMode(getBackground());
    trans.setToTranslation(xOrig + pipOffset, y);
    g2.setTransform(trans);
    g2.fillPolygon(xPip);

    // Reset graphics context
    trans.setToIdentity();
    g2.setTransform(trans);
    g2.setColor(origColor);
    g2.setPaintMode();
}

From source file:HelloUniverse.java

private void drawYPip(Graphics2D g2, float angle) {
    AffineTransform trans = new AffineTransform();
    int x;/*from  w ww .  j a  v  a  2  s  .  c  o  m*/
    int xOrig = margin;
    int yOrig = margin + diameter + space;
    Color origColor = g2.getColor();

    if (angle <= Math.PI) {
        x = xOrig + diameter - (int) ((Math.abs(angle - Math.PI / 2) / (Math.PI / 2)) * diameter / 2);
    } else
        x = xOrig + (int) ((Math.abs((angle - Math.PI * 1.5)) / (Math.PI / 2)) * diameter / 2);

    if (angle < Math.PI / 2 || angle > Math.PI * 1.5)
        g2.setColor(Color.red); // Infront on wheel
    else {
        g2.setColor(Color.black); // Behind Wheel
        g2.setClip(yBackClip);
    }

    g2.setXORMode(getBackground());
    trans.setToTranslation(x, yOrig + pipOffset);
    g2.setTransform(trans);
    g2.fillPolygon(yPip);

    // Reset graphics context
    trans.setToIdentity();
    g2.setTransform(trans);
    g2.setColor(origColor);
    g2.setPaintMode();
}