private static float calculateScaleFactor() { if (SystemInfo.isMac) { return 1.0f; } if (SystemProperties.has("hidpi") && !SystemProperties.is("hidpi")) { return 1.0f; } if (SystemInfo.isLinux) { final int dpi = getSystemDPI(); if (dpi < 120) return 1f; if (dpi < 144) return 1.25f; if (dpi < 168) return 1.5f; if (dpi < 192) return 1.75f; return 2f; } int size = -1; /*try { if (SystemInfo.isWindows) { size = (Integer)Toolkit.getDefaultToolkit().getDesktopProperty("win.system.font.height"); } } catch (Exception e) {// } */ if (size == -1) { size = Fonts.label().getSize(); } if (size <= 13) return 1.0f; if (size <= 16) return 1.25f; if (size <= 18) return 1.5f; if (size < 24) return 1.75f; return 2.0f; }
public Rectangle getVisualBounds(JComponent c, int type, int width, int height) { Rectangle bounds = new Rectangle(0, 0, width, height); if (type == VisuallyLayoutable.CLIP_BOUNDS) { return bounds; } AbstractButton b = (AbstractButton) c; if (type == VisuallyLayoutable.COMPONENT_BOUNDS && b.getBorder() != null && b.isBorderPainted()) { Border border = b.getBorder(); if (border instanceof BackgroundBorder) { border = ((BackgroundBorder) border).getBackgroundBorder(); if (border instanceof VisualMargin) { InsetsUtil.subtractInto(((VisualMargin) border).getVisualMargin(c), bounds); } else if (border instanceof QuaquaButtonBorder) { InsetsUtil.subtractInto(((QuaquaButtonBorder) border).getVisualMargin(c), bounds); } } return bounds; } String text = b.getText(); boolean isEmpty = (text == null || text.length() == 0); if (isEmpty) { text = " "; } Icon icon = (b.isEnabled()) ? b.getIcon() : b.getDisabledIcon(); if ((icon == null) && (text == null)) { return null; } FontMetrics fm = c.getFontMetrics(c.getFont()); Insets insets = c.getInsets(viewInsets); viewR.x = insets.left; viewR.y = insets.top; viewR.width = width - (insets.left + insets.right); viewR.height = height - (insets.top + insets.bottom); iconR.x = iconR.y = iconR.width = iconR.height = 0; textR.x = textR.y = textR.width = textR.height = 0; String clippedText = layoutCL(b, fm, text, icon, viewR, iconR, textR); Rectangle textBounds = Fonts.getPerceivedBounds(text, c.getFont(), c); if (isEmpty) { textBounds.width = 0; } int ascent = fm.getAscent(); textR.x += textBounds.x; textR.width = textBounds.width; textR.y += ascent + textBounds.y; textR.height -= fm.getHeight() - textBounds.height; bounds.setBounds(textR); return bounds; }
private static float calculateScaleFactor() { if (SystemInfo.isMac) { return 1.0f; } if (SystemProperties.has("hidpi") && !SystemProperties.is("hidpi")) { return 1.0f; } // On Linux: rely on DPI if (SystemInfo.isLinux) { final int dpi = getSystemDPI(); if (dpi < 120) return 1f; if (dpi < 144) return 1.25f; if (dpi < 168) return 1.5f; if (dpi < 192) return 1.75f; return 2f; } int size = -1; // On Windows: rely on default system font if (SystemInfo.isWindows) { UIUtil.initSystemFontData(); Pair<String, Integer> fdata = UIUtil.getSystemFontData(); if (fdata != null) size = fdata.getSecond(); } if (size == -1) { size = Fonts.label().getSize(); } if (size <= 13) return 1.0f; if (size <= 16) return 1.25f; if (size <= 18) return 1.5f; if (size < 24) return 1.75f; return 2.0f; }
public class Theme { public static final Font FONT = Fonts.regular(); public static final Color BACKGROUND = new ColorUIResource(244, 244, 244); public static final Color FOREGROUND = new ColorUIResource(50, 50, 50); public static final Color DISABLED_FOREGROUND = new ColorUIResource(120, 120, 120); public static final Color SELECTION_BACKGROUND = new ColorUIResource(211, 211, 211); public static final Color SELECTION_FOREGROUND = new ColorUIResource(50, 50, 50); public static final Color FOCUS_BORDER_COLOR = new ColorUIResource(51, 173, 213); public static final Color CONTROL_BORDER_COLOR = new ColorUIResource(181, 181, 181); public static final Color CONTROL_DISABLED_BORDER_COLOR = new ColorUIResource(218, 218, 218); public static final Color CONTROL_SELECTED_BORDER_COLOR = new ColorUIResource(160, 160, 160); public static final Color CONTROL_DISABLED_INTERNAL_BORDER_HI_COLOR = new ColorUIResource(247, 247, 247); public static final Color CONTROL_DISABLED_INTERNAL_BORDER_LOW_COLOR = new ColorUIResource(236, 236, 236); public static final Color CONTROL_INTERNAL_BORDER_HI_COLOR = new ColorUIResource(254, 254, 254); public static final Color CONTROL_INTERNAL_BORDER_LOW_COLOR = new ColorUIResource(226, 226, 226); public static final Insets CONTROL_BORDER_INSETS = new InsetsUIResource(4, 8, 4, 8); public static final Color CONTROL_BACKGROUND_HI = new ColorUIResource(240, 240, 240); public static final Color CONTROL_BACKGROUND_LO = new ColorUIResource(215, 215, 215); public static final Color CONTROL_DISABLED_BACKGROUND_HI = new ColorUIResource(241, 241, 241); public static final Color CONTROL_DISABLED_BACKGROUND_LO = new ColorUIResource(233, 233, 233); public static final Color CONTROL_HOVER_BACKGROUND_HI = new ColorUIResource(250, 250, 250); public static final Color CONTROL_HOVER_BACKGROUND_LO = new ColorUIResource(226, 226, 226); public static final Color CONTROL_ARMED_BACKGROUND_HI = new ColorUIResource(228, 228, 228); public static final Color CONTROL_ARMED_BACKGROUND_LO = new ColorUIResource(207, 207, 207); public static final Color CONTROL_SELECTED_BACKGROUND_HI = new ColorUIResource(186, 186, 186); public static final Color CONTROL_SELECTED_BACKGROUND_LO = new ColorUIResource(210, 210, 210); public static final Color CONTROL_DISABLED_SELECTED_BACKGROUND_HI = new ColorUIResource(220, 220, 220); public static final Color CONTROL_DISABLED_SELECTED_BACKGROUND_LO = new ColorUIResource(230, 230, 230); public static final Color CONTROL_SELECTED_HOVER_BACKGROUND_HI = new ColorUIResource(195, 195, 195); public static final Color CONTROL_SELECTED_HOVER_BACKGROUND_LO = new ColorUIResource(220, 220, 220); public static final Color CONTROL_SELECTED_ARMED_BACKGROUND_HI = new ColorUIResource(175, 175, 175); public static final Color CONTROL_SELECTED_ARMED_BACKGROUND_LO = new ColorUIResource(197, 197, 197); public static final Border SCROLL_PANE_BORDER = new BorderUIResource.LineBorderUIResource(CONTROL_BORDER_COLOR, 1); public static final Color COMBOBOX_POPUP_BORDER_COLOR = new ColorUIResource(182, 182, 182); public static final Color TOOLBAR_BORDER_COLOR = new ColorUIResource(181, 181, 181); public static final Color TOOLBAR_BACKGROUND_HI_COLOR = new ColorUIResource(248, 248, 248); public static final Color TOOLBAR_BACKGROUND_LO_COLOR = new ColorUIResource(231, 231, 231); public static final Color CONTEXT_MENU_BORDER_COLOR = new ColorUIResource(195, 195, 195); public static final Border CONTEXT_MENU_BORDER = new BorderUIResource( BorderFactory.createCompoundBorder( BorderFactory.createLineBorder(CONTEXT_MENU_BORDER_COLOR, 1), BorderFactory.createEmptyBorder(2, 0, 2, 0))); public static final Color CONTEXT_MENU_BACKGROUND = new ColorUIResource(255, 255, 255); public static final Color TABS_BACKGROUND_HI = new ColorUIResource(227, 227, 227); public static final Color TABS_BACKGROUND_LOW = new ColorUIResource(208, 208, 208); public static final Color TABLE_GRID_COLOR = new ColorUIResource(160, 160, 160); // Presque blanc mais pas exactement (254, permet d'eviter que awt fasses des trucs bizarre quand // il paint // plusieurs fois la même cellule dans le cas des spans. public static final Color TABLE_CELL_BACKGROUND = new ColorUIResource(254, 254, 254); public static final Color TABLE_CELL_ALTERNATE_BACKGROUND = new ColorUIResource(244, 244, 244); public static final Border TABLE_CELL_FOCUS_BORDER = new BorderUIResource.LineBorderUIResource(FOCUS_BORDER_COLOR, 1); public static final Color TOOLTIP_BORDER_COLOR_HI = new ColorUIResource(122, 122, 122); public static final Color TOOLTIP_BORDER_COLOR_LO = new ColorUIResource(107, 107, 107); public static final Color TOOLTIP_BACKGROUND_LO = new ColorUIResource(55, 55, 55); public static final Color TOOLTIP_BACKGROUND_HI = new ColorUIResource(66, 66, 66); public static final Color LIST_BACKGROUND = new ColorUIResource(255, 255, 255); public static final Color TEXT_BACKGROUND = new ColorUIResource(255, 255, 255); }