Compare commits
256 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d8df8c9631 | ||
|
|
f61a7288eb | ||
|
|
47a1122f04 | ||
|
|
e1bfabbce5 | ||
|
|
9708fec0e0 | ||
|
|
7f4efaf0a3 | ||
|
|
269eb0ba29 | ||
|
|
7dac3825d7 | ||
|
|
6c0b122fbc | ||
|
|
4da2bd90cb | ||
|
|
cb70fb4e82 | ||
|
|
2593a43d72 | ||
|
|
e44ff5b72a | ||
|
|
22cb1b50a6 | ||
|
|
95a15c3cf8 | ||
|
|
ab320684f5 | ||
|
|
a284b69a1e | ||
|
|
b590f41254 | ||
|
|
a97076ead5 | ||
|
|
0b6df8be1c | ||
|
|
150bab0b57 | ||
|
|
a253b6c0cf | ||
|
|
efcbc1fbdb | ||
|
|
ae28c595f9 | ||
|
|
1d08ddda60 | ||
|
|
578379fd00 | ||
|
|
7c9f550d4c | ||
|
|
84d4510d70 | ||
|
|
fa194ec258 | ||
|
|
fd56de403d | ||
|
|
85fde46504 | ||
|
|
b283178979 | ||
|
|
bddef38a7c | ||
|
|
b5f2f77944 | ||
|
|
fca0718ed0 | ||
|
|
0d44ade6ea | ||
|
|
6018f83a22 | ||
|
|
0b6247851b | ||
|
|
8640dee053 | ||
|
|
824db2e3bd | ||
|
|
c2c79c4676 | ||
|
|
4795fe5687 | ||
|
|
d508f339c1 | ||
|
|
c7054537e7 | ||
|
|
b98b904023 | ||
|
|
253df9325d | ||
|
|
78a9cc1d0c | ||
|
|
b25fcc3381 | ||
|
|
51d7bc2c37 | ||
|
|
09a18b2305 | ||
|
|
31f2feee2e | ||
|
|
218bb62bfd | ||
|
|
694c2ad767 | ||
|
|
97943fcd38 | ||
|
|
77f33467d2 | ||
|
|
651454170d | ||
|
|
7ca48bd136 | ||
|
|
968e508bb5 | ||
|
|
a6d318a197 | ||
|
|
cd20f4086b | ||
|
|
ebd5905947 | ||
|
|
817a3c62bb | ||
|
|
f8f58400fe | ||
|
|
ef06840649 | ||
|
|
b17c14d62e | ||
|
|
19dba94064 | ||
|
|
601e24f9e7 | ||
|
|
c7f323ee13 | ||
|
|
e4522f3af4 | ||
|
|
79af461a5b | ||
|
|
2e8e07faf6 | ||
|
|
ecdb000818 | ||
|
|
999fd0d4da | ||
|
|
705dd9558f | ||
|
|
97ca866ffa | ||
|
|
543b977db7 | ||
|
|
ebb8a6d025 | ||
|
|
506543281e | ||
|
|
60322be22a | ||
|
|
e1f30f24a8 | ||
|
|
1759f6b25c | ||
|
|
6578f25cc9 | ||
|
|
8c26e0323f | ||
|
|
a5575894ab | ||
|
|
357823a027 | ||
|
|
a6d3f6b3eb | ||
|
|
ae4c69e75c | ||
|
|
31cadc532b | ||
|
|
6e8443473b | ||
|
|
cca4ab3cd8 | ||
|
|
dab0ee3306 | ||
|
|
c6d1ed91a7 | ||
|
|
a613a244f4 | ||
|
|
268fe15004 | ||
|
|
7bc9be686f | ||
|
|
751919ec5a | ||
|
|
da913b426e | ||
|
|
d8ef99cd8f | ||
|
|
d08a6d7dd3 | ||
|
|
896e9bca8e | ||
|
|
1df9597bb1 | ||
|
|
eaf55f2099 | ||
|
|
5018a1f9eb | ||
|
|
71ba8f55a7 | ||
|
|
b65db707ed | ||
|
|
ed62266a43 | ||
|
|
49913b7dad | ||
|
|
3eeeb9e00b | ||
|
|
bfb1642284 | ||
|
|
0544a605c3 | ||
|
|
3f5acda132 | ||
|
|
02b1ba2926 | ||
|
|
7f7f9e3c7c | ||
|
|
6fcee03752 | ||
|
|
5782ceeb5d | ||
|
|
f752db5892 | ||
|
|
bce58bc97b | ||
|
|
d373687bc4 | ||
|
|
e5e510c825 | ||
|
|
29064ec72f | ||
|
|
953eee1dc8 | ||
|
|
75f76f4875 | ||
|
|
ecfbe68c33 | ||
|
|
7f02eb9cf0 | ||
|
|
4ab90065dc | ||
|
|
d3e39a1359 | ||
|
|
60e5861de4 | ||
|
|
ca7f5045ae | ||
|
|
b0997fb5d2 | ||
|
|
37dab9fb22 | ||
|
|
fb44c8fbe4 | ||
|
|
94375b7d36 | ||
|
|
8b585deb78 | ||
|
|
4d8b544aed | ||
|
|
548d651d29 | ||
|
|
0b342acec9 | ||
|
|
cc6d3c1b1a | ||
|
|
74a748d92e | ||
|
|
1de81d0af5 | ||
|
|
ff9ef21f67 | ||
|
|
266a546478 | ||
|
|
87407ca832 | ||
|
|
90282d4436 | ||
|
|
abbe6d6c1f | ||
|
|
a28f701e6f | ||
|
|
4cdc995a7f | ||
|
|
c708205593 | ||
|
|
a22c6c8013 | ||
|
|
b576f473e5 | ||
|
|
0b127caa83 | ||
|
|
4507ce359d | ||
|
|
3e14f28dc2 | ||
|
|
a9dcf09d13 | ||
|
|
c8998c2bcf | ||
|
|
10bf1295bc | ||
|
|
1e869973d4 | ||
|
|
731c8962c9 | ||
|
|
294b8bb789 | ||
|
|
4f9b819f48 | ||
|
|
5318d5fa8e | ||
|
|
98b156bdde | ||
|
|
511dd02107 | ||
|
|
f1f7a2e7b6 | ||
|
|
d557cf5427 | ||
|
|
39d2941099 | ||
|
|
2a732306a1 | ||
|
|
8a72b30cbc | ||
|
|
ed9cb0f918 | ||
|
|
7e0915cb9c | ||
|
|
a51294d570 | ||
|
|
d962f218a1 | ||
|
|
7b248427f0 | ||
|
|
b99fb8b11f | ||
|
|
26250e790f | ||
|
|
b26dbe81f4 | ||
|
|
903212345b | ||
|
|
025f6564dc | ||
|
|
35f97368fa | ||
|
|
09e5c86488 | ||
|
|
8998371cae | ||
|
|
29e1dc6b55 | ||
|
|
439e63b52f | ||
|
|
eea341fb33 | ||
|
|
359eedf773 | ||
|
|
866751ffc1 | ||
|
|
38a3a0768d | ||
|
|
03b42749cd | ||
|
|
60fd78e082 | ||
|
|
9edaf58929 | ||
|
|
5000186f85 | ||
|
|
cacf0ea987 | ||
|
|
067501cbe7 | ||
|
|
9fe0cf496b | ||
|
|
9d0823038e | ||
|
|
5a05efefdd | ||
|
|
988d171bdd | ||
|
|
e6f72bf343 | ||
|
|
89c5a0c57b | ||
|
|
d97146393c | ||
|
|
1c52f1f76c | ||
|
|
9bd3a68115 | ||
|
|
f58780d36b | ||
|
|
6eb15ab437 | ||
|
|
00dc7004f5 | ||
|
|
8ec0e57235 | ||
|
|
d75dc9e70c | ||
|
|
ec2fccbb0e | ||
|
|
34861166e8 | ||
|
|
584fa0a26e | ||
|
|
6c48489d89 | ||
|
|
ba9c884a0c | ||
|
|
360f0bafe0 | ||
|
|
4327c13dca | ||
|
|
4f2256f713 | ||
|
|
5167cd368f | ||
|
|
ef7289d11a | ||
|
|
cb11d98bf7 | ||
|
|
992349da8c | ||
|
|
2e7637f274 | ||
|
|
1f8eaf4a64 | ||
|
|
46ac7a9dc7 | ||
|
|
0d86d39217 | ||
|
|
1f591f3d1b | ||
|
|
30c6ddba37 | ||
|
|
406eeaec96 | ||
|
|
2fe5652bc6 | ||
|
|
39bf68a6bd | ||
|
|
a7a4a19824 | ||
|
|
7f906ba0ea | ||
|
|
07bf6e4506 | ||
|
|
a331760321 | ||
|
|
d9c240d729 | ||
|
|
d9526c19e7 | ||
|
|
1798ccd284 | ||
|
|
ab1ce7fab1 | ||
|
|
e9b2f17171 | ||
|
|
d3bf4433b7 | ||
|
|
ba0f43455b | ||
|
|
638af4bcd7 | ||
|
|
5eab843d97 | ||
|
|
c55f0e239e | ||
|
|
32d9381745 | ||
|
|
77fc564e70 | ||
|
|
3b84314c45 | ||
|
|
6db39d1860 | ||
|
|
1762ead89f | ||
|
|
98a3c4b0f5 | ||
|
|
6e990a7e31 | ||
|
|
8e49904f8d | ||
|
|
69f52c8abd | ||
|
|
d7b0754327 | ||
|
|
2a00de11f1 | ||
|
|
923cc51f3e | ||
|
|
c8f7478170 | ||
|
|
bffac60bf8 | ||
|
|
ae8323e2f8 |
8
.gitbugtraq
Normal 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}"
|
||||||
29
.github/workflows/ci.yml
vendored
@@ -34,6 +34,7 @@ jobs:
|
|||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
- uses: gradle/wrapper-validation-action@v1
|
- uses: gradle/wrapper-validation-action@v1
|
||||||
|
if: matrix.java == '1.8'
|
||||||
|
|
||||||
- name: Setup Java ${{ matrix.java }}
|
- name: Setup Java ${{ matrix.java }}
|
||||||
uses: actions/setup-java@v1
|
uses: actions/setup-java@v1
|
||||||
@@ -72,7 +73,7 @@ jobs:
|
|||||||
needs: build
|
needs: build
|
||||||
if: |
|
if: |
|
||||||
github.event_name == 'push' &&
|
github.event_name == 'push' &&
|
||||||
github.ref == 'refs/heads/main' &&
|
(github.ref == 'refs/heads/main' || startsWith( github.ref, 'refs/heads/develop-' )) &&
|
||||||
github.repository == 'JFormDesigner/FlatLaf'
|
github.repository == 'JFormDesigner/FlatLaf'
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
@@ -97,11 +98,22 @@ jobs:
|
|||||||
restore-keys: ${{ runner.os }}-gradle
|
restore-keys: ${{ runner.os }}-gradle
|
||||||
|
|
||||||
- name: Publish snapshot to oss.sonatype.org
|
- name: Publish snapshot to oss.sonatype.org
|
||||||
run: ./gradlew publish -Dorg.gradle.internal.publish.checksums.insecure=true
|
run: ./gradlew publish :flatlaf-theme-editor:build -Dorg.gradle.internal.publish.checksums.insecure=true
|
||||||
env:
|
env:
|
||||||
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
|
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
|
||||||
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
|
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:
|
release:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -133,7 +145,7 @@ jobs:
|
|||||||
restore-keys: ${{ runner.os }}-gradle
|
restore-keys: ${{ runner.os }}-gradle
|
||||||
|
|
||||||
- name: Release a new stable version to Maven Central
|
- name: Release a new stable version to Maven Central
|
||||||
run: ./gradlew publish :flatlaf-demo:build -Drelease=true
|
run: ./gradlew publish :flatlaf-demo:build :flatlaf-theme-editor:build -Drelease=true
|
||||||
env:
|
env:
|
||||||
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
|
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
|
||||||
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
|
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
|
||||||
@@ -150,3 +162,14 @@ jobs:
|
|||||||
localDir: "flatlaf-demo/build/libs"
|
localDir: "flatlaf-demo/build/libs"
|
||||||
remoteDir: "."
|
remoteDir: "."
|
||||||
options: "--only-newer --no-recursion --verbose=1"
|
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"
|
||||||
|
|||||||
266
CHANGELOG.md
@@ -1,6 +1,270 @@
|
|||||||
FlatLaf Change Log
|
FlatLaf Change Log
|
||||||
==================
|
==================
|
||||||
|
|
||||||
|
## 1.6.5
|
||||||
|
|
||||||
|
#### Fixed bugs
|
||||||
|
|
||||||
|
- Linux: Fixed font problems when running on Oracle Java (OpenJDK is not
|
||||||
|
affected):
|
||||||
|
- oversized text if system font is "Inter" (issue #427)
|
||||||
|
- missing text if system font is "Cantarell" (on Fedora)
|
||||||
|
- MenuItem: Changed accelerator delimiter from `-` to `+`. (Windows and Linux).
|
||||||
|
- ComboBox: Fixed occasional `StackOverflowError` when modifying combo box not
|
||||||
|
on AWT thread. (issue #432)
|
||||||
|
- macOS: Fixed `NullPointerException` when using AWT component
|
||||||
|
`java.awt.Choice`. (issue #439)
|
||||||
|
- Native window decorations: Do not exit application with `UnsatisfiedLinkError`
|
||||||
|
in case that FlatLaf DLL cannot be executed because of restrictions on
|
||||||
|
temporary directory. Instead, continue with default window decorations. (issue
|
||||||
|
#436)
|
||||||
|
|
||||||
|
|
||||||
|
## 1.6.4
|
||||||
|
|
||||||
|
#### Fixed bugs
|
||||||
|
|
||||||
|
- ComboBox: Fixed regression in FlatLaf 1.6.3 that makes selected item invisible
|
||||||
|
in popup list if `DefaultListCellRenderer` is used as renderer. If using
|
||||||
|
default renderer, it works. (issue #426)
|
||||||
|
|
||||||
|
|
||||||
|
## 1.6.3
|
||||||
|
|
||||||
|
#### Fixed bugs
|
||||||
|
|
||||||
|
- ComboBox (not editable): Fixed regression in FlatLaf 1.6.2 that may display
|
||||||
|
text in non-editable combo boxes in bold. (issue #423)
|
||||||
|
- Tree: Fixed editing cell issue with custom cell renderer and cell editor that
|
||||||
|
use same component for rendering and editing. (issue #385)
|
||||||
|
|
||||||
|
|
||||||
|
## 1.6.2
|
||||||
|
|
||||||
|
#### Fixed bugs
|
||||||
|
|
||||||
|
- ComboBox (not editable): Fixed background painted outside of border if round
|
||||||
|
edges are enabled (client property `JComponent.roundRect` is `true`). (similar
|
||||||
|
to issue #382; regression since fixing #330 in FlatLaf 1.4)
|
||||||
|
- ComboBox: Fixed `NullPointerException`, which may occur under special
|
||||||
|
circumstances. (issue #408)
|
||||||
|
- Table: Do not select text in cell editor when it gets focus (when
|
||||||
|
`JTable.surrendersFocusOnKeystroke` is `true`) and
|
||||||
|
`TextComponent.selectAllOnFocusPolicy` is `once` (the default) or `always`.
|
||||||
|
(issue #395)
|
||||||
|
- Linux: Fixed NPE when using `java.awt.TrayIcon`. (issue #405)
|
||||||
|
- FileChooser: Workaround for crash on Windows with Java 17 32-bit (disabled
|
||||||
|
Windows icons). Java 17 64-bit is not affected. (issue #403)
|
||||||
|
- Native window decorations: Fixed layout loop, which may occur under special
|
||||||
|
circumstances and slows down the application. (issue #420)
|
||||||
|
|
||||||
|
|
||||||
|
## 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 fixing #330 in 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
|
## 1.1.2
|
||||||
|
|
||||||
#### New features and improvements
|
#### New features and improvements
|
||||||
@@ -164,7 +428,7 @@ FlatLaf Change Log
|
|||||||
- CheckBox and RadioButton: Fill component background as soon as background
|
- CheckBox and RadioButton: Fill component background as soon as background
|
||||||
color is different to default background color, even if component is not
|
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
|
opaque (which is the default). This paints selection if using the component as
|
||||||
cell renderer a Table, Tree or List.
|
cell renderer in Table, Tree or List.
|
||||||
- TextComponents: Border of focused non-editable text components had wrong
|
- TextComponents: Border of focused non-editable text components had wrong
|
||||||
color.
|
color.
|
||||||
- Custom window decorations: Fixed top window border in dark themes when running
|
- Custom window decorations: Fixed top window border in dark themes when running
|
||||||
|
|||||||
15
README.md
@@ -67,20 +67,23 @@ docs).
|
|||||||
Addons
|
Addons
|
||||||
------
|
------
|
||||||
|
|
||||||
- [IntelliJ Themes Pack](flatlaf-intellij-themes)
|
- [IntelliJ Themes Pack](flatlaf-intellij-themes) - bundles many popular
|
||||||
- [Extras](flatlaf-extras)
|
open-source 3rd party themes
|
||||||
- [SwingX](flatlaf-swingx)
|
- [Extras](flatlaf-extras) - SVG icon, tri-state check box, UI inspectors, and
|
||||||
- [JIDE Common Layer](flatlaf-jide-oss)
|
more
|
||||||
|
- [SwingX](flatlaf-swingx) - support for SwingX components
|
||||||
|
- [JIDE Common Layer](flatlaf-jide-oss) - support for JIDE Common Layer
|
||||||
|
components
|
||||||
|
|
||||||
|
|
||||||
Getting started
|
Getting started
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
To enable FlatLaf, add following code to your main method before you create any
|
To use FlatLaf, add following code to your main method before you create any
|
||||||
Swing component:
|
Swing component:
|
||||||
|
|
||||||
~~~java
|
~~~java
|
||||||
FlatLightLaf.install();
|
FlatLightLaf.setup();
|
||||||
|
|
||||||
// create UI here...
|
// create UI here...
|
||||||
~~~
|
~~~
|
||||||
|
|||||||
@@ -14,8 +14,8 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
val releaseVersion = "1.1.2"
|
val releaseVersion = "1.6.5"
|
||||||
val developmentVersion = "1.2-SNAPSHOT"
|
val developmentVersion = "1.6.6-SNAPSHOT"
|
||||||
|
|
||||||
version = if( java.lang.Boolean.getBoolean( "release" ) ) releaseVersion else developmentVersion
|
version = if( java.lang.Boolean.getBoolean( "release" ) ) releaseVersion else developmentVersion
|
||||||
|
|
||||||
@@ -47,19 +47,35 @@ allprojects {
|
|||||||
targetCompatibility = "1.8"
|
targetCompatibility = "1.8"
|
||||||
|
|
||||||
options.encoding = "ISO-8859-1"
|
options.encoding = "ISO-8859-1"
|
||||||
|
options.isDeprecation = false
|
||||||
}
|
}
|
||||||
|
|
||||||
withType<Jar>().configureEach {
|
withType<Jar>().configureEach {
|
||||||
// manifest for all created JARs
|
// manifest for all created JARs
|
||||||
manifest.attributes(mapOf(
|
manifest.attributes(
|
||||||
"Implementation-Vendor" to "FormDev Software GmbH",
|
"Implementation-Vendor" to "FormDev Software GmbH",
|
||||||
"Implementation-Copyright" to "Copyright (C) 2019-${java.time.LocalDate.now().year} FormDev Software GmbH. All rights reserved.",
|
"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
|
// add META-INF/LICENSE to all created JARs
|
||||||
from( "${rootDir}/LICENSE" ) {
|
from( "${rootDir}/LICENSE" ) {
|
||||||
into( "META-INF" )
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,12 @@ plugins {
|
|||||||
`flatlaf-publish`
|
`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 {
|
java {
|
||||||
withSourcesJar()
|
withSourcesJar()
|
||||||
withJavadocJar()
|
withJavadocJar()
|
||||||
@@ -45,16 +51,6 @@ 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" )
|
archiveBaseName.set( "flatlaf" )
|
||||||
}
|
}
|
||||||
@@ -62,6 +58,11 @@ tasks {
|
|||||||
named<Jar>( "javadocJar" ) {
|
named<Jar>( "javadocJar" ) {
|
||||||
archiveBaseName.set( "flatlaf" )
|
archiveBaseName.set( "flatlaf" )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test {
|
||||||
|
useJUnitPlatform()
|
||||||
|
testLogging.exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
flatlafPublish {
|
flatlafPublish {
|
||||||
|
|||||||
@@ -39,8 +39,9 @@ public interface FlatClientProperties
|
|||||||
* {@link #BUTTON_TYPE_SQUARE},
|
* {@link #BUTTON_TYPE_SQUARE},
|
||||||
* {@link #BUTTON_TYPE_ROUND_RECT},
|
* {@link #BUTTON_TYPE_ROUND_RECT},
|
||||||
* {@link #BUTTON_TYPE_TAB},
|
* {@link #BUTTON_TYPE_TAB},
|
||||||
* {@link #BUTTON_TYPE_HELP} or
|
* {@link #BUTTON_TYPE_HELP},
|
||||||
* {@link BUTTON_TYPE_TOOLBAR_BUTTON}
|
* {@link #BUTTON_TYPE_TOOLBAR_BUTTON} or
|
||||||
|
* {@link #BUTTON_TYPE_BORDERLESS}
|
||||||
*/
|
*/
|
||||||
String BUTTON_TYPE = "JButton.buttonType";
|
String BUTTON_TYPE = "JButton.buttonType";
|
||||||
|
|
||||||
@@ -89,6 +90,16 @@ public interface FlatClientProperties
|
|||||||
*/
|
*/
|
||||||
String BUTTON_TYPE_TOOLBAR_BUTTON = "toolBarButton";
|
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.
|
* Specifies selected state of a checkbox.
|
||||||
* <p>
|
* <p>
|
||||||
@@ -272,6 +283,8 @@ public interface FlatClientProperties
|
|||||||
/**
|
/**
|
||||||
* Background color of window title bar (requires enabled window decorations).
|
* Background color of window title bar (requires enabled window decorations).
|
||||||
* <p>
|
* <p>
|
||||||
|
* (requires Window 10)
|
||||||
|
* <p>
|
||||||
* <strong>Component</strong> {@link javax.swing.JRootPane}<br>
|
* <strong>Component</strong> {@link javax.swing.JRootPane}<br>
|
||||||
* <strong>Value type</strong> {@link java.awt.Color}
|
* <strong>Value type</strong> {@link java.awt.Color}
|
||||||
*
|
*
|
||||||
@@ -282,6 +295,8 @@ public interface FlatClientProperties
|
|||||||
/**
|
/**
|
||||||
* Foreground color of window title bar (requires enabled window decorations).
|
* Foreground color of window title bar (requires enabled window decorations).
|
||||||
* <p>
|
* <p>
|
||||||
|
* (requires Window 10)
|
||||||
|
* <p>
|
||||||
* <strong>Component</strong> {@link javax.swing.JRootPane}<br>
|
* <strong>Component</strong> {@link javax.swing.JRootPane}<br>
|
||||||
* <strong>Value type</strong> {@link java.awt.Color}
|
* <strong>Value type</strong> {@link java.awt.Color}
|
||||||
*
|
*
|
||||||
@@ -718,6 +733,18 @@ public interface FlatClientProperties
|
|||||||
*/
|
*/
|
||||||
String PLACEHOLDER_TEXT = "JTextField.placeholderText";
|
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 ------------------------------------------------------
|
//---- JToggleButton ------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package com.formdev.flatlaf;
|
package com.formdev.flatlaf;
|
||||||
|
|
||||||
|
import javax.swing.UIManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Flat LaF that has a dark color scheme and looks like Darcula LaF.
|
* A Flat LaF that has a dark color scheme and looks like Darcula LaF.
|
||||||
* <p>
|
* <p>
|
||||||
@@ -29,10 +31,28 @@ public class FlatDarculaLaf
|
|||||||
{
|
{
|
||||||
public static final String NAME = "FlatLaf Darcula";
|
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() {
|
public static void installLafInfo() {
|
||||||
installLafInfo( NAME, FlatDarculaLaf.class );
|
installLafInfo( NAME, FlatDarculaLaf.class );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,8 +34,16 @@ public class FlatDarkLaf
|
|||||||
* Sets the application look and feel to this LaF
|
* Sets the application look and feel to this LaF
|
||||||
* using {@link UIManager#setLookAndFeel(javax.swing.LookAndFeel)}.
|
* 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() {
|
public static boolean install() {
|
||||||
return install( new FlatDarkLaf() );
|
return setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package com.formdev.flatlaf;
|
package com.formdev.flatlaf;
|
||||||
|
|
||||||
|
import javax.swing.UIManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Flat LaF that has a light color scheme and looks like IntelliJ LaF.
|
* A Flat LaF that has a light color scheme and looks like IntelliJ LaF.
|
||||||
* <p>
|
* <p>
|
||||||
@@ -29,10 +31,28 @@ public class FlatIntelliJLaf
|
|||||||
{
|
{
|
||||||
public static final String NAME = "FlatLaf IntelliJ";
|
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() {
|
public static void installLafInfo() {
|
||||||
installLafInfo( NAME, FlatIntelliJLaf.class );
|
installLafInfo( NAME, FlatIntelliJLaf.class );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,9 +32,14 @@ import java.beans.PropertyChangeListener;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.MissingResourceException;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
import java.util.ResourceBundle;
|
||||||
import java.util.ServiceLoader;
|
import java.util.ServiceLoader;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
@@ -44,6 +49,7 @@ import javax.swing.ImageIcon;
|
|||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JDialog;
|
import javax.swing.JDialog;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JMenuBar;
|
||||||
import javax.swing.LookAndFeel;
|
import javax.swing.LookAndFeel;
|
||||||
import javax.swing.PopupFactory;
|
import javax.swing.PopupFactory;
|
||||||
import javax.swing.RootPaneContainer;
|
import javax.swing.RootPaneContainer;
|
||||||
@@ -54,6 +60,7 @@ import javax.swing.UIManager;
|
|||||||
import javax.swing.UnsupportedLookAndFeelException;
|
import javax.swing.UnsupportedLookAndFeelException;
|
||||||
import javax.swing.plaf.ColorUIResource;
|
import javax.swing.plaf.ColorUIResource;
|
||||||
import javax.swing.plaf.FontUIResource;
|
import javax.swing.plaf.FontUIResource;
|
||||||
|
import javax.swing.plaf.IconUIResource;
|
||||||
import javax.swing.plaf.UIResource;
|
import javax.swing.plaf.UIResource;
|
||||||
import javax.swing.plaf.basic.BasicLookAndFeel;
|
import javax.swing.plaf.basic.BasicLookAndFeel;
|
||||||
import javax.swing.text.StyleContext;
|
import javax.swing.text.StyleContext;
|
||||||
@@ -61,9 +68,11 @@ import javax.swing.text.html.HTMLEditorKit;
|
|||||||
import com.formdev.flatlaf.ui.FlatNativeWindowBorder;
|
import com.formdev.flatlaf.ui.FlatNativeWindowBorder;
|
||||||
import com.formdev.flatlaf.ui.FlatPopupFactory;
|
import com.formdev.flatlaf.ui.FlatPopupFactory;
|
||||||
import com.formdev.flatlaf.ui.FlatRootPaneUI;
|
import com.formdev.flatlaf.ui.FlatRootPaneUI;
|
||||||
|
import com.formdev.flatlaf.ui.FlatUIUtils;
|
||||||
import com.formdev.flatlaf.util.GrayFilter;
|
import com.formdev.flatlaf.util.GrayFilter;
|
||||||
import com.formdev.flatlaf.util.LoggingFacade;
|
import com.formdev.flatlaf.util.LoggingFacade;
|
||||||
import com.formdev.flatlaf.util.MultiResolutionImageSupport;
|
import com.formdev.flatlaf.util.MultiResolutionImageSupport;
|
||||||
|
import com.formdev.flatlaf.util.StringUtils;
|
||||||
import com.formdev.flatlaf.util.SystemInfo;
|
import com.formdev.flatlaf.util.SystemInfo;
|
||||||
import com.formdev.flatlaf.util.UIScale;
|
import com.formdev.flatlaf.util.UIScale;
|
||||||
|
|
||||||
@@ -90,21 +99,30 @@ public abstract class FlatLaf
|
|||||||
private MnemonicHandler mnemonicHandler;
|
private MnemonicHandler mnemonicHandler;
|
||||||
|
|
||||||
private Consumer<UIDefaults> postInitialization;
|
private Consumer<UIDefaults> postInitialization;
|
||||||
|
private List<Function<Object, Object>> uiDefaultsGetters;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the application look and feel to the given LaF
|
* Sets the application look and feel to the given LaF
|
||||||
* using {@link UIManager#setLookAndFeel(javax.swing.LookAndFeel)}.
|
* using {@link UIManager#setLookAndFeel(javax.swing.LookAndFeel)}.
|
||||||
*/
|
*/
|
||||||
public static boolean install( LookAndFeel newLookAndFeel ) {
|
public static boolean setup( LookAndFeel newLookAndFeel ) {
|
||||||
try {
|
try {
|
||||||
UIManager.setLookAndFeel( newLookAndFeel );
|
UIManager.setLookAndFeel( newLookAndFeel );
|
||||||
return true;
|
return true;
|
||||||
} catch( Exception ex ) {
|
} catch( Exception ex ) {
|
||||||
LoggingFacade.INSTANCE.logSevere( "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;
|
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.
|
* Adds the given look and feel to the set of available look and feels.
|
||||||
* <p>
|
* <p>
|
||||||
@@ -181,8 +199,10 @@ public abstract class FlatLaf
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Icon getDisabledIcon( JComponent component, Icon icon ) {
|
public Icon getDisabledIcon( JComponent component, Icon icon ) {
|
||||||
if( icon instanceof DisabledIconProvider )
|
if( icon instanceof DisabledIconProvider ) {
|
||||||
return ((DisabledIconProvider)icon).getDisabledIcon();
|
Icon disabledIcon = ((DisabledIconProvider)icon).getDisabledIcon();
|
||||||
|
return !(disabledIcon instanceof UIResource) ? new IconUIResource( disabledIcon ) : disabledIcon;
|
||||||
|
}
|
||||||
|
|
||||||
if( icon instanceof ImageIcon ) {
|
if( icon instanceof ImageIcon ) {
|
||||||
Object grayFilter = UIManager.get( "Component.grayFilter" );
|
Object grayFilter = UIManager.get( "Component.grayFilter" );
|
||||||
@@ -245,6 +265,12 @@ public abstract class FlatLaf
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
Toolkit toolkit = Toolkit.getDefaultToolkit();
|
Toolkit toolkit = Toolkit.getDefaultToolkit();
|
||||||
|
|
||||||
|
// make sure that AWT desktop properties are initialized (on Linux)
|
||||||
|
// before invoking toolkit.addPropertyChangeListener()
|
||||||
|
// https://github.com/JFormDesigner/FlatLaf/issues/405#issuecomment-960242342
|
||||||
|
toolkit.getDesktopProperty( "dummy" );
|
||||||
|
|
||||||
toolkit.addPropertyChangeListener( desktopPropertyName, desktopPropertyListener );
|
toolkit.addPropertyChangeListener( desktopPropertyName, desktopPropertyListener );
|
||||||
if( desktopPropertyName2 != null )
|
if( desktopPropertyName2 != null )
|
||||||
toolkit.addPropertyChangeListener( desktopPropertyName2, desktopPropertyListener );
|
toolkit.addPropertyChangeListener( desktopPropertyName2, desktopPropertyListener );
|
||||||
@@ -318,7 +344,7 @@ public abstract class FlatLaf
|
|||||||
Method m = UIManager.class.getMethod( "createLookAndFeel", String.class );
|
Method m = UIManager.class.getMethod( "createLookAndFeel", String.class );
|
||||||
aquaLaf = (BasicLookAndFeel) m.invoke( null, "Mac OS X" );
|
aquaLaf = (BasicLookAndFeel) m.invoke( null, "Mac OS X" );
|
||||||
} else
|
} else
|
||||||
aquaLaf = (BasicLookAndFeel) Class.forName( aquaLafClassName ).newInstance();
|
aquaLaf = (BasicLookAndFeel) Class.forName( aquaLafClassName ).getDeclaredConstructor().newInstance();
|
||||||
} catch( Exception ex ) {
|
} catch( Exception ex ) {
|
||||||
LoggingFacade.INSTANCE.logSevere( "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();
|
throw new IllegalStateException();
|
||||||
@@ -338,14 +364,21 @@ public abstract class FlatLaf
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UIDefaults getDefaults() {
|
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
|
// add flag that indicates whether the LaF is light or dark
|
||||||
// (can be queried without using FlatLaf API)
|
// (can be queried without using FlatLaf API)
|
||||||
defaults.put( "laf.dark", isDark() );
|
defaults.put( "laf.dark", isDark() );
|
||||||
|
|
||||||
// add resource bundle for localized texts
|
// init resource bundle for localized texts
|
||||||
defaults.addResourceBundle( "com.formdev.flatlaf.resources.Bundle" );
|
initResourceBundle( defaults, "com.formdev.flatlaf.resources.Bundle" );
|
||||||
|
|
||||||
// initialize some defaults (for overriding) that are used in UI delegates,
|
// initialize some defaults (for overriding) that are used in UI delegates,
|
||||||
// but are not set in BasicLookAndFeel
|
// but are not set in BasicLookAndFeel
|
||||||
@@ -441,6 +474,45 @@ public abstract class FlatLaf
|
|||||||
return null;
|
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 ) {
|
private void initFonts( UIDefaults defaults ) {
|
||||||
FontUIResource uiFont = null;
|
FontUIResource uiFont = null;
|
||||||
|
|
||||||
@@ -553,6 +625,8 @@ public abstract class FlatLaf
|
|||||||
defaults.put( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON );
|
defaults.put( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON );
|
||||||
} else if( SystemInfo.isJava_9_orLater ) {
|
} else if( SystemInfo.isJava_9_orLater ) {
|
||||||
Object desktopHints = Toolkit.getDefaultToolkit().getDesktopProperty( DESKTOPFONTHINTS );
|
Object desktopHints = Toolkit.getDefaultToolkit().getDesktopProperty( DESKTOPFONTHINTS );
|
||||||
|
if( desktopHints == null )
|
||||||
|
desktopHints = fallbackAATextInfo();
|
||||||
if( desktopHints instanceof Map ) {
|
if( desktopHints instanceof Map ) {
|
||||||
@SuppressWarnings( "unchecked" )
|
@SuppressWarnings( "unchecked" )
|
||||||
Map<Object, Object> hints = (Map<Object, Object>) desktopHints;
|
Map<Object, Object> hints = (Map<Object, Object>) desktopHints;
|
||||||
@@ -575,6 +649,8 @@ public abstract class FlatLaf
|
|||||||
Object value = Class.forName( "sun.swing.SwingUtilities2$AATextInfo" )
|
Object value = Class.forName( "sun.swing.SwingUtilities2$AATextInfo" )
|
||||||
.getMethod( "getAATextInfo", boolean.class )
|
.getMethod( "getAATextInfo", boolean.class )
|
||||||
.invoke( null, true );
|
.invoke( null, true );
|
||||||
|
if( value == null )
|
||||||
|
value = fallbackAATextInfo();
|
||||||
defaults.put( key, value );
|
defaults.put( key, value );
|
||||||
} catch( Exception ex ) {
|
} catch( Exception ex ) {
|
||||||
LoggingFacade.INSTANCE.logSevere( null, ex );
|
LoggingFacade.INSTANCE.logSevere( null, ex );
|
||||||
@@ -583,6 +659,47 @@ public abstract class FlatLaf
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void putDefaults( UIDefaults defaults, Object value, String... keys ) {
|
private void putDefaults( UIDefaults defaults, Object value, String... keys ) {
|
||||||
for( String key : keys )
|
for( String key : keys )
|
||||||
defaults.put( key, value );
|
defaults.put( key, value );
|
||||||
@@ -762,12 +879,23 @@ public abstract class FlatLaf
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Revalidate and repaint all displayable frames and dialogs.
|
* Revalidate and repaint all displayable frames and dialogs.
|
||||||
|
* <p>
|
||||||
|
* Useful to update UI after changing {@code TitlePane.menuBarEmbedded}.
|
||||||
*
|
*
|
||||||
* @since 1.1.2
|
* @since 1.1.2
|
||||||
*/
|
*/
|
||||||
public static void revalidateAndRepaintAllFramesAndDialogs() {
|
public static void revalidateAndRepaintAllFramesAndDialogs() {
|
||||||
for( Window w : Window.getWindows() ) {
|
for( Window w : Window.getWindows() ) {
|
||||||
if( isDisplayableFrameOrDialog( w ) ) {
|
if( isDisplayableFrameOrDialog( w ) ) {
|
||||||
|
// revalidate menu bar
|
||||||
|
JMenuBar menuBar = (w instanceof JFrame)
|
||||||
|
? ((JFrame)w).getJMenuBar()
|
||||||
|
: (w instanceof JDialog
|
||||||
|
? ((JDialog)w).getJMenuBar()
|
||||||
|
: null);
|
||||||
|
if( menuBar != null )
|
||||||
|
menuBar.revalidate();
|
||||||
|
|
||||||
w.revalidate();
|
w.revalidate();
|
||||||
w.repaint();
|
w.repaint();
|
||||||
}
|
}
|
||||||
@@ -776,6 +904,9 @@ public abstract class FlatLaf
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Repaint all displayable frames and dialogs.
|
* Repaint all displayable frames and dialogs.
|
||||||
|
* <p>
|
||||||
|
* Useful to update UI after changing {@code TitlePane.unifiedBackground},
|
||||||
|
* {@code MenuItem.selectionType} or {@code Component.hideMnemonics}.
|
||||||
*
|
*
|
||||||
* @since 1.1.2
|
* @since 1.1.2
|
||||||
*/
|
*/
|
||||||
@@ -814,6 +945,139 @@ public abstract class FlatLaf
|
|||||||
return super.hashCode();
|
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 ---------------------------------------------------
|
//---- class ActiveFont ---------------------------------------------------
|
||||||
|
|
||||||
private static class ActiveFont
|
private static class ActiveFont
|
||||||
|
|||||||
@@ -34,8 +34,16 @@ public class FlatLightLaf
|
|||||||
* Sets the application look and feel to this LaF
|
* Sets the application look and feel to this LaF
|
||||||
* using {@link UIManager#setLookAndFeel(javax.swing.LookAndFeel)}.
|
* 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() {
|
public static boolean install() {
|
||||||
return install( new FlatLightLaf() );
|
return setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ public interface FlatSystemProperties
|
|||||||
* (requires Window 10)
|
* (requires Window 10)
|
||||||
* <p>
|
* <p>
|
||||||
* <strong>Allowed Values</strong> {@code false} and {@code true}<br>
|
* <strong>Allowed Values</strong> {@code false} and {@code true}<br>
|
||||||
* <strong>Default</strong> true
|
* <strong>Default</strong> {@code true}
|
||||||
*/
|
*/
|
||||||
String USE_JETBRAINS_CUSTOM_DECORATIONS = "flatlaf.useJetBrainsCustomDecorations";
|
String USE_JETBRAINS_CUSTOM_DECORATIONS = "flatlaf.useJetBrainsCustomDecorations";
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ import javax.swing.UIDefaults;
|
|||||||
import javax.swing.plaf.ColorUIResource;
|
import javax.swing.plaf.ColorUIResource;
|
||||||
import com.formdev.flatlaf.json.Json;
|
import com.formdev.flatlaf.json.Json;
|
||||||
import com.formdev.flatlaf.json.ParseException;
|
import com.formdev.flatlaf.json.ParseException;
|
||||||
|
import com.formdev.flatlaf.util.ColorFunctions;
|
||||||
import com.formdev.flatlaf.util.LoggingFacade;
|
import com.formdev.flatlaf.util.LoggingFacade;
|
||||||
import com.formdev.flatlaf.util.StringUtils;
|
import com.formdev.flatlaf.util.StringUtils;
|
||||||
|
|
||||||
@@ -67,20 +68,28 @@ public class IntelliJTheme
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads a IntelliJ .theme.json file from the given input stream,
|
* 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.
|
* The input stream is automatically closed.
|
||||||
* Using a buffered input stream is not necessary.
|
* Using a buffered input stream is not necessary.
|
||||||
*/
|
*/
|
||||||
public static boolean install( InputStream in ) {
|
public static boolean setup( InputStream in ) {
|
||||||
try {
|
try {
|
||||||
return FlatLaf.install( createLaf( in ) );
|
return FlatLaf.setup( createLaf( in ) );
|
||||||
} catch( Exception ex ) {
|
} catch( Exception ex ) {
|
||||||
LoggingFacade.INSTANCE.logSevere( "FlatLaf: Failed to load IntelliJ theme", ex );
|
LoggingFacade.INSTANCE.logSevere( "FlatLaf: Failed to load IntelliJ theme", ex );
|
||||||
return false;
|
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
|
* Loads a IntelliJ .theme.json file from the given input stream and
|
||||||
* creates a Laf instance for it.
|
* creates a Laf instance for it.
|
||||||
@@ -215,6 +224,12 @@ public class IntelliJTheme
|
|||||||
if( !uiKeys.contains( "ToggleButton.foreground" ) && uiKeys.contains( "Button.foreground" ) )
|
if( !uiKeys.contains( "ToggleButton.foreground" ) && uiKeys.contains( "Button.foreground" ) )
|
||||||
defaults.put( "ToggleButton.foreground", defaults.get( "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
|
// fix List and Table background colors in Material UI Lite themes
|
||||||
if( isMaterialUILite ) {
|
if( isMaterialUILite ) {
|
||||||
defaults.put( "List.background", defaults.get( "Tree.background" ) );
|
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
|
// remove theme specific UI defaults and remember only those for current theme
|
||||||
Map<Object, Object> themeSpecificDefaults = new HashMap<>();
|
Map<Object, Object> themeSpecificDefaults = new HashMap<>();
|
||||||
String currentThemePrefix = '[' + name.replace( ' ', '_' ) + ']';
|
String currentThemePrefix = '[' + name.replace( ' ', '_' ) + ']';
|
||||||
|
String currentThemeAndAuthorPrefix = '[' + name.replace( ' ', '_' ) + "---" + author.replace( ' ', '_' ) + ']';
|
||||||
String currentAuthorPrefix = "[author-" + author.replace( ' ', '_' ) + ']';
|
String currentAuthorPrefix = "[author-" + author.replace( ' ', '_' ) + ']';
|
||||||
String allThemesPrefix = "[*]";
|
String allThemesPrefix = "[*]";
|
||||||
String[] prefixes = { currentThemePrefix, currentAuthorPrefix, allThemesPrefix };
|
String[] prefixes = { currentThemePrefix, currentThemeAndAuthorPrefix, currentAuthorPrefix, allThemesPrefix };
|
||||||
for( String key : themeSpecificKeys ) {
|
for( String key : themeSpecificKeys ) {
|
||||||
Object value = defaults.remove( key );
|
Object value = defaults.remove( key );
|
||||||
for( String prefix : prefixes ) {
|
for( String prefix : prefixes ) {
|
||||||
@@ -344,6 +360,10 @@ public class IntelliJTheme
|
|||||||
|
|
||||||
// replace all values in UI defaults that match the wildcard key
|
// replace all values in UI defaults that match the wildcard key
|
||||||
for( Object k : defaultsKeysCache ) {
|
for( Object k : defaultsKeysCache ) {
|
||||||
|
if( k.equals( "Desktop.background" ) ||
|
||||||
|
k.equals( "DesktopIcon.background" ) )
|
||||||
|
continue;
|
||||||
|
|
||||||
if( k instanceof String ) {
|
if( k instanceof String ) {
|
||||||
// support replacing of mapped keys
|
// support replacing of mapped keys
|
||||||
// (e.g. set ComboBox.buttonEditableBackground to *.background
|
// (e.g. set ComboBox.buttonEditableBackground to *.background
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package com.formdev.flatlaf;
|
package com.formdev.flatlaf;
|
||||||
|
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
|
import java.awt.FontMetrics;
|
||||||
import java.awt.GraphicsConfiguration;
|
import java.awt.GraphicsConfiguration;
|
||||||
import java.awt.GraphicsEnvironment;
|
import java.awt.GraphicsEnvironment;
|
||||||
import java.awt.Toolkit;
|
import java.awt.Toolkit;
|
||||||
@@ -28,7 +29,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
import javax.swing.text.StyleContext;
|
||||||
import com.formdev.flatlaf.util.LoggingFacade;
|
import com.formdev.flatlaf.util.LoggingFacade;
|
||||||
import com.formdev.flatlaf.util.StringUtils;
|
import com.formdev.flatlaf.util.StringUtils;
|
||||||
import com.formdev.flatlaf.util.SystemInfo;
|
import com.formdev.flatlaf.util.SystemInfo;
|
||||||
@@ -55,25 +56,39 @@ class LinuxFontPolicy
|
|||||||
|
|
||||||
String family = "";
|
String family = "";
|
||||||
int style = Font.PLAIN;
|
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 );
|
StringTokenizer st = new StringTokenizer( (String) fontName );
|
||||||
while( st.hasMoreTokens() ) {
|
while( st.hasMoreTokens() ) {
|
||||||
String word = st.nextToken();
|
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;
|
style |= Font.ITALIC;
|
||||||
else if( word.equalsIgnoreCase( "bold" ) )
|
else if( lword.equals( "bold" ) )
|
||||||
style |= Font.BOLD;
|
style |= Font.BOLD;
|
||||||
else if( Character.isDigit( word.charAt( 0 ) ) ) {
|
else if( Character.isDigit( word.charAt( 0 ) ) ) {
|
||||||
try {
|
try {
|
||||||
size = Integer.parseInt( word );
|
dsize = Double.parseDouble( word );
|
||||||
} catch( NumberFormatException ex ) {
|
} catch( NumberFormatException ex ) {
|
||||||
// ignore
|
// 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);
|
family = family.isEmpty() ? word : (family + ' ' + word);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Ubuntu font is rendered poorly (except if running in JetBrains VM)
|
// Ubuntu font is rendered poorly (except if running in JetBrains VM)
|
||||||
// --> use Liberation Sans font
|
// --> use Liberation Sans font
|
||||||
@@ -83,8 +98,8 @@ class LinuxFontPolicy
|
|||||||
family = "Liberation Sans";
|
family = "Liberation Sans";
|
||||||
|
|
||||||
// scale font size
|
// scale font size
|
||||||
double dsize = size * getGnomeFontScale();
|
dsize *= getGnomeFontScale();
|
||||||
size = (int) (dsize + 0.5);
|
int size = (int) (dsize + 0.5);
|
||||||
if( size < 1 )
|
if( size < 1 )
|
||||||
size = 1;
|
size = 1;
|
||||||
|
|
||||||
@@ -93,7 +108,48 @@ class LinuxFontPolicy
|
|||||||
if( logicalFamily != null )
|
if( logicalFamily != null )
|
||||||
family = logicalFamily;
|
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( Font.DIALOG.equals( family ) )
|
||||||
|
return font;
|
||||||
|
|
||||||
|
// if the font family does not match any font on the system, "Dialog" family is returned
|
||||||
|
if( !Font.DIALOG.equals( font.getFamily() ) ) {
|
||||||
|
// check for font problems
|
||||||
|
// - font height much larger than expected (e.g. font Inter; Oracle Java 8)
|
||||||
|
// - character width is zero (e.g. font Cantarell; Fedora; Oracle Java 8)
|
||||||
|
FontMetrics fm = StyleContext.getDefaultStyleContext().getFontMetrics( font );
|
||||||
|
if( fm.getHeight() > size * 2 || fm.stringWidth( "a" ) == 0 )
|
||||||
|
return createFont( Font.DIALOG, style, size, dsize );
|
||||||
|
|
||||||
|
return font;
|
||||||
|
}
|
||||||
|
|
||||||
|
// find last word in family
|
||||||
|
int index = family.lastIndexOf( ' ' );
|
||||||
|
if( index < 0 )
|
||||||
|
return createFont( Font.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 ) {
|
private static Font createFont( String family, int style, int size, double dsize ) {
|
||||||
@@ -265,6 +321,9 @@ class LinuxFontPolicy
|
|||||||
* - running on JetBrains Runtime 11 or later and scaling is enabled in system Settings
|
* - running on JetBrains Runtime 11 or later and scaling is enabled in system Settings
|
||||||
*/
|
*/
|
||||||
private static boolean isSystemScaling() {
|
private static boolean isSystemScaling() {
|
||||||
|
if( GraphicsEnvironment.isHeadless() )
|
||||||
|
return true;
|
||||||
|
|
||||||
GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment()
|
GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment()
|
||||||
.getDefaultScreenDevice().getDefaultConfiguration();
|
.getDefaultScreenDevice().getDefaultConfiguration();
|
||||||
return UIScale.getSystemScaleFactor( gc ) > 1;
|
return UIScale.getSystemScaleFactor( gc ) > 1;
|
||||||
|
|||||||
@@ -442,8 +442,8 @@ class UIDefaultsLoader
|
|||||||
private static Object parseInstance( String value, List<ClassLoader> addonClassLoaders ) {
|
private static Object parseInstance( String value, List<ClassLoader> addonClassLoaders ) {
|
||||||
return (LazyValue) t -> {
|
return (LazyValue) t -> {
|
||||||
try {
|
try {
|
||||||
return findClass( value, addonClassLoaders ).newInstance();
|
return findClass( value, addonClassLoaders ).getDeclaredConstructor().newInstance();
|
||||||
} catch( InstantiationException | IllegalAccessException | ClassNotFoundException ex ) {
|
} catch( Exception ex ) {
|
||||||
LoggingFacade.INSTANCE.logSevere( "FlatLaf: Failed to instantiate '" + value + "'.", ex );
|
LoggingFacade.INSTANCE.logSevere( "FlatLaf: Failed to instantiate '" + value + "'.", ex );
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -604,6 +604,13 @@ class UIDefaultsLoader
|
|||||||
case "fadeout": return parseColorHSLIncreaseDecrease( 3, false, params, resolver, reportError );
|
case "fadeout": return parseColorHSLIncreaseDecrease( 3, false, params, resolver, reportError );
|
||||||
case "fade": return parseColorFade( params, resolver, reportError );
|
case "fade": return parseColorFade( params, resolver, reportError );
|
||||||
case "spin": return parseColorSpin( 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 {
|
} finally {
|
||||||
parseColorDepth--;
|
parseColorDepth--;
|
||||||
@@ -753,6 +760,68 @@ class UIDefaultsLoader
|
|||||||
return parseFunctionBaseColor( colorStr, function, derived, resolver, reportError );
|
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,
|
private static Object parseFunctionBaseColor( String colorStr, ColorFunction function,
|
||||||
boolean derived, Function<String, String> resolver, boolean reportError )
|
boolean derived, Function<String, String> resolver, boolean reportError )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ public class FlatCapsLockIcon
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
|
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
|
||||||
<g fill="none" fill-rule="evenodd">
|
<g fill="none" fill-rule="evenodd">
|
||||||
<rect width="16" height="16" fill="#6E6E6E" rx="3"/>
|
<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"/>
|
<path fill="#FFF" d="M2,8 L8,2 L14,8 L11,8 L11,10 L5,10 L5,8 L2,8 Z"/>
|
||||||
</g>
|
</g>
|
||||||
</svg>
|
</svg>
|
||||||
@@ -52,7 +52,7 @@ public class FlatCapsLockIcon
|
|||||||
|
|
||||||
Path2D path = new Path2D.Float( Path2D.WIND_EVEN_ODD );
|
Path2D path = new Path2D.Float( Path2D.WIND_EVEN_ODD );
|
||||||
path.append( new RoundRectangle2D.Float( 0, 0, 16, 16, 6, 6 ), false );
|
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 );
|
path.append( FlatUIUtils.createPath( 2,8, 8,2, 14,8, 11,8, 11,10, 5,10, 5,8 ), false );
|
||||||
g.fill( path );
|
g.fill( path );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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 );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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 ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -48,8 +48,8 @@ public class FlatArrowButton
|
|||||||
protected final Color pressedBackground;
|
protected final Color pressedBackground;
|
||||||
|
|
||||||
private int arrowWidth = DEFAULT_ARROW_WIDTH;
|
private int arrowWidth = DEFAULT_ARROW_WIDTH;
|
||||||
private int xOffset = 0;
|
private float xOffset = 0;
|
||||||
private int yOffset = 0;
|
private float yOffset = 0;
|
||||||
|
|
||||||
private boolean hover;
|
private boolean hover;
|
||||||
private boolean pressed;
|
private boolean pressed;
|
||||||
@@ -117,19 +117,19 @@ public class FlatArrowButton
|
|||||||
return pressed;
|
return pressed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getXOffset() {
|
public float getXOffset() {
|
||||||
return xOffset;
|
return xOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setXOffset( int xOffset ) {
|
public void setXOffset( float xOffset ) {
|
||||||
this.xOffset = xOffset;
|
this.xOffset = xOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getYOffset() {
|
public float getYOffset() {
|
||||||
return yOffset;
|
return yOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setYOffset( int yOffset ) {
|
public void setYOffset( float yOffset ) {
|
||||||
this.yOffset = yOffset;
|
this.yOffset = yOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,6 +141,21 @@ public class FlatArrowButton
|
|||||||
return FlatUIUtils.deriveColor( foreground, this.foreground );
|
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
|
@Override
|
||||||
public Dimension getPreferredSize() {
|
public Dimension getPreferredSize() {
|
||||||
return scale( super.getPreferredSize() );
|
return scale( super.getPreferredSize() );
|
||||||
@@ -170,13 +185,7 @@ public class FlatArrowButton
|
|||||||
}
|
}
|
||||||
|
|
||||||
// paint arrow
|
// paint arrow
|
||||||
g.setColor( deriveForeground( isEnabled()
|
g.setColor( deriveForeground( getArrowColor() ) );
|
||||||
? (pressedForeground != null && isPressed()
|
|
||||||
? pressedForeground
|
|
||||||
: (hoverForeground != null && isHover()
|
|
||||||
? hoverForeground
|
|
||||||
: foreground))
|
|
||||||
: disabledForeground ) );
|
|
||||||
paintArrow( (Graphics2D) g );
|
paintArrow( (Graphics2D) g );
|
||||||
|
|
||||||
FlatUIUtils.resetRenderingHints( g, oldRenderingHints );
|
FlatUIUtils.resetRenderingHints( g, oldRenderingHints );
|
||||||
|
|||||||
@@ -22,17 +22,12 @@ import java.awt.Component;
|
|||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
import java.awt.KeyboardFocusManager;
|
|
||||||
import java.awt.Paint;
|
import java.awt.Paint;
|
||||||
import javax.swing.JComboBox;
|
import javax.swing.JComboBox;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JScrollPane;
|
import javax.swing.JScrollPane;
|
||||||
import javax.swing.JSpinner;
|
import javax.swing.JSpinner;
|
||||||
import javax.swing.JTable;
|
|
||||||
import javax.swing.JTextField;
|
|
||||||
import javax.swing.JTree;
|
|
||||||
import javax.swing.JViewport;
|
import javax.swing.JViewport;
|
||||||
import javax.swing.SwingUtilities;
|
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.plaf.basic.BasicBorders;
|
import javax.swing.plaf.basic.BasicBorders;
|
||||||
import com.formdev.flatlaf.FlatClientProperties;
|
import com.formdev.flatlaf.FlatClientProperties;
|
||||||
@@ -50,6 +45,7 @@ import com.formdev.flatlaf.util.DerivedColor;
|
|||||||
*
|
*
|
||||||
* @uiDefault Component.focusWidth int
|
* @uiDefault Component.focusWidth int
|
||||||
* @uiDefault Component.innerFocusWidth int or float
|
* @uiDefault Component.innerFocusWidth int or float
|
||||||
|
* @uiDefault Component.innerOutlineWidth int or float
|
||||||
* @uiDefault Component.focusColor Color
|
* @uiDefault Component.focusColor Color
|
||||||
* @uiDefault Component.borderColor Color
|
* @uiDefault Component.borderColor Color
|
||||||
* @uiDefault Component.disabledBorderColor Color
|
* @uiDefault Component.disabledBorderColor Color
|
||||||
@@ -164,37 +160,13 @@ public class FlatBorder
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isFocused( Component c ) {
|
protected boolean isFocused( Component c ) {
|
||||||
if( c instanceof JScrollPane ) {
|
if( c instanceof JScrollPane )
|
||||||
JViewport viewport = ((JScrollPane)c).getViewport();
|
return FlatScrollPaneUI.isPermanentFocusOwner( (JScrollPane) c );
|
||||||
Component view = (viewport != null) ? viewport.getView() : null;
|
else if( c instanceof JComboBox )
|
||||||
if( view != null ) {
|
return FlatComboBoxUI.isPermanentFocusOwner( (JComboBox<?>) c );
|
||||||
if( FlatUIUtils.isPermanentFocusOwner( view ) )
|
else if( c instanceof JSpinner )
|
||||||
return true;
|
return FlatSpinnerUI.isPermanentFocusOwner( (JSpinner) c );
|
||||||
|
else
|
||||||
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
|
|
||||||
return FlatUIUtils.isPermanentFocusOwner( c );
|
return FlatUIUtils.isPermanentFocusOwner( c );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,13 +177,14 @@ public class FlatBorder
|
|||||||
@Override
|
@Override
|
||||||
public Insets getBorderInsets( Component c, Insets insets ) {
|
public Insets getBorderInsets( Component c, Insets insets ) {
|
||||||
float focusWidth = scale( (float) getFocusWidth( c ) );
|
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 = super.getBorderInsets( c, insets );
|
||||||
insets.top = Math.round( scale( (float) insets.top ) + ow );
|
|
||||||
insets.left = Math.round( scale( (float) insets.left ) + ow );
|
insets.top = scale( insets.top ) + ow;
|
||||||
insets.bottom = Math.round( scale( (float) insets.bottom ) + ow );
|
insets.left = scale( insets.left ) + ow;
|
||||||
insets.right = Math.round( scale( (float) insets.right ) + ow );
|
insets.bottom = scale( insets.bottom ) + ow;
|
||||||
|
insets.right = scale( insets.right ) + ow;
|
||||||
|
|
||||||
if( isCellEditor( c ) ) {
|
if( isCellEditor( c ) ) {
|
||||||
// remove top and bottom insets if used as cell editor
|
// remove top and bottom insets if used as cell editor
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import java.awt.Color;
|
|||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.GradientPaint;
|
import java.awt.GradientPaint;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
import java.awt.Paint;
|
import java.awt.Paint;
|
||||||
import javax.swing.AbstractButton;
|
import javax.swing.AbstractButton;
|
||||||
@@ -42,11 +43,13 @@ import com.formdev.flatlaf.util.UIScale;
|
|||||||
* @uiDefault Button.default.hoverBorderColor Color optional
|
* @uiDefault Button.default.hoverBorderColor Color optional
|
||||||
* @uiDefault Button.default.focusedBorderColor Color
|
* @uiDefault Button.default.focusedBorderColor Color
|
||||||
* @uiDefault Button.default.focusColor Color
|
* @uiDefault Button.default.focusColor Color
|
||||||
|
* @uiDefault Button.toolbar.focusColor Color optional; defaults to Component.focusColor
|
||||||
* @uiDefault Button.borderWidth int
|
* @uiDefault Button.borderWidth int
|
||||||
* @uiDefault Button.default.borderWidth int
|
* @uiDefault Button.default.borderWidth int
|
||||||
* @uiDefault Button.innerFocusWidth int or float optional; defaults to Component.innerFocusWidth
|
* @uiDefault Button.innerFocusWidth int or float optional; defaults to Component.innerFocusWidth
|
||||||
* @uiDefault Button.toolbar.margin Insets
|
* @uiDefault Button.toolbar.margin Insets
|
||||||
* @uiDefault Button.toolbar.spacingInsets Insets
|
* @uiDefault Button.toolbar.spacingInsets Insets
|
||||||
|
* @uiDefault Button.toolbar.focusWidth int or float optional; default is 1
|
||||||
* @uiDefault Button.arc int
|
* @uiDefault Button.arc int
|
||||||
*
|
*
|
||||||
* @author Karl Tauber
|
* @author Karl Tauber
|
||||||
@@ -64,25 +67,60 @@ public class FlatButtonBorder
|
|||||||
protected final Color defaultHoverBorderColor = UIManager.getColor( "Button.default.hoverBorderColor" );
|
protected final Color defaultHoverBorderColor = UIManager.getColor( "Button.default.hoverBorderColor" );
|
||||||
protected final Color defaultFocusedBorderColor = UIManager.getColor( "Button.default.focusedBorderColor" );
|
protected final Color defaultFocusedBorderColor = UIManager.getColor( "Button.default.focusedBorderColor" );
|
||||||
protected final Color defaultFocusColor = UIManager.getColor( "Button.default.focusColor" );
|
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 borderWidth = UIManager.getInt( "Button.borderWidth" );
|
||||||
protected final int defaultBorderWidth = UIManager.getInt( "Button.default.borderWidth" );
|
protected final int defaultBorderWidth = UIManager.getInt( "Button.default.borderWidth" );
|
||||||
protected final float buttonInnerFocusWidth = FlatUIUtils.getUIFloat( "Button.innerFocusWidth", innerFocusWidth );
|
protected final float buttonInnerFocusWidth = FlatUIUtils.getUIFloat( "Button.innerFocusWidth", innerFocusWidth );
|
||||||
protected final Insets toolbarMargin = UIManager.getInsets( "Button.toolbar.margin" );
|
protected final Insets toolbarMargin = UIManager.getInsets( "Button.toolbar.margin" );
|
||||||
protected final Insets toolbarSpacingInsets = UIManager.getInsets( "Button.toolbar.spacingInsets" );
|
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" );
|
protected final int arc = UIManager.getInt( "Button.arc" );
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void paintBorder( Component c, Graphics g, int x, int y, int width, int height ) {
|
public void paintBorder( Component c, Graphics g, int x, int y, int width, int height ) {
|
||||||
if( FlatButtonUI.isContentAreaFilled( c ) &&
|
if( FlatButtonUI.isContentAreaFilled( c ) &&
|
||||||
!FlatButtonUI.isToolBarButton( c ) &&
|
!FlatButtonUI.isToolBarButton( c ) &&
|
||||||
|
(!FlatButtonUI.isBorderlessButton( c ) || FlatUIUtils.isPermanentFocusOwner( c )) &&
|
||||||
!FlatButtonUI.isHelpButton( c ) &&
|
!FlatButtonUI.isHelpButton( c ) &&
|
||||||
!FlatToggleButtonUI.isTabButton( c ) )
|
!FlatToggleButtonUI.isTabButton( c ) )
|
||||||
super.paintBorder( c, g, x, y, width, height );
|
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
|
@Override
|
||||||
protected Color getFocusColor( Component c ) {
|
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
|
@Override
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import java.awt.Insets;
|
|||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.awt.geom.RoundRectangle2D;
|
import java.awt.geom.RoundRectangle2D;
|
||||||
import java.beans.PropertyChangeEvent;
|
import java.beans.PropertyChangeEvent;
|
||||||
|
import java.util.Objects;
|
||||||
import javax.swing.AbstractButton;
|
import javax.swing.AbstractButton;
|
||||||
import javax.swing.ButtonModel;
|
import javax.swing.ButtonModel;
|
||||||
import javax.swing.Icon;
|
import javax.swing.Icon;
|
||||||
@@ -129,6 +130,7 @@ public class FlatButtonUI
|
|||||||
protected Color toolbarSelectedBackground;
|
protected Color toolbarSelectedBackground;
|
||||||
|
|
||||||
private Icon helpButtonIcon;
|
private Icon helpButtonIcon;
|
||||||
|
private Insets defaultMargin;
|
||||||
|
|
||||||
private boolean defaults_initialized = false;
|
private boolean defaults_initialized = false;
|
||||||
|
|
||||||
@@ -184,6 +186,7 @@ public class FlatButtonUI
|
|||||||
toolbarSelectedBackground = UIManager.getColor( prefix + "toolbar.selectedBackground" );
|
toolbarSelectedBackground = UIManager.getColor( prefix + "toolbar.selectedBackground" );
|
||||||
|
|
||||||
helpButtonIcon = UIManager.getIcon( "HelpButton.icon" );
|
helpButtonIcon = UIManager.getIcon( "HelpButton.icon" );
|
||||||
|
defaultMargin = UIManager.getInsets( prefix + "margin" );
|
||||||
|
|
||||||
defaults_initialized = true;
|
defaults_initialized = true;
|
||||||
}
|
}
|
||||||
@@ -285,6 +288,10 @@ public class FlatButtonUI
|
|||||||
(c instanceof AbstractButton && clientPropertyEquals( (AbstractButton) c, BUTTON_TYPE, BUTTON_TYPE_TOOLBAR_BUTTON ));
|
(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
|
@Override
|
||||||
public void update( Graphics g, JComponent c ) {
|
public void update( Graphics g, JComponent c ) {
|
||||||
// fill background if opaque to avoid garbage if user sets opaque to true
|
// fill background if opaque to avoid garbage if user sets opaque to true
|
||||||
@@ -332,8 +339,9 @@ public class FlatButtonUI
|
|||||||
|
|
||||||
// paint shadow
|
// paint shadow
|
||||||
Color shadowColor = def ? defaultShadowColor : this.shadowColor;
|
Color shadowColor = def ? defaultShadowColor : this.shadowColor;
|
||||||
if( !isToolBarButton && shadowColor != null && shadowWidth > 0 && focusWidth > 0 &&
|
if( shadowColor != null && shadowWidth > 0 && focusWidth > 0 && c.isEnabled() &&
|
||||||
!(isFocusPainted( c ) && FlatUIUtils.isPermanentFocusOwner( c )) && c.isEnabled() )
|
!isToolBarButton && !isBorderlessButton( c ) &&
|
||||||
|
!(isFocusPainted( c ) && FlatUIUtils.isPermanentFocusOwner( c )) )
|
||||||
{
|
{
|
||||||
g2.setColor( shadowColor );
|
g2.setColor( shadowColor );
|
||||||
g2.fill( new RoundRectangle2D.Float( focusWidth, focusWidth + UIScale.scale( (float) shadowWidth ),
|
g2.fill( new RoundRectangle2D.Float( focusWidth, focusWidth + UIScale.scale( (float) shadowWidth ),
|
||||||
@@ -388,7 +396,7 @@ public class FlatButtonUI
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected Color getBackground( JComponent c ) {
|
protected Color getBackground( JComponent c ) {
|
||||||
boolean toolBarButton = isToolBarButton( c );
|
boolean toolBarButton = isToolBarButton( c ) || isBorderlessButton( c );
|
||||||
|
|
||||||
// selected state
|
// selected state
|
||||||
if( ((AbstractButton)c).isSelected() ) {
|
if( ((AbstractButton)c).isSelected() ) {
|
||||||
@@ -461,7 +469,7 @@ public class FlatButtonUI
|
|||||||
if( !c.isEnabled() )
|
if( !c.isEnabled() )
|
||||||
return disabledText;
|
return disabledText;
|
||||||
|
|
||||||
if( ((AbstractButton)c).isSelected() && !isToolBarButton( c ) )
|
if( ((AbstractButton)c).isSelected() && !(isToolBarButton( c ) || isBorderlessButton( c )) )
|
||||||
return selectedForeground;
|
return selectedForeground;
|
||||||
|
|
||||||
// use component foreground if explicitly set
|
// use component foreground if explicitly set
|
||||||
@@ -494,16 +502,23 @@ public class FlatButtonUI
|
|||||||
} else if( isIconOnlyOrSingleCharacter && ((AbstractButton)c).getIcon() == null ) {
|
} else if( isIconOnlyOrSingleCharacter && ((AbstractButton)c).getIcon() == null ) {
|
||||||
// make single-character-no-icon button square (increase width)
|
// make single-character-no-icon button square (increase width)
|
||||||
prefSize.width = Math.max( prefSize.width, prefSize.height );
|
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
|
// apply minimum width/height
|
||||||
float focusWidth = FlatUIUtils.getBorderFocusWidth( c );
|
int fw = Math.round( FlatUIUtils.getBorderFocusWidth( c ) * 2 );
|
||||||
prefSize.width = Math.max( prefSize.width, scale( FlatUIUtils.minimumWidth( c, minimumWidth ) ) + Math.round( focusWidth * 2 ) );
|
prefSize.width = Math.max( prefSize.width, scale( FlatUIUtils.minimumWidth( c, minimumWidth ) ) + fw );
|
||||||
prefSize.height = Math.max( prefSize.height, scale( FlatUIUtils.minimumHeight( c, 0 ) ) + Math.round( focusWidth * 2 ) );
|
prefSize.height = Math.max( prefSize.height, scale( FlatUIUtils.minimumHeight( c, 0 ) ) + fw );
|
||||||
}
|
}
|
||||||
|
|
||||||
return prefSize;
|
return prefSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean hasDefaultMargins( JComponent c ) {
|
||||||
|
Insets margin = ((AbstractButton)c).getMargin();
|
||||||
|
return margin instanceof UIResource && Objects.equals( margin, defaultMargin );
|
||||||
|
}
|
||||||
|
|
||||||
//---- class FlatButtonListener -------------------------------------------
|
//---- class FlatButtonListener -------------------------------------------
|
||||||
|
|
||||||
protected class FlatButtonListener
|
protected class FlatButtonListener
|
||||||
|
|||||||
@@ -18,10 +18,13 @@ package com.formdev.flatlaf.ui;
|
|||||||
|
|
||||||
import static com.formdev.flatlaf.FlatClientProperties.*;
|
import static com.formdev.flatlaf.FlatClientProperties.*;
|
||||||
import java.awt.EventQueue;
|
import java.awt.EventQueue;
|
||||||
|
import java.awt.Insets;
|
||||||
|
import java.awt.Rectangle;
|
||||||
import java.awt.event.FocusEvent;
|
import java.awt.event.FocusEvent;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import javax.swing.JFormattedTextField;
|
import javax.swing.JFormattedTextField;
|
||||||
import javax.swing.plaf.UIResource;
|
import javax.swing.plaf.UIResource;
|
||||||
|
import javax.swing.text.BadLocationException;
|
||||||
import javax.swing.text.DefaultCaret;
|
import javax.swing.text.DefaultCaret;
|
||||||
import javax.swing.text.Document;
|
import javax.swing.text.Document;
|
||||||
import javax.swing.text.JTextComponent;
|
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
|
@Override
|
||||||
public void focusGained( FocusEvent e ) {
|
public void focusGained( FocusEvent e ) {
|
||||||
if( !wasTemporaryLost && (!isMousePressed || selectAllOnMouseClick) )
|
if( !wasTemporaryLost && (!isMousePressed || selectAllOnMouseClick) )
|
||||||
@@ -92,7 +108,7 @@ public class FlatCaret
|
|||||||
protected void selectAllOnFocusGained() {
|
protected void selectAllOnFocusGained() {
|
||||||
JTextComponent c = getComponent();
|
JTextComponent c = getComponent();
|
||||||
Document doc = c.getDocument();
|
Document doc = c.getDocument();
|
||||||
if( doc == null || !c.isEnabled() || !c.isEditable() )
|
if( doc == null || !c.isEnabled() || !c.isEditable() || FlatUIUtils.isCellEditor( c ) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Object selectAllOnFocusPolicy = c.getClientProperty( SELECT_ALL_ON_FOCUS_POLICY );
|
Object selectAllOnFocusPolicy = c.getClientProperty( SELECT_ALL_ON_FOCUS_POLICY );
|
||||||
@@ -127,4 +143,23 @@ public class FlatCaret
|
|||||||
moveDot( doc.getLength() );
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,11 +17,13 @@
|
|||||||
package com.formdev.flatlaf.ui;
|
package com.formdev.flatlaf.ui;
|
||||||
|
|
||||||
import static com.formdev.flatlaf.util.UIScale.scale;
|
import static com.formdev.flatlaf.util.UIScale.scale;
|
||||||
|
import static com.formdev.flatlaf.util.UIScale.unscale;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.ComponentOrientation;
|
import java.awt.ComponentOrientation;
|
||||||
import java.awt.Container;
|
import java.awt.Container;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
|
import java.awt.FontMetrics;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.GraphicsConfiguration;
|
import java.awt.GraphicsConfiguration;
|
||||||
@@ -39,10 +41,9 @@ import java.awt.event.MouseEvent;
|
|||||||
import java.awt.event.MouseListener;
|
import java.awt.event.MouseListener;
|
||||||
import java.awt.geom.Rectangle2D;
|
import java.awt.geom.Rectangle2D;
|
||||||
import java.beans.PropertyChangeListener;
|
import java.beans.PropertyChangeListener;
|
||||||
import java.lang.ref.WeakReference;
|
|
||||||
import javax.swing.AbstractAction;
|
import javax.swing.AbstractAction;
|
||||||
import javax.swing.BorderFactory;
|
import javax.swing.BorderFactory;
|
||||||
import javax.swing.ComboBoxEditor;
|
import javax.swing.CellRendererPane;
|
||||||
import javax.swing.DefaultListCellRenderer;
|
import javax.swing.DefaultListCellRenderer;
|
||||||
import javax.swing.InputMap;
|
import javax.swing.InputMap;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
@@ -60,13 +61,13 @@ import javax.swing.UIManager;
|
|||||||
import javax.swing.border.AbstractBorder;
|
import javax.swing.border.AbstractBorder;
|
||||||
import javax.swing.border.Border;
|
import javax.swing.border.Border;
|
||||||
import javax.swing.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
|
import javax.swing.plaf.UIResource;
|
||||||
import javax.swing.plaf.basic.BasicComboBoxUI;
|
import javax.swing.plaf.basic.BasicComboBoxUI;
|
||||||
import javax.swing.plaf.basic.BasicComboPopup;
|
import javax.swing.plaf.basic.BasicComboPopup;
|
||||||
import javax.swing.plaf.basic.ComboPopup;
|
import javax.swing.plaf.basic.ComboPopup;
|
||||||
import javax.swing.text.JTextComponent;
|
import javax.swing.text.JTextComponent;
|
||||||
import com.formdev.flatlaf.FlatClientProperties;
|
import com.formdev.flatlaf.FlatClientProperties;
|
||||||
import com.formdev.flatlaf.util.SystemInfo;
|
import com.formdev.flatlaf.util.SystemInfo;
|
||||||
import com.formdev.flatlaf.util.UIScale;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides the Flat LaF UI delegate for {@link javax.swing.JComboBox}.
|
* Provides the Flat LaF UI delegate for {@link javax.swing.JComboBox}.
|
||||||
@@ -91,14 +92,17 @@ import com.formdev.flatlaf.util.UIScale;
|
|||||||
* @uiDefault Component.borderColor Color
|
* @uiDefault Component.borderColor Color
|
||||||
* @uiDefault Component.disabledBorderColor Color
|
* @uiDefault Component.disabledBorderColor Color
|
||||||
* @uiDefault ComboBox.editableBackground Color optional; defaults to ComboBox.background
|
* @uiDefault ComboBox.editableBackground Color optional; defaults to ComboBox.background
|
||||||
|
* @uiDefault ComboBox.focusedBackground Color optional
|
||||||
* @uiDefault ComboBox.disabledBackground Color
|
* @uiDefault ComboBox.disabledBackground Color
|
||||||
* @uiDefault ComboBox.disabledForeground Color
|
* @uiDefault ComboBox.disabledForeground Color
|
||||||
* @uiDefault ComboBox.buttonBackground Color
|
* @uiDefault ComboBox.buttonBackground Color
|
||||||
* @uiDefault ComboBox.buttonEditableBackground Color
|
* @uiDefault ComboBox.buttonEditableBackground Color
|
||||||
|
* @uiDefault ComboBox.buttonFocusedBackground Color optional; defaults to ComboBox.focusedBackground
|
||||||
* @uiDefault ComboBox.buttonArrowColor Color
|
* @uiDefault ComboBox.buttonArrowColor Color
|
||||||
* @uiDefault ComboBox.buttonDisabledArrowColor Color
|
* @uiDefault ComboBox.buttonDisabledArrowColor Color
|
||||||
* @uiDefault ComboBox.buttonHoverArrowColor Color
|
* @uiDefault ComboBox.buttonHoverArrowColor Color
|
||||||
* @uiDefault ComboBox.buttonPressedArrowColor Color
|
* @uiDefault ComboBox.buttonPressedArrowColor Color
|
||||||
|
* @uiDefault ComboBox.popupBackground Color optional
|
||||||
*
|
*
|
||||||
* @author Karl Tauber
|
* @author Karl Tauber
|
||||||
*/
|
*/
|
||||||
@@ -114,21 +118,25 @@ public class FlatComboBoxUI
|
|||||||
protected Color disabledBorderColor;
|
protected Color disabledBorderColor;
|
||||||
|
|
||||||
protected Color editableBackground;
|
protected Color editableBackground;
|
||||||
|
protected Color focusedBackground;
|
||||||
protected Color disabledBackground;
|
protected Color disabledBackground;
|
||||||
protected Color disabledForeground;
|
protected Color disabledForeground;
|
||||||
|
|
||||||
protected Color buttonBackground;
|
protected Color buttonBackground;
|
||||||
protected Color buttonEditableBackground;
|
protected Color buttonEditableBackground;
|
||||||
|
protected Color buttonFocusedBackground;
|
||||||
protected Color buttonArrowColor;
|
protected Color buttonArrowColor;
|
||||||
protected Color buttonDisabledArrowColor;
|
protected Color buttonDisabledArrowColor;
|
||||||
protected Color buttonHoverArrowColor;
|
protected Color buttonHoverArrowColor;
|
||||||
protected Color buttonPressedArrowColor;
|
protected Color buttonPressedArrowColor;
|
||||||
|
|
||||||
|
protected Color popupBackground;
|
||||||
|
|
||||||
private MouseListener hoverListener;
|
private MouseListener hoverListener;
|
||||||
protected boolean hover;
|
protected boolean hover;
|
||||||
protected boolean pressed;
|
protected boolean pressed;
|
||||||
|
|
||||||
private WeakReference<Component> lastRendererComponent;
|
private CellPaddingBorder paddingBorder;
|
||||||
|
|
||||||
public static ComponentUI createUI( JComponent c ) {
|
public static ComponentUI createUI( JComponent c ) {
|
||||||
return new FlatComboBoxUI();
|
return new FlatComboBoxUI();
|
||||||
@@ -194,23 +202,26 @@ public class FlatComboBoxUI
|
|||||||
disabledBorderColor = UIManager.getColor( "Component.disabledBorderColor" );
|
disabledBorderColor = UIManager.getColor( "Component.disabledBorderColor" );
|
||||||
|
|
||||||
editableBackground = UIManager.getColor( "ComboBox.editableBackground" );
|
editableBackground = UIManager.getColor( "ComboBox.editableBackground" );
|
||||||
|
focusedBackground = UIManager.getColor( "ComboBox.focusedBackground" );
|
||||||
disabledBackground = UIManager.getColor( "ComboBox.disabledBackground" );
|
disabledBackground = UIManager.getColor( "ComboBox.disabledBackground" );
|
||||||
disabledForeground = UIManager.getColor( "ComboBox.disabledForeground" );
|
disabledForeground = UIManager.getColor( "ComboBox.disabledForeground" );
|
||||||
|
|
||||||
buttonBackground = UIManager.getColor( "ComboBox.buttonBackground" );
|
buttonBackground = UIManager.getColor( "ComboBox.buttonBackground" );
|
||||||
|
buttonFocusedBackground = UIManager.getColor( "ComboBox.buttonFocusedBackground" );
|
||||||
buttonEditableBackground = UIManager.getColor( "ComboBox.buttonEditableBackground" );
|
buttonEditableBackground = UIManager.getColor( "ComboBox.buttonEditableBackground" );
|
||||||
buttonArrowColor = UIManager.getColor( "ComboBox.buttonArrowColor" );
|
buttonArrowColor = UIManager.getColor( "ComboBox.buttonArrowColor" );
|
||||||
buttonDisabledArrowColor = UIManager.getColor( "ComboBox.buttonDisabledArrowColor" );
|
buttonDisabledArrowColor = UIManager.getColor( "ComboBox.buttonDisabledArrowColor" );
|
||||||
buttonHoverArrowColor = UIManager.getColor( "ComboBox.buttonHoverArrowColor" );
|
buttonHoverArrowColor = UIManager.getColor( "ComboBox.buttonHoverArrowColor" );
|
||||||
buttonPressedArrowColor = UIManager.getColor( "ComboBox.buttonPressedArrowColor" );
|
buttonPressedArrowColor = UIManager.getColor( "ComboBox.buttonPressedArrowColor" );
|
||||||
|
|
||||||
|
popupBackground = UIManager.getColor( "ComboBox.popupBackground" );
|
||||||
|
|
||||||
// set maximumRowCount
|
// set maximumRowCount
|
||||||
int maximumRowCount = UIManager.getInt( "ComboBox.maximumRowCount" );
|
int maximumRowCount = UIManager.getInt( "ComboBox.maximumRowCount" );
|
||||||
if( maximumRowCount > 0 && maximumRowCount != 8 && comboBox.getMaximumRowCount() == 8 )
|
if( maximumRowCount > 0 && maximumRowCount != 8 && comboBox.getMaximumRowCount() == 8 )
|
||||||
comboBox.setMaximumRowCount( maximumRowCount );
|
comboBox.setMaximumRowCount( maximumRowCount );
|
||||||
|
|
||||||
// scale
|
paddingBorder = new CellPaddingBorder( padding );
|
||||||
padding = UIScale.scale( padding );
|
|
||||||
|
|
||||||
MigLayoutVisualPadding.install( comboBox );
|
MigLayoutVisualPadding.install( comboBox );
|
||||||
}
|
}
|
||||||
@@ -223,16 +234,22 @@ public class FlatComboBoxUI
|
|||||||
disabledBorderColor = null;
|
disabledBorderColor = null;
|
||||||
|
|
||||||
editableBackground = null;
|
editableBackground = null;
|
||||||
|
focusedBackground = null;
|
||||||
disabledBackground = null;
|
disabledBackground = null;
|
||||||
disabledForeground = null;
|
disabledForeground = null;
|
||||||
|
|
||||||
buttonBackground = null;
|
buttonBackground = null;
|
||||||
buttonEditableBackground = null;
|
buttonEditableBackground = null;
|
||||||
|
buttonFocusedBackground = null;
|
||||||
buttonArrowColor = null;
|
buttonArrowColor = null;
|
||||||
buttonDisabledArrowColor = null;
|
buttonDisabledArrowColor = null;
|
||||||
buttonHoverArrowColor = null;
|
buttonHoverArrowColor = null;
|
||||||
buttonPressedArrowColor = null;
|
buttonPressedArrowColor = null;
|
||||||
|
|
||||||
|
popupBackground = null;
|
||||||
|
|
||||||
|
paddingBorder.uninstall();
|
||||||
|
|
||||||
MigLayoutVisualPadding.uninstall( comboBox );
|
MigLayoutVisualPadding.uninstall( comboBox );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,9 +260,16 @@ public class FlatComboBoxUI
|
|||||||
public void layoutContainer( Container parent ) {
|
public void layoutContainer( Container parent ) {
|
||||||
super.layoutContainer( parent );
|
super.layoutContainer( parent );
|
||||||
|
|
||||||
if( arrowButton != null ) {
|
// on macOS, a Swing combo box is used for AWT component java.awt.Choice
|
||||||
|
// and the font may be (temporary) null
|
||||||
|
|
||||||
|
if( arrowButton != null && comboBox.getFont() != 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();
|
Insets insets = getInsets();
|
||||||
int buttonWidth = parent.getPreferredSize().height - insets.top - insets.bottom;
|
int buttonWidth = Math.min( parent.getPreferredSize().height - insets.top - insets.bottom, maxButtonWidth );
|
||||||
if( buttonWidth != arrowButton.getWidth() ) {
|
if( buttonWidth != arrowButton.getWidth() ) {
|
||||||
// set width of arrow button to preferred height of combobox
|
// set width of arrow button to preferred height of combobox
|
||||||
int xOffset = comboBox.getComponentOrientation().isLeftToRight()
|
int xOffset = comboBox.getComponentOrientation().isLeftToRight()
|
||||||
@@ -259,11 +283,6 @@ public class FlatComboBoxUI
|
|||||||
editor.setBounds( rectangleForCurrentValue() );
|
editor.setBounds( rectangleForCurrentValue() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( editor != null && padding != null ) {
|
|
||||||
// fix editor bounds by subtracting padding
|
|
||||||
editor.setBounds( FlatUIUtils.subtractInsets( editor.getBounds(), padding ) );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -321,14 +340,16 @@ public class FlatComboBoxUI
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ComboBoxEditor createEditor() {
|
protected void configureEditor() {
|
||||||
ComboBoxEditor comboBoxEditor = super.createEditor();
|
super.configureEditor();
|
||||||
|
|
||||||
Component editor = comboBoxEditor.getEditorComponent();
|
|
||||||
if( editor instanceof JTextField ) {
|
if( editor instanceof JTextField ) {
|
||||||
JTextField textField = (JTextField) editor;
|
JTextField textField = (JTextField) editor;
|
||||||
textField.setColumns( editorColumns );
|
textField.setColumns( editorColumns );
|
||||||
|
|
||||||
|
// 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,
|
// 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
|
// otherwise it is replaced with default text field border when switching LaF
|
||||||
// because javax.swing.plaf.basic.BasicComboBoxEditor.BorderlessTextField.setBorder()
|
// because javax.swing.plaf.basic.BasicComboBoxEditor.BorderlessTextField.setBorder()
|
||||||
@@ -336,24 +357,15 @@ public class FlatComboBoxUI
|
|||||||
// instead of "border instanceof javax.swing.plaf.UIResource"
|
// instead of "border instanceof javax.swing.plaf.UIResource"
|
||||||
textField.setBorder( BorderFactory.createEmptyBorder() );
|
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
|
// explicitly make non-opaque
|
||||||
if( editor instanceof JComponent )
|
if( editor instanceof JComponent )
|
||||||
((JComponent)editor).setOpaque( false );
|
((JComponent)editor).setOpaque( false );
|
||||||
|
|
||||||
editor.applyComponentOrientation( comboBox.getComponentOrientation() );
|
editor.applyComponentOrientation( comboBox.getComponentOrientation() );
|
||||||
|
|
||||||
|
updateEditorPadding();
|
||||||
updateEditorColors();
|
updateEditorColors();
|
||||||
|
|
||||||
// macOS
|
// macOS
|
||||||
@@ -370,6 +382,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() {
|
private void updateEditorColors() {
|
||||||
// use non-UIResource colors because when SwingUtilities.updateComponentTreeUI()
|
// use non-UIResource colors because when SwingUtilities.updateComponentTreeUI()
|
||||||
// is used, then the editor is updated after the combobox and the
|
// is used, then the editor is updated after the combobox and the
|
||||||
@@ -390,6 +421,15 @@ public class FlatComboBoxUI
|
|||||||
public void update( Graphics g, JComponent c ) {
|
public void update( Graphics g, JComponent c ) {
|
||||||
float focusWidth = FlatUIUtils.getBorderFocusWidth( c );
|
float focusWidth = FlatUIUtils.getBorderFocusWidth( c );
|
||||||
float arc = FlatUIUtils.getBorderArc( 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
|
// fill background if opaque to avoid garbage if user sets opaque to true
|
||||||
if( c.isOpaque() && (focusWidth > 0 || arc > 0) )
|
if( c.isOpaque() && (focusWidth > 0 || arc > 0) )
|
||||||
@@ -407,12 +447,17 @@ public class FlatComboBoxUI
|
|||||||
boolean isLeftToRight = comboBox.getComponentOrientation().isLeftToRight();
|
boolean isLeftToRight = comboBox.getComponentOrientation().isLeftToRight();
|
||||||
|
|
||||||
// paint background
|
// paint background
|
||||||
|
if( paintBackground || c.isOpaque() ) {
|
||||||
g2.setColor( getBackground( enabled ) );
|
g2.setColor( getBackground( enabled ) );
|
||||||
FlatUIUtils.paintComponentBackground( g2, 0, 0, width, height, focusWidth, arc );
|
FlatUIUtils.paintComponentBackground( g2, 0, 0, width, height, focusWidth, arc );
|
||||||
|
|
||||||
// paint arrow button background
|
// paint arrow button background
|
||||||
if( enabled ) {
|
if( enabled && !isCellRenderer ) {
|
||||||
g2.setColor( paintButton ? buttonEditableBackground : buttonBackground );
|
g2.setColor( paintButton
|
||||||
|
? buttonEditableBackground
|
||||||
|
: (buttonFocusedBackground != null || focusedBackground != null) && isPermanentFocusOwner( comboBox )
|
||||||
|
? (buttonFocusedBackground != null ? buttonFocusedBackground : focusedBackground)
|
||||||
|
: buttonBackground );
|
||||||
Shape oldClip = g2.getClip();
|
Shape oldClip = g2.getClip();
|
||||||
if( isLeftToRight )
|
if( isLeftToRight )
|
||||||
g2.clipRect( arrowX, 0, width - arrowX, height );
|
g2.clipRect( arrowX, 0, width - arrowX, height );
|
||||||
@@ -429,6 +474,7 @@ public class FlatComboBoxUI
|
|||||||
float lx = isLeftToRight ? arrowX : arrowX + arrowWidth - lw;
|
float lx = isLeftToRight ? arrowX : arrowX + arrowWidth - lw;
|
||||||
g2.fill( new Rectangle2D.Float( lx, focusWidth, lw, height - 1 - (focusWidth * 2)) );
|
g2.fill( new Rectangle2D.Float( lx, focusWidth, lw, height - 1 - (focusWidth * 2)) );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// avoid that the "current value" renderer is invoked with enabled antialiasing
|
// avoid that the "current value" renderer is invoked with enabled antialiasing
|
||||||
FlatUIUtils.resetRenderingHints( g2, oldRenderingHints );
|
FlatUIUtils.resetRenderingHints( g2, oldRenderingHints );
|
||||||
@@ -439,30 +485,33 @@ public class FlatComboBoxUI
|
|||||||
@Override
|
@Override
|
||||||
@SuppressWarnings( "unchecked" )
|
@SuppressWarnings( "unchecked" )
|
||||||
public void paintCurrentValue( Graphics g, Rectangle bounds, boolean hasFocus ) {
|
public void paintCurrentValue( Graphics g, Rectangle bounds, boolean hasFocus ) {
|
||||||
|
paddingBorder.uninstall();
|
||||||
|
|
||||||
ListCellRenderer<Object> renderer = comboBox.getRenderer();
|
ListCellRenderer<Object> renderer = comboBox.getRenderer();
|
||||||
uninstallCellPaddingBorder( renderer );
|
|
||||||
if( renderer == null )
|
if( renderer == null )
|
||||||
renderer = new DefaultListCellRenderer();
|
renderer = new DefaultListCellRenderer();
|
||||||
Component c = renderer.getListCellRendererComponent( listBox, comboBox.getSelectedItem(), -1, false, false );
|
Component c = renderer.getListCellRendererComponent( listBox, comboBox.getSelectedItem(), -1, false, false );
|
||||||
c.setFont( comboBox.getFont() );
|
c.setFont( comboBox.getFont() );
|
||||||
c.applyComponentOrientation( comboBox.getComponentOrientation() );
|
c.applyComponentOrientation( comboBox.getComponentOrientation() );
|
||||||
uninstallCellPaddingBorder( c );
|
|
||||||
|
|
||||||
boolean enabled = comboBox.isEnabled();
|
boolean enabled = comboBox.isEnabled();
|
||||||
c.setBackground( getBackground( enabled ) );
|
c.setBackground( getBackground( enabled ) );
|
||||||
c.setForeground( getForeground( enabled ) );
|
c.setForeground( getForeground( enabled ) );
|
||||||
|
|
||||||
|
// make renderer component temporary non-opaque to avoid that renderer paints
|
||||||
|
// background outside of border if combobox uses larger arc for edges
|
||||||
|
// (e.g. FlatClientProperties.COMPONENT_ROUND_RECT is true)
|
||||||
|
if( c instanceof JComponent )
|
||||||
|
((JComponent)c).setOpaque( false );
|
||||||
|
|
||||||
boolean shouldValidate = (c instanceof JPanel);
|
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 );
|
currentValuePane.paintComponent( g, c, comboBox, bounds.x, bounds.y, bounds.width, bounds.height, shouldValidate );
|
||||||
|
paddingBorder.uninstall();
|
||||||
|
|
||||||
|
if( c instanceof JComponent )
|
||||||
|
((JComponent)c).setOpaque( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -471,9 +520,20 @@ public class FlatComboBoxUI
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected Color getBackground( boolean enabled ) {
|
protected Color getBackground( boolean enabled ) {
|
||||||
return enabled
|
if( enabled ) {
|
||||||
? (editableBackground != null && comboBox.isEditable() ? editableBackground : comboBox.getBackground())
|
Color background = comboBox.getBackground();
|
||||||
: (isIntelliJTheme ? FlatUIUtils.getParentBackground( comboBox ) : disabledBackground);
|
|
||||||
|
// 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 ) {
|
protected Color getForeground( boolean enabled ) {
|
||||||
@@ -483,75 +543,68 @@ public class FlatComboBoxUI
|
|||||||
@Override
|
@Override
|
||||||
public Dimension getMinimumSize( JComponent c ) {
|
public Dimension getMinimumSize( JComponent c ) {
|
||||||
Dimension minimumSize = super.getMinimumSize( 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;
|
return minimumSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Dimension getDefaultSize() {
|
protected Dimension getDefaultSize() {
|
||||||
@SuppressWarnings( "unchecked" )
|
paddingBorder.uninstall();
|
||||||
ListCellRenderer<Object> renderer = comboBox.getRenderer();
|
|
||||||
uninstallCellPaddingBorder( renderer );
|
|
||||||
|
|
||||||
Dimension size = super.getDefaultSize();
|
Dimension size = super.getDefaultSize();
|
||||||
|
paddingBorder.uninstall();
|
||||||
uninstallCellPaddingBorder( renderer );
|
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Dimension getDisplaySize() {
|
protected Dimension getDisplaySize() {
|
||||||
@SuppressWarnings( "unchecked" )
|
paddingBorder.uninstall();
|
||||||
ListCellRenderer<Object> renderer = comboBox.getRenderer();
|
|
||||||
uninstallCellPaddingBorder( renderer );
|
|
||||||
|
|
||||||
Dimension displaySize = super.getDisplaySize();
|
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
|
// recalculate width without hardcoded 100 under special conditions
|
||||||
if( displaySize.width == 100 + padding.left + padding.right &&
|
if( displayWidth == 100 &&
|
||||||
comboBox.isEditable() &&
|
comboBox.isEditable() &&
|
||||||
comboBox.getItemCount() == 0 &&
|
comboBox.getItemCount() == 0 &&
|
||||||
comboBox.getPrototypeDisplayValue() == null )
|
comboBox.getPrototypeDisplayValue() == null )
|
||||||
{
|
{
|
||||||
int width = getDefaultSize().width;
|
displayWidth = Math.max( getDefaultSize().width, editor.getPreferredSize().width );
|
||||||
width = Math.max( width, editor.getPreferredSize().width );
|
|
||||||
width += padding.left + padding.right;
|
|
||||||
displaySize = new Dimension( width, displaySize.height );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uninstallCellPaddingBorder( renderer );
|
return new Dimension( displayWidth, displayHeight );
|
||||||
return displaySize;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Dimension getSizeForComponent( Component comp ) {
|
protected Dimension getSizeForComponent( Component comp ) {
|
||||||
|
paddingBorder.install( comp );
|
||||||
Dimension size = super.getSizeForComponent( comp );
|
Dimension size = super.getSizeForComponent( comp );
|
||||||
|
paddingBorder.uninstall();
|
||||||
// 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 );
|
|
||||||
|
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Insets getRendererComponentInsets( Component rendererComponent ) {
|
private boolean isCellRenderer() {
|
||||||
if( rendererComponent instanceof JComponent ) {
|
return comboBox.getParent() instanceof CellRendererPane;
|
||||||
Border rendererBorder = ((JComponent)rendererComponent).getBorder();
|
|
||||||
if( rendererBorder != null )
|
|
||||||
return rendererBorder.getBorderInsets( rendererComponent );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 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() );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void uninstallCellPaddingBorder( Object o ) {
|
/**
|
||||||
CellPaddingBorder.uninstall( o );
|
* @since 1.3
|
||||||
if( lastRendererComponent != null ) {
|
*/
|
||||||
CellPaddingBorder.uninstall( lastRendererComponent );
|
public static boolean isPermanentFocusOwner( JComboBox<?> comboBox ) {
|
||||||
lastRendererComponent = null;
|
if( comboBox.isEditable() ) {
|
||||||
}
|
Component editorComponent = comboBox.getEditor().getEditorComponent();
|
||||||
|
return (editorComponent != null) ? FlatUIUtils.isPermanentFocusOwner( editorComponent ) : false;
|
||||||
|
} else
|
||||||
|
return FlatUIUtils.isPermanentFocusOwner( comboBox );
|
||||||
}
|
}
|
||||||
|
|
||||||
//---- class FlatComboBoxButton -------------------------------------------
|
//---- class FlatComboBoxButton -------------------------------------------
|
||||||
@@ -580,6 +633,14 @@ public class FlatComboBoxUI
|
|||||||
protected boolean isPressed() {
|
protected boolean isPressed() {
|
||||||
return super.isPressed() || (!comboBox.isEditable() ? pressed : false);
|
return super.isPressed() || (!comboBox.isEditable() ? pressed : false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Color getArrowColor() {
|
||||||
|
if( isCellRenderer() && isCellRendererBackgroundChanged() )
|
||||||
|
return comboBox.getForeground();
|
||||||
|
|
||||||
|
return super.getArrowColor();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---- class FlatComboPopup -----------------------------------------------
|
//---- class FlatComboPopup -----------------------------------------------
|
||||||
@@ -588,13 +649,11 @@ public class FlatComboBoxUI
|
|||||||
protected class FlatComboPopup
|
protected class FlatComboPopup
|
||||||
extends BasicComboPopup
|
extends BasicComboPopup
|
||||||
{
|
{
|
||||||
private CellPaddingBorder paddingBorder;
|
|
||||||
|
|
||||||
protected FlatComboPopup( JComboBox combo ) {
|
protected FlatComboPopup( JComboBox combo ) {
|
||||||
super( combo );
|
super( combo );
|
||||||
|
|
||||||
// BasicComboPopup listens to JComboBox.componentOrientation and updates
|
// 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
|
// switching the LaF and a new combo popup is created, the component
|
||||||
// orientation is not applied.
|
// orientation is not applied.
|
||||||
ComponentOrientation o = comboBox.getComponentOrientation();
|
ComponentOrientation o = comboBox.getComponentOrientation();
|
||||||
@@ -648,6 +707,9 @@ public class FlatComboBoxUI
|
|||||||
protected void configurePopup() {
|
protected void configurePopup() {
|
||||||
super.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" );
|
Border border = UIManager.getBorder( "PopupMenu.border" );
|
||||||
if( border != null )
|
if( border != null )
|
||||||
setBorder( border );
|
setBorder( border );
|
||||||
@@ -658,6 +720,8 @@ public class FlatComboBoxUI
|
|||||||
super.configureList();
|
super.configureList();
|
||||||
|
|
||||||
list.setCellRenderer( new PopupListCellRenderer() );
|
list.setCellRenderer( new PopupListCellRenderer() );
|
||||||
|
if( popupBackground != null )
|
||||||
|
list.setBackground( popupBackground );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -671,6 +735,34 @@ public class FlatComboBoxUI
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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 -----
|
//---- class PopupListCellRenderer -----
|
||||||
|
|
||||||
private class PopupListCellRenderer
|
private class PopupListCellRenderer
|
||||||
@@ -680,22 +772,15 @@ public class FlatComboBoxUI
|
|||||||
public Component getListCellRendererComponent( JList list, Object value,
|
public Component getListCellRendererComponent( JList list, Object value,
|
||||||
int index, boolean isSelected, boolean cellHasFocus )
|
int index, boolean isSelected, boolean cellHasFocus )
|
||||||
{
|
{
|
||||||
ListCellRenderer renderer = comboBox.getRenderer();
|
paddingBorder.uninstall();
|
||||||
CellPaddingBorder.uninstall( renderer );
|
|
||||||
CellPaddingBorder.uninstall( lastRendererComponent );
|
|
||||||
|
|
||||||
|
ListCellRenderer renderer = comboBox.getRenderer();
|
||||||
if( renderer == null )
|
if( renderer == null )
|
||||||
renderer = new DefaultListCellRenderer();
|
renderer = new DefaultListCellRenderer();
|
||||||
Component c = renderer.getListCellRendererComponent( list, value, index, isSelected, cellHasFocus );
|
Component c = renderer.getListCellRendererComponent( list, value, index, isSelected, cellHasFocus );
|
||||||
c.applyComponentOrientation( comboBox.getComponentOrientation() );
|
c.applyComponentOrientation( comboBox.getComponentOrientation() );
|
||||||
|
|
||||||
if( c instanceof JComponent ) {
|
paddingBorder.install( c );
|
||||||
if( paddingBorder == null )
|
|
||||||
paddingBorder = new CellPaddingBorder( padding );
|
|
||||||
paddingBorder.install( (JComponent) c );
|
|
||||||
}
|
|
||||||
|
|
||||||
lastRendererComponent = (c != renderer) ? new WeakReference<>( c ) : null;
|
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
@@ -705,50 +790,72 @@ public class FlatComboBoxUI
|
|||||||
//---- class CellPaddingBorder --------------------------------------------
|
//---- 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,
|
* 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.
|
* which vertically aligns text in popup list with text in combobox.
|
||||||
*
|
* <p>
|
||||||
* The renderer border is painted on the outside of this border.
|
* The renderer border is painted on the outer side of this border.
|
||||||
*/
|
*/
|
||||||
private static class CellPaddingBorder
|
private static class CellPaddingBorder
|
||||||
extends AbstractBorder
|
extends AbstractBorder
|
||||||
{
|
{
|
||||||
private final Insets padding;
|
private final Insets padding;
|
||||||
|
private JComponent rendererComponent;
|
||||||
private Border rendererBorder;
|
private Border rendererBorder;
|
||||||
|
|
||||||
CellPaddingBorder( Insets padding ) {
|
CellPaddingBorder( Insets padding ) {
|
||||||
this.padding = padding;
|
this.padding = padding;
|
||||||
}
|
}
|
||||||
|
|
||||||
void install( JComponent rendererComponent ) {
|
// using synchronized to avoid problems with code that modifies combo box
|
||||||
Border oldBorder = rendererComponent.getBorder();
|
// (model, selection, etc) not on AWT thread (which should be not done)
|
||||||
if( !(oldBorder instanceof CellPaddingBorder) ) {
|
synchronized void install( Component c ) {
|
||||||
rendererBorder = oldBorder;
|
if( !(c instanceof JComponent) )
|
||||||
rendererComponent.setBorder( this );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void uninstall( Object o ) {
|
|
||||||
if( o instanceof WeakReference )
|
|
||||||
o = ((WeakReference<?>)o).get();
|
|
||||||
|
|
||||||
if( !(o instanceof JComponent) )
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
JComponent rendererComponent = (JComponent) o;
|
JComponent jc = (JComponent) c;
|
||||||
Border border = rendererComponent.getBorder();
|
Border oldBorder = jc.getBorder();
|
||||||
if( border instanceof CellPaddingBorder ) {
|
if( oldBorder == this )
|
||||||
CellPaddingBorder paddingBorder = (CellPaddingBorder) border;
|
return; // already installed
|
||||||
rendererComponent.setBorder( paddingBorder.rendererBorder );
|
|
||||||
paddingBorder.rendererBorder = null;
|
// 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();
|
||||||
|
jc.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.
|
||||||
|
*/
|
||||||
|
synchronized void uninstall() {
|
||||||
|
if( rendererComponent == null )
|
||||||
|
return;
|
||||||
|
|
||||||
|
if( rendererComponent.getBorder() == this )
|
||||||
|
rendererComponent.setBorder( rendererBorder );
|
||||||
|
rendererComponent = null;
|
||||||
|
rendererBorder = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Insets getBorderInsets( Component c, Insets insets ) {
|
synchronized public Insets getBorderInsets( Component c, Insets insets ) {
|
||||||
if( rendererBorder != null ) {
|
Insets padding = scale( this.padding );
|
||||||
|
if( rendererBorder != null && !(rendererBorder instanceof CellPaddingBorder) ) {
|
||||||
Insets insideInsets = rendererBorder.getBorderInsets( c );
|
Insets insideInsets = rendererBorder.getBorderInsets( c );
|
||||||
insets.top = Math.max( padding.top, insideInsets.top );
|
insets.top = Math.max( padding.top, insideInsets.top );
|
||||||
insets.left = Math.max( padding.left, insideInsets.left );
|
insets.left = Math.max( padding.left, insideInsets.left );
|
||||||
|
|||||||
@@ -16,10 +16,12 @@
|
|||||||
|
|
||||||
package com.formdev.flatlaf.ui;
|
package com.formdev.flatlaf.ui;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.Container;
|
import java.awt.Container;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.EventQueue;
|
import java.awt.EventQueue;
|
||||||
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Image;
|
import java.awt.Image;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
@@ -28,11 +30,13 @@ import java.awt.Point;
|
|||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.beans.PropertyChangeListener;
|
||||||
import java.beans.PropertyVetoException;
|
import java.beans.PropertyVetoException;
|
||||||
import javax.swing.BorderFactory;
|
import javax.swing.BorderFactory;
|
||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
|
import javax.swing.JDesktopPane;
|
||||||
import javax.swing.event.MouseInputAdapter;
|
import javax.swing.event.MouseInputAdapter;
|
||||||
import javax.swing.event.MouseInputListener;
|
import javax.swing.event.MouseInputListener;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
@@ -45,6 +49,7 @@ import javax.swing.SwingUtilities;
|
|||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
import javax.swing.plaf.basic.BasicDesktopIconUI;
|
import javax.swing.plaf.basic.BasicDesktopIconUI;
|
||||||
|
import com.formdev.flatlaf.util.MultiResolutionImageSupport;
|
||||||
import com.formdev.flatlaf.util.UIScale;
|
import com.formdev.flatlaf.util.UIScale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -75,11 +80,21 @@ public class FlatDesktopIconUI
|
|||||||
private JToolTip titleTip;
|
private JToolTip titleTip;
|
||||||
private ActionListener closeListener;
|
private ActionListener closeListener;
|
||||||
private MouseInputListener mouseInputListener;
|
private MouseInputListener mouseInputListener;
|
||||||
|
private PropertyChangeListener ancestorListener;
|
||||||
|
|
||||||
public static ComponentUI createUI( JComponent c ) {
|
public static ComponentUI createUI( JComponent c ) {
|
||||||
return new FlatDesktopIconUI();
|
return new FlatDesktopIconUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void installUI( JComponent c ) {
|
||||||
|
super.installUI( c );
|
||||||
|
|
||||||
|
// update dock icon preview if already iconified
|
||||||
|
if( c.isDisplayable() )
|
||||||
|
updateDockIconPreviewLater();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void uninstallUI( JComponent c ) {
|
public void uninstallUI( JComponent c ) {
|
||||||
super.uninstallUI( c );
|
super.uninstallUI( c );
|
||||||
@@ -136,6 +151,17 @@ public class FlatDesktopIconUI
|
|||||||
};
|
};
|
||||||
closeButton.addActionListener( closeListener );
|
closeButton.addActionListener( closeListener );
|
||||||
closeButton.addMouseListener( mouseInputListener );
|
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
|
@Override
|
||||||
@@ -146,6 +172,9 @@ public class FlatDesktopIconUI
|
|||||||
closeButton.removeMouseListener( mouseInputListener );
|
closeButton.removeMouseListener( mouseInputListener );
|
||||||
closeListener = null;
|
closeListener = null;
|
||||||
mouseInputListener = null;
|
mouseInputListener = null;
|
||||||
|
|
||||||
|
desktopIcon.removePropertyChangeListener( "ancestor", ancestorListener );
|
||||||
|
ancestorListener = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -228,15 +257,30 @@ public class FlatDesktopIconUI
|
|||||||
return getPreferredSize( c );
|
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
|
// use invoke later to make sure that components are updated when switching LaF
|
||||||
EventQueue.invokeLater( () -> {
|
EventQueue.invokeLater( () -> {
|
||||||
if( dockIcon != null )
|
if( dockIcon != null )
|
||||||
updateDockIconLater();
|
updateDockIconPreview();
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateDockIconLater() {
|
protected void updateDockIconPreview() {
|
||||||
// make sure that frame is not selected
|
// make sure that frame is not selected
|
||||||
if( frame.isSelected() ) {
|
if( frame.isSelected() ) {
|
||||||
try {
|
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
|
// paint internal frame to buffered image
|
||||||
int frameWidth = Math.max( frame.getWidth(), 1 );
|
int frameWidth = Math.max( frame.getWidth(), 1 );
|
||||||
int frameHeight = Math.max( frame.getHeight(), 1 );
|
int frameHeight = Math.max( frame.getHeight(), 1 );
|
||||||
BufferedImage frameImage = new BufferedImage( frameWidth, frameHeight, BufferedImage.TYPE_INT_ARGB );
|
BufferedImage frameImage = new BufferedImage( frameWidth, frameHeight, BufferedImage.TYPE_INT_ARGB );
|
||||||
Graphics2D g = frameImage.createGraphics();
|
Graphics2D g = frameImage.createGraphics();
|
||||||
try {
|
try {
|
||||||
//TODO fix missing internal frame header when switching LaF
|
|
||||||
frame.paint( g );
|
frame.paint( g );
|
||||||
} finally {
|
} finally {
|
||||||
g.dispose();
|
g.dispose();
|
||||||
@@ -270,6 +323,27 @@ public class FlatDesktopIconUI
|
|||||||
|
|
||||||
// scale preview
|
// scale preview
|
||||||
Image previewImage = frameImage.getScaledInstance( previewWidth, previewHeight, Image.SCALE_SMOOTH );
|
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 ) );
|
dockIcon.setIcon( new ImageIcon( previewImage ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,11 +16,16 @@
|
|||||||
|
|
||||||
package com.formdev.flatlaf.ui;
|
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.JComponent;
|
||||||
import javax.swing.JInternalFrame;
|
import javax.swing.JInternalFrame.JDesktopIcon;
|
||||||
import javax.swing.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
import javax.swing.plaf.UIResource;
|
|
||||||
import javax.swing.plaf.basic.BasicDesktopPaneUI;
|
import javax.swing.plaf.basic.BasicDesktopPaneUI;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -36,30 +41,96 @@ import javax.swing.plaf.basic.BasicDesktopPaneUI;
|
|||||||
public class FlatDesktopPaneUI
|
public class FlatDesktopPaneUI
|
||||||
extends BasicDesktopPaneUI
|
extends BasicDesktopPaneUI
|
||||||
{
|
{
|
||||||
|
private LayoutDockListener layoutDockListener;
|
||||||
|
private boolean layoutDockPending;
|
||||||
|
|
||||||
public static ComponentUI createUI( JComponent c ) {
|
public static ComponentUI createUI( JComponent c ) {
|
||||||
return new FlatDesktopPaneUI();
|
return new FlatDesktopPaneUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void installDesktopManager() {
|
public void installUI( JComponent c ) {
|
||||||
desktopManager = desktop.getDesktopManager();
|
super.installUI( c );
|
||||||
if( desktopManager == null ) {
|
|
||||||
desktopManager = new FlatDesktopManager();
|
layoutDockLaterOnce();
|
||||||
desktop.setDesktopManager( desktopManager );
|
}
|
||||||
|
|
||||||
|
@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
|
private class LayoutDockListener
|
||||||
extends DefaultDesktopManager
|
extends ComponentAdapter
|
||||||
implements UIResource
|
implements ContainerListener
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void iconifyFrame( JInternalFrame f ) {
|
public void componentAdded( ContainerEvent e ) {
|
||||||
super.iconifyFrame( f );
|
layoutDockLaterOnce();
|
||||||
|
}
|
||||||
|
|
||||||
((FlatDesktopIconUI)f.getDesktopIcon().getUI()).updateDockIcon();
|
@Override
|
||||||
|
public void componentRemoved( ContainerEvent e ) {
|
||||||
|
layoutDockLaterOnce();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void componentResized( ComponentEvent e ) {
|
||||||
|
layoutDockLaterOnce();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,15 +17,17 @@
|
|||||||
package com.formdev.flatlaf.ui;
|
package com.formdev.flatlaf.ui;
|
||||||
|
|
||||||
import static com.formdev.flatlaf.util.UIScale.scale;
|
import static com.formdev.flatlaf.util.UIScale.scale;
|
||||||
|
import java.awt.Color;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Insets;
|
||||||
|
import java.awt.event.FocusListener;
|
||||||
import java.beans.PropertyChangeEvent;
|
import java.beans.PropertyChangeEvent;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JEditorPane;
|
import javax.swing.JEditorPane;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
import javax.swing.plaf.UIResource;
|
|
||||||
import javax.swing.plaf.basic.BasicEditorPaneUI;
|
import javax.swing.plaf.basic.BasicEditorPaneUI;
|
||||||
import javax.swing.text.JTextComponent;
|
import javax.swing.text.JTextComponent;
|
||||||
import com.formdev.flatlaf.FlatClientProperties;
|
import com.formdev.flatlaf.FlatClientProperties;
|
||||||
@@ -53,6 +55,7 @@ import com.formdev.flatlaf.util.HiDPIUtils;
|
|||||||
*
|
*
|
||||||
* @uiDefault Component.minimumWidth int
|
* @uiDefault Component.minimumWidth int
|
||||||
* @uiDefault Component.isIntelliJTheme boolean
|
* @uiDefault Component.isIntelliJTheme boolean
|
||||||
|
* @uiDefault EditorPane.focusedBackground Color optional
|
||||||
*
|
*
|
||||||
* @author Karl Tauber
|
* @author Karl Tauber
|
||||||
*/
|
*/
|
||||||
@@ -61,8 +64,12 @@ public class FlatEditorPaneUI
|
|||||||
{
|
{
|
||||||
protected int minimumWidth;
|
protected int minimumWidth;
|
||||||
protected boolean isIntelliJTheme;
|
protected boolean isIntelliJTheme;
|
||||||
|
protected Color focusedBackground;
|
||||||
|
|
||||||
|
private Insets defaultMargin;
|
||||||
|
|
||||||
private Object oldHonorDisplayProperties;
|
private Object oldHonorDisplayProperties;
|
||||||
|
private FocusListener focusListener;
|
||||||
|
|
||||||
public static ComponentUI createUI( JComponent c ) {
|
public static ComponentUI createUI( JComponent c ) {
|
||||||
return new FlatEditorPaneUI();
|
return new FlatEditorPaneUI();
|
||||||
@@ -72,8 +79,12 @@ public class FlatEditorPaneUI
|
|||||||
protected void installDefaults() {
|
protected void installDefaults() {
|
||||||
super.installDefaults();
|
super.installDefaults();
|
||||||
|
|
||||||
|
String prefix = getPropertyPrefix();
|
||||||
minimumWidth = UIManager.getInt( "Component.minimumWidth" );
|
minimumWidth = UIManager.getInt( "Component.minimumWidth" );
|
||||||
isIntelliJTheme = UIManager.getBoolean( "Component.isIntelliJTheme" );
|
isIntelliJTheme = UIManager.getBoolean( "Component.isIntelliJTheme" );
|
||||||
|
focusedBackground = UIManager.getColor( prefix + ".focusedBackground" );
|
||||||
|
|
||||||
|
defaultMargin = UIManager.getInsets( prefix + ".margin" );
|
||||||
|
|
||||||
// use component font and foreground for HTML text
|
// use component font and foreground for HTML text
|
||||||
oldHonorDisplayProperties = getComponent().getClientProperty( JEditorPane.HONOR_DISPLAY_PROPERTIES );
|
oldHonorDisplayProperties = getComponent().getClientProperty( JEditorPane.HONOR_DISPLAY_PROPERTIES );
|
||||||
@@ -84,9 +95,28 @@ public class FlatEditorPaneUI
|
|||||||
protected void uninstallDefaults() {
|
protected void uninstallDefaults() {
|
||||||
super.uninstallDefaults();
|
super.uninstallDefaults();
|
||||||
|
|
||||||
|
focusedBackground = null;
|
||||||
|
|
||||||
getComponent().putClientProperty( JEditorPane.HONOR_DISPLAY_PROPERTIES, oldHonorDisplayProperties );
|
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
|
@Override
|
||||||
protected void propertyChange( PropertyChangeEvent e ) {
|
protected void propertyChange( PropertyChangeEvent e ) {
|
||||||
super.propertyChange( e );
|
super.propertyChange( e );
|
||||||
@@ -103,15 +133,19 @@ public class FlatEditorPaneUI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dimension getPreferredSize( JComponent c ) {
|
public Dimension getPreferredSize( JComponent c ) {
|
||||||
return applyMinimumWidth( c, super.getPreferredSize( c ), minimumWidth );
|
return applyMinimumWidth( c, super.getPreferredSize( c ), minimumWidth, defaultMargin );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dimension getMinimumSize( JComponent c ) {
|
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)
|
// Assume that text area is in a scroll pane (that displays the border)
|
||||||
// and subtract 1px border line width.
|
// and subtract 1px border line width.
|
||||||
// Using "(scale( 1 ) * 2)" instead of "scale( 2 )" to deal with rounding
|
// Using "(scale( 1 ) * 2)" instead of "scale( 2 )" to deal with rounding
|
||||||
@@ -128,14 +162,11 @@ public class FlatEditorPaneUI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paintBackground( Graphics g ) {
|
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() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -262,14 +262,22 @@ public class FlatFileChooserUI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FileView getFileView( JFileChooser fc ) {
|
public FileView getFileView( JFileChooser fc ) {
|
||||||
return fileView;
|
return doNotUseSystemIcons() ? super.getFileView( fc ) : fileView;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearIconCache() {
|
public void clearIconCache() {
|
||||||
|
if( doNotUseSystemIcons() )
|
||||||
|
super.clearIconCache();
|
||||||
|
else
|
||||||
fileView.clearIconCache();
|
fileView.clearIconCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean doNotUseSystemIcons() {
|
||||||
|
// Java 17 32bit craches on Windows when using system icons
|
||||||
|
return SystemInfo.isWindows && SystemInfo.isJava_17_orLater && !SystemInfo.isX86_64;
|
||||||
|
}
|
||||||
|
|
||||||
//---- class FlatFileView -------------------------------------------------
|
//---- class FlatFileView -------------------------------------------------
|
||||||
|
|
||||||
private class FlatFileView
|
private class FlatFileView
|
||||||
|
|||||||
@@ -39,11 +39,10 @@ import javax.swing.plaf.ComponentUI;
|
|||||||
*
|
*
|
||||||
* <!-- FlatTextFieldUI -->
|
* <!-- FlatTextFieldUI -->
|
||||||
*
|
*
|
||||||
* @uiDefault TextComponent.arc int
|
|
||||||
* @uiDefault Component.focusWidth int
|
|
||||||
* @uiDefault Component.minimumWidth int
|
* @uiDefault Component.minimumWidth int
|
||||||
* @uiDefault Component.isIntelliJTheme boolean
|
* @uiDefault Component.isIntelliJTheme boolean
|
||||||
* @uiDefault FormattedTextField.placeholderForeground Color
|
* @uiDefault FormattedTextField.placeholderForeground Color
|
||||||
|
* @uiDefault FormattedTextField.focusedBackground Color optional
|
||||||
* @uiDefault TextComponent.selectAllOnFocusPolicy String never, once (default) or always
|
* @uiDefault TextComponent.selectAllOnFocusPolicy String never, once (default) or always
|
||||||
* @uiDefault TextComponent.selectAllOnMouseClick boolean
|
* @uiDefault TextComponent.selectAllOnMouseClick boolean
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import java.awt.Color;
|
|||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.LayoutManager;
|
import java.awt.LayoutManager;
|
||||||
|
import java.awt.Rectangle;
|
||||||
import java.beans.PropertyChangeEvent;
|
import java.beans.PropertyChangeEvent;
|
||||||
import java.beans.PropertyChangeListener;
|
import java.beans.PropertyChangeListener;
|
||||||
import javax.swing.BorderFactory;
|
import javax.swing.BorderFactory;
|
||||||
@@ -146,6 +147,19 @@ public class FlatInternalFrameTitlePane
|
|||||||
closeButton.setVisible( frame.isClosable() );
|
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.
|
* Does nothing because FlatLaf internal frames do not have system menus.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -22,10 +22,13 @@ import java.awt.Component;
|
|||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
|
import java.awt.Rectangle;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JInternalFrame;
|
import javax.swing.JInternalFrame;
|
||||||
import javax.swing.LookAndFeel;
|
import javax.swing.LookAndFeel;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
|
import javax.swing.event.MouseInputAdapter;
|
||||||
import javax.swing.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
import javax.swing.plaf.basic.BasicInternalFrameUI;
|
import javax.swing.plaf.basic.BasicInternalFrameUI;
|
||||||
|
|
||||||
@@ -122,6 +125,11 @@ public class FlatInternalFrameUI
|
|||||||
return new FlatWindowResizer.InternalFrameResizer( frame, this::getDesktopManager );
|
return new FlatWindowResizer.InternalFrameResizer( frame, this::getDesktopManager );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected MouseInputAdapter createBorderListener( JInternalFrame w ) {
|
||||||
|
return new FlatBorderListener();
|
||||||
|
}
|
||||||
|
|
||||||
//---- class FlatInternalFrameBorder --------------------------------------
|
//---- class FlatInternalFrameBorder --------------------------------------
|
||||||
|
|
||||||
public static 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 );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,10 +20,12 @@ import java.awt.Color;
|
|||||||
import java.awt.EventQueue;
|
import java.awt.EventQueue;
|
||||||
import java.awt.event.FocusEvent;
|
import java.awt.event.FocusEvent;
|
||||||
import java.awt.event.FocusListener;
|
import java.awt.event.FocusListener;
|
||||||
|
import java.beans.PropertyChangeListener;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
import javax.swing.plaf.basic.BasicListUI;
|
import javax.swing.plaf.basic.BasicListUI;
|
||||||
|
import com.formdev.flatlaf.FlatClientProperties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides the Flat LaF UI delegate for {@link javax.swing.JList}.
|
* Provides the Flat LaF UI delegate for {@link javax.swing.JList}.
|
||||||
@@ -95,6 +97,17 @@ public class FlatListUI
|
|||||||
selectionInactiveForeground = null;
|
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
|
@Override
|
||||||
protected FocusListener createFocusListener() {
|
protected FocusListener createFocusListener() {
|
||||||
return new BasicListUI.FocusHandler() {
|
return new BasicListUI.FocusHandler() {
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package com.formdev.flatlaf.ui;
|
package com.formdev.flatlaf.ui;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
import java.awt.Container;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.awt.Window;
|
import java.awt.Window;
|
||||||
import java.beans.PropertyChangeListener;
|
import java.beans.PropertyChangeListener;
|
||||||
@@ -24,7 +25,6 @@ import java.util.List;
|
|||||||
import javax.swing.JDialog;
|
import javax.swing.JDialog;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JRootPane;
|
import javax.swing.JRootPane;
|
||||||
import javax.swing.SwingUtilities;
|
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.event.ChangeListener;
|
import javax.swing.event.ChangeListener;
|
||||||
import com.formdev.flatlaf.FlatClientProperties;
|
import com.formdev.flatlaf.FlatClientProperties;
|
||||||
@@ -76,6 +76,11 @@ public class FlatNativeWindowBorder
|
|||||||
if( !isSupported() )
|
if( !isSupported() )
|
||||||
return null;
|
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
|
// Check whether root pane already has a window, which is the case when
|
||||||
// switching from another LaF to FlatLaf.
|
// switching from another LaF to FlatLaf.
|
||||||
// Also check whether the window is displayable, which is required to install
|
// Also check whether the window is displayable, which is required to install
|
||||||
@@ -83,9 +88,8 @@ public class FlatNativeWindowBorder
|
|||||||
// If the window is not displayable, then it was probably closed/disposed but not yet removed
|
// 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().
|
// 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.
|
// It could be also be a window that is currently hidden, but may be shown later.
|
||||||
Window window = SwingUtilities.windowForComponent( rootPane );
|
if( parent instanceof Window && parent.isDisplayable() )
|
||||||
if( window != null && window.isDisplayable() )
|
install( (Window) parent );
|
||||||
install( window );
|
|
||||||
|
|
||||||
// Install FlatLaf native window border, which must be done late,
|
// Install FlatLaf native window border, which must be done late,
|
||||||
// when the native window is already created, because it needs access to the window.
|
// when the native window is already created, because it needs access to the window.
|
||||||
@@ -125,6 +129,10 @@ public class FlatNativeWindowBorder
|
|||||||
// enable native window border for window
|
// enable native window border for window
|
||||||
setHasCustomDecoration( frame, true );
|
setHasCustomDecoration( frame, true );
|
||||||
|
|
||||||
|
// avoid double window title bar if enabling native window border failed
|
||||||
|
if( !hasCustomDecoration( frame ) )
|
||||||
|
return;
|
||||||
|
|
||||||
// enable Swing window decoration
|
// enable Swing window decoration
|
||||||
rootPane.setWindowDecorationStyle( JRootPane.FRAME );
|
rootPane.setWindowDecorationStyle( JRootPane.FRAME );
|
||||||
|
|
||||||
@@ -143,6 +151,10 @@ public class FlatNativeWindowBorder
|
|||||||
// enable native window border for window
|
// enable native window border for window
|
||||||
setHasCustomDecoration( dialog, true );
|
setHasCustomDecoration( dialog, true );
|
||||||
|
|
||||||
|
// avoid double window title bar if enabling native window border failed
|
||||||
|
if( !hasCustomDecoration( dialog ) )
|
||||||
|
return;
|
||||||
|
|
||||||
// enable Swing window decoration
|
// enable Swing window decoration
|
||||||
rootPane.setWindowDecorationStyle( JRootPane.PLAIN_DIALOG );
|
rootPane.setWindowDecorationStyle( JRootPane.PLAIN_DIALOG );
|
||||||
}
|
}
|
||||||
@@ -166,9 +178,9 @@ public class FlatNativeWindowBorder
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// uninstall native window border
|
// uninstall native window border
|
||||||
Window window = SwingUtilities.windowForComponent( rootPane );
|
Container parent = rootPane.getParent();
|
||||||
if( window != null )
|
if( parent instanceof Window )
|
||||||
uninstall( window );
|
uninstall( (Window) parent );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void uninstall( Window window ) {
|
private static void uninstall( Window window ) {
|
||||||
|
|||||||
@@ -22,7 +22,11 @@ import java.awt.Dimension;
|
|||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.GridBagConstraints;
|
import java.awt.GridBagConstraints;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
|
import javax.swing.Box;
|
||||||
|
import javax.swing.BoxLayout;
|
||||||
|
import javax.swing.Icon;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.border.Border;
|
import javax.swing.border.Border;
|
||||||
@@ -88,6 +92,7 @@ public class FlatOptionPaneUI
|
|||||||
protected int messagePadding;
|
protected int messagePadding;
|
||||||
protected int maxCharactersPerLine;
|
protected int maxCharactersPerLine;
|
||||||
private int focusWidth;
|
private int focusWidth;
|
||||||
|
private boolean sameSizeButtons;
|
||||||
|
|
||||||
public static ComponentUI createUI( JComponent c ) {
|
public static ComponentUI createUI( JComponent c ) {
|
||||||
return new FlatOptionPaneUI();
|
return new FlatOptionPaneUI();
|
||||||
@@ -101,6 +106,7 @@ public class FlatOptionPaneUI
|
|||||||
messagePadding = UIManager.getInt( "OptionPane.messagePadding" );
|
messagePadding = UIManager.getInt( "OptionPane.messagePadding" );
|
||||||
maxCharactersPerLine = UIManager.getInt( "OptionPane.maxCharactersPerLine" );
|
maxCharactersPerLine = UIManager.getInt( "OptionPane.maxCharactersPerLine" );
|
||||||
focusWidth = UIManager.getInt( "Component.focusWidth" );
|
focusWidth = UIManager.getInt( "Component.focusWidth" );
|
||||||
|
sameSizeButtons = FlatUIUtils.getUIBoolean( "OptionPane.sameSizeButtons", true );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -157,15 +163,40 @@ public class FlatOptionPaneUI
|
|||||||
cons.insets.bottom = UIScale.scale( messagePadding );
|
cons.insets.bottom = UIScale.scale( messagePadding );
|
||||||
|
|
||||||
// disable line wrapping for HTML
|
// disable line wrapping for HTML
|
||||||
if( msg instanceof String && BasicHTML.isHTMLString( (String) msg ) )
|
if( msg != null &&
|
||||||
|
!(msg instanceof Component) &&
|
||||||
|
!(msg instanceof Object[]) &&
|
||||||
|
!(msg instanceof Icon) )
|
||||||
|
{
|
||||||
|
msg = msg.toString();
|
||||||
|
if( BasicHTML.isHTMLString( (String) msg ) )
|
||||||
maxll = Integer.MAX_VALUE;
|
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 );
|
super.addMessageComponents( container, cons, msg, maxll, internallyCreated );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateChildPanels( Container c ) {
|
private void updateChildPanels( Container c ) {
|
||||||
for( Component child : c.getComponents() ) {
|
for( Component child : c.getComponents() ) {
|
||||||
if( child instanceof JPanel ) {
|
if( child.getClass() == JPanel.class ) {
|
||||||
JPanel panel = (JPanel)child;
|
JPanel panel = (JPanel)child;
|
||||||
|
|
||||||
// make sub-panel non-opaque for OptionPane.background
|
// make sub-panel non-opaque for OptionPane.background
|
||||||
@@ -177,11 +208,10 @@ public class FlatOptionPaneUI
|
|||||||
panel.setBorder( new NonUIResourceBorder( border ) );
|
panel.setBorder( new NonUIResourceBorder( border ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( child instanceof Container ) {
|
if( child instanceof Container )
|
||||||
updateChildPanels( (Container) child );
|
updateChildPanels( (Container) child );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private Component findByName( Container c, String name ) {
|
private Component findByName( Container c, String name ) {
|
||||||
for( Component child : c.getComponents() ) {
|
for( Component child : c.getComponents() ) {
|
||||||
@@ -197,6 +227,11 @@ public class FlatOptionPaneUI
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean getSizeButtonsToSameWidth() {
|
||||||
|
return sameSizeButtons;
|
||||||
|
}
|
||||||
|
|
||||||
//---- class NonUIResourceBorder ------------------------------------------
|
//---- class NonUIResourceBorder ------------------------------------------
|
||||||
|
|
||||||
private static class NonUIResourceBorder
|
private static class NonUIResourceBorder
|
||||||
|
|||||||
@@ -16,30 +16,31 @@
|
|||||||
|
|
||||||
package com.formdev.flatlaf.ui;
|
package com.formdev.flatlaf.ui;
|
||||||
|
|
||||||
import java.awt.Color;
|
|
||||||
import java.awt.Dimension;
|
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Insets;
|
||||||
|
import java.awt.Shape;
|
||||||
import java.awt.Toolkit;
|
import java.awt.Toolkit;
|
||||||
import java.awt.event.FocusListener;
|
|
||||||
import java.awt.event.KeyAdapter;
|
import java.awt.event.KeyAdapter;
|
||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
import java.awt.event.KeyListener;
|
import java.awt.event.KeyListener;
|
||||||
import java.beans.PropertyChangeEvent;
|
import javax.swing.Action;
|
||||||
|
import javax.swing.ActionMap;
|
||||||
import javax.swing.Icon;
|
import javax.swing.Icon;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.LookAndFeel;
|
import javax.swing.LookAndFeel;
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
import javax.swing.plaf.basic.BasicPasswordFieldUI;
|
import javax.swing.text.DefaultEditorKit;
|
||||||
import javax.swing.text.Caret;
|
import javax.swing.text.Element;
|
||||||
import javax.swing.text.JTextComponent;
|
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}.
|
* Provides the Flat LaF UI delegate for {@link javax.swing.JPasswordField}.
|
||||||
*
|
*
|
||||||
* <!-- BasicPasswordFieldUI -->
|
* <!-- BasicTextFieldUI -->
|
||||||
*
|
*
|
||||||
* @uiDefault PasswordField.font Font
|
* @uiDefault PasswordField.font Font
|
||||||
* @uiDefault PasswordField.background Color
|
* @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.inactiveForeground Color used if not enabled (yes, this is confusing; this should be named disabledForeground)
|
||||||
* @uiDefault PasswordField.border Border
|
* @uiDefault PasswordField.border Border
|
||||||
* @uiDefault PasswordField.margin Insets
|
* @uiDefault PasswordField.margin Insets
|
||||||
* @uiDefault PasswordField.echoChar character
|
|
||||||
* @uiDefault PasswordField.caretBlinkRate int default is 500 milliseconds
|
* @uiDefault PasswordField.caretBlinkRate int default is 500 milliseconds
|
||||||
*
|
*
|
||||||
* <!-- FlatPasswordFieldUI -->
|
* <!-- FlatTextFieldUI -->
|
||||||
*
|
*
|
||||||
* @uiDefault Component.minimumWidth int
|
* @uiDefault Component.minimumWidth int
|
||||||
* @uiDefault Component.isIntelliJTheme boolean
|
* @uiDefault Component.isIntelliJTheme boolean
|
||||||
* @uiDefault PasswordField.placeholderForeground Color
|
* @uiDefault PasswordField.placeholderForeground Color
|
||||||
* @uiDefault PasswordField.showCapsLock boolean
|
* @uiDefault PasswordField.focusedBackground Color optional
|
||||||
* @uiDefault PasswordField.capsLockIcon Icon
|
|
||||||
* @uiDefault TextComponent.selectAllOnFocusPolicy String never, once (default) or always
|
* @uiDefault TextComponent.selectAllOnFocusPolicy String never, once (default) or always
|
||||||
* @uiDefault TextComponent.selectAllOnMouseClick boolean
|
* @uiDefault TextComponent.selectAllOnMouseClick boolean
|
||||||
*
|
*
|
||||||
|
* <!-- FlatPasswordFieldUI -->
|
||||||
|
*
|
||||||
|
* @uiDefault PasswordField.echoChar character
|
||||||
|
* @uiDefault PasswordField.showCapsLock boolean
|
||||||
|
* @uiDefault PasswordField.capsLockIcon Icon
|
||||||
|
*
|
||||||
* @author Karl Tauber
|
* @author Karl Tauber
|
||||||
*/
|
*/
|
||||||
public class FlatPasswordFieldUI
|
public class FlatPasswordFieldUI
|
||||||
extends BasicPasswordFieldUI
|
extends FlatTextFieldUI
|
||||||
{
|
{
|
||||||
protected int minimumWidth;
|
|
||||||
protected boolean isIntelliJTheme;
|
|
||||||
protected Color placeholderForeground;
|
|
||||||
protected boolean showCapsLock;
|
protected boolean showCapsLock;
|
||||||
protected Icon capsLockIcon;
|
protected Icon capsLockIcon;
|
||||||
|
|
||||||
private FocusListener focusListener;
|
|
||||||
private KeyListener capsLockListener;
|
private KeyListener capsLockListener;
|
||||||
|
|
||||||
public static ComponentUI createUI( JComponent c ) {
|
public static ComponentUI createUI( JComponent c ) {
|
||||||
return new FlatPasswordFieldUI();
|
return new FlatPasswordFieldUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getPropertyPrefix() {
|
||||||
|
return "PasswordField";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void installDefaults() {
|
protected void installDefaults() {
|
||||||
super.installDefaults();
|
super.installDefaults();
|
||||||
|
|
||||||
String prefix = getPropertyPrefix();
|
String prefix = getPropertyPrefix();
|
||||||
minimumWidth = UIManager.getInt( "Component.minimumWidth" );
|
Character echoChar = (Character) UIManager.get( prefix + ".echoChar" );
|
||||||
isIntelliJTheme = UIManager.getBoolean( "Component.isIntelliJTheme" );
|
if( echoChar != null )
|
||||||
placeholderForeground = UIManager.getColor( prefix + ".placeholderForeground" );
|
LookAndFeel.installProperty( getComponent(), "echoChar", echoChar );
|
||||||
|
|
||||||
showCapsLock = UIManager.getBoolean( "PasswordField.showCapsLock" );
|
showCapsLock = UIManager.getBoolean( "PasswordField.showCapsLock" );
|
||||||
capsLockIcon = UIManager.getIcon( "PasswordField.capsLockIcon" );
|
capsLockIcon = UIManager.getIcon( "PasswordField.capsLockIcon" );
|
||||||
|
|
||||||
LookAndFeel.installProperty( getComponent(), "opaque", false );
|
|
||||||
|
|
||||||
MigLayoutVisualPadding.install( getComponent() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void uninstallDefaults() {
|
protected void uninstallDefaults() {
|
||||||
super.uninstallDefaults();
|
super.uninstallDefaults();
|
||||||
|
|
||||||
placeholderForeground = null;
|
|
||||||
capsLockIcon = null;
|
capsLockIcon = null;
|
||||||
|
|
||||||
MigLayoutVisualPadding.uninstall( getComponent() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void installListeners() {
|
protected void installListeners() {
|
||||||
super.installListeners();
|
super.installListeners();
|
||||||
|
|
||||||
focusListener = new FlatUIUtils.RepaintFocusListener( getComponent() );
|
// update caps lock indicator
|
||||||
capsLockListener = new KeyAdapter() {
|
capsLockListener = new KeyAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void keyPressed( KeyEvent e ) {
|
public void keyPressed( KeyEvent e ) {
|
||||||
@@ -124,12 +124,13 @@ public class FlatPasswordFieldUI
|
|||||||
repaint( e );
|
repaint( e );
|
||||||
}
|
}
|
||||||
private void repaint( KeyEvent e ) {
|
private void repaint( KeyEvent e ) {
|
||||||
if( e.getKeyCode() == KeyEvent.VK_CAPS_LOCK )
|
if( e.getKeyCode() == KeyEvent.VK_CAPS_LOCK ) {
|
||||||
e.getComponent().repaint();
|
e.getComponent().repaint();
|
||||||
|
scrollCaretToVisible();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
getComponent().addFocusListener( focusListener );
|
|
||||||
getComponent().addKeyListener( capsLockListener );
|
getComponent().addKeyListener( capsLockListener );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,59 +138,74 @@ public class FlatPasswordFieldUI
|
|||||||
protected void uninstallListeners() {
|
protected void uninstallListeners() {
|
||||||
super.uninstallListeners();
|
super.uninstallListeners();
|
||||||
|
|
||||||
getComponent().removeFocusListener( focusListener );
|
|
||||||
getComponent().removeKeyListener( capsLockListener );
|
getComponent().removeKeyListener( capsLockListener );
|
||||||
focusListener = null;
|
|
||||||
capsLockListener = null;
|
capsLockListener = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Caret createCaret() {
|
protected void installKeyboardActions() {
|
||||||
return new FlatCaret( UIManager.getString( "TextComponent.selectAllOnFocusPolicy" ),
|
super.installKeyboardActions();
|
||||||
UIManager.getBoolean( "TextComponent.selectAllOnMouseClick" ) );
|
|
||||||
|
// 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
|
@Override
|
||||||
protected void propertyChange( PropertyChangeEvent e ) {
|
public View create( Element elem ) {
|
||||||
super.propertyChange( e );
|
return new PasswordView( elem );
|
||||||
FlatTextFieldUI.propertyChange( getComponent(), e );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paintSafely( Graphics g ) {
|
protected void paintSafely( Graphics g ) {
|
||||||
FlatTextFieldUI.paintBackground( g, getComponent(), isIntelliJTheme );
|
// safe and restore clipping area because super.paintSafely() modifies it
|
||||||
FlatTextFieldUI.paintPlaceholder( g, getComponent(), placeholderForeground );
|
// and the caps lock icon would be truncated
|
||||||
paintCapsLock( g );
|
Shape oldClip = g.getClip();
|
||||||
|
super.paintSafely( g );
|
||||||
|
g.setClip( oldClip );
|
||||||
|
|
||||||
super.paintSafely( HiDPIUtils.createGraphicsTextYCorrection( (Graphics2D) g ) );
|
paintCapsLock( g );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void paintCapsLock( Graphics g ) {
|
protected void paintCapsLock( Graphics g ) {
|
||||||
if( !showCapsLock )
|
if( !isCapsLockVisible() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
JTextComponent c = getComponent();
|
JTextComponent c = getComponent();
|
||||||
if( !FlatUIUtils.isPermanentFocusOwner( c ) ||
|
|
||||||
!Toolkit.getDefaultToolkit().getLockingKeyState( KeyEvent.VK_CAPS_LOCK ) )
|
|
||||||
return;
|
|
||||||
|
|
||||||
int y = (c.getHeight() - capsLockIcon.getIconHeight()) / 2;
|
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 );
|
capsLockIcon.paintIcon( c, g, x, y );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
protected void paintBackground( Graphics g ) {
|
* @since 1.4
|
||||||
// background is painted elsewhere
|
*/
|
||||||
|
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
|
@Override
|
||||||
public Dimension getPreferredSize( JComponent c ) {
|
protected Insets getPadding() {
|
||||||
return FlatTextFieldUI.applyMinimumWidth( c, super.getPreferredSize( c ), minimumWidth );
|
Insets padding = super.getPadding();
|
||||||
}
|
if( !isCapsLockVisible() )
|
||||||
|
return padding;
|
||||||
|
|
||||||
@Override
|
boolean ltr = getComponent().getComponentOrientation().isLeftToRight();
|
||||||
public Dimension getMinimumSize( JComponent c ) {
|
int iconWidth = capsLockIcon.getIconWidth();
|
||||||
return FlatTextFieldUI.applyMinimumWidth( c, super.getMinimumSize( c ), minimumWidth );
|
return FlatUIUtils.addInsets( padding, new Insets( 0, ltr ? 0 : iconWidth, 0, ltr ? iconWidth : 0 ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,11 +20,16 @@ import java.awt.Color;
|
|||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.Container;
|
import java.awt.Container;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
|
import java.awt.GraphicsConfiguration;
|
||||||
|
import java.awt.GraphicsDevice;
|
||||||
|
import java.awt.GraphicsEnvironment;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
import java.awt.MouseInfo;
|
import java.awt.MouseInfo;
|
||||||
import java.awt.Panel;
|
import java.awt.Panel;
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
|
import java.awt.PointerInfo;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
|
import java.awt.Toolkit;
|
||||||
import java.awt.Window;
|
import java.awt.Window;
|
||||||
import java.awt.event.ComponentEvent;
|
import java.awt.event.ComponentEvent;
|
||||||
import java.awt.event.ComponentListener;
|
import java.awt.event.ComponentListener;
|
||||||
@@ -39,6 +44,7 @@ import javax.swing.Popup;
|
|||||||
import javax.swing.PopupFactory;
|
import javax.swing.PopupFactory;
|
||||||
import javax.swing.RootPaneContainer;
|
import javax.swing.RootPaneContainer;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
|
import javax.swing.ToolTipManager;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.border.Border;
|
import javax.swing.border.Border;
|
||||||
import com.formdev.flatlaf.FlatClientProperties;
|
import com.formdev.flatlaf.FlatClientProperties;
|
||||||
@@ -62,7 +68,7 @@ public class FlatPopupFactory
|
|||||||
public Popup getPopup( Component owner, Component contents, int x, int y )
|
public Popup getPopup( Component owner, Component contents, int x, int y )
|
||||||
throws IllegalArgumentException
|
throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
Point pt = fixToolTipLocation( contents, x, y );
|
Point pt = fixToolTipLocation( owner, contents, x, y );
|
||||||
if( pt != null ) {
|
if( pt != null ) {
|
||||||
x = pt.x;
|
x = pt.x;
|
||||||
y = pt.y;
|
y = pt.y;
|
||||||
@@ -115,6 +121,10 @@ public class FlatPopupFactory
|
|||||||
popupWindow.getGraphicsConfiguration() == owner.getGraphicsConfiguration() )
|
popupWindow.getGraphicsConfiguration() == owner.getGraphicsConfiguration() )
|
||||||
return popup;
|
return popup;
|
||||||
|
|
||||||
|
// avoid endless loop (should newer happen; PopupFactory cache size is 5)
|
||||||
|
if( ++count > 10 )
|
||||||
|
return popup;
|
||||||
|
|
||||||
// remove contents component from popup window
|
// remove contents component from popup window
|
||||||
if( popupWindow instanceof JWindow )
|
if( popupWindow instanceof JWindow )
|
||||||
((JWindow)popupWindow).getContentPane().removeAll();
|
((JWindow)popupWindow).getContentPane().removeAll();
|
||||||
@@ -122,10 +132,6 @@ public class FlatPopupFactory
|
|||||||
// dispose unused popup
|
// dispose unused popup
|
||||||
// (do not invoke popup.hide() because this would cache the popup window)
|
// (do not invoke popup.hide() because this would cache the popup window)
|
||||||
popupWindow.dispose();
|
popupWindow.dispose();
|
||||||
|
|
||||||
// avoid endless loop (should newer happen; PopupFactory cache size is 5)
|
|
||||||
if( ++count > 10 )
|
|
||||||
return popup;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,17 +212,21 @@ public class FlatPopupFactory
|
|||||||
/**
|
/**
|
||||||
* Usually ToolTipManager places a tooltip at (mouseLocation.x, mouseLocation.y + 20).
|
* Usually ToolTipManager places a tooltip at (mouseLocation.x, mouseLocation.y + 20).
|
||||||
* In case that the tooltip would be partly outside of the screen,
|
* 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.
|
* But this can place the tooltip under the mouse location and hide the owner component.
|
||||||
* <p>
|
* <p>
|
||||||
* This method checks whether the current mouse location is within tooltip bounds
|
* This method checks whether the current mouse location is within tooltip bounds
|
||||||
* and corrects the y-location so that the tooltip is placed above the mouse location.
|
* and corrects the y-location so that the tooltip is placed above the mouse location.
|
||||||
*/
|
*/
|
||||||
private Point fixToolTipLocation( Component contents, int x, int y ) {
|
private Point fixToolTipLocation( Component owner, Component contents, int x, int y ) {
|
||||||
if( !(contents instanceof JToolTip) || !wasInvokedFromToolTipManager() )
|
if( !(contents instanceof JToolTip) || !wasInvokedFromToolTipManager() )
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
Point mouseLocation = MouseInfo.getPointerInfo().getLocation();
|
PointerInfo pointerInfo = MouseInfo.getPointerInfo();
|
||||||
|
if( pointerInfo == null )
|
||||||
|
return null;
|
||||||
|
|
||||||
|
Point mouseLocation = pointerInfo.getLocation();
|
||||||
Dimension tipSize = contents.getPreferredSize();
|
Dimension tipSize = contents.getPreferredSize();
|
||||||
|
|
||||||
// check whether mouse location is within tooltip bounds
|
// check whether mouse location is within tooltip bounds
|
||||||
@@ -224,18 +234,34 @@ public class FlatPopupFactory
|
|||||||
if( !tipBounds.contains( mouseLocation ) )
|
if( !tipBounds.contains( mouseLocation ) )
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
// place tooltip above mouse location
|
// find GraphicsConfiguration at mouse location (similar to ToolTipManager.getDrawingGC())
|
||||||
return new Point( x, mouseLocation.y - tipSize.height - UIScale.scale( 20 ) );
|
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() {
|
private boolean wasInvokedFromToolTipManager() {
|
||||||
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
|
return StackUtils.wasInvokedFrom( ToolTipManager.class.getName(), "showTipWindow", 8 );
|
||||||
for( StackTraceElement stackTraceElement : stackTrace ) {
|
|
||||||
if( "javax.swing.ToolTipManager".equals( stackTraceElement.getClassName() ) &&
|
|
||||||
"showTipWindow".equals( stackTraceElement.getMethodName() ) )
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//---- class NonFlashingPopup ---------------------------------------------
|
//---- class NonFlashingPopup ---------------------------------------------
|
||||||
@@ -463,6 +489,9 @@ public class FlatPopupFactory
|
|||||||
JLayeredPane layeredPane = ((RootPaneContainer)window).getLayeredPane();
|
JLayeredPane layeredPane = ((RootPaneContainer)window).getLayeredPane();
|
||||||
layeredPane.add( dropShadowPanel, JLayeredPane.POPUP_LAYER, 0 );
|
layeredPane.add( dropShadowPanel, JLayeredPane.POPUP_LAYER, 0 );
|
||||||
|
|
||||||
|
moveMediumWeightDropShadow();
|
||||||
|
resizeMediumWeightDropShadow();
|
||||||
|
|
||||||
mediumPanelListener = new ComponentListener() {
|
mediumPanelListener = new ComponentListener() {
|
||||||
@Override
|
@Override
|
||||||
public void componentShown( ComponentEvent e ) {
|
public void componentShown( ComponentEvent e ) {
|
||||||
@@ -478,17 +507,12 @@ public class FlatPopupFactory
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void componentMoved( ComponentEvent e ) {
|
public void componentMoved( ComponentEvent e ) {
|
||||||
if( dropShadowPanel != null && mediumWeightPanel != null ) {
|
moveMediumWeightDropShadow();
|
||||||
Point location = mediumWeightPanel.getLocation();
|
|
||||||
Insets insets = dropShadowPanel.getInsets();
|
|
||||||
dropShadowPanel.setLocation( location.x - insets.left, location.y - insets.top );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void componentResized( ComponentEvent e ) {
|
public void componentResized( ComponentEvent e ) {
|
||||||
if( dropShadowPanel != null )
|
resizeMediumWeightDropShadow();
|
||||||
dropShadowPanel.setSize( FlatUIUtils.addInsets( mediumWeightPanel.getSize(), dropShadowPanel.getInsets() ) );
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
mediumWeightPanel.addComponentListener( mediumPanelListener );
|
mediumWeightPanel.addComponentListener( mediumPanelListener );
|
||||||
@@ -504,5 +528,18 @@ public class FlatPopupFactory
|
|||||||
parent.repaint( bounds.x, bounds.y, bounds.width, bounds.height );
|
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() ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ import javax.swing.plaf.ComponentUI;
|
|||||||
*
|
*
|
||||||
* <!-- BasicSeparatorUI -->
|
* <!-- BasicSeparatorUI -->
|
||||||
*
|
*
|
||||||
* @uiDefault PopupMenuSeparator.background Color unused
|
* @uiDefault Separator.background Color unused
|
||||||
* @uiDefault PopupMenuSeparator.foreground Color
|
* @uiDefault Separator.foreground Color
|
||||||
*
|
*
|
||||||
* <!-- FlatSeparatorUI -->
|
* <!-- FlatSeparatorUI -->
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -18,11 +18,14 @@ package com.formdev.flatlaf.ui;
|
|||||||
|
|
||||||
import static com.formdev.flatlaf.util.UIScale.scale;
|
import static com.formdev.flatlaf.util.UIScale.scale;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
import java.awt.Container;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
|
import java.util.Objects;
|
||||||
import javax.swing.AbstractButton;
|
import javax.swing.AbstractButton;
|
||||||
|
import javax.swing.CellRendererPane;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.LookAndFeel;
|
import javax.swing.LookAndFeel;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
@@ -120,10 +123,11 @@ public class FlatRadioButtonUI
|
|||||||
public void paint( Graphics g, JComponent c ) {
|
public void paint( Graphics g, JComponent c ) {
|
||||||
// fill background even if not opaque if
|
// fill background even if not opaque if
|
||||||
// - contentAreaFilled is true and
|
// - 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() &&
|
if( !c.isOpaque() &&
|
||||||
((AbstractButton)c).isContentAreaFilled() &&
|
((AbstractButton)c).isContentAreaFilled() &&
|
||||||
!defaultBackground.equals( c.getBackground() ) )
|
!Objects.equals( c.getBackground(), getDefaultBackground( c ) ) )
|
||||||
{
|
{
|
||||||
g.setColor( c.getBackground() );
|
g.setColor( c.getBackground() );
|
||||||
g.fillRect( 0, 0, c.getWidth(), c.getHeight() );
|
g.fillRect( 0, 0, c.getWidth(), c.getHeight() );
|
||||||
@@ -160,6 +164,18 @@ public class FlatRadioButtonUI
|
|||||||
FlatButtonUI.paintText( g, b, textRect, text, b.isEnabled() ? b.getForeground() : disabledText );
|
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 ) {
|
private int getIconFocusWidth( JComponent c ) {
|
||||||
AbstractButton b = (AbstractButton) c;
|
AbstractButton b = (AbstractButton) c;
|
||||||
return (b.getIcon() == null && getDefaultIcon() instanceof FlatCheckBoxIcon)
|
return (b.getIcon() == null && getDefaultIcon() instanceof FlatCheckBoxIcon)
|
||||||
|
|||||||
@@ -27,7 +27,11 @@ import java.awt.Insets;
|
|||||||
import java.awt.LayoutManager;
|
import java.awt.LayoutManager;
|
||||||
import java.awt.LayoutManager2;
|
import java.awt.LayoutManager2;
|
||||||
import java.awt.Window;
|
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.PropertyChangeEvent;
|
||||||
|
import java.beans.PropertyChangeListener;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JDialog;
|
import javax.swing.JDialog;
|
||||||
@@ -36,6 +40,7 @@ import javax.swing.JLayeredPane;
|
|||||||
import javax.swing.JMenuBar;
|
import javax.swing.JMenuBar;
|
||||||
import javax.swing.JRootPane;
|
import javax.swing.JRootPane;
|
||||||
import javax.swing.LookAndFeel;
|
import javax.swing.LookAndFeel;
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.border.Border;
|
import javax.swing.border.Border;
|
||||||
import javax.swing.plaf.BorderUIResource;
|
import javax.swing.plaf.BorderUIResource;
|
||||||
@@ -79,6 +84,8 @@ public class FlatRootPaneUI
|
|||||||
|
|
||||||
private Object nativeWindowBorderData;
|
private Object nativeWindowBorderData;
|
||||||
private LayoutManager oldLayout;
|
private LayoutManager oldLayout;
|
||||||
|
private PropertyChangeListener ancestorListener;
|
||||||
|
private ComponentListener componentListener;
|
||||||
|
|
||||||
public static ComponentUI createUI( JComponent c ) {
|
public static ComponentUI createUI( JComponent c ) {
|
||||||
return new FlatRootPaneUI();
|
return new FlatRootPaneUI();
|
||||||
@@ -136,6 +143,61 @@ public class FlatRootPaneUI
|
|||||||
c.putClientProperty( "jetbrains.awt.windowDarkAppearance", FlatLaf.isLafDark() );
|
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
|
* @since 1.1.2
|
||||||
*/
|
*/
|
||||||
@@ -306,7 +368,7 @@ public class FlatRootPaneUI
|
|||||||
? getSizeFunc.apply( rootPane.getContentPane() )
|
? getSizeFunc.apply( rootPane.getContentPane() )
|
||||||
: rootPane.getSize();
|
: 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;
|
int height = titlePaneSize.height + contentSize.height;
|
||||||
if( titlePane == null || !titlePane.isMenuBarEmbedded() ) {
|
if( titlePane == null || !titlePane.isMenuBarEmbedded() ) {
|
||||||
JMenuBar menuBar = rootPane.getJMenuBar();
|
JMenuBar menuBar = rootPane.getJMenuBar();
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package com.formdev.flatlaf.ui;
|
|||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
|
import java.awt.KeyboardFocusManager;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.awt.event.ContainerEvent;
|
import java.awt.event.ContainerEvent;
|
||||||
import java.awt.event.ContainerListener;
|
import java.awt.event.ContainerListener;
|
||||||
@@ -34,11 +35,13 @@ import javax.swing.JComponent;
|
|||||||
import javax.swing.JScrollBar;
|
import javax.swing.JScrollBar;
|
||||||
import javax.swing.JScrollPane;
|
import javax.swing.JScrollPane;
|
||||||
import javax.swing.JTable;
|
import javax.swing.JTable;
|
||||||
|
import javax.swing.JTree;
|
||||||
import javax.swing.JViewport;
|
import javax.swing.JViewport;
|
||||||
import javax.swing.LookAndFeel;
|
import javax.swing.LookAndFeel;
|
||||||
import javax.swing.ScrollPaneConstants;
|
import javax.swing.ScrollPaneConstants;
|
||||||
import javax.swing.Scrollable;
|
import javax.swing.Scrollable;
|
||||||
import javax.swing.SwingConstants;
|
import javax.swing.SwingConstants;
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
import javax.swing.plaf.basic.BasicScrollPaneUI;
|
import javax.swing.plaf.basic.BasicScrollPaneUI;
|
||||||
@@ -329,6 +332,31 @@ public class FlatScrollPaneUI
|
|||||||
paint( g, c );
|
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 ------------------------------------------------------
|
//---- class Handler ------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -350,11 +378,13 @@ public class FlatScrollPaneUI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void focusGained( FocusEvent e ) {
|
public void focusGained( FocusEvent e ) {
|
||||||
|
// necessary to update focus border
|
||||||
scrollpane.repaint();
|
scrollpane.repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void focusLost( FocusEvent e ) {
|
public void focusLost( FocusEvent e ) {
|
||||||
|
// necessary to update focus border
|
||||||
scrollpane.repaint();
|
scrollpane.repaint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,9 +18,11 @@ package com.formdev.flatlaf.ui;
|
|||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Font;
|
||||||
import java.awt.FontMetrics;
|
import java.awt.FontMetrics;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Insets;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.awt.Shape;
|
import java.awt.Shape;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
@@ -176,9 +178,27 @@ public class FlatSliderUI
|
|||||||
if( slider.getOrientation() == JSlider.VERTICAL )
|
if( slider.getOrientation() == JSlider.VERTICAL )
|
||||||
return -1;
|
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
|
// compute a baseline so that the track is vertically centered
|
||||||
FontMetrics fm = slider.getFontMetrics( slider.getFont() );
|
return trackY + Math.round( (trackHeight - fm.getHeight()) / 2f ) + fm.getAscent() - 1;
|
||||||
return trackRect.y + Math.round( (trackRect.height - fm.getHeight()) / 2f ) + fm.getAscent() - 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import java.awt.Color;
|
|||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.Container;
|
import java.awt.Container;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
|
import java.awt.FontMetrics;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
@@ -39,6 +40,7 @@ import javax.swing.LookAndFeel;
|
|||||||
import javax.swing.SwingConstants;
|
import javax.swing.SwingConstants;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
|
import javax.swing.plaf.UIResource;
|
||||||
import javax.swing.plaf.basic.BasicSpinnerUI;
|
import javax.swing.plaf.basic.BasicSpinnerUI;
|
||||||
import com.formdev.flatlaf.FlatClientProperties;
|
import com.formdev.flatlaf.FlatClientProperties;
|
||||||
|
|
||||||
@@ -65,6 +67,7 @@ import com.formdev.flatlaf.FlatClientProperties;
|
|||||||
* @uiDefault Component.disabledBorderColor Color
|
* @uiDefault Component.disabledBorderColor Color
|
||||||
* @uiDefault Spinner.disabledBackground Color
|
* @uiDefault Spinner.disabledBackground Color
|
||||||
* @uiDefault Spinner.disabledForeground Color
|
* @uiDefault Spinner.disabledForeground Color
|
||||||
|
* @uiDefault Spinner.focusedBackground Color optional
|
||||||
* @uiDefault Spinner.buttonBackground Color
|
* @uiDefault Spinner.buttonBackground Color
|
||||||
* @uiDefault Spinner.buttonArrowColor Color
|
* @uiDefault Spinner.buttonArrowColor Color
|
||||||
* @uiDefault Spinner.buttonDisabledArrowColor Color
|
* @uiDefault Spinner.buttonDisabledArrowColor Color
|
||||||
@@ -87,6 +90,7 @@ public class FlatSpinnerUI
|
|||||||
protected Color disabledBorderColor;
|
protected Color disabledBorderColor;
|
||||||
protected Color disabledBackground;
|
protected Color disabledBackground;
|
||||||
protected Color disabledForeground;
|
protected Color disabledForeground;
|
||||||
|
protected Color focusedBackground;
|
||||||
protected Color buttonBackground;
|
protected Color buttonBackground;
|
||||||
protected Color buttonArrowColor;
|
protected Color buttonArrowColor;
|
||||||
protected Color buttonDisabledArrowColor;
|
protected Color buttonDisabledArrowColor;
|
||||||
@@ -112,6 +116,7 @@ public class FlatSpinnerUI
|
|||||||
disabledBorderColor = UIManager.getColor( "Component.disabledBorderColor" );
|
disabledBorderColor = UIManager.getColor( "Component.disabledBorderColor" );
|
||||||
disabledBackground = UIManager.getColor( "Spinner.disabledBackground" );
|
disabledBackground = UIManager.getColor( "Spinner.disabledBackground" );
|
||||||
disabledForeground = UIManager.getColor( "Spinner.disabledForeground" );
|
disabledForeground = UIManager.getColor( "Spinner.disabledForeground" );
|
||||||
|
focusedBackground = UIManager.getColor( "Spinner.focusedBackground" );
|
||||||
buttonBackground = UIManager.getColor( "Spinner.buttonBackground" );
|
buttonBackground = UIManager.getColor( "Spinner.buttonBackground" );
|
||||||
buttonArrowColor = UIManager.getColor( "Spinner.buttonArrowColor" );
|
buttonArrowColor = UIManager.getColor( "Spinner.buttonArrowColor" );
|
||||||
buttonDisabledArrowColor = UIManager.getColor( "Spinner.buttonDisabledArrowColor" );
|
buttonDisabledArrowColor = UIManager.getColor( "Spinner.buttonDisabledArrowColor" );
|
||||||
@@ -119,9 +124,6 @@ public class FlatSpinnerUI
|
|||||||
buttonPressedArrowColor = UIManager.getColor( "Spinner.buttonPressedArrowColor" );
|
buttonPressedArrowColor = UIManager.getColor( "Spinner.buttonPressedArrowColor" );
|
||||||
padding = UIManager.getInsets( "Spinner.padding" );
|
padding = UIManager.getInsets( "Spinner.padding" );
|
||||||
|
|
||||||
// scale
|
|
||||||
padding = scale( padding );
|
|
||||||
|
|
||||||
MigLayoutVisualPadding.install( spinner );
|
MigLayoutVisualPadding.install( spinner );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,6 +135,7 @@ public class FlatSpinnerUI
|
|||||||
disabledBorderColor = null;
|
disabledBorderColor = null;
|
||||||
disabledBackground = null;
|
disabledBackground = null;
|
||||||
disabledForeground = null;
|
disabledForeground = null;
|
||||||
|
focusedBackground = null;
|
||||||
buttonBackground = null;
|
buttonBackground = null;
|
||||||
buttonArrowColor = null;
|
buttonArrowColor = null;
|
||||||
buttonDisabledArrowColor = null;
|
buttonDisabledArrowColor = null;
|
||||||
@@ -172,14 +175,7 @@ public class FlatSpinnerUI
|
|||||||
@Override
|
@Override
|
||||||
protected JComponent createEditor() {
|
protected JComponent createEditor() {
|
||||||
JComponent editor = super.createEditor();
|
JComponent editor = super.createEditor();
|
||||||
|
configureEditor( editor );
|
||||||
// explicitly make non-opaque
|
|
||||||
editor.setOpaque( false );
|
|
||||||
JTextField textField = getEditorTextField( editor );
|
|
||||||
if( textField != null )
|
|
||||||
textField.setOpaque( false );
|
|
||||||
|
|
||||||
updateEditorColors();
|
|
||||||
return editor;
|
return editor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,8 +183,21 @@ public class FlatSpinnerUI
|
|||||||
protected void replaceEditor( JComponent oldEditor, JComponent newEditor ) {
|
protected void replaceEditor( JComponent oldEditor, JComponent newEditor ) {
|
||||||
super.replaceEditor( oldEditor, newEditor );
|
super.replaceEditor( oldEditor, newEditor );
|
||||||
|
|
||||||
|
configureEditor( newEditor );
|
||||||
|
|
||||||
removeEditorFocusListener( oldEditor );
|
removeEditorFocusListener( oldEditor );
|
||||||
addEditorFocusListener( newEditor );
|
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();
|
updateEditorColors();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,6 +213,12 @@ public class FlatSpinnerUI
|
|||||||
textField.removeFocusListener( getHandler() );
|
textField.removeFocusListener( getHandler() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateEditorPadding() {
|
||||||
|
JTextField textField = getEditorTextField( spinner.getEditor() );
|
||||||
|
if( textField != null )
|
||||||
|
textField.putClientProperty( FlatClientProperties.TEXT_FIELD_PADDING, padding );
|
||||||
|
}
|
||||||
|
|
||||||
private void updateEditorColors() {
|
private void updateEditorColors() {
|
||||||
JTextField textField = getEditorTextField( spinner.getEditor() );
|
JTextField textField = getEditorTextField( spinner.getEditor() );
|
||||||
if( textField != null ) {
|
if( textField != null ) {
|
||||||
@@ -221,10 +236,34 @@ public class FlatSpinnerUI
|
|||||||
: null;
|
: 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 ) {
|
protected Color getBackground( boolean enabled ) {
|
||||||
return enabled
|
if( enabled ) {
|
||||||
? spinner.getBackground()
|
Color background = spinner.getBackground();
|
||||||
: (isIntelliJTheme ? FlatUIUtils.getParentBackground( spinner ) : disabledBackground);
|
|
||||||
|
// 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 ) {
|
protected Color getForeground( boolean enabled ) {
|
||||||
@@ -250,7 +289,7 @@ public class FlatSpinnerUI
|
|||||||
FlatArrowButton button = new FlatArrowButton( direction, arrowType, buttonArrowColor,
|
FlatArrowButton button = new FlatArrowButton( direction, arrowType, buttonArrowColor,
|
||||||
buttonDisabledArrowColor, buttonHoverArrowColor, null, buttonPressedArrowColor, null );
|
buttonDisabledArrowColor, buttonHoverArrowColor, null, buttonPressedArrowColor, null );
|
||||||
button.setName( name );
|
button.setName( name );
|
||||||
button.setYOffset( (direction == SwingConstants.NORTH) ? 1 : -1 );
|
button.setYOffset( (direction == SwingConstants.NORTH) ? 1.25f : -1.25f );
|
||||||
if( direction == SwingConstants.NORTH )
|
if( direction == SwingConstants.NORTH )
|
||||||
installNextButtonListeners( button );
|
installNextButtonListeners( button );
|
||||||
else
|
else
|
||||||
@@ -344,6 +383,7 @@ public class FlatSpinnerUI
|
|||||||
@Override
|
@Override
|
||||||
public Dimension preferredLayoutSize( Container parent ) {
|
public Dimension preferredLayoutSize( Container parent ) {
|
||||||
Insets insets = parent.getInsets();
|
Insets insets = parent.getInsets();
|
||||||
|
Insets padding = scale( FlatSpinnerUI.this.padding );
|
||||||
Dimension editorSize = (editor != null) ? editor.getPreferredSize() : new Dimension( 0, 0 );
|
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
|
// 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( nextButton == null && previousButton == null ) {
|
||||||
if( editor != null )
|
if( editor != null )
|
||||||
editor.setBounds( FlatUIUtils.subtractInsets( r, padding ) );
|
editor.setBounds( r );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle editorRect = new Rectangle( r );
|
Rectangle editorRect = new Rectangle( r );
|
||||||
Rectangle buttonsRect = new Rectangle( r );
|
Rectangle buttonsRect = new Rectangle( r );
|
||||||
|
|
||||||
|
// 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)
|
// make button area square (if spinner has preferred height)
|
||||||
int buttonsWidth = parent.getPreferredSize().height - insets.top - insets.bottom;
|
int buttonsWidth = Math.min( parent.getPreferredSize().height - insets.top - insets.bottom, maxButtonWidth );
|
||||||
buttonsRect.width = buttonsWidth;
|
buttonsRect.width = buttonsWidth;
|
||||||
|
|
||||||
if( parent.getComponentOrientation().isLeftToRight() ) {
|
if( parent.getComponentOrientation().isLeftToRight() ) {
|
||||||
@@ -388,7 +432,7 @@ public class FlatSpinnerUI
|
|||||||
}
|
}
|
||||||
|
|
||||||
if( editor != null )
|
if( editor != null )
|
||||||
editor.setBounds( FlatUIUtils.subtractInsets( editorRect, padding ) );
|
editor.setBounds( editorRect );
|
||||||
|
|
||||||
int nextHeight = (buttonsRect.height / 2) + (buttonsRect.height % 2); // round up
|
int nextHeight = (buttonsRect.height / 2) + (buttonsRect.height % 2); // round up
|
||||||
if( nextButton != null )
|
if( nextButton != null )
|
||||||
@@ -405,6 +449,7 @@ public class FlatSpinnerUI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void focusGained( FocusEvent e ) {
|
public void focusGained( FocusEvent e ) {
|
||||||
|
// necessary to update focus border
|
||||||
spinner.repaint();
|
spinner.repaint();
|
||||||
|
|
||||||
// if spinner gained focus, transfer it to the editor text field
|
// if spinner gained focus, transfer it to the editor text field
|
||||||
@@ -417,6 +462,7 @@ public class FlatSpinnerUI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void focusLost( FocusEvent e ) {
|
public void focusLost( FocusEvent e ) {
|
||||||
|
// necessary to update focus border
|
||||||
spinner.repaint();
|
spinner.repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -58,6 +58,8 @@ import java.util.function.BiConsumer;
|
|||||||
import java.util.function.IntConsumer;
|
import java.util.function.IntConsumer;
|
||||||
import javax.accessibility.Accessible;
|
import javax.accessibility.Accessible;
|
||||||
import javax.accessibility.AccessibleContext;
|
import javax.accessibility.AccessibleContext;
|
||||||
|
import javax.swing.Action;
|
||||||
|
import javax.swing.ActionMap;
|
||||||
import javax.swing.ButtonModel;
|
import javax.swing.ButtonModel;
|
||||||
import javax.swing.Icon;
|
import javax.swing.Icon;
|
||||||
import javax.swing.JButton;
|
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
|
// the default also includes Ctrl+TAB/Ctrl+Shift+TAB, which we need to switch tabs
|
||||||
if( focusForwardTraversalKeys == null ) {
|
if( focusForwardTraversalKeys == null ) {
|
||||||
focusForwardTraversalKeys = Collections.singleton( KeyStroke.getKeyStroke( KeyEvent.VK_TAB, 0 ) );
|
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
|
// Ideally we should use `LookAndFeel.installProperty( tabPane, "focusTraversalKeysForward", keys )` here
|
||||||
// instead of `tabPane.setFocusTraversalKeys()`, but WindowsTabbedPaneUI also uses later method
|
// 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() {
|
private Handler getHandler() {
|
||||||
if( handler == null )
|
if( handler == null )
|
||||||
handler = new Handler();
|
handler = new Handler();
|
||||||
@@ -826,6 +842,17 @@ public class FlatTabbedPaneUI
|
|||||||
paintTabArea( g, tabPlacement, selectedIndex );
|
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
|
@Override
|
||||||
protected void paintTab( Graphics g, int tabPlacement, Rectangle[] rects,
|
protected void paintTab( Graphics g, int tabPlacement, Rectangle[] rects,
|
||||||
int tabIndex, Rectangle iconRect, Rectangle textRect )
|
int tabIndex, Rectangle iconRect, Rectangle textRect )
|
||||||
@@ -2959,4 +2986,51 @@ public class FlatTabbedPaneUI
|
|||||||
scrollBackwardButtonPrefSize = backwardButton.getPreferredSize();
|
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 );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,28 +18,27 @@ package com.formdev.flatlaf.ui;
|
|||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.Container;
|
import java.awt.Cursor;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.geom.Rectangle2D;
|
import java.awt.geom.Rectangle2D;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import javax.swing.Icon;
|
import javax.swing.Icon;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JScrollPane;
|
|
||||||
import javax.swing.JTable;
|
import javax.swing.JTable;
|
||||||
import javax.swing.ScrollPaneConstants;
|
|
||||||
import javax.swing.SwingConstants;
|
import javax.swing.SwingConstants;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.border.Border;
|
import javax.swing.border.Border;
|
||||||
|
import javax.swing.event.MouseInputListener;
|
||||||
import javax.swing.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
import javax.swing.plaf.UIResource;
|
import javax.swing.plaf.UIResource;
|
||||||
import javax.swing.plaf.basic.BasicTableHeaderUI;
|
import javax.swing.plaf.basic.BasicTableHeaderUI;
|
||||||
import javax.swing.table.TableCellRenderer;
|
import javax.swing.table.TableCellRenderer;
|
||||||
import javax.swing.table.TableColumn;
|
|
||||||
import javax.swing.table.TableColumnModel;
|
import javax.swing.table.TableColumnModel;
|
||||||
import com.formdev.flatlaf.util.UIScale;
|
import com.formdev.flatlaf.util.UIScale;
|
||||||
|
|
||||||
@@ -54,17 +53,22 @@ import com.formdev.flatlaf.util.UIScale;
|
|||||||
*
|
*
|
||||||
* <!-- FlatTableHeaderUI -->
|
* <!-- FlatTableHeaderUI -->
|
||||||
*
|
*
|
||||||
* @uiDefault TableHeader.separatorColor Color
|
|
||||||
* @uiDefault TableHeader.bottomSeparatorColor Color
|
* @uiDefault TableHeader.bottomSeparatorColor Color
|
||||||
* @uiDefault TableHeader.height int
|
* @uiDefault TableHeader.height int
|
||||||
* @uiDefault TableHeader.sortIconPosition String right (default), left, top or bottom
|
* @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
|
* @author Karl Tauber
|
||||||
*/
|
*/
|
||||||
public class FlatTableHeaderUI
|
public class FlatTableHeaderUI
|
||||||
extends BasicTableHeaderUI
|
extends BasicTableHeaderUI
|
||||||
{
|
{
|
||||||
protected Color separatorColor;
|
|
||||||
protected Color bottomSeparatorColor;
|
protected Color bottomSeparatorColor;
|
||||||
protected int height;
|
protected int height;
|
||||||
protected int sortIconPosition;
|
protected int sortIconPosition;
|
||||||
@@ -77,7 +81,6 @@ public class FlatTableHeaderUI
|
|||||||
protected void installDefaults() {
|
protected void installDefaults() {
|
||||||
super.installDefaults();
|
super.installDefaults();
|
||||||
|
|
||||||
separatorColor = UIManager.getColor( "TableHeader.separatorColor" );
|
|
||||||
bottomSeparatorColor = UIManager.getColor( "TableHeader.bottomSeparatorColor" );
|
bottomSeparatorColor = UIManager.getColor( "TableHeader.bottomSeparatorColor" );
|
||||||
height = UIManager.getInt( "TableHeader.height" );
|
height = UIManager.getInt( "TableHeader.height" );
|
||||||
switch( Objects.toString( UIManager.getString( "TableHeader.sortIconPosition" ), "right" ) ) {
|
switch( Objects.toString( UIManager.getString( "TableHeader.sortIconPosition" ), "right" ) ) {
|
||||||
@@ -93,27 +96,49 @@ public class FlatTableHeaderUI
|
|||||||
protected void uninstallDefaults() {
|
protected void uninstallDefaults() {
|
||||||
super.uninstallDefaults();
|
super.uninstallDefaults();
|
||||||
|
|
||||||
separatorColor = null;
|
|
||||||
bottomSeparatorColor = 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
|
@Override
|
||||||
public void paint( Graphics g, JComponent c ) {
|
public void paint( Graphics g, JComponent c ) {
|
||||||
if( header.getColumnModel().getColumnCount() <= 0 )
|
TableColumnModel columnModel = header.getColumnModel();
|
||||||
|
if( columnModel.getColumnCount() <= 0 )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// do not paint borders if JTableHeader.setDefaultRenderer() was used
|
// 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( totalWidth < header.getWidth() ) {
|
||||||
|
// do not paint bottom separator if JTableHeader.setDefaultRenderer() was used
|
||||||
TableCellRenderer defaultRenderer = header.getDefaultRenderer();
|
TableCellRenderer defaultRenderer = header.getDefaultRenderer();
|
||||||
boolean paintBorders = isSystemDefaultRenderer( defaultRenderer );
|
boolean paintBottomSeparator = isSystemDefaultRenderer( defaultRenderer );
|
||||||
if( !paintBorders ) {
|
if( !paintBottomSeparator && header.getTable() != null ) {
|
||||||
// check whether the renderer delegates to the system default renderer
|
// check whether the renderer delegates to the system default renderer
|
||||||
Component rendererComponent = defaultRenderer.getTableCellRendererComponent(
|
Component rendererComponent = defaultRenderer.getTableCellRendererComponent(
|
||||||
header.getTable(), "", false, false, -1, 0 );
|
header.getTable(), "", false, false, -1, 0 );
|
||||||
paintBorders = isSystemDefaultRenderer( rendererComponent );
|
paintBottomSeparator = isSystemDefaultRenderer( rendererComponent );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( paintBorders )
|
if( paintBottomSeparator ) {
|
||||||
paintColumnBorders( g, c );
|
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
|
// temporary use own default renderer if necessary
|
||||||
FlatTableCellHeaderRenderer sortIconRenderer = null;
|
FlatTableCellHeaderRenderer sortIconRenderer = null;
|
||||||
@@ -130,9 +155,6 @@ public class FlatTableHeaderUI
|
|||||||
sortIconRenderer.reset();
|
sortIconRenderer.reset();
|
||||||
header.setDefaultRenderer( sortIconRenderer.delegate );
|
header.setDefaultRenderer( sortIconRenderer.delegate );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( paintBorders )
|
|
||||||
paintDraggedColumnBorders( g, c );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isSystemDefaultRenderer( Object headerRenderer ) {
|
private boolean isSystemDefaultRenderer( Object headerRenderer ) {
|
||||||
@@ -141,17 +163,8 @@ public class FlatTableHeaderUI
|
|||||||
rendererClassName.equals( "sun.swing.FilePane$AlignableTableHeaderRenderer" );
|
rendererClassName.equals( "sun.swing.FilePane$AlignableTableHeaderRenderer" );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void paintColumnBorders( Graphics g, JComponent c ) {
|
protected void paintBottomSeparator( Graphics g, JComponent c, int x, int w ) {
|
||||||
int width = c.getWidth();
|
|
||||||
int height = c.getHeight();
|
|
||||||
float lineWidth = UIScale.scale( 1f );
|
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();
|
Graphics2D g2 = (Graphics2D) g.create();
|
||||||
try {
|
try {
|
||||||
@@ -159,78 +172,7 @@ public class FlatTableHeaderUI
|
|||||||
|
|
||||||
// paint bottom line
|
// paint bottom line
|
||||||
g2.setColor( bottomSeparatorColor );
|
g2.setColor( bottomSeparatorColor );
|
||||||
g2.fill( new Rectangle2D.Float( 0, height - lineWidth, width, lineWidth ) );
|
g2.fill( new Rectangle2D.Float( x, c.getHeight() - lineWidth, w, 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 ) );
|
|
||||||
} finally {
|
} finally {
|
||||||
g2.dispose();
|
g2.dispose();
|
||||||
}
|
}
|
||||||
@@ -244,32 +186,6 @@ public class FlatTableHeaderUI
|
|||||||
return size;
|
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 ----------------------------------
|
//---- class FlatTableCellHeaderRenderer ----------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -346,4 +262,54 @@ public class FlatTableHeaderUI
|
|||||||
return (origBorder != null) ? origBorder.isBorderOpaque() : false;
|
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() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import java.awt.Graphics2D;
|
|||||||
import java.awt.event.FocusEvent;
|
import java.awt.event.FocusEvent;
|
||||||
import java.awt.event.FocusListener;
|
import java.awt.event.FocusListener;
|
||||||
import java.awt.geom.Rectangle2D;
|
import java.awt.geom.Rectangle2D;
|
||||||
|
import java.beans.PropertyChangeListener;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JScrollPane;
|
import javax.swing.JScrollPane;
|
||||||
import javax.swing.JViewport;
|
import javax.swing.JViewport;
|
||||||
@@ -34,6 +35,7 @@ import javax.swing.UIManager;
|
|||||||
import javax.swing.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
import javax.swing.plaf.basic.BasicTableUI;
|
import javax.swing.plaf.basic.BasicTableUI;
|
||||||
import javax.swing.table.JTableHeader;
|
import javax.swing.table.JTableHeader;
|
||||||
|
import com.formdev.flatlaf.FlatClientProperties;
|
||||||
import com.formdev.flatlaf.util.Graphics2DProxy;
|
import com.formdev.flatlaf.util.Graphics2DProxy;
|
||||||
import com.formdev.flatlaf.util.SystemInfo;
|
import com.formdev.flatlaf.util.SystemInfo;
|
||||||
import com.formdev.flatlaf.util.UIScale;
|
import com.formdev.flatlaf.util.UIScale;
|
||||||
@@ -69,6 +71,7 @@ import com.formdev.flatlaf.util.UIScale;
|
|||||||
* @uiDefault Table.rowHeight int
|
* @uiDefault Table.rowHeight int
|
||||||
* @uiDefault Table.showHorizontalLines boolean
|
* @uiDefault Table.showHorizontalLines boolean
|
||||||
* @uiDefault Table.showVerticalLines boolean
|
* @uiDefault Table.showVerticalLines boolean
|
||||||
|
* @uiDefault Table.showTrailingVerticalLine boolean
|
||||||
* @uiDefault Table.intercellSpacing Dimension
|
* @uiDefault Table.intercellSpacing Dimension
|
||||||
* @uiDefault Table.selectionInactiveBackground Color
|
* @uiDefault Table.selectionInactiveBackground Color
|
||||||
* @uiDefault Table.selectionInactiveForeground Color
|
* @uiDefault Table.selectionInactiveForeground Color
|
||||||
@@ -90,6 +93,7 @@ public class FlatTableUI
|
|||||||
{
|
{
|
||||||
protected boolean showHorizontalLines;
|
protected boolean showHorizontalLines;
|
||||||
protected boolean showVerticalLines;
|
protected boolean showVerticalLines;
|
||||||
|
/** @since 1.6 */ protected boolean showTrailingVerticalLine;
|
||||||
protected Dimension intercellSpacing;
|
protected Dimension intercellSpacing;
|
||||||
|
|
||||||
protected Color selectionBackground;
|
protected Color selectionBackground;
|
||||||
@@ -101,6 +105,8 @@ public class FlatTableUI
|
|||||||
private boolean oldShowVerticalLines;
|
private boolean oldShowVerticalLines;
|
||||||
private Dimension oldIntercellSpacing;
|
private Dimension oldIntercellSpacing;
|
||||||
|
|
||||||
|
private PropertyChangeListener propertyChangeListener;
|
||||||
|
|
||||||
public static ComponentUI createUI( JComponent c ) {
|
public static ComponentUI createUI( JComponent c ) {
|
||||||
return new FlatTableUI();
|
return new FlatTableUI();
|
||||||
}
|
}
|
||||||
@@ -111,6 +117,7 @@ public class FlatTableUI
|
|||||||
|
|
||||||
showHorizontalLines = UIManager.getBoolean( "Table.showHorizontalLines" );
|
showHorizontalLines = UIManager.getBoolean( "Table.showHorizontalLines" );
|
||||||
showVerticalLines = UIManager.getBoolean( "Table.showVerticalLines" );
|
showVerticalLines = UIManager.getBoolean( "Table.showVerticalLines" );
|
||||||
|
showTrailingVerticalLine = UIManager.getBoolean( "Table.showTrailingVerticalLine" );
|
||||||
intercellSpacing = UIManager.getDimension( "Table.intercellSpacing" );
|
intercellSpacing = UIManager.getDimension( "Table.intercellSpacing" );
|
||||||
|
|
||||||
selectionBackground = UIManager.getColor( "Table.selectionBackground" );
|
selectionBackground = UIManager.getColor( "Table.selectionBackground" );
|
||||||
@@ -159,6 +166,25 @@ public class FlatTableUI
|
|||||||
table.setIntercellSpacing( oldIntercellSpacing );
|
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
|
@Override
|
||||||
protected FocusListener createFocusListener() {
|
protected FocusListener createFocusListener() {
|
||||||
return new BasicTableUI.FocusHandler() {
|
return new BasicTableUI.FocusHandler() {
|
||||||
@@ -240,7 +266,7 @@ public class FlatTableUI
|
|||||||
if( isDragging &&
|
if( isDragging &&
|
||||||
SystemInfo.isJava_9_orLater &&
|
SystemInfo.isJava_9_orLater &&
|
||||||
((horizontalLines && y1 == y2) || (verticalLines && x1 == x2)) &&
|
((horizontalLines && y1 == y2) || (verticalLines && x1 == x2)) &&
|
||||||
wasInvokedFromPaintDraggedArea() )
|
wasInvokedFromMethod( "paintDraggedArea" ) )
|
||||||
{
|
{
|
||||||
if( y1 == y2 ) {
|
if( y1 == y2 ) {
|
||||||
// horizontal grid line
|
// horizontal grid line
|
||||||
@@ -282,22 +308,8 @@ public class FlatTableUI
|
|||||||
return wasInvokedFromMethod( "paintGrid" );
|
return wasInvokedFromMethod( "paintGrid" );
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean wasInvokedFromPaintDraggedArea() {
|
|
||||||
return wasInvokedFromMethod( "paintDraggedArea" );
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean wasInvokedFromMethod( String methodName ) {
|
private boolean wasInvokedFromMethod( String methodName ) {
|
||||||
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
|
return StackUtils.wasInvokedFrom( BasicTableUI.class.getName(), methodName, 8 );
|
||||||
for( int i = 0; i < 10 || i < stackTrace.length; i++ ) {
|
|
||||||
if( "javax.swing.plaf.basic.BasicTableUI".equals( stackTrace[i].getClassName() ) ) {
|
|
||||||
String methodName2 = stackTrace[i].getMethodName();
|
|
||||||
if( "paintCell".equals( methodName2 ) )
|
|
||||||
return false;
|
|
||||||
if( methodName.equals( methodName2 ) )
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -306,6 +318,10 @@ public class FlatTableUI
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected boolean hideLastVerticalLine() {
|
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 viewport = SwingUtilities.getUnwrappedParent( table );
|
||||||
Container viewportParent = (viewport != null) ? viewport.getParent() : null;
|
Container viewportParent = (viewport != null) ? viewport.getParent() : null;
|
||||||
if( !(viewportParent instanceof JScrollPane) )
|
if( !(viewportParent instanceof JScrollPane) )
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ import java.awt.Color;
|
|||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Insets;
|
||||||
|
import java.awt.event.FocusListener;
|
||||||
import java.beans.PropertyChangeEvent;
|
import java.beans.PropertyChangeEvent;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JTextArea;
|
import javax.swing.JTextArea;
|
||||||
@@ -52,6 +54,7 @@ import com.formdev.flatlaf.util.HiDPIUtils;
|
|||||||
* @uiDefault Component.isIntelliJTheme boolean
|
* @uiDefault Component.isIntelliJTheme boolean
|
||||||
* @uiDefault TextArea.disabledBackground Color used if not enabled
|
* @uiDefault TextArea.disabledBackground Color used if not enabled
|
||||||
* @uiDefault TextArea.inactiveBackground Color used if not editable
|
* @uiDefault TextArea.inactiveBackground Color used if not editable
|
||||||
|
* @uiDefault TextArea.focusedBackground Color optional
|
||||||
*
|
*
|
||||||
* @author Karl Tauber
|
* @author Karl Tauber
|
||||||
*/
|
*/
|
||||||
@@ -63,6 +66,11 @@ public class FlatTextAreaUI
|
|||||||
protected Color background;
|
protected Color background;
|
||||||
protected Color disabledBackground;
|
protected Color disabledBackground;
|
||||||
protected Color inactiveBackground;
|
protected Color inactiveBackground;
|
||||||
|
protected Color focusedBackground;
|
||||||
|
|
||||||
|
private Insets defaultMargin;
|
||||||
|
|
||||||
|
private FocusListener focusListener;
|
||||||
|
|
||||||
public static ComponentUI createUI( JComponent c ) {
|
public static ComponentUI createUI( JComponent c ) {
|
||||||
return new FlatTextAreaUI();
|
return new FlatTextAreaUI();
|
||||||
@@ -84,6 +92,9 @@ public class FlatTextAreaUI
|
|||||||
background = UIManager.getColor( "TextArea.background" );
|
background = UIManager.getColor( "TextArea.background" );
|
||||||
disabledBackground = UIManager.getColor( "TextArea.disabledBackground" );
|
disabledBackground = UIManager.getColor( "TextArea.disabledBackground" );
|
||||||
inactiveBackground = UIManager.getColor( "TextArea.inactiveBackground" );
|
inactiveBackground = UIManager.getColor( "TextArea.inactiveBackground" );
|
||||||
|
focusedBackground = UIManager.getColor( "TextArea.focusedBackground" );
|
||||||
|
|
||||||
|
defaultMargin = UIManager.getInsets( "TextArea.margin" );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -93,6 +104,24 @@ public class FlatTextAreaUI
|
|||||||
background = null;
|
background = null;
|
||||||
disabledBackground = null;
|
disabledBackground = null;
|
||||||
inactiveBackground = 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
|
@Override
|
||||||
@@ -146,7 +175,7 @@ public class FlatTextAreaUI
|
|||||||
if( c instanceof JTextArea && ((JTextArea)c).getColumns() > 0 )
|
if( c instanceof JTextArea && ((JTextArea)c).getColumns() > 0 )
|
||||||
return size;
|
return size;
|
||||||
|
|
||||||
return FlatEditorPaneUI.applyMinimumWidth( c, size, minimumWidth );
|
return FlatEditorPaneUI.applyMinimumWidth( c, size, minimumWidth, defaultMargin );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -156,14 +185,6 @@ public class FlatTextAreaUI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paintBackground( Graphics g ) {
|
protected void paintBackground( Graphics g ) {
|
||||||
JTextComponent c = getComponent();
|
FlatEditorPaneUI.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 );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,8 +24,10 @@ import java.awt.FontMetrics;
|
|||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
|
import java.awt.Rectangle;
|
||||||
import java.awt.event.FocusListener;
|
import java.awt.event.FocusListener;
|
||||||
import java.beans.PropertyChangeEvent;
|
import java.beans.PropertyChangeEvent;
|
||||||
|
import java.util.Objects;
|
||||||
import javax.swing.JComboBox;
|
import javax.swing.JComboBox;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JSpinner;
|
import javax.swing.JSpinner;
|
||||||
@@ -40,6 +42,7 @@ import javax.swing.text.JTextComponent;
|
|||||||
import com.formdev.flatlaf.FlatClientProperties;
|
import com.formdev.flatlaf.FlatClientProperties;
|
||||||
import com.formdev.flatlaf.util.HiDPIUtils;
|
import com.formdev.flatlaf.util.HiDPIUtils;
|
||||||
import com.formdev.flatlaf.util.JavaCompatibility;
|
import com.formdev.flatlaf.util.JavaCompatibility;
|
||||||
|
import com.formdev.flatlaf.util.UIScale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides the Flat LaF UI delegate for {@link javax.swing.JTextField}.
|
* 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.minimumWidth int
|
||||||
* @uiDefault Component.isIntelliJTheme boolean
|
* @uiDefault Component.isIntelliJTheme boolean
|
||||||
* @uiDefault TextField.placeholderForeground Color
|
* @uiDefault TextField.placeholderForeground Color
|
||||||
|
* @uiDefault TextField.focusedBackground Color optional
|
||||||
* @uiDefault TextComponent.selectAllOnFocusPolicy String never, once (default) or always
|
* @uiDefault TextComponent.selectAllOnFocusPolicy String never, once (default) or always
|
||||||
* @uiDefault TextComponent.selectAllOnMouseClick boolean
|
* @uiDefault TextComponent.selectAllOnMouseClick boolean
|
||||||
*
|
*
|
||||||
@@ -75,6 +79,9 @@ public class FlatTextFieldUI
|
|||||||
protected int minimumWidth;
|
protected int minimumWidth;
|
||||||
protected boolean isIntelliJTheme;
|
protected boolean isIntelliJTheme;
|
||||||
protected Color placeholderForeground;
|
protected Color placeholderForeground;
|
||||||
|
protected Color focusedBackground;
|
||||||
|
|
||||||
|
private Insets defaultMargin;
|
||||||
|
|
||||||
private FocusListener focusListener;
|
private FocusListener focusListener;
|
||||||
|
|
||||||
@@ -90,6 +97,9 @@ public class FlatTextFieldUI
|
|||||||
minimumWidth = UIManager.getInt( "Component.minimumWidth" );
|
minimumWidth = UIManager.getInt( "Component.minimumWidth" );
|
||||||
isIntelliJTheme = UIManager.getBoolean( "Component.isIntelliJTheme" );
|
isIntelliJTheme = UIManager.getBoolean( "Component.isIntelliJTheme" );
|
||||||
placeholderForeground = UIManager.getColor( prefix + ".placeholderForeground" );
|
placeholderForeground = UIManager.getColor( prefix + ".placeholderForeground" );
|
||||||
|
focusedBackground = UIManager.getColor( prefix + ".focusedBackground" );
|
||||||
|
|
||||||
|
defaultMargin = UIManager.getInsets( prefix + ".margin" );
|
||||||
|
|
||||||
LookAndFeel.installProperty( getComponent(), "opaque", false );
|
LookAndFeel.installProperty( getComponent(), "opaque", false );
|
||||||
|
|
||||||
@@ -101,6 +111,7 @@ public class FlatTextFieldUI
|
|||||||
super.uninstallDefaults();
|
super.uninstallDefaults();
|
||||||
|
|
||||||
placeholderForeground = null;
|
placeholderForeground = null;
|
||||||
|
focusedBackground = null;
|
||||||
|
|
||||||
MigLayoutVisualPadding.uninstall( getComponent() );
|
MigLayoutVisualPadding.uninstall( getComponent() );
|
||||||
}
|
}
|
||||||
@@ -109,7 +120,8 @@ public class FlatTextFieldUI
|
|||||||
protected void installListeners() {
|
protected void installListeners() {
|
||||||
super.installListeners();
|
super.installListeners();
|
||||||
|
|
||||||
focusListener = new FlatUIUtils.RepaintFocusListener( getComponent() );
|
// necessary to update focus border and background
|
||||||
|
focusListener = new FlatUIUtils.RepaintFocusListener( getComponent(), null );
|
||||||
getComponent().addFocusListener( focusListener );
|
getComponent().addFocusListener( focusListener );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,6 +149,7 @@ public class FlatTextFieldUI
|
|||||||
switch( e.getPropertyName() ) {
|
switch( e.getPropertyName() ) {
|
||||||
case FlatClientProperties.PLACEHOLDER_TEXT:
|
case FlatClientProperties.PLACEHOLDER_TEXT:
|
||||||
case FlatClientProperties.COMPONENT_ROUND_RECT:
|
case FlatClientProperties.COMPONENT_ROUND_RECT:
|
||||||
|
case FlatClientProperties.TEXT_FIELD_PADDING:
|
||||||
c.repaint();
|
c.repaint();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -148,8 +161,8 @@ public class FlatTextFieldUI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paintSafely( Graphics g ) {
|
protected void paintSafely( Graphics g ) {
|
||||||
paintBackground( g, getComponent(), isIntelliJTheme );
|
paintBackground( g, getComponent(), isIntelliJTheme, focusedBackground );
|
||||||
paintPlaceholder( g, getComponent(), placeholderForeground );
|
paintPlaceholder( g );
|
||||||
|
|
||||||
super.paintSafely( HiDPIUtils.createGraphicsTextYCorrection( (Graphics2D) g ) );
|
super.paintSafely( HiDPIUtils.createGraphicsTextYCorrection( (Graphics2D) g ) );
|
||||||
}
|
}
|
||||||
@@ -159,7 +172,7 @@ public class FlatTextFieldUI
|
|||||||
// background is painted elsewhere
|
// 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:
|
// do not paint background if:
|
||||||
// - not opaque and
|
// - not opaque and
|
||||||
// - border is not a flat border and
|
// - border is not a flat border and
|
||||||
@@ -180,19 +193,34 @@ public class FlatTextFieldUI
|
|||||||
try {
|
try {
|
||||||
FlatUIUtils.setRenderingHints( g2 );
|
FlatUIUtils.setRenderingHints( g2 );
|
||||||
|
|
||||||
Color background = c.getBackground();
|
g2.setColor( getBackground( c, isIntelliJTheme, focusedBackground ) );
|
||||||
g2.setColor( !(background instanceof UIResource)
|
|
||||||
? background
|
|
||||||
: (isIntelliJTheme && (!c.isEnabled() || !c.isEditable())
|
|
||||||
? FlatUIUtils.getParentBackground( c )
|
|
||||||
: background) );
|
|
||||||
FlatUIUtils.paintComponentBackground( g2, 0, 0, c.getWidth(), c.getHeight(), focusWidth, arc );
|
FlatUIUtils.paintComponentBackground( g2, 0, 0, c.getWidth(), c.getHeight(), focusWidth, arc );
|
||||||
} finally {
|
} finally {
|
||||||
g2.dispose();
|
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
|
// check whether text component is empty
|
||||||
if( c.getDocument().getLength() > 0 )
|
if( c.getDocument().getLength() > 0 )
|
||||||
return;
|
return;
|
||||||
@@ -207,15 +235,14 @@ public class FlatTextFieldUI
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// compute placeholder location
|
// compute placeholder location
|
||||||
Insets insets = c.getInsets();
|
Rectangle r = getVisibleEditorRect();
|
||||||
FontMetrics fm = c.getFontMetrics( c.getFont() );
|
FontMetrics fm = c.getFontMetrics( c.getFont() );
|
||||||
int x = insets.left;
|
String clippedPlaceholder = JavaCompatibility.getClippedString( c, fm, (String) placeholder, r.width );
|
||||||
int y = insets.top + fm.getAscent() + ((c.getHeight() - insets.top - insets.bottom - fm.getHeight()) / 2);
|
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
|
// paint placeholder
|
||||||
g.setColor( placeholderForeground );
|
g.setColor( placeholderForeground );
|
||||||
String clippedPlaceholder = JavaCompatibility.getClippedString( jc, fm,
|
|
||||||
(String) placeholder, c.getWidth() - insets.left - insets.right );
|
|
||||||
FlatUIUtils.drawString( c, g, clippedPlaceholder, x, y );
|
FlatUIUtils.drawString( c, g, clippedPlaceholder, x, y );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,11 +256,15 @@ public class FlatTextFieldUI
|
|||||||
return applyMinimumWidth( c, super.getMinimumSize( c ), minimumWidth );
|
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
|
// do not apply minimum width if JTextField.columns is set
|
||||||
if( c instanceof JTextField && ((JTextField)c).getColumns() > 0 )
|
if( c instanceof JTextField && ((JTextField)c).getColumns() > 0 )
|
||||||
return size;
|
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
|
// do not apply minimum width if used in combobox or spinner
|
||||||
Container parent = c.getParent();
|
Container parent = c.getParent();
|
||||||
if( parent instanceof JComboBox ||
|
if( parent instanceof JComboBox ||
|
||||||
@@ -246,4 +277,41 @@ public class FlatTextFieldUI
|
|||||||
size.width = Math.max( size.width, scale( minimumWidth ) + Math.round( focusWidth * 2 ) );
|
size.width = Math.max( size.width, scale( minimumWidth ) + Math.round( focusWidth * 2 ) );
|
||||||
return size;
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,17 +16,18 @@
|
|||||||
|
|
||||||
package com.formdev.flatlaf.ui;
|
package com.formdev.flatlaf.ui;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Insets;
|
||||||
|
import java.awt.event.FocusListener;
|
||||||
import java.beans.PropertyChangeEvent;
|
import java.beans.PropertyChangeEvent;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JEditorPane;
|
import javax.swing.JEditorPane;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
import javax.swing.plaf.UIResource;
|
|
||||||
import javax.swing.plaf.basic.BasicTextPaneUI;
|
import javax.swing.plaf.basic.BasicTextPaneUI;
|
||||||
import javax.swing.text.JTextComponent;
|
|
||||||
import com.formdev.flatlaf.util.HiDPIUtils;
|
import com.formdev.flatlaf.util.HiDPIUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -51,6 +52,7 @@ import com.formdev.flatlaf.util.HiDPIUtils;
|
|||||||
*
|
*
|
||||||
* @uiDefault Component.minimumWidth int
|
* @uiDefault Component.minimumWidth int
|
||||||
* @uiDefault Component.isIntelliJTheme boolean
|
* @uiDefault Component.isIntelliJTheme boolean
|
||||||
|
* @uiDefault TextPane.focusedBackground Color optional
|
||||||
*
|
*
|
||||||
* @author Karl Tauber
|
* @author Karl Tauber
|
||||||
*/
|
*/
|
||||||
@@ -59,8 +61,12 @@ public class FlatTextPaneUI
|
|||||||
{
|
{
|
||||||
protected int minimumWidth;
|
protected int minimumWidth;
|
||||||
protected boolean isIntelliJTheme;
|
protected boolean isIntelliJTheme;
|
||||||
|
protected Color focusedBackground;
|
||||||
|
|
||||||
|
private Insets defaultMargin;
|
||||||
|
|
||||||
private Object oldHonorDisplayProperties;
|
private Object oldHonorDisplayProperties;
|
||||||
|
private FocusListener focusListener;
|
||||||
|
|
||||||
public static ComponentUI createUI( JComponent c ) {
|
public static ComponentUI createUI( JComponent c ) {
|
||||||
return new FlatTextPaneUI();
|
return new FlatTextPaneUI();
|
||||||
@@ -70,8 +76,12 @@ public class FlatTextPaneUI
|
|||||||
protected void installDefaults() {
|
protected void installDefaults() {
|
||||||
super.installDefaults();
|
super.installDefaults();
|
||||||
|
|
||||||
|
String prefix = getPropertyPrefix();
|
||||||
minimumWidth = UIManager.getInt( "Component.minimumWidth" );
|
minimumWidth = UIManager.getInt( "Component.minimumWidth" );
|
||||||
isIntelliJTheme = UIManager.getBoolean( "Component.isIntelliJTheme" );
|
isIntelliJTheme = UIManager.getBoolean( "Component.isIntelliJTheme" );
|
||||||
|
focusedBackground = UIManager.getColor( prefix + ".focusedBackground" );
|
||||||
|
|
||||||
|
defaultMargin = UIManager.getInsets( prefix + ".margin" );
|
||||||
|
|
||||||
// use component font and foreground for HTML text
|
// use component font and foreground for HTML text
|
||||||
oldHonorDisplayProperties = getComponent().getClientProperty( JEditorPane.HONOR_DISPLAY_PROPERTIES );
|
oldHonorDisplayProperties = getComponent().getClientProperty( JEditorPane.HONOR_DISPLAY_PROPERTIES );
|
||||||
@@ -82,9 +92,28 @@ public class FlatTextPaneUI
|
|||||||
protected void uninstallDefaults() {
|
protected void uninstallDefaults() {
|
||||||
super.uninstallDefaults();
|
super.uninstallDefaults();
|
||||||
|
|
||||||
|
focusedBackground = null;
|
||||||
|
|
||||||
getComponent().putClientProperty( JEditorPane.HONOR_DISPLAY_PROPERTIES, oldHonorDisplayProperties );
|
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
|
@Override
|
||||||
protected void propertyChange( PropertyChangeEvent e ) {
|
protected void propertyChange( PropertyChangeEvent e ) {
|
||||||
super.propertyChange( e );
|
super.propertyChange( e );
|
||||||
@@ -93,12 +122,12 @@ public class FlatTextPaneUI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dimension getPreferredSize( JComponent c ) {
|
public Dimension getPreferredSize( JComponent c ) {
|
||||||
return FlatEditorPaneUI.applyMinimumWidth( c, super.getPreferredSize( c ), minimumWidth );
|
return FlatEditorPaneUI.applyMinimumWidth( c, super.getPreferredSize( c ), minimumWidth, defaultMargin );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dimension getMinimumSize( JComponent c ) {
|
public Dimension getMinimumSize( JComponent c ) {
|
||||||
return FlatEditorPaneUI.applyMinimumWidth( c, super.getMinimumSize( c ), minimumWidth );
|
return FlatEditorPaneUI.applyMinimumWidth( c, super.getMinimumSize( c ), minimumWidth, defaultMargin );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -108,14 +137,6 @@ public class FlatTextPaneUI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paintBackground( Graphics g ) {
|
protected void paintBackground( Graphics g ) {
|
||||||
JTextComponent c = getComponent();
|
FlatEditorPaneUI.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 );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -351,7 +351,7 @@ public class FlatTitlePane
|
|||||||
|
|
||||||
// set icon
|
// set icon
|
||||||
if( !images.isEmpty() )
|
if( !images.isEmpty() )
|
||||||
iconLabel.setIcon( FlatTitlePaneIcon.create( images, iconSize ) );
|
iconLabel.setIcon( new FlatTitlePaneIcon( images, iconSize ) );
|
||||||
else {
|
else {
|
||||||
// no icon set on window --> use default icon
|
// no icon set on window --> use default icon
|
||||||
Icon defaultIcon = UIManager.getIcon( "TitlePane.icon" );
|
Icon defaultIcon = UIManager.getIcon( "TitlePane.icon" );
|
||||||
@@ -508,7 +508,7 @@ public class FlatTitlePane
|
|||||||
|
|
||||||
protected void menuBarLayouted() {
|
protected void menuBarLayouted() {
|
||||||
updateNativeTitleBarHeightAndHitTestSpotsLater();
|
updateNativeTitleBarHeightAndHitTestSpotsLater();
|
||||||
revalidate();
|
doLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*debug
|
/*debug
|
||||||
@@ -521,13 +521,13 @@ public class FlatTitlePane
|
|||||||
g.drawLine( 0, debugTitleBarHeight, getWidth(), debugTitleBarHeight );
|
g.drawLine( 0, debugTitleBarHeight, getWidth(), debugTitleBarHeight );
|
||||||
}
|
}
|
||||||
if( debugHitTestSpots != null ) {
|
if( debugHitTestSpots != null ) {
|
||||||
g.setColor( Color.blue );
|
g.setColor( Color.red );
|
||||||
Point offset = SwingUtilities.convertPoint( this, 0, 0, window );
|
Point offset = SwingUtilities.convertPoint( this, 0, 0, window );
|
||||||
for( Rectangle r : debugHitTestSpots )
|
for( Rectangle r : debugHitTestSpots )
|
||||||
g.drawRect( r.x - offset.x, r.y - offset.y, r.width - 1, r.height - 1 );
|
g.drawRect( r.x - offset.x, r.y - offset.y, r.width - 1, r.height - 1 );
|
||||||
}
|
}
|
||||||
if( debugAppIconBounds != null ) {
|
if( debugAppIconBounds != null ) {
|
||||||
g.setColor( Color.red );
|
g.setColor( Color.blue);
|
||||||
Point offset = SwingUtilities.convertPoint( this, 0, 0, window );
|
Point offset = SwingUtilities.convertPoint( this, 0, 0, window );
|
||||||
Rectangle r = debugAppIconBounds;
|
Rectangle r = debugAppIconBounds;
|
||||||
g.drawRect( r.x - offset.x, r.y - offset.y, r.width - 1, r.height - 1 );
|
g.drawRect( r.x - offset.x, r.y - offset.y, r.width - 1, r.height - 1 );
|
||||||
@@ -723,14 +723,29 @@ debug*/
|
|||||||
List<Rectangle> hitTestSpots = new ArrayList<>();
|
List<Rectangle> hitTestSpots = new ArrayList<>();
|
||||||
Rectangle appIconBounds = null;
|
Rectangle appIconBounds = null;
|
||||||
if( iconLabel.isVisible() ) {
|
if( iconLabel.isVisible() ) {
|
||||||
// compute real icon size (without insets)
|
// compute real icon size (without insets; 1px wider for easier hitting)
|
||||||
Point location = SwingUtilities.convertPoint( iconLabel, 0, 0, window );
|
Point location = SwingUtilities.convertPoint( iconLabel, 0, 0, window );
|
||||||
Insets iconInsets = iconLabel.getInsets();
|
Insets iconInsets = iconLabel.getInsets();
|
||||||
Rectangle iconBounds = new Rectangle(
|
Rectangle iconBounds = new Rectangle(
|
||||||
location.x + iconInsets.left,
|
location.x + iconInsets.left - 1,
|
||||||
location.y + iconInsets.top,
|
location.y + iconInsets.top - 1,
|
||||||
iconLabel.getWidth() - iconInsets.left - iconInsets.right,
|
iconLabel.getWidth() - iconInsets.left - iconInsets.right + 2,
|
||||||
iconLabel.getHeight() - iconInsets.top - iconInsets.bottom );
|
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() )
|
if( hasJBRCustomDecoration() )
|
||||||
hitTestSpots.add( iconBounds );
|
hitTestSpots.add( iconBounds );
|
||||||
|
|||||||
@@ -20,8 +20,6 @@ import java.awt.Dimension;
|
|||||||
import java.awt.Image;
|
import java.awt.Image;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.swing.Icon;
|
|
||||||
import javax.swing.ImageIcon;
|
|
||||||
import com.formdev.flatlaf.util.MultiResolutionImageSupport;
|
import com.formdev.flatlaf.util.MultiResolutionImageSupport;
|
||||||
import com.formdev.flatlaf.util.ScaledImageIcon;
|
import com.formdev.flatlaf.util.ScaledImageIcon;
|
||||||
|
|
||||||
@@ -31,40 +29,43 @@ import com.formdev.flatlaf.util.ScaledImageIcon;
|
|||||||
public class FlatTitlePaneIcon
|
public class FlatTitlePaneIcon
|
||||||
extends ScaledImageIcon
|
extends ScaledImageIcon
|
||||||
{
|
{
|
||||||
public static Icon create( List<Image> images, Dimension size ) {
|
private final List<Image> images;
|
||||||
// collect all images including multi-resolution variants
|
|
||||||
|
/**
|
||||||
|
* @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<>();
|
List<Image> allImages = new ArrayList<>();
|
||||||
for( Image image : images ) {
|
for( Image image : images ) {
|
||||||
if( MultiResolutionImageSupport.isMultiResolutionImage( image ) )
|
if( MultiResolutionImageSupport.isMultiResolutionImage( image ) )
|
||||||
allImages.addAll( MultiResolutionImageSupport.getResolutionVariants( image ) );
|
allImages.add( MultiResolutionImageSupport.getResolutionVariant( image, destImageWidth, destImageHeight ) );
|
||||||
else
|
else
|
||||||
allImages.add( image );
|
allImages.add( image );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( allImages.size() == 1 )
|
||||||
|
return allImages.get( 0 );
|
||||||
|
|
||||||
// sort images by size
|
// sort images by size
|
||||||
allImages.sort( (image1, image2) -> {
|
allImages.sort( (image1, image2) -> {
|
||||||
return image1.getWidth( null ) - image2.getWidth( null );
|
return image1.getWidth( null ) - image2.getWidth( null );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
// create icon
|
// search for optimal image size
|
||||||
return new FlatTitlePaneIcon( allImages, size );
|
for( Image image : allImages ) {
|
||||||
}
|
|
||||||
|
|
||||||
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 ) {
|
|
||||||
if( destImageWidth <= image.getWidth( null ) &&
|
if( destImageWidth <= image.getWidth( null ) &&
|
||||||
destImageHeight <= image.getHeight( null ) )
|
destImageHeight <= image.getHeight( null ) )
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
return images.get( images.size() - 1 );
|
// use largest image
|
||||||
|
return allImages.get( allImages.size() - 1 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import java.awt.event.ContainerEvent;
|
|||||||
import java.awt.event.ContainerListener;
|
import java.awt.event.ContainerListener;
|
||||||
import javax.swing.AbstractButton;
|
import javax.swing.AbstractButton;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
|
import javax.swing.UIManager;
|
||||||
import javax.swing.border.Border;
|
import javax.swing.border.Border;
|
||||||
import javax.swing.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
import javax.swing.plaf.basic.BasicToolBarUI;
|
import javax.swing.plaf.basic.BasicToolBarUI;
|
||||||
@@ -41,15 +42,47 @@ import javax.swing.plaf.basic.BasicToolBarUI;
|
|||||||
* @uiDefault ToolBar.floatingForeground Color
|
* @uiDefault ToolBar.floatingForeground Color
|
||||||
* @uiDefault ToolBar.isRollover boolean
|
* @uiDefault ToolBar.isRollover boolean
|
||||||
*
|
*
|
||||||
|
* <!-- FlatToolBarUI -->
|
||||||
|
*
|
||||||
|
* @uiDefault ToolBar.focusableButtons boolean
|
||||||
|
*
|
||||||
* @author Karl Tauber
|
* @author Karl Tauber
|
||||||
*/
|
*/
|
||||||
public class FlatToolBarUI
|
public class FlatToolBarUI
|
||||||
extends BasicToolBarUI
|
extends BasicToolBarUI
|
||||||
{
|
{
|
||||||
|
/** @since 1.4 */
|
||||||
|
protected boolean focusableButtons;
|
||||||
|
|
||||||
public static ComponentUI createUI( JComponent c ) {
|
public static ComponentUI createUI( JComponent c ) {
|
||||||
return new FlatToolBarUI();
|
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
|
@Override
|
||||||
protected ContainerListener createToolBarContListener() {
|
protected ContainerListener createToolBarContListener() {
|
||||||
return new ToolBarContListener() {
|
return new ToolBarContListener() {
|
||||||
@@ -57,22 +90,36 @@ public class FlatToolBarUI
|
|||||||
public void componentAdded( ContainerEvent e ) {
|
public void componentAdded( ContainerEvent e ) {
|
||||||
super.componentAdded( e );
|
super.componentAdded( e );
|
||||||
|
|
||||||
|
if( !focusableButtons ) {
|
||||||
Component c = e.getChild();
|
Component c = e.getChild();
|
||||||
if( c instanceof AbstractButton )
|
if( c instanceof AbstractButton )
|
||||||
c.setFocusable( false );
|
c.setFocusable( false );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void componentRemoved( ContainerEvent e ) {
|
public void componentRemoved( ContainerEvent e ) {
|
||||||
super.componentRemoved( e );
|
super.componentRemoved( e );
|
||||||
|
|
||||||
|
if( !focusableButtons ) {
|
||||||
Component c = e.getChild();
|
Component c = e.getChild();
|
||||||
if( c instanceof AbstractButton )
|
if( c instanceof AbstractButton )
|
||||||
c.setFocusable( true );
|
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
|
// disable rollover border
|
||||||
@Override protected void setBorderToRollover( Component c ) {}
|
@Override protected void setBorderToRollover( Component c ) {}
|
||||||
@Override protected void setBorderToNonRollover( Component c ) {}
|
@Override protected void setBorderToNonRollover( Component c ) {}
|
||||||
|
|||||||
@@ -107,6 +107,8 @@ public class FlatTreeUI
|
|||||||
protected boolean wideSelection;
|
protected boolean wideSelection;
|
||||||
protected boolean showCellFocusIndicator;
|
protected boolean showCellFocusIndicator;
|
||||||
|
|
||||||
|
private Color defaultCellNonSelectionBackground;
|
||||||
|
|
||||||
public static ComponentUI createUI( JComponent c ) {
|
public static ComponentUI createUI( JComponent c ) {
|
||||||
return new FlatTreeUI();
|
return new FlatTreeUI();
|
||||||
}
|
}
|
||||||
@@ -125,6 +127,8 @@ public class FlatTreeUI
|
|||||||
wideSelection = UIManager.getBoolean( "Tree.wideSelection" );
|
wideSelection = UIManager.getBoolean( "Tree.wideSelection" );
|
||||||
showCellFocusIndicator = UIManager.getBoolean( "Tree.showCellFocusIndicator" );
|
showCellFocusIndicator = UIManager.getBoolean( "Tree.showCellFocusIndicator" );
|
||||||
|
|
||||||
|
defaultCellNonSelectionBackground = UIManager.getColor( "Tree.textBackground" );
|
||||||
|
|
||||||
// scale
|
// scale
|
||||||
int rowHeight = FlatUIUtils.getUIInt( "Tree.rowHeight", 16 );
|
int rowHeight = FlatUIUtils.getUIInt( "Tree.rowHeight", 16 );
|
||||||
if( rowHeight > 0 )
|
if( rowHeight > 0 )
|
||||||
@@ -144,6 +148,8 @@ public class FlatTreeUI
|
|||||||
selectionInactiveBackground = null;
|
selectionInactiveBackground = null;
|
||||||
selectionInactiveForeground = null;
|
selectionInactiveForeground = null;
|
||||||
selectionBorderColor = null;
|
selectionBorderColor = null;
|
||||||
|
|
||||||
|
defaultCellNonSelectionBackground = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -224,6 +230,26 @@ public class FlatTreeUI
|
|||||||
tree.repaint( 0, r.y, tree.getWidth(), r.height );
|
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
|
* Same as super.paintRow(), but supports wide selection and uses
|
||||||
* inactive selection background/foreground if tree is not focused.
|
* inactive selection background/foreground if tree is not focused.
|
||||||
@@ -237,9 +263,19 @@ public class FlatTreeUI
|
|||||||
boolean isDropRow = isDropRow( row );
|
boolean isDropRow = isDropRow( row );
|
||||||
boolean needsSelectionPainting = (isSelected || isDropRow) && isPaintSelection();
|
boolean needsSelectionPainting = (isSelected || isDropRow) && isPaintSelection();
|
||||||
|
|
||||||
// do not paint row if editing, except if selection needs painted
|
// do not paint row if editing
|
||||||
if( isEditing && !needsSelectionPainting )
|
if( isEditing ) {
|
||||||
|
// paint wide selection
|
||||||
|
// (do not access cell renderer here to avoid side effect
|
||||||
|
// if renderer component is also used as editor component)
|
||||||
|
if( isSelected && isWideSelection() ) {
|
||||||
|
Color oldColor = g.getColor();
|
||||||
|
g.setColor( selectionInactiveBackground );
|
||||||
|
paintWideSelection( g, clipBounds, insets, bounds, path, row, isExpanded, hasBeenExpanded, isLeaf );
|
||||||
|
g.setColor( oldColor );
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
boolean hasFocus = FlatUIUtils.isPermanentFocusOwner( tree );
|
boolean hasFocus = FlatUIUtils.isPermanentFocusOwner( tree );
|
||||||
boolean cellHasFocus = hasFocus && (row == getLeadSelectionRow());
|
boolean cellHasFocus = hasFocus && (row == getLeadSelectionRow());
|
||||||
@@ -296,6 +332,42 @@ public class FlatTreeUI
|
|||||||
|
|
||||||
if( isWideSelection() ) {
|
if( isWideSelection() ) {
|
||||||
// wide selection
|
// wide selection
|
||||||
|
paintWideSelection( 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 );
|
||||||
|
|
||||||
|
// restore background selection color and border selection color
|
||||||
|
if( oldBackgroundSelectionColor != null )
|
||||||
|
((DefaultTreeCellRenderer)rendererComponent).setBackgroundSelectionColor( oldBackgroundSelectionColor );
|
||||||
|
if( oldBorderSelectionColor != null )
|
||||||
|
((DefaultTreeCellRenderer)rendererComponent).setBorderSelectionColor( oldBorderSelectionColor );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void paintWideSelection( Graphics g, Rectangle clipBounds, Insets insets, Rectangle bounds,
|
||||||
|
TreePath path, int row, boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf )
|
||||||
|
{
|
||||||
g.fillRect( 0, bounds.y, tree.getWidth(), bounds.height );
|
g.fillRect( 0, bounds.y, tree.getWidth(), bounds.height );
|
||||||
|
|
||||||
// paint expand/collapse icon
|
// paint expand/collapse icon
|
||||||
@@ -304,8 +376,9 @@ public class FlatTreeUI
|
|||||||
paintExpandControl( g, clipBounds, insets, bounds,
|
paintExpandControl( g, clipBounds, insets, bounds,
|
||||||
path, row, isExpanded, hasBeenExpanded, isLeaf );
|
path, row, isExpanded, hasBeenExpanded, isLeaf );
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
// non-wide selection
|
|
||||||
|
private void paintCellBackground( Graphics g, Component rendererComponent, Rectangle bounds ) {
|
||||||
int xOffset = 0;
|
int xOffset = 0;
|
||||||
int imageOffset = 0;
|
int imageOffset = 0;
|
||||||
|
|
||||||
@@ -321,22 +394,6 @@ public class FlatTreeUI
|
|||||||
g.fillRect( bounds.x + xOffset, bounds.y, bounds.width - imageOffset, bounds.height );
|
g.fillRect( bounds.x + xOffset, bounds.y, bounds.width - imageOffset, bounds.height );
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 );
|
|
||||||
}
|
|
||||||
|
|
||||||
// paint renderer
|
|
||||||
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 )
|
|
||||||
((DefaultTreeCellRenderer)rendererComponent).setBackgroundSelectionColor( oldBackgroundSelectionColor );
|
|
||||||
if( oldBorderSelectionColor != null )
|
|
||||||
((DefaultTreeCellRenderer)rendererComponent).setBorderSelectionColor( oldBorderSelectionColor );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether dropping on a row.
|
* Checks whether dropping on a row.
|
||||||
* See DefaultTreeCellRenderer.getTreeCellRendererComponent().
|
* See DefaultTreeCellRenderer.getTreeCellRendererComponent().
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ public class FlatUIUtils
|
|||||||
{
|
{
|
||||||
public static final boolean MAC_USE_QUARTZ = Boolean.getBoolean( "apple.awt.graphics.UseQuartz" );
|
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<>();
|
private static WeakHashMap<LookAndFeel, IdentityHashMap<Object, ComponentUI>> sharedUIinstances = new WeakHashMap<>();
|
||||||
|
|
||||||
public static Rectangle addInsets( Rectangle r, Insets insets ) {
|
public static Rectangle addInsets( Rectangle r, Insets insets ) {
|
||||||
@@ -94,6 +95,11 @@ public class FlatUIUtils
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Insets addInsets( Insets insets1, Insets insets2 ) {
|
public static Insets addInsets( Insets insets1, Insets insets2 ) {
|
||||||
|
if( insets1 == null )
|
||||||
|
return insets2;
|
||||||
|
if( insets2 == null )
|
||||||
|
return insets1;
|
||||||
|
|
||||||
return new Insets(
|
return new Insets(
|
||||||
insets1.top + insets2.top,
|
insets1.top + insets2.top,
|
||||||
insets1.left + insets2.left,
|
insets1.left + insets2.left,
|
||||||
@@ -660,7 +666,7 @@ public class FlatUIUtils
|
|||||||
* @since 1.1
|
* @since 1.1
|
||||||
*/
|
*/
|
||||||
public static void paintArrow( Graphics2D g, int x, int y, int width, int height,
|
public static void paintArrow( Graphics2D g, int x, int y, int width, int height,
|
||||||
int direction, boolean chevron, int arrowSize, int xOffset, int yOffset )
|
int direction, boolean chevron, int arrowSize, float xOffset, float yOffset )
|
||||||
{
|
{
|
||||||
// compute arrow width/height
|
// compute arrow width/height
|
||||||
int aw = UIScale.scale( arrowSize + (chevron ? 0 : 1) );
|
int aw = UIScale.scale( arrowSize + (chevron ? 0 : 1) );
|
||||||
@@ -679,8 +685,10 @@ public class FlatUIUtils
|
|||||||
int extra = chevron ? 1 : 0;
|
int extra = chevron ? 1 : 0;
|
||||||
|
|
||||||
// compute arrow location
|
// compute arrow location
|
||||||
int ax = x + Math.round( ((width - (aw + extra)) / 2f) + UIScale.scale( (float) xOffset ) );
|
float ox = ((width - (aw + extra)) / 2f) + UIScale.scale( xOffset );
|
||||||
int ay = y + Math.round( ((height - (ah + extra)) / 2f) + UIScale.scale( (float) yOffset ) );
|
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
|
// paint arrow
|
||||||
g.translate( ax, ay );
|
g.translate( ax, ay );
|
||||||
@@ -818,6 +826,27 @@ debug*/
|
|||||||
return explicitlySet;
|
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.
|
* Creates a shared component UI for the given key and the current Laf.
|
||||||
* Each Laf instance has its own shared component UI instance.
|
* Each Laf instance has its own shared component UI instance.
|
||||||
@@ -826,6 +855,9 @@ debug*/
|
|||||||
* may use multiple Laf instances at the same time.
|
* may use multiple Laf instances at the same time.
|
||||||
*/
|
*/
|
||||||
public static ComponentUI createSharedUI( Object key, Supplier<ComponentUI> newInstanceSupplier ) {
|
public static ComponentUI createSharedUI( Object key, Supplier<ComponentUI> newInstanceSupplier ) {
|
||||||
|
if( !useSharedUIs )
|
||||||
|
return newInstanceSupplier.get();
|
||||||
|
|
||||||
return sharedUIinstances
|
return sharedUIinstances
|
||||||
.computeIfAbsent( UIManager.getLookAndFeel(), k -> new IdentityHashMap<>() )
|
.computeIfAbsent( UIManager.getLookAndFeel(), k -> new IdentityHashMap<>() )
|
||||||
.computeIfAbsent( key, k -> newInstanceSupplier.get() );
|
.computeIfAbsent( key, k -> newInstanceSupplier.get() );
|
||||||
@@ -837,18 +869,22 @@ debug*/
|
|||||||
implements FocusListener
|
implements FocusListener
|
||||||
{
|
{
|
||||||
private final Component repaintComponent;
|
private final Component repaintComponent;
|
||||||
|
private final Predicate<Component> repaintCondition;
|
||||||
|
|
||||||
public RepaintFocusListener( Component repaintComponent ) {
|
public RepaintFocusListener( Component repaintComponent, Predicate<Component> repaintCondition ) {
|
||||||
this.repaintComponent = repaintComponent;
|
this.repaintComponent = repaintComponent;
|
||||||
|
this.repaintCondition = repaintCondition;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void focusGained( FocusEvent e ) {
|
public void focusGained( FocusEvent e ) {
|
||||||
|
if( repaintCondition == null || repaintCondition.test( repaintComponent ) )
|
||||||
repaintComponent.repaint();
|
repaintComponent.repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void focusLost( FocusEvent e ) {
|
public void focusLost( FocusEvent e ) {
|
||||||
|
if( repaintCondition == null || repaintCondition.test( repaintComponent ) )
|
||||||
repaintComponent.repaint();
|
repaintComponent.repaint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -181,8 +181,12 @@ public abstract class FlatWindowResizer
|
|||||||
protected abstract boolean isWindowResizable();
|
protected abstract boolean isWindowResizable();
|
||||||
protected abstract Rectangle getWindowBounds();
|
protected abstract Rectangle getWindowBounds();
|
||||||
protected abstract void setWindowBounds( Rectangle r );
|
protected abstract void setWindowBounds( Rectangle r );
|
||||||
|
protected abstract boolean limitToParentBounds();
|
||||||
|
protected abstract Rectangle getParentBounds();
|
||||||
protected abstract boolean honorMinimumSizeOnResize();
|
protected abstract boolean honorMinimumSizeOnResize();
|
||||||
|
protected abstract boolean honorMaximumSizeOnResize();
|
||||||
protected abstract Dimension getWindowMinimumSize();
|
protected abstract Dimension getWindowMinimumSize();
|
||||||
|
protected abstract Dimension getWindowMaximumSize();
|
||||||
|
|
||||||
protected void beginResizing( int direction ) {}
|
protected void beginResizing( int direction ) {}
|
||||||
protected void endResizing() {}
|
protected void endResizing() {}
|
||||||
@@ -283,6 +287,16 @@ public abstract class FlatWindowResizer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean limitToParentBounds() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Rectangle getParentBounds() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean honorMinimumSizeOnResize() {
|
protected boolean honorMinimumSizeOnResize() {
|
||||||
return
|
return
|
||||||
@@ -290,11 +304,21 @@ public abstract class FlatWindowResizer
|
|||||||
(honorDialogMinimumSizeOnResize && window instanceof Dialog);
|
(honorDialogMinimumSizeOnResize && window instanceof Dialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean honorMaximumSizeOnResize() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Dimension getWindowMinimumSize() {
|
protected Dimension getWindowMinimumSize() {
|
||||||
return window.getMinimumSize();
|
return window.getMinimumSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Dimension getWindowMaximumSize() {
|
||||||
|
return window.getMaximumSize();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
boolean isDialog() {
|
boolean isDialog() {
|
||||||
return window instanceof Dialog;
|
return window instanceof Dialog;
|
||||||
@@ -354,16 +378,36 @@ public abstract class FlatWindowResizer
|
|||||||
desktopManager.get().resizeFrame( getFrame(), r.x, r.y, r.width, r.height );
|
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
|
@Override
|
||||||
protected boolean honorMinimumSizeOnResize() {
|
protected boolean honorMinimumSizeOnResize() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean honorMaximumSizeOnResize() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Dimension getWindowMinimumSize() {
|
protected Dimension getWindowMinimumSize() {
|
||||||
return getFrame().getMinimumSize();
|
return getFrame().getMinimumSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Dimension getWindowMaximumSize() {
|
||||||
|
return getFrame().getMaximumSize();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void beginResizing( int direction ) {
|
protected void beginResizing( int direction ) {
|
||||||
desktopManager.get().beginResizingFrame( getFrame(), direction );
|
desktopManager.get().beginResizingFrame( getFrame(), direction );
|
||||||
@@ -521,7 +565,7 @@ debug*/
|
|||||||
int xOnScreen = e.getXOnScreen();
|
int xOnScreen = e.getXOnScreen();
|
||||||
int yOnScreen = e.getYOnScreen();
|
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.
|
// This is necessary because window manager may alter window bounds while resizing.
|
||||||
// E.g. when having two monitors with different scale factors and 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
|
// a window on first screen to the second screen, then the window manager may
|
||||||
@@ -535,41 +579,72 @@ debug*/
|
|||||||
// top
|
// top
|
||||||
if( resizeDir == N_RESIZE_CURSOR || resizeDir == NW_RESIZE_CURSOR || resizeDir == NE_RESIZE_CURSOR ) {
|
if( resizeDir == N_RESIZE_CURSOR || resizeDir == NW_RESIZE_CURSOR || resizeDir == NE_RESIZE_CURSOR ) {
|
||||||
newBounds.y = yOnScreen - dragTopOffset;
|
newBounds.y = yOnScreen - dragTopOffset;
|
||||||
|
if( limitToParentBounds() && newBounds.y < 0 )
|
||||||
|
newBounds.y = 0;
|
||||||
newBounds.height += (oldBounds.y - newBounds.y);
|
newBounds.height += (oldBounds.y - newBounds.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
// bottom
|
// 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;
|
newBounds.height = (yOnScreen + dragBottomOffset) - newBounds.y;
|
||||||
|
if( limitToParentBounds() ) {
|
||||||
|
int parentHeight = getParentBounds().height;
|
||||||
|
if( newBounds.y + newBounds.height > parentHeight )
|
||||||
|
newBounds.height = parentHeight - newBounds.y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// left
|
// left
|
||||||
if( resizeDir == W_RESIZE_CURSOR || resizeDir == NW_RESIZE_CURSOR || resizeDir == SW_RESIZE_CURSOR ) {
|
if( resizeDir == W_RESIZE_CURSOR || resizeDir == NW_RESIZE_CURSOR || resizeDir == SW_RESIZE_CURSOR ) {
|
||||||
newBounds.x = xOnScreen - dragLeftOffset;
|
newBounds.x = xOnScreen - dragLeftOffset;
|
||||||
|
if( limitToParentBounds() && newBounds.x < 0 )
|
||||||
|
newBounds.x = 0;
|
||||||
newBounds.width += (oldBounds.x - newBounds.x);
|
newBounds.width += (oldBounds.x - newBounds.x);
|
||||||
}
|
}
|
||||||
|
|
||||||
// right
|
// 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;
|
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
|
// apply minimum window size
|
||||||
Dimension minimumSize = honorMinimumSizeOnResize() ? getWindowMinimumSize() : null;
|
Dimension minimumSize = honorMinimumSizeOnResize() ? getWindowMinimumSize() : null;
|
||||||
if( minimumSize == null )
|
if( minimumSize == null )
|
||||||
minimumSize = UIScale.scale( new Dimension( 150, 50 ) );
|
minimumSize = UIScale.scale( new Dimension( 150, 50 ) );
|
||||||
if( newBounds.width < minimumSize.width ) {
|
if( newBounds.width < minimumSize.width )
|
||||||
if( newBounds.x != oldBounds.x )
|
changeWidth( oldBounds, newBounds, minimumSize.width );
|
||||||
newBounds.x -= (minimumSize.width - newBounds.width);
|
if( newBounds.height < minimumSize.height )
|
||||||
newBounds.width = minimumSize.width;
|
changeHeight( oldBounds, newBounds, minimumSize.height );
|
||||||
}
|
|
||||||
if( newBounds.height < minimumSize.height ) {
|
// apply maximum window size
|
||||||
if( newBounds.y != oldBounds.y )
|
if( honorMaximumSizeOnResize() ) {
|
||||||
newBounds.y -= (minimumSize.height - newBounds.height);
|
Dimension maximumSize = getWindowMaximumSize();
|
||||||
newBounds.height = minimumSize.height;
|
if( newBounds.width > maximumSize.width )
|
||||||
|
changeWidth( oldBounds, newBounds, maximumSize.width );
|
||||||
|
if( newBounds.height > maximumSize.height )
|
||||||
|
changeHeight( oldBounds, newBounds, maximumSize.height );
|
||||||
}
|
}
|
||||||
|
|
||||||
// set window bounds
|
// set window bounds
|
||||||
if( !newBounds.equals( oldBounds ) )
|
if( !newBounds.equals( oldBounds ) )
|
||||||
setWindowBounds( newBounds );
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ import java.awt.Point;
|
|||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.awt.Window;
|
import java.awt.Window;
|
||||||
import java.awt.geom.AffineTransform;
|
import java.awt.geom.AffineTransform;
|
||||||
|
import java.beans.PropertyChangeEvent;
|
||||||
|
import java.beans.PropertyChangeListener;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.IdentityHashMap;
|
import java.util.IdentityHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -94,6 +96,11 @@ class FlatWindowsNativeWindowBorder
|
|||||||
// Java 9 and later does not have this problem.
|
// Java 9 and later does not have this problem.
|
||||||
try {
|
try {
|
||||||
System.loadLibrary( "jawt" );
|
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 ) {
|
} catch( Exception ex ) {
|
||||||
LoggingFacade.INSTANCE.logSevere( null, ex );
|
LoggingFacade.INSTANCE.logSevere( null, ex );
|
||||||
}
|
}
|
||||||
@@ -156,11 +163,18 @@ class FlatWindowsNativeWindowBorder
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// install
|
// install
|
||||||
|
try {
|
||||||
WndProc wndProc = new WndProc( window );
|
WndProc wndProc = new WndProc( window );
|
||||||
if( wndProc.hwnd == 0 )
|
if( wndProc.hwnd == 0 )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
windowsMap.put( window, wndProc );
|
windowsMap.put( window, wndProc );
|
||||||
|
} catch( UnsatisfiedLinkError ex ) {
|
||||||
|
// catch for the case that the operating system prevents execution of DLL
|
||||||
|
// (e.g. if DLLs in temp folder are restricted)
|
||||||
|
// --> continue application without custom decorations
|
||||||
|
LoggingFacade.INSTANCE.logSevere( null, ex );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void uninstall( Window window ) {
|
private void uninstall( Window window ) {
|
||||||
@@ -289,6 +303,7 @@ class FlatWindowsNativeWindowBorder
|
|||||||
//---- class WndProc ------------------------------------------------------
|
//---- class WndProc ------------------------------------------------------
|
||||||
|
|
||||||
private class WndProc
|
private class WndProc
|
||||||
|
implements PropertyChangeListener
|
||||||
{
|
{
|
||||||
// WM_NCHITTEST mouse position codes
|
// WM_NCHITTEST mouse position codes
|
||||||
private static final int
|
private static final int
|
||||||
@@ -308,30 +323,41 @@ class FlatWindowsNativeWindowBorder
|
|||||||
this.window = window;
|
this.window = window;
|
||||||
|
|
||||||
hwnd = installImpl( window );
|
hwnd = installImpl( window );
|
||||||
|
if( hwnd == 0 )
|
||||||
|
return;
|
||||||
|
|
||||||
// remove the OS window title bar
|
// remove the OS window title bar
|
||||||
if( window instanceof JFrame && ((JFrame)window).getExtendedState() != 0 ) {
|
updateFrame( hwnd, (window instanceof JFrame) ? ((JFrame)window).getExtendedState() : 0 );
|
||||||
// In case that the frame should be maximized or minimized immediately
|
|
||||||
// when showing, then it is necessary to defer ::SetWindowPos() invocation.
|
// set window background (used when resizing window)
|
||||||
// Otherwise the frame will not be maximized or minimized.
|
updateWindowBackground();
|
||||||
// This occurs only if frame.pack() was no invoked.
|
window.addPropertyChangeListener( "background", this );
|
||||||
EventQueue.invokeLater( () -> {
|
|
||||||
updateFrame( hwnd );
|
|
||||||
});
|
|
||||||
} else
|
|
||||||
updateFrame( hwnd );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void uninstall() {
|
void uninstall() {
|
||||||
|
window.removePropertyChangeListener( "background", this );
|
||||||
|
|
||||||
uninstallImpl( hwnd );
|
uninstallImpl( hwnd );
|
||||||
|
|
||||||
// cleanup
|
// cleanup
|
||||||
window = null;
|
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 long installImpl( Window window );
|
||||||
private native void uninstallImpl( long hwnd );
|
private native void uninstallImpl( long hwnd );
|
||||||
private native void updateFrame( 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 );
|
private native void showWindow( long hwnd, int cmd );
|
||||||
|
|
||||||
// invoked from native code
|
// invoked from native code
|
||||||
|
|||||||
@@ -70,9 +70,10 @@ public class JBRCustomDecorations
|
|||||||
return null;
|
return null;
|
||||||
|
|
||||||
// check whether root pane already has a parent, which is the case when switching LaF
|
// check whether root pane already has a parent, which is the case when switching LaF
|
||||||
Window window = SwingUtilities.windowForComponent( rootPane );
|
Container parent = rootPane.getParent();
|
||||||
if( window != null ) {
|
if( parent != null ) {
|
||||||
FlatNativeWindowBorder.install( window );
|
if( parent instanceof Window )
|
||||||
|
FlatNativeWindowBorder.install( (Window) parent );
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,9 +111,9 @@ public class JBRCustomDecorations
|
|||||||
// since it is actually not possible to uninstall JBR decorations,
|
// since it is actually not possible to uninstall JBR decorations,
|
||||||
// simply reduce titleBarHeight so that it is still possible to resize window
|
// simply reduce titleBarHeight so that it is still possible to resize window
|
||||||
// and remove hitTestSpots
|
// and remove hitTestSpots
|
||||||
Window window = SwingUtilities.windowForComponent( rootPane );
|
Container parent = rootPane.getParent();
|
||||||
if( window != null )
|
if( parent instanceof Window )
|
||||||
setHasCustomDecoration( window, false );
|
setHasCustomDecoration( (Window) parent, false );
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean hasCustomDecoration( Window window ) {
|
static boolean hasCustomDecoration( Window window ) {
|
||||||
|
|||||||
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,13 +26,16 @@ import java.awt.Color;
|
|||||||
public class ColorFunctions
|
public class ColorFunctions
|
||||||
{
|
{
|
||||||
public static Color applyFunctions( Color color, ColorFunction... functions ) {
|
public static Color applyFunctions( Color color, ColorFunction... functions ) {
|
||||||
|
// convert RGB to HSL
|
||||||
float[] hsl = HSLColor.fromRGB( color );
|
float[] hsl = HSLColor.fromRGB( color );
|
||||||
float alpha = color.getAlpha() / 255f;
|
float alpha = color.getAlpha() / 255f;
|
||||||
float[] hsla = { hsl[0], hsl[1], hsl[2], alpha * 100 };
|
float[] hsla = { hsl[0], hsl[1], hsl[2], alpha * 100 };
|
||||||
|
|
||||||
|
// apply color functions
|
||||||
for( ColorFunction function : functions )
|
for( ColorFunction function : functions )
|
||||||
function.apply( hsla );
|
function.apply( hsla );
|
||||||
|
|
||||||
|
// convert HSL to RGB
|
||||||
return HSLColor.toRGB( hsla[0], hsla[1], hsla[2], hsla[3] / 100 );
|
return HSLColor.toRGB( hsla[0], hsla[1], hsla[2], hsla[3] / 100 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,7 +148,46 @@ public class ColorFunctions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---- 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.
|
* Set the alpha of a color.
|
||||||
@@ -169,4 +211,42 @@ public class ColorFunctions
|
|||||||
return String.format( "fade(%.0f%%)", amount );
|
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 );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -256,11 +256,6 @@ public class Graphics2DProxy
|
|||||||
delegate.dispose();
|
delegate.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void finalize() {
|
|
||||||
delegate.finalize();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return delegate.toString();
|
return delegate.toString();
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.nio.file.FileAlreadyExistsException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
@@ -144,26 +145,46 @@ public class NativeLibrary
|
|||||||
String suffix = (dot >= 0) ? name.substring( dot ) : "";
|
String suffix = (dot >= 0) ? name.substring( dot ) : "";
|
||||||
|
|
||||||
Path tempDir = getTempDir();
|
Path tempDir = getTempDir();
|
||||||
if( tempDir != null ) {
|
|
||||||
deleteTemporaryFiles( tempDir );
|
|
||||||
|
|
||||||
return Files.createTempFile( tempDir, prefix, suffix );
|
// Note:
|
||||||
} else
|
// Not using Files.createTempFile() here because it uses random number generator SecureRandom,
|
||||||
return Files.createTempFile( prefix, suffix );
|
// 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 {
|
private static Path getTempDir() throws IOException {
|
||||||
|
// get standard temporary directory
|
||||||
|
String tmpdir = System.getProperty( "java.io.tmpdir" );
|
||||||
|
|
||||||
if( SystemInfo.isWindows ) {
|
if( SystemInfo.isWindows ) {
|
||||||
// On Windows, where File.delete() and File.deleteOnExit() does not work
|
// On Windows, where File.delete() and File.deleteOnExit() does not work
|
||||||
// for loaded native libraries, they will be deleted on next application startup.
|
// for loaded native libraries, they will be deleted on next application startup.
|
||||||
// The default temporary directory may contain hundreds or thousands of files.
|
// The default temporary directory may contain hundreds or thousands of files.
|
||||||
// To make searching for "marked for deletion" files as fast as possible,
|
// To make searching for "marked for deletion" files as fast as possible,
|
||||||
// use a sub directory that contains only our temporary native libraries.
|
// use a sub directory that contains only our temporary native libraries.
|
||||||
Path tempDir = Paths.get( System.getProperty( "java.io.tmpdir" ) + "/flatlaf.temp" );
|
tmpdir += "\\flatlaf.temp";
|
||||||
|
}
|
||||||
|
|
||||||
|
// create temporary directory
|
||||||
|
Path tempDir = Paths.get( tmpdir );
|
||||||
Files.createDirectories( tempDir );
|
Files.createDirectories( tempDir );
|
||||||
|
|
||||||
|
// delete no longer needed temporary files (from already exited applications)
|
||||||
|
if( SystemInfo.isWindows )
|
||||||
|
deleteTemporaryFiles( tempDir );
|
||||||
|
|
||||||
return tempDir;
|
return tempDir;
|
||||||
} else
|
|
||||||
return null; // use standard temporary directory
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void deleteTemporaryFiles( Path tempDir ) {
|
private static void deleteTemporaryFiles( Path tempDir ) {
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ debug*/
|
|||||||
double scaleFactor = systemScaleFactor * userScaleFactor;
|
double scaleFactor = systemScaleFactor * userScaleFactor;
|
||||||
|
|
||||||
// paint input image icon if not necessary to scale
|
// 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 );
|
imageIcon.paintIcon( c, g, x, y );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ public class SystemInfo
|
|||||||
public static final boolean isJava_9_orLater;
|
public static final boolean isJava_9_orLater;
|
||||||
public static final boolean isJava_11_orLater;
|
public static final boolean isJava_11_orLater;
|
||||||
public static final boolean isJava_15_orLater;
|
public static final boolean isJava_15_orLater;
|
||||||
|
/** @since 2 */ public static final boolean isJava_17_orLater;
|
||||||
|
|
||||||
// Java VMs
|
// Java VMs
|
||||||
public static final boolean isJetBrainsJVM;
|
public static final boolean isJetBrainsJVM;
|
||||||
@@ -82,6 +83,7 @@ public class SystemInfo
|
|||||||
isJava_9_orLater = (javaVersion >= toVersion( 9, 0, 0, 0 ));
|
isJava_9_orLater = (javaVersion >= toVersion( 9, 0, 0, 0 ));
|
||||||
isJava_11_orLater = (javaVersion >= toVersion( 11, 0, 0, 0 ));
|
isJava_11_orLater = (javaVersion >= toVersion( 11, 0, 0, 0 ));
|
||||||
isJava_15_orLater = (javaVersion >= toVersion( 15, 0, 0, 0 ));
|
isJava_15_orLater = (javaVersion >= toVersion( 15, 0, 0, 0 ));
|
||||||
|
isJava_17_orLater = (javaVersion >= toVersion( 17, 0, 0, 0 ));
|
||||||
|
|
||||||
// Java VMs
|
// Java VMs
|
||||||
isJetBrainsJVM = System.getProperty( "java.vm.vendor", "Unknown" )
|
isJetBrainsJVM = System.getProperty( "java.vm.vendor", "Unknown" )
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ import com.formdev.flatlaf.FlatSystemProperties;
|
|||||||
* <p>
|
* <p>
|
||||||
* Two scaling modes are supported by FlatLaf for HiDPI displays:
|
* Two scaling modes are supported by FlatLaf for HiDPI displays:
|
||||||
*
|
*
|
||||||
* <h3>1) system scaling mode</h3>
|
* <h2>1) system scaling mode</h2>
|
||||||
*
|
*
|
||||||
* This mode is supported since Java 9 on all platforms and in some Java 8 VMs
|
* 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
|
* (e.g. Apple and JetBrains). The JRE determines the scale factor per-display and
|
||||||
@@ -54,7 +54,7 @@ import com.formdev.flatlaf.FlatSystemProperties;
|
|||||||
* The scale factor may be different for each connected display.
|
* 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.
|
* The scale factor may change for a window when moving the window from one display to another one.
|
||||||
*
|
*
|
||||||
* <h3>2) user scaling mode</h3>
|
* <h2>2) user scaling mode</h2>
|
||||||
*
|
*
|
||||||
* This mode is mainly for Java 8 compatibility, but is also used on Linux
|
* This mode is mainly for Java 8 compatibility, but is also used on Linux
|
||||||
* or if the default font is changed.
|
* or if the default font is changed.
|
||||||
|
|||||||
@@ -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() );
|
||||||
|
} );
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -166,7 +166,7 @@ Desktop.background = #3E434C
|
|||||||
|
|
||||||
#---- DesktopIcon ----
|
#---- DesktopIcon ----
|
||||||
|
|
||||||
DesktopIcon.background = lighten($Desktop.background,10%)
|
DesktopIcon.background = lighten($Desktop.background,10%,derived)
|
||||||
|
|
||||||
|
|
||||||
#---- InternalFrame ----
|
#---- InternalFrame ----
|
||||||
|
|||||||
@@ -374,7 +374,7 @@ MenuItem.iconTextGap = 6
|
|||||||
MenuItem.textAcceleratorGap = 24
|
MenuItem.textAcceleratorGap = 24
|
||||||
MenuItem.textNoAcceleratorGap = 6
|
MenuItem.textNoAcceleratorGap = 6
|
||||||
MenuItem.acceleratorArrowGap = 2
|
MenuItem.acceleratorArrowGap = 2
|
||||||
MenuItem.acceleratorDelimiter = -
|
MenuItem.acceleratorDelimiter = +
|
||||||
[mac]MenuItem.acceleratorDelimiter =
|
[mac]MenuItem.acceleratorDelimiter =
|
||||||
|
|
||||||
# for MenuItem.selectionType = underline
|
# for MenuItem.selectionType = underline
|
||||||
@@ -514,6 +514,17 @@ ScrollPane.fillUpperCorner = true
|
|||||||
ScrollPane.smoothScrolling = 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 ----
|
||||||
|
|
||||||
Separator.height = 3
|
Separator.height = 3
|
||||||
@@ -617,6 +628,7 @@ TabbedPane.closeCrossLineWidth = {float}1
|
|||||||
Table.rowHeight = 20
|
Table.rowHeight = 20
|
||||||
Table.showHorizontalLines = false
|
Table.showHorizontalLines = false
|
||||||
Table.showVerticalLines = false
|
Table.showVerticalLines = false
|
||||||
|
Table.showTrailingVerticalLine = false
|
||||||
Table.consistentHomeEndKeyBehavior = true
|
Table.consistentHomeEndKeyBehavior = true
|
||||||
Table.intercellSpacing = {dimension}0,0
|
Table.intercellSpacing = {dimension}0,0
|
||||||
Table.scrollPaneBorder = com.formdev.flatlaf.ui.FlatBorder
|
Table.scrollPaneBorder = com.formdev.flatlaf.ui.FlatBorder
|
||||||
@@ -642,10 +654,11 @@ Table.dropLineShortColor = @dropLineShortColor
|
|||||||
#---- TableHeader ----
|
#---- TableHeader ----
|
||||||
|
|
||||||
TableHeader.height = 25
|
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.focusCellBackground = $TableHeader.background
|
||||||
TableHeader.background = @textComponentBackground
|
TableHeader.background = @textComponentBackground
|
||||||
|
TableHeader.showTrailingVerticalLine = false
|
||||||
|
|
||||||
#---- TextArea ----
|
#---- TextArea ----
|
||||||
|
|
||||||
@@ -751,6 +764,7 @@ ToolBar.separatorWidth = 7
|
|||||||
ToolBar.separatorColor = $Separator.foreground
|
ToolBar.separatorColor = $Separator.foreground
|
||||||
|
|
||||||
ToolBar.spacingBorder = $Button.toolbar.spacingInsets
|
ToolBar.spacingBorder = $Button.toolbar.spacingInsets
|
||||||
|
ToolBar.focusableButtons = false
|
||||||
|
|
||||||
|
|
||||||
#---- ToolTipManager ----
|
#---- ToolTipManager ----
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ Desktop.background = #E6EBF0
|
|||||||
|
|
||||||
#---- DesktopIcon ----
|
#---- DesktopIcon ----
|
||||||
|
|
||||||
DesktopIcon.background = darken($Desktop.background,10%)
|
DesktopIcon.background = darken($Desktop.background,10%,derived)
|
||||||
|
|
||||||
|
|
||||||
#---- HelpButton ----
|
#---- HelpButton ----
|
||||||
|
|||||||
@@ -133,8 +133,8 @@ ToggleButton.endBackground = $ToggleButton.background
|
|||||||
|
|
||||||
[Dark_purple]Slider.focusedColor = fade($Component.focusColor,70%,derived)
|
[Dark_purple]Slider.focusedColor = fade($Component.focusColor,70%,derived)
|
||||||
|
|
||||||
[Dracula]ProgressBar.selectionBackground = #fff
|
[Dracula---Zihan_Ma]ProgressBar.selectionBackground = #fff
|
||||||
[Dracula]ProgressBar.selectionForeground = #fff
|
[Dracula---Zihan_Ma]ProgressBar.selectionForeground = #fff
|
||||||
|
|
||||||
[Gradianto_Dark_Fuchsia]MenuItem.checkBackground = @ijMenuCheckBackgroundL10
|
[Gradianto_Dark_Fuchsia]MenuItem.checkBackground = @ijMenuCheckBackgroundL10
|
||||||
[Gradianto_Dark_Fuchsia]MenuItem.underlineSelectionCheckBackground = @ijMenuCheckBackgroundL10
|
[Gradianto_Dark_Fuchsia]MenuItem.underlineSelectionCheckBackground = @ijMenuCheckBackgroundL10
|
||||||
@@ -181,7 +181,7 @@ ToggleButton.endBackground = $ToggleButton.background
|
|||||||
[One_Dark]MenuItem.underlineSelectionCheckBackground = @ijMenuCheckBackgroundL10
|
[One_Dark]MenuItem.underlineSelectionCheckBackground = @ijMenuCheckBackgroundL10
|
||||||
[One_Dark]Slider.focusedColor = fade(#568af2,40%)
|
[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.checkBackground = @ijMenuCheckBackgroundL10
|
||||||
[vuesion-theme]MenuItem.underlineSelectionCheckBackground = @ijMenuCheckBackgroundL10
|
[vuesion-theme]MenuItem.underlineSelectionCheckBackground = @ijMenuCheckBackgroundL10
|
||||||
@@ -198,6 +198,9 @@ ToggleButton.endBackground = $ToggleButton.background
|
|||||||
[dark][author-Mallowigi]MenuItem.checkBackground = @ijMenuCheckBackgroundL20
|
[dark][author-Mallowigi]MenuItem.checkBackground = @ijMenuCheckBackgroundL20
|
||||||
[dark][author-Mallowigi]MenuItem.underlineSelectionCheckBackground = @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.selectionBackground = #fff
|
||||||
[Dracula_Contrast]ProgressBar.selectionForeground = #fff
|
[Dracula_Contrast]ProgressBar.selectionForeground = #fff
|
||||||
|
|
||||||
@@ -237,14 +240,14 @@ ToggleButton.endBackground = $ToggleButton.background
|
|||||||
[Night_Owl_Contrast]ProgressBar.selectionBackground = #ddd
|
[Night_Owl_Contrast]ProgressBar.selectionBackground = #ddd
|
||||||
[Night_Owl_Contrast]ProgressBar.selectionForeground = #ddd
|
[Night_Owl_Contrast]ProgressBar.selectionForeground = #ddd
|
||||||
|
|
||||||
[Solarized_Dark]ProgressBar.selectionBackground = #ccc
|
[Solarized_Dark---Mallowigi]ProgressBar.selectionBackground = #ccc
|
||||||
[Solarized_Dark]ProgressBar.selectionForeground = #ccc
|
[Solarized_Dark---Mallowigi]ProgressBar.selectionForeground = #ccc
|
||||||
|
|
||||||
[Material_Solarized_Dark_Contrast]ProgressBar.selectionBackground = #ccc
|
[Solarized_Dark_Contrast]ProgressBar.selectionBackground = #ccc
|
||||||
[Material_Solarized_Dark_Contrast]ProgressBar.selectionForeground = #ccc
|
[Solarized_Dark_Contrast]ProgressBar.selectionForeground = #ccc
|
||||||
|
|
||||||
[Solarized_Light]ProgressBar.selectionBackground = #222
|
[Solarized_Light---Mallowigi]ProgressBar.selectionBackground = #222
|
||||||
[Solarized_Light]ProgressBar.selectionForeground = #fff
|
[Solarized_Light---Mallowigi]ProgressBar.selectionForeground = #fff
|
||||||
|
|
||||||
[Material_Solarized_Light_Contrast]ProgressBar.selectionBackground = #222
|
[Solarized_Light_Contrast]ProgressBar.selectionBackground = #222
|
||||||
[Material_Solarized_Light_Contrast]ProgressBar.selectionForeground = #fff
|
[Solarized_Light_Contrast]ProgressBar.selectionForeground = #fff
|
||||||
|
|||||||
@@ -0,0 +1,203 @@
|
|||||||
|
/*
|
||||||
|
* 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 static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Component;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Insets;
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.border.Border;
|
||||||
|
import javax.swing.border.LineBorder;
|
||||||
|
import javax.swing.plaf.basic.BasicComboBoxEditor;
|
||||||
|
import javax.swing.plaf.basic.BasicComboBoxRenderer;
|
||||||
|
import org.junit.jupiter.api.AfterAll;
|
||||||
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
|
import com.formdev.flatlaf.util.UIScale;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Karl Tauber
|
||||||
|
*/
|
||||||
|
public class TestFlatComponentSizes
|
||||||
|
{
|
||||||
|
@BeforeAll
|
||||||
|
static void setup() {
|
||||||
|
TestUtils.setup( false );
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterAll
|
||||||
|
static void cleanup() {
|
||||||
|
TestUtils.cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
static float[] factors() {
|
||||||
|
return TestUtils.FACTORS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@MethodSource( "factors" )
|
||||||
|
void sizes( float factor ) {
|
||||||
|
TestUtils.scaleFont( factor );
|
||||||
|
|
||||||
|
|
||||||
|
// should have same default size (minimumWidth is 64)
|
||||||
|
JTextField textField = new JTextField();
|
||||||
|
JFormattedTextField formattedTextField = new JFormattedTextField();
|
||||||
|
JPasswordField passwordField = new JPasswordField();
|
||||||
|
JSpinner spinner = new JSpinner();
|
||||||
|
|
||||||
|
Dimension textFieldSize = textField.getPreferredSize();
|
||||||
|
assertEquals( textFieldSize, formattedTextField.getPreferredSize() );
|
||||||
|
assertEquals( textFieldSize, passwordField.getPreferredSize() );
|
||||||
|
assertEquals( textFieldSize, spinner.getPreferredSize() );
|
||||||
|
|
||||||
|
|
||||||
|
// should have same default size (minimumWidth is 72)
|
||||||
|
JButton button = new JButton( "text" );
|
||||||
|
JComboBox<String> comboBox = new JComboBox<>();
|
||||||
|
JComboBox<String> comboBoxEditable = new JComboBox<>();
|
||||||
|
comboBoxEditable.setEditable( true );
|
||||||
|
|
||||||
|
Dimension buttonSize = button.getPreferredSize();
|
||||||
|
assertEquals( buttonSize, comboBox.getPreferredSize() );
|
||||||
|
assertEquals( buttonSize, comboBoxEditable.getPreferredSize() );
|
||||||
|
|
||||||
|
|
||||||
|
// should have same height
|
||||||
|
JToggleButton toggleButton = new JToggleButton( "text" );
|
||||||
|
|
||||||
|
assertEquals( textFieldSize.height, button.getPreferredSize().height );
|
||||||
|
assertEquals( textFieldSize.height, toggleButton.getPreferredSize().height );
|
||||||
|
|
||||||
|
|
||||||
|
// should have same size
|
||||||
|
JCheckBox checkBox = new JCheckBox( "text" );
|
||||||
|
JRadioButton radioButton = new JRadioButton( "text" );
|
||||||
|
assertEquals( checkBox.getPreferredSize(), radioButton.getPreferredSize() );
|
||||||
|
|
||||||
|
|
||||||
|
// should have same size
|
||||||
|
JMenu menu = new JMenu( "text" );
|
||||||
|
JMenuItem menuItem = new JMenuItem( "text" );
|
||||||
|
JCheckBoxMenuItem checkBoxMenuItem = new JCheckBoxMenuItem( "text" );
|
||||||
|
JRadioButtonMenuItem radioButtonMenuItem = new JRadioButtonMenuItem( "text" );
|
||||||
|
|
||||||
|
Dimension menuSize = menu.getPreferredSize();
|
||||||
|
assertEquals( menuSize, menuItem.getPreferredSize() );
|
||||||
|
assertEquals( menuSize, checkBoxMenuItem.getPreferredSize() );
|
||||||
|
assertEquals( menuSize, radioButtonMenuItem.getPreferredSize() );
|
||||||
|
|
||||||
|
|
||||||
|
TestUtils.resetFont();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@MethodSource( "factors" )
|
||||||
|
void comboBox( float factor ) {
|
||||||
|
TestUtils.scaleFont( factor );
|
||||||
|
|
||||||
|
String[] items = { "t" };
|
||||||
|
JComboBox<String> comboBox = new JComboBox<>( items );
|
||||||
|
JComboBox<String> comboBox2 = new JComboBox<>( items );
|
||||||
|
JComboBox<String> comboBox3 = new JComboBox<>( items );
|
||||||
|
JComboBox<String> comboBox4 = new JComboBox<>( items );
|
||||||
|
|
||||||
|
applyCustomComboBoxRendererBorder( comboBox2, new LineBorder( Color.orange, UIScale.scale( 6 ) ) );
|
||||||
|
applyCustomComboBoxRendererBorder( comboBox3, new BorderWithIcon() );
|
||||||
|
applyCustomComboBoxRendererBorder( comboBox4, null );
|
||||||
|
|
||||||
|
Dimension size = comboBox.getPreferredSize();
|
||||||
|
assertEquals( size.width, comboBox2.getPreferredSize().width );
|
||||||
|
assertEquals( size.height - (2 * UIScale.scale( 2 )) + (2 * UIScale.scale( 6 )), comboBox2.getPreferredSize().height );
|
||||||
|
assertEquals( size, comboBox3.getPreferredSize() );
|
||||||
|
assertEquals( size, comboBox4.getPreferredSize() );
|
||||||
|
|
||||||
|
TestUtils.resetFont();
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings( "unchecked" )
|
||||||
|
private void applyCustomComboBoxRendererBorder( JComboBox<String> comboBox, Border border ) {
|
||||||
|
BasicComboBoxRenderer customRenderer = new BasicComboBoxRenderer();
|
||||||
|
customRenderer.setBorder( border );
|
||||||
|
comboBox.setRenderer( customRenderer );
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@MethodSource( "factors" )
|
||||||
|
void comboBoxEditable( float factor ) {
|
||||||
|
TestUtils.scaleFont( factor );
|
||||||
|
|
||||||
|
String[] items = { "t" };
|
||||||
|
JComboBox<String> comboBox = new JComboBox<>( items );
|
||||||
|
JComboBox<String> comboBox2 = new JComboBox<>( items );
|
||||||
|
JComboBox<String> comboBox3 = new JComboBox<>( items );
|
||||||
|
JComboBox<String> comboBox4 = new JComboBox<>( items );
|
||||||
|
|
||||||
|
comboBox.setEditable( true );
|
||||||
|
comboBox2.setEditable( true );
|
||||||
|
comboBox3.setEditable( true );
|
||||||
|
comboBox4.setEditable( true );
|
||||||
|
|
||||||
|
applyCustomComboBoxEditorBorder( comboBox2, new LineBorder( Color.orange, UIScale.scale( 6 ) ) );
|
||||||
|
applyCustomComboBoxEditorBorder( comboBox3, new BorderWithIcon() );
|
||||||
|
applyCustomComboBoxEditorBorder( comboBox4, null );
|
||||||
|
|
||||||
|
Dimension size = comboBox.getPreferredSize();
|
||||||
|
assertEquals( size.width, comboBox2.getPreferredSize().width );
|
||||||
|
assertEquals( size.height - (2 * UIScale.scale( 2 )) + (2 * UIScale.scale( 6 )), comboBox2.getPreferredSize().height );
|
||||||
|
assertEquals( size, comboBox3.getPreferredSize() );
|
||||||
|
assertEquals( size, comboBox4.getPreferredSize() );
|
||||||
|
|
||||||
|
TestUtils.resetFont();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void applyCustomComboBoxEditorBorder( JComboBox<String> comboBox, Border border ) {
|
||||||
|
JTextField customTextField = new JTextField();
|
||||||
|
if( border != null )
|
||||||
|
customTextField.setBorder( border );
|
||||||
|
comboBox.setEditor( new BasicComboBoxEditor() {
|
||||||
|
@Override
|
||||||
|
protected JTextField createEditorComponent() {
|
||||||
|
return customTextField;
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
//---- class BorderWithIcon -----------------------------------------------
|
||||||
|
|
||||||
|
private static class BorderWithIcon
|
||||||
|
implements Border
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void paintBorder( Component c, Graphics g, int x, int y, int width, int height ) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isBorderOpaque() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Insets getBorderInsets( Component c ) {
|
||||||
|
return new Insets( 0, 0, 0, UIScale.scale( 16 ) + 4 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* 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 org.junit.jupiter.api.BeforeAll;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Karl Tauber
|
||||||
|
*/
|
||||||
|
public class TestFlatComponentSizesWithFocus
|
||||||
|
extends TestFlatComponentSizes
|
||||||
|
{
|
||||||
|
@BeforeAll
|
||||||
|
static void setup() {
|
||||||
|
TestUtils.setup( true );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* 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.Font;
|
||||||
|
import javax.swing.UIManager;
|
||||||
|
import com.formdev.flatlaf.FlatIntelliJLaf;
|
||||||
|
import com.formdev.flatlaf.FlatLightLaf;
|
||||||
|
import com.formdev.flatlaf.FlatSystemProperties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Karl Tauber
|
||||||
|
*/
|
||||||
|
public class TestUtils
|
||||||
|
{
|
||||||
|
public static final float[] FACTORS = new float[] { 1f, 1.25f, 1.5f, 1.75f, 2f, 2.25f, 2.5f, 2.75f, 3f, 3.25f, 3.5f, 3.75f, 4f, 5f, 6f };
|
||||||
|
|
||||||
|
public static void setup( boolean withFocus ) {
|
||||||
|
System.setProperty( FlatSystemProperties.UI_SCALE, "1x" );
|
||||||
|
if( withFocus )
|
||||||
|
FlatIntelliJLaf.setup();
|
||||||
|
else
|
||||||
|
FlatLightLaf.setup();
|
||||||
|
System.clearProperty( FlatSystemProperties.UI_SCALE );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void cleanup() {
|
||||||
|
UIManager.put( "defaultFont", null );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void scaleFont( float factor ) {
|
||||||
|
Font defaultFont = UIManager.getLookAndFeelDefaults().getFont( "defaultFont" );
|
||||||
|
UIManager.put( "defaultFont", defaultFont.deriveFont( (float) Math.round( defaultFont.getSize() * factor ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void resetFont() {
|
||||||
|
UIManager.put( "defaultFont", null );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
|
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
|
||||||
<g fill="none" fill-rule="evenodd">
|
<g fill="none" fill-rule="evenodd">
|
||||||
<rect width="16" height="16" fill="#6E6E6E" rx="3"/>
|
<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"/>
|
<path fill="#FFF" d="M2,8 L8,2 L14,8 L11,8 L11,10 L5,10 L5,8 L2,8 Z"/>
|
||||||
</g>
|
</g>
|
||||||
</svg>
|
</svg>
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 326 B After Width: | Height: | Size: 328 B |
3
flatlaf-core/svg/ClearHoveredIcon.svg
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<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>
|
||||||
|
After Width: | Height: | Size: 446 B |
3
flatlaf-core/svg/ClearIcon.svg
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<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>
|
||||||
|
After Width: | Height: | Size: 202 B |
6
flatlaf-core/svg/SearchIcon.svg
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<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>
|
||||||
|
After Width: | Height: | Size: 526 B |
7
flatlaf-core/svg/SearchWithHistoryIcon.svg
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<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>
|
||||||
|
After Width: | Height: | Size: 579 B |
@@ -18,18 +18,11 @@ plugins {
|
|||||||
`java-library`
|
`java-library`
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
|
||||||
maven {
|
|
||||||
// for using MigLayout snapshot
|
|
||||||
url = uri( "https://oss.sonatype.org/content/repositories/snapshots/" )
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation( project( ":flatlaf-core" ) )
|
implementation( project( ":flatlaf-core" ) )
|
||||||
implementation( project( ":flatlaf-extras" ) )
|
implementation( project( ":flatlaf-extras" ) )
|
||||||
implementation( project( ":flatlaf-intellij-themes" ) )
|
implementation( project( ":flatlaf-intellij-themes" ) )
|
||||||
implementation( "com.miglayout:miglayout-swing:5.3-SNAPSHOT" )
|
implementation( "com.miglayout:miglayout-swing:5.3" )
|
||||||
implementation( "com.jgoodies:jgoodies-forms:1.9.0" )
|
implementation( "com.jgoodies:jgoodies-forms:1.9.0" )
|
||||||
// implementation( project( ":flatlaf-natives-jna" ) )
|
// implementation( project( ":flatlaf-natives-jna" ) )
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import javax.swing.plaf.metal.MetalLookAndFeel;
|
|||||||
import javax.swing.plaf.nimbus.NimbusLookAndFeel;
|
import javax.swing.plaf.nimbus.NimbusLookAndFeel;
|
||||||
import com.formdev.flatlaf.*;
|
import com.formdev.flatlaf.*;
|
||||||
import com.formdev.flatlaf.extras.FlatAnimatedLafChange;
|
import com.formdev.flatlaf.extras.FlatAnimatedLafChange;
|
||||||
|
import com.formdev.flatlaf.util.LoggingFacade;
|
||||||
import com.formdev.flatlaf.util.SystemInfo;
|
import com.formdev.flatlaf.util.SystemInfo;
|
||||||
import com.formdev.flatlaf.util.UIScale;
|
import com.formdev.flatlaf.util.UIScale;
|
||||||
import net.miginfocom.layout.ConstraintParser;
|
import net.miginfocom.layout.ConstraintParser;
|
||||||
@@ -240,7 +241,7 @@ class ControlBar
|
|||||||
frame.setSize( Math.max( prefSize.width, width ), Math.max( prefSize.height, height ) );
|
frame.setSize( Math.max( prefSize.width, width ), Math.max( prefSize.height, height ) );
|
||||||
|
|
||||||
} catch( Exception ex ) {
|
} catch( Exception ex ) {
|
||||||
ex.printStackTrace();
|
LoggingFacade.INSTANCE.logSevere( null, ex );
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,10 @@ package com.formdev.flatlaf.demo;
|
|||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.*;
|
import java.awt.event.*;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.time.Year;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.prefs.Preferences;
|
import java.util.prefs.Preferences;
|
||||||
@@ -34,8 +38,10 @@ import com.formdev.flatlaf.extras.FlatUIDefaultsInspector;
|
|||||||
import com.formdev.flatlaf.extras.components.FlatButton;
|
import com.formdev.flatlaf.extras.components.FlatButton;
|
||||||
import com.formdev.flatlaf.extras.components.FlatButton.ButtonType;
|
import com.formdev.flatlaf.extras.components.FlatButton.ButtonType;
|
||||||
import com.formdev.flatlaf.extras.FlatSVGUtils;
|
import com.formdev.flatlaf.extras.FlatSVGUtils;
|
||||||
|
import com.formdev.flatlaf.ui.FlatUIUtils;
|
||||||
import com.formdev.flatlaf.ui.JBRCustomDecorations;
|
import com.formdev.flatlaf.ui.JBRCustomDecorations;
|
||||||
import com.formdev.flatlaf.util.SystemInfo;
|
import com.formdev.flatlaf.util.SystemInfo;
|
||||||
|
import com.formdev.flatlaf.util.UIScale;
|
||||||
import net.miginfocom.layout.ConstraintParser;
|
import net.miginfocom.layout.ConstraintParser;
|
||||||
import net.miginfocom.layout.LC;
|
import net.miginfocom.layout.LC;
|
||||||
import net.miginfocom.layout.UnitValue;
|
import net.miginfocom.layout.UnitValue;
|
||||||
@@ -127,7 +133,36 @@ class DemoFrame
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void aboutActionPerformed() {
|
private void aboutActionPerformed() {
|
||||||
JOptionPane.showMessageDialog( this, "FlatLaf Demo", "About", JOptionPane.PLAIN_MESSAGE );
|
JLabel titleLabel = new JLabel( "FlatLaf Demo" );
|
||||||
|
Font titleFont = titleLabel.getFont();
|
||||||
|
titleLabel.setFont( titleFont.deriveFont( (float) titleFont.getSize() + UIScale.scale( 6 ) ) );
|
||||||
|
|
||||||
|
String link = "https://www.formdev.com/flatlaf/";
|
||||||
|
JLabel linkLabel = new JLabel( "<html><a href=\"#\">" + link + "</a></html>" );
|
||||||
|
linkLabel.setCursor( Cursor.getPredefinedCursor( Cursor.HAND_CURSOR ) );
|
||||||
|
linkLabel.addMouseListener( new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mouseClicked( MouseEvent e ) {
|
||||||
|
try {
|
||||||
|
Desktop.getDesktop().browse( new URI( link ) );
|
||||||
|
} catch( IOException | URISyntaxException ex ) {
|
||||||
|
JOptionPane.showMessageDialog( linkLabel,
|
||||||
|
"Failed to open '" + link + "' in browser.",
|
||||||
|
"About", JOptionPane.PLAIN_MESSAGE );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
|
||||||
|
|
||||||
|
JOptionPane.showMessageDialog( this,
|
||||||
|
new Object[] {
|
||||||
|
titleLabel,
|
||||||
|
"Demonstrates FlatLaf Swing look and feel",
|
||||||
|
" ",
|
||||||
|
"Copyright 2019-" + Year.now() + " FormDev Software GmbH",
|
||||||
|
linkLabel,
|
||||||
|
},
|
||||||
|
"About", JOptionPane.PLAIN_MESSAGE );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void selectedTabChanged() {
|
private void selectedTabChanged() {
|
||||||
@@ -185,6 +220,8 @@ class DemoFrame
|
|||||||
|
|
||||||
Font font = UIManager.getFont( "defaultFont" );
|
Font font = UIManager.getFont( "defaultFont" );
|
||||||
Font newFont = StyleContext.getDefaultStyleContext().getFont( fontFamily, font.getStyle(), font.getSize() );
|
Font newFont = StyleContext.getDefaultStyleContext().getFont( fontFamily, font.getStyle(), font.getSize() );
|
||||||
|
// StyleContext.getFont() may return a UIResource, which would cause loosing user scale factor on Windows
|
||||||
|
newFont = FlatUIUtils.nonUIResource( newFont );
|
||||||
UIManager.put( "defaultFont", newFont );
|
UIManager.put( "defaultFont", newFont );
|
||||||
|
|
||||||
FlatLaf.updateUI();
|
FlatLaf.updateUI();
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import com.formdev.flatlaf.FlatLightLaf;
|
|||||||
import com.formdev.flatlaf.FlatPropertiesLaf;
|
import com.formdev.flatlaf.FlatPropertiesLaf;
|
||||||
import com.formdev.flatlaf.IntelliJTheme;
|
import com.formdev.flatlaf.IntelliJTheme;
|
||||||
import com.formdev.flatlaf.demo.intellijthemes.IJThemesPanel;
|
import com.formdev.flatlaf.demo.intellijthemes.IJThemesPanel;
|
||||||
|
import com.formdev.flatlaf.util.LoggingFacade;
|
||||||
import com.formdev.flatlaf.util.StringUtils;
|
import com.formdev.flatlaf.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -50,7 +51,7 @@ public class DemoPrefs
|
|||||||
state = Preferences.userRoot().node( rootPath );
|
state = Preferences.userRoot().node( rootPath );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void initLaf( String[] args ) {
|
public static void setupLaf( String[] args ) {
|
||||||
// set look and feel
|
// set look and feel
|
||||||
try {
|
try {
|
||||||
if( args.length > 0 )
|
if( args.length > 0 )
|
||||||
@@ -60,11 +61,11 @@ public class DemoPrefs
|
|||||||
if( IntelliJTheme.ThemeLaf.class.getName().equals( lafClassName ) ) {
|
if( IntelliJTheme.ThemeLaf.class.getName().equals( lafClassName ) ) {
|
||||||
String theme = state.get( KEY_LAF_THEME, "" );
|
String theme = state.get( KEY_LAF_THEME, "" );
|
||||||
if( theme.startsWith( RESOURCE_PREFIX ) )
|
if( theme.startsWith( RESOURCE_PREFIX ) )
|
||||||
IntelliJTheme.install( IJThemesPanel.class.getResourceAsStream( IJThemesPanel.THEMES_PACKAGE + theme.substring( RESOURCE_PREFIX.length() ) ) );
|
IntelliJTheme.setup( IJThemesPanel.class.getResourceAsStream( IJThemesPanel.THEMES_PACKAGE + theme.substring( RESOURCE_PREFIX.length() ) ) );
|
||||||
else if( theme.startsWith( FILE_PREFIX ) )
|
else if( theme.startsWith( FILE_PREFIX ) )
|
||||||
FlatLaf.install( IntelliJTheme.createLaf( new FileInputStream( theme.substring( FILE_PREFIX.length() ) ) ) );
|
FlatLaf.setup( IntelliJTheme.createLaf( new FileInputStream( theme.substring( FILE_PREFIX.length() ) ) ) );
|
||||||
else
|
else
|
||||||
FlatLightLaf.install();
|
FlatLightLaf.setup();
|
||||||
|
|
||||||
if( !theme.isEmpty() )
|
if( !theme.isEmpty() )
|
||||||
UIManager.getLookAndFeelDefaults().put( THEME_UI_KEY, theme );
|
UIManager.getLookAndFeelDefaults().put( THEME_UI_KEY, theme );
|
||||||
@@ -73,9 +74,9 @@ public class DemoPrefs
|
|||||||
if( theme.startsWith( FILE_PREFIX ) ) {
|
if( theme.startsWith( FILE_PREFIX ) ) {
|
||||||
File themeFile = new File( theme.substring( FILE_PREFIX.length() ) );
|
File themeFile = new File( theme.substring( FILE_PREFIX.length() ) );
|
||||||
String themeName = StringUtils.removeTrailing( themeFile.getName(), ".properties" );
|
String themeName = StringUtils.removeTrailing( themeFile.getName(), ".properties" );
|
||||||
FlatLaf.install( new FlatPropertiesLaf( themeName, themeFile ) );
|
FlatLaf.setup( new FlatPropertiesLaf( themeName, themeFile ) );
|
||||||
} else
|
} else
|
||||||
FlatLightLaf.install();
|
FlatLightLaf.setup();
|
||||||
|
|
||||||
if( !theme.isEmpty() )
|
if( !theme.isEmpty() )
|
||||||
UIManager.getLookAndFeelDefaults().put( THEME_UI_KEY, theme );
|
UIManager.getLookAndFeelDefaults().put( THEME_UI_KEY, theme );
|
||||||
@@ -83,10 +84,10 @@ public class DemoPrefs
|
|||||||
UIManager.setLookAndFeel( lafClassName );
|
UIManager.setLookAndFeel( lafClassName );
|
||||||
}
|
}
|
||||||
} catch( Throwable ex ) {
|
} catch( Throwable ex ) {
|
||||||
ex.printStackTrace();
|
LoggingFacade.INSTANCE.logSevere( null, ex );
|
||||||
|
|
||||||
// fallback
|
// fallback
|
||||||
FlatLightLaf.install();
|
FlatLightLaf.setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
// remember active look and feel
|
// remember active look and feel
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ public class FlatLafDemo
|
|||||||
FlatLaf.registerCustomDefaultsSource( "com.formdev.flatlaf.demo" );
|
FlatLaf.registerCustomDefaultsSource( "com.formdev.flatlaf.demo" );
|
||||||
|
|
||||||
// set look and feel
|
// set look and feel
|
||||||
DemoPrefs.initLaf( args );
|
DemoPrefs.setupLaf( args );
|
||||||
|
|
||||||
// install inspectors
|
// install inspectors
|
||||||
FlatInspector.install( "ctrl shift alt X" );
|
FlatInspector.install( "ctrl shift alt X" );
|
||||||
|
|||||||
@@ -18,8 +18,13 @@ package com.formdev.flatlaf.demo.extras;
|
|||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import com.formdev.flatlaf.extras.*;
|
import com.formdev.flatlaf.extras.*;
|
||||||
|
import com.formdev.flatlaf.extras.FlatSVGIcon.ColorFilter;
|
||||||
import com.formdev.flatlaf.extras.components.FlatTriStateCheckBox;
|
import com.formdev.flatlaf.extras.components.FlatTriStateCheckBox;
|
||||||
|
import com.formdev.flatlaf.util.HSLColor;
|
||||||
import net.miginfocom.swing.*;
|
import net.miginfocom.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.HierarchyEvent;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Karl Tauber
|
* @author Karl Tauber
|
||||||
@@ -27,6 +32,9 @@ import net.miginfocom.swing.*;
|
|||||||
public class ExtrasPanel
|
public class ExtrasPanel
|
||||||
extends JPanel
|
extends JPanel
|
||||||
{
|
{
|
||||||
|
private Timer rainbowIconTimer;
|
||||||
|
private int rainbowCounter = 0;
|
||||||
|
|
||||||
public ExtrasPanel() {
|
public ExtrasPanel() {
|
||||||
initComponents();
|
initComponents();
|
||||||
|
|
||||||
@@ -50,6 +58,34 @@ public class ExtrasPanel
|
|||||||
addSVGIcon( "errorDialog.svg" );
|
addSVGIcon( "errorDialog.svg" );
|
||||||
addSVGIcon( "informationDialog.svg" );
|
addSVGIcon( "informationDialog.svg" );
|
||||||
addSVGIcon( "warningDialog.svg" );
|
addSVGIcon( "warningDialog.svg" );
|
||||||
|
|
||||||
|
initRainbowIcon();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initRainbowIcon() {
|
||||||
|
FlatSVGIcon icon = new FlatSVGIcon( "com/formdev/flatlaf/demo/extras/svg/informationDialog.svg" );
|
||||||
|
icon.setColorFilter( new ColorFilter( color -> {
|
||||||
|
rainbowCounter += 1;
|
||||||
|
rainbowCounter %= 255;
|
||||||
|
return Color.getHSBColor( rainbowCounter / 255f, 1, 1 );
|
||||||
|
} ) );
|
||||||
|
rainbowIcon.setIcon( icon );
|
||||||
|
|
||||||
|
rainbowIconTimer = new Timer( 30, e -> {
|
||||||
|
rainbowIcon.repaint();
|
||||||
|
} );
|
||||||
|
|
||||||
|
// start rainbow timer only if panel is shown ("Extras" tab is active)
|
||||||
|
addHierarchyListener( e -> {
|
||||||
|
if( e.getID() == HierarchyEvent.HIERARCHY_CHANGED &&
|
||||||
|
(e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0 )
|
||||||
|
{
|
||||||
|
if( isShowing() )
|
||||||
|
rainbowIconTimer.start();
|
||||||
|
else
|
||||||
|
rainbowIconTimer.stop();
|
||||||
|
}
|
||||||
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addSVGIcon( String name ) {
|
private void addSVGIcon( String name ) {
|
||||||
@@ -60,6 +96,36 @@ public class ExtrasPanel
|
|||||||
triStateLabel1.setText( triStateCheckBox1.getState().toString() );
|
triStateLabel1.setText( triStateCheckBox1.getState().toString() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void redChanged() {
|
||||||
|
brighterToggleButton.setSelected( false );
|
||||||
|
|
||||||
|
Function<Color, Color> mapper = null;
|
||||||
|
if( redToggleButton.isSelected() ) {
|
||||||
|
float[] redHSL = HSLColor.fromRGB( Color.red );
|
||||||
|
mapper = color -> {
|
||||||
|
float[] hsl = HSLColor.fromRGB( color );
|
||||||
|
return HSLColor.toRGB( redHSL[0], 70, hsl[2] );
|
||||||
|
};
|
||||||
|
}
|
||||||
|
FlatSVGIcon.ColorFilter.getInstance().setMapper( mapper );
|
||||||
|
|
||||||
|
// repaint whole application window because global color filter also affects
|
||||||
|
// icons in menubar, toolbar, etc.
|
||||||
|
SwingUtilities.windowForComponent( this ).repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void brighterChanged() {
|
||||||
|
redToggleButton.setSelected( false );
|
||||||
|
|
||||||
|
FlatSVGIcon.ColorFilter.getInstance().setMapper( brighterToggleButton.isSelected()
|
||||||
|
? color -> color.brighter().brighter()
|
||||||
|
: null );
|
||||||
|
|
||||||
|
// repaint whole application window because global color filter also affects
|
||||||
|
// icons in menubar, toolbar, etc.
|
||||||
|
SwingUtilities.windowForComponent( this ).repaint();
|
||||||
|
}
|
||||||
|
|
||||||
private void initComponents() {
|
private void initComponents() {
|
||||||
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
|
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
|
||||||
label4 = new JLabel();
|
label4 = new JLabel();
|
||||||
@@ -69,6 +135,13 @@ public class ExtrasPanel
|
|||||||
label2 = new JLabel();
|
label2 = new JLabel();
|
||||||
svgIconsPanel = new JPanel();
|
svgIconsPanel = new JPanel();
|
||||||
label3 = new JLabel();
|
label3 = new JLabel();
|
||||||
|
separator1 = new JSeparator();
|
||||||
|
label5 = new JLabel();
|
||||||
|
label6 = new JLabel();
|
||||||
|
rainbowIcon = new JLabel();
|
||||||
|
label7 = new JLabel();
|
||||||
|
redToggleButton = new JToggleButton();
|
||||||
|
brighterToggleButton = new JToggleButton();
|
||||||
|
|
||||||
//======== this ========
|
//======== this ========
|
||||||
setLayout(new MigLayout(
|
setLayout(new MigLayout(
|
||||||
@@ -81,6 +154,10 @@ public class ExtrasPanel
|
|||||||
"[]para" +
|
"[]para" +
|
||||||
"[]" +
|
"[]" +
|
||||||
"[]" +
|
"[]" +
|
||||||
|
"[]" +
|
||||||
|
"[]" +
|
||||||
|
"[]" +
|
||||||
|
"[]" +
|
||||||
"[]"));
|
"[]"));
|
||||||
|
|
||||||
//---- label4 ----
|
//---- label4 ----
|
||||||
@@ -119,6 +196,30 @@ public class ExtrasPanel
|
|||||||
//---- label3 ----
|
//---- label3 ----
|
||||||
label3.setText("The icons may change colors when switching to another theme.");
|
label3.setText("The icons may change colors when switching to another theme.");
|
||||||
add(label3, "cell 1 3 2 1");
|
add(label3, "cell 1 3 2 1");
|
||||||
|
add(separator1, "cell 1 4 2 1,growx");
|
||||||
|
|
||||||
|
//---- label5 ----
|
||||||
|
label5.setText("Color filters can be also applied to icons. Globally or for each instance.");
|
||||||
|
add(label5, "cell 1 5 2 1");
|
||||||
|
|
||||||
|
//---- label6 ----
|
||||||
|
label6.setText("Rainbow color filter");
|
||||||
|
add(label6, "cell 1 6 2 1");
|
||||||
|
add(rainbowIcon, "cell 1 6 2 1");
|
||||||
|
|
||||||
|
//---- label7 ----
|
||||||
|
label7.setText("Global icon color filter");
|
||||||
|
add(label7, "cell 1 7 2 1");
|
||||||
|
|
||||||
|
//---- redToggleButton ----
|
||||||
|
redToggleButton.setText("Toggle RED");
|
||||||
|
redToggleButton.addActionListener(e -> redChanged());
|
||||||
|
add(redToggleButton, "cell 1 7 2 1");
|
||||||
|
|
||||||
|
//---- brighterToggleButton ----
|
||||||
|
brighterToggleButton.setText("Toggle brighter");
|
||||||
|
brighterToggleButton.addActionListener(e -> brighterChanged());
|
||||||
|
add(brighterToggleButton, "cell 1 7 2 1");
|
||||||
// JFormDesigner - End of component initialization //GEN-END:initComponents
|
// JFormDesigner - End of component initialization //GEN-END:initComponents
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,5 +231,12 @@ public class ExtrasPanel
|
|||||||
private JLabel label2;
|
private JLabel label2;
|
||||||
private JPanel svgIconsPanel;
|
private JPanel svgIconsPanel;
|
||||||
private JLabel label3;
|
private JLabel label3;
|
||||||
|
private JSeparator separator1;
|
||||||
|
private JLabel label5;
|
||||||
|
private JLabel label6;
|
||||||
|
private JLabel rainbowIcon;
|
||||||
|
private JLabel label7;
|
||||||
|
private JToggleButton redToggleButton;
|
||||||
|
private JToggleButton brighterToggleButton;
|
||||||
// JFormDesigner - End of variables declaration //GEN-END:variables
|
// JFormDesigner - End of variables declaration //GEN-END:variables
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
JFDML JFormDesigner: "7.0.2.0.298" Java: "14" encoding: "UTF-8"
|
JFDML JFormDesigner: "7.0.3.1.342" Java: "16" encoding: "UTF-8"
|
||||||
|
|
||||||
new FormModel {
|
new FormModel {
|
||||||
contentType: "form/swing"
|
contentType: "form/swing"
|
||||||
@@ -6,7 +6,7 @@ new FormModel {
|
|||||||
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
|
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
|
||||||
"$layoutConstraints": "insets dialog,hidemode 3"
|
"$layoutConstraints": "insets dialog,hidemode 3"
|
||||||
"$columnConstraints": "[][][left]"
|
"$columnConstraints": "[][][left]"
|
||||||
"$rowConstraints": "[]para[][][]"
|
"$rowConstraints": "[]para[][][][][][][]"
|
||||||
} ) {
|
} ) {
|
||||||
name: "this"
|
name: "this"
|
||||||
add( new FormComponent( "javax.swing.JLabel" ) {
|
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||||
@@ -56,6 +56,48 @@ new FormModel {
|
|||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
"value": "cell 1 3 2 1"
|
"value": "cell 1 3 2 1"
|
||||||
} )
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JSeparator" ) {
|
||||||
|
name: "separator1"
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 1 4 2 1,growx"
|
||||||
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||||
|
name: "label5"
|
||||||
|
"text": "Color filters can be also applied to icons. Globally or for each instance."
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 1 5 2 1"
|
||||||
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||||
|
name: "label6"
|
||||||
|
"text": "Rainbow color filter"
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 1 6 2 1"
|
||||||
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||||
|
name: "rainbowIcon"
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 1 6 2 1"
|
||||||
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||||
|
name: "label7"
|
||||||
|
"text": "Global icon color filter"
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 1 7 2 1"
|
||||||
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JToggleButton" ) {
|
||||||
|
name: "redToggleButton"
|
||||||
|
"text": "Toggle RED"
|
||||||
|
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "redChanged", false ) )
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 1 7 2 1"
|
||||||
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JToggleButton" ) {
|
||||||
|
name: "brighterToggleButton"
|
||||||
|
"text": "Toggle brighter"
|
||||||
|
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "brighterChanged", false ) )
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 1 7 2 1"
|
||||||
|
} )
|
||||||
}, new FormLayoutConstraints( null ) {
|
}, new FormLayoutConstraints( null ) {
|
||||||
"location": new java.awt.Point( 0, 0 )
|
"location": new java.awt.Point( 0, 0 )
|
||||||
"size": new java.awt.Dimension( 500, 300 )
|
"size": new java.awt.Dimension( 500, 300 )
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import java.nio.charset.StandardCharsets;
|
|||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.StandardOpenOption;
|
import java.nio.file.StandardOpenOption;
|
||||||
|
import com.formdev.flatlaf.util.LoggingFacade;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This tool creates look and feel classes for all themes listed in themes.json.
|
* This tool creates look and feel classes for all themes listed in themes.json.
|
||||||
@@ -120,7 +121,7 @@ public class IJThemesClassGenerator
|
|||||||
Files.write( out, content.getBytes( StandardCharsets.ISO_8859_1 ),
|
Files.write( out, content.getBytes( StandardCharsets.ISO_8859_1 ),
|
||||||
StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING );
|
StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING );
|
||||||
} catch( IOException ex ) {
|
} catch( IOException ex ) {
|
||||||
ex.printStackTrace();
|
LoggingFacade.INSTANCE.logSevere( null, ex );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,9 +161,9 @@ public class IJThemesClassGenerator
|
|||||||
"{\n" +
|
"{\n" +
|
||||||
" public static final String NAME = \"${themeName}\";\n" +
|
" public static final String NAME = \"${themeName}\";\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
" public static boolean install() {\n" +
|
" public static boolean setup() {\n" +
|
||||||
" try {\n" +
|
" try {\n" +
|
||||||
" return install( new ${themeClass}() );\n" +
|
" return setup( new ${themeClass}() );\n" +
|
||||||
" } catch( RuntimeException ex ) {\n" +
|
" } catch( RuntimeException ex ) {\n" +
|
||||||
" return false;\n" +
|
" return false;\n" +
|
||||||
" }\n" +
|
" }\n" +
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* 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.demo.intellijthemes;
|
||||||
|
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.Reader;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
import com.formdev.flatlaf.json.Json;
|
||||||
|
import com.formdev.flatlaf.json.ParseException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This tool checks whether there are duplicate name fields in all theme .json files.
|
||||||
|
*
|
||||||
|
* This is important for following file, where the name is used for theme specific UI defaults:
|
||||||
|
* flatlaf-core/src/main/resources/com/formdev/flatlaf/IntelliJTheme$ThemeLaf.properties
|
||||||
|
*
|
||||||
|
* @author Karl Tauber
|
||||||
|
*/
|
||||||
|
public class IJThemesDuplicateNameChecker
|
||||||
|
{
|
||||||
|
public static void main( String[] args ) {
|
||||||
|
IJThemesManager themesManager = new IJThemesManager();
|
||||||
|
themesManager.loadBundledThemes();
|
||||||
|
|
||||||
|
HashSet<String> names = new HashSet<>();
|
||||||
|
for( IJThemeInfo ti : themesManager.bundledThemes ) {
|
||||||
|
if( ti.sourceCodeUrl == null || ti.sourceCodePath == null )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
String jsonPath = "../flatlaf-intellij-themes/src/main/resources" + IJThemesPanel.THEMES_PACKAGE + ti.resourceName;
|
||||||
|
String name;
|
||||||
|
try {
|
||||||
|
name = readNameFromJson( jsonPath );
|
||||||
|
} catch( IOException ex ) {
|
||||||
|
System.err.println( "Failed to read '" + jsonPath + "'" );
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( names.contains( name ) )
|
||||||
|
System.out.println( "Duplicate name '" + name + "'" );
|
||||||
|
names.add( name );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String readNameFromJson( String jsonPath ) throws IOException {
|
||||||
|
try( Reader reader = new InputStreamReader( new FileInputStream( jsonPath ), StandardCharsets.UTF_8 ) ) {
|
||||||
|
@SuppressWarnings( "unchecked" )
|
||||||
|
Map<String, Object> json = (Map<String, Object>) Json.parse( reader );
|
||||||
|
return (String) json.get( "name" );
|
||||||
|
} catch( ParseException ex ) {
|
||||||
|
throw new IOException( ex.getMessage(), ex );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,6 +26,7 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import com.formdev.flatlaf.json.Json;
|
import com.formdev.flatlaf.json.Json;
|
||||||
|
import com.formdev.flatlaf.util.LoggingFacade;
|
||||||
import com.formdev.flatlaf.util.StringUtils;
|
import com.formdev.flatlaf.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -46,7 +47,7 @@ class IJThemesManager
|
|||||||
try( Reader reader = new InputStreamReader( getClass().getResourceAsStream( "themes.json" ), StandardCharsets.UTF_8 ) ) {
|
try( Reader reader = new InputStreamReader( getClass().getResourceAsStream( "themes.json" ), StandardCharsets.UTF_8 ) ) {
|
||||||
json = (Map<String, Object>) Json.parse( reader );
|
json = (Map<String, Object>) Json.parse( reader );
|
||||||
} catch( IOException ex ) {
|
} catch( IOException ex ) {
|
||||||
ex.printStackTrace();
|
LoggingFacade.INSTANCE.logSevere( null, ex );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ import com.formdev.flatlaf.IntelliJTheme;
|
|||||||
import com.formdev.flatlaf.demo.DemoPrefs;
|
import com.formdev.flatlaf.demo.DemoPrefs;
|
||||||
import com.formdev.flatlaf.extras.FlatAnimatedLafChange;
|
import com.formdev.flatlaf.extras.FlatAnimatedLafChange;
|
||||||
import com.formdev.flatlaf.extras.FlatSVGIcon;
|
import com.formdev.flatlaf.extras.FlatSVGIcon;
|
||||||
|
import com.formdev.flatlaf.util.LoggingFacade;
|
||||||
import com.formdev.flatlaf.util.StringUtils;
|
import com.formdev.flatlaf.util.StringUtils;
|
||||||
import net.miginfocom.swing.*;
|
import net.miginfocom.swing.*;
|
||||||
|
|
||||||
@@ -259,7 +260,7 @@ public class IJThemesPanel
|
|||||||
try {
|
try {
|
||||||
UIManager.setLookAndFeel( themeInfo.lafClassName );
|
UIManager.setLookAndFeel( themeInfo.lafClassName );
|
||||||
} catch( Exception ex ) {
|
} catch( Exception ex ) {
|
||||||
ex.printStackTrace();
|
LoggingFacade.INSTANCE.logSevere( null, ex );
|
||||||
showInformationDialog( "Failed to create '" + themeInfo.lafClassName + "'.", ex );
|
showInformationDialog( "Failed to create '" + themeInfo.lafClassName + "'.", ex );
|
||||||
}
|
}
|
||||||
} else if( themeInfo.themeFile != null ) {
|
} else if( themeInfo.themeFile != null ) {
|
||||||
@@ -267,19 +268,19 @@ public class IJThemesPanel
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if( themeInfo.themeFile.getName().endsWith( ".properties" ) ) {
|
if( themeInfo.themeFile.getName().endsWith( ".properties" ) ) {
|
||||||
FlatLaf.install( new FlatPropertiesLaf( themeInfo.name, themeInfo.themeFile ) );
|
FlatLaf.setup( new FlatPropertiesLaf( themeInfo.name, themeInfo.themeFile ) );
|
||||||
} else
|
} else
|
||||||
FlatLaf.install( IntelliJTheme.createLaf( new FileInputStream( themeInfo.themeFile ) ) );
|
FlatLaf.setup( IntelliJTheme.createLaf( new FileInputStream( themeInfo.themeFile ) ) );
|
||||||
|
|
||||||
DemoPrefs.getState().put( DemoPrefs.KEY_LAF_THEME, DemoPrefs.FILE_PREFIX + themeInfo.themeFile );
|
DemoPrefs.getState().put( DemoPrefs.KEY_LAF_THEME, DemoPrefs.FILE_PREFIX + themeInfo.themeFile );
|
||||||
} catch( Exception ex ) {
|
} catch( Exception ex ) {
|
||||||
ex.printStackTrace();
|
LoggingFacade.INSTANCE.logSevere( null, ex );
|
||||||
showInformationDialog( "Failed to load '" + themeInfo.themeFile + "'.", ex );
|
showInformationDialog( "Failed to load '" + themeInfo.themeFile + "'.", ex );
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
FlatAnimatedLafChange.showSnapshot();
|
FlatAnimatedLafChange.showSnapshot();
|
||||||
|
|
||||||
IntelliJTheme.install( getClass().getResourceAsStream( THEMES_PACKAGE + themeInfo.resourceName ) );
|
IntelliJTheme.setup( getClass().getResourceAsStream( THEMES_PACKAGE + themeInfo.resourceName ) );
|
||||||
DemoPrefs.getState().put( DemoPrefs.KEY_LAF_THEME, DemoPrefs.RESOURCE_PREFIX + themeInfo.resourceName );
|
DemoPrefs.getState().put( DemoPrefs.KEY_LAF_THEME, DemoPrefs.RESOURCE_PREFIX + themeInfo.resourceName );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import java.net.URLConnection;
|
|||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import com.formdev.flatlaf.util.LoggingFacade;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This tool updates all IntelliJ themes listed in themes.json by downloading
|
* This tool updates all IntelliJ themes listed in themes.json by downloading
|
||||||
@@ -61,7 +62,7 @@ public class IJThemesUpdater
|
|||||||
URLConnection con = url.openConnection();
|
URLConnection con = url.openConnection();
|
||||||
Files.copy( con.getInputStream(), out, StandardCopyOption.REPLACE_EXISTING );
|
Files.copy( con.getInputStream(), out, StandardCopyOption.REPLACE_EXISTING );
|
||||||
} catch( IOException ex ) {
|
} catch( IOException ex ) {
|
||||||
ex.printStackTrace();
|
LoggingFacade.INSTANCE.logSevere( null, ex );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
<!-- Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -->
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
|
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
|
||||||
<g fill="none" fill-rule="evenodd" transform="translate(2 2)">
|
<g fill="none" fill-rule="evenodd" transform="translate(2 2)">
|
||||||
<rect width="5.5" height="5.5" fill="#59A869"/>
|
<rect width="5.5" height="5.5" fill="#59A869"/>
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 403 B After Width: | Height: | Size: 550 B |
@@ -1,3 +1,4 @@
|
|||||||
|
<!-- Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -->
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
|
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
|
||||||
<g fill="none" fill-rule="evenodd">
|
<g fill="none" fill-rule="evenodd">
|
||||||
<path fill="#6E6E6E" d="M11,3 L4,3 L4,11 L2,11 L2,1 L11,1 L11,3 Z"/>
|
<path fill="#6E6E6E" d="M11,3 L4,3 L4,11 L2,11 L2,1 L11,1 L11,3 Z"/>
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 363 B After Width: | Height: | Size: 510 B |
@@ -1,3 +1,4 @@
|
|||||||
|
<!-- Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -->
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
|
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
|
||||||
<polygon fill="#59A869" fill-rule="evenodd" points="4 2 14 8 4 14"/>
|
<polygon fill="#59A869" fill-rule="evenodd" points="4 2 14 8 4 14"/>
|
||||||
</svg>
|
</svg>
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 162 B After Width: | Height: | Size: 309 B |
@@ -1,3 +1,4 @@
|
|||||||
|
<!-- Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -->
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
|
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
|
||||||
<g fill="none" fill-rule="evenodd">
|
<g fill="none" fill-rule="evenodd">
|
||||||
<rect width="6" height="1" x="5" y="12" fill="#6E6E6E"/>
|
<rect width="6" height="1" x="5" y="12" fill="#6E6E6E"/>
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 493 B After Width: | Height: | Size: 640 B |
@@ -1,3 +1,4 @@
|
|||||||
|
<!-- Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -->
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
|
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
|
||||||
<g fill="none" fill-rule="evenodd">
|
<g fill="none" fill-rule="evenodd">
|
||||||
<rect width="6" height="1" x="5" y="12" fill="#6E6E6E"/>
|
<rect width="6" height="1" x="5" y="12" fill="#6E6E6E"/>
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 493 B After Width: | Height: | Size: 640 B |