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

The following are Jave code examples for showing how to use getColor() 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: JavaGraph   File: StrokedLineBorder.java   View Source Code Vote up 6 votes
/**
 * Overrides the super method to set the stroke first.
 * @param c the component for which this border is being painted
 * @param g the paint graphics
 * @param x the x position of the painted border
 * @param y the y position of the painted border
 * @param width the width of the painted border
 * @param height the height of the painted border
 */
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width,
        int height) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setStroke(this.stroke);

    Color oldColor = g.getColor();
    int i = this.thickness / 2;
    g.setColor(this.lineColor);
    if (!this.roundedCorners) {
        g.drawRect(x + i, y + i, width - i - i - 1, height - i - i - 1);
    } else {
        g.drawRoundRect(x + i, y + i, width - i - i - 1,
            height - i - i - 1, this.thickness, this.thickness);
    }
    g.setColor(oldColor);
}
 
Example 2
Project: incubator-netbeans   File: LoweredBorder.java   View Source Code Vote up 6 votes
public void paintBorder (
    Component c,
    Graphics g,
    int x, int y, int w, int h
) {
    Color oldColor = g.getColor ();
    g.translate (x, y);
    g.setColor (darker);
    g.drawLine (0, 0, 0, h - 1);
    g.drawLine (1, 0, w - 1, 0);
    g.setColor (brighter);
    g.drawLine (1, h - 1, w - 1, h - 1);
    g.drawLine (w - 1, 1, w - 1, h - 2);
    g.translate (-x, -y);
    g.setColor (oldColor);
}
 
Example 3
Project: jdk8u-jdk   File: MotifIconFactory.java   View Source Code Vote up 6 votes
public void drawCheckBezelOut(Graphics g, int x, int y, int csize){
    Color controlShadow = UIManager.getColor("controlShadow");

    int w = csize;
    int h = csize;
    Color oldColor = g.getColor();

    g.translate(x,y);
    g.setColor(highlight);    // inner 3D border
    g.drawLine(0, 0, 0, h-1);
    g.drawLine(1, 0, w-1, 0);

    g.setColor(shadow);         // black drop shadow  __|
    g.drawLine(1, h-1, w-1, h-1);
    g.drawLine(w-1, h-1, w-1, 1);
    g.translate(-x,-y);
    g.setColor(oldColor);
}
 
Example 4
Project: OpenJSharp   File: MotifIconFactory.java   View Source Code Vote up 6 votes
public void drawCheckBezelOut(Graphics g, int x, int y, int csize){
    Color controlShadow = UIManager.getColor("controlShadow");

    int w = csize;
    int h = csize;
    Color oldColor = g.getColor();

    g.translate(x,y);
    g.setColor(highlight);    // inner 3D border
    g.drawLine(0, 0, 0, h-1);
    g.drawLine(1, 0, w-1, 0);

    g.setColor(shadow);         // black drop shadow  __|
    g.drawLine(1, h-1, w-1, h-1);
    g.drawLine(w-1, h-1, w-1, 1);
    g.translate(-x,-y);
    g.setColor(oldColor);
}
 
Example 5
Project: incubator-netbeans   File: ThinBevelBorder.java   View Source Code Vote up 6 votes
protected void paintRaisedBevel(Component c, Graphics g, int x, int y, int width, int height) {
    Color oldColor = g.getColor();
    int h = height;
    int w = width;

    g.translate(x, y);

    g.setColor(getHighlightOuterColor(c));
    g.drawLine(0, 0, 0, h - 2);
    g.drawLine(1, 0, w - 2, 0);

    g.setColor(getShadowOuterColor(c));
    g.drawLine(0, h - 1, w - 1, h - 1);
    g.drawLine(w - 1, 0, w - 1, h - 2);

    g.translate(-x, -y);
    g.setColor(oldColor);
}
 
