Example usage for java.awt Graphics setXORMode

List of usage examples for java.awt Graphics setXORMode

Introduction

In this page you can find the example usage for java.awt Graphics 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:MouseDragActionPanel.java

public void mouseDragged(MouseEvent evt) {
    int x = evt.getX();
    int y = evt.getY();

    if (currentSquareIndex >= 0) {
        Graphics g = getGraphics();
        g.setXORMode(getBackground());
        ((Graphics2D) g).draw(squares[currentSquareIndex]);
        squares[currentSquareIndex].x = x;
        squares[currentSquareIndex].y = y;
        ((Graphics2D) g).draw(squares[currentSquareIndex]);
        g.dispose();/*from   ww  w  .  jav  a2s  .co  m*/
    }
}

From source file:MainClass.java

public void paint(Graphics g) {
    int w = getSize().width;
    int midW = w / 2;

    g.drawString("XOR Mode", 0, 30);

    g.drawOval(7, 37, 50, 50);/*from  w ww  . j  a v a  2  s  .  c o m*/

    g.setXORMode(Color.white);

    for (int i = 0; i < 15; i += 3) {
        g.drawOval(10 + i, 40 + i, 50, 50);
    }

    g.setPaintMode();

    g.drawString("Paint Mode", midW, 30);

    g.drawOval(midW + 7, 37, 50, 50);

    for (int i = 0; i < 15; i += 3) {
        g.drawOval(midW + 10 + i, 40 + i, 50, 50);
    }
}

From source file:Main.java

public void paint(Graphics g) {
    int w = getSize().width;
    int midW = w / 2;

    g.drawString("XOR Mode", 0, 30);

    g.drawOval(7, 37, 50, 50);/*www  .ja v a 2 s .c o  m*/

    g.setXORMode(Color.white);

    for (int i = 0; i < 15; i += 3) {
        g.drawOval(10 + i, 40 + i, 50, 50);
    }

    g.setPaintMode();

    g.drawString("Paint Mode", midW, 30);

    g.drawOval(midW + 7, 37, 50, 50);

    for (int i = 0; i < 15; i += 3) {
        g.drawOval(midW + 10 + i, 40 + i, 50, 50);
    }

}

From source file:XORPanel.java

public void paintComponent(Graphics g) {
    super.paintComponent(g);
    g.setColor(Color.red);/*from  w ww  . ja  va2  s.  c o  m*/
    g.fillRect(10, 10, 80, 30);
    g.setColor(Color.green);
    g.fillRect(50, 20, 80, 30);
    g.setColor(Color.blue);
    g.fillRect(130, 40, 80, 30);
    g.setXORMode(Color.green);
    g.fillRect(90, 30, 80, 30);
}

From source file:XORModePaintWithMouse.java

public void paint(Graphics g) {
    g.drawLine(0, 0, 100, 100);/*www  . j  av  a2  s  .  co m*/
    g.drawLine(0, 100, 100, 0);
    g.setColor(Color.blue);
    g.drawLine(40, 25, 250, 180);
    g.drawLine(75, 90, 400, 400);
    g.setColor(Color.green);

    // xor cross hairs
    g.setXORMode(Color.black);
    g.drawLine(chsX - 10, chsY, chsX + 10, chsY);
    g.drawLine(chsX, chsY - 10, chsX, chsY + 10);
    g.setPaintMode();
}

From source file:FancyCaret.java

public void paint(Graphics g) {
    JTextComponent comp = getComponent();
    if (comp == null)
        return;/*from w  w  w  . j a v a  2s.  co m*/

    int dot = getDot();
    Rectangle r = null;
    char dotChar;
    try {
        r = comp.modelToView(dot);
        if (r == null)
            return;
        dotChar = comp.getText(dot, 1).charAt(0);
    } catch (BadLocationException e) {
        return;
    }

    if ((x != r.x) || (y != r.y)) {
        repaint();
        x = r.x;
        y = r.y;
        height = r.height;
    }

    g.setColor(comp.getCaretColor());
    g.setXORMode(comp.getBackground());

    if (dotChar == '\n') {
        int diam = r.height;
        if (isVisible())
            g.fillArc(r.x - diam / 2, r.y, diam, diam, 270, 180); // half circle
        width = diam / 2 + 2;
        return;
    }

    if (dotChar == '\t')
        try {
            Rectangle nextr = comp.modelToView(dot + 1);
            if ((r.y == nextr.y) && (r.x < nextr.x)) {
                width = nextr.x - r.x;
                if (isVisible())
                    g.fillRoundRect(r.x, r.y, width, r.height, 12, 12);
                return;
            } else
                dotChar = ' ';
        } catch (BadLocationException e) {
            dotChar = ' ';
        }

    width = g.getFontMetrics().charWidth(dotChar);
    if (isVisible())
        g.fillRect(r.x, r.y, width, r.height);
}

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

private void xorRectangle(Point start_point, Point end_point) {
    Graphics g = getGraphics();
    g.setXORMode(Color.white);
    g.setColor(Color.gray);//from w w  w  .j  a  v  a  2 s .co m

    Rectangle rect = makeRectangle(start_point, end_point);
    g.drawRect(rect.x, rect.y, rect.width, rect.height);
}

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

private void xorSelections(Point start_point, Point end_point) {
    Graphics g = getGraphics();
    g.setXORMode(Color.white);
    g.setColor(Color.gray);/*from www  . jav  a2 s  . co m*/

    int dx = end_point.x - start_point.x;
    int dy = end_point.y - start_point.y;
    for (AnnotationObject a : selections) {
        Rectangle rect = rectangles_complete.get(a);
        g.drawRect(dx + rect.x, dy + rect.y, rect.width, rect.height);
    }
}

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

private void xorConnection(AnnotationObject selection, Point start_point, Point end_point) {

    Graphics g = getGraphics();
    g.setXORMode(Color.white);
    g.setColor(Color.gray);/* w  w  w  . j  a  v  a 2 s  .  co  m*/

    Rectangle rect = rectangles_complete.get(selection);
    Point2D peak = dataToScreenCoords(selection.getPeakPoint());

    // select anchor
    Point2D anchor = computeAnchor(rect, end_point, peak);

    // draw connection
    g.drawLine((int) anchor.getX(), (int) anchor.getY(), (int) end_point.getX(), (int) end_point.getY());
    g.drawLine((int) end_point.getX(), (int) end_point.getY(), (int) peak.getX(), (int) peak.getY());
}

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

private void xorResizing(AnnotationObject selection, Point start_point, Point end_point) {
    Graphics g = getGraphics();
    g.setXORMode(Color.white);
    g.setColor(Color.gray);/*from   w ww  .  j  a  va2 s .c om*/

    Rectangle rect = rectangles.get(selection);

    double scale = 1.;
    if (start_point.x > midx(rect)) {
        scale = Math.min((double) (end_point.x - start_point.x + rect.width / 2.) / (double) (rect.width / 2.),
                (double) (start_point.y - end_point.y + rect.height) / (double) (rect.height));
    } else {
        scale = Math.min((double) (start_point.x - end_point.x + rect.width / 2.) / (double) (rect.width / 2.),
                (double) (start_point.y - end_point.y + rect.height) / (double) (rect.height));
    }
    scale = Math.max(0., scale);

    g.drawRect((int) (midx(rect) - rect.width * scale / 2.), (int) (bottom(rect) - rect.height * scale),
            (int) (rect.width * scale), (int) (rect.height * scale));
}