Java Code Examples for java.awt.Graphics#setPaintMode()

The following examples show how to use java.awt.Graphics#setPaintMode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TextEditor.java    From groovy with Apache License 2.0 6 votes vote down vote up
public void paint(Graphics g) {
    if (isVisible()) {
        try {
            JTextComponent component = getComponent();
            Rectangle r = component.getUI().modelToView(component, getDot());
            Color c = g.getColor();
            g.setColor(component.getBackground());
            g.setXORMode(component.getCaretColor());
            r.setBounds(r.x, r.y,
                    g.getFontMetrics().charWidth('w'),
                    g.getFontMetrics().getHeight());
            g.fillRect(r.x, r.y, r.width, r.height);
            g.setPaintMode();
            g.setColor(c);
        } catch (BadLocationException e) {
            e.printStackTrace();
        }
    }
}
 
Example 2
Source File: BlockCaret.java    From basicv2 with The Unlicense 6 votes vote down vote up
public void paint(Graphics g) {
	if (isVisible()) {
		try {
			JTextComponent component = getComponent();
			Rectangle r = component.getUI().modelToView(component, getDot());
			Color c = g.getColor();
			g.setColor(component.getBackground());
			g.setXORMode(component.getCaretColor());
			r.setBounds(r.x, r.y, g.getFontMetrics().charWidth('w'), g.getFontMetrics().getHeight());
			g.fillRect(r.x, r.y, r.width, r.height);
			g.setPaintMode();
			g.setColor(c);
		} catch (BadLocationException e) {
			e.printStackTrace();
		}
	}
}
 
Example 3
Source File: BoardPainter.java    From FancyBing with GNU General Public License v3.0 6 votes vote down vote up
private void drawShadows(Graphics graphics, ConstField[][] field)
{
    if (m_fieldSize <= 5)
        return;
    Graphics2D graphics2D =
        graphics instanceof Graphics2D ? (Graphics2D)graphics : null;
    if (graphics2D == null)
        return;
    graphics2D.setComposite(COMPOSITE_3);
    int size = m_fieldSize - 2 * Field.getStoneMargin(m_fieldSize);
    int offsetX = getShadowOffset() / 2; // Relates to stone gradient
    int offsetY = getShadowOffset();
    for (int x = 0; x < m_size; ++x)
        for (int y = 0; y < m_size; ++y)
        {
            if (field[x][y].getColor() == EMPTY)
                continue;
            Point location = getCenter(x, y);
            graphics.setColor(Color.black);
            graphics.fillOval(location.x - size / 2 + offsetX,
                              location.y - size / 2 + offsetY,
                              size, size);
        }
    graphics.setPaintMode();
}
 
Example 4
Source File: DrawingPanel.java    From osp with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Drags the corner of the ZoomBox.
 * Drag uses XORMode drawing to first erase and then repaint the box.
 *
 * @param xpix
 * @param ypix
 */
public void drag(int xpix, int ypix) {
  if(!visible) {
    return;
  }
  dragged = true;
  xstop = xpix;
  ystop = ypix;
  Graphics g = getGraphics();
  if(g==null) {
    return;
  }
  g.setXORMode(Color.green);
  g.drawRect(Math.min(xstart, xlast), Math.min(ystart, ylast), Math.abs(xlast-xstart), Math.abs(ylast-ystart));
  xlast = xstop;
  ylast = ystop;
  g.drawRect(Math.min(xstart, xlast), Math.min(ystart, ylast), Math.abs(xlast-xstart), Math.abs(ylast-ystart));
  g.setPaintMode();
  g.dispose();
}
 
Example 5
Source File: BasicScreenUI.java    From tn5250j with GNU General Public License v2.0 6 votes vote down vote up
protected void paintCursor(Graphics g)
  {
//       if (cursorEnabled)
//       {
//         iOhioPosition pos = screen.getCursor();
//      if (screen.cursorShown) {
         iOhioPosition pos = new iOhioPosition(screen.getCurrentRow(),screen.getCurrentCol());
//   //      System.out.println("Cursor at " + pos.getColumn() + "," + pos.getRow());
         Rectangle r = modelToView(pos);
//         g.setColor(Color.red);
//         g.setXORMode(Color.red);
         g.setColor(Color.red);
         g.setXORMode(colorBg);
         g.fillRect(r.x, r.y, r.width, r.height);
         g.setPaintMode();
//       }
//     }
  }
 
Example 6
Source File: CompositionArea.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
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
Source File: CompositionArea.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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
Source File: CompositionArea.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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
Source File: CompositionArea.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
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 10
Source File: CompositionArea.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
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 11
Source File: CompositionArea.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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 12
Source File: CompositionArea.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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 13
Source File: CompositionArea.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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 14
Source File: CompositionArea.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
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 15
Source File: EditablePlot.java    From OpenDA with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 16
Source File: ProductSceneView.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private void drawPixelBorder(int currentPixelX, int currentPixelY, int currentLevel, boolean showBorder) {
    final Graphics g = getGraphics();
    g.setXORMode(Color.white);
    if (pixelBorderDrawn) {
        drawPixelBorder(g, currentLevelPixelX, currentLevelPixelY, this.currentLevel);
        pixelBorderDrawn = false;
    }
    if (showBorder) {
        drawPixelBorder(g, currentPixelX, currentPixelY, currentLevel);
        pixelBorderDrawn = true;
    }
    g.setPaintMode();
    g.dispose();
}
 
Example 17
Source File: CompositionArea.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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 18
Source File: CompositionArea.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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 19
Source File: Plot.java    From opt4j with MIT License 4 votes vote down vote up
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<PlotPoint> pts = _points.elementAt(dataset);
	PlotPoint pt = 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 = _prevx.elementAt(dataset).longValue();
	long prevy = _prevy.elementAt(dataset).longValue();

	// Avoid drawing points and lines that are invisible.
	// Note that if the size of the dataset is 1, then we have only
	// one point, so we should be sure to draw it.
	if ((xpos != prevx) || (ypos != prevy) || (pts.size() == 1)) {
		// 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(Long.valueOf(xpos), dataset);
		_prevy.setElementAt(Long.valueOf(ypos), dataset);

		// Draw decorations that may be specified on a per-dataset basis
		Format fmt = _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 20
Source File: Plot.java    From OpenDA with GNU Lesser General Public License v3.0 4 votes vote down vote up
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();
    }
}