Example 6
Project: incubator-netbeans   File: ThinBevelBorder.java   View Source Code Vote up 6 votes
protected void paintLoweredBevel(Component c, Graphics g, int x, int y, int width, int height) {
    Color oldColor = g.getColor();
    int h = height;
    int w = width;

    g.translate(x, y);

    g.setColor(getShadowInnerColor(c));
    g.drawLine(0, 0, 0, h - 1);
    g.drawLine(1, 0, w - 1, 0);

    g.setColor(getHighlightOuterColor(c));
    g.drawLine(1, h - 1, w - 1, h - 1);
    g.drawLine(w - 1, 1, w - 1, h - 2);

    g.translate(-x, -y);
    g.setColor(oldColor);
}
 
Example 7
Project: OpenJSharp   File: BasicBorders.java   View Source Code Vote up 6 votes
public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) {
    AbstractButton b = (AbstractButton) c;
    ButtonModel model = b.getModel();

    Color shade = shadow;
    Component p = b.getParent();
    if (p != null && p.getBackground().equals(shadow)) {
        shade = darkShadow;
    }

    if ((model.isRollover() && !(model.isPressed() && !model.isArmed())) ||
        model.isSelected()) {

        Color oldColor = g.getColor();
        g.translate(x, y);

        if (model.isPressed() && model.isArmed() || model.isSelected()) {
            // Draw the pressd button
            g.setColor(shade);
            g.drawRect(0, 0, w-1, h-1);
            g.setColor(lightHighlight);
            g.drawLine(w-1, 0, w-1, h-1);
            g.drawLine(0, h-1, w-1, h-1);
        } else {
            // Draw a rollover button
            g.setColor(lightHighlight);
            g.drawRect(0, 0, w-1, h-1);
            g.setColor(shade);
            g.drawLine(w-1, 0, w-1, h-1);
            g.drawLine(0, h-1, w-1, h-1);
        }
        g.translate(-x, -y);
        g.setColor(oldColor);
    }
}
 
Example 8
Project: openjdk-jdk10   File: XComponentPeer.java   View Source Code Vote up 5 votes
void draw3DRect(Graphics g, Color bg,
                int x, int y, int width, int height,
                boolean raised) {
    Color c = g.getColor();
    Color shadow = bg.darker();
    Color highlight = bg.brighter();

    g.setColor(raised ? highlight : shadow);
    g.drawLine(x, y, x, y + height);
    g.drawLine(x + 1, y, x + width - 1, y);
    g.setColor(raised ? shadow : highlight);
    g.drawLine(x + 1, y + height, x + width, y + height);
    g.drawLine(x + width, y, x + width, y + height - 1);
    g.setColor(c);
}
 
Example 9
Project: openjdk-jdk10   File: WindowsBorders.java   View Source Code Vote up 5 votes
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    Color oldColor = g.getColor();
    int i;

    g.setColor(lineColor);
    for(i = 0; i < thickness; i++)  {
        BasicGraphicsUtils.drawDashedRect(g, x+i, y+i, width-i-i, height-i-i);
    }
    g.setColor(oldColor);
}
 
Example 10
Project: MaxSim   File: ColorChooserButton.java   View Source Code Vote up 5 votes
public void paintIcon(Component c, Graphics g, int x, int y) {
    Color oldColor = g.getColor();
    g.translate(x, y);

    g.setColor(color);
    g.fillRect(0, 0, ICON_SIZE.width, ICON_SIZE.height);

    g.setColor(Color.black);
    g.drawRect(0, 0, ICON_SIZE.width, ICON_SIZE.height);

    g.translate(-x, -y);
    g.setColor(oldColor);
}
 
