Example usage for java.awt Graphics2D translate

List of usage examples for java.awt Graphics2D translate

Introduction

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

Prototype

public abstract void translate(double tx, double ty);

Source Link

Document

Concatenates the current Graphics2D Transform with a translation transform.

Usage

From source file:org.forester.archaeopteryx.TreePanel.java

final public int print(final Graphics g, final PageFormat page_format, final int page_index)
        throws PrinterException {
    if (page_index > 0) {
        return (NO_SUCH_PAGE);
    } else {/*from w w  w  .  j a v a 2  s . co m*/
        final Graphics2D g2d = (Graphics2D) g;
        g2d.translate(page_format.getImageableX(), page_format.getImageableY());
        // Turn off double buffering !?
        paintPhylogeny(g2d, true, false, 0, 0, 0, 0);
        // Turn double buffering back on !?
        return (PAGE_EXISTS);
    }
}

From source file:org.gvsig.remotesensing.scatterplot.chart.ScatterPlotDiagram.java

/**
 * Paints the component by drawing the chart to fill the entire component,
 * but allowing for the insets (which will be non-zero if a border has been
 * set for this component).  To increase performance (at the expense of
 * memory), an off-screen buffer image can be used.
 *
 * @param g  the graphics device for drawing on.
 *///from w  w  w  . j a  va2  s .  c o  m
public void paintComponent(Graphics g) {
    super.paintComponent(g);
    if (this.chart == null) {
        return;
    }
    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();
    this.scaleX = 1.0;
    this.scaleY = 1.0;

    if (drawWidth < this.minimumDrawWidth) {
        this.scaleX = drawWidth / this.minimumDrawWidth;
        drawWidth = this.minimumDrawWidth;
        scale = true;
    } else if (drawWidth > this.maximumDrawWidth) {
        this.scaleX = drawWidth / this.maximumDrawWidth;
        drawWidth = this.maximumDrawWidth;
        scale = true;
    }
    if (drawHeight < this.minimumDrawHeight) {
        this.scaleY = drawHeight / this.minimumDrawHeight;
        drawHeight = this.minimumDrawHeight;
        scale = true;
    } else if (drawHeight > this.maximumDrawHeight) {
        this.scaleY = drawHeight / this.maximumDrawHeight;
        drawHeight = this.maximumDrawHeight;
        scale = true;
    }

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

    // are we using the chart buffer?
    if (this.useBuffer) {

        // if buffer is being refreshed, it needs clearing unless it is
        // new - use the following flag to track this...
        boolean clearBuffer = true;

        // do we need to resize the buffer?
        if ((this.chartBuffer == null) || (this.chartBufferWidth != available.getWidth())
                || (this.chartBufferHeight != available.getHeight())) {
            this.chartBufferWidth = (int) available.getWidth();
            this.chartBufferHeight = (int) available.getHeight();
            this.chartBuffer = createImage(this.chartBufferWidth, this.chartBufferHeight);
            //                GraphicsConfiguration gc = g2.getDeviceConfiguration();
            //                this.chartBuffer = gc.createCompatibleImage(
            //                        this.chartBufferWidth, this.chartBufferHeight, 
            //                        Transparency.TRANSLUCENT);
            this.refreshBuffer = true;
            clearBuffer = false; // buffer is new, no clearing required
        }

        // do we need to redraw the buffer?
        if (this.refreshBuffer) {

            this.refreshBuffer = false; // clear the flag

            Rectangle2D bufferArea = new Rectangle2D.Double(0, 0, this.chartBufferWidth,
                    this.chartBufferHeight);

            Graphics2D bufferG2 = (Graphics2D) this.chartBuffer.getGraphics();
            if (clearBuffer) {
                bufferG2.clearRect(0, 0, this.chartBufferWidth, this.chartBufferHeight);
            }
            if (scale) {
                AffineTransform saved = bufferG2.getTransform();
                AffineTransform st = AffineTransform.getScaleInstance(this.scaleX, this.scaleY);
                bufferG2.transform(st);
                this.chart.draw(bufferG2, chartArea, this.anchor, this.info);
                bufferG2.setTransform(saved);
            } else {
                this.chart.draw(bufferG2, bufferArea, this.anchor, this.info);
            }
        }
        g2.drawImage(this.chartBuffer, insets.left, insets.top, this);
        g2.draw((Shape) activeROI.getShapesList().get(1));
        // Dibujar las rois que se encuentren activas

    }

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

        AffineTransform saved = g2.getTransform();
        g2.translate(insets.left, insets.top);
        if (scale) {
            AffineTransform st = AffineTransform.getScaleInstance(this.scaleX, this.scaleY);
            g2.transform(st);
        }
        this.chart.draw(g2, chartArea, this.anchor, this.info);
        g2.drawImage(this.chartBuffer, insets.left, insets.top, this);

        // Se pintan las Roi activa
        drawsROIs(g2);
        g2.setTransform(saved);
    }

    g2.dispose();
    this.anchor = null;
}

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;/*  www.  j  a  v  a  2 s  .c  o  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.isti.traceview.common.TraceViewChartPanel.java

/**
 * Paints the component by drawing the chart to fill the entire component, but allowing for the
 * insets (which will be non-zero if a border has been set for this component). To increase
 * performance (at the expense of memory), an off-screen buffer image can be used.
 * /*  ww  w . j  ava 2  s  .c  om*/
 * @param g
 *            the graphics device for drawing on.
 */
