Compare commits

..

404 Commits

Author SHA1 Message Date
Karl Tauber
a253b6c0cf release 1.6.1 2021-10-14 22:35:33 +02:00
Karl Tauber
efcbc1fbdb Native window decorations: catch UnsatisfiedLinkError when trying to load jawt.dll to avoid an application crash (Java 8 on Windows 10 only) 2021-10-14 18:59:26 +02:00
Karl Tauber
ae28c595f9 release 1.6 2021-09-14 15:00:29 +02:00
Karl Tauber
1d08ddda60 InternalFrame: added missing since 1.6 2021-09-14 14:56:21 +02:00
Karl Tauber
578379fd00 Table and TableHeader: renamed UI keys Table[Header].showLastVerticalLine to Table[Header].showTrailingVerticalLine (issue #332) 2021-09-14 14:31:17 +02:00
Karl Tauber
7c9f550d4c ComboBox: fixed popup location if shown above of combo box (Java 8 only) 2021-09-14 14:16:53 +02:00
Karl Tauber
84d4510d70 ComboBox: fixed popup border painting on HiDPI screens (e.g. at 150% scaling) 2021-09-14 12:46:51 +02:00
Karl Tauber
fa194ec258 TableHeader: fixed missing trailing vertical separator line if used in upper left corner of scroll pane (issue #332) 2021-09-14 00:52:59 +02:00
Karl Tauber
fd56de403d Slider: fixed calculation of baseline (see also PR #214) 2021-09-13 22:05:48 +02:00
Karl Tauber
85fde46504 Testing: FlatSingleComponentTest: revalidate and repaint when changing component orientation using Alt+R 2021-09-13 10:11:09 +02:00
Karl Tauber
b283178979 Spinner: fixed painting of border corners on left side (issue #382; regression since FlatLaf 1.4)
ComboBox (editable): fixed wrong border of internal text field under special circumstances
2021-09-10 16:37:07 +02:00
Karl Tauber
bddef38a7c Theme Editor: preview: added "editable" check box for text components 2021-09-08 00:22:02 +02:00
Karl Tauber
b5f2f77944 Theme Editor: layout of "All" preview tab improvements:
- right align "enabled" and "focused" check boxes
- two columns for controls
- removed help button
- JTextArea, JEditorPane and JTextPane in single line
- reduced some vertical gaps
2021-09-08 00:10:53 +02:00
Karl Tauber
fca0718ed0 Native window decorations: fixed unwanted uninstall of native window border when using JInternalFrame (which has its own JRootPane) and invoking updateUI() on internal frame (e.g. in preview of FlatLaf Theme Editor) 2021-09-07 17:55:45 +02:00
Karl Tauber
0d44ade6ea Theme Editor: preview improvements:
- remember state of "enabled", "focused" and "buttonType" and sync it with all editors
- added "_" button near "JMenuBar" label to test menu underline selection
2021-09-07 14:31:09 +02:00
Karl Tauber
6018f83a22 Theme Editor: center some labels and help buttons in preview 2021-09-05 22:15:49 +02:00
Karl Tauber
0b6247851b Theme Editor: fixed preview of focused list and table selection 2021-09-05 22:05:21 +02:00
Karl Tauber
8640dee053 Theme Editor: preview improvements:
- added "focused" checkbox to "All" tab to preview focused components
- added "button type" selector to "Buttons" tab
- added "unfocused"/"focused" header labels to "Buttons" and "Switches" tabs
- use local variables instead of fields where possible
2021-09-05 21:08:36 +02:00
Karl Tauber
824db2e3bd Table and TableHeader: added UI defaults to show last vertical line (issue #332) 2021-09-05 11:51:28 +02:00
Karl Tauber
c2c79c4676 Theme Editor:
- remember last used preview tab
- sync selected preview tab with all editors
2021-09-05 11:13:29 +02:00
Karl Tauber
4795fe5687 Theme Editor:
- added preview of buttons, checkboxes, radiobuttons, etc in various states (hover, pressed, focused, selected, disabled)
  (copied from `FlatComponentStateTest`)
- moved components preview panel from FlatThemePreview.jfd` to FlatThemePreviewAll.jfd`
- added tabs at top of preview area
2021-09-05 10:55:51 +02:00
Karl Tauber
d508f339c1 TableHeader: do not show resize cursor for last column if resizing last column is not possible because auto resize mode of table is not off (issue #332) 2021-09-04 18:20:21 +02:00
Karl Tauber
c7054537e7 Testing: FlatSingleComponentTest: support changing component orientation using Alt+R 2021-09-04 13:28:02 +02:00
Karl Tauber
b98b904023 added missing UI defaults to javadoc 2021-09-04 13:24:19 +02:00
Karl Tauber
253df9325d Extras: FlatAnimatedLafChange: made animated Laf change transition smoother 2021-09-04 13:19:12 +02:00
Karl Tauber
78a9cc1d0c Theme Editor: fixed: editor was not focused after startup or when switching directory 2021-09-03 17:32:59 +02:00
Karl Tauber
b25fcc3381 OptionPane: fixed rendering of longer HTML text if it is passed as StringBuilder, StringBuffer, or any other object that returns HTML text in method toString() (similar to issue #12) 2021-09-03 11:26:30 +02:00
Karl Tauber
51d7bc2c37 TextField, FormattedTextField, PasswordField and ComboBox: fixed alignment of placeholder text in right-to-left component orientation 2021-09-02 16:18:53 +02:00
Karl Tauber
09a18b2305 Theme Editor:
- highlight opened directory in history combobox list
- support removing directories from history ('x' button in combobox list)
2021-08-29 18:39:40 +02:00
Karl Tauber
31f2feee2e Theme Editor:
- special renderer for directory history combobox list that dimes path parts
- disable menu items and buttons if no directory or editor is open
- set editor font size when opening new editor if increased/decreased
2021-08-29 16:06:50 +02:00
Karl Tauber
218bb62bfd Theme Editor:
- fixed increasing layout and wrong top border color of find/replace bar when switching Laf
- fixed duplicate keys in reference auto-completion
2021-08-29 14:28:11 +02:00
Karl Tauber
694c2ad767 Theme Editor: preview improvements:
- added JSplitPane (contains JList and JTree)
- sort first column in JTable to have preview of sort direction arrow
- fixed background color of JEditorPane and JTextPane when enabling/disabling
- keep first JMenu enabled, but disable the menu items
2021-08-29 11:44:38 +02:00
Karl Tauber
97943fcd38 Theme Editor: changed main class to com.formdev.flatlaf.themeeditor.FlatThemeEditor 2021-08-28 17:38:51 +02:00
Karl Tauber
77f33467d2 Theme Editor: fixed endless look in "replace all" when replacing e.g. "a" with "aa" 2021-08-28 17:37:02 +02:00
Karl Tauber
651454170d Theme Editor:
- fixed duplicate lines action if selection includes line separator at the end
- preview: do not disable internal components of JInternalFrame
2021-08-28 14:30:11 +02:00
Karl Tauber
7ca48bd136 Theme Editor:
- support lazy values and icon colors in overlay color preview
- support icon colors in preview
- support icon colors in reference auto-completion
- support changing preview theme when editing FlatLaf.properties via adding `@baseTheme = dark|darcula|intellij`
2021-08-28 14:18:11 +02:00
Karl Tauber
968e508bb5 Theme Editor:
- change border color of find field to red if noting found/matches
- update search match highlighting after reloading file on external change
2021-08-27 22:53:04 +02:00
Karl Tauber
a6d318a197 Theme Editor: fixed missing keys (e.g. Button.foreground) in reference auto-completion, which are defined as wildcards or have some prefix 2021-08-27 22:32:59 +02:00
Karl Tauber
cd20f4086b Theme Editor: fixed preview of focused button in FlatDarkLaf (and probably other null value related issues) 2021-08-27 18:32:42 +02:00
Karl Tauber
ebd5905947 Theme Editor: preview improvements:
- added JToolBar, JProgressBar with string painted, JDesktopPane and JInternalFrame
- placed text components side-by-side to save vertical space
- changed button texts and removed tooltips
- fixed painting of table cell focus border
- added missing add.svg
2021-08-27 16:10:10 +02:00
Karl Tauber
817a3c62bb Theme Editor: preview improvements:
- fixed table header borders (runWithUIDefaultsGetter() in paint())
- cache lazy values
- use runWithUIDefaultsGetter() in layout(), validateTree() and paint()
2021-08-24 22:32:48 +02:00
Karl Tauber
f8f58400fe Theme Editor: added list, tree and table to preview 2021-08-24 21:49:09 +02:00
Karl Tauber
ef06840649 Theme Editor: basic README.md with shapshot download link 2021-08-24 18:38:21 +02:00
Karl Tauber
b17c14d62e Theme Editor: use UTF-8 encoding to load properties files 2021-08-24 17:50:03 +02:00
Karl Tauber
19dba94064 IntelliJ Themes: removed deprecated install() methods
but keep them in the flatlaf-core for API compatibility in NetBeans plugin
2021-08-24 17:38:19 +02:00
Karl Tauber
601e24f9e7 Theme Editor: fixed "..." in menus 2021-08-24 16:52:45 +02:00
Karl Tauber
c7f323ee13 Theme Editor: added window icon 2021-08-24 16:49:55 +02:00
Karl Tauber
e4522f3af4 Theme Editor: added "About" dialog
Demo: updated "About" dialog
2021-08-24 16:40:17 +02:00
Karl Tauber
79af461a5b Theme Editor: instead of creating empty FlatLightLaf.properties and FlatDarkLaf.properties, add some how-to-use description to those files 2021-08-24 15:38:15 +02:00
Karl Tauber
2e8e07faf6 Theme Editor: auto-completion for keys improved:
- now also contains variables and keys defined in current and base themes
- appended " = "
- removes some unsupported keys (fonts and input maps)
2021-08-24 15:13:30 +02:00
Karl Tauber
ecdb000818 Theme Editor: avoid changing editor text (and adding item to undo history) when simply pressing OK button in "Insert Color" dialog without changing anything 2021-08-23 23:56:27 +02:00
Karl Tauber
999fd0d4da Theme Editor: generate .java file when creating new theme 2021-08-23 23:52:22 +02:00
Karl Tauber
705dd9558f Theme Editor:
- added "New Properties File" action to "File" menu
- added "+" button to tabbed pane
- ask to create .properties files when opening a directory that does not contain .properties files
- fixed Darcula baseTheme/preview
2021-08-23 23:02:41 +02:00
Karl Tauber
97ca866ffa OptionPane: fixed OptionPane.sameSizeButtons, which did not work as expected when setting to false 2021-08-23 16:53:23 +02:00
Karl Tauber
543b977db7 updated SVG icons from IntelliJ IDEA Community Edition to latest versions that include license header; added license header to SVGs where it were missing 2021-08-23 15:57:26 +02:00
Karl Tauber
ebb8a6d025 Theme Editor: ignore custom UI delegates in preview 2021-08-23 15:00:28 +02:00
Karl Tauber
506543281e Theme Editor: "Insert Color" dialog now immediately updates editor with new color, which updates "live" preview; also save/restore location of dialog 2021-08-23 14:41:53 +02:00
Karl Tauber
60322be22a Theme Editor: added "Insert Color" action to "Edit" menu that opens a color chooser dialog and inserts/edits a color at caret position 2021-08-23 14:06:18 +02:00
Karl Tauber
e1f30f24a8 Theme Editor: to toggle comment, add Ctrl+7 for German keyboards where Ctrl+/ does not work 2021-08-22 17:34:18 +02:00
Karl Tauber
1759f6b25c Theme Editor: increment/decrement color parts (red, green, blue or alpha) at caret using Ctrl+UP/Ctrl+DOWN 2021-08-22 17:26:29 +02:00
Karl Tauber
6578f25cc9 GitHub Actions: upload theme editor 2021-08-22 16:10:29 +02:00
Karl Tauber
8c26e0323f Theme Editor: increment/decrement numbers at caret using Ctrl+UP/Ctrl+DOWN 2021-08-22 15:33:29 +02:00
Karl Tauber
a5575894ab Theme Editor:
- update preview after 300ms (was 500ms)
- added separator between editor and preview
2021-08-22 14:26:18 +02:00
Karl Tauber
357823a027 Theme Editor: added "Show HSL/RGB colors" menu items to "View" menu to control display of color models in overlay color preview 2021-08-22 12:34:48 +02:00
Karl Tauber
a6d3f6b3eb Theme Editor: added menu components to preview 2021-08-22 11:19:47 +02:00
Karl Tauber
ae4c69e75c Theme Editor: fixed preview when switching Laf 2021-08-22 11:13:05 +02:00
Karl Tauber
31cadc532b Theme Editor:
- F12 now activates editor if focus is in preview or in find/replace
- changed accelerators for light/dark themes from F11/F12 to Alt+F1/F2
2021-08-22 00:33:34 +02:00
Karl Tauber
6e8443473b Theme Editor: special order for tabs: first core themes, then other themes 2021-08-21 23:27:43 +02:00
Karl Tauber
cca4ab3cd8 Theme Editor: fixed tabbed pane "more tabs" popup in preview 2021-08-21 18:24:57 +02:00
Karl Tauber
dab0ee3306 Theme Editor: added "live" preview 2021-08-21 18:09:59 +02:00
Karl Tauber
c6d1ed91a7 Menus: fixed missing modifiers flags in ActionEvent (issue #371; regression since FlatLaf 1.3) 2021-08-13 20:32:07 +02:00
Karl Tauber
a613a244f4 InternalFrame: double-click on icon in internal frame title bar now closes the internal frame (issue #374) 2021-08-13 19:11:03 +02:00
Karl Tauber
268fe15004 Tree: improved support for JTree.getPathForLocation(int x, int y) in wide selection (issue #373)
this is experimental and disabled by default; enable with:
`UIManager.put( "FlatLaf.experimental.tree.widePathForLocation", true );`
2021-08-13 00:19:34 +02:00
Karl Tauber
7bc9be686f FlatLaf: use larger initial capacity for UI defaults table to avoid resizing hash table and to save some memory 2021-08-13 00:13:54 +02:00
Karl Tauber
751919ec5a Theme Editor: find/replace improvements:
- while typing in find field, select match near caret and scroll to it
- PageUp/PageDown keys scroll editor if find/replace fields have focus
2021-08-12 22:05:08 +02:00
Karl Tauber
da913b426e Theme Editor: paint current line highlight always in the line where the caret is, which makes it easier to locate current match when using find/replace
RSyntaxTextArea paints line highlight only if selection is empty (caret dot == mark)
2021-08-11 23:59:33 +02:00
Karl Tauber
d8ef99cd8f Theme Editor: support resolving properties that use wildcards 2021-08-11 23:24:55 +02:00
Karl Tauber
d08a6d7dd3 Theme Editor: support loading/resolving base properties from core themes 2021-08-11 22:38:35 +02:00
Karl Tauber
896e9bca8e Theme Editor: re-implemented support loading/resolving base properties from other editors in opened directory 2021-08-11 21:53:10 +02:00
Karl Tauber
1df9597bb1 Theme Editor: support Ctrl+PageDown/PageUp to switch to next/previous editor 2021-08-09 10:19:24 +02:00
Karl Tauber
eaf55f2099 Theme Editor: store unscaled window bounds in preferences so that using Java 8 or 9+ results in same size on screen 2021-08-08 19:15:10 +02:00
Karl Tauber
5018a1f9eb Theme Editor: increase/decrease editor font size 2021-08-08 19:14:46 +02:00
Karl Tauber
71ba8f55a7 Theme Editor:
- support dark theme (menu "View > Dark Laf")
- moved RSyntaxTextArea theme config from XML to properties files
- bracket matching enabled
- highlight selected tab background
2021-08-08 17:43:59 +02:00
Karl Tauber
b65db707ed Theme Editor: auto-completion improved: support auto-activate after spaces, tabs or ',' 2021-08-07 14:59:20 +02:00
Karl Tauber
ed62266a43 Theme Editor: always select all text in find/replace text fields 2021-08-07 12:55:25 +02:00
Karl Tauber
49913b7dad Theme Editor: duplicate lines with Ctrl+Alt+Up or Ctrl+Alt+Down 2021-08-07 12:51:00 +02:00
Karl Tauber
3eeeb9e00b Theme Editor: update RSyntaxTextArea from 3.1.2 to 3.1.3 2021-08-07 11:18:00 +02:00
Karl Tauber
bfb1642284 UIDefaultsDump: dump HSL color values 2021-08-06 10:45:57 +02:00
Karl Tauber
0544a605c3 UIDefaultsLoader: added tint() and shade() color functions (inspired by Less CSS) 2021-08-05 23:37:42 +02:00
Karl Tauber
3f5acda132 UI defaults inspector: round HSL values (as also done in theme editor) 2021-08-05 18:49:03 +02:00
Karl Tauber
02b1ba2926 UIDefaultsLoader: added mix() color function (inspired by Less CSS) 2021-08-05 18:19:42 +02:00
Karl Tauber
7f7f9e3c7c UIDefaultsLoader: added changeHue(), changeSaturation(), changeLightness() and changeAlpha() color functions (inspired by Sass CSS color.change() function) 2021-08-05 17:08:20 +02:00
Karl Tauber
6fcee03752 release 1.5 2021-08-04 15:13:58 +02:00
Karl Tauber
5782ceeb5d README.md: added descriptions to addons 2021-08-04 14:27:57 +02:00
Karl Tauber
f752db5892 FileChooser: fixed missing (localized) texts when FlatLaf is loaded in special classloader
(e.g. plugin system in Apache NetBeans)

https://issues.apache.org/jira/browse/NETBEANS-5865
2021-08-04 11:15:18 +02:00
Karl Tauber
bce58bc97b SwingX: added search and clear icons to JXSearchField (issue #359) 2021-08-03 17:52:49 +02:00
Karl Tauber
d373687bc4 Testing: added FlatSingleComponentTest to easier test/debug single components 2021-08-03 15:16:04 +02:00
Karl Tauber
e5e510c825 Demo: fixed inconsistent behavior when first changing font size and then font family, which did loose user scale factor on Windows in Java 9+ (issue #352) 2021-08-02 19:16:38 +02:00
Karl Tauber
29064ec72f Button and TextComponent: do not apply minimum width/height if margins are set (issue #364) 2021-08-02 18:36:10 +02:00
Karl Tauber
953eee1dc8 TableHeader: made getRolloverColumn() public to allow usage in custom renderers (issue #336) 2021-08-02 18:01:08 +02:00
Karl Tauber
75f76f4875 ComboBox and Spinner: limit arrow button width if component has large preferred height (issue #361) 2021-08-02 15:27:25 +02:00
Karl Tauber
ecfbe68c33 Native window decorations: updated DLLs (issues #357 and #339)
built by GitHub Actions:
https://github.com/JFormDesigner/FlatLaf/actions/runs/1085691279
2021-07-31 21:22:09 +02:00
Karl Tauber
7f02eb9cf0 Native window decorations: when window is initially shown, fill background with window background color (instead of white), which avoids flickering in dark themes (issue #339) 2021-07-31 21:05:01 +02:00
Karl Tauber
4ab90065dc Native window decorations: when resizing a window to the right or to the bottom, then first fill the new space with the window background color (instead of black) before the layout is updated (issue #339) 2021-07-31 18:02:10 +02:00
Karl Tauber
d3e39a1359 Native window decorations: fixed occasional application crash on Windows 10 in flatlaf-windows.dll (issue #357) 2021-07-30 23:06:09 +02:00
Karl Tauber
60e5861de4 InternalFrame: limit internal frame bounds to parent bounds on resize; honor maximum size of internal frame (issue #362) 2021-07-29 16:44:50 +02:00
Karl Tauber
ca7f5045ae Popup: fixed incorrectly placed drop shadow for medium-weight popups in maximized windows (issue #358) 2021-07-29 15:39:16 +02:00
Karl Tauber
b0997fb5d2 release 1.4 2021-07-13 11:02:10 +02:00
Karl Tauber
37dab9fb22 TabbedPane: fixed rendering of tab separators in scroll layout if scaled on HiDPI screens 2021-07-12 11:48:34 +02:00
Karl Tauber
fb44c8fbe4 TextField: fixed location of placeholder text if paddings are used (e.g. in ComboBox) (for commit a9dcf09d13) 2021-07-10 21:05:26 +02:00
Karl Tauber
94375b7d36 Extras: added support for client property JTextField.padding (for commit a9dcf09d13) 2021-07-10 20:59:34 +02:00
Karl Tauber
8b585deb78 ToolBar: support focusable buttons in toolbar (issue #346)
fixed focusable state when switching to/from other Laf
2021-07-10 13:32:30 +02:00
Karl Tauber
4d8b544aed UIDefaultsKeysDump: also use FlatTestLaf, which adds missing keys to FlatLafUIKeys.txt 2021-07-10 13:28:02 +02:00
Karl Tauber
548d651d29 PasswordField: move the lower bar of the caps lock icon up a half pixel 2021-07-10 11:03:13 +02:00
Karl Tauber
0b342acec9 PasswordField: paint caps lock icon on left side in right-to-left component orientation 2021-07-09 15:14:29 +02:00
Karl Tauber
cc6d3c1b1a PasswordField: Caps lock icon no longer painted over long text (issue #172) 2021-07-09 15:03:16 +02:00
Karl Tauber
74a748d92e use LoggingFacade instead of printStackTrace() in flatlaf-extras and flatlaf-demo 2021-07-09 13:22:37 +02:00
Karl Tauber
1de81d0af5 ComboBox: fixed StackOverflowError when using single renderer instance in multiple comboboxes (regression since commit 4507ce359d) 2021-07-09 11:39:35 +02:00
Karl Tauber
ff9ef21f67 OptionPane: align wrapped lines to the right if component orientation is right-to-left (issue #350) 2021-07-08 17:53:44 +02:00
Karl Tauber
266a546478 Window decorations: window title bar width is no longer considered when calculating preferred/minimum width of window (issue #351) 2021-07-08 16:54:34 +02:00
Karl Tauber
87407ca832 Table and PopupFactory: use StackWalker in Java 9+ for better performance (issue #334) 2021-07-08 14:02:50 +02:00
Karl Tauber
90282d4436 UI defaults dumps updated for issue #335 2021-07-08 00:02:33 +02:00
Karl Tauber
abbe6d6c1f ToolBar: paint focus indicator for focused button in toolbar (issue #346) 2021-07-07 18:17:45 +02:00
Karl Tauber
a28f701e6f OptionPane: do not make child components, which are derived from JPanel, non-opaque (issue #349) 2021-07-07 10:57:54 +02:00
Karl Tauber
4cdc995a7f ComboBox: simplified code in configureEditor() 2021-07-05 23:14:05 +02:00
Karl Tauber
c708205593 TestFlatComponentSizes: shortened combobox text because unit tests on GitHub Actions use font size 15 2021-07-05 20:06:07 +02:00
Karl Tauber
a22c6c8013 ComboBox (not editable):
- increased size of internal renderer pane to the component border so that it can paint within the whole component
- increase combo box size if a custom renderer uses a border with insets that are larger than the default combo box padding (`2,6,2,6`)
2021-07-05 18:41:17 +02:00
Karl Tauber
b576f473e5 fixed component heights at 1.25x, 1.75x and 2.25x scaling factors (Java 8 only) so that Button, ComboBox, Spinner and TextField components (including subclasses) have same heights 2021-07-05 15:15:37 +02:00
Karl Tauber
0b127caa83 ComboBox: fixed minimum width if focusWidth > 0 (to be equal with button minimum width)
added some unit tests to compare component sizes
2021-07-05 11:07:32 +02:00
Karl Tauber
4507ce359d ComboBox: reworked uninstall of CellPaddingBorder, which is temporary used for cell renderers, to make it easier to understand and reliable
(tested using FlatCustomBordersTest, FlatNetBeansTest, etc)
2021-07-03 10:43:55 +02:00
Karl Tauber
3e14f28dc2 ComboBox (editable) and Spinner: increased size of internal text field to the component border so that it behaves like plain text field (issue #330) 2021-07-02 18:43:37 +02:00
Karl Tauber
a9dcf09d13 TextField: support adding extra padding
(for #172, #173 and #330)
2021-07-02 15:38:45 +02:00
Karl Tauber
c8998c2bcf PasswordField: UI delegate FlatPasswordFieldUI now extends FlatTextFieldUI (instead of BasicPasswordFieldUI) to avoid duplicate code and for easier extensibility (e.g. for #173 and #341) 2021-07-02 14:03:54 +02:00
Karl Tauber
10bf1295bc CHANGELOG.md: fixed UI key ComboBox.popupFocusedBackground to ComboBox.popupBackground 2021-07-02 10:52:30 +02:00
Karl Tauber
1e869973d4 release 1.3 2021-07-02 10:40:27 +02:00
Karl Tauber
731c8962c9 added missing since 1.3 2021-07-02 10:21:55 +02:00
Karl Tauber
294b8bb789 Extras: FlatInspector: fixed border value when class hierarchy is enabled 2021-07-02 10:14:51 +02:00
Karl Tauber
4f9b819f48 Spinner: reduced gap between up and down arrows, which was increased by previous commit (issue #329) 2021-06-30 18:57:54 +02:00
Karl Tauber
5318d5fa8e ScrollBar: fixed left/top arrow icon location (if visible) (issue #329)
(tested using FlatPaintingTest)
2021-06-30 18:47:16 +02:00
Karl Tauber
98b156bdde TextComponents: use focusedBackground also if not editable (but enabled)
(PR #338)
2021-06-30 00:01:33 +02:00
Karl Tauber
511dd02107 JIDE: build using latest version of JIDE library com.formdev:jide-oss:3.7.12 2021-06-29 22:58:42 +02:00
Karl Tauber
f1f7a2e7b6 Extras: FlatInspector: fixed missing "UI" row on Java 9+ 2021-06-27 23:19:36 +02:00
Karl Tauber
d557cf5427 FlatTestFrame: do not print stack trace if lafs.properties does not exist 2021-06-27 21:36:49 +02:00
Karl Tauber
39d2941099 removed duplicate ; 2021-06-25 10:48:00 +02:00
Karl Tauber
2a732306a1 ComboBox: renamed UI key ComboBox.popupFocusedBackground to ComboBox.popupBackground 2021-06-22 08:59:11 +02:00
Karl Tauber
8a72b30cbc Merge pull request #338 from Chrriis/focusedBackground
Issue #335: allow a different background on focus
2021-06-15 11:57:17 +02:00
Karl Tauber
ed9cb0f918 Spinner: support Spinner.focusedBackground
ComboBox:
- prefer explicit set background color over focusedBackground
- if ComboBox.buttonFocusedBackground is not specified use ComboBox.focusedBackground
- added ComboBox.popupFocusedBackground

(issue #335)
2021-06-15 11:50:30 +02:00
Karl Tauber
7e0915cb9c FlatBorder: refractored ComboBox, ScrollPane and Spinner focus owner checking to UI delegates (for later usage) 2021-06-13 11:21:55 +02:00
Karl Tauber
a51294d570 TextComponents:
- use focusedBackground only if editable (and enabled)
- prefer explicit set background color over focusedBackground
- added FlatTextFieldUI.getBackground() used by all text components
- support EditorPane.focusedBackground
- support TextPane.focusedBackground

(issue #335)
2021-06-12 20:46:59 +02:00
Karl Tauber
d962f218a1 ToolTip: fixed positioning of huge tooltips (issue #333) 2021-06-11 20:53:09 +02:00
Karl Tauber
7b248427f0 fixed white lines at bottom and right side of window (in dark themes on HiDPI screens with scaling enabled) 2021-06-11 16:16:41 +02:00
Christopher Deckers
b99fb8b11f Use focused background color for combo popups. 2021-06-09 09:56:50 +02:00
Christopher Deckers
26250e790f Issue #335: allow a different background on focus. 2021-06-08 10:12:59 +02:00
Karl Tauber
b26dbe81f4 README.md: changed deprecated FlatLightLaf.install() to FlatLightLaf.setup() 2021-06-01 16:23:54 +02:00
Karl Tauber
903212345b .gitbugtraq added (for SmartGit) 2021-06-01 16:21:58 +02:00
Karl Tauber
025f6564dc release 1.2 2021-05-18 18:23:41 +02:00
Karl Tauber
35f97368fa Native window decorations: double-click at upper-left corner of maximized frame did not close window (issue #326) 2021-05-18 18:00:53 +02:00
Karl Tauber
09e5c86488 FlatLaf.getDisabledIcon() now returns a instanceof UIResource for disabled SVG icons to allow recreation of disabled icons when switching to another Laf 2021-05-15 17:51:33 +02:00
Karl Tauber
8998371cae Extras: FlatSVGUtils.createWindowIconImages(): return multi-resolution image only on Windows because Java implementations for macOS and Linux do not support multi-resolution images for window title icons
(issue #323)
2021-05-14 17:33:40 +02:00
Karl Tauber
29e1dc6b55 FlatTitlePaneIcon: use getResolutionVariant(width, height) instead of getResolutionVariants() to allow creation of requested size on demand and to avoids creation of all resolution variants
Extras: `FlatSVGUtils.createWindowIconImages()` now returns a single multi-resolution image that creates requested image sizes on demand from SVG

(issue #323)
2021-05-14 16:43:47 +02:00
Karl Tauber
439e63b52f Native window decorations: updated DLLs (issue #283)
built by GitHub Actions:
https://github.com/JFormDesigner/FlatLaf/actions/runs/838543378
2021-05-13 13:43:45 +02:00
Karl Tauber
eea341fb33 Native window decorations: fixed broken maximizing window (under special conditions) when restoring frame state at startup (issue #283) 2021-05-13 12:10:11 +02:00
Karl Tauber
359eedf773 Native window decorations: fixed slow application startup under particular conditions (issue #319) 2021-05-13 00:54:22 +02:00
Karl Tauber
866751ffc1 Extras: FlatInspector: show class hierarchies when pressing Alt key and prettified class names (dimmed package name) 2021-05-12 19:03:13 +02:00
Karl Tauber
38a3a0768d Tree: fill cell background if DefaultTreeCellRenderer.setBackgroundNonSelectionColor(Color) was used (issue #322) 2021-05-12 15:45:36 +02:00
Karl Tauber
03b42749cd replaced deprecated (since Java 9) KeyEvent.*_MASK with KeyEvent.*_DOWN_MASK 2021-05-12 14:03:16 +02:00
Karl Tauber
60fd78e082 build.gradle.kts: removed unnecessary mapOf() and fixed formatting 2021-05-12 13:59:50 +02:00
Karl Tauber
9edaf58929 Linux: fixed/improved detection of user font settings (issue #309) 2021-05-04 22:41:00 +02:00
Karl Tauber
5000186f85 Linux: enable text anti-aliasing if no Gnome or KDE Desktop properties are available (issue #218) 2021-05-04 22:11:15 +02:00
Karl Tauber
cacf0ea987 ComboBox: support using as cell renderer (e.g. in JTable) 2021-05-04 21:39:08 +02:00
Karl Tauber
067501cbe7 Native window decorations: avoid double window title bar if enabling native window border failed (issue #315) 2021-04-23 21:12:40 +02:00
Karl Tauber
9fe0cf496b Native window decorations: updated DLLs (issue #315)
built by GitHub Actions:
https://github.com/JFormDesigner/FlatLaf/actions/runs/778322373
2021-04-23 18:23:44 +02:00
Karl Tauber
9d0823038e Native window decorations: fixed occasional double window title bar when creating many frames or dialogs (issue #315) 2021-04-23 18:14:00 +02:00
Karl Tauber
5a05efefdd build.gradle.kts:
- moved javadoc options from subprojects to root project
- removed "API" from titles in HTML files
- added subproject name and version to header and footer
- use links to Java 11 API
2021-04-22 23:00:28 +02:00
Karl Tauber
988d171bdd fixed javadoc warnings/errors when building with Java 15 2021-04-22 16:20:50 +02:00
Karl Tauber
e6f72bf343 fixed some deprecation warnings when compiling with Java 11 2021-04-22 15:53:02 +02:00
Karl Tauber
89c5a0c57b FlatSVGIcon: fixed javadoc issues 2021-04-22 14:27:14 +02:00
Karl Tauber
d97146393c renamed Flat*Laf.install() methods to Flat*Laf.setup() to avoid confusion with UIManager.installLookAndFeel(LookAndFeelInfo info); the old Flat*Laf.install() methods are still there, but marked as deprecated 2021-04-22 14:20:09 +02:00
Karl Tauber
1c52f1f76c CheckBox and RadioButton: do not fill background if used as cell renderer, except if cell is selected or has different background color (issue #311) 2021-04-22 00:14:42 +02:00
Karl Tauber
9bd3a68115 update miglayout-swing from 5.3-SNAPSHOT to 5.3 2021-04-20 21:01:55 +02:00
Karl Tauber
f58780d36b FlatSVGIcon: share color filter in derived icons 2021-04-18 18:30:56 +02:00
Karl Tauber
6eb15ab437 FlatSVGIcon: added missing javadoc and updated CHANGELOG.md 2021-04-18 17:43:12 +02:00
Karl Tauber
00dc7004f5 Merge pull request #303 from xDUDSSx/extras-svg-icon-filter
FlatSVGIcon color filters
2021-04-18 17:31:01 +02:00
Karl Tauber
8ec0e57235 FlatSVGIcon: use fluent API for color filter 2021-04-18 17:05:22 +02:00
Karl Tauber
d75dc9e70c FlatSVGIcon: support light and dark mappings in single color filter 2021-04-18 16:37:24 +02:00
Karl Tauber
ec2fccbb0e FlatSVGIcon: if icon has color filter and did change the color, then do not apply global color filter 2021-04-16 23:25:22 +02:00
Karl Tauber
34861166e8 Demo: ExtrasPanel: added "Toggle RED" button 2021-04-16 23:03:38 +02:00
Karl Tauber
584fa0a26e Demo: ExtrasPanel:
- animate "rainbow" icon only if extras tab is visible
- recreated added components in JFormDesigner
2021-04-16 22:56:44 +02:00
Karl Tauber
6c48489d89 FlatSVGIcon:
- added getters for all fields passed to constructors
- preserve disabled state in derive() methods
- ColorFilter: create hash maps only if needed/used
2021-04-16 21:53:15 +02:00
Karl Tauber
ba9c884a0c FlatSVGIcon:
- renamed FlatSVGIcon.setFilter(...) to setColorFilter()
- renamed ColorFilter.setFilter(Function) to setMapper(Function)
- replaced ColorFilter.createGrayFilterFunction(int,int,int) with universal createRGBImageFilterFunction(RGBImageFilter)
- ColorFilter: use default color palette mapping only in global filter
2021-04-16 21:33:23 +02:00
Karl Tauber
360f0bafe0 Extras: FlatInspector: always show tooltip over highlight figures 2021-04-16 15:12:55 +02:00
Karl Tauber
4327c13dca FlatTestFrame: moved 3rd party lafs to lafs.properties 2021-04-16 14:57:43 +02:00
Karl Tauber
4f2256f713 TableHeader: Moved table header column border painting from FlatTableHeaderUI to new border FlatTableHeaderBorder to improve compatibility with custom table header implementations (issue #228) 2021-04-14 19:34:44 +02:00
Karl Tauber
5167cd368f JIDE: JideTabbedPane: updated CHANGELOG.md 2021-04-13 16:32:20 +02:00
Karl Tauber
ef7289d11a Merge pull request #306 from JFormDesigner/jidetabbedpane
JideTabbedPane improvements
2021-04-13 16:29:49 +02:00
Karl Tauber
cb11d98bf7 JIDE: JideTabbedPane: hide tab selection and tab area separator for tabbedPane.setHideOneTab(true) if tabbed pane contains only one tab 2021-04-13 12:20:11 +02:00
Karl Tauber
992349da8c JIDE: JideTabbedPane: fixed close button in tab area, which was visible even if shown on tabs (regression in previous commit) 2021-04-13 12:06:28 +02:00
Karl Tauber
2e7637f274 JIDE: JideTabbedPane: fixed close button in tab area 2021-04-13 11:25:42 +02:00
Karl Tauber
1f8eaf4a64 JIDE: JideTabbedPane: fixed scroll and list buttons 2021-04-13 10:51:04 +02:00
Karl Tauber
46ac7a9dc7 IntelliJ Themes: fixed background colors of DesktopPane and DesktopIcon in all themes 2021-04-11 19:39:47 +02:00
Karl Tauber
0d86d39217 IntelliJ Themes: minor fixes to text in progress bars for some themes 2021-04-11 18:59:23 +02:00
Karl Tauber
1f591f3d1b IntelliJ Themes: added "Material Theme UI Lite / GitHub Dark" theme 2021-04-11 17:42:57 +02:00
Karl Tauber
30c6ddba37 IntelliJ Themes: updated themes to newest versions (used IJThemesUpdater) 2021-04-11 17:35:25 +02:00
Karl Tauber
406eeaec96 PopupFactory: fixed occasional NullPointerException in FlatPopupFactory.fixToolTipLocation() (issue #305) 2021-04-11 16:00:36 +02:00
Karl Tauber
2fe5652bc6 DesktopPane: automatically layout icons in dock (without invoking from DesktopManager), which eliminates the need for FlatDesktopManager 2021-04-11 15:10:59 +02:00
Karl Tauber
39bf68a6bd DesktopIcon: automatically update preview (without invoking from DesktopManager) 2021-04-11 14:58:20 +02:00
Karl Tauber
a7a4a19824 DesktopIcon: use derived color for icon background, based on background color of JDesktopPane 2021-04-11 14:48:19 +02:00
Karl Tauber
7f906ba0ea DesktopPane: fixed empty minimized icon when switching LaF (regression since commit ab1ce7fab16597c518dd00a4c4e86320d98410c1; see PR #294) 2021-04-10 15:53:45 +02:00
Karl Tauber
07bf6e4506 DesktopPane: on HiDPI screens, use high-resolution images for preview of iconified internal frames in dock 2021-04-10 14:36:46 +02:00
Karl Tauber
a331760321 DesktopPane: made private methods/fields protected to allow overriding 2021-04-10 13:36:44 +02:00
Karl Tauber
d9c240d729 DesktopPane: fixed incomplete minimized icon when switching LaF 2021-04-10 12:46:13 +02:00
Karl Tauber
d9526c19e7 DesktopPane: improved layout of iconified internal frames in dock 2021-04-10 12:39:26 +02:00
Karl Tauber
1798ccd284 Merge pull request #294 from lsimediasarl/main
Fixed JInternalFrame iconified content snapshot for already installed DesktopManager
2021-04-10 00:05:02 +02:00
Karl Tauber
ab1ce7fab1 DesktopPane: avoid using two instances of DefaultDesktopManager if a custom desktop manager is used/wrapped (see PR #294) 2021-04-09 18:17:15 +02:00
DUDSS
e9b2f17171 FlatSVGIcon: Fixed an oversight 2021-04-09 13:41:08 +02:00
DUDSS
d3bf4433b7 FlatSVGIcon: Removed unnecessary getInstance method. Changed the demo a little and added a utility method to ColorFilter to easily create a brightness/contrast/alpha filter. 2021-04-09 13:36:49 +02:00
DUDSS
ba0f43455b Reworked how the FlatSVGIcon filters work. Filters are now set using the ColorFilter class and can work globally too. Added related demo components to flatlaf-demo extras tab. 2021-04-09 13:36:49 +02:00
DUDSS
638af4bcd7 Added an option to specify an RGBImageFilter to a FlatSVGIcon 2021-04-09 13:36:48 +02:00
Karl Tauber
5eab843d97 Button and ToggleButton:
- updated CHANGELOG.md for #276
- FlatComponentsTest: use FlatButton and FlatToggleButton
- FlatButtonUI: avoid unnecessary reading client property if shadowColor is null, which is the case in most themes
2021-04-09 11:44:59 +02:00
Karl Tauber
c55f0e239e Merge pull request #276 from ingokegel/border_less_button
Added ButtonType.borderLess
2021-04-09 11:17:11 +02:00
Ingo Kegel
32d9381745 Renamed borderLess to borderless 2021-04-08 22:36:42 +02:00
Karl Tauber
77fc564e70 TabbedPane: fixed actions scrollTabsForwardAction and scrollTabsBackwardAction when used from outside (e.g. in NetBeans) 2021-04-08 01:15:29 +02:00
Karl Tauber
3b84314c45 client/system properties: javadoc fixes 2021-04-07 16:25:24 +02:00
Karl Tauber
5729c20386 release 1.1.2 2021-04-07 11:53:18 +02:00
Karl Tauber
a4d70d8095 FlatTextComponentsTest: fixed compiler warnings (for previous commit) 2021-04-07 10:34:11 +02:00
Karl Tauber
8fcce349d5 ComboBox and Spinner: fixed too wide arrow button if component is higher than preferred (issue #302) 2021-04-07 01:39:29 +02:00
Karl Tauber
5a94676a3a Merge pull request #269 from SchiopuMatei/main
Added option for downscaling
2021-04-07 00:24:18 +02:00
Karl Tauber
f32d72ee62 UIScale:
- allow scale factors less than 100% for system property `flatlaf.uiScale`
- no longer round scale factor of system property `flatlaf.uiScale` to 1/4
- renamed system property `flatlaf.uiDowncale.enabled` to `flatlaf.uiScale.allowScaleDown`
- round smaller scale factors to 1/10
- absolute minimum user scale factor is now 0.1
2021-04-07 00:21:15 +02:00
Karl Tauber
e35fc8620c JIDE: fixed null font in other Lafs if (wrongly) using LookAndFeelFactory.addUIDefaultsInitializer() or LookAndFeelFactory.addUIDefaultsCustomizer() (issue #288) 2021-04-06 18:35:48 +02:00
Karl Tauber
277c288952 IntelliJ Themes: fixed system colors 2021-04-06 11:29:55 +02:00
Karl Tauber
240b08e55c IntelliJ Themes: fixed window title bar background if unified background is enabled 2021-04-06 11:04:52 +02:00
Karl Tauber
fe7f345661 Native window decorations: support changing title bar background and foreground colors per window (via client property) also if unified window title bar is enabled 2021-04-06 10:46:28 +02:00
Karl Tauber
c8db01c958 SplitPane: fixed JSplitPane.setContinuousLayout(false) (issue #301) 2021-04-05 14:24:49 +02:00
Karl Tauber
f456185f7d Native window decorations: support changing title bar background and foreground colors per window (via client property) 2021-04-05 14:19:41 +02:00
Karl Tauber
801b555835 Window decorations: fixed random window title bar background for unified backgrounds in cases were background is not filled by custom window/rootpane components (issue #254) 2021-04-04 11:47:15 +02:00
Karl Tauber
eee177e64b Window decorations: enabling/disabling menu bar embedding via system and client properties now works the same way as for window decorations
(previously it was only possible to disable menu bar embedding)
2021-04-03 16:19:11 +02:00
Karl Tauber
63639f8e96 Native window decorations: cleaned-up/simplified JetBrains Runtime custom window decorations "enabled" checking:
- `FlatSystemProperties.USE_WINDOW_DECORATIONS` is now also used for JBR custom window decorations
- `FlatSystemProperties.USE_JETBRAINS_CUSTOM_DECORATIONS` is now only used to disable JBR custom window decorations; then FlatLaf native window decorations are used
- JBR custom window decorations are now disabled when running in JetBrains Projector, Webswing or WinPE
2021-04-03 13:32:46 +02:00
Karl Tauber
de1b0b1bb6 MenuBar: do not use TitlePane.unifiedBackground if window decorations are disabled for the window 2021-04-03 11:51:45 +02:00
Karl Tauber
bbdd7fc2b4 Demo:
- keep "Options > Window decorations" selected for JetBrains Runtime
- disable "Options > Use underline menu selection" on macOS
- added font size `11`
2021-04-03 11:49:57 +02:00
Karl Tauber
6addb5c4b4 Native window decorations:
- API to check whether current platform supports window decorations `FlatLaf.supportsNativeWindowDecorations()`
- API to toggle window decorations of all windows `FlatLaf.setUseNativeWindowDecorations(boolean)`
- `FlatClientProperties.USE_WINDOW_DECORATIONS` can now used to toggle window decorations for single window
- cleaned-up/fixed/simplified window decorations "enabled" checking:
  1. if `FlatSystemProperties.USE_WINDOW_DECORATIONS` is set, its value is used
  2. if `FlatClientProperties.USE_WINDOW_DECORATIONS` is set, its value is used
  3. use value of UI default `TitlePane.useWindowDecorations`
2021-04-03 11:13:57 +02:00
Karl Tauber
b47e0c88d6 Merge pull request #298 from Bios-Marcel/fix-demo-menu-item-states
Fix selected states for native window border related menu items
2021-04-02 16:13:36 +02:00
Marcel Schramm
d06993d940 Add comment explaining why the use of JBR results in not having custom decorations 2021-04-01 22:14:39 +02:00
Karl Tauber
d31f167b9e TabbedPane: fixed NPE when creating/modifying in another thread (issue #299) 2021-04-01 12:35:50 +02:00
Karl Tauber
f12ee6c167 added dummy class to empty opend module packages 2021-04-01 09:40:22 +02:00
Karl Tauber
983b341f33 Native window decorations: fixed loading of native library when using JPMS for application (issue #289) 2021-04-01 01:07:35 +02:00
Karl Tauber
f3e6642f05 Button and ToggleButton: simplified/unified code of FlatButtonUI.getBackground() (issue #292) 2021-03-31 23:14:45 +02:00
Karl Tauber
0a63990d21 Button and ToggleButton: do not paint background of disabled (and unselected) toolBar buttons (issue #292; regression since fixing #112) 2021-03-31 22:28:43 +02:00
Karl Tauber
6909bb4b03 Native window decorations: removed superfluous pixel-line at top of screen when window is maximized (issue #296) 2021-03-31 20:56:17 +02:00
Marcel Schramm
620aa8bcee Fix selected states for native window border related menu items
The menu items for custom window decorations and embeded menu bar aren't selected anymore if the feature isn't supported.
On top of that, there's now a tooltip indicating that these aren't supported.
2021-03-31 19:59:29 +02:00
Stephan Bodmer
6db39d1860 Implemented desktop manager wrapper for already installed desktop manager so the iconifyFrame with small
content snapshot are still available

Signed-off-by: Stephan Bodmer <sbodmer@lsi-media.ch>
2021-03-31 13:58:25 +02:00
Stephan Bodmer
1762ead89f s
Signed-off-by: Stephan Bodmer <sbodmer@lsi-media.ch>
2021-03-31 13:54:40 +02:00
Karl Tauber
d13ddeb944 use larger font when running on WinPE (issue #279) 2021-03-30 11:00:27 +02:00
Karl Tauber
1b5da0e1d1 Window decorations: support enabling/disabling unified title bar backgrounds at runtime without FlatLaf.updateUI() 2021-03-30 01:34:34 +02:00
Karl Tauber
7a2d0e7fcb fixed crash when running in Webswing (issue #290) 2021-03-30 01:06:30 +02:00
Karl Tauber
477c3b6b1e README.md: added link to FlatLaf 1.0 announcement on Reddit 2021-03-28 18:44:21 +02:00
Karl Tauber
95312c3650 release 1.1.1 2021-03-28 16:04:14 +02:00
Karl Tauber
98a3c4b0f5 JIDE: JideTabbedPane: fixed disabled tab text, which was unreadable in dark themes 2021-03-27 19:19:17 +01:00
Karl Tauber
6e990a7e31 JIDE: JideTabbedPane: fixed hover background of close button on selected tab 2021-03-27 18:46:37 +01:00
Karl Tauber
8e49904f8d JIDE: JideTabbedPane: fixed location of tab title editing box 2021-03-27 18:22:10 +01:00
Karl Tauber
69f52c8abd JIDE: JideTabbedPane: scale tab gripper 2021-03-27 17:48:58 +01:00
Karl Tauber
d7b0754327 JIDE: JideTabbedPane: tab layout fixes for compact resize mode 2021-03-27 17:03:49 +01:00
Karl Tauber
2a00de11f1 JIDE: JideTabbedPane: fixed tab icon and title locations in vertical tabs 2021-03-27 14:28:21 +01:00
Karl Tauber
923cc51f3e JIDE: JideTabbedPane: FlatJideOssContainerTest updated (based on FlatContainerTest) 2021-03-27 12:18:06 +01:00
Karl Tauber
c8f7478170 JIDE: JideTabbedPane:
- use `FlatTabbedPaneCloseIcon` for tab close buttons
- scale close buttons
- fix close buttons location
2021-03-27 11:02:33 +01:00
Karl Tauber
9006e835c6 natives.yml: exclude ~/.gradle/caches/modules-2/modules-2.lock from Gradle cache 2021-03-26 21:52:28 +01:00
Karl Tauber
f801d61929 support running on WinPE (issue #279) 2021-03-26 21:51:11 +01:00
Karl Tauber
a143e5777c Extras: FlatInspector: fixed InaccessibleObjectException when running in Java 16 2021-03-26 21:44:41 +01:00
Karl Tauber
bffac60bf8 JIDE: JideTabbedPane:
- support selected tab background
- support tab separators
2021-03-25 18:49:16 +01:00
Karl Tauber
bf500e46e7 Window decorations: fixed wrong/missing window icon when application replaces InternalFrame.icon (issue #284) 2021-03-25 16:14:41 +01:00
Karl Tauber
4a2f79f390 Native window decorations: updated DLLs (issues #282 and #283)
built by GitHub Actions:
https://github.com/JFormDesigner/FlatLaf/actions/runs/686023039
2021-03-25 11:10:13 +01:00
Karl Tauber
c24ce7c5bc Native window decorations: fixed broken maximizing window when restoring frame state at startup (issue #283) 2021-03-25 10:32:24 +01:00
Karl Tauber
8a6a0c7971 Native window decorations: fixed missing animations when minimizing, maximizing or restoring a window using window title bar buttons (issue #282) 2021-03-24 23:59:59 +01:00
Karl Tauber
de6e5bd800 fixed missing focus indicators in heavy-weight popups (issue #273) 2021-03-24 11:43:06 +01:00
Karl Tauber
e18a04f9e6 Merge pull request #278 from ingokegel/native_provider_setter
Add a setter for the native provider
2021-03-24 11:34:22 +01:00
Karl Tauber
14fc652f4b Window decorations: fixed right aligned progress bar in embedded menu bar was overlapping window title (issue #272) 2021-03-23 19:23:18 +01:00
Ingo Kegel
9a876e747a Added setter for native provider
This makes it possible to support situations where the extraction of a DLL at runtime is not possible
2021-03-23 16:47:08 +01:00
Karl Tauber
f8ee8b27fb InternalFrame: fixed translucent internal frame menu bar background if TitlePane.unifiedBackground is true (issue #274) 2021-03-23 15:08:01 +01:00
Karl Tauber
ce1a1487aa support menu bars in JDialog 2021-03-23 14:58:53 +01:00
Karl Tauber
fe1e364a1d Native window decorations: support disabling native window decorations per window via client property (issue #277) 2021-03-23 13:18:07 +01:00
Karl Tauber
eabb052107 Native window decorations: fixed double window title bar when first disposing a window and then showing it again (issue #277) 2021-03-23 10:07:43 +01:00
Karl Tauber
734f3621f1 Window decorations: Fixed NPE in FlatTitlePane.findHorizontalGlue() (issue #275) 2021-03-22 18:47:53 +01:00
Ingo Kegel
ae8323e2f8 Added ButtonType.borderLess for buttons that look like toolbar buttons but have a focus indicator.
This behavior can be achieved with JideButton, but it would be preferable to use FlatButton instead.
2021-03-22 16:45:37 +01:00
Karl Tauber
9612a81f2e release 1.1 2021-03-21 14:03:36 +01:00
Karl Tauber
2945a36cef added since 1.1 2021-03-21 13:53:57 +01:00
Karl Tauber
b84dc5bfcc JIDE and SwingX: README.md: added links to dependencies on maven central 2021-03-21 13:29:23 +01:00
Karl Tauber
60486fd880 JIDE: build using latest version of JIDE library com.formdev:jide-oss:3.7.11.1 2021-03-20 19:19:33 +01:00
Karl Tauber
891091cebc SwingX: fixed compiling module-info (broken since previous commit) 2021-03-19 17:06:23 +01:00
Karl Tauber
1493ddcf41 SwingX: the library on Maven Central no longer depends on org.swinglabs.swingx:swingx-all:1.6.5-1 to avoid problems when another SwingX library should be used 2021-03-19 16:23:29 +01:00
Karl Tauber
4299c50537 JIDE: the library on Maven Central no longer depends on com.jidesoft:jide-oss:3.6.18 to avoid problems when another JIDE library should be used (issue #270) 2021-03-19 16:22:24 +01:00
Karl Tauber
14577c396d JIDE: fixed hover/selection background colors of JideSplitButton and JideSplitToggleButton 2021-03-19 15:59:59 +01:00
Karl Tauber
e9b566241d JIDE: support JideSplitButton and JideSplitToggleButton 2021-03-19 15:39:32 +01:00
Karl Tauber
d39b08c035 FlatArrowButton: refactored arrow painting to FlatUIUtils.paintArrow() so that it can be easily used other components (e.g. JideSplitButton) 2021-03-19 01:21:19 +01:00
Karl Tauber
69ac683c8c Support running in JetBrains Projector (https://jetbrains.com/projector/) 2021-03-17 00:43:08 +01:00
Karl Tauber
eafd0b3d06 use lambdas for listeners (where possible) instead of extending Basic*UI.*Handler classes
some of those `Basic*UI.*Handler` classes may be deprecated in a future Java version (see https://github.com/openjdk/jdk/pull/1958)

this should also avoid loading of those `Basic*UI.*Handler` classes at runtime
2021-03-17 00:34:35 +01:00
Karl Tauber
310a4989dc JIDE: made used fonts "active" and restored fonts modified in LookAndFeelFactory.installJideExtension() 2021-03-16 23:23:40 +01:00
Karl Tauber
3d0df51839 JIDE: support JideLabel to fix wrong text colors in dark themes 2021-03-16 22:52:13 +01:00
Karl Tauber
ede02aaaa5 TabbedPane: use float arc for tab area button background 2021-03-16 22:20:46 +01:00
Karl Tauber
beff149004 JIDE: support JideButton and JideToggleButton 2021-03-16 22:15:32 +01:00
Karl Tauber
07db6e8fb0 Extras: FlatInspector: fixed NPE if component class is in default package 2021-03-16 13:46:25 +01:00
Karl Tauber
46852c0780 JIDE: invoke LookAndFeelFactory.installJideExtension() early in FlatJidePopupMenuUI to be sure that Jide extensions are installed 2021-03-16 13:26:36 +01:00
Karl Tauber
a5e41c573f JIDE: UIDefaultsDump: dump UI defaults added by LookAndFeelFactory.installJideExtension() 2021-03-16 11:38:49 +01:00
SchiopuMatei
ed91aa4648 Added option for downscaling 2021-03-15 20:41:40 +02:00
Karl Tauber
9a94395d30 JIDE: split FlatJideOssTest (moved JideTabbedPane to FlatJideOssContainerTest`) 2021-03-15 17:40:31 +01:00
Karl Tauber
04aa61c2bb Merge pull request #268 from title-pane-improvements
Title pane improvements (Windows 10 only)
2021-03-14 17:39:50 +01:00
Karl Tauber
035a13df54 Window decorations: support unified backgrounds for window title bar, menu bar and main content (issue #254) 2021-03-14 15:13:26 +01:00
Karl Tauber
e8a6f0ca3d Native window decorations: added flatlaf-windows-x86.dll and updated flatlaf-windows-x86_64.dll
built by GitHub Actions:
https://github.com/JFormDesigner/FlatLaf/actions/runs/650060630
2021-03-14 00:20:22 +01:00
Karl Tauber
1fc519b9de natives.yml: run "Native Libraries" also when natives.yml changed 2021-03-14 00:02:01 +01:00
Karl Tauber
2bcf38e2e3 natives.yml: run "Native Libraries" on any change in native project (e.g. when changing Gradle build script) 2021-03-13 23:59:30 +01:00
Karl Tauber
8eb44a68cb Native window decorations: support 32-bit JREs 2021-03-13 23:41:38 +01:00
Karl Tauber
30c7b442a8 Window decorations:
- support customizing of window title alignment: left aligned or centered (default is left without embedded menubar and centered with embedded menubar)
- improved centering of window title with embedded menubar (issue #252)
2021-03-13 17:08:47 +01:00
Karl Tauber
cee2211108 Demo: added "users" icon to right side of menu bar to demonstrate this feature 2021-03-13 11:14:51 +01:00
Karl Tauber
b7bcbccd45 Window decorations: support right aligned extra components in JFrame title pane with embedded menu bar 2021-03-13 11:10:50 +01:00
Karl Tauber
d2ccb97eba Native window decorations: use LoggingFacade 2021-03-12 23:18:13 +01:00
Karl Tauber
39d56f2603 Merge pull request #267 from native-window-decorations
Native window decorations for Windows 10 (using JNI)
2021-03-12 23:15:19 +01:00
Karl Tauber
83e904dd2d Merge pull request #262 from native-window-decorations-jna
Native window decorations for Windows 10 (using JNA)
2021-03-12 23:08:35 +01:00
Karl Tauber
110c787eba Merge pull request #265 from ingokegel:optional_logging
Make the module dependency on java.logging optional
2021-03-12 22:57:04 +01:00
Karl Tauber
7c7ff289de removed module java.logging from module-info.javas 2021-03-12 22:52:59 +01:00
Karl Tauber
617a35c51b LoggingFacade:
- make LoggingFacadeImpl classes package private
- added missing @Override
- minor formatting changes
2021-03-12 21:16:57 +01:00
Karl Tauber
73487ccf65 Native window decorations:
- enabled by default (via UI property `TitlePane.useWindowDecorations`)
- dropped system property `flatlaf.useNativeWindowDecorations` and replaced with `flatlaf.useWindowDecorations`
- old functionality of system property `flatlaf.useWindowDecorations` removed
2021-03-11 10:54:23 +01:00
Ingo Kegel
712bff9c99 Use System.Logger for logging with Java 9+ 2021-03-10 17:56:27 +01:00
Ingo Kegel
eedfcf86aa LoggingFacade: moved to com.formdev.flatlaf.util, added license header, fixed NPEs in logging calls and removed overloads of logSevere 2021-03-10 17:06:12 +01:00
Karl Tauber
f730848928 Native window decorations: added flatlaf-windows-x86_64.dll
built by GitHub Actions:
https://github.com/JFormDesigner/FlatLaf/actions/runs/636694710
2021-03-10 16:16:50 +01:00
Karl Tauber
61d0574c5c Native window decorations: added READMEs 2021-03-09 19:08:53 +01:00
Karl Tauber
2f01e01ec1 Native window decorations: delete temporary DLLs on next startup (same approach as used in JNA) 2021-03-07 00:10:15 +01:00
Karl Tauber
cbcf66df7f Native window decorations: fixed enabled items is system menu 2021-03-06 16:23:10 +01:00
Karl Tauber
cfaeea039b Native window decorations: fixed enabled items is system menu 2021-03-06 16:21:22 +01:00
Karl Tauber
a891d1eb54 Native window decorations: never build :flatlaf-natives-windows:jar because it is not used/needed 2021-03-06 15:26:18 +01:00
Karl Tauber
4372052ef0 Native window decorations: do not try to build native library (on Windows) if no C++ compiler is available 2021-03-06 15:18:23 +01:00
Karl Tauber
8734b062dc Native window decorations: avoid using C-runtime, which reduces the DLL size from 100kb to 8kb 2021-03-06 12:01:49 +01:00
Ingo Kegel
343451de65 Make the module dependency on java.logging optional
Currently, FlatLaf has the following module dependencies:

$ jdeps --list-deps --multi-release 9 flatlaf-1.0.jar
   java.base
   java.desktop
   java.logging

This commit makes the java.logging dependency optional and hides logging behind a facade that falls back to printing to stderr if the java.logging module is not available.

To test, create a reduced JRE with a command like

jdk-15/bin/jlink.exe --module-path jdk-15/jmods --add-modules java.desktop --add-modules java.instrument --output jre-15-desktop-only

(adding java.instrument, so the FlatLafDemo main class can be started from IntelliJ IDEA)
2021-03-05 16:44:08 +01:00
Karl Tauber
144d65c776 Native window decorations: initial implementation in C++ using JNI 2021-03-05 10:31:31 +01:00
Karl Tauber
a6815574f7 Native window decorations: renamed project flatlaf-native-jna to flatlaf-natives/flatlaf-natives-jna
removed module-info.java because this JAR is not released/published
2021-03-04 11:04:47 +01:00
Karl Tauber
e5a116a0d4 Extras: FlatInspector: removed println (fixes #263) 2021-02-25 16:54:05 +01:00
Karl Tauber
0beef6b108 README.md: new applications using FlatLaf:
- install4j
2021-02-25 00:00:30 +01:00
Karl Tauber
7341008449 Native window decorations: fixed missing top border line 2021-02-24 23:17:41 +01:00
Karl Tauber
49bd53194a Native window decorations: show window system menu when left-clicking on application icon, close window on left-double-click on app icon 2021-02-23 23:31:36 +01:00
Karl Tauber
baf4437efc Native window decorations: show window system menu when right-clicking on caption 2021-02-23 01:10:59 +01:00
Karl Tauber
b244f80f81 Native window decorations: support autohide taskbar 2021-02-22 22:57:43 +01:00
Karl Tauber
e41c91a42b Native window decorations: fixed exception when switching Laf after closing a dialog 2021-02-22 09:56:40 +01:00
Karl Tauber
b9a2e3ceac Native window decorations: initial implementation (using JNA; will be replaced with JNI later) 2021-02-21 17:51:19 +01:00
Karl Tauber
fa7dd3bdc4 GitHub Actions: upload all built libs 2021-02-21 17:18:59 +01:00
Karl Tauber
9a8c68b846 GitHub Actions: renamed master to main 2021-02-19 16:38:25 +01:00
Karl Tauber
698e33ddf4 IntelliJ Themes: fixed text color of CheckBoxMenuItem and RadioButtonMenuItem in all "Arc" themes (issue #259) 2021-02-19 11:33:15 +01:00
Karl Tauber
909258ba14 README.md: added "Getting started" and direct links to documentation 2021-02-14 12:32:56 +01:00
Karl Tauber
2ad6bd1d23 release 1.0 2021-02-13 13:42:04 +01:00
Karl Tauber
510ffd41d8 PopupFactory: fixed NullPointerException when PopupFactory.getPopup() is invoked with parameter owner set to null 2021-02-13 13:31:30 +01:00
Karl Tauber
4f00591c4e Table: fixed wrong grid line thickness in dragged column on HiDPI screens on Java 9+ (issue #236) 2021-02-12 11:32:12 +01:00
Karl Tauber
5b65ed87cd FileChooser: fixed display of date in details view if current user is selected in "Look in" combobox (Windows 10 only; issue #249) 2021-02-12 11:10:25 +01:00
Karl Tauber
b0121c422d GitHub Actions: added Gradle wrapper validation 2021-02-11 23:52:11 +01:00
Karl Tauber
a9e9fad222 Extras: FlatInspector: tooltip is no longer limited to window bounds 2021-02-11 18:23:01 +01:00
Karl Tauber
b5fc07acc7 TabbedPane: custom TabbedPane.selectedForeground color did not work when TabbedPane.foreground has also custom color (issue #257) 2021-02-11 12:04:36 +01:00
Karl Tauber
140ebfdb92 release 1.0-rc3 2021-02-06 23:31:53 +01:00
Karl Tauber
37d0179de1 GitHub Actions: upload demo (was removed in previous commit) 2021-02-06 23:27:39 +01:00
Karl Tauber
823d4b0fe2 dropped usage of bintray, jcenter and jfrog artifactory
deploy to Sonatype OSSRH

snapshots are now here:
https://oss.sonatype.org/content/repositories/snapshots/com/formdev/
2021-02-06 19:02:32 +01:00
Karl Tauber
dd1eacf4f0 update to Gradle 6.8.2
./gradlew wrapper --gradle-version=6.8.2
2021-02-06 11:35:35 +01:00
Karl Tauber
86c33dd686 fixed javadoc syntax error 2021-02-06 11:26:57 +01:00
Karl Tauber
c6757cc61b UI defaults inspector: filter by colors with alpha and derived colors 2021-02-06 01:32:32 +01:00
Karl Tauber
a38cf284dd UI defaults inspector: show color functions in value tooltips 2021-02-06 01:31:34 +01:00
Karl Tauber
575b8e3f7f UI defaults inspector: for derived colors, no longer change Item.value from Color to Color[] because this could cause problems if there is a UI value of type Color[] 2021-02-06 01:01:48 +01:00
Karl Tauber
bc443f47f1 Theme Editor: fixed NPE (caused by no longer implemented base files support) 2021-02-05 23:33:26 +01:00
Karl Tauber
b631bcc0db UIDefaultsLoader: check for endless recursion in parsing color functions (e.g. abc = darken($abc,10%)) 2021-02-05 23:30:48 +01:00
Karl Tauber
5ccd92ece6 CheckBox: fixed background of check boxes in JIDE CheckBoxTree (broken since commit dd8ab242fb) 2021-02-04 19:41:14 +01:00
Karl Tauber
2f3c8868a7 IntelliJ Themes: fixed table header background when dragging column in "Dark Flat" and "Light Flat" themes 2021-02-04 19:18:06 +01:00
Karl Tauber
6f7b5e8005 README.md: removed JCenter and replaced download links to bintray with Maven Central 2021-02-04 16:48:53 +01:00
Karl Tauber
10d1e4b798 UIDefaultsDump: dump color value in same format as used in FlatLaf properties files; also dump alpha as percentage 2021-02-04 15:24:50 +01:00
Karl Tauber
9d5934df14 Extras: FlatInspector: use HTML in tooltip 2021-02-04 15:19:33 +01:00
Karl Tauber
be507de6c1 Label and ToolTip: made inserting BASE_SIZE rule into HTML text more reliable 2021-02-04 15:10:27 +01:00
Karl Tauber
e5d3c08821 Fixed color of <address> tag in HTML text 2021-02-04 12:58:14 +01:00
Karl Tauber
027b4ab7da Label and ToolTip: fixed font sizes for <code>, <kbd>, <big>, <small> and <samp> tags in HTML text
ToolTip: update font size if `tiptext` property changes
2021-02-04 12:56:18 +01:00
Karl Tauber
fefea0d7ec IntelliJ Themes: updated themes to newest versions (used IJThemesUpdater) 2021-02-02 18:00:17 +01:00
Karl Tauber
33f30bfd19 README.md: new applications using FlatLaf:
- DbVisualizer
- MagicPlot
- Thermo-Calc
- Burp Suite
- BurpCustomizer
- IGMAS+
2021-02-01 21:58:18 +01:00
Karl Tauber
e9d4b9961a README.md: made "commercial" bold 2021-02-01 15:14:07 +01:00
Karl Tauber
b94248fe79 README.md: removed "new" badge from projects using FlatLaf 2021-02-01 14:58:44 +01:00
Karl Tauber
225975e0dd FlatTestFrame: added 5x and 6x scale factors 2021-02-01 13:57:36 +01:00
Karl Tauber
eac7492143 FlatAnimatedIconTest: made animation of switch smooth on high scale factors 2021-02-01 12:55:14 +01:00
Karl Tauber
b3c40bf448 release 1.0-rc2 2021-02-01 01:39:52 +01:00
Karl Tauber
02f7cd77f4 FlatBorder: fixed wrong round edge of focused components in themes without outer focus border (Flat Light/Dark) 2021-02-01 01:30:52 +01:00
Karl Tauber
7f8f3aa99b Button: undone most style changes done in previous commit related to focused and default buttons:
- default button: white background and wide border
- focused button: light blue background and thin border

(the light blue default button did not look beautiful IMHO)
2021-02-01 01:08:20 +01:00
Karl Tauber
0bcdc14909 - Button:
- In "Flat Light" theme, changed styles of focused and default buttons to
    avoid confusion with all other themes. Focused buttons now have a white
    background (was light blue) and a slightly wider border. The default button
    now has a light blue background (was white) and a thin border. In all other
    themes the default button also has colored background.
  - In "Flat Dark" theme, use slightly wider border for focused buttons.
- CheckBox and RadioButton: In "Flat Dark" theme, use blueish background for
  focused components.
2021-01-31 20:02:24 +01:00
Karl Tauber
526c25a02b FlatComponentStateTest: fixed insets 2021-01-31 18:51:28 +01:00
Karl Tauber
f48da9dab1 FlatComponentStateTest: added text field and combobox (for comparison) 2021-01-31 16:17:47 +01:00
Karl Tauber
2e8dfda12e FlatComponentStateTest: added help buttons 2021-01-31 00:55:29 +01:00
Karl Tauber
63da576d85 FlatComponentStateTest: added selected checkboxes and radiobuttons 2021-01-30 20:53:07 +01:00
Karl Tauber
0ab4206540 FlatComponentStateTest added 2021-01-30 18:43:11 +01:00
Karl Tauber
212ae90401 client property "JComponent.focusOwner" added to allow customizing detection of focused state (issue #185) 2021-01-30 17:54:47 +01:00
Karl Tauber
d4e5d0be45 javadoc fixes 2021-01-30 17:46:53 +01:00
Karl Tauber
3520a0f1fb TextComponents: border of focused non-editable text components had wrong color 2021-01-30 01:06:03 +01:00
Karl Tauber
036090a947 Button: fixed behavior of Enter key on focused button on Windows and Linux, which now clicks the focused button (instead of the default button) 2021-01-30 00:37:36 +01:00
Karl Tauber
dc570c683a UI defaults: added Java 8 and 9+ InputMap dumps of NimbusLookAndFeel, which are different on Linux (and macOS) than on Windows because they use GTK key bindings (see GTKKeybindings.installKeybindings(), invoked from NimbusLookAndFeel.getDefaults()) 2021-01-29 23:00:06 +01:00
Karl Tauber
9f85d34c91 JIDE: updated UI defaults dumps for commit 7d0f7e1c8e (support JidePopupMenu) 2021-01-29 22:06:01 +01:00
Karl Tauber
16bf1fb6c3 README.md: screenshots updated 2021-01-28 23:26:30 +01:00
Karl Tauber
47c4d508e0 Demo: updated screenshot mode 2021-01-28 23:26:16 +01:00
Karl Tauber
e5d9060623 UI defaults: added links to docs and note to properties files 2021-01-23 18:49:35 +01:00
Karl Tauber
fdf28fc385 javadoc and comment updates/fixes 2021-01-23 18:05:46 +01:00
Karl Tauber
9015a4d56b Window decorations: fixed top window border in dark themes when running in JetBrains Runtime (issue #244)
fixed/improved calculation of active border color
2021-01-23 16:59:53 +01:00
Karl Tauber
38301454a6 CHANGELOG.md: added recently merged PRs #245 2021-01-22 11:10:04 +01:00
Karl Tauber
9b3a22c4ca FlatComponents2Test: simplified layout and reduced frame size 2021-01-21 23:58:22 +01:00
Karl Tauber
548dbc3649 Merge pull request #245 from ingokegel/tree_wide_selection
Added a per-tree wide selection setting
2021-01-21 23:19:33 +01:00
Karl Tauber
3474129812 Tree:
- paint non-wide selection in FlatTreeUI.paintRow() instead of using reflection to change private field in DefaultTreeCellRenderer
- use DefaultTreeCellRenderer.getBackgroundSelectionColor() as selection color (if possible)
- added boolean client property JTree.paintSelection to disable selection painting in FlatTreeUI.paintRow()
- FlatComponents2Test:
  - added checkboxes for wideSelection and paintSelection client properties
  - added possibility to test various kinds of tree cell renderers
  - added JXTree, JIDE CheckBoxTree

(PR #245)
2021-01-21 17:38:20 +01:00
Karl Tauber
63193feebe JIDE: JidePopupMenu:
- added test to FlatJideOssTest
- updated README.md and CHANGELOG.md

(PR #246)
2021-01-21 00:14:42 +01:00
Karl Tauber
51f22bfe75 Merge pull request #246 from ingokegel/jide_popup_menu_ui
Added UI for JidePopupMenu
2021-01-21 00:05:32 +01:00
Ingo Kegel
7d0f7e1c8e Added UI for JidePopupMenu 2021-01-20 16:18:48 +01:00
Karl Tauber
dd8ab242fb CheckBox and RadioButton: fill component background as soon as background color is different to default background color, even if component is not opaque (which is the default). This paints selection if using the component as cell renderer a Table, Tree or List (better fix for #77) 2021-01-19 19:13:20 +01:00
Ingo Kegel
60f3428da7 Added a per-tree wide selection setting 2021-01-19 17:46:41 +01:00
431 changed files with 40052 additions and 10303 deletions

4
.gitattributes vendored
View File

@@ -15,8 +15,12 @@
# BINARY FILES:
# Disable line ending normalize on checkin.
*.dll binary
*.dylib binary
*.gif binary
*.jar binary
*.lib binary
*.png binary
*.sketch binary
*.so binary
*.zip binary

8
.gitbugtraq Normal file
View File

@@ -0,0 +1,8 @@
# links issue numbers in git commit messages to issue tracker
# https://github.com/mstrap/bugtraq
# for SmartGit - https://www.syntevo.com/smartgit/
[bugtraq]
url = "https://github.com/JFormDesigner/FlatLaf/issues/%BUGID%"
loglinkregex = "#[0-9]{1,5}"
logregex = "[0-9]{1,5}"

View File

@@ -33,6 +33,8 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: gradle/wrapper-validation-action@v1
- name: Setup Java ${{ matrix.java }}
uses: actions/setup-java@v1
with:
@@ -60,12 +62,7 @@ jobs:
with:
name: FlatLaf-build-artifacts
path: |
flatlaf-core/build/libs
flatlaf-demo/build/libs
flatlaf-extras/build/libs
flatlaf-intellij-themes/build/libs
flatlaf-jide-oss/build/libs
flatlaf-swingx/build/libs
flatlaf-*/build/libs
!**/*-javadoc.jar
!**/*-sources.jar
@@ -75,7 +72,7 @@ jobs:
needs: build
if: |
github.event_name == 'push' &&
github.ref == 'refs/heads/master' &&
github.ref == 'refs/heads/main' &&
github.repository == 'JFormDesigner/FlatLaf'
steps:
@@ -99,11 +96,22 @@ jobs:
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle.kts') }}
restore-keys: ${{ runner.os }}-gradle
- name: Publish snapshot to oss.jfrog.org
run: ./gradlew artifactoryPublish
- name: Publish snapshot to oss.sonatype.org
run: ./gradlew publish :flatlaf-theme-editor:build -Dorg.gradle.internal.publish.checksums.insecure=true
env:
BINTRAY_USER: ${{ secrets.BINTRAY_USER }}
BINTRAY_KEY: ${{ secrets.BINTRAY_KEY }}
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
- name: Upload theme editor
uses: sebastianpopp/ftp-action@releases/v2
with:
host: ${{ secrets.FTP_SERVER }}
user: ${{ secrets.FTP_USERNAME }}
password: ${{ secrets.FTP_PASSWORD }}
forceSsl: true
localDir: "flatlaf-theme-editor/build/libs"
remoteDir: "snapshots"
options: "--only-newer --no-recursion --verbose=1"
release:
@@ -135,8 +143,32 @@ jobs:
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle.kts') }}
restore-keys: ${{ runner.os }}-gradle
- name: Release a new stable version to bintray
run: ./gradlew bintrayUpload -Drelease=true
- name: Release a new stable version to Maven Central
run: ./gradlew publish :flatlaf-demo:build :flatlaf-theme-editor:build -Drelease=true
env:
BINTRAY_USER: ${{ secrets.BINTRAY_USER }}
BINTRAY_KEY: ${{ secrets.BINTRAY_KEY }}
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
- name: Upload demo
uses: sebastianpopp/ftp-action@releases/v2
with:
host: ${{ secrets.FTP_SERVER }}
user: ${{ secrets.FTP_USERNAME }}
password: ${{ secrets.FTP_PASSWORD }}
forceSsl: true
localDir: "flatlaf-demo/build/libs"
remoteDir: "."
options: "--only-newer --no-recursion --verbose=1"
- name: Upload theme editor
uses: sebastianpopp/ftp-action@releases/v2
with:
host: ${{ secrets.FTP_SERVER }}
user: ${{ secrets.FTP_USERNAME }}
password: ${{ secrets.FTP_PASSWORD }}
forceSsl: true
localDir: "flatlaf-theme-editor/build/libs"
remoteDir: "."
options: "--only-newer --no-recursion --verbose=1"

58
.github/workflows/natives.yml vendored Normal file
View File

@@ -0,0 +1,58 @@
# https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle
name: Native Libraries
on:
push:
branches:
- '*'
tags:
- '[0-9]*'
paths:
- 'flatlaf-natives/flatlaf-natives-windows/**'
- '.github/workflows/natives.yml'
pull_request:
branches:
- '*'
paths:
- 'flatlaf-natives/flatlaf-natives-windows/**'
- '.github/workflows/natives.yml'
jobs:
Windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- uses: gradle/wrapper-validation-action@v1
- name: Setup Java 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Cache Gradle wrapper
uses: actions/cache@v1
with:
path: ~/.gradle/wrapper
key: ${{ runner.os }}-gradle-wrapper-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }}
- name: Cache Gradle cache
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
!~/.gradle/caches/modules-2/modules-2.lock
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle.kts') }}
restore-keys: ${{ runner.os }}-gradle
- name: Build with Gradle
run: ./gradlew :flatlaf-natives-windows:build
- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
name: FlatLaf-natives-windows-build-artifacts
path: |
flatlaf-natives/flatlaf-natives-windows/build

2
.gitignore vendored
View File

@@ -9,3 +9,5 @@ out/
*.iml
*.ipr
*.iws
.vs/
.vscode/

View File

@@ -1,6 +1,382 @@
FlatLaf Change Log
==================
## 1.6.1
#### Fixed bugs
- Native window decorations: Catch `UnsatisfiedLinkError` when trying to load
`jawt.dll` to avoid an application crash (Java 8 on Windows 10 only).
## 1.6
#### New features and improvements
- InternalFrame: Double-click on icon in internal frame title bar now closes the
internal frame. (issue #374)
- IntelliJ Themes: Removed deprecated `install()` methods.
#### Fixed bugs
- Menus: Fixed missing modifiers flags in `ActionEvent` (e.g. `Ctrl` key
pressed) when running in Java 9+ on Linux, macOS. Occurs also on Windows in
large popup menus that do not fit into the window. (issue #371; regression
since FlatLaf 1.3)
- OptionPane: Fixed `OptionPane.sameSizeButtons`, which did not work as expected
when setting to `false`.
- OptionPane: Fixed rendering of longer HTML text if it is passed as
`StringBuilder`, `StringBuffer`, or any other object that returns HTML text in
method `toString()`. (similar to issue #12)
- ComboBox: Fixed popup border painting on HiDPI screens (e.g. at 150% scaling).
- ComboBox: Fixed popup location if shown above of combo box (Java 8 only).
- ComboBox (editable): Fixed wrong border of internal text field under special
circumstances.
- Spinner: Fixed painting of border corners on left side. (issue #382;
regression since FlatLaf 1.4)
- TableHeader: Do not show resize cursor for last column if resizing last column
is not possible because auto resize mode of table is not off. (issue #332)
- TableHeader: Fixed missing trailing vertical separator line if used in upper
left corner of scroll pane. (issue #332)
- TextField, FormattedTextField, PasswordField and ComboBox: Fixed alignment of
placeholder text in right-to-left component orientation.
- Slider: Fixed calculation of baseline, which was wrong under some
circumstances.
## 1.5
#### New features and improvements
- SwingX: Added search and clear icons to `JXSearchField`. (issue #359)
#### Fixed bugs
- Button and TextComponent: Do not apply minimum width/height if margins are
set. (issue #364)
- ComboBox and Spinner: Limit arrow button width if component has large
preferred height. (issue #361)
- FileChooser: Fixed missing (localized) texts when FlatLaf is loaded in special
classloader (e.g. plugin system in Apache NetBeans).
- InternalFrame: Limit internal frame bounds to parent bounds on resize. Also
honor maximum size of internal frame. (issue #362)
- Popup: Fixed incorrectly placed drop shadow for medium-weight popups in
maximized windows. (issue #358)
- Native window decorations (Windows 10 only):
- Fixed occasional application crash in `flatlaf-windows.dll`. (issue #357)
- When window is initially shown, fill background with window background color
(instead of white), which avoids flickering in dark themes. (issue 339)
- When resizing a window at the right/bottom edge, then first fill the new
space with the window background color (instead of black) before the layout
is updated.
- When resizing a window at the left/top edge, then first fill the new space
with the window background color (instead of garbage) before the layout is
updated.
## 1.4
#### New features and improvements
- TextField, FormattedTextField and PasswordField: Support adding extra padding.
(set client property `JTextField.padding` to `Insets`).
- PasswordField: UI delegate `FlatPasswordFieldUI` now extends `FlatTextFieldUI`
(instead of `BasicPasswordFieldUI`) to avoid duplicate code and for easier
extensibility.
- Table and PopupFactory: Use `StackWalker` in Java 9+ for better performance.
(issue #334)
- ToolBar: Paint focus indicator for focused button in toolbar. (issue #346)
- ToolBar: Support focusable buttons in toolbar (set UI value
`ToolBar.focusableButtons` to `true`). (issue #346)
#### Fixed bugs
- ComboBox (editable) and Spinner: Increased size of internal text field to the
component border so that it behaves like plain text field (mouse click to left
of text now positions caret to first character instead of opening ComboBox
popup; mouse cursor is now of type "text" within the whole component, except
for arrow buttons). (issue #330)
- ComboBox (not editable): Increased size of internal renderer pane to the
component border so that it can paint within the whole component. Also
increase combo box size if a custom renderer uses a border with insets that
are larger than the default combo box padding (`2,6,2,6`).
- Fixed component heights at `1.25x`, `1.75x` and `2.25x` scaling factors (Java
8 only) so that Button, ComboBox, Spinner and TextField components (including
subclasses) have same heights. This increases heights of Button and TextField
components by:
- `2px` at `1.75x` in **Light** and **Dark** themes
- `2px` at `1.25x` and `2.25x` in **IntelliJ** and **Darcula** themes
- OptionPane: Do not make child components, which are derived from `JPanel`,
non-opaque. (issue #349)
- OptionPane: Align wrapped lines to the right if component orientation is
right-to-left. (issue #350)
- PasswordField: Caps lock icon no longer painted over long text. (issue #172)
- PasswordField: Paint caps lock icon on left side in right-to-left component
orientation.
- Window decorations: Window title bar width is no longer considered when
calculating preferred/minimum width of window. (issue #351)
## 1.3
#### New features and improvements
- TextComponents, ComboBox and Spinner: Support different background color when
component is focused (use UI values `TextField.focusedBackground`,
`PasswordField.focusedBackground`, `FormattedTextField.focusedBackground`,
`TextArea.focusedBackground`, `TextPane.focusedBackground`,
`EditorPane.focusedBackground`, `ComboBox.focusedBackground`,
`ComboBox.buttonFocusedBackground`, `ComboBox.popupBackground` and
`Spinner.focusedBackground`). (issue #335)
#### Fixed bugs
- Fixed white lines at bottom and right side of window (in dark themes on HiDPI
screens with scaling enabled).
- ScrollBar: Fixed left/top arrow icon location (if visible). (issue #329)
- Spinner: Fixed up/down arrow icon location.
- ToolTip: Fixed positioning of huge tooltips. (issue #333)
## 1.2
#### New features and improvements
- Renamed `Flat*Laf.install()` methods to `Flat*Laf.setup()` to avoid confusion
with `UIManager.installLookAndFeel(LookAndFeelInfo info)`. The old
`Flat*Laf.install()` methods are still there, but marked as deprecated. They
will be removed in a future version.
- Button and ToggleButton: Support borderless button style (set client property
`JButton.buttonType` to `borderless`). (PR #276)
- ComboBox: Support using as cell renderer (e.g. in `JTable`).
- DesktopPane: Improved layout of iconified internal frames in dock:
- Always placed at bottom-left in desktop pane.
- Newly iconified frames are added to the right side of the dock.
- If frame is deiconified, dock is compacted (icons move to the left).
- If dock is wider than desktop width, additional rows are used.
- If desktop pane is resized, layout of dock is updated.
- TableHeader: Moved table header column border painting from
`FlatTableHeaderUI` to new border `FlatTableHeaderBorder` to improve
compatibility with custom table header implementations. (issue #228)
- Linux: Enable text anti-aliasing if no Gnome or KDE Desktop properties are
available. (issue #218)
- IntelliJ Themes: Added "Material Theme UI Lite / GitHub Dark" theme.
- JIDE Common Layer: Improved support for `JideTabbedPane`. (PR #306)
- Extras: `FlatSVGIcon` improvements:
- Each icon can now have its own color filter. (PR #303)
- Use mapper function in color filter to dynamically map colors. (PR #303)
- Color filter supports light and dark themes.
- Getters for icon name, classloader, etc.
- Extras: UI Inspector: Show class hierarchies when pressing <kbd>Alt</kbd> key
and prettified class names (dimmed package name).
- Extras: `FlatSVGUtils.createWindowIconImages()` now returns a single
multi-resolution image that creates requested image sizes on demand from SVG
(only on Windows with Java 9+).
#### Fixed bugs
- CheckBox and RadioButton: Do not fill background if used as cell renderer,
except if cell is selected or has different background color. (issue #311)
- DesktopPane:
- Fixed missing preview of iconified internal frames in dock when using a
custom desktop manager. (PR #294)
- Fixed incomplete preview of iconified internal frames in dock when switching
LaF.
- On HiDPI screens, use high-resolution images for preview of iconified
internal frames in dock.
- PopupFactory: Fixed occasional `NullPointerException` in
`FlatPopupFactory.fixToolTipLocation()`. (issue #305)
- Tree: Fill cell background if
`DefaultTreeCellRenderer.setBackgroundNonSelectionColor(Color)` was used.
(issue #322)
- IntelliJ Themes: Fixed background colors of DesktopPane and DesktopIcon in all
themes.
- Native window decorations:
- Fixed slow application startup under particular conditions. (e.g. incomplete
custom JRE) (issue #319)
- Fixed occasional double window title bar when creating many frames or
dialogs. (issue #315)
- Fixed broken maximizing window (under special conditions) when restoring
frame state at startup.
- Title icon: For multi-resolution images now use `getResolutionVariant(width,
height)` (instead of `getResolutionVariants()`) to allow creation of
requested size on demand. This also avoids creation of all resolution
variants.
- Double-click at upper-left corner of maximized frame did not close window.
(issue #326)
- Linux: Fixed/improved detection of user font settings. (issue #309)
## 1.1.2
#### New features and improvements
- Native window decorations: Added API to check whether current platform
supports window decorations (`FlatLaf.supportsNativeWindowDecorations()`) and
to toggle window decorations of all windows
(`FlatLaf.setUseNativeWindowDecorations(boolean)`).
- Native window decorations: Support changing title bar background and
foreground colors per window. (set client properties
`JRootPane.titleBarBackground` and `JRootPane.titleBarForeground` on root pane
to a `java.awt.Color`).
#### Fixed bugs
- Native window decorations: Fixed loading of native library when using Java
Platform Module System (JPMS) for application. (issue #289)
- Native window decorations: Removed superfluous pixel-line at top of screen
when window is maximized. (issue #296)
- Window decorations: Fixed random window title bar background in cases were
background is not filled by custom window or root pane components and unified
background is enabled.
- IntelliJ Themes: Fixed window title bar background if unified background is
enabled.
- IntelliJ Themes: Fixed system colors.
- Button and ToggleButton: Do not paint background of disabled (and unselected)
toolBar buttons. (issue #292; regression since fixing #112)
- ComboBox and Spinner: Fixed too wide arrow button if component is higher than
preferred. (issue #302)
- SplitPane: `JSplitPane.setContinuousLayout(false)` did not work. (issue #301)
- TabbedPane: Fixed NPE when creating/modifying in another thread. (issue #299)
- Fixed crash when running in Webswing. (issue #290)
## 1.1.1
#### New features and improvements
- Native window decorations: Support disabling native window decorations per
window. (set client property `JRootPane.useWindowDecorations` on root pane to
`false`).
- Support running on WinPE. (issue #279)
#### Fixed bugs
- Native window decorations: Fixed missing animations when minimizing,
maximizing or restoring a window using window title bar buttons. (issue #282)
- Native window decorations: Fixed broken maximizing window when restoring frame
state at startup. (issue #283)
- Native window decorations: Fixed double window title bar when first disposing
a window with `frame.dispose()` and then showing it again with
`frame.setVisible(true)`. (issue #277)
- Custom window decorations: Fixed NPE in `FlatTitlePane.findHorizontalGlue()`.
(issue #275)
- Custom window decorations: Fixed right aligned progress bar in embedded menu
bar was overlapping window title. (issue #272)
- Fixed missing focus indicators in heavy-weight popups. (issue #273)
- InternalFrame: Fixed translucent internal frame menu bar background if
`TitlePane.unifiedBackground` is `true`. (issue #274)
- Extras: UI Inspector: Fixed `InaccessibleObjectException` when running in Java 16.
## 1.1
#### New features and improvements
- Windows 10 only:
- Native window decorations for Windows 10 enables dark frame/dialog title bar
and embedded menu bar with all JREs, while still having native Windows 10
border drop shadows, resize behavior, window snapping and system window
menu. (PR #267)
- Custom window decorations: Support right aligned components in `JFrame`
title bar with embedded menu bar (using `Box.createHorizontalGlue()`). (PR
#268)
- Custom window decorations: Improved centering of window title with embedded
menu bar. (PR #268; issue #252)
- Custom window decorations: Support unified backgrounds for window title bar,
menu bar and main content. If enabled with `UIManager.put(
"TitlePane.unifiedBackground", true );` then window title bar and menu bar
use same background color as main content. (PR #268; issue #254)
- JIDE Common Layer: Support `JideButton`, `JideLabel`, `JideSplitButton`,
`JideToggleButton` and `JideToggleSplitButton`.
- JIDE Common Layer: The library on Maven Central no longer depends on
`com.jidesoft:jide-oss:3.6.18` to avoid problems when another JIDE library
should be used. (issue #270)
- SwingX: The library on Maven Central no longer depends on
`org.swinglabs.swingx:swingx-all:1.6.5-1` to avoid problems when another
SwingX library should be used.
- Support running in [JetBrains Projector](https://jetbrains.com/projector/).
#### Fixed bugs
- IntelliJ Themes: Fixed text color of CheckBoxMenuItem and RadioButtonMenuItem
in all "Arc" themes. (issue #259)
## 1.0
#### New features and improvements
- Extras: UI Inspector: Tooltip is no longer limited to window bounds.
#### Fixed bugs
- TabbedPane: Custom `TabbedPane.selectedForeground` color did not work when
`TabbedPane.foreground` has also custom color. (issue #257)
- FileChooser: Fixed display of date in details view if current user is selected
in "Look in" combobox. (Windows 10 only; issue #249)
- Table: Fixed wrong grid line thickness in dragged column on HiDPI screens on
Java 9+. (issue #236)
- PopupFactory: Fixed `NullPointerException` when `PopupFactory.getPopup()` is
invoked with parameter `owner` set to `null`.
## 1.0-rc3
#### New features and improvements
- Extras:
- UI Inspector: Use HTML in tooltip. Display color value in same format as
used in FlatLaf properties files. Added color preview.
#### Fixed bugs
- Label and ToolTip: Fixed font sizes for `<code>`, `<kbd>`, `<big>`, `<small>`
and `<samp>` tags in HTML text.
- Fixed color of `<address>` tag in HTML text.
- IntelliJ Themes: Fixed table header background when dragging column in "Dark
Flat" and "Light Flat" themes.
- CheckBox: Fixed background of check boxes in JIDE `CheckBoxTree`. (regression
in 1.0-rc2)
## 1.0-rc2
#### New features and improvements
- Button:
- In "Flat Light" theme, use a slightly thinner border for focused buttons
(because they already have light blue background).
- In "Flat Dark" theme, use slightly wider border for focused buttons.
- CheckBox and RadioButton: In "Flat Dark" theme, use blueish background for
focused components.
- Tree: Support disabling wide selection per component. (set client property
`JTree.wideSelection` to `false`). (PR #245)
- Tree: Support disabling selection painting per component. Then the tree cell
renderer is responsible for selection painting. (set client property
`JTree.paintSelection` to `false`).
- JIDE Common Layer: Support `JidePopupMenu`.
#### Fixed bugs
- Button: Fixed behavior of <kbd>Enter</kbd> key on focused button on Windows
and Linux, which now clicks the focused button (instead of the default
button).
- On Windows, this is a regression in 1.0-rc1.
- On macOS, the <kbd>Enter</kbd> key always clicks the default button, which
is the platform behavior.
- On all platforms, the default button can be always clicked with
<kbd>Ctrl+Enter</kbd> keys, even if another button is focused.
- CheckBox and RadioButton: Fill component background as soon as background
color is different to default background color, even if component is not
opaque (which is the default). This paints selection if using the component as
cell renderer in Table, Tree or List.
- TextComponents: Border of focused non-editable text components had wrong
color.
- Custom window decorations: Fixed top window border in dark themes when running
in JetBrains Runtime.
## 1.0-rc1
#### New features and improvements

121
README.md
View File

@@ -37,7 +37,7 @@ Requires Java 8 or newer.
Download
--------
FlatLaf binaries are available on **JCenter** and **Maven Central**.
FlatLaf binaries are available on **Maven Central**.
If you use Maven or Gradle, add a dependency with following coordinates to your
build script:
@@ -48,16 +48,16 @@ build script:
Otherwise download `flatlaf-<version>.jar` here:
[![Download](https://api.bintray.com/packages/jformdesigner/flatlaf/flatlaf/images/download.svg)](https://bintray.com/jformdesigner/flatlaf/flatlaf/_latestVersion)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.formdev/flatlaf/badge.svg?style=flat-square&color=007ec6)](https://maven-badges.herokuapp.com/maven-central/com.formdev/flatlaf)
### Snapshots
FlatLaf snapshot binaries are available in
[JFrog Artifactory](https://oss.jfrog.org/artifactory/oss-snapshot-local/com/formdev/).
To access the latest snapshot, change the FlatLaf version(s) in the dependencies
FlatLaf snapshot binaries are available on
[Sonatype OSSRH](https://oss.sonatype.org/content/repositories/snapshots/com/formdev/flatlaf/).
To access the latest snapshot, change the FlatLaf version in your dependencies
to `<version>-SNAPSHOT` (e.g. `0.27-SNAPSHOT`) and add the repository
`https://oss.jfrog.org/artifactory/oss-snapshot-local` to your build (see
`https://oss.sonatype.org/content/repositories/snapshots/` to your build (see
[Maven](https://maven.apache.org/guides/mini/guide-multiple-repositories.html)
and
[Gradle](https://docs.gradle.org/current/userguide/declaring_repositories.html#sec:declaring_custom_repository)
@@ -67,42 +67,83 @@ docs).
Addons
------
- [IntelliJ Themes Pack](flatlaf-intellij-themes)
- [Extras](flatlaf-extras)
- [SwingX](flatlaf-swingx)
- [JIDE Common Layer](flatlaf-jide-oss)
- [IntelliJ Themes Pack](flatlaf-intellij-themes) - bundles many popular
open-source 3rd party themes
- [Extras](flatlaf-extras) - SVG icon, tri-state check box, UI inspectors, and
more
- [SwingX](flatlaf-swingx) - support for SwingX components
- [JIDE Common Layer](flatlaf-jide-oss) - support for JIDE Common Layer
components
Getting started
---------------
To use FlatLaf, add following code to your main method before you create any
Swing component:
~~~java
FlatLightLaf.setup();
// create UI here...
~~~
Documentation
-------------
For more information and documentation visit
[FlatLaf Home](https://www.formdev.com/flatlaf/)
[FlatLaf Home](https://www.formdev.com/flatlaf/):
- [Themes](https://www.formdev.com/flatlaf/themes/)
- [Customizing](https://www.formdev.com/flatlaf/customizing/)
- [How to Customize](https://www.formdev.com/flatlaf/how-to-customize/)
- [Properties Files](https://www.formdev.com/flatlaf/properties-files/)
- [Client Properties](https://www.formdev.com/flatlaf/client-properties/)
- [System Properties](https://www.formdev.com/flatlaf/system-properties/)
Buzz
----
- [What others say about FlatLaf on Twitter](https://twitter.com/search?f=live&q=flatlaf)
- [FlatLaf 1.0 announcement on Reddit](https://www.reddit.com/r/java/comments/lsbcwe/flatlaf_10_swing_look_and_feel/)
- [FlatLaf announcement on Reddit](https://www.reddit.com/r/java/comments/dl0hu3/flatlaf_flat_look_and_feel/)
Projects using FlatLaf
----------------------
Applications using FlatLaf
--------------------------
- [Apache NetBeans](https://netbeans.apache.org/) 11.3 - IDE for Java, PHP, HTML
and much more
- [jclasslib bytecode viewer](https://github.com/ingokegel/jclasslib) 5.5
- [KeyStore Explorer](https://keystore-explorer.org/) 5.4.3
- ![New](images/new.svg) [OWASP ZAP](https://www.zaproxy.org/) 2.10 - the worlds
most widely used web app scanner
- ![New](images/new.svg) [JOSM](https://josm.openstreetmap.de/) - an extensible
editor for [OpenStreetMap](https://www.openstreetmap.org/) (requires FlatLaf
JOSM plugin)
- [jAlbum](https://jalbum.net/) 21 (commercial) - creates photo album websites
- [XMLmind XML Editor](https://www.xmlmind.com/xmleditor/) 9.3 (commercial)
- [Total Validator](https://www.totalvalidator.com/) 15 (commercial) - checks
your website
- ![New](images/new.svg)
[install4j](https://www.ej-technologies.com/products/install4j/overview.html)
9.0 (**commercial**) - the powerful multi-platform Java installer builder
- ![New](images/new.svg) [DbVisualizer](https://www.dbvis.com/) 12.0
(**commercial**) - the universal database tool for developers, analysts and
DBAs
- ![New](images/new.svg) [MagicPlot](https://magicplot.com/) 3.0
(**commercial**) - Software for nonlinear fitting, plotting and data analysis
- ![New](images/new.svg)
[Thermo-Calc](https://thermocalc.com/products/thermo-calc/) 2021a
(**commercial**) - Thermodynamics and Properties Software
- [OWASP ZAP](https://www.zaproxy.org/) 2.10 - the worlds most widely used web
app scanner
- ![New](images/new.svg)
[Burp Suite Professional and Community Edition](https://portswigger.net/burp/pro)
2020.11.2 (**commercial**) - the leading software for web security testing
- ![New](images/new.svg)
[BurpCustomizer](https://github.com/CoreyD97/BurpCustomizer) - adds more
FlatLaf themes to Burp Suite
- [JOSM](https://josm.openstreetmap.de/) - an extensible editor for
[OpenStreetMap](https://www.openstreetmap.org/) (requires FlatLaf JOSM plugin)
- [jAlbum](https://jalbum.net/) 21 (**commercial**) - creates photo album
websites
- [XMLmind XML Editor](https://www.xmlmind.com/xmleditor/) 9.3 (**commercial**)
- [Total Validator](https://www.totalvalidator.com/) 15 (**commercial**) -
checks your website
- [j-lawyer](https://github.com/jlawyerorg/j-lawyer-org) - Kanzleisoftware
- [MegaMek](https://github.com/MegaMek/megamek) v0.47.4 and
[MekHQ](https://github.com/MegaMek/mekhq) v0.47.5 - a turn-based sci-fi board
@@ -116,32 +157,33 @@ Projects using FlatLaf
gamepad mapping software
- [SpringRemote](https://github.com/HaleyWang/SpringRemote) - remote Linux SSH
connections manager
- ![New](images/new.svg) [jEnTunnel](https://github.com/ggrandes/jentunnel) -
manage SSH Tunnels made easy
- [jEnTunnel](https://github.com/ggrandes/jentunnel) - manage SSH Tunnels made
easy
- [mendelson AS2](https://sourceforge.net/projects/mec-as2/),
[AS4](https://sourceforge.net/projects/mendelson-as4/) and
[OFTP2](https://sourceforge.net/projects/mendelson-oftp2/) (open-source) and
[mendelson AS2](https://mendelson-e-c.com/as2/),
[AS4](https://mendelson-e-c.com/as4/) and
[OFTP2](https://mendelson-e-c.com/oftp2) (commercial)
[OFTP2](https://mendelson-e-c.com/oftp2) (**commercial**)
- ![New](images/new.svg) [IGMAS+](https://www.gfz-potsdam.de/igmas) -
Interactive Gravity and Magnetic Application System
- [MeteoInfo](https://github.com/meteoinfo/MeteoInfo) 2.2 - GIS and scientific
computation environment for meteorological community
- [lsfusion platform](https://github.com/lsfusion/platform) 4 - information
systems development platform
- ![New](images/new.svg) [JPass](https://github.com/gaborbata/jpass) - password
manager with strong encryption
- [JPass](https://github.com/gaborbata/jpass) - password manager with strong
encryption
- [Jes - Die Java-E<>R](https://www.jes-eur.de)
- [Mapton](https://mapton.org/) 2.0
([source code](https://github.com/trixon/mapton)) - some kind of map
application (based on NetBeans platform)
- [Pseudo Assembler IDE](https://github.com/tomasz-herman/PseudoAssemblerIDE) -
IDE for Pseudo-Assembler
- ![New](images/new.svg) [Linotte](https://github.com/cpc6128/LangageLinotte)
3.1 - French programming language created to learn programming
- ![New](images/new.svg) [MEKA](https://github.com/Waikato/meka) 1.9.3 -
multi-label classifiers and evaluation procedures using the Weka machine
learning framework
- ![New](images/new.svg) [Shutter Encoder](https://www.shutterencoder.com/) 14.2
- [Linotte](https://github.com/cpc6128/LangageLinotte) 3.1 - French programming
language created to learn programming
- [MEKA](https://github.com/Waikato/meka) 1.9.3 - multi-label classifiers and
evaluation procedures using the Weka machine learning framework
- [Shutter Encoder](https://www.shutterencoder.com/) 14.2
([source code](https://github.com/paulpacifico/shutter-encoder)) -
professional video converter and compression tool (screenshots show **old**
look)
@@ -149,15 +191,12 @@ Projects using FlatLaf
sound files in time or frequency domain
- [RemoteLight](https://github.com/Drumber/RemoteLight) - multifunctional LED
control software
- ![New](images/new.svg)
[ThunderFocus](https://github.com/marcocipriani01/ThunderFocus) -
- [ThunderFocus](https://github.com/marcocipriani01/ThunderFocus) -
Arduino-based telescope focuser
- ![New](images/new.svg)
[Novel-Grabber](https://github.com/Flameish/Novel-Grabber) - download novels
- [Novel-Grabber](https://github.com/Flameish/Novel-Grabber) - download novels
from any webnovel and lightnovel site
- ![New](images/new.svg) [lectureStudio](https://www.lecturestudio.org/)
4.3.1060 - digitize your lectures with ease
- ![New](images/new.svg)
[Android Tool](https://github.com/fast-geek/Android-Tool) - makes popular adb
- [lectureStudio](https://www.lecturestudio.org/) 4.3.1060 - digitize your
lectures with ease
- [Android Tool](https://github.com/fast-geek/Android-Tool) - makes popular adb
and fastboot commands easier to use
- and more...

View File

@@ -14,8 +14,8 @@
* limitations under the License.
*/
val releaseVersion = "1.0-rc1"
val developmentVersion = "1.0-rc2-SNAPSHOT"
val releaseVersion = "1.6.1"
val developmentVersion = "2.0-SNAPSHOT"
version = if( java.lang.Boolean.getBoolean( "release" ) ) releaseVersion else developmentVersion
@@ -23,7 +23,7 @@ allprojects {
version = rootProject.version
repositories {
jcenter()
mavenCentral()
}
}
@@ -40,17 +40,6 @@ println( "Java ${System.getProperty( "java.version" )}" )
println()
extra["bintray.user"] = System.getenv( "BINTRAY_USER" ) ?: System.getProperty( "bintray.user" )
extra["bintray.key"] = System.getenv( "BINTRAY_KEY" ) ?: System.getProperty( "bintray.key" )
// if true, do not upload to bintray
extra["bintray.dryRun"] = false
// if true, uploaded artifacts are visible to all
// if false, only visible to owner when logged into bintray
extra["bintray.publish"] = false
allprojects {
tasks {
withType<JavaCompile>().configureEach {
@@ -58,19 +47,35 @@ allprojects {
targetCompatibility = "1.8"
options.encoding = "ISO-8859-1"
options.isDeprecation = false
}
withType<Jar>().configureEach {
// manifest for all created JARs
manifest.attributes(mapOf(
manifest.attributes(
"Implementation-Vendor" to "FormDev Software GmbH",
"Implementation-Copyright" to "Copyright (C) 2019-${java.time.LocalDate.now().year} FormDev Software GmbH. All rights reserved.",
"Implementation-Version" to project.version))
"Implementation-Version" to project.version
)
// add META-INF/LICENSE to all created JARs
from("${rootDir}/LICENSE") {
into("META-INF")
from( "${rootDir}/LICENSE" ) {
into( "META-INF" )
}
}
withType<Javadoc>().configureEach {
options {
this as StandardJavadocDocletOptions
title = "${project.name} $version"
header = title
isUse = true
tags = listOf( "uiDefault", "clientProperty" )
addStringOption( "Xdoclint:all,-missing", "-Xdoclint:all,-missing" )
links( "https://docs.oracle.com/en/java/javase/11/docs/api/" )
}
isFailOnError = false
}
}
}

View File

@@ -20,15 +20,5 @@ plugins {
// required for kotlin-dsl or embedded-kotlin plugins
repositories {
jcenter()
}
dependencies {
// NOTE: keep plugin versions in sync with settings.gradle.kts
// "com.jfrog.bintray" plugin
implementation( "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4" )
// "com.jfrog.artifactory" plugin
implementation( "org.jfrog.buildinfo:build-info-extractor-gradle:4.13.0" )
mavenCentral()
}

View File

@@ -27,6 +27,10 @@ if( JavaVersion.current() >= JavaVersion.VERSION_1_9 ) {
}
}
dependencies {
add( "java9Compile", sourceSets.main.get().output )
}
tasks {
named<JavaCompile>( "compileJava9Java" ) {
sourceCompatibility = "9"

View File

@@ -33,9 +33,17 @@ if( JavaVersion.current() >= JavaVersion.VERSION_1_9 ) {
sourceSets {
create( "module-info" ) {
java {
// include "src/main/java" here to get compile errors if classes are
// include "src/main/java" and "src/main/java9" here to get compile errors if classes are
// used from other modules that are not specified in module dependencies
setSrcDirs( listOf( "src/main/module-info", "src/main/java" ) )
setSrcDirs( listOf( "src/main/module-info", "src/main/java", "src/main/java9" ) )
// exclude Java 8 source file if an equally named Java 9+ source file exists
exclude {
if( it.isDirectory )
return@exclude false
val java9file = file( "${projectDir}/src/main/java9/${it.path}" )
java9file.exists() && java9file != it.file
}
}
}
}
@@ -48,7 +56,8 @@ if( JavaVersion.current() >= JavaVersion.VERSION_1_9 ) {
dependsOn( extension.paths )
options.compilerArgs.add( "--module-path" )
options.compilerArgs.add( configurations.runtimeClasspath.get().asPath )
options.compilerArgs.add( configurations.runtimeClasspath.get().asPath
+ File.pathSeparator + configurations.compileClasspath.get().asPath )
}
jar {

View File

@@ -26,8 +26,7 @@ val extension = project.extensions.create<PublishExtension>( "flatlafPublish" )
plugins {
`maven-publish`
id( "com.jfrog.bintray" )
id( "com.jfrog.artifactory" )
signing
}
publishing {
@@ -74,49 +73,40 @@ publishing {
}
}
}
}
bintray {
user = rootProject.extra["bintray.user"] as String?
key = rootProject.extra["bintray.key"] as String?
repositories {
maven {
name = "OSSRH"
setPublications( "maven" )
val releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
val snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
url = uri( if( java.lang.Boolean.getBoolean( "release" ) ) releasesRepoUrl else snapshotsRepoUrl )
with( pkg ) {
repo = "flatlaf"
afterEvaluate {
this@with.name = extension.artifactId
credentials {
// get from gradle.properties
val ossrhUsername: String? by project
val ossrhPassword: String? by project
username = System.getenv( "OSSRH_USERNAME" ) ?: ossrhUsername
password = System.getenv( "OSSRH_PASSWORD" ) ?: ossrhPassword
}
}
setLicenses( "Apache-2.0" )
vcsUrl = "https://github.com/JFormDesigner/FlatLaf"
with( version ) {
name = project.version.toString()
}
publish = rootProject.extra["bintray.publish"] as Boolean
dryRun = rootProject.extra["bintray.dryRun"] as Boolean
}
}
artifactory {
setContextUrl( "https://oss.jfrog.org" )
signing {
// get from gradle.properties
val signingKey: String? by project
val signingPassword: String? by project
publish( closureOf<org.jfrog.gradle.plugin.artifactory.dsl.PublisherConfig> {
repository( delegateClosureOf<groovy.lang.GroovyObject> {
setProperty( "repoKey", "oss-snapshot-local" )
setProperty( "username", rootProject.extra["bintray.user"] as String? )
setProperty( "password", rootProject.extra["bintray.key"] as String? )
} )
val key = System.getenv( "SIGNING_KEY" ) ?: signingKey
val password = System.getenv( "SIGNING_PASSWORD" ) ?: signingPassword
defaults( delegateClosureOf<groovy.lang.GroovyObject> {
invokeMethod( "publications", "maven" )
setProperty( "publishArtifacts", true )
setProperty( "publishPom", true )
} )
} )
resolve( delegateClosureOf<org.jfrog.gradle.plugin.artifactory.dsl.ResolverConfig> {
setProperty( "repoKey", "jcenter" )
} )
useInMemoryPgpKeys( key, password )
sign( publishing.publications["maven"] )
}
// disable signing of snapshots
tasks.withType<Sign>().configureEach {
onlyIf { java.lang.Boolean.getBoolean( "release" ) }
}

View File

@@ -21,12 +21,28 @@ plugins {
`flatlaf-publish`
}
dependencies {
testImplementation( "org.junit.jupiter:junit-jupiter-api:5.7.2" )
testImplementation( "org.junit.jupiter:junit-jupiter-params" )
testRuntimeOnly( "org.junit.jupiter:junit-jupiter-engine" )
}
java {
withSourcesJar()
withJavadocJar()
}
tasks {
compileJava {
// generate JNI headers
options.headerOutputDirectory.set( buildDir.resolve( "generated/jni-headers" ) )
}
processResources {
// build native libraries
dependsOn( ":flatlaf-natives-windows:assemble" )
}
jar {
archiveBaseName.set( "flatlaf" )
@@ -35,23 +51,18 @@ tasks {
}
}
javadoc {
options {
this as StandardJavadocDocletOptions
use( true )
tags = listOf( "uiDefault", "clientProperty" )
addStringOption( "Xdoclint:all,-missing", "-Xdoclint:all,-missing" )
}
isFailOnError = false
}
named<Jar>("sourcesJar" ) {
named<Jar>( "sourcesJar" ) {
archiveBaseName.set( "flatlaf" )
}
named<Jar>("javadocJar" ) {
named<Jar>( "javadocJar" ) {
archiveBaseName.set( "flatlaf" )
}
test {
useJUnitPlatform()
testLogging.exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
}
}
flatlafPublish {

View File

@@ -22,6 +22,8 @@ import javax.swing.JComponent;
import javax.swing.SwingConstants;
/**
* Defines/documents own client properties used in FlatLaf.
*
* @author Karl Tauber
*/
public interface FlatClientProperties
@@ -37,8 +39,9 @@ public interface FlatClientProperties
* {@link #BUTTON_TYPE_SQUARE},
* {@link #BUTTON_TYPE_ROUND_RECT},
* {@link #BUTTON_TYPE_TAB},
* {@link #BUTTON_TYPE_HELP} or
* {@link BUTTON_TYPE_TOOLBAR_BUTTON}
* {@link #BUTTON_TYPE_HELP},
* {@link #BUTTON_TYPE_TOOLBAR_BUTTON} or
* {@link #BUTTON_TYPE_BORDERLESS}
*/
String BUTTON_TYPE = "JButton.buttonType";
@@ -87,6 +90,16 @@ public interface FlatClientProperties
*/
String BUTTON_TYPE_TOOLBAR_BUTTON = "toolBarButton";
/**
* Paint the button without a border in the unfocused state.
* <p>
* <strong>Components</strong> {@link javax.swing.JButton} and {@link javax.swing.JToggleButton}
*
* @see #BUTTON_TYPE
* @since 1.2
*/
String BUTTON_TYPE_BORDERLESS = "borderless";
/**
* Specifies selected state of a checkbox.
* <p>
@@ -170,6 +183,25 @@ public interface FlatClientProperties
*/
String OUTLINE_WARNING = "warning";
/**
* Specifies a callback that is invoked to check whether a component is permanent focus owner.
* Used to paint focus indicators.
* <p>
* May be useful in special cases for custom components.
* <p>
* Use a {@link java.util.function.Predicate} that receives the component as parameter:
* <pre>{@code
* myComponent.putClientProperty( "JComponent.focusOwner",
* (Predicate<JComponent>) c -> {
* return ...; // check here
* } );
* }</pre>
* <p>
* <strong>Component</strong> {@link javax.swing.JComponent}<br>
* <strong>Value type</strong> {@link java.util.function.Predicate}&lt;javax.swing.JComponent&gt;
*/
String COMPONENT_FOCUS_OWNER = "JComponent.focusOwner";
//---- Popup --------------------------------------------------------------
/**
@@ -211,14 +243,67 @@ public interface FlatClientProperties
//---- JRootPane ----------------------------------------------------------
/**
* Specifies whether the menu bar is embedded into the title pane if custom
* window decorations are enabled. Default is {@code true}.
* Specifies whether FlatLaf native window decorations should be used
* for {@code JFrame} or {@code JDialog}.
* <p>
* Setting this enables/disables using FlatLaf native window decorations
* for the window that contains the root pane.
* <p>
* This client property has lower priority than system property
* {@link FlatSystemProperties#USE_WINDOW_DECORATIONS}, but higher priority
* than UI default {@code TitlePane.useWindowDecorations}.
* <p>
* (requires Window 10)
* <p>
* <strong>Component</strong> {@link javax.swing.JRootPane}<br>
* <strong>Value type</strong> {@link java.lang.Boolean}
*
* @since 1.1.1
*/
String USE_WINDOW_DECORATIONS = "JRootPane.useWindowDecorations";
/**
* Specifies whether the menu bar is embedded into the window title pane
* if window decorations are enabled.
* <p>
* Setting this enables/disables embedding
* for the window that contains the root pane.
* <p>
* This client property has lower priority than system property
* {@link FlatSystemProperties#MENUBAR_EMBEDDED}, but higher priority
* than UI default {@code TitlePane.menuBarEmbedded}.
* <p>
* (requires Window 10)
* <p>
* <strong>Component</strong> {@link javax.swing.JRootPane}<br>
* <strong>Value type</strong> {@link java.lang.Boolean}
*/
String MENU_BAR_EMBEDDED = "JRootPane.menuBarEmbedded";
/**
* Background color of window title bar (requires enabled window decorations).
* <p>
* (requires Window 10)
* <p>
* <strong>Component</strong> {@link javax.swing.JRootPane}<br>
* <strong>Value type</strong> {@link java.awt.Color}
*
* @since 1.1.2
*/
String TITLE_BAR_BACKGROUND = "JRootPane.titleBarBackground";
/**
* Foreground color of window title bar (requires enabled window decorations).
* <p>
* (requires Window 10)
* <p>
* <strong>Component</strong> {@link javax.swing.JRootPane}<br>
* <strong>Value type</strong> {@link java.awt.Color}
*
* @since 1.1.2
*/
String TITLE_BAR_FOREGROUND = "JRootPane.titleBarForeground";
//---- JScrollBar / JScrollPane -------------------------------------------
/**
@@ -232,7 +317,7 @@ public interface FlatClientProperties
/**
* Specifies whether the scroll pane uses smooth scrolling.
* <p>
* <strong>Component</strong> {{@link javax.swing.JScrollPane}<br>
* <strong>Component</strong> {@link javax.swing.JScrollPane}<br>
* <strong>Value type</strong> {@link java.lang.Boolean}
*/
String SCROLL_PANE_SMOOTH_SCROLLING = "JScrollPane.smoothScrolling";
@@ -293,10 +378,12 @@ public interface FlatClientProperties
String TABBED_PANE_MAXIMUM_TAB_WIDTH = "JTabbedPane.maximumTabWidth";
/**
* Specifies the height of a tab.
* Specifies the minimum height of a tab.
* <p>
* <strong>Component</strong> {@link javax.swing.JTabbedPane}<br>
* <strong>Value type</strong> {@link java.lang.Integer}
*
* @see #TABBED_PANE_TAB_INSETS
*/
String TABBED_PANE_TAB_HEIGHT = "JTabbedPane.tabHeight";
@@ -306,6 +393,8 @@ public interface FlatClientProperties
* <strong>Component</strong> {@link javax.swing.JTabbedPane}
* or tab content components (see {@link javax.swing.JTabbedPane#setComponentAt(int, java.awt.Component)})<br>
* <strong>Value type</strong> {@link java.awt.Insets}
*
* @see #TABBED_PANE_TAB_HEIGHT
*/
String TABBED_PANE_TAB_INSETS = "JTabbedPane.tabInsets";
@@ -644,6 +733,18 @@ public interface FlatClientProperties
*/
String PLACEHOLDER_TEXT = "JTextField.placeholderText";
/**
* Specifies the padding of the text.
* This changes the location and size of the text view within the component bounds,
* but does not affect the size of the component.
* <p>
* <strong>Component</strong> {@link javax.swing.JTextField} (and subclasses)<br>
* <strong>Value type</strong> {@link java.awt.Insets}
*
* @since 1.4
*/
String TEXT_FIELD_PADDING = "JTextField.padding";
//---- JToggleButton ------------------------------------------------------
/**
@@ -670,6 +771,25 @@ public interface FlatClientProperties
*/
String TAB_BUTTON_SELECTED_BACKGROUND = "JToggleButton.tab.selectedBackground";
//---- JTree --------------------------------------------------------------
/**
* Override if a tree shows a wide selection. Default is {@code true}.
* <p>
* <strong>Component</strong> {@link javax.swing.JTree}<br>
* <strong>Value type</strong> {@link java.lang.Boolean}
*/
String TREE_WIDE_SELECTION = "JTree.wideSelection";
/**
* Specifies whether tree item selection is painted. Default is {@code true}.
* If set to {@code false}, then the tree cell renderer is responsible for painting selection.
* <p>
* <strong>Component</strong> {@link javax.swing.JTree}<br>
* <strong>Value type</strong> {@link java.lang.Boolean}
*/
String TREE_PAINT_SELECTION = "JTree.paintSelection";
//---- helper methods -----------------------------------------------------
/**

View File

@@ -16,6 +16,8 @@
package com.formdev.flatlaf;
import javax.swing.UIManager;
/**
* A Flat LaF that has a dark color scheme and looks like Darcula LaF.
* <p>
@@ -29,10 +31,28 @@ public class FlatDarculaLaf
{
public static final String NAME = "FlatLaf Darcula";
public static boolean install() {
return install( new FlatDarculaLaf() );
/**
* Sets the application look and feel to this LaF
* using {@link UIManager#setLookAndFeel(javax.swing.LookAndFeel)}.
*/
public static boolean setup() {
return setup( new FlatDarculaLaf() );
}
/**
* @deprecated use {@link #setup()} instead; this method will be removed in a future version
*/
@Deprecated
public static boolean install() {
return setup();
}
/**
* Adds this look and feel to the set of available look and feels.
* <p>
* Useful if your application uses {@link UIManager#getInstalledLookAndFeels()}
* to query available LaFs and display them to the user in a combobox.
*/
public static void installLafInfo() {
installLafInfo( NAME, FlatDarculaLaf.class );
}

View File

@@ -34,8 +34,16 @@ public class FlatDarkLaf
* Sets the application look and feel to this LaF
* using {@link UIManager#setLookAndFeel(javax.swing.LookAndFeel)}.
*/
public static boolean setup() {
return setup( new FlatDarkLaf() );
}
/**
* @deprecated use {@link #setup()} instead; this method will be removed in a future version
*/
@Deprecated
public static boolean install() {
return install( new FlatDarkLaf() );
return setup();
}
/**

View File

@@ -42,10 +42,12 @@ class FlatInputMaps
}
private static void initBasicInputMaps( UIDefaults defaults ) {
defaults.put( "Button.focusInputMap", new UIDefaults.LazyInputMap( new Object[] {
"SPACE", "pressed",
"released SPACE", "released"
} ) );
if( SystemInfo.isMacOS ) {
defaults.put( "Button.focusInputMap", new UIDefaults.LazyInputMap( new Object[] {
"SPACE", "pressed",
"released SPACE", "released"
} ) );
}
modifyInputMap( defaults, "ComboBox.ancestorInputMap",
"SPACE", "spacePopup",

View File

@@ -16,6 +16,8 @@
package com.formdev.flatlaf;
import javax.swing.UIManager;
/**
* A Flat LaF that has a light color scheme and looks like IntelliJ LaF.
* <p>
@@ -29,10 +31,28 @@ public class FlatIntelliJLaf
{
public static final String NAME = "FlatLaf IntelliJ";
public static boolean install() {
return install( new FlatIntelliJLaf() );
/**
* Sets the application look and feel to this LaF
* using {@link UIManager#setLookAndFeel(javax.swing.LookAndFeel)}.
*/
public static boolean setup() {
return setup( new FlatIntelliJLaf() );
}
/**
* @deprecated use {@link #setup()} instead; this method will be removed in a future version
*/
@Deprecated
public static boolean install() {
return setup();
}
/**
* Adds this look and feel to the set of available look and feels.
* <p>
* Useful if your application uses {@link UIManager#getInstalledLookAndFeels()}
* to query available LaFs and display them to the user in a combobox.
*/
public static void installLafInfo() {
installLafInfo( NAME, FlatIntelliJLaf.class );
}

View File

@@ -32,14 +32,17 @@ import java.beans.PropertyChangeListener;
import java.io.File;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.Properties;
import java.util.ResourceBundle;
import java.util.ServiceLoader;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.ImageIcon;
@@ -48,6 +51,7 @@ import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.LookAndFeel;
import javax.swing.PopupFactory;
import javax.swing.RootPaneContainer;
import javax.swing.SwingUtilities;
import javax.swing.UIDefaults;
import javax.swing.UIDefaults.ActiveValue;
@@ -55,14 +59,19 @@ import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.plaf.ColorUIResource;
import javax.swing.plaf.FontUIResource;
import javax.swing.plaf.IconUIResource;
import javax.swing.plaf.UIResource;
import javax.swing.plaf.basic.BasicLookAndFeel;
import javax.swing.text.StyleContext;
import javax.swing.text.html.HTMLEditorKit;
import com.formdev.flatlaf.ui.FlatNativeWindowBorder;
import com.formdev.flatlaf.ui.FlatPopupFactory;
import com.formdev.flatlaf.ui.JBRCustomDecorations;
import com.formdev.flatlaf.ui.FlatRootPaneUI;
import com.formdev.flatlaf.ui.FlatUIUtils;
import com.formdev.flatlaf.util.GrayFilter;
import com.formdev.flatlaf.util.LoggingFacade;
import com.formdev.flatlaf.util.MultiResolutionImageSupport;
import com.formdev.flatlaf.util.StringUtils;
import com.formdev.flatlaf.util.SystemInfo;
import com.formdev.flatlaf.util.UIScale;
@@ -74,7 +83,6 @@ import com.formdev.flatlaf.util.UIScale;
public abstract class FlatLaf
extends BasicLookAndFeel
{
static final Logger LOG = Logger.getLogger( FlatLaf.class.getName() );
private static final String DESKTOPFONTHINTS = "awt.font.desktophints";
private static List<Object> customDefaultsSources;
@@ -90,24 +98,30 @@ public abstract class FlatLaf
private MnemonicHandler mnemonicHandler;
private Consumer<UIDefaults> postInitialization;
private Boolean oldFrameWindowDecorated;
private Boolean oldDialogWindowDecorated;
private List<Function<Object, Object>> uiDefaultsGetters;
/**
* Sets the application look and feel to the given LaF
* using {@link UIManager#setLookAndFeel(javax.swing.LookAndFeel)}.
*/
public static boolean install( LookAndFeel newLookAndFeel ) {
public static boolean setup( LookAndFeel newLookAndFeel ) {
try {
UIManager.setLookAndFeel( newLookAndFeel );
return true;
} catch( Exception ex ) {
LOG.log( Level.SEVERE, "FlatLaf: Failed to initialize look and feel '" + newLookAndFeel.getClass().getName() + "'.", ex );
LoggingFacade.INSTANCE.logSevere( "FlatLaf: Failed to setup look and feel '" + newLookAndFeel.getClass().getName() + "'.", ex );
return false;
}
}
/**
* @deprecated use {@link #setup(LookAndFeel)} instead; this method will be removed in a future version
*/
@Deprecated
public static boolean install( LookAndFeel newLookAndFeel ) {
return setup( newLookAndFeel );
}
/**
* Adds the given look and feel to the set of available look and feels.
* <p>
@@ -145,28 +159,28 @@ public abstract class FlatLaf
* Returns whether FlatLaf supports custom window decorations.
* This depends on the operating system and on the used Java runtime.
* <p>
* To use custom window decorations in your application, enable them with
* following code (before creating any frames or dialogs). Then custom window
* decorations are only enabled if this method returns {@code true}.
* <pre>
* JFrame.setDefaultLookAndFeelDecorated( true );
* JDialog.setDefaultLookAndFeelDecorated( true );
* </pre>
* This method returns {@code true} on Windows 10 (see exception below), {@code false} otherwise.
* <p>
* Returns {@code true} on Windows 10, {@code false} otherwise.
* <p>
* Return also {@code false} if running on Windows 10 in
* Returns also {@code false} on Windows 10 if:
* <ul>
* <li>FlatLaf native window border support is available (requires Windows 10)</li>
* <li>running in
* <a href="https://confluence.jetbrains.com/display/JBR/JetBrains+Runtime">JetBrains Runtime 11 (or later)</a>
* (<a href="https://github.com/JetBrains/JetBrainsRuntime">source code on github</a>)
* and JBR supports custom window decorations. In this case, JBR custom decorations
* are enabled if {@link JFrame#isDefaultLookAndFeelDecorated()} or
* {@link JDialog#isDefaultLookAndFeelDecorated()} return {@code true}.
* and JBR supports custom window decorations
* </li>
* </ul>
* In this cases, custom decorations are enabled by the root pane.
* Usage of {@link JFrame#setDefaultLookAndFeelDecorated(boolean)} or
* {@link JDialog#setDefaultLookAndFeelDecorated(boolean)} is not necessary.
*/
@Override
public boolean getSupportsWindowDecorations() {
if( SystemInfo.isJetBrainsJVM_11_orLater &&
SystemInfo.isWindows_10_orLater &&
JBRCustomDecorations.isSupported() )
if( SystemInfo.isProjector || SystemInfo.isWebswing || SystemInfo.isWinPE )
return false;
if( SystemInfo.isWindows_10_orLater &&
FlatNativeWindowBorder.isSupported() )
return false;
return SystemInfo.isWindows_10_orLater;
@@ -184,8 +198,10 @@ public abstract class FlatLaf
@Override
public Icon getDisabledIcon( JComponent component, Icon icon ) {
if( icon instanceof DisabledIconProvider )
return ((DisabledIconProvider)icon).getDisabledIcon();
if( icon instanceof DisabledIconProvider ) {
Icon disabledIcon = ((DisabledIconProvider)icon).getDisabledIcon();
return !(disabledIcon instanceof UIResource) ? new IconUIResource( disabledIcon ) : disabledIcon;
}
if( icon instanceof ImageIcon ) {
Object grayFilter = UIManager.get( "Component.grayFilter" );
@@ -262,19 +278,9 @@ public abstract class FlatLaf
Color linkColor = defaults.getColor( "Component.linkColor" );
if( linkColor != null ) {
new HTMLEditorKit().getStyleSheet().addRule(
String.format( "a { color: #%06x; }", linkColor.getRGB() & 0xffffff ) );
String.format( "a, address { color: #%06x; }", linkColor.getRGB() & 0xffffff ) );
}
};
// enable/disable window decorations, but only if system property is either
// "true" or "false"; in other cases it is not changed
Boolean useWindowDecorations = FlatSystemProperties.getBooleanStrict( FlatSystemProperties.USE_WINDOW_DECORATIONS, null );
if( useWindowDecorations != null ) {
oldFrameWindowDecorated = JFrame.isDefaultLookAndFeelDecorated();
oldDialogWindowDecorated = JDialog.isDefaultLookAndFeelDecorated();
JFrame.setDefaultLookAndFeelDecorated( useWindowDecorations );
JDialog.setDefaultLookAndFeelDecorated( useWindowDecorations );
}
}
@Override
@@ -304,17 +310,9 @@ public abstract class FlatLaf
}
// restore default link color
new HTMLEditorKit().getStyleSheet().addRule( "a { color: blue; }" );
new HTMLEditorKit().getStyleSheet().addRule( "a, address { color: blue; }" );
postInitialization = null;
// restore enable/disable window decorations
if( oldFrameWindowDecorated != null ) {
JFrame.setDefaultLookAndFeelDecorated( oldFrameWindowDecorated );
JDialog.setDefaultLookAndFeelDecorated( oldDialogWindowDecorated );
oldFrameWindowDecorated = null;
oldDialogWindowDecorated = null;
}
super.uninitialize();
}
@@ -339,9 +337,9 @@ public abstract class FlatLaf
Method m = UIManager.class.getMethod( "createLookAndFeel", String.class );
aquaLaf = (BasicLookAndFeel) m.invoke( null, "Mac OS X" );
} else
aquaLaf = (BasicLookAndFeel) Class.forName( aquaLafClassName ).newInstance();
aquaLaf = (BasicLookAndFeel) Class.forName( aquaLafClassName ).getDeclaredConstructor().newInstance();
} catch( Exception ex ) {
LOG.log( Level.SEVERE, "FlatLaf: Failed to initialize Aqua look and feel '" + aquaLafClassName + "'.", ex );
LoggingFacade.INSTANCE.logSevere( "FlatLaf: Failed to initialize Aqua look and feel '" + aquaLafClassName + "'.", ex );
throw new IllegalStateException();
}
@@ -359,14 +357,21 @@ public abstract class FlatLaf
@Override
public UIDefaults getDefaults() {
UIDefaults defaults = super.getDefaults();
// use larger initial capacity to avoid resizing UI defaults hash table
// (from 610 to 1221 to 2443 entries) and to save some memory
UIDefaults defaults = new FlatUIDefaults( 1500, 0.75f );
// initialize basic defaults (see super.getDefaults())
initClassDefaults( defaults );
initSystemColorDefaults( defaults );
initComponentDefaults( defaults );
// add flag that indicates whether the LaF is light or dark
// (can be queried without using FlatLaf API)
defaults.put( "laf.dark", isDark() );
// add resource bundle for localized texts
defaults.addResourceBundle( "com.formdev.flatlaf.resources.Bundle" );
// init resource bundle for localized texts
initResourceBundle( defaults, "com.formdev.flatlaf.resources.Bundle" );
// initialize some defaults (for overriding) that are used in UI delegates,
// but are not set in BasicLookAndFeel
@@ -400,6 +405,12 @@ public abstract class FlatLaf
initIconColors( defaults, isDark() );
FlatInputMaps.initInputMaps( defaults );
// copy InternalFrame.icon (the Java cup) to TitlePane.icon
// (using defaults.remove() to avoid that lazy value is resolved and icon loaded here)
Object icon = defaults.remove( "InternalFrame.icon" );
defaults.put( "InternalFrame.icon", icon );
defaults.put( "TitlePane.icon", icon );
// get addons and sort them by priority
ServiceLoader<FlatDefaultsAddon> addonLoader = ServiceLoader.load( FlatDefaultsAddon.class );
List<FlatDefaultsAddon> addons = new ArrayList<>();
@@ -456,13 +467,60 @@ public abstract class FlatLaf
return null;
}
private void initResourceBundle( UIDefaults defaults, String bundleName ) {
// add resource bundle for localized texts
defaults.addResourceBundle( bundleName );
// Check whether Swing can not load the FlatLaf resource bundle,
// which can happen in applications that use some plugin system
// and load FlatLaf in a plugin that uses its own classloader.
// (e.g. Apache NetBeans)
if( defaults.get( "FileChooser.fileNameHeaderText" ) != null )
return;
// load FlatLaf resource bundle and add content to defaults
try {
ResourceBundle bundle = ResourceBundle.getBundle( bundleName, defaults.getDefaultLocale() );
Enumeration<String> keys = bundle.getKeys();
while( keys.hasMoreElements() ) {
String key = keys.nextElement();
String value = bundle.getString( key );
String baseKey = StringUtils.removeTrailing( key, ".textAndMnemonic" );
if( baseKey != key ) {
String text = value.replace( "&", "" );
String mnemonic = null;
int index = value.indexOf( '&' );
if( index >= 0 )
mnemonic = Integer.toString( Character.toUpperCase( value.charAt( index + 1 ) ) );
defaults.put( baseKey + "Text", text );
if( mnemonic != null )
defaults.put( baseKey + "Mnemonic", mnemonic );
} else
defaults.put( key, value );
}
} catch( MissingResourceException ex ) {
LoggingFacade.INSTANCE.logSevere( null, ex );
}
}
private void initFonts( UIDefaults defaults ) {
FontUIResource uiFont = null;
if( SystemInfo.isWindows ) {
Font winFont = (Font) Toolkit.getDefaultToolkit().getDesktopProperty( "win.messagebox.font" );
if( winFont != null )
uiFont = createCompositeFont( winFont.getFamily(), winFont.getStyle(), winFont.getSize() );
if( winFont != null ) {
if( SystemInfo.isWinPE ) {
// on WinPE use "win.defaultGUI.font", which is usually Tahoma,
// because Segoe UI font is not available on WinPE
Font winPEFont = (Font) Toolkit.getDefaultToolkit().getDesktopProperty( "win.defaultGUI.font" );
if( winPEFont != null )
uiFont = createCompositeFont( winPEFont.getFamily(), winPEFont.getStyle(), winFont.getSize() );
} else
uiFont = createCompositeFont( winFont.getFamily(), winFont.getStyle(), winFont.getSize() );
}
} else if( SystemInfo.isMacOS ) {
String fontName;
@@ -499,7 +557,7 @@ public abstract class FlatLaf
// use active value for all fonts to allow changing fonts in all components
// (similar as in Nimbus L&F) with:
// UIManager.put( "defaultFont", myFont );
Object activeFont = new ActiveFont( 1 );
Object activeFont = new ActiveFont( 1 );
// override fonts
for( Object key : defaults.keySet() ) {
@@ -522,6 +580,13 @@ public abstract class FlatLaf
return (font instanceof FontUIResource) ? (FontUIResource) font : new FontUIResource( font );
}
/**
* @since 1.1
*/
public static ActiveValue createActiveFontValue( float scaleFactor ) {
return new ActiveFont( scaleFactor );
}
/**
* Adds the default color palette for action icons and object icons to the given UIDefaults.
* <p>
@@ -553,6 +618,8 @@ public abstract class FlatLaf
defaults.put( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON );
} else if( SystemInfo.isJava_9_orLater ) {
Object desktopHints = Toolkit.getDefaultToolkit().getDesktopProperty( DESKTOPFONTHINTS );
if( desktopHints == null )
desktopHints = fallbackAATextInfo();
if( desktopHints instanceof Map ) {
@SuppressWarnings( "unchecked" )
Map<Object, Object> hints = (Map<Object, Object>) desktopHints;
@@ -575,9 +642,52 @@ public abstract class FlatLaf
Object value = Class.forName( "sun.swing.SwingUtilities2$AATextInfo" )
.getMethod( "getAATextInfo", boolean.class )
.invoke( null, true );
if( value == null )
value = fallbackAATextInfo();
defaults.put( key, value );
} catch( Exception ex ) {
Logger.getLogger( FlatLaf.class.getName() ).log( Level.SEVERE, null, ex );
LoggingFacade.INSTANCE.logSevere( null, ex );
throw new RuntimeException( ex );
}
}
}
private Object fallbackAATextInfo() {
// do nothing if explicitly overridden
if( System.getProperty( "awt.useSystemAAFontSettings" ) != null )
return null;
Object aaHint = null;
Integer lcdContrastHint = null;
if( SystemInfo.isLinux ) {
// see sun.awt.UNIXToolkit.getDesktopAAHints()
Toolkit toolkit = Toolkit.getDefaultToolkit();
if( toolkit.getDesktopProperty( "gnome.Xft/Antialias" ) == null &&
toolkit.getDesktopProperty( "fontconfig/Antialias" ) == null )
{
// no Gnome or KDE Desktop properties available
// --> enable antialiasing
aaHint = RenderingHints.VALUE_TEXT_ANTIALIAS_ON;
}
}
if( aaHint == null )
return null;
if( SystemInfo.isJava_9_orLater ) {
Map<Object, Object> hints = new HashMap<>();
hints.put( RenderingHints.KEY_TEXT_ANTIALIASING, aaHint );
hints.put( RenderingHints.KEY_TEXT_LCD_CONTRAST, lcdContrastHint );
return hints;
} else {
// Java 8
try {
return Class.forName( "sun.swing.SwingUtilities2$AATextInfo" )
.getConstructor( Object.class, Integer.class )
.newInstance( aaHint, lcdContrastHint );
} catch( Exception ex ) {
LoggingFacade.INSTANCE.logSevere( null, ex );
throw new RuntimeException( ex );
}
}
@@ -684,7 +794,7 @@ public abstract class FlatLaf
// update UI
updateUI();
} catch( UnsupportedLookAndFeelException ex ) {
LOG.log( Level.SEVERE, "FlatLaf: Failed to reinitialize look and feel '" + lookAndFeel.getClass().getName() + "'.", ex );
LoggingFacade.INSTANCE.logSevere( "FlatLaf: Failed to reinitialize look and feel '" + lookAndFeel.getClass().getName() + "'.", ex );
}
} );
}
@@ -717,6 +827,79 @@ public abstract class FlatLaf
} );
}
/**
* Returns whether native window decorations are supported on current platform.
* <p>
* This requires Windows 10, but may be disabled if running in special environments
* (JetBrains Projector, Webswing or WinPE) or if loading native library fails.
* If system property {@link FlatSystemProperties#USE_WINDOW_DECORATIONS} is set to
* {@code false}, then this method also returns {@code false}.
*
* @since 1.1.2
*/
public static boolean supportsNativeWindowDecorations() {
return SystemInfo.isWindows_10_orLater && FlatNativeWindowBorder.isSupported();
}
/**
* Returns whether native window decorations are enabled.
*
* @since 1.1.2
*/
public static boolean isUseNativeWindowDecorations() {
return UIManager.getBoolean( "TitlePane.useWindowDecorations" );
}
/**
* Sets whether native window decorations are enabled.
* <p>
* Existing frames and dialogs will be updated.
*
* @since 1.1.2
*/
public static void setUseNativeWindowDecorations( boolean enabled ) {
UIManager.put( "TitlePane.useWindowDecorations", enabled );
if( !(UIManager.getLookAndFeel() instanceof FlatLaf) )
return;
// update existing frames and dialogs
for( Window w : Window.getWindows() ) {
if( isDisplayableFrameOrDialog( w ) )
FlatRootPaneUI.updateNativeWindowBorder( ((RootPaneContainer)w).getRootPane() );
}
}
/**
* Revalidate and repaint all displayable frames and dialogs.
*
* @since 1.1.2
*/
public static void revalidateAndRepaintAllFramesAndDialogs() {
for( Window w : Window.getWindows() ) {
if( isDisplayableFrameOrDialog( w ) ) {
w.revalidate();
w.repaint();
}
}
}
/**
* Repaint all displayable frames and dialogs.
*
* @since 1.1.2
*/
public static void repaintAllFramesAndDialogs() {
for( Window w : Window.getWindows() ) {
if( isDisplayableFrameOrDialog( w ) )
w.repaint();
}
}
private static boolean isDisplayableFrameOrDialog( Window w ) {
return w.isDisplayable() && (w instanceof JFrame || w instanceof JDialog);
}
public static boolean isShowMnemonics() {
return MnemonicHandler.isShowMnemonics();
}
@@ -741,6 +924,139 @@ public abstract class FlatLaf
return super.hashCode();
}
/**
* Registers a UI defaults getter function that is invoked before the standard getter.
* This allows using different UI defaults for special purposes
* (e.g. using multiple themes at the same time).
* <p>
* The key is passed as parameter to the function.
* If the function returns {@code null}, then the next registered function is invoked.
* If all registered functions return {@code null}, then the current look and feel is asked.
* If the function returns {@link #NULL_VALUE}, then the UI value becomes {@code null}.
*
* @see #unregisterUIDefaultsGetter(Function)
* @see #runWithUIDefaultsGetter(Function, Runnable)
* @since 1.6
*/
public void registerUIDefaultsGetter( Function<Object, Object> uiDefaultsGetter ) {
if( uiDefaultsGetters == null )
uiDefaultsGetters = new ArrayList<>();
uiDefaultsGetters.remove( uiDefaultsGetter );
uiDefaultsGetters.add( uiDefaultsGetter );
// disable shared UIs
FlatUIUtils.setUseSharedUIs( false );
}
/**
* Unregisters a UI defaults getter function that was invoked before the standard getter.
*
* @see #registerUIDefaultsGetter(Function)
* @see #runWithUIDefaultsGetter(Function, Runnable)
* @since 1.6
*/
public void unregisterUIDefaultsGetter( Function<Object, Object> uiDefaultsGetter ) {
if( uiDefaultsGetters == null )
return;
uiDefaultsGetters.remove( uiDefaultsGetter );
// enable shared UIs
if( uiDefaultsGetters.isEmpty() )
FlatUIUtils.setUseSharedUIs( true );
}
/**
* Registers a UI defaults getter function that is invoked before the standard getter,
* runs the given runnable and unregisters the UI defaults getter function again.
* This allows using different UI defaults for special purposes
* (e.g. using multiple themes at the same time).
* If the current look and feel is not FlatLaf, then the getter is ignored and
* the given runnable invoked.
* <p>
* The key is passed as parameter to the function.
* If the function returns {@code null}, then the next registered function is invoked.
* If all registered functions return {@code null}, then the current look and feel is asked.
* If the function returns {@link #NULL_VALUE}, then the UI value becomes {@code null}.
* <p>
* Example:
* <pre>{@code
* // create secondary theme
* UIDefaults darkDefaults = new FlatDarkLaf().getDefaults();
*
* // create panel using secondary theme
* FlatLaf.runWithUIDefaultsGetter( key -> {
* Object value = darkDefaults.get( key );
* return (value != null) ? value : FlatLaf.NULL_VALUE;
* }, () -> {
* // TODO create components that should use secondary theme here
* } );
* }</pre>
*
* @see #registerUIDefaultsGetter(Function)
* @see #unregisterUIDefaultsGetter(Function)
* @since 1.6
*/
public static void runWithUIDefaultsGetter( Function<Object, Object> uiDefaultsGetter, Runnable runnable ) {
LookAndFeel laf = UIManager.getLookAndFeel();
if( laf instanceof FlatLaf ) {
((FlatLaf)laf).registerUIDefaultsGetter( uiDefaultsGetter );
try {
runnable.run();
} finally {
((FlatLaf)laf).unregisterUIDefaultsGetter( uiDefaultsGetter );
}
} else
runnable.run();
}
/**
* Special value returned by functions used in {@link #runWithUIDefaultsGetter(Function, Runnable)}
* or {@link #registerUIDefaultsGetter(Function)} to indicate that the UI value should
* become {@code null}.
*
* @see #runWithUIDefaultsGetter(Function, Runnable)
* @see #registerUIDefaultsGetter(Function)
* @since 1.6
*/
public static final Object NULL_VALUE = new Object();
//---- class FlatUIDefaults -----------------------------------------------
private class FlatUIDefaults
extends UIDefaults
{
FlatUIDefaults( int initialCapacity, float loadFactor ) {
super( initialCapacity, loadFactor );
}
@Override
public Object get( Object key ) {
Object value = getValue( key );
return (value != null) ? (value != NULL_VALUE ? value : null) : super.get( key );
}
@Override
public Object get( Object key, Locale l ) {
Object value = getValue( key );
return (value != null) ? (value != NULL_VALUE ? value : null) : super.get( key, l );
}
private Object getValue( Object key ) {
if( uiDefaultsGetters == null )
return null;
for( int i = uiDefaultsGetters.size() - 1; i >= 0; i-- ) {
Object value = uiDefaultsGetters.get( i ).apply( key );
if( value != null )
return value;
}
return null;
}
}
//---- class ActiveFont ---------------------------------------------------
private static class ActiveFont
@@ -760,6 +1076,10 @@ public abstract class FlatLaf
public Object createValue( UIDefaults table ) {
Font defaultFont = UIManager.getFont( "defaultFont" );
// fallback (to avoid NPE in case that this is used in another Laf)
if( defaultFont == null )
defaultFont = UIManager.getFont( "Label.font" );
if( lastDefaultFont != defaultFont ) {
lastDefaultFont = defaultFont;

View File

@@ -34,8 +34,16 @@ public class FlatLightLaf
* Sets the application look and feel to this LaF
* using {@link UIManager#setLookAndFeel(javax.swing.LookAndFeel)}.
*/
public static boolean setup() {
return setup( new FlatLightLaf() );
}
/**
* @deprecated use {@link #setup()} instead; this method will be removed in a future version
*/
@Deprecated
public static boolean install() {
return install( new FlatLightLaf() );
return setup();
}
/**

View File

@@ -16,8 +16,7 @@
package com.formdev.flatlaf;
import javax.swing.JDialog;
import javax.swing.JFrame;
import com.formdev.flatlaf.util.UIScale;
/**
* Defines/documents own system properties used in FlatLaf.
@@ -35,6 +34,8 @@ public interface FlatSystemProperties
* To replace the Java 9+ system scale factor, use system property "sun.java2d.uiScale",
* which has the same syntax as this one.
* <p>
* Since FlatLaf 1.1.2: Scale factors less then 100% are allowed.
* <p>
* <strong>Allowed Values</strong> e.g. {@code 1.5}, {@code 1.5x}, {@code 150%} or {@code 144dpi} (96dpi is 100%)<br>
*/
String UI_SCALE = "flatlaf.uiScale";
@@ -47,6 +48,17 @@ public interface FlatSystemProperties
*/
String UI_SCALE_ENABLED = "flatlaf.uiScale.enabled";
/**
* Specifies whether values smaller than 100% are allowed for the user scale factor
* (see {@link UIScale#getUserScaleFactor()}).
* <p>
* <strong>Allowed Values</strong> {@code false} and {@code true}<br>
* <strong>Default</strong> {@code false}
*
* @since 1.1.2
*/
String UI_SCALE_ALLOW_SCALE_DOWN = "flatlaf.uiScale.allowScaleDown";
/**
* Specifies whether Ubuntu font should be used on Ubuntu Linux.
* By default, if not running in a JetBrains Runtime, the Liberation Sans font
@@ -58,11 +70,18 @@ public interface FlatSystemProperties
String USE_UBUNTU_FONT = "flatlaf.useUbuntuFont";
/**
* Specifies whether custom look and feel window decorations should be used
* Specifies whether native window decorations should be used
* when creating {@code JFrame} or {@code JDialog}.
* <p>
* If this system property is set, FlatLaf invokes {@link JFrame#setDefaultLookAndFeelDecorated(boolean)}
* and {@link JDialog#setDefaultLookAndFeelDecorated(boolean)} on LaF initialization.
* Setting this to {@code true} forces using native window decorations
* even if they are not enabled by the application.<br>
* Setting this to {@code false} disables using native window decorations.
* <p>
* This system property has higher priority than client property
* {@link FlatClientProperties#USE_WINDOW_DECORATIONS} and
* UI default {@code TitlePane.useWindowDecorations}.
* <p>
* (requires Window 10)
* <p>
* <strong>Allowed Values</strong> {@code false} and {@code true}<br>
* <strong>Default</strong> none
@@ -76,8 +95,10 @@ public interface FlatSystemProperties
* <a href="https://confluence.jetbrains.com/display/JBR/JetBrains+Runtime">JetBrains Runtime</a>
* (based on OpenJDK).
* <p>
* Setting this to {@code true} forces using JetBrains Runtime custom window decorations
* even if they are not enabled by the application.
* Setting this to {@code false} disables using JetBrains Runtime custom window decorations.
* Then FlatLaf native window decorations are used.
* <p>
* (requires Window 10)
* <p>
* <strong>Allowed Values</strong> {@code false} and {@code true}<br>
* <strong>Default</strong> {@code true}
@@ -85,10 +106,20 @@ public interface FlatSystemProperties
String USE_JETBRAINS_CUSTOM_DECORATIONS = "flatlaf.useJetBrainsCustomDecorations";
/**
* Specifies whether menubar is embedded into custom window decorations.
* Specifies whether the menu bar is embedded into the window title pane
* if window decorations are enabled.
* <p>
* Setting this to {@code true} forces embedding.<br>
* Setting this to {@code false} disables embedding.
* <p>
* This system property has higher priority than client property
* {@link FlatClientProperties#MENU_BAR_EMBEDDED} and
* UI default {@code TitlePane.menuBarEmbedded}.
* <p>
* (requires Window 10)
* <p>
* <strong>Allowed Values</strong> {@code false} and {@code true}<br>
* <strong>Default</strong> {@code true}
* <strong>Default</strong> none
*/
String MENUBAR_EMBEDDED = "flatlaf.menuBarEmbedded";

View File

@@ -30,11 +30,12 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import javax.swing.UIDefaults;
import javax.swing.plaf.ColorUIResource;
import com.formdev.flatlaf.json.Json;
import com.formdev.flatlaf.json.ParseException;
import com.formdev.flatlaf.util.ColorFunctions;
import com.formdev.flatlaf.util.LoggingFacade;
import com.formdev.flatlaf.util.StringUtils;
/**
@@ -67,20 +68,28 @@ public class IntelliJTheme
/**
* Loads a IntelliJ .theme.json file from the given input stream,
* creates a Laf instance for it and installs it.
* creates a Laf instance for it and sets it up.
*
* The input stream is automatically closed.
* Using a buffered input stream is not necessary.
*/
public static boolean install( InputStream in ) {
public static boolean setup( InputStream in ) {
try {
return FlatLaf.install( createLaf( in ) );
return FlatLaf.setup( createLaf( in ) );
} catch( Exception ex ) {
FlatLaf.LOG.log( Level.SEVERE, "FlatLaf: Failed to load IntelliJ theme", ex );
LoggingFacade.INSTANCE.logSevere( "FlatLaf: Failed to load IntelliJ theme", ex );
return false;
}
}
/**
* @deprecated use {@link #setup(InputStream)} instead; this method will be removed in a future version
*/
@Deprecated
public static boolean install( InputStream in ) {
return setup( in );
}
/**
* Loads a IntelliJ .theme.json file from the given input stream and
* creates a Laf instance for it.
@@ -215,6 +224,12 @@ public class IntelliJTheme
if( !uiKeys.contains( "ToggleButton.foreground" ) && uiKeys.contains( "Button.foreground" ) )
defaults.put( "ToggleButton.foreground", defaults.get( "Button.foreground" ) );
// fix DesktopPane background (use Panel.background and make it 5% darker/lighter)
Color desktopBackgroundBase = defaults.getColor( "Panel.background" );
Color desktopBackground = ColorFunctions.applyFunctions( desktopBackgroundBase,
new ColorFunctions.HSLIncreaseDecrease( 2, dark, 5, false, true ) );
defaults.put( "Desktop.background", new ColorUIResource( desktopBackground ) );
// fix List and Table background colors in Material UI Lite themes
if( isMaterialUILite ) {
defaults.put( "List.background", defaults.get( "Tree.background" ) );
@@ -241,9 +256,10 @@ public class IntelliJTheme
// remove theme specific UI defaults and remember only those for current theme
Map<Object, Object> themeSpecificDefaults = new HashMap<>();
String currentThemePrefix = '[' + name.replace( ' ', '_' ) + ']';
String currentThemeAndAuthorPrefix = '[' + name.replace( ' ', '_' ) + "---" + author.replace( ' ', '_' ) + ']';
String currentAuthorPrefix = "[author-" + author.replace( ' ', '_' ) + ']';
String allThemesPrefix = "[*]";
String[] prefixes = { currentThemePrefix, currentAuthorPrefix, allThemesPrefix };
String[] prefixes = { currentThemePrefix, currentThemeAndAuthorPrefix, currentAuthorPrefix, allThemesPrefix };
for( String key : themeSpecificKeys ) {
Object value = defaults.remove( key );
for( String prefix : prefixes ) {
@@ -324,7 +340,7 @@ public class IntelliJTheme
try {
uiValue = UIDefaultsLoader.parseValue( key, valueStr );
} catch( RuntimeException ex ) {
UIDefaultsLoader.logParseError( Level.CONFIG, key, valueStr, ex );
UIDefaultsLoader.logParseError( key, valueStr, ex, false );
return; // ignore invalid value
}
}
@@ -344,6 +360,10 @@ public class IntelliJTheme
// replace all values in UI defaults that match the wildcard key
for( Object k : defaultsKeysCache ) {
if( k.equals( "Desktop.background" ) ||
k.equals( "DesktopIcon.background" ) )
continue;
if( k instanceof String ) {
// support replacing of mapped keys
// (e.g. set ComboBox.buttonEditableBackground to *.background

View File

@@ -28,7 +28,8 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;
import java.util.logging.Level;
import com.formdev.flatlaf.util.LoggingFacade;
import com.formdev.flatlaf.util.StringUtils;
import com.formdev.flatlaf.util.SystemInfo;
import com.formdev.flatlaf.util.UIScale;
@@ -54,24 +55,38 @@ class LinuxFontPolicy
String family = "";
int style = Font.PLAIN;
int size = 10;
double dsize = 10;
// parse pango font description
// see https://developer.gnome.org/pango/1.46/pango-Fonts.html#pango-font-description-from-string
StringTokenizer st = new StringTokenizer( (String) fontName );
while( st.hasMoreTokens() ) {
String word = st.nextToken();
if( word.equalsIgnoreCase( "italic" ) )
// remove trailing ',' (e.g. in "Ubuntu Condensed, 11" or "Ubuntu Condensed, Bold 11")
if( word.endsWith( "," ) )
word = word.substring( 0, word.length() - 1 ).trim();
String lword = word.toLowerCase();
if( lword.equals( "italic" ) || lword.equals( "oblique" ) )
style |= Font.ITALIC;
else if( word.equalsIgnoreCase( "bold" ) )
else if( lword.equals( "bold" ) )
style |= Font.BOLD;
else if( Character.isDigit( word.charAt( 0 ) ) ) {
try {
size = Integer.parseInt( word );
dsize = Double.parseDouble( word );
} catch( NumberFormatException ex ) {
// ignore
}
} else
} else {
// remove '-' from "Semi-Bold", "Extra-Light", etc
if( lword.startsWith( "semi-" ) || lword.startsWith( "demi-" ) )
word = word.substring( 0, 4 ) + word.substring( 5 );
else if( lword.startsWith( "extra-" ) || lword.startsWith( "ultra-" ) )
word = word.substring( 0, 5 ) + word.substring( 6 );
family = family.isEmpty() ? word : (family + ' ' + word);
}
}
// Ubuntu font is rendered poorly (except if running in JetBrains VM)
@@ -82,8 +97,8 @@ class LinuxFontPolicy
family = "Liberation Sans";
// scale font size
double dsize = size * getGnomeFontScale();
size = (int) (dsize + 0.5);
dsize *= getGnomeFontScale();
int size = (int) (dsize + 0.5);
if( size < 1 )
size = 1;
@@ -92,7 +107,37 @@ class LinuxFontPolicy
if( logicalFamily != null )
family = logicalFamily;
return createFont( family, style, size, dsize );
return createFontEx( family, style, size, dsize );
}
/**
* Create a font for the given family, style and size.
* If the font family does not match any font on the system,
* then the last word (usually a font weight) from the family name is removed and tried again.
* E.g. family 'URW Bookman Light' is not found, but 'URW Bookman' is found.
* If still not found, then font of family 'Dialog' is returned.
*/
private static Font createFontEx( String family, int style, int size, double dsize ) {
for(;;) {
Font font = createFont( family, style, size, dsize );
// if the font family does not match any font on the system, "Dialog" family is returned
if( !"Dialog".equals( font.getFamily() ) || "Dialog".equals( family ) )
return font;
// find last word in family
int index = family.lastIndexOf( ' ' );
if( index < 0 )
return createFont( "Dialog", style, size, dsize );
// check whether last work contains some font weight (e.g. Ultra-Bold or Heavy)
String lastWord = family.substring( index + 1 ).toLowerCase();
if( lastWord.contains( "bold" ) || lastWord.contains( "heavy" ) || lastWord.contains( "black" ) )
style |= Font.BOLD;
// remove last word from family and try again
family = family.substring( 0, index );
}
}
private static Font createFont( String family, int style, int size, double dsize ) {
@@ -172,7 +217,7 @@ class LinuxFontPolicy
if( "1".equals( strs.get( 5 ) ) )
style |= Font.ITALIC;
} catch( RuntimeException ex ) {
FlatLaf.LOG.log( Level.CONFIG, "FlatLaf: Failed to parse 'font=" + generalFont + "'.", ex );
LoggingFacade.INSTANCE.logConfig( "FlatLaf: Failed to parse 'font=" + generalFont + "'.", ex );
}
}
@@ -186,7 +231,7 @@ class LinuxFontPolicy
if( dpi < 50 )
dpi = 50;
} catch( NumberFormatException ex ) {
FlatLaf.LOG.log( Level.CONFIG, "FlatLaf: Failed to parse 'forceFontDPI=" + forceFontDPI + "'.", ex );
LoggingFacade.INSTANCE.logConfig( "FlatLaf: Failed to parse 'forceFontDPI=" + forceFontDPI + "'.", ex );
}
}
@@ -225,7 +270,7 @@ class LinuxFontPolicy
while( (line = reader.readLine()) != null )
lines.add( line );
} catch( IOException ex ) {
FlatLaf.LOG.log( Level.CONFIG, "FlatLaf: Failed to read '" + filename + "'.", ex );
LoggingFacade.INSTANCE.logConfig( "FlatLaf: Failed to read '" + filename + "'.", ex );
}
return lines;
}
@@ -264,6 +309,9 @@ class LinuxFontPolicy
* - running on JetBrains Runtime 11 or later and scaling is enabled in system Settings
*/
private static boolean isSystemScaling() {
if( GraphicsEnvironment.isHeadless() )
return true;
GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment()
.getDefaultScreenDevice().getDefaultConfiguration();
return UIScale.getSystemScaleFactor( gc ) > 1;

View File

@@ -28,6 +28,7 @@ import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.lang.ref.WeakReference;
import javax.swing.AbstractButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
@@ -137,10 +138,17 @@ class MnemonicHandler
// get menu bar and first menu
Component c = e.getComponent();
JRootPane rootPane = SwingUtilities.getRootPane( c );
Window window = (rootPane != null) ? SwingUtilities.getWindowAncestor( rootPane ) : null;
JMenuBar menuBar = (rootPane != null) ? rootPane.getJMenuBar() : null;
if( menuBar == null && window instanceof JFrame )
menuBar = ((JFrame)window).getJMenuBar();
if( menuBar == null ) {
// get menu bar from frame/dialog because there
// may be multiple nested root panes in a frame/dialog
// (e.g. each internal frame has its own root pane)
Window window = SwingUtilities.getWindowAncestor( c );
if( window instanceof JFrame )
menuBar = ((JFrame)window).getJMenuBar();
else if( window instanceof JDialog )
menuBar = ((JDialog)window).getJMenuBar();
}
JMenu firstMenu = (menuBar != null) ? menuBar.getMenu( 0 ) : null;
// select first menu and show mnemonics

View File

@@ -33,7 +33,6 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.function.Function;
import java.util.logging.Level;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.UIDefaults.ActiveValue;
@@ -48,6 +47,7 @@ import com.formdev.flatlaf.util.ColorFunctions.ColorFunction;
import com.formdev.flatlaf.util.DerivedColor;
import com.formdev.flatlaf.util.GrayFilter;
import com.formdev.flatlaf.util.HSLColor;
import com.formdev.flatlaf.util.LoggingFacade;
import com.formdev.flatlaf.util.StringUtils;
import com.formdev.flatlaf.util.SystemInfo;
import com.formdev.flatlaf.util.UIScale;
@@ -72,6 +72,8 @@ class UIDefaultsLoader
private static final String OPTIONAL_PREFIX = "?";
private static final String WILDCARD_PREFIX = "*.";
private static int parseColorDepth;
static void loadDefaultsFromProperties( Class<?> lookAndFeelClass, List<FlatDefaultsAddon> addons,
Properties additionalDefaults, boolean dark, UIDefaults defaults )
{
@@ -119,7 +121,7 @@ class UIDefaultsLoader
addonClassLoaders.add( addonClassLoader );
}
// load custom properties files (usually provides by applications)
// load custom properties files (usually provided by applications)
List<Object> customDefaultsSources = FlatLaf.getCustomDefaultsSources();
int size = (customDefaultsSources != null) ? customDefaultsSources.size() : 0;
for( int i = 0; i < size; i++ ) {
@@ -241,16 +243,20 @@ class UIDefaultsLoader
try {
defaults.put( key, parseValue( key, value, null, resolver, addonClassLoaders ) );
} catch( RuntimeException ex ) {
logParseError( Level.SEVERE, key, value, ex );
logParseError( key, value, ex, true );
}
}
} catch( IOException ex ) {
FlatLaf.LOG.log( Level.SEVERE, "FlatLaf: Failed to load properties files.", ex );
LoggingFacade.INSTANCE.logSevere( "FlatLaf: Failed to load properties files.", ex );
}
}
static void logParseError( Level level, String key, String value, RuntimeException ex ) {
FlatLaf.LOG.log( level, "FlatLaf: Failed to parse: '" + key + '=' + value + '\'', ex );
static void logParseError( String key, String value, RuntimeException ex, boolean severe ) {
String message = "FlatLaf: Failed to parse: '" + key + '=' + value + '\'';
if( severe )
LoggingFacade.INSTANCE.logSevere( message, ex );
else
LoggingFacade.INSTANCE.logConfig( message, ex );
}
static String resolveValue( String value, Function<String, String> propertiesGetter ) {
@@ -436,9 +442,9 @@ class UIDefaultsLoader
private static Object parseInstance( String value, List<ClassLoader> addonClassLoaders ) {
return (LazyValue) t -> {
try {
return findClass( value, addonClassLoaders ).newInstance();
} catch( InstantiationException | IllegalAccessException | ClassNotFoundException ex ) {
FlatLaf.LOG.log( Level.SEVERE, "FlatLaf: Failed to instantiate '" + value + "'.", ex );
return findClass( value, addonClassLoaders ).getDeclaredConstructor().newInstance();
} catch( Exception ex ) {
LoggingFacade.INSTANCE.logSevere( "FlatLaf: Failed to instantiate '" + value + "'.", ex );
return null;
}
};
@@ -449,7 +455,7 @@ class UIDefaultsLoader
try {
return findClass( value, addonClassLoaders );
} catch( ClassNotFoundException ex ) {
FlatLaf.LOG.log( Level.SEVERE, "FlatLaf: Failed to find class '" + value + "'.", ex );
LoggingFacade.INSTANCE.logSevere( "FlatLaf: Failed to find class '" + value + "'.", ex );
return null;
}
};
@@ -580,19 +586,34 @@ class UIDefaultsLoader
if( params.isEmpty() )
throw new IllegalArgumentException( "missing parameters in function '" + value + "'" );
switch( function ) {
case "rgb": return parseColorRgbOrRgba( false, params, resolver, reportError );
case "rgba": return parseColorRgbOrRgba( true, params, resolver, reportError );
case "hsl": return parseColorHslOrHsla( false, params );
case "hsla": return parseColorHslOrHsla( true, params );
case "lighten": return parseColorHSLIncreaseDecrease( 2, true, params, resolver, reportError );
case "darken": return parseColorHSLIncreaseDecrease( 2, false, params, resolver, reportError );
case "saturate": return parseColorHSLIncreaseDecrease( 1, true, params, resolver, reportError );
case "desaturate": return parseColorHSLIncreaseDecrease( 1, false, params, resolver, reportError );
case "fadein": return parseColorHSLIncreaseDecrease( 3, true, params, resolver, reportError );
case "fadeout": return parseColorHSLIncreaseDecrease( 3, false, params, resolver, reportError );
case "fade": return parseColorFade( params, resolver, reportError );
case "spin": return parseColorSpin( params, resolver, reportError );
if( parseColorDepth > 100 )
throw new IllegalArgumentException( "endless recursion in color function '" + value + "'" );
parseColorDepth++;
try {
switch( function ) {
case "rgb": return parseColorRgbOrRgba( false, params, resolver, reportError );
case "rgba": return parseColorRgbOrRgba( true, params, resolver, reportError );
case "hsl": return parseColorHslOrHsla( false, params );
case "hsla": return parseColorHslOrHsla( true, params );
case "lighten": return parseColorHSLIncreaseDecrease( 2, true, params, resolver, reportError );
case "darken": return parseColorHSLIncreaseDecrease( 2, false, params, resolver, reportError );
case "saturate": return parseColorHSLIncreaseDecrease( 1, true, params, resolver, reportError );
case "desaturate": return parseColorHSLIncreaseDecrease( 1, false, params, resolver, reportError );
case "fadein": return parseColorHSLIncreaseDecrease( 3, true, params, resolver, reportError );
case "fadeout": return parseColorHSLIncreaseDecrease( 3, false, params, resolver, reportError );
case "fade": return parseColorFade( params, resolver, reportError );
case "spin": return parseColorSpin( params, resolver, reportError );
case "changeHue": return parseColorChange( 0, params, resolver, reportError );
case "changeSaturation":return parseColorChange( 1, params, resolver, reportError );
case "changeLightness": return parseColorChange( 2, params, resolver, reportError );
case "changeAlpha": return parseColorChange( 3, params, resolver, reportError );
case "mix": return parseColorMix( null, params, resolver, reportError );
case "tint": return parseColorMix( "#fff", params, resolver, reportError );
case "shade": return parseColorMix( "#000", params, resolver, reportError );
}
} finally {
parseColorDepth--;
}
throw new IllegalArgumentException( "unknown color function '" + value + "'" );
@@ -739,6 +760,68 @@ class UIDefaultsLoader
return parseFunctionBaseColor( colorStr, function, derived, resolver, reportError );
}
/**
* Syntax: changeHue(color,value[,options]) or
* changeSaturation(color,value[,options]) or
* changeLightness(color,value[,options]) or
* changeAlpha(color,value[,options])
* - color: a color (e.g. #f00) or a color function
* - value: for hue: number of degrees; otherwise: percentage 0-100%
* - options: [derived]
*/
private static Object parseColorChange( int hslIndex,
List<String> params, Function<String, String> resolver, boolean reportError )
{
String colorStr = params.get( 0 );
int value = (hslIndex == 0)
? parseInteger( params.get( 1 ), true )
: parsePercentage( params.get( 1 ) );
boolean derived = false;
if( params.size() > 2 ) {
String options = params.get( 2 );
derived = options.contains( "derived" );
}
// create function
ColorFunction function = new ColorFunctions.HSLChange( hslIndex, value );
// parse base color, apply function and create derived color
return parseFunctionBaseColor( colorStr, function, derived, resolver, reportError );
}
/**
* Syntax: mix(color1,color2[,weight]) or
* tint(color[,weight]) or
* shade(color[,weight])
* - color1: a color (e.g. #f00) or a color function
* - color2: a color (e.g. #f00) or a color function
* - weight: the weight (in range 0-100%) to mix the two colors
* larger weight uses more of first color, smaller weight more of second color
*/
private static Object parseColorMix( String color1Str, List<String> params, Function<String, String> resolver, boolean reportError ) {
int i = 0;
if( color1Str == null )
color1Str = params.get( i++ );
String color2Str = params.get( i++ );
int weight = 50;
if( params.size() > i )
weight = parsePercentage( params.get( i++ ) );
// parse second color
String resolvedColor2Str = resolver.apply( color2Str );
ColorUIResource color2 = (ColorUIResource) parseColorOrFunction( resolvedColor2Str, resolver, reportError );
if( color2 == null )
return null;
// create function
ColorFunction function = new ColorFunctions.Mix( color2, weight );
// parse first color, apply function and create mixed color
return parseFunctionBaseColor( color1Str, function, false, resolver, reportError );
}
private static Object parseFunctionBaseColor( String colorStr, ColorFunction function,
boolean derived, Function<String, String> resolver, boolean reportError )
{
@@ -918,7 +1001,7 @@ class UIDefaultsLoader
Object value = UIManager.get( uiKey );
if( value == null && !optional )
FlatLaf.LOG.log( Level.SEVERE, "FlatLaf: '" + uiKey + "' not found in UI defaults." );
LoggingFacade.INSTANCE.logSevere( "FlatLaf: '" + uiKey + "' not found in UI defaults.", null );
return value;
}
}

View File

@@ -44,7 +44,7 @@ public class FlatCapsLockIcon
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
<g fill="none" fill-rule="evenodd">
<rect width="16" height="16" fill="#6E6E6E" rx="3"/>
<rect width="6" height="2" x="5" y="12" fill="#FFF"/>
<rect width="6" height="2" x="5" y="11.5" fill="#FFF"/>
<path fill="#FFF" d="M2,8 L8,2 L14,8 L11,8 L11,10 L5,10 L5,8 L2,8 Z"/>
</g>
</svg>
@@ -52,7 +52,7 @@ public class FlatCapsLockIcon
Path2D path = new Path2D.Float( Path2D.WIND_EVEN_ODD );
path.append( new RoundRectangle2D.Float( 0, 0, 16, 16, 6, 6 ), false );
path.append( new Rectangle2D.Float( 5, 12, 6, 2 ), false );
path.append( new Rectangle2D.Float( 5, 11.5f, 6, 2 ), false );
path.append( FlatUIUtils.createPath( 2,8, 8,2, 14,8, 11,8, 11,10, 5,10, 5,8 ), false );
g.fill( path );
}

View File

@@ -146,8 +146,14 @@ public class FlatCheckBoxIcon
paintBorder( c, g );
// paint background
g.setColor( FlatUIUtils.deriveColor( getBackground( c, selected ),
selected ? selectedBackground : background ) );
Color bg = FlatUIUtils.deriveColor( getBackground( c, selected ),
selected ? selectedBackground : background );
if( bg.getAlpha() < 255 ) {
// fill background with default color before filling with non-opaque background
g.setColor( selected ? selectedBackground : background );
paintBackground( c, g );
}
g.setColor( bg );
paintBackground( c, g );
// paint checkmark

View File

@@ -0,0 +1,85 @@
/*
* Copyright 2021 FormDev Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.formdev.flatlaf.icons;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics2D;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Line2D;
import java.awt.geom.Path2D;
import javax.swing.AbstractButton;
import javax.swing.ButtonModel;
import javax.swing.UIManager;
import com.formdev.flatlaf.ui.FlatUIUtils;
/**
* "clear" icon for search fields.
*
* @uiDefault SearchField.clearIconColor Color
* @uiDefault SearchField.clearIconHoverColor Color
* @uiDefault SearchField.clearIconPressedColor Color
*
* @author Karl Tauber
* @since 1.5
*/
public class FlatClearIcon
extends FlatAbstractIcon
{
protected Color clearIconColor = UIManager.getColor( "SearchField.clearIconColor" );
protected Color clearIconHoverColor = UIManager.getColor( "SearchField.clearIconHoverColor" );
protected Color clearIconPressedColor = UIManager.getColor( "SearchField.clearIconPressedColor" );
public FlatClearIcon() {
super( 16, 16, null );
}
@Override
protected void paintIcon( Component c, Graphics2D g ) {
if( c instanceof AbstractButton ) {
ButtonModel model = ((AbstractButton)c).getModel();
if( model.isPressed() || model.isRollover() ) {
/*
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
<path fill="#7F8B91" fill-opacity=".5" fill-rule="evenodd" d="M8,1.75 C11.4517797,1.75 14.25,4.54822031 14.25,8 C14.25,11.4517797 11.4517797,14.25 8,14.25 C4.54822031,14.25 1.75,11.4517797 1.75,8 C1.75,4.54822031 4.54822031,1.75 8,1.75 Z M10.5,4.5 L8,7 L5.5,4.5 L4.5,5.5 L7,8 L4.5,10.5 L5.5,11.5 L8,9 L10.5,11.5 L11.5,10.5 L9,8 L11.5,5.5 L10.5,4.5 Z"/>
</svg>
*/
// paint filled circle with cross
g.setColor( model.isPressed() ? clearIconPressedColor : clearIconHoverColor );
Path2D path = new Path2D.Float( Path2D.WIND_EVEN_ODD );
path.append( new Ellipse2D.Float( 1.75f, 1.75f, 12.5f, 12.5f ), false );
path.append( FlatUIUtils.createPath( 4.5,5.5, 5.5,4.5, 8,7, 10.5,4.5, 11.5,5.5, 9,8, 11.5,10.5, 10.5,11.5, 8,9, 5.5,11.5, 4.5,10.5, 7,8 ), false );
g.fill( path );
return;
}
}
/*
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
<path fill="none" stroke="#7F8B91" stroke-linecap="square" stroke-opacity=".5" d="M5,5 L11,11 M5,11 L11,5"/>
</svg>
*/
// paint cross
g.setColor( clearIconColor );
Path2D path = new Path2D.Float( Path2D.WIND_EVEN_ODD );
path.append( new Line2D.Float( 5,5, 11,11 ), false );
path.append( new Line2D.Float( 5,11, 11,5 ), false );
g.draw( path );
}
}

View File

@@ -31,6 +31,8 @@ import com.formdev.flatlaf.ui.FlatUIUtils;
*
* @uiDefault Component.focusWidth int
* @uiDefault Component.focusColor Color
* @uiDefault HelpButton.innerFocusWidth int or float optional; defaults to Component.innerFocusWidth
* @uiDefault HelpButton.borderWidth int optional; default is 1
* @uiDefault HelpButton.borderColor Color
* @uiDefault HelpButton.disabledBorderColor Color
* @uiDefault HelpButton.focusedBorderColor Color
@@ -50,6 +52,8 @@ public class FlatHelpButtonIcon
{
protected final int focusWidth = UIManager.getInt( "Component.focusWidth" );
protected final Color focusColor = UIManager.getColor( "Component.focusColor" );
protected final float innerFocusWidth = FlatUIUtils.getUIFloat( "HelpButton.innerFocusWidth", FlatUIUtils.getUIFloat( "Component.innerFocusWidth", 0 ) );
protected final int borderWidth = FlatUIUtils.getUIInt( "HelpButton.borderWidth", 1 );
protected final Color borderColor = UIManager.getColor( "HelpButton.borderColor" );
protected final Color disabledBorderColor = UIManager.getColor( "HelpButton.disabledBorderColor" );
@@ -84,12 +88,18 @@ public class FlatHelpButtonIcon
boolean enabled = c.isEnabled();
boolean focused = FlatUIUtils.isPermanentFocusOwner( c );
// paint focused border
float xy = 0.5f;
float wh = iconSize - 1;
// paint outer focus border
if( focused && FlatButtonUI.isFocusPainted( c ) ) {
g2.setColor( focusColor );
g2.fill( new Ellipse2D.Float( 0.5f, 0.5f, iconSize - 1, iconSize - 1 ) );
g2.fill( new Ellipse2D.Float( xy, xy, wh, wh ) );
}
xy += focusWidth;
wh -= (focusWidth * 2);
// paint border
g2.setColor( FlatButtonUI.buttonStateColor( c,
borderColor,
@@ -97,7 +107,19 @@ public class FlatHelpButtonIcon
focusedBorderColor,
hoverBorderColor,
null ) );
g2.fill( new Ellipse2D.Float( focusWidth + 0.5f, focusWidth + 0.5f, 21, 21 ) );
g2.fill( new Ellipse2D.Float( xy, xy, wh, wh ) );
xy += borderWidth;
wh -= (borderWidth * 2);
// paint inner focus border
if( innerFocusWidth > 0 && focused && FlatButtonUI.isFocusPainted( c ) ) {
g2.setColor( focusColor );
g2.fill( new Ellipse2D.Float( xy, xy, wh, wh ) );
xy += innerFocusWidth;
wh -= (innerFocusWidth * 2);
}
// paint background
g2.setColor( FlatUIUtils.deriveColor( FlatButtonUI.buttonStateColor( c,
@@ -106,7 +128,7 @@ public class FlatHelpButtonIcon
focusedBackground,
hoverBackground,
pressedBackground ), background ) );
g2.fill( new Ellipse2D.Float( focusWidth + 1.5f, focusWidth + 1.5f, 19, 19 ) );
g2.fill( new Ellipse2D.Float( xy, xy, wh, wh ) );
// paint question mark
Path2D q = new Path2D.Float();

View File

@@ -0,0 +1,69 @@
/*
* Copyright 2021 FormDev Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.formdev.flatlaf.icons;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics2D;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import javax.swing.UIManager;
import com.formdev.flatlaf.ui.FlatButtonUI;
import com.formdev.flatlaf.ui.FlatUIUtils;
/**
* "search" icon for search fields.
*
* @uiDefault SearchField.searchIconColor Color
* @uiDefault SearchField.searchIconHoverColor Color
* @uiDefault SearchField.searchIconPressedColor Color
*
* @author Karl Tauber
* @since 1.5
*/
public class FlatSearchIcon
extends FlatAbstractIcon
{
protected Color searchIconColor = UIManager.getColor( "SearchField.searchIconColor" );
protected Color searchIconHoverColor = UIManager.getColor( "SearchField.searchIconHoverColor" );
protected Color searchIconPressedColor = UIManager.getColor( "SearchField.searchIconPressedColor" );
public FlatSearchIcon() {
super( 16, 16, null );
}
@Override
protected void paintIcon( Component c, Graphics2D g ) {
/*
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
<g fill="none" fill-opacity=".9" fill-rule="evenodd">
<polygon fill="#7F8B91" points="10.813 9.75 14 12.938 12.938 14 9.75 10.813"/>
<path fill="#7F8B91" d="M7,2 C9.76142375,2 12,4.23857625 12,7 C12,9.76142375 9.76142375,12 7,12 C4.23857625,12 2,9.76142375 2,7 C2,4.23857625 4.23857625,2 7,2 Z M7,3 C4.790861,3 3,4.790861 3,7 C3,9.209139 4.790861,11 7,11 C9.209139,11 11,9.209139 11,7 C11,4.790861 9.209139,3 7,3 Z"/>
</g>
</svg>
*/
g.setColor( FlatButtonUI.buttonStateColor( c, searchIconColor, searchIconColor,
null, searchIconHoverColor, searchIconPressedColor ) );
// paint magnifier
Area area = new Area( new Ellipse2D.Float( 2, 2, 10, 10 ) );
area.subtract( new Area( new Ellipse2D.Float( 3, 3, 8, 8 ) ) );
area.add( new Area( FlatUIUtils.createPath( 10.813,9.75, 14,12.938, 12.938,14, 9.75,10.813 ) ) );
g.fill( area );
}
}

View File

@@ -0,0 +1,55 @@
/*
* Copyright 2021 FormDev Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.formdev.flatlaf.icons;
import java.awt.Component;
import java.awt.Graphics2D;
import com.formdev.flatlaf.ui.FlatUIUtils;
/**
* "search with history" icon for search fields.
*
* @author Karl Tauber
* @since 1.5
*/
public class FlatSearchWithHistoryIcon
extends FlatSearchIcon
{
public FlatSearchWithHistoryIcon() {
}
@Override
protected void paintIcon( Component c, Graphics2D g ) {
/*
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
<g fill="none" fill-opacity=".9" fill-rule="evenodd">
<polygon fill="#7F8B91" points="8.813 9.75 12 12.938 10.938 14 7.75 10.813"/>
<path fill="#7F8B91" d="M5,2 C7.76142375,2 10,4.23857625 10,7 C10,9.76142375 7.76142375,12 5,12 C2.23857625,12 0,9.76142375 0,7 C0,4.23857625 2.23857625,2 5,2 Z M5,3 C2.790861,3 1,4.790861 1,7 C1,9.209139 2.790861,11 5,11 C7.209139,11 9,9.209139 9,7 C9,4.790861 7.209139,3 5,3 Z"/>
<polygon fill="#7F8B91" points="11 7 16 7 13.5 10"/>
</g>
</svg>
*/
// paint magnifier
g.translate( -2, 0 );
super.paintIcon( c, g );
g.translate( 2, 0 );
// paint history arrow
g.fill( FlatUIUtils.createPath( 11,7, 16,7, 13.5,10 ) );
}
}

View File

@@ -0,0 +1,28 @@
/*
* Copyright 2021 FormDev Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.formdev.flatlaf.resources;
/**
* The only purpose of this file is to add a .class file to this package to make it non-empty.
* Otherwise the compiler outputs a warning because this package is opend in module-info.java.
* Also when using --patch-module (e.g. from an IDE), an error would occur for empty packages.
*
* @author Karl Tauber
*/
interface EmptyPackage
{
}

View File

@@ -17,16 +17,13 @@
package com.formdev.flatlaf.ui;
import static com.formdev.flatlaf.util.UIScale.scale;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.geom.Path2D;
import javax.swing.JComponent;
import javax.swing.plaf.UIResource;
import javax.swing.plaf.basic.BasicArrowButton;
@@ -51,8 +48,8 @@ public class FlatArrowButton
protected final Color pressedBackground;
private int arrowWidth = DEFAULT_ARROW_WIDTH;
private int xOffset = 0;
private int yOffset = 0;
private float xOffset = 0;
private float yOffset = 0;
private boolean hover;
private boolean pressed;
@@ -120,19 +117,19 @@ public class FlatArrowButton
return pressed;
}
public int getXOffset() {
public float getXOffset() {
return xOffset;
}
public void setXOffset( int xOffset ) {
public void setXOffset( float xOffset ) {
this.xOffset = xOffset;
}
public int getYOffset() {
public float getYOffset() {
return yOffset;
}
public void setYOffset( int yOffset ) {
public void setYOffset( float yOffset ) {
this.yOffset = yOffset;
}
@@ -144,6 +141,21 @@ public class FlatArrowButton
return FlatUIUtils.deriveColor( foreground, this.foreground );
}
/**
* Returns the color used to paint the arrow.
*
* @since 1.2
*/
protected Color getArrowColor() {
return isEnabled()
? (pressedForeground != null && isPressed()
? pressedForeground
: (hoverForeground != null && isHover()
? hoverForeground
: foreground))
: disabledForeground;
}
@Override
public Dimension getPreferredSize() {
return scale( super.getPreferredSize() );
@@ -173,13 +185,7 @@ public class FlatArrowButton
}
// paint arrow
g.setColor( deriveForeground( isEnabled()
? (pressedForeground != null && isPressed()
? pressedForeground
: (hoverForeground != null && isHover()
? hoverForeground
: foreground))
: disabledForeground ) );
g.setColor( deriveForeground( getArrowColor() ) );
paintArrow( (Graphics2D) g );
FlatUIUtils.resetRenderingHints( g, oldRenderingHints );
@@ -190,73 +196,14 @@ public class FlatArrowButton
}
protected void paintArrow( Graphics2D g ) {
int direction = getDirection();
boolean vert = (direction == NORTH || direction == SOUTH);
// compute width/height
int w = scale( arrowWidth + (chevron ? 0 : 1) );
int h = scale( (arrowWidth / 2) + (chevron ? 0 : 1) );
// rotate width/height
int rw = vert ? w : h;
int rh = vert ? h : w;
// chevron lines end 1px outside of width/height
if( chevron ) {
// add 1px to width/height for position calculation only
rw++;
rh++;
}
int x = Math.round( (getWidth() - rw) / 2f + scale( (float) xOffset ) );
int y = Math.round( (getHeight() - rh) / 2f + scale( (float) yOffset ) );
int x = 0;
// move arrow for round borders
Container parent = getParent();
if( vert && parent instanceof JComponent && FlatUIUtils.hasRoundBorder( (JComponent) parent ) )
x -= scale( parent.getComponentOrientation().isLeftToRight() ? 1 : -1 );
// paint arrow
g.translate( x, y );
/*debug
debugPaint( g, vert, rw, rh );
debug*/
Shape arrowShape = createArrowShape( direction, chevron, w, h );
if( chevron ) {
g.setStroke( new BasicStroke( scale( 1f ) ) );
g.draw( arrowShape );
} else {
// triangle
g.fill( arrowShape );
}
g.translate( -x, -y );
FlatUIUtils.paintArrow( g, x, 0, getWidth(), getHeight(), getDirection(), chevron, arrowWidth, xOffset, yOffset );
}
public static Shape createArrowShape( int direction, boolean chevron, float w, float h ) {
switch( direction ) {
case NORTH: return FlatUIUtils.createPath( !chevron, 0,h, (w / 2f),0, w,h );
case SOUTH: return FlatUIUtils.createPath( !chevron, 0,0, (w / 2f),h, w,0 );
case WEST: return FlatUIUtils.createPath( !chevron, h,0, 0,(w / 2f), h,w );
case EAST: return FlatUIUtils.createPath( !chevron, 0,0, h,(w / 2f), 0,w );
default: return new Path2D.Float();
}
}
/*debug
private void debugPaint( Graphics g, boolean vert, int w, int h ) {
Color oldColor = g.getColor();
g.setColor( Color.red );
g.drawRect( 0, 0, w - 1, h - 1 );
int xy1 = -2;
int xy2 = h + 1;
for( int i = 0; i < 20; i++ ) {
g.drawRect( vert ? 0 : xy1, vert ? xy1 : 0, 0, 0 );
g.drawRect( vert ? 0 : xy2, vert ? xy2 : 0, 0, 0 );
xy1 -= 2;
xy2 += 2;
}
g.setColor( oldColor );
}
debug*/
}

View File

@@ -22,20 +22,14 @@ import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.KeyboardFocusManager;
import java.awt.Paint;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JScrollPane;
import javax.swing.JSpinner;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.JViewport;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.plaf.basic.BasicBorders;
import javax.swing.text.JTextComponent;
import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.util.DerivedColor;
@@ -51,6 +45,7 @@ import com.formdev.flatlaf.util.DerivedColor;
*
* @uiDefault Component.focusWidth int
* @uiDefault Component.innerFocusWidth int or float
* @uiDefault Component.innerOutlineWidth int or float
* @uiDefault Component.focusColor Color
* @uiDefault Component.borderColor Color
* @uiDefault Component.disabledBorderColor Color
@@ -95,12 +90,14 @@ public class FlatBorder
// paint outer border
if( outlineColor != null || isFocused( c ) ) {
float innerWidth = !isCellEditor( c ) && !(c instanceof JScrollPane)
? (outlineColor != null ? innerOutlineWidth : innerFocusWidth)
? (outlineColor != null ? innerOutlineWidth : getInnerFocusWidth( c ))
: 0;
g2.setColor( (outlineColor != null) ? outlineColor : getFocusColor( c ) );
FlatUIUtils.paintComponentOuterBorder( g2, x, y, width, height,
focusWidth, borderWidth + scale( innerWidth ), arc );
if( focusWidth > 0 || innerWidth > 0 ) {
g2.setColor( (outlineColor != null) ? outlineColor : getFocusColor( c ) );
FlatUIUtils.paintComponentOuterBorder( g2, x, y, width, height,
focusWidth, borderWidth + scale( innerWidth ), arc );
}
}
// paint border
@@ -159,41 +156,17 @@ public class FlatBorder
return false;
}
return c.isEnabled() && (!(c instanceof JTextComponent) || ((JTextComponent)c).isEditable());
return c.isEnabled();
}
protected boolean isFocused( Component c ) {
if( c instanceof JScrollPane ) {
JViewport viewport = ((JScrollPane)c).getViewport();
Component view = (viewport != null) ? viewport.getView() : null;
if( view != null ) {
if( FlatUIUtils.isPermanentFocusOwner( view ) )
return true;
if( (view instanceof JTable && ((JTable)view).isEditing()) ||
(view instanceof JTree && ((JTree)view).isEditing()) )
{
Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
if( focusOwner != null )
return SwingUtilities.isDescendingFrom( focusOwner, view );
}
}
return false;
} else if( c instanceof JComboBox && ((JComboBox<?>)c).isEditable() ) {
Component editorComponent = ((JComboBox<?>)c).getEditor().getEditorComponent();
return (editorComponent != null) ? FlatUIUtils.isPermanentFocusOwner( editorComponent ) : false;
} else if( c instanceof JSpinner ) {
if( FlatUIUtils.isPermanentFocusOwner( c ) )
return true;
JComponent editor = ((JSpinner)c).getEditor();
if( editor instanceof JSpinner.DefaultEditor ) {
JTextField textField = ((JSpinner.DefaultEditor)editor).getTextField();
if( textField != null )
return FlatUIUtils.isPermanentFocusOwner( textField );
}
return false;
} else
if( c instanceof JScrollPane )
return FlatScrollPaneUI.isPermanentFocusOwner( (JScrollPane) c );
else if( c instanceof JComboBox )
return FlatComboBoxUI.isPermanentFocusOwner( (JComboBox<?>) c );
else if( c instanceof JSpinner )
return FlatSpinnerUI.isPermanentFocusOwner( (JSpinner) c );
else
return FlatUIUtils.isPermanentFocusOwner( c );
}
@@ -204,13 +177,14 @@ public class FlatBorder
@Override
public Insets getBorderInsets( Component c, Insets insets ) {
float focusWidth = scale( (float) getFocusWidth( c ) );
float ow = focusWidth + scale( (float) getLineWidth( c ) );
int ow = Math.round( focusWidth + scale( (float) getLineWidth( c ) ) );
insets = super.getBorderInsets( c, insets );
insets.top = Math.round( scale( (float) insets.top ) + ow );
insets.left = Math.round( scale( (float) insets.left ) + ow );
insets.bottom = Math.round( scale( (float) insets.bottom ) + ow );
insets.right = Math.round( scale( (float) insets.right ) + ow );
insets.top = scale( insets.top ) + ow;
insets.left = scale( insets.left ) + ow;
insets.bottom = scale( insets.bottom ) + ow;
insets.right = scale( insets.right ) + ow;
if( isCellEditor( c ) ) {
// remove top and bottom insets if used as cell editor
@@ -236,6 +210,13 @@ public class FlatBorder
return focusWidth;
}
/**
* Returns the (unscaled) thickness of the inner focus border.
*/
protected float getInnerFocusWidth( Component c ) {
return innerFocusWidth;
}
/**
* Returns the (unscaled) line thickness used to compute the border insets.
* This may be different to {@link #getBorderWidth}.

View File

@@ -20,6 +20,7 @@ import java.awt.Color;
import java.awt.Component;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.Paint;
import javax.swing.AbstractButton;
@@ -42,10 +43,13 @@ import com.formdev.flatlaf.util.UIScale;
* @uiDefault Button.default.hoverBorderColor Color optional
* @uiDefault Button.default.focusedBorderColor Color
* @uiDefault Button.default.focusColor Color
* @uiDefault Button.toolbar.focusColor Color optional; defaults to Component.focusColor
* @uiDefault Button.borderWidth int
* @uiDefault Button.default.borderWidth int
* @uiDefault Button.innerFocusWidth int or float optional; defaults to Component.innerFocusWidth
* @uiDefault Button.toolbar.margin Insets
* @uiDefault Button.toolbar.spacingInsets Insets
* @uiDefault Button.toolbar.focusWidth int or float optional; default is 1
* @uiDefault Button.arc int
*
* @author Karl Tauber
@@ -63,24 +67,60 @@ public class FlatButtonBorder
protected final Color defaultHoverBorderColor = UIManager.getColor( "Button.default.hoverBorderColor" );
protected final Color defaultFocusedBorderColor = UIManager.getColor( "Button.default.focusedBorderColor" );
protected final Color defaultFocusColor = UIManager.getColor( "Button.default.focusColor" );
/** @since 1.4 */
protected final Color toolbarFocusColor = UIManager.getColor( "Button.toolbar.focusColor" );
protected final int borderWidth = UIManager.getInt( "Button.borderWidth" );
protected final int defaultBorderWidth = UIManager.getInt( "Button.default.borderWidth" );
protected final float buttonInnerFocusWidth = FlatUIUtils.getUIFloat( "Button.innerFocusWidth", innerFocusWidth );
protected final Insets toolbarMargin = UIManager.getInsets( "Button.toolbar.margin" );
protected final Insets toolbarSpacingInsets = UIManager.getInsets( "Button.toolbar.spacingInsets" );
/** @since 1.4 */
protected final float toolbarFocusWidth = FlatUIUtils.getUIFloat( "Button.toolbar.focusWidth", 1.5f );
protected final int arc = UIManager.getInt( "Button.arc" );
@Override
public void paintBorder( Component c, Graphics g, int x, int y, int width, int height ) {
if( FlatButtonUI.isContentAreaFilled( c ) &&
!FlatButtonUI.isToolBarButton( c ) &&
(!FlatButtonUI.isBorderlessButton( c ) || FlatUIUtils.isPermanentFocusOwner( c )) &&
!FlatButtonUI.isHelpButton( c ) &&
!FlatToggleButtonUI.isTabButton( c ) )
super.paintBorder( c, g, x, y, width, height );
else if( FlatButtonUI.isToolBarButton( c ) && isFocused( c ) )
paintToolBarFocus( c, g, x, y, width, height );
}
/**
* @since 1.4
*/
protected void paintToolBarFocus( Component c, Graphics g, int x, int y, int width, int height ) {
Graphics2D g2 = (Graphics2D) g.create();
try {
FlatUIUtils.setRenderingHints( g2 );
float focusWidth = UIScale.scale( toolbarFocusWidth );
float arc = UIScale.scale( (float) getArc( c ) );
Color outlineColor = getOutlineColor( c );
Insets spacing = UIScale.scale( toolbarSpacingInsets );
x += spacing.left;
y += spacing.top;
width -= spacing.left + spacing.right;
height -= spacing.top + spacing.bottom;
g2.setColor( (outlineColor != null) ? outlineColor : getFocusColor( c ) );
// not using paintComponentOuterBorder() here because its round edges look too "thick"
FlatUIUtils.paintComponentBorder( g2, x, y, width, height, 0, focusWidth, arc );
} finally {
g2.dispose();
}
}
@Override
protected Color getFocusColor( Component c ) {
return FlatButtonUI.isDefaultButton( c ) ? defaultFocusColor : super.getFocusColor( c );
return (toolbarFocusColor != null && FlatButtonUI.isToolBarButton( c ))
? toolbarFocusColor
: (FlatButtonUI.isDefaultButton( c ) ? defaultFocusColor : super.getFocusColor( c ));
}
@Override
@@ -134,6 +174,11 @@ public class FlatButtonBorder
return FlatToggleButtonUI.isTabButton( c ) ? 0 : super.getFocusWidth( c );
}
@Override
protected float getInnerFocusWidth( Component c ) {
return buttonInnerFocusWidth;
}
@Override
protected int getBorderWidth( Component c ) {
return FlatButtonUI.isDefaultButton( c ) ? defaultBorderWidth : borderWidth;

View File

@@ -30,6 +30,7 @@ import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.geom.RoundRectangle2D;
import java.beans.PropertyChangeEvent;
import java.util.Objects;
import javax.swing.AbstractButton;
import javax.swing.ButtonModel;
import javax.swing.Icon;
@@ -129,6 +130,7 @@ public class FlatButtonUI
protected Color toolbarSelectedBackground;
private Icon helpButtonIcon;
private Insets defaultMargin;
private boolean defaults_initialized = false;
@@ -184,6 +186,7 @@ public class FlatButtonUI
toolbarSelectedBackground = UIManager.getColor( prefix + "toolbar.selectedBackground" );
helpButtonIcon = UIManager.getIcon( "HelpButton.icon" );
defaultMargin = UIManager.getInsets( prefix + "margin" );
defaults_initialized = true;
}
@@ -285,6 +288,10 @@ public class FlatButtonUI
(c instanceof AbstractButton && clientPropertyEquals( (AbstractButton) c, BUTTON_TYPE, BUTTON_TYPE_TOOLBAR_BUTTON ));
}
static boolean isBorderlessButton( Component c ) {
return c instanceof AbstractButton && clientPropertyEquals( (AbstractButton) c, BUTTON_TYPE, BUTTON_TYPE_BORDERLESS );
}
@Override
public void update( Graphics g, JComponent c ) {
// fill background if opaque to avoid garbage if user sets opaque to true
@@ -332,8 +339,9 @@ public class FlatButtonUI
// paint shadow
Color shadowColor = def ? defaultShadowColor : this.shadowColor;
if( !isToolBarButton && shadowColor != null && shadowWidth > 0 && focusWidth > 0 &&
!(isFocusPainted( c ) && FlatUIUtils.isPermanentFocusOwner( c )) && c.isEnabled() )
if( shadowColor != null && shadowWidth > 0 && focusWidth > 0 && c.isEnabled() &&
!isToolBarButton && !isBorderlessButton( c ) &&
!(isFocusPainted( c ) && FlatUIUtils.isPermanentFocusOwner( c )) )
{
g2.setColor( shadowColor );
g2.fill( new RoundRectangle2D.Float( focusWidth, focusWidth + UIScale.scale( (float) shadowWidth ),
@@ -388,41 +396,35 @@ public class FlatButtonUI
}
protected Color getBackground( JComponent c ) {
boolean toolBarButton = isToolBarButton( c ) || isBorderlessButton( c );
// selected state
if( ((AbstractButton)c).isSelected() ) {
// in toolbar use same colors for disabled and enabled because
// in toolbar use same background colors for disabled and enabled because
// we assume that toolbar icon is shown disabled
boolean toolBarButton = isToolBarButton( c );
return buttonStateColor( c,
toolBarButton ? toolbarSelectedBackground : selectedBackground,
toolBarButton ? toolbarSelectedBackground : disabledSelectedBackground,
null, null,
null,
null,
toolBarButton ? toolbarPressedBackground : pressedBackground );
}
if( !c.isEnabled() )
return disabledBackground;
// toolbar button
if( isToolBarButton( c ) ) {
ButtonModel model = ((AbstractButton)c).getModel();
if( model.isPressed() )
return toolbarPressedBackground;
if( model.isRollover() )
return toolbarHoverBackground;
// use component background if explicitly set
if( toolBarButton ) {
Color bg = c.getBackground();
if( isCustomBackground( bg ) )
return bg;
// do not paint background
return null;
return buttonStateColor( c,
isCustomBackground( bg ) ? bg : null,
null,
null,
toolbarHoverBackground,
toolbarPressedBackground );
}
boolean def = isDefaultButton( c );
return buttonStateColor( c,
getBackgroundBase( c, def ),
null,
disabledBackground,
isCustomBackground( c.getBackground() ) ? null : (def ? defaultFocusedBackground : focusedBackground),
def ? defaultHoverBackground : hoverBackground,
def ? defaultPressedBackground : pressedBackground );
@@ -444,16 +446,18 @@ public class FlatButtonUI
public static Color buttonStateColor( Component c, Color enabledColor, Color disabledColor,
Color focusedColor, Color hoverColor, Color pressedColor )
{
AbstractButton b = (c instanceof AbstractButton) ? (AbstractButton) c : null;
if( !c.isEnabled() )
return disabledColor;
if( pressedColor != null && b != null && b.getModel().isPressed() )
return pressedColor;
if( c instanceof AbstractButton ) {
ButtonModel model = ((AbstractButton)c).getModel();
if( hoverColor != null && b != null && b.getModel().isRollover() )
return hoverColor;
if( pressedColor != null && model.isPressed() )
return pressedColor;
if( hoverColor != null && model.isRollover() )
return hoverColor;
}
if( focusedColor != null && isFocusPainted( c ) && FlatUIUtils.isPermanentFocusOwner( c ) )
return focusedColor;
@@ -465,7 +469,7 @@ public class FlatButtonUI
if( !c.isEnabled() )
return disabledText;
if( ((AbstractButton)c).isSelected() && !isToolBarButton( c ) )
if( ((AbstractButton)c).isSelected() && !(isToolBarButton( c ) || isBorderlessButton( c )) )
return selectedForeground;
// use component foreground if explicitly set
@@ -498,16 +502,23 @@ public class FlatButtonUI
} else if( isIconOnlyOrSingleCharacter && ((AbstractButton)c).getIcon() == null ) {
// make single-character-no-icon button square (increase width)
prefSize.width = Math.max( prefSize.width, prefSize.height );
} else if( !isIconOnlyOrSingleCharacter && !isToolBarButton( c ) && c.getBorder() instanceof FlatButtonBorder ) {
} else if( !isIconOnlyOrSingleCharacter && !isToolBarButton( c ) &&
c.getBorder() instanceof FlatButtonBorder && hasDefaultMargins( c ) )
{
// apply minimum width/height
float focusWidth = FlatUIUtils.getBorderFocusWidth( c );
prefSize.width = Math.max( prefSize.width, scale( FlatUIUtils.minimumWidth( c, minimumWidth ) ) + Math.round( focusWidth * 2 ) );
prefSize.height = Math.max( prefSize.height, scale( FlatUIUtils.minimumHeight( c, 0 ) ) + Math.round( focusWidth * 2 ) );
int fw = Math.round( FlatUIUtils.getBorderFocusWidth( c ) * 2 );
prefSize.width = Math.max( prefSize.width, scale( FlatUIUtils.minimumWidth( c, minimumWidth ) ) + fw );
prefSize.height = Math.max( prefSize.height, scale( FlatUIUtils.minimumHeight( c, 0 ) ) + fw );
}
return prefSize;
}
private boolean hasDefaultMargins( JComponent c ) {
Insets margin = ((AbstractButton)c).getMargin();
return margin instanceof UIResource && Objects.equals( margin, defaultMargin );
}
//---- class FlatButtonListener -------------------------------------------
protected class FlatButtonListener

View File

@@ -18,10 +18,13 @@ package com.formdev.flatlaf.ui;
import static com.formdev.flatlaf.FlatClientProperties.*;
import java.awt.EventQueue;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.event.FocusEvent;
import java.awt.event.MouseEvent;
import javax.swing.JFormattedTextField;
import javax.swing.plaf.UIResource;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultCaret;
import javax.swing.text.Document;
import javax.swing.text.JTextComponent;
@@ -61,6 +64,19 @@ public class FlatCaret
}
}
@Override
protected void adjustVisibility( Rectangle nloc ) {
JTextComponent c = getComponent();
if( c != null && c.getUI() instanceof FlatTextFieldUI ) {
Insets padding = ((FlatTextFieldUI)c.getUI()).getPadding();
if( padding != null ) {
nloc.x -= padding.left;
nloc.y -= padding.top;
}
}
super.adjustVisibility( nloc );
}
@Override
public void focusGained( FocusEvent e ) {
if( !wasTemporaryLost && (!isMousePressed || selectAllOnMouseClick) )
@@ -127,4 +143,23 @@ public class FlatCaret
moveDot( doc.getLength() );
}
}
/**
* @since 1.4
*/
public void scrollCaretToVisible() {
JTextComponent c = getComponent();
if( c == null || c.getUI() == null )
return;
try {
Rectangle loc = c.getUI().modelToView( c, getDot(), getDotBias() );
if( loc != null ) {
adjustVisibility( loc );
damage( loc );
}
} catch( BadLocationException ex ) {
// ignore
}
}
}

View File

@@ -17,11 +17,13 @@
package com.formdev.flatlaf.ui;
import static com.formdev.flatlaf.util.UIScale.scale;
import static com.formdev.flatlaf.util.UIScale.unscale;
import java.awt.Color;
import java.awt.Component;
import java.awt.ComponentOrientation;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
@@ -38,12 +40,10 @@ import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.geom.Rectangle2D;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.lang.ref.WeakReference;
import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.ComboBoxEditor;
import javax.swing.CellRendererPane;
import javax.swing.DefaultListCellRenderer;
import javax.swing.InputMap;
import javax.swing.JButton;
@@ -61,13 +61,13 @@ import javax.swing.UIManager;
import javax.swing.border.AbstractBorder;
import javax.swing.border.Border;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.UIResource;
import javax.swing.plaf.basic.BasicComboBoxUI;
import javax.swing.plaf.basic.BasicComboPopup;
import javax.swing.plaf.basic.ComboPopup;
import javax.swing.text.JTextComponent;
import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.util.SystemInfo;
import com.formdev.flatlaf.util.UIScale;
/**
* Provides the Flat LaF UI delegate for {@link javax.swing.JComboBox}.
@@ -92,14 +92,17 @@ import com.formdev.flatlaf.util.UIScale;
* @uiDefault Component.borderColor Color
* @uiDefault Component.disabledBorderColor Color
* @uiDefault ComboBox.editableBackground Color optional; defaults to ComboBox.background
* @uiDefault ComboBox.focusedBackground Color optional
* @uiDefault ComboBox.disabledBackground Color
* @uiDefault ComboBox.disabledForeground Color
* @uiDefault ComboBox.buttonBackground Color
* @uiDefault ComboBox.buttonEditableBackground Color
* @uiDefault ComboBox.buttonFocusedBackground Color optional; defaults to ComboBox.focusedBackground
* @uiDefault ComboBox.buttonArrowColor Color
* @uiDefault ComboBox.buttonDisabledArrowColor Color
* @uiDefault ComboBox.buttonHoverArrowColor Color
* @uiDefault ComboBox.buttonPressedArrowColor Color
* @uiDefault ComboBox.popupBackground Color optional
*
* @author Karl Tauber
*/
@@ -115,21 +118,25 @@ public class FlatComboBoxUI
protected Color disabledBorderColor;
protected Color editableBackground;
protected Color focusedBackground;
protected Color disabledBackground;
protected Color disabledForeground;
protected Color buttonBackground;
protected Color buttonEditableBackground;
protected Color buttonFocusedBackground;
protected Color buttonArrowColor;
protected Color buttonDisabledArrowColor;
protected Color buttonHoverArrowColor;
protected Color buttonPressedArrowColor;
protected Color popupBackground;
private MouseListener hoverListener;
protected boolean hover;
protected boolean pressed;
private WeakReference<Component> lastRendererComponent;
private CellPaddingBorder paddingBorder;
public static ComponentUI createUI( JComponent c ) {
return new FlatComboBoxUI();
@@ -195,23 +202,26 @@ public class FlatComboBoxUI
disabledBorderColor = UIManager.getColor( "Component.disabledBorderColor" );
editableBackground = UIManager.getColor( "ComboBox.editableBackground" );
focusedBackground = UIManager.getColor( "ComboBox.focusedBackground" );
disabledBackground = UIManager.getColor( "ComboBox.disabledBackground" );
disabledForeground = UIManager.getColor( "ComboBox.disabledForeground" );
buttonBackground = UIManager.getColor( "ComboBox.buttonBackground" );
buttonFocusedBackground = UIManager.getColor( "ComboBox.buttonFocusedBackground" );
buttonEditableBackground = UIManager.getColor( "ComboBox.buttonEditableBackground" );
buttonArrowColor = UIManager.getColor( "ComboBox.buttonArrowColor" );
buttonDisabledArrowColor = UIManager.getColor( "ComboBox.buttonDisabledArrowColor" );
buttonHoverArrowColor = UIManager.getColor( "ComboBox.buttonHoverArrowColor" );
buttonPressedArrowColor = UIManager.getColor( "ComboBox.buttonPressedArrowColor" );
popupBackground = UIManager.getColor( "ComboBox.popupBackground" );
// set maximumRowCount
int maximumRowCount = UIManager.getInt( "ComboBox.maximumRowCount" );
if( maximumRowCount > 0 && maximumRowCount != 8 && comboBox.getMaximumRowCount() == 8 )
comboBox.setMaximumRowCount( maximumRowCount );
// scale
padding = UIScale.scale( padding );
paddingBorder = new CellPaddingBorder( padding );
MigLayoutVisualPadding.install( comboBox );
}
@@ -224,16 +234,22 @@ public class FlatComboBoxUI
disabledBorderColor = null;
editableBackground = null;
focusedBackground = null;
disabledBackground = null;
disabledForeground = null;
buttonBackground = null;
buttonEditableBackground = null;
buttonFocusedBackground = null;
buttonArrowColor = null;
buttonDisabledArrowColor = null;
buttonHoverArrowColor = null;
buttonPressedArrowColor = null;
popupBackground = null;
paddingBorder.uninstall();
MigLayoutVisualPadding.uninstall( comboBox );
}
@@ -244,9 +260,25 @@ public class FlatComboBoxUI
public void layoutContainer( Container parent ) {
super.layoutContainer( parent );
if ( editor != null && padding != null ) {
// fix editor bounds by subtracting padding
editor.setBounds( FlatUIUtils.subtractInsets( editor.getBounds(), padding ) );
if( arrowButton != null ) {
// limit button width to height of a raw combobox (without insets)
FontMetrics fm = comboBox.getFontMetrics( comboBox.getFont() );
int maxButtonWidth = fm.getHeight() + scale( padding.top ) + scale( padding.bottom );
Insets insets = getInsets();
int buttonWidth = Math.min( parent.getPreferredSize().height - insets.top - insets.bottom, maxButtonWidth );
if( buttonWidth != arrowButton.getWidth() ) {
// set width of arrow button to preferred height of combobox
int xOffset = comboBox.getComponentOrientation().isLeftToRight()
? arrowButton.getWidth() - buttonWidth
: 0;
arrowButton.setBounds( arrowButton.getX() + xOffset, arrowButton.getY(),
buttonWidth, arrowButton.getHeight() );
// update editor bounds
if( editor != null )
editor.setBounds( rectangleForCurrentValue() );
}
}
}
};
@@ -274,30 +306,28 @@ public class FlatComboBoxUI
@Override
protected PropertyChangeListener createPropertyChangeListener() {
return new BasicComboBoxUI.PropertyChangeHandler() {
@Override
public void propertyChange( PropertyChangeEvent e ) {
super.propertyChange( e );
PropertyChangeListener superListener = super.createPropertyChangeListener();
return e -> {
superListener.propertyChange( e );
Object source = e.getSource();
String propertyName = e.getPropertyName();
Object source = e.getSource();
String propertyName = e.getPropertyName();
if( editor != null &&
((source == comboBox && propertyName == "foreground") ||
(source == editor && propertyName == "enabled")) )
{
// fix editor component colors
updateEditorColors();
} else if( editor != null && source == comboBox && propertyName == "componentOrientation" ) {
ComponentOrientation o = (ComponentOrientation) e.getNewValue();
editor.applyComponentOrientation( o );
} else if( editor != null && FlatClientProperties.PLACEHOLDER_TEXT.equals( propertyName ) )
editor.repaint();
else if( FlatClientProperties.COMPONENT_ROUND_RECT.equals( propertyName ) )
comboBox.repaint();
else if( FlatClientProperties.MINIMUM_WIDTH.equals( propertyName ) )
comboBox.revalidate();
}
if( editor != null &&
((source == comboBox && propertyName == "foreground") ||
(source == editor && propertyName == "enabled")) )
{
// fix editor component colors
updateEditorColors();
} else if( editor != null && source == comboBox && propertyName == "componentOrientation" ) {
ComponentOrientation o = (ComponentOrientation) e.getNewValue();
editor.applyComponentOrientation( o );
} else if( editor != null && FlatClientProperties.PLACEHOLDER_TEXT.equals( propertyName ) )
editor.repaint();
else if( FlatClientProperties.COMPONENT_ROUND_RECT.equals( propertyName ) )
comboBox.repaint();
else if( FlatClientProperties.MINIMUM_WIDTH.equals( propertyName ) )
comboBox.revalidate();
};
}
@@ -307,39 +337,32 @@ public class FlatComboBoxUI
}
@Override
protected ComboBoxEditor createEditor() {
ComboBoxEditor comboBoxEditor = super.createEditor();
protected void configureEditor() {
super.configureEditor();
Component editor = comboBoxEditor.getEditorComponent();
if( editor instanceof JTextField ) {
JTextField textField = (JTextField) editor;
textField.setColumns( editorColumns );
// assign a non-null and non-javax.swing.plaf.UIResource border to the text field,
// otherwise it is replaced with default text field border when switching LaF
// because javax.swing.plaf.basic.BasicComboBoxEditor.BorderlessTextField.setBorder()
// uses "border instanceof javax.swing.plaf.basic.BasicComboBoxEditor.UIResource"
// instead of "border instanceof javax.swing.plaf.UIResource"
textField.setBorder( BorderFactory.createEmptyBorder() );
// remove default text field border from editor
Border border = textField.getBorder();
if( border == null || border instanceof UIResource ) {
// assign a non-null and non-javax.swing.plaf.UIResource border to the text field,
// otherwise it is replaced with default text field border when switching LaF
// because javax.swing.plaf.basic.BasicComboBoxEditor.BorderlessTextField.setBorder()
// uses "border instanceof javax.swing.plaf.basic.BasicComboBoxEditor.UIResource"
// instead of "border instanceof javax.swing.plaf.UIResource"
textField.setBorder( BorderFactory.createEmptyBorder() );
}
}
return comboBoxEditor;
}
@Override
protected void configureEditor() {
super.configureEditor();
// remove default text field border from editor
if( editor instanceof JTextField && ((JTextField)editor).getBorder() instanceof FlatTextBorder )
((JTextField)editor).setBorder( BorderFactory.createEmptyBorder() );
// explicitly make non-opaque
if( editor instanceof JComponent )
((JComponent)editor).setOpaque( false );
editor.applyComponentOrientation( comboBox.getComponentOrientation() );
updateEditorPadding();
updateEditorColors();
// macOS
@@ -356,6 +379,25 @@ public class FlatComboBoxUI
}
}
private void updateEditorPadding() {
if( !(editor instanceof JTextField) )
return;
JTextField textField = (JTextField) editor;
Insets insets = textField.getInsets();
Insets pad = padding;
if( insets.top != 0 || insets.left != 0 || insets.bottom != 0 || insets.right != 0 ) {
// if text field has custom border, subtract text field insets from padding
pad = new Insets(
unscale( Math.max( scale( padding.top ) - insets.top, 0 ) ),
unscale( Math.max( scale( padding.left ) - insets.left, 0 ) ),
unscale( Math.max( scale( padding.bottom ) - insets.bottom, 0 ) ),
unscale( Math.max( scale( padding.right ) - insets.right, 0 ) )
);
}
textField.putClientProperty( FlatClientProperties.TEXT_FIELD_PADDING, pad );
}
private void updateEditorColors() {
// use non-UIResource colors because when SwingUtilities.updateComponentTreeUI()
// is used, then the editor is updated after the combobox and the
@@ -376,6 +418,15 @@ public class FlatComboBoxUI
public void update( Graphics g, JComponent c ) {
float focusWidth = FlatUIUtils.getBorderFocusWidth( c );
float arc = FlatUIUtils.getBorderArc( c );
boolean paintBackground = true;
// check whether used as cell renderer
boolean isCellRenderer = c.getParent() instanceof CellRendererPane;
if( isCellRenderer ) {
focusWidth = 0;
arc = 0;
paintBackground = isCellRendererBackgroundChanged();
}
// fill background if opaque to avoid garbage if user sets opaque to true
if( c.isOpaque() && (focusWidth > 0 || arc > 0) )
@@ -393,27 +444,33 @@ public class FlatComboBoxUI
boolean isLeftToRight = comboBox.getComponentOrientation().isLeftToRight();
// paint background
g2.setColor( getBackground( enabled ) );
FlatUIUtils.paintComponentBackground( g2, 0, 0, width, height, focusWidth, arc );
// paint arrow button background
if( enabled ) {
g2.setColor( paintButton ? buttonEditableBackground : buttonBackground );
Shape oldClip = g2.getClip();
if( isLeftToRight )
g2.clipRect( arrowX, 0, width - arrowX, height );
else
g2.clipRect( 0, 0, arrowX + arrowWidth, height );
if( paintBackground || c.isOpaque() ) {
g2.setColor( getBackground( enabled ) );
FlatUIUtils.paintComponentBackground( g2, 0, 0, width, height, focusWidth, arc );
g2.setClip( oldClip );
}
// paint vertical line between value and arrow button
if( paintButton ) {
g2.setColor( enabled ? borderColor : disabledBorderColor );
float lw = scale( 1f );
float lx = isLeftToRight ? arrowX : arrowX + arrowWidth - lw;
g2.fill( new Rectangle2D.Float( lx, focusWidth, lw, height - 1 - (focusWidth * 2)) );
// paint arrow button background
if( enabled && !isCellRenderer ) {
g2.setColor( paintButton
? buttonEditableBackground
: (buttonFocusedBackground != null || focusedBackground != null) && isPermanentFocusOwner( comboBox )
? (buttonFocusedBackground != null ? buttonFocusedBackground : focusedBackground)
: buttonBackground );
Shape oldClip = g2.getClip();
if( isLeftToRight )
g2.clipRect( arrowX, 0, width - arrowX, height );
else
g2.clipRect( 0, 0, arrowX + arrowWidth, height );
FlatUIUtils.paintComponentBackground( g2, 0, 0, width, height, focusWidth, arc );
g2.setClip( oldClip );
}
// paint vertical line between value and arrow button
if( paintButton ) {
g2.setColor( enabled ? borderColor : disabledBorderColor );
float lw = scale( 1f );
float lx = isLeftToRight ? arrowX : arrowX + arrowWidth - lw;
g2.fill( new Rectangle2D.Float( lx, focusWidth, lw, height - 1 - (focusWidth * 2)) );
}
}
// avoid that the "current value" renderer is invoked with enabled antialiasing
@@ -425,30 +482,24 @@ public class FlatComboBoxUI
@Override
@SuppressWarnings( "unchecked" )
public void paintCurrentValue( Graphics g, Rectangle bounds, boolean hasFocus ) {
paddingBorder.uninstall();
ListCellRenderer<Object> renderer = comboBox.getRenderer();
uninstallCellPaddingBorder( renderer );
if( renderer == null )
renderer = new DefaultListCellRenderer();
Component c = renderer.getListCellRendererComponent( listBox, comboBox.getSelectedItem(), -1, false, false );
c.setFont( comboBox.getFont() );
c.applyComponentOrientation( comboBox.getComponentOrientation() );
uninstallCellPaddingBorder( c );
boolean enabled = comboBox.isEnabled();
c.setBackground( getBackground( enabled ) );
c.setForeground( getForeground( enabled ) );
boolean shouldValidate = (c instanceof JPanel);
if( padding != null )
bounds = FlatUIUtils.subtractInsets( bounds, padding );
// increase the size of the rendering area to make sure that the text
// is vertically aligned with other component types (e.g. JTextField)
Insets rendererInsets = getRendererComponentInsets( c );
if( rendererInsets != null )
bounds = FlatUIUtils.addInsets( bounds, rendererInsets );
paddingBorder.install( c );
currentValuePane.paintComponent( g, c, comboBox, bounds.x, bounds.y, bounds.width, bounds.height, shouldValidate );
paddingBorder.uninstall();
}
@Override
@@ -457,9 +508,20 @@ public class FlatComboBoxUI
}
protected Color getBackground( boolean enabled ) {
return enabled
? (editableBackground != null && comboBox.isEditable() ? editableBackground : comboBox.getBackground())
: (isIntelliJTheme ? FlatUIUtils.getParentBackground( comboBox ) : disabledBackground);
if( enabled ) {
Color background = comboBox.getBackground();
// always use explicitly set color
if( !(background instanceof UIResource) )
return background;
// focused
if( focusedBackground != null && isPermanentFocusOwner( comboBox ) )
return focusedBackground;
return (editableBackground != null && comboBox.isEditable()) ? editableBackground : background;
} else
return isIntelliJTheme ? FlatUIUtils.getParentBackground( comboBox ) : disabledBackground;
}
protected Color getForeground( boolean enabled ) {
@@ -469,75 +531,68 @@ public class FlatComboBoxUI
@Override
public Dimension getMinimumSize( JComponent c ) {
Dimension minimumSize = super.getMinimumSize( c );
minimumSize.width = Math.max( minimumSize.width, scale( FlatUIUtils.minimumWidth( c, minimumWidth ) ) );
int fw = Math.round( FlatUIUtils.getBorderFocusWidth( c ) * 2 );
minimumSize.width = Math.max( minimumSize.width, scale( FlatUIUtils.minimumWidth( c, minimumWidth ) ) + fw );
return minimumSize;
}
@Override
protected Dimension getDefaultSize() {
@SuppressWarnings( "unchecked" )
ListCellRenderer<Object> renderer = comboBox.getRenderer();
uninstallCellPaddingBorder( renderer );
paddingBorder.uninstall();
Dimension size = super.getDefaultSize();
uninstallCellPaddingBorder( renderer );
paddingBorder.uninstall();
return size;
}
@Override
protected Dimension getDisplaySize() {
@SuppressWarnings( "unchecked" )
ListCellRenderer<Object> renderer = comboBox.getRenderer();
uninstallCellPaddingBorder( renderer );
paddingBorder.uninstall();
Dimension displaySize = super.getDisplaySize();
paddingBorder.uninstall();
// remove padding added in super.getDisplaySize()
int displayWidth = displaySize.width - padding.left - padding.right;
int displayHeight = displaySize.height - padding.top - padding.bottom;
// recalculate width without hardcoded 100 under special conditions
if( displaySize.width == 100 + padding.left + padding.right &&
if( displayWidth == 100 &&
comboBox.isEditable() &&
comboBox.getItemCount() == 0 &&
comboBox.getPrototypeDisplayValue() == null )
{
int width = getDefaultSize().width;
width = Math.max( width, editor.getPreferredSize().width );
width += padding.left + padding.right;
displaySize = new Dimension( width, displaySize.height );
displayWidth = Math.max( getDefaultSize().width, editor.getPreferredSize().width );
}
uninstallCellPaddingBorder( renderer );
return displaySize;
return new Dimension( displayWidth, displayHeight );
}
@Override
protected Dimension getSizeForComponent( Component comp ) {
paddingBorder.install( comp );
Dimension size = super.getSizeForComponent( comp );
// remove the renderer border top/bottom insets from the size to make sure that
// the combobox gets the same height as other component types (e.g. JTextField)
Insets rendererInsets = getRendererComponentInsets( comp );
if( rendererInsets != null )
size = new Dimension( size.width, size.height - rendererInsets.top - rendererInsets.bottom );
paddingBorder.uninstall();
return size;
}
private Insets getRendererComponentInsets( Component rendererComponent ) {
if( rendererComponent instanceof JComponent ) {
Border rendererBorder = ((JComponent)rendererComponent).getBorder();
if( rendererBorder != null )
return rendererBorder.getBorderInsets( rendererComponent );
}
return null;
private boolean isCellRenderer() {
return comboBox.getParent() instanceof CellRendererPane;
}
private void uninstallCellPaddingBorder( Object o ) {
CellPaddingBorder.uninstall( o );
if( lastRendererComponent != null ) {
CellPaddingBorder.uninstall( lastRendererComponent );
lastRendererComponent = null;
}
private boolean isCellRendererBackgroundChanged() {
// parent is a CellRendererPane, parentParent is e.g. a JTable
Container parentParent = comboBox.getParent().getParent();
return parentParent != null && !comboBox.getBackground().equals( parentParent.getBackground() );
}
/**
* @since 1.3
*/
public static boolean isPermanentFocusOwner( JComboBox<?> comboBox ) {
if( comboBox.isEditable() ) {
Component editorComponent = comboBox.getEditor().getEditorComponent();
return (editorComponent != null) ? FlatUIUtils.isPermanentFocusOwner( editorComponent ) : false;
} else
return FlatUIUtils.isPermanentFocusOwner( comboBox );
}
//---- class FlatComboBoxButton -------------------------------------------
@@ -566,6 +621,14 @@ public class FlatComboBoxUI
protected boolean isPressed() {
return super.isPressed() || (!comboBox.isEditable() ? pressed : false);
}
@Override
protected Color getArrowColor() {
if( isCellRenderer() && isCellRendererBackgroundChanged() )
return comboBox.getForeground();
return super.getArrowColor();
}
}
//---- class FlatComboPopup -----------------------------------------------
@@ -574,13 +637,11 @@ public class FlatComboBoxUI
protected class FlatComboPopup
extends BasicComboPopup
{
private CellPaddingBorder paddingBorder;
protected FlatComboPopup( JComboBox combo ) {
super( combo );
// BasicComboPopup listens to JComboBox.componentOrientation and updates
// the component orientation of the list, scroller and popup, but when
// the component orientation of the list, scroll pane and popup, but when
// switching the LaF and a new combo popup is created, the component
// orientation is not applied.
ComponentOrientation o = comboBox.getComponentOrientation();
@@ -634,6 +695,9 @@ public class FlatComboBoxUI
protected void configurePopup() {
super.configurePopup();
// make opaque to avoid that background shines thru border (e.g. at 150% scaling)
setOpaque( true );
Border border = UIManager.getBorder( "PopupMenu.border" );
if( border != null )
setBorder( border );
@@ -644,21 +708,49 @@ public class FlatComboBoxUI
super.configureList();
list.setCellRenderer( new PopupListCellRenderer() );
if( popupBackground != null )
list.setBackground( popupBackground );
}
@Override
protected PropertyChangeListener createPropertyChangeListener() {
return new BasicComboPopup.PropertyChangeHandler() {
@Override
public void propertyChange( PropertyChangeEvent e ) {
super.propertyChange( e );
PropertyChangeListener superListener = super.createPropertyChangeListener();
return e -> {
superListener.propertyChange( e );
if( e.getPropertyName() == "renderer" )
list.setCellRenderer( new PopupListCellRenderer() );
}
if( e.getPropertyName() == "renderer" )
list.setCellRenderer( new PopupListCellRenderer() );
};
}
@Override
protected int getPopupHeightForRowCount( int maxRowCount ) {
int height = super.getPopupHeightForRowCount( maxRowCount );
paddingBorder.uninstall();
return height;
}
@Override
public void show( Component invoker, int x, int y ) {
// Java 8: fix y coordinate if popup is shown above the combobox
// (already fixed in Java 9+ https://bugs.openjdk.java.net/browse/JDK-7072653)
if( y < 0 && !SystemInfo.isJava_9_orLater ) {
Border popupBorder = getBorder();
if( popupBorder != null ) {
Insets insets = popupBorder.getBorderInsets( this );
y -= insets.top + insets.bottom;
}
}
super.show( invoker, x, y );
}
@Override
protected void paintChildren( Graphics g ) {
super.paintChildren( g );
paddingBorder.uninstall();
}
//---- class PopupListCellRenderer -----
private class PopupListCellRenderer
@@ -668,22 +760,15 @@ public class FlatComboBoxUI
public Component getListCellRendererComponent( JList list, Object value,
int index, boolean isSelected, boolean cellHasFocus )
{
ListCellRenderer renderer = comboBox.getRenderer();
CellPaddingBorder.uninstall( renderer );
CellPaddingBorder.uninstall( lastRendererComponent );
paddingBorder.uninstall();
ListCellRenderer renderer = comboBox.getRenderer();
if( renderer == null )
renderer = new DefaultListCellRenderer();
Component c = renderer.getListCellRendererComponent( list, value, index, isSelected, cellHasFocus );
c.applyComponentOrientation( comboBox.getComponentOrientation() );
if( c instanceof JComponent ) {
if( paddingBorder == null )
paddingBorder = new CellPaddingBorder( padding );
paddingBorder.install( (JComponent) c );
}
lastRendererComponent = (c != renderer) ? new WeakReference<>( c ) : null;
paddingBorder.install( c );
return c;
}
@@ -693,49 +778,69 @@ public class FlatComboBoxUI
//---- class CellPaddingBorder --------------------------------------------
/**
* Cell padding border used only in popup list.
*
* Cell padding border used in popup list and for current value if not editable.
* <p>
* The insets are the union of the cell padding and the renderer border insets,
* which vertically aligns text in popup list with text in combobox.
*
* The renderer border is painted on the outside of this border.
* <p>
* The renderer border is painted on the outer side of this border.
*/
private static class CellPaddingBorder
extends AbstractBorder
{
private final Insets padding;
private JComponent rendererComponent;
private Border rendererBorder;
CellPaddingBorder( Insets padding ) {
this.padding = padding;
}
void install( JComponent rendererComponent ) {
Border oldBorder = rendererComponent.getBorder();
if( !(oldBorder instanceof CellPaddingBorder) ) {
rendererBorder = oldBorder;
rendererComponent.setBorder( this );
}
}
static void uninstall( Object o ) {
if( o instanceof WeakReference )
o = ((WeakReference<?>)o).get();
if( !(o instanceof JComponent) )
void install( Component c ) {
if( !(c instanceof JComponent) )
return;
JComponent rendererComponent = (JComponent) o;
Border border = rendererComponent.getBorder();
if( border instanceof CellPaddingBorder ) {
CellPaddingBorder paddingBorder = (CellPaddingBorder) border;
rendererComponent.setBorder( paddingBorder.rendererBorder );
paddingBorder.rendererBorder = null;
}
JComponent jc = (JComponent) c;
Border oldBorder = jc.getBorder();
if( oldBorder == this )
return; // already installed
// component already has a padding border --> uninstall it
// (may happen if single renderer instance is used in multiple comboboxes)
if( oldBorder instanceof CellPaddingBorder )
((CellPaddingBorder)oldBorder).uninstall();
// this border can be installed only at one component
// (may happen if a renderer returns varying components)
uninstall();
// remember component where this border was installed for uninstall
rendererComponent = jc;
// remember old border and replace it
rendererBorder = jc.getBorder();
rendererComponent.setBorder( this );
}
/**
* Uninstall border from previously installed component.
* Because this border is installed in PopupListCellRenderer.getListCellRendererComponent(),
* there is no single place to uninstall it.
* This is the reason why this method is called from various places.
*/
void uninstall() {
if( rendererComponent == null )
return;
if( rendererComponent.getBorder() == this )
rendererComponent.setBorder( rendererBorder );
rendererComponent = null;
rendererBorder = null;
}
@Override
public Insets getBorderInsets( Component c, Insets insets ) {
Insets padding = scale( this.padding );
if( rendererBorder != null ) {
Insets insideInsets = rendererBorder.getBorderInsets( c );
insets.top = Math.max( padding.top, insideInsets.top );

View File

@@ -16,10 +16,12 @@
package com.formdev.flatlaf.ui;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Insets;
@@ -28,11 +30,13 @@ import java.awt.Point;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.beans.PropertyChangeListener;
import java.beans.PropertyVetoException;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JDesktopPane;
import javax.swing.event.MouseInputAdapter;
import javax.swing.event.MouseInputListener;
import javax.swing.JLabel;
@@ -45,6 +49,7 @@ import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicDesktopIconUI;
import com.formdev.flatlaf.util.MultiResolutionImageSupport;
import com.formdev.flatlaf.util.UIScale;
/**
@@ -75,11 +80,21 @@ public class FlatDesktopIconUI
private JToolTip titleTip;
private ActionListener closeListener;
private MouseInputListener mouseInputListener;
private PropertyChangeListener ancestorListener;
public static ComponentUI createUI( JComponent c ) {
return new FlatDesktopIconUI();
}
@Override
public void installUI( JComponent c ) {
super.installUI( c );
// update dock icon preview if already iconified
if( c.isDisplayable() )
updateDockIconPreviewLater();
}
@Override
public void uninstallUI( JComponent c ) {
super.uninstallUI( c );
@@ -136,6 +151,17 @@ public class FlatDesktopIconUI
};
closeButton.addActionListener( closeListener );
closeButton.addMouseListener( mouseInputListener );
ancestorListener = e -> {
if( e.getNewValue() != null ) {
// update dock icon preview if desktopIcon is added to desktop (internal frame was iconified)
updateDockIconPreviewLater();
} else {
// remove preview icon to release memory
dockIcon.setIcon( null );
}
};
desktopIcon.addPropertyChangeListener( "ancestor", ancestorListener );
}
@Override
@@ -146,6 +172,9 @@ public class FlatDesktopIconUI
closeButton.removeMouseListener( mouseInputListener );
closeListener = null;
mouseInputListener = null;
desktopIcon.removePropertyChangeListener( "ancestor", ancestorListener );
ancestorListener = null;
}
@Override
@@ -228,15 +257,30 @@ public class FlatDesktopIconUI
return getPreferredSize( c );
}
void updateDockIcon() {
@Override
public void update( Graphics g, JComponent c ) {
if( c.isOpaque() ) {
// fill background with color derived from desktop pane
Color background = c.getBackground();
JDesktopPane desktopPane = desktopIcon.getDesktopPane();
g.setColor( (desktopPane != null)
? FlatUIUtils.deriveColor( background, desktopPane.getBackground() )
: background );
g.fillRect( 0, 0, c.getWidth(), c.getHeight() );
}
paint( g, c );
}
private void updateDockIconPreviewLater() {
// use invoke later to make sure that components are updated when switching LaF
EventQueue.invokeLater( () -> {
if( dockIcon != null )
updateDockIconLater();
updateDockIconPreview();
} );
}
private void updateDockIconLater() {
protected void updateDockIconPreview() {
// make sure that frame is not selected
if( frame.isSelected() ) {
try {
@@ -246,13 +290,22 @@ public class FlatDesktopIconUI
}
}
// layout internal frame title pane, which was recreated when switching Laf
// (directly invoke doLayout() because frame.validate() does not work here
// because frame is not displayable)
if( !frame.isValid() )
frame.doLayout();
for( Component c : frame.getComponents() ) {
if( !c.isValid() )
c.doLayout();
}
// paint internal frame to buffered image
int frameWidth = Math.max( frame.getWidth(), 1 );
int frameHeight = Math.max( frame.getHeight(), 1 );
BufferedImage frameImage = new BufferedImage( frameWidth, frameHeight, BufferedImage.TYPE_INT_ARGB );
Graphics2D g = frameImage.createGraphics();
try {
//TODO fix missing internal frame header when switching LaF
frame.paint( g );
} finally {
g.dispose();
@@ -270,6 +323,27 @@ public class FlatDesktopIconUI
// scale preview
Image previewImage = frameImage.getScaledInstance( previewWidth, previewHeight, Image.SCALE_SMOOTH );
if( MultiResolutionImageSupport.isAvailable() ) {
// On HiDPI screens, create preview images for 1x, 2x and current scale factor.
// The icon then chooses the best resolution for painting, which is usually
// the one for the current scale factor. But if changing scale factor or
// moving window to another screen with different scale factor, then another
// resolution may be used because the preview icon is not updated.
Image previewImage2x = frameImage.getScaledInstance( previewWidth * 2, previewHeight * 2, Image.SCALE_SMOOTH );
double scaleFactor = UIScale.getSystemScaleFactor( desktopIcon.getGraphicsConfiguration() );
if( scaleFactor != 1 && scaleFactor != 2 ) {
Image previewImageCurrent = frameImage.getScaledInstance(
(int) Math.round( previewWidth * scaleFactor ),
(int) Math.round( previewHeight * scaleFactor ),
Image.SCALE_SMOOTH );
// the images must be ordered by resolution
previewImage = (scaleFactor < 2)
? MultiResolutionImageSupport.create( 0, previewImage, previewImageCurrent, previewImage2x )
: MultiResolutionImageSupport.create( 0, previewImage, previewImage2x, previewImageCurrent );
} else
previewImage = MultiResolutionImageSupport.create( 0, previewImage, previewImage2x );
}
dockIcon.setIcon( new ImageIcon( previewImage ) );
}

View File

@@ -16,11 +16,16 @@
package com.formdev.flatlaf.ui;
import javax.swing.DefaultDesktopManager;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.ContainerEvent;
import java.awt.event.ContainerListener;
import javax.swing.JComponent;
import javax.swing.JInternalFrame;
import javax.swing.JInternalFrame.JDesktopIcon;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.UIResource;
import javax.swing.plaf.basic.BasicDesktopPaneUI;
/**
@@ -36,30 +41,96 @@ import javax.swing.plaf.basic.BasicDesktopPaneUI;
public class FlatDesktopPaneUI
extends BasicDesktopPaneUI
{
private LayoutDockListener layoutDockListener;
private boolean layoutDockPending;
public static ComponentUI createUI( JComponent c ) {
return new FlatDesktopPaneUI();
}
@Override
protected void installDesktopManager() {
desktopManager = desktop.getDesktopManager();
if( desktopManager == null ) {
desktopManager = new FlatDesktopManager();
desktop.setDesktopManager( desktopManager );
public void installUI( JComponent c ) {
super.installUI( c );
layoutDockLaterOnce();
}
@Override
protected void installListeners() {
super.installListeners();
layoutDockListener = new LayoutDockListener();
desktop.addContainerListener( layoutDockListener );
desktop.addComponentListener( layoutDockListener );
}
@Override
protected void uninstallListeners() {
super.uninstallListeners();
desktop.removeContainerListener( layoutDockListener );
desktop.removeComponentListener( layoutDockListener );
layoutDockListener = null;
}
private void layoutDockLaterOnce() {
if( layoutDockPending )
return;
layoutDockPending = true;
EventQueue.invokeLater( () -> {
layoutDockPending = false;
if( desktop != null )
layoutDock();
} );
}
protected void layoutDock() {
Dimension desktopSize = desktop.getSize();
int x = 0;
int y = desktopSize.height;
int rowHeight = 0;
for( Component c : desktop.getComponents() ) {
if( !(c instanceof JDesktopIcon) )
continue;
JDesktopIcon icon = (JDesktopIcon) c;
Dimension iconSize = icon.getPreferredSize();
if( x + iconSize.width > desktopSize.width ) {
// new row
x = 0;
y -= rowHeight;
rowHeight = 0;
}
icon.setLocation( x, y - iconSize.height );
x += iconSize.width;
rowHeight = Math.max( iconSize.height, rowHeight );
}
}
//---- class FlatDesktopManager -------------------------------------------
//---- class LayoutDockListener -------------------------------------------
private class FlatDesktopManager
extends DefaultDesktopManager
implements UIResource
private class LayoutDockListener
extends ComponentAdapter
implements ContainerListener
{
@Override
public void iconifyFrame( JInternalFrame f ) {
super.iconifyFrame( f );
public void componentAdded( ContainerEvent e ) {
layoutDockLaterOnce();
}
((FlatDesktopIconUI)f.getDesktopIcon().getUI()).updateDockIcon();
@Override
public void componentRemoved( ContainerEvent e ) {
layoutDockLaterOnce();
}
@Override
public void componentResized( ComponentEvent e ) {
layoutDockLaterOnce();
}
}
}

View File

@@ -17,15 +17,17 @@
package com.formdev.flatlaf.ui;
import static com.formdev.flatlaf.util.UIScale.scale;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.event.FocusListener;
import java.beans.PropertyChangeEvent;
import javax.swing.JComponent;
import javax.swing.JEditorPane;
import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.UIResource;
import javax.swing.plaf.basic.BasicEditorPaneUI;
import javax.swing.text.JTextComponent;
import com.formdev.flatlaf.FlatClientProperties;
@@ -53,6 +55,7 @@ import com.formdev.flatlaf.util.HiDPIUtils;
*
* @uiDefault Component.minimumWidth int
* @uiDefault Component.isIntelliJTheme boolean
* @uiDefault EditorPane.focusedBackground Color optional
*
* @author Karl Tauber
*/
@@ -61,8 +64,12 @@ public class FlatEditorPaneUI
{
protected int minimumWidth;
protected boolean isIntelliJTheme;
protected Color focusedBackground;
private Insets defaultMargin;
private Object oldHonorDisplayProperties;
private FocusListener focusListener;
public static ComponentUI createUI( JComponent c ) {
return new FlatEditorPaneUI();
@@ -72,8 +79,12 @@ public class FlatEditorPaneUI
protected void installDefaults() {
super.installDefaults();
String prefix = getPropertyPrefix();
minimumWidth = UIManager.getInt( "Component.minimumWidth" );
isIntelliJTheme = UIManager.getBoolean( "Component.isIntelliJTheme" );
focusedBackground = UIManager.getColor( prefix + ".focusedBackground" );
defaultMargin = UIManager.getInsets( prefix + ".margin" );
// use component font and foreground for HTML text
oldHonorDisplayProperties = getComponent().getClientProperty( JEditorPane.HONOR_DISPLAY_PROPERTIES );
@@ -84,9 +95,28 @@ public class FlatEditorPaneUI
protected void uninstallDefaults() {
super.uninstallDefaults();
focusedBackground = null;
getComponent().putClientProperty( JEditorPane.HONOR_DISPLAY_PROPERTIES, oldHonorDisplayProperties );
}
@Override
protected void installListeners() {
super.installListeners();
// necessary to update focus background
focusListener = new FlatUIUtils.RepaintFocusListener( getComponent(), c -> focusedBackground != null );
getComponent().addFocusListener( focusListener );
}
@Override
protected void uninstallListeners() {
super.uninstallListeners();
getComponent().removeFocusListener( focusListener );
focusListener = null;
}
@Override
protected void propertyChange( PropertyChangeEvent e ) {
super.propertyChange( e );
@@ -103,15 +133,19 @@ public class FlatEditorPaneUI
@Override
public Dimension getPreferredSize( JComponent c ) {
return applyMinimumWidth( c, super.getPreferredSize( c ), minimumWidth );
return applyMinimumWidth( c, super.getPreferredSize( c ), minimumWidth, defaultMargin );
}
@Override
public Dimension getMinimumSize( JComponent c ) {
return applyMinimumWidth( c, super.getMinimumSize( c ), minimumWidth );
return applyMinimumWidth( c, super.getMinimumSize( c ), minimumWidth, defaultMargin );
}
static Dimension applyMinimumWidth( JComponent c, Dimension size, int minimumWidth ) {
static Dimension applyMinimumWidth( JComponent c, Dimension size, int minimumWidth, Insets defaultMargin ) {
// do not apply minimum width if JTextComponent.margin is set
if( !FlatTextFieldUI.hasDefaultMargins( c, defaultMargin ) )
return size;
// Assume that text area is in a scroll pane (that displays the border)
// and subtract 1px border line width.
// Using "(scale( 1 ) * 2)" instead of "scale( 2 )" to deal with rounding
@@ -128,14 +162,11 @@ public class FlatEditorPaneUI
@Override
protected void paintBackground( Graphics g ) {
JTextComponent c = getComponent();
paintBackground( g, getComponent(), isIntelliJTheme, focusedBackground );
}
// for compatibility with IntelliJ themes
if( isIntelliJTheme && (!c.isEnabled() || !c.isEditable()) && (c.getBackground() instanceof UIResource) ) {
FlatUIUtils.paintParentBackground( g, c );
return;
}
super.paintBackground( g );
static void paintBackground( Graphics g, JTextComponent c, boolean isIntelliJTheme, Color focusedBackground ) {
g.setColor( FlatTextFieldUI.getBackground( c, isIntelliJTheme, focusedBackground ) );
g.fillRect( 0, 0, c.getWidth(), c.getHeight() );
}
}

View File

@@ -31,13 +31,17 @@ import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JToggleButton;
import javax.swing.UIManager;
import javax.swing.filechooser.FileView;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.metal.MetalFileChooserUI;
import javax.swing.table.TableCellRenderer;
import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.util.ScaledImageIcon;
import com.formdev.flatlaf.util.SystemInfo;
import com.formdev.flatlaf.util.UIScale;
/**
@@ -190,6 +194,62 @@ public class FlatFileChooserUI
}
}
@Override
protected JPanel createDetailsView( JFileChooser fc ) {
JPanel p = super.createDetailsView( fc );
if( !SystemInfo.isWindows )
return p;
// find scroll pane
JScrollPane scrollPane = null;
for( Component c : p.getComponents() ) {
if( c instanceof JScrollPane ) {
scrollPane = (JScrollPane) c;
break;
}
}
if( scrollPane == null )
return p;
// get scroll view, which should be a table
Component view = scrollPane.getViewport().getView();
if( !(view instanceof JTable) )
return p;
JTable table = (JTable) view;
// on Windows 10, the date may contain left-to-right (0x200e) and right-to-left (0x200f)
// mark characters (see https://en.wikipedia.org/wiki/Left-to-right_mark)
// when the "current user" item is selected in the "look in" combobox
// --> remove them
TableCellRenderer defaultRenderer = table.getDefaultRenderer( Object.class );
table.setDefaultRenderer( Object.class, new TableCellRenderer() {
@Override
public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected,
boolean hasFocus, int row, int column )
{
// remove left-to-right and right-to-left mark characters
if( value instanceof String && ((String)value).startsWith( "\u200e" ) ) {
String str = (String) value;
char[] buf = new char[str.length()];
int j = 0;
for( int i = 0; i < buf.length; i++ ) {
char ch = str.charAt( i );
if( ch != '\u200e' && ch != '\u200f' )
buf[j++] = ch;
}
value = new String( buf, 0, j );
}
return defaultRenderer.getTableCellRendererComponent( table, value, isSelected, hasFocus, row, column );
}
} );
return p;
}
@Override
public Dimension getPreferredSize( JComponent c ) {
return UIScale.scale( super.getPreferredSize( c ) );

View File

@@ -39,11 +39,10 @@ import javax.swing.plaf.ComponentUI;
*
* <!-- FlatTextFieldUI -->
*
* @uiDefault TextComponent.arc int
* @uiDefault Component.focusWidth int
* @uiDefault Component.minimumWidth int
* @uiDefault Component.isIntelliJTheme boolean
* @uiDefault FormattedTextField.placeholderForeground Color
* @uiDefault FormattedTextField.focusedBackground Color optional
* @uiDefault TextComponent.selectAllOnFocusPolicy String never, once (default) or always
* @uiDefault TextComponent.selectAllOnMouseClick boolean
*

View File

@@ -21,6 +21,7 @@ import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.LayoutManager;
import java.awt.Rectangle;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.BorderFactory;
@@ -146,6 +147,19 @@ public class FlatInternalFrameTitlePane
closeButton.setVisible( frame.isClosable() );
}
Rectangle getFrameIconBounds() {
Icon icon = titleLabel.getIcon();
if( icon == null )
return null;
int iconWidth = icon.getIconWidth();
int iconHeight = icon.getIconHeight();
boolean leftToRight = titleLabel.getComponentOrientation().isLeftToRight();
int x = titleLabel.getX() + (leftToRight ? 0 : (titleLabel.getWidth() - iconWidth));
int y = titleLabel.getY() + ((titleLabel.getHeight() - iconHeight) / 2);
return new Rectangle( x, y, iconWidth, iconHeight );
}
/**
* Does nothing because FlatLaf internal frames do not have system menus.
*/

View File

@@ -22,10 +22,13 @@ import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import javax.swing.JComponent;
import javax.swing.JInternalFrame;
import javax.swing.LookAndFeel;
import javax.swing.UIManager;
import javax.swing.event.MouseInputAdapter;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicInternalFrameUI;
@@ -122,6 +125,11 @@ public class FlatInternalFrameUI
return new FlatWindowResizer.InternalFrameResizer( frame, this::getDesktopManager );
}
@Override
protected MouseInputAdapter createBorderListener( JInternalFrame w ) {
return new FlatBorderListener();
}
//---- class FlatInternalFrameBorder --------------------------------------
public static class FlatInternalFrameBorder
@@ -195,4 +203,29 @@ public class FlatInternalFrameUI
}
}
}
//---- class FlatBorderListener -------------------------------------------
/**
* @since 1.6
*/
protected class FlatBorderListener
extends BorderListener
{
@Override
public void mouseClicked( MouseEvent e ) {
if( e.getClickCount() == 2 && !frame.isIcon() &&
e.getSource() instanceof FlatInternalFrameTitlePane )
{
Rectangle iconBounds = ((FlatInternalFrameTitlePane)e.getSource()).getFrameIconBounds();
if( iconBounds != null && iconBounds.contains( e.getX(), e.getY() ) ) {
if( frame.isClosable() )
frame.doDefaultCloseAction();
return;
}
}
super.mouseClicked( e );
}
}
}

View File

@@ -22,6 +22,9 @@ import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.beans.PropertyChangeEvent;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import javax.swing.Icon;
import javax.swing.JComponent;
import javax.swing.JLabel;
@@ -96,23 +99,37 @@ public class FlatLabelUI
}
/**
* Checks whether text contains HTML headings and adds a special CSS rule to
* re-calculate heading font sizes based on current component font size.
* Checks whether text contains HTML tags that use "absolute-size" keywords
* (e.g. "x-large") for font-size in default style sheet
* (see javax/swing/text/html/default.css).
* If yes, adds a special CSS rule (BASE_SIZE) to the HTML text, which
* re-calculates font sizes based on current component font size.
*/
static void updateHTMLRenderer( JComponent c, String text, boolean always ) {
if( BasicHTML.isHTMLString( text ) &&
c.getClientProperty( "html.disable" ) != Boolean.TRUE &&
text.contains( "<h" ) &&
(text.contains( "<h1" ) || text.contains( "<h2" ) || text.contains( "<h3" ) ||
text.contains( "<h4" ) || text.contains( "<h5" ) || text.contains( "<h6" )) )
needsFontBaseSize( text ) )
{
int headIndex = text.indexOf( "<head>" );
// BASE_SIZE rule is parsed in javax.swing.text.html.StyleSheet.addRule()
String style = "<style>BASE_SIZE " + c.getFont().getSize() + "</style>";
if( headIndex < 0 )
style = "<head>" + style + "</head>";
int insertIndex = headIndex >= 0 ? (headIndex + "<head>".length()) : "<html>".length();
String lowerText = text.toLowerCase();
int headIndex;
int styleIndex;
int insertIndex;
if( (headIndex = lowerText.indexOf( "<head>" )) >= 0 ) {
// there is a <head> tag --> insert after <head> tag
insertIndex = headIndex + "<head>".length();
} else if( (styleIndex = lowerText.indexOf( "<style>" )) >= 0 ) {
// there is a <style> tag --> insert before <style> tag
insertIndex = styleIndex;
} else {
// no <head> or <style> tag --> insert <head> tag after <html> tag
style = "<head>" + style + "</head>";
insertIndex = "<html>".length();
}
text = text.substring( 0, insertIndex )
+ style
+ text.substring( insertIndex );
@@ -122,6 +139,44 @@ public class FlatLabelUI
BasicHTML.updateRenderer( c, text );
}
private static Set<String> tagsUseFontSizeSet;
private static boolean needsFontBaseSize( String text ) {
if( tagsUseFontSizeSet == null ) {
// tags that use font-size in javax/swing/text/html/default.css
tagsUseFontSizeSet = new HashSet<>( Arrays.asList(
"h1", "h2", "h3", "h4", "h5", "h6", "code", "kbd", "big", "small", "samp" ) );
}
// search for tags in HTML text
int textLength = text.length();
for( int i = 6; i < textLength - 1; i++ ) {
if( text.charAt( i ) == '<' ) {
switch( text.charAt( i + 1 ) ) {
// first letters of tags in tagsUseFontSizeSet
case 'b': case 'B':
case 'c': case 'C':
case 'h': case 'H':
case 'k': case 'K':
case 's': case 'S':
int tagBegin = i + 1;
for( i += 2; i < textLength; i++ ) {
if( !Character.isLetterOrDigit( text.charAt( i ) ) ) {
String tag = text.substring( tagBegin, i ).toLowerCase();
if( tagsUseFontSizeSet.contains( tag ) )
return true;
break;
}
}
break;
}
}
}
return false;
}
static Graphics createGraphicsHTMLTextYCorrection( Graphics g, JComponent c ) {
return (c.getClientProperty( BasicHTML.propertyKey ) != null)
? HiDPIUtils.createGraphicsTextYCorrection( (Graphics2D) g )

View File

@@ -20,10 +20,12 @@ import java.awt.Color;
import java.awt.EventQueue;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.beans.PropertyChangeListener;
import javax.swing.JComponent;
import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicListUI;
import com.formdev.flatlaf.FlatClientProperties;
/**
* Provides the Flat LaF UI delegate for {@link javax.swing.JList}.
@@ -95,6 +97,17 @@ public class FlatListUI
selectionInactiveForeground = null;
}
@Override
protected PropertyChangeListener createPropertyChangeListener() {
PropertyChangeListener superListener = super.createPropertyChangeListener();
return e -> {
superListener.propertyChange( e );
if( FlatClientProperties.COMPONENT_FOCUS_OWNER.equals( e.getPropertyName() ) )
toggleSelectionColors();
};
}
@Override
protected FocusListener createFocusListener() {
return new BasicListUI.FocusHandler() {

View File

@@ -16,17 +16,24 @@
package com.formdev.flatlaf.ui;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Window;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.ActionMap;
import javax.swing.JComponent;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JRootPane;
import javax.swing.LookAndFeel;
import javax.swing.MenuElement;
import javax.swing.MenuSelectionManager;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.plaf.ActionMapUIResource;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.UIResource;
import javax.swing.plaf.basic.BasicMenuBarUI;
import com.formdev.flatlaf.FlatLaf;
import com.formdev.flatlaf.util.SystemInfo;
@@ -40,6 +47,7 @@ import com.formdev.flatlaf.util.SystemInfo;
* @uiDefault MenuBar.background Color
* @uiDefault MenuBar.foreground Color
* @uiDefault MenuBar.border Border
* @uiDefault TitlePane.unifiedBackground boolean
*
* @author Karl Tauber
*/
@@ -55,6 +63,13 @@ public class FlatMenuBarUI
* Do not add any functionality here.
*/
@Override
protected void installDefaults() {
super.installDefaults();
LookAndFeel.installProperty( menuBar, "opaque", false );
}
@Override
protected void installKeyboardActions() {
super.installKeyboardActions();
@@ -67,6 +82,44 @@ public class FlatMenuBarUI
map.put( "takeFocus", new TakeFocus() );
}
@Override
public void update( Graphics g, JComponent c ) {
// paint background
Color background = getBackground( c );
if( background != null ) {
g.setColor( background );
g.fillRect( 0, 0, c.getWidth(), c.getHeight() );
}
paint( g, c );
}
protected Color getBackground( JComponent c ) {
Color background = c.getBackground();
// paint background if opaque or if having custom background color
if( c.isOpaque() || !(background instanceof UIResource) )
return background;
// paint background if menu bar is not the "main" menu bar
JRootPane rootPane = SwingUtilities.getRootPane( c );
if( rootPane == null || !(rootPane.getParent() instanceof Window) || rootPane.getJMenuBar() != c )
return background;
// use parent background for unified title pane
// (not storing value of "TitlePane.unifiedBackground" in class to allow changing at runtime)
if( UIManager.getBoolean( "TitlePane.unifiedBackground" ) &&
FlatNativeWindowBorder.hasCustomDecoration( (Window) rootPane.getParent() ) )
background = FlatUIUtils.getParentBackground( c );
// paint background in full screen mode
if( FlatUIUtils.isFullScreen( rootPane ) )
return background;
// do not paint background if menu bar is embedded into title pane
return FlatRootPaneUI.isMenuBarEmbedded( rootPane ) ? null : background;
}
//---- class TakeFocus ----------------------------------------------------
/**

View File

@@ -0,0 +1,360 @@
/*
* Copyright 2021 FormDev Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.formdev.flatlaf.ui;
import java.awt.Color;
import java.awt.Container;
import java.awt.Rectangle;
import java.awt.Window;
import java.beans.PropertyChangeListener;
import java.util.List;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JRootPane;
import javax.swing.UIManager;
import javax.swing.event.ChangeListener;
import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.FlatLaf;
import com.formdev.flatlaf.FlatSystemProperties;
import com.formdev.flatlaf.ui.JBRCustomDecorations.JBRWindowTopBorder;
import com.formdev.flatlaf.util.SystemInfo;
/**
* Support for custom window decorations with native window border.
*
* @author Karl Tauber
* @since 1.1
*/
public class FlatNativeWindowBorder
{
// can use window decorations if:
// - on Windows 10
// - not when running in JetBrains Projector, Webswing or WinPE
// - not disabled via system property
private static final boolean canUseWindowDecorations =
SystemInfo.isWindows_10_orLater &&
!SystemInfo.isProjector &&
!SystemInfo.isWebswing &&
!SystemInfo.isWinPE &&
FlatSystemProperties.getBoolean( FlatSystemProperties.USE_WINDOW_DECORATIONS, true );
// check this field before using class JBRCustomDecorations to avoid unnecessary loading of that class
private static final boolean canUseJBRCustomDecorations =
canUseWindowDecorations &&
SystemInfo.isJetBrainsJVM_11_orLater &&
FlatSystemProperties.getBoolean( FlatSystemProperties.USE_JETBRAINS_CUSTOM_DECORATIONS, true );
private static Boolean supported;
private static Provider nativeProvider;
public static boolean isSupported() {
if( canUseJBRCustomDecorations )
return JBRCustomDecorations.isSupported();
initialize();
return supported;
}
static Object install( JRootPane rootPane ) {
if( canUseJBRCustomDecorations )
return JBRCustomDecorations.install( rootPane );
if( !isSupported() )
return null;
// do nothing if root pane has a parent that is not a window (e.g. a JInternalFrame)
Container parent = rootPane.getParent();
if( parent != null && !(parent instanceof Window) )
return null;
// Check whether root pane already has a window, which is the case when
// switching from another LaF to FlatLaf.
// Also check whether the window is displayable, which is required to install
// FlatLaf native window border.
// If the window is not displayable, then it was probably closed/disposed but not yet removed
// from the list of windows that AWT maintains and returns with Window.getWindows().
// It could be also be a window that is currently hidden, but may be shown later.
if( parent instanceof Window && parent.isDisplayable() )
install( (Window) parent );
// Install FlatLaf native window border, which must be done late,
// when the native window is already created, because it needs access to the window.
// Uninstall FlatLaf native window border when window is disposed (or root pane removed).
// "ancestor" property change event is fired from JComponent.addNotify() and removeNotify().
PropertyChangeListener ancestorListener = e -> {
Object newValue = e.getNewValue();
if( newValue instanceof Window )
install( (Window) newValue );
else if( newValue == null && e.getOldValue() instanceof Window )
uninstall( (Window) e.getOldValue() );
};
rootPane.addPropertyChangeListener( "ancestor", ancestorListener );
return ancestorListener;
}
static void install( Window window ) {
if( hasCustomDecoration( window ) )
return;
// do not enable native window border if LaF provides decorations
if( UIManager.getLookAndFeel().getSupportsWindowDecorations() )
return;
if( window instanceof JFrame ) {
JFrame frame = (JFrame) window;
JRootPane rootPane = frame.getRootPane();
// check whether disabled via system property, client property or UI default
if( !useWindowDecorations( rootPane ) )
return;
// do not enable native window border if frame is undecorated
if( frame.isUndecorated() )
return;
// enable native window border for window
setHasCustomDecoration( frame, true );
// avoid double window title bar if enabling native window border failed
if( !hasCustomDecoration( frame ) )
return;
// enable Swing window decoration
rootPane.setWindowDecorationStyle( JRootPane.FRAME );
} else if( window instanceof JDialog ) {
JDialog dialog = (JDialog) window;
JRootPane rootPane = dialog.getRootPane();
// check whether disabled via system property, client property or UI default
if( !useWindowDecorations( rootPane ) )
return;
// do not enable native window border if dialog is undecorated
if( dialog.isUndecorated() )
return;
// enable native window border for window
setHasCustomDecoration( dialog, true );
// avoid double window title bar if enabling native window border failed
if( !hasCustomDecoration( dialog ) )
return;
// enable Swing window decoration
rootPane.setWindowDecorationStyle( JRootPane.PLAIN_DIALOG );
}
}
static void uninstall( JRootPane rootPane, Object data ) {
if( canUseJBRCustomDecorations ) {
JBRCustomDecorations.uninstall( rootPane, data );
return;
}
if( !isSupported() )
return;
// remove listener
if( data instanceof PropertyChangeListener )
rootPane.removePropertyChangeListener( "ancestor", (PropertyChangeListener) data );
// do not uninstall when switching to another FlatLaf theme and if still enabled
if( UIManager.getLookAndFeel() instanceof FlatLaf && useWindowDecorations( rootPane ) )
return;
// uninstall native window border
Container parent = rootPane.getParent();
if( parent instanceof Window )
uninstall( (Window) parent );
}
private static void uninstall( Window window ) {
if( !hasCustomDecoration( window ) )
return;
// disable native window border for window
setHasCustomDecoration( window, false );
if( window instanceof JFrame ) {
JFrame frame = (JFrame) window;
// disable Swing window decoration
frame.getRootPane().setWindowDecorationStyle( JRootPane.NONE );
} else if( window instanceof JDialog ) {
JDialog dialog = (JDialog) window;
// disable Swing window decoration
dialog.getRootPane().setWindowDecorationStyle( JRootPane.NONE );
}
}
private static boolean useWindowDecorations( JRootPane rootPane ) {
return FlatUIUtils.getBoolean( rootPane,
FlatSystemProperties.USE_WINDOW_DECORATIONS,
FlatClientProperties.USE_WINDOW_DECORATIONS,
"TitlePane.useWindowDecorations",
false );
}
public static boolean hasCustomDecoration( Window window ) {
if( canUseJBRCustomDecorations )
return JBRCustomDecorations.hasCustomDecoration( window );
if( !isSupported() )
return false;
return nativeProvider.hasCustomDecoration( window );
}
public static void setHasCustomDecoration( Window window, boolean hasCustomDecoration ) {
if( canUseJBRCustomDecorations ) {
JBRCustomDecorations.setHasCustomDecoration( window, hasCustomDecoration );
return;
}
if( !isSupported() )
return;
nativeProvider.setHasCustomDecoration( window, hasCustomDecoration );
}
static void setTitleBarHeightAndHitTestSpots( Window window, int titleBarHeight,
List<Rectangle> hitTestSpots, Rectangle appIconBounds )
{
if( canUseJBRCustomDecorations ) {
JBRCustomDecorations.setTitleBarHeightAndHitTestSpots( window, titleBarHeight, hitTestSpots );
return;
}
if( !isSupported() )
return;
nativeProvider.setTitleBarHeight( window, titleBarHeight );
nativeProvider.setTitleBarHitTestSpots( window, hitTestSpots );
nativeProvider.setTitleBarAppIconBounds( window, appIconBounds );
}
static boolean showWindow( Window window, int cmd ) {
if( canUseJBRCustomDecorations || !isSupported() )
return false;
return nativeProvider.showWindow( window, cmd );
}
private static void initialize() {
if( supported != null )
return;
supported = false;
if( !canUseWindowDecorations )
return;
try {
/*
Class<?> cls = Class.forName( "com.formdev.flatlaf.natives.jna.windows.FlatWindowsNativeWindowBorder" );
Method m = cls.getMethod( "getInstance" );
setNativeProvider( (Provider) m.invoke( null ) );
*/
setNativeProvider( FlatWindowsNativeWindowBorder.getInstance() );
} catch( Exception ex ) {
// ignore
}
}
/**
* @since 1.1.1
*/
public static void setNativeProvider( Provider provider ) {
if( nativeProvider != null )
throw new IllegalStateException();
nativeProvider = provider;
supported = (nativeProvider != null);
}
//---- interface Provider -------------------------------------------------
public interface Provider
{
boolean hasCustomDecoration( Window window );
void setHasCustomDecoration( Window window, boolean hasCustomDecoration );
void setTitleBarHeight( Window window, int titleBarHeight );
void setTitleBarHitTestSpots( Window window, List<Rectangle> hitTestSpots );
void setTitleBarAppIconBounds( Window window, Rectangle appIconBounds );
// commands for showWindow(); values must match Win32 API
// https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindow
int SW_MAXIMIZE = 3;
int SW_MINIMIZE = 6;
int SW_RESTORE = 9;
boolean showWindow( Window window, int cmd );
boolean isColorizationColorAffectsBorders();
Color getColorizationColor();
int getColorizationColorBalance();
void addChangeListener( ChangeListener l );
void removeChangeListener( ChangeListener l );
}
//---- class WindowTopBorder -------------------------------------------
static class WindowTopBorder
extends JBRCustomDecorations.JBRWindowTopBorder
{
private static WindowTopBorder instance;
static JBRWindowTopBorder getInstance() {
if( canUseJBRCustomDecorations )
return JBRWindowTopBorder.getInstance();
if( instance == null )
instance = new WindowTopBorder();
return instance;
}
@Override
void installListeners() {
nativeProvider.addChangeListener( e -> {
update();
// repaint top borders of all windows
for( Window window : Window.getWindows() ) {
if( window.isDisplayable() )
window.repaint( 0, 0, window.getWidth(), 1 );
}
} );
}
@Override
boolean isColorizationColorAffectsBorders() {
return nativeProvider.isColorizationColorAffectsBorders();
}
@Override
Color getColorizationColor() {
return nativeProvider.getColorizationColor();
}
@Override
int getColorizationColorBalance() {
return nativeProvider.getColorizationColorBalance();
}
}
}

View File

@@ -22,7 +22,11 @@ import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.Icon;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.border.Border;
@@ -88,6 +92,7 @@ public class FlatOptionPaneUI
protected int messagePadding;
protected int maxCharactersPerLine;
private int focusWidth;
private boolean sameSizeButtons;
public static ComponentUI createUI( JComponent c ) {
return new FlatOptionPaneUI();
@@ -101,6 +106,7 @@ public class FlatOptionPaneUI
messagePadding = UIManager.getInt( "OptionPane.messagePadding" );
maxCharactersPerLine = UIManager.getInt( "OptionPane.maxCharactersPerLine" );
focusWidth = UIManager.getInt( "Component.focusWidth" );
sameSizeButtons = FlatUIUtils.getUIBoolean( "OptionPane.sameSizeButtons", true );
}
@Override
@@ -157,15 +163,40 @@ public class FlatOptionPaneUI
cons.insets.bottom = UIScale.scale( messagePadding );
// disable line wrapping for HTML
if( msg instanceof String && BasicHTML.isHTMLString( (String) msg ) )
maxll = Integer.MAX_VALUE;
if( msg != null &&
!(msg instanceof Component) &&
!(msg instanceof Object[]) &&
!(msg instanceof Icon) )
{
msg = msg.toString();
if( BasicHTML.isHTMLString( (String) msg ) )
maxll = Integer.MAX_VALUE;
}
// fix right-to-left alignment if super.addMessageComponents() breaks longer lines
// into multiple labels and puts them into a box that aligns them to the left
if( msg instanceof Box ) {
Box box = (Box) msg;
if( "OptionPane.verticalBox".equals( box.getName() ) &&
box.getLayout() instanceof BoxLayout &&
((BoxLayout)box.getLayout()).getAxis() == BoxLayout.Y_AXIS )
{
box.addPropertyChangeListener( "componentOrientation", e -> {
float alignX = box.getComponentOrientation().isLeftToRight() ? 0 : 1;
for( Component c : box.getComponents() ) {
if( c instanceof JLabel && "OptionPane.label".equals( c.getName() ) )
((JLabel)c).setAlignmentX( alignX );
}
} );
}
}
super.addMessageComponents( container, cons, msg, maxll, internallyCreated );
}
private void updateChildPanels( Container c ) {
for( Component child : c.getComponents() ) {
if( child instanceof JPanel ) {
if( child.getClass() == JPanel.class ) {
JPanel panel = (JPanel)child;
// make sub-panel non-opaque for OptionPane.background
@@ -177,9 +208,8 @@ public class FlatOptionPaneUI
panel.setBorder( new NonUIResourceBorder( border ) );
}
if( child instanceof Container ) {
if( child instanceof Container )
updateChildPanels( (Container) child );
}
}
}
@@ -197,6 +227,11 @@ public class FlatOptionPaneUI
return null;
}
@Override
protected boolean getSizeButtonsToSameWidth() {
return sameSizeButtons;
}
//---- class NonUIResourceBorder ------------------------------------------
private static class NonUIResourceBorder

View File

@@ -16,30 +16,31 @@
package com.formdev.flatlaf.ui;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.Shape;
import java.awt.Toolkit;
import java.awt.event.FocusListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.beans.PropertyChangeEvent;
import javax.swing.Action;
import javax.swing.ActionMap;
import javax.swing.Icon;
import javax.swing.JComponent;
import javax.swing.LookAndFeel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicPasswordFieldUI;
import javax.swing.text.Caret;
import javax.swing.text.DefaultEditorKit;
import javax.swing.text.Element;
import javax.swing.text.JTextComponent;
import com.formdev.flatlaf.util.HiDPIUtils;
import javax.swing.text.PasswordView;
import javax.swing.text.View;
/**
* Provides the Flat LaF UI delegate for {@link javax.swing.JPasswordField}.
*
* <!-- BasicPasswordFieldUI -->
* <!-- BasicTextFieldUI -->
*
* @uiDefault PasswordField.font Font
* @uiDefault PasswordField.background Color
@@ -52,68 +53,67 @@ import com.formdev.flatlaf.util.HiDPIUtils;
* @uiDefault PasswordField.inactiveForeground Color used if not enabled (yes, this is confusing; this should be named disabledForeground)
* @uiDefault PasswordField.border Border
* @uiDefault PasswordField.margin Insets
* @uiDefault PasswordField.echoChar character
* @uiDefault PasswordField.caretBlinkRate int default is 500 milliseconds
*
* <!-- FlatPasswordFieldUI -->
* <!-- FlatTextFieldUI -->
*
* @uiDefault Component.minimumWidth int
* @uiDefault Component.isIntelliJTheme boolean
* @uiDefault PasswordField.placeholderForeground Color
* @uiDefault PasswordField.showCapsLock boolean
* @uiDefault PasswordField.capsLockIcon Icon
* @uiDefault PasswordField.focusedBackground Color optional
* @uiDefault TextComponent.selectAllOnFocusPolicy String never, once (default) or always
* @uiDefault TextComponent.selectAllOnMouseClick boolean
*
* <!-- FlatPasswordFieldUI -->
*
* @uiDefault PasswordField.echoChar character
* @uiDefault PasswordField.showCapsLock boolean
* @uiDefault PasswordField.capsLockIcon Icon
*
* @author Karl Tauber
*/
public class FlatPasswordFieldUI
extends BasicPasswordFieldUI
extends FlatTextFieldUI
{
protected int minimumWidth;
protected boolean isIntelliJTheme;
protected Color placeholderForeground;
protected boolean showCapsLock;
protected Icon capsLockIcon;
private FocusListener focusListener;
private KeyListener capsLockListener;
public static ComponentUI createUI( JComponent c ) {
return new FlatPasswordFieldUI();
}
@Override
protected String getPropertyPrefix() {
return "PasswordField";
}
@Override
protected void installDefaults() {
super.installDefaults();
String prefix = getPropertyPrefix();
minimumWidth = UIManager.getInt( "Component.minimumWidth" );
isIntelliJTheme = UIManager.getBoolean( "Component.isIntelliJTheme" );
placeholderForeground = UIManager.getColor( prefix + ".placeholderForeground" );
Character echoChar = (Character) UIManager.get( prefix + ".echoChar" );
if( echoChar != null )
LookAndFeel.installProperty( getComponent(), "echoChar", echoChar );
showCapsLock = UIManager.getBoolean( "PasswordField.showCapsLock" );
capsLockIcon = UIManager.getIcon( "PasswordField.capsLockIcon" );
LookAndFeel.installProperty( getComponent(), "opaque", false );
MigLayoutVisualPadding.install( getComponent() );
}
@Override
protected void uninstallDefaults() {
super.uninstallDefaults();
placeholderForeground = null;
capsLockIcon = null;
MigLayoutVisualPadding.uninstall( getComponent() );
}
@Override
protected void installListeners() {
super.installListeners();
focusListener = new FlatUIUtils.RepaintFocusListener( getComponent() );
// update caps lock indicator
capsLockListener = new KeyAdapter() {
@Override
public void keyPressed( KeyEvent e ) {
@@ -124,12 +124,13 @@ public class FlatPasswordFieldUI
repaint( e );
}
private void repaint( KeyEvent e ) {
if( e.getKeyCode() == KeyEvent.VK_CAPS_LOCK )
if( e.getKeyCode() == KeyEvent.VK_CAPS_LOCK ) {
e.getComponent().repaint();
scrollCaretToVisible();
}
}
};
getComponent().addFocusListener( focusListener );
getComponent().addKeyListener( capsLockListener );
}
@@ -137,59 +138,74 @@ public class FlatPasswordFieldUI
protected void uninstallListeners() {
super.uninstallListeners();
getComponent().removeFocusListener( focusListener );
getComponent().removeKeyListener( capsLockListener );
focusListener = null;
capsLockListener = null;
}
@Override
protected Caret createCaret() {
return new FlatCaret( UIManager.getString( "TextComponent.selectAllOnFocusPolicy" ),
UIManager.getBoolean( "TextComponent.selectAllOnMouseClick" ) );
protected void installKeyboardActions() {
super.installKeyboardActions();
// map "select-word" action (double-click) to "select-line" action
ActionMap map = SwingUtilities.getUIActionMap( getComponent() );
if( map != null && map.get( DefaultEditorKit.selectWordAction ) != null ) {
Action selectLineAction = map.get( DefaultEditorKit.selectLineAction );
if( selectLineAction != null )
map.put( DefaultEditorKit.selectWordAction, selectLineAction );
}
}
@Override
protected void propertyChange( PropertyChangeEvent e ) {
super.propertyChange( e );
FlatTextFieldUI.propertyChange( getComponent(), e );
public View create( Element elem ) {
return new PasswordView( elem );
}
@Override
protected void paintSafely( Graphics g ) {
FlatTextFieldUI.paintBackground( g, getComponent(), isIntelliJTheme );
FlatTextFieldUI.paintPlaceholder( g, getComponent(), placeholderForeground );
paintCapsLock( g );
// safe and restore clipping area because super.paintSafely() modifies it
// and the caps lock icon would be truncated
Shape oldClip = g.getClip();
super.paintSafely( g );
g.setClip( oldClip );
super.paintSafely( HiDPIUtils.createGraphicsTextYCorrection( (Graphics2D) g ) );
paintCapsLock( g );
}
protected void paintCapsLock( Graphics g ) {
if( !showCapsLock )
if( !isCapsLockVisible() )
return;
JTextComponent c = getComponent();
if( !FlatUIUtils.isPermanentFocusOwner( c ) ||
!Toolkit.getDefaultToolkit().getLockingKeyState( KeyEvent.VK_CAPS_LOCK ) )
return;
int y = (c.getHeight() - capsLockIcon.getIconHeight()) / 2;
int x = c.getWidth() - capsLockIcon.getIconWidth() - y;
int x = c.getComponentOrientation().isLeftToRight()
? c.getWidth() - capsLockIcon.getIconWidth() - y
: y;
capsLockIcon.paintIcon( c, g, x, y );
}
@Override
protected void paintBackground( Graphics g ) {
// background is painted elsewhere
/**
* @since 1.4
*/
protected boolean isCapsLockVisible() {
if( !showCapsLock )
return false;
JTextComponent c = getComponent();
return FlatUIUtils.isPermanentFocusOwner( c ) &&
Toolkit.getDefaultToolkit().getLockingKeyState( KeyEvent.VK_CAPS_LOCK );
}
/**
* @since 1.4
*/
@Override
public Dimension getPreferredSize( JComponent c ) {
return FlatTextFieldUI.applyMinimumWidth( c, super.getPreferredSize( c ), minimumWidth );
}
protected Insets getPadding() {
Insets padding = super.getPadding();
if( !isCapsLockVisible() )
return padding;
@Override
public Dimension getMinimumSize( JComponent c ) {
return FlatTextFieldUI.applyMinimumWidth( c, super.getMinimumSize( c ), minimumWidth );
boolean ltr = getComponent().getComponentOrientation().isLeftToRight();
int iconWidth = capsLockIcon.getIconWidth();
return FlatUIUtils.addInsets( padding, new Insets( 0, ltr ? 0 : iconWidth, 0, ltr ? iconWidth : 0 ) );
}
}

View File

@@ -20,11 +20,16 @@ import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Insets;
import java.awt.MouseInfo;
import java.awt.Panel;
import java.awt.Point;
import java.awt.PointerInfo;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
@@ -39,6 +44,7 @@ import javax.swing.Popup;
import javax.swing.PopupFactory;
import javax.swing.RootPaneContainer;
import javax.swing.SwingUtilities;
import javax.swing.ToolTipManager;
import javax.swing.UIManager;
import javax.swing.border.Border;
import com.formdev.flatlaf.FlatClientProperties;
@@ -70,7 +76,7 @@ public class FlatPopupFactory
boolean forceHeavyWeight = isOptionEnabled( owner, contents, FlatClientProperties.POPUP_FORCE_HEAVY_WEIGHT, "Popup.forceHeavyWeight" );
if( !isOptionEnabled( owner, contents, FlatClientProperties.POPUP_DROP_SHADOW_PAINTED, "Popup.dropShadowPainted" ) )
if( !isOptionEnabled( owner, contents, FlatClientProperties.POPUP_DROP_SHADOW_PAINTED, "Popup.dropShadowPainted" ) || SystemInfo.isProjector || SystemInfo.isWebswing )
return new NonFlashingPopup( getPopupForScreenOfOwner( owner, contents, x, y, forceHeavyWeight ), contents );
// macOS and Linux adds drop shadow to heavy weight popups
@@ -111,6 +117,7 @@ public class FlatPopupFactory
// check whether heavy weight popup window is on same screen as owner component
if( popupWindow == null ||
owner == null ||
popupWindow.getGraphicsConfiguration() == owner.getGraphicsConfiguration() )
return popup;
@@ -205,7 +212,7 @@ public class FlatPopupFactory
/**
* Usually ToolTipManager places a tooltip at (mouseLocation.x, mouseLocation.y + 20).
* In case that the tooltip would be partly outside of the screen,
* ToolTipManagerthe changes the location so that the entire tooltip fits on screen.
* the ToolTipManager changes the location so that the entire tooltip fits on screen.
* But this can place the tooltip under the mouse location and hide the owner component.
* <p>
* This method checks whether the current mouse location is within tooltip bounds
@@ -215,7 +222,11 @@ public class FlatPopupFactory
if( !(contents instanceof JToolTip) || !wasInvokedFromToolTipManager() )
return null;
Point mouseLocation = MouseInfo.getPointerInfo().getLocation();
PointerInfo pointerInfo = MouseInfo.getPointerInfo();
if( pointerInfo == null )
return null;
Point mouseLocation = pointerInfo.getLocation();
Dimension tipSize = contents.getPreferredSize();
// check whether mouse location is within tooltip bounds
@@ -223,18 +234,34 @@ public class FlatPopupFactory
if( !tipBounds.contains( mouseLocation ) )
return null;
// place tooltip above mouse location
return new Point( x, mouseLocation.y - tipSize.height - UIScale.scale( 20 ) );
// find GraphicsConfiguration at mouse location (similar to ToolTipManager.getDrawingGC())
GraphicsConfiguration gc = null;
for( GraphicsDevice device : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices() ) {
GraphicsConfiguration dgc = device.getDefaultConfiguration();
if( dgc.getBounds().contains( mouseLocation ) ) {
gc = dgc;
break;
}
}
if( gc == null )
gc = owner.getGraphicsConfiguration();
if( gc == null )
return null;
Rectangle screenBounds = gc.getBounds();
Insets screenInsets = Toolkit.getDefaultToolkit().getScreenInsets( gc );
int screenTop = screenBounds.y + screenInsets.top;
// place tooltip above mouse location if there is enough space
int newY = mouseLocation.y - tipSize.height - UIScale.scale( 20 );
if( newY < screenTop )
return null;
return new Point( x, newY );
}
private boolean wasInvokedFromToolTipManager() {
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
for( StackTraceElement stackTraceElement : stackTrace ) {
if( "javax.swing.ToolTipManager".equals( stackTraceElement.getClassName() ) &&
"showTipWindow".equals( stackTraceElement.getMethodName() ) )
return true;
}
return false;
return StackUtils.wasInvokedFrom( ToolTipManager.class.getName(), "showTipWindow", 8 );
}
//---- class NonFlashingPopup ---------------------------------------------
@@ -450,10 +477,10 @@ public class FlatPopupFactory
mediumWeightShown = true;
Window window = SwingUtilities.windowForComponent( owner );
if( window == null )
if( owner == null )
return;
Window window = SwingUtilities.windowForComponent( owner );
if( !(window instanceof RootPaneContainer) )
return;
@@ -462,6 +489,9 @@ public class FlatPopupFactory
JLayeredPane layeredPane = ((RootPaneContainer)window).getLayeredPane();
layeredPane.add( dropShadowPanel, JLayeredPane.POPUP_LAYER, 0 );
moveMediumWeightDropShadow();
resizeMediumWeightDropShadow();
mediumPanelListener = new ComponentListener() {
@Override
public void componentShown( ComponentEvent e ) {
@@ -477,17 +507,12 @@ public class FlatPopupFactory
@Override
public void componentMoved( ComponentEvent e ) {
if( dropShadowPanel != null && mediumWeightPanel != null ) {
Point location = mediumWeightPanel.getLocation();
Insets insets = dropShadowPanel.getInsets();
dropShadowPanel.setLocation( location.x - insets.left, location.y - insets.top );
}
moveMediumWeightDropShadow();
}
@Override
public void componentResized( ComponentEvent e ) {
if( dropShadowPanel != null )
dropShadowPanel.setSize( FlatUIUtils.addInsets( mediumWeightPanel.getSize(), dropShadowPanel.getInsets() ) );
resizeMediumWeightDropShadow();
}
};
mediumWeightPanel.addComponentListener( mediumPanelListener );
@@ -503,5 +528,18 @@ public class FlatPopupFactory
parent.repaint( bounds.x, bounds.y, bounds.width, bounds.height );
}
}
private void moveMediumWeightDropShadow() {
if( dropShadowPanel != null && mediumWeightPanel != null ) {
Point location = mediumWeightPanel.getLocation();
Insets insets = dropShadowPanel.getInsets();
dropShadowPanel.setLocation( location.x - insets.left, location.y - insets.top );
}
}
private void resizeMediumWeightDropShadow() {
if( dropShadowPanel != null && mediumWeightPanel != null )
dropShadowPanel.setSize( FlatUIUtils.addInsets( mediumWeightPanel.getSize(), dropShadowPanel.getInsets() ) );
}
}
}

View File

@@ -24,8 +24,8 @@ import javax.swing.plaf.ComponentUI;
*
* <!-- BasicSeparatorUI -->
*
* @uiDefault PopupMenuSeparator.background Color unused
* @uiDefault PopupMenuSeparator.foreground Color
* @uiDefault Separator.background Color unused
* @uiDefault Separator.foreground Color
*
* <!-- FlatSeparatorUI -->
*

View File

@@ -18,16 +18,18 @@ package com.formdev.flatlaf.ui;
import static com.formdev.flatlaf.util.UIScale.scale;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.Rectangle;
import java.util.Objects;
import javax.swing.AbstractButton;
import javax.swing.CellRendererPane;
import javax.swing.JComponent;
import javax.swing.LookAndFeel;
import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.UIResource;
import javax.swing.plaf.basic.BasicRadioButtonUI;
import com.formdev.flatlaf.icons.FlatCheckBoxIcon;
import com.formdev.flatlaf.util.UIScale;
@@ -58,6 +60,8 @@ public class FlatRadioButtonUI
protected int iconTextGap;
protected Color disabledText;
private Color defaultBackground;
private boolean defaults_initialized = false;
public static ComponentUI createUI( JComponent c ) {
@@ -74,6 +78,8 @@ public class FlatRadioButtonUI
iconTextGap = FlatUIUtils.getUIInt( prefix + "iconTextGap", 4 );
disabledText = UIManager.getColor( prefix + "disabledText" );
defaultBackground = UIManager.getColor( prefix + "background" );
defaults_initialized = true;
}
@@ -117,10 +123,11 @@ public class FlatRadioButtonUI
public void paint( Graphics g, JComponent c ) {
// fill background even if not opaque if
// - contentAreaFilled is true and
// - if background was explicitly set to a non-UIResource color
// - if background color is different to default background color
// (this paints selection if using the component as cell renderer)
if( !c.isOpaque() &&
((AbstractButton)c).isContentAreaFilled() &&
!(c.getBackground() instanceof UIResource) )
!Objects.equals( c.getBackground(), getDefaultBackground( c ) ) )
{
g.setColor( c.getBackground() );
g.fillRect( 0, 0, c.getWidth(), c.getHeight() );
@@ -157,6 +164,18 @@ public class FlatRadioButtonUI
FlatButtonUI.paintText( g, b, textRect, text, b.isEnabled() ? b.getForeground() : disabledText );
}
/**
* Returns the default background color of the component.
* If the component is used as cell renderer (e.g. in JTable),
* then the background color of the renderer container is returned.
*/
private Color getDefaultBackground( JComponent c ) {
Container parent = c.getParent();
return (parent instanceof CellRendererPane && parent.getParent() != null)
? parent.getParent().getBackground()
: defaultBackground;
}
private int getIconFocusWidth( JComponent c ) {
AbstractButton b = (AbstractButton) c;
return (b.getIcon() == null && getDefaultIcon() instanceof FlatCheckBoxIcon)

View File

@@ -27,7 +27,11 @@ import java.awt.Insets;
import java.awt.LayoutManager;
import java.awt.LayoutManager2;
import java.awt.Window;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.function.Function;
import javax.swing.JComponent;
import javax.swing.JDialog;
@@ -36,10 +40,12 @@ import javax.swing.JLayeredPane;
import javax.swing.JMenuBar;
import javax.swing.JRootPane;
import javax.swing.LookAndFeel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.plaf.BorderUIResource;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.RootPaneUI;
import javax.swing.plaf.UIResource;
import javax.swing.plaf.basic.BasicRootPaneUI;
import com.formdev.flatlaf.FlatClientProperties;
@@ -70,17 +76,16 @@ import com.formdev.flatlaf.util.UIScale;
public class FlatRootPaneUI
extends BasicRootPaneUI
{
// check this field before using class JBRCustomDecorations to avoid unnecessary loading of that class
static final boolean canUseJBRCustomDecorations
= SystemInfo.isJetBrainsJVM_11_orLater && SystemInfo.isWindows_10_orLater;
protected final Color borderColor = UIManager.getColor( "TitlePane.borderColor" );
protected JRootPane rootPane;
protected FlatTitlePane titlePane;
protected FlatWindowResizer windowResizer;
private Object nativeWindowBorderData;
private LayoutManager oldLayout;
private PropertyChangeListener ancestorListener;
private ComponentListener componentListener;
public static ComponentUI createUI( JComponent c ) {
return new FlatRootPaneUI();
@@ -97,8 +102,7 @@ public class FlatRootPaneUI
else
installBorder();
if( canUseJBRCustomDecorations )
JBRCustomDecorations.install( rootPane );
installNativeWindowBorder();
}
protected void installBorder() {
@@ -113,6 +117,7 @@ public class FlatRootPaneUI
public void uninstallUI( JComponent c ) {
super.uninstallUI( c );
uninstallNativeWindowBorder();
uninstallClientDecorations();
rootPane = null;
}
@@ -138,11 +143,94 @@ public class FlatRootPaneUI
c.putClientProperty( "jetbrains.awt.windowDarkAppearance", FlatLaf.isLafDark() );
}
@Override
protected void installListeners( JRootPane root ) {
super.installListeners( root );
if( SystemInfo.isJava_9_orLater ) {
// On HiDPI screens, where scaling is used, there may be white lines at the
// bottom and at the right side of the window when it is initially shown.
// This is very disturbing in dark themes, but hard to notice in light themes.
// Seems to be a rounding issue when Swing adds dirty region of window
// using RepaintManager.nativeAddDirtyRegion().
//
// Note: Not using a HierarchyListener here, which would be much easier,
// because this causes problems with mouse clicks in heavy-weight popups.
// Instead, add a listener to the root pane that waits until it is added
// to a window, then add a component listener to the window.
// See: https://github.com/JFormDesigner/FlatLaf/issues/371
ancestorListener = e -> {
Object oldValue = e.getOldValue();
Object newValue = e.getNewValue();
if( newValue instanceof Window ) {
if( componentListener == null ) {
componentListener = new ComponentAdapter() {
@Override
public void componentShown( ComponentEvent e ) {
// add whole root pane to dirty regions when window is initially shown
root.getParent().repaint( root.getX(), root.getY(), root.getWidth(), root.getHeight() );
}
};
}
((Window)newValue).addComponentListener( componentListener );
} else if( newValue == null && oldValue instanceof Window ) {
if( componentListener != null )
((Window)oldValue).removeComponentListener( componentListener );
}
};
root.addPropertyChangeListener( "ancestor", ancestorListener );
}
}
@Override
protected void uninstallListeners( JRootPane root ) {
super.uninstallListeners( root );
if( SystemInfo.isJava_9_orLater ) {
if( componentListener != null ) {
Window window = SwingUtilities.windowForComponent( root );
if( window != null )
window.removeComponentListener( componentListener );
componentListener = null;
}
root.removePropertyChangeListener( "ancestor", ancestorListener );
ancestorListener = null;
}
}
/**
* @since 1.1.2
*/
protected void installNativeWindowBorder() {
nativeWindowBorderData = FlatNativeWindowBorder.install( rootPane );
}
/**
* @since 1.1.2
*/
protected void uninstallNativeWindowBorder() {
FlatNativeWindowBorder.uninstall( rootPane, nativeWindowBorderData );
nativeWindowBorderData = null;
}
/**
* @since 1.1.2
*/
public static void updateNativeWindowBorder( JRootPane rootPane ) {
RootPaneUI rui = rootPane.getUI();
if( !(rui instanceof FlatRootPaneUI) )
return;
FlatRootPaneUI ui = (FlatRootPaneUI) rui;
ui.uninstallNativeWindowBorder();
ui.installNativeWindowBorder();
}
protected void installClientDecorations() {
boolean isJBRSupported = canUseJBRCustomDecorations && JBRCustomDecorations.isSupported();
boolean isNativeWindowBorderSupported = FlatNativeWindowBorder.isSupported();
// install border
if( rootPane.getWindowDecorationStyle() != JRootPane.NONE && !isJBRSupported )
if( rootPane.getWindowDecorationStyle() != JRootPane.NONE && !isNativeWindowBorderSupported )
LookAndFeel.installBorder( rootPane, "RootPane.border" );
else
LookAndFeel.uninstallBorder( rootPane );
@@ -155,7 +243,7 @@ public class FlatRootPaneUI
rootPane.setLayout( createRootLayout() );
// install window resizer
if( !isJBRSupported )
if( !isNativeWindowBorderSupported )
windowResizer = createWindowResizer();
}
@@ -219,6 +307,10 @@ public class FlatRootPaneUI
installBorder();
break;
case FlatClientProperties.USE_WINDOW_DECORATIONS:
updateNativeWindowBorder( rootPane );
break;
case FlatClientProperties.MENU_BAR_EMBEDDED:
if( titlePane != null ) {
titlePane.menuBarChanged();
@@ -226,9 +318,22 @@ public class FlatRootPaneUI
rootPane.repaint();
}
break;
case FlatClientProperties.TITLE_BAR_BACKGROUND:
case FlatClientProperties.TITLE_BAR_FOREGROUND:
if( titlePane != null )
titlePane.titleBarColorsChanged();
break;
}
}
protected static boolean isMenuBarEmbedded( JRootPane rootPane ) {
RootPaneUI ui = rootPane.getUI();
return ui instanceof FlatRootPaneUI &&
((FlatRootPaneUI)ui).titlePane != null &&
((FlatRootPaneUI)ui).titlePane.isMenuBarEmbedded();
}
//---- class FlatRootLayout -----------------------------------------------
protected class FlatRootLayout
@@ -263,7 +368,7 @@ public class FlatRootPaneUI
? getSizeFunc.apply( rootPane.getContentPane() )
: rootPane.getSize();
int width = Math.max( titlePaneSize.width, contentSize.width );
int width = contentSize.width; // title pane width is not considered here
int height = titlePaneSize.height + contentSize.height;
if( titlePane == null || !titlePane.isMenuBarEmbedded() ) {
JMenuBar menuBar = rootPane.getJMenuBar();
@@ -299,15 +404,16 @@ public class FlatRootPaneUI
rootPane.getGlassPane().setBounds( x, y, width, height );
int nextY = 0;
if( !isFullScreen && titlePane != null ) {
Dimension prefSize = titlePane.getPreferredSize();
titlePane.setBounds( 0, 0, width, prefSize.height );
nextY += prefSize.height;
if( titlePane != null ) {
int prefHeight = !isFullScreen ? titlePane.getPreferredSize().height : 0;
titlePane.setBounds( 0, 0, width, prefHeight );
nextY += prefHeight;
}
JMenuBar menuBar = rootPane.getJMenuBar();
if( menuBar != null && menuBar.isVisible() ) {
if( !isFullScreen && titlePane != null && titlePane.isMenuBarEmbedded() ) {
boolean embedded = !isFullScreen && titlePane != null && titlePane.isMenuBarEmbedded();
if( embedded ) {
titlePane.validate();
menuBar.setBounds( titlePane.getMenuBarBounds() );
} else {
@@ -344,6 +450,9 @@ public class FlatRootPaneUI
//---- class FlatWindowBorder ---------------------------------------------
/**
* Window border used for non-native window decorations.
*/
public static class FlatWindowBorder
extends BorderUIResource.EmptyBorderUIResource
{
@@ -358,7 +467,7 @@ public class FlatRootPaneUI
@Override
public Insets getBorderInsets( Component c, Insets insets ) {
if( isWindowMaximized( c ) || FlatUIUtils.isFullScreen( c ) ) {
// hide border if window is maximized
// hide border if window is maximized or full screen
insets.top = insets.left = insets.bottom = insets.right = 0;
return insets;
} else
@@ -421,7 +530,9 @@ public class FlatRootPaneUI
(parent instanceof JFrame &&
(((JFrame)parent).getJMenuBar() == null ||
!((JFrame)parent).getJMenuBar().isVisible())) ||
parent instanceof JDialog;
(parent instanceof JDialog &&
(((JDialog)parent).getJMenuBar() == null ||
!((JDialog)parent).getJMenuBar().isVisible()));
}
}
}

View File

@@ -23,7 +23,6 @@ import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Objects;
import javax.swing.InputMap;
@@ -168,30 +167,28 @@ public class FlatScrollBarUI
@Override
protected PropertyChangeListener createPropertyChangeListener() {
return new BasicScrollBarUI.PropertyChangeHandler() {
@Override
public void propertyChange( PropertyChangeEvent e ) {
super.propertyChange( e );
PropertyChangeListener superListener = super.createPropertyChangeListener();
return e -> {
superListener.propertyChange( e );
switch( e.getPropertyName() ) {
case FlatClientProperties.SCROLL_BAR_SHOW_BUTTONS:
scrollbar.revalidate();
scrollbar.repaint();
break;
switch( e.getPropertyName() ) {
case FlatClientProperties.SCROLL_BAR_SHOW_BUTTONS:
scrollbar.revalidate();
scrollbar.repaint();
break;
case "componentOrientation":
// this is missing in BasicScrollBarUI.Handler.propertyChange()
InputMap inputMap = (InputMap) UIManager.get( "ScrollBar.ancestorInputMap" );
if( !scrollbar.getComponentOrientation().isLeftToRight() ) {
InputMap rtlInputMap = (InputMap) UIManager.get( "ScrollBar.ancestorInputMap.RightToLeft" );
if( rtlInputMap != null ) {
rtlInputMap.setParent( inputMap );
inputMap = rtlInputMap;
}
case "componentOrientation":
// this is missing in BasicScrollBarUI.Handler.propertyChange()
InputMap inputMap = (InputMap) UIManager.get( "ScrollBar.ancestorInputMap" );
if( !scrollbar.getComponentOrientation().isLeftToRight() ) {
InputMap rtlInputMap = (InputMap) UIManager.get( "ScrollBar.ancestorInputMap.RightToLeft" );
if( rtlInputMap != null ) {
rtlInputMap.setParent( inputMap );
inputMap = rtlInputMap;
}
SwingUtilities.replaceUIInputMap( scrollbar, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, inputMap );
break;
}
}
SwingUtilities.replaceUIInputMap( scrollbar, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, inputMap );
break;
}
};
}

View File

@@ -19,6 +19,7 @@ package com.formdev.flatlaf.ui;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.KeyboardFocusManager;
import java.awt.Rectangle;
import java.awt.event.ContainerEvent;
import java.awt.event.ContainerListener;
@@ -34,11 +35,13 @@ import javax.swing.JComponent;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTree;
import javax.swing.JViewport;
import javax.swing.LookAndFeel;
import javax.swing.ScrollPaneConstants;
import javax.swing.Scrollable;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicScrollPaneUI;
@@ -105,19 +108,17 @@ public class FlatScrollPaneUI
@Override
protected MouseWheelListener createMouseWheelListener() {
return new BasicScrollPaneUI.MouseWheelHandler() {
@Override
public void mouseWheelMoved( MouseWheelEvent e ) {
if( isSmoothScrollingEnabled() &&
scrollpane.isWheelScrollingEnabled() &&
e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL &&
e.getPreciseWheelRotation() != 0 &&
e.getPreciseWheelRotation() != e.getWheelRotation() )
{
mouseWheelMovedSmooth( e );
} else
super.mouseWheelMoved( e );
}
MouseWheelListener superListener = super.createMouseWheelListener();
return e -> {
if( isSmoothScrollingEnabled() &&
scrollpane.isWheelScrollingEnabled() &&
e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL &&
e.getPreciseWheelRotation() != 0 &&
e.getPreciseWheelRotation() != e.getWheelRotation() )
{
mouseWheelMovedSmooth( e );
} else
superListener.mouseWheelMoved( e );
};
}
@@ -239,41 +240,39 @@ public class FlatScrollPaneUI
@Override
protected PropertyChangeListener createPropertyChangeListener() {
return new BasicScrollPaneUI.PropertyChangeHandler() {
@Override
public void propertyChange( PropertyChangeEvent e ) {
super.propertyChange( e );
PropertyChangeListener superListener = super.createPropertyChangeListener();
return e -> {
superListener.propertyChange( e );
switch( e.getPropertyName() ) {
case FlatClientProperties.SCROLL_BAR_SHOW_BUTTONS:
JScrollBar vsb = scrollpane.getVerticalScrollBar();
JScrollBar hsb = scrollpane.getHorizontalScrollBar();
if( vsb != null ) {
vsb.revalidate();
vsb.repaint();
}
if( hsb != null ) {
hsb.revalidate();
hsb.repaint();
}
break;
case ScrollPaneConstants.LOWER_LEFT_CORNER:
case ScrollPaneConstants.LOWER_RIGHT_CORNER:
case ScrollPaneConstants.UPPER_LEFT_CORNER:
case ScrollPaneConstants.UPPER_RIGHT_CORNER:
// remove border from buttons added to corners
Object corner = e.getNewValue();
if( corner instanceof JButton &&
((JButton)corner).getBorder() instanceof FlatButtonBorder &&
scrollpane.getViewport() != null &&
scrollpane.getViewport().getView() instanceof JTable )
{
((JButton)corner).setBorder( BorderFactory.createEmptyBorder() );
((JButton)corner).setFocusable( false );
}
switch( e.getPropertyName() ) {
case FlatClientProperties.SCROLL_BAR_SHOW_BUTTONS:
JScrollBar vsb = scrollpane.getVerticalScrollBar();
JScrollBar hsb = scrollpane.getHorizontalScrollBar();
if( vsb != null ) {
vsb.revalidate();
vsb.repaint();
}
if( hsb != null ) {
hsb.revalidate();
hsb.repaint();
}
break;
}
case ScrollPaneConstants.LOWER_LEFT_CORNER:
case ScrollPaneConstants.LOWER_RIGHT_CORNER:
case ScrollPaneConstants.UPPER_LEFT_CORNER:
case ScrollPaneConstants.UPPER_RIGHT_CORNER:
// remove border from buttons added to corners
Object corner = e.getNewValue();
if( corner instanceof JButton &&
((JButton)corner).getBorder() instanceof FlatButtonBorder &&
scrollpane.getViewport() != null &&
scrollpane.getViewport().getView() instanceof JTable )
{
((JButton)corner).setBorder( BorderFactory.createEmptyBorder() );
((JButton)corner).setFocusable( false );
}
break;
}
};
}
@@ -333,6 +332,31 @@ public class FlatScrollPaneUI
paint( g, c );
}
/**
* @since 1.3
*/
public static boolean isPermanentFocusOwner( JScrollPane scrollPane ) {
JViewport viewport = scrollPane.getViewport();
Component view = (viewport != null) ? viewport.getView() : null;
if( view == null )
return false;
// check whether view is focus owner
if( FlatUIUtils.isPermanentFocusOwner( view ) )
return true;
// check whether editor component in JTable or JTree is focus owner
if( (view instanceof JTable && ((JTable)view).isEditing()) ||
(view instanceof JTree && ((JTree)view).isEditing()) )
{
Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
if( focusOwner != null )
return SwingUtilities.isDescendingFrom( focusOwner, view );
}
return false;
}
//---- class Handler ------------------------------------------------------
/**
@@ -354,11 +378,13 @@ public class FlatScrollPaneUI
@Override
public void focusGained( FocusEvent e ) {
// necessary to update focus border
scrollpane.repaint();
}
@Override
public void focusLost( FocusEvent e ) {
// necessary to update focus border
scrollpane.repaint();
}
}

View File

@@ -18,9 +18,11 @@ package com.formdev.flatlaf.ui;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.event.MouseEvent;
@@ -176,9 +178,27 @@ public class FlatSliderUI
if( slider.getOrientation() == JSlider.VERTICAL )
return -1;
// use default font (instead of slider font) because the slider font size
// may be different to label font size, but we want align the track/thumb with labels
Font font = UIManager.getFont( "defaultFont" );
if( font == null )
font = slider.getFont();
FontMetrics fm = slider.getFontMetrics( font );
// calculate track y coordinate and height
// (not using field trackRect here because slider size may be [0,0]
// and field trackRect may have invalid values in this case)
Insets insets = slider.getInsets();
int thumbHeight = getThumbSize().height;
int contentHeight = height - insets.top - insets.bottom - focusInsets.top - focusInsets.bottom;
int centerSpacing = thumbHeight
+ (slider.getPaintTicks() ? getTickLength() : 0)
+ (slider.getPaintLabels() ? getHeightOfTallestLabel() : 0);
int trackY = insets.top + focusInsets.top + (contentHeight - centerSpacing - 1) / 2;
int trackHeight = thumbHeight;
// compute a baseline so that the track is vertically centered
FontMetrics fm = slider.getFontMetrics( slider.getFont() );
return trackRect.y + Math.round( (trackRect.height - fm.getHeight()) / 2f ) + fm.getAscent() - 1;
return trackY + Math.round( (trackHeight - fm.getHeight()) / 2f ) + fm.getAscent() - 1;
}
@Override

View File

@@ -21,6 +21,7 @@ import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
@@ -39,6 +40,7 @@ import javax.swing.LookAndFeel;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.UIResource;
import javax.swing.plaf.basic.BasicSpinnerUI;
import com.formdev.flatlaf.FlatClientProperties;
@@ -65,6 +67,7 @@ import com.formdev.flatlaf.FlatClientProperties;
* @uiDefault Component.disabledBorderColor Color
* @uiDefault Spinner.disabledBackground Color
* @uiDefault Spinner.disabledForeground Color
* @uiDefault Spinner.focusedBackground Color optional
* @uiDefault Spinner.buttonBackground Color
* @uiDefault Spinner.buttonArrowColor Color
* @uiDefault Spinner.buttonDisabledArrowColor Color
@@ -87,6 +90,7 @@ public class FlatSpinnerUI
protected Color disabledBorderColor;
protected Color disabledBackground;
protected Color disabledForeground;
protected Color focusedBackground;
protected Color buttonBackground;
protected Color buttonArrowColor;
protected Color buttonDisabledArrowColor;
@@ -112,6 +116,7 @@ public class FlatSpinnerUI
disabledBorderColor = UIManager.getColor( "Component.disabledBorderColor" );
disabledBackground = UIManager.getColor( "Spinner.disabledBackground" );
disabledForeground = UIManager.getColor( "Spinner.disabledForeground" );
focusedBackground = UIManager.getColor( "Spinner.focusedBackground" );
buttonBackground = UIManager.getColor( "Spinner.buttonBackground" );
buttonArrowColor = UIManager.getColor( "Spinner.buttonArrowColor" );
buttonDisabledArrowColor = UIManager.getColor( "Spinner.buttonDisabledArrowColor" );
@@ -119,9 +124,6 @@ public class FlatSpinnerUI
buttonPressedArrowColor = UIManager.getColor( "Spinner.buttonPressedArrowColor" );
padding = UIManager.getInsets( "Spinner.padding" );
// scale
padding = scale( padding );
MigLayoutVisualPadding.install( spinner );
}
@@ -133,6 +135,7 @@ public class FlatSpinnerUI
disabledBorderColor = null;
disabledBackground = null;
disabledForeground = null;
focusedBackground = null;
buttonBackground = null;
buttonArrowColor = null;
buttonDisabledArrowColor = null;
@@ -172,14 +175,7 @@ public class FlatSpinnerUI
@Override
protected JComponent createEditor() {
JComponent editor = super.createEditor();
// explicitly make non-opaque
editor.setOpaque( false );
JTextField textField = getEditorTextField( editor );
if( textField != null )
textField.setOpaque( false );
updateEditorColors();
configureEditor( editor );
return editor;
}
@@ -187,8 +183,21 @@ public class FlatSpinnerUI
protected void replaceEditor( JComponent oldEditor, JComponent newEditor ) {
super.replaceEditor( oldEditor, newEditor );
configureEditor( newEditor );
removeEditorFocusListener( oldEditor );
addEditorFocusListener( newEditor );
}
/** @since 1.6 */
protected void configureEditor( JComponent editor ) {
// explicitly make non-opaque
editor.setOpaque( false );
JTextField textField = getEditorTextField( editor );
if( textField != null )
textField.setOpaque( false );
updateEditorPadding();
updateEditorColors();
}
@@ -204,6 +213,12 @@ public class FlatSpinnerUI
textField.removeFocusListener( getHandler() );
}
private void updateEditorPadding() {
JTextField textField = getEditorTextField( spinner.getEditor() );
if( textField != null )
textField.putClientProperty( FlatClientProperties.TEXT_FIELD_PADDING, padding );
}
private void updateEditorColors() {
JTextField textField = getEditorTextField( spinner.getEditor() );
if( textField != null ) {
@@ -221,10 +236,34 @@ public class FlatSpinnerUI
: null;
}
/**
* @since 1.3
*/
public static boolean isPermanentFocusOwner( JSpinner spinner ) {
if( FlatUIUtils.isPermanentFocusOwner( spinner ) )
return true;
JTextField textField = getEditorTextField( spinner.getEditor() );
return (textField != null)
? FlatUIUtils.isPermanentFocusOwner( textField )
: false;
}
protected Color getBackground( boolean enabled ) {
return enabled
? spinner.getBackground()
: (isIntelliJTheme ? FlatUIUtils.getParentBackground( spinner ) : disabledBackground);
if( enabled ) {
Color background = spinner.getBackground();
// always use explicitly set color
if( !(background instanceof UIResource) )
return background;
// focused
if( focusedBackground != null && isPermanentFocusOwner( spinner ) )
return focusedBackground;
return background;
} else
return isIntelliJTheme ? FlatUIUtils.getParentBackground( spinner ) : disabledBackground;
}
protected Color getForeground( boolean enabled ) {
@@ -250,7 +289,7 @@ public class FlatSpinnerUI
FlatArrowButton button = new FlatArrowButton( direction, arrowType, buttonArrowColor,
buttonDisabledArrowColor, buttonHoverArrowColor, null, buttonPressedArrowColor, null );
button.setName( name );
button.setYOffset( (direction == SwingConstants.NORTH) ? 1 : -1 );
button.setYOffset( (direction == SwingConstants.NORTH) ? 1.25f : -1.25f );
if( direction == SwingConstants.NORTH )
installNextButtonListeners( button );
else
@@ -344,6 +383,7 @@ public class FlatSpinnerUI
@Override
public Dimension preferredLayoutSize( Container parent ) {
Insets insets = parent.getInsets();
Insets padding = scale( FlatSpinnerUI.this.padding );
Dimension editorSize = (editor != null) ? editor.getPreferredSize() : new Dimension( 0, 0 );
// the arrows width is the same as the inner height so that the arrows area is square
@@ -368,15 +408,19 @@ public class FlatSpinnerUI
if( nextButton == null && previousButton == null ) {
if( editor != null )
editor.setBounds( FlatUIUtils.subtractInsets( r, padding ) );
editor.setBounds( r );
return;
}
Rectangle editorRect = new Rectangle( r );
Rectangle buttonsRect = new Rectangle( r );
// make button area square
int buttonsWidth = r.height;
// limit buttons width to height of a raw spinner (without insets)
FontMetrics fm = spinner.getFontMetrics( spinner.getFont() );
int maxButtonWidth = fm.getHeight() + scale( padding.top ) + scale( padding.bottom );
// make button area square (if spinner has preferred height)
int buttonsWidth = Math.min( parent.getPreferredSize().height - insets.top - insets.bottom, maxButtonWidth );
buttonsRect.width = buttonsWidth;
if( parent.getComponentOrientation().isLeftToRight() ) {
@@ -388,7 +432,7 @@ public class FlatSpinnerUI
}
if( editor != null )
editor.setBounds( FlatUIUtils.subtractInsets( editorRect, padding ) );
editor.setBounds( editorRect );
int nextHeight = (buttonsRect.height / 2) + (buttonsRect.height % 2); // round up
if( nextButton != null )
@@ -405,6 +449,7 @@ public class FlatSpinnerUI
@Override
public void focusGained( FocusEvent e ) {
// necessary to update focus border
spinner.repaint();
// if spinner gained focus, transfer it to the editor text field
@@ -417,6 +462,7 @@ public class FlatSpinnerUI
@Override
public void focusLost( FocusEvent e ) {
// necessary to update focus border
spinner.repaint();
}

View File

@@ -46,10 +46,13 @@ import com.formdev.flatlaf.util.UIScale;
* @uiDefault SplitPaneDivider.border Border
* @uiDefault SplitPaneDivider.draggingColor Color only used if continuousLayout is false
*
* <!-- JSplitPane -->
*
* @uiDefault SplitPane.continuousLayout boolean
*
* <!-- FlatSplitPaneUI -->
*
* @uiDefault Component.arrowType String chevron (default) or triangle
* @uiDefault SplitPane.continuousLayout boolean
* @uiDefault SplitPaneDivider.oneTouchArrowColor Color
* @uiDefault SplitPaneDivider.oneTouchHoverArrowColor Color
* @uiDefault SplitPaneDivider.oneTouchPressedArrowColor Color
@@ -65,7 +68,6 @@ public class FlatSplitPaneUI
extends BasicSplitPaneUI
{
protected String arrowType;
private Boolean continuousLayout;
protected Color oneTouchArrowColor;
protected Color oneTouchHoverArrowColor;
protected Color oneTouchPressedArrowColor;
@@ -85,8 +87,6 @@ public class FlatSplitPaneUI
oneTouchPressedArrowColor = UIManager.getColor( "SplitPaneDivider.oneTouchPressedArrowColor" );
super.installDefaults();
continuousLayout = (Boolean) UIManager.get( "SplitPane.continuousLayout" );
}
@Override
@@ -98,11 +98,6 @@ public class FlatSplitPaneUI
oneTouchPressedArrowColor = null;
}
@Override
public boolean isContinuousLayout() {
return super.isContinuousLayout() || (continuousLayout != null && Boolean.TRUE.equals( continuousLayout ));
}
@Override
public BasicSplitPaneDivider createDefaultDivider() {
return new FlatSplitPaneDivider( this );

View File

@@ -58,6 +58,8 @@ import java.util.function.BiConsumer;
import java.util.function.IntConsumer;
import javax.accessibility.Accessible;
import javax.accessibility.AccessibleContext;
import javax.swing.Action;
import javax.swing.ActionMap;
import javax.swing.ButtonModel;
import javax.swing.Icon;
import javax.swing.JButton;
@@ -325,7 +327,7 @@ public class FlatTabbedPaneUI
// the default also includes Ctrl+TAB/Ctrl+Shift+TAB, which we need to switch tabs
if( focusForwardTraversalKeys == null ) {
focusForwardTraversalKeys = Collections.singleton( KeyStroke.getKeyStroke( KeyEvent.VK_TAB, 0 ) );
focusBackwardTraversalKeys = Collections.singleton( KeyStroke.getKeyStroke( KeyEvent.VK_TAB, InputEvent.SHIFT_MASK ) );
focusBackwardTraversalKeys = Collections.singleton( KeyStroke.getKeyStroke( KeyEvent.VK_TAB, InputEvent.SHIFT_DOWN_MASK ) );
}
// Ideally we should use `LookAndFeel.installProperty( tabPane, "focusTraversalKeysForward", keys )` here
// instead of `tabPane.setFocusTraversalKeys()`, but WindowsTabbedPaneUI also uses later method
@@ -490,6 +492,20 @@ public class FlatTabbedPaneUI
}
}
@Override
protected void installKeyboardActions() {
super.installKeyboardActions();
// get shared action map, used for all tabbed panes
ActionMap map = SwingUtilities.getUIActionMap( tabPane );
if( map != null ) {
// this is required for the case that those actions are used from outside
// (e.g. wheel tab scroller in NetBeans)
RunWithOriginalLayoutManagerDelegateAction.install( map, "scrollTabsForwardAction" );
RunWithOriginalLayoutManagerDelegateAction.install( map, "scrollTabsBackwardAction" );
}
}
private Handler getHandler() {
if( handler == null )
handler = new Handler();
@@ -722,6 +738,13 @@ public class FlatTabbedPaneUI
}
protected Insets getRealTabAreaInsets( int tabPlacement ) {
// this is to avoid potential NPE in ensureSelectedTabIsVisible()
// (see https://github.com/JFormDesigner/FlatLaf/issues/299)
// but now should actually never occur because added more checks to
// ensureSelectedTabIsVisibleLater() and ensureSelectedTabIsVisible()
if( tabAreaInsets == null )
tabAreaInsets = new Insets( 0, 0, 0, 0 );
Insets currentTabAreaInsets = super.getTabAreaInsets( tabPlacement );
Insets insets = (Insets) currentTabAreaInsets.clone();
@@ -819,6 +842,17 @@ public class FlatTabbedPaneUI
paintTabArea( g, tabPlacement, selectedIndex );
}
@Override
protected void paintTabArea( Graphics g, int tabPlacement, int selectedIndex ) {
// need to set rendering hints here too because this method is also invoked
// from BasicTabbedPaneUI.ScrollableTabPanel.paintComponent()
Object[] oldHints = FlatUIUtils.setRenderingHints( g );
super.paintTabArea( g, tabPlacement, selectedIndex );
FlatUIUtils.resetRenderingHints( g, oldHints );
}
@Override
protected void paintTab( Graphics g, int tabPlacement, Rectangle[] rects,
int tabIndex, Rectangle iconRect, Rectangle textRect )
@@ -893,7 +927,7 @@ public class FlatTabbedPaneUI
Color color;
if( tabPane.isEnabled() && tabPane.isEnabledAt( tabIndex ) ) {
color = tabPane.getForegroundAt( tabIndex );
if( isSelected && (color instanceof UIResource) && selectedForeground != null )
if( isSelected && selectedForeground != null && color == tabPane.getForeground() )
color = selectedForeground;
} else
color = disabledForeground;
@@ -1386,13 +1420,18 @@ public class FlatTabbedPaneUI
}
protected void ensureSelectedTabIsVisibleLater() {
// do nothing if not yet displayable or if not invoked from dispatch thread,
// which may be the case when creating/modifying in another thread
if( !tabPane.isDisplayable() || !EventQueue.isDispatchThread() )
return;
EventQueue.invokeLater( () -> {
ensureSelectedTabIsVisible();
} );
}
protected void ensureSelectedTabIsVisible() {
if( tabPane == null || tabViewport == null )
if( tabPane == null || tabViewport == null || !tabPane.isDisplayable() )
return;
ensureCurrentLayout();
@@ -1559,7 +1598,7 @@ public class FlatTabbedPaneUI
FlatUIUtils.paintComponentBackground( g, left, top,
getWidth() - left - right,
getHeight() - top - bottom,
0, scale( buttonArc ) );
0, scale( (float) buttonArc ) );
}
}
@@ -2947,4 +2986,51 @@ public class FlatTabbedPaneUI
scrollBackwardButtonPrefSize = backwardButton.getPreferredSize();
}
}
//---- class RunWithOriginalLayoutManagerDelegateAction -------------------
private static class RunWithOriginalLayoutManagerDelegateAction
implements Action
{
private final Action delegate;
static void install( ActionMap map, String key ) {
Action oldAction = map.get( key );
if( oldAction == null || oldAction instanceof RunWithOriginalLayoutManagerDelegateAction )
return; // not found or already installed
map.put( key, new RunWithOriginalLayoutManagerDelegateAction( oldAction ) );
}
private RunWithOriginalLayoutManagerDelegateAction( Action delegate ) {
this.delegate = delegate;
}
@Override
public Object getValue( String key ) {
return delegate.getValue( key );
}
@Override
public boolean isEnabled() {
return delegate.isEnabled();
}
@Override public void putValue( String key, Object value ) {}
@Override public void setEnabled( boolean b ) {}
@Override public void addPropertyChangeListener( PropertyChangeListener listener ) {}
@Override public void removePropertyChangeListener( PropertyChangeListener listener ) {}
@Override
public void actionPerformed( ActionEvent e ) {
JTabbedPane tabbedPane = (JTabbedPane) e.getSource();
ComponentUI ui = tabbedPane.getUI();
if( ui instanceof FlatTabbedPaneUI ) {
((FlatTabbedPaneUI)ui).runWithOriginalLayoutManager( () -> {
delegate.actionPerformed( e );
} );
} else
delegate.actionPerformed( e );
}
}
}

View File

@@ -0,0 +1,137 @@
/*
* Copyright 2021 FormDev Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.formdev.flatlaf.ui;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JViewport;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumn;
import com.formdev.flatlaf.util.UIScale;
/**
* Cell border for {@code sun.swing.table.DefaultTableCellHeaderRenderer}
* (used by {@link javax.swing.table.JTableHeader}).
* <p>
* Uses separate cell margins from UI defaults to allow easy customizing.
*
* @author Karl Tauber
* @since 1.2
*/
public class FlatTableHeaderBorder
extends FlatEmptyBorder
{
protected Color separatorColor = UIManager.getColor( "TableHeader.separatorColor" );
protected Color bottomSeparatorColor = UIManager.getColor( "TableHeader.bottomSeparatorColor" );
/** @since 1.6 */ protected boolean showTrailingVerticalLine = UIManager.getBoolean( "TableHeader.showTrailingVerticalLine" );
public FlatTableHeaderBorder() {
super( UIManager.getInsets( "TableHeader.cellMargins" ) );
}
@Override
public void paintBorder( Component c, Graphics g, int x, int y, int width, int height ) {
JTableHeader header = (JTableHeader) SwingUtilities.getAncestorOfClass( JTableHeader.class, c );
boolean leftToRight = (header != null ? header : c).getComponentOrientation().isLeftToRight();
boolean paintLeft = !leftToRight;
boolean paintRight = leftToRight;
if( header != null ) {
int hx = SwingUtilities.convertPoint( c, x, y, header ).x;
if( isDraggedColumn( header, hx ) )
paintLeft = paintRight = true;
else {
if( hx <= 0 && !leftToRight && hideTrailingVerticalLine( header ) )
paintLeft = false;
if( hx + width >= header.getWidth() && leftToRight && hideTrailingVerticalLine( header ) )
paintRight = false;
}
}
float lineWidth = UIScale.scale( 1f );
Graphics2D g2 = (Graphics2D) g.create();
try {
FlatUIUtils.setRenderingHints( g2 );
// paint column separator lines
g2.setColor( separatorColor );
if( paintLeft )
g2.fill( new Rectangle2D.Float( x, y, lineWidth, height - lineWidth ) );
if( paintRight )
g2.fill( new Rectangle2D.Float( x + width - lineWidth, y, lineWidth, height - lineWidth ) );
// paint bottom line
g2.setColor( bottomSeparatorColor );
g2.fill( new Rectangle2D.Float( x, y + height - lineWidth, width, lineWidth ) );
} finally {
g2.dispose();
}
}
protected boolean isDraggedColumn( JTableHeader header, int x ) {
TableColumn draggedColumn = header.getDraggedColumn();
if( draggedColumn == null )
return false;
int draggedDistance = header.getDraggedDistance();
if( draggedDistance == 0 )
return false;
int columnCount = header.getColumnModel().getColumnCount();
for( int i = 0; i < columnCount; i++ ) {
if( header.getHeaderRect( i ).x + draggedDistance == x )
return true;
}
return false;
}
protected boolean hideTrailingVerticalLine( JTableHeader header ) {
if( showTrailingVerticalLine )
return false;
// do not hide if table header is not a child of a scroll pane
Container viewport = header.getParent();
Container viewportParent = (viewport != null) ? viewport.getParent() : null;
if( !(viewportParent instanceof JScrollPane) )
return false;
// do not hide if table header is not the column header of the scroll pane
JScrollPane scrollPane = (JScrollPane) viewportParent;
JViewport columnHeader = scrollPane.getColumnHeader();
if( viewport != columnHeader )
return false;
// hide if vertical scroll bar is not shown
JScrollBar vsb = scrollPane.getVerticalScrollBar();
if( vsb == null || !vsb.isVisible() )
return true;
// if "ScrollPane.fillUpperCorner" is true, then javax.swing.ScrollPaneLayout
// extends the vertical scrollbar into the upper right/left corner
return vsb.getY() == viewport.getY();
}
}

View File

@@ -18,28 +18,27 @@ package com.formdev.flatlaf.ui;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.geom.Rectangle2D;
import java.util.Objects;
import javax.swing.Icon;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ScrollPaneConstants;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.event.MouseInputListener;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.UIResource;
import javax.swing.plaf.basic.BasicTableHeaderUI;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
import com.formdev.flatlaf.util.UIScale;
@@ -54,17 +53,22 @@ import com.formdev.flatlaf.util.UIScale;
*
* <!-- FlatTableHeaderUI -->
*
* @uiDefault TableHeader.separatorColor Color
* @uiDefault TableHeader.bottomSeparatorColor Color
* @uiDefault TableHeader.height int
* @uiDefault TableHeader.sortIconPosition String right (default), left, top or bottom
*
* <!-- FlatTableHeaderBorder -->
*
* @uiDefault TableHeader.cellMargins Insets
* @uiDefault TableHeader.separatorColor Color
* @uiDefault TableHeader.bottomSeparatorColor Color
* @uiDefault TableHeader.showTrailingVerticalLine boolean
*
* @author Karl Tauber
*/
public class FlatTableHeaderUI
extends BasicTableHeaderUI
{
protected Color separatorColor;
protected Color bottomSeparatorColor;
protected int height;
protected int sortIconPosition;
@@ -77,7 +81,6 @@ public class FlatTableHeaderUI
protected void installDefaults() {
super.installDefaults();
separatorColor = UIManager.getColor( "TableHeader.separatorColor" );
bottomSeparatorColor = UIManager.getColor( "TableHeader.bottomSeparatorColor" );
height = UIManager.getInt( "TableHeader.height" );
switch( Objects.toString( UIManager.getString( "TableHeader.sortIconPosition" ), "right" ) ) {
@@ -93,27 +96,49 @@ public class FlatTableHeaderUI
protected void uninstallDefaults() {
super.uninstallDefaults();
separatorColor = null;
bottomSeparatorColor = null;
}
@Override
protected MouseInputListener createMouseInputListener() {
return new FlatMouseInputHandler();
}
// overridden and made public to allow usage in custom renderers
@Override
public int getRolloverColumn() {
return super.getRolloverColumn();
}
@Override
public void paint( Graphics g, JComponent c ) {
if( header.getColumnModel().getColumnCount() <= 0 )
TableColumnModel columnModel = header.getColumnModel();
if( columnModel.getColumnCount() <= 0 )
return;
// do not paint borders if JTableHeader.setDefaultRenderer() was used
TableCellRenderer defaultRenderer = header.getDefaultRenderer();
boolean paintBorders = isSystemDefaultRenderer( defaultRenderer );
if( !paintBorders ) {
// check whether the renderer delegates to the system default renderer
Component rendererComponent = defaultRenderer.getTableCellRendererComponent(
header.getTable(), "", false, false, -1, 0 );
paintBorders = isSystemDefaultRenderer( rendererComponent );
}
// compute total width of all columns
int columnCount = columnModel.getColumnCount();
int totalWidth = 0;
for( int i = 0; i < columnCount; i++ )
totalWidth += columnModel.getColumn( i ).getWidth();
if( paintBorders )
paintColumnBorders( g, c );
if( totalWidth < header.getWidth() ) {
// do not paint bottom separator if JTableHeader.setDefaultRenderer() was used
TableCellRenderer defaultRenderer = header.getDefaultRenderer();
boolean paintBottomSeparator = isSystemDefaultRenderer( defaultRenderer );
if( !paintBottomSeparator && header.getTable() != null ) {
// check whether the renderer delegates to the system default renderer
Component rendererComponent = defaultRenderer.getTableCellRendererComponent(
header.getTable(), "", false, false, -1, 0 );
paintBottomSeparator = isSystemDefaultRenderer( rendererComponent );
}
if( paintBottomSeparator ) {
int w = c.getWidth() - totalWidth;
int x = header.getComponentOrientation().isLeftToRight() ? c.getWidth() - w : 0;
paintBottomSeparator( g, c, x, w );
}
}
// temporary use own default renderer if necessary
FlatTableCellHeaderRenderer sortIconRenderer = null;
@@ -130,9 +155,6 @@ public class FlatTableHeaderUI
sortIconRenderer.reset();
header.setDefaultRenderer( sortIconRenderer.delegate );
}
if( paintBorders )
paintDraggedColumnBorders( g, c );
}
private boolean isSystemDefaultRenderer( Object headerRenderer ) {
@@ -141,17 +163,8 @@ public class FlatTableHeaderUI
rendererClassName.equals( "sun.swing.FilePane$AlignableTableHeaderRenderer" );
}
protected void paintColumnBorders( Graphics g, JComponent c ) {
int width = c.getWidth();
int height = c.getHeight();
protected void paintBottomSeparator( Graphics g, JComponent c, int x, int w ) {
float lineWidth = UIScale.scale( 1f );
float topLineIndent = lineWidth;
float bottomLineIndent = lineWidth * 3;
TableColumnModel columnModel = header.getColumnModel();
int columnCount = columnModel.getColumnCount();
int sepCount = columnCount;
if( hideLastVerticalLine() )
sepCount--;
Graphics2D g2 = (Graphics2D) g.create();
try {
@@ -159,78 +172,7 @@ public class FlatTableHeaderUI
// paint bottom line
g2.setColor( bottomSeparatorColor );
g2.fill( new Rectangle2D.Float( 0, height - lineWidth, width, lineWidth ) );
// paint column separator lines
g2.setColor( separatorColor );
float y = topLineIndent;
float h = height - bottomLineIndent;
if( header.getComponentOrientation().isLeftToRight() ) {
int x = 0;
for( int i = 0; i < sepCount; i++ ) {
x += columnModel.getColumn( i ).getWidth();
g2.fill( new Rectangle2D.Float( x - lineWidth, y, lineWidth, h ) );
}
// paint trailing separator (on right side)
if( !hideTrailingVerticalLine() )
g2.fill( new Rectangle2D.Float( header.getWidth() - lineWidth, y, lineWidth, h ) );
} else {
Rectangle cellRect = header.getHeaderRect( 0 );
int x = cellRect.x + cellRect.width;
for( int i = 0; i < sepCount; i++ ) {
x -= columnModel.getColumn( i ).getWidth();
g2.fill( new Rectangle2D.Float( x - (i < sepCount - 1 ? lineWidth : 0), y, lineWidth, h ) );
}
// paint trailing separator (on left side)
if( !hideTrailingVerticalLine() )
g2.fill( new Rectangle2D.Float( 0, y, lineWidth, h ) );
}
} finally {
g2.dispose();
}
}
private void paintDraggedColumnBorders( Graphics g, JComponent c ) {
TableColumn draggedColumn = header.getDraggedColumn();
if( draggedColumn == null )
return;
// find index of dragged column
TableColumnModel columnModel = header.getColumnModel();
int columnCount = columnModel.getColumnCount();
int draggedColumnIndex = -1;
for( int i = 0; i < columnCount; i++ ) {
if( columnModel.getColumn( i ) == draggedColumn ) {
draggedColumnIndex = i;
break;
}
}
if( draggedColumnIndex < 0 )
return;
float lineWidth = UIScale.scale( 1f );
float topLineIndent = lineWidth;
float bottomLineIndent = lineWidth * 3;
Rectangle r = header.getHeaderRect( draggedColumnIndex );
r.x += header.getDraggedDistance();
Graphics2D g2 = (Graphics2D) g.create();
try {
FlatUIUtils.setRenderingHints( g2 );
// paint dragged bottom line
g2.setColor( bottomSeparatorColor );
g2.fill( new Rectangle2D.Float( r.x, r.y + r.height - lineWidth, r.width, lineWidth ) );
// paint dragged column separator lines
g2.setColor( separatorColor );
g2.fill( new Rectangle2D.Float( r.x, topLineIndent, lineWidth, r.height - bottomLineIndent ) );
g2.fill( new Rectangle2D.Float( r.x + r.width - lineWidth, r.y + topLineIndent, lineWidth, r.height - bottomLineIndent ) );
g2.fill( new Rectangle2D.Float( x, c.getHeight() - lineWidth, w, lineWidth ) );
} finally {
g2.dispose();
}
@@ -244,32 +186,6 @@ public class FlatTableHeaderUI
return size;
}
protected boolean hideLastVerticalLine() {
Container viewport = header.getParent();
Container viewportParent = (viewport != null) ? viewport.getParent() : null;
if( !(viewportParent instanceof JScrollPane) )
return false;
Rectangle cellRect = header.getHeaderRect( header.getColumnModel().getColumnCount() - 1 );
// using component orientation of scroll pane here because it is also used in FlatTableUI
JScrollPane scrollPane = (JScrollPane) viewportParent;
return scrollPane.getComponentOrientation().isLeftToRight()
? cellRect.x + cellRect.width >= viewport.getWidth()
: cellRect.x <= 0;
}
protected boolean hideTrailingVerticalLine() {
Container viewport = header.getParent();
Container viewportParent = (viewport != null) ? viewport.getParent() : null;
if( !(viewportParent instanceof JScrollPane) )
return false;
JScrollPane scrollPane = (JScrollPane) viewportParent;
return viewport == scrollPane.getColumnHeader() &&
scrollPane.getCorner( ScrollPaneConstants.UPPER_TRAILING_CORNER ) == null;
}
//---- class FlatTableCellHeaderRenderer ----------------------------------
/**
@@ -346,4 +262,54 @@ public class FlatTableHeaderUI
return (origBorder != null) ? origBorder.isBorderOpaque() : false;
}
}
//---- class FlatMouseInputHandler ----------------------------------------
/**
* @since 1.6
*/
protected class FlatMouseInputHandler
extends MouseInputHandler
{
Cursor oldCursor;
@Override
public void mouseMoved( MouseEvent e ) {
// restore old cursor, which is necessary because super.mouseMoved() swaps cursors
if( oldCursor != null ) {
header.setCursor( oldCursor );
oldCursor = null;
}
super.mouseMoved( e );
// if resizing last column is not possible, then Swing still shows a resize cursor,
// which can be confusing for the user --> change cursor to standard cursor
JTable table;
int column;
if( header.isEnabled() &&
(table = header.getTable()) != null &&
table.getAutoResizeMode() != JTable.AUTO_RESIZE_OFF &&
header.getCursor() == Cursor.getPredefinedCursor( Cursor.E_RESIZE_CURSOR ) &&
(column = header.columnAtPoint( e.getPoint() )) >= 0 &&
column == header.getColumnModel().getColumnCount() - 1 )
{
// mouse is in last column
Rectangle r = header.getHeaderRect( column );
r.grow( -3, 0 );
if( !r.contains( e.getX(), e.getY() ) ) {
// mouse is in left or right resize area of last column
boolean isResizeLastColumn = (e.getX() >= r.x + (r.width / 2));
if( !header.getComponentOrientation().isLeftToRight() )
isResizeLastColumn = !isResizeLastColumn;
if( isResizeLastColumn ) {
// resize is not possible --> change cursor to standard cursor
oldCursor = header.getCursor();
header.setCursor( Cursor.getDefaultCursor() );
}
}
}
}
}
}

View File

@@ -25,7 +25,7 @@ import java.awt.Graphics2D;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.geom.Rectangle2D;
import javax.swing.JCheckBox;
import java.beans.PropertyChangeListener;
import javax.swing.JComponent;
import javax.swing.JScrollPane;
import javax.swing.JViewport;
@@ -34,8 +34,10 @@ import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicTableUI;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.JTableHeader;
import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.util.Graphics2DProxy;
import com.formdev.flatlaf.util.SystemInfo;
import com.formdev.flatlaf.util.UIScale;
/**
@@ -69,6 +71,7 @@ import com.formdev.flatlaf.util.UIScale;
* @uiDefault Table.rowHeight int
* @uiDefault Table.showHorizontalLines boolean
* @uiDefault Table.showVerticalLines boolean
* @uiDefault Table.showTrailingVerticalLine boolean
* @uiDefault Table.intercellSpacing Dimension
* @uiDefault Table.selectionInactiveBackground Color
* @uiDefault Table.selectionInactiveForeground Color
@@ -90,6 +93,7 @@ public class FlatTableUI
{
protected boolean showHorizontalLines;
protected boolean showVerticalLines;
/** @since 1.6 */ protected boolean showTrailingVerticalLine;
protected Dimension intercellSpacing;
protected Color selectionBackground;
@@ -101,6 +105,8 @@ public class FlatTableUI
private boolean oldShowVerticalLines;
private Dimension oldIntercellSpacing;
private PropertyChangeListener propertyChangeListener;
public static ComponentUI createUI( JComponent c ) {
return new FlatTableUI();
}
@@ -111,6 +117,7 @@ public class FlatTableUI
showHorizontalLines = UIManager.getBoolean( "Table.showHorizontalLines" );
showVerticalLines = UIManager.getBoolean( "Table.showVerticalLines" );
showTrailingVerticalLine = UIManager.getBoolean( "Table.showTrailingVerticalLine" );
intercellSpacing = UIManager.getDimension( "Table.intercellSpacing" );
selectionBackground = UIManager.getColor( "Table.selectionBackground" );
@@ -137,12 +144,6 @@ public class FlatTableUI
oldIntercellSpacing = table.getIntercellSpacing();
table.setIntercellSpacing( intercellSpacing );
}
// checkbox is non-opaque in FlatLaf and therefore would not paint selection
// --> make checkbox renderer opaque (but opaque in Metal or Windows LaF)
TableCellRenderer booleanRenderer = table.getDefaultRenderer( Boolean.class );
if( booleanRenderer instanceof JCheckBox )
((JCheckBox)booleanRenderer).setOpaque( true );
}
@Override
@@ -165,6 +166,25 @@ public class FlatTableUI
table.setIntercellSpacing( oldIntercellSpacing );
}
@Override
protected void installListeners() {
super.installListeners();
propertyChangeListener = e -> {
if( FlatClientProperties.COMPONENT_FOCUS_OWNER.equals( e.getPropertyName() ) )
toggleSelectionColors();
};
table.addPropertyChangeListener( propertyChangeListener );
}
@Override
protected void uninstallListeners() {
super.uninstallListeners();
table.removePropertyChangeListener( propertyChangeListener );
propertyChangeListener = null;
}
@Override
protected FocusListener createFocusListener() {
return new BasicTableUI.FocusHandler() {
@@ -221,15 +241,18 @@ public class FlatTableUI
// - do not paint last vertical grid line if line is on right edge of scroll pane
// - fix unstable grid line thickness when scaled at 125%, 150%, 175%, 225%, ...
// which paints either 1px or 2px lines depending on location
// - on Java 9+, fix wrong grid line thickness in dragged column
boolean hideLastVerticalLine = hideLastVerticalLine();
int tableWidth = table.getWidth();
JTableHeader header = table.getTableHeader();
boolean isDragging = (header != null && header.getDraggedColumn() != null);
double systemScaleFactor = UIScale.getSystemScaleFactor( (Graphics2D) g );
double lineThickness = (1. / systemScaleFactor) * (int) systemScaleFactor;
// Java 8 uses drawLine() to paint grid lines
// Java 9+ uses fillRect() to paint grid lines
// Java 9+ uses fillRect() to paint grid lines (except for dragged column)
g = new Graphics2DProxy( (Graphics2D) g ) {
@Override
public void drawLine( int x1, int y1, int x2, int y2 ) {
@@ -239,6 +262,22 @@ public class FlatTableUI
wasInvokedFromPaintGrid() )
return;
// on Java 9+, fix wrong grid line thickness in dragged column
if( isDragging &&
SystemInfo.isJava_9_orLater &&
((horizontalLines && y1 == y2) || (verticalLines && x1 == x2)) &&
wasInvokedFromMethod( "paintDraggedArea" ) )
{
if( y1 == y2 ) {
// horizontal grid line
super.fill( new Rectangle2D.Double( x1, y1, x2 - x1 + 1, lineThickness ) );
} else if( x1 == x2 ) {
// vertical grid line
super.fill( new Rectangle2D.Double( x1, y1, lineThickness, y2 - y1 + 1 ) );
}
return;
}
super.drawLine( x1, y1, x2, y2 );
}
@@ -266,13 +305,11 @@ public class FlatTableUI
}
private boolean wasInvokedFromPaintGrid() {
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
for( int i = 0; i < 10 || i < stackTrace.length; i++ ) {
if( "javax.swing.plaf.basic.BasicTableUI".equals( stackTrace[i].getClassName() ) &&
"paintGrid".equals( stackTrace[i].getMethodName() ) )
return true;
}
return false;
return wasInvokedFromMethod( "paintGrid" );
}
private boolean wasInvokedFromMethod( String methodName ) {
return StackUtils.wasInvokedFrom( BasicTableUI.class.getName(), methodName, 8 );
}
};
}
@@ -281,6 +318,10 @@ public class FlatTableUI
}
protected boolean hideLastVerticalLine() {
if( showTrailingVerticalLine )
return false;
// do not hide if table is not a child of a scroll pane
Container viewport = SwingUtilities.getUnwrappedParent( table );
Container viewportParent = (viewport != null) ? viewport.getParent() : null;
if( !(viewportParent instanceof JScrollPane) )

View File

@@ -20,6 +20,8 @@ import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.event.FocusListener;
import java.beans.PropertyChangeEvent;
import javax.swing.JComponent;
import javax.swing.JTextArea;
@@ -52,6 +54,7 @@ import com.formdev.flatlaf.util.HiDPIUtils;
* @uiDefault Component.isIntelliJTheme boolean
* @uiDefault TextArea.disabledBackground Color used if not enabled
* @uiDefault TextArea.inactiveBackground Color used if not editable
* @uiDefault TextArea.focusedBackground Color optional
*
* @author Karl Tauber
*/
@@ -63,6 +66,11 @@ public class FlatTextAreaUI
protected Color background;
protected Color disabledBackground;
protected Color inactiveBackground;
protected Color focusedBackground;
private Insets defaultMargin;
private FocusListener focusListener;
public static ComponentUI createUI( JComponent c ) {
return new FlatTextAreaUI();
@@ -84,6 +92,9 @@ public class FlatTextAreaUI
background = UIManager.getColor( "TextArea.background" );
disabledBackground = UIManager.getColor( "TextArea.disabledBackground" );
inactiveBackground = UIManager.getColor( "TextArea.inactiveBackground" );
focusedBackground = UIManager.getColor( "TextArea.focusedBackground" );
defaultMargin = UIManager.getInsets( "TextArea.margin" );
}
@Override
@@ -93,6 +104,24 @@ public class FlatTextAreaUI
background = null;
disabledBackground = null;
inactiveBackground = null;
focusedBackground = null;
}
@Override
protected void installListeners() {
super.installListeners();
// necessary to update focus background
focusListener = new FlatUIUtils.RepaintFocusListener( getComponent(), c -> focusedBackground != null );
getComponent().addFocusListener( focusListener );
}
@Override
protected void uninstallListeners() {
super.uninstallListeners();
getComponent().removeFocusListener( focusListener );
focusListener = null;
}
@Override
@@ -146,7 +175,7 @@ public class FlatTextAreaUI
if( c instanceof JTextArea && ((JTextArea)c).getColumns() > 0 )
return size;
return FlatEditorPaneUI.applyMinimumWidth( c, size, minimumWidth );
return FlatEditorPaneUI.applyMinimumWidth( c, size, minimumWidth, defaultMargin );
}
@Override
@@ -156,14 +185,6 @@ public class FlatTextAreaUI
@Override
protected void paintBackground( Graphics g ) {
JTextComponent c = getComponent();
// for compatibility with IntelliJ themes
if( isIntelliJTheme && (!c.isEnabled() || !c.isEditable()) && (c.getBackground() instanceof UIResource) ) {
FlatUIUtils.paintParentBackground( g, c );
return;
}
super.paintBackground( g );
FlatEditorPaneUI.paintBackground( g, getComponent(), isIntelliJTheme, focusedBackground );
}
}

View File

@@ -24,8 +24,10 @@ import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.event.FocusListener;
import java.beans.PropertyChangeEvent;
import java.util.Objects;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JSpinner;
@@ -40,6 +42,7 @@ import javax.swing.text.JTextComponent;
import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.util.HiDPIUtils;
import com.formdev.flatlaf.util.JavaCompatibility;
import com.formdev.flatlaf.util.UIScale;
/**
* Provides the Flat LaF UI delegate for {@link javax.swing.JTextField}.
@@ -64,6 +67,7 @@ import com.formdev.flatlaf.util.JavaCompatibility;
* @uiDefault Component.minimumWidth int
* @uiDefault Component.isIntelliJTheme boolean
* @uiDefault TextField.placeholderForeground Color
* @uiDefault TextField.focusedBackground Color optional
* @uiDefault TextComponent.selectAllOnFocusPolicy String never, once (default) or always
* @uiDefault TextComponent.selectAllOnMouseClick boolean
*
@@ -75,6 +79,9 @@ public class FlatTextFieldUI
protected int minimumWidth;
protected boolean isIntelliJTheme;
protected Color placeholderForeground;
protected Color focusedBackground;
private Insets defaultMargin;
private FocusListener focusListener;
@@ -90,6 +97,9 @@ public class FlatTextFieldUI
minimumWidth = UIManager.getInt( "Component.minimumWidth" );
isIntelliJTheme = UIManager.getBoolean( "Component.isIntelliJTheme" );
placeholderForeground = UIManager.getColor( prefix + ".placeholderForeground" );
focusedBackground = UIManager.getColor( prefix + ".focusedBackground" );
defaultMargin = UIManager.getInsets( prefix + ".margin" );
LookAndFeel.installProperty( getComponent(), "opaque", false );
@@ -101,6 +111,7 @@ public class FlatTextFieldUI
super.uninstallDefaults();
placeholderForeground = null;
focusedBackground = null;
MigLayoutVisualPadding.uninstall( getComponent() );
}
@@ -109,7 +120,8 @@ public class FlatTextFieldUI
protected void installListeners() {
super.installListeners();
focusListener = new FlatUIUtils.RepaintFocusListener( getComponent() );
// necessary to update focus border and background
focusListener = new FlatUIUtils.RepaintFocusListener( getComponent(), null );
getComponent().addFocusListener( focusListener );
}
@@ -137,6 +149,7 @@ public class FlatTextFieldUI
switch( e.getPropertyName() ) {
case FlatClientProperties.PLACEHOLDER_TEXT:
case FlatClientProperties.COMPONENT_ROUND_RECT:
case FlatClientProperties.TEXT_FIELD_PADDING:
c.repaint();
break;
@@ -148,8 +161,8 @@ public class FlatTextFieldUI
@Override
protected void paintSafely( Graphics g ) {
paintBackground( g, getComponent(), isIntelliJTheme );
paintPlaceholder( g, getComponent(), placeholderForeground );
paintBackground( g, getComponent(), isIntelliJTheme, focusedBackground );
paintPlaceholder( g );
super.paintSafely( HiDPIUtils.createGraphicsTextYCorrection( (Graphics2D) g ) );
}
@@ -159,7 +172,7 @@ public class FlatTextFieldUI
// background is painted elsewhere
}
static void paintBackground( Graphics g, JTextComponent c, boolean isIntelliJTheme ) {
static void paintBackground( Graphics g, JTextComponent c, boolean isIntelliJTheme, Color focusedBackground ) {
// do not paint background if:
// - not opaque and
// - border is not a flat border and
@@ -180,19 +193,34 @@ public class FlatTextFieldUI
try {
FlatUIUtils.setRenderingHints( g2 );
Color background = c.getBackground();
g2.setColor( !(background instanceof UIResource)
? background
: (isIntelliJTheme && (!c.isEnabled() || !c.isEditable())
? FlatUIUtils.getParentBackground( c )
: background) );
g2.setColor( getBackground( c, isIntelliJTheme, focusedBackground ) );
FlatUIUtils.paintComponentBackground( g2, 0, 0, c.getWidth(), c.getHeight(), focusWidth, arc );
} finally {
g2.dispose();
}
}
static void paintPlaceholder( Graphics g, JTextComponent c, Color placeholderForeground ) {
static Color getBackground( JTextComponent c, boolean isIntelliJTheme, Color focusedBackground ) {
Color background = c.getBackground();
// always use explicitly set color
if( !(background instanceof UIResource) )
return background;
// focused
if( focusedBackground != null && FlatUIUtils.isPermanentFocusOwner( c ) )
return focusedBackground;
// for compatibility with IntelliJ themes
if( isIntelliJTheme && (!c.isEnabled() || !c.isEditable()) )
return FlatUIUtils.getParentBackground( c );
return background;
}
protected void paintPlaceholder( Graphics g ) {
JTextComponent c = getComponent();
// check whether text component is empty
if( c.getDocument().getLength() > 0 )
return;
@@ -207,15 +235,14 @@ public class FlatTextFieldUI
return;
// compute placeholder location
Insets insets = c.getInsets();
Rectangle r = getVisibleEditorRect();
FontMetrics fm = c.getFontMetrics( c.getFont() );
int x = insets.left;
int y = insets.top + fm.getAscent() + ((c.getHeight() - insets.top - insets.bottom - fm.getHeight()) / 2);
String clippedPlaceholder = JavaCompatibility.getClippedString( c, fm, (String) placeholder, r.width );
int x = r.x + (c.getComponentOrientation().isLeftToRight() ? 0 : r.width - fm.stringWidth( clippedPlaceholder ));
int y = r.y + fm.getAscent() + ((r.height - fm.getHeight()) / 2);
// paint placeholder
g.setColor( placeholderForeground );
String clippedPlaceholder = JavaCompatibility.getClippedString( jc, fm,
(String) placeholder, c.getWidth() - insets.left - insets.right );
FlatUIUtils.drawString( c, g, clippedPlaceholder, x, y );
}
@@ -229,11 +256,15 @@ public class FlatTextFieldUI
return applyMinimumWidth( c, super.getMinimumSize( c ), minimumWidth );
}
static Dimension applyMinimumWidth( JComponent c, Dimension size, int minimumWidth ) {
private Dimension applyMinimumWidth( JComponent c, Dimension size, int minimumWidth ) {
// do not apply minimum width if JTextField.columns is set
if( c instanceof JTextField && ((JTextField)c).getColumns() > 0 )
return size;
// do not apply minimum width if JTextComponent.margin is set
if( !hasDefaultMargins( c, defaultMargin ) )
return size;
// do not apply minimum width if used in combobox or spinner
Container parent = c.getParent();
if( parent instanceof JComboBox ||
@@ -246,4 +277,41 @@ public class FlatTextFieldUI
size.width = Math.max( size.width, scale( minimumWidth ) + Math.round( focusWidth * 2 ) );
return size;
}
static boolean hasDefaultMargins( JComponent c, Insets defaultMargin ) {
Insets margin = ((JTextComponent)c).getMargin();
return margin instanceof UIResource && Objects.equals( margin, defaultMargin );
}
@Override
protected Rectangle getVisibleEditorRect() {
Rectangle r = super.getVisibleEditorRect();
if( r != null ) {
// remove padding
Insets padding = getPadding();
if( padding != null ) {
r = FlatUIUtils.subtractInsets( r, padding );
r.width = Math.max( r.width, 0 );
r.height = Math.max( r.height, 0 );
}
}
return r;
}
/**
* @since 1.4
*/
protected Insets getPadding() {
Object padding = getComponent().getClientProperty( FlatClientProperties.TEXT_FIELD_PADDING );
return (padding instanceof Insets) ? UIScale.scale( (Insets) padding ) : null;
}
/**
* @since 1.4
*/
protected void scrollCaretToVisible() {
Caret caret = getComponent().getCaret();
if( caret instanceof FlatCaret )
((FlatCaret)caret).scrollCaretToVisible();
}
}

View File

@@ -16,17 +16,18 @@
package com.formdev.flatlaf.ui;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.event.FocusListener;
import java.beans.PropertyChangeEvent;
import javax.swing.JComponent;
import javax.swing.JEditorPane;
import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.UIResource;
import javax.swing.plaf.basic.BasicTextPaneUI;
import javax.swing.text.JTextComponent;
import com.formdev.flatlaf.util.HiDPIUtils;
/**
@@ -51,6 +52,7 @@ import com.formdev.flatlaf.util.HiDPIUtils;
*
* @uiDefault Component.minimumWidth int
* @uiDefault Component.isIntelliJTheme boolean
* @uiDefault TextPane.focusedBackground Color optional
*
* @author Karl Tauber
*/
@@ -59,8 +61,12 @@ public class FlatTextPaneUI
{
protected int minimumWidth;
protected boolean isIntelliJTheme;
protected Color focusedBackground;
private Insets defaultMargin;
private Object oldHonorDisplayProperties;
private FocusListener focusListener;
public static ComponentUI createUI( JComponent c ) {
return new FlatTextPaneUI();
@@ -70,8 +76,12 @@ public class FlatTextPaneUI
protected void installDefaults() {
super.installDefaults();
String prefix = getPropertyPrefix();
minimumWidth = UIManager.getInt( "Component.minimumWidth" );
isIntelliJTheme = UIManager.getBoolean( "Component.isIntelliJTheme" );
focusedBackground = UIManager.getColor( prefix + ".focusedBackground" );
defaultMargin = UIManager.getInsets( prefix + ".margin" );
// use component font and foreground for HTML text
oldHonorDisplayProperties = getComponent().getClientProperty( JEditorPane.HONOR_DISPLAY_PROPERTIES );
@@ -82,9 +92,28 @@ public class FlatTextPaneUI
protected void uninstallDefaults() {
super.uninstallDefaults();
focusedBackground = null;
getComponent().putClientProperty( JEditorPane.HONOR_DISPLAY_PROPERTIES, oldHonorDisplayProperties );
}
@Override
protected void installListeners() {
super.installListeners();
// necessary to update focus background
focusListener = new FlatUIUtils.RepaintFocusListener( getComponent(), c -> focusedBackground != null );
getComponent().addFocusListener( focusListener );
}
@Override
protected void uninstallListeners() {
super.uninstallListeners();
getComponent().removeFocusListener( focusListener );
focusListener = null;
}
@Override
protected void propertyChange( PropertyChangeEvent e ) {
super.propertyChange( e );
@@ -93,12 +122,12 @@ public class FlatTextPaneUI
@Override
public Dimension getPreferredSize( JComponent c ) {
return FlatEditorPaneUI.applyMinimumWidth( c, super.getPreferredSize( c ), minimumWidth );
return FlatEditorPaneUI.applyMinimumWidth( c, super.getPreferredSize( c ), minimumWidth, defaultMargin );
}
@Override
public Dimension getMinimumSize( JComponent c ) {
return FlatEditorPaneUI.applyMinimumWidth( c, super.getMinimumSize( c ), minimumWidth );
return FlatEditorPaneUI.applyMinimumWidth( c, super.getMinimumSize( c ), minimumWidth, defaultMargin );
}
@Override
@@ -108,14 +137,6 @@ public class FlatTextPaneUI
@Override
protected void paintBackground( Graphics g ) {
JTextComponent c = getComponent();
// for compatibility with IntelliJ themes
if( isIntelliJTheme && (!c.isEnabled() || !c.isEditable()) && (c.getBackground() instanceof UIResource) ) {
FlatUIUtils.paintParentBackground( g, c );
return;
}
super.paintBackground( g );
FlatEditorPaneUI.paintBackground( g, getComponent(), isIntelliJTheme, focusedBackground );
}
}

View File

@@ -16,6 +16,7 @@
package com.formdev.flatlaf.ui;
import static com.formdev.flatlaf.FlatClientProperties.*;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
@@ -47,6 +48,7 @@ import java.util.List;
import java.util.Objects;
import javax.accessibility.AccessibleContext;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.Icon;
import javax.swing.ImageIcon;
@@ -63,7 +65,7 @@ import javax.swing.border.AbstractBorder;
import javax.swing.border.Border;
import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.FlatSystemProperties;
import com.formdev.flatlaf.ui.JBRCustomDecorations.JBRWindowTopBorder;
import com.formdev.flatlaf.ui.FlatNativeWindowBorder.WindowTopBorder;
import com.formdev.flatlaf.util.ScaledImageIcon;
import com.formdev.flatlaf.util.SystemInfo;
import com.formdev.flatlaf.util.UIScale;
@@ -77,12 +79,16 @@ import com.formdev.flatlaf.util.UIScale;
* @uiDefault TitlePane.inactiveForeground Color
* @uiDefault TitlePane.embeddedForeground Color
* @uiDefault TitlePane.borderColor Color optional
* @uiDefault TitlePane.unifiedBackground boolean
* @uiDefault TitlePane.iconSize Dimension
* @uiDefault TitlePane.iconMargins Insets
* @uiDefault TitlePane.titleMargins Insets
* @uiDefault TitlePane.menuBarMargins Insets
* @uiDefault TitlePane.menuBarEmbedded boolean
* @uiDefault TitlePane.buttonMaximizedHeight int
* @uiDefault TitlePane.centerTitle boolean
* @uiDefault TitlePane.centerTitleIfMenuBarEmbedded boolean
* @uiDefault TitlePane.menuBarTitleGap int
* @uiDefault TitlePane.icon Icon
* @uiDefault TitlePane.closeIcon Icon
* @uiDefault TitlePane.iconifyIcon Icon
* @uiDefault TitlePane.maximizeIcon Icon
@@ -100,9 +106,11 @@ public class FlatTitlePane
protected final Color embeddedForeground = UIManager.getColor( "TitlePane.embeddedForeground" );
protected final Color borderColor = UIManager.getColor( "TitlePane.borderColor" );
protected final Insets menuBarMargins = UIManager.getInsets( "TitlePane.menuBarMargins" );
protected final Dimension iconSize = UIManager.getDimension( "TitlePane.iconSize" );
protected final int buttonMaximizedHeight = UIManager.getInt( "TitlePane.buttonMaximizedHeight" );
protected final boolean centerTitle = UIManager.getBoolean( "TitlePane.centerTitle" );
protected final boolean centerTitleIfMenuBarEmbedded = FlatUIUtils.getUIBoolean( "TitlePane.centerTitleIfMenuBarEmbedded", true );
protected final int menuBarTitleGap = FlatUIUtils.getUIInt( "TitlePane.menuBarTitleGap", 20 );
protected final JRootPane rootPane;
@@ -147,9 +155,15 @@ public class FlatTitlePane
protected void addSubComponents() {
leftPanel = new JPanel();
iconLabel = new JLabel();
titleLabel = new JLabel();
titleLabel = new JLabel() {
@Override
public void updateUI() {
setUI( new FlatTitleLabelUI() );
}
};
iconLabel.setBorder( new FlatEmptyBorder( UIManager.getInsets( "TitlePane.iconMargins" ) ) );
titleLabel.setBorder( new FlatEmptyBorder( UIManager.getInsets( "TitlePane.titleMargins" ) ) );
titleLabel.setHorizontalAlignment( SwingConstants.CENTER );
leftPanel.setLayout( new BoxLayout( leftPanel, BoxLayout.LINE_AXIS ) );
leftPanel.setOpaque( false );
@@ -159,9 +173,7 @@ public class FlatTitlePane
@Override
public Dimension getPreferredSize() {
JMenuBar menuBar = rootPane.getJMenuBar();
return (menuBar != null && menuBar.isVisible() && isMenuBarEmbedded())
? FlatUIUtils.addInsets( menuBar.getPreferredSize(), UIScale.scale( menuBarMargins ) )
: new Dimension();
return hasVisibleEmbeddedMenuBar( menuBar ) ? menuBar.getPreferredSize() : new Dimension();
}
};
leftPanel.add( menuBarPlaceholder );
@@ -184,6 +196,20 @@ public class FlatTitlePane
if( !getComponentOrientation().isLeftToRight() )
leftPanel.setLocation( leftPanel.getX() + (oldWidth - newWidth), leftPanel.getY() );
}
// If menu bar is embedded and contains a horizontal glue component,
// then move the title label to the same location as the glue component
// and give it the same width.
// This allows placing any component on the trailing side of the title pane.
JMenuBar menuBar = rootPane.getJMenuBar();
if( hasVisibleEmbeddedMenuBar( menuBar ) ) {
Component horizontalGlue = findHorizontalGlue( menuBar );
if( horizontalGlue != null ) {
Point glueLocation = SwingUtilities.convertPoint( horizontalGlue, 0, 0, titleLabel );
titleLabel.setBounds( titleLabel.getX() + glueLocation.x, titleLabel.getY(),
horizontalGlue.getWidth(), titleLabel.getHeight() );
}
}
}
} );
@@ -240,10 +266,17 @@ public class FlatTitlePane
}
protected void activeChanged( boolean active ) {
boolean hasEmbeddedMenuBar = rootPane.getJMenuBar() != null && rootPane.getJMenuBar().isVisible() && isMenuBarEmbedded();
Color background = FlatUIUtils.nonUIResource( active ? activeBackground : inactiveBackground );
Color foreground = FlatUIUtils.nonUIResource( active ? activeForeground : inactiveForeground );
Color titleForeground = (hasEmbeddedMenuBar && active) ? FlatUIUtils.nonUIResource( embeddedForeground ) : foreground;
Color background = clientPropertyColor( rootPane, TITLE_BAR_BACKGROUND, null );
Color foreground = clientPropertyColor( rootPane, TITLE_BAR_FOREGROUND, null );
Color titleForeground = foreground;
if( background == null )
background = FlatUIUtils.nonUIResource( active ? activeBackground : inactiveBackground );
if( foreground == null ) {
foreground = FlatUIUtils.nonUIResource( active ? activeForeground : inactiveForeground );
titleForeground = (active && hasVisibleEmbeddedMenuBar( rootPane.getJMenuBar() ))
? FlatUIUtils.nonUIResource( embeddedForeground )
: foreground;
}
setBackground( background );
titleLabel.setForeground( titleForeground );
@@ -252,8 +285,6 @@ public class FlatTitlePane
restoreButton.setForeground( foreground );
closeButton.setForeground( foreground );
titleLabel.setHorizontalAlignment( hasEmbeddedMenuBar ? SwingConstants.CENTER : SwingConstants.LEADING );
// this is necessary because hover/pressed colors are derived from background color
iconifyButton.setBackground( background );
maximizeButton.setBackground( background );
@@ -320,10 +351,10 @@ public class FlatTitlePane
// set icon
if( !images.isEmpty() )
iconLabel.setIcon( FlatTitlePaneIcon.create( images, iconSize ) );
iconLabel.setIcon( new FlatTitlePaneIcon( images, iconSize ) );
else {
// no icon set on window --> use default icon
Icon defaultIcon = UIManager.getIcon( "InternalFrame.icon" );
Icon defaultIcon = UIManager.getIcon( "TitlePane.icon" );
if( defaultIcon != null && (defaultIcon.getIconWidth() == 0 || defaultIcon.getIconHeight() == 0) )
defaultIcon = null;
if( defaultIcon != null ) {
@@ -337,7 +368,7 @@ public class FlatTitlePane
// show/hide icon
iconLabel.setVisible( hasIcon );
updateJBRHitTestSpotsAndTitleBarHeightLater();
updateNativeTitleBarHeightAndHitTestSpotsLater();
}
@Override
@@ -355,7 +386,7 @@ public class FlatTitlePane
installWindowListeners();
}
updateJBRHitTestSpotsAndTitleBarHeightLater();
updateNativeTitleBarHeightAndHitTestSpotsLater();
}
@Override
@@ -394,11 +425,23 @@ public class FlatTitlePane
window.removeComponentListener( handler );
}
/**
* Returns whether this title pane currently has an visible and embedded menubar.
*/
protected boolean hasVisibleEmbeddedMenuBar( JMenuBar menuBar ) {
return menuBar != null && menuBar.isVisible() && isMenuBarEmbedded();
}
/**
* Returns whether the menubar should be embedded into the title pane.
*/
protected boolean isMenuBarEmbedded() {
// not storing value of "TitlePane.menuBarEmbedded" in class to allow changing at runtime
return UIManager.getBoolean( "TitlePane.menuBarEmbedded" ) &&
FlatClientProperties.clientPropertyBoolean( rootPane, FlatClientProperties.MENU_BAR_EMBEDDED, true ) &&
FlatSystemProperties.getBoolean( FlatSystemProperties.MENUBAR_EMBEDDED, true );
return FlatUIUtils.getBoolean( rootPane,
FlatSystemProperties.MENUBAR_EMBEDDED,
FlatClientProperties.MENU_BAR_EMBEDDED,
"TitlePane.menuBarEmbedded",
false );
}
protected Rectangle getMenuBarBounds() {
@@ -412,13 +455,42 @@ public class FlatTitlePane
Insets borderInsets = getBorder().getBorderInsets( this );
bounds.height += borderInsets.bottom;
return FlatUIUtils.subtractInsets( bounds, UIScale.scale( getMenuBarMargins() ) );
// If menu bar is embedded and contains a horizontal glue component,
// then make the menu bar wider so that it completely overlaps the title label.
// Since the menu bar is not opaque, the title label is still visible.
// The title label is moved to the location of the glue component by the layout manager.
// This allows placing any component on the trailing side of the title pane.
Component horizontalGlue = findHorizontalGlue( rootPane.getJMenuBar() );
if( horizontalGlue != null ) {
boolean leftToRight = getComponentOrientation().isLeftToRight();
int titleWidth = leftToRight
? buttonPanel.getX() - (leftPanel.getX() + leftPanel.getWidth())
: leftPanel.getX() - (buttonPanel.getX() + buttonPanel.getWidth());
titleWidth = Math.max( titleWidth, 0 ); // title width may be negative
bounds.width += titleWidth;
if( !leftToRight )
bounds.x -= titleWidth;
}
return bounds;
}
protected Insets getMenuBarMargins() {
return getComponentOrientation().isLeftToRight()
? menuBarMargins
: new Insets( menuBarMargins.top, menuBarMargins.right, menuBarMargins.bottom, menuBarMargins.left );
protected Component findHorizontalGlue( JMenuBar menuBar ) {
if( menuBar == null )
return null;
int count = menuBar.getComponentCount();
for( int i = count - 1; i >= 0; i-- ) {
Component c = menuBar.getComponent( i );
if( c instanceof Box.Filler && c.getMaximumSize().width >= Short.MAX_VALUE )
return c;
}
return null;
}
protected void titleBarColorsChanged() {
activeChanged( window == null || window.isActive() );
repaint();
}
protected void menuBarChanged() {
@@ -435,7 +507,8 @@ public class FlatTitlePane
}
protected void menuBarLayouted() {
updateJBRHitTestSpotsAndTitleBarHeightLater();
updateNativeTitleBarHeightAndHitTestSpotsLater();
revalidate();
}
/*debug
@@ -448,16 +521,27 @@ public class FlatTitlePane
g.drawLine( 0, debugTitleBarHeight, getWidth(), debugTitleBarHeight );
}
if( debugHitTestSpots != null ) {
g.setColor( Color.blue );
g.setColor( Color.red );
Point offset = SwingUtilities.convertPoint( this, 0, 0, window );
for( Rectangle r : debugHitTestSpots )
g.drawRect( r.x, r.y, r.width, r.height );
g.drawRect( r.x - offset.x, r.y - offset.y, r.width - 1, r.height - 1 );
}
if( debugAppIconBounds != null ) {
g.setColor( Color.blue);
Point offset = SwingUtilities.convertPoint( this, 0, 0, window );
Rectangle r = debugAppIconBounds;
g.drawRect( r.x - offset.x, r.y - offset.y, r.width - 1, r.height - 1 );
}
}
debug*/
@Override
protected void paintComponent( Graphics g ) {
g.setColor( getBackground() );
// not storing value of "TitlePane.unifiedBackground" in class to allow changing at runtime
g.setColor( (UIManager.getBoolean( "TitlePane.unifiedBackground" ) &&
clientPropertyColor( rootPane, TITLE_BAR_BACKGROUND, null ) == null)
? FlatUIUtils.getParentBackground( this )
: getBackground() );
g.fillRect( 0, 0, getWidth(), getHeight() );
}
@@ -475,10 +559,12 @@ debug*/
* Iconifies the window.
*/
protected void iconify() {
if( window instanceof Frame ) {
Frame frame = (Frame) window;
if( !(window instanceof Frame) )
return;
Frame frame = (Frame) window;
if( !FlatNativeWindowBorder.showWindow( window, FlatNativeWindowBorder.Provider.SW_MINIMIZE ) )
frame.setExtendedState( frame.getExtendedState() | Frame.ICONIFIED );
}
}
/**
@@ -496,16 +582,17 @@ debug*/
rootPane.putClientProperty( "_flatlaf.maximizedBoundsUpToDate", true );
// maximize window
frame.setExtendedState( frame.getExtendedState() | Frame.MAXIMIZED_BOTH );
if( !FlatNativeWindowBorder.showWindow( frame, FlatNativeWindowBorder.Provider.SW_MAXIMIZE ) )
frame.setExtendedState( frame.getExtendedState() | Frame.MAXIMIZED_BOTH );
}
protected void updateMaximizedBounds() {
Frame frame = (Frame) window;
// set maximized bounds to avoid that maximized window overlaps Windows task bar
// (if not running in JBR and if not modified from the application)
// (if not having native window border and if not modified from the application)
Rectangle oldMaximizedBounds = frame.getMaximizedBounds();
if( !hasJBRCustomDecoration() &&
if( !hasNativeCustomDecoration() &&
(oldMaximizedBounds == null ||
Objects.equals( oldMaximizedBounds, rootPane.getClientProperty( "_flatlaf.maximizedBounds" ) )) )
{
@@ -584,8 +671,11 @@ debug*/
* Restores the window size.
*/
protected void restore() {
if( window instanceof Frame ) {
Frame frame = (Frame) window;
if( !(window instanceof Frame) )
return;
Frame frame = (Frame) window;
if( !FlatNativeWindowBorder.showWindow( window, FlatNativeWindowBorder.Provider.SW_RESTORE ) ) {
int state = frame.getExtendedState();
frame.setExtendedState( ((state & Frame.ICONIFIED) != 0)
? (state & ~Frame.ICONIFIED)
@@ -601,65 +691,133 @@ debug*/
window.dispatchEvent( new WindowEvent( window, WindowEvent.WINDOW_CLOSING ) );
}
protected boolean hasJBRCustomDecoration() {
return FlatRootPaneUI.canUseJBRCustomDecorations &&
window != null &&
JBRCustomDecorations.hasCustomDecoration( window );
private boolean hasJBRCustomDecoration() {
return window != null && JBRCustomDecorations.hasCustomDecoration( window );
}
protected void updateJBRHitTestSpotsAndTitleBarHeightLater() {
/**
* Returns whether windows uses native window border and has custom decorations enabled.
*/
protected boolean hasNativeCustomDecoration() {
return window != null && FlatNativeWindowBorder.hasCustomDecoration( window );
}
protected void updateNativeTitleBarHeightAndHitTestSpotsLater() {
EventQueue.invokeLater( () -> {
updateJBRHitTestSpotsAndTitleBarHeight();
updateNativeTitleBarHeightAndHitTestSpots();
} );
}
protected void updateJBRHitTestSpotsAndTitleBarHeight() {
protected void updateNativeTitleBarHeightAndHitTestSpots() {
if( !isDisplayable() )
return;
if( !hasJBRCustomDecoration() )
if( !hasNativeCustomDecoration() )
return;
List<Rectangle> hitTestSpots = new ArrayList<>();
if( iconLabel.isVisible() )
addJBRHitTestSpot( iconLabel, false, hitTestSpots );
addJBRHitTestSpot( buttonPanel, false, hitTestSpots );
addJBRHitTestSpot( menuBarPlaceholder, true, hitTestSpots );
int titleBarHeight = getHeight();
// slightly reduce height so that component receives mouseExit events
if( titleBarHeight > 0 )
titleBarHeight--;
JBRCustomDecorations.setHitTestSpotsAndTitleBarHeight( window, hitTestSpots, titleBarHeight );
List<Rectangle> hitTestSpots = new ArrayList<>();
Rectangle appIconBounds = null;
if( iconLabel.isVisible() ) {
// compute real icon size (without insets; 1px wider for easier hitting)
Point location = SwingUtilities.convertPoint( iconLabel, 0, 0, window );
Insets iconInsets = iconLabel.getInsets();
Rectangle iconBounds = new Rectangle(
location.x + iconInsets.left - 1,
location.y + iconInsets.top - 1,
iconLabel.getWidth() - iconInsets.left - iconInsets.right + 2,
iconLabel.getHeight() - iconInsets.top - iconInsets.bottom + 2 );
// if frame is maximized, increase icon bounds to upper-left corner
// of window to allow closing window via double-click in upper-left corner
if( window instanceof Frame &&
(((Frame)window).getExtendedState() & Frame.MAXIMIZED_BOTH) != 0 )
{
iconBounds.height += iconBounds.y;
iconBounds.y = 0;
if( window.getComponentOrientation().isLeftToRight() ) {
iconBounds.width += iconBounds.x;
iconBounds.x = 0;
} else
iconBounds.width += iconInsets.right;
}
if( hasJBRCustomDecoration() )
hitTestSpots.add( iconBounds );
else
appIconBounds = iconBounds;
}
Rectangle r = getNativeHitTestSpot( buttonPanel );
if( r != null )
hitTestSpots.add( r );
JMenuBar menuBar = rootPane.getJMenuBar();
if( hasVisibleEmbeddedMenuBar( menuBar ) ) {
r = getNativeHitTestSpot( menuBarPlaceholder );
if( r != null ) {
Component horizontalGlue = findHorizontalGlue( menuBar );
if( horizontalGlue != null ) {
// If menu bar is embedded and contains a horizontal glue component,
// then split the hit test spot into two spots so that
// the glue component area can used to move the window.
Point glueLocation = SwingUtilities.convertPoint( horizontalGlue, 0, 0, window );
Rectangle r2;
if( getComponentOrientation().isLeftToRight() ) {
int trailingWidth = (r.x + r.width - HIT_TEST_SPOT_GROW) - glueLocation.x;
r.width -= trailingWidth;
r2 = new Rectangle( glueLocation.x + horizontalGlue.getWidth(), r.y, trailingWidth, r.height );
} else {
int leadingWidth = (glueLocation.x + horizontalGlue.getWidth()) - (r.x + HIT_TEST_SPOT_GROW);
r.x += leadingWidth;
r.width -= leadingWidth;
r2 = new Rectangle( glueLocation.x -leadingWidth, r.y, leadingWidth, r.height );
}
r2.grow( HIT_TEST_SPOT_GROW, HIT_TEST_SPOT_GROW );
hitTestSpots.add( r2 );
}
hitTestSpots.add( r );
}
}
FlatNativeWindowBorder.setTitleBarHeightAndHitTestSpots( window, titleBarHeight, hitTestSpots, appIconBounds );
/*debug
debugHitTestSpots = hitTestSpots;
debugTitleBarHeight = titleBarHeight;
debugHitTestSpots = hitTestSpots;
debugAppIconBounds = appIconBounds;
repaint();
debug*/
}
protected void addJBRHitTestSpot( JComponent c, boolean subtractMenuBarMargins, List<Rectangle> hitTestSpots ) {
protected Rectangle getNativeHitTestSpot( JComponent c ) {
Dimension size = c.getSize();
if( size.width <= 0 || size.height <= 0 )
return;
return null;
Point location = SwingUtilities.convertPoint( c, 0, 0, window );
Rectangle r = new Rectangle( location, size );
if( subtractMenuBarMargins )
r = FlatUIUtils.subtractInsets( r, UIScale.scale( getMenuBarMargins() ) );
// slightly increase rectangle so that component receives mouseExit events
r.grow( 2, 2 );
hitTestSpots.add( r );
r.grow( HIT_TEST_SPOT_GROW, HIT_TEST_SPOT_GROW );
return r;
}
private static final int HIT_TEST_SPOT_GROW = 2;
/*debug
private List<Rectangle> debugHitTestSpots;
private int debugTitleBarHeight;
private List<Rectangle> debugHitTestSpots;
private Rectangle debugAppIconBounds;
debug*/
//---- class TitlePaneBorder ----------------------------------------------
//---- class FlatTitlePaneBorder ------------------------------------------
protected class FlatTitlePaneBorder
extends AbstractBorder
@@ -676,8 +834,8 @@ debug*/
} else if( borderColor != null && (rootPane.getJMenuBar() == null || !rootPane.getJMenuBar().isVisible()) )
insets.bottom += UIScale.scale( 1 );
if( hasJBRCustomDecoration() )
insets = FlatUIUtils.addInsets( insets, JBRWindowTopBorder.getInstance().getBorderInsets() );
if( hasNativeCustomDecoration() && !isWindowMaximized( c ) )
insets = FlatUIUtils.addInsets( insets, WindowTopBorder.getInstance().getBorderInsets() );
return insets;
}
@@ -695,13 +853,57 @@ debug*/
FlatUIUtils.paintFilledRectangle( g, borderColor, x, y + height - lineHeight, width, lineHeight );
}
if( hasJBRCustomDecoration() )
JBRWindowTopBorder.getInstance().paintBorder( c, g, x, y, width, height );
if( hasNativeCustomDecoration() && !isWindowMaximized( c ) )
WindowTopBorder.getInstance().paintBorder( c, g, x, y, width, height );
}
protected Border getMenuBarBorder() {
JMenuBar menuBar = rootPane.getJMenuBar();
return (menuBar != null && menuBar.isVisible() && isMenuBarEmbedded()) ? menuBar.getBorder() : null;
return hasVisibleEmbeddedMenuBar( menuBar ) ? menuBar.getBorder() : null;
}
protected boolean isWindowMaximized( Component c ) {
return window instanceof Frame
? (((Frame)window).getExtendedState() & Frame.MAXIMIZED_BOTH) != 0
: false;
}
}
//---- class FlatTitleLabelUI ---------------------------------------------
/**
* @since 1.1
*/
protected class FlatTitleLabelUI
extends FlatLabelUI
{
@Override
protected void paintEnabledText( JLabel l, Graphics g, String s, int textX, int textY ) {
boolean hasEmbeddedMenuBar = hasVisibleEmbeddedMenuBar( rootPane.getJMenuBar() );
int labelWidth = l.getWidth();
int textWidth = labelWidth - (textX * 2);
int gap = UIScale.scale( menuBarTitleGap );
// The passed in textX coordinate is always to horizontally center the text within the label bounds.
// Modify textX so that the text is painted either centered within the window bounds or leading aligned.
boolean center = hasEmbeddedMenuBar ? centerTitleIfMenuBarEmbedded : centerTitle;
if( center ) {
// If window is wide enough, center title within window bounds.
// Otherwise leave it centered within free space (label bounds).
int centeredTextX = ((l.getParent().getWidth() - textWidth) / 2) - l.getX();
if( centeredTextX >= gap && centeredTextX + textWidth <= labelWidth - gap )
textX = centeredTextX;
} else {
// leading aligned
boolean leftToRight = getComponentOrientation().isLeftToRight();
Insets insets = l.getInsets();
int leadingInset = hasEmbeddedMenuBar ? gap : (leftToRight ? insets.left : insets.right);
int leadingTextX = leftToRight ? leadingInset : labelWidth - leadingInset - textWidth;
if( leftToRight ? leadingTextX < textX : leadingTextX > textX )
textX = leadingTextX;
}
super.paintEnabledText( l, g, s, textX, textY );
}
}
@@ -730,7 +932,7 @@ debug*/
break;
case "componentOrientation":
updateJBRHitTestSpotsAndTitleBarHeightLater();
updateNativeTitleBarHeightAndHitTestSpotsLater();
break;
}
}
@@ -740,10 +942,10 @@ debug*/
@Override
public void windowActivated( WindowEvent e ) {
activeChanged( true );
updateJBRHitTestSpotsAndTitleBarHeight();
updateNativeTitleBarHeightAndHitTestSpots();
if( hasJBRCustomDecoration() )
JBRWindowTopBorder.getInstance().repaintBorder( FlatTitlePane.this );
if( hasNativeCustomDecoration() )
WindowTopBorder.getInstance().repaintBorder( FlatTitlePane.this );
repaintWindowBorder();
}
@@ -751,10 +953,10 @@ debug*/
@Override
public void windowDeactivated( WindowEvent e ) {
activeChanged( false );
updateJBRHitTestSpotsAndTitleBarHeight();
updateNativeTitleBarHeightAndHitTestSpots();
if( hasJBRCustomDecoration() )
JBRWindowTopBorder.getInstance().repaintBorder( FlatTitlePane.this );
if( hasNativeCustomDecoration() )
WindowTopBorder.getInstance().repaintBorder( FlatTitlePane.this );
repaintWindowBorder();
}
@@ -762,7 +964,7 @@ debug*/
@Override
public void windowStateChanged( WindowEvent e ) {
frameStateChanged();
updateJBRHitTestSpotsAndTitleBarHeight();
updateNativeTitleBarHeightAndHitTestSpots();
}
//---- interface MouseListener ----
@@ -775,7 +977,7 @@ debug*/
if( e.getSource() == iconLabel ) {
// double-click on icon closes window
close();
} else if( !hasJBRCustomDecoration() &&
} else if( !hasNativeCustomDecoration() &&
window instanceof Frame &&
((Frame)window).isResizable() )
{
@@ -808,8 +1010,8 @@ debug*/
if( window == null )
return; // should newer occur
if( hasJBRCustomDecoration() )
return; // do nothing if running in JBR
if( hasNativeCustomDecoration() )
return; // do nothing if having native window border
// restore window if it is maximized
if( window instanceof Frame ) {
@@ -852,7 +1054,7 @@ debug*/
@Override
public void componentResized( ComponentEvent e ) {
updateJBRHitTestSpotsAndTitleBarHeightLater();
updateNativeTitleBarHeightAndHitTestSpotsLater();
}
@Override

View File

@@ -20,8 +20,6 @@ import java.awt.Dimension;
import java.awt.Image;
import java.util.ArrayList;
import java.util.List;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import com.formdev.flatlaf.util.MultiResolutionImageSupport;
import com.formdev.flatlaf.util.ScaledImageIcon;
@@ -31,40 +29,43 @@ import com.formdev.flatlaf.util.ScaledImageIcon;
public class FlatTitlePaneIcon
extends ScaledImageIcon
{
public static Icon create( List<Image> images, Dimension size ) {
// collect all images including multi-resolution variants
private final List<Image> images;
/**
* @since 1.2
*/
public FlatTitlePaneIcon( List<Image> images, Dimension size ) {
super( null, size.width, size.height );
this.images = images;
}
@Override
protected Image getResolutionVariant( int destImageWidth, int destImageHeight ) {
// collect all images including multi-resolution variants for requested size
List<Image> allImages = new ArrayList<>();
for( Image image : images ) {
if( MultiResolutionImageSupport.isMultiResolutionImage( image ) )
allImages.addAll( MultiResolutionImageSupport.getResolutionVariants( image ) );
allImages.add( MultiResolutionImageSupport.getResolutionVariant( image, destImageWidth, destImageHeight ) );
else
allImages.add( image );
}
if( allImages.size() == 1 )
return allImages.get( 0 );
// sort images by size
allImages.sort( (image1, image2) -> {
return image1.getWidth( null ) - image2.getWidth( null );
} );
// create icon
return new FlatTitlePaneIcon( allImages, size );
}
private final List<Image> images;
private FlatTitlePaneIcon( List<Image> images, Dimension size ) {
super( new ImageIcon( images.get( 0 ) ), size.width, size.height );
this.images = images;
}
@Override
protected Image getResolutionVariant( int destImageWidth, int destImageHeight ) {
for( Image image : images ) {
// search for optimal image size
for( Image image : allImages ) {
if( destImageWidth <= image.getWidth( null ) &&
destImageHeight <= image.getHeight( null ) )
return image;
}
return images.get( images.size() - 1 );
// use largest image
return allImages.get( allImages.size() - 1 );
}
}

View File

@@ -22,6 +22,7 @@ import java.awt.event.ContainerEvent;
import java.awt.event.ContainerListener;
import javax.swing.AbstractButton;
import javax.swing.JComponent;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicToolBarUI;
@@ -41,15 +42,47 @@ import javax.swing.plaf.basic.BasicToolBarUI;
* @uiDefault ToolBar.floatingForeground Color
* @uiDefault ToolBar.isRollover boolean
*
* <!-- FlatToolBarUI -->
*
* @uiDefault ToolBar.focusableButtons boolean
*
* @author Karl Tauber
*/
public class FlatToolBarUI
extends BasicToolBarUI
{
/** @since 1.4 */
protected boolean focusableButtons;
public static ComponentUI createUI( JComponent c ) {
return new FlatToolBarUI();
}
@Override
public void installUI( JComponent c ) {
super.installUI( c );
// disable focusable state of buttons (when switching from another Laf)
if( !focusableButtons )
setButtonsFocusable( false );
}
@Override
public void uninstallUI( JComponent c ) {
super.uninstallUI( c );
// re-enable focusable state of buttons (when switching to another Laf)
if( !focusableButtons )
setButtonsFocusable( true );
}
@Override
protected void installDefaults() {
super.installDefaults();
focusableButtons = UIManager.getBoolean( "ToolBar.focusableButtons" );
}
@Override
protected ContainerListener createToolBarContListener() {
return new ToolBarContListener() {
@@ -57,22 +90,36 @@ public class FlatToolBarUI
public void componentAdded( ContainerEvent e ) {
super.componentAdded( e );
Component c = e.getChild();
if( c instanceof AbstractButton )
c.setFocusable( false );
if( !focusableButtons ) {
Component c = e.getChild();
if( c instanceof AbstractButton )
c.setFocusable( false );
}
}
@Override
public void componentRemoved( ContainerEvent e ) {
super.componentRemoved( e );
Component c = e.getChild();
if( c instanceof AbstractButton )
c.setFocusable( true );
if( !focusableButtons ) {
Component c = e.getChild();
if( c instanceof AbstractButton )
c.setFocusable( true );
}
}
};
}
/**
* @since 1.4
*/
protected void setButtonsFocusable( boolean focusable ) {
for( Component c : toolBar.getComponents() ) {
if( c instanceof AbstractButton )
c.setFocusable( focusable );
}
}
// disable rollover border
@Override protected void setBorderToRollover( Component c ) {}
@Override protected void setBorderToNonRollover( Component c ) {}

View File

@@ -71,7 +71,7 @@ public class FlatToolTipUI
if( sharedPropertyChangedListener == null ) {
sharedPropertyChangedListener = e -> {
String name = e.getPropertyName();
if( name == "text" || name == "font" || name == "foreground" ) {
if( name == "tiptext" || name == "font" || name == "foreground" ) {
JToolTip toolTip = (JToolTip) e.getSource();
FlatLabelUI.updateHTMLRenderer( toolTip, toolTip.getTipText(), false );
}

View File

@@ -16,6 +16,8 @@
package com.formdev.flatlaf.ui;
import static com.formdev.flatlaf.FlatClientProperties.*;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
@@ -23,10 +25,11 @@ import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.CellRendererPane;
import javax.swing.Icon;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JTree;
import javax.swing.LookAndFeel;
import javax.swing.SwingUtilities;
@@ -104,6 +107,8 @@ public class FlatTreeUI
protected boolean wideSelection;
protected boolean showCellFocusIndicator;
private Color defaultCellNonSelectionBackground;
public static ComponentUI createUI( JComponent c ) {
return new FlatTreeUI();
}
@@ -122,6 +127,8 @@ public class FlatTreeUI
wideSelection = UIManager.getBoolean( "Tree.wideSelection" );
showCellFocusIndicator = UIManager.getBoolean( "Tree.showCellFocusIndicator" );
defaultCellNonSelectionBackground = UIManager.getColor( "Tree.textBackground" );
// scale
int rowHeight = FlatUIUtils.getUIInt( "Tree.rowHeight", 16 );
if( rowHeight > 0 )
@@ -141,13 +148,12 @@ public class FlatTreeUI
selectionInactiveBackground = null;
selectionInactiveForeground = null;
selectionBorderColor = null;
defaultCellNonSelectionBackground = null;
}
@Override
protected MouseListener createMouseListener() {
if( !wideSelection )
return super.createMouseListener();
return new BasicTreeUI.MouseHandler() {
@Override
public void mousePressed( MouseEvent e ) {
@@ -165,7 +171,7 @@ public class FlatTreeUI
}
private MouseEvent handleWideMouseEvent( MouseEvent e ) {
if( !tree.isEnabled() || !SwingUtilities.isLeftMouseButton( e ) || e.isConsumed() )
if( !isWideSelection() || !tree.isEnabled() || !SwingUtilities.isLeftMouseButton( e ) || e.isConsumed() )
return e;
int x = e.getX();
@@ -192,32 +198,58 @@ public class FlatTreeUI
@Override
protected PropertyChangeListener createPropertyChangeListener() {
if( !wideSelection )
return super.createPropertyChangeListener();
PropertyChangeListener superListener = super.createPropertyChangeListener();
return e -> {
superListener.propertyChange( e );
return new BasicTreeUI.PropertyChangeHandler() {
@Override
public void propertyChange( PropertyChangeEvent e ) {
super.propertyChange( e );
if( e.getSource() == tree ) {
switch( e.getPropertyName() ) {
case TREE_WIDE_SELECTION:
case TREE_PAINT_SELECTION:
tree.repaint();
break;
if( e.getSource() == tree && e.getPropertyName() == "dropLocation" ) {
JTree.DropLocation oldValue = (JTree.DropLocation) e.getOldValue();
repaintWideDropLocation( oldValue );
repaintWideDropLocation( tree.getDropLocation() );
case "dropLocation":
if( isWideSelection() ) {
JTree.DropLocation oldValue = (JTree.DropLocation) e.getOldValue();
repaintWideDropLocation( oldValue );
repaintWideDropLocation( tree.getDropLocation() );
}
break;
}
}
private void repaintWideDropLocation(JTree.DropLocation loc) {
if( loc == null || isDropLine( loc ) )
return;
Rectangle r = tree.getPathBounds( loc.getPath() );
if( r != null )
tree.repaint( 0, r.y, tree.getWidth(), r.height );
}
};
}
private void repaintWideDropLocation(JTree.DropLocation loc) {
if( loc == null || isDropLine( loc ) )
return;
Rectangle r = tree.getPathBounds( loc.getPath() );
if( r != null )
tree.repaint( 0, r.y, tree.getWidth(), r.height );
}
@Override
public Rectangle getPathBounds( JTree tree, TreePath path ) {
Rectangle bounds = super.getPathBounds( tree, path );
// If this method was invoked from JTree.getPathForLocation(int x, int y) to check whether
// the location is within tree node bounds, then return the bounds of a wide node.
// This changes the behavior of JTree.getPathForLocation(int x, int y) and
// JTree.getRowForLocation(int x, int y), which now return the path/row even
// if [x,y] is in the wide row area outside of the actual tree node.
if( bounds != null &&
isWideSelection() &&
UIManager.getBoolean( "FlatLaf.experimental.tree.widePathForLocation" ) &&
StackUtils.wasInvokedFrom( JTree.class.getName(), "getPathForLocation", 5 ) )
{
bounds.x = 0;
bounds.width = tree.getWidth();
}
return bounds;
}
/**
* Same as super.paintRow(), but supports wide selection and uses
* inactive selection background/foreground if tree is not focused.
@@ -227,34 +259,22 @@ public class FlatTreeUI
TreePath path, int row, boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf )
{
boolean isEditing = (editingComponent != null && editingRow == row);
boolean hasFocus = FlatUIUtils.isPermanentFocusOwner( tree );
boolean cellHasFocus = hasFocus && (row == getLeadSelectionRow());
boolean isSelected = tree.isRowSelected( row );
boolean isDropRow = isDropRow( row );
boolean needsSelectionPainting = (isSelected || isDropRow) && isPaintSelection();
// do not paint row if editing, except if selection needs painted
if( isEditing && !needsSelectionPainting )
return;
boolean hasFocus = FlatUIUtils.isPermanentFocusOwner( tree );
boolean cellHasFocus = hasFocus && (row == getLeadSelectionRow());
// if tree is used as cell renderer in another component (e.g. in Rhino JavaScript debugger),
// check whether that component is focused to get correct selection colors
if( !hasFocus && isSelected && tree.getParent() instanceof CellRendererPane )
hasFocus = FlatUIUtils.isPermanentFocusOwner( tree.getParent().getParent() );
// wide selection background
if( wideSelection && (isSelected || isDropRow) ) {
// fill background
g.setColor( isDropRow
? UIManager.getColor( "Tree.dropCellBackground" )
: (hasFocus ? selectionBackground : selectionInactiveBackground) );
g.fillRect( 0, bounds.y, tree.getWidth(), bounds.height );
// paint expand/collapse icon
if( shouldPaintExpandControl( path, row, isExpanded, hasBeenExpanded, isLeaf ) ) {
paintExpandControl( g, clipBounds, insets, bounds,
path, row, isExpanded, hasBeenExpanded, isLeaf );
}
}
if( isEditing )
return;
// get renderer component
Component rendererComponent = currentCellRenderer.getTreeCellRendererComponent( tree,
path.getLastPathComponent(), isSelected, isExpanded, isLeaf, row, cellHasFocus );
@@ -290,8 +310,51 @@ public class FlatTreeUI
}
}
// paint selection background
if( needsSelectionPainting ) {
// set selection color
Color oldColor = g.getColor();
g.setColor( isDropRow
? UIManager.getColor( "Tree.dropCellBackground" )
: (rendererComponent instanceof DefaultTreeCellRenderer
? ((DefaultTreeCellRenderer)rendererComponent).getBackgroundSelectionColor()
: (hasFocus ? selectionBackground : selectionInactiveBackground)) );
if( isWideSelection() ) {
// wide selection
g.fillRect( 0, bounds.y, tree.getWidth(), bounds.height );
// paint expand/collapse icon
// (was already painted before, but painted over with wide selection)
if( shouldPaintExpandControl( path, row, isExpanded, hasBeenExpanded, isLeaf ) ) {
paintExpandControl( g, clipBounds, insets, bounds,
path, row, isExpanded, hasBeenExpanded, isLeaf );
}
} else {
// non-wide selection
paintCellBackground( g, rendererComponent, bounds );
}
// this is actually not necessary because renderer should always set color
// before painting, but doing anyway to avoid any side effect (in bad renderers)
g.setColor( oldColor );
} else {
// paint cell background if DefaultTreeCellRenderer.getBackgroundNonSelectionColor() is set
if( rendererComponent instanceof DefaultTreeCellRenderer ) {
DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) rendererComponent;
Color bg = renderer.getBackgroundNonSelectionColor();
if( bg != null && !bg.equals( defaultCellNonSelectionBackground ) ) {
Color oldColor = g.getColor();
g.setColor( bg );
paintCellBackground( g, rendererComponent, bounds );
g.setColor( oldColor );
}
}
}
// paint renderer
rendererPane.paintComponent( g, rendererComponent, tree, bounds.x, bounds.y, bounds.width, bounds.height, true );
if( !isEditing )
rendererPane.paintComponent( g, rendererComponent, tree, bounds.x, bounds.y, bounds.width, bounds.height, true );
// restore background selection color and border selection color
if( oldBackgroundSelectionColor != null )
@@ -300,6 +363,22 @@ public class FlatTreeUI
((DefaultTreeCellRenderer)rendererComponent).setBorderSelectionColor( oldBorderSelectionColor );
}
private void paintCellBackground( Graphics g, Component rendererComponent, Rectangle bounds ) {
int xOffset = 0;
int imageOffset = 0;
if( rendererComponent instanceof JLabel ) {
JLabel label = (JLabel) rendererComponent;
Icon icon = label.getIcon();
imageOffset = (icon != null && label.getText() != null)
? icon.getIconWidth() + Math.max( label.getIconTextGap() - 1, 0 )
: 0;
xOffset = label.getComponentOrientation().isLeftToRight() ? imageOffset : 0;
}
g.fillRect( bounds.x + xOffset, bounds.y, bounds.width - imageOffset, bounds.height );
}
/**
* Checks whether dropping on a row.
* See DefaultTreeCellRenderer.getTreeCellRendererComponent().
@@ -314,6 +393,14 @@ public class FlatTreeUI
@Override
protected Rectangle getDropLineRect( DropLocation loc ) {
Rectangle r = super.getDropLineRect( loc );
return wideSelection ? new Rectangle( 0, r.y, tree.getWidth(), r.height ) : r;
return isWideSelection() ? new Rectangle( 0, r.y, tree.getWidth(), r.height ) : r;
}
protected boolean isWideSelection() {
return clientPropertyBoolean( tree, TREE_WIDE_SELECTION, wideSelection );
}
protected boolean isPaintSelection() {
return clientPropertyBoolean( tree, TREE_PAINT_SELECTION, true );
}
}

View File

@@ -16,6 +16,7 @@
package com.formdev.flatlaf.ui;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
@@ -30,6 +31,7 @@ import java.awt.KeyboardFocusManager;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.Window;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
@@ -39,10 +41,12 @@ import java.awt.geom.Rectangle2D;
import java.awt.geom.RoundRectangle2D;
import java.util.IdentityHashMap;
import java.util.WeakHashMap;
import java.util.function.Predicate;
import java.util.function.Supplier;
import javax.swing.JComponent;
import javax.swing.JTable;
import javax.swing.LookAndFeel;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.border.Border;
@@ -50,6 +54,7 @@ import javax.swing.border.CompoundBorder;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.UIResource;
import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.FlatSystemProperties;
import com.formdev.flatlaf.util.DerivedColor;
import com.formdev.flatlaf.util.Graphics2DProxy;
import com.formdev.flatlaf.util.HiDPIUtils;
@@ -64,6 +69,7 @@ public class FlatUIUtils
{
public static final boolean MAC_USE_QUARTZ = Boolean.getBoolean( "apple.awt.graphics.UseQuartz" );
private static boolean useSharedUIs = true;
private static WeakHashMap<LookAndFeel, IdentityHashMap<Object, ComponentUI>> sharedUIinstances = new WeakHashMap<>();
public static Rectangle addInsets( Rectangle r, Insets insets ) {
@@ -89,6 +95,11 @@ public class FlatUIUtils
}
public static Insets addInsets( Insets insets1, Insets insets2 ) {
if( insets1 == null )
return insets2;
if( insets2 == null )
return insets1;
return new Insets(
insets1.top + insets2.top,
insets1.left + insets2.left,
@@ -118,6 +129,14 @@ public class FlatUIUtils
return (color != null) ? color : UIManager.getColor( defaultKey );
}
/**
* @since 1.1
*/
public static boolean getUIBoolean( String key, boolean defaultValue ) {
Object value = UIManager.get( key );
return (value instanceof Boolean) ? (Boolean) value : defaultValue;
}
public static int getUIInt( String key, int defaultValue ) {
Object value = UIManager.get( key );
return (value instanceof Integer) ? (Integer) value : defaultValue;
@@ -128,6 +147,25 @@ public class FlatUIUtils
return (value instanceof Number) ? ((Number)value).floatValue() : defaultValue;
}
/**
* @since 1.1.2
*/
public static boolean getBoolean( JComponent c, String systemPropertyKey,
String clientPropertyKey, String uiKey, boolean defaultValue )
{
// check whether forced to true/false via system property
Boolean value = FlatSystemProperties.getBooleanStrict( systemPropertyKey, null );
if( value != null )
return value;
// check whether forced to true/false via client property
value = FlatClientProperties.clientPropertyBooleanStrict( c, clientPropertyKey, null );
if( value != null )
return value;
return getUIBoolean( uiKey, defaultValue );
}
public static boolean isChevron( String arrowType ) {
return !"triangle".equals( arrowType );
}
@@ -173,12 +211,29 @@ public class FlatUIUtils
/**
* Returns whether the given component is the permanent focus owner and
* is in the active window. Used to paint focus indicators.
* is in the active window or in a popup window owned by the active window.
* Used to paint focus indicators.
*/
@SuppressWarnings( "unchecked" )
public static boolean isPermanentFocusOwner( Component c ) {
KeyboardFocusManager keyboardFocusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
if( c instanceof JComponent ) {
Object value = ((JComponent)c).getClientProperty( FlatClientProperties.COMPONENT_FOCUS_OWNER );
if( value instanceof Predicate ) {
return ((Predicate<JComponent>)value).test( (JComponent) c ) &&
isInActiveWindow( c, keyboardFocusManager.getActiveWindow() );
}
}
return keyboardFocusManager.getPermanentFocusOwner() == c &&
keyboardFocusManager.getActiveWindow() == SwingUtilities.windowForComponent( c );
isInActiveWindow( c, keyboardFocusManager.getActiveWindow() );
}
private static boolean isInActiveWindow( Component c, Window activeWindow ) {
Window window = SwingUtilities.windowForComponent( c );
return window == activeWindow ||
(window != null && window.getType() == Window.Type.POPUP && window.getOwner() == activeWindow);
}
/**
@@ -334,7 +389,7 @@ public class FlatUIUtils
float innerArc = arc - (lineWidth * 2);
// reduce outer arc slightly for small arcs to make the curve slightly wider
if( arc > 0 && arc < UIScale.scale( 10 ) )
if( focusWidth > 0 && arc > 0 && arc < UIScale.scale( 10 ) )
outerArc -= UIScale.scale( 2f );
Path2D path = new Path2D.Float( Path2D.WIND_EVEN_ODD );
@@ -593,6 +648,113 @@ public class FlatUIUtils
return rect;
}
/**
* Paints a chevron or triangle arrow in the center of the given rectangle.
*
* @param g the graphics context used for painting
* @param x the x coordinate of the rectangle
* @param y the y coordinate of the rectangle
* @param width the width of the rectangle
* @param height the height of the rectangle
* @param direction the arrow direction ({@link SwingConstants#NORTH}, {@link SwingConstants#SOUTH}
* {@link SwingConstants#WEST} or {@link SwingConstants#EAST})
* @param chevron {@code true} for chevron arrow, {@code false} for triangle arrow
* @param arrowSize the width of the painted arrow (for vertical direction) (will be scaled)
* @param xOffset a offset added to the x coordinate of the arrow to paint it out-of-center. Usually zero. (will be scaled)
* @param yOffset a offset added to the y coordinate of the arrow to paint it out-of-center. Usually zero. (will be scaled)
*
* @since 1.1
*/
public static void paintArrow( Graphics2D g, int x, int y, int width, int height,
int direction, boolean chevron, int arrowSize, float xOffset, float yOffset )
{
// compute arrow width/height
int aw = UIScale.scale( arrowSize + (chevron ? 0 : 1) );
int ah = UIScale.scale( (arrowSize / 2) + (chevron ? 0 : 1) );
// rotate arrow width/height for horizontal directions
boolean vert = (direction == SwingConstants.NORTH || direction == SwingConstants.SOUTH);
if( !vert ) {
int temp = aw;
aw = ah;
ah = temp;
}
// chevron lines end 1px outside of width/height
// --> add 1px to arrow width/height for position calculation
int extra = chevron ? 1 : 0;
// compute arrow location
float ox = ((width - (aw + extra)) / 2f) + UIScale.scale( xOffset );
float oy = ((height - (ah + extra)) / 2f) + UIScale.scale( yOffset );
int ax = x + ((direction == SwingConstants.WEST) ? -Math.round( -ox ) : Math.round( ox ));
int ay = y + ((direction == SwingConstants.NORTH) ? -Math.round( -oy ) : Math.round( oy ));
// paint arrow
g.translate( ax, ay );
/*debug
debugPaintArrow( g, Color.red, vert, aw + extra, ah + extra );
debug*/
Shape arrowShape = createArrowShape( direction, chevron, aw, ah );
if( chevron ) {
Stroke oldStroke = g.getStroke();
g.setStroke( new BasicStroke( UIScale.scale( 1f ) ) );
g.draw( arrowShape );
g.setStroke( oldStroke );
} else {
// triangle
g.fill( arrowShape );
}
g.translate( -ax, -ay );
}
/**
* Creates a chevron or triangle arrow shape for the given direction and size.
* <p>
* The chevron shape is a open path that can be painted with {@link Graphics2D#draw(Shape)}.
* The triangle shape is a close path that can be painted with {@link Graphics2D#fill(Shape)}.
*
* @param direction the arrow direction ({@link SwingConstants#NORTH}, {@link SwingConstants#SOUTH}
* {@link SwingConstants#WEST} or {@link SwingConstants#EAST})
* @param chevron {@code true} for chevron arrow, {@code false} for triangle arrow
* @param w the width of the returned shape
* @param h the height of the returned shape
*
* @since 1.1
*/
public static Shape createArrowShape( int direction, boolean chevron, float w, float h ) {
switch( direction ) {
case SwingConstants.NORTH: return createPath( !chevron, 0,h, (w / 2f),0, w,h );
case SwingConstants.SOUTH: return createPath( !chevron, 0,0, (w / 2f),h, w,0 );
case SwingConstants.WEST: return createPath( !chevron, w,0, 0,(h / 2f), w,h );
case SwingConstants.EAST: return createPath( !chevron, 0,0, w,(h / 2f), 0,h );
default: return new Path2D.Float();
}
}
/*debug
private static void debugPaintArrow( Graphics2D g, Color color, boolean vert, int w, int h ) {
Color oldColor = g.getColor();
g.setColor( color );
g.fill( createRectangle( 0, 0, w, h, 1 ) );
int xy1 = -2;
int x2 = w + 1;
int y2 = h + 1;
for( int i = 0; i < 20; i++ ) {
g.fillRect( 0, xy1, 1, 1 );
g.fillRect( 0, y2, 1, 1 );
g.fillRect( xy1, 0, 1, 1 );
g.fillRect( x2, 0, 1, 1 );
xy1 -= 2;
x2 += 2;
y2 += 2;
}
g.setColor( oldColor );
}
debug*/
/**
* Creates a closed path for the given points.
*/
@@ -664,6 +826,27 @@ public class FlatUIUtils
return explicitlySet;
}
/**
* Returns whether shared UI delegates are used.
*
* @since 1.6
*/
public static boolean isUseSharedUIs() {
return useSharedUIs;
}
/**
* Specifies whether shared UI delegates are used.
* This does not change already existing UI delegates.
*
* @since 1.6
*/
public static boolean setUseSharedUIs( boolean useSharedUIs ) {
boolean old = FlatUIUtils.useSharedUIs;
FlatUIUtils.useSharedUIs = useSharedUIs;
return old;
}
/**
* Creates a shared component UI for the given key and the current Laf.
* Each Laf instance has its own shared component UI instance.
@@ -672,6 +855,9 @@ public class FlatUIUtils
* may use multiple Laf instances at the same time.
*/
public static ComponentUI createSharedUI( Object key, Supplier<ComponentUI> newInstanceSupplier ) {
if( !useSharedUIs )
return newInstanceSupplier.get();
return sharedUIinstances
.computeIfAbsent( UIManager.getLookAndFeel(), k -> new IdentityHashMap<>() )
.computeIfAbsent( key, k -> newInstanceSupplier.get() );
@@ -683,19 +869,23 @@ public class FlatUIUtils
implements FocusListener
{
private final Component repaintComponent;
private final Predicate<Component> repaintCondition;
public RepaintFocusListener( Component repaintComponent ) {
public RepaintFocusListener( Component repaintComponent, Predicate<Component> repaintCondition ) {
this.repaintComponent = repaintComponent;
this.repaintCondition = repaintCondition;
}
@Override
public void focusGained( FocusEvent e ) {
repaintComponent.repaint();
if( repaintCondition == null || repaintCondition.test( repaintComponent ) )
repaintComponent.repaint();
}
@Override
public void focusLost( FocusEvent e ) {
repaintComponent.repaint();
if( repaintCondition == null || repaintCondition.test( repaintComponent ) )
repaintComponent.repaint();
}
}
}

View File

@@ -181,8 +181,12 @@ public abstract class FlatWindowResizer
protected abstract boolean isWindowResizable();
protected abstract Rectangle getWindowBounds();
protected abstract void setWindowBounds( Rectangle r );
protected abstract boolean limitToParentBounds();
protected abstract Rectangle getParentBounds();
protected abstract boolean honorMinimumSizeOnResize();
protected abstract boolean honorMaximumSizeOnResize();
protected abstract Dimension getWindowMinimumSize();
protected abstract Dimension getWindowMaximumSize();
protected void beginResizing( int direction ) {}
protected void endResizing() {}
@@ -283,6 +287,16 @@ public abstract class FlatWindowResizer
}
}
@Override
protected boolean limitToParentBounds() {
return false;
}
@Override
protected Rectangle getParentBounds() {
return null;
}
@Override
protected boolean honorMinimumSizeOnResize() {
return
@@ -290,11 +304,21 @@ public abstract class FlatWindowResizer
(honorDialogMinimumSizeOnResize && window instanceof Dialog);
}
@Override
protected boolean honorMaximumSizeOnResize() {
return false;
}
@Override
protected Dimension getWindowMinimumSize() {
return window.getMinimumSize();
}
@Override
protected Dimension getWindowMaximumSize() {
return window.getMaximumSize();
}
@Override
boolean isDialog() {
return window instanceof Dialog;
@@ -354,16 +378,36 @@ public abstract class FlatWindowResizer
desktopManager.get().resizeFrame( getFrame(), r.x, r.y, r.width, r.height );
}
@Override
protected boolean limitToParentBounds() {
return true;
}
@Override
protected Rectangle getParentBounds() {
return getFrame().getParent().getBounds();
}
@Override
protected boolean honorMinimumSizeOnResize() {
return true;
}
@Override
protected boolean honorMaximumSizeOnResize() {
return true;
}
@Override
protected Dimension getWindowMinimumSize() {
return getFrame().getMinimumSize();
}
@Override
protected Dimension getWindowMaximumSize() {
return getFrame().getMaximumSize();
}
@Override
protected void beginResizing( int direction ) {
desktopManager.get().beginResizingFrame( getFrame(), direction );
@@ -521,7 +565,7 @@ debug*/
int xOnScreen = e.getXOnScreen();
int yOnScreen = e.getYOnScreen();
// Get current window bounds and compute new bounds based them.
// Get current window bounds and compute new bounds based on them.
// This is necessary because window manager may alter window bounds while resizing.
// E.g. when having two monitors with different scale factors and resizing
// a window on first screen to the second screen, then the window manager may
@@ -535,41 +579,72 @@ debug*/
// top
if( resizeDir == N_RESIZE_CURSOR || resizeDir == NW_RESIZE_CURSOR || resizeDir == NE_RESIZE_CURSOR ) {
newBounds.y = yOnScreen - dragTopOffset;
if( limitToParentBounds() && newBounds.y < 0 )
newBounds.y = 0;
newBounds.height += (oldBounds.y - newBounds.y);
}
// bottom
if( resizeDir == S_RESIZE_CURSOR || resizeDir == SW_RESIZE_CURSOR || resizeDir == SE_RESIZE_CURSOR )
if( resizeDir == S_RESIZE_CURSOR || resizeDir == SW_RESIZE_CURSOR || resizeDir == SE_RESIZE_CURSOR ) {
newBounds.height = (yOnScreen + dragBottomOffset) - newBounds.y;
if( limitToParentBounds() ) {
int parentHeight = getParentBounds().height;
if( newBounds.y + newBounds.height > parentHeight )
newBounds.height = parentHeight - newBounds.y;
}
}
// left
if( resizeDir == W_RESIZE_CURSOR || resizeDir == NW_RESIZE_CURSOR || resizeDir == SW_RESIZE_CURSOR ) {
newBounds.x = xOnScreen - dragLeftOffset;
if( limitToParentBounds() && newBounds.x < 0 )
newBounds.x = 0;
newBounds.width += (oldBounds.x - newBounds.x);
}
// right
if( resizeDir == E_RESIZE_CURSOR || resizeDir == NE_RESIZE_CURSOR || resizeDir == SE_RESIZE_CURSOR )
if( resizeDir == E_RESIZE_CURSOR || resizeDir == NE_RESIZE_CURSOR || resizeDir == SE_RESIZE_CURSOR ) {
newBounds.width = (xOnScreen + dragRightOffset) - newBounds.x;
if( limitToParentBounds() ) {
int parentWidth = getParentBounds().width;
if( newBounds.x + newBounds.width > parentWidth )
newBounds.width = parentWidth - newBounds.x;
}
}
// apply minimum window size
Dimension minimumSize = honorMinimumSizeOnResize() ? getWindowMinimumSize() : null;
if( minimumSize == null )
minimumSize = UIScale.scale( new Dimension( 150, 50 ) );
if( newBounds.width < minimumSize.width ) {
if( newBounds.x != oldBounds.x )
newBounds.x -= (minimumSize.width - newBounds.width);
newBounds.width = minimumSize.width;
}
if( newBounds.height < minimumSize.height ) {
if( newBounds.y != oldBounds.y )
newBounds.y -= (minimumSize.height - newBounds.height);
newBounds.height = minimumSize.height;
if( newBounds.width < minimumSize.width )
changeWidth( oldBounds, newBounds, minimumSize.width );
if( newBounds.height < minimumSize.height )
changeHeight( oldBounds, newBounds, minimumSize.height );
// apply maximum window size
if( honorMaximumSizeOnResize() ) {
Dimension maximumSize = getWindowMaximumSize();
if( newBounds.width > maximumSize.width )
changeWidth( oldBounds, newBounds, maximumSize.width );
if( newBounds.height > maximumSize.height )
changeHeight( oldBounds, newBounds, maximumSize.height );
}
// set window bounds
if( !newBounds.equals( oldBounds ) )
setWindowBounds( newBounds );
}
private void changeWidth( Rectangle oldBounds, Rectangle newBounds, int width ) {
if( newBounds.x != oldBounds.x )
newBounds.x -= (width - newBounds.width);
newBounds.width = width;
}
private void changeHeight( Rectangle oldBounds, Rectangle newBounds, int height ) {
if( newBounds.y != oldBounds.y )
newBounds.y -= (height - newBounds.height);
newBounds.height = height;
}
}
}

View File

@@ -0,0 +1,424 @@
/*
* Copyright 2021 FormDev Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.formdev.flatlaf.ui;
import java.awt.Color;
import java.awt.Dialog;
import java.awt.EventQueue;
import java.awt.Frame;
import java.awt.GraphicsConfiguration;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Window;
import java.awt.geom.AffineTransform;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Collections;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.Timer;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.EventListenerList;
import com.formdev.flatlaf.util.LoggingFacade;
import com.formdev.flatlaf.util.NativeLibrary;
import com.formdev.flatlaf.util.SystemInfo;
//
// Interesting resources:
// https://github.com/microsoft/terminal/blob/main/src/cascadia/WindowsTerminal/NonClientIslandWindow.cpp
// https://docs.microsoft.com/en-us/windows/win32/dwm/customframe
// https://github.com/JetBrains/JetBrainsRuntime/blob/master/src/java.desktop/windows/native/libawt/windows/awt_Frame.cpp
// https://github.com/JetBrains/JetBrainsRuntime/commit/d2820524a1aa211b1c49b30f659b9b4d07a6f96e
// https://github.com/JetBrains/JetBrainsRuntime/pull/18
// https://medium.com/swlh/customizing-the-title-bar-of-an-application-window-50a4ac3ed27e
// https://github.com/kalbetredev/CustomDecoratedJFrame
// https://github.com/Guerra24/NanoUI-win32
// https://github.com/oberth/custom-chrome
// https://github.com/rossy/borderless-window
//
/**
* Native window border support for Windows 10 when using custom decorations.
* <p>
* If the application wants to use custom decorations, the Windows 10 title bar is hidden
* (including minimize, maximize and close buttons), but not the resize borders (including drop shadow).
* Windows 10 window snapping functionality will remain unaffected:
* https://support.microsoft.com/en-us/windows/snap-your-windows-885a9b1e-a983-a3b1-16cd-c531795e6241
*
* @author Karl Tauber
* @since 1.1
*/
class FlatWindowsNativeWindowBorder
implements FlatNativeWindowBorder.Provider
{
private final Map<Window, WndProc> windowsMap = Collections.synchronizedMap( new IdentityHashMap<>() );
private final EventListenerList listenerList = new EventListenerList();
private Timer fireStateChangedTimer;
private boolean colorizationUpToDate;
private boolean colorizationColorAffectsBorders;
private Color colorizationColor;
private int colorizationColorBalance;
private static NativeLibrary nativeLibrary;
private static FlatWindowsNativeWindowBorder instance;
static FlatNativeWindowBorder.Provider getInstance() {
// requires Windows 10
if( !SystemInfo.isWindows_10_orLater )
return null;
// load native library
if( nativeLibrary == null ) {
if( !SystemInfo.isJava_9_orLater ) {
// In Java 8, load jawt.dll (part of JRE) explicitly because it
// is not found when running application with <jdk>/bin/java.exe.
// When using <jdk>/jre/bin/java.exe, it is found.
// jawt.dll is located in <jdk>/jre/bin/.
// Java 9 and later does not have this problem.
try {
System.loadLibrary( "jawt" );
} catch( UnsatisfiedLinkError ex ) {
// log error only if native library jawt.dll not already loaded
String message = ex.getMessage();
if( message == null || !message.contains( "already loaded in another classloader" ) )
LoggingFacade.INSTANCE.logSevere( null, ex );
} catch( Exception ex ) {
LoggingFacade.INSTANCE.logSevere( null, ex );
}
}
String libraryName = "com/formdev/flatlaf/natives/flatlaf-windows-x86";
if( SystemInfo.isX86_64 )
libraryName += "_64";
nativeLibrary = new NativeLibrary( libraryName, null, true );
}
// check whether native library was successfully loaded
if( !nativeLibrary.isLoaded() )
return null;
// create new instance
if( instance == null )
instance = new FlatWindowsNativeWindowBorder();
return instance;
}
private FlatWindowsNativeWindowBorder() {
}
@Override
public boolean hasCustomDecoration( Window window ) {
return windowsMap.containsKey( window );
}
/**
* Tell the window whether the application wants use custom decorations.
* If {@code true}, the Windows 10 title bar is hidden (including minimize,
* maximize and close buttons), but not the resize borders (including drop shadow).
*/
@Override
public void setHasCustomDecoration( Window window, boolean hasCustomDecoration ) {
if( hasCustomDecoration )
install( window );
else
uninstall( window );
}
private void install( Window window ) {
// requires Windows 10
if( !SystemInfo.isWindows_10_orLater )
return;
// only JFrame and JDialog are supported
if( !(window instanceof JFrame) && !(window instanceof JDialog) )
return;
// not supported if frame/dialog is undecorated
if( (window instanceof Frame && ((Frame)window).isUndecorated()) ||
(window instanceof Dialog && ((Dialog)window).isUndecorated()) )
return;
// check whether already installed
if( windowsMap.containsKey( window ) )
return;
// install
WndProc wndProc = new WndProc( window );
if( wndProc.hwnd == 0 )
return;
windowsMap.put( window, wndProc );
}
private void uninstall( Window window ) {
WndProc wndProc = windowsMap.remove( window );
if( wndProc != null )
wndProc.uninstall();
}
@Override
public void setTitleBarHeight( Window window, int titleBarHeight ) {
WndProc wndProc = windowsMap.get( window );
if( wndProc == null )
return;
wndProc.titleBarHeight = titleBarHeight;
}
@Override
public void setTitleBarHitTestSpots( Window window, List<Rectangle> hitTestSpots ) {
WndProc wndProc = windowsMap.get( window );
if( wndProc == null )
return;
wndProc.hitTestSpots = hitTestSpots.toArray( new Rectangle[hitTestSpots.size()] );
}
@Override
public void setTitleBarAppIconBounds( Window window, Rectangle appIconBounds ) {
WndProc wndProc = windowsMap.get( window );
if( wndProc == null )
return;
wndProc.appIconBounds = (appIconBounds != null) ? new Rectangle( appIconBounds ) : null;
}
@Override
public boolean showWindow( Window window, int cmd ) {
WndProc wndProc = windowsMap.get( window );
if( wndProc == null )
return false;
wndProc.showWindow( wndProc.hwnd, cmd );
return true;
}
@Override
public boolean isColorizationColorAffectsBorders() {
updateColorization();
return colorizationColorAffectsBorders;
}
@Override
public Color getColorizationColor() {
updateColorization();
return colorizationColor;
}
@Override
public int getColorizationColorBalance() {
updateColorization();
return colorizationColorBalance;
}
private void updateColorization() {
if( colorizationUpToDate )
return;
colorizationUpToDate = true;
String subKey = "SOFTWARE\\Microsoft\\Windows\\DWM";
int value = registryGetIntValue( subKey, "ColorPrevalence", -1 );
colorizationColorAffectsBorders = (value > 0);
value = registryGetIntValue( subKey, "ColorizationColor", -1 );
colorizationColor = (value != -1) ? new Color( value ) : null;
colorizationColorBalance = registryGetIntValue( subKey, "ColorizationColorBalance", -1 );
}
private native static int registryGetIntValue( String key, String valueName, int defaultValue );
@Override
public void addChangeListener( ChangeListener l ) {
listenerList.add( ChangeListener.class, l );
}
@Override
public void removeChangeListener( ChangeListener l ) {
listenerList.remove( ChangeListener.class, l );
}
private void fireStateChanged() {
Object[] listeners = listenerList.getListenerList();
if( listeners.length == 0 )
return;
ChangeEvent e = new ChangeEvent( this );
for( int i = 0; i < listeners.length; i += 2 ) {
if( listeners[i] == ChangeListener.class )
((ChangeListener)listeners[i+1]).stateChanged( e );
}
}
/**
* Because there may be sent many WM_DWMCOLORIZATIONCOLORCHANGED messages,
* slightly delay event firing and fire it only once (on the AWT thread).
*/
void fireStateChangedLaterOnce() {
EventQueue.invokeLater( () -> {
if( fireStateChangedTimer != null ) {
fireStateChangedTimer.restart();
return;
}
fireStateChangedTimer = new Timer( 300, e -> {
fireStateChangedTimer = null;
colorizationUpToDate = false;
fireStateChanged();
} );
fireStateChangedTimer.setRepeats( false );
fireStateChangedTimer.start();
} );
}
//---- class WndProc ------------------------------------------------------
private class WndProc
implements PropertyChangeListener
{
// WM_NCHITTEST mouse position codes
private static final int
HTCLIENT = 1,
HTCAPTION = 2,
HTSYSMENU = 3,
HTTOP = 12;
private Window window;
private final long hwnd;
private int titleBarHeight;
private Rectangle[] hitTestSpots;
private Rectangle appIconBounds;
WndProc( Window window ) {
this.window = window;
hwnd = installImpl( window );
if( hwnd == 0 )
return;
// remove the OS window title bar
updateFrame( hwnd, (window instanceof JFrame) ? ((JFrame)window).getExtendedState() : 0 );
// set window background (used when resizing window)
updateWindowBackground();
window.addPropertyChangeListener( "background", this );
}
void uninstall() {
window.removePropertyChangeListener( "background", this );
uninstallImpl( hwnd );
// cleanup
window = null;
}
@Override
public void propertyChange( PropertyChangeEvent e ) {
updateWindowBackground();
}
private void updateWindowBackground() {
Color bg = window.getBackground();
if( bg != null )
setWindowBackground( hwnd, bg.getRed(), bg.getGreen(), bg.getBlue() );
}
private native long installImpl( Window window );
private native void uninstallImpl( long hwnd );
private native void updateFrame( long hwnd, int state );
private native void setWindowBackground( long hwnd, int r, int g, int b );
private native void showWindow( long hwnd, int cmd );
// invoked from native code
private int onNcHitTest( int x, int y, boolean isOnResizeBorder ) {
// scale-down mouse x/y
Point pt = scaleDown( x, y );
int sx = pt.x;
int sy = pt.y;
// return HTSYSMENU if mouse is over application icon
// - left-click on HTSYSMENU area shows system menu
// - double-left-click sends WM_CLOSE
if( appIconBounds != null && appIconBounds.contains( sx, sy ) )
return HTSYSMENU;
boolean isOnTitleBar = (sy < titleBarHeight);
if( isOnTitleBar ) {
// use a second reference to the array to avoid that it can be changed
// in another thread while processing the array
Rectangle[] hitTestSpots2 = hitTestSpots;
for( Rectangle spot : hitTestSpots2 ) {
if( spot.contains( sx, sy ) )
return HTCLIENT;
}
return isOnResizeBorder ? HTTOP : HTCAPTION;
}
return isOnResizeBorder ? HTTOP : HTCLIENT;
}
/**
* Scales down in the same way as AWT.
* See AwtWin32GraphicsDevice::ScaleDownX() and ::ScaleDownY()
*/
private Point scaleDown( int x, int y ) {
GraphicsConfiguration gc = window.getGraphicsConfiguration();
if( gc == null )
return new Point( x, y );
AffineTransform t = gc.getDefaultTransform();
return new Point( clipRound( x / t.getScaleX() ), clipRound( y / t.getScaleY() ) );
}
/**
* Rounds in the same way as AWT.
* See AwtWin32GraphicsDevice::ClipRound()
*/
private int clipRound( double value ) {
value -= 0.5;
if( value < Integer.MIN_VALUE )
return Integer.MIN_VALUE;
if( value > Integer.MAX_VALUE )
return Integer.MAX_VALUE;
return (int) Math.ceil( value );
}
// invoked from native code
private boolean isFullscreen() {
GraphicsConfiguration gc = window.getGraphicsConfiguration();
if( gc == null )
return false;
return gc.getDevice().getFullScreenWindow() == window;
}
// invoked from native code
private void fireStateChangedLaterOnce() {
FlatWindowsNativeWindowBorder.this.fireStateChangedLaterOnce();
}
}
}

View File

@@ -29,17 +29,14 @@ import java.awt.event.HierarchyEvent;
import java.awt.event.HierarchyListener;
import java.beans.PropertyChangeListener;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JRootPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.plaf.BorderUIResource;
import com.formdev.flatlaf.FlatLaf;
import com.formdev.flatlaf.FlatSystemProperties;
import com.formdev.flatlaf.util.LoggingFacade;
import com.formdev.flatlaf.util.HiDPIUtils;
import com.formdev.flatlaf.util.SystemInfo;
@@ -55,26 +52,30 @@ import com.formdev.flatlaf.util.SystemInfo;
*/
public class JBRCustomDecorations
{
private static boolean initialized;
private static Boolean supported;
private static Method Window_hasCustomDecoration;
private static Method Window_setHasCustomDecoration;
private static Method WWindowPeer_setCustomDecorationHitTestSpots;
private static Method WWindowPeer_setCustomDecorationTitleBarHeight;
private static Method WWindowPeer_setCustomDecorationHitTestSpots;
private static Method AWTAccessor_getComponentAccessor;
private static Method AWTAccessor_ComponentAccessor_getPeer;
public static boolean isSupported() {
initialize();
return Window_setHasCustomDecoration != null;
return supported;
}
static void install( JRootPane rootPane ) {
static Object install( JRootPane rootPane ) {
if( !isSupported() )
return;
return null;
// check whether root pane already has a parent, which is the case when switching LaF
if( rootPane.getParent() != null )
return;
Container parent = rootPane.getParent();
if( parent != null ) {
if( parent instanceof Window )
FlatNativeWindowBorder.install( (Window) parent );
return null;
}
// Use hierarchy listener to wait until the root pane is added to a window.
// Enabling JBR decorations must be done very early, probably before
@@ -88,8 +89,9 @@ public class JBRCustomDecorations
Container parent = e.getChangedParent();
if( parent instanceof Window )
install( (Window) parent );
FlatNativeWindowBorder.install( (Window) parent );
// remove listener since it is actually not possible to uninstall JBR decorations
// use invokeLater to remove listener to avoid that listener
// is removed while listener queue is processed
EventQueue.invokeLater( () -> {
@@ -98,54 +100,20 @@ public class JBRCustomDecorations
}
};
rootPane.addHierarchyListener( addListener );
return addListener;
}
static void install( Window window ) {
if( !isSupported() )
return;
static void uninstall( JRootPane rootPane, Object data ) {
// remove listener (if not yet done)
if( data instanceof HierarchyListener )
rootPane.removeHierarchyListener( (HierarchyListener) data );
// do not enable JBR decorations if LaF provides decorations
if( UIManager.getLookAndFeel().getSupportsWindowDecorations() )
return;
if( window instanceof JFrame ) {
JFrame frame = (JFrame) window;
// do not enable JBR decorations if JFrame should use system window decorations
// and if not forced to use JBR decorations
if( !JFrame.isDefaultLookAndFeelDecorated() &&
!FlatSystemProperties.getBoolean( FlatSystemProperties.USE_JETBRAINS_CUSTOM_DECORATIONS, false ))
return;
// do not enable JBR decorations if frame is undecorated
if( frame.isUndecorated() )
return;
// enable JBR custom window decoration for window
setHasCustomDecoration( frame );
// enable Swing window decoration
frame.getRootPane().setWindowDecorationStyle( JRootPane.FRAME );
} else if( window instanceof JDialog ) {
JDialog dialog = (JDialog) window;
// do not enable JBR decorations if JDialog should use system window decorations
// and if not forced to use JBR decorations
if( !JDialog.isDefaultLookAndFeelDecorated() &&
!FlatSystemProperties.getBoolean( FlatSystemProperties.USE_JETBRAINS_CUSTOM_DECORATIONS, false ))
return;
// do not enable JBR decorations if dialog is undecorated
if( dialog.isUndecorated() )
return;
// enable JBR custom window decoration for window
setHasCustomDecoration( dialog );
// enable Swing window decoration
dialog.getRootPane().setWindowDecorationStyle( JRootPane.PLAIN_DIALOG );
}
// since it is actually not possible to uninstall JBR decorations,
// simply reduce titleBarHeight so that it is still possible to resize window
// and remove hitTestSpots
Container parent = rootPane.getParent();
if( parent instanceof Window )
setHasCustomDecoration( (Window) parent, false );
}
static boolean hasCustomDecoration( Window window ) {
@@ -155,48 +123,48 @@ public class JBRCustomDecorations
try {
return (Boolean) Window_hasCustomDecoration.invoke( window );
} catch( Exception ex ) {
Logger.getLogger( FlatLaf.class.getName() ).log( Level.SEVERE, null, ex );
LoggingFacade.INSTANCE.logSevere( null, ex );
return false;
}
}
static void setHasCustomDecoration( Window window ) {
static void setHasCustomDecoration( Window window, boolean hasCustomDecoration ) {
if( !isSupported() )
return;
try {
Window_setHasCustomDecoration.invoke( window );
if( hasCustomDecoration )
Window_setHasCustomDecoration.invoke( window );
else
setTitleBarHeightAndHitTestSpots( window, 4, Collections.emptyList() );
} catch( Exception ex ) {
Logger.getLogger( FlatLaf.class.getName() ).log( Level.SEVERE, null, ex );
LoggingFacade.INSTANCE.logSevere( null, ex );
}
}
static void setHitTestSpotsAndTitleBarHeight( Window window, List<Rectangle> hitTestSpots, int titleBarHeight ) {
static void setTitleBarHeightAndHitTestSpots( Window window, int titleBarHeight, List<Rectangle> hitTestSpots ) {
if( !isSupported() )
return;
try {
Object compAccessor = AWTAccessor_getComponentAccessor.invoke( null );
Object peer = AWTAccessor_ComponentAccessor_getPeer.invoke( compAccessor, window );
WWindowPeer_setCustomDecorationHitTestSpots.invoke( peer, hitTestSpots );
WWindowPeer_setCustomDecorationTitleBarHeight.invoke( peer, titleBarHeight );
WWindowPeer_setCustomDecorationHitTestSpots.invoke( peer, hitTestSpots );
} catch( Exception ex ) {
Logger.getLogger( FlatLaf.class.getName() ).log( Level.SEVERE, null, ex );
LoggingFacade.INSTANCE.logSevere( null, ex );
}
}
private static void initialize() {
if( initialized )
if( supported != null )
return;
initialized = true;
supported = false;
// requires JetBrains Runtime 11 and Windows 10
if( !SystemInfo.isJetBrainsJVM_11_orLater || !SystemInfo.isWindows_10_orLater )
return;
if( !FlatSystemProperties.getBoolean( FlatSystemProperties.USE_JETBRAINS_CUSTOM_DECORATIONS, true ) )
return;
try {
Class<?> awtAcessorClass = Class.forName( "sun.awt.AWTAccessor" );
Class<?> compAccessorClass = Class.forName( "sun.awt.AWTAccessor$ComponentAccessor" );
@@ -204,15 +172,17 @@ public class JBRCustomDecorations
AWTAccessor_ComponentAccessor_getPeer = compAccessorClass.getDeclaredMethod( "getPeer", Component.class );
Class<?> peerClass = Class.forName( "sun.awt.windows.WWindowPeer" );
WWindowPeer_setCustomDecorationHitTestSpots = peerClass.getDeclaredMethod( "setCustomDecorationHitTestSpots", List.class );
WWindowPeer_setCustomDecorationTitleBarHeight = peerClass.getDeclaredMethod( "setCustomDecorationTitleBarHeight", int.class );
WWindowPeer_setCustomDecorationHitTestSpots.setAccessible( true );
WWindowPeer_setCustomDecorationHitTestSpots = peerClass.getDeclaredMethod( "setCustomDecorationHitTestSpots", List.class );
WWindowPeer_setCustomDecorationTitleBarHeight.setAccessible( true );
WWindowPeer_setCustomDecorationHitTestSpots.setAccessible( true );
Window_hasCustomDecoration = Window.class.getDeclaredMethod( "hasCustomDecoration" );
Window_setHasCustomDecoration = Window.class.getDeclaredMethod( "setHasCustomDecoration" );
Window_hasCustomDecoration.setAccessible( true );
Window_setHasCustomDecoration.setAccessible( true );
supported = true;
} catch( Exception ex ) {
// ignore
}
@@ -227,7 +197,6 @@ public class JBRCustomDecorations
private final Color defaultActiveBorder = new Color( 0x707070 );
private final Color inactiveLightColor = new Color( 0xaaaaaa );
private final Color inactiveDarkColor = new Color( 0x3f3f3f );
private boolean colorizationAffectsBorders;
private Color activeColor = defaultActiveBorder;
@@ -238,15 +207,22 @@ public class JBRCustomDecorations
return instance;
}
private JBRWindowTopBorder() {
JBRWindowTopBorder() {
super( 1, 0, 0, 0 );
colorizationAffectsBorders = calculateAffectsBorders();
activeColor = calculateActiveBorderColor();
update();
installListeners();
}
void update() {
colorizationAffectsBorders = isColorizationColorAffectsBorders();
activeColor = calculateActiveBorderColor();
}
void installListeners() {
Toolkit toolkit = Toolkit.getDefaultToolkit();
toolkit.addPropertyChangeListener( "win.dwm.colorizationColor.affects.borders", e -> {
colorizationAffectsBorders = calculateAffectsBorders();
colorizationAffectsBorders = isColorizationColorAffectsBorders();
activeColor = calculateActiveBorderColor();
} );
@@ -258,40 +234,50 @@ public class JBRCustomDecorations
toolkit.addPropertyChangeListener( "win.frame.activeBorderColor", l );
}
private boolean calculateAffectsBorders() {
boolean isColorizationColorAffectsBorders() {
Object value = Toolkit.getDefaultToolkit().getDesktopProperty( "win.dwm.colorizationColor.affects.borders" );
return (value instanceof Boolean) ? (Boolean) value : true;
}
Color getColorizationColor() {
return (Color) Toolkit.getDefaultToolkit().getDesktopProperty( "win.dwm.colorizationColor" );
}
int getColorizationColorBalance() {
Object value = Toolkit.getDefaultToolkit().getDesktopProperty( "win.dwm.colorizationColorBalance" );
return (value instanceof Integer) ? (Integer) value : -1;
}
private Color calculateActiveBorderColor() {
if( !colorizationAffectsBorders )
return defaultActiveBorder;
Toolkit toolkit = Toolkit.getDefaultToolkit();
Color colorizationColor = (Color) toolkit.getDesktopProperty( "win.dwm.colorizationColor" );
Color colorizationColor = getColorizationColor();
if( colorizationColor != null ) {
Object colorizationColorBalanceObj = toolkit.getDesktopProperty( "win.dwm.colorizationColorBalance" );
if( colorizationColorBalanceObj instanceof Integer ) {
int colorizationColorBalance = (Integer) colorizationColorBalanceObj;
if( colorizationColorBalance < 0 )
colorizationColorBalance = 100;
int colorizationColorBalance = getColorizationColorBalance();
if( colorizationColorBalance < 0 || colorizationColorBalance > 100 )
colorizationColorBalance = 100;
if( colorizationColorBalance == 0 )
return new Color( 0xD9D9D9 );
if( colorizationColorBalance == 100 )
return colorizationColor;
if( colorizationColorBalance == 0 )
return new Color( 0xD9D9D9 );
if( colorizationColorBalance == 100 )
return colorizationColor;
float alpha = colorizationColorBalance / 100.0f;
float remainder = 1 - alpha;
int r = Math.round( (colorizationColor.getRed() * alpha + 0xD9 * remainder) );
int g = Math.round( (colorizationColor.getGreen() * alpha + 0xD9 * remainder) );
int b = Math.round( (colorizationColor.getBlue() * alpha + 0xD9 * remainder) );
return new Color( r, g, b );
}
return colorizationColor;
float alpha = colorizationColorBalance / 100.0f;
float remainder = 1 - alpha;
int r = Math.round( colorizationColor.getRed() * alpha + 0xD9 * remainder );
int g = Math.round( colorizationColor.getGreen() * alpha + 0xD9 * remainder );
int b = Math.round( colorizationColor.getBlue() * alpha + 0xD9 * remainder );
// avoid potential IllegalArgumentException in Color constructor
r = Math.min( Math.max( r, 0 ), 255 );
g = Math.min( Math.max( g, 0 ), 255 );
b = Math.min( Math.max( b, 0 ), 255 );
return new Color( r, g, b );
}
Color activeBorderColor = (Color) toolkit.getDesktopProperty( "win.frame.activeBorderColor" );
Color activeBorderColor = (Color) Toolkit.getDefaultToolkit().getDesktopProperty( "win.frame.activeBorderColor" );
return (activeBorderColor != null) ? activeBorderColor : UIManager.getColor( "MenuBar.borderColor" );
}
@@ -300,7 +286,14 @@ public class JBRCustomDecorations
Window window = SwingUtilities.windowForComponent( c );
boolean active = (window != null) ? window.isActive() : false;
g.setColor( active ? activeColor : (FlatLaf.isLafDark() ? inactiveDarkColor : inactiveLightColor) );
// paint top border
// - in light themes
// - in dark themes only for active windows if colorization affects borders
boolean paintTopBorder = !FlatLaf.isLafDark() || (active && colorizationAffectsBorders);
if( !paintTopBorder )
return;
g.setColor( active ? activeColor : inactiveLightColor );
HiDPIUtils.paintAtScale1x( (Graphics2D) g, x, y, width, height, this::paintImpl );
}

View File

@@ -0,0 +1,50 @@
/*
* Copyright 2021 FormDev Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.formdev.flatlaf.ui;
import java.util.function.BiPredicate;
/**
* @author Karl Tauber
*/
class StackUtils
{
private static final StackUtils INSTANCE = new StackUtilsImpl();
// hide from javadoc
StackUtils() {
}
/**
* Checks whether current method was invoked from the given class and method.
*/
public static boolean wasInvokedFrom( String className, String methodName, int limit ) {
return wasInvokedFrom( (c,m) -> c.equals( className ) && m.equals( methodName ), limit );
}
/**
* Checks whether current method was invoked from a class and method using the given predicate,
* which gets the class name of the stack frame as first parameter and the method name as second parameter.
*/
public static boolean wasInvokedFrom( BiPredicate<String, String> predicate, int limit ) {
return INSTANCE.wasInvokedFromImpl( predicate, limit );
}
boolean wasInvokedFromImpl( BiPredicate<String, String> predicate, int limit ) {
throw new UnsupportedOperationException();
}
}

View File

@@ -0,0 +1,41 @@
/*
* Copyright 2021 FormDev Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.formdev.flatlaf.ui;
import java.util.function.BiPredicate;
/**
* @author Karl Tauber
*/
class StackUtilsImpl
extends StackUtils
{
@Override
boolean wasInvokedFromImpl( BiPredicate<String, String> predicate, int limit ) {
int count = -2;
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
for( StackTraceElement stackTraceElement : stackTrace ) {
if( predicate.test( stackTraceElement.getClassName(), stackTraceElement.getMethodName() ) )
return true;
count++;
if( limit > 0 && count > limit )
return false;
}
return false;
}
}

View File

@@ -26,13 +26,16 @@ import java.awt.Color;
public class ColorFunctions
{
public static Color applyFunctions( Color color, ColorFunction... functions ) {
// convert RGB to HSL
float[] hsl = HSLColor.fromRGB( color );
float alpha = color.getAlpha() / 255f;
float[] hsla = { hsl[0], hsl[1], hsl[2], alpha * 100 };
// apply color functions
for( ColorFunction function : functions )
function.apply( hsla );
// convert HSL to RGB
return HSLColor.toRGB( hsla[0], hsla[1], hsla[2], hsla[3] / 100 );
}
@@ -128,9 +131,63 @@ public class ColorFunctions
? hsla[hslIndex] > 65
: hsla[hslIndex] < 35;
}
@Override
public String toString() {
String name;
switch( hslIndex ) {
case 0: name = "spin"; break;
case 1: name = increase ? "saturate" : "desaturate"; break;
case 2: name = increase ? "lighten" : "darken"; break;
case 3: name = increase ? "fadein" : "fadeout"; break;
default: throw new IllegalArgumentException();
}
return String.format( "%s(%.0f%%%s%s)", name, amount,
(relative ? " relative" : ""),
(autoInverse ? " autoInverse" : "") );
}
}
//---- class HSLIncreaseDecrease ------------------------------------------
//---- class HSLChange ----------------------------------------------------
/**
* Set the hue, saturation, luminance or alpha of a color.
*
* @since 1.6
*/
public static class HSLChange
implements ColorFunction
{
public final int hslIndex;
public final float value;
public HSLChange( int hslIndex, float value ) {
this.hslIndex = hslIndex;
this.value = value;
}
@Override
public void apply( float[] hsla ) {
hsla[hslIndex] = (hslIndex == 0)
? value % 360
: clamp( value );
}
@Override
public String toString() {
String name;
switch( hslIndex ) {
case 0: name = "changeHue"; break;
case 1: name = "changeSaturation"; break;
case 2: name = "changeLightness"; break;
case 3: name = "changeAlpha"; break;
default: throw new IllegalArgumentException();
}
return String.format( "%s(%.0f%s)", name, value, (hslIndex == 0 ? "" : "%") );
}
}
//---- class Fade ---------------------------------------------------------
/**
* Set the alpha of a color.
@@ -148,5 +205,48 @@ public class ColorFunctions
public void apply( float[] hsla ) {
hsla[3] = clamp( amount );
}
@Override
public String toString() {
return String.format( "fade(%.0f%%)", amount );
}
}
//---- class Mix ----------------------------------------------------------
/**
* Mix two colors.
*
* @since 1.6
*/
public static class Mix
implements ColorFunction
{
public final Color color2;
public final float weight;
public Mix( Color color2, float weight ) {
this.color2 = color2;
this.weight = weight;
}
@Override
public void apply( float[] hsla ) {
// convert from HSL to RGB because color mixing is done on RGB values
Color color1 = HSLColor.toRGB( hsla[0], hsla[1], hsla[2], hsla[3] / 100 );
// mix
Color color = mix( color1, color2, weight / 100 );
// convert RGB to HSL
float[] hsl = HSLColor.fromRGB( color );
System.arraycopy( hsl, 0, hsla, 0, hsl.length );
hsla[3] = (color.getAlpha() / 255f) * 100;
}
@Override
public String toString() {
return String.format( "mix(#%08x,%.0f%%)", color2.getRGB(), weight );
}
}
}

View File

@@ -59,4 +59,17 @@ public class DerivedColor
public ColorFunction[] getFunctions() {
return functions;
}
@Override
public String toString() {
StringBuilder buf = new StringBuilder();
buf.append( super.toString() );
for( ColorFunction function : functions ) {
buf.append( '\n' );
buf.append( function.toString() );
}
return buf.toString();
}
}

View File

@@ -256,11 +256,6 @@ public class Graphics2DProxy
delegate.dispose();
}
@Override
public void finalize() {
delegate.finalize();
}
@Override
public String toString() {
return delegate.toString();

View File

@@ -134,7 +134,7 @@ public class HiDPIUtils
// - fractional scale factors result in fractional component Y device coordinates
// - fractional text Y device coordinates are rounded for horizontal lines of characters
// - maybe different rounding methods for drawing primitives (e.g. rectangle) and text
// - Java adds 0.5 to X/Y positions in before drawing string in BufferedTextPipe.enqueueGlyphList()
// - Java adds 0.5 to X/Y positions before drawing string in BufferedTextPipe.enqueueGlyphList()
// this is not the optimal solution, but works very good in most cases
// (tested with class FlatPaintingStringTest on Windows 10 with font "Segoe UI")

View File

@@ -21,10 +21,7 @@ import java.awt.Graphics;
import java.awt.Graphics2D;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JComponent;
import com.formdev.flatlaf.FlatLaf;
/**
* Provides Java version compatibility methods.
@@ -58,7 +55,7 @@ public class JavaCompatibility
? new Class[] { JComponent.class, Graphics2D.class, String.class, int.class, float.class, float.class }
: new Class[] { JComponent.class, Graphics.class, String.class, int.class, int.class, int.class } );
} catch( Exception ex ) {
Logger.getLogger( FlatLaf.class.getName() ).log( Level.SEVERE, null, ex );
LoggingFacade.INSTANCE.logSevere( null, ex );
throw new RuntimeException( ex );
}
}
@@ -70,7 +67,7 @@ public class JavaCompatibility
else
drawStringUnderlineCharAtMethod.invoke( null, c, g, text, underlinedIndex, x, y );
} catch( IllegalAccessException | IllegalArgumentException | InvocationTargetException ex ) {
Logger.getLogger( FlatLaf.class.getName() ).log( Level.SEVERE, null, ex );
LoggingFacade.INSTANCE.logSevere( null, ex );
throw new RuntimeException( ex );
}
}
@@ -94,7 +91,7 @@ public class JavaCompatibility
: "clipStringIfNecessary",
new Class[] { JComponent.class, FontMetrics.class, String.class, int.class } );
} catch( Exception ex ) {
Logger.getLogger( FlatLaf.class.getName() ).log( Level.SEVERE, null, ex );
LoggingFacade.INSTANCE.logSevere( null, ex );
throw new RuntimeException( ex );
}
}
@@ -103,7 +100,7 @@ public class JavaCompatibility
try {
return (String) getClippedStringMethod.invoke( null, c, fm, string, availTextWidth );
} catch( IllegalAccessException | IllegalArgumentException | InvocationTargetException ex ) {
Logger.getLogger( FlatLaf.class.getName() ).log( Level.SEVERE, null, ex );
LoggingFacade.INSTANCE.logSevere( null, ex );
throw new RuntimeException( ex );
}
}

View File

@@ -0,0 +1,28 @@
/*
* Copyright 2021 FormDev Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.formdev.flatlaf.util;
/**
* @since 1.1
*/
public interface LoggingFacade
{
LoggingFacade INSTANCE = new LoggingFacadeImpl();
void logSevere( String message, Throwable t );
void logConfig( String message, Throwable t );
}

View File

@@ -0,0 +1,40 @@
/*
* Copyright 2021 FormDev Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.formdev.flatlaf.util;
import com.formdev.flatlaf.FlatLaf;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* @since 1.1
*/
class LoggingFacadeImpl
implements LoggingFacade
{
private static final Logger LOG = Logger.getLogger( FlatLaf.class.getName() );
@Override
public void logSevere( String message, Throwable t ) {
LOG.log( Level.SEVERE, message, t );
}
@Override
public void logConfig( String message, Throwable t ) {
LOG.log( Level.CONFIG, message, t );
}
}

View File

@@ -0,0 +1,220 @@
/*
* Copyright 2021 FormDev Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.formdev.flatlaf.util;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.FileAlreadyExistsException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
/**
* Helper class to load native library (.dll, .so or .dylib) stored in Jar.
* <p>
* Copies native library to users temporary folder before loading it.
*
* @author Karl Tauber
* @since 1.1
*/
public class NativeLibrary
{
private static final String DELETE_SUFFIX = ".delete";
private static boolean deletedTemporary;
private final boolean loaded;
/**
* Load native library from given classloader.
* <p>
* Note regarding Java Platform Module System (JPMS):
* If classloader is {@code null}, the library can be only loaded from the module
* that contains this class.
* If classloader is not {@code null}, then the package that contains the library
* must be specified as "open" in module-info.java of the module that contains the library.
*
* @param libraryName resource name of the native library (without "lib" prefix and without extension)
* @param classLoader the classloader used to locate the library, or {@code null}
* @param supported whether the native library is supported on the current platform
*/
public NativeLibrary( String libraryName, ClassLoader classLoader, boolean supported ) {
this.loaded = supported
? loadLibraryFromJar( libraryName, classLoader )
: false;
}
/**
* Returns whether the native library is loaded.
* <p>
* Returns {@code false} if not supported on current platform as specified in constructor
* or if loading failed.
*/
public boolean isLoaded() {
return loaded;
}
private static boolean loadLibraryFromJar( String libraryName, ClassLoader classLoader ) {
// add prefix and suffix to library name
libraryName = decorateLibraryName( libraryName );
// find library
URL libraryUrl = (classLoader != null)
? classLoader.getResource( libraryName )
: NativeLibrary.class.getResource( "/" + libraryName );
if( libraryUrl == null ) {
log( "Library '" + libraryName + "' not found", null );
return false;
}
File tempFile = null;
try {
// for development environment
if( "file".equals( libraryUrl.getProtocol() ) ) {
File libraryFile = new File( libraryUrl.getPath() );
if( libraryFile.isFile() ) {
// load library without copying
System.load( libraryFile.getCanonicalPath() );
return true;
}
}
// create temporary file
Path tempPath = createTempFile( libraryName );
tempFile = tempPath.toFile();
// copy library to temporary file
try( InputStream in = libraryUrl.openStream() ) {
Files.copy( in, tempPath, StandardCopyOption.REPLACE_EXISTING );
}
// load library
System.load( tempFile.getCanonicalPath() );
// delete library
deleteOrMarkForDeletion( tempFile );
return true;
} catch( Throwable ex ) {
log( null, ex );
if( tempFile != null )
deleteOrMarkForDeletion( tempFile );
return false;
}
}
private static String decorateLibraryName( String libraryName ) {
if( SystemInfo.isWindows )
return libraryName.concat( ".dll" );
String suffix = SystemInfo.isMacOS ? ".dylib" : ".so";
int sep = libraryName.lastIndexOf( '/' );
return (sep >= 0)
? libraryName.substring( 0, sep + 1 ) + "lib" + libraryName.substring( sep + 1 ) + suffix
: "lib" + libraryName + suffix;
}
private static void log( String msg, Throwable thrown ) {
LoggingFacade.INSTANCE.logSevere( msg, thrown );
}
private static Path createTempFile( String libraryName ) throws IOException {
int sep = libraryName.lastIndexOf( '/' );
String name = (sep >= 0) ? libraryName.substring( sep + 1 ) : libraryName;
int dot = name.lastIndexOf( '.' );
String prefix = ((dot >= 0) ? name.substring( 0, dot ) : name) + '-';
String suffix = (dot >= 0) ? name.substring( dot ) : "";
Path tempDir = getTempDir();
// Note:
// Not using Files.createTempFile() here because it uses random number generator SecureRandom,
// which may take 5-10 seconds to initialize under particular conditions.
// Use current time in nanoseconds instead of a random number.
// To avoid (theoretical) collisions, append a counter.
long nanoTime = System.nanoTime();
for( int i = 0;; i++ ) {
String s = prefix + Long.toUnsignedString( nanoTime ) + i + suffix;
try {
return Files.createFile( tempDir.resolve( s ) );
} catch( FileAlreadyExistsException ex ) {
// ignore --> increment counter and try again
}
}
}
private static Path getTempDir() throws IOException {
// get standard temporary directory
String tmpdir = System.getProperty( "java.io.tmpdir" );
if( SystemInfo.isWindows ) {
// On Windows, where File.delete() and File.deleteOnExit() does not work
// for loaded native libraries, they will be deleted on next application startup.
// The default temporary directory may contain hundreds or thousands of files.
// To make searching for "marked for deletion" files as fast as possible,
// use a sub directory that contains only our temporary native libraries.
tmpdir += "\\flatlaf.temp";
}
// create temporary directory
Path tempDir = Paths.get( tmpdir );
Files.createDirectories( tempDir );
// delete no longer needed temporary files (from already exited applications)
if( SystemInfo.isWindows )
deleteTemporaryFiles( tempDir );
return tempDir;
}
private static void deleteTemporaryFiles( Path tempDir ) {
if( deletedTemporary )
return;
deletedTemporary = true;
File[] markerFiles = tempDir.toFile().listFiles( (dir, name) -> name.endsWith( DELETE_SUFFIX ) );
if( markerFiles == null )
return;
for( File markerFile : markerFiles ) {
File toDeleteFile = new File( markerFile.getParent(), StringUtils.removeTrailing( markerFile.getName(), DELETE_SUFFIX ) );
if( !toDeleteFile.exists() || toDeleteFile.delete() )
markerFile.delete();
}
}
private static void deleteOrMarkForDeletion( File file ) {
// try to delete the native library
if( file.delete() )
return;
// not possible to delete on Windows because native library file is locked
// --> create "to delete" marker file (used at next startup)
try {
File markFile = new File( file.getParent(), file.getName() + DELETE_SUFFIX );
markFile.createNewFile();
} catch( IOException ex2 ) {
// ignore
}
}
}

View File

@@ -77,7 +77,7 @@ debug*/
double scaleFactor = systemScaleFactor * userScaleFactor;
// paint input image icon if not necessary to scale
if( scaleFactor == 1 && iconWidth == imageIcon.getIconWidth() && iconHeight == imageIcon.getIconHeight() ) {
if( scaleFactor == 1 && imageIcon != null && iconWidth == imageIcon.getIconWidth() && iconHeight == imageIcon.getIconHeight() ) {
imageIcon.paintIcon( c, g, x, y );
return;
}

View File

@@ -38,6 +38,9 @@ public class SystemInfo
public static final boolean isMacOS_10_14_Mojave_orLater;
public static final boolean isMacOS_10_15_Catalina_orLater;
// OS architecture
/** @since 1.1 */ public static final boolean isX86_64;
// Java versions
public static final long javaVersion;
public static final boolean isJava_9_orLater;
@@ -51,6 +54,11 @@ public class SystemInfo
// UI toolkits
public static final boolean isKDE;
// other
/** @since 1.1 */ public static final boolean isProjector;
/** @since 1.1.2 */ public static final boolean isWebswing;
/** @since 1.1.1 */ public static final boolean isWinPE;
static {
// platforms
String osName = System.getProperty( "os.name" ).toLowerCase( Locale.ENGLISH );
@@ -65,6 +73,10 @@ public class SystemInfo
isMacOS_10_14_Mojave_orLater = (isMacOS && osVersion >= toVersion( 10, 14, 0, 0 ));
isMacOS_10_15_Catalina_orLater = (isMacOS && osVersion >= toVersion( 10, 15, 0, 0 ));
// OS architecture
String osArch = System.getProperty( "os.arch" );
isX86_64 = osArch.equals( "amd64" ) || osArch.equals( "x86_64" );
// Java versions
javaVersion = scanVersion( System.getProperty( "java.version" ) );
isJava_9_orLater = (javaVersion >= toVersion( 9, 0, 0, 0 ));
@@ -78,6 +90,11 @@ public class SystemInfo
// UI toolkits
isKDE = (isLinux && System.getenv( "KDE_FULL_SESSION" ) != null);
// other
isProjector = Boolean.getBoolean( "org.jetbrains.projector.server.enable" );
isWebswing = (System.getProperty( "webswing.rootDir" ) != null);
isWinPE = isWindows && "X:\\Windows\\System32".equalsIgnoreCase( System.getProperty( "user.dir" ) );
}
public static long scanVersion( String version ) {

View File

@@ -36,9 +36,14 @@ import javax.swing.plaf.UIResource;
import com.formdev.flatlaf.FlatSystemProperties;
/**
* Two scaling modes are supported for HiDPI displays:
* This class handles scaling in Swing UIs.
* It computes user scaling factor based on font size and
* provides methods to scale integer, float, {@link Dimension} and {@link Insets}.
* This class is look and feel independent.
* <p>
* Two scaling modes are supported by FlatLaf for HiDPI displays:
*
* 1) system scaling mode
* <h2>1) system scaling mode</h2>
*
* This mode is supported since Java 9 on all platforms and in some Java 8 VMs
* (e.g. Apple and JetBrains). The JRE determines the scale factor per-display and
@@ -49,7 +54,7 @@ import com.formdev.flatlaf.FlatSystemProperties;
* The scale factor may be different for each connected display.
* The scale factor may change for a window when moving the window from one display to another one.
*
* 2) user scaling mode
* <h2>2) user scaling mode</h2>
*
* This mode is mainly for Java 8 compatibility, but is also used on Linux
* or if the default font is changed.
@@ -85,6 +90,9 @@ public class UIScale
private static Boolean jreHiDPI;
/**
* Returns whether system scaling is enabled.
*/
public static boolean isSystemScalingEnabled() {
if( jreHiDPI != null )
return jreHiDPI;
@@ -112,10 +120,16 @@ public class UIScale
return jreHiDPI;
}
/**
* Returns the system scale factor for the given graphics context.
*/
public static double getSystemScaleFactor( Graphics2D g ) {
return isSystemScalingEnabled() ? getSystemScaleFactor( g.getDeviceConfiguration() ) : 1;
}
/**
* Returns the system scale factor for the given graphics configuration.
*/
public static double getSystemScaleFactor( GraphicsConfiguration gc ) {
return (isSystemScalingEnabled() && gc != null) ? gc.getDefaultTransform().getScaleX() : 1;
}
@@ -166,7 +180,7 @@ public class UIScale
// apply custom scale factor specified in system property "flatlaf.uiScale"
float customScaleFactor = getCustomScaleFactor();
if( customScaleFactor > 0 ) {
setUserScaleFactor( customScaleFactor );
setUserScaleFactor( customScaleFactor, false );
return;
}
@@ -216,7 +230,7 @@ public class UIScale
} else
newScaleFactor = computeScaleFactor( font );
setUserScaleFactor( newScaleFactor );
setUserScaleFactor( newScaleFactor, true );
}
private static float computeScaleFactor( Font font ) {
@@ -260,7 +274,7 @@ public class UIScale
if( scaleFactor == fontScaleFactor )
return font;
int newFontSize = Math.round( (font.getSize() / fontScaleFactor) * scaleFactor );
int newFontSize = Math.max( Math.round( (font.getSize() / fontScaleFactor) * scaleFactor ), 1 );
return new FontUIResource( font.deriveFont( (float) newFontSize ) );
}
@@ -297,16 +311,29 @@ public class UIScale
}
}
/**
* Returns the user scale factor.
*/
public static float getUserScaleFactor() {
initialize();
return scaleFactor;
}
private static void setUserScaleFactor( float scaleFactor ) {
if( scaleFactor <= 1f )
scaleFactor = 1f;
else // round scale factor to 1/4
scaleFactor = Math.round( scaleFactor * 4f ) / 4f;
/**
* Sets the user scale factor.
*/
private static void setUserScaleFactor( float scaleFactor, boolean normalize ) {
if( normalize ) {
if( scaleFactor < 1f ) {
scaleFactor = FlatSystemProperties.getBoolean( FlatSystemProperties.UI_SCALE_ALLOW_SCALE_DOWN, false )
? Math.round( scaleFactor * 10f ) / 10f // round small scale factor to 1/10
: 1f;
} else if( scaleFactor > 1f ) // round scale factor to 1/4
scaleFactor = Math.round( scaleFactor * 4f ) / 4f;
}
// minimum scale factor
scaleFactor = Math.max( scaleFactor, 0.1f );
float oldScaleFactor = UIScale.scaleFactor;
UIScale.scaleFactor = scaleFactor;
@@ -318,40 +345,65 @@ public class UIScale
changeSupport.firePropertyChange( "userScaleFactor", oldScaleFactor, scaleFactor );
}
/**
* Multiplies the given value by the user scale factor.
*/
public static float scale( float value ) {
initialize();
return (scaleFactor == 1) ? value : (value * scaleFactor);
}
/**
* Multiplies the given value by the user scale factor and rounds the result.
*/
public static int scale( int value ) {
initialize();
return (scaleFactor == 1) ? value : Math.round( value * scaleFactor );
}
/**
* Similar as scale(int) but always "rounds down".
* Similar as {@link #scale(int)} but always "rounds down".
* <p>
* For use in special cases. {@link #scale(int)} is the preferred method.
*/
public static int scale2( int value ) {
initialize();
return (scaleFactor == 1) ? value : (int) (value * scaleFactor);
}
/**
* Divides the given value by the user scale factor.
*/
public static float unscale( float value ) {
initialize();
return (scaleFactor == 1f) ? value : (value / scaleFactor);
}
/**
* Divides the given value by the user scale factor and rounds the result.
*/
public static int unscale( int value ) {
initialize();
return (scaleFactor == 1f) ? value : Math.round( value / scaleFactor );
}
/**
* If user scale factor is not 1, scale the given graphics context by invoking
* {@link Graphics2D#scale(double, double)} with user scale factor.
*/
public static void scaleGraphics( Graphics2D g ) {
initialize();
if( scaleFactor != 1f )
g.scale( scaleFactor, scaleFactor );
}
/**
* Scales the given dimension with the user scale factor.
* <p>
* If user scale factor is 1, then the given dimension is simply returned.
* Otherwise a new instance of {@link Dimension} or {@link DimensionUIResource}
* is returned, depending on whether the passed dimension implements {@link UIResource}.
*/
public static Dimension scale( Dimension dimension ) {
initialize();
return (dimension == null || scaleFactor == 1f)
@@ -361,6 +413,13 @@ public class UIScale
: new Dimension ( scale( dimension.width ), scale( dimension.height ) ));
}
/**
* Scales the given insets with the user scale factor.
* <p>
* If user scale factor is 1, then the given insets is simply returned.
* Otherwise a new instance of {@link Insets} or {@link InsetsUIResource}
* is returned, depending on whether the passed dimension implements {@link UIResource}.
*/
public static Insets scale( Insets insets ) {
initialize();
return (insets == null || scaleFactor == 1f)

View File

@@ -0,0 +1,37 @@
/*
* Copyright 2021 FormDev Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.formdev.flatlaf.ui;
import java.util.function.BiPredicate;
/**
* @author Karl Tauber
*/
class StackUtilsImpl
extends StackUtils
{
@Override
boolean wasInvokedFromImpl( BiPredicate<String, String> predicate, int limit ) {
return StackWalker.getInstance().walk( stream -> {
if( limit > 0 )
stream = stream.limit( limit + 2 );
return stream.anyMatch( f -> {
return predicate.test( f.getClassName(), f.getMethodName() );
} );
} );
}
}

View File

@@ -0,0 +1,38 @@
/*
* Copyright 2021 FormDev Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.formdev.flatlaf.util;
import com.formdev.flatlaf.FlatLaf;
/**
* @since 1.1
*/
class LoggingFacadeImpl
implements LoggingFacade
{
private static final System.Logger LOG = System.getLogger( FlatLaf.class.getName() );
@Override
public void logSevere( String message, Throwable t ) {
LOG.log( System.Logger.Level.ERROR, message, t );
}
@Override
public void logConfig( String message, Throwable t ) {
LOG.log( System.Logger.Level.DEBUG, message, t );
}
}

View File

@@ -19,7 +19,6 @@
*/
module com.formdev.flatlaf {
requires java.desktop;
requires java.logging;
exports com.formdev.flatlaf;
exports com.formdev.flatlaf.icons;

View File

@@ -14,15 +14,35 @@
# limitations under the License.
#
#
# This file is loaded for "FlatLaf Darcula" theme (that extend class FlatDarculaLaf)
# and for all dark IntelliJ Platform themes.
#
# Documentation:
# - https://www.formdev.com/flatlaf/properties-files/
# - https://www.formdev.com/flatlaf/how-to-customize/
#
# NOTE: Avoid copying the whole content of this file to own properties files.
# This will make upgrading to newer FlatLaf versions complex and error-prone.
# Instead copy and modify only those properties that you need to alter.
#
# Colors and style mostly based on Darcula theme from IntelliJ IDEA Community Edition,
# which is licensed under the Apache 2.0 license. Copyright 2000-2019 JetBrains s.r.o.
# See: https://github.com/JetBrains/intellij-community/
#---- Button ----
Button.innerFocusWidth = 0
Button.default.boldText = true
#---- CheckBox ----
CheckBox.icon.focusedBackground = null
#---- Component ----
Component.focusWidth = 2

View File

@@ -14,6 +14,18 @@
# limitations under the License.
#
#
# This file is loaded for all dark themes (that extend class FlatDarkLaf).
#
# Documentation:
# - https://www.formdev.com/flatlaf/properties-files/
# - https://www.formdev.com/flatlaf/how-to-customize/
#
# NOTE: Avoid copying the whole content of this file to own properties files.
# This will make upgrading to newer FlatLaf versions complex and error-prone.
# Instead copy and modify only those properties that you need to alter.
#
# Colors and style mostly based on Darcula theme from IntelliJ IDEA Community Edition,
# which is licensed under the Apache 2.0 license. Copyright 2000-2019 JetBrains s.r.o.
# See: https://github.com/JetBrains/intellij-community/
@@ -72,6 +84,8 @@ Button.disabledBorderColor = $Button.borderColor
Button.focusedBorderColor = $Component.focusedBorderColor
Button.hoverBorderColor = $Button.focusedBorderColor
Button.innerFocusWidth = 1
Button.default.background = #365880
Button.default.foreground = #bbb
Button.default.hoverBackground = lighten($Button.default.background,3%,derived)
@@ -103,6 +117,7 @@ CheckBox.icon.disabledCheckmarkColor = #606060
# focused
CheckBox.icon.focusedBorderColor = #466D94
CheckBox.icon.focusedBackground = fade($CheckBox.icon.focusedBorderColor,30%)
# hover
CheckBox.icon.hoverBorderColor = $CheckBox.icon.focusedBorderColor
@@ -151,7 +166,7 @@ Desktop.background = #3E434C
#---- DesktopIcon ----
DesktopIcon.background = lighten($Desktop.background,10%)
DesktopIcon.background = lighten($Desktop.background,10%,derived)
#---- InternalFrame ----

View File

@@ -14,6 +14,19 @@
# limitations under the License.
#
#
# This file is loaded for "FlatLaf IntelliJ" theme (that extend class FlatIntelliJLaf)
# and for all light IntelliJ Platform themes.
#
# Documentation:
# - https://www.formdev.com/flatlaf/properties-files/
# - https://www.formdev.com/flatlaf/how-to-customize/
#
# NOTE: Avoid copying the whole content of this file to own properties files.
# This will make upgrading to newer FlatLaf versions complex and error-prone.
# Instead copy and modify only those properties that you need to alter.
#
# Colors and style mostly based on IntelliJ theme from IntelliJ IDEA Community Edition,
# which is licensed under the Apache 2.0 license. Copyright 2000-2019 JetBrains s.r.o.
# See: https://github.com/JetBrains/intellij-community/

View File

@@ -14,6 +14,18 @@
# limitations under the License.
#
#
# This file is loaded for all themes.
#
# Documentation:
# - https://www.formdev.com/flatlaf/properties-files/
# - https://www.formdev.com/flatlaf/how-to-customize/
#
# NOTE: Avoid copying the whole content of this file to own properties files.
# This will make upgrading to newer FlatLaf versions complex and error-prone.
# Instead copy and modify only those properties that you need to alter.
#
#---- UI delegates ----
ButtonUI = com.formdev.flatlaf.ui.FlatButtonUI
@@ -272,12 +284,15 @@ HelpButton.focusedBorderColor = $CheckBox.icon.focusedBorderColor
HelpButton.hoverBorderColor = $?CheckBox.icon.hoverBorderColor
HelpButton.background = $CheckBox.icon.background
HelpButton.disabledBackground = $CheckBox.icon.disabledBackground
HelpButton.focusedBackground = $?CheckBox.icon.focusedBackground
HelpButton.focusedBackground = $?Button.focusedBackground
HelpButton.hoverBackground = $?CheckBox.icon.hoverBackground
HelpButton.pressedBackground = $?CheckBox.icon.pressedBackground
HelpButton.questionMarkColor = $CheckBox.icon.checkmarkColor
HelpButton.disabledQuestionMarkColor = $CheckBox.icon.disabledCheckmarkColor
HelpButton.borderWidth = $?Button.borderWidth
HelpButton.innerFocusWidth = $?Button.innerFocusWidth
#---- InternalFrame ----
@@ -499,6 +514,17 @@ ScrollPane.fillUpperCorner = true
ScrollPane.smoothScrolling = true
#---- SearchField ----
SearchField.searchIconColor = fadeout(Actions.GreyInline,10%,lazy)
SearchField.searchIconHoverColor = fadeout(Actions.GreyInline,30%,lazy)
SearchField.searchIconPressedColor = fadeout(Actions.GreyInline,50%,lazy)
SearchField.clearIconColor = fadeout(Actions.GreyInline,50%,lazy)
SearchField.clearIconHoverColor = $SearchField.clearIconColor
SearchField.clearIconPressedColor = fadeout(Actions.GreyInline,20%,lazy)
#---- Separator ----
Separator.height = 3
@@ -602,6 +628,7 @@ TabbedPane.closeCrossLineWidth = {float}1
Table.rowHeight = 20
Table.showHorizontalLines = false
Table.showVerticalLines = false
Table.showTrailingVerticalLine = false
Table.consistentHomeEndKeyBehavior = true
Table.intercellSpacing = {dimension}0,0
Table.scrollPaneBorder = com.formdev.flatlaf.ui.FlatBorder
@@ -627,10 +654,11 @@ Table.dropLineShortColor = @dropLineShortColor
#---- TableHeader ----
TableHeader.height = 25
TableHeader.cellBorder = 2,3,2,3
TableHeader.cellBorder = com.formdev.flatlaf.ui.FlatTableHeaderBorder
TableHeader.cellMargins = 2,3,2,3
TableHeader.focusCellBackground = $TableHeader.background
TableHeader.background = @textComponentBackground
TableHeader.showTrailingVerticalLine = false
#---- TextArea ----
@@ -670,13 +698,17 @@ TitledBorder.border = 1,1,1,1,$Separator.foreground
#---- TitlePane ----
TitlePane.useWindowDecorations = true
TitlePane.menuBarEmbedded = true
TitlePane.unifiedBackground = false
TitlePane.iconSize = 16,16
TitlePane.iconMargins = 3,8,3,0
TitlePane.menuBarMargins = 0,8,0,22
TitlePane.titleMargins = 3,8,3,8
TitlePane.iconMargins = 3,8,3,8
TitlePane.titleMargins = 3,0,3,0
TitlePane.buttonSize = 44,30
TitlePane.buttonMaximizedHeight = 22
TitlePane.centerTitle = false
TitlePane.centerTitleIfMenuBarEmbedded = true
TitlePane.menuBarTitleGap = 20
TitlePane.closeIcon = com.formdev.flatlaf.icons.FlatWindowCloseIcon
TitlePane.iconifyIcon = com.formdev.flatlaf.icons.FlatWindowIconifyIcon
TitlePane.maximizeIcon = com.formdev.flatlaf.icons.FlatWindowMaximizeIcon
@@ -732,6 +764,7 @@ ToolBar.separatorWidth = 7
ToolBar.separatorColor = $Separator.foreground
ToolBar.spacingBorder = $Button.toolbar.spacingInsets
ToolBar.focusableButtons = false
#---- ToolTipManager ----

View File

@@ -14,6 +14,18 @@
# limitations under the License.
#
#
# This file is loaded for all light themes (that extend class FlatLightLaf).
#
# Documentation:
# - https://www.formdev.com/flatlaf/properties-files/
# - https://www.formdev.com/flatlaf/how-to-customize/
#
# NOTE: Avoid copying the whole content of this file to own properties files.
# This will make upgrading to newer FlatLaf versions complex and error-prone.
# Instead copy and modify only those properties that you need to alter.
#
# Colors and style mostly based on IntelliJ theme from IntelliJ IDEA Community Edition,
# which is licensed under the Apache 2.0 license. Copyright 2000-2019 JetBrains s.r.o.
# See: https://github.com/JetBrains/intellij-community/
@@ -73,6 +85,8 @@ Button.disabledBorderColor = $Component.disabledBorderColor
Button.focusedBorderColor = $Component.focusedBorderColor
Button.hoverBorderColor = $Button.focusedBorderColor
Button.innerFocusWidth = 0
Button.default.background = $Button.background
Button.default.foreground = @foreground
Button.default.focusedBackground = $Button.focusedBackground
@@ -158,7 +172,7 @@ Desktop.background = #E6EBF0
#---- DesktopIcon ----
DesktopIcon.background = darken($Desktop.background,10%)
DesktopIcon.background = darken($Desktop.background,10%,derived)
#---- HelpButton ----

View File

@@ -14,6 +14,36 @@
# limitations under the License.
#
#
# This file is loaded for all IntelliJ Platform themes.
#
# Documentation:
# - https://www.formdev.com/flatlaf/properties-files/
# - https://www.formdev.com/flatlaf/how-to-customize/
#
#---- system colors ----
# fix (most) system colors because they are usually not set in .json files
desktop = lazy(TextField.background)
activeCaptionText = lazy(TextField.foreground)
inactiveCaptionText = lazy(TextField.foreground)
window = lazy(Panel.background)
windowBorder = lazy(TextField.foreground)
windowText = lazy(TextField.foreground)
menu = lazy(Menu.background)
menuText = lazy(Menu.foreground)
text = lazy(TextField.background)
textText = lazy(TextField.foreground)
textHighlight = lazy(TextField.selectionBackground)
textHighlightText = lazy(TextField.selectionForeground)
textInactiveText = lazy(TextField.inactiveForeground)
control = lazy(Panel.background)
controlText = lazy(TextField.foreground)
info = lazy(ToolTip.background)
infoText = lazy(ToolTip.foreground)
#---- Button ----
Button.startBackground = $Button.background
@@ -61,21 +91,33 @@ ToggleButton.endBackground = $ToggleButton.background
@ijMenuCheckBackgroundL20 = lighten(@selectionBackground,20%,derived noAutoInverse)
@ijMenuCheckBackgroundD10 = darken(@selectionBackground,10%,derived noAutoInverse)
[Arc_Theme]CheckBoxMenuItem.foreground = lazy(MenuItem.foreground)
[Arc_Theme]PopupMenu.foreground = lazy(MenuItem.foreground)
[Arc_Theme]RadioButtonMenuItem.foreground = lazy(MenuItem.foreground)
[Arc_Theme]ProgressBar.selectionBackground = #000
[Arc_Theme]ProgressBar.selectionForeground = #fff
[Arc_Theme]List.selectionInactiveForeground = #fff
[Arc_Theme]Table.selectionInactiveForeground = #fff
[Arc_Theme]Tree.selectionInactiveForeground = #fff
[Arc_Theme_-_Orange]CheckBoxMenuItem.foreground = lazy(MenuItem.foreground)
[Arc_Theme_-_Orange]PopupMenu.foreground = lazy(MenuItem.foreground)
[Arc_Theme_-_Orange]RadioButtonMenuItem.foreground = lazy(MenuItem.foreground)
[Arc_Theme_-_Orange]ProgressBar.selectionBackground = #000
[Arc_Theme_-_Orange]ProgressBar.selectionForeground = #fff
[Arc_Theme_-_Orange]List.selectionInactiveForeground = #fff
[Arc_Theme_-_Orange]Table.selectionInactiveForeground = #fff
[Arc_Theme_-_Orange]Tree.selectionInactiveForeground = #fff
[Arc_Theme_Dark]CheckBoxMenuItem.foreground = lazy(MenuItem.foreground)
[Arc_Theme_Dark]PopupMenu.foreground = lazy(MenuItem.foreground)
[Arc_Theme_Dark]RadioButtonMenuItem.foreground = lazy(MenuItem.foreground)
[Arc_Theme_Dark]ProgressBar.selectionBackground = #ddd
[Arc_Theme_Dark]ProgressBar.selectionForeground = #ddd
[Arc_Theme_Dark_-_Orange]CheckBoxMenuItem.foreground = lazy(MenuItem.foreground)
[Arc_Theme_Dark_-_Orange]PopupMenu.foreground = lazy(MenuItem.foreground)
[Arc_Theme_Dark_-_Orange]RadioButtonMenuItem.foreground = lazy(MenuItem.foreground)
[Arc_Theme_Dark_-_Orange]ProgressBar.selectionBackground = #ddd
[Arc_Theme_Dark_-_Orange]ProgressBar.selectionForeground = #fff
@@ -87,10 +129,12 @@ ToggleButton.endBackground = $ToggleButton.background
[Cyan_light]MenuItem.checkBackground = @ijMenuCheckBackgroundL20
[Cyan_light]MenuItem.underlineSelectionCheckBackground = @ijMenuCheckBackgroundL20
[Dark_Flat_Theme]TableHeader.background = #3B3B3B
[Dark_purple]Slider.focusedColor = fade($Component.focusColor,70%,derived)
[Dracula]ProgressBar.selectionBackground = #fff
[Dracula]ProgressBar.selectionForeground = #fff
[Dracula---Zihan_Ma]ProgressBar.selectionBackground = #fff
[Dracula---Zihan_Ma]ProgressBar.selectionForeground = #fff
[Gradianto_Dark_Fuchsia]MenuItem.checkBackground = @ijMenuCheckBackgroundL10
[Gradianto_Dark_Fuchsia]MenuItem.underlineSelectionCheckBackground = @ijMenuCheckBackgroundL10
@@ -115,6 +159,8 @@ ToggleButton.endBackground = $ToggleButton.background
[High_contrast]ToggleButton.disabledSelectedBackground = #444
[High_contrast]ToggleButton.toolbar.selectedBackground = #fff
[Light_Flat]TableHeader.background = #E5E5E9
[Monocai]MenuItem.checkBackground = @ijMenuCheckBackgroundL10
[Monocai]MenuItem.underlineSelectionCheckBackground = @ijMenuCheckBackgroundL10
@Monocai.acceleratorForeground = lazy(MenuItem.disabledForeground)
@@ -135,7 +181,7 @@ ToggleButton.endBackground = $ToggleButton.background
[One_Dark]MenuItem.underlineSelectionCheckBackground = @ijMenuCheckBackgroundL10
[One_Dark]Slider.focusedColor = fade(#568af2,40%)
[Solarized_Dark]Slider.focusedColor = fade($Component.focusColor,80%,derived)
[Solarized_Dark---4lex4]Slider.focusedColor = fade($Component.focusColor,80%,derived)
[vuesion-theme]MenuItem.checkBackground = @ijMenuCheckBackgroundL10
[vuesion-theme]MenuItem.underlineSelectionCheckBackground = @ijMenuCheckBackgroundL10
@@ -152,6 +198,9 @@ ToggleButton.endBackground = $ToggleButton.background
[dark][author-Mallowigi]MenuItem.checkBackground = @ijMenuCheckBackgroundL20
[dark][author-Mallowigi]MenuItem.underlineSelectionCheckBackground = @ijMenuCheckBackgroundL20
[Dracula---Mallowigi]ProgressBar.selectionBackground = #fff
[Dracula---Mallowigi]ProgressBar.selectionForeground = #fff
[Dracula_Contrast]ProgressBar.selectionBackground = #fff
[Dracula_Contrast]ProgressBar.selectionForeground = #fff
@@ -191,14 +240,14 @@ ToggleButton.endBackground = $ToggleButton.background
[Night_Owl_Contrast]ProgressBar.selectionBackground = #ddd
[Night_Owl_Contrast]ProgressBar.selectionForeground = #ddd
[Solarized_Dark]ProgressBar.selectionBackground = #ccc
[Solarized_Dark]ProgressBar.selectionForeground = #ccc
[Solarized_Dark---Mallowigi]ProgressBar.selectionBackground = #ccc
[Solarized_Dark---Mallowigi]ProgressBar.selectionForeground = #ccc
[Material_Solarized_Dark_Contrast]ProgressBar.selectionBackground = #ccc
[Material_Solarized_Dark_Contrast]ProgressBar.selectionForeground = #ccc
[Solarized_Dark_Contrast]ProgressBar.selectionBackground = #ccc
[Solarized_Dark_Contrast]ProgressBar.selectionForeground = #ccc
[Solarized_Light]ProgressBar.selectionBackground = #222
[Solarized_Light]ProgressBar.selectionForeground = #fff
[Solarized_Light---Mallowigi]ProgressBar.selectionBackground = #222
[Solarized_Light---Mallowigi]ProgressBar.selectionForeground = #fff
[Material_Solarized_Light_Contrast]ProgressBar.selectionBackground = #222
[Material_Solarized_Light_Contrast]ProgressBar.selectionForeground = #fff
[Solarized_Light_Contrast]ProgressBar.selectionBackground = #222
[Solarized_Light_Contrast]ProgressBar.selectionForeground = #fff

Some files were not shown because too many files have changed in this diff Show More