Example 11
Project: The-Kraken-Pathfinding   File: CircularObstacle.java   View Source Code Vote up 5 votes
@Override
	public void print(Graphics g, GraphicPanel f)
	{
//		if(radius <= 0)
//			g.fillOval(f.XtoWindow(position.getX()) - 5, f.YtoWindow(position.getY()) - 5, 10, 10);
//		else
		g.drawOval(f.XtoWindow(position.getX() - radius), f.YtoWindow(position.getY() + radius), f.distanceXtoWindow((radius) * 2), f.distanceYtoWindow((radius) * 2));
		
		Color c = g.getColor();
		Color cTransparent = new Color(c.getRed(), c.getGreen(), c.getBlue(), 30);
		g.setColor(cTransparent);
		
		g.fillOval(f.XtoWindow(position.getX() - radius), f.YtoWindow(position.getY() + radius), f.distanceXtoWindow((radius) * 2), f.distanceYtoWindow((radius) * 2));		
	}
 
Example 12
Project: OpenJSharp   File: GTKGraphicsUtils.java   View Source Code Vote up 5 votes
public void paintText(SynthContext context, Graphics g, String text,
                      int x, int y, int mnemonicIndex) {
    if (text == null || text.length() <= 0) {
        // We don't need to paint empty strings
        return;
    }

    if (context.getRegion() == Region.INTERNAL_FRAME_TITLE_PANE) {
        // Metacity handles painting of text on internal frame title,
        // ignore this.
        return;
    }
    int componentState = context.getComponentState();
    if ((componentState & SynthConstants.DISABLED) ==
                          SynthConstants.DISABLED){
        Color orgColor = g.getColor();
        g.setColor(context.getStyle().getColor(context,
                                               GTKColorType.WHITE));
        x += 1;
        y += 1;
        super.paintText(context, g, text, x, y, mnemonicIndex);

        g.setColor(orgColor);
        x -= 1;
        y -= 1;
        super.paintText(context, g, text, x, y, mnemonicIndex);
    }
    else {
        String themeName = GTKLookAndFeel.getGtkThemeName();
        if (themeName != null && themeName.startsWith("blueprint") &&
            shouldShadowText(context.getRegion(), componentState)) {

            g.setColor(Color.BLACK);
            super.paintText(context, g, text, x+1, y+1, mnemonicIndex);
            g.setColor(Color.WHITE);
        }

        super.paintText(context, g, text, x, y, mnemonicIndex);
    }
}
 
Example 13
Project: incubator-netbeans   File: ComboTest.java   View Source Code Vote up 5 votes
public void paintIcon(Component c, Graphics g, int x, int y) {
    Color col = g.getColor();
    try {
        g.setColor(Color.BLUE);
        g.drawRect(x, y, getIconWidth(), getIconHeight());
        g.fillRect(x+3, y+3, getIconWidth()-5, getIconHeight()-5);
    } finally {
        g.setColor(col);
    }
}
 
Example 14
Project: incubator-netbeans   File: ComboTest.java   View Source Code Vote up 5 votes
public void paintIcon(Component c, Graphics g, int x, int y) {
    Color col = g.getColor();
    try {
        g.setColor(Color.GREEN);
        g.drawRect(x, y, getIconWidth(), getIconHeight());
        g.fillRect(x+3, y+3, getIconWidth()-5, getIconHeight()-5);
    } finally {
        g.setColor(col);
    }
}
 
Example 15
Project: xdman   File: XDMMenuItemUI.java   View Source Code Vote up 5 votes
@Override
protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor) {
	ButtonModel model = menuItem.getModel();
	Color oldColor = g.getColor();
	int menuWidth = menuItem.getWidth();
	int menuHeight = menuItem.getHeight();

	g.setColor(colorBg);
	g.fillRect(0, 0, menuWidth, menuHeight);

	if (model.isArmed()
			|| (menuItem instanceof JMenu && model.isSelected())) {
		paintButtonPressed(g, menuItem);
	} else {
		// if (menuItem.getIcon() != null) {
		// int gap = menuItem.getIcon().getIconWidth() + 2;
		// g.setColor(this.darkColor);
		// g.drawLine(gap, 0, gap, menuItem.getHeight());
		// g.setColor(this.lightColor);
		// g.drawLine(gap + 1, 0, gap + 1, menuItem.getHeight());
		// }
	}

	if (menuItem instanceof JCheckBoxMenuItem) {
		if (((JCheckBoxMenuItem) menuItem).isSelected()) {
			// chkIcon.paintIcon(menuItem, g, 5, 5);
		}
	}

	g.setColor(oldColor);
}
 
