Java Code Examples for java.awt.Graphics.setXORMode()

The following are Jave code examples for showing how to use setXORMode() of the java.awt.Graphics class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: jdk8u-jdk   File: DrawXORModeTest.java   View Source Code Vote up 6 votes
@Override
public void paint(Graphics g) {
    if (g == null || !(g instanceof Graphics2D)) {
        return;
    }
    g.setColor(Color.white);
    g.setXORMode(Color.black);
    Graphics2D dg = (Graphics2D) g;
    Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT,
            BasicStroke.JOIN_MITER,
            10.0f,
            new float[]{1.0f, 1.0f},
            0.0f);
    dg.setStroke(stroke);
    try {
        dg.draw(new Line2D.Float(10, 10, 20, 20));
    } catch (Throwable e) {
        synchronized (this) {
            theError = e;
        }
    } finally {
        didDraw.countDown();
    }
}
 
Example 2
Project: openjdk-jdk10   File: DrawXORModeTest.java   View Source Code Vote up 6 votes
@Override
public void paint(Graphics g) {
    if (g == null || !(g instanceof Graphics2D)) {
        return;
    }
    g.setColor(Color.white);
    g.setXORMode(Color.black);
    Graphics2D dg = (Graphics2D) g;
    Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT,
            BasicStroke.JOIN_MITER,
            10.0f,
            new float[]{1.0f, 1.0f},
            0.0f);
    dg.setStroke(stroke);
    try {
        dg.draw(new Line2D.Float(10, 10, 20, 20));
    } catch (Throwable e) {
        synchronized (this) {
            theError = e;
        }
    } finally {
        didDraw.countDown();
    }
}
 
Example 3
Project: incubator-netbeans   File: DragManager.java   View Source Code Vote up 5 votes
public void paint(Graphics g) {
    g.setXORMode(Color.white); //Color of line varies
    
    for (DragItem elem : allItems) {
        elem.paint(g);
    }
}
 
Example 4
Project: OpenDA   File: EditablePlot.java   View Source Code Vote up 5 votes
private synchronized void _editPoint(int x, int y) {

        if (_dataset < 0) return;

        Graphics graphics = getGraphics();
        // constrain to be in range
        if (y > _lry) y = _lry;
        if (y < _uly) y = _uly;
        if (x > _lrx) x = _lrx;
        if (x < _ulx) x = _ulx;

        if (x <= _currentEditX || x >= _lrx) {
            // ignore
            return;
        }
        int step = _currentEditX;
        while (step <= x) {
            int index = step-(_lrx-_editSpecX.length);
            double proportion =
                (step - _currentEditX)/(double)(x - _currentEditX);
            int newY = (int)(_currentEditY + proportion*(y-_currentEditY));
            if (!_editSpecSet[index]) {
                _editSpecX[index] = step;
                _editSpecY[index] = newY;
                _editSpecSet[index] = true;

                // Draw point, linearly interpolated from previous point
                graphics.setXORMode(_editColor);
                graphics.drawLine(step, newY-1, step, newY+1);
                graphics.setPaintMode();
            }
            step++;
        }
        _currentEditX = x;
        _currentEditY = y;
    }
 
Example 5
Project: OpenDA   File: EditablePlot.java   View Source Code Vote up 5 votes
private synchronized void _editStart(int x, int y) {

        if (_dataset < 0) return;

        // constrain to be in range
        if (y > _lry) y = _lry;
        if (y < _uly) y = _uly;
        if (x > _lrx) x = _lrx;
        if (x < _ulx) x = _ulx;

        // Allocate a vector to store the points.
        int size = _lrx - x + 1;
        _editSpecX = new int[size];
        _editSpecY = new int[size];
        _editSpecSet = new boolean[size];

        _editSpecX[0] = x;
        _editSpecY[0] = y;
        _editSpecSet[0] = true;

        _currentEditX = x;
        _currentEditY = y;

        Graphics graphics = getGraphics();
        // Draw point (as a 3 pixel vertical line, for thickness)
        graphics.setXORMode(_editColor);
        graphics.drawLine(x, y-1, x, y+1);
        graphics.setPaintMode();
    }
 
Example 6
Project: OpenJSharp   File: CompositionArea.java   View Source Code Vote up 5 votes
public void paint(Graphics g) {
    super.paint(g);
    g.setColor(getForeground());
    TextLayout layout = composedTextLayout;
    if (layout != null) {
        layout.draw((Graphics2D) g, TEXT_ORIGIN_X, TEXT_ORIGIN_Y);
    }
    if (caret != null) {
        Rectangle rectangle = getCaretRectangle(caret);
        g.setXORMode(getBackground());
        g.fillRect(rectangle.x, rectangle.y, 1, rectangle.height);
        g.setPaintMode();
    }
}
 