public void paintComponent(Graphics g) {
    super.paintComponent(g);
    if (this.chart == null) {
        return;
    }
    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();
    this.scaleX = 1.0;
    this.scaleY = 1.0;

    if (drawWidth < this.minimumDrawWidth) {
        this.scaleX = drawWidth / this.minimumDrawWidth;
        drawWidth = this.minimumDrawWidth;
        scale = true;
    } else if (drawWidth > this.maximumDrawWidth) {
        this.scaleX = drawWidth / this.maximumDrawWidth;
        drawWidth = this.maximumDrawWidth;
        scale = true;
    }

    if (drawHeight < this.minimumDrawHeight) {
        this.scaleY = drawHeight / this.minimumDrawHeight;
        drawHeight = this.minimumDrawHeight;
        scale = true;
    } else if (drawHeight > this.maximumDrawHeight) {
        this.scaleY = drawHeight / this.maximumDrawHeight;
        drawHeight = this.maximumDrawHeight;
        scale = true;
    }

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

    // are we using the chart buffer?
    if (this.useBuffer) {
        // do we need to resize the buffer?
        if ((this.chartBuffer == null) || (this.chartBufferWidth != available.getWidth())
                || (this.chartBufferHeight != available.getHeight())) {
            this.chartBufferWidth = (int) available.getWidth();
            this.chartBufferHeight = (int) available.getHeight();
            this.chartBuffer = new BufferedImage(this.chartBufferWidth, this.chartBufferHeight,
                    BufferedImage.TYPE_INT_RGB);
            //this.chartBuffer = createImage(this.chartBufferWidth, this.chartBufferHeight);  -by Max
            // GraphicsConfiguration gc = g2.getDeviceConfiguration();
            // this.chartBuffer = gc.createCompatibleImage(
            // this.chartBufferWidth, this.chartBufferHeight,
            // Transparency.TRANSLUCENT);
            this.refreshBuffer = true;
        }

        // do we need to redraw the buffer?
        if (this.refreshBuffer) {
            Rectangle2D bufferArea = new Rectangle2D.Double(0, 0, this.chartBufferWidth,
                    this.chartBufferHeight);
            Graphics2D bufferG2 = (Graphics2D) this.chartBuffer.getGraphics();
            if (scale) {
                AffineTransform saved = bufferG2.getTransform();
                AffineTransform st = AffineTransform.getScaleInstance(this.scaleX, this.scaleY);
                bufferG2.transform(st);
                this.chart.draw(bufferG2, chartArea, this.anchor, this.info);
                bufferG2.setTransform(saved);
            } else {
                this.chart.draw(bufferG2, bufferArea, this.anchor, this.info);
            }

            this.refreshBuffer = false;
        }

        // zap the buffer onto the panel...
        g2.drawImage(this.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(this.scaleX, this.scaleY);
            g2.transform(st);
        }
        this.chart.draw(g2, chartArea, this.anchor, this.info);
        g2.setTransform(saved);
    }

    // Redraw the zoom rectangle (if present)
    drawZoomRectangle(g2);

    g2.dispose();
    this.anchor = null;
    this.verticalTraceLine = null;
    this.horizontalTraceLine = null;
}

From source file:org.rdv.viz.chart.ChartPanel.java

/**
 * Paints the component by drawing the chart to fill the entire component,
 * but allowing for the insets (which will be non-zero if a border has been
 * set for this component).  To increase performance (at the expense of
 * memory), an off-screen buffer image can be used.
 *
 * @param g  the graphics device for drawing on.
 *//*ww w  . j a  va2s.  c  o  m*/