Example 16
Project: openjdk-jdk10   File: BasicArrowButton.java   View Source Code Vote up 5 votes
private void paintScaledTriangle(Graphics g, double x, double y, double size,
                                 int direction, boolean isEnabled) {
    size = Math.max(size, 2);
    Path2D.Double path = new Path2D.Double();
    path.moveTo(-size, size / 2);
    path.lineTo(size, size / 2);
    path.lineTo(0, -size / 2);
    path.closePath();
    AffineTransform affineTransform = new AffineTransform();
    affineTransform.rotate(Math.PI * (direction - 1) / 4);
    path.transform(affineTransform);

    Graphics2D g2d = (Graphics2D) g;
    double tx = x + size / 2;
    double ty = y + size / 2;
    g2d.translate(tx, ty);
    Color oldColor = g.getColor();
    if (!isEnabled) {
        g2d.translate(1, 0);
        g2d.setColor(highlight);
        g2d.fill(path);
        g2d.translate(-1, 0);
    }
    g2d.setColor(isEnabled ? darkShadow : shadow);
    g2d.fill(path);
    g2d.translate(-tx, -ty);
    g2d.setColor(oldColor);
}
 
Example 17
Project: JavaGraph   File: JGraphUI.java   View Source Code Vote up 5 votes
/** Renders the rubber band on the given graphics object. */
public void draw(Graphics g) {
    if (this.bounds.width >= 0) {
        Color oldColor = g.getColor();
        g.setColor(JAttr.RUBBER_FOREGROUND);
        g.drawRect(this.bounds.x, this.bounds.y, this.bounds.width,
            this.bounds.height);
        g.setColor(JAttr.RUBBER_BACKGROUND);
        g.fillRect(this.bounds.x, this.bounds.y, this.bounds.width,
            this.bounds.height);
        g.setColor(oldColor);
    }
}
 
Example 18
Project: OpenJSharp   File: MatteBorder.java   View Source Code Vote up 5 votes
/**
 * Paints the matte border.
 */
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    Insets insets = getBorderInsets(c);
    Color oldColor = g.getColor();
    g.translate(x, y);

    // If the tileIcon failed loading, paint as gray.
    if (tileIcon != null) {
        color = (tileIcon.getIconWidth() == -1) ? Color.gray : null;
    }

    if (color != null) {
        g.setColor(color);
        g.fillRect(0, 0, width - insets.right, insets.top);
        g.fillRect(0, insets.top, insets.left, height - insets.top);
        g.fillRect(insets.left, height - insets.bottom, width - insets.left, insets.bottom);
        g.fillRect(width - insets.right, 0, insets.right, height - insets.bottom);

    } else if (tileIcon != null) {
        int tileW = tileIcon.getIconWidth();
        int tileH = tileIcon.getIconHeight();
        paintEdge(c, g, 0, 0, width - insets.right, insets.top, tileW, tileH);
        paintEdge(c, g, 0, insets.top, insets.left, height - insets.top, tileW, tileH);
        paintEdge(c, g, insets.left, height - insets.bottom, width - insets.left, insets.bottom, tileW, tileH);
        paintEdge(c, g, width - insets.right, 0, insets.right, height - insets.bottom, tileW, tileH);
    }
    g.translate(-x, -y);
    g.setColor(oldColor);

}
 
