Java Code Examples for java.awt.Color#darker()

The following examples show how to use java.awt.Color#darker() . These examples are extracted from open source projects. 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 Project: qpid-broker-j   File: ColorFactory.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Converts a colour name known to the JDK into a {@link Color} instance.  Additionally,
 * if the work dark_ is prepended to the colour, a darker shade of the same colour is
 * produced.
 *
 * @param colourName
 * @return colour instance
 */
public static Color toColour(String colourName)
{
    boolean darkVersion = false;
    if (colourName.toLowerCase().startsWith("dark_"))
    {
        colourName = colourName.replaceFirst("(?i)dark_", "");
        darkVersion = true;
    }

    Color colour = getColourFromStaticField(colourName);
    if (darkVersion)
    {
        return colour.darker();
    }
    else
    {
        return colour;
    }
}
 
Example 2
void draw3DOval(Graphics g, Color bg,
            int x, int y, int w, int h, boolean raised)
{
    Color c = g.getColor();
    Color shadow = bg.darker();
    Color highlight = bg.brighter();

    g.setColor(raised ? highlight : shadow);
    g.drawArc(x, y, w, h, 45, 180);
    g.setColor(raised ? shadow : highlight);
    g.drawArc(x, y, w, h, 225, 180);
    g.setColor(c);
}
 
Example 3
Source Project: blog-codes   File: ShadowBorder.java    License: Apache License 2.0 5 votes vote down vote up
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h)
{
	// choose which colors we want to use
	Color bg = c.getBackground();

	if (c.getParent() != null)
	{
		bg = c.getParent().getBackground();
	}

	if (bg != null)
	{
		Color mid = bg.darker();
		Color edge = average(mid, bg);

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

		// draw the drop-shadow
		g.setColor(mid);
		g.drawLine(1, h - 2, w - 2, h - 2);
		g.drawLine(w - 2, 1, w - 2, h - 2);

		g.setColor(edge);
		g.drawLine(2, h - 1, w - 2, h - 1);
		g.drawLine(w - 1, 2, w - 1, h - 2);
	}
}
 
Example 4
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 5
void draw3DOval(Graphics g, Color bg,
            int x, int y, int w, int h, boolean raised)
{
    Color c = g.getColor();
    Color shadow = bg.darker();
    Color highlight = bg.brighter();

    g.setColor(raised ? highlight : shadow);
    g.drawArc(x, y, w, h, 45, 180);
    g.setColor(raised ? shadow : highlight);
    g.drawArc(x, y, w, h, 225, 180);
    g.setColor(c);
}
 
Example 6
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 7
Source Project: Pixie   File: MonochromeIcon.java    License: MIT License 5 votes vote down vote up
/**
 * Create an icon of the specified dimension and color.
 *
 * @param width  - the width of the icon
 * @param height - the height of the icon
 * @param color  - the color of the icon
 */
public MonochromeIcon(int width, int height, Color color) {
    this.width = width;
    this.height = height;
    this.color = color;

    this.border = color.darker();
}
 
Example 8
void draw3DOval(Graphics g, Color bg,
            int x, int y, int w, int h, boolean raised)
{
    Color c = g.getColor();
    Color shadow = bg.darker();
    Color highlight = bg.brighter();

    g.setColor(raised ? highlight : shadow);
    g.drawArc(x, y, w, h, 45, 180);
    g.setColor(raised ? shadow : highlight);
    g.drawArc(x, y, w, h, 225, 180);
    g.setColor(c);
}
 
Example 9
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 10
void draw3DOval(Graphics g, Color bg,
            int x, int y, int w, int h, boolean raised)
{
    Color c = g.getColor();
    Color shadow = bg.darker();
    Color highlight = bg.brighter();

    g.setColor(raised ? highlight : shadow);
    g.drawArc(x, y, w, h, 45, 180);
    g.setColor(raised ? shadow : highlight);
    g.drawArc(x, y, w, h, 225, 180);
    g.setColor(c);
}
 
Example 11
Source Project: dsworkbench   File: ColorCellRenderer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    JLabel l = (JLabel) c;

    Color selectColor = (Color) value;
    if (isSelected && bMarkSelection && selectColor != null) {
        selectColor = selectColor.darker();
    }
    l.setBackground(selectColor);
    l.setForeground(selectColor);
    l.setText("");
    return l;
}
 
Example 12
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 13
Source Project: binnavi   File: ZyLabelContent.java    License: Apache License 2.0 5 votes vote down vote up
public void updateContentSelectionColor(final Color fillColor, final boolean isSelected) {
  final Color nodeSelectionColor = fillColor.darker();

  if (isSelected) {
    setSelectionColor(nodeSelectionColor.darker());
  } else {
    setSelectionColor(nodeSelectionColor);
  }
}
 
Example 14
private Color getNextItemColor() {
    int newItemIndex = itemNames.size();
    int colorsCount  = ColorFactory.getPredefinedColorsCount();
    Color color = null;

    if (newItemIndex >= colorsCount) {
        color = ColorFactory.getPredefinedColor(newItemIndex % colorsCount);
        int darkerFactor = newItemIndex / colorsCount;
        while (darkerFactor-- > 0) color = color.darker();
    } else {
        color = ColorFactory.getPredefinedColor(newItemIndex);
    }

    return color;
}
 
Example 15
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 16
Source Project: netbeans   File: TimelineColorFactory.java    License: Apache License 2.0 5 votes vote down vote up
static Color getColor(int index) {
    Color color;

    if (index >= PREDEFINED_COLORS.length) {
        color = getPredefinedColor(index % PREDEFINED_COLORS.length);
        int darkerFactor = index / PREDEFINED_COLORS.length;
        while (darkerFactor-- > 0) color = color.darker();
    } else {
        color = getPredefinedColor(index);
    }

    return color;
}
 
Example 17
void draw3DOval(Graphics g, Color bg,
            int x, int y, int w, int h, boolean raised)
{
    Color c = g.getColor();
    Color shadow = bg.darker();
    Color highlight = bg.brighter();

    g.setColor(raised ? highlight : shadow);
    g.drawArc(x, y, w, h, 45, 180);
    g.setColor(raised ? shadow : highlight);
    g.drawArc(x, y, w, h, 225, 180);
    g.setColor(c);
}
 
Example 18
Source Project: chipster   File: PeakSelectable.java    License: MIT License 4 votes vote down vote up
public void render(GBrowserView view, Color color) {		

		Rectangle rect = new Rectangle();

		rect.x = view.bpToTrack(region.start);
		rect.width = view.bpToTrack(region.end) - rect.x;

		if (rect.width < MIN_VISIBLE_PEAK_SIZE) {
			rect.width = MIN_VISIBLE_PEAK_SIZE;
		}

		rect.y = 0;
		rect.height = PEAK_SYMBOL_HEIGHT;

		this.rectDrawable = new RectDrawable(rect, color, color.darker());
	}
 
Example 19
Source Project: netbeans   File: OutputOptions.java    License: Apache License 2.0 4 votes vote down vote up
static Color ensureContrastingColor(Color fg, Color bg) {
    if (bg == null) {
        if (isNimbus()) {
            bg = UIManager.getColor("Tree.background"); //NOI18N
            if (null == bg) {
                bg = Color.WHITE;
            }
        } else {
            bg = UIManager.getColor("text"); //NOI18N

            if (bg == null) {
                bg = Color.WHITE;
            }
        }
    }
    if (fg == null) {
        if (isNimbus()) {
            fg = UIManager.getColor("Tree.foreground"); //NOI18N
            if (null == fg) {
                fg = Color.BLACK;
            }
        } else {
            fg = UIManager.getColor("textText"); //NOI18N
            if (fg == null) {
                fg = Color.BLACK;
            }
        }
    }

    if (Color.BLACK.equals(fg) && Color.WHITE.equals(fg)) {
        return fg;
    }

    boolean replace = fg.equals(bg);
    int dif = 0;

    if (!replace) {
        dif = difference(fg, bg);
        replace = dif < 60;
    }

    if (replace) {
        int lum = luminance(bg);
        boolean darker = lum >= 128;

        if (darker) {
            fg = fg.darker();
        } else {
            fg = fg.brighter();
        }
    }

    return fg;
}
 
Example 20
Source Project: netbeans   File: CoverageBar.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected void paintComponent(Graphics g) {

    if (!(g instanceof Graphics2D)) {
        return;
    }

    int width = getWidth();
    int barRectWidth = width;
    int height = getHeight();
    int barRectHeight = height;

    if (barRectWidth <= 0 || barRectHeight <= 0) {
        return;
    }

    int amountFull = (int) (barRectWidth * coveragePercentage / 100.0f);

    Graphics2D g2 = (Graphics2D) g;

    g2.setColor(getBackground());

    Color notCoveredLight = NOT_COVERED_LIGHT;
    Color notCoveredDark = NOT_COVERED_DARK;
    Color coveredLight = COVERED_LIGHT;
    Color coveredDark = COVERED_DARK;
    if (emphasize) {
        coveredDark = coveredDark.darker();
    } else if (selected) {
        coveredLight = coveredLight.brighter();
        coveredDark = coveredDark.darker();
    }
    if (emphasize) {
        notCoveredDark = notCoveredDark.darker();
    } else if (selected) {
        notCoveredLight = notCoveredLight.brighter();
        notCoveredDark = notCoveredDark.darker();
    }

    g2.setPaint(new GradientPaint(0, 0, notCoveredLight,
            0, height / 2, notCoveredDark));
    g2.fillRect(amountFull, 1, width - 1, height / 2);
    g2.setPaint(new GradientPaint(0, height / 2, notCoveredDark,
            0, 2 * height, notCoveredLight));
    g2.fillRect(amountFull, height / 2, width - 1, height / 2);

    g2.setColor(getForeground());

    g2.setPaint(new GradientPaint(0, 0, coveredLight,
            0, height / 2, coveredDark));
    g2.fillRect(1, 1, amountFull, height / 2);
    g2.setPaint(new GradientPaint(0, height / 2, coveredDark,
            0, 2 * height, coveredLight));
    g2.fillRect(1, height / 2, amountFull, height / 2);

    Rectangle oldClip = g2.getClipBounds();
    if (coveragePercentage > 0.0f) {
        g2.setColor(coveredDark);
        g2.clipRect(0, 0, amountFull + 1, height);
        g2.drawRect(0, 0, width - 1, height - 1);
    }
    if (coveragePercentage < 100.0f) {
        g2.setColor(notCoveredDark);
        g2.setClip(oldClip);
        g2.clipRect(amountFull, 0, width, height);
        g2.drawRect(0, 0, width - 1, height - 1);
    }
    g2.setClip(oldClip);

    g2.setFont(getFont());
    paintDropShadowText(g2, barRectWidth, barRectHeight);
}