public void paintComponent(Graphics g) {
    super.paintComponent(g);
    if (this.chart == null) {
        return;
    }
    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();
    this.scaleX = 1.0;
    this.scaleY = 1.0;

    if (drawWidth < this.minimumDrawWidth) {
        this.scaleX = drawWidth / this.minimumDrawWidth;
        drawWidth = this.minimumDrawWidth;
        scale = true;
    } else if (drawWidth > this.maximumDrawWidth) {
        this.scaleX = drawWidth / this.maximumDrawWidth;
        drawWidth = this.maximumDrawWidth;
        scale = true;
    }

    if (drawHeight < this.minimumDrawHeight) {
        this.scaleY = drawHeight / this.minimumDrawHeight;
        drawHeight = this.minimumDrawHeight;
        scale = true;
    } else if (drawHeight > this.maximumDrawHeight) {
        this.scaleY = drawHeight / this.maximumDrawHeight;
        drawHeight = this.maximumDrawHeight;
        scale = true;
    }

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

    // are we using the chart buffer?
    if (this.useBuffer) {

        // if buffer is being refreshed, it needs clearing unless it is
        // new - use the following flag to track this...
        boolean clearBuffer = true;

        // do we need to resize the buffer?
        if ((this.chartBuffer == null) || (this.chartBufferWidth != available.getWidth())
                || (this.chartBufferHeight != available.getHeight())) {
            this.chartBufferWidth = (int) available.getWidth();
            this.chartBufferHeight = (int) available.getHeight();
            this.chartBuffer = createImage(this.chartBufferWidth, this.chartBufferHeight);
            //                GraphicsConfiguration gc = g2.getDeviceConfiguration();
            //                this.chartBuffer = gc.createCompatibleImage(
            //                        this.chartBufferWidth, this.chartBufferHeight,
            //                        Transparency.TRANSLUCENT);
            this.refreshBuffer = true;
            clearBuffer = false; // buffer is new, no clearing required
        }

        // do we need to redraw the buffer?
        if (this.refreshBuffer) {

            this.refreshBuffer = false; // clear the flag

            Rectangle2D bufferArea = new Rectangle2D.Double(0, 0, this.chartBufferWidth,
                    this.chartBufferHeight);

            Graphics2D bufferG2 = (Graphics2D) this.chartBuffer.getGraphics();
            if (clearBuffer) {
                bufferG2.clearRect(0, 0, this.chartBufferWidth, this.chartBufferHeight);
            }
            if (scale) {
                AffineTransform saved = bufferG2.getTransform();
                AffineTransform st = AffineTransform.getScaleInstance(this.scaleX, this.scaleY);
                bufferG2.transform(st);
                this.chart.draw(bufferG2, chartArea, this.anchor, this.info);
                bufferG2.setTransform(saved);
            } else {
                this.chart.draw(bufferG2, bufferArea, this.anchor, this.info);
            }

        }

        // zap the buffer onto the panel...
        g2.drawImage(this.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(this.scaleX, this.scaleY);
            g2.transform(st);
        }
        this.chart.draw(g2, chartArea, this.anchor, this.info);
        g2.setTransform(saved);

    }

    // Redraw the zoom rectangle (if present)
    drawZoomRectangle(g2);

    g2.dispose();

    this.anchor = null;
    this.verticalTraceLine = null;
    this.horizontalTraceLine = null;

}

From source file:lu.fisch.unimozer.Diagram.java

