/** * 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)); }
/** * 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 hFactor Amount to scale the hue * @param lFactor Amount to scale the lightness * @param sFactor 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)); }
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); }
/** * 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); }
public static void main(final String[] args) throws InvocationTargetException, InterruptedException { SwingUtilities.invokeAndWait(() -> { UIDefaults ui = UIManager.getDefaults(); ui.put("control", new ColorUIResource(54, 54, 54)); final JDialog dialog = new JDialog(); final JFrame frame = new JFrame(); frame.pack(); dialog.pack(); final Color dialogBackground = dialog.getBackground(); final Color frameBackground = frame.getBackground(); frame.dispose(); dialog.dispose(); if (!dialogBackground.equals(frameBackground)) { System.err.println("Expected:" + frameBackground); System.err.println("Actual:" + dialogBackground); throw new RuntimeException("Wrong background color"); } }); }
/** * Takes a UIManager color key and ensures that it is stored as a * ColorUIResource, not a Color. */ private static void convert (String key) { Color c = UIManager.getColor(key); if (c != null && !(c instanceof ColorUIResource)) { UIManager.put (key, new ColorUIResource(c)); } }
public static void updateVirtualItemForTheme(Colors currentTheme) { if (currentTheme == null) { selectedThumbBorder = BorderFactory.createLineBorder(new ColorUIResource(122, 170, 233), 2); } else { selectedThumbBorder = BorderFactory.createLineBorder(currentTheme.getFileChooserColors()[1], 2); } }
@Override public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { g.translate(x, y); g.setColor(new ColorUIResource(90, 90, 90)); g.drawLine(0, 0, w - 1, 0); g.drawLine(0, 0, 0, h - 1); g.setColor(new ColorUIResource(255, 255, 255)); g.drawLine(w - 1, 1, w - 1, h - 1); g.drawLine(1, h - 1, w - 1, h - 1); g.translate(-x, -y); }
@Override public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { g.translate(x, y); g.setColor(new ColorUIResource(190, 190, 190)); g.drawLine(0, 0, w - 1, 0); g.drawLine(0, 0, 0, h - 1); g.setColor(new ColorUIResource(220, 220, 220)); g.drawLine(w - 1, 1, w - 1, h - 1); g.drawLine(1, h - 1, w - 1, h - 1); g.translate(-x, -y); }
@Override public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { g.translate(x, y); g.setColor(new ColorUIResource(220, 220, 220)); g.drawLine(0, 0, w, 0); g.drawLine(0, h - 1, w, h - 1); g.setColor(new ColorUIResource(200, 200, 200)); g.drawLine(0, 1, w, 1); g.drawLine(0, h - 2, w, h - 2); g.translate(-x, -y); }
@Override protected void paintToImage(Component c, Graphics g, int w, int h, Object[] args) { g.setColor(new ColorUIResource(252, 252, 252)); g.fillRect(0, 0, w, 3); Graphics2D g2 = (Graphics2D) g; g2.setPaint(new GradientPaint(0, 3, new ColorUIResource(252, 252, 252), 0, h - 3, new ColorUIResource(232, 232, 232))); g2.fillRect(0, 3, w, h - 3); }
private static void configureUI() { UIManager.put("ScrollBarUI", "com.transparentdiscord.UI.Custom.CustomScrollBarUI"); System.setProperty("awt.useSystemAAFontSettings", "on"); System.setProperty("swing.aatext", "true"); UIManager.put("ScrollBar.width", 4); UIManager.put("ScrollBar.track", new ColorUIResource(new Color(0,0,0,0))); UIManager.put("ScrollBar.thumb", new ColorUIResource(Color.decode("#99AAB5"))); UIManager.put("ScrollBar.thumbDarkShadow", new ColorUIResource(Color.decode("#99AAB5"))); UIManager.put("ScrollBar.thumbShadow", new ColorUIResource(Color.decode("#99AAB5"))); UIManager.put("ScrollBar.thumbHighlight", new ColorUIResource(Color.decode("#99AAB5"))); }
public void addCustomEntriesToTable(UIDefaults table) { super.addCustomEntriesToTable(table); // table.put("Button.gradient", Arrays.asList(new Object[] { // new Float(.3f), new Float(0f), new ColorUIResource(light_gray),// new // // ColorUIResource(0xDDE8F3), // new ColorUIResource(new Color(245,245,245)), getSecondary2() })); // Color cccccc = new ColorUIResource(0xCCCCCC); Color dadada = new ColorUIResource(0xDADADA); // Color c8ddf2 = new ColorUIResource(0xC8DDF2); List<Object> buttonGradient = Arrays.asList(new Object[] { new Float(1f), new Float(0f), getWhite(), dadada, new ColorUIResource(dadada) }); // Arrays.asList(new Object[] { // new Float(.3f), // new Float(0f), // new ColorUIResource(new Color(230, 230, 230)),// new // // ColorUIResource(0xDDE8F3), // new ColorUIResource(new Color(235, 235, 235)), // new ColorUIResource(new Color(180, 180, 180)) }); table.put("Button.gradient", buttonGradient); table.put("ScrollBar.gradient", buttonGradient); table.put("RadioButton.gradient", buttonGradient); table.put("RadioButtonMenuItem.gradient", buttonGradient); // table.put("ScrollBar.gradient", buttonGradient); // // table.put("Button.gradient", Arrays.asList(new Object[] { // new Float(.3f), new Float(0f), new ColorUIResource(Color.black),// // new // // ColorUIResource(0xDDE8F3), // getWhite(), getSecondary2() })); // // System.out.println(table.get("Button.gradient")); }
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); }
@Override protected ColorUIResource getPrimary3() { return primary3; }
@Override protected ColorUIResource getSecondary2() { return secondary2; }
public ColorUIResource getCommonBackground() { return PANEL_BACKGROUND; }
public ColorUIResource[] getTabbedPaneColors() { return this.tabbedPaneColors; }
@Override public ColorUIResource getAcceleratorForeground() { return getBlack(); }
public ColorUIResource getDesktopBackgroundColor() { return this.desktopBackgroundColor; }
@Override protected void initSystemColorDefaults(UIDefaults table) { Object[] systemColors = { "desktop", getDesktopColor(), /* Color of the desktop background */ "activeCaption", getWindowTitleBackground(), /* Color for captions (title bars) when they are active. */ "activeCaptionText", getWindowTitleForeground(), /* Text color for text in captions (title bars). */ "activeCaptionBorder", getPrimaryControlShadow(), /* Border color for caption (title bar) window borders. */ "inactiveCaption", getWindowTitleBackground(), /* Color for captions (title bars) when not active. */ "inactiveCaptionText", getWindowTitleForeground(), /* Text color for text in inactive captions (title bars). */ "inactiveCaptionBorder", getControlShadow(), /* Border color for inactive caption (title bar) window borders. */ "window", Colors.WINDOW_BACKGROUND, // getWindowBackground(), /* Default color for // the interior of windows */ "windowBorder", getColors().getCommonBackground(), /* ??? */ "windowText", getUserTextColor(), /* ??? */ "menu", getMenuBackground(), /* Background color for menus */ "menuText", getMenuForeground(), /* Text color for menus */ "text", getTextBackground(), "textText", getUserTextColor(), "textHighlight", getTextHighlightColor(), "textHighlightText", Colors.TEXT_HIGHLIGHT_FOREGROUND, "textInactiveText", getInactiveSystemTextColor(), "control", getColors().getCommonBackground(), "controlText", getControlTextColor(), /* * Default color for text in controls */ "controlHighlight", getControlHighlight(), /* Specular highlight (opposite of the shadow) */ "controlLtHighlight", getControlHighlight(), /* Highlight color for controls */ "controlShadow", getControlShadow(), /* Shadow color for controls */ "controlDkShadow", getControlDarkShadow(), /* Dark shadow color for controls */ "scrollbar", getColors().getCommonBackground(), /* Scrollbar background (usually the "track") */ "info", new ColorUIResource(252, 252, 252), /* ToolTip Background */ // "infoText", /* ToolTip Text */ }; for (int i = 0; i < systemColors.length; i += 2) { table.put(systemColors[i], systemColors[i + 1]); } }
public static ColorUIResource getDesktopColor() { return new ColorUIResource(0, 0, 0); }
@Override protected ColorUIResource getPrimary1() { return primary1; }
public static ColorUIResource getControlHighlight() { return new ColorUIResource(255, 255, 255); }
public static ColorUIResource getPrimaryControlDarkShadow() { return new ColorUIResource(70, 70, 70); }
public static ColorUIResource getPrimaryControlHighlight() { return new ColorUIResource(255, 255, 255); }
@Override protected ColorUIResource getSecondary3() { return sc3; }
@Override public ColorUIResource getMenuSelectedForeground() { return getWhite(); }
@Override protected ColorUIResource getBlack() { return black; }
public static ColorUIResource getWindowTitleBackground() { return new ColorUIResource(220, 225, 230); }
public static ColorUIResource getWindowTitleForeground() { return new ColorUIResource(255, 255, 255); }
public static ColorUIResource getMenuBackground() { return new ColorUIResource(250, 250, 250); }