Example usage for java.awt Graphics2D setXORMode

List of usage examples for java.awt Graphics2D setXORMode

Introduction

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

Prototype

public abstract void setXORMode(Color c1);

Source Link

Document

Sets the paint mode of this graphics context to alternate between this graphics context's current color and the new specified color.

Usage

From source file:com.isti.traceview.common.TraceViewChartPanel.java

/**
 * Draws zoom rectangle (if present). The drawing is performed in XOR mode, therefore when this
 * method is called twice in a row, the second call will completely restore the state of the
 * canvas.// ww w  . j a va 2  s.co m
 * 
 * @param g2
 *            the graphics device.
 */
private void drawZoomRectangle(Graphics2D g2) {
    // Set XOR mode to draw the zoom rectangle
    g2.setXORMode(Color.gray);
    if (this.zoomRectangle != null) {
        if (this.fillZoomRectangle) {
            g2.fill(this.zoomRectangle);
        } else {
            g2.draw(this.zoomRectangle);
        }
    }
    // Reset to the default 'overwrite' mode
    g2.setPaintMode();
}

From source file:com.isti.traceview.common.TraceViewChartPanel.java

/**
 * Draws a vertical line used to trace the mouse position to the horizontal axis.
 * /*from  w w w  .jav  a 2 s .  c  o m*/
 * @param g2
 *            the graphics device.
 * @param x
 *            the x-coordinate of the trace line.
 */
private void drawHorizontalAxisTrace(Graphics2D g2, int x) {
    Rectangle2D dataArea = getScreenDataArea();

    g2.setXORMode(Color.orange);
    if (((int) dataArea.getMinX() < x) && (x < (int) dataArea.getMaxX())) {

        if (this.verticalTraceLine != null) {
            g2.draw(this.verticalTraceLine);
            this.verticalTraceLine.setLine(x, (int) dataArea.getMinY(), x, (int) dataArea.getMaxY());
        } else {
            this.verticalTraceLine = new Line2D.Float(x, (int) dataArea.getMinY(), x, (int) dataArea.getMaxY());
        }
        g2.draw(this.verticalTraceLine);
    }

    // Reset to the default 'overwrite' mode
    g2.setPaintMode();
}

From source file:com.isti.traceview.common.TraceViewChartPanel.java

/**
 * Draws a horizontal line used to trace the mouse position to the vertical axis.
 * //from  www  . j  av  a  2  s  . c  o m
 * @param g2
 *            the graphics device.
 * @param y
 *            the y-coordinate of the trace line.
 */
private void drawVerticalAxisTrace(Graphics2D g2, int y) {
    Rectangle2D dataArea = getScreenDataArea();

    g2.setXORMode(Color.orange);
    if (((int) dataArea.getMinY() < y) && (y < (int) dataArea.getMaxY())) {

        if (this.horizontalTraceLine != null) {
            g2.draw(this.horizontalTraceLine);
            this.horizontalTraceLine.setLine((int) dataArea.getMinX(), y, (int) dataArea.getMaxX(), y);
        } else {
            this.horizontalTraceLine = new Line2D.Float((int) dataArea.getMinX(), y, (int) dataArea.getMaxX(),
                    y);
        }
        g2.draw(this.horizontalTraceLine);
    }

    // Reset to the default 'overwrite' mode
    g2.setPaintMode();
}

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

/**
 * Draws a vertical line used to trace the mouse position to the horizontal
 * axis./*from  w  ww.j  a v  a2s.c  o m*/
 *
 * @param g2 the graphics device.
 * @param x  the x-coordinate of the trace line.
 */
private void drawHorizontalAxisTrace(Graphics2D g2, int x) {

    Rectangle2D dataArea = getScreenDataArea();

    g2.setXORMode(Color.orange);
    if (((int) dataArea.getMinX() < x) && (x < (int) dataArea.getMaxX())) {

        if (this.verticalTraceLine != null) {
            g2.draw(this.verticalTraceLine);
            this.verticalTraceLine.setLine(x, (int) dataArea.getMinY(), x, (int) dataArea.getMaxY());
        } else {
            this.verticalTraceLine = new Line2D.Float(x, (int) dataArea.getMinY(), x, (int) dataArea.getMaxY());
        }
        g2.draw(this.verticalTraceLine);
    }

    // Reset to the default 'overwrite' mode
    g2.setPaintMode();
}

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

/**
 * Draws a horizontal line used to trace the mouse position to the vertical
 * axis.//from  www.jav  a2  s.  co m
 *
 * @param g2 the graphics device.
 * @param y  the y-coordinate of the trace line.
 */