@Override
public int print(Graphics g, PageFormat pageFormat, int page) throws PrinterException {
    /*/* ww w . j  a  v a 2 s  .  c om*/
        // clone paper
        Paper originalPaper = pageFormat.getPaper();
        Paper paper = new Paper();
        // resize it
        paper.setSize(originalPaper.getWidth(), originalPaper.getHeight());
        paper.setImageableArea(
                originalPaper.getImageableX(),
                originalPaper.getImageableY()+30,
                originalPaper.getImageableWidth(),
                originalPaper.getImageableHeight()-60);
        // apply it
        pageFormat.setPaper(paper);
    */
    /*                Paper paper = new Paper();
        paper.setSize(pageFormat.getWidth(),pageFormat.getHeight());
                
        double paddingLeftRight = pageFormat.getImageableX();
        double paddingTopBottom = pageFormat.getImageableY()+30;
        if (pageFormat.getOrientation()==PageFormat.LANDSCAPE)
        {
            paddingLeftRight = 60;
            paddingTopBottom = 60;
        }
        paper.setImageableArea(paddingLeftRight,
                               paddingTopBottom,
                               pageFormat.getWidth()-2*paddingLeftRight,
                               pageFormat.getHeight()-2*paddingTopBottom);
        pageFormat.setPaper(paper);*/

    if (page == 0) {
        pageList.clear();
        if (printOptions.printCode() == true) {
            /*Set<String> set = classes.keySet();
            Iterator<String> itr = set.iterator();
            while (itr.hasNext())
            {
              String str = itr.next();*/

            /* let's try this one ... */
            for (Entry<String, MyClass> entry : classes.entrySet()) {
                // get the actual class ...
                String str = entry.getKey();

                MyClass thisClass = classes.get(str);
                CodeEditor edit = new CodeEditor();
                edit.setFont(new Font(edit.getFont().getName(), Font.PLAIN, printOptions.getFontSize()));

                String code = "";
                // get code, depending on JavaDoc filter
                if (printOptions.printJavaDoc())
                    code = thisClass.getContent().getText();
                else
                    code = thisClass.getJavaCodeCommentless();

                // filter double lines
                if (printOptions.filterDoubleLines()) {
                    StringList sl = StringList.explode(code, "\n");
                    sl.removeDoubleEmptyLines();
                    code = sl.getText();
                }

                //edit.setDiagram(diagram);
                edit.setCode(code);

                // resize the picture
                PageFormat pf = (PageFormat) pageFormat.clone();
                Paper pa = pf.getPaper();
                pa.setImageableArea(pa.getImageableX(), pa.getImageableY() + 20, pa.getImageableWidth(),
                        pa.getImageableHeight() - 40);
                pf.setPaper(pa);

                //sheets = new Vector<BufferedImage>();
                int p = 0;
                int result = 0;
                do {
                    /*BufferedImage img = new BufferedImage((int) pageFormat.getImageableWidth(),(int) pageFormat.getImageableHeight(),BufferedImage.TYPE_INT_RGB );
                    img.getGraphics().setColor(Color.WHITE);
                    img.getGraphics().fillRect(0,0,(int) pageFormat.getImageableWidth(),(int) pageFormat.getImageableHeight());*/

                    BufferedImage img = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
                    result = edit.print(img.createGraphics(), pf, p);
                    if (result == PAGE_EXISTS) {
                        //sheets.add(img);
                        pageList.add(str);
                        p++;
                    }
                } while (result == PAGE_EXISTS);

                //edit.print(g, pf, p);
                edit = null;
                System.gc();
            }
        }
    }

    if (page == 0 && printOptions.printDiagram() == true) {
        Graphics2D g2d = (Graphics2D) g;

        int yOffset = (int) pageFormat.getImageableY();

        g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());

        double sX = (pageFormat.getImageableWidth() - 1) / getDiagramWidth();
        double sY = (pageFormat.getImageableHeight() - 1 - 40) / getDiagramHeight();
        double sca = Math.min(sX, sY);
        if (sca > 1) {
            sca = 1;
        }
        g2d.translate(0, 20);
        g2d.scale(sca, sca);

        paint(g2d);

        g2d.scale(1 / sca, 1 / sca);
        g2d.translate(0, -(20));
        g2d.translate(-pageFormat.getImageableX(), -pageFormat.getImageableY());

        printHeaderFooter(g2d, pageFormat, page, new String());

        PageFormat pf = (PageFormat) pageFormat.clone();
        Paper pa = pf.getPaper();
        pa.setImageableArea(pa.getImageableX(), pa.getImageableY() + 20, pa.getImageableWidth(),
                pa.getImageableHeight() - 40);
        pf.setPaper(pa);

        // reset the paper
        //pageFormat.setPaper(originalPaper);
        return (PAGE_EXISTS);
    } else {
        int origPage = page;

        if (printOptions.printDiagram() == true)
            page--;

        if (page >= pageList.size() || printOptions.printCode() == false)
            return (NO_SUCH_PAGE);
        else {
            String mc = pageList.get(page);
            page--;
            int p = 0;
            while (page >= 0) {
                if (pageList.get(page).equals(mc))
                    p++;
                page--;
            }
            MyClass thisClass = classes.get(mc);

            CodeEditor edit = new CodeEditor();
            edit.setFont(new Font(edit.getFont().getName(), Font.PLAIN, printOptions.getFontSize()));

            String code = "";
            // get code, depending on JavaDoc filter
            if (printOptions.printJavaDoc())
                code = thisClass.getContent().getText();
            else
                code = thisClass.getJavaCodeCommentless();

            // filter double lines
            if (printOptions.filterDoubleLines()) {
                StringList sl = StringList.explode(code, "\n");
                sl.removeDoubleEmptyLines();
                code = sl.getText();
            }

            edit.setCode(code);

            printHeaderFooter(g, pageFormat, origPage, thisClass.getShortName());

            PageFormat pf = (PageFormat) pageFormat.clone();
            Paper pa = pf.getPaper();
            pa.setImageableArea(pa.getImageableX(), pa.getImageableY() + 20, pa.getImageableWidth(),
                    pa.getImageableHeight() - 40);
            pf.setPaper(pa);

            edit.print(g, pf, p);
            edit = null;
            System.gc();

            // reset the paper
            //pageFormat.setPaper(originalPaper);
            return (PAGE_EXISTS);
        }
    }
}