Example 7
Project: jdk8u-jdk   File: CompositionArea.java   View Source Code Vote up 5 votes
public void paint(Graphics g) {
    super.paint(g);
    g.setColor(getForeground());
    TextLayout layout = composedTextLayout;
    if (layout != null) {
        layout.draw((Graphics2D) g, TEXT_ORIGIN_X, TEXT_ORIGIN_Y);
    }
    if (caret != null) {
        Rectangle rectangle = getCaretRectangle(caret);
        g.setXORMode(getBackground());
        g.fillRect(rectangle.x, rectangle.y, 1, rectangle.height);
        g.setPaintMode();
    }
}
 
Example 8
Project: openjdk-jdk10   File: CompositionArea.java   View Source Code Vote up 5 votes
public void paint(Graphics g) {
    super.paint(g);
    g.setColor(getForeground());
    TextLayout layout = composedTextLayout;
    if (layout != null) {
        layout.draw((Graphics2D) g, TEXT_ORIGIN_X, TEXT_ORIGIN_Y);
    }
    if (caret != null) {
        Rectangle rectangle = getCaretRectangle(caret);
        g.setXORMode(getBackground());
        g.fillRect(rectangle.x, rectangle.y, 1, rectangle.height);
        g.setPaintMode();
    }
}
 
Example 9
Project: OpenDA   File: Plot.java   View Source Code Vote up 4 votes
private void _drawPlotPoint(Graphics graphics,
        int dataset, int index) {
    if (_pointsPersistence > 0 || _xPersistence > 0.0) {
        // To allow erasing to work by just redrawing the points.
        if (_background == null) {
            // java.awt.Component.setBackground(color) says that
            // if the color "parameter is null then this component
            // will inherit the  background color of its parent."
            graphics.setXORMode(getBackground());
        } else {
            graphics.setXORMode(_background);
        }
    }
    // Set the color
    if (_usecolor) {
        int color = dataset % _colors.length;
        graphics.setColor(_colors[color]);
    } else {
        graphics.setColor(_foreground);
    }

    Vector pts = (Vector)_points.elementAt(dataset);
    PlotPoint pt = (PlotPoint)pts.elementAt(index);
    // Use long here because these numbers can be quite large
    // (when we are zoomed out a lot).
    long ypos = _lry - (long)((pt.y - _yMin) * _yscale);
    long xpos = _ulx + (long)((pt.x - _xMin) * _xscale);

    // Draw the line to the previous point.
    long prevx = ((Long)_prevx.elementAt(dataset)).longValue();
    long prevy = ((Long)_prevy.elementAt(dataset)).longValue();
    // MIN_VALUE is a flag that there has been no previous x or y.
    if (pt.connected) {
        _drawLine(graphics, dataset, xpos, ypos, prevx, prevy, true, 2f);
    }

    // Save the current point as the "previous" point for future
    // line drawing.
    _prevx.setElementAt(new Long(xpos), dataset);
    _prevy.setElementAt(new Long(ypos), dataset);

    // Draw decorations that may be specified on a per-dataset basis
    Format fmt = (Format)_formats.elementAt(dataset);
    if (fmt.impulsesUseDefault) {
        if (_impulses) _drawImpulse(graphics, xpos, ypos, true);
    } else {
        if (fmt.impulses) _drawImpulse(graphics, xpos, ypos, true);
    }

    // Check to see whether the dataset has a marks directive
    int marks = _marks;
    if (!fmt.marksUseDefault) marks = fmt.marks;
    if (marks != 0) _drawPoint(graphics, dataset, xpos, ypos, true);

    if (_bars) _drawBar(graphics, dataset, xpos, ypos, true);
    if (pt.errorBar)
        _drawErrorBar(graphics, dataset, xpos,
                _lry - (long)((pt.yLowEB - _yMin) * _yscale),
                _lry - (long)((pt.yHighEB - _yMin) * _yscale), true);

    // Restore the color, in case the box gets redrawn.
    graphics.setColor(_foreground);
    if (_pointsPersistence > 0 || _xPersistence > 0.0) {
        // Restore paint mode in case axes get redrawn.
        graphics.setPaintMode();
    }
}
 
Example 10
Project: jiracli   File: BlockCaret.java   View Source Code Vote up 4 votes
@Override
public void paint(Graphics g) {
    JTextComponent comp = getComponent();
    if (comp == null) {
        return;
    }

    int dot = getDot();

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

    if (dotChar == '\r' || dotChar == '\n') {
        dotChar = ' ';
    }

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

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

    width = g.getFontMetrics().charWidth(dotChar);
    if (width <= 0) {
        width = g.getFontMetrics().charWidth(' ');
    }

    if (isVisible()) {
        g.fillRect(rectangle.x, rectangle.y, width, rectangle.height);
    }
}