javax.swing.plaf.ColorUIResource Java Examples

The following examples show how to use javax.swing.plaf.ColorUIResource. 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: PropertiesMetalTheme.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * parse a comma delimited list of 3 strings into a Color
 */
private ColorUIResource parseColor(String s) {
    int red = 0;
    int green = 0;
    int blue = 0;
    try {
        StringTokenizer st = new StringTokenizer(s, ",");

        red = Integer.parseInt(st.nextToken());
        green = Integer.parseInt(st.nextToken());
        blue = Integer.parseInt(st.nextToken());

    } catch (Exception e) {
        System.out.println(e);
        System.out.println("Couldn't parse color :" + s);
    }

    return new ColorUIResource(red, green, blue);
}
 
Example #2
Source File: PropertiesMetalTheme.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * parse a comma delimited list of 3 strings into a Color
 */
private ColorUIResource parseColor(String s) {
    int red = 0;
    int green = 0;
    int blue = 0;
    try {
        StringTokenizer st = new StringTokenizer(s, ",");

        red = Integer.parseInt(st.nextToken());
        green = Integer.parseInt(st.nextToken());
        blue = Integer.parseInt(st.nextToken());

    } catch (Exception e) {
        System.out.println(e);
        System.out.println("Couldn't parse color :" + s);
    }

    return new ColorUIResource(red, green, blue);
}
 
Example #3
Source File: ColorCustomizationTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
void testNames() {
    Color defaultColor = label.getBackground();

    UIManager.put("\"BlueLabel\"[Enabled].background",
            new ColorUIResource(Color.BLUE));
    UIManager.put("\"RedLabel\"[Enabled].background",
            new ColorUIResource(Color.RED));
    nimbus.register(Region.LABEL, "\"BlueLabel\"");
    nimbus.register(Region.LABEL, "\"RedLabel\"");

    label.setName("BlueLabel");
    check(Color.BLUE);
    label.setName("RedLabel");
    check(Color.RED);

    // remove name, color goes back to default
    label.setName(null);
    check(defaultColor);
}
 
Example #4
Source File: IntelliJTheme.java    From FlatLaf with Apache License 2.0 6 votes vote down vote up
private void applyColorPalette( UIDefaults defaults ) {
	if( icons == null )
		return;

	Object palette = icons.get( "ColorPalette" );
	if( !(palette instanceof Map) )
		return;

	@SuppressWarnings( "unchecked" )
	Map<String, Object> colorPalette = (Map<String, Object>) palette;
	for( Map.Entry<String, Object> e : colorPalette.entrySet() ) {
		String key = e.getKey();
		Object value = e.getValue();
		if( key.startsWith( "Checkbox." ) || !(value instanceof String) )
			continue;

		if( dark )
			key = StringUtils.removeTrailing( key, ".Dark" );

		ColorUIResource color = toColor( (String) value );
		if( color != null )
			defaults.put( key, color );
	}
}
 
Example #5
Source File: IntelliJTheme.java    From FlatLaf with Apache License 2.0 6 votes vote down vote up
/**
 * http://www.jetbrains.org/intellij/sdk/docs/reference_guide/ui_themes/themes_customize.html#defining-named-colors
 */
private void loadNamedColors( UIDefaults defaults ) {
	if( colors == null )
		return;

	namedColors = new HashMap<>();

	for( Map.Entry<String, String> e : colors.entrySet() ) {
		String value = e.getValue();
		ColorUIResource color = UIDefaultsLoader.parseColor( value );
		if( color != null ) {
			String key = e.getKey();
			namedColors.put( key, color );
			defaults.put( "ColorPalette." + key, color );
		}
	}
}
 
Example #6
Source File: GTKColorType.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates and returns a new color derived from the passed in color.
 * The transformation is done in the HLS color space using the specified
 * arguments to scale.
 *
 * @param color Color to alter
 * @param hFactory Amount to scale the hue
 * @param lFactor Amount to scale the lightness
 * @param sFactory Amount to sacle saturation
 * @return newly created color
 */
static Color adjustColor(Color color, float hFactor, float lFactor,
                         float sFactor) {
    float h;
    float l;
    float s;

    synchronized(HLS_COLOR_LOCK) {
        float[] hls = rgbToHLS(color.getRGB(), HLS_COLORS);
        h = hls[0];
        l = hls[1];
        s = hls[2];
    }
    h = Math.min(360, hFactor * h);
    l = Math.min(1, lFactor * l);
    s = Math.min(1, sFactor * s);
    return new ColorUIResource(hlsToRGB(h, l, s));
}
 