From source file:tufts.vue.LWComponent.java

/** transform relative to the child after already being transformed relative to the parent */
protected void transformDownG(final Graphics2D a) {
    if (mTemporaryTransform != null) {
        a.transform(mTemporaryTransform);
    } else {/*ww  w .  j  a  v  a 2  s.c  o  m*/
        a.translate(this.x, this.y);
        if (this.scale != 1)
            a.scale(this.scale, this.scale);
    }
}

From source file:org.forester.archaeopteryx.TreePanel.java

final private void paintNodeDataUnrootedCirc(final Graphics2D g, final PhylogenyNode node, final boolean to_pdf,
        final boolean to_graphics_file, final boolean radial_labels, final double ur_angle,
        final boolean is_in_found_nodes) {
    if (isNodeDataInvisibleUnrootedCirc(node) && !to_graphics_file && !to_pdf) {
        return;// w  w w.ja v  a2  s.  com
    }
    if ((to_pdf || to_graphics_file) && getOptions().isPrintBlackAndWhite()) {
        g.setColor(Color.BLACK);
    } else if (is_in_found_nodes) {
        g.setColor(getTreeColorSet().getFoundColor());
    } else if (getControlPanel().isColorAccordingToTaxonomy()) {
        g.setColor(getTaxonomyBasedColor(node));
    } else {
        g.setColor(getTreeColorSet().getSequenceColor());
    }
    _sb.setLength(0);
    _sb.append(" ");
    if (node.getNodeData().isHasTaxonomy()
            && (getControlPanel().isShowTaxonomyCode() || getControlPanel().isShowTaxonomyNames())) {
        final Taxonomy taxonomy = node.getNodeData().getTaxonomy();
        if (_control_panel.isShowTaxonomyCode() && !ForesterUtil.isEmpty(taxonomy.getTaxonomyCode())) {
            _sb.append(taxonomy.getTaxonomyCode());
            _sb.append(" ");
        }
        if (_control_panel.isShowTaxonomyNames()) {
            if (!ForesterUtil.isEmpty(taxonomy.getScientificName())
                    && !ForesterUtil.isEmpty(taxonomy.getCommonName())) {
                _sb.append(taxonomy.getScientificName());
                _sb.append(" (");
                _sb.append(taxonomy.getCommonName());
                _sb.append(") ");
            } else if (!ForesterUtil.isEmpty(taxonomy.getScientificName())) {
                _sb.append(taxonomy.getScientificName());
                _sb.append(" ");
            } else if (!ForesterUtil.isEmpty(taxonomy.getCommonName())) {
                _sb.append(taxonomy.getCommonName());
                _sb.append(" ");
            }
        }
    }
    if (node.isCollapse() && ((!node.isRoot() && !node.getParent().isCollapse()) || node.isRoot())) {
        _sb.append(" [");
        _sb.append(node.getAllExternalDescendants().size());
        _sb.append("]");
    }
    if (getControlPanel().isShowNodeNames() && (node.getNodeName().length() > 0)) {
        if (_sb.length() > 0) {
            _sb.append(" ");
        }
        _sb.append(node.getNodeName());
    }
    if (node.getNodeData().isHasSequence()) {
        if (getControlPanel().isShowSequenceAcc()
                && (node.getNodeData().getSequence().getAccession() != null)) {
            if (_sb.length() > 0) {
                _sb.append(" ");
            }
            if (!ForesterUtil.isEmpty(node.getNodeData().getSequence().getAccession().getSource())) {
                _sb.append(node.getNodeData().getSequence().getAccession().getSource());
                _sb.append(":");
            }
            _sb.append(node.getNodeData().getSequence().getAccession().getValue());
        }
        if (getControlPanel().isShowGeneNames() && (node.getNodeData().getSequence().getName().length() > 0)) {
            //                if ( _sb.length() > 0 ) {
            //                    _sb.append( " " );
            //                }
            //                _sb.append( node.getNodeData().getSequence().getName() );
            PhylogenyNode parent = node.getParent();
            double x1 = parent.getXcoord();
            double y1 = parent.getYcoord();
            double x2 = node.getXcoord();
            double y2 = node.getYcoord();
            double above_the_line = 1.0;

            if (getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED) {
                double center_of_branch_x = Math.abs(x1 + x2) / 2.0;
                double center_of_branch_y = Math.abs(y1 + y2) / 2.0;
                TreePanel.drawString(node.getNodeData().getSequence().getName(), center_of_branch_x,
                        center_of_branch_y - above_the_line, g);
            }
        }
    }
    g.setFont(getTreeFontSet().getLargeFont());
    if (is_in_found_nodes) {
        g.setFont(getTreeFontSet().getLargeFont().deriveFont(Font.BOLD));
    }
    if (_sb.length() > 1) {
        final String sb_str = _sb.toString();
        double m = 0;
        if (_graphics_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR) {
            m = _urt_nodeid_angle_map.get(node.getNodeId()) % TWO_PI;
        } else {
            m = (float) (ur_angle % TWO_PI);
        }
        _at = g.getTransform();
        boolean need_to_reset = false;
        final float x_coord = node.getXcoord();
        final float y_coord = node.getYcoord() + (getTreeFontSet()._fm_large.getAscent() / 3.0f);
        if (radial_labels) {
            need_to_reset = true;
            boolean left = false;
            if ((m > HALF_PI) && (m < ONEHALF_PI)) {
                m -= PI;
                left = true;
            }
            g.rotate(m, x_coord, node.getYcoord());
            if (left) {
                g.translate(-(getTreeFontSet()._fm_large.getStringBounds(sb_str, g).getWidth()), 0);
            }
        } else {
            if ((m > HALF_PI) && (m < ONEHALF_PI)) {
                need_to_reset = true;
                g.translate(-getTreeFontSet()._fm_large.getStringBounds(sb_str, g).getWidth(), 0);
            }
        }
        TreePanel.drawString(sb_str, x_coord, y_coord, g);
        if (need_to_reset) {
            g.setTransform(_at);
        }
    }
}

