Java Code Examples for javax.swing.JComponent#getForeground()

The following examples show how to use javax.swing.JComponent#getForeground() . 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: FlatLaf   File: FlatButtonUI.java    License: Apache License 2.0 5 votes vote down vote up
protected Color getForeground( JComponent c ) {
	if( !c.isEnabled() )
		return disabledText;

	// use component foreground if explicitly set
	Color fg = c.getForeground();
	if( isCustomForeground( fg ) )
		return fg;

	boolean def = isDefaultButton( c );
	return def ? defaultForeground : fg;
}
 
Example 2
Source Project: netbeans   File: MenuEditLayer.java    License: Apache License 2.0 5 votes vote down vote up
private void configureEditedComponent(JComponent c) {
    if(c == null) return;
    if(USE_NEW_ITEM_COLOR_SWITCHING) {
        if(c.getForeground() == Color.LIGHT_GRAY) {
            c.setForeground(getNormalForeground(c));
        }
    }
}
 
Example 3
Source Project: pumpernickel   File: ChasingArrowsThrobberUI.java    License: MIT License 5 votes vote down vote up
@Override
protected synchronized void paintForeground(Graphics2D g, JComponent jc,
		Dimension size, Float fixedFraction) {

	g.setStroke(stroke);

	float f;
	if (fixedFraction != null) {
		f = fixedFraction;
	} else {
		int p = getPeriod(jc, DEFAULT_PERIOD);
		f = System.currentTimeMillis() % p;
		f = f / ((float) p);
	}
	f = f * 2 * PI;

	Color color = jc == null ? getDefaultForeground() : jc.getForeground();
	g.setColor(color);

	for (int k = 0; k < 2; k++) {
		transform.setToRotation(f + k * Math.PI, size.width / 2,
				size.height / 2);

		path.reset();
		path.moveTo(x[0], y[0]);
		path.lineTo(x[1], y[1]);
		path.lineTo(x[2], y[2]);
		path.lineTo(x[0], y[0]);
		path.transform(transform);

		g.fill(path);

		path.reset();
		path.append(arc.getPathIterator(transform), false);
		g.draw(path);
	}
}
 
Example 4
Source Project: pumpernickel   File: AquaThrobberUI.java    License: MIT License 5 votes vote down vote up
@Override
public void paintForeground(Graphics2D g, JComponent jc, Dimension size,
		Float fixedFraction) {
	float f;
	if (fixedFraction == null) {
		int p = getPeriod(jc, DEFAULT_PERIOD);
		f = ((float) (System.currentTimeMillis() % p)) / ((float) p);
	} else {
		f = fixedFraction;
	}
	Color color = jc == null ? getDefaultForeground() : jc.getForeground();
	paint(g, f, color, size.width / 2, size.height / 2, 5, 8, 1.9f);
}
 
Example 5
Source Project: pumpernickel   File: PulsingCirclesThrobberUI.java    License: MIT License 5 votes vote down vote up
@Override
protected synchronized void paintForeground(Graphics2D g, JComponent jc,
		Dimension size, Float fixedFraction) {
	float f;
	if (fixedFraction != null) {
		f = fixedFraction;
	} else {
		int p = getPeriod(jc, DEFAULT_PERIOD);
		float t = System.currentTimeMillis() % p;
		f = t / p;
	}

	boolean spiral = false;
	double maxDotSize = spiral ? 2 : 2.2;

	Color color = jc == null ? getDefaultForeground() : jc.getForeground();
	g.setColor(color);
	for (int a = 0; a < 8; a++) {
		double z = a / 8.0;
		double r = spiral ? 6 * ((z - f + 1) % 1) : 6;
		double x = size.width / 2 + r * Math.cos(Math.PI * 2 * z);
		double y = size.width / 2 + r * Math.sin(Math.PI * 2 * z);
		double k = maxDotSize * ((z - f + 1) % 1);
		Ellipse2D dot = new Ellipse2D.Double(x - k, y - k, 2 * k, 2 * k);
		g.fill(dot);
	}
}
 
Example 6
public static void increaseTextBrightness(JComponent c) {
    Color color = c.getForeground();
    c.putClientProperty("mouseover_brightness", color);
    float[] hsb = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null);
    
    hsb[2] = Math.min(1.0f, hsb[2] * 2.0f);
    c.setForeground(Color.getHSBColor(hsb[0], hsb[1], hsb[2]));
}
 
Example 7
Source Project: netbeans   File: Coloring.java    License: Apache License 2.0 4 votes vote down vote up
/** Apply this coloring to component colors/font.
* The underline and strikeThrough line colors have no effect here.
*/
public void apply(JComponent c) {
    // Possibly change font
    if (font != null) {
        if (fontMode == FONT_MODE_DEFAULT) {
            c.setFont(font);

        } else { // non-default font-mode
            Font origFont = c.getFont();
            if (origFont != null) {
                synchronized (cacheLock) {
                    Font f = (Font)fontAndForeColorCache.get(origFont);
                    if (f == null) {
                        f = modifyFont(origFont);
                        fontAndForeColorCache.put(origFont, f);
                    }
                    c.setFont(f);
                }
            }
        }
    }

    // Possibly change fore-color
    if (foreColor != null) {
        if (!hasAlpha(foreColor)) {
            c.setForeground(foreColor);

        } else { // non-default fore color-mode
            Color origForeColor = c.getForeground();
            if (origForeColor != null) {
                synchronized (cacheLock) {
                    Color fc = (Color)fontAndForeColorCache.get(origForeColor);
                    if (fc == null) {
                        fc = modifyForeColor(origForeColor);
                        fontAndForeColorCache.put(origForeColor, fc);
                    }
                    c.setForeground(fc);
                }
            }
        }
    }

    // Possibly change back-color
    if (backColor != null) {
        if (!hasAlpha(backColor)) {
            c.setBackground(backColor);

        } else { // non-default back color-mode
            Color origBackColor = c.getBackground();
            if (origBackColor != null) {
                synchronized (cacheLock) {
                    Color bc = (Color)backColorCache.get(origBackColor);
                    if (bc == null) {
                        bc = modifyBackColor(origBackColor);
                        backColorCache.put(origBackColor, bc);
                    }
                    c.setBackground(bc);
                }
            }
        }
    }
}
 
Example 8
Source Project: PolyGlot   File: PGTUtil.java    License: MIT License 4 votes vote down vote up
/**
 * gets a worker that can make a given component flash
 *
 * @param flashMe component to make flash
 * @param flashColor color to use for flashing
 * @param isBack whether display color is background (rather than foreground)
 * @return SwingWorker that will make given component flash if run
 */
public static SwingWorker getFlashWorker(final JComponent flashMe, final Color flashColor, final boolean isBack) {
    // this will pop out in its own little thread...
    return new SwingWorker() {
        @Override
        protected Object doInBackground() {
            Color originColor;
            if (isBack) {
                originColor = flashMe.getBackground();
            } else {
                originColor = flashMe.getForeground();
            }

            Color requiredColor = flashColor.equals(originColor)
                    ? Color.white : flashColor;

            try {
                for (int i = 0; i < PGTUtil.NUM_MENU_FLASHES; i++) {
                    if (isBack) {
                        flashMe.setBackground(requiredColor);
                    } else {
                        flashMe.setEnabled(false);
                    }
                    // suppression for this is broken. Super annoying.
                    Thread.sleep(PGTUtil.MENU_FLASH_SLEEP);
                    if (isBack) {
                        flashMe.setBackground(originColor);
                    } else {
                        flashMe.setEnabled(true);
                    }
                    Thread.sleep(PGTUtil.MENU_FLASH_SLEEP);
                }
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                // catch of thread interrupt not logworthy
                // IOHandler.writeErrorLog(e);
            }

            return null;
        }
    };
}