Example #7
Source File: UIManagerDefaults.java    From darklaf with MIT License 6 votes vote down vote up
private String getComponentName(final String key, final Object value) {
    // The key is of the form:
    // "componentName.componentProperty", or
    // "componentNameUI", or
    // "someOtherString"
    String componentName;
    final int pos = componentNameEndOffset(key);
    if (pos != -1) {
        componentName = key.substring(0, pos);
    } else if (key.endsWith("UI")) {
        componentName = key.substring(0, key.length() - 2);
    } else if (value instanceof ColorUIResource) {
        componentName = "System Colors";
    } else {
        componentName = "Miscellaneous";
    }
    // Fix inconsistency
    if (componentName.equals("Checkbox")) {
        componentName = "CheckBox";
    }
    return componentName;
}
 
Example #8
Source File: ForegroundColorGenerationTask.java    From darklaf with MIT License 6 votes vote down vote up
public static ColorUIResource makeAdjustedForeground(final Color fg, final Color bg, final Bias bias,
                                                     final double minimumBrightnessDifference) {
    final double[] hslFG = DarkColorModelHSL.RGBtoHSLValues(fg.getRed(), fg.getGreen(), fg.getBlue());
    final double[] hslBG = DarkColorModelHSL.RGBtoHSLValues(bg.getRed(), bg.getGreen(), bg.getBlue());
    double bgBrightness = hslBG[2];
    double fgBrightness = hslFG[2];

    Bias b = bias != null ? bias : Bias.getBackground();

    if (b == Bias.BACKGROUND) {
        double bgBright = ColorUtil.getLuminance(bg);
        b = bgBright <= b.threshold ? Bias.WHITE : Bias.BLACK;
    }

    double bright1 = fgBrightness > bgBrightness && (fgBrightness - bgBrightness) >= minimumBrightnessDifference
            ? hslFG[2]
            : Math.min(bgBrightness + minimumBrightnessDifference, 1);
    double bright2 = fgBrightness < bgBrightness && (bgBrightness - fgBrightness) >= minimumBrightnessDifference
            ? hslFG[2]
            : Math.max(bgBrightness - minimumBrightnessDifference, 0);

    double brightness = b == Bias.WHITE ? bright1 : bright2;
    return new DarkColorUIResource(DarkColorModelHSL.getColorFromHSLValues(hslFG[0], hslFG[1], brightness));
}
 
Example #9
Source File: Metacity.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static Color parseColorString(String str) {
    if (str.charAt(0) == '#') {
        str = str.substring(1);

        int i = str.length();

        if (i < 3 || i > 12 || (i % 3) != 0) {
            return null;
        }

        i /= 3;

        int r;
        int g;
        int b;

        try {
            r = Integer.parseInt(str.substring(0, i), 16);
            g = Integer.parseInt(str.substring(i, i * 2), 16);
            b = Integer.parseInt(str.substring(i * 2, i * 3), 16);
        } catch (NumberFormatException nfe) {
            return null;
        }

        if (i == 4) {
            return new ColorUIResource(r / 65535.0f, g / 65535.0f, b / 65535.0f);
        } else if (i == 1) {
            return new ColorUIResource(r / 15.0f, g / 15.0f, b / 15.0f);
        } else if (i == 2) {
            return new ColorUIResource(r, g, b);
        } else {
            return new ColorUIResource(r / 4095.0f, g / 4095.0f, b / 4095.0f);
        }
    } else {
        return XColors.lookupColor(str);
    }
}
 
Example #10
Source File: FlatTestFrame.java    From FlatLaf with Apache License 2.0 5 votes vote down vote up
private void explicitColorsChanged() {
	EventQueue.invokeLater( () -> {
		boolean explicit = explicitColorsCheckBox.isSelected();
		ColorUIResource restoreColor = new ColorUIResource( Color.white );

		boolean dark = FlatLaf.isLafDark();
		Color magenta = dark ? Color.magenta.darker() : Color.magenta;
		Color orange = dark ? Color.orange.darker() : Color.orange;
		Color blue = dark ? Color.blue.darker() : Color.blue;
		Color green = dark ? Color.green.darker() : Color.green;

		updateComponentsRecur( content, (c, type) -> {
			if( type == "view" || type == "tab" ) {
				c.setForeground( explicit ? magenta : restoreColor );
				c.setBackground( explicit ? orange : restoreColor );
			} else {
				c.setForeground( explicit ? blue : restoreColor );
				c.setBackground( explicit ? green : restoreColor );
			}
		} );

		// because colors may depend on state (e.g. disabled JTextField)
		// it is best to update all UI delegates to get correct result
		if( !explicit )
			SwingUtilities.updateComponentTreeUI( content );
	} );
}
 
Example #11
Source File: IntelliJTheme.java    From FlatLaf with Apache License 2.0 5 votes vote down vote up
private ColorUIResource toColor( String value ) {
	// map named colors
	ColorUIResource color = namedColors.get( value );

	// parse color
	return (color != null) ? color : UIDefaultsLoader.parseColor( value );
}
 