From source file:tufts.vue.LWComponent.java

/**
 * Useful for drawing drag images into an existing graphics buffer, or drawing exportable images.
 *
 * @param alpha 0.0 (invisible) to 1.0 (no alpha -- completely opaque)
 * @param maxSize max dimensions for image. May be null.  Image may be smaller than maxSize.
 * @param fillColor -- if non-null, will be rendered as background for image.
 * @param zoomRequest -- desired zoom; ignored if maxSize is non-null
 * also set, background fill will have transparency of alpha^3 to enhance contrast.
 *///from   w  w w. j  a va  2 s  .  co m

public void drawImage(Graphics2D g, double alpha, Dimension maxSize, Color fillColor, double zoomRequest) {
    //if (DEBUG.IMAGE) out("drawImage; size " + maxSize);

    final boolean drawBorder = false;// this instanceof LWMap; // hack for dragged images of LWMaps

    final Rectangle2D.Float bounds = getImageBounds();
    final Rectangle clip = g.getClipBounds();
    final Size fillSize = new Size(bounds);
    final double zoom = computeZoomAndSize(bounds, maxSize, zoomRequest, fillSize);

    if (DEBUG.IMAGE)
        out(TERM_GREEN + "drawImage:" + "\n\t   mapBounds: " + fmt(bounds) + "\n\t        fill: " + fillColor
                + "\n\t     maxSize: " + maxSize + "\n\t zoomRequest: " + zoomRequest + "\n\t     fitZoom: "
                + zoom + "\n\t    fillSize: " + fillSize + "\n\t          gc: " + g + "\n\t        clip: "
                + fmt(clip) + "\n\t       alpha: " + alpha + TERM_CLEAR);

    final int width = fillSize.pixelWidth();
    final int height = fillSize.pixelHeight();

    final DrawContext dc = new DrawContext(g, this);

    dc.setInteractive(false);

    if (alpha == OPAQUE) {
        dc.setPrintQuality();
    } else {
        // if alpha, assume drag image (todo: better specified as an argument)
        dc.setDraftQuality();
    }

    dc.setBackgroundFill(getRenderFillColor(null)); // sure we want null here?
    dc.setClipOptimized(false); // always draw all children -- don't bother to check bounds
    if (DEBUG.IMAGE)
        out(TERM_GREEN + "drawImage: " + dc + TERM_CLEAR);

    if (fillColor != null) {
        //             if (false && alpha != OPAQUE) {
        //                 Color c = fillColor;
        //                 // if we have an alpha and a fill, amplify the alpha on the background fill
        //                 // by changing the fill to one that has alpha*alpha, for a total of
        //                 // alpha*alpha*alpha given our GC already has an alpha set.
        //                 fillColor = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int) (alpha*alpha*255+0.5));
        //             }
        if (alpha != OPAQUE)
            dc.setAlpha(alpha, AlphaComposite.SRC); // erase any underlying in cache
        if (DEBUG.IMAGE)
            out("drawImage: fill=" + fillColor);
        g.setColor(fillColor);
        g.fillRect(0, 0, width, height);
    } else { //if (alpha != OPAQUE) {
        // we didn't have a fill, but we have an alpha: make sure any cached data is cleared
        // todo?: if fill is null, we need to clear as well -- it means we have implied alpha on any non-drawn bits
        // TODO: if this is a selection drag, we usually want to fill with the map color (or ideally, the color
        // of the common parent, e.g., a slide, if there's one common parent)
        dc.g.setComposite(AlphaComposite.Clear);
        g.fillRect(0, 0, width, height);
    }

    //if (alpha != OPAQUE)
    dc.setAlpha(alpha, AlphaComposite.SRC);

    if (DEBUG.IMAGE && DEBUG.META) {
        // Fill the entire imageable area
        g.setColor(Color.green);
        g.fillRect(0, 0, Short.MAX_VALUE, Short.MAX_VALUE);
    }

    final AffineTransform rawTransform = g.getTransform();

    if (zoom != 1.0)
        dc.g.scale(zoom, zoom);

    // translate so that the upper left corner of the map region
    // we're drawing is at 0,0 on the underlying image

    g.translate(-bounds.getX(), -bounds.getY());

    // GC *must* have a bounds set or we get NPE's in JComponent (textBox) rendering
    dc.setMasterClip(bounds);

    if (DEBUG.IMAGE && DEBUG.META) {
        // fill the clipped area so we can check our clip bounds
        dc.g.setColor(Color.red);
        dc.g.fillRect(-Short.MAX_VALUE / 2, -Short.MAX_VALUE / 2, // larger values than this can blow out internal GC code and we get nothing
                Short.MAX_VALUE, Short.MAX_VALUE);
    }

    if (this instanceof LWImage) {
        // for some reason, raw images don't seem to want to draw unless we fill first
        dc.g.setColor(Color.white);
        dc.g.fill(bounds);
    }

    // render to the image through the DrawContext/GC pointing to it
    draw(dc);

    if (drawBorder) {
        g.setTransform(rawTransform);
        //g.setColor(Color.red);
        //g.fillRect(0,0, Short.MAX_VALUE, Short.MAX_VALUE);
        if (DEBUG.IMAGE) {
            g.setColor(Color.black);
            dc.setAntiAlias(false);
        } else
            g.setColor(Color.darkGray);
        g.drawRect(0, 0, width - 1, height - 1);
    }

    if (DEBUG.IMAGE)
        out(TERM_GREEN + "drawImage: completed\n" + TERM_CLEAR);

}

From source file:org.simmi.GeneSetHead.java

License:asdf

public void repaintGCSkew(List<Sequence> selclist, Graphics2D g2, int size, GeneGroup gg, String selspec) {
    g2.setColor(Color.white);/*w  ww .  j  ava2  s.co  m*/
    g2.fillRect(0, 0, 1024, 1024);
    g2.setFont(g2.getFont().deriveFont(10.0f));
    int total = 0;
    int g = 0;
    int c = 0;
    double gcstotal = 0.0;
    for (Sequence ctg : selclist) {
        //Sequence ctg = clist.get( u );
        if (gg != null) {
            for (Tegeval tv : gg.getTegevals()) {
                if (tv.getContshort() == ctg) {
                    int i = tv.start;

                    int x1 = (int) (512.0 + (384.0 - 100.0) * Math.cos((i + total) * 2.0 * Math.PI / size));
                    int y1 = (int) (512.0 + (384.0 - 100.0) * Math.sin((i + total) * 2.0 * Math.PI / size));
                    int x2 = (int) (512.0 + (384.0 + 100.0) * Math.cos((i + total) * 2.0 * Math.PI / size));
                    int y2 = (int) (512.0 + (384.0 + 100.0) * Math.sin((i + total) * 2.0 * Math.PI / size));

                    g2.setColor(Color.green);
                    g2.drawLine(x1, y1, x2, y2);
                }
            }
        }

        double horn = total * 2.0 * Math.PI / size;
        double horn2 = (total + ctg.length()) * 2.0 * Math.PI / size;

        int x1 = (int) (512.0 + (384.0 - 100.0) * Math.cos(horn));
        int y1 = (int) (512.0 + (384.0 - 100.0) * Math.sin(horn));
        int x2 = (int) (512.0 + (384.0 + 100.0) * Math.cos(horn));
        int y2 = (int) (512.0 + (384.0 + 100.0) * Math.sin(horn));
        g2.setColor(Color.black);
        g2.drawLine(x1, y1, x2, y2);

        int xoff = (int) (512.0 + (384.0 + 100.0) * Math.cos(horn2));
        int yoff = (int) (512.0 + (384.0 + 100.0) * Math.sin(horn2));
        if (horn < Math.PI) {
            g2.translate(x2, y2);
            g2.rotate(horn + Math.PI / 2.0);
            g2.drawString(ctg.getName(), 0, 0);
            g2.rotate(-horn - Math.PI / 2.0);
            g2.translate(-x2, -y2);
        } else {
            g2.translate(xoff, yoff);
            g2.rotate(horn2 + Math.PI / 2.0);
            g2.drawString(ctg.getName(), -g2.getFontMetrics().stringWidth(ctg.getName()), 0);
            g2.rotate(-horn2 - Math.PI / 2.0);
            g2.translate(-xoff, -yoff);
        }

        for (int i = 0; i < ctg.length(); i += 500) {
            for (int k = i; k < Math.min(ctg.length(), i + 500); k++) {
                char chr = ctg.charAt(k);
                if (chr == 'g' || chr == 'G') {
                    g++;
                } else if (chr == 'c' || chr == 'C') {
                    c++;
                }
            }

            int gcount = 0;
            int ccount = 0;
            int acount = 0;
            int tcount = 0;
            for (int k = i; k < Math.min(ctg.length(), i + 10000); k++) {
                char chr = k - 5000 < 0 ? ctg.charAt(ctg.length() + (k - 5000)) : ctg.charAt(k - 5000);
                if (chr == 'g' || chr == 'G') {
                    gcount++;
                } else if (chr == 'c' || chr == 'C') {
                    ccount++;
                } else if (chr == 'a' || chr == 'A')
                    acount++;
                else if (chr == 't' || chr == 'T')
                    tcount++;
            }

            if (gcount > 0 || ccount > 0) {
                double gcskew = (gcount - ccount) / (double) (gcount + ccount);

                gcstotal += gcskew;

                x1 = (int) (512.0 + (384.0) * Math.cos((i + total) * 2.0 * Math.PI / size));
                y1 = (int) (512.0 + (384.0) * Math.sin((i + total) * 2.0 * Math.PI / size));
                x2 = (int) (512.0 + (384.0 + gcskew * 100.0) * Math.cos((i + total) * 2.0 * Math.PI / size));
                y2 = (int) (512.0 + (384.0 + gcskew * 100.0) * Math.sin((i + total) * 2.0 * Math.PI / size));

                if (gcskew >= 0)
                    g2.setColor(Color.blue);
                else
                    g2.setColor(Color.red);
                g2.drawLine(x1, y1, x2, y2);
            }

            if (acount > 0 || tcount > 0) {
                double atskew = (acount - tcount) / (double) (acount + tcount);

                x1 = (int) (512.0 + (300.0) * Math.cos((i + total) * 2.0 * Math.PI / size));
                y1 = (int) (512.0 + (300.0) * Math.sin((i + total) * 2.0 * Math.PI / size));
                x2 = (int) (512.0 + (300.0 + atskew * 100.0) * Math.cos((i + total) * 2.0 * Math.PI / size));
                y2 = (int) (512.0 + (300.0 + atskew * 100.0) * Math.sin((i + total) * 2.0 * Math.PI / size));

                if (atskew >= 0)
                    g2.setColor(Color.blue);
                else
                    g2.setColor(Color.red);
                g2.drawLine(x1, y1, x2, y2);
            }
        }
        total += ctg.length();
    }

    g2.setColor(Color.black);
    g2.setFont(g2.getFont().deriveFont(java.awt.Font.ITALIC).deriveFont(32.0f));
    String[] specsplit; // = selspec.split("_");

    if (selspec.contains("hermus"))
        specsplit = selspec.split("_");
    else {
        Matcher m = Pattern.compile("\\d").matcher(selspec);
        int firstDigitLocation = m.find() ? m.start() : 0;
        if (firstDigitLocation == 0)
            specsplit = new String[] { "Thermus", selspec };
        else
            specsplit = new String[] { "Thermus", selspec.substring(0, firstDigitLocation),
                    selspec.substring(firstDigitLocation) };
    }

    int k = 0;
    for (String spec : specsplit) {
        int strw = g2.getFontMetrics().stringWidth(spec);
        g2.drawString(spec, (1024 - strw) / 2, 1024 / 2 - specsplit.length * 32 / 2 + 32 + k * 32);
        k++;
    }

    /*double gcs = gcstotal/total; //(g-c)/(g+c);
    String gcstr = Double.toString( Math.round( gcs*1000000.0 ) );
    g2.drawString( gcstr+"ppm", 768, 512 );*/
}