Example 19
Project: VASSAL-src   File: Region.java   View Source Code Vote up 4 votes
public void draw(Graphics g, Rectangle bounds, Rectangle visibleRect, double scale, boolean reversed, int xOffset, int yOffset) {
  if (!bounds.intersects(visibleRect)) {
    return;
  }

  final int labelOffset = 7;

  int size = (int) (scale * myGrid.getFontSize() + 0.5);
  Font f = new Font("Dialog", Font.PLAIN, size); //$NON-NLS-1$

  Color fg = selected ? Color.white : Color.black;
  Color bg = selected ? Color.black : Color.white;

  Rectangle region = bounds.intersection(visibleRect);

  Shape oldClip = g.getClip();
  if (oldClip != null) {
    Area clipArea = new Area(oldClip);
    clipArea.intersect(new Area(region));
    g.setClip(clipArea);
  }

  int posX = (int) (scale * origin.x + 0.5) + bounds.x - 1 + xOffset;
  int posY = (int) (scale * origin.y + 0.5) + bounds.y - 1 + yOffset;

  Color saveColor = g.getColor();

  g.setColor(bg);
  g.fillRect(posX, posY, 3, 3);
  g.setColor(fg);
  g.drawRect(posX, posY, 3, 3);

  g.setColor(saveColor);

  Labeler.drawLabel(g, getLocalizedConfigureName(), posX, posY + labelOffset, f, Labeler.CENTER,
                    Labeler.TOP, fg, bg, fg);
  g.setClip(oldClip);

  // Calculate and store the selection rectangle
  int width = g.getFontMetrics().stringWidth(getConfigureName() + "  ")+1; //$NON-NLS-1$
  int height = g.getFontMetrics().getHeight()+1;

  selectionRect.setLocation(posX - (width / 2), posY - 1);
  selectionRect.setSize(width, height + labelOffset + 1);

}
 
Example 20
Project: myfaces-trinidad   File: PainterImageRenderer.java   View Source Code Vote up 4 votes
/**
  * Render the image given the Map of
  * properties that describe what to render.  A PaintContext
  * object is created using the given Map of properties.
  */
@Override
public Image renderImage(
  ImageContext imageContext,
  Map<Object, Object> requestedProperties,
  Map<Object, Object> responseProperties
  )
{
    if (!isRenderable(imageContext, requestedProperties))
    {
      return null;
    }

    Painter painter = getPainter(imageContext, requestedProperties);

    // First we measure the preferred size using a dummy image of
    // size 1x1 - we need this image to get the Graphics obejct
    // for measuring.
    BufferedImage measureImage = createImage(1, 1);

    // Create a PaintContext to use for measuring
    PaintContext measureContext = createPaintContext(imageContext,
                                                     measureImage,
                                                     requestedProperties,
                                                     responseProperties);

    // Get a measurement for the requested image
    Dimension d = painter.getPreferredSize(measureContext);

    int width = d.width;
    int height = d.height;

    // We're done with the measure image and context - free them up
    measureImage.flush();
    disposePaintContext(measureContext);

    // Now that we know how big the image should be, create the image
    // that we'll use for painting
    BufferedImage paintImage = createImage(width, height);

    // Create a PaintContext to use for drawing
    PaintContext paintContext = createPaintContext(imageContext,
                                                   paintImage,
                                                   requestedProperties,
                                                   responseProperties);

    // Fill in the image with the surrounding color
    Graphics g = paintContext.getPaintGraphics();
    Color oldColor = g.getColor();
    g.setColor(paintContext.getSurroundingColor());
    g.fillRect(0, 0, width, height);
    g.setColor(oldColor);

    // Paint the image
    painter.paint(paintContext, g, 0, 0, width, height);

    // Now that we are done painting, dispose the PaintContext
    disposePaintContext(paintContext);

    // Store width/height for client
    responseProperties.put(WIDTH_RESPONSE_KEY,
                           width);
    responseProperties.put(HEIGHT_RESPONSE_KEY,
                           height);

    return paintImage;
}