private void drawVerticalAxisTrace(Graphics2D g2, int y) {

    Rectangle2D dataArea = getScreenDataArea();

    g2.setXORMode(Color.orange);
    if (((int) dataArea.getMinY() < y) && (y < (int) dataArea.getMaxY())) {

        if (this.horizontalTraceLine != null) {
            g2.draw(this.horizontalTraceLine);
            this.horizontalTraceLine.setLine((int) dataArea.getMinX(), y, (int) dataArea.getMaxX(), y);
        } else {
            this.horizontalTraceLine = new Line2D.Float((int) dataArea.getMinX(), y, (int) dataArea.getMaxX(),
                    y);
        }
        g2.draw(this.horizontalTraceLine);
    }

    // Reset to the default 'overwrite' mode
    g2.setPaintMode();
}

From source file:org.tsho.dmc2.core.chart.TrajectoryRenderer.java

public void render(final Graphics2D g2, final Rectangle2D dataArea, final PlotRenderingInfo info) {
    ValueAxis domainAxis = plot.getDomainAxis();
    ValueAxis rangeAxis = plot.getRangeAxis();

    Stroke stroke = new BasicStroke(7f);
    Stroke origStroke = g2.getStroke();
    Color color = Color.BLACK;

    /* transients */
    if (!continua) {
        stepper.initialize();//  w  w  w.  j av  a 2s .c  o  m

        state = STATE_TRANSIENTS;

        try {
            for (index = 0; index < transients; index++) {
                stepper.step();
                if (stopped) {
                    state = STATE_STOPPED;
                    return;
                }
            }
        } catch (RuntimeException re) {
            throw new RuntimeException(re);
        }

        index = 0;
        prevX = 0;
        prevY = 0;
    }

    state = STATE_POINTS;

    Stepper.Point2D point;
    double[] fullPoint = new double[dataset.getNcol()];
    dataset.clearRows();
    int x, y;
    int start = index;
    int end = 0;
    if (index == 0) {
        end = start + iterations + 1;
    } else {
        end = start + iterations;
    }

    for (; index < end; index++) {
        point = stepper.getCurrentPoint2D();
        stepper.getCurrentValue(fullPoint);
        try {
            dataset.addRow((double[]) fullPoint.clone());
        } catch (DatasetException e) {
            System.err.println(e);
        }

        if (!timePlot) {
            x = (int) domainAxis.valueToJava2D(point.getX(), dataArea, RectangleEdge.BOTTOM);
        } else {
            x = (int) domainAxis.valueToJava2D(index + transients, dataArea, RectangleEdge.BOTTOM);
        }

        y = (int) rangeAxis.valueToJava2D(point.getY(), dataArea, RectangleEdge.LEFT);

        if (Double.isNaN(point.getX()) || Double.isNaN(point.getY())) {
            System.err.println("NaN values at iteration " + index);
            //FIXME
            //Don't simply throw exception: that would mess up the state machine!
            //throw new RuntimeException("NaN values at iteration " + index);
        }

        if (delay > 0) {
            boolean flag = false;

            try {
                Thread.sleep(delay * 5);

                drawItem(g2, index, x, y);

                g2.setXORMode(color);
                g2.setStroke(stroke);
                g2.drawRect(x - 1, y - 1, 3, 3);

                flag = true;

                Thread.sleep(delay * 5);
            } catch (final InterruptedException e) {
            }

            if (flag) {
                g2.drawRect(x - 1, y - 1, 3, 3);
                g2.setPaintMode();
                g2.setStroke(origStroke);
            } else {
                drawItem(g2, index, x, y);
            }
        } else {
            drawItem(g2, index, x, y);
        }

        try {
            stepper.step();
        } catch (RuntimeException re) {
            throw new RuntimeException(re);
        }

        if (stopped) {
            state = STATE_STOPPED;
            return;
        }
    }

    state = STATE_FINISHED;
}

From source file:com.rapidminer.gui.plotter.charts.AbstractChartPanel.java

/**
 * Draws a vertical line used to trace the mouse position to the horizontal axis.
 * /*from w w  w  . j ava2 s .  c o  m*/
 * @param g2
 *            the graphics device.
 * @param x
 *            the x-coordinate of the trace line.
 */
private void drawHorizontalAxisTrace(Graphics2D g2, int x) {

    Rectangle2D dataArea = getScreenDataArea();

    g2.setXORMode(Color.orange);
    if ((int) dataArea.getMinX() < x && x < (int) dataArea.getMaxX()) {

        if (this.verticalTraceLine != null) {
            g2.draw(this.verticalTraceLine);
            this.verticalTraceLine.setLine(x, (int) dataArea.getMinY(), x, (int) dataArea.getMaxY());
        } else {
            this.verticalTraceLine = new Line2D.Float(x, (int) dataArea.getMinY(), x, (int) dataArea.getMaxY());
        }
        g2.draw(this.verticalTraceLine);
    }

    // Reset to the default 'overwrite' mode
    g2.setPaintMode();
}

From source file:com.rapidminer.gui.plotter.charts.AbstractChartPanel.java

/**
 * Draws a horizontal line used to trace the mouse position to the vertical axis.
 * /*  w  ww.  ja v a2s . com*/
 * @param g2
 *            the graphics device.
 * @param y
 *            the y-coordinate of the trace line.
 */
private void drawVerticalAxisTrace(Graphics2D g2, int y) {

    Rectangle2D dataArea = getScreenDataArea();

    g2.setXORMode(Color.orange);
    if ((int) dataArea.getMinY() < y && y < (int) dataArea.getMaxY()) {

        if (this.horizontalTraceLine != null) {
            g2.draw(this.horizontalTraceLine);
            this.horizontalTraceLine.setLine((int) dataArea.getMinX(), y, (int) dataArea.getMaxX(), y);
        } else {
            this.horizontalTraceLine = new Line2D.Float((int) dataArea.getMinX(), y, (int) dataArea.getMaxX(),
                    y);
        }
        g2.draw(this.horizontalTraceLine);
    }

    // Reset to the default 'overwrite' mode
    g2.setPaintMode();
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.reporting.AnnotationReportCanvas.java

protected void paintAnnotations(Graphics2D g2d) {

    DecimalFormat mz_df = new DecimalFormat("0.0");

    // set font//  w  w w .  ja  v  a  2s. c  om
    Font old_font = g2d.getFont();
    Font new_font = new Font(theOptions.ANNOTATION_MZ_FONT, Font.PLAIN, theOptions.ANNOTATION_MZ_SIZE);

    // compute bboxes
    PositionManager pman = new PositionManager();
    BBoxManager bbman = new BBoxManager();
    computeRectangles(pman, bbman);

    // compute connections
    computeConnections();

    // paint connections
    for (AnnotationObject a : theDocument.getAnnotations()) {
        boolean selected = !is_printing && selections.contains(a);

        // paint arrow        
        Polygon connection = connections.get(a);
        if (connection != null) {
            g2d.setColor(theOptions.CONNECTION_LINES_COLOR);
            g2d.setStroke((selected) ? new BasicStroke((float) (1. + theOptions.ANNOTATION_LINE_WIDTH))
                    : new BasicStroke((float) theOptions.ANNOTATION_LINE_WIDTH));
            g2d.draw(connection);
            g2d.setStroke(new BasicStroke(1));
        }

        // paint control point       
        if (selected) {
            g2d.setColor(Color.black);
            Point2D cp = connections_cp.get(a);
            if (cp != null) {
                int s = (int) (2 + theOptions.ANNOTATION_LINE_WIDTH);
                g2d.fill(new Rectangle((int) cp.getX() - s, (int) cp.getY() - s, 2 * s, 2 * s));
            }
        }
    }

    // paint glycans
    for (AnnotationObject a : theDocument.getAnnotations()) {
        boolean highlighted = a.isHighlighted();
        boolean selected = !is_printing && selections.contains(a);

        // set scale
        theGlycanRenderer.getGraphicOptions().setScale(theOptions.SCALE_GLYCANS * theDocument.getScale(a));

        // paint highlighted region
        if (highlighted) {
            Rectangle c_bbox = rectangles_complete.get(a);

            g2d.setColor(theOptions.HIGHLIGHTED_COLOR);
            g2d.setXORMode(Color.white);
            g2d.fill(c_bbox);
            g2d.setPaintMode();

            g2d.setColor(Color.black);
            g2d.draw(c_bbox);
        }

        // paint glycan
        for (Glycan s : a.getStructures())
            theGlycanRenderer.paint(g2d, s, null, null, false, false, pman, bbman);

        // paint MZ text
        g2d.setFont(new_font);
        g2d.setColor(theOptions.MASS_TEXT_COLOR);
        String mz_text = mz_df.format(a.getPeakPoint().getX());
        Rectangle mz_bbox = rectangles_text.get(a);
        g2d.drawString(mz_text, mz_bbox.x, mz_bbox.y + mz_bbox.height);

        // paint selection        
        if (selected) {
            // paint rectangle
            Rectangle c_bbox = rectangles_complete.get(a);

            g2d.setStroke(new BasicStroke(highlighted ? 2 : 1));
            g2d.setColor(Color.black);

            g2d.draw(c_bbox);

            g2d.setStroke(new BasicStroke(1));

            // paint resize points        
            Polygon p1 = new Polygon();
            int cx1 = right(c_bbox);
            int cy1 = top(c_bbox);
            p1.addPoint(cx1, cy1);
            p1.addPoint(cx1 - 2 * theOptions.ANNOTATION_MARGIN / 3, cy1);
            p1.addPoint(cx1, cy1 + 2 * theOptions.ANNOTATION_MARGIN / 3);
            g2d.fill(p1);

            Polygon p2 = new Polygon();
            int cx2 = left(c_bbox);
            int cy2 = top(c_bbox);
            p2.addPoint(cx2, cy2);
            p2.addPoint(cx2 + 2 * theOptions.ANNOTATION_MARGIN / 3, cy2);
            p2.addPoint(cx2, cy2 + 2 * theOptions.ANNOTATION_MARGIN / 3);
            g2d.fill(p2);
        }
    }

    g2d.setFont(old_font);
}

From source file:figs.treeVisualization.gui.TimeAxisTree2DPanel.java

/**
 *  Paint this Component using the Tree2DPainter with TimeBars
 *
 *  @param g the graphics device/*  w ww.j a v a2  s. c o m*/
 */
@Override
protected void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D g2 = (Graphics2D) g.create();

    /**
     * Enable antialiased graphics.
     */
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

    Dimension currentSize = this.getSize();

    /**
     * Check to see if this component has changed size or if this
     * is our first time drawing.
     */
    if (this.fDimension == null || !this.fDimension.equals(currentSize) || this.fTreeArea == null
            || this.fLeftTreeArea == null || this.fEstMaxDateWidth == null) {
        this.fDimension = currentSize;

        this.fTreeArea = new Rectangle2D.Double(0, 0, currentSize.getWidth(), currentSize.getHeight());

        /** Adjust the width ratio using the maximum date width. */
        this.refreshLeafNodes();
        this.estimateMaximumDateWidth(g2);
        if ((this.fEstMaxDateWidth * 2) > (this.fTreeArea.getWidth() * this.fTreeWidthRatio)
                - this.fTreeArea.getWidth()) {
            this.fTreeWidthRatio = (this.fTreeArea.getWidth() - (this.fEstMaxDateWidth * 2))
                    / this.fTreeArea.getWidth();
        }

        /** Make left tree area for tree. */
        this.fLeftTreeArea = new Rectangle2D.Double(0, 0, this.fTreeArea.getWidth() * this.fTreeWidthRatio,
                this.fTreeArea.getHeight());

        /** Now, clear the right tree area so that it will be recalculated. */
        this.fRightTreeArea = null;
    }

    /** Paint the tree. */
    this.fTreePainter.drawTree(g2, this.fLeftTreeArea);

    /**
     * Check to see if we have calculated the date data.
     * The order of this is very important. We need to have
     * called the painter before we can get the coordinates.
     */
    if (this.fLeafNodes.isEmpty() || this.fLeafDates.isEmpty())
        /** Just calculate the Leaf data. */
        this.refreshLeafNodes();

    /**
     *  Draw the date axis and lines to the leaf nodes.
     */
    if (fTopLeafDate != null || fBottomLeafDate != null) {

        if (this.fRightTreeArea == null) {
            calculateDateMargins();
            this.fRightTreeArea = new Rectangle2D.Double(this.fTreeArea.getWidth() * this.fTreeWidthRatio,
                    this.fTopLeafPt.getY(), this.fTreeArea.getWidth(), this.fBottomLeafPt.getY());
        }

        double cursor = this.fRightTreeArea.getX()
                + ((this.fRightTreeArea.getWidth() - this.fRightTreeArea.getX()) / 2);
        drawDateAxis(g2, cursor, this.fRightTreeArea);
        drawDatesToLeafs(g2, cursor, this.fRightTreeArea);
    } else {
        // g2."No TIME INFORMATION AVAILABLE
        // g2.drawString("NO TIME INFORMATION AVAILABLE", x, y);
        System.out.println("TimeBarPanel: No time information available!");
    }

    if (this.fMousePressed && this.fMouseSelectionRect != null) {
        /** Color of line varies depending on image colors. */
        g2.setXORMode(Color.white);
        g2.drawRect(this.fMouseSelectionRect.x, this.fMouseSelectionRect.y, this.fMouseSelectionRect.width - 1,
                this.fMouseSelectionRect.height - 1);
    }

}