Example #12
Source File: Metacity.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static Color parseColorString(String str) {
    if (str.charAt(0) == '#') {
        str = str.substring(1);

        int i = str.length();

        if (i < 3 || i > 12 || (i % 3) != 0) {
            return null;
        }

        i /= 3;

        int r;
        int g;
        int b;

        try {
            r = Integer.parseInt(str.substring(0, i), 16);
            g = Integer.parseInt(str.substring(i, i * 2), 16);
            b = Integer.parseInt(str.substring(i * 2, i * 3), 16);
        } catch (NumberFormatException nfe) {
            return null;
        }

        if (i == 4) {
            return new ColorUIResource(r / 65535.0f, g / 65535.0f, b / 65535.0f);
        } else if (i == 1) {
            return new ColorUIResource(r / 15.0f, g / 15.0f, b / 15.0f);
        } else if (i == 2) {
            return new ColorUIResource(r, g, b);
        } else {
            return new ColorUIResource(r / 4095.0f, g / 4095.0f, b / 4095.0f);
        }
    } else {
        return XColors.lookupColor(str);
    }
}
 
Example #13
Source File: ColorCustomizationTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
void testInheritance() {
    Color defaultColor = label.getBackground();

    // more specific setting is in global defaults
    UIManager.put("Label[Enabled].background", new ColorUIResource(Color.RED));

    // less specific one is in overrides
    UIDefaults defs = new UIDefaults();
    defs.put("Label.background", new ColorUIResource(Color.GREEN));

    // global wins
    label.putClientProperty("Nimbus.Overrides", defs);
    check(Color.RED);

    // now override wins
    label.putClientProperty("Nimbus.Overrides.InheritDefaults", false);
    check(Color.GREEN);

    // global is back
    label.putClientProperty("Nimbus.Overrides.InheritDefaults", true);
    check(Color.RED);

    // back to default color
    UIManager.put("Label[Enabled].background", null);
    label.putClientProperty("Nimbus.Overrides.InheritDefaults", false);
    label.putClientProperty("Nimbus.Overrides", null);
    check(defaultColor);
}
 
Example #14
Source File: UIDefaultsLoader.java    From FlatLaf with Apache License 2.0 5 votes vote down vote up
/**
 * Syntax: hsl(hue,saturation,lightness) or hsla(hue,saturation,lightness,alpha)
 *   - hue: an integer 0-360 representing degrees
 *   - saturation: a percentage 0-100%
 *   - lightness: a percentage 0-100%
 *   - alpha: a percentage 0-100%
 */
private static ColorUIResource parseColorHslOrHsla( boolean hasAlpha, List<String> params ) {
	int hue = parseInteger( params.get( 0 ), 0, 360, false );
	int saturation = parsePercentage( params.get( 1 ) );
	int lightness = parsePercentage( params.get( 2 ) );
	int alpha = hasAlpha ? parsePercentage( params.get( 3 ) ) : 100;

	float[] hsl = new float[] { hue, saturation, lightness };
	return new ColorUIResource( HSLColor.toRGB( hsl, alpha / 100f ) );
}
 
Example #15
Source File: GreenMetalTheme.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected ColorUIResource getPrimary1() {
    return primary1;
}
 
Example #16
Source File: PropertiesMetalTheme.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected ColorUIResource getWhite() {
    return white;
}
 
Example #17
Source File: ContrastMetalTheme.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public ColorUIResource getPrimaryControlHighlight() {
    return primaryHighlight;
}
 
Example #18
Source File: KhakiMetalTheme.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected ColorUIResource getSecondary2() {
    return secondary2;
}
 
Example #19
Source File: javax_swing_plaf_ColorUIResource.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
protected ColorUIResource getObject() {
    return new ColorUIResource(0x44, 0x22, 0x11);
}
 
Example #20
Source File: AquaMetalTheme.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected ColorUIResource getPrimary3() {
    return primary3;
}
 
Example #21
Source File: AquaMetalTheme.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected ColorUIResource getPrimary2() {
    return primary2;
}
 
Example #22
Source File: javax_swing_plaf_ColorUIResource.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
protected ColorUIResource getAnotherObject() {
    return null; // TODO: could not update property
    // return new ColorUIResource(Color.BLACK);
}
 
Example #23
Source File: ContrastMetalTheme.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public ColorUIResource getHighlightedTextColor() {
    return getWhite();
}
 
Example #24
Source File: KhakiMetalTheme.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected ColorUIResource getSecondary2() {
    return secondary2;
}
 
Example #25
Source File: KhakiMetalTheme.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected ColorUIResource getPrimary3() {
    return primary3;
}
 
Example #26
Source File: KhakiMetalTheme.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected ColorUIResource getPrimary3() {
    return primary3;
}
 
Example #27
Source File: KhakiMetalTheme.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected ColorUIResource getPrimary2() {
    return primary2;
}
 
Example #28
Source File: KhakiMetalTheme.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected ColorUIResource getPrimary1() {
    return primary1;
}
 
Example #29
Source File: GreenMetalTheme.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected ColorUIResource getPrimary2() {
    return primary2;
}
 
Example #30
Source File: GreenMetalTheme.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected ColorUIResource getPrimary3() {
    return primary3;
}