mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-12 06:57:13 -06:00
Compare commits
109 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
069a7c809c | ||
|
|
883b4d735a | ||
|
|
9f39b269bb | ||
|
|
36c405c708 | ||
|
|
bc7c68ebe4 | ||
|
|
6c502ad4c5 | ||
|
|
100aa0b621 | ||
|
|
8e42b19934 | ||
|
|
1a456d5d68 | ||
|
|
e83c26a76a | ||
|
|
6e7c2a616b | ||
|
|
0699454df8 | ||
|
|
92c110548a | ||
|
|
ca88023560 | ||
|
|
12fc2299ec | ||
|
|
2089c77b84 | ||
|
|
4f5a3e8d8b | ||
|
|
95522846ac | ||
|
|
614ac956de | ||
|
|
c228362c01 | ||
|
|
f6c5db07f2 | ||
|
|
78e7839213 | ||
|
|
86a4f306c6 | ||
|
|
0e523f1193 | ||
|
|
9041a16b22 | ||
|
|
596ff3382d | ||
|
|
cbd80252ed | ||
|
|
bcd7a7e3dd | ||
|
|
9c98f1a553 | ||
|
|
c3d214aa23 | ||
|
|
d301f6e104 | ||
|
|
eb9fa585f7 | ||
|
|
16c6ffb032 | ||
|
|
7858e42e37 | ||
|
|
30132aa6b0 | ||
|
|
bf4d4cc2c5 | ||
|
|
9f0554c883 | ||
|
|
218ea6ce47 | ||
|
|
0baae7da8b | ||
|
|
fb4576fc1b | ||
|
|
16f3f9e6ff | ||
|
|
fee7cf6265 | ||
|
|
2dd75c4a64 | ||
|
|
d2f46cd0b5 | ||
|
|
10914083e6 | ||
|
|
5d167da55e | ||
|
|
b381e20e57 | ||
|
|
475cc9a9a5 | ||
|
|
264d6fbd6d | ||
|
|
2826cf379b | ||
|
|
d28745df29 | ||
|
|
94f9e4a1be | ||
|
|
ec547e1d65 | ||
|
|
61d4eb649b | ||
|
|
52ad15e375 | ||
|
|
ff00a6c0f0 | ||
|
|
9b1ebd658d | ||
|
|
f842530537 | ||
|
|
63077bbb19 | ||
|
|
4dad337377 | ||
|
|
10a965d765 | ||
|
|
3e9c9c9066 | ||
|
|
8b5a738e65 | ||
|
|
2c041dce3a | ||
|
|
ef151c68f4 | ||
|
|
52feaac92a | ||
|
|
cddbb3d7d4 | ||
|
|
42764550e6 | ||
|
|
6ee737b314 | ||
|
|
f460ef7685 | ||
|
|
9977bcb468 | ||
|
|
7437d984c7 | ||
|
|
5cd0b2403c | ||
|
|
a372da22f3 | ||
|
|
8b10d3ba5a | ||
|
|
a8b15c6a12 | ||
|
|
23bac7e5fd | ||
|
|
b82ee2ef61 | ||
|
|
b7761f4b71 | ||
|
|
f9a4f9771c | ||
|
|
d2acb2c98a | ||
|
|
d60bd5df14 | ||
|
|
73b6ca3762 | ||
|
|
6c18431a30 | ||
|
|
a49d20249f | ||
|
|
ad384acd57 | ||
|
|
69851b7f3a | ||
|
|
92b53bf0df | ||
|
|
93e0496fd2 | ||
|
|
5151951f46 | ||
|
|
58dbccec2d | ||
|
|
90de14d013 | ||
|
|
5f961618bf | ||
|
|
37c375e2fa | ||
|
|
1758c175ed | ||
|
|
96f2a02cfa | ||
|
|
96d4bda6c8 | ||
|
|
02cf6050a1 | ||
|
|
38cf32a2e9 | ||
|
|
2ae7589d14 | ||
|
|
bcb2e1f0a1 | ||
|
|
14932d3f07 | ||
|
|
c3b9dc397d | ||
|
|
58b653f55d | ||
|
|
1dcdc42dde | ||
|
|
58a0a16985 | ||
|
|
a117243f14 | ||
|
|
22411060be | ||
|
|
045263ae58 |
6
.github/workflows/ci.yml
vendored
6
.github/workflows/ci.yml
vendored
@@ -26,6 +26,10 @@ jobs:
|
|||||||
- 8
|
- 8
|
||||||
- 11 # LTS
|
- 11 # LTS
|
||||||
- 17 # LTS
|
- 17 # LTS
|
||||||
|
toolchain: [""]
|
||||||
|
include:
|
||||||
|
- java: 17
|
||||||
|
toolchain: 19 # latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
@@ -41,7 +45,7 @@ jobs:
|
|||||||
cache: gradle
|
cache: gradle
|
||||||
|
|
||||||
- name: Build with Gradle
|
- name: Build with Gradle
|
||||||
run: ./gradlew build
|
run: ./gradlew build -Dtoolchain=${{ matrix.toolchain }}
|
||||||
|
|
||||||
- name: Upload artifacts
|
- name: Upload artifacts
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v3
|
||||||
|
|||||||
22
.github/workflows/natives.yml
vendored
22
.github/workflows/natives.yml
vendored
@@ -9,20 +9,26 @@ on:
|
|||||||
tags:
|
tags:
|
||||||
- '[0-9]*'
|
- '[0-9]*'
|
||||||
paths:
|
paths:
|
||||||
- 'flatlaf-natives/flatlaf-natives-windows/**'
|
- 'flatlaf-natives/**'
|
||||||
- '.github/workflows/natives.yml'
|
- '.github/workflows/natives.yml'
|
||||||
- 'gradle/wrapper/gradle-wrapper.properties'
|
- 'gradle/wrapper/gradle-wrapper.properties'
|
||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
branches:
|
||||||
- '*'
|
- '*'
|
||||||
paths:
|
paths:
|
||||||
- 'flatlaf-natives/flatlaf-natives-windows/**'
|
- 'flatlaf-natives/**'
|
||||||
- '.github/workflows/natives.yml'
|
- '.github/workflows/natives.yml'
|
||||||
- 'gradle/wrapper/gradle-wrapper.properties'
|
- 'gradle/wrapper/gradle-wrapper.properties'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
Windows:
|
Natives:
|
||||||
runs-on: windows-latest
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os:
|
||||||
|
- windows
|
||||||
|
- ubuntu
|
||||||
|
|
||||||
|
runs-on: ${{ matrix.os }}-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
@@ -37,14 +43,14 @@ jobs:
|
|||||||
cache: gradle
|
cache: gradle
|
||||||
|
|
||||||
- name: Build with Gradle
|
- name: Build with Gradle
|
||||||
# --no-daemon is necessary on Windows otherwise caching Gradle would fail with:
|
# --no-daemon is necessary on Windows otherwise caching Gradle would fail with:
|
||||||
# tar.exe: Couldn't open ~/.gradle/caches/modules-2/modules-2.lock: Permission denied
|
# tar.exe: Couldn't open ~/.gradle/caches/modules-2/modules-2.lock: Permission denied
|
||||||
run: ./gradlew :flatlaf-natives-windows:build-natives --no-daemon
|
run: ./gradlew build-natives --no-daemon
|
||||||
|
|
||||||
- name: Upload artifacts
|
- name: Upload artifacts
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: FlatLaf-natives-windows-build-artifacts
|
name: FlatLaf-natives-build-artifacts-${{ matrix.os }}
|
||||||
path: |
|
path: |
|
||||||
flatlaf-core/src/main/resources/com/formdev/flatlaf/natives
|
flatlaf-core/src/main/resources/com/formdev/flatlaf/natives
|
||||||
flatlaf-natives/flatlaf-natives-windows/build
|
flatlaf-natives/flatlaf-natives-*/build
|
||||||
|
|||||||
128
CHANGELOG.md
128
CHANGELOG.md
@@ -1,6 +1,132 @@
|
|||||||
FlatLaf Change Log
|
FlatLaf Change Log
|
||||||
==================
|
==================
|
||||||
|
|
||||||
|
## 2.6
|
||||||
|
|
||||||
|
#### New features and improvements
|
||||||
|
|
||||||
|
- If value of system property `flatlaf.nativeLibraryPath` is `system`, then
|
||||||
|
`System.loadLibrary(String)` is used to load the native library.
|
||||||
|
- TabbedPane: Switch and close tabs on left mouse click only. (PR #595)
|
||||||
|
|
||||||
|
#### Fixed bugs
|
||||||
|
|
||||||
|
- ComboBox and Spinner: Fixed missing arrow buttons if preferred height is zero.
|
||||||
|
Minimum width of arrow buttons is 3/4 of default width.
|
||||||
|
- MenuBar: Fixed NPE in `FlatMenuItemRenderer.getTopLevelFont()` if menu item
|
||||||
|
does not have a parent. (issue #600; regression since implementing #589 in
|
||||||
|
FlatLaf 2.5)
|
||||||
|
- ScrollBar: Show "pressed" feedback on track/thumb only for left mouse button.
|
||||||
|
If absolute positioning is enabled (the default), then also for middle mouse
|
||||||
|
button.
|
||||||
|
- Arrow buttons in ComboBox, Spinner, ScrollBar and TabbedPane: Show "pressed"
|
||||||
|
feedback only for left mouse button.
|
||||||
|
- ScaledImageIcon: Do not throw exceptions if image was has invalid size (e.g.
|
||||||
|
not found). Instead, paint a red rectangle (similar to `FlatSVGIcon`).
|
||||||
|
- Fixed NPE in `FlatUIUtils.isCellEditor()`. (issue #601)
|
||||||
|
|
||||||
|
|
||||||
|
## 2.5
|
||||||
|
|
||||||
|
#### New features and improvements
|
||||||
|
|
||||||
|
- Linux: Use X11 window manager events to move window and to show window menu
|
||||||
|
(right-click on window title bar), if custom window decorations are enabled.
|
||||||
|
This gives FlatLaf windows a more "native" feeling. (issue #482)
|
||||||
|
- MenuBar: Support different menu selection style UI defaults for `MenuBar` and
|
||||||
|
`MenuItem`. (issue #587)
|
||||||
|
- MenuBar: Top level menus now use `MenuBar.font` instead of `Menu.font`. (issue
|
||||||
|
#589)
|
||||||
|
- PasswordField: Reveal button is now hidden (and turned off) if password field
|
||||||
|
is disabled. (issue #501)
|
||||||
|
- TabbedPane: New option to disable tab run rotation in wrap layout. Set UI
|
||||||
|
value `TabbedPane.rotateTabRuns` to `false`. (issue #574)
|
||||||
|
- Window decorations:
|
||||||
|
- Added client property to mark components in embedded menu bar as "caption"
|
||||||
|
(allow moving window). (issue #569)
|
||||||
|
- Option to show window icon only in frames, but not in dialogs. Set UI value
|
||||||
|
`TitlePane.showIconInDialogs` to `false`. (issue #589)
|
||||||
|
- Added UI value `TitlePane.font` to customize window title font. (issue #589)
|
||||||
|
- Added system property `flatlaf.updateUIOnSystemFontChange` to allow disabling
|
||||||
|
automatic UI update when system font changes. (issue #580)
|
||||||
|
|
||||||
|
#### Fixed bugs
|
||||||
|
|
||||||
|
- Fixed missing UI value `MenuItem.acceleratorDelimiter` on macOS. (was `null`,
|
||||||
|
is now an empty string)
|
||||||
|
- Fixed possible exception in `FlatUIUtils.resetRenderingHints()`. (issue #575)
|
||||||
|
- Fixed AWT components on macOS, which use Swing components internally. (issue
|
||||||
|
#583)
|
||||||
|
- SwingX: Fixed missing highlighting of "today" in `JXMonthView` and
|
||||||
|
`JXDatePicker`.
|
||||||
|
|
||||||
|
|
||||||
|
## 2.4
|
||||||
|
|
||||||
|
#### New features and improvements
|
||||||
|
|
||||||
|
- Native window decorations (Windows 10/11 only):
|
||||||
|
- There is now a small area at top of the embedded menu bar to resize the
|
||||||
|
window.
|
||||||
|
- Improved window title bar layout for small window widths:
|
||||||
|
- Width of iconify/maximize/close buttons is reduced (if necessary) to give
|
||||||
|
more space to embedded menu bar and title.
|
||||||
|
- Window title now has a minimum width to always allow moving window
|
||||||
|
(click-and-drag on window title). Instead, embedded menu bar is made
|
||||||
|
smaller.
|
||||||
|
- Option to show window icon beside window title, if menu bar is embedded or
|
||||||
|
title is centered. Set UI value `TitlePane.showIconBesideTitle` to `true`.
|
||||||
|
- No longer reduce height of window title bar if it has an embedded menu bar
|
||||||
|
and is maximized.
|
||||||
|
|
||||||
|
#### Fixed bugs
|
||||||
|
|
||||||
|
- ComboBox: Fixed vertical alignment of text in popup list with text in combo
|
||||||
|
box in IntelliJ/Darcula themes.
|
||||||
|
- Menus: Fixed application freeze under very special conditions (invoking
|
||||||
|
`FlatLaf.initialize()` twice in NetBeans GUI builder) and using menu that has
|
||||||
|
submenus. See
|
||||||
|
[NetBeans issue #4231](https://github.com/apache/netbeans/issues/4231#issuecomment-1179611682)
|
||||||
|
for details.
|
||||||
|
- MenuItem: Fixed sometimes wrapped HTML text on HiDPI screens on Windows.
|
||||||
|
- TableHeader: Fixed exception when changing table structure (e.g. removing
|
||||||
|
column) from a table header popup menu action. (issue #532)
|
||||||
|
- `HiDPIUtils.paintAtScale1x()` now supports rotated graphics. (issue #557)
|
||||||
|
- Typography: No longer use `Consolas` or `Courier New` as monospaced font on
|
||||||
|
Windows because they have bad vertically placement.
|
||||||
|
- Native window decorations (Windows 10/11 only):
|
||||||
|
- Do not center window title if embedded menu bar is empty or has no menus at
|
||||||
|
left side, but some components at right side. (issue #558)
|
||||||
|
- Do not use window decorations if system property `sun.java2d.opengl` is
|
||||||
|
`true` on Windows 10. (issue #540)
|
||||||
|
- Fixed missing top window border in dark themes if window drop shadows are
|
||||||
|
disabled in system settings. (issue #554; Windows 10 only)
|
||||||
|
- Right-to-left component orientation of title bar was lost when switching
|
||||||
|
theme.
|
||||||
|
|
||||||
|
|
||||||
|
## 2.3
|
||||||
|
|
||||||
|
#### New features and improvements
|
||||||
|
|
||||||
|
- FileChooser: Added (optional) shortcuts panel. On Windows it contains "Recent
|
||||||
|
Items", "Desktop", "Documents", "This PC" and "Network". On macOS and Linux it
|
||||||
|
is empty/hidden. (issue #100)
|
||||||
|
- Button and ToggleButton: Added missing foreground colors for hover, pressed,
|
||||||
|
focused and selected states. (issue #535)
|
||||||
|
- Table: Optionally paint alternating rows below table if table is smaller than
|
||||||
|
scroll pane. Set UI value `Table.paintOutsideAlternateRows` to `true`.
|
||||||
|
Requires that `Table.alternateRowColor` is set to a color. (issue #504)
|
||||||
|
- ToggleButton: Made the underline placement of tab-style toggle buttons
|
||||||
|
configurable. (PR #530; issue #529)
|
||||||
|
- Added spanish translation. (PR #525)
|
||||||
|
|
||||||
|
#### Fixed bugs
|
||||||
|
|
||||||
|
- IntelliJ Themes: Fixed `TitledBorder` text color in "Monokai Pro" theme.
|
||||||
|
(issue #524)
|
||||||
|
|
||||||
|
|
||||||
## 2.2
|
## 2.2
|
||||||
|
|
||||||
#### New features and improvements
|
#### New features and improvements
|
||||||
@@ -141,7 +267,7 @@ FlatLaf Change Log
|
|||||||
- Possibility to hide window title bar icon (for single window set client
|
- Possibility to hide window title bar icon (for single window set client
|
||||||
property `JRootPane.titleBarShowIcon` to `false`; for all windows set UI
|
property `JRootPane.titleBarShowIcon` to `false`; for all windows set UI
|
||||||
value `TitlePane.showIcon` to `false`).
|
value `TitlePane.showIcon` to `false`).
|
||||||
- OptionPane: Hide window title bar icon by default. Can be be made visibly by
|
- OptionPane: Hide window title bar icon by default. Can be made visibly by
|
||||||
setting UI default `OptionPane.showIcon` to `true`. (issue #416)
|
setting UI default `OptionPane.showIcon` to `true`. (issue #416)
|
||||||
- No longer show the Java "duke/cup" icon if no window icon image is set.
|
- No longer show the Java "duke/cup" icon if no window icon image is set.
|
||||||
(issue #416)
|
(issue #416)
|
||||||
|
|||||||
@@ -14,8 +14,8 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
val releaseVersion = "2.2"
|
val releaseVersion = "2.6"
|
||||||
val developmentVersion = "2.3-SNAPSHOT"
|
val developmentVersion = "3.0-SNAPSHOT"
|
||||||
|
|
||||||
version = if( java.lang.Boolean.getBoolean( "release" ) ) releaseVersion else developmentVersion
|
version = if( java.lang.Boolean.getBoolean( "release" ) ) releaseVersion else developmentVersion
|
||||||
|
|
||||||
@@ -37,6 +37,9 @@ println( "----------------------------------------------------------------------
|
|||||||
println( "FlatLaf Version: ${version}" )
|
println( "FlatLaf Version: ${version}" )
|
||||||
println( "Gradle ${gradle.gradleVersion} at ${gradle.gradleHomeDir}" )
|
println( "Gradle ${gradle.gradleVersion} at ${gradle.gradleHomeDir}" )
|
||||||
println( "Java ${System.getProperty( "java.version" )}" )
|
println( "Java ${System.getProperty( "java.version" )}" )
|
||||||
|
val toolchainJavaVersion = System.getProperty( "toolchain" )
|
||||||
|
if( !toolchainJavaVersion.isNullOrEmpty() )
|
||||||
|
println( "Java toolchain ${toolchainJavaVersion}" )
|
||||||
println()
|
println()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
46
buildSrc/src/main/kotlin/flatlaf-cpp-library.gradle.kts
Normal file
46
buildSrc/src/main/kotlin/flatlaf-cpp-library.gradle.kts
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
`cpp-library`
|
||||||
|
}
|
||||||
|
|
||||||
|
library {
|
||||||
|
// disable debuggable for release builds to make shared libraries smaller
|
||||||
|
binaries.configureEach( CppSharedLibrary::class ) {
|
||||||
|
with( compileTask.get() ) {
|
||||||
|
if( name.contains( "Release" ) )
|
||||||
|
isDebuggable = false
|
||||||
|
}
|
||||||
|
with( linkTask.get() ) {
|
||||||
|
if( name.contains( "Release" ) )
|
||||||
|
debuggable.set( false )
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks {
|
||||||
|
withType<CppCompile>().configureEach {
|
||||||
|
doFirst {
|
||||||
|
println( "Used Tool Chain:" )
|
||||||
|
println( " - ${toolChain.get()}" )
|
||||||
|
println( "Available Tool Chains:" )
|
||||||
|
toolChains.forEach {
|
||||||
|
println( " - $it" )
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
36
buildSrc/src/main/kotlin/flatlaf-jni-headers.gradle.kts
Normal file
36
buildSrc/src/main/kotlin/flatlaf-jni-headers.gradle.kts
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
open class JniHeadersExtension {
|
||||||
|
var headers: List<String> = emptyList()
|
||||||
|
}
|
||||||
|
|
||||||
|
val extension = project.extensions.create<JniHeadersExtension>( "flatlafJniHeaders" )
|
||||||
|
|
||||||
|
|
||||||
|
tasks {
|
||||||
|
register<Copy>( "jni-headers" ) {
|
||||||
|
// depend on :flatlaf-core:compileJava because it generates the JNI headers
|
||||||
|
dependsOn( ":flatlaf-core:compileJava" )
|
||||||
|
|
||||||
|
from( project( ":flatlaf-core" ).buildDir.resolve( "generated/jni-headers" ) )
|
||||||
|
into( "src/main/headers" )
|
||||||
|
include( extension.headers )
|
||||||
|
filter<org.apache.tools.ant.filters.FixCrLfFilter>(
|
||||||
|
"eol" to org.apache.tools.ant.filters.FixCrLfFilter.CrLf.newInstance( "lf" )
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -61,8 +61,6 @@ if( JavaVersion.current() >= JavaVersion.VERSION_1_9 ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
jar {
|
jar {
|
||||||
manifest.attributes( "Multi-Release" to "true" )
|
|
||||||
|
|
||||||
from( sourceSets["module-info"].output ) {
|
from( sourceSets["module-info"].output ) {
|
||||||
include( "module-info.class" )
|
include( "module-info.class" )
|
||||||
}
|
}
|
||||||
|
|||||||
26
buildSrc/src/main/kotlin/flatlaf-toolchain.gradle.kts
Normal file
26
buildSrc/src/main/kotlin/flatlaf-toolchain.gradle.kts
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
java
|
||||||
|
}
|
||||||
|
|
||||||
|
val toolchainJavaVersion = System.getProperty( "toolchain" )
|
||||||
|
if( !toolchainJavaVersion.isNullOrEmpty() ) {
|
||||||
|
java.toolchain {
|
||||||
|
languageVersion.set( JavaLanguageVersion.of( toolchainJavaVersion ) )
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
`java-library`
|
`java-library`
|
||||||
|
`flatlaf-toolchain`
|
||||||
`flatlaf-module-info`
|
`flatlaf-module-info`
|
||||||
`flatlaf-java9`
|
`flatlaf-java9`
|
||||||
`flatlaf-publish`
|
`flatlaf-publish`
|
||||||
@@ -29,7 +30,7 @@ dependencies {
|
|||||||
testRuntimeOnly( "org.junit.jupiter:junit-jupiter-engine" )
|
testRuntimeOnly( "org.junit.jupiter:junit-jupiter-engine" )
|
||||||
|
|
||||||
// https://github.com/jtulach/netbeans-apitest
|
// https://github.com/jtulach/netbeans-apitest
|
||||||
sigtest( "org.netbeans.tools:sigtest-maven-plugin:1.4" )
|
sigtest( "org.netbeans.tools:sigtest-maven-plugin:1.7" )
|
||||||
}
|
}
|
||||||
|
|
||||||
java {
|
java {
|
||||||
@@ -66,6 +67,9 @@ tasks {
|
|||||||
test {
|
test {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
testLogging.exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
|
testLogging.exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
|
||||||
|
|
||||||
|
if( JavaVersion.current() >= JavaVersion.VERSION_1_9 )
|
||||||
|
jvmArgs( listOf( "--add-opens", "java.desktop/javax.swing.plaf.basic=ALL-UNNAMED" ) )
|
||||||
}
|
}
|
||||||
|
|
||||||
register( "sigtestGenerate" ) {
|
register( "sigtestGenerate" ) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#Signature file v4.1
|
#Signature file v4.1
|
||||||
#Version 2.1
|
#Version 2.5
|
||||||
|
|
||||||
CLSS public abstract interface com.formdev.flatlaf.FlatClientProperties
|
CLSS public abstract interface com.formdev.flatlaf.FlatClientProperties
|
||||||
fld public final static java.lang.String BUTTON_TYPE = "JButton.buttonType"
|
fld public final static java.lang.String BUTTON_TYPE = "JButton.buttonType"
|
||||||
@@ -11,6 +11,7 @@ fld public final static java.lang.String BUTTON_TYPE_TAB = "tab"
|
|||||||
fld public final static java.lang.String BUTTON_TYPE_TOOLBAR_BUTTON = "toolBarButton"
|
fld public final static java.lang.String BUTTON_TYPE_TOOLBAR_BUTTON = "toolBarButton"
|
||||||
fld public final static java.lang.String COMPONENT_FOCUS_OWNER = "JComponent.focusOwner"
|
fld public final static java.lang.String COMPONENT_FOCUS_OWNER = "JComponent.focusOwner"
|
||||||
fld public final static java.lang.String COMPONENT_ROUND_RECT = "JComponent.roundRect"
|
fld public final static java.lang.String COMPONENT_ROUND_RECT = "JComponent.roundRect"
|
||||||
|
fld public final static java.lang.String COMPONENT_TITLE_BAR_CAPTION = "JComponent.titleBarCaption"
|
||||||
fld public final static java.lang.String MENU_BAR_EMBEDDED = "JRootPane.menuBarEmbedded"
|
fld public final static java.lang.String MENU_BAR_EMBEDDED = "JRootPane.menuBarEmbedded"
|
||||||
fld public final static java.lang.String MINIMUM_HEIGHT = "JComponent.minimumHeight"
|
fld public final static java.lang.String MINIMUM_HEIGHT = "JComponent.minimumHeight"
|
||||||
fld public final static java.lang.String MINIMUM_WIDTH = "JComponent.minimumWidth"
|
fld public final static java.lang.String MINIMUM_WIDTH = "JComponent.minimumWidth"
|
||||||
@@ -30,6 +31,9 @@ fld public final static java.lang.String SELECT_ALL_ON_FOCUS_POLICY = "JTextFiel
|
|||||||
fld public final static java.lang.String SELECT_ALL_ON_FOCUS_POLICY_ALWAYS = "always"
|
fld public final static java.lang.String SELECT_ALL_ON_FOCUS_POLICY_ALWAYS = "always"
|
||||||
fld public final static java.lang.String SELECT_ALL_ON_FOCUS_POLICY_NEVER = "never"
|
fld public final static java.lang.String SELECT_ALL_ON_FOCUS_POLICY_NEVER = "never"
|
||||||
fld public final static java.lang.String SELECT_ALL_ON_FOCUS_POLICY_ONCE = "once"
|
fld public final static java.lang.String SELECT_ALL_ON_FOCUS_POLICY_ONCE = "once"
|
||||||
|
fld public final static java.lang.String SPLIT_PANE_EXPANDABLE_SIDE = "JSplitPane.expandableSide"
|
||||||
|
fld public final static java.lang.String SPLIT_PANE_EXPANDABLE_SIDE_LEFT = "left"
|
||||||
|
fld public final static java.lang.String SPLIT_PANE_EXPANDABLE_SIDE_RIGHT = "right"
|
||||||
fld public final static java.lang.String SQUARE_SIZE = "JButton.squareSize"
|
fld public final static java.lang.String SQUARE_SIZE = "JButton.squareSize"
|
||||||
fld public final static java.lang.String STYLE = "FlatLaf.style"
|
fld public final static java.lang.String STYLE = "FlatLaf.style"
|
||||||
fld public final static java.lang.String STYLE_CLASS = "FlatLaf.styleClass"
|
fld public final static java.lang.String STYLE_CLASS = "FlatLaf.styleClass"
|
||||||
@@ -72,6 +76,7 @@ fld public final static java.lang.String TABBED_PANE_TRAILING_COMPONENT = "JTabb
|
|||||||
fld public final static java.lang.String TAB_BUTTON_SELECTED_BACKGROUND = "JToggleButton.tab.selectedBackground"
|
fld public final static java.lang.String TAB_BUTTON_SELECTED_BACKGROUND = "JToggleButton.tab.selectedBackground"
|
||||||
fld public final static java.lang.String TAB_BUTTON_UNDERLINE_COLOR = "JToggleButton.tab.underlineColor"
|
fld public final static java.lang.String TAB_BUTTON_UNDERLINE_COLOR = "JToggleButton.tab.underlineColor"
|
||||||
fld public final static java.lang.String TAB_BUTTON_UNDERLINE_HEIGHT = "JToggleButton.tab.underlineHeight"
|
fld public final static java.lang.String TAB_BUTTON_UNDERLINE_HEIGHT = "JToggleButton.tab.underlineHeight"
|
||||||
|
fld public final static java.lang.String TAB_BUTTON_UNDERLINE_PLACEMENT = "JToggleButton.tab.underlinePlacement"
|
||||||
fld public final static java.lang.String TEXT_FIELD_CLEAR_CALLBACK = "JTextField.clearCallback"
|
fld public final static java.lang.String TEXT_FIELD_CLEAR_CALLBACK = "JTextField.clearCallback"
|
||||||
fld public final static java.lang.String TEXT_FIELD_LEADING_COMPONENT = "JTextField.leadingComponent"
|
fld public final static java.lang.String TEXT_FIELD_LEADING_COMPONENT = "JTextField.leadingComponent"
|
||||||
fld public final static java.lang.String TEXT_FIELD_LEADING_ICON = "JTextField.leadingIcon"
|
fld public final static java.lang.String TEXT_FIELD_LEADING_ICON = "JTextField.leadingIcon"
|
||||||
@@ -181,6 +186,7 @@ meth public java.lang.String getID()
|
|||||||
meth public java.util.Map<java.lang.String,java.lang.String> getExtraDefaults()
|
meth public java.util.Map<java.lang.String,java.lang.String> getExtraDefaults()
|
||||||
meth public javax.swing.Icon getDisabledIcon(javax.swing.JComponent,javax.swing.Icon)
|
meth public javax.swing.Icon getDisabledIcon(javax.swing.JComponent,javax.swing.Icon)
|
||||||
meth public javax.swing.UIDefaults getDefaults()
|
meth public javax.swing.UIDefaults getDefaults()
|
||||||
|
meth public static <%0 extends java.lang.Object> {%%0} getStyleableValue(javax.swing.JComponent,java.lang.String)
|
||||||
meth public static boolean install(javax.swing.LookAndFeel)
|
meth public static boolean install(javax.swing.LookAndFeel)
|
||||||
anno 0 java.lang.Deprecated()
|
anno 0 java.lang.Deprecated()
|
||||||
meth public static boolean isLafDark()
|
meth public static boolean isLafDark()
|
||||||
@@ -189,6 +195,7 @@ meth public static boolean isUseNativeWindowDecorations()
|
|||||||
meth public static boolean setup(javax.swing.LookAndFeel)
|
meth public static boolean setup(javax.swing.LookAndFeel)
|
||||||
meth public static boolean supportsNativeWindowDecorations()
|
meth public static boolean supportsNativeWindowDecorations()
|
||||||
meth public static java.lang.Object parseDefaultsValue(java.lang.String,java.lang.String,java.lang.Class<?>)
|
meth public static java.lang.Object parseDefaultsValue(java.lang.String,java.lang.String,java.lang.Class<?>)
|
||||||
|
meth public static java.util.Map<java.lang.String,java.lang.Class<?>> getStyleableInfos(javax.swing.JComponent)
|
||||||
meth public static java.util.Map<java.lang.String,java.lang.String> getGlobalExtraDefaults()
|
meth public static java.util.Map<java.lang.String,java.lang.String> getGlobalExtraDefaults()
|
||||||
meth public static javax.swing.UIDefaults$ActiveValue createActiveFontValue(float)
|
meth public static javax.swing.UIDefaults$ActiveValue createActiveFontValue(float)
|
||||||
meth public static void hideMnemonics()
|
meth public static void hideMnemonics()
|
||||||
@@ -216,7 +223,7 @@ meth public void setExtraDefaults(java.util.Map<java.lang.String,java.lang.Strin
|
|||||||
meth public void uninitialize()
|
meth public void uninitialize()
|
||||||
meth public void unregisterUIDefaultsGetter(java.util.function.Function<java.lang.Object,java.lang.Object>)
|
meth public void unregisterUIDefaultsGetter(java.util.function.Function<java.lang.Object,java.lang.Object>)
|
||||||
supr javax.swing.plaf.basic.BasicLookAndFeel
|
supr javax.swing.plaf.basic.BasicLookAndFeel
|
||||||
hfds DESKTOPFONTHINTS,aquaLoaded,customDefaultsSources,desktopPropertyListener,desktopPropertyName,desktopPropertyName2,extraDefaults,globalExtraDefaults,mnemonicHandler,oldPopupFactory,postInitialization,subMenuUsabilityHelper,uiDefaultsGetters,updateUIPending
|
hfds DESKTOPFONTHINTS,aquaLoaded,customDefaultsSources,desktopPropertyListener,desktopPropertyName,desktopPropertyName2,extraDefaults,getUIMethod,getUIMethodInitialized,globalExtraDefaults,mnemonicHandler,oldPopupFactory,postInitialization,subMenuUsabilityHelperInstalled,uiDefaultsGetters,updateUIPending
|
||||||
hcls ActiveFont,FlatUIDefaults,ImageIconUIResource
|
hcls ActiveFont,FlatUIDefaults,ImageIconUIResource
|
||||||
|
|
||||||
CLSS public abstract interface static com.formdev.flatlaf.FlatLaf$DisabledIconProvider
|
CLSS public abstract interface static com.formdev.flatlaf.FlatLaf$DisabledIconProvider
|
||||||
@@ -255,6 +262,7 @@ fld public final static java.lang.String NATIVE_LIBRARY_PATH = "flatlaf.nativeLi
|
|||||||
fld public final static java.lang.String UI_SCALE = "flatlaf.uiScale"
|
fld public final static java.lang.String UI_SCALE = "flatlaf.uiScale"
|
||||||
fld public final static java.lang.String UI_SCALE_ALLOW_SCALE_DOWN = "flatlaf.uiScale.allowScaleDown"
|
fld public final static java.lang.String UI_SCALE_ALLOW_SCALE_DOWN = "flatlaf.uiScale.allowScaleDown"
|
||||||
fld public final static java.lang.String UI_SCALE_ENABLED = "flatlaf.uiScale.enabled"
|
fld public final static java.lang.String UI_SCALE_ENABLED = "flatlaf.uiScale.enabled"
|
||||||
|
fld public final static java.lang.String UPDATE_UI_ON_SYSTEM_FONT_CHANGE = "flatlaf.updateUIOnSystemFontChange"
|
||||||
fld public final static java.lang.String USE_JETBRAINS_CUSTOM_DECORATIONS = "flatlaf.useJetBrainsCustomDecorations"
|
fld public final static java.lang.String USE_JETBRAINS_CUSTOM_DECORATIONS = "flatlaf.useJetBrainsCustomDecorations"
|
||||||
fld public final static java.lang.String USE_TEXT_Y_CORRECTION = "flatlaf.useTextYCorrection"
|
fld public final static java.lang.String USE_TEXT_Y_CORRECTION = "flatlaf.useTextYCorrection"
|
||||||
fld public final static java.lang.String USE_UBUNTU_FONT = "flatlaf.useUbuntuFont"
|
fld public final static java.lang.String USE_UBUNTU_FONT = "flatlaf.useUbuntuFont"
|
||||||
@@ -662,6 +670,7 @@ CLSS public com.formdev.flatlaf.util.SystemInfo
|
|||||||
cons public init()
|
cons public init()
|
||||||
fld public final static boolean isAARCH64
|
fld public final static boolean isAARCH64
|
||||||
fld public final static boolean isJava_11_orLater
|
fld public final static boolean isJava_11_orLater
|
||||||
|
fld public final static boolean isJava_12_orLater
|
||||||
fld public final static boolean isJava_15_orLater
|
fld public final static boolean isJava_15_orLater
|
||||||
fld public final static boolean isJava_17_orLater
|
fld public final static boolean isJava_17_orLater
|
||||||
fld public final static boolean isJava_18_orLater
|
fld public final static boolean isJava_18_orLater
|
||||||
@@ -670,6 +679,7 @@ fld public final static boolean isJetBrainsJVM
|
|||||||
fld public final static boolean isJetBrainsJVM_11_orLater
|
fld public final static boolean isJetBrainsJVM_11_orLater
|
||||||
fld public final static boolean isKDE
|
fld public final static boolean isKDE
|
||||||
fld public final static boolean isLinux
|
fld public final static boolean isLinux
|
||||||
|
fld public final static boolean isMacFullWindowContentSupported
|
||||||
fld public final static boolean isMacOS
|
fld public final static boolean isMacOS
|
||||||
fld public final static boolean isMacOS_10_11_ElCapitan_orLater
|
fld public final static boolean isMacOS_10_11_ElCapitan_orLater
|
||||||
fld public final static boolean isMacOS_10_14_Mojave_orLater
|
fld public final static boolean isMacOS_10_14_Mojave_orLater
|
||||||
|
|||||||
@@ -253,6 +253,19 @@ public interface FlatClientProperties
|
|||||||
*/
|
*/
|
||||||
String COMPONENT_FOCUS_OWNER = "JComponent.focusOwner";
|
String COMPONENT_FOCUS_OWNER = "JComponent.focusOwner";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies whether a component in an embedded menu bar should behave as caption
|
||||||
|
* (left-click allows moving window, right-click shows window system menu).
|
||||||
|
* The component does not receive mouse pressed/released/clicked/dragged events,
|
||||||
|
* but it gets mouse entered/exited/moved events.
|
||||||
|
* <p>
|
||||||
|
* <strong>Component</strong> {@link javax.swing.JComponent}<br>
|
||||||
|
* <strong>Value type</strong> {@link java.lang.Boolean}
|
||||||
|
*
|
||||||
|
* @since 2.5
|
||||||
|
*/
|
||||||
|
String COMPONENT_TITLE_BAR_CAPTION = "JComponent.titleBarCaption";
|
||||||
|
|
||||||
//---- Popup --------------------------------------------------------------
|
//---- Popup --------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -992,7 +1005,22 @@ public interface FlatClientProperties
|
|||||||
//---- JToggleButton ------------------------------------------------------
|
//---- JToggleButton ------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Height of underline if toggle button type is {@link #BUTTON_TYPE_TAB}.
|
* Placement of underline if toggle button type is {@link #BUTTON_TYPE_TAB}
|
||||||
|
* <p>
|
||||||
|
* <strong>Component</strong> {@link javax.swing.JToggleButton}<br>
|
||||||
|
* <strong>Value type</strong> {@link java.lang.Integer}<br>
|
||||||
|
* <strong>SupportedValues:</strong>
|
||||||
|
* {@link SwingConstants#BOTTOM} (default)
|
||||||
|
* {@link SwingConstants#TOP},
|
||||||
|
* {@link SwingConstants#LEFT} or
|
||||||
|
* {@link SwingConstants#RIGHT}
|
||||||
|
*
|
||||||
|
* @since 2.3
|
||||||
|
*/
|
||||||
|
String TAB_BUTTON_UNDERLINE_PLACEMENT = "JToggleButton.tab.underlinePlacement";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Thickness of underline if toggle button type is {@link #BUTTON_TYPE_TAB}.
|
||||||
* <p>
|
* <p>
|
||||||
* <strong>Component</strong> {@link javax.swing.JToggleButton}<br>
|
* <strong>Component</strong> {@link javax.swing.JToggleButton}<br>
|
||||||
* <strong>Value type</strong> {@link java.lang.Integer}
|
* <strong>Value type</strong> {@link java.lang.Integer}
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ public class FlatDarculaLaf
|
|||||||
/**
|
/**
|
||||||
* 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)}.
|
||||||
|
*
|
||||||
|
* @since 1.2
|
||||||
*/
|
*/
|
||||||
public static boolean setup() {
|
public static boolean setup() {
|
||||||
return setup( new FlatDarculaLaf() );
|
return setup( new FlatDarculaLaf() );
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ 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)}.
|
||||||
|
*
|
||||||
|
* @since 1.2
|
||||||
*/
|
*/
|
||||||
public static boolean setup() {
|
public static boolean setup() {
|
||||||
return setup( new FlatDarkLaf() );
|
return setup( new FlatDarkLaf() );
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ public class FlatIntelliJLaf
|
|||||||
/**
|
/**
|
||||||
* 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)}.
|
||||||
|
*
|
||||||
|
* @since 1.2
|
||||||
*/
|
*/
|
||||||
public static boolean setup() {
|
public static boolean setup() {
|
||||||
return setup( new FlatIntelliJLaf() );
|
return setup( new FlatIntelliJLaf() );
|
||||||
|
|||||||
@@ -30,6 +30,9 @@ import java.awt.image.ImageProducer;
|
|||||||
import java.beans.PropertyChangeEvent;
|
import java.beans.PropertyChangeEvent;
|
||||||
import java.beans.PropertyChangeListener;
|
import java.beans.PropertyChangeListener;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.lang.invoke.MethodHandle;
|
||||||
|
import java.lang.invoke.MethodHandles;
|
||||||
|
import java.lang.invoke.MethodType;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -63,6 +66,7 @@ import javax.swing.UIDefaults.LazyValue;
|
|||||||
import javax.swing.UIManager;
|
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.ComponentUI;
|
||||||
import javax.swing.plaf.FontUIResource;
|
import javax.swing.plaf.FontUIResource;
|
||||||
import javax.swing.plaf.IconUIResource;
|
import javax.swing.plaf.IconUIResource;
|
||||||
import javax.swing.plaf.UIResource;
|
import javax.swing.plaf.UIResource;
|
||||||
@@ -73,6 +77,7 @@ 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.ui.FlatUIUtils;
|
||||||
|
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableUI;
|
||||||
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;
|
||||||
@@ -103,7 +108,7 @@ public abstract class FlatLaf
|
|||||||
|
|
||||||
private PopupFactory oldPopupFactory;
|
private PopupFactory oldPopupFactory;
|
||||||
private MnemonicHandler mnemonicHandler;
|
private MnemonicHandler mnemonicHandler;
|
||||||
private SubMenuUsabilityHelper subMenuUsabilityHelper;
|
private boolean subMenuUsabilityHelperInstalled;
|
||||||
|
|
||||||
private Consumer<UIDefaults> postInitialization;
|
private Consumer<UIDefaults> postInitialization;
|
||||||
private List<Function<Object, Object>> uiDefaultsGetters;
|
private List<Function<Object, Object>> uiDefaultsGetters;
|
||||||
@@ -111,6 +116,8 @@ public abstract class FlatLaf
|
|||||||
/**
|
/**
|
||||||
* 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)}.
|
||||||
|
*
|
||||||
|
* @since 1.2
|
||||||
*/
|
*/
|
||||||
public static boolean setup( LookAndFeel newLookAndFeel ) {
|
public static boolean setup( LookAndFeel newLookAndFeel ) {
|
||||||
try {
|
try {
|
||||||
@@ -232,6 +239,15 @@ public abstract class FlatLaf
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
|
// do not initialize if this is not the current look and feel
|
||||||
|
// This is only necessary for special Laf usage. E.g. in GUI builders,
|
||||||
|
// which may use multiple Lafs and may invoke this method directly.
|
||||||
|
// This avoids that listeners and factories are installed multiple times.
|
||||||
|
// In case of the NetBeans GUI builder, which does not invoke uninitialize(),
|
||||||
|
// this also avoids that listeners stay registered in the system.
|
||||||
|
if( UIManager.getLookAndFeel() != this )
|
||||||
|
return;
|
||||||
|
|
||||||
if( SystemInfo.isMacOS )
|
if( SystemInfo.isMacOS )
|
||||||
initializeAqua();
|
initializeAqua();
|
||||||
|
|
||||||
@@ -246,8 +262,7 @@ public abstract class FlatLaf
|
|||||||
mnemonicHandler.install();
|
mnemonicHandler.install();
|
||||||
|
|
||||||
// install submenu usability helper
|
// install submenu usability helper
|
||||||
subMenuUsabilityHelper = new SubMenuUsabilityHelper();
|
subMenuUsabilityHelperInstalled = SubMenuUsabilityHelper.install();
|
||||||
subMenuUsabilityHelper.install();
|
|
||||||
|
|
||||||
// listen to desktop property changes to update UI if system font or scaling changes
|
// listen to desktop property changes to update UI if system font or scaling changes
|
||||||
if( SystemInfo.isWindows ) {
|
if( SystemInfo.isWindows ) {
|
||||||
@@ -266,6 +281,9 @@ public abstract class FlatLaf
|
|||||||
}
|
}
|
||||||
if( desktopPropertyName != null ) {
|
if( desktopPropertyName != null ) {
|
||||||
desktopPropertyListener = e -> {
|
desktopPropertyListener = e -> {
|
||||||
|
if( !FlatSystemProperties.getBoolean( FlatSystemProperties.UPDATE_UI_ON_SYSTEM_FONT_CHANGE, true ) )
|
||||||
|
return;
|
||||||
|
|
||||||
String propertyName = e.getPropertyName();
|
String propertyName = e.getPropertyName();
|
||||||
if( desktopPropertyName.equals( propertyName ) || propertyName.equals( desktopPropertyName2 ) )
|
if( desktopPropertyName.equals( propertyName ) || propertyName.equals( desktopPropertyName2 ) )
|
||||||
reSetLookAndFeel();
|
reSetLookAndFeel();
|
||||||
@@ -304,6 +322,10 @@ public abstract class FlatLaf
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void uninitialize() {
|
public void uninitialize() {
|
||||||
|
// do not uninitialize if this is not the current look and feel
|
||||||
|
if( UIManager.getLookAndFeel() != this )
|
||||||
|
return;
|
||||||
|
|
||||||
// remove desktop property listener
|
// remove desktop property listener
|
||||||
if( desktopPropertyListener != null ) {
|
if( desktopPropertyListener != null ) {
|
||||||
Toolkit toolkit = Toolkit.getDefaultToolkit();
|
Toolkit toolkit = Toolkit.getDefaultToolkit();
|
||||||
@@ -329,9 +351,9 @@ public abstract class FlatLaf
|
|||||||
}
|
}
|
||||||
|
|
||||||
// uninstall submenu usability helper
|
// uninstall submenu usability helper
|
||||||
if( subMenuUsabilityHelper != null ) {
|
if( subMenuUsabilityHelperInstalled ) {
|
||||||
subMenuUsabilityHelper.uninstall();
|
SubMenuUsabilityHelper.uninstall();
|
||||||
subMenuUsabilityHelper = null;
|
subMenuUsabilityHelperInstalled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// restore default link color
|
// restore default link color
|
||||||
@@ -559,6 +581,7 @@ public abstract class FlatLaf
|
|||||||
|
|
||||||
// add fonts that are not set in BasicLookAndFeel
|
// add fonts that are not set in BasicLookAndFeel
|
||||||
defaults.put( "RootPane.font", activeFont );
|
defaults.put( "RootPane.font", activeFont );
|
||||||
|
defaults.put( "TitlePane.font", activeFont );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initDefaultFont( UIDefaults defaults ) {
|
private void initDefaultFont( UIDefaults defaults ) {
|
||||||
@@ -1213,6 +1236,62 @@ public abstract class FlatLaf
|
|||||||
*/
|
*/
|
||||||
public static final Object NULL_VALUE = new Object();
|
public static final Object NULL_VALUE = new Object();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns information about styleable values of a component.
|
||||||
|
* <p>
|
||||||
|
* This is equivalent to: {@code ((StyleableUI)c.getUI()).getStyleableInfos(c)}
|
||||||
|
*
|
||||||
|
* @since 2.5
|
||||||
|
*/
|
||||||
|
public static Map<String, Class<?>> getStyleableInfos( JComponent c ) {
|
||||||
|
StyleableUI ui = getStyleableUI( c );
|
||||||
|
return (ui != null) ? ui.getStyleableInfos( c ) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the (styled) value for the given key from the given component.
|
||||||
|
* <p>
|
||||||
|
* This is equivalent to: {@code ((StyleableUI)c.getUI()).getStyleableValue(c, key)}
|
||||||
|
*
|
||||||
|
* @since 2.5
|
||||||
|
*/
|
||||||
|
@SuppressWarnings( "unchecked" )
|
||||||
|
public static <T> T getStyleableValue( JComponent c, String key ) {
|
||||||
|
StyleableUI ui = getStyleableUI( c );
|
||||||
|
return (ui != null) ? (T) ui.getStyleableValue( c, key ) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static StyleableUI getStyleableUI( JComponent c ) {
|
||||||
|
if( !getUIMethodInitialized ) {
|
||||||
|
getUIMethodInitialized = true;
|
||||||
|
|
||||||
|
if( SystemInfo.isJava_9_orLater ) {
|
||||||
|
try {
|
||||||
|
// JComponent.getUI() is available since Java 9
|
||||||
|
getUIMethod = MethodHandles.lookup().findVirtual( JComponent.class, "getUI",
|
||||||
|
MethodType.methodType( ComponentUI.class ) );
|
||||||
|
} catch( Exception ex ) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Object ui;
|
||||||
|
if( getUIMethod != null )
|
||||||
|
ui = getUIMethod.invoke( c );
|
||||||
|
else
|
||||||
|
ui = c.getClass().getMethod( "getUI" ).invoke( c );
|
||||||
|
return (ui instanceof StyleableUI) ? (StyleableUI) ui : null;
|
||||||
|
} catch( Throwable ex ) {
|
||||||
|
// ignore
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean getUIMethodInitialized;
|
||||||
|
private static MethodHandle getUIMethod;
|
||||||
|
|
||||||
//---- class FlatUIDefaults -----------------------------------------------
|
//---- class FlatUIDefaults -----------------------------------------------
|
||||||
|
|
||||||
private class FlatUIDefaults
|
private class FlatUIDefaults
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ 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)}.
|
||||||
|
*
|
||||||
|
* @since 1.2
|
||||||
*/
|
*/
|
||||||
public static boolean setup() {
|
public static boolean setup() {
|
||||||
return setup( new FlatLightLaf() );
|
return setup( new FlatLightLaf() );
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.formdev.flatlaf;
|
package com.formdev.flatlaf;
|
||||||
|
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
import com.formdev.flatlaf.util.UIScale;
|
import com.formdev.flatlaf.util.UIScale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -140,9 +141,33 @@ public interface FlatSystemProperties
|
|||||||
String USE_TEXT_Y_CORRECTION = "flatlaf.useTextYCorrection";
|
String USE_TEXT_Y_CORRECTION = "flatlaf.useTextYCorrection";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies a directory in which the native FlatLaf library have been extracted.
|
* Specifies whether FlatLaf updates the UI when the system font changes.
|
||||||
|
* If {@code true}, {@link SwingUtilities#updateComponentTreeUI(java.awt.Component)}
|
||||||
|
* gets invoked for all windows if the system font has changed.
|
||||||
|
* This is the similar to when switching to another look and feel (theme).
|
||||||
|
* Applications that do not work correctly when switching look and feel,
|
||||||
|
* should disable this option to avoid corrupted UI.
|
||||||
|
* <p>
|
||||||
|
* <strong>Allowed Values</strong> {@code false} and {@code true}<br>
|
||||||
|
* <strong>Default</strong> {@code true}
|
||||||
|
* @since 2.5
|
||||||
|
*/
|
||||||
|
String UPDATE_UI_ON_SYSTEM_FONT_CHANGE = "flatlaf.updateUIOnSystemFontChange";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies a directory in which the native FlatLaf libraries have been extracted.
|
||||||
* The path can be absolute or relative to current application working directory.
|
* The path can be absolute or relative to current application working directory.
|
||||||
* This can be used to avoid extraction of the native libraries to the temporary directory at runtime.
|
* This can be used to avoid extraction of the native libraries to the temporary directory at runtime.
|
||||||
|
* <p>
|
||||||
|
* If the value is {@code "system"}, then {@link System#loadLibrary(String)} is
|
||||||
|
* used to load the native library.
|
||||||
|
* Searches for the native library in classloader of caller
|
||||||
|
* (using {@link ClassLoader#findLibrary(String)}) and in paths specified
|
||||||
|
* in system properties {@code sun.boot.library.path} and {@code java.library.path}.
|
||||||
|
* (supported since FlatLaf 2.6)
|
||||||
|
* <p>
|
||||||
|
* If the native library can not loaded from the given path (or via {@link System#loadLibrary(String)}),
|
||||||
|
* then the embedded native library is extracted to the temporary directory and loaded from there.
|
||||||
*
|
*
|
||||||
* @since 2
|
* @since 2
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -73,6 +73,8 @@ public class IntelliJTheme
|
|||||||
*
|
*
|
||||||
* 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.
|
||||||
|
*
|
||||||
|
* @since 1.2
|
||||||
*/
|
*/
|
||||||
public static boolean setup( InputStream in ) {
|
public static boolean setup( InputStream in ) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -59,6 +59,11 @@ class SubMenuUsabilityHelper
|
|||||||
private static final String KEY_USE_SAFE_TRIANGLE = "Menu.useSafeTriangle";
|
private static final String KEY_USE_SAFE_TRIANGLE = "Menu.useSafeTriangle";
|
||||||
private static final String KEY_SHOW_SAFE_TRIANGLE = "FlatLaf.debug.menu.showSafeTriangle";
|
private static final String KEY_SHOW_SAFE_TRIANGLE = "FlatLaf.debug.menu.showSafeTriangle";
|
||||||
|
|
||||||
|
// Using a static field to ensure that there is only one instance in the system.
|
||||||
|
// Multiple instances would freeze the application.
|
||||||
|
// https://github.com/apache/netbeans/issues/4231#issuecomment-1179616607
|
||||||
|
private static SubMenuUsabilityHelper instance;
|
||||||
|
|
||||||
private SubMenuEventQueue subMenuEventQueue;
|
private SubMenuEventQueue subMenuEventQueue;
|
||||||
private SafeTrianglePainter safeTrianglePainter;
|
private SafeTrianglePainter safeTrianglePainter;
|
||||||
private boolean changePending;
|
private boolean changePending;
|
||||||
@@ -74,13 +79,22 @@ class SubMenuUsabilityHelper
|
|||||||
|
|
||||||
private Rectangle invokerBounds;
|
private Rectangle invokerBounds;
|
||||||
|
|
||||||
void install() {
|
static synchronized boolean install() {
|
||||||
MenuSelectionManager.defaultManager().addChangeListener( this );
|
if( instance != null )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
instance = new SubMenuUsabilityHelper();
|
||||||
|
MenuSelectionManager.defaultManager().addChangeListener( instance );
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void uninstall() {
|
static synchronized void uninstall() {
|
||||||
MenuSelectionManager.defaultManager().removeChangeListener( this );
|
if( instance == null )
|
||||||
uninstallEventQueue();
|
return;
|
||||||
|
|
||||||
|
MenuSelectionManager.defaultManager().removeChangeListener( instance );
|
||||||
|
instance.uninstallEventQueue();
|
||||||
|
instance = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -298,7 +312,7 @@ debug*/
|
|||||||
if( window instanceof RootPaneContainer ) {
|
if( window instanceof RootPaneContainer ) {
|
||||||
JLayeredPane layeredPane = ((RootPaneContainer)window).getLayeredPane();
|
JLayeredPane layeredPane = ((RootPaneContainer)window).getLayeredPane();
|
||||||
setSize( layeredPane.getSize() );
|
setSize( layeredPane.getSize() );
|
||||||
layeredPane.add( this, new Integer( JLayeredPane.POPUP_LAYER + 1 ) );
|
layeredPane.add( this, Integer.valueOf( JLayeredPane.POPUP_LAYER + 1 ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -466,6 +466,10 @@ class UIDefaultsLoader
|
|||||||
if( knownValueTypes == null ) {
|
if( knownValueTypes == null ) {
|
||||||
// create lazy
|
// create lazy
|
||||||
knownValueTypes = new HashMap<>();
|
knownValueTypes = new HashMap<>();
|
||||||
|
// system colors
|
||||||
|
knownValueTypes.put( "activeCaptionBorder", ValueType.COLOR );
|
||||||
|
knownValueTypes.put( "inactiveCaptionBorder", ValueType.COLOR );
|
||||||
|
knownValueTypes.put( "windowBorder", ValueType.COLOR );
|
||||||
// SplitPane
|
// SplitPane
|
||||||
knownValueTypes.put( "SplitPane.dividerSize", ValueType.INTEGER );
|
knownValueTypes.put( "SplitPane.dividerSize", ValueType.INTEGER );
|
||||||
knownValueTypes.put( "SplitPaneDivider.gripDotSize", ValueType.INTEGER );
|
knownValueTypes.put( "SplitPaneDivider.gripDotSize", ValueType.INTEGER );
|
||||||
@@ -780,6 +784,7 @@ class UIDefaultsLoader
|
|||||||
case "tint": return parseColorMix( "#fff", params, resolver, reportError );
|
case "tint": return parseColorMix( "#fff", params, resolver, reportError );
|
||||||
case "shade": return parseColorMix( "#000", params, resolver, reportError );
|
case "shade": return parseColorMix( "#000", params, resolver, reportError );
|
||||||
case "contrast": return parseColorContrast( params, resolver, reportError );
|
case "contrast": return parseColorContrast( params, resolver, reportError );
|
||||||
|
case "over": return parseColorOver( params, resolver, reportError );
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
parseColorDepth--;
|
parseColorDepth--;
|
||||||
@@ -847,7 +852,7 @@ class UIDefaultsLoader
|
|||||||
int lightness = parsePercentage( params.get( 2 ) );
|
int lightness = parsePercentage( params.get( 2 ) );
|
||||||
int alpha = hasAlpha ? parsePercentage( params.get( 3 ) ) : 100;
|
int alpha = hasAlpha ? parsePercentage( params.get( 3 ) ) : 100;
|
||||||
|
|
||||||
float[] hsl = new float[] { hue, saturation, lightness };
|
float[] hsl = { hue, saturation, lightness };
|
||||||
return new ColorUIResource( HSLColor.toRGB( hsl, alpha / 100f ) );
|
return new ColorUIResource( HSLColor.toRGB( hsl, alpha / 100f ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1041,6 +1046,34 @@ class UIDefaultsLoader
|
|||||||
return parseColorOrFunction( resolver.apply( darkOrLightColor ), resolver, reportError );
|
return parseColorOrFunction( resolver.apply( darkOrLightColor ), resolver, reportError );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Syntax: over(foreground,background)
|
||||||
|
* - foreground: a foreground color (e.g. #f00) or a color function;
|
||||||
|
* the alpha of this color is used as weight to mix the two colors
|
||||||
|
* - background: a background color (e.g. #f00) or a color function
|
||||||
|
*/
|
||||||
|
private static ColorUIResource parseColorOver( List<String> params, Function<String, String> resolver, boolean reportError ) {
|
||||||
|
String foregroundStr = params.get( 0 );
|
||||||
|
String backgroundStr = params.get( 1 );
|
||||||
|
|
||||||
|
// parse foreground color
|
||||||
|
ColorUIResource foreground = (ColorUIResource) parseColorOrFunction( resolver.apply( foregroundStr ), resolver, reportError );
|
||||||
|
if( foreground == null || foreground.getAlpha() == 255 )
|
||||||
|
return foreground;
|
||||||
|
|
||||||
|
// foreground color without alpha
|
||||||
|
ColorUIResource foreground2 = new ColorUIResource( foreground.getRGB() );
|
||||||
|
|
||||||
|
// parse background color
|
||||||
|
ColorUIResource background = (ColorUIResource) parseColorOrFunction( resolver.apply( backgroundStr ), resolver, reportError );
|
||||||
|
if( background == null )
|
||||||
|
return foreground2;
|
||||||
|
|
||||||
|
// create new color
|
||||||
|
float weight = foreground.getAlpha() / 255f;
|
||||||
|
return new ColorUIResource( ColorFunctions.mix( foreground2, background, weight ) );
|
||||||
|
}
|
||||||
|
|
||||||
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 )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -49,6 +49,14 @@ public class FlatCapsLockIcon
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
public Object getStyleableValue( String key ) {
|
||||||
|
switch( key ) {
|
||||||
|
case "capsLockIconColor": return color;
|
||||||
|
default: return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paintIcon( Component c, Graphics2D g ) {
|
protected void paintIcon( Component c, Graphics2D g ) {
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -172,6 +172,11 @@ public class FlatCheckBoxIcon
|
|||||||
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
public Object getStyleableValue( String key ) {
|
||||||
|
return FlatStylingSupport.getAnnotatedStyleableValue( this, key );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paintIcon( Component c, Graphics2D g ) {
|
protected void paintIcon( Component c, Graphics2D g ) {
|
||||||
boolean indeterminate = isIndeterminate( c );
|
boolean indeterminate = isIndeterminate( c );
|
||||||
|
|||||||
@@ -59,6 +59,11 @@ public class FlatCheckBoxMenuItemIcon
|
|||||||
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
public Object getStyleableValue( String key ) {
|
||||||
|
return FlatStylingSupport.getAnnotatedStyleableValue( this, key );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paintIcon( Component c, Graphics2D g2 ) {
|
protected void paintIcon( Component c, Graphics2D g2 ) {
|
||||||
boolean selected = (c instanceof AbstractButton) && ((AbstractButton)c).isSelected();
|
boolean selected = (c instanceof AbstractButton) && ((AbstractButton)c).isSelected();
|
||||||
|
|||||||
@@ -69,6 +69,11 @@ public class FlatClearIcon
|
|||||||
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
public Object getStyleableValue( String key ) {
|
||||||
|
return FlatStylingSupport.getAnnotatedStyleableValue( this, key );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paintIcon( Component c, Graphics2D g ) {
|
protected void paintIcon( Component c, Graphics2D g ) {
|
||||||
if( !ignoreButtonState && c instanceof AbstractButton ) {
|
if( !ignoreButtonState && c instanceof AbstractButton ) {
|
||||||
|
|||||||
@@ -84,6 +84,11 @@ public class FlatHelpButtonIcon
|
|||||||
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
public Object getStyleableValue( String key ) {
|
||||||
|
return FlatStylingSupport.getAnnotatedStyleableValue( this, key );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paintIcon( Component c, Graphics2D g2 ) {
|
protected void paintIcon( Component c, Graphics2D g2 ) {
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -61,6 +61,11 @@ public class FlatMenuArrowIcon
|
|||||||
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
public Object getStyleableValue( String key ) {
|
||||||
|
return FlatStylingSupport.getAnnotatedStyleableValue( this, key );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paintIcon( Component c, Graphics2D g ) {
|
protected void paintIcon( Component c, Graphics2D g ) {
|
||||||
if( c != null && !c.getComponentOrientation().isLeftToRight() )
|
if( c != null && !c.getComponentOrientation().isLeftToRight() )
|
||||||
|
|||||||
@@ -67,6 +67,11 @@ public class FlatSearchIcon
|
|||||||
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
public Object getStyleableValue( String key ) {
|
||||||
|
return FlatStylingSupport.getAnnotatedStyleableValue( this, key );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paintIcon( Component c, Graphics2D g ) {
|
protected void paintIcon( Component c, Graphics2D g ) {
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -76,6 +76,11 @@ public class FlatTabbedPaneCloseIcon
|
|||||||
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
public Object getStyleableValue( String key ) {
|
||||||
|
return FlatStylingSupport.getAnnotatedStyleableValue( this, key );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paintIcon( Component c, Graphics2D g ) {
|
protected void paintIcon( Component c, Graphics2D g ) {
|
||||||
// paint background
|
// paint background
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import java.awt.Graphics2D;
|
|||||||
import java.awt.event.MouseAdapter;
|
import java.awt.event.MouseAdapter;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
import javax.swing.plaf.UIResource;
|
import javax.swing.plaf.UIResource;
|
||||||
import javax.swing.plaf.basic.BasicArrowButton;
|
import javax.swing.plaf.basic.BasicArrowButton;
|
||||||
|
|
||||||
@@ -82,14 +83,18 @@ public class FlatArrowButton
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mousePressed( MouseEvent e ) {
|
public void mousePressed( MouseEvent e ) {
|
||||||
pressed = true;
|
if( SwingUtilities.isLeftMouseButton( e ) ) {
|
||||||
repaint();
|
pressed = true;
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseReleased( MouseEvent e ) {
|
public void mouseReleased( MouseEvent e ) {
|
||||||
pressed = false;
|
if( SwingUtilities.isLeftMouseButton( e ) ) {
|
||||||
repaint();
|
pressed = false;
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,6 +101,12 @@ public class FlatBorder
|
|||||||
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
@Override
|
||||||
|
public Object getStyleableValue( String key ) {
|
||||||
|
return FlatStylingSupport.getAnnotatedStyleableValue( this, key );
|
||||||
|
}
|
||||||
|
|
||||||
@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 ) {
|
||||||
Graphics2D g2 = (Graphics2D) g.create();
|
Graphics2D g2 = (Graphics2D) g.create();
|
||||||
|
|||||||
@@ -78,20 +78,27 @@ import com.formdev.flatlaf.util.UIScale;
|
|||||||
* @uiDefault Button.startBackground Color optional; if set, a gradient paint is used and Button.background is ignored
|
* @uiDefault Button.startBackground Color optional; if set, a gradient paint is used and Button.background is ignored
|
||||||
* @uiDefault Button.endBackground Color optional; if set, a gradient paint is used
|
* @uiDefault Button.endBackground Color optional; if set, a gradient paint is used
|
||||||
* @uiDefault Button.focusedBackground Color optional
|
* @uiDefault Button.focusedBackground Color optional
|
||||||
|
* @uiDefault Button.focusedForeground Color optional
|
||||||
* @uiDefault Button.hoverBackground Color optional
|
* @uiDefault Button.hoverBackground Color optional
|
||||||
|
* @uiDefault Button.hoverForeground Color optional
|
||||||
* @uiDefault Button.pressedBackground Color optional
|
* @uiDefault Button.pressedBackground Color optional
|
||||||
|
* @uiDefault Button.pressedForeground Color optional
|
||||||
* @uiDefault Button.selectedBackground Color
|
* @uiDefault Button.selectedBackground Color
|
||||||
* @uiDefault Button.selectedForeground Color
|
* @uiDefault Button.selectedForeground Color
|
||||||
* @uiDefault Button.disabledBackground Color optional
|
* @uiDefault Button.disabledBackground Color optional
|
||||||
* @uiDefault Button.disabledText Color
|
* @uiDefault Button.disabledText Color
|
||||||
* @uiDefault Button.disabledSelectedBackground Color
|
* @uiDefault Button.disabledSelectedBackground Color
|
||||||
|
* @uiDefault Button.disabledSelectedForeground Color optional
|
||||||
* @uiDefault Button.default.background Color
|
* @uiDefault Button.default.background Color
|
||||||
* @uiDefault Button.default.startBackground Color optional; if set, a gradient paint is used and Button.default.background is ignored
|
* @uiDefault Button.default.startBackground Color optional; if set, a gradient paint is used and Button.default.background is ignored
|
||||||
* @uiDefault Button.default.endBackground Color optional; if set, a gradient paint is used
|
* @uiDefault Button.default.endBackground Color optional; if set, a gradient paint is used
|
||||||
* @uiDefault Button.default.foreground Color
|
* @uiDefault Button.default.foreground Color
|
||||||
* @uiDefault Button.default.focusedBackground Color optional
|
* @uiDefault Button.default.focusedBackground Color optional
|
||||||
|
* @uiDefault Button.default.focusedForeground Color optional
|
||||||
* @uiDefault Button.default.hoverBackground Color optional
|
* @uiDefault Button.default.hoverBackground Color optional
|
||||||
|
* @uiDefault Button.default.hoverForeground Color optional
|
||||||
* @uiDefault Button.default.pressedBackground Color optional
|
* @uiDefault Button.default.pressedBackground Color optional
|
||||||
|
* @uiDefault Button.default.pressedForeground Color optional
|
||||||
* @uiDefault Button.default.boldText boolean
|
* @uiDefault Button.default.boldText boolean
|
||||||
* @uiDefault Button.paintShadow boolean default is false
|
* @uiDefault Button.paintShadow boolean default is false
|
||||||
* @uiDefault Button.shadowWidth int default is 2
|
* @uiDefault Button.shadowWidth int default is 2
|
||||||
@@ -99,8 +106,13 @@ import com.formdev.flatlaf.util.UIScale;
|
|||||||
* @uiDefault Button.default.shadowColor Color optional
|
* @uiDefault Button.default.shadowColor Color optional
|
||||||
* @uiDefault Button.toolbar.spacingInsets Insets
|
* @uiDefault Button.toolbar.spacingInsets Insets
|
||||||
* @uiDefault Button.toolbar.hoverBackground Color
|
* @uiDefault Button.toolbar.hoverBackground Color
|
||||||
|
* @uiDefault Button.toolbar.hoverForeground Color optional
|
||||||
* @uiDefault Button.toolbar.pressedBackground Color
|
* @uiDefault Button.toolbar.pressedBackground Color
|
||||||
|
* @uiDefault Button.toolbar.pressedForeground Color optional
|
||||||
* @uiDefault Button.toolbar.selectedBackground Color
|
* @uiDefault Button.toolbar.selectedBackground Color
|
||||||
|
* @uiDefault Button.toolbar.selectedForeground Color optional
|
||||||
|
* @uiDefault Button.toolbar.disabledSelectedBackground Color optional
|
||||||
|
* @uiDefault Button.toolbar.disabledSelectedForeground Color optional
|
||||||
*
|
*
|
||||||
* @author Karl Tauber
|
* @author Karl Tauber
|
||||||
*/
|
*/
|
||||||
@@ -117,20 +129,27 @@ public class FlatButtonUI
|
|||||||
protected Color startBackground;
|
protected Color startBackground;
|
||||||
protected Color endBackground;
|
protected Color endBackground;
|
||||||
@Styleable protected Color focusedBackground;
|
@Styleable protected Color focusedBackground;
|
||||||
|
/** @since 2.3 */ @Styleable protected Color focusedForeground;
|
||||||
@Styleable protected Color hoverBackground;
|
@Styleable protected Color hoverBackground;
|
||||||
|
/** @since 2.3 */ @Styleable protected Color hoverForeground;
|
||||||
@Styleable protected Color pressedBackground;
|
@Styleable protected Color pressedBackground;
|
||||||
|
/** @since 2.3 */ @Styleable protected Color pressedForeground;
|
||||||
@Styleable protected Color selectedBackground;
|
@Styleable protected Color selectedBackground;
|
||||||
@Styleable protected Color selectedForeground;
|
@Styleable protected Color selectedForeground;
|
||||||
@Styleable protected Color disabledBackground;
|
@Styleable protected Color disabledBackground;
|
||||||
@Styleable protected Color disabledText;
|
@Styleable protected Color disabledText;
|
||||||
@Styleable protected Color disabledSelectedBackground;
|
@Styleable protected Color disabledSelectedBackground;
|
||||||
|
/** @since 2.3 */ @Styleable protected Color disabledSelectedForeground;
|
||||||
|
|
||||||
@Styleable(dot=true) protected Color defaultBackground;
|
@Styleable(dot=true) protected Color defaultBackground;
|
||||||
protected Color defaultEndBackground;
|
protected Color defaultEndBackground;
|
||||||
@Styleable(dot=true) protected Color defaultForeground;
|
@Styleable(dot=true) protected Color defaultForeground;
|
||||||
@Styleable(dot=true) protected Color defaultFocusedBackground;
|
@Styleable(dot=true) protected Color defaultFocusedBackground;
|
||||||
|
/** @since 2.3 */ @Styleable(dot=true) protected Color defaultFocusedForeground;
|
||||||
@Styleable(dot=true) protected Color defaultHoverBackground;
|
@Styleable(dot=true) protected Color defaultHoverBackground;
|
||||||
|
/** @since 2.3 */ @Styleable(dot=true) protected Color defaultHoverForeground;
|
||||||
@Styleable(dot=true) protected Color defaultPressedBackground;
|
@Styleable(dot=true) protected Color defaultPressedBackground;
|
||||||
|
/** @since 2.3 */ @Styleable(dot=true) protected Color defaultPressedForeground;
|
||||||
@Styleable(dot=true) protected boolean defaultBoldText;
|
@Styleable(dot=true) protected boolean defaultBoldText;
|
||||||
|
|
||||||
@Styleable protected boolean paintShadow;
|
@Styleable protected boolean paintShadow;
|
||||||
@@ -139,8 +158,13 @@ public class FlatButtonUI
|
|||||||
@Styleable(dot=true) protected Color defaultShadowColor;
|
@Styleable(dot=true) protected Color defaultShadowColor;
|
||||||
|
|
||||||
@Styleable(dot=true) protected Color toolbarHoverBackground;
|
@Styleable(dot=true) protected Color toolbarHoverBackground;
|
||||||
|
/** @since 2.3 */ @Styleable(dot=true) protected Color toolbarHoverForeground;
|
||||||
@Styleable(dot=true) protected Color toolbarPressedBackground;
|
@Styleable(dot=true) protected Color toolbarPressedBackground;
|
||||||
|
/** @since 2.3 */ @Styleable(dot=true) protected Color toolbarPressedForeground;
|
||||||
@Styleable(dot=true) protected Color toolbarSelectedBackground;
|
@Styleable(dot=true) protected Color toolbarSelectedBackground;
|
||||||
|
/** @since 2.3 */ @Styleable(dot=true) protected Color toolbarSelectedForeground;
|
||||||
|
/** @since 2.3 */ @Styleable(dot=true) protected Color toolbarDisabledSelectedBackground;
|
||||||
|
/** @since 2.3 */ @Styleable(dot=true) protected Color toolbarDisabledSelectedForeground;
|
||||||
|
|
||||||
// only used via styling (not in UI defaults, but has likewise client properties)
|
// only used via styling (not in UI defaults, but has likewise client properties)
|
||||||
/** @since 2 */ @Styleable protected String buttonType;
|
/** @since 2 */ @Styleable protected String buttonType;
|
||||||
@@ -157,7 +181,7 @@ public class FlatButtonUI
|
|||||||
private AtomicBoolean borderShared;
|
private AtomicBoolean borderShared;
|
||||||
|
|
||||||
public static ComponentUI createUI( JComponent c ) {
|
public static ComponentUI createUI( JComponent c ) {
|
||||||
return FlatUIUtils.canUseSharedUI( c )
|
return FlatUIUtils.canUseSharedUI( c ) && !FlatUIUtils.needsLightAWTPeer( c )
|
||||||
? FlatUIUtils.createSharedUI( FlatButtonUI.class, () -> new FlatButtonUI( true ) )
|
? FlatUIUtils.createSharedUI( FlatButtonUI.class, () -> new FlatButtonUI( true ) )
|
||||||
: new FlatButtonUI( false );
|
: new FlatButtonUI( false );
|
||||||
}
|
}
|
||||||
@@ -169,6 +193,13 @@ public class FlatButtonUI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void installUI( JComponent c ) {
|
public void installUI( JComponent c ) {
|
||||||
|
if( FlatUIUtils.needsLightAWTPeer( c ) )
|
||||||
|
FlatUIUtils.runWithLightAWTPeerUIDefaults( () -> installUIImpl( c ) );
|
||||||
|
else
|
||||||
|
installUIImpl( c );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void installUIImpl( JComponent c ) {
|
||||||
super.installUI( c );
|
super.installUI( c );
|
||||||
|
|
||||||
installStyle( (AbstractButton) c );
|
installStyle( (AbstractButton) c );
|
||||||
@@ -190,20 +221,27 @@ public class FlatButtonUI
|
|||||||
startBackground = UIManager.getColor( prefix + "startBackground" );
|
startBackground = UIManager.getColor( prefix + "startBackground" );
|
||||||
endBackground = UIManager.getColor( prefix + "endBackground" );
|
endBackground = UIManager.getColor( prefix + "endBackground" );
|
||||||
focusedBackground = UIManager.getColor( prefix + "focusedBackground" );
|
focusedBackground = UIManager.getColor( prefix + "focusedBackground" );
|
||||||
|
focusedForeground = UIManager.getColor( prefix + "focusedForeground" );
|
||||||
hoverBackground = UIManager.getColor( prefix + "hoverBackground" );
|
hoverBackground = UIManager.getColor( prefix + "hoverBackground" );
|
||||||
|
hoverForeground = UIManager.getColor( prefix + "hoverForeground" );
|
||||||
pressedBackground = UIManager.getColor( prefix + "pressedBackground" );
|
pressedBackground = UIManager.getColor( prefix + "pressedBackground" );
|
||||||
|
pressedForeground = UIManager.getColor( prefix + "pressedForeground" );
|
||||||
selectedBackground = UIManager.getColor( prefix + "selectedBackground" );
|
selectedBackground = UIManager.getColor( prefix + "selectedBackground" );
|
||||||
selectedForeground = UIManager.getColor( prefix + "selectedForeground" );
|
selectedForeground = UIManager.getColor( prefix + "selectedForeground" );
|
||||||
disabledBackground = UIManager.getColor( prefix + "disabledBackground" );
|
disabledBackground = UIManager.getColor( prefix + "disabledBackground" );
|
||||||
disabledText = UIManager.getColor( prefix + "disabledText" );
|
disabledText = UIManager.getColor( prefix + "disabledText" );
|
||||||
disabledSelectedBackground = UIManager.getColor( prefix + "disabledSelectedBackground" );
|
disabledSelectedBackground = UIManager.getColor( prefix + "disabledSelectedBackground" );
|
||||||
|
disabledSelectedForeground = UIManager.getColor( prefix + "disabledSelectedForeground" );
|
||||||
|
|
||||||
defaultBackground = FlatUIUtils.getUIColor( "Button.default.startBackground", "Button.default.background" );
|
defaultBackground = FlatUIUtils.getUIColor( "Button.default.startBackground", "Button.default.background" );
|
||||||
defaultEndBackground = UIManager.getColor( "Button.default.endBackground" );
|
defaultEndBackground = UIManager.getColor( "Button.default.endBackground" );
|
||||||
defaultForeground = UIManager.getColor( "Button.default.foreground" );
|
defaultForeground = UIManager.getColor( "Button.default.foreground" );
|
||||||
defaultFocusedBackground = UIManager.getColor( "Button.default.focusedBackground" );
|
defaultFocusedBackground = UIManager.getColor( "Button.default.focusedBackground" );
|
||||||
|
defaultFocusedForeground = UIManager.getColor( "Button.default.focusedForeground" );
|
||||||
defaultHoverBackground = UIManager.getColor( "Button.default.hoverBackground" );
|
defaultHoverBackground = UIManager.getColor( "Button.default.hoverBackground" );
|
||||||
|
defaultHoverForeground = UIManager.getColor( "Button.default.hoverForeground" );
|
||||||
defaultPressedBackground = UIManager.getColor( "Button.default.pressedBackground" );
|
defaultPressedBackground = UIManager.getColor( "Button.default.pressedBackground" );
|
||||||
|
defaultPressedForeground = UIManager.getColor( "Button.default.pressedForeground" );
|
||||||
defaultBoldText = UIManager.getBoolean( "Button.default.boldText" );
|
defaultBoldText = UIManager.getBoolean( "Button.default.boldText" );
|
||||||
|
|
||||||
paintShadow = UIManager.getBoolean( "Button.paintShadow" );
|
paintShadow = UIManager.getBoolean( "Button.paintShadow" );
|
||||||
@@ -212,8 +250,13 @@ public class FlatButtonUI
|
|||||||
defaultShadowColor = UIManager.getColor( "Button.default.shadowColor" );
|
defaultShadowColor = UIManager.getColor( "Button.default.shadowColor" );
|
||||||
|
|
||||||
toolbarHoverBackground = UIManager.getColor( prefix + "toolbar.hoverBackground" );
|
toolbarHoverBackground = UIManager.getColor( prefix + "toolbar.hoverBackground" );
|
||||||
|
toolbarHoverForeground = UIManager.getColor( prefix + "toolbar.hoverForeground" );
|
||||||
toolbarPressedBackground = UIManager.getColor( prefix + "toolbar.pressedBackground" );
|
toolbarPressedBackground = UIManager.getColor( prefix + "toolbar.pressedBackground" );
|
||||||
|
toolbarPressedForeground = UIManager.getColor( prefix + "toolbar.pressedForeground" );
|
||||||
toolbarSelectedBackground = UIManager.getColor( prefix + "toolbar.selectedBackground" );
|
toolbarSelectedBackground = UIManager.getColor( prefix + "toolbar.selectedBackground" );
|
||||||
|
toolbarSelectedForeground = UIManager.getColor( prefix + "toolbar.selectedForeground" );
|
||||||
|
toolbarDisabledSelectedBackground = UIManager.getColor( prefix + "toolbar.disabledSelectedBackground" );
|
||||||
|
toolbarDisabledSelectedForeground = UIManager.getColor( prefix + "toolbar.disabledSelectedForeground" );
|
||||||
|
|
||||||
helpButtonIcon = UIManager.getIcon( "HelpButton.icon" );
|
helpButtonIcon = UIManager.getIcon( "HelpButton.icon" );
|
||||||
defaultMargin = UIManager.getInsets( prefix + "margin" );
|
defaultMargin = UIManager.getInsets( prefix + "margin" );
|
||||||
@@ -330,6 +373,18 @@ public class FlatButtonUI
|
|||||||
return infos;
|
return infos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
@Override
|
||||||
|
public Object getStyleableValue( JComponent c, String key ) {
|
||||||
|
if( key.startsWith( "help." ) ) {
|
||||||
|
return (helpButtonIcon instanceof FlatHelpButtonIcon)
|
||||||
|
? ((FlatHelpButtonIcon)helpButtonIcon).getStyleableValue( key.substring( "help.".length() ) )
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FlatStylingSupport.getAnnotatedStyleableValue( this, c.getBorder(), key );
|
||||||
|
}
|
||||||
|
|
||||||
static boolean isContentAreaFilled( Component c ) {
|
static boolean isContentAreaFilled( Component c ) {
|
||||||
return !(c instanceof AbstractButton) || ((AbstractButton)c).isContentAreaFilled();
|
return !(c instanceof AbstractButton) || ((AbstractButton)c).isContentAreaFilled();
|
||||||
}
|
}
|
||||||
@@ -532,6 +587,8 @@ public class FlatButtonUI
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void paintText( Graphics g, AbstractButton b, Rectangle textRect, String text, Color foreground ) {
|
public static void paintText( Graphics g, AbstractButton b, Rectangle textRect, String text, Color foreground ) {
|
||||||
|
if(foreground == null)
|
||||||
|
foreground=Color.red;
|
||||||
FontMetrics fm = b.getFontMetrics( b.getFont() );
|
FontMetrics fm = b.getFontMetrics( b.getFont() );
|
||||||
int mnemonicIndex = FlatLaf.isShowMnemonics() ? b.getDisplayedMnemonicIndex() : -1;
|
int mnemonicIndex = FlatLaf.isShowMnemonics() ? b.getDisplayedMnemonicIndex() : -1;
|
||||||
|
|
||||||
@@ -545,11 +602,14 @@ public class FlatButtonUI
|
|||||||
|
|
||||||
// selected state
|
// selected state
|
||||||
if( ((AbstractButton)c).isSelected() ) {
|
if( ((AbstractButton)c).isSelected() ) {
|
||||||
// in toolbar use same background colors for disabled and enabled because
|
// in toolbar, if toolbarDisabledSelectedBackground is null,
|
||||||
|
// use same background colors for disabled and enabled because
|
||||||
// we assume that toolbar icon is shown disabled
|
// we assume that toolbar icon is shown disabled
|
||||||
return buttonStateColor( c,
|
return buttonStateColor( c,
|
||||||
toolBarButton ? toolbarSelectedBackground : selectedBackground,
|
toolBarButton ? toolbarSelectedBackground : selectedBackground,
|
||||||
toolBarButton ? toolbarSelectedBackground : disabledSelectedBackground,
|
toolBarButton
|
||||||
|
? (toolbarDisabledSelectedBackground != null ? toolbarDisabledSelectedBackground : toolbarSelectedBackground)
|
||||||
|
: disabledSelectedBackground,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
toolBarButton ? toolbarPressedBackground : pressedBackground );
|
toolBarButton ? toolbarPressedBackground : pressedBackground );
|
||||||
@@ -576,6 +636,9 @@ public class FlatButtonUI
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected Color getBackgroundBase( JComponent c, boolean def ) {
|
protected Color getBackgroundBase( JComponent c, boolean def ) {
|
||||||
|
if( FlatUIUtils.isAWTPeer( c ) )
|
||||||
|
return background;
|
||||||
|
|
||||||
// use component background if explicitly set
|
// use component background if explicitly set
|
||||||
Color bg = c.getBackground();
|
Color bg = c.getBackground();
|
||||||
if( isCustomBackground( bg ) )
|
if( isCustomBackground( bg ) )
|
||||||
@@ -614,18 +677,48 @@ public class FlatButtonUI
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected Color getForeground( JComponent c ) {
|
protected Color getForeground( JComponent c ) {
|
||||||
if( !c.isEnabled() )
|
boolean toolBarButton = isToolBarButton( c ) || isBorderlessButton( c );
|
||||||
return disabledText;
|
|
||||||
|
|
||||||
if( ((AbstractButton)c).isSelected() && !(isToolBarButton( c ) || isBorderlessButton( c )) )
|
// selected state
|
||||||
return selectedForeground;
|
if( ((AbstractButton)c).isSelected() ) {
|
||||||
|
return buttonStateColor( c,
|
||||||
|
toolBarButton
|
||||||
|
? (toolbarSelectedForeground != null ? toolbarSelectedForeground : c.getForeground())
|
||||||
|
: selectedForeground,
|
||||||
|
toolBarButton
|
||||||
|
? (toolbarDisabledSelectedForeground != null ? toolbarDisabledSelectedForeground : disabledText)
|
||||||
|
: (disabledSelectedForeground != null ? disabledSelectedForeground : disabledText),
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
toolBarButton ? toolbarPressedForeground : pressedForeground );
|
||||||
|
}
|
||||||
|
|
||||||
|
// toolbar button
|
||||||
|
if( toolBarButton ) {
|
||||||
|
return buttonStateColor( c,
|
||||||
|
c.getForeground(),
|
||||||
|
disabledText,
|
||||||
|
null,
|
||||||
|
toolbarHoverForeground,
|
||||||
|
toolbarPressedForeground );
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean def = isDefaultButton( c );
|
||||||
|
return buttonStateColor( c,
|
||||||
|
getForegroundBase( c, def ),
|
||||||
|
disabledText,
|
||||||
|
isCustomForeground( c.getForeground() ) ? null : (def ? defaultFocusedForeground : focusedForeground),
|
||||||
|
def ? defaultHoverForeground : hoverForeground,
|
||||||
|
def ? defaultPressedForeground : pressedForeground );
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @since 2.3 */
|
||||||
|
protected Color getForegroundBase( JComponent c, boolean def ) {
|
||||||
// use component foreground if explicitly set
|
// use component foreground if explicitly set
|
||||||
Color fg = c.getForeground();
|
Color fg = c.getForeground();
|
||||||
if( isCustomForeground( fg ) )
|
if( isCustomForeground( fg ) )
|
||||||
return fg;
|
return fg;
|
||||||
|
|
||||||
boolean def = isDefaultButton( c );
|
|
||||||
return def ? defaultForeground : fg;
|
return def ? defaultForeground : fg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,18 +16,20 @@
|
|||||||
|
|
||||||
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.beans.PropertyChangeListener;
|
import java.beans.PropertyChangeListener;
|
||||||
|
import java.lang.invoke.MethodHandles;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
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.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
import javax.swing.plaf.basic.BasicCheckBoxMenuItemUI;
|
import javax.swing.plaf.basic.BasicCheckBoxMenuItemUI;
|
||||||
|
import javax.swing.plaf.basic.BasicMenuItemUI;
|
||||||
|
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableField;
|
||||||
|
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableLookupProvider;
|
||||||
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableUI;
|
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableUI;
|
||||||
import com.formdev.flatlaf.ui.FlatStylingSupport.UnknownStyleException;
|
|
||||||
import com.formdev.flatlaf.util.LoggingFacade;
|
import com.formdev.flatlaf.util.LoggingFacade;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -58,9 +60,15 @@ import com.formdev.flatlaf.util.LoggingFacade;
|
|||||||
*
|
*
|
||||||
* @author Karl Tauber
|
* @author Karl Tauber
|
||||||
*/
|
*/
|
||||||
|
@StyleableField( cls=BasicMenuItemUI.class, key="selectionBackground" )
|
||||||
|
@StyleableField( cls=BasicMenuItemUI.class, key="selectionForeground" )
|
||||||
|
@StyleableField( cls=BasicMenuItemUI.class, key="disabledForeground" )
|
||||||
|
@StyleableField( cls=BasicMenuItemUI.class, key="acceleratorForeground" )
|
||||||
|
@StyleableField( cls=BasicMenuItemUI.class, key="acceleratorSelectionForeground" )
|
||||||
|
|
||||||
public class FlatCheckBoxMenuItemUI
|
public class FlatCheckBoxMenuItemUI
|
||||||
extends BasicCheckBoxMenuItemUI
|
extends BasicCheckBoxMenuItemUI
|
||||||
implements StyleableUI
|
implements StyleableUI, StyleableLookupProvider
|
||||||
{
|
{
|
||||||
private FlatMenuItemRenderer renderer;
|
private FlatMenuItemRenderer renderer;
|
||||||
private Map<String, Object> oldStyleValues;
|
private Map<String, Object> oldStyleValues;
|
||||||
@@ -119,29 +127,27 @@ public class FlatCheckBoxMenuItemUI
|
|||||||
|
|
||||||
/** @since 2 */
|
/** @since 2 */
|
||||||
protected Object applyStyleProperty( String key, Object value ) {
|
protected Object applyStyleProperty( String key, Object value ) {
|
||||||
try {
|
return FlatMenuItemUI.applyStyleProperty( menuItem, this, renderer, key, value );
|
||||||
return renderer.applyStyleProperty( key, value );
|
|
||||||
} catch ( UnknownStyleException ex ) {
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
|
|
||||||
Object oldValue;
|
|
||||||
switch( key ) {
|
|
||||||
// BasicMenuItemUI
|
|
||||||
case "selectionBackground": oldValue = selectionBackground; selectionBackground = (Color) value; return oldValue;
|
|
||||||
case "selectionForeground": oldValue = selectionForeground; selectionForeground = (Color) value; return oldValue;
|
|
||||||
case "disabledForeground": oldValue = disabledForeground; disabledForeground = (Color) value; return oldValue;
|
|
||||||
case "acceleratorForeground": oldValue = acceleratorForeground; acceleratorForeground = (Color) value; return oldValue;
|
|
||||||
case "acceleratorSelectionForeground": oldValue = acceleratorSelectionForeground; acceleratorSelectionForeground = (Color) value; return oldValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
return FlatStylingSupport.applyToAnnotatedObjectOrComponent( this, menuItem, key, value );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @since 2 */
|
/** @since 2 */
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
|
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
|
||||||
return FlatMenuItemUI.getStyleableInfos( renderer );
|
return FlatMenuItemUI.getStyleableInfos( this, renderer );
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
@Override
|
||||||
|
public Object getStyleableValue( JComponent c, String key ) {
|
||||||
|
return FlatMenuItemUI.getStyleableValue( this, renderer, key );
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
@Override
|
||||||
|
public MethodHandles.Lookup getLookupForStyling() {
|
||||||
|
// MethodHandles.lookup() is caller sensitive and must be invoked in this class,
|
||||||
|
// otherwise it is not possible to access protected fields in JRE superclass
|
||||||
|
return MethodHandles.lookup();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ public class FlatCheckBoxUI
|
|||||||
extends FlatRadioButtonUI
|
extends FlatRadioButtonUI
|
||||||
{
|
{
|
||||||
public static ComponentUI createUI( JComponent c ) {
|
public static ComponentUI createUI( JComponent c ) {
|
||||||
return FlatUIUtils.canUseSharedUI( c )
|
return FlatUIUtils.canUseSharedUI( c ) && !FlatUIUtils.needsLightAWTPeer( c )
|
||||||
? FlatUIUtils.createSharedUI( FlatCheckBoxUI.class, () -> new FlatCheckBoxUI( true ) )
|
? FlatUIUtils.createSharedUI( FlatCheckBoxUI.class, () -> new FlatCheckBoxUI( true ) )
|
||||||
: new FlatCheckBoxUI( false );
|
: new FlatCheckBoxUI( false );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ 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.invoke.MethodHandles;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import javax.swing.AbstractAction;
|
import javax.swing.AbstractAction;
|
||||||
@@ -70,6 +71,8 @@ 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.ui.FlatStylingSupport.Styleable;
|
import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable;
|
||||||
|
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableField;
|
||||||
|
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableLookupProvider;
|
||||||
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableUI;
|
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableUI;
|
||||||
import com.formdev.flatlaf.util.LoggingFacade;
|
import com.formdev.flatlaf.util.LoggingFacade;
|
||||||
import com.formdev.flatlaf.util.SystemInfo;
|
import com.formdev.flatlaf.util.SystemInfo;
|
||||||
@@ -117,9 +120,11 @@ import com.formdev.flatlaf.util.SystemInfo;
|
|||||||
*
|
*
|
||||||
* @author Karl Tauber
|
* @author Karl Tauber
|
||||||
*/
|
*/
|
||||||
|
@StyleableField( cls=BasicComboBoxUI.class, key="padding" )
|
||||||
|
|
||||||
public class FlatComboBoxUI
|
public class FlatComboBoxUI
|
||||||
extends BasicComboBoxUI
|
extends BasicComboBoxUI
|
||||||
implements StyleableUI
|
implements StyleableUI, StyleableLookupProvider
|
||||||
{
|
{
|
||||||
@Styleable protected int minimumWidth;
|
@Styleable protected int minimumWidth;
|
||||||
@Styleable protected int editorColumns;
|
@Styleable protected int editorColumns;
|
||||||
@@ -127,6 +132,7 @@ public class FlatComboBoxUI
|
|||||||
@Styleable protected String arrowType;
|
@Styleable protected String arrowType;
|
||||||
protected boolean isIntelliJTheme;
|
protected boolean isIntelliJTheme;
|
||||||
|
|
||||||
|
private Color background;
|
||||||
@Styleable protected Color editableBackground;
|
@Styleable protected Color editableBackground;
|
||||||
@Styleable protected Color focusedBackground;
|
@Styleable protected Color focusedBackground;
|
||||||
@Styleable protected Color disabledBackground;
|
@Styleable protected Color disabledBackground;
|
||||||
@@ -160,6 +166,13 @@ public class FlatComboBoxUI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void installUI( JComponent c ) {
|
public void installUI( JComponent c ) {
|
||||||
|
if( FlatUIUtils.needsLightAWTPeer( c ) )
|
||||||
|
FlatUIUtils.runWithLightAWTPeerUIDefaults( () -> installUIImpl( c ) );
|
||||||
|
else
|
||||||
|
installUIImpl( c );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void installUIImpl( JComponent c ) {
|
||||||
super.installUI( c );
|
super.installUI( c );
|
||||||
|
|
||||||
installStyle();
|
installStyle();
|
||||||
@@ -222,6 +235,7 @@ public class FlatComboBoxUI
|
|||||||
arrowType = UIManager.getString( "Component.arrowType" );
|
arrowType = UIManager.getString( "Component.arrowType" );
|
||||||
isIntelliJTheme = UIManager.getBoolean( "Component.isIntelliJTheme" );
|
isIntelliJTheme = UIManager.getBoolean( "Component.isIntelliJTheme" );
|
||||||
|
|
||||||
|
background = UIManager.getColor( "ComboBox.background" );
|
||||||
editableBackground = UIManager.getColor( "ComboBox.editableBackground" );
|
editableBackground = UIManager.getColor( "ComboBox.editableBackground" );
|
||||||
focusedBackground = UIManager.getColor( "ComboBox.focusedBackground" );
|
focusedBackground = UIManager.getColor( "ComboBox.focusedBackground" );
|
||||||
disabledBackground = UIManager.getColor( "ComboBox.disabledBackground" );
|
disabledBackground = UIManager.getColor( "ComboBox.disabledBackground" );
|
||||||
@@ -254,6 +268,7 @@ public class FlatComboBoxUI
|
|||||||
protected void uninstallDefaults() {
|
protected void uninstallDefaults() {
|
||||||
super.uninstallDefaults();
|
super.uninstallDefaults();
|
||||||
|
|
||||||
|
background = null;
|
||||||
editableBackground = null;
|
editableBackground = null;
|
||||||
focusedBackground = null;
|
focusedBackground = null;
|
||||||
disabledBackground = null;
|
disabledBackground = null;
|
||||||
@@ -293,11 +308,14 @@ public class FlatComboBoxUI
|
|||||||
// limit button width to height of a raw combobox (without insets)
|
// limit button width to height of a raw combobox (without insets)
|
||||||
FontMetrics fm = comboBox.getFontMetrics( comboBox.getFont() );
|
FontMetrics fm = comboBox.getFontMetrics( comboBox.getFont() );
|
||||||
int maxButtonWidth = fm.getHeight() + scale( padding.top ) + scale( padding.bottom );
|
int maxButtonWidth = fm.getHeight() + scale( padding.top ) + scale( padding.bottom );
|
||||||
|
int minButtonWidth = (maxButtonWidth * 3) / 4;
|
||||||
|
|
||||||
|
// make button square (except if width is limited)
|
||||||
Insets insets = getInsets();
|
Insets insets = getInsets();
|
||||||
int buttonWidth = Math.min( parent.getPreferredSize().height - insets.top - insets.bottom, maxButtonWidth );
|
int buttonWidth = Math.min( Math.max( parent.getHeight() - insets.top - insets.bottom, minButtonWidth ), maxButtonWidth );
|
||||||
|
|
||||||
if( buttonWidth != arrowButton.getWidth() ) {
|
if( buttonWidth != arrowButton.getWidth() ) {
|
||||||
// set width of arrow button to preferred height of combobox
|
// set width of arrow button
|
||||||
int xOffset = comboBox.getComponentOrientation().isLeftToRight()
|
int xOffset = comboBox.getComponentOrientation().isLeftToRight()
|
||||||
? arrowButton.getWidth() - buttonWidth
|
? arrowButton.getWidth() - buttonWidth
|
||||||
: 0;
|
: 0;
|
||||||
@@ -491,13 +509,6 @@ public class FlatComboBoxUI
|
|||||||
|
|
||||||
/** @since 2 */
|
/** @since 2 */
|
||||||
protected Object applyStyleProperty( String key, Object value ) {
|
protected Object applyStyleProperty( String key, Object value ) {
|
||||||
// BasicComboBoxUI
|
|
||||||
if( key.equals( "padding" ) ) {
|
|
||||||
Object oldValue = padding;
|
|
||||||
padding = (Insets) value;
|
|
||||||
return oldValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( borderShared == null )
|
if( borderShared == null )
|
||||||
borderShared = new AtomicBoolean( true );
|
borderShared = new AtomicBoolean( true );
|
||||||
return FlatStylingSupport.applyToAnnotatedObjectOrBorder( this, key, value, comboBox, borderShared );
|
return FlatStylingSupport.applyToAnnotatedObjectOrBorder( this, key, value, comboBox, borderShared );
|
||||||
@@ -506,11 +517,21 @@ public class FlatComboBoxUI
|
|||||||
/** @since 2 */
|
/** @since 2 */
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
|
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
|
||||||
Map<String, Class<?>> infos = new FlatStylingSupport.StyleableInfosMap<>();
|
return FlatStylingSupport.getAnnotatedStyleableInfos( this, comboBox.getBorder() );
|
||||||
infos.put( "padding", Insets.class );
|
}
|
||||||
FlatStylingSupport.collectAnnotatedStyleableInfos( this, infos );
|
|
||||||
FlatStylingSupport.collectStyleableInfos( comboBox.getBorder(), infos );
|
/** @since 2.5 */
|
||||||
return infos;
|
@Override
|
||||||
|
public Object getStyleableValue( JComponent c, String key ) {
|
||||||
|
return FlatStylingSupport.getAnnotatedStyleableValue( this, comboBox.getBorder(), key );
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
@Override
|
||||||
|
public MethodHandles.Lookup getLookupForStyling() {
|
||||||
|
// MethodHandles.lookup() is caller sensitive and must be invoked in this class,
|
||||||
|
// otherwise it is not possible to access protected fields in JRE superclass
|
||||||
|
return MethodHandles.lookup();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -608,7 +629,7 @@ public class FlatComboBoxUI
|
|||||||
|
|
||||||
boolean shouldValidate = (c instanceof JPanel);
|
boolean shouldValidate = (c instanceof JPanel);
|
||||||
|
|
||||||
paddingBorder.install( c );
|
paddingBorder.install( c, 0 );
|
||||||
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();
|
paddingBorder.uninstall();
|
||||||
|
|
||||||
@@ -623,6 +644,9 @@ public class FlatComboBoxUI
|
|||||||
|
|
||||||
protected Color getBackground( boolean enabled ) {
|
protected Color getBackground( boolean enabled ) {
|
||||||
if( enabled ) {
|
if( enabled ) {
|
||||||
|
if( FlatUIUtils.isAWTPeer( comboBox ) )
|
||||||
|
return background;
|
||||||
|
|
||||||
Color background = comboBox.getBackground();
|
Color background = comboBox.getBackground();
|
||||||
|
|
||||||
// always use explicitly set color
|
// always use explicitly set color
|
||||||
@@ -682,7 +706,7 @@ public class FlatComboBoxUI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Dimension getSizeForComponent( Component comp ) {
|
protected Dimension getSizeForComponent( Component comp ) {
|
||||||
paddingBorder.install( comp );
|
paddingBorder.install( comp, 0 );
|
||||||
Dimension size = super.getSizeForComponent( comp );
|
Dimension size = super.getSizeForComponent( comp );
|
||||||
paddingBorder.uninstall();
|
paddingBorder.uninstall();
|
||||||
return size;
|
return size;
|
||||||
@@ -900,7 +924,7 @@ public class FlatComboBoxUI
|
|||||||
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() );
|
||||||
|
|
||||||
paddingBorder.install( c );
|
paddingBorder.install( c, Math.round( FlatUIUtils.getBorderFocusWidth( comboBox ) ) );
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
@@ -923,6 +947,7 @@ public class FlatComboBoxUI
|
|||||||
private Insets padding;
|
private Insets padding;
|
||||||
private JComponent rendererComponent;
|
private JComponent rendererComponent;
|
||||||
private Border rendererBorder;
|
private Border rendererBorder;
|
||||||
|
private int focusWidth;
|
||||||
|
|
||||||
CellPaddingBorder( Insets padding ) {
|
CellPaddingBorder( Insets padding ) {
|
||||||
this.padding = padding;
|
this.padding = padding;
|
||||||
@@ -930,10 +955,12 @@ public class FlatComboBoxUI
|
|||||||
|
|
||||||
// using synchronized to avoid problems with code that modifies combo box
|
// using synchronized to avoid problems with code that modifies combo box
|
||||||
// (model, selection, etc) not on AWT thread (which should be not done)
|
// (model, selection, etc) not on AWT thread (which should be not done)
|
||||||
synchronized void install( Component c ) {
|
synchronized void install( Component c, int focusWidth ) {
|
||||||
if( !(c instanceof JComponent) )
|
if( !(c instanceof JComponent) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
this.focusWidth = focusWidth;
|
||||||
|
|
||||||
JComponent jc = (JComponent) c;
|
JComponent jc = (JComponent) c;
|
||||||
Border oldBorder = jc.getBorder();
|
Border oldBorder = jc.getBorder();
|
||||||
if( oldBorder == this )
|
if( oldBorder == this )
|
||||||
@@ -987,6 +1014,12 @@ public class FlatComboBoxUI
|
|||||||
insets.bottom = padding.bottom;
|
insets.bottom = padding.bottom;
|
||||||
insets.right = padding.right;
|
insets.right = padding.right;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if used in popup list, add focus width for exact vertical alignment
|
||||||
|
// of text in popup list with text in combobox
|
||||||
|
insets.left += focusWidth;
|
||||||
|
insets.right += focusWidth;
|
||||||
|
|
||||||
return insets;
|
return insets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -107,6 +107,12 @@ public class FlatDropShadowBorder
|
|||||||
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
@Override
|
||||||
|
public Object getStyleableValue( String key ) {
|
||||||
|
return FlatStylingSupport.getAnnotatedStyleableValue( this, key );
|
||||||
|
}
|
||||||
|
|
||||||
@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( shadowSize <= 0 )
|
if( shadowSize <= 0 )
|
||||||
|
|||||||
@@ -209,6 +209,12 @@ public class FlatEditorPaneUI
|
|||||||
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
@Override
|
||||||
|
public Object getStyleableValue( JComponent c, String key ) {
|
||||||
|
return FlatStylingSupport.getAnnotatedStyleableValue( this, key );
|
||||||
|
}
|
||||||
|
|
||||||
private void updateBackground() {
|
private void updateBackground() {
|
||||||
FlatTextFieldUI.updateBackground( getComponent(), background,
|
FlatTextFieldUI.updateBackground( getComponent(), background,
|
||||||
disabledBackground, inactiveBackground,
|
disabledBackground, inactiveBackground,
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ public class FlatEmptyBorder
|
|||||||
protected static Insets scaleInsets( Component c, Insets insets,
|
protected static Insets scaleInsets( Component c, Insets insets,
|
||||||
int top, int left, int bottom, int right )
|
int top, int left, int bottom, int right )
|
||||||
{
|
{
|
||||||
boolean leftToRight = left == right || c.getComponentOrientation().isLeftToRight();
|
boolean leftToRight = left == right || c == null || c.getComponentOrientation().isLeftToRight();
|
||||||
insets.left = scale( leftToRight ? left : right );
|
insets.left = scale( leftToRight ? left : right );
|
||||||
insets.top = scale( top );
|
insets.top = scale( top );
|
||||||
insets.right = scale( leftToRight ? right : left );
|
insets.right = scale( leftToRight ? right : left );
|
||||||
@@ -76,4 +76,9 @@ public class FlatEmptyBorder
|
|||||||
right = insets.right;
|
right = insets.right;
|
||||||
return oldInsets;
|
return oldInsets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
public Insets getStyleableValue() {
|
||||||
|
return new Insets( top, left, bottom, right );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,11 +19,21 @@ package com.formdev.flatlaf.ui;
|
|||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Image;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
|
import java.awt.LayoutManager;
|
||||||
|
import java.awt.RenderingHints;
|
||||||
|
import java.beans.PropertyChangeEvent;
|
||||||
|
import java.beans.PropertyChangeListener;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.function.Function;
|
||||||
import javax.swing.AbstractButton;
|
import javax.swing.AbstractButton;
|
||||||
import javax.swing.Box;
|
import javax.swing.Box;
|
||||||
import javax.swing.BoxLayout;
|
import javax.swing.BoxLayout;
|
||||||
|
import javax.swing.ButtonGroup;
|
||||||
import javax.swing.Icon;
|
import javax.swing.Icon;
|
||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
@@ -34,12 +44,16 @@ import javax.swing.JPanel;
|
|||||||
import javax.swing.JScrollPane;
|
import javax.swing.JScrollPane;
|
||||||
import javax.swing.JTable;
|
import javax.swing.JTable;
|
||||||
import javax.swing.JToggleButton;
|
import javax.swing.JToggleButton;
|
||||||
|
import javax.swing.JToolBar;
|
||||||
|
import javax.swing.SwingConstants;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
|
import javax.swing.filechooser.FileSystemView;
|
||||||
import javax.swing.filechooser.FileView;
|
import javax.swing.filechooser.FileView;
|
||||||
import javax.swing.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
import javax.swing.plaf.metal.MetalFileChooserUI;
|
import javax.swing.plaf.metal.MetalFileChooserUI;
|
||||||
import javax.swing.table.TableCellRenderer;
|
import javax.swing.table.TableCellRenderer;
|
||||||
import com.formdev.flatlaf.FlatClientProperties;
|
import com.formdev.flatlaf.FlatClientProperties;
|
||||||
|
import com.formdev.flatlaf.util.LoggingFacade;
|
||||||
import com.formdev.flatlaf.util.ScaledImageIcon;
|
import com.formdev.flatlaf.util.ScaledImageIcon;
|
||||||
import com.formdev.flatlaf.util.SystemInfo;
|
import com.formdev.flatlaf.util.SystemInfo;
|
||||||
import com.formdev.flatlaf.util.UIScale;
|
import com.formdev.flatlaf.util.UIScale;
|
||||||
@@ -133,12 +147,21 @@ import com.formdev.flatlaf.util.UIScale;
|
|||||||
* @uiDefault FileChooser.listViewActionLabelText String
|
* @uiDefault FileChooser.listViewActionLabelText String
|
||||||
* @uiDefault FileChooser.detailsViewActionLabelText String
|
* @uiDefault FileChooser.detailsViewActionLabelText String
|
||||||
*
|
*
|
||||||
|
* <!-- FlatFileChooserUI -->
|
||||||
|
*
|
||||||
|
* @uiDefault FileChooser.shortcuts.buttonSize Dimension optional; default is 84,64
|
||||||
|
* @uiDefault FileChooser.shortcuts.iconSize Dimension optional; default is 32,32
|
||||||
|
* @uiDefault FileChooser.shortcuts.filesFunction Function<File[], File[]>
|
||||||
|
* @uiDefault FileChooser.shortcuts.displayNameFunction Function<File, String>
|
||||||
|
* @uiDefault FileChooser.shortcuts.iconFunction Function<File, Icon>
|
||||||
|
*
|
||||||
* @author Karl Tauber
|
* @author Karl Tauber
|
||||||
*/
|
*/
|
||||||
public class FlatFileChooserUI
|
public class FlatFileChooserUI
|
||||||
extends MetalFileChooserUI
|
extends MetalFileChooserUI
|
||||||
{
|
{
|
||||||
private final FlatFileView fileView = new FlatFileView();
|
private final FlatFileView fileView = new FlatFileView();
|
||||||
|
private FlatShortcutsPanel shortcutsPanel;
|
||||||
|
|
||||||
public static ComponentUI createUI( JComponent c ) {
|
public static ComponentUI createUI( JComponent c ) {
|
||||||
return new FlatFileChooserUI( (JFileChooser) c );
|
return new FlatFileChooserUI( (JFileChooser) c );
|
||||||
@@ -153,6 +176,25 @@ public class FlatFileChooserUI
|
|||||||
super.installComponents( fc );
|
super.installComponents( fc );
|
||||||
|
|
||||||
patchUI( fc );
|
patchUI( fc );
|
||||||
|
|
||||||
|
if( !UIManager.getBoolean( "FileChooser.noPlacesBar" ) ) { // same as in Windows L&F
|
||||||
|
FlatShortcutsPanel panel = createShortcutsPanel( fc );
|
||||||
|
if( panel.getComponentCount() > 0 ) {
|
||||||
|
shortcutsPanel = panel;
|
||||||
|
fc.add( shortcutsPanel, BorderLayout.LINE_START );
|
||||||
|
fc.addPropertyChangeListener( shortcutsPanel );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void uninstallComponents( JFileChooser fc ) {
|
||||||
|
super.uninstallComponents( fc );
|
||||||
|
|
||||||
|
if( shortcutsPanel != null ) {
|
||||||
|
fc.removePropertyChangeListener( shortcutsPanel );
|
||||||
|
shortcutsPanel = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void patchUI( JFileChooser fc ) {
|
private void patchUI( JFileChooser fc ) {
|
||||||
@@ -192,6 +234,25 @@ public class FlatFileChooserUI
|
|||||||
} catch( ArrayIndexOutOfBoundsException ex ) {
|
} catch( ArrayIndexOutOfBoundsException ex ) {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// put north, center and south components into a new panel so that
|
||||||
|
// the shortcuts panel (at west) gets full height
|
||||||
|
LayoutManager layout = fc.getLayout();
|
||||||
|
if( layout instanceof BorderLayout ) {
|
||||||
|
BorderLayout borderLayout = (BorderLayout) layout;
|
||||||
|
borderLayout.setHgap( 8 );
|
||||||
|
|
||||||
|
Component north = borderLayout.getLayoutComponent( BorderLayout.NORTH );
|
||||||
|
Component center = borderLayout.getLayoutComponent( BorderLayout.CENTER );
|
||||||
|
Component south = borderLayout.getLayoutComponent( BorderLayout.SOUTH );
|
||||||
|
if( north != null && center != null && south != null ) {
|
||||||
|
JPanel p = new JPanel( new BorderLayout( 0, 11 ) );
|
||||||
|
p.add( north, BorderLayout.NORTH );
|
||||||
|
p.add( center, BorderLayout.CENTER );
|
||||||
|
p.add( south, BorderLayout.SOUTH );
|
||||||
|
fc.add( p, BorderLayout.CENTER );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -250,9 +311,19 @@ public class FlatFileChooserUI
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.3 */
|
||||||
|
protected FlatShortcutsPanel createShortcutsPanel( JFileChooser fc ) {
|
||||||
|
return new FlatShortcutsPanel( fc );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dimension getPreferredSize( JComponent c ) {
|
public Dimension getPreferredSize( JComponent c ) {
|
||||||
return UIScale.scale( super.getPreferredSize( c ) );
|
Dimension prefSize = super.getPreferredSize( c );
|
||||||
|
Dimension minSize = getMinimumSize( c );
|
||||||
|
int shortcutsPanelWidth = (shortcutsPanel != null) ? shortcutsPanel.getPreferredSize().width : 0;
|
||||||
|
return new Dimension(
|
||||||
|
Math.max( prefSize.width, minSize.width + shortcutsPanelWidth ),
|
||||||
|
Math.max( prefSize.height, minSize.height ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -316,4 +387,234 @@ public class FlatFileChooserUI
|
|||||||
return icon;
|
return icon;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---- class FlatShortcutsPanel -------------------------------------------
|
||||||
|
|
||||||
|
/** @since 2.3 */
|
||||||
|
public static class FlatShortcutsPanel
|
||||||
|
extends JToolBar
|
||||||
|
implements PropertyChangeListener
|
||||||
|
{
|
||||||
|
private final JFileChooser fc;
|
||||||
|
|
||||||
|
private final Dimension buttonSize;
|
||||||
|
private final Dimension iconSize;
|
||||||
|
private final Function<File[], File[]> filesFunction;
|
||||||
|
private final Function<File, String> displayNameFunction;
|
||||||
|
private final Function<File, Icon> iconFunction;
|
||||||
|
|
||||||
|
protected final File[] files;
|
||||||
|
protected final JToggleButton[] buttons;
|
||||||
|
protected final ButtonGroup buttonGroup;
|
||||||
|
|
||||||
|
@SuppressWarnings( "unchecked" )
|
||||||
|
public FlatShortcutsPanel( JFileChooser fc ) {
|
||||||
|
super( JToolBar.VERTICAL );
|
||||||
|
this.fc = fc;
|
||||||
|
setFloatable( false );
|
||||||
|
|
||||||
|
buttonSize = UIScale.scale( getUIDimension( "FileChooser.shortcuts.buttonSize", 84, 64 ) );
|
||||||
|
iconSize = getUIDimension( "FileChooser.shortcuts.iconSize", 32, 32 );
|
||||||
|
|
||||||
|
filesFunction = (Function<File[], File[]>) UIManager.get( "FileChooser.shortcuts.filesFunction" );
|
||||||
|
displayNameFunction = (Function<File, String>) UIManager.get( "FileChooser.shortcuts.displayNameFunction" );
|
||||||
|
iconFunction = (Function<File, Icon>) UIManager.get( "FileChooser.shortcuts.iconFunction" );
|
||||||
|
|
||||||
|
FileSystemView fsv = fc.getFileSystemView();
|
||||||
|
File[] files = getChooserShortcutPanelFiles( fsv );
|
||||||
|
if( filesFunction != null )
|
||||||
|
files = filesFunction.apply( files );
|
||||||
|
this.files = files;
|
||||||
|
|
||||||
|
// create toolbar buttons
|
||||||
|
buttons = new JToggleButton[files.length];
|
||||||
|
buttonGroup = new ButtonGroup();
|
||||||
|
for( int i = 0; i < files.length; i++ ) {
|
||||||
|
// wrap drive path
|
||||||
|
if( fsv.isFileSystemRoot( files[i] ) )
|
||||||
|
files[i] = fsv.createFileObject( files[i].getAbsolutePath() );
|
||||||
|
|
||||||
|
File file = files[i];
|
||||||
|
String name = getDisplayName( fsv, file );
|
||||||
|
Icon icon = getIcon( fsv, file );
|
||||||
|
|
||||||
|
// remove path from name
|
||||||
|
int lastSepIndex = name.lastIndexOf( File.separatorChar );
|
||||||
|
if( lastSepIndex >= 0 && lastSepIndex < name.length() - 1 )
|
||||||
|
name = name.substring( lastSepIndex + 1 );
|
||||||
|
|
||||||
|
// scale icon (if necessary)
|
||||||
|
if( icon instanceof ImageIcon )
|
||||||
|
icon = new ScaledImageIcon( (ImageIcon) icon, iconSize.width, iconSize.height );
|
||||||
|
else if( icon != null )
|
||||||
|
icon = new ShortcutIcon( icon, iconSize.width, iconSize.height );
|
||||||
|
|
||||||
|
// create button
|
||||||
|
JToggleButton button = createButton( name, icon );
|
||||||
|
button.addActionListener( e -> {
|
||||||
|
fc.setCurrentDirectory( file );
|
||||||
|
} );
|
||||||
|
|
||||||
|
add( button );
|
||||||
|
buttonGroup.add( button );
|
||||||
|
buttons[i] = button;
|
||||||
|
}
|
||||||
|
|
||||||
|
directoryChanged( fc.getCurrentDirectory() );
|
||||||
|
}
|
||||||
|
|
||||||
|
private Dimension getUIDimension( String key, int defaultWidth, int defaultHeight ) {
|
||||||
|
Dimension size = UIManager.getDimension( key );
|
||||||
|
if( size == null )
|
||||||
|
size = new Dimension( defaultWidth, defaultHeight );
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected JToggleButton createButton( String name, Icon icon ) {
|
||||||
|
JToggleButton button = new JToggleButton( name, icon );
|
||||||
|
button.setVerticalTextPosition( SwingConstants.BOTTOM );
|
||||||
|
button.setHorizontalTextPosition( SwingConstants.CENTER );
|
||||||
|
button.setAlignmentX( Component.CENTER_ALIGNMENT );
|
||||||
|
button.setIconTextGap( 0 );
|
||||||
|
button.setPreferredSize( buttonSize );
|
||||||
|
button.setMaximumSize( buttonSize );
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected File[] getChooserShortcutPanelFiles( FileSystemView fsv ) {
|
||||||
|
try {
|
||||||
|
if( SystemInfo.isJava_12_orLater ) {
|
||||||
|
Method m = fsv.getClass().getMethod( "getChooserShortcutPanelFiles" );
|
||||||
|
File[] files = (File[]) m.invoke( fsv );
|
||||||
|
|
||||||
|
// on macOS and Linux, files consists only of the user home directory
|
||||||
|
if( files.length == 1 && files[0].equals( new File( System.getProperty( "user.home" ) ) ) )
|
||||||
|
files = new File[0];
|
||||||
|
|
||||||
|
return files;
|
||||||
|
} else if( SystemInfo.isWindows ) {
|
||||||
|
Class<?> cls = Class.forName( "sun.awt.shell.ShellFolder" );
|
||||||
|
Method m = cls.getMethod( "get", String.class );
|
||||||
|
return (File[]) m.invoke( null, "fileChooserShortcutPanelFolders" );
|
||||||
|
}
|
||||||
|
} catch( IllegalAccessException ex ) {
|
||||||
|
// do not log because access may be denied via VM option '--illegal-access=deny'
|
||||||
|
} catch( Exception ex ) {
|
||||||
|
LoggingFacade.INSTANCE.logSevere( null, ex );
|
||||||
|
}
|
||||||
|
|
||||||
|
// fallback
|
||||||
|
return new File[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getDisplayName( FileSystemView fsv, File file ) {
|
||||||
|
if( displayNameFunction != null ) {
|
||||||
|
String name = displayNameFunction.apply( file );
|
||||||
|
if( name != null )
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
return fsv.getSystemDisplayName( file );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Icon getIcon( FileSystemView fsv, File file ) {
|
||||||
|
if( iconFunction != null ) {
|
||||||
|
Icon icon = iconFunction.apply( file );
|
||||||
|
if( icon != null )
|
||||||
|
return icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Java 17+ supports getting larger system icons
|
||||||
|
try {
|
||||||
|
if( SystemInfo.isJava_17_orLater ) {
|
||||||
|
Method m = fsv.getClass().getMethod( "getSystemIcon", File.class, int.class, int.class );
|
||||||
|
return (Icon) m.invoke( fsv, file, iconSize.width, iconSize.height );
|
||||||
|
} else if( iconSize.width > 16 || iconSize.height > 16 ) {
|
||||||
|
Class<?> cls = Class.forName( "sun.awt.shell.ShellFolder" );
|
||||||
|
if( cls.isInstance( file ) ) {
|
||||||
|
Method m = file.getClass().getMethod( "getIcon", boolean.class );
|
||||||
|
m.setAccessible( true );
|
||||||
|
Image image = (Image) m.invoke( file, true );
|
||||||
|
if( image != null )
|
||||||
|
return new ImageIcon( image );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch( IllegalAccessException ex ) {
|
||||||
|
// do not log because access may be denied via VM option '--illegal-access=deny'
|
||||||
|
} catch( Exception ex ) {
|
||||||
|
LoggingFacade.INSTANCE.logSevere( null, ex );
|
||||||
|
}
|
||||||
|
|
||||||
|
// get system icon in default size 16x16
|
||||||
|
return fsv.getSystemIcon( file );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void directoryChanged( File file ) {
|
||||||
|
if( file != null ) {
|
||||||
|
String absolutePath = file.getAbsolutePath();
|
||||||
|
for( int i = 0; i < files.length; i++ ) {
|
||||||
|
// also compare path because otherwise selecting "Documents"
|
||||||
|
// in "Look in" combobox would not select "Documents" shortcut item
|
||||||
|
if( files[i].equals( file ) || files[i].getAbsolutePath().equals( absolutePath ) ) {
|
||||||
|
buttons[i].setSelected( true );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
buttonGroup.clearSelection();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void propertyChange( PropertyChangeEvent e ) {
|
||||||
|
switch( e.getPropertyName() ) {
|
||||||
|
case JFileChooser.DIRECTORY_CHANGED_PROPERTY:
|
||||||
|
directoryChanged( fc.getCurrentDirectory() );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---- class ShortcutIcon -------------------------------------------------
|
||||||
|
|
||||||
|
private static class ShortcutIcon
|
||||||
|
implements Icon
|
||||||
|
{
|
||||||
|
private final Icon icon;
|
||||||
|
private final int iconWidth;
|
||||||
|
private final int iconHeight;
|
||||||
|
|
||||||
|
ShortcutIcon( Icon icon, int iconWidth, int iconHeight ) {
|
||||||
|
this.icon = icon;
|
||||||
|
this.iconWidth = iconWidth;
|
||||||
|
this.iconHeight = iconHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paintIcon( Component c, Graphics g, int x, int y ) {
|
||||||
|
Graphics2D g2 = (Graphics2D) g.create();
|
||||||
|
try {
|
||||||
|
// set rendering hint for the case that the icon is a bitmap (not used for vector icons)
|
||||||
|
g2.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC );
|
||||||
|
|
||||||
|
double scale = (double) getIconWidth() / (double) icon.getIconWidth();
|
||||||
|
g2.translate( x, y );
|
||||||
|
g2.scale( scale, scale );
|
||||||
|
|
||||||
|
icon.paintIcon( c, g2, 0, 0 );
|
||||||
|
} finally {
|
||||||
|
g2.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getIconWidth() {
|
||||||
|
return UIScale.scale( iconWidth );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getIconHeight() {
|
||||||
|
return UIScale.scale( iconHeight );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -179,6 +179,12 @@ public class FlatInternalFrameUI
|
|||||||
return FlatStylingSupport.getAnnotatedStyleableInfos( this, frame.getBorder() );
|
return FlatStylingSupport.getAnnotatedStyleableInfos( this, frame.getBorder() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
@Override
|
||||||
|
public Object getStyleableValue( JComponent c, String key ) {
|
||||||
|
return FlatStylingSupport.getAnnotatedStyleableValue( this, frame.getBorder(), key );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update( Graphics g, JComponent c ) {
|
public void update( Graphics g, JComponent c ) {
|
||||||
// The internal frame actually should be opaque and fill its background,
|
// The internal frame actually should be opaque and fill its background,
|
||||||
@@ -253,6 +259,23 @@ public class FlatInternalFrameUI
|
|||||||
return infos;
|
return infos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
@Override
|
||||||
|
public Object getStyleableValue( String key ) {
|
||||||
|
switch( key ) {
|
||||||
|
case "borderMargins": return getStyleableValue();
|
||||||
|
|
||||||
|
case "activeDropShadowColor": return activeDropShadowBorder.getStyleableValue( "shadowColor" );
|
||||||
|
case "activeDropShadowInsets": return activeDropShadowBorder.getStyleableValue( "shadowInsets" );
|
||||||
|
case "activeDropShadowOpacity": return activeDropShadowBorder.getStyleableValue( "shadowOpacity" );
|
||||||
|
case "inactiveDropShadowColor": return inactiveDropShadowBorder.getStyleableValue( "shadowColor" );
|
||||||
|
case "inactiveDropShadowInsets": return inactiveDropShadowBorder.getStyleableValue( "shadowInsets" );
|
||||||
|
case "inactiveDropShadowOpacity": return inactiveDropShadowBorder.getStyleableValue( "shadowOpacity" );
|
||||||
|
}
|
||||||
|
|
||||||
|
return FlatStylingSupport.getAnnotatedStyleableValue( this, key );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Insets getBorderInsets( Component c, Insets insets ) {
|
public Insets getBorderInsets( Component c, Insets insets ) {
|
||||||
if( c instanceof JInternalFrame && ((JInternalFrame)c).isMaximum() ) {
|
if( c instanceof JInternalFrame && ((JInternalFrame)c).isMaximum() ) {
|
||||||
|
|||||||
@@ -158,6 +158,12 @@ public class FlatLabelUI
|
|||||||
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
@Override
|
||||||
|
public Object getStyleableValue( JComponent c, String key ) {
|
||||||
|
return FlatStylingSupport.getAnnotatedStyleableValue( this, key );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether text contains HTML tags that use "absolute-size" keywords
|
* Checks whether text contains HTML tags that use "absolute-size" keywords
|
||||||
* (e.g. "x-large") for font-size in default style sheet
|
* (e.g. "x-large") for font-size in default style sheet
|
||||||
|
|||||||
@@ -90,6 +90,13 @@ public class FlatListUI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void installUI( JComponent c ) {
|
public void installUI( JComponent c ) {
|
||||||
|
if( FlatUIUtils.needsLightAWTPeer( c ) )
|
||||||
|
FlatUIUtils.runWithLightAWTPeerUIDefaults( () -> installUIImpl( c ) );
|
||||||
|
else
|
||||||
|
installUIImpl( c );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void installUIImpl( JComponent c ) {
|
||||||
super.installUI( c );
|
super.installUI( c );
|
||||||
|
|
||||||
installStyle();
|
installStyle();
|
||||||
@@ -209,6 +216,12 @@ public class FlatListUI
|
|||||||
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
@Override
|
||||||
|
public Object getStyleableValue( JComponent c, String key ) {
|
||||||
|
return FlatStylingSupport.getAnnotatedStyleableValue( this, key );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Toggle selection colors from focused to inactive and vice versa.
|
* Toggle selection colors from focused to inactive and vice versa.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -51,6 +51,12 @@ public class FlatMenuBarBorder
|
|||||||
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
@Override
|
||||||
|
public Object getStyleableValue( String key ) {
|
||||||
|
return FlatStylingSupport.getAnnotatedStyleableValue( this, key );
|
||||||
|
}
|
||||||
|
|
||||||
@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( !showBottomSeparator( c ) )
|
if( !showBottomSeparator( c ) )
|
||||||
|
|||||||
@@ -18,8 +18,10 @@ 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.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
|
import java.awt.LayoutManager;
|
||||||
import java.awt.Window;
|
import java.awt.Window;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.beans.PropertyChangeListener;
|
import java.beans.PropertyChangeListener;
|
||||||
@@ -27,6 +29,7 @@ import java.util.Map;
|
|||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import javax.swing.AbstractAction;
|
import javax.swing.AbstractAction;
|
||||||
import javax.swing.ActionMap;
|
import javax.swing.ActionMap;
|
||||||
|
import javax.swing.BoxLayout;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JMenu;
|
import javax.swing.JMenu;
|
||||||
import javax.swing.JMenuBar;
|
import javax.swing.JMenuBar;
|
||||||
@@ -40,11 +43,13 @@ import javax.swing.plaf.ActionMapUIResource;
|
|||||||
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.BasicMenuBarUI;
|
import javax.swing.plaf.basic.BasicMenuBarUI;
|
||||||
|
import javax.swing.plaf.basic.DefaultMenuLayout;
|
||||||
import com.formdev.flatlaf.FlatLaf;
|
import com.formdev.flatlaf.FlatLaf;
|
||||||
import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable;
|
import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable;
|
||||||
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableUI;
|
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableUI;
|
||||||
import com.formdev.flatlaf.util.LoggingFacade;
|
import com.formdev.flatlaf.util.LoggingFacade;
|
||||||
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.JMenuBar}.
|
* Provides the Flat LaF UI delegate for {@link javax.swing.JMenuBar}.
|
||||||
@@ -71,6 +76,8 @@ public class FlatMenuBarUI
|
|||||||
|
|
||||||
// used in FlatMenuUI
|
// used in FlatMenuUI
|
||||||
/** @since 2 */ @Styleable protected Color hoverBackground;
|
/** @since 2 */ @Styleable protected Color hoverBackground;
|
||||||
|
/** @since 2.5 */ @Styleable protected Color selectionBackground;
|
||||||
|
/** @since 2.5 */ @Styleable protected Color selectionForeground;
|
||||||
/** @since 2 */ @Styleable protected Color underlineSelectionBackground;
|
/** @since 2 */ @Styleable protected Color underlineSelectionBackground;
|
||||||
/** @since 2 */ @Styleable protected Color underlineSelectionColor;
|
/** @since 2 */ @Styleable protected Color underlineSelectionColor;
|
||||||
/** @since 2 */ @Styleable protected int underlineSelectionHeight = -1;
|
/** @since 2 */ @Styleable protected int underlineSelectionHeight = -1;
|
||||||
@@ -100,6 +107,10 @@ public class FlatMenuBarUI
|
|||||||
super.installDefaults();
|
super.installDefaults();
|
||||||
|
|
||||||
LookAndFeel.installProperty( menuBar, "opaque", false );
|
LookAndFeel.installProperty( menuBar, "opaque", false );
|
||||||
|
|
||||||
|
LayoutManager layout = menuBar.getLayout();
|
||||||
|
if( layout == null || layout instanceof UIResource )
|
||||||
|
menuBar.setLayout( new FlatMenuBarLayout( menuBar ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -165,6 +176,12 @@ public class FlatMenuBarUI
|
|||||||
return FlatStylingSupport.getAnnotatedStyleableInfos( this, menuBar.getBorder() );
|
return FlatStylingSupport.getAnnotatedStyleableInfos( this, menuBar.getBorder() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
@Override
|
||||||
|
public Object getStyleableValue( JComponent c, String key ) {
|
||||||
|
return FlatStylingSupport.getAnnotatedStyleableValue( this, menuBar.getBorder(), key );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update( Graphics g, JComponent c ) {
|
public void update( Graphics g, JComponent c ) {
|
||||||
// paint background
|
// paint background
|
||||||
@@ -221,6 +238,130 @@ public class FlatMenuBarUI
|
|||||||
rootPane.getWindowDecorationStyle() != JRootPane.NONE;
|
rootPane.getWindowDecorationStyle() != JRootPane.NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---- class FlatMenuBarLayout --------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 2.4
|
||||||
|
*/
|
||||||
|
protected static class FlatMenuBarLayout
|
||||||
|
extends DefaultMenuLayout
|
||||||
|
{
|
||||||
|
public FlatMenuBarLayout( Container target ) {
|
||||||
|
super( target, BoxLayout.LINE_AXIS );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void layoutContainer( Container target ) {
|
||||||
|
super.layoutContainer( target );
|
||||||
|
|
||||||
|
|
||||||
|
// The only purpose of the code below is to make sure that a horizontal glue,
|
||||||
|
// which can be used to move window and displays the window title in embedded menu bar,
|
||||||
|
// is always visible within the menu bar bounds and has a minimum width.
|
||||||
|
// If this is not the case, the horizontal glue is made larger and
|
||||||
|
// components that are on the left side of the glue are made smaller.
|
||||||
|
|
||||||
|
|
||||||
|
// get root pane and check whether this menu bar is the root pane menu bar
|
||||||
|
JRootPane rootPane = SwingUtilities.getRootPane( target );
|
||||||
|
if( rootPane == null || rootPane.getJMenuBar() != target )
|
||||||
|
return;
|
||||||
|
|
||||||
|
// get title pane and check whether menu bar is embedded
|
||||||
|
FlatTitlePane titlePane = FlatRootPaneUI.getTitlePane( rootPane );
|
||||||
|
if( titlePane == null || !titlePane.isMenuBarEmbedded() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
// check whether there is a horizontal glue (used for window title in embedded menu bar)
|
||||||
|
// and check minimum width of horizontal glue
|
||||||
|
Component horizontalGlue = titlePane.findHorizontalGlue( (JMenuBar) target );
|
||||||
|
int minTitleWidth = UIScale.scale( titlePane.titleMinimumWidth );
|
||||||
|
if( horizontalGlue != null && horizontalGlue.getWidth() < minTitleWidth ) {
|
||||||
|
// get index of glue component
|
||||||
|
int glueIndex = -1;
|
||||||
|
Component[] components = target.getComponents();
|
||||||
|
for( int i = components.length - 1; i >= 0; i-- ) {
|
||||||
|
if( components[i] == horizontalGlue ) {
|
||||||
|
glueIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if( glueIndex < 0 )
|
||||||
|
return; // should never happen
|
||||||
|
|
||||||
|
if( target.getComponentOrientation().isLeftToRight() ) {
|
||||||
|
// left-to-right
|
||||||
|
|
||||||
|
// make horizontal glue wider (minimum title width)
|
||||||
|
int offset = minTitleWidth - horizontalGlue.getWidth();
|
||||||
|
horizontalGlue.setSize( minTitleWidth, horizontalGlue.getHeight() );
|
||||||
|
|
||||||
|
// check whether glue is fully visible
|
||||||
|
int minGlueX = target.getWidth() - target.getInsets().right - minTitleWidth;
|
||||||
|
if( minGlueX < horizontalGlue.getX() ) {
|
||||||
|
// move glue to the left to make it fully visible
|
||||||
|
offset -= (horizontalGlue.getX() - minGlueX);
|
||||||
|
horizontalGlue.setLocation( minGlueX, horizontalGlue.getY() );
|
||||||
|
|
||||||
|
// shrink and move components that are on the left side of the glue
|
||||||
|
for( int i = glueIndex - 1; i >= 0; i-- ) {
|
||||||
|
Component c = components[i];
|
||||||
|
if( c.getX() > minGlueX ) {
|
||||||
|
// move component and set width to zero
|
||||||
|
c.setBounds( minGlueX, c.getY(), 0, c.getHeight() );
|
||||||
|
} else {
|
||||||
|
// reduce size of component
|
||||||
|
c.setSize( minGlueX - c.getX(), c.getHeight() );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// move components that are on the right side of the glue
|
||||||
|
for( int i = glueIndex + 1; i < components.length; i++ ) {
|
||||||
|
Component c = components[i];
|
||||||
|
c.setLocation( c.getX() + offset, c.getY() );
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// right-to-left
|
||||||
|
|
||||||
|
// make horizontal glue wider (minimum title width)
|
||||||
|
int offset = minTitleWidth - horizontalGlue.getWidth();
|
||||||
|
horizontalGlue.setBounds( horizontalGlue.getX() - offset, horizontalGlue.getY(),
|
||||||
|
minTitleWidth, horizontalGlue.getHeight() );
|
||||||
|
|
||||||
|
// check whether glue is fully visible
|
||||||
|
int minGlueX = target.getInsets().left;
|
||||||
|
if( minGlueX > horizontalGlue.getX() ) {
|
||||||
|
// move glue to the right to make it fully visible
|
||||||
|
offset -= (horizontalGlue.getX() - minGlueX);
|
||||||
|
horizontalGlue.setLocation( minGlueX, horizontalGlue.getY() );
|
||||||
|
|
||||||
|
// shrink and move components that are on the right side of the glue
|
||||||
|
int x = horizontalGlue.getX() + horizontalGlue.getWidth();
|
||||||
|
for( int i = glueIndex - 1; i >= 0; i-- ) {
|
||||||
|
Component c = components[i];
|
||||||
|
if( c.getX() + c.getWidth() < x ) {
|
||||||
|
// move component and set width to zero
|
||||||
|
c.setBounds( x, c.getY(), 0, c.getHeight() );
|
||||||
|
} else {
|
||||||
|
// move component and reduce size
|
||||||
|
c.setBounds( x, c.getY(), c.getWidth() - (x - c.getX()), c.getHeight() );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// move components that are on the left side of the glue
|
||||||
|
for( int i = glueIndex + 1; i < components.length; i++ ) {
|
||||||
|
Component c = components[i];
|
||||||
|
c.setLocation( c.getX() - offset, c.getY() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//---- class TakeFocus ----------------------------------------------------
|
//---- class TakeFocus ----------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -97,6 +97,7 @@ public class FlatMenuItemRenderer
|
|||||||
@Styleable protected int underlineSelectionHeight = UIManager.getInt( "MenuItem.underlineSelectionHeight" );
|
@Styleable protected int underlineSelectionHeight = UIManager.getInt( "MenuItem.underlineSelectionHeight" );
|
||||||
|
|
||||||
private boolean iconsShared = true;
|
private boolean iconsShared = true;
|
||||||
|
private final Font menuFont = UIManager.getFont( "Menu.font" );
|
||||||
|
|
||||||
protected FlatMenuItemRenderer( JMenuItem menuItem, Icon checkIcon, Icon arrowIcon,
|
protected FlatMenuItemRenderer( JMenuItem menuItem, Icon checkIcon, Icon arrowIcon,
|
||||||
Font acceleratorFont, String acceleratorDelimiter )
|
Font acceleratorFont, String acceleratorDelimiter )
|
||||||
@@ -169,6 +170,19 @@ public class FlatMenuItemRenderer
|
|||||||
return infos;
|
return infos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
public Object getStyleableValue( String key ) {
|
||||||
|
if( key.startsWith( "icon." ) ) {
|
||||||
|
String key2 = key.substring( "icon.".length() );
|
||||||
|
if( checkIcon instanceof FlatCheckBoxMenuItemIcon )
|
||||||
|
return ((FlatCheckBoxMenuItemIcon)checkIcon).getStyleableValue( key2 );
|
||||||
|
if( arrowIcon instanceof FlatMenuArrowIcon )
|
||||||
|
return ((FlatMenuArrowIcon)arrowIcon).getStyleableValue( key2 );
|
||||||
|
}
|
||||||
|
|
||||||
|
return FlatStylingSupport.getAnnotatedStyleableValue( this, key );
|
||||||
|
}
|
||||||
|
|
||||||
protected Dimension getPreferredMenuItemSize() {
|
protected Dimension getPreferredMenuItemSize() {
|
||||||
int width = 0;
|
int width = 0;
|
||||||
int height = 0;
|
int height = 0;
|
||||||
@@ -180,7 +194,8 @@ public class FlatMenuItemRenderer
|
|||||||
|
|
||||||
// layout icon and text
|
// layout icon and text
|
||||||
SwingUtilities.layoutCompoundLabel( menuItem,
|
SwingUtilities.layoutCompoundLabel( menuItem,
|
||||||
menuItem.getFontMetrics( menuItem.getFont() ), menuItem.getText(), getIconForLayout(),
|
menuItem.getFontMetrics( isTopLevelMenu ? getTopLevelFont() : menuItem.getFont() ),
|
||||||
|
menuItem.getText(), getIconForLayout(),
|
||||||
menuItem.getVerticalAlignment(), menuItem.getHorizontalAlignment(),
|
menuItem.getVerticalAlignment(), menuItem.getHorizontalAlignment(),
|
||||||
menuItem.getVerticalTextPosition(), menuItem.getHorizontalTextPosition(),
|
menuItem.getVerticalTextPosition(), menuItem.getHorizontalTextPosition(),
|
||||||
viewRect, iconRect, textRect, scale( menuItem.getIconTextGap() ) );
|
viewRect, iconRect, textRect, scale( menuItem.getIconTextGap() ) );
|
||||||
@@ -282,7 +297,8 @@ public class FlatMenuItemRenderer
|
|||||||
|
|
||||||
// layout icon and text
|
// layout icon and text
|
||||||
SwingUtilities.layoutCompoundLabel( menuItem,
|
SwingUtilities.layoutCompoundLabel( menuItem,
|
||||||
menuItem.getFontMetrics( menuItem.getFont() ), menuItem.getText(), getIconForLayout(),
|
menuItem.getFontMetrics( isTopLevelMenu ? getTopLevelFont() : menuItem.getFont() ),
|
||||||
|
menuItem.getText(), getIconForLayout(),
|
||||||
menuItem.getVerticalAlignment(), menuItem.getHorizontalAlignment(),
|
menuItem.getVerticalAlignment(), menuItem.getHorizontalAlignment(),
|
||||||
menuItem.getVerticalTextPosition(), menuItem.getHorizontalTextPosition(),
|
menuItem.getVerticalTextPosition(), menuItem.getHorizontalTextPosition(),
|
||||||
labelRect, iconRect, textRect, scale( menuItem.getIconTextGap() ) );
|
labelRect, iconRect, textRect, scale( menuItem.getIconTextGap() ) );
|
||||||
@@ -392,9 +408,10 @@ debug*/
|
|||||||
}
|
}
|
||||||
|
|
||||||
int mnemonicIndex = FlatLaf.isShowMnemonics() ? menuItem.getDisplayedMnemonicIndex() : -1;
|
int mnemonicIndex = FlatLaf.isShowMnemonics() ? menuItem.getDisplayedMnemonicIndex() : -1;
|
||||||
Color foreground = (isTopLevelMenu( menuItem ) ? menuItem.getParent() : menuItem).getForeground();
|
boolean isTopLevelMenu = isTopLevelMenu( menuItem );
|
||||||
|
Color foreground = (isTopLevelMenu ? menuItem.getParent() : menuItem).getForeground();
|
||||||
|
|
||||||
paintText( g, menuItem, textRect, text, mnemonicIndex, menuItem.getFont(),
|
paintText( g, menuItem, textRect, text, mnemonicIndex, isTopLevelMenu ? getTopLevelFont() : menuItem.getFont(),
|
||||||
foreground, isUnderlineSelection() ? foreground : selectionForeground, disabledForeground );
|
foreground, isUnderlineSelection() ? foreground : selectionForeground, disabledForeground );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -446,6 +463,19 @@ debug*/
|
|||||||
protected static void paintHTMLText( Graphics g, JMenuItem menuItem,
|
protected static void paintHTMLText( Graphics g, JMenuItem menuItem,
|
||||||
Rectangle textRect, View htmlView, Color selectionForeground )
|
Rectangle textRect, View htmlView, Color selectionForeground )
|
||||||
{
|
{
|
||||||
|
// On Windows, using Segoe UI font, Java 15 or older and scaling greater than 1,
|
||||||
|
// the width of the HTML view may be initially too small (because component
|
||||||
|
// is not connected to a GraphicsConfiguration when getPreferredSize() is invoked).
|
||||||
|
// Since Java 16, this seems to be fixed somehow by doing popup menu layout twice.
|
||||||
|
//
|
||||||
|
// If using a too small width for htmlView.paint(), the view would rearrange
|
||||||
|
// its children and wrap them to two lines. To avoid this, use view preferred X span
|
||||||
|
// for painting. Core Lafs actually do the same in class MenuItemLayoutHelper.
|
||||||
|
//
|
||||||
|
// Example HTML text that causes the problem: "<html>some <b>HTML</b> <i>text</i></html>"
|
||||||
|
textRect = new Rectangle( textRect );
|
||||||
|
textRect.width = (int) htmlView.getPreferredSpan( View.X_AXIS );
|
||||||
|
|
||||||
if( isArmedOrSelected( menuItem ) && selectionForeground != null )
|
if( isArmedOrSelected( menuItem ) && selectionForeground != null )
|
||||||
g = new GraphicsProxyWithTextColor( (Graphics2D) g, selectionForeground );
|
g = new GraphicsProxyWithTextColor( (Graphics2D) g, selectionForeground );
|
||||||
|
|
||||||
@@ -468,6 +498,15 @@ debug*/
|
|||||||
return "underline".equals( UIManager.getString( "MenuItem.selectionType" ) );
|
return "underline".equals( UIManager.getString( "MenuItem.selectionType" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Font getTopLevelFont() {
|
||||||
|
Font font = menuItem.getFont();
|
||||||
|
// menu item parent may be null if JMenu.isTopLevelMenu() is overridden
|
||||||
|
// and does not check parent (e.g. com.jidesoft.swing.JideMenu.isTopLevelMenu())
|
||||||
|
return (font != menuFont || menuItem.getParent() == null)
|
||||||
|
? font
|
||||||
|
: menuItem.getParent().getFont();
|
||||||
|
}
|
||||||
|
|
||||||
private Icon getIconForPainting() {
|
private Icon getIconForPainting() {
|
||||||
Icon icon = menuItem.getIcon();
|
Icon icon = menuItem.getIcon();
|
||||||
|
|
||||||
|
|||||||
@@ -16,16 +16,19 @@
|
|||||||
|
|
||||||
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.beans.PropertyChangeListener;
|
import java.beans.PropertyChangeListener;
|
||||||
|
import java.lang.invoke.MethodHandles;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import javax.swing.Icon;
|
import javax.swing.Icon;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
|
import javax.swing.JMenuItem;
|
||||||
import javax.swing.LookAndFeel;
|
import javax.swing.LookAndFeel;
|
||||||
import javax.swing.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
import javax.swing.plaf.basic.BasicMenuItemUI;
|
import javax.swing.plaf.basic.BasicMenuItemUI;
|
||||||
|
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableField;
|
||||||
|
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableLookupProvider;
|
||||||
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableUI;
|
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableUI;
|
||||||
import com.formdev.flatlaf.ui.FlatStylingSupport.UnknownStyleException;
|
import com.formdev.flatlaf.ui.FlatStylingSupport.UnknownStyleException;
|
||||||
import com.formdev.flatlaf.util.LoggingFacade;
|
import com.formdev.flatlaf.util.LoggingFacade;
|
||||||
@@ -58,9 +61,15 @@ import com.formdev.flatlaf.util.LoggingFacade;
|
|||||||
*
|
*
|
||||||
* @author Karl Tauber
|
* @author Karl Tauber
|
||||||
*/
|
*/
|
||||||
|
@StyleableField( cls=BasicMenuItemUI.class, key="selectionBackground" )
|
||||||
|
@StyleableField( cls=BasicMenuItemUI.class, key="selectionForeground" )
|
||||||
|
@StyleableField( cls=BasicMenuItemUI.class, key="disabledForeground" )
|
||||||
|
@StyleableField( cls=BasicMenuItemUI.class, key="acceleratorForeground" )
|
||||||
|
@StyleableField( cls=BasicMenuItemUI.class, key="acceleratorSelectionForeground" )
|
||||||
|
|
||||||
public class FlatMenuItemUI
|
public class FlatMenuItemUI
|
||||||
extends BasicMenuItemUI
|
extends BasicMenuItemUI
|
||||||
implements StyleableUI
|
implements StyleableUI, StyleableLookupProvider
|
||||||
{
|
{
|
||||||
private FlatMenuItemRenderer renderer;
|
private FlatMenuItemRenderer renderer;
|
||||||
private Map<String, Object> oldStyleValues;
|
private Map<String, Object> oldStyleValues;
|
||||||
@@ -119,42 +128,54 @@ public class FlatMenuItemUI
|
|||||||
|
|
||||||
/** @since 2 */
|
/** @since 2 */
|
||||||
protected Object applyStyleProperty( String key, Object value ) {
|
protected Object applyStyleProperty( String key, Object value ) {
|
||||||
|
return applyStyleProperty( menuItem, this, renderer, key, value );
|
||||||
|
}
|
||||||
|
|
||||||
|
static Object applyStyleProperty( JMenuItem menuItem, BasicMenuItemUI ui,
|
||||||
|
FlatMenuItemRenderer renderer, String key, Object value )
|
||||||
|
{
|
||||||
try {
|
try {
|
||||||
return renderer.applyStyleProperty( key, value );
|
return renderer.applyStyleProperty( key, value );
|
||||||
} catch ( UnknownStyleException ex ) {
|
} catch ( UnknownStyleException ex ) {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
Object oldValue;
|
return FlatStylingSupport.applyToAnnotatedObjectOrComponent( ui, menuItem, key, value );
|
||||||
switch( key ) {
|
|
||||||
// BasicMenuItemUI
|
|
||||||
case "selectionBackground": oldValue = selectionBackground; selectionBackground = (Color) value; return oldValue;
|
|
||||||
case "selectionForeground": oldValue = selectionForeground; selectionForeground = (Color) value; return oldValue;
|
|
||||||
case "disabledForeground": oldValue = disabledForeground; disabledForeground = (Color) value; return oldValue;
|
|
||||||
case "acceleratorForeground": oldValue = acceleratorForeground; acceleratorForeground = (Color) value; return oldValue;
|
|
||||||
case "acceleratorSelectionForeground": oldValue = acceleratorSelectionForeground; acceleratorSelectionForeground = (Color) value; return oldValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
return FlatStylingSupport.applyToAnnotatedObjectOrComponent( this, menuItem, key, value );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @since 2 */
|
/** @since 2 */
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
|
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
|
||||||
return getStyleableInfos( renderer );
|
return getStyleableInfos( this, renderer );
|
||||||
}
|
}
|
||||||
|
|
||||||
static Map<String, Class<?>> getStyleableInfos( FlatMenuItemRenderer renderer ) {
|
static Map<String, Class<?>> getStyleableInfos( BasicMenuItemUI ui, FlatMenuItemRenderer renderer ) {
|
||||||
Map<String, Class<?>> infos = new FlatStylingSupport.StyleableInfosMap<>();
|
Map<String, Class<?>> infos = FlatStylingSupport.getAnnotatedStyleableInfos( ui );
|
||||||
infos.put( "selectionBackground", Color.class );
|
|
||||||
infos.put( "selectionForeground", Color.class );
|
|
||||||
infos.put( "disabledForeground", Color.class );
|
|
||||||
infos.put( "acceleratorForeground", Color.class );
|
|
||||||
infos.put( "acceleratorSelectionForeground", Color.class );
|
|
||||||
infos.putAll( renderer.getStyleableInfos() );
|
infos.putAll( renderer.getStyleableInfos() );
|
||||||
return infos;
|
return infos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
@Override
|
||||||
|
public Object getStyleableValue( JComponent c, String key ) {
|
||||||
|
return getStyleableValue( this, renderer, key );
|
||||||
|
}
|
||||||
|
|
||||||
|
static Object getStyleableValue( BasicMenuItemUI ui, FlatMenuItemRenderer renderer, String key ) {
|
||||||
|
Object value = renderer.getStyleableValue( key );
|
||||||
|
if( value == null )
|
||||||
|
value = FlatStylingSupport.getAnnotatedStyleableValue( ui, key );
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
@Override
|
||||||
|
public MethodHandles.Lookup getLookupForStyling() {
|
||||||
|
// MethodHandles.lookup() is caller sensitive and must be invoked in this class,
|
||||||
|
// otherwise it is not possible to access protected fields in JRE superclass
|
||||||
|
return MethodHandles.lookup();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Dimension getPreferredMenuItemSize( JComponent c, Icon checkIcon, Icon arrowIcon, int defaultTextIconGap ) {
|
protected Dimension getPreferredMenuItemSize( JComponent c, Icon checkIcon, Icon arrowIcon, int defaultTextIconGap ) {
|
||||||
return renderer.getPreferredMenuItemSize();
|
return renderer.getPreferredMenuItemSize();
|
||||||
|
|||||||
@@ -20,8 +20,10 @@ import java.awt.Color;
|
|||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Rectangle;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.beans.PropertyChangeListener;
|
import java.beans.PropertyChangeListener;
|
||||||
|
import java.lang.invoke.MethodHandles;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import javax.swing.ButtonModel;
|
import javax.swing.ButtonModel;
|
||||||
@@ -35,9 +37,11 @@ import javax.swing.UIManager;
|
|||||||
import javax.swing.event.MouseInputListener;
|
import javax.swing.event.MouseInputListener;
|
||||||
import javax.swing.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
import javax.swing.plaf.MenuBarUI;
|
import javax.swing.plaf.MenuBarUI;
|
||||||
|
import javax.swing.plaf.basic.BasicMenuItemUI;
|
||||||
import javax.swing.plaf.basic.BasicMenuUI;
|
import javax.swing.plaf.basic.BasicMenuUI;
|
||||||
|
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableField;
|
||||||
|
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableLookupProvider;
|
||||||
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableUI;
|
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableUI;
|
||||||
import com.formdev.flatlaf.ui.FlatStylingSupport.UnknownStyleException;
|
|
||||||
import com.formdev.flatlaf.util.LoggingFacade;
|
import com.formdev.flatlaf.util.LoggingFacade;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -72,15 +76,23 @@ import com.formdev.flatlaf.util.LoggingFacade;
|
|||||||
* <!-- FlatMenuRenderer -->
|
* <!-- FlatMenuRenderer -->
|
||||||
*
|
*
|
||||||
* @uiDefault MenuBar.hoverBackground Color
|
* @uiDefault MenuBar.hoverBackground Color
|
||||||
|
* @uiDefault MenuBar.selectionBackground Color
|
||||||
|
* @uiDefault MenuBar.selectionForeground Color
|
||||||
* @uiDefault MenuBar.underlineSelectionBackground Color
|
* @uiDefault MenuBar.underlineSelectionBackground Color
|
||||||
* @uiDefault MenuBar.underlineSelectionColor Color
|
* @uiDefault MenuBar.underlineSelectionColor Color
|
||||||
* @uiDefault MenuBar.underlineSelectionHeight int
|
* @uiDefault MenuBar.underlineSelectionHeight int
|
||||||
*
|
*
|
||||||
* @author Karl Tauber
|
* @author Karl Tauber
|
||||||
*/
|
*/
|
||||||
|
@StyleableField( cls=BasicMenuItemUI.class, key="selectionBackground" )
|
||||||
|
@StyleableField( cls=BasicMenuItemUI.class, key="selectionForeground" )
|
||||||
|
@StyleableField( cls=BasicMenuItemUI.class, key="disabledForeground" )
|
||||||
|
@StyleableField( cls=BasicMenuItemUI.class, key="acceleratorForeground" )
|
||||||
|
@StyleableField( cls=BasicMenuItemUI.class, key="acceleratorSelectionForeground" )
|
||||||
|
|
||||||
public class FlatMenuUI
|
public class FlatMenuUI
|
||||||
extends BasicMenuUI
|
extends BasicMenuUI
|
||||||
implements StyleableUI
|
implements StyleableUI, StyleableLookupProvider
|
||||||
{
|
{
|
||||||
private FlatMenuItemRenderer renderer;
|
private FlatMenuItemRenderer renderer;
|
||||||
private Map<String, Object> oldStyleValues;
|
private Map<String, Object> oldStyleValues;
|
||||||
@@ -166,29 +178,27 @@ public class FlatMenuUI
|
|||||||
|
|
||||||
/** @since 2 */
|
/** @since 2 */
|
||||||
protected Object applyStyleProperty( String key, Object value ) {
|
protected Object applyStyleProperty( String key, Object value ) {
|
||||||
try {
|
return FlatMenuItemUI.applyStyleProperty( menuItem, this, renderer, key, value );
|
||||||
return renderer.applyStyleProperty( key, value );
|
|
||||||
} catch ( UnknownStyleException ex ) {
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
|
|
||||||
Object oldValue;
|
|
||||||
switch( key ) {
|
|
||||||
// BasicMenuItemUI
|
|
||||||
case "selectionBackground": oldValue = selectionBackground; selectionBackground = (Color) value; return oldValue;
|
|
||||||
case "selectionForeground": oldValue = selectionForeground; selectionForeground = (Color) value; return oldValue;
|
|
||||||
case "disabledForeground": oldValue = disabledForeground; disabledForeground = (Color) value; return oldValue;
|
|
||||||
case "acceleratorForeground": oldValue = acceleratorForeground; acceleratorForeground = (Color) value; return oldValue;
|
|
||||||
case "acceleratorSelectionForeground": oldValue = acceleratorSelectionForeground; acceleratorSelectionForeground = (Color) value; return oldValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
return FlatStylingSupport.applyToAnnotatedObjectOrComponent( this, menuItem, key, value );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @since 2 */
|
/** @since 2 */
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
|
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
|
||||||
return FlatMenuItemUI.getStyleableInfos( renderer );
|
return FlatMenuItemUI.getStyleableInfos( this, renderer );
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
@Override
|
||||||
|
public Object getStyleableValue( JComponent c, String key ) {
|
||||||
|
return FlatMenuItemUI.getStyleableValue( this, renderer, key );
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
@Override
|
||||||
|
public MethodHandles.Lookup getLookupForStyling() {
|
||||||
|
// MethodHandles.lookup() is caller sensitive and must be invoked in this class,
|
||||||
|
// otherwise it is not possible to access protected fields in JRE superclass
|
||||||
|
return MethodHandles.lookup();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -216,6 +226,8 @@ public class FlatMenuUI
|
|||||||
extends FlatMenuItemRenderer
|
extends FlatMenuItemRenderer
|
||||||
{
|
{
|
||||||
protected Color hoverBackground = UIManager.getColor( "MenuBar.hoverBackground" );
|
protected Color hoverBackground = UIManager.getColor( "MenuBar.hoverBackground" );
|
||||||
|
protected Color menuBarSelectionBackground = UIManager.getColor( "MenuBar.selectionBackground" );
|
||||||
|
protected Color menuBarSelectionForeground = UIManager.getColor( "MenuBar.selectionForeground" );
|
||||||
protected Color menuBarUnderlineSelectionBackground = FlatUIUtils.getUIColor( "MenuBar.underlineSelectionBackground", underlineSelectionBackground );
|
protected Color menuBarUnderlineSelectionBackground = FlatUIUtils.getUIColor( "MenuBar.underlineSelectionBackground", underlineSelectionBackground );
|
||||||
protected Color menuBarUnderlineSelectionColor = FlatUIUtils.getUIColor( "MenuBar.underlineSelectionColor", underlineSelectionColor );
|
protected Color menuBarUnderlineSelectionColor = FlatUIUtils.getUIColor( "MenuBar.underlineSelectionColor", underlineSelectionColor );
|
||||||
protected int menuBarUnderlineSelectionHeight = FlatUIUtils.getUIInt( "MenuBar.underlineSelectionHeight", underlineSelectionHeight );
|
protected int menuBarUnderlineSelectionHeight = FlatUIUtils.getUIInt( "MenuBar.underlineSelectionHeight", underlineSelectionHeight );
|
||||||
@@ -231,6 +243,10 @@ public class FlatMenuUI
|
|||||||
if( ((JMenu)menuItem).isTopLevelMenu() ) {
|
if( ((JMenu)menuItem).isTopLevelMenu() ) {
|
||||||
if( isUnderlineSelection() )
|
if( isUnderlineSelection() )
|
||||||
selectionBackground = getStyleFromMenuBarUI( ui -> ui.underlineSelectionBackground, menuBarUnderlineSelectionBackground );
|
selectionBackground = getStyleFromMenuBarUI( ui -> ui.underlineSelectionBackground, menuBarUnderlineSelectionBackground );
|
||||||
|
else {
|
||||||
|
selectionBackground = getStyleFromMenuBarUI( ui -> ui.selectionBackground,
|
||||||
|
menuBarSelectionBackground != null ? menuBarSelectionBackground : selectionBackground );
|
||||||
|
}
|
||||||
|
|
||||||
ButtonModel model = menuItem.getModel();
|
ButtonModel model = menuItem.getModel();
|
||||||
if( model.isRollover() && !model.isArmed() && !model.isSelected() && model.isEnabled() ) {
|
if( model.isRollover() && !model.isArmed() && !model.isSelected() && model.isEnabled() ) {
|
||||||
@@ -243,6 +259,16 @@ public class FlatMenuUI
|
|||||||
super.paintBackground( g, selectionBackground );
|
super.paintBackground( g, selectionBackground );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void paintText( Graphics g, Rectangle textRect, String text, Color selectionForeground, Color disabledForeground ) {
|
||||||
|
if( ((JMenu)menuItem).isTopLevelMenu() && !isUnderlineSelection() ) {
|
||||||
|
selectionForeground = getStyleFromMenuBarUI( ui -> ui.selectionForeground,
|
||||||
|
menuBarSelectionForeground != null ? menuBarSelectionForeground : selectionForeground );
|
||||||
|
}
|
||||||
|
|
||||||
|
super.paintText( g, textRect, text, selectionForeground, disabledForeground );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paintUnderlineSelection( Graphics g, Color underlineSelectionColor, int underlineSelectionHeight ) {
|
protected void paintUnderlineSelection( Graphics g, Color underlineSelectionColor, int underlineSelectionHeight ) {
|
||||||
if( ((JMenu)menuItem).isTopLevelMenu() ) {
|
if( ((JMenu)menuItem).isTopLevelMenu() ) {
|
||||||
|
|||||||
@@ -0,0 +1,115 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022 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.io.File;
|
||||||
|
import com.formdev.flatlaf.FlatSystemProperties;
|
||||||
|
import com.formdev.flatlaf.util.LoggingFacade;
|
||||||
|
import com.formdev.flatlaf.util.NativeLibrary;
|
||||||
|
import com.formdev.flatlaf.util.SystemInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper class to load FlatLaf native library (.dll, .so or .dylib),
|
||||||
|
* if available for current operating system and CPU architecture.
|
||||||
|
*
|
||||||
|
* @author Karl Tauber
|
||||||
|
* @since 2.3
|
||||||
|
*/
|
||||||
|
class FlatNativeLibrary
|
||||||
|
{
|
||||||
|
private static NativeLibrary nativeLibrary;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads native library (if available) and returns whether loaded successfully.
|
||||||
|
* Returns {@code false} if no native library is available.
|
||||||
|
*/
|
||||||
|
static synchronized boolean isLoaded() {
|
||||||
|
initialize();
|
||||||
|
return (nativeLibrary != null) ? nativeLibrary.isLoaded() : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void initialize() {
|
||||||
|
if( nativeLibrary != null )
|
||||||
|
return;
|
||||||
|
|
||||||
|
String libraryName;
|
||||||
|
if( SystemInfo.isWindows_10_orLater && (SystemInfo.isX86 || SystemInfo.isX86_64) ) {
|
||||||
|
// Windows: requires Windows 10/11 (x86 or x86_64)
|
||||||
|
|
||||||
|
libraryName = "flatlaf-windows-x86";
|
||||||
|
if( SystemInfo.isX86_64 )
|
||||||
|
libraryName += "_64";
|
||||||
|
|
||||||
|
// In Java 8, load jawt.dll (part of JRE) explicitly because it
|
||||||
|
// is not found when running application with <jdk>/bin/java.exe.
|
||||||
|
// When using <jdk>/jre/bin/java.exe, it is found.
|
||||||
|
// jawt.dll is located in <jdk>/jre/bin/.
|
||||||
|
// Java 9 and later do not have this problem,
|
||||||
|
// but load jawt.dll anyway to be on the safe side.
|
||||||
|
loadJAWT();
|
||||||
|
} else if( SystemInfo.isLinux && SystemInfo.isX86_64 ) {
|
||||||
|
// Linux: requires x86_64
|
||||||
|
|
||||||
|
libraryName = "flatlaf-linux-x86_64";
|
||||||
|
|
||||||
|
// Load libjawt.so (part of JRE) explicitly because it is not found
|
||||||
|
// in all Java versions/distributions.
|
||||||
|
// E.g. not found in Java 13 and later from openjdk.java.net.
|
||||||
|
// There seems to be also differences between distributions.
|
||||||
|
// E.g. Adoptium Java 17 does not need this, but Java 17 from openjdk.java.net does.
|
||||||
|
loadJAWT();
|
||||||
|
} else
|
||||||
|
return; // no native library available for current OS or CPU architecture
|
||||||
|
|
||||||
|
// load native library
|
||||||
|
nativeLibrary = createNativeLibrary( libraryName );
|
||||||
|
}
|
||||||
|
|
||||||
|
private static NativeLibrary createNativeLibrary( String libraryName ) {
|
||||||
|
String libraryPath = System.getProperty( FlatSystemProperties.NATIVE_LIBRARY_PATH );
|
||||||
|
if( libraryPath != null ) {
|
||||||
|
if( "system".equals( libraryPath ) ) {
|
||||||
|
NativeLibrary library = new NativeLibrary( libraryName, true );
|
||||||
|
if( library.isLoaded() )
|
||||||
|
return library;
|
||||||
|
|
||||||
|
LoggingFacade.INSTANCE.logSevere( "Did not find library " + libraryName + " in java.library.path, using extracted library instead", null );
|
||||||
|
} else {
|
||||||
|
File libraryFile = new File( libraryPath, System.mapLibraryName( libraryName ) );
|
||||||
|
if( libraryFile.exists() )
|
||||||
|
return new NativeLibrary( libraryFile, true );
|
||||||
|
|
||||||
|
LoggingFacade.INSTANCE.logSevere( "Did not find external library " + libraryFile + ", using extracted library instead", null );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new NativeLibrary( "com/formdev/flatlaf/natives/" + libraryName, null, true );
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void loadJAWT() {
|
||||||
|
try {
|
||||||
|
System.loadLibrary( "jawt" );
|
||||||
|
} catch( UnsatisfiedLinkError ex ) {
|
||||||
|
// log error only if native library jawt.dll not already loaded
|
||||||
|
String message = ex.getMessage();
|
||||||
|
if( message == null || !message.contains( "already loaded in another classloader" ) )
|
||||||
|
LoggingFacade.INSTANCE.logSevere( message, ex );
|
||||||
|
} catch( Exception ex ) {
|
||||||
|
LoggingFacade.INSTANCE.logSevere( ex.getMessage(), ex );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022 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.Point;
|
||||||
|
import java.awt.Toolkit;
|
||||||
|
import java.awt.Window;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.geom.AffineTransform;
|
||||||
|
import javax.swing.JDialog;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Native methods for Linux.
|
||||||
|
* <p>
|
||||||
|
* <b>Note</b>: This is private API. Do not use!
|
||||||
|
*
|
||||||
|
* @author Karl Tauber
|
||||||
|
* @since 2.5
|
||||||
|
*/
|
||||||
|
class FlatNativeLinuxLibrary
|
||||||
|
{
|
||||||
|
static boolean isLoaded() {
|
||||||
|
return FlatNativeLibrary.isLoaded();
|
||||||
|
}
|
||||||
|
|
||||||
|
// direction for _NET_WM_MOVERESIZE message
|
||||||
|
// see https://specifications.freedesktop.org/wm-spec/wm-spec-latest.html
|
||||||
|
static final int MOVE = 8;
|
||||||
|
|
||||||
|
private static Boolean isXWindowSystem;
|
||||||
|
|
||||||
|
private static boolean isXWindowSystem() {
|
||||||
|
if( isXWindowSystem == null )
|
||||||
|
isXWindowSystem = Toolkit.getDefaultToolkit().getClass().getName().endsWith( ".XToolkit" );
|
||||||
|
return isXWindowSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
static boolean isWMUtilsSupported( Window window ) {
|
||||||
|
return hasCustomDecoration( window ) && isXWindowSystem() && isLoaded();
|
||||||
|
}
|
||||||
|
|
||||||
|
static boolean moveOrResizeWindow( Window window, MouseEvent e, int direction ) {
|
||||||
|
Point pt = scale( window, e.getLocationOnScreen() );
|
||||||
|
return xMoveOrResizeWindow( window, pt.x, pt.y, direction );
|
||||||
|
|
||||||
|
/*
|
||||||
|
try {
|
||||||
|
Class<?> cls = Class.forName( "com.formdev.flatlaf.natives.jna.linux.X11WmUtils" );
|
||||||
|
java.lang.reflect.Method m = cls.getMethod( "xMoveOrResizeWindow", Window.class, int.class, int.class, int.class );
|
||||||
|
return (Boolean) m.invoke( null, window, pt.x, pt.y, direction );
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
static boolean showWindowMenu( Window window, MouseEvent e ) {
|
||||||
|
Point pt = scale( window, e.getLocationOnScreen() );
|
||||||
|
return xShowWindowMenu( window, pt.x, pt.y );
|
||||||
|
|
||||||
|
/*
|
||||||
|
try {
|
||||||
|
Class<?> cls = Class.forName( "com.formdev.flatlaf.natives.jna.linux.X11WmUtils" );
|
||||||
|
java.lang.reflect.Method m = cls.getMethod( "xShowWindowMenu", Window.class, int.class, int.class );
|
||||||
|
return (Boolean) m.invoke( null, window, pt.x, pt.y );
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Point scale( Window window, Point pt ) {
|
||||||
|
AffineTransform transform = window.getGraphicsConfiguration().getDefaultTransform();
|
||||||
|
int x = (int) Math.round( pt.x * transform.getScaleX() );
|
||||||
|
int y = (int) Math.round( pt.y * transform.getScaleY() );
|
||||||
|
return new Point( x, y );
|
||||||
|
}
|
||||||
|
|
||||||
|
// X Window System
|
||||||
|
private static native boolean xMoveOrResizeWindow( Window window, int x, int y, int direction );
|
||||||
|
private static native boolean xShowWindowMenu( Window window, int x, int y );
|
||||||
|
|
||||||
|
private static boolean hasCustomDecoration( Window window ) {
|
||||||
|
return (window instanceof JFrame && JFrame.isDefaultLookAndFeelDecorated() && ((JFrame)window).isUndecorated()) ||
|
||||||
|
(window instanceof JDialog && JDialog.isDefaultLookAndFeelDecorated() && ((JDialog)window).isUndecorated());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -42,11 +42,13 @@ import com.formdev.flatlaf.util.SystemInfo;
|
|||||||
public class FlatNativeWindowBorder
|
public class FlatNativeWindowBorder
|
||||||
{
|
{
|
||||||
// can use window decorations if:
|
// can use window decorations if:
|
||||||
// - on Windows 10
|
// - on Windows 10 or later
|
||||||
|
// - not if system property "sun.java2d.opengl" is true on Windows 10
|
||||||
// - not when running in JetBrains Projector, Webswing or WinPE
|
// - not when running in JetBrains Projector, Webswing or WinPE
|
||||||
// - not disabled via system property
|
// - not disabled via system property
|
||||||
private static final boolean canUseWindowDecorations =
|
private static final boolean canUseWindowDecorations =
|
||||||
SystemInfo.isWindows_10_orLater &&
|
SystemInfo.isWindows_10_orLater &&
|
||||||
|
(SystemInfo.isWindows_11_orLater || !FlatSystemProperties.getBoolean( "sun.java2d.opengl", false )) &&
|
||||||
!SystemInfo.isProjector &&
|
!SystemInfo.isProjector &&
|
||||||
!SystemInfo.isWebswing &&
|
!SystemInfo.isWebswing &&
|
||||||
!SystemInfo.isWinPE &&
|
!SystemInfo.isWinPE &&
|
||||||
|
|||||||
@@ -127,6 +127,12 @@ public class FlatPanelUI
|
|||||||
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
@Override
|
||||||
|
public Object getStyleableValue( JComponent c, String key ) {
|
||||||
|
return FlatStylingSupport.getAnnotatedStyleableValue( this, key );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update( Graphics g, JComponent c ) {
|
public void update( Graphics g, JComponent c ) {
|
||||||
// fill background
|
// fill background
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import java.awt.Toolkit;
|
|||||||
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 java.util.Map;
|
import java.util.Map;
|
||||||
import javax.swing.Action;
|
import javax.swing.Action;
|
||||||
import javax.swing.ActionMap;
|
import javax.swing.ActionMap;
|
||||||
@@ -233,6 +234,14 @@ public class FlatPasswordFieldUI
|
|||||||
return infos;
|
return infos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getStyleableValue( JComponent c, String key ) {
|
||||||
|
if( key.equals( "capsLockIconColor" ) && capsLockIcon instanceof FlatCapsLockIcon )
|
||||||
|
return ((FlatCapsLockIcon)capsLockIcon).getStyleableValue( key );
|
||||||
|
|
||||||
|
return super.getStyleableValue( c, key );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View create( Element elem ) {
|
public View create( Element elem ) {
|
||||||
return new PasswordView( elem );
|
return new PasswordView( elem );
|
||||||
@@ -283,6 +292,7 @@ public class FlatPasswordFieldUI
|
|||||||
protected void installRevealButton() {
|
protected void installRevealButton() {
|
||||||
if( showRevealButton ) {
|
if( showRevealButton ) {
|
||||||
revealButton = createRevealButton();
|
revealButton = createRevealButton();
|
||||||
|
updateRevealButton();
|
||||||
installLayout();
|
installLayout();
|
||||||
getComponent().add( revealButton );
|
getComponent().add( revealButton );
|
||||||
}
|
}
|
||||||
@@ -290,28 +300,64 @@ public class FlatPasswordFieldUI
|
|||||||
|
|
||||||
/** @since 2 */
|
/** @since 2 */
|
||||||
protected JToggleButton createRevealButton() {
|
protected JToggleButton createRevealButton() {
|
||||||
JToggleButton button = new JToggleButton( revealIcon );
|
JPasswordField c = (JPasswordField) getComponent();
|
||||||
|
JToggleButton button = new JToggleButton( revealIcon, !c.echoCharIsSet() );
|
||||||
button.setName( "PasswordField.revealButton" );
|
button.setName( "PasswordField.revealButton" );
|
||||||
prepareLeadingOrTrailingComponent( button );
|
prepareLeadingOrTrailingComponent( button );
|
||||||
button.putClientProperty( FlatClientProperties.STYLE_CLASS, "inTextField revealButton" );
|
button.putClientProperty( FlatClientProperties.STYLE_CLASS, "inTextField revealButton" );
|
||||||
if( FlatClientProperties.clientPropertyBoolean( getComponent(), KEY_REVEAL_SELECTED, false ) ) {
|
if( FlatClientProperties.clientPropertyBoolean( c, KEY_REVEAL_SELECTED, false ) ) {
|
||||||
button.setSelected( true );
|
button.setSelected( true );
|
||||||
updateEchoChar( true );
|
updateEchoChar( true );
|
||||||
}
|
}
|
||||||
button.addActionListener( e -> {
|
button.addActionListener( e -> {
|
||||||
boolean selected = button.isSelected();
|
boolean selected = button.isSelected();
|
||||||
updateEchoChar( selected );
|
updateEchoChar( selected );
|
||||||
getComponent().putClientProperty( KEY_REVEAL_SELECTED, selected );
|
c.putClientProperty( KEY_REVEAL_SELECTED, selected );
|
||||||
} );
|
} );
|
||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
protected void updateRevealButton() {
|
||||||
|
if( revealButton == null )
|
||||||
|
return;
|
||||||
|
|
||||||
|
JTextComponent c = getComponent();
|
||||||
|
boolean visible = c.isEnabled();
|
||||||
|
if( visible != revealButton.isVisible() ) {
|
||||||
|
revealButton.setVisible( visible );
|
||||||
|
c.revalidate();
|
||||||
|
c.repaint();
|
||||||
|
|
||||||
|
if( !visible ) {
|
||||||
|
revealButton.setSelected( false );
|
||||||
|
updateEchoChar( false );
|
||||||
|
getComponent().putClientProperty( KEY_REVEAL_SELECTED, null );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void propertyChange( PropertyChangeEvent e ) {
|
||||||
|
super.propertyChange( e );
|
||||||
|
|
||||||
|
switch( e.getPropertyName() ) {
|
||||||
|
case "enabled":
|
||||||
|
updateRevealButton();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void updateEchoChar( boolean selected ) {
|
private void updateEchoChar( boolean selected ) {
|
||||||
char newEchoChar = selected
|
char newEchoChar = selected
|
||||||
? 0
|
? 0
|
||||||
: (echoChar != null ? echoChar : '*');
|
: (echoChar != null ? echoChar : '*');
|
||||||
|
|
||||||
JPasswordField c = (JPasswordField) getComponent();
|
JPasswordField c = (JPasswordField) getComponent();
|
||||||
|
if( newEchoChar == c.getEchoChar() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
// set echo char
|
||||||
LookAndFeel.installProperty( c, "echoChar", newEchoChar );
|
LookAndFeel.installProperty( c, "echoChar", newEchoChar );
|
||||||
|
|
||||||
// check whether was able to set echo char via LookAndFeel.installProperty()
|
// check whether was able to set echo char via LookAndFeel.installProperty()
|
||||||
|
|||||||
@@ -36,7 +36,9 @@ import java.awt.Window;
|
|||||||
import java.awt.event.ComponentEvent;
|
import java.awt.event.ComponentEvent;
|
||||||
import java.awt.event.ComponentListener;
|
import java.awt.event.ComponentListener;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.invoke.MethodHandle;
|
||||||
|
import java.lang.invoke.MethodHandles;
|
||||||
|
import java.lang.invoke.MethodType;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JLayeredPane;
|
import javax.swing.JLayeredPane;
|
||||||
@@ -64,8 +66,8 @@ import com.formdev.flatlaf.util.UIScale;
|
|||||||
public class FlatPopupFactory
|
public class FlatPopupFactory
|
||||||
extends PopupFactory
|
extends PopupFactory
|
||||||
{
|
{
|
||||||
private Method java8getPopupMethod;
|
private MethodHandle java8getPopupMethod;
|
||||||
private Method java9getPopupMethod;
|
private MethodHandle java9getPopupMethod;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Popup getPopup( Component owner, Component contents, int x, int y )
|
public Popup getPopup( Component owner, Component contents, int x, int y )
|
||||||
@@ -192,23 +194,25 @@ public class FlatPopupFactory
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if( SystemInfo.isJava_9_orLater ) {
|
if( SystemInfo.isJava_9_orLater ) {
|
||||||
|
// Java 9: protected Popup getPopup( Component owner, Component contents, int x, int y, boolean isHeavyWeightPopup )
|
||||||
if( java9getPopupMethod == null ) {
|
if( java9getPopupMethod == null ) {
|
||||||
java9getPopupMethod = PopupFactory.class.getDeclaredMethod(
|
MethodType mt = MethodType.methodType( Popup.class, Component.class, Component.class, int.class, int.class, boolean.class );
|
||||||
"getPopup", Component.class, Component.class, int.class, int.class, boolean.class );
|
java9getPopupMethod = MethodHandles.lookup().findVirtual( PopupFactory.class, "getPopup", mt );
|
||||||
}
|
}
|
||||||
return (Popup) java9getPopupMethod.invoke( this, owner, contents, x, y, true );
|
return (Popup) java9getPopupMethod.invoke( this, owner, contents, x, y, true );
|
||||||
} else {
|
} else {
|
||||||
// Java 8
|
// Java 8: private Popup getPopup( Component owner, Component contents, int ownerX, int ownerY, int popupType )
|
||||||
if( java8getPopupMethod == null ) {
|
if( java8getPopupMethod == null ) {
|
||||||
java8getPopupMethod = PopupFactory.class.getDeclaredMethod(
|
Method m = PopupFactory.class.getDeclaredMethod(
|
||||||
"getPopup", Component.class, Component.class, int.class, int.class, int.class );
|
"getPopup", Component.class, Component.class, int.class, int.class, int.class );
|
||||||
java8getPopupMethod.setAccessible( true );
|
m.setAccessible( true );
|
||||||
|
java8getPopupMethod = MethodHandles.lookup().unreflect( m );
|
||||||
}
|
}
|
||||||
return (Popup) java8getPopupMethod.invoke( this, owner, contents, x, y, /*HEAVY_WEIGHT_POPUP*/ 2 );
|
return (Popup) java8getPopupMethod.invoke( this, owner, contents, x, y, /*HEAVY_WEIGHT_POPUP*/ 2 );
|
||||||
}
|
}
|
||||||
} catch( NoSuchMethodException | SecurityException | IllegalAccessException | InvocationTargetException ex ) {
|
} catch( Throwable ex ) {
|
||||||
// ignore
|
// fallback
|
||||||
return null;
|
return super.getPopup( owner, contents, x, y );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -66,6 +66,16 @@ public class FlatPopupMenuBorder
|
|||||||
return infos;
|
return infos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
@Override
|
||||||
|
public Object getStyleableValue( String key ) {
|
||||||
|
switch( key ) {
|
||||||
|
case "borderInsets": return getStyleableValue();
|
||||||
|
case "borderColor": return borderColor;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Color getLineColor() {
|
public Color getLineColor() {
|
||||||
return (borderColor != null) ? borderColor : super.getLineColor();
|
return (borderColor != null) ? borderColor : super.getLineColor();
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ public class FlatPopupMenuUI
|
|||||||
|
|
||||||
LayoutManager layout = popupMenu.getLayout();
|
LayoutManager layout = popupMenu.getLayout();
|
||||||
if( layout == null || layout instanceof UIResource )
|
if( layout == null || layout instanceof UIResource )
|
||||||
popupMenu.setLayout( new FlatMenuLayout( popupMenu, BoxLayout.Y_AXIS ) );
|
popupMenu.setLayout( new FlatPopupMenuLayout( popupMenu, BoxLayout.Y_AXIS ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -184,6 +184,12 @@ public class FlatPopupMenuUI
|
|||||||
return FlatStylingSupport.getAnnotatedStyleableInfos( this, popupMenu.getBorder() );
|
return FlatStylingSupport.getAnnotatedStyleableInfos( this, popupMenu.getBorder() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
@Override
|
||||||
|
public Object getStyleableValue( JComponent c, String key ) {
|
||||||
|
return FlatStylingSupport.getAnnotatedStyleableValue( this, popupMenu.getBorder(), key );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Popup getPopup( JPopupMenu popup, int x, int y ) {
|
public Popup getPopup( JPopupMenu popup, int x, int y ) {
|
||||||
// do not add scroller to combobox popups or to popups that already have a scroll pane
|
// do not add scroller to combobox popups or to popups that already have a scroll pane
|
||||||
@@ -230,12 +236,15 @@ public class FlatPopupMenuUI
|
|||||||
return screenBounds.height - screenInsets.top - screenInsets.bottom;
|
return screenBounds.height - screenInsets.top - screenInsets.bottom;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---- class FlatMenuLayout -----------------------------------------------
|
//---- class FlatPopupMenuLayout ------------------------------------------
|
||||||
|
|
||||||
protected static class FlatMenuLayout
|
/**
|
||||||
|
* @since 2.4
|
||||||
|
*/
|
||||||
|
protected static class FlatPopupMenuLayout
|
||||||
extends DefaultMenuLayout
|
extends DefaultMenuLayout
|
||||||
{
|
{
|
||||||
public FlatMenuLayout( Container target, int axis ) {
|
public FlatPopupMenuLayout( Container target, int axis ) {
|
||||||
super( target, axis );
|
super( target, axis );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -160,6 +160,12 @@ public class FlatProgressBarUI
|
|||||||
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
@Override
|
||||||
|
public Object getStyleableValue( JComponent c, String key ) {
|
||||||
|
return FlatStylingSupport.getAnnotatedStyleableValue( this, key );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dimension getPreferredSize( JComponent c ) {
|
public Dimension getPreferredSize( JComponent c ) {
|
||||||
Dimension size = super.getPreferredSize( c );
|
Dimension size = super.getPreferredSize( c );
|
||||||
|
|||||||
@@ -16,18 +16,20 @@
|
|||||||
|
|
||||||
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.beans.PropertyChangeListener;
|
import java.beans.PropertyChangeListener;
|
||||||
|
import java.lang.invoke.MethodHandles;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
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.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
|
import javax.swing.plaf.basic.BasicMenuItemUI;
|
||||||
import javax.swing.plaf.basic.BasicRadioButtonMenuItemUI;
|
import javax.swing.plaf.basic.BasicRadioButtonMenuItemUI;
|
||||||
|
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableField;
|
||||||
|
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableLookupProvider;
|
||||||
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableUI;
|
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableUI;
|
||||||
import com.formdev.flatlaf.ui.FlatStylingSupport.UnknownStyleException;
|
|
||||||
import com.formdev.flatlaf.util.LoggingFacade;
|
import com.formdev.flatlaf.util.LoggingFacade;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -58,9 +60,15 @@ import com.formdev.flatlaf.util.LoggingFacade;
|
|||||||
*
|
*
|
||||||
* @author Karl Tauber
|
* @author Karl Tauber
|
||||||
*/
|
*/
|
||||||
|
@StyleableField( cls=BasicMenuItemUI.class, key="selectionBackground" )
|
||||||
|
@StyleableField( cls=BasicMenuItemUI.class, key="selectionForeground" )
|
||||||
|
@StyleableField( cls=BasicMenuItemUI.class, key="disabledForeground" )
|
||||||
|
@StyleableField( cls=BasicMenuItemUI.class, key="acceleratorForeground" )
|
||||||
|
@StyleableField( cls=BasicMenuItemUI.class, key="acceleratorSelectionForeground" )
|
||||||
|
|
||||||
public class FlatRadioButtonMenuItemUI
|
public class FlatRadioButtonMenuItemUI
|
||||||
extends BasicRadioButtonMenuItemUI
|
extends BasicRadioButtonMenuItemUI
|
||||||
implements StyleableUI
|
implements StyleableUI, StyleableLookupProvider
|
||||||
{
|
{
|
||||||
private FlatMenuItemRenderer renderer;
|
private FlatMenuItemRenderer renderer;
|
||||||
private Map<String, Object> oldStyleValues;
|
private Map<String, Object> oldStyleValues;
|
||||||
@@ -119,29 +127,27 @@ public class FlatRadioButtonMenuItemUI
|
|||||||
|
|
||||||
/** @since 2 */
|
/** @since 2 */
|
||||||
protected Object applyStyleProperty( String key, Object value ) {
|
protected Object applyStyleProperty( String key, Object value ) {
|
||||||
try {
|
return FlatMenuItemUI.applyStyleProperty( menuItem, this, renderer, key, value );
|
||||||
return renderer.applyStyleProperty( key, value );
|
|
||||||
} catch ( UnknownStyleException ex ) {
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
|
|
||||||
Object oldValue;
|
|
||||||
switch( key ) {
|
|
||||||
// BasicMenuItemUI
|
|
||||||
case "selectionBackground": oldValue = selectionBackground; selectionBackground = (Color) value; return oldValue;
|
|
||||||
case "selectionForeground": oldValue = selectionForeground; selectionForeground = (Color) value; return oldValue;
|
|
||||||
case "disabledForeground": oldValue = disabledForeground; disabledForeground = (Color) value; return oldValue;
|
|
||||||
case "acceleratorForeground": oldValue = acceleratorForeground; acceleratorForeground = (Color) value; return oldValue;
|
|
||||||
case "acceleratorSelectionForeground": oldValue = acceleratorSelectionForeground; acceleratorSelectionForeground = (Color) value; return oldValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
return FlatStylingSupport.applyToAnnotatedObjectOrComponent( this, menuItem, key, value );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @since 2 */
|
/** @since 2 */
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
|
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
|
||||||
return FlatMenuItemUI.getStyleableInfos( renderer );
|
return FlatMenuItemUI.getStyleableInfos( this, renderer );
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
@Override
|
||||||
|
public Object getStyleableValue( JComponent c, String key ) {
|
||||||
|
return FlatMenuItemUI.getStyleableValue( this, renderer, key );
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
@Override
|
||||||
|
public MethodHandles.Lookup getLookupForStyling() {
|
||||||
|
// MethodHandles.lookup() is caller sensitive and must be invoked in this class,
|
||||||
|
// otherwise it is not possible to access protected fields in JRE superclass
|
||||||
|
return MethodHandles.lookup();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -18,12 +18,16 @@ 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.Component;
|
||||||
import java.awt.Container;
|
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.awt.event.MouseAdapter;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
import java.beans.PropertyChangeEvent;
|
import java.beans.PropertyChangeEvent;
|
||||||
|
import java.beans.PropertyChangeListener;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import javax.swing.AbstractButton;
|
import javax.swing.AbstractButton;
|
||||||
@@ -31,6 +35,7 @@ import javax.swing.CellRendererPane;
|
|||||||
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.BasicButtonListener;
|
import javax.swing.plaf.basic.BasicButtonListener;
|
||||||
@@ -78,7 +83,7 @@ public class FlatRadioButtonUI
|
|||||||
private Map<String, Object> oldStyleValues;
|
private Map<String, Object> oldStyleValues;
|
||||||
|
|
||||||
public static ComponentUI createUI( JComponent c ) {
|
public static ComponentUI createUI( JComponent c ) {
|
||||||
return FlatUIUtils.canUseSharedUI( c )
|
return FlatUIUtils.canUseSharedUI( c ) && !FlatUIUtils.needsLightAWTPeer( c )
|
||||||
? FlatUIUtils.createSharedUI( FlatRadioButtonUI.class, () -> new FlatRadioButtonUI( true ) )
|
? FlatUIUtils.createSharedUI( FlatRadioButtonUI.class, () -> new FlatRadioButtonUI( true ) )
|
||||||
: new FlatRadioButtonUI( false );
|
: new FlatRadioButtonUI( false );
|
||||||
}
|
}
|
||||||
@@ -90,11 +95,29 @@ public class FlatRadioButtonUI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void installUI( JComponent c ) {
|
public void installUI( JComponent c ) {
|
||||||
|
if( FlatUIUtils.needsLightAWTPeer( c ) )
|
||||||
|
FlatUIUtils.runWithLightAWTPeerUIDefaults( () -> installUIImpl( c ) );
|
||||||
|
else
|
||||||
|
installUIImpl( c );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void installUIImpl( JComponent c ) {
|
||||||
super.installUI( c );
|
super.installUI( c );
|
||||||
|
|
||||||
|
if( FlatUIUtils.isAWTPeer( c ) )
|
||||||
|
AWTPeerMouseExitedFix.install( c );
|
||||||
|
|
||||||
installStyle( (AbstractButton) c );
|
installStyle( (AbstractButton) c );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void uninstallUI( JComponent c ) {
|
||||||
|
super.uninstallUI( c );
|
||||||
|
|
||||||
|
if( FlatUIUtils.isAWTPeer( c ) )
|
||||||
|
AWTPeerMouseExitedFix.uninstall( c );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void installDefaults( AbstractButton b ) {
|
public void installDefaults( AbstractButton b ) {
|
||||||
super.installDefaults( b );
|
super.installDefaults( b );
|
||||||
@@ -199,6 +222,19 @@ public class FlatRadioButtonUI
|
|||||||
return infos;
|
return infos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
@Override
|
||||||
|
public Object getStyleableValue( JComponent c, String key ) {
|
||||||
|
// style icon
|
||||||
|
if( key.startsWith( "icon." ) ) {
|
||||||
|
return (icon instanceof FlatCheckBoxIcon)
|
||||||
|
? ((FlatCheckBoxIcon)icon).getStyleableValue( key.substring( "icon.".length() ) )
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FlatStylingSupport.getAnnotatedStyleableValue( this, key );
|
||||||
|
}
|
||||||
|
|
||||||
private static final Insets tempInsets = new Insets( 0, 0, 0, 0 );
|
private static final Insets tempInsets = new Insets( 0, 0, 0, 0 );
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -308,4 +344,69 @@ public class FlatRadioButtonUI
|
|||||||
FlatRadioButtonUI.this.propertyChange( b, e );
|
FlatRadioButtonUI.this.propertyChange( b, e );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---- class AWTPeerMouseExitedFix ----------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hack for missing mouse-exited event for java.awt.Checkbox on macOS (to fix hover effect).
|
||||||
|
*
|
||||||
|
* On macOS, AWT components internally use Swing components.
|
||||||
|
* This is implemented in class sun.lwawt.LWCheckboxPeer, which uses
|
||||||
|
* a container component CheckboxDelegate that has a JCheckBox and a JRadioButton
|
||||||
|
* as children. Only one of them is visible.
|
||||||
|
*
|
||||||
|
* The reason that mouse-exited event is not sent to the JCheckBox or JRadioButton
|
||||||
|
* is that sun.lwawt.LWComponentPeer.createDelegateEvent() uses
|
||||||
|
* SwingUtilities.getDeepestComponentAt() to find the event target,
|
||||||
|
* which finds the container component CheckboxDelegate,
|
||||||
|
* which receives the mouse-exited event.
|
||||||
|
*
|
||||||
|
* This class adds listeners and forwards the mouse-exited event
|
||||||
|
* from CheckboxDelegate to JCheckBox or JRadioButton.
|
||||||
|
*/
|
||||||
|
private static class AWTPeerMouseExitedFix
|
||||||
|
extends MouseAdapter
|
||||||
|
implements PropertyChangeListener
|
||||||
|
{
|
||||||
|
private final JComponent button;
|
||||||
|
|
||||||
|
static void install( JComponent button ) {
|
||||||
|
AWTPeerMouseExitedFix l = new AWTPeerMouseExitedFix( button );
|
||||||
|
button.addPropertyChangeListener( "ancestor", l );
|
||||||
|
Container parent = button.getParent();
|
||||||
|
if( parent != null )
|
||||||
|
parent.addMouseListener( l );
|
||||||
|
}
|
||||||
|
|
||||||
|
static void uninstall( JComponent button ) {
|
||||||
|
for( PropertyChangeListener l : button.getPropertyChangeListeners( "ancestor" ) ) {
|
||||||
|
if( l instanceof AWTPeerMouseExitedFix ) {
|
||||||
|
button.removePropertyChangeListener( "ancestor", l );
|
||||||
|
Container parent = button.getParent();
|
||||||
|
if( parent != null )
|
||||||
|
parent.removeMouseListener( (AWTPeerMouseExitedFix) l );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AWTPeerMouseExitedFix( JComponent button ) {
|
||||||
|
this.button = button;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void propertyChange( PropertyChangeEvent e ) {
|
||||||
|
if( e.getOldValue() instanceof Component )
|
||||||
|
((Component)e.getOldValue()).removeMouseListener( this );
|
||||||
|
if( e.getNewValue() instanceof Component ) {
|
||||||
|
((Component)e.getNewValue()).removeMouseListener( this ); // avoid duplicate listeners
|
||||||
|
((Component)e.getNewValue()).addMouseListener( this );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseExited( MouseEvent e ) {
|
||||||
|
button.dispatchEvent( SwingUtilities.convertMouseEvent( e.getComponent(), e, button ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -364,6 +364,12 @@ public class FlatRootPaneUI
|
|||||||
((FlatRootPaneUI)ui).titlePane.isMenuBarEmbedded();
|
((FlatRootPaneUI)ui).titlePane.isMenuBarEmbedded();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.4 */
|
||||||
|
protected static FlatTitlePane getTitlePane( JRootPane rootPane ) {
|
||||||
|
RootPaneUI ui = rootPane.getUI();
|
||||||
|
return ui instanceof FlatRootPaneUI ? ((FlatRootPaneUI)ui).titlePane : null;
|
||||||
|
}
|
||||||
|
|
||||||
//---- class FlatRootLayout -----------------------------------------------
|
//---- class FlatRootLayout -----------------------------------------------
|
||||||
|
|
||||||
protected class FlatRootLayout
|
protected class FlatRootLayout
|
||||||
|
|||||||
@@ -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.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
@@ -24,6 +25,7 @@ import java.awt.Rectangle;
|
|||||||
import java.awt.event.MouseAdapter;
|
import java.awt.event.MouseAdapter;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.beans.PropertyChangeListener;
|
import java.beans.PropertyChangeListener;
|
||||||
|
import java.lang.invoke.MethodHandles;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import javax.swing.InputMap;
|
import javax.swing.InputMap;
|
||||||
@@ -36,9 +38,13 @@ import javax.swing.UIManager;
|
|||||||
import javax.swing.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
import javax.swing.plaf.basic.BasicScrollBarUI;
|
import javax.swing.plaf.basic.BasicScrollBarUI;
|
||||||
import com.formdev.flatlaf.FlatClientProperties;
|
import com.formdev.flatlaf.FlatClientProperties;
|
||||||
|
import com.formdev.flatlaf.FlatLaf;
|
||||||
import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable;
|
import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable;
|
||||||
|
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableField;
|
||||||
|
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableLookupProvider;
|
||||||
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableUI;
|
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableUI;
|
||||||
import com.formdev.flatlaf.util.LoggingFacade;
|
import com.formdev.flatlaf.util.LoggingFacade;
|
||||||
|
import com.formdev.flatlaf.util.SystemInfo;
|
||||||
import com.formdev.flatlaf.util.UIScale;
|
import com.formdev.flatlaf.util.UIScale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -77,9 +83,15 @@ import com.formdev.flatlaf.util.UIScale;
|
|||||||
*
|
*
|
||||||
* @author Karl Tauber
|
* @author Karl Tauber
|
||||||
*/
|
*/
|
||||||
|
@StyleableField( cls=BasicScrollBarUI.class, key="track", fieldName="trackColor" )
|
||||||
|
@StyleableField( cls=BasicScrollBarUI.class, key="thumb", fieldName="thumbColor" )
|
||||||
|
@StyleableField( cls=BasicScrollBarUI.class, key="width", fieldName="scrollBarWidth" )
|
||||||
|
@StyleableField( cls=BasicScrollBarUI.class, key="minimumThumbSize" )
|
||||||
|
@StyleableField( cls=BasicScrollBarUI.class, key="maximumThumbSize" )
|
||||||
|
|
||||||
public class FlatScrollBarUI
|
public class FlatScrollBarUI
|
||||||
extends BasicScrollBarUI
|
extends BasicScrollBarUI
|
||||||
implements StyleableUI
|
implements StyleableUI, StyleableLookupProvider
|
||||||
{
|
{
|
||||||
// overrides BasicScrollBarUI.supportsAbsolutePositioning (which is private)
|
// overrides BasicScrollBarUI.supportsAbsolutePositioning (which is private)
|
||||||
@Styleable protected boolean allowsAbsolutePositioning;
|
@Styleable protected boolean allowsAbsolutePositioning;
|
||||||
@@ -108,6 +120,7 @@ public class FlatScrollBarUI
|
|||||||
protected boolean hoverThumb;
|
protected boolean hoverThumb;
|
||||||
|
|
||||||
private Map<String, Object> oldStyleValues;
|
private Map<String, Object> oldStyleValues;
|
||||||
|
private boolean isAWTPeer;
|
||||||
|
|
||||||
public static ComponentUI createUI( JComponent c ) {
|
public static ComponentUI createUI( JComponent c ) {
|
||||||
return new FlatScrollBarUI();
|
return new FlatScrollBarUI();
|
||||||
@@ -221,6 +234,37 @@ public class FlatScrollBarUI
|
|||||||
}
|
}
|
||||||
SwingUtilities.replaceUIInputMap( scrollbar, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, inputMap );
|
SwingUtilities.replaceUIInputMap( scrollbar, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, inputMap );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "ancestor":
|
||||||
|
// check whether scroll bar is used as AWT peer on macOS
|
||||||
|
if( SystemInfo.isMacOS ) {
|
||||||
|
Container p = scrollbar.getParent();
|
||||||
|
for( int i = 0; i < 2 && p != null; i++, p = p.getParent() ) {
|
||||||
|
if( FlatUIUtils.isAWTPeer( p ) ) {
|
||||||
|
// Used to disable hover, which does not work correctly
|
||||||
|
// because scroll bars do not receive mouse exited event.
|
||||||
|
// The scroll pane, including its scroll bars, is not part
|
||||||
|
// of the component hierarchy and does not receive mouse events
|
||||||
|
// directly. Instead LWComponentPeer receives mouse events
|
||||||
|
// and delegates them to peers, but entered/exited events
|
||||||
|
// are sent only for the whole scroll pane.
|
||||||
|
// Exited event is only sent when mouse leaves scroll pane.
|
||||||
|
// If mouse enters/exits scroll bar, no entered/exited events are sent.
|
||||||
|
isAWTPeer = true;
|
||||||
|
|
||||||
|
// if dark theme is active, reinstall using light theme
|
||||||
|
if( FlatLaf.isLafDark() ) {
|
||||||
|
FlatUIUtils.runWithLightAWTPeerUIDefaults( () -> {
|
||||||
|
JScrollBar scrollbar = this.scrollbar;
|
||||||
|
uninstallUI( scrollbar );
|
||||||
|
installUI( scrollbar );
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -246,30 +290,27 @@ public class FlatScrollBarUI
|
|||||||
|
|
||||||
/** @since 2 */
|
/** @since 2 */
|
||||||
protected Object applyStyleProperty( String key, Object value ) {
|
protected Object applyStyleProperty( String key, Object value ) {
|
||||||
Object oldValue;
|
|
||||||
switch( key ) {
|
|
||||||
// BasicScrollBarUI
|
|
||||||
case "track": oldValue = trackColor; trackColor = (Color) value; return oldValue;
|
|
||||||
case "thumb": oldValue = thumbColor; thumbColor = (Color) value; return oldValue;
|
|
||||||
case "width": oldValue = scrollBarWidth; scrollBarWidth = (int) value; return oldValue;
|
|
||||||
case "minimumThumbSize": oldValue = minimumThumbSize; minimumThumbSize = (Dimension) value; return oldValue;
|
|
||||||
case "maximumThumbSize": oldValue = maximumThumbSize; maximumThumbSize = (Dimension) value; return oldValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
return FlatStylingSupport.applyToAnnotatedObjectOrComponent( this, scrollbar, key, value );
|
return FlatStylingSupport.applyToAnnotatedObjectOrComponent( this, scrollbar, key, value );
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @since 2 */
|
/** @since 2 */
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
|
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
|
||||||
Map<String, Class<?>> infos = new FlatStylingSupport.StyleableInfosMap<>();
|
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
||||||
infos.put( "track", Color.class );
|
}
|
||||||
infos.put( "thumb", Color.class );
|
|
||||||
infos.put( "width", int.class );
|
/** @since 2.5 */
|
||||||
infos.put( "minimumThumbSize", Dimension.class );
|
@Override
|
||||||
infos.put( "maximumThumbSize", Dimension.class );
|
public Object getStyleableValue( JComponent c, String key ) {
|
||||||
FlatStylingSupport.collectAnnotatedStyleableInfos( this, infos );
|
return FlatStylingSupport.getAnnotatedStyleableValue( this, key );
|
||||||
return infos;
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
@Override
|
||||||
|
public MethodHandles.Lookup getLookupForStyling() {
|
||||||
|
// MethodHandles.lookup() is caller sensitive and must be invoked in this class,
|
||||||
|
// otherwise it is not possible to access protected fields in JRE superclass
|
||||||
|
return MethodHandles.lookup();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -311,6 +352,9 @@ public class FlatScrollBarUI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paintTrack( Graphics g, JComponent c, Rectangle trackBounds ) {
|
protected void paintTrack( Graphics g, JComponent c, Rectangle trackBounds ) {
|
||||||
|
if( trackBounds.isEmpty() || !scrollbar.isEnabled() )
|
||||||
|
return;
|
||||||
|
|
||||||
g.setColor( getTrackColor( c, hoverTrack, isPressed && hoverTrack && !hoverThumb ) );
|
g.setColor( getTrackColor( c, hoverTrack, isPressed && hoverTrack && !hoverThumb ) );
|
||||||
paintTrackOrThumb( g, c, trackBounds, trackInsets, trackArc );
|
paintTrackOrThumb( g, c, trackBounds, trackInsets, trackArc );
|
||||||
}
|
}
|
||||||
@@ -357,7 +401,7 @@ public class FlatScrollBarUI
|
|||||||
Color trackColor = FlatUIUtils.deriveColor( this.trackColor, c.getBackground() );
|
Color trackColor = FlatUIUtils.deriveColor( this.trackColor, c.getBackground() );
|
||||||
return (pressed && pressedTrackColor != null)
|
return (pressed && pressedTrackColor != null)
|
||||||
? FlatUIUtils.deriveColor( pressedTrackColor, trackColor )
|
? FlatUIUtils.deriveColor( pressedTrackColor, trackColor )
|
||||||
: ((hover && hoverTrackColor != null)
|
: ((hover && hoverTrackColor != null && !isAWTPeer)
|
||||||
? FlatUIUtils.deriveColor( hoverTrackColor, trackColor )
|
? FlatUIUtils.deriveColor( hoverTrackColor, trackColor )
|
||||||
: trackColor);
|
: trackColor);
|
||||||
}
|
}
|
||||||
@@ -367,7 +411,7 @@ public class FlatScrollBarUI
|
|||||||
Color thumbColor = FlatUIUtils.deriveColor( this.thumbColor, trackColor );
|
Color thumbColor = FlatUIUtils.deriveColor( this.thumbColor, trackColor );
|
||||||
return (pressed && pressedThumbColor != null)
|
return (pressed && pressedThumbColor != null)
|
||||||
? FlatUIUtils.deriveColor( pressedThumbColor, thumbColor )
|
? FlatUIUtils.deriveColor( pressedThumbColor, thumbColor )
|
||||||
: ((hover && hoverThumbColor != null)
|
: ((hover && hoverThumbColor != null && !isAWTPeer)
|
||||||
? FlatUIUtils.deriveColor( hoverThumbColor, thumbColor )
|
? FlatUIUtils.deriveColor( hoverThumbColor, thumbColor )
|
||||||
: thumbColor);
|
: thumbColor);
|
||||||
}
|
}
|
||||||
@@ -411,18 +455,31 @@ public class FlatScrollBarUI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mousePressed( MouseEvent e ) {
|
public void mousePressed( MouseEvent e ) {
|
||||||
isPressed = true;
|
if( SwingUtilities.isLeftMouseButton( e ) || isAbsolutePositioning( e ) ) {
|
||||||
repaint();
|
isPressed = true;
|
||||||
|
repaint();
|
||||||
|
|
||||||
|
// update hover because BasicScrollBarUI.TrackListener.mousePressed()
|
||||||
|
// moves the track on middle-click (if absolute positioning is enabled)
|
||||||
|
if( isAbsolutePositioning( e ) )
|
||||||
|
update( e.getX(), e.getY() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseReleased( MouseEvent e ) {
|
public void mouseReleased( MouseEvent e ) {
|
||||||
isPressed = false;
|
if( SwingUtilities.isLeftMouseButton( e ) || isAbsolutePositioning( e ) ) {
|
||||||
repaint();
|
isPressed = false;
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
|
||||||
update( e.getX(), e.getY() );
|
update( e.getX(), e.getY() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isAbsolutePositioning( MouseEvent e ) {
|
||||||
|
return getSupportsAbsolutePositioning() && SwingUtilities.isMiddleMouseButton( e );
|
||||||
|
}
|
||||||
|
|
||||||
private void update( int x, int y ) {
|
private void update( int x, int y ) {
|
||||||
boolean inTrack = getTrackBounds().contains( x, y );
|
boolean inTrack = getTrackBounds().contains( x, y );
|
||||||
boolean inThumb = getThumbBounds().contains( x, y );
|
boolean inThumb = getThumbBounds().contains( x, y );
|
||||||
|
|||||||
@@ -87,6 +87,13 @@ public class FlatScrollPaneUI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void installUI( JComponent c ) {
|
public void installUI( JComponent c ) {
|
||||||
|
if( FlatUIUtils.needsLightAWTPeer( c ) )
|
||||||
|
FlatUIUtils.runWithLightAWTPeerUIDefaults( () -> installUIImpl( c ) );
|
||||||
|
else
|
||||||
|
installUIImpl( c );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void installUIImpl( JComponent c ) {
|
||||||
super.installUI( c );
|
super.installUI( c );
|
||||||
|
|
||||||
int focusWidth = UIManager.getInt( "Component.focusWidth" );
|
int focusWidth = UIManager.getInt( "Component.focusWidth" );
|
||||||
@@ -343,6 +350,12 @@ public class FlatScrollPaneUI
|
|||||||
return FlatStylingSupport.getAnnotatedStyleableInfos( this, scrollpane.getBorder() );
|
return FlatStylingSupport.getAnnotatedStyleableInfos( this, scrollpane.getBorder() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
@Override
|
||||||
|
public Object getStyleableValue( JComponent c, String key ) {
|
||||||
|
return FlatStylingSupport.getAnnotatedStyleableValue( this, scrollpane.getBorder(), key );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void updateViewport( PropertyChangeEvent e ) {
|
protected void updateViewport( PropertyChangeEvent e ) {
|
||||||
super.updateViewport( e );
|
super.updateViewport( e );
|
||||||
|
|||||||
@@ -170,6 +170,12 @@ public class FlatSeparatorUI
|
|||||||
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
@Override
|
||||||
|
public Object getStyleableValue( JComponent c, String key ) {
|
||||||
|
return FlatStylingSupport.getAnnotatedStyleableValue( this, key );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void paint( Graphics g, JComponent c ) {
|
public void paint( Graphics g, JComponent c ) {
|
||||||
Graphics2D g2 = (Graphics2D) g.create();
|
Graphics2D g2 = (Graphics2D) g.create();
|
||||||
|
|||||||
@@ -222,6 +222,12 @@ public class FlatSliderUI
|
|||||||
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
@Override
|
||||||
|
public Object getStyleableValue( JComponent c, String key ) {
|
||||||
|
return FlatStylingSupport.getAnnotatedStyleableValue( this, key );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getBaseline( JComponent c, int width, int height ) {
|
public int getBaseline( JComponent c, int width, int height ) {
|
||||||
if( c == null )
|
if( c == null )
|
||||||
|
|||||||
@@ -223,6 +223,12 @@ public class FlatSpinnerUI
|
|||||||
return FlatStylingSupport.getAnnotatedStyleableInfos( this, spinner.getBorder() );
|
return FlatStylingSupport.getAnnotatedStyleableInfos( this, spinner.getBorder() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
@Override
|
||||||
|
public Object getStyleableValue( JComponent c, String key ) {
|
||||||
|
return FlatStylingSupport.getAnnotatedStyleableValue( this, spinner.getBorder(), key );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected JComponent createEditor() {
|
protected JComponent createEditor() {
|
||||||
JComponent editor = super.createEditor();
|
JComponent editor = super.createEditor();
|
||||||
@@ -477,9 +483,10 @@ public class FlatSpinnerUI
|
|||||||
// limit buttons width to height of a raw spinner (without insets)
|
// limit buttons width to height of a raw spinner (without insets)
|
||||||
FontMetrics fm = spinner.getFontMetrics( spinner.getFont() );
|
FontMetrics fm = spinner.getFontMetrics( spinner.getFont() );
|
||||||
int maxButtonWidth = fm.getHeight() + scale( padding.top ) + scale( padding.bottom );
|
int maxButtonWidth = fm.getHeight() + scale( padding.top ) + scale( padding.bottom );
|
||||||
|
int minButtonWidth = (maxButtonWidth * 3) / 4;
|
||||||
|
|
||||||
// make button area square (if spinner has preferred height)
|
// make button area square (except if width is limited)
|
||||||
int buttonsWidth = Math.min( parent.getPreferredSize().height - insets.top - insets.bottom, maxButtonWidth );
|
int buttonsWidth = Math.min( Math.max( buttonsRect.height, minButtonWidth ), maxButtonWidth );
|
||||||
buttonsRect.width = buttonsWidth;
|
buttonsRect.width = buttonsWidth;
|
||||||
|
|
||||||
if( parent.getComponentOrientation().isLeftToRight() ) {
|
if( parent.getComponentOrientation().isLeftToRight() ) {
|
||||||
|
|||||||
@@ -183,6 +183,17 @@ public class FlatSplitPaneUI
|
|||||||
return infos;
|
return infos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
@Override
|
||||||
|
public Object getStyleableValue( JComponent c, String key ) {
|
||||||
|
if( divider instanceof FlatSplitPaneDivider ) {
|
||||||
|
Object value = ((FlatSplitPaneDivider)divider).getStyleableValue( key );
|
||||||
|
if( value != null )
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
return FlatStylingSupport.getAnnotatedStyleableValue( this, key );
|
||||||
|
}
|
||||||
|
|
||||||
//---- class FlatSplitPaneDivider -----------------------------------------
|
//---- class FlatSplitPaneDivider -----------------------------------------
|
||||||
|
|
||||||
protected class FlatSplitPaneDivider
|
protected class FlatSplitPaneDivider
|
||||||
@@ -200,20 +211,21 @@ public class FlatSplitPaneUI
|
|||||||
setLayout( new FlatDividerLayout() );
|
setLayout( new FlatDividerLayout() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** @since 2 */
|
||||||
* @since 2
|
|
||||||
*/
|
|
||||||
protected Object applyStyleProperty( String key, Object value ) {
|
protected Object applyStyleProperty( String key, Object value ) {
|
||||||
return FlatStylingSupport.applyToAnnotatedObject( this, key, value );
|
return FlatStylingSupport.applyToAnnotatedObject( this, key, value );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** @since 2 */
|
||||||
* @since 2
|
|
||||||
*/
|
|
||||||
public Map<String, Class<?>> getStyleableInfos() {
|
public Map<String, Class<?>> getStyleableInfos() {
|
||||||
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
public Object getStyleableValue( String key ) {
|
||||||
|
return FlatStylingSupport.getAnnotatedStyleableValue( this, key );
|
||||||
|
}
|
||||||
|
|
||||||
void updateStyle() {
|
void updateStyle() {
|
||||||
if( leftButton instanceof FlatOneTouchButton )
|
if( leftButton instanceof FlatOneTouchButton )
|
||||||
((FlatOneTouchButton)leftButton).updateStyle();
|
((FlatOneTouchButton)leftButton).updateStyle();
|
||||||
|
|||||||
@@ -18,9 +18,11 @@ package com.formdev.flatlaf.ui;
|
|||||||
|
|
||||||
import java.beans.PropertyChangeListener;
|
import java.beans.PropertyChangeListener;
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Repeatable;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
|
import java.lang.invoke.MethodHandles;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
@@ -63,15 +65,55 @@ public class FlatStylingSupport
|
|||||||
Class<?> type() default Void.class;
|
Class<?> type() default Void.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates that a field in the specified (super) class
|
||||||
|
* is intended to be used by FlatLaf styling support.
|
||||||
|
* <p>
|
||||||
|
* Use this annotation, instead of {@link Styleable}, to style fields
|
||||||
|
* in superclasses, where it is not possible to use {@link Styleable}.
|
||||||
|
* <p>
|
||||||
|
* Classes using this annotation may implement {@link StyleableLookupProvider}
|
||||||
|
* to give access to protected fields (in JRE) in modular applications.
|
||||||
|
*
|
||||||
|
* @since 2.5
|
||||||
|
*/
|
||||||
|
@Target(ElementType.TYPE)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Repeatable(StyleableFields.class)
|
||||||
|
public @interface StyleableField {
|
||||||
|
Class<?> cls();
|
||||||
|
String key();
|
||||||
|
String fieldName() default "";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Container annotation for {@link StyleableField}.
|
||||||
|
*
|
||||||
|
* @since 2.5
|
||||||
|
*/
|
||||||
|
@Target(ElementType.TYPE)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface StyleableFields {
|
||||||
|
StyleableField[] value();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/** @since 2 */
|
/** @since 2 */
|
||||||
public interface StyleableUI {
|
public interface StyleableUI {
|
||||||
Map<String, Class<?>> getStyleableInfos( JComponent c );
|
Map<String, Class<?>> getStyleableInfos( JComponent c );
|
||||||
|
/** @since 2.5 */ Object getStyleableValue( JComponent c, String key );
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @since 2 */
|
/** @since 2 */
|
||||||
public interface StyleableBorder {
|
public interface StyleableBorder {
|
||||||
Object applyStyleProperty( String key, Object value );
|
Object applyStyleProperty( String key, Object value );
|
||||||
Map<String, Class<?>> getStyleableInfos();
|
Map<String, Class<?>> getStyleableInfos();
|
||||||
|
/** @since 2.5 */ Object getStyleableValue( String key );
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
public interface StyleableLookupProvider {
|
||||||
|
MethodHandles.Lookup getLookupForStyling();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -365,21 +407,25 @@ public class FlatStylingSupport
|
|||||||
public static Object applyToAnnotatedObject( Object obj, String key, Object value )
|
public static Object applyToAnnotatedObject( Object obj, String key, Object value )
|
||||||
throws UnknownStyleException, IllegalArgumentException
|
throws UnknownStyleException, IllegalArgumentException
|
||||||
{
|
{
|
||||||
String fieldName = key;
|
String fieldName = keyToFieldName( key );
|
||||||
int dotIndex = key.indexOf( '.' );
|
|
||||||
if( dotIndex >= 0 ) {
|
|
||||||
// remove first dot in key and change subsequent character to uppercase
|
|
||||||
fieldName = key.substring( 0, dotIndex )
|
|
||||||
+ Character.toUpperCase( key.charAt( dotIndex + 1 ) )
|
|
||||||
+ key.substring( dotIndex + 2 );
|
|
||||||
}
|
|
||||||
|
|
||||||
return applyToField( obj, fieldName, key, value, field -> {
|
return applyToField( obj, fieldName, key, value, field -> {
|
||||||
Styleable styleable = field.getAnnotation( Styleable.class );
|
Styleable styleable = field.getAnnotation( Styleable.class );
|
||||||
return styleable != null && styleable.dot() == (dotIndex >= 0);
|
return styleable != null && styleable.dot() == (fieldName != key);
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String keyToFieldName( String key ) {
|
||||||
|
int dotIndex = key.indexOf( '.' );
|
||||||
|
if( dotIndex < 0 )
|
||||||
|
return key;
|
||||||
|
|
||||||
|
// remove first dot in key and change subsequent character to uppercase
|
||||||
|
return key.substring( 0, dotIndex )
|
||||||
|
+ Character.toUpperCase( key.charAt( dotIndex + 1 ) )
|
||||||
|
+ key.substring( dotIndex + 2 );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Applies the given value to a field of the given object.
|
* Applies the given value to a field of the given object.
|
||||||
*
|
*
|
||||||
@@ -405,26 +451,17 @@ public class FlatStylingSupport
|
|||||||
for(;;) {
|
for(;;) {
|
||||||
try {
|
try {
|
||||||
Field f = cls.getDeclaredField( fieldName );
|
Field f = cls.getDeclaredField( fieldName );
|
||||||
if( predicate == null || predicate.test( f ) ) {
|
if( predicate == null || predicate.test( f ) )
|
||||||
if( !isValidField( f ) )
|
return applyToField( f, obj, value, false );
|
||||||
throw new IllegalArgumentException( "field '" + cls.getName() + "." + fieldName + "' is final or static" );
|
|
||||||
|
|
||||||
try {
|
|
||||||
// necessary to access protected fields in other packages
|
|
||||||
f.setAccessible( true );
|
|
||||||
|
|
||||||
// get old value and set new value
|
|
||||||
Object oldValue = f.get( obj );
|
|
||||||
f.set( obj, convertToEnum( value, f.getType() ) );
|
|
||||||
return oldValue;
|
|
||||||
} catch( IllegalAccessException ex ) {
|
|
||||||
throw new IllegalArgumentException( "failed to access field '" + cls.getName() + "." + fieldName + "'", ex );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch( NoSuchFieldException ex ) {
|
} catch( NoSuchFieldException ex ) {
|
||||||
// field not found in class --> try superclass
|
// field not found in class --> try superclass
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for( StyleableField styleableField : cls.getAnnotationsByType( StyleableField.class ) ) {
|
||||||
|
if( key.equals( styleableField.key() ) )
|
||||||
|
return applyToField( getStyleableField( styleableField ), obj, value, true );
|
||||||
|
}
|
||||||
|
|
||||||
cls = cls.getSuperclass();
|
cls = cls.getSuperclass();
|
||||||
if( cls == null )
|
if( cls == null )
|
||||||
throw new UnknownStyleException( key );
|
throw new UnknownStyleException( key );
|
||||||
@@ -437,11 +474,83 @@ public class FlatStylingSupport
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Object applyToField( Field f, Object obj, Object value, boolean useMethodHandles ) {
|
||||||
|
checkValidField( f );
|
||||||
|
|
||||||
|
if( useMethodHandles && obj instanceof StyleableLookupProvider ) {
|
||||||
|
try {
|
||||||
|
// use method handles to access protected fields in JRE in modular applications
|
||||||
|
MethodHandles.Lookup lookup = ((StyleableLookupProvider)obj).getLookupForStyling();
|
||||||
|
|
||||||
|
// get old value and set new value
|
||||||
|
Object oldValue = lookup.unreflectGetter( f ).invoke( obj );
|
||||||
|
lookup.unreflectSetter( f ).invoke( obj, convertToEnum( value, f.getType() ) );
|
||||||
|
return oldValue;
|
||||||
|
} catch( Throwable ex ) {
|
||||||
|
throw newFieldAccessFailed( f, ex );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// necessary to access protected fields in other packages
|
||||||
|
f.setAccessible( true );
|
||||||
|
|
||||||
|
// get old value and set new value
|
||||||
|
Object oldValue = f.get( obj );
|
||||||
|
f.set( obj, convertToEnum( value, f.getType() ) );
|
||||||
|
return oldValue;
|
||||||
|
} catch( IllegalAccessException ex ) {
|
||||||
|
throw newFieldAccessFailed( f, ex );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Object getFieldValue( Field f, Object obj, boolean useMethodHandles ) {
|
||||||
|
checkValidField( f );
|
||||||
|
|
||||||
|
if( useMethodHandles && obj instanceof StyleableLookupProvider ) {
|
||||||
|
// use method handles to access protected fields in JRE in modular applications
|
||||||
|
try {
|
||||||
|
MethodHandles.Lookup lookup = ((StyleableLookupProvider)obj).getLookupForStyling();
|
||||||
|
return lookup.unreflectGetter( f ).invoke( obj );
|
||||||
|
} catch( Throwable ex ) {
|
||||||
|
throw newFieldAccessFailed( f, ex );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
f.setAccessible( true );
|
||||||
|
return f.get( obj );
|
||||||
|
} catch( IllegalAccessException ex ) {
|
||||||
|
throw newFieldAccessFailed( f, ex );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IllegalArgumentException newFieldAccessFailed( Field f, Throwable ex ) {
|
||||||
|
return new IllegalArgumentException( "failed to access field '" + f.getDeclaringClass().getName() + "." + f.getName() + "'", ex );
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void checkValidField( Field f ) {
|
||||||
|
if( !isValidField( f ) )
|
||||||
|
throw new IllegalArgumentException( "field '" + f.getDeclaringClass().getName() + "." + f.getName() + "' is final or static" );
|
||||||
|
}
|
||||||
|
|
||||||
private static boolean isValidField( Field f ) {
|
private static boolean isValidField( Field f ) {
|
||||||
int modifiers = f.getModifiers();
|
int modifiers = f.getModifiers();
|
||||||
return (modifiers & (Modifier.FINAL|Modifier.STATIC)) == 0 && !f.isSynthetic();
|
return (modifiers & (Modifier.FINAL|Modifier.STATIC)) == 0 && !f.isSynthetic();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Field getStyleableField( StyleableField styleableField ) {
|
||||||
|
String fieldName = styleableField.fieldName();
|
||||||
|
if( fieldName.isEmpty() )
|
||||||
|
fieldName = styleableField.key();
|
||||||
|
|
||||||
|
try {
|
||||||
|
return styleableField.cls().getDeclaredField( fieldName );
|
||||||
|
} catch( NoSuchFieldException ex ) {
|
||||||
|
throw new IllegalArgumentException( "field '" + styleableField.cls().getName() + "." + fieldName + "' not found", ex );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Applies the given value to a property of the given object.
|
* Applies the given value to a property of the given object.
|
||||||
* Works only for properties that have public getter and setter methods.
|
* Works only for properties that have public getter and setter methods.
|
||||||
@@ -628,6 +737,7 @@ public class FlatStylingSupport
|
|||||||
Class<?> cls = obj.getClass();
|
Class<?> cls = obj.getClass();
|
||||||
|
|
||||||
for(;;) {
|
for(;;) {
|
||||||
|
// find fields annotated with 'Styleable'
|
||||||
for( Field f : cls.getDeclaredFields() ) {
|
for( Field f : cls.getDeclaredFields() ) {
|
||||||
if( !isValidField( f ) )
|
if( !isValidField( f ) )
|
||||||
continue;
|
continue;
|
||||||
@@ -666,6 +776,20 @@ public class FlatStylingSupport
|
|||||||
infos.put( name, type );
|
infos.put( name, type );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get fields specified in 'StyleableField' annotation
|
||||||
|
for( StyleableField styleableField : cls.getAnnotationsByType( StyleableField.class ) ) {
|
||||||
|
String name = styleableField.key();
|
||||||
|
|
||||||
|
// for the case that the same field name is used in a class and in
|
||||||
|
// one of its superclasses, do not process field in superclass
|
||||||
|
if( processedFields.contains( name ) )
|
||||||
|
continue;
|
||||||
|
processedFields.add( name );
|
||||||
|
|
||||||
|
Field f = getStyleableField( styleableField );
|
||||||
|
infos.put( name, f.getType() );
|
||||||
|
}
|
||||||
|
|
||||||
cls = cls.getSuperclass();
|
cls = cls.getSuperclass();
|
||||||
if( cls == null )
|
if( cls == null )
|
||||||
return;
|
return;
|
||||||
@@ -686,6 +810,52 @@ public class FlatStylingSupport
|
|||||||
infos.put( keyPrefix.concat( e.getKey() ), e.getValue() );
|
infos.put( keyPrefix.concat( e.getKey() ), e.getValue() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Object getAnnotatedStyleableValue( Object obj, String key ) {
|
||||||
|
String fieldName = keyToFieldName( key );
|
||||||
|
Class<?> cls = obj.getClass();
|
||||||
|
|
||||||
|
for(;;) {
|
||||||
|
try {
|
||||||
|
// find field annotated with 'Styleable'
|
||||||
|
Field f = cls.getDeclaredField( fieldName );
|
||||||
|
Styleable styleable = f.getAnnotation( Styleable.class );
|
||||||
|
if( styleable != null ) {
|
||||||
|
if( styleable.dot() != (fieldName != key) )
|
||||||
|
throw new IllegalArgumentException( "'Styleable.dot' on field '" + fieldName + "' does not match key '" + key + "'" );
|
||||||
|
if( styleable.type() != Void.class )
|
||||||
|
throw new IllegalArgumentException( "'Styleable.type' on field '" + fieldName + "' not supported" );
|
||||||
|
|
||||||
|
return getFieldValue( f, obj, false );
|
||||||
|
}
|
||||||
|
} catch( NoSuchFieldException ex ) {
|
||||||
|
// field not found in class --> try superclass
|
||||||
|
}
|
||||||
|
|
||||||
|
// find field specified in 'StyleableField' annotation
|
||||||
|
for( StyleableField styleableField : cls.getAnnotationsByType( StyleableField.class ) ) {
|
||||||
|
if( key.equals( styleableField.key() ) )
|
||||||
|
return getFieldValue( getStyleableField( styleableField ), obj, true );
|
||||||
|
}
|
||||||
|
|
||||||
|
cls = cls.getSuperclass();
|
||||||
|
if( cls == null )
|
||||||
|
return null;
|
||||||
|
|
||||||
|
String superclassName = cls.getName();
|
||||||
|
if( superclassName.startsWith( "java." ) || superclassName.startsWith( "javax." ) )
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object getAnnotatedStyleableValue( Object obj, Border border, String key ) {
|
||||||
|
if( border instanceof StyleableBorder ) {
|
||||||
|
Object value = ((StyleableBorder)border).getStyleableValue( key );
|
||||||
|
if( value != null )
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
return getAnnotatedStyleableValue( obj, key );
|
||||||
|
}
|
||||||
|
|
||||||
//---- class UnknownStyleException ----------------------------------------
|
//---- class UnknownStyleException ----------------------------------------
|
||||||
|
|
||||||
public static class UnknownStyleException
|
public static class UnknownStyleException
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ import com.formdev.flatlaf.util.UIScale;
|
|||||||
* @uiDefault TabbedPane.showTabSeparators boolean
|
* @uiDefault TabbedPane.showTabSeparators boolean
|
||||||
* @uiDefault TabbedPane.tabSeparatorsFullHeight boolean
|
* @uiDefault TabbedPane.tabSeparatorsFullHeight boolean
|
||||||
* @uiDefault TabbedPane.hasFullBorder boolean
|
* @uiDefault TabbedPane.hasFullBorder boolean
|
||||||
* @uiDefault TabbedPane.activeTabBorder boolean
|
* @uiDefault TabbedPane.rotateTabRuns boolean
|
||||||
*
|
*
|
||||||
* @uiDefault TabbedPane.tabLayoutPolicy String wrap (default) or scroll
|
* @uiDefault TabbedPane.tabLayoutPolicy String wrap (default) or scroll
|
||||||
* @uiDefault TabbedPane.tabType String underlined (default) or card
|
* @uiDefault TabbedPane.tabType String underlined (default) or card
|
||||||
@@ -220,6 +220,7 @@ public class FlatTabbedPaneUI
|
|||||||
@Styleable protected boolean tabSeparatorsFullHeight;
|
@Styleable protected boolean tabSeparatorsFullHeight;
|
||||||
@Styleable protected boolean hasFullBorder;
|
@Styleable protected boolean hasFullBorder;
|
||||||
@Styleable protected boolean tabsOpaque = true;
|
@Styleable protected boolean tabsOpaque = true;
|
||||||
|
/** @since 2.5 */ @Styleable protected boolean rotateTabRuns = true;
|
||||||
|
|
||||||
@Styleable(type=String.class) private int tabType;
|
@Styleable(type=String.class) private int tabType;
|
||||||
@Styleable(type=String.class) private int tabsPopupPolicy;
|
@Styleable(type=String.class) private int tabsPopupPolicy;
|
||||||
@@ -342,6 +343,7 @@ public class FlatTabbedPaneUI
|
|||||||
tabSeparatorsFullHeight = UIManager.getBoolean( "TabbedPane.tabSeparatorsFullHeight" );
|
tabSeparatorsFullHeight = UIManager.getBoolean( "TabbedPane.tabSeparatorsFullHeight" );
|
||||||
hasFullBorder = UIManager.getBoolean( "TabbedPane.hasFullBorder" );
|
hasFullBorder = UIManager.getBoolean( "TabbedPane.hasFullBorder" );
|
||||||
tabsOpaque = UIManager.getBoolean( "TabbedPane.tabsOpaque" );
|
tabsOpaque = UIManager.getBoolean( "TabbedPane.tabsOpaque" );
|
||||||
|
rotateTabRuns = FlatUIUtils.getUIBoolean( "TabbedPane.rotateTabRuns", true );
|
||||||
|
|
||||||
tabType = parseTabType( UIManager.getString( "TabbedPane.tabType" ) );
|
tabType = parseTabType( UIManager.getString( "TabbedPane.tabType" ) );
|
||||||
tabsPopupPolicy = parseTabsPopupPolicy( UIManager.getString( "TabbedPane.tabsPopupPolicy" ) );
|
tabsPopupPolicy = parseTabsPopupPolicy( UIManager.getString( "TabbedPane.tabsPopupPolicy" ) );
|
||||||
@@ -687,6 +689,76 @@ public class FlatTabbedPaneUI
|
|||||||
return infos;
|
return infos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
@Override
|
||||||
|
public Object getStyleableValue( JComponent c, String key ) {
|
||||||
|
// close icon
|
||||||
|
if( key.startsWith( "close" ) ) {
|
||||||
|
return (closeIcon instanceof FlatTabbedPaneCloseIcon)
|
||||||
|
? ((FlatTabbedPaneCloseIcon)closeIcon).getStyleableValue( key )
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch( key ) {
|
||||||
|
// BasicTabbedPaneUI
|
||||||
|
case "tabInsets": return tabInsets;
|
||||||
|
case "tabAreaInsets": return tabAreaInsets;
|
||||||
|
case "textIconGap": return textIconGapUnscaled;
|
||||||
|
|
||||||
|
// FlatTabbedPaneUI
|
||||||
|
case "tabType":
|
||||||
|
switch( tabType ) {
|
||||||
|
default:
|
||||||
|
case TAB_TYPE_UNDERLINED: return TABBED_PANE_TAB_TYPE_UNDERLINED;
|
||||||
|
case TAB_TYPE_CARD: return TABBED_PANE_TAB_TYPE_CARD;
|
||||||
|
}
|
||||||
|
|
||||||
|
case "tabsPopupPolicy":
|
||||||
|
switch( tabsPopupPolicy ) {
|
||||||
|
default:
|
||||||
|
case AS_NEEDED: return TABBED_PANE_POLICY_AS_NEEDED;
|
||||||
|
case NEVER: return TABBED_PANE_POLICY_NEVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
case "scrollButtonsPolicy":
|
||||||
|
switch( scrollButtonsPolicy ) {
|
||||||
|
default:
|
||||||
|
case AS_NEEDED_SINGLE: return TABBED_PANE_POLICY_AS_NEEDED_SINGLE;
|
||||||
|
case AS_NEEDED: return TABBED_PANE_POLICY_AS_NEEDED;
|
||||||
|
case NEVER: return TABBED_PANE_POLICY_NEVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
case "scrollButtonsPlacement":
|
||||||
|
switch( scrollButtonsPlacement ) {
|
||||||
|
default:
|
||||||
|
case BOTH: return TABBED_PANE_PLACEMENT_BOTH;
|
||||||
|
case TRAILING: return TABBED_PANE_PLACEMENT_TRAILING;
|
||||||
|
}
|
||||||
|
|
||||||
|
case "tabAreaAlignment": return alignmentToString( tabAreaAlignment, TABBED_PANE_ALIGN_LEADING );
|
||||||
|
case "tabAlignment": return alignmentToString( tabAlignment, TABBED_PANE_ALIGN_CENTER );
|
||||||
|
|
||||||
|
case "tabWidthMode":
|
||||||
|
switch( tabWidthMode ) {
|
||||||
|
default:
|
||||||
|
case WIDTH_MODE_PREFERRED: return TABBED_PANE_TAB_WIDTH_MODE_PREFERRED;
|
||||||
|
case WIDTH_MODE_EQUAL: return TABBED_PANE_TAB_WIDTH_MODE_EQUAL;
|
||||||
|
case WIDTH_MODE_COMPACT: return TABBED_PANE_TAB_WIDTH_MODE_COMPACT;
|
||||||
|
}
|
||||||
|
|
||||||
|
case "tabIconPlacement":
|
||||||
|
switch( tabIconPlacement ) {
|
||||||
|
default:
|
||||||
|
case LEADING: return "leading";
|
||||||
|
case TRAILING: return "trailing";
|
||||||
|
case TOP: return "top";
|
||||||
|
case BOTTOM: return "bottom";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return FlatStylingSupport.getAnnotatedStyleableValue( this, key );
|
||||||
|
}
|
||||||
|
|
||||||
protected void setRolloverTab( int x, int y ) {
|
protected void setRolloverTab( int x, int y ) {
|
||||||
setRolloverTab( tabForCoordinate( tabPane, x, y ) );
|
setRolloverTab( tabForCoordinate( tabPane, x, y ) );
|
||||||
}
|
}
|
||||||
@@ -1022,7 +1094,7 @@ public class FlatTabbedPaneUI
|
|||||||
|
|
||||||
// paint selection indicator
|
// paint selection indicator
|
||||||
if( isSelected )
|
if( isSelected )
|
||||||
paintTabSelection( g, tabPlacement, x, y, w, h );
|
paintTabSelection( g, tabPlacement, tabIndex, x, y, w, h );
|
||||||
|
|
||||||
if( tabPane.getTabComponentAt( tabIndex ) != null )
|
if( tabPane.getTabComponentAt( tabIndex ) != null )
|
||||||
return;
|
return;
|
||||||
@@ -1211,14 +1283,19 @@ public class FlatTabbedPaneUI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void paintTabSelection( Graphics g, int tabPlacement, int x, int y, int w, int h ) {
|
protected void paintTabSelection( Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h ) {
|
||||||
g.setColor( tabPane.isEnabled()
|
g.setColor( tabPane.isEnabled()
|
||||||
? (isTabbedPaneOrChildFocused() ? underlineColor : inactiveUnderlineColor)
|
? (isTabbedPaneOrChildFocused() ? underlineColor : inactiveUnderlineColor)
|
||||||
: disabledUnderlineColor );
|
: disabledUnderlineColor );
|
||||||
|
|
||||||
// paint underline selection
|
// paint underline selection
|
||||||
boolean atBottom = (getTabType() != TAB_TYPE_CARD);
|
boolean atBottom = (getTabType() != TAB_TYPE_CARD);
|
||||||
Insets contentInsets = getContentBorderInsets( tabPlacement );
|
Insets contentInsets = atBottom
|
||||||
|
? ((!rotateTabRuns && runCount > 1 && !isScrollTabLayout() && getRunForTab( tabPane.getTabCount(), tabIndex ) > 0)
|
||||||
|
? new Insets( 0, 0, 0, 0 )
|
||||||
|
: getContentBorderInsets( tabPlacement ))
|
||||||
|
: null;
|
||||||
|
|
||||||
int tabSelectionHeight = scale( atBottom ? this.tabSelectionHeight : cardTabSelectionHeight );
|
int tabSelectionHeight = scale( atBottom ? this.tabSelectionHeight : cardTabSelectionHeight );
|
||||||
int sx, sy;
|
int sx, sy;
|
||||||
switch( tabPlacement ) {
|
switch( tabPlacement ) {
|
||||||
@@ -1377,7 +1454,7 @@ public class FlatTabbedPaneUI
|
|||||||
else
|
else
|
||||||
g.clipRect( 0, vr.y, tabPane.getWidth(), vr.height );
|
g.clipRect( 0, vr.y, tabPane.getWidth(), vr.height );
|
||||||
|
|
||||||
paintTabSelection( g, tabPlacement, tabRect.x, tabRect.y, tabRect.width, tabRect.height );
|
paintTabSelection( g, tabPlacement, selectedIndex, tabRect.x, tabRect.y, tabRect.width, tabRect.height );
|
||||||
g.setClip( oldClip );
|
g.setClip( oldClip );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1530,6 +1607,11 @@ public class FlatTabbedPaneUI
|
|||||||
super.getTabRunCount( tabPane );
|
super.getTabRunCount( tabPane );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean shouldRotateTabRuns( int tabPlacement ) {
|
||||||
|
return rotateTabRuns;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean isLastInRun( int tabIndex ) {
|
private boolean isLastInRun( int tabIndex ) {
|
||||||
int run = getRunForTab( tabPane.getTabCount(), tabIndex );
|
int run = getRunForTab( tabPane.getTabCount(), tabIndex );
|
||||||
return lastTabInRun( tabPane.getTabCount(), run ) == tabIndex;
|
return lastTabInRun( tabPane.getTabCount(), run ) == tabIndex;
|
||||||
@@ -1685,6 +1767,16 @@ public class FlatTabbedPaneUI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String alignmentToString( int value, String defaultValue ) {
|
||||||
|
switch( value ) {
|
||||||
|
case LEADING: return TABBED_PANE_ALIGN_LEADING;
|
||||||
|
case TRAILING: return TABBED_PANE_ALIGN_TRAILING;
|
||||||
|
case CENTER: return TABBED_PANE_ALIGN_CENTER;
|
||||||
|
case FILL: return TABBED_PANE_ALIGN_FILL;
|
||||||
|
default: return defaultValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected static int parseTabWidthMode( String str ) {
|
protected static int parseTabWidthMode( String str ) {
|
||||||
if( str == null )
|
if( str == null )
|
||||||
return WIDTH_MODE_PREFERRED;
|
return WIDTH_MODE_PREFERRED;
|
||||||
@@ -2497,7 +2589,7 @@ public class FlatTabbedPaneUI
|
|||||||
public void mousePressed( MouseEvent e ) {
|
public void mousePressed( MouseEvent e ) {
|
||||||
updateRollover( e );
|
updateRollover( e );
|
||||||
|
|
||||||
if( !isPressedTabClose() )
|
if( !isPressedTabClose() && SwingUtilities.isLeftMouseButton( e ) )
|
||||||
mouseDelegate.mousePressed( e );
|
mouseDelegate.mousePressed( e );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2552,7 +2644,7 @@ public class FlatTabbedPaneUI
|
|||||||
|
|
||||||
// check whether mouse hit tab close area
|
// check whether mouse hit tab close area
|
||||||
boolean hitClose = isTabClosable( tabIndex ) && getTabCloseHitArea( tabIndex ).contains( x, y );
|
boolean hitClose = isTabClosable( tabIndex ) && getTabCloseHitArea( tabIndex ).contains( x, y );
|
||||||
if( e.getID() == MouseEvent.MOUSE_PRESSED )
|
if( e.getID() == MouseEvent.MOUSE_PRESSED && SwingUtilities.isLeftMouseButton( e ) )
|
||||||
pressedTabIndex = hitClose ? tabIndex : -1;
|
pressedTabIndex = hitClose ? tabIndex : -1;
|
||||||
setRolloverTabClose( hitClose );
|
setRolloverTabClose( hitClose );
|
||||||
setPressedTabClose( hitClose && tabIndex == pressedTabIndex );
|
setPressedTabClose( hitClose && tabIndex == pressedTabIndex );
|
||||||
|
|||||||
@@ -39,7 +39,9 @@ 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.JTableHeader;
|
||||||
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.ui.FlatStylingSupport.Styleable;
|
import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable;
|
||||||
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableUI;
|
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableUI;
|
||||||
@@ -169,6 +171,22 @@ public class FlatTableHeaderUI
|
|||||||
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
@Override
|
||||||
|
public Object getStyleableValue( JComponent c, String key ) {
|
||||||
|
if( key.equals( "sortIconPosition" ) ) {
|
||||||
|
switch( sortIconPosition ) {
|
||||||
|
default:
|
||||||
|
case SwingConstants.RIGHT: return "right";
|
||||||
|
case SwingConstants.LEFT: return "left";
|
||||||
|
case SwingConstants.TOP: return "top";
|
||||||
|
case SwingConstants.BOTTOM: return "bottom";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return FlatStylingSupport.getAnnotatedStyleableValue( this, key );
|
||||||
|
}
|
||||||
|
|
||||||
private static int parseSortIconPosition( String str ) {
|
private static int parseSortIconPosition( String str ) {
|
||||||
if( str == null )
|
if( str == null )
|
||||||
str = "";
|
str = "";
|
||||||
@@ -195,6 +213,8 @@ public class FlatTableHeaderUI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void paint( Graphics g, JComponent c ) {
|
public void paint( Graphics g, JComponent c ) {
|
||||||
|
fixDraggedAndResizingColumns( header );
|
||||||
|
|
||||||
TableColumnModel columnModel = header.getColumnModel();
|
TableColumnModel columnModel = header.getColumnModel();
|
||||||
if( columnModel.getColumnCount() <= 0 )
|
if( columnModel.getColumnCount() <= 0 )
|
||||||
return;
|
return;
|
||||||
@@ -269,6 +289,32 @@ public class FlatTableHeaderUI
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void fixDraggedAndResizingColumns( JTableHeader header ) {
|
||||||
|
if( header == null )
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Dragged column may be outdated in the case that the table structure
|
||||||
|
// was changed from a table header popup menu action. In this case
|
||||||
|
// the paint methods in BasicTableHeaderUI and BasicTableUI would throw exceptions.
|
||||||
|
TableColumn draggedColumn = header.getDraggedColumn();
|
||||||
|
if( draggedColumn != null && !isValidColumn( header.getColumnModel(), draggedColumn ) )
|
||||||
|
header.setDraggedColumn( null );
|
||||||
|
|
||||||
|
// also clear outdated resizing column (although this seems not cause exceptions)
|
||||||
|
TableColumn resizingColumn = header.getResizingColumn();
|
||||||
|
if( resizingColumn != null && !isValidColumn( header.getColumnModel(), resizingColumn ) )
|
||||||
|
header.setResizingColumn( null );
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isValidColumn( TableColumnModel cm, TableColumn column ) {
|
||||||
|
int count = cm.getColumnCount();
|
||||||
|
for( int i = 0; i < count; i++ ) {
|
||||||
|
if( cm.getColumn( i ) == column )
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
//---- class FlatTableCellHeaderRenderer ----------------------------------
|
//---- class FlatTableCellHeaderRenderer ----------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ import com.formdev.flatlaf.util.UIScale;
|
|||||||
* @uiDefault Table.intercellSpacing Dimension
|
* @uiDefault Table.intercellSpacing Dimension
|
||||||
* @uiDefault Table.selectionInactiveBackground Color
|
* @uiDefault Table.selectionInactiveBackground Color
|
||||||
* @uiDefault Table.selectionInactiveForeground Color
|
* @uiDefault Table.selectionInactiveForeground Color
|
||||||
|
* @uiDefault Table.paintOutsideAlternateRows boolean
|
||||||
*
|
*
|
||||||
* <!-- FlatTableCellBorder -->
|
* <!-- FlatTableCellBorder -->
|
||||||
*
|
*
|
||||||
@@ -95,7 +96,7 @@ import com.formdev.flatlaf.util.UIScale;
|
|||||||
*/
|
*/
|
||||||
public class FlatTableUI
|
public class FlatTableUI
|
||||||
extends BasicTableUI
|
extends BasicTableUI
|
||||||
implements StyleableUI
|
implements StyleableUI, FlatViewportUI.ViewportPainter
|
||||||
{
|
{
|
||||||
protected boolean showHorizontalLines;
|
protected boolean showHorizontalLines;
|
||||||
protected boolean showVerticalLines;
|
protected boolean showVerticalLines;
|
||||||
@@ -285,6 +286,12 @@ public class FlatTableUI
|
|||||||
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
@Override
|
||||||
|
public Object getStyleableValue( JComponent c, String key ) {
|
||||||
|
return FlatStylingSupport.getAnnotatedStyleableValue( this, key );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Toggle selection colors from focused to inactive and vice versa.
|
* Toggle selection colors from focused to inactive and vice versa.
|
||||||
*
|
*
|
||||||
@@ -313,6 +320,8 @@ public class FlatTableUI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void paint( Graphics g, JComponent c ) {
|
public void paint( Graphics g, JComponent c ) {
|
||||||
|
FlatTableHeaderUI.fixDraggedAndResizingColumns( table.getTableHeader() );
|
||||||
|
|
||||||
boolean horizontalLines = table.getShowHorizontalLines();
|
boolean horizontalLines = table.getShowHorizontalLines();
|
||||||
boolean verticalLines = table.getShowVerticalLines();
|
boolean verticalLines = table.getShowVerticalLines();
|
||||||
if( horizontalLines || verticalLines ) {
|
if( horizontalLines || verticalLines ) {
|
||||||
@@ -421,4 +430,38 @@ public class FlatTableUI
|
|||||||
? (viewport != rowHeader)
|
? (viewport != rowHeader)
|
||||||
: (viewport == rowHeader || rowHeader == null);
|
: (viewport == rowHeader || rowHeader == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.3 */
|
||||||
|
@Override
|
||||||
|
public void paintViewport( Graphics g, JComponent c, JViewport viewport ) {
|
||||||
|
int viewportWidth = viewport.getWidth();
|
||||||
|
int viewportHeight = viewport.getHeight();
|
||||||
|
|
||||||
|
// fill viewport background in same color as table background
|
||||||
|
if( viewport.isOpaque() ) {
|
||||||
|
g.setColor( table.getBackground() );
|
||||||
|
g.fillRect( 0, 0, viewportWidth, viewportHeight );
|
||||||
|
}
|
||||||
|
|
||||||
|
// paint alternating empty rows
|
||||||
|
boolean paintOutside = UIManager.getBoolean( "Table.paintOutsideAlternateRows" );
|
||||||
|
Color alternateColor;
|
||||||
|
if( paintOutside && (alternateColor = UIManager.getColor( "Table.alternateRowColor" )) != null ) {
|
||||||
|
g.setColor( alternateColor );
|
||||||
|
|
||||||
|
int rowCount = table.getRowCount();
|
||||||
|
|
||||||
|
// paint alternating empty rows below the table
|
||||||
|
int tableHeight = table.getHeight();
|
||||||
|
if( tableHeight < viewportHeight ) {
|
||||||
|
int tableWidth = table.getWidth();
|
||||||
|
int rowHeight = table.getRowHeight();
|
||||||
|
|
||||||
|
for( int y = tableHeight, row = rowCount; y < viewportHeight; y += rowHeight, row++ ) {
|
||||||
|
if( row % 2 != 0 )
|
||||||
|
g.fillRect( 0, y, tableWidth, rowHeight );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,6 +86,13 @@ public class FlatTextAreaUI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void installUI( JComponent c ) {
|
public void installUI( JComponent c ) {
|
||||||
|
if( FlatUIUtils.needsLightAWTPeer( c ) )
|
||||||
|
FlatUIUtils.runWithLightAWTPeerUIDefaults( () -> installUIImpl( c ) );
|
||||||
|
else
|
||||||
|
installUIImpl( c );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void installUIImpl( JComponent c ) {
|
||||||
super.installUI( c );
|
super.installUI( c );
|
||||||
|
|
||||||
installStyle();
|
installStyle();
|
||||||
@@ -183,6 +190,12 @@ public class FlatTextAreaUI
|
|||||||
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
@Override
|
||||||
|
public Object getStyleableValue( JComponent c, String key ) {
|
||||||
|
return FlatStylingSupport.getAnnotatedStyleableValue( this, key );
|
||||||
|
}
|
||||||
|
|
||||||
private void updateBackground() {
|
private void updateBackground() {
|
||||||
FlatTextFieldUI.updateBackground( getComponent(), background,
|
FlatTextFieldUI.updateBackground( getComponent(), background,
|
||||||
disabledBackground, inactiveBackground,
|
disabledBackground, inactiveBackground,
|
||||||
|
|||||||
@@ -128,6 +128,13 @@ public class FlatTextFieldUI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void installUI( JComponent c ) {
|
public void installUI( JComponent c ) {
|
||||||
|
if( FlatUIUtils.needsLightAWTPeer( c ) )
|
||||||
|
FlatUIUtils.runWithLightAWTPeerUIDefaults( () -> installUIImpl( c ) );
|
||||||
|
else
|
||||||
|
installUIImpl( c );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void installUIImpl( JComponent c ) {
|
||||||
super.installUI( c );
|
super.installUI( c );
|
||||||
|
|
||||||
leadingIcon = clientProperty( c, TEXT_FIELD_LEADING_ICON, null, Icon.class );
|
leadingIcon = clientProperty( c, TEXT_FIELD_LEADING_ICON, null, Icon.class );
|
||||||
@@ -354,6 +361,12 @@ public class FlatTextFieldUI
|
|||||||
return FlatStylingSupport.getAnnotatedStyleableInfos( this, getComponent().getBorder() );
|
return FlatStylingSupport.getAnnotatedStyleableInfos( this, getComponent().getBorder() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
@Override
|
||||||
|
public Object getStyleableValue( JComponent c, String key ) {
|
||||||
|
return FlatStylingSupport.getAnnotatedStyleableValue( this, getComponent().getBorder(), key );
|
||||||
|
}
|
||||||
|
|
||||||
private void updateBackground() {
|
private void updateBackground() {
|
||||||
updateBackground( getComponent(), background,
|
updateBackground( getComponent(), background,
|
||||||
disabledBackground, inactiveBackground,
|
disabledBackground, inactiveBackground,
|
||||||
|
|||||||
@@ -191,6 +191,12 @@ public class FlatTextPaneUI
|
|||||||
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
@Override
|
||||||
|
public Object getStyleableValue( JComponent c, String key ) {
|
||||||
|
return FlatStylingSupport.getAnnotatedStyleableValue( this, key );
|
||||||
|
}
|
||||||
|
|
||||||
private void updateBackground() {
|
private void updateBackground() {
|
||||||
FlatTextFieldUI.updateBackground( getComponent(), background,
|
FlatTextFieldUI.updateBackground( getComponent(), background,
|
||||||
disabledBackground, inactiveBackground,
|
disabledBackground, inactiveBackground,
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ import java.awt.Container;
|
|||||||
import java.awt.Dialog;
|
import java.awt.Dialog;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.EventQueue;
|
import java.awt.EventQueue;
|
||||||
|
import java.awt.Font;
|
||||||
|
import java.awt.FontMetrics;
|
||||||
import java.awt.Frame;
|
import java.awt.Frame;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.GraphicsConfiguration;
|
import java.awt.GraphicsConfiguration;
|
||||||
@@ -31,6 +33,7 @@ import java.awt.Image;
|
|||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
|
import java.awt.Toolkit;
|
||||||
import java.awt.Window;
|
import java.awt.Window;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.awt.event.ComponentEvent;
|
import java.awt.event.ComponentEvent;
|
||||||
@@ -50,13 +53,14 @@ import javax.accessibility.AccessibleContext;
|
|||||||
import javax.swing.BorderFactory;
|
import javax.swing.BorderFactory;
|
||||||
import javax.swing.Box;
|
import javax.swing.Box;
|
||||||
import javax.swing.BoxLayout;
|
import javax.swing.BoxLayout;
|
||||||
|
import javax.swing.Icon;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
|
import javax.swing.JDialog;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JMenuBar;
|
import javax.swing.JMenuBar;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JRootPane;
|
import javax.swing.JRootPane;
|
||||||
import javax.swing.SwingConstants;
|
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.border.AbstractBorder;
|
import javax.swing.border.AbstractBorder;
|
||||||
@@ -70,6 +74,7 @@ import com.formdev.flatlaf.util.UIScale;
|
|||||||
/**
|
/**
|
||||||
* Provides the Flat LaF title bar.
|
* Provides the Flat LaF title bar.
|
||||||
*
|
*
|
||||||
|
* @uiDefault TitlePane.font Font
|
||||||
* @uiDefault TitlePane.background Color
|
* @uiDefault TitlePane.background Color
|
||||||
* @uiDefault TitlePane.inactiveBackground Color
|
* @uiDefault TitlePane.inactiveBackground Color
|
||||||
* @uiDefault TitlePane.foreground Color
|
* @uiDefault TitlePane.foreground Color
|
||||||
@@ -78,15 +83,20 @@ import com.formdev.flatlaf.util.UIScale;
|
|||||||
* @uiDefault TitlePane.borderColor Color optional
|
* @uiDefault TitlePane.borderColor Color optional
|
||||||
* @uiDefault TitlePane.unifiedBackground boolean
|
* @uiDefault TitlePane.unifiedBackground boolean
|
||||||
* @uiDefault TitlePane.showIcon boolean
|
* @uiDefault TitlePane.showIcon boolean
|
||||||
|
* @uiDefault TitlePane.showIconInDialogs boolean
|
||||||
* @uiDefault TitlePane.noIconLeftGap int
|
* @uiDefault TitlePane.noIconLeftGap int
|
||||||
* @uiDefault TitlePane.iconSize Dimension
|
* @uiDefault TitlePane.iconSize Dimension
|
||||||
* @uiDefault TitlePane.iconMargins Insets
|
* @uiDefault TitlePane.iconMargins Insets
|
||||||
* @uiDefault TitlePane.titleMargins Insets
|
* @uiDefault TitlePane.titleMargins Insets
|
||||||
* @uiDefault TitlePane.menuBarEmbedded boolean
|
* @uiDefault TitlePane.menuBarEmbedded boolean
|
||||||
|
* @uiDefault TitlePane.titleMinimumWidth int
|
||||||
|
* @uiDefault TitlePane.buttonMinimumWidth int
|
||||||
* @uiDefault TitlePane.buttonMaximizedHeight int
|
* @uiDefault TitlePane.buttonMaximizedHeight int
|
||||||
* @uiDefault TitlePane.centerTitle boolean
|
* @uiDefault TitlePane.centerTitle boolean
|
||||||
* @uiDefault TitlePane.centerTitleIfMenuBarEmbedded boolean
|
* @uiDefault TitlePane.centerTitleIfMenuBarEmbedded boolean
|
||||||
|
* @uiDefault TitlePane.showIconBesideTitle boolean
|
||||||
* @uiDefault TitlePane.menuBarTitleGap int
|
* @uiDefault TitlePane.menuBarTitleGap int
|
||||||
|
* @uiDefault TitlePane.menuBarResizeHeight int
|
||||||
* @uiDefault TitlePane.closeIcon Icon
|
* @uiDefault TitlePane.closeIcon Icon
|
||||||
* @uiDefault TitlePane.iconifyIcon Icon
|
* @uiDefault TitlePane.iconifyIcon Icon
|
||||||
* @uiDefault TitlePane.maximizeIcon Icon
|
* @uiDefault TitlePane.maximizeIcon Icon
|
||||||
@@ -97,6 +107,7 @@ import com.formdev.flatlaf.util.UIScale;
|
|||||||
public class FlatTitlePane
|
public class FlatTitlePane
|
||||||
extends JComponent
|
extends JComponent
|
||||||
{
|
{
|
||||||
|
/** @since 2.5 */ protected final Font titleFont = UIManager.getFont( "TitlePane.font" );
|
||||||
protected final Color activeBackground = UIManager.getColor( "TitlePane.background" );
|
protected final Color activeBackground = UIManager.getColor( "TitlePane.background" );
|
||||||
protected final Color inactiveBackground = UIManager.getColor( "TitlePane.inactiveBackground" );
|
protected final Color inactiveBackground = UIManager.getColor( "TitlePane.inactiveBackground" );
|
||||||
protected final Color activeForeground = UIManager.getColor( "TitlePane.foreground" );
|
protected final Color activeForeground = UIManager.getColor( "TitlePane.foreground" );
|
||||||
@@ -105,12 +116,18 @@ public class FlatTitlePane
|
|||||||
protected final Color borderColor = UIManager.getColor( "TitlePane.borderColor" );
|
protected final Color borderColor = UIManager.getColor( "TitlePane.borderColor" );
|
||||||
|
|
||||||
/** @since 2 */ protected final boolean showIcon = FlatUIUtils.getUIBoolean( "TitlePane.showIcon", true );
|
/** @since 2 */ protected final boolean showIcon = FlatUIUtils.getUIBoolean( "TitlePane.showIcon", true );
|
||||||
|
/** @since 2.5 */ protected final boolean showIconInDialogs = FlatUIUtils.getUIBoolean( "TitlePane.showIconInDialogs", true );
|
||||||
/** @since 2 */ protected final int noIconLeftGap = FlatUIUtils.getUIInt( "TitlePane.noIconLeftGap", 8 );
|
/** @since 2 */ protected final int noIconLeftGap = FlatUIUtils.getUIInt( "TitlePane.noIconLeftGap", 8 );
|
||||||
protected final Dimension iconSize = UIManager.getDimension( "TitlePane.iconSize" );
|
protected final Dimension iconSize = UIManager.getDimension( "TitlePane.iconSize" );
|
||||||
|
/** @since 2.4 */ protected final int titleMinimumWidth = FlatUIUtils.getUIInt( "TitlePane.titleMinimumWidth", 60 );
|
||||||
|
/** @since 2.4 */ protected final int buttonMinimumWidth = FlatUIUtils.getUIInt( "TitlePane.buttonMinimumWidth", 30 );
|
||||||
protected final int buttonMaximizedHeight = UIManager.getInt( "TitlePane.buttonMaximizedHeight" );
|
protected final int buttonMaximizedHeight = UIManager.getInt( "TitlePane.buttonMaximizedHeight" );
|
||||||
protected final boolean centerTitle = UIManager.getBoolean( "TitlePane.centerTitle" );
|
protected final boolean centerTitle = UIManager.getBoolean( "TitlePane.centerTitle" );
|
||||||
protected final boolean centerTitleIfMenuBarEmbedded = FlatUIUtils.getUIBoolean( "TitlePane.centerTitleIfMenuBarEmbedded", true );
|
protected final boolean centerTitleIfMenuBarEmbedded = FlatUIUtils.getUIBoolean( "TitlePane.centerTitleIfMenuBarEmbedded", true );
|
||||||
protected final int menuBarTitleGap = FlatUIUtils.getUIInt( "TitlePane.menuBarTitleGap", 20 );
|
/** @since 2.4 */ protected final boolean showIconBesideTitle = UIManager.getBoolean( "TitlePane.showIconBesideTitle" );
|
||||||
|
protected final int menuBarTitleGap = FlatUIUtils.getUIInt( "TitlePane.menuBarTitleGap", 40 );
|
||||||
|
/** @since 2.4 */ protected final int menuBarTitleMinimumGap = FlatUIUtils.getUIInt( "TitlePane.menuBarTitleMinimumGap", 12 );
|
||||||
|
/** @since 2.4 */ protected final int menuBarResizeHeight = FlatUIUtils.getUIInt( "TitlePane.menuBarResizeHeight", 4 );
|
||||||
|
|
||||||
protected final JRootPane rootPane;
|
protected final JRootPane rootPane;
|
||||||
|
|
||||||
@@ -142,6 +159,8 @@ public class FlatTitlePane
|
|||||||
|
|
||||||
// necessary for closing window with double-click on icon
|
// necessary for closing window with double-click on icon
|
||||||
iconLabel.addMouseListener( handler );
|
iconLabel.addMouseListener( handler );
|
||||||
|
|
||||||
|
applyComponentOrientation( rootPane.getComponentOrientation() );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected FlatTitlePaneBorder createTitlePaneBorder() {
|
protected FlatTitlePaneBorder createTitlePaneBorder() {
|
||||||
@@ -163,7 +182,6 @@ public class FlatTitlePane
|
|||||||
};
|
};
|
||||||
iconLabel.setBorder( new FlatEmptyBorder( UIManager.getInsets( "TitlePane.iconMargins" ) ) );
|
iconLabel.setBorder( new FlatEmptyBorder( UIManager.getInsets( "TitlePane.iconMargins" ) ) );
|
||||||
titleLabel.setBorder( new FlatEmptyBorder( UIManager.getInsets( "TitlePane.titleMargins" ) ) );
|
titleLabel.setBorder( new FlatEmptyBorder( UIManager.getInsets( "TitlePane.titleMargins" ) ) );
|
||||||
titleLabel.setHorizontalAlignment( SwingConstants.CENTER );
|
|
||||||
|
|
||||||
leftPanel.setLayout( new BoxLayout( leftPanel, BoxLayout.LINE_AXIS ) );
|
leftPanel.setLayout( new BoxLayout( leftPanel, BoxLayout.LINE_AXIS ) );
|
||||||
leftPanel.setOpaque( false );
|
leftPanel.setOpaque( false );
|
||||||
@@ -183,18 +201,52 @@ public class FlatTitlePane
|
|||||||
setLayout( new BorderLayout() {
|
setLayout( new BorderLayout() {
|
||||||
@Override
|
@Override
|
||||||
public void layoutContainer( Container target ) {
|
public void layoutContainer( Container target ) {
|
||||||
super.layoutContainer( target );
|
// compute available bounds
|
||||||
|
|
||||||
// make left panel (with embedded menu bar) smaller if horizontal space is rare
|
|
||||||
// to avoid that embedded menu bar overlaps button bar
|
|
||||||
Insets insets = target.getInsets();
|
Insets insets = target.getInsets();
|
||||||
int width = target.getWidth() - insets.left - insets.right;
|
int x = insets.left;
|
||||||
if( leftPanel.getWidth() + buttonPanel.getWidth() > width ) {
|
int y = insets.top;
|
||||||
int oldWidth = leftPanel.getWidth();
|
int w = target.getWidth() - insets.left - insets.right;
|
||||||
int newWidth = Math.max( width - buttonPanel.getWidth(), 0 );
|
int h = target.getHeight() - insets.top - insets.bottom;
|
||||||
leftPanel.setSize( newWidth, leftPanel.getHeight() );
|
|
||||||
if( !getComponentOrientation().isLeftToRight() )
|
// compute widths
|
||||||
leftPanel.setLocation( leftPanel.getX() + (oldWidth - newWidth), leftPanel.getY() );
|
int leftWidth = leftPanel.getPreferredSize().width;
|
||||||
|
int buttonsWidth = buttonPanel.getPreferredSize().width;
|
||||||
|
int titleWidth = w - leftWidth - buttonsWidth;
|
||||||
|
int minTitleWidth = UIScale.scale( titleMinimumWidth );
|
||||||
|
|
||||||
|
// increase minimum width if icon is show besides the title
|
||||||
|
Icon icon = titleLabel.getIcon();
|
||||||
|
if( icon != null ) {
|
||||||
|
Insets iconInsets = iconLabel.getInsets();
|
||||||
|
int iconTextGap = titleLabel.getComponentOrientation().isLeftToRight() ? iconInsets.right : iconInsets.left;
|
||||||
|
minTitleWidth += icon.getIconWidth() + iconTextGap;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if title is too small, reduce width of buttons
|
||||||
|
if( titleWidth < minTitleWidth ) {
|
||||||
|
buttonsWidth = Math.max( buttonsWidth - (minTitleWidth - titleWidth), buttonPanel.getMinimumSize().width );
|
||||||
|
titleWidth = w - leftWidth - buttonsWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if title is still too small, reduce width of left panel (icon and embedded menu bar)
|
||||||
|
if( titleWidth < minTitleWidth ) {
|
||||||
|
int minLeftWidth = iconLabel.isVisible()
|
||||||
|
? iconLabel.getWidth() - iconLabel.getInsets().right
|
||||||
|
: UIScale.scale( noIconLeftGap );
|
||||||
|
leftWidth = Math.max( leftWidth - (minTitleWidth - titleWidth), minLeftWidth );
|
||||||
|
titleWidth = w - leftWidth - buttonsWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( target.getComponentOrientation().isLeftToRight() ) {
|
||||||
|
// left-to-right
|
||||||
|
leftPanel.setBounds( x, y, leftWidth, h );
|
||||||
|
titleLabel.setBounds( x + leftWidth, y, titleWidth, h );
|
||||||
|
buttonPanel.setBounds( x + leftWidth + titleWidth, y, buttonsWidth, h );
|
||||||
|
} else {
|
||||||
|
// right-to-left
|
||||||
|
buttonPanel.setBounds( x, y, buttonsWidth, h );
|
||||||
|
titleLabel.setBounds( x + buttonsWidth, y, titleWidth, h );
|
||||||
|
leftPanel.setBounds( x + buttonsWidth + titleWidth, y, leftWidth, h );
|
||||||
}
|
}
|
||||||
|
|
||||||
// If menu bar is embedded and contains a horizontal glue component,
|
// If menu bar is embedded and contains a horizontal glue component,
|
||||||
@@ -233,10 +285,7 @@ public class FlatTitlePane
|
|||||||
@Override
|
@Override
|
||||||
public Dimension getPreferredSize() {
|
public Dimension getPreferredSize() {
|
||||||
Dimension size = super.getPreferredSize();
|
Dimension size = super.getPreferredSize();
|
||||||
if( buttonMaximizedHeight > 0 &&
|
if( buttonMaximizedHeight > 0 && isWindowMaximized() && !hasVisibleEmbeddedMenuBar( rootPane.getJMenuBar() ) ) {
|
||||||
window instanceof Frame &&
|
|
||||||
(((Frame)window).getExtendedState() & Frame.MAXIMIZED_BOTH) != 0 )
|
|
||||||
{
|
|
||||||
// make title pane height smaller when frame is maximized
|
// make title pane height smaller when frame is maximized
|
||||||
size = new Dimension( size.width, Math.min( size.height, UIScale.scale( buttonMaximizedHeight ) ) );
|
size = new Dimension( size.width, Math.min( size.height, UIScale.scale( buttonMaximizedHeight ) ) );
|
||||||
}
|
}
|
||||||
@@ -259,7 +308,13 @@ public class FlatTitlePane
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected JButton createButton( String iconKey, String accessibleName, ActionListener action ) {
|
protected JButton createButton( String iconKey, String accessibleName, ActionListener action ) {
|
||||||
JButton button = new JButton( UIManager.getIcon( iconKey ) );
|
JButton button = new JButton( UIManager.getIcon( iconKey ) ) {
|
||||||
|
@Override
|
||||||
|
public Dimension getMinimumSize() {
|
||||||
|
// allow the button to shrink if space is rare
|
||||||
|
return new Dimension( UIScale.scale( buttonMinimumWidth ), super.getMinimumSize().height );
|
||||||
|
}
|
||||||
|
};
|
||||||
button.setFocusable( false );
|
button.setFocusable( false );
|
||||||
button.setContentAreaFilled( false );
|
button.setContentAreaFilled( false );
|
||||||
button.setBorder( BorderFactory.createEmptyBorder() );
|
button.setBorder( BorderFactory.createEmptyBorder() );
|
||||||
@@ -309,6 +364,7 @@ public class FlatTitlePane
|
|||||||
restoreButton.setVisible( resizable && maximized );
|
restoreButton.setVisible( resizable && maximized );
|
||||||
|
|
||||||
if( maximized &&
|
if( maximized &&
|
||||||
|
!(SystemInfo.isLinux && FlatNativeLinuxLibrary.isWMUtilsSupported( window )) &&
|
||||||
rootPane.getClientProperty( "_flatlaf.maximizedBoundsUpToDate" ) == null )
|
rootPane.getClientProperty( "_flatlaf.maximizedBoundsUpToDate" ) == null )
|
||||||
{
|
{
|
||||||
rootPane.putClientProperty( "_flatlaf.maximizedBoundsUpToDate", null );
|
rootPane.putClientProperty( "_flatlaf.maximizedBoundsUpToDate", null );
|
||||||
@@ -339,9 +395,13 @@ public class FlatTitlePane
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void updateIcon() {
|
protected void updateIcon() {
|
||||||
|
boolean defaultShowIcon = showIcon;
|
||||||
|
if( !showIconInDialogs && rootPane.getParent() instanceof JDialog )
|
||||||
|
defaultShowIcon = false;
|
||||||
|
|
||||||
// get window images
|
// get window images
|
||||||
List<Image> images = null;
|
List<Image> images = null;
|
||||||
if( clientPropertyBoolean( rootPane, TITLE_BAR_SHOW_ICON, showIcon ) ) {
|
if( clientPropertyBoolean( rootPane, TITLE_BAR_SHOW_ICON, defaultShowIcon ) ) {
|
||||||
images = window.getIconImages();
|
images = window.getIconImages();
|
||||||
if( images.isEmpty() ) {
|
if( images.isEmpty() ) {
|
||||||
// search in owners
|
// search in owners
|
||||||
@@ -356,11 +416,12 @@ public class FlatTitlePane
|
|||||||
boolean hasIcon = (images != null && !images.isEmpty());
|
boolean hasIcon = (images != null && !images.isEmpty());
|
||||||
|
|
||||||
// set icon
|
// set icon
|
||||||
iconLabel.setIcon( hasIcon ? new FlatTitlePaneIcon( images, iconSize ) : null );
|
iconLabel.setIcon( hasIcon && !showIconBesideTitle ? new FlatTitlePaneIcon( images, iconSize ) : null );
|
||||||
|
titleLabel.setIcon( hasIcon && showIconBesideTitle ? new FlatTitlePaneIcon( images, iconSize ) : null );
|
||||||
|
|
||||||
// show/hide icon
|
// show/hide icon
|
||||||
iconLabel.setVisible( hasIcon );
|
iconLabel.setVisible( hasIcon && !showIconBesideTitle );
|
||||||
leftPanel.setBorder( hasIcon ? null : FlatUIUtils.nonUIResource( new FlatEmptyBorder( 0, noIconLeftGap, 0, 0 ) ) );
|
leftPanel.setBorder( hasIcon && !showIconBesideTitle ? null : FlatUIUtils.nonUIResource( new FlatEmptyBorder( 0, noIconLeftGap, 0, 0 ) ) );
|
||||||
|
|
||||||
updateNativeTitleBarHeightAndHitTestSpotsLater();
|
updateNativeTitleBarHeightAndHitTestSpotsLater();
|
||||||
}
|
}
|
||||||
@@ -567,6 +628,11 @@ debug*/
|
|||||||
frame.setExtendedState( frame.getExtendedState() | Frame.ICONIFIED );
|
frame.setExtendedState( frame.getExtendedState() | Frame.ICONIFIED );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.4 */
|
||||||
|
protected boolean isWindowMaximized() {
|
||||||
|
return window instanceof Frame && (((Frame)window).getExtendedState() & Frame.MAXIMIZED_BOTH) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maximizes the window.
|
* Maximizes the window.
|
||||||
*/
|
*/
|
||||||
@@ -683,6 +749,17 @@ debug*/
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void maximizeOrRestore() {
|
||||||
|
if( !(window instanceof Frame) || !((Frame)window).isResizable() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
Frame frame = (Frame) window;
|
||||||
|
if( (frame.getExtendedState() & Frame.MAXIMIZED_BOTH) != 0 )
|
||||||
|
restore();
|
||||||
|
else
|
||||||
|
maximize();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes the window.
|
* Closes the window.
|
||||||
*/
|
*/
|
||||||
@@ -729,7 +806,7 @@ debug*/
|
|||||||
List<Rectangle> hitTestSpots = new ArrayList<>();
|
List<Rectangle> hitTestSpots = new ArrayList<>();
|
||||||
Rectangle appIconBounds = null;
|
Rectangle appIconBounds = null;
|
||||||
|
|
||||||
if( iconLabel.isVisible() ) {
|
if( !showIconBesideTitle && iconLabel.isVisible() ) {
|
||||||
// compute real icon size (without insets; 1px larger for easier hitting)
|
// compute real icon size (without insets; 1px larger 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();
|
||||||
@@ -741,9 +818,7 @@ debug*/
|
|||||||
|
|
||||||
// if frame is maximized, increase icon bounds to upper-left corner
|
// if frame is maximized, increase icon bounds to upper-left corner
|
||||||
// of window to allow closing window via double-click in upper-left corner
|
// of window to allow closing window via double-click in upper-left corner
|
||||||
if( window instanceof Frame &&
|
if( isWindowMaximized() ) {
|
||||||
(((Frame)window).getExtendedState() & Frame.MAXIMIZED_BOTH) != 0 )
|
|
||||||
{
|
|
||||||
iconBounds.height += iconBounds.y;
|
iconBounds.height += iconBounds.y;
|
||||||
iconBounds.y = 0;
|
iconBounds.y = 0;
|
||||||
|
|
||||||
@@ -758,6 +833,38 @@ debug*/
|
|||||||
hitTestSpots.add( iconBounds );
|
hitTestSpots.add( iconBounds );
|
||||||
else
|
else
|
||||||
appIconBounds = iconBounds;
|
appIconBounds = iconBounds;
|
||||||
|
} else if( showIconBesideTitle && titleLabel.getIcon() != null && titleLabel.getUI() instanceof FlatTitleLabelUI ) {
|
||||||
|
FlatTitleLabelUI ui = (FlatTitleLabelUI) titleLabel.getUI();
|
||||||
|
|
||||||
|
// compute real icon bounds
|
||||||
|
Insets insets = titleLabel.getInsets();
|
||||||
|
Rectangle viewR = new Rectangle( insets.left, insets.top,
|
||||||
|
titleLabel.getWidth() - insets.left - insets.right,
|
||||||
|
titleLabel.getHeight() - insets.top - insets.bottom );
|
||||||
|
Rectangle iconR = new Rectangle();
|
||||||
|
Rectangle textR = new Rectangle();
|
||||||
|
ui.layoutCL( titleLabel, titleLabel.getFontMetrics( titleLabel.getFont() ),
|
||||||
|
titleLabel.getText(), titleLabel.getIcon(),
|
||||||
|
viewR, iconR, textR );
|
||||||
|
|
||||||
|
// Windows shows the window system menu only in the upper-left corner
|
||||||
|
if( iconR.x == 0 ) {
|
||||||
|
// convert icon location to window coordinates
|
||||||
|
Point location = SwingUtilities.convertPoint( titleLabel, 0, 0, window );
|
||||||
|
iconR.x += location.x;
|
||||||
|
iconR.y += location.y;
|
||||||
|
|
||||||
|
// make icon bounds 1px larger for easier hitting
|
||||||
|
iconR.x -= 1;
|
||||||
|
iconR.y -= 1;
|
||||||
|
iconR.width += 2;
|
||||||
|
iconR.height += 2;
|
||||||
|
|
||||||
|
if( hasJBRCustomDecoration() )
|
||||||
|
hitTestSpots.add( iconR );
|
||||||
|
else
|
||||||
|
appIconBounds = iconR;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle r = getNativeHitTestSpot( buttonPanel );
|
Rectangle r = getNativeHitTestSpot( buttonPanel );
|
||||||
@@ -768,26 +875,41 @@ debug*/
|
|||||||
if( hasVisibleEmbeddedMenuBar( menuBar ) ) {
|
if( hasVisibleEmbeddedMenuBar( menuBar ) ) {
|
||||||
r = getNativeHitTestSpot( menuBar );
|
r = getNativeHitTestSpot( menuBar );
|
||||||
if( r != null ) {
|
if( r != null ) {
|
||||||
Component horizontalGlue = findHorizontalGlue( menuBar );
|
// if frame is resizable and not maximized, make menu bar hit test spot smaller at top
|
||||||
if( horizontalGlue != null ) {
|
// to have a small area above the menu bar to resize the window
|
||||||
// If menu bar is embedded and contains a horizontal glue component,
|
if( window instanceof Frame && ((Frame)window).isResizable() && !isWindowMaximized() ) {
|
||||||
// then split the hit test spot into two spots so that
|
// limit to 8, because Windows does not use a larger height
|
||||||
// the glue component area can be used to move the window.
|
int resizeHeight = UIScale.scale( Math.min( menuBarResizeHeight, 8 ) );
|
||||||
|
r.y += resizeHeight;
|
||||||
|
r.height -= resizeHeight;
|
||||||
|
}
|
||||||
|
|
||||||
Point glueLocation = SwingUtilities.convertPoint( horizontalGlue, 0, 0, window );
|
int count = menuBar.getComponentCount();
|
||||||
int x2 = glueLocation.x + horizontalGlue.getWidth();
|
for( int i = count - 1; i >= 0; i-- ) {
|
||||||
Rectangle r2;
|
Component c = menuBar.getComponent( i );
|
||||||
if( getComponentOrientation().isLeftToRight() ) {
|
if( c instanceof Box.Filler ||
|
||||||
r2 = new Rectangle( x2, r.y, (r.x + r.width) - x2, r.height );
|
(c instanceof JComponent && clientPropertyBoolean( (JComponent) c, COMPONENT_TITLE_BAR_CAPTION, false ) ) )
|
||||||
|
{
|
||||||
|
// If menu bar is embedded and contains a horizontal glue or caption component,
|
||||||
|
// then split the hit test spot so that
|
||||||
|
// the glue/caption component area can be used to move the window.
|
||||||
|
|
||||||
r.width = glueLocation.x - r.x;
|
Point glueLocation = SwingUtilities.convertPoint( c, 0, 0, window );
|
||||||
} else {
|
int x2 = glueLocation.x + c.getWidth();
|
||||||
r2 = new Rectangle( r.x, r.y, glueLocation.x - r.x, r.height );
|
Rectangle r2;
|
||||||
|
if( getComponentOrientation().isLeftToRight() ) {
|
||||||
|
r2 = new Rectangle( x2, r.y, (r.x + r.width) - x2, r.height );
|
||||||
|
|
||||||
r.width = (r.x + r.width) - x2;
|
r.width = glueLocation.x - r.x;
|
||||||
r.x = x2;
|
} else {
|
||||||
|
r2 = new Rectangle( r.x, r.y, glueLocation.x - r.x, r.height );
|
||||||
|
|
||||||
|
r.width = (r.x + r.width) - x2;
|
||||||
|
r.x = x2;
|
||||||
|
}
|
||||||
|
if( r2.width > 0 )
|
||||||
|
hitTestSpots.add( r2 );
|
||||||
}
|
}
|
||||||
hitTestSpots.add( r2 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hitTestSpots.add( r );
|
hitTestSpots.add( r );
|
||||||
@@ -854,7 +976,7 @@ debug*/
|
|||||||
} else if( borderColor != null && (rootPane.getJMenuBar() == null || !rootPane.getJMenuBar().isVisible()) )
|
} else if( borderColor != null && (rootPane.getJMenuBar() == null || !rootPane.getJMenuBar().isVisible()) )
|
||||||
insets.bottom += UIScale.scale( 1 );
|
insets.bottom += UIScale.scale( 1 );
|
||||||
|
|
||||||
if( !SystemInfo.isWindows_11_orLater && hasNativeCustomDecoration() && !isWindowMaximized( c ) )
|
if( !SystemInfo.isWindows_11_orLater && hasNativeCustomDecoration() && !isWindowMaximized() )
|
||||||
insets = FlatUIUtils.addInsets( insets, WindowTopBorder.getInstance().getBorderInsets() );
|
insets = FlatUIUtils.addInsets( insets, WindowTopBorder.getInstance().getBorderInsets() );
|
||||||
|
|
||||||
return insets;
|
return insets;
|
||||||
@@ -873,7 +995,7 @@ debug*/
|
|||||||
FlatUIUtils.paintFilledRectangle( g, borderColor, x, y + height - lineHeight, width, lineHeight );
|
FlatUIUtils.paintFilledRectangle( g, borderColor, x, y + height - lineHeight, width, lineHeight );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !SystemInfo.isWindows_11_orLater && hasNativeCustomDecoration() && !isWindowMaximized( c ) )
|
if( !SystemInfo.isWindows_11_orLater && hasNativeCustomDecoration() && !isWindowMaximized() )
|
||||||
WindowTopBorder.getInstance().paintBorder( c, g, x, y, width, height );
|
WindowTopBorder.getInstance().paintBorder( c, g, x, y, width, height );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -881,10 +1003,6 @@ debug*/
|
|||||||
JMenuBar menuBar = rootPane.getJMenuBar();
|
JMenuBar menuBar = rootPane.getJMenuBar();
|
||||||
return hasVisibleEmbeddedMenuBar( menuBar ) ? menuBar.getBorder() : null;
|
return hasVisibleEmbeddedMenuBar( menuBar ) ? menuBar.getBorder() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isWindowMaximized( Component c ) {
|
|
||||||
return window instanceof Frame && (((Frame) window).getExtendedState() & Frame.MAXIMIZED_BOTH) != 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//---- class FlatTitleLabelUI ---------------------------------------------
|
//---- class FlatTitleLabelUI ---------------------------------------------
|
||||||
@@ -898,32 +1016,109 @@ debug*/
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paintEnabledText( JLabel l, Graphics g, String s, int textX, int textY ) {
|
protected void installDefaults( JLabel c ) {
|
||||||
boolean hasEmbeddedMenuBar = hasVisibleEmbeddedMenuBar( rootPane.getJMenuBar() );
|
super.installDefaults( c );
|
||||||
int labelWidth = l.getWidth();
|
|
||||||
int textWidth = labelWidth - (textX * 2);
|
|
||||||
int gap = UIScale.scale( menuBarTitleGap );
|
|
||||||
|
|
||||||
// The passed in textX coordinate is always to horizontally center the text within the label bounds.
|
if( titleFont != null )
|
||||||
// Modify textX so that the text is painted either centered within the window bounds or leading aligned.
|
c.setFont( titleFont );
|
||||||
boolean center = hasEmbeddedMenuBar ? centerTitleIfMenuBarEmbedded : centerTitle;
|
}
|
||||||
if( center ) {
|
|
||||||
// If window is wide enough, center title within window bounds.
|
@Override
|
||||||
// Otherwise, leave it centered within free space (label bounds).
|
protected String layoutCL( JLabel label, FontMetrics fontMetrics, String text, Icon icon,
|
||||||
int centeredTextX = ((l.getParent().getWidth() - textWidth) / 2) - l.getX();
|
Rectangle viewR, Rectangle iconR, Rectangle textR )
|
||||||
if( centeredTextX >= gap && centeredTextX + textWidth <= labelWidth - gap )
|
{
|
||||||
textX = centeredTextX;
|
JMenuBar menuBar = rootPane.getJMenuBar();
|
||||||
} else {
|
boolean hasEmbeddedMenuBar = hasVisibleEmbeddedMenuBar( menuBar );
|
||||||
// leading aligned
|
boolean hasEmbeddedLeadingMenus = hasEmbeddedMenuBar && hasLeadingMenus( menuBar );
|
||||||
boolean leftToRight = getComponentOrientation().isLeftToRight();
|
boolean leftToRight = getComponentOrientation().isLeftToRight();
|
||||||
Insets insets = l.getInsets();
|
|
||||||
int leadingInset = hasEmbeddedMenuBar ? gap : (leftToRight ? insets.left : insets.right);
|
if( hasEmbeddedMenuBar ) {
|
||||||
int leadingTextX = leftToRight ? leadingInset : labelWidth - leadingInset - textWidth;
|
int minGap = UIScale.scale( menuBarTitleMinimumGap );
|
||||||
if( leftToRight ? leadingTextX < textX : leadingTextX > textX )
|
|
||||||
textX = leadingTextX;
|
// apply minimum leading gap (between embedded menu bar and title)
|
||||||
|
if( hasEmbeddedLeadingMenus ) {
|
||||||
|
if( leftToRight )
|
||||||
|
viewR.x += minGap;
|
||||||
|
viewR.width -= minGap;
|
||||||
|
}
|
||||||
|
|
||||||
|
// apply minimum trailing gap (between title and right aligned components of embedded menu bar)
|
||||||
|
Component horizontalGlue = findHorizontalGlue( menuBar );
|
||||||
|
if( horizontalGlue != null && menuBar.getComponent( menuBar.getComponentCount() - 1 ) != horizontalGlue ) {
|
||||||
|
if( !leftToRight )
|
||||||
|
viewR.x += minGap;
|
||||||
|
viewR.width -= minGap;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
super.paintEnabledText( l, g, s, textX, textY );
|
// compute icon width and gap (if icon is show besides the title)
|
||||||
|
int iconTextGap = 0;
|
||||||
|
int iconWidthAndGap = 0;
|
||||||
|
if( icon != null ) {
|
||||||
|
Insets iconInsets = iconLabel.getInsets();
|
||||||
|
iconTextGap = leftToRight ? iconInsets.right : iconInsets.left;
|
||||||
|
iconWidthAndGap = icon.getIconWidth() + iconTextGap;
|
||||||
|
}
|
||||||
|
|
||||||
|
// layout title and icon (if show besides the title)
|
||||||
|
String clippedText = SwingUtilities.layoutCompoundLabel( label, fontMetrics, text, icon,
|
||||||
|
label.getVerticalAlignment(), label.getHorizontalAlignment(),
|
||||||
|
label.getVerticalTextPosition(), label.getHorizontalTextPosition(),
|
||||||
|
viewR, iconR, textR,
|
||||||
|
iconTextGap );
|
||||||
|
|
||||||
|
// compute text X location
|
||||||
|
if( !clippedText.equals( text ) ) {
|
||||||
|
// if text is clipped, align to left (or right)
|
||||||
|
textR.x = leftToRight
|
||||||
|
? viewR.x + iconWidthAndGap
|
||||||
|
: viewR.x + viewR.width - iconWidthAndGap - textR.width;
|
||||||
|
} else {
|
||||||
|
int leadingGap = hasEmbeddedLeadingMenus ? UIScale.scale( menuBarTitleGap - menuBarTitleMinimumGap ) : 0;
|
||||||
|
|
||||||
|
boolean center = hasEmbeddedLeadingMenus ? centerTitleIfMenuBarEmbedded : centerTitle;
|
||||||
|
if( center ) {
|
||||||
|
// If window is wide enough, center title within window bounds.
|
||||||
|
// Otherwise, center within free space (label bounds).
|
||||||
|
Container parent = label.getParent();
|
||||||
|
int centeredTextX = (parent != null) ? ((parent.getWidth() - textR.width - iconWidthAndGap) / 2) + iconWidthAndGap - label.getX() : -1;
|
||||||
|
textR.x = (centeredTextX >= viewR.x + leadingGap && centeredTextX + textR.width <= viewR.x + viewR.width - leadingGap)
|
||||||
|
? centeredTextX
|
||||||
|
: viewR.x + ((viewR.width - textR.width - iconWidthAndGap) / 2) + iconWidthAndGap;
|
||||||
|
} else {
|
||||||
|
// leading aligned with leading gap, which is reduced if space is rare
|
||||||
|
textR.x = leftToRight
|
||||||
|
? Math.min( viewR.x + leadingGap + iconWidthAndGap, viewR.x + viewR.width - textR.width )
|
||||||
|
: Math.max( viewR.x + viewR.width - leadingGap - iconWidthAndGap - textR.width, viewR.x );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// compute icon X location (relative to text X location)
|
||||||
|
if( icon != null ) {
|
||||||
|
iconR.x = leftToRight
|
||||||
|
? textR.x - iconWidthAndGap
|
||||||
|
: textR.x + textR.width + iconTextGap;
|
||||||
|
}
|
||||||
|
|
||||||
|
return clippedText;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasLeadingMenus( JMenuBar menuBar ) {
|
||||||
|
// check whether menu bar is empty
|
||||||
|
if( menuBar.getComponentCount() == 0 || menuBar.getWidth() == 0 )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// check whether menu bar has a leading glue component
|
||||||
|
// (no menus/components at left side)
|
||||||
|
Component horizontalGlue = findHorizontalGlue( menuBar );
|
||||||
|
if( horizontalGlue != null ) {
|
||||||
|
boolean leftToRight = getComponentOrientation().isLeftToRight();
|
||||||
|
if( (leftToRight && horizontalGlue.getX() == 0) ||
|
||||||
|
(!leftToRight && horizontalGlue.getX() + horizontalGlue.getWidth() == menuBar.getWidth()) )
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -990,23 +1185,30 @@ debug*/
|
|||||||
//---- interface MouseListener ----
|
//---- interface MouseListener ----
|
||||||
|
|
||||||
private Point dragOffset;
|
private Point dragOffset;
|
||||||
|
private boolean nativeMove;
|
||||||
|
private long lastSingleClickWhen;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked( MouseEvent e ) {
|
public void mouseClicked( MouseEvent e ) {
|
||||||
|
// on Linux, when using native library, the mouse clicked event
|
||||||
|
// is usually not sent and maximize/restore is done in mouse pressed event
|
||||||
|
// this check is here for the case that a mouse clicked event comes thru for some reason
|
||||||
|
if( SystemInfo.isLinux && FlatNativeLinuxLibrary.isWMUtilsSupported( window ) ) {
|
||||||
|
// see comment in mousePressed()
|
||||||
|
if( lastSingleClickWhen != 0 && (e.getWhen() - lastSingleClickWhen) <= getMultiClickInterval() ) {
|
||||||
|
lastSingleClickWhen = 0;
|
||||||
|
maximizeOrRestore();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if( e.getClickCount() == 2 && SwingUtilities.isLeftMouseButton( e ) ) {
|
if( e.getClickCount() == 2 && SwingUtilities.isLeftMouseButton( e ) ) {
|
||||||
if( e.getSource() == iconLabel ) {
|
if( e.getSource() == iconLabel ) {
|
||||||
// double-click on icon closes window
|
// double-click on icon closes window
|
||||||
close();
|
close();
|
||||||
} else if( !hasNativeCustomDecoration() &&
|
} else if( !hasNativeCustomDecoration() ) {
|
||||||
window instanceof Frame &&
|
|
||||||
((Frame)window).isResizable() )
|
|
||||||
{
|
|
||||||
// maximize/restore on double-click
|
// maximize/restore on double-click
|
||||||
Frame frame = (Frame) window;
|
maximizeOrRestore();
|
||||||
if( (frame.getExtendedState() & Frame.MAXIMIZED_BOTH) != 0 )
|
|
||||||
restore();
|
|
||||||
else
|
|
||||||
maximize();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1016,10 +1218,56 @@ debug*/
|
|||||||
if( window == null )
|
if( window == null )
|
||||||
return; // should newer occur
|
return; // should newer occur
|
||||||
|
|
||||||
|
// on Linux, show window menu
|
||||||
|
if( SwingUtilities.isRightMouseButton( e ) &&
|
||||||
|
SystemInfo.isLinux && FlatNativeLinuxLibrary.isWMUtilsSupported( window ) )
|
||||||
|
{
|
||||||
|
e.consume();
|
||||||
|
FlatNativeLinuxLibrary.showWindowMenu( window, e );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if( !SwingUtilities.isLeftMouseButton( e ) )
|
if( !SwingUtilities.isLeftMouseButton( e ) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
dragOffset = SwingUtilities.convertPoint( FlatTitlePane.this, e.getPoint(), window );
|
dragOffset = SwingUtilities.convertPoint( FlatTitlePane.this, e.getPoint(), window );
|
||||||
|
nativeMove = false;
|
||||||
|
|
||||||
|
// on Linux, move or maximize/restore window
|
||||||
|
if( SystemInfo.isLinux && FlatNativeLinuxLibrary.isWMUtilsSupported( window ) ) {
|
||||||
|
// The fired Java mouse events, when doing a double-click and the first click
|
||||||
|
// sends a _NET_WM_MOVERESIZE message, are different for various Linux distributions:
|
||||||
|
// CentOS 7 (GNOME 3.28.2, X11): PRESSED(clickCount=1) PRESSED(clickCount=2) RELEASED(clickCount=2)
|
||||||
|
// Ubuntu 20.04 (GNOME 3.36.1, X11): PRESSED(clickCount=1) PRESSED(clickCount=2) RELEASED(clickCount=2)
|
||||||
|
// Ubuntu 22.04 (GNOME 42.2, Wayland): PRESSED(clickCount=1) RELEASED(clickCount=1) CLICKED(clickCount=1)
|
||||||
|
// Kubuntu 22.04 (KDE 5.24.4, X11): PRESSED(clickCount=1) PRESSED(clickCount=1) RELEASED(clickCount=1)
|
||||||
|
|
||||||
|
// double-click is not always recognized in Java when using _NET_WM_MOVERESIZE message
|
||||||
|
int clickCount = e.getClickCount();
|
||||||
|
if( clickCount == 1 && lastSingleClickWhen != 0 && (e.getWhen() - lastSingleClickWhen) <= getMultiClickInterval() )
|
||||||
|
clickCount = 2;
|
||||||
|
|
||||||
|
switch( clickCount ) {
|
||||||
|
case 1:
|
||||||
|
// move window via _NET_WM_MOVERESIZE message
|
||||||
|
e.consume();
|
||||||
|
nativeMove = FlatNativeLinuxLibrary.moveOrResizeWindow( window, e, FlatNativeLinuxLibrary.MOVE );
|
||||||
|
lastSingleClickWhen = e.getWhen();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
// maximize/restore on double-click
|
||||||
|
// also done here because no mouse clicked event is sent when using _NET_WM_MOVERESIZE message
|
||||||
|
lastSingleClickWhen = 0;
|
||||||
|
maximizeOrRestore();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getMultiClickInterval() {
|
||||||
|
Object value = Toolkit.getDefaultToolkit().getDesktopProperty( "awt.multiClickInterval" );
|
||||||
|
return (value instanceof Integer) ? (Integer) value : 500;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void mouseReleased( MouseEvent e ) {}
|
@Override public void mouseReleased( MouseEvent e ) {}
|
||||||
@@ -1030,9 +1278,12 @@ debug*/
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseDragged( MouseEvent e ) {
|
public void mouseDragged( MouseEvent e ) {
|
||||||
if( window == null )
|
if( window == null || dragOffset == null )
|
||||||
return; // should newer occur
|
return; // should newer occur
|
||||||
|
|
||||||
|
if( nativeMove )
|
||||||
|
return;
|
||||||
|
|
||||||
if( !SwingUtilities.isLeftMouseButton( e ) )
|
if( !SwingUtilities.isLeftMouseButton( e ) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@@ -22,10 +22,7 @@ import java.awt.Component;
|
|||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.beans.PropertyChangeEvent;
|
import java.beans.PropertyChangeEvent;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import javax.swing.AbstractButton;
|
import javax.swing.*;
|
||||||
import javax.swing.JComponent;
|
|
||||||
import javax.swing.JToggleButton;
|
|
||||||
import javax.swing.UIManager;
|
|
||||||
import javax.swing.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable;
|
import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable;
|
||||||
import com.formdev.flatlaf.ui.FlatStylingSupport.UnknownStyleException;
|
import com.formdev.flatlaf.ui.FlatStylingSupport.UnknownStyleException;
|
||||||
@@ -51,15 +48,29 @@ import com.formdev.flatlaf.util.UIScale;
|
|||||||
* @uiDefault ToggleButton.iconTextGap int
|
* @uiDefault ToggleButton.iconTextGap int
|
||||||
* @uiDefault ToggleButton.startBackground Color optional; if set, a gradient paint is used and ToggleButton.background is ignored
|
* @uiDefault ToggleButton.startBackground Color optional; if set, a gradient paint is used and ToggleButton.background is ignored
|
||||||
* @uiDefault ToggleButton.endBackground Color optional; if set, a gradient paint is used
|
* @uiDefault ToggleButton.endBackground Color optional; if set, a gradient paint is used
|
||||||
* @uiDefault ToggleButton.pressedBackground Color
|
* @uiDefault ToggleButton.focusedBackground Color optional
|
||||||
|
* @uiDefault ToggleButton.focusedForeground Color optional
|
||||||
|
* @uiDefault ToggleButton.hoverBackground Color optional
|
||||||
|
* @uiDefault ToggleButton.hoverForeground Color optional
|
||||||
|
* @uiDefault ToggleButton.pressedBackground Color optional
|
||||||
|
* @uiDefault ToggleButton.pressedForeground Color optional
|
||||||
* @uiDefault ToggleButton.selectedBackground Color
|
* @uiDefault ToggleButton.selectedBackground Color
|
||||||
* @uiDefault ToggleButton.selectedForeground Color
|
* @uiDefault ToggleButton.selectedForeground Color
|
||||||
* @uiDefault ToggleButton.disabledBackground Color optional
|
* @uiDefault ToggleButton.disabledBackground Color optional
|
||||||
* @uiDefault ToggleButton.disabledText Color
|
* @uiDefault ToggleButton.disabledText Color
|
||||||
* @uiDefault ToggleButton.disabledSelectedBackground Color
|
* @uiDefault ToggleButton.disabledSelectedBackground Color
|
||||||
|
* @uiDefault ToggleButton.disabledSelectedForeground Color optional
|
||||||
|
* @uiDefault Button.paintShadow boolean default is false
|
||||||
|
* @uiDefault Button.shadowWidth int default is 2
|
||||||
|
* @uiDefault Button.shadowColor Color optional
|
||||||
* @uiDefault ToggleButton.toolbar.hoverBackground Color
|
* @uiDefault ToggleButton.toolbar.hoverBackground Color
|
||||||
|
* @uiDefault ToggleButton.toolbar.hoverForeground Color optional
|
||||||
* @uiDefault ToggleButton.toolbar.pressedBackground Color
|
* @uiDefault ToggleButton.toolbar.pressedBackground Color
|
||||||
|
* @uiDefault ToggleButton.toolbar.pressedForeground Color optional
|
||||||
* @uiDefault ToggleButton.toolbar.selectedBackground Color
|
* @uiDefault ToggleButton.toolbar.selectedBackground Color
|
||||||
|
* @uiDefault ToggleButton.toolbar.selectedForeground Color optional
|
||||||
|
* @uiDefault ToggleButton.toolbar.disabledSelectedBackground Color optional
|
||||||
|
* @uiDefault ToggleButton.toolbar.disabledSelectedForeground Color optional
|
||||||
*
|
*
|
||||||
* <!-- FlatToggleButtonUI -->
|
* <!-- FlatToggleButtonUI -->
|
||||||
*
|
*
|
||||||
@@ -67,8 +78,11 @@ import com.formdev.flatlaf.util.UIScale;
|
|||||||
* @uiDefault ToggleButton.tab.underlineColor Color
|
* @uiDefault ToggleButton.tab.underlineColor Color
|
||||||
* @uiDefault ToggleButton.tab.disabledUnderlineColor Color
|
* @uiDefault ToggleButton.tab.disabledUnderlineColor Color
|
||||||
* @uiDefault ToggleButton.tab.selectedBackground Color optional
|
* @uiDefault ToggleButton.tab.selectedBackground Color optional
|
||||||
|
* @uiDefault ToggleButton.tab.selectedForeground Color optional
|
||||||
* @uiDefault ToggleButton.tab.hoverBackground Color
|
* @uiDefault ToggleButton.tab.hoverBackground Color
|
||||||
|
* @uiDefault ToggleButton.tab.hoverForeground Color optional
|
||||||
* @uiDefault ToggleButton.tab.focusBackground Color
|
* @uiDefault ToggleButton.tab.focusBackground Color
|
||||||
|
* @uiDefault ToggleButton.tab.focusForeground Color optional
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @author Karl Tauber
|
* @author Karl Tauber
|
||||||
@@ -80,8 +94,11 @@ public class FlatToggleButtonUI
|
|||||||
@Styleable(dot=true) protected Color tabUnderlineColor;
|
@Styleable(dot=true) protected Color tabUnderlineColor;
|
||||||
@Styleable(dot=true) protected Color tabDisabledUnderlineColor;
|
@Styleable(dot=true) protected Color tabDisabledUnderlineColor;
|
||||||
@Styleable(dot=true) protected Color tabSelectedBackground;
|
@Styleable(dot=true) protected Color tabSelectedBackground;
|
||||||
|
/** @since 2.3 */ @Styleable(dot=true) protected Color tabSelectedForeground;
|
||||||
@Styleable(dot=true) protected Color tabHoverBackground;
|
@Styleable(dot=true) protected Color tabHoverBackground;
|
||||||
|
/** @since 2.3 */ @Styleable(dot=true) protected Color tabHoverForeground;
|
||||||
@Styleable(dot=true) protected Color tabFocusBackground;
|
@Styleable(dot=true) protected Color tabFocusBackground;
|
||||||
|
/** @since 2.3 */ @Styleable(dot=true) protected Color tabFocusForeground;
|
||||||
|
|
||||||
private boolean defaults_initialized = false;
|
private boolean defaults_initialized = false;
|
||||||
|
|
||||||
@@ -114,8 +131,11 @@ public class FlatToggleButtonUI
|
|||||||
tabUnderlineColor = UIManager.getColor( "ToggleButton.tab.underlineColor" );
|
tabUnderlineColor = UIManager.getColor( "ToggleButton.tab.underlineColor" );
|
||||||
tabDisabledUnderlineColor = UIManager.getColor( "ToggleButton.tab.disabledUnderlineColor" );
|
tabDisabledUnderlineColor = UIManager.getColor( "ToggleButton.tab.disabledUnderlineColor" );
|
||||||
tabSelectedBackground = UIManager.getColor( "ToggleButton.tab.selectedBackground" );
|
tabSelectedBackground = UIManager.getColor( "ToggleButton.tab.selectedBackground" );
|
||||||
|
tabSelectedForeground = UIManager.getColor( "ToggleButton.tab.selectedForeground" );
|
||||||
tabHoverBackground = UIManager.getColor( "ToggleButton.tab.hoverBackground" );
|
tabHoverBackground = UIManager.getColor( "ToggleButton.tab.hoverBackground" );
|
||||||
|
tabHoverForeground = UIManager.getColor( "ToggleButton.tab.hoverForeground" );
|
||||||
tabFocusBackground = UIManager.getColor( "ToggleButton.tab.focusBackground" );
|
tabFocusBackground = UIManager.getColor( "ToggleButton.tab.focusBackground" );
|
||||||
|
tabFocusForeground = UIManager.getColor( "ToggleButton.tab.focusForeground" );
|
||||||
|
|
||||||
defaults_initialized = true;
|
defaults_initialized = true;
|
||||||
}
|
}
|
||||||
@@ -142,6 +162,7 @@ public class FlatToggleButtonUI
|
|||||||
b.repaint();
|
b.repaint();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case TAB_BUTTON_UNDERLINE_PLACEMENT:
|
||||||
case TAB_BUTTON_UNDERLINE_HEIGHT:
|
case TAB_BUTTON_UNDERLINE_HEIGHT:
|
||||||
case TAB_BUTTON_UNDERLINE_COLOR:
|
case TAB_BUTTON_UNDERLINE_COLOR:
|
||||||
case TAB_BUTTON_SELECTED_BACKGROUND:
|
case TAB_BUTTON_SELECTED_BACKGROUND:
|
||||||
@@ -196,13 +217,42 @@ public class FlatToggleButtonUI
|
|||||||
|
|
||||||
// paint underline if selected
|
// paint underline if selected
|
||||||
if( selected ) {
|
if( selected ) {
|
||||||
int underlineHeight = UIScale.scale( clientPropertyInt( c, TAB_BUTTON_UNDERLINE_HEIGHT, tabUnderlineHeight ) );
|
int underlineThickness = UIScale.scale( clientPropertyInt( c, TAB_BUTTON_UNDERLINE_HEIGHT, tabUnderlineHeight ) );
|
||||||
g.setColor( c.isEnabled()
|
g.setColor( c.isEnabled()
|
||||||
? clientPropertyColor( c, TAB_BUTTON_UNDERLINE_COLOR, tabUnderlineColor )
|
? clientPropertyColor( c, TAB_BUTTON_UNDERLINE_COLOR, tabUnderlineColor )
|
||||||
: tabDisabledUnderlineColor );
|
: tabDisabledUnderlineColor );
|
||||||
g.fillRect( 0, height - underlineHeight, width, underlineHeight );
|
int placement = clientPropertyInt( c, TAB_BUTTON_UNDERLINE_PLACEMENT, SwingConstants.BOTTOM );
|
||||||
|
switch (placement) {
|
||||||
|
case SwingConstants.TOP:
|
||||||
|
g.fillRect( 0, 0, width, underlineThickness );
|
||||||
|
break;
|
||||||
|
case SwingConstants.LEFT:
|
||||||
|
g.fillRect( 0, 0, underlineThickness, height );
|
||||||
|
break;
|
||||||
|
case SwingConstants.RIGHT:
|
||||||
|
g.fillRect( width - underlineThickness, 0, underlineThickness, height );
|
||||||
|
break;
|
||||||
|
case SwingConstants.BOTTOM:
|
||||||
|
default:
|
||||||
|
g.fillRect( 0, height - underlineThickness, width, underlineThickness );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
super.paintBackground( g, c );
|
super.paintBackground( g, c );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Color getForeground( JComponent c ) {
|
||||||
|
if( isTabButton( c ) ) {
|
||||||
|
if( !c.isEnabled() )
|
||||||
|
return disabledText;
|
||||||
|
|
||||||
|
if( tabSelectedForeground != null && ((AbstractButton)c).isSelected() )
|
||||||
|
return tabSelectedForeground;
|
||||||
|
|
||||||
|
return buttonStateColor( c, c.getForeground(), disabledText,
|
||||||
|
tabFocusForeground, tabHoverForeground, null );
|
||||||
|
} else
|
||||||
|
return super.getForeground( c );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -160,6 +160,12 @@ public class FlatToolBarSeparatorUI
|
|||||||
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
@Override
|
||||||
|
public Object getStyleableValue( JComponent c, String key ) {
|
||||||
|
return FlatStylingSupport.getAnnotatedStyleableValue( this, key );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dimension getPreferredSize( JComponent c ) {
|
public Dimension getPreferredSize( JComponent c ) {
|
||||||
Dimension size = ((JToolBar.Separator)c).getSeparatorSize();
|
Dimension size = ((JToolBar.Separator)c).getSeparatorSize();
|
||||||
|
|||||||
@@ -201,6 +201,12 @@ public class FlatToolBarUI
|
|||||||
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
@Override
|
||||||
|
public Object getStyleableValue( JComponent c, String key ) {
|
||||||
|
return FlatStylingSupport.getAnnotatedStyleableValue( this, key );
|
||||||
|
}
|
||||||
|
|
||||||
/** @since 1.4 */
|
/** @since 1.4 */
|
||||||
protected void setButtonsFocusable( boolean focusable ) {
|
protected void setButtonsFocusable( boolean focusable ) {
|
||||||
for( Component c : toolBar.getComponents() )
|
for( Component c : toolBar.getComponents() )
|
||||||
|
|||||||
@@ -340,6 +340,12 @@ public class FlatTreeUI
|
|||||||
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.5 */
|
||||||
|
@Override
|
||||||
|
public Object getStyleableValue( JComponent c, String key ) {
|
||||||
|
return FlatStylingSupport.getAnnotatedStyleableValue( this, key );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import java.awt.Rectangle;
|
|||||||
import java.awt.RenderingHints;
|
import java.awt.RenderingHints;
|
||||||
import java.awt.Shape;
|
import java.awt.Shape;
|
||||||
import java.awt.Stroke;
|
import java.awt.Stroke;
|
||||||
|
import java.awt.SystemColor;
|
||||||
import java.awt.Window;
|
import java.awt.Window;
|
||||||
import java.awt.event.FocusEvent;
|
import java.awt.event.FocusEvent;
|
||||||
import java.awt.event.FocusListener;
|
import java.awt.event.FocusListener;
|
||||||
@@ -45,20 +46,27 @@ import java.util.WeakHashMap;
|
|||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
|
import javax.swing.JScrollPane;
|
||||||
import javax.swing.JTable;
|
import javax.swing.JTable;
|
||||||
|
import javax.swing.JTextField;
|
||||||
import javax.swing.LookAndFeel;
|
import javax.swing.LookAndFeel;
|
||||||
import javax.swing.SwingConstants;
|
import javax.swing.SwingConstants;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
|
import javax.swing.UIDefaults;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.border.Border;
|
import javax.swing.border.Border;
|
||||||
import javax.swing.border.CompoundBorder;
|
import javax.swing.border.CompoundBorder;
|
||||||
import javax.swing.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
import javax.swing.plaf.UIResource;
|
import javax.swing.plaf.UIResource;
|
||||||
import com.formdev.flatlaf.FlatClientProperties;
|
import com.formdev.flatlaf.FlatClientProperties;
|
||||||
|
import com.formdev.flatlaf.FlatIntelliJLaf;
|
||||||
|
import com.formdev.flatlaf.FlatLaf;
|
||||||
|
import com.formdev.flatlaf.FlatLightLaf;
|
||||||
import com.formdev.flatlaf.FlatSystemProperties;
|
import com.formdev.flatlaf.FlatSystemProperties;
|
||||||
import com.formdev.flatlaf.util.DerivedColor;
|
import com.formdev.flatlaf.util.DerivedColor;
|
||||||
import com.formdev.flatlaf.util.Graphics2DProxy;
|
import com.formdev.flatlaf.util.Graphics2DProxy;
|
||||||
import com.formdev.flatlaf.util.HiDPIUtils;
|
import com.formdev.flatlaf.util.HiDPIUtils;
|
||||||
|
import com.formdev.flatlaf.util.SystemInfo;
|
||||||
import com.formdev.flatlaf.util.UIScale;
|
import com.formdev.flatlaf.util.UIScale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -202,6 +210,9 @@ public class FlatUIUtils
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isCellEditor( Component c ) {
|
public static boolean isCellEditor( Component c ) {
|
||||||
|
if( c == null )
|
||||||
|
return false;
|
||||||
|
|
||||||
// check whether used in cell editor (check 3 levels up)
|
// check whether used in cell editor (check 3 levels up)
|
||||||
Component c2 = c;
|
Component c2 = c;
|
||||||
for( int i = 0; i <= 2 && c2 != null; i++ ) {
|
for( int i = 0; i <= 2 && c2 != null; i++ ) {
|
||||||
@@ -241,6 +252,11 @@ public class FlatUIUtils
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// invoke hasFocus() here because components may have overridden this method
|
||||||
|
// (e.g. Swing delegate components used for AWT components on macOS)
|
||||||
|
if( c.hasFocus() )
|
||||||
|
return true;
|
||||||
|
|
||||||
return keyboardFocusManager.getPermanentFocusOwner() == c &&
|
return keyboardFocusManager.getPermanentFocusOwner() == c &&
|
||||||
isInActiveWindow( c, keyboardFocusManager.getActiveWindow() );
|
isInActiveWindow( c, keyboardFocusManager.getActiveWindow() );
|
||||||
}
|
}
|
||||||
@@ -251,6 +267,38 @@ public class FlatUIUtils
|
|||||||
(window != null && window.getType() == Window.Type.POPUP && window.getOwner() == activeWindow);
|
(window != null && window.getType() == Window.Type.POPUP && window.getOwner() == activeWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static boolean isAWTPeer( Component c ) {
|
||||||
|
// on macOS, Swing components are used for AWT components
|
||||||
|
if( SystemInfo.isMacOS )
|
||||||
|
return c.getClass().getName().startsWith( "sun.lwawt.LW" );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether component is used as peer for AWT (on macOS) and
|
||||||
|
* whether a dark FlatLaf theme is active, which requires special handling
|
||||||
|
* because AWT always uses light colors.
|
||||||
|
*/
|
||||||
|
static boolean needsLightAWTPeer( JComponent c ) {
|
||||||
|
return FlatUIUtils.isAWTPeer( c ) && FlatLaf.isLafDark();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static UIDefaults lightAWTPeerDefaults;
|
||||||
|
|
||||||
|
static void runWithLightAWTPeerUIDefaults( Runnable runnable ) {
|
||||||
|
if( lightAWTPeerDefaults == null ) {
|
||||||
|
FlatLaf lightLaf = UIManager.getInt( "Component.focusWidth" ) >= 2
|
||||||
|
? new FlatIntelliJLaf()
|
||||||
|
: new FlatLightLaf();
|
||||||
|
lightAWTPeerDefaults = lightLaf.getDefaults();
|
||||||
|
}
|
||||||
|
|
||||||
|
FlatLaf.runWithUIDefaultsGetter( key -> {
|
||||||
|
Object value = lightAWTPeerDefaults.get( key );
|
||||||
|
return (value != null) ? value : FlatLaf.NULL_VALUE;
|
||||||
|
}, runnable );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the given component is in a window that is in full-screen mode.
|
* Returns whether the given component is in a window that is in full-screen mode.
|
||||||
*/
|
*/
|
||||||
@@ -335,7 +383,7 @@ public class FlatUIUtils
|
|||||||
*/
|
*/
|
||||||
public static Object[] setRenderingHints( Graphics g ) {
|
public static Object[] setRenderingHints( Graphics g ) {
|
||||||
Graphics2D g2 = (Graphics2D) g;
|
Graphics2D g2 = (Graphics2D) g;
|
||||||
Object[] oldRenderingHints = new Object[] {
|
Object[] oldRenderingHints = {
|
||||||
g2.getRenderingHint( RenderingHints.KEY_ANTIALIASING ),
|
g2.getRenderingHint( RenderingHints.KEY_ANTIALIASING ),
|
||||||
g2.getRenderingHint( RenderingHints.KEY_STROKE_CONTROL ),
|
g2.getRenderingHint( RenderingHints.KEY_STROKE_CONTROL ),
|
||||||
};
|
};
|
||||||
@@ -352,8 +400,10 @@ public class FlatUIUtils
|
|||||||
*/
|
*/
|
||||||
public static void resetRenderingHints( Graphics g, Object[] oldRenderingHints ) {
|
public static void resetRenderingHints( Graphics g, Object[] oldRenderingHints ) {
|
||||||
Graphics2D g2 = (Graphics2D) g;
|
Graphics2D g2 = (Graphics2D) g;
|
||||||
g2.setRenderingHint( RenderingHints.KEY_ANTIALIASING, oldRenderingHints[0] );
|
if( oldRenderingHints[0] != null )
|
||||||
g2.setRenderingHint( RenderingHints.KEY_STROKE_CONTROL, oldRenderingHints[1] );
|
g2.setRenderingHint( RenderingHints.KEY_ANTIALIASING, oldRenderingHints[0] );
|
||||||
|
if( oldRenderingHints[1] != null )
|
||||||
|
g2.setRenderingHint( RenderingHints.KEY_STROKE_CONTROL, oldRenderingHints[1] );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -376,7 +426,7 @@ public class FlatUIUtils
|
|||||||
}
|
}
|
||||||
|
|
||||||
Graphics2D g2 = (Graphics2D) g;
|
Graphics2D g2 = (Graphics2D) g;
|
||||||
Object[] oldRenderingHints2 = new Object[] {
|
Object[] oldRenderingHints2 = {
|
||||||
g2.getRenderingHint( RenderingHints.KEY_ANTIALIASING ),
|
g2.getRenderingHint( RenderingHints.KEY_ANTIALIASING ),
|
||||||
g2.getRenderingHint( RenderingHints.KEY_STROKE_CONTROL ),
|
g2.getRenderingHint( RenderingHints.KEY_STROKE_CONTROL ),
|
||||||
};
|
};
|
||||||
@@ -664,9 +714,9 @@ public class FlatUIUtils
|
|||||||
* is smaller than its bounds (for the focus decoration).
|
* is smaller than its bounds (for the focus decoration).
|
||||||
*/
|
*/
|
||||||
public static void paintParentBackground( Graphics g, JComponent c ) {
|
public static void paintParentBackground( Graphics g, JComponent c ) {
|
||||||
Container parent = findOpaqueParent( c );
|
Color background = getParentBackground( c );
|
||||||
if( parent != null ) {
|
if( background != null ) {
|
||||||
g.setColor( parent.getBackground() );
|
g.setColor( background );
|
||||||
g.fillRect( 0, 0, c.getWidth(), c.getHeight() );
|
g.fillRect( 0, 0, c.getWidth(), c.getHeight() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -676,9 +726,20 @@ public class FlatUIUtils
|
|||||||
*/
|
*/
|
||||||
public static Color getParentBackground( JComponent c ) {
|
public static Color getParentBackground( JComponent c ) {
|
||||||
Container parent = findOpaqueParent( c );
|
Container parent = findOpaqueParent( c );
|
||||||
return (parent != null)
|
// parent.getBackground() may return null
|
||||||
? parent.getBackground()
|
// (e.g. for Swing delegate components used for AWT components on macOS)
|
||||||
: UIManager.getColor( "Panel.background" ); // fallback, probably never used
|
Color background = (parent != null) ? parent.getBackground() : null;
|
||||||
|
if( background != null )
|
||||||
|
return background;
|
||||||
|
|
||||||
|
if( isAWTPeer( c ) ) {
|
||||||
|
// AWT peers usually use component background, except for TextField and ScrollPane
|
||||||
|
return c instanceof JTextField || c instanceof JScrollPane || c.getBackground() == null
|
||||||
|
? SystemColor.window
|
||||||
|
: c.getBackground();
|
||||||
|
}
|
||||||
|
|
||||||
|
return UIManager.getColor( "Panel.background" );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ package com.formdev.flatlaf.ui;
|
|||||||
|
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JTable;
|
|
||||||
import javax.swing.JViewport;
|
import javax.swing.JViewport;
|
||||||
import javax.swing.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
import javax.swing.plaf.basic.BasicViewportUI;
|
import javax.swing.plaf.basic.BasicViewportUI;
|
||||||
@@ -43,15 +43,28 @@ public class FlatViewportUI
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update( Graphics g, JComponent c ) {
|
public void paint( Graphics g, JComponent c ) {
|
||||||
Component view = ((JViewport)c).getView();
|
super.paint( g, c );
|
||||||
if( c.isOpaque() && view instanceof JTable ) {
|
|
||||||
// paint viewport background in same color as table background
|
|
||||||
g.setColor( view.getBackground() );
|
|
||||||
g.fillRect( 0, 0, c.getWidth(), c.getHeight() );
|
|
||||||
|
|
||||||
paint( g, c );
|
Component view = ((JViewport)c).getView();
|
||||||
} else
|
if( view instanceof JComponent ) {
|
||||||
super.update( g, c );
|
try {
|
||||||
|
Method m = view.getClass().getMethod( "getUI" );
|
||||||
|
Object ui = m.invoke( view );
|
||||||
|
if( ui instanceof ViewportPainter )
|
||||||
|
((ViewportPainter)ui).paintViewport( g, (JComponent) view, (JViewport) c );
|
||||||
|
} catch( Exception ex ) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---- interface ViewportPainter ------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 2.3
|
||||||
|
*/
|
||||||
|
public interface ViewportPainter {
|
||||||
|
void paintViewport( Graphics g, JComponent c, JViewport viewport );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ import java.awt.Window;
|
|||||||
import java.awt.geom.AffineTransform;
|
import java.awt.geom.AffineTransform;
|
||||||
import java.beans.PropertyChangeEvent;
|
import java.beans.PropertyChangeEvent;
|
||||||
import java.beans.PropertyChangeListener;
|
import java.beans.PropertyChangeListener;
|
||||||
import java.io.File;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.IdentityHashMap;
|
import java.util.IdentityHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -38,9 +37,7 @@ import javax.swing.Timer;
|
|||||||
import javax.swing.event.ChangeEvent;
|
import javax.swing.event.ChangeEvent;
|
||||||
import javax.swing.event.ChangeListener;
|
import javax.swing.event.ChangeListener;
|
||||||
import javax.swing.event.EventListenerList;
|
import javax.swing.event.EventListenerList;
|
||||||
import com.formdev.flatlaf.FlatSystemProperties;
|
|
||||||
import com.formdev.flatlaf.util.LoggingFacade;
|
import com.formdev.flatlaf.util.LoggingFacade;
|
||||||
import com.formdev.flatlaf.util.NativeLibrary;
|
|
||||||
import com.formdev.flatlaf.util.SystemInfo;
|
import com.formdev.flatlaf.util.SystemInfo;
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -84,7 +81,6 @@ class FlatWindowsNativeWindowBorder
|
|||||||
private Color colorizationColor;
|
private Color colorizationColor;
|
||||||
private int colorizationColorBalance;
|
private int colorizationColorBalance;
|
||||||
|
|
||||||
private static NativeLibrary nativeLibrary;
|
|
||||||
private static FlatWindowsNativeWindowBorder instance;
|
private static FlatWindowsNativeWindowBorder instance;
|
||||||
|
|
||||||
static FlatNativeWindowBorder.Provider getInstance() {
|
static FlatNativeWindowBorder.Provider getInstance() {
|
||||||
@@ -96,31 +92,8 @@ class FlatWindowsNativeWindowBorder
|
|||||||
if( !SystemInfo.isX86 && !SystemInfo.isX86_64 )
|
if( !SystemInfo.isX86 && !SystemInfo.isX86_64 )
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
// load native library
|
|
||||||
if( nativeLibrary == null ) {
|
|
||||||
if( !SystemInfo.isJava_9_orLater ) {
|
|
||||||
// In Java 8, load jawt.dll (part of JRE) explicitly because it
|
|
||||||
// is not found when running application with <jdk>/bin/java.exe.
|
|
||||||
// When using <jdk>/jre/bin/java.exe, it is found.
|
|
||||||
// jawt.dll is located in <jdk>/jre/bin/.
|
|
||||||
// Java 9 and later does not have this problem.
|
|
||||||
try {
|
|
||||||
System.loadLibrary( "jawt" );
|
|
||||||
} catch( UnsatisfiedLinkError ex ) {
|
|
||||||
// log error only if native library jawt.dll not already loaded
|
|
||||||
String message = ex.getMessage();
|
|
||||||
if( message == null || !message.contains( "already loaded in another classloader" ) )
|
|
||||||
LoggingFacade.INSTANCE.logSevere( null, ex );
|
|
||||||
} catch( Exception ex ) {
|
|
||||||
LoggingFacade.INSTANCE.logSevere( null, ex );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
nativeLibrary = createNativeLibrary();
|
|
||||||
}
|
|
||||||
|
|
||||||
// check whether native library was successfully loaded
|
// check whether native library was successfully loaded
|
||||||
if( !nativeLibrary.isLoaded() )
|
if( !FlatNativeLibrary.isLoaded() )
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
// create new instance
|
// create new instance
|
||||||
@@ -129,23 +102,6 @@ class FlatWindowsNativeWindowBorder
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static NativeLibrary createNativeLibrary() {
|
|
||||||
String libraryName = "flatlaf-windows-x86";
|
|
||||||
if( SystemInfo.isX86_64 )
|
|
||||||
libraryName += "_64";
|
|
||||||
|
|
||||||
String libraryPath = System.getProperty( FlatSystemProperties.NATIVE_LIBRARY_PATH );
|
|
||||||
if( libraryPath != null ) {
|
|
||||||
File libraryFile = new File( libraryPath, System.mapLibraryName( libraryName ) );
|
|
||||||
if( libraryFile.exists() )
|
|
||||||
return new NativeLibrary( libraryFile, true );
|
|
||||||
else
|
|
||||||
LoggingFacade.INSTANCE.logSevere( "Did not find external library " + libraryFile + ", using extracted library instead", null );
|
|
||||||
}
|
|
||||||
|
|
||||||
return new NativeLibrary( "com/formdev/flatlaf/natives/" + libraryName, null, true );
|
|
||||||
}
|
|
||||||
|
|
||||||
private FlatWindowsNativeWindowBorder() {
|
private FlatWindowsNativeWindowBorder() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -195,11 +195,13 @@ public class JBRCustomDecorations
|
|||||||
{
|
{
|
||||||
private static JBRWindowTopBorder instance;
|
private static JBRWindowTopBorder instance;
|
||||||
|
|
||||||
private final Color defaultActiveBorder = new Color( 0x707070 );
|
private final Color activeLightColor = new Color( 0x707070 );
|
||||||
|
private final Color activeDarkColor = new Color( 0x2D2E2F );
|
||||||
private final Color inactiveLightColor = new Color( 0xaaaaaa );
|
private final Color inactiveLightColor = new Color( 0xaaaaaa );
|
||||||
|
private final Color inactiveDarkColor = new Color( 0x494A4B );
|
||||||
|
|
||||||
private boolean colorizationAffectsBorders;
|
private boolean colorizationAffectsBorders;
|
||||||
private Color activeColor = defaultActiveBorder;
|
private Color activeColor;
|
||||||
|
|
||||||
static JBRWindowTopBorder getInstance() {
|
static JBRWindowTopBorder getInstance() {
|
||||||
if( instance == null )
|
if( instance == null )
|
||||||
@@ -250,7 +252,7 @@ public class JBRCustomDecorations
|
|||||||
|
|
||||||
private Color calculateActiveBorderColor() {
|
private Color calculateActiveBorderColor() {
|
||||||
if( !colorizationAffectsBorders )
|
if( !colorizationAffectsBorders )
|
||||||
return defaultActiveBorder;
|
return null;
|
||||||
|
|
||||||
Color colorizationColor = getColorizationColor();
|
Color colorizationColor = getColorizationColor();
|
||||||
if( colorizationColor != null ) {
|
if( colorizationColor != null ) {
|
||||||
@@ -285,15 +287,11 @@ public class JBRCustomDecorations
|
|||||||
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 ) {
|
||||||
Window window = SwingUtilities.windowForComponent( c );
|
Window window = SwingUtilities.windowForComponent( c );
|
||||||
boolean active = window != null && window.isActive();
|
boolean active = window != null && window.isActive();
|
||||||
|
boolean dark = FlatLaf.isLafDark();
|
||||||
|
|
||||||
// paint top border
|
g.setColor( active
|
||||||
// - in light themes
|
? (activeColor != null ? activeColor : (dark ? activeDarkColor : activeLightColor))
|
||||||
// - in dark themes only for active windows if colorization affects borders
|
: (dark ? inactiveDarkColor : inactiveLightColor) );
|
||||||
boolean paintTopBorder = !FlatLaf.isLafDark() || (active && colorizationAffectsBorders);
|
|
||||||
if( !paintTopBorder )
|
|
||||||
return;
|
|
||||||
|
|
||||||
g.setColor( active ? activeColor : inactiveLightColor );
|
|
||||||
HiDPIUtils.paintAtScale1x( (Graphics2D) g, x, y, width, height, this::paintImpl );
|
HiDPIUtils.paintAtScale1x( (Graphics2D) g, x, y, width, height, this::paintImpl );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -143,8 +143,8 @@ public class MigLayoutVisualPadding
|
|||||||
//---- class FlatMigInsets ------------------------------------------------
|
//---- class FlatMigInsets ------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Marker class to identify our visual paddings and leaf paddings,
|
* Marker class to identify our visual paddings and leave paddings
|
||||||
* which were set from outside, untouched.
|
* set from outside untouched.
|
||||||
*/
|
*/
|
||||||
private static class FlatMigInsets
|
private static class FlatMigInsets
|
||||||
extends Insets
|
extends Insets
|
||||||
|
|||||||
@@ -48,30 +48,55 @@ public class HiDPIUtils
|
|||||||
*/
|
*/
|
||||||
public static void paintAtScale1x( Graphics2D g, int x, int y, int width, int height, Painter painter ) {
|
public static void paintAtScale1x( Graphics2D g, int x, int y, int width, int height, Painter painter ) {
|
||||||
// save original transform
|
// save original transform
|
||||||
AffineTransform transform = g.getTransform();
|
AffineTransform t = g.getTransform();
|
||||||
|
|
||||||
|
// get scale X/Y and shear X/Y
|
||||||
|
double scaleX = t.getScaleX();
|
||||||
|
double scaleY = t.getScaleY();
|
||||||
|
double shearX = t.getShearX();
|
||||||
|
double shearY = t.getShearY();
|
||||||
|
|
||||||
|
// check whether rotated
|
||||||
|
// (also check for negative scale X/Y because shear X/Y are zero for 180 degrees rotation)
|
||||||
|
boolean rotated = (shearX != 0 || shearY != 0 || scaleX <= 0 || scaleY <= 0);
|
||||||
|
if( rotated ) {
|
||||||
|
// resulting scale X/Y values are always positive
|
||||||
|
scaleX = Math.hypot( scaleX, shearX );
|
||||||
|
scaleY = Math.hypot( scaleY, shearY );
|
||||||
|
} else {
|
||||||
|
// make scale X/Y positive
|
||||||
|
scaleX = Math.abs( scaleX );
|
||||||
|
scaleY = Math.abs( scaleY );
|
||||||
|
}
|
||||||
|
|
||||||
// check whether scaled
|
// check whether scaled
|
||||||
if( transform.getScaleX() == 1 && transform.getScaleY() == 1 ) {
|
if( scaleX == 1 && scaleY == 1 ) {
|
||||||
painter.paint( g, x, y, width, height, 1 );
|
painter.paint( g, x, y, width, height, 1 );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// scale rectangle
|
// scale rectangle
|
||||||
Rectangle2D.Double scaledRect = scale( transform, x, y, width, height );
|
Rectangle2D.Double scaledRect = scale( scaleX, scaleY, t, x, y, width, height );
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// unscale to factor 1.0 and move origin (to whole numbers)
|
// unscale to factor 1.0, keep rotation and move origin (to whole numbers)
|
||||||
g.setTransform( new AffineTransform( 1, 0, 0, 1,
|
AffineTransform t1x;
|
||||||
Math.floor( scaledRect.x ), Math.floor( scaledRect.y ) ) );
|
if( rotated ) {
|
||||||
|
t1x = new AffineTransform( t.getScaleX(), t.getShearY(), t.getShearX(), t.getScaleY(),
|
||||||
|
Math.floor( scaledRect.x ), Math.floor( scaledRect.y ) );
|
||||||
|
t1x.scale( 1. / scaleX, 1. / scaleY );
|
||||||
|
} else
|
||||||
|
t1x = new AffineTransform( 1, 0, 0, 1, Math.floor( scaledRect.x ), Math.floor( scaledRect.y ) );
|
||||||
|
g.setTransform( t1x );
|
||||||
|
|
||||||
int swidth = (int) scaledRect.width;
|
int swidth = (int) scaledRect.width;
|
||||||
int sheight = (int) scaledRect.height;
|
int sheight = (int) scaledRect.height;
|
||||||
|
|
||||||
// paint
|
// paint
|
||||||
painter.paint( g, 0, 0, swidth, sheight, transform.getScaleX() );
|
painter.paint( g, 0, 0, swidth, sheight, scaleX );
|
||||||
} finally {
|
} finally {
|
||||||
// restore original transform
|
// restore original transform
|
||||||
g.setTransform( transform );
|
g.setTransform( t );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,20 +105,16 @@ public class HiDPIUtils
|
|||||||
* sun.java2d.pipe.PixelToParallelogramConverter.fillRectangle(),
|
* sun.java2d.pipe.PixelToParallelogramConverter.fillRectangle(),
|
||||||
* which is used by Graphics.fillRect().
|
* which is used by Graphics.fillRect().
|
||||||
*/
|
*/
|
||||||
private static Rectangle2D.Double scale( AffineTransform transform, int x, int y, int width, int height ) {
|
private static Rectangle2D.Double scale( double scaleX, double scaleY, AffineTransform t, int x, int y, int width, int height ) {
|
||||||
double dx1 = transform.getScaleX();
|
double px = (x * scaleX) + t.getTranslateX();
|
||||||
double dy2 = transform.getScaleY();
|
double py = (y * scaleY) + t.getTranslateY();
|
||||||
double px = x * dx1 + transform.getTranslateX();
|
|
||||||
double py = y * dy2 + transform.getTranslateY();
|
|
||||||
dx1 *= width;
|
|
||||||
dy2 *= height;
|
|
||||||
|
|
||||||
double newx = normalize( px );
|
double newX = normalize( px );
|
||||||
double newy = normalize( py );
|
double newY = normalize( py );
|
||||||
dx1 = normalize( px + dx1 ) - newx;
|
double newWidth = normalize( px + (width * scaleX) ) - newX;
|
||||||
dy2 = normalize( py + dy2 ) - newy;
|
double newHeight = normalize( py + (height * scaleY) ) - newY;
|
||||||
|
|
||||||
return new Rectangle2D.Double( newx, newy, dx1, dy2 );
|
return new Rectangle2D.Double( newX, newY, newWidth, newHeight );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static double normalize( double value ) {
|
private static double normalize( double value ) {
|
||||||
|
|||||||
@@ -19,8 +19,9 @@ package com.formdev.flatlaf.util;
|
|||||||
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.lang.reflect.InvocationTargetException;
|
import java.lang.invoke.MethodHandle;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.invoke.MethodHandles;
|
||||||
|
import java.lang.invoke.MethodType;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -32,8 +33,8 @@ import javax.swing.JComponent;
|
|||||||
*/
|
*/
|
||||||
public class JavaCompatibility
|
public class JavaCompatibility
|
||||||
{
|
{
|
||||||
private static Method drawStringUnderlineCharAtMethod;
|
private static MethodHandle drawStringUnderlineCharAtMethod;
|
||||||
private static Method getClippedStringMethod;
|
private static MethodHandle getClippedStringMethod;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Java 8: sun.swing.SwingUtilities2.drawStringUnderlineCharAt( JComponent c,
|
* Java 8: sun.swing.SwingUtilities2.drawStringUnderlineCharAt( JComponent c,
|
||||||
@@ -51,9 +52,10 @@ public class JavaCompatibility
|
|||||||
Class<?> cls = Class.forName( SystemInfo.isJava_9_orLater
|
Class<?> cls = Class.forName( SystemInfo.isJava_9_orLater
|
||||||
? "javax.swing.plaf.basic.BasicGraphicsUtils"
|
? "javax.swing.plaf.basic.BasicGraphicsUtils"
|
||||||
: "sun.swing.SwingUtilities2" );
|
: "sun.swing.SwingUtilities2" );
|
||||||
drawStringUnderlineCharAtMethod = cls.getMethod( "drawStringUnderlineCharAt", SystemInfo.isJava_9_orLater
|
MethodType mt = MethodType.methodType( void.class, SystemInfo.isJava_9_orLater
|
||||||
? new Class[] { JComponent.class, Graphics2D.class, String.class, int.class, float.class, float.class }
|
? new Class[] { JComponent.class, Graphics2D.class, String.class, int.class, float.class, float.class }
|
||||||
: new Class[] { JComponent.class, Graphics.class, String.class, int.class, int.class, int.class } );
|
: new Class[] { JComponent.class, Graphics.class, String.class, int.class, int.class, int.class } );
|
||||||
|
drawStringUnderlineCharAtMethod = MethodHandles.publicLookup().findStatic( cls, "drawStringUnderlineCharAt", mt );
|
||||||
} catch( Exception ex ) {
|
} catch( Exception ex ) {
|
||||||
LoggingFacade.INSTANCE.logSevere( null, ex );
|
LoggingFacade.INSTANCE.logSevere( null, ex );
|
||||||
throw new RuntimeException( ex );
|
throw new RuntimeException( ex );
|
||||||
@@ -63,10 +65,10 @@ public class JavaCompatibility
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if( SystemInfo.isJava_9_orLater )
|
if( SystemInfo.isJava_9_orLater )
|
||||||
drawStringUnderlineCharAtMethod.invoke( null, c, g, text, underlinedIndex, (float) x, (float) y );
|
drawStringUnderlineCharAtMethod.invoke( c, (Graphics2D) g, text, underlinedIndex, (float) x, (float) y );
|
||||||
else
|
else
|
||||||
drawStringUnderlineCharAtMethod.invoke( null, c, g, text, underlinedIndex, x, y );
|
drawStringUnderlineCharAtMethod.invoke( c, g, text, underlinedIndex, x, y );
|
||||||
} catch( IllegalAccessException | IllegalArgumentException | InvocationTargetException ex ) {
|
} catch( Throwable ex ) {
|
||||||
LoggingFacade.INSTANCE.logSevere( null, ex );
|
LoggingFacade.INSTANCE.logSevere( null, ex );
|
||||||
throw new RuntimeException( ex );
|
throw new RuntimeException( ex );
|
||||||
}
|
}
|
||||||
@@ -86,10 +88,11 @@ public class JavaCompatibility
|
|||||||
Class<?> cls = Class.forName( SystemInfo.isJava_9_orLater
|
Class<?> cls = Class.forName( SystemInfo.isJava_9_orLater
|
||||||
? "javax.swing.plaf.basic.BasicGraphicsUtils"
|
? "javax.swing.plaf.basic.BasicGraphicsUtils"
|
||||||
: "sun.swing.SwingUtilities2" );
|
: "sun.swing.SwingUtilities2" );
|
||||||
getClippedStringMethod = cls.getMethod( SystemInfo.isJava_9_orLater
|
MethodType mt = MethodType.methodType( String.class, JComponent.class, FontMetrics.class, String.class, int.class );
|
||||||
|
getClippedStringMethod = MethodHandles.publicLookup().findStatic( cls, SystemInfo.isJava_9_orLater
|
||||||
? "getClippedString"
|
? "getClippedString"
|
||||||
: "clipStringIfNecessary",
|
: "clipStringIfNecessary",
|
||||||
JComponent.class, FontMetrics.class, String.class, int.class );
|
mt );
|
||||||
} catch( Exception ex ) {
|
} catch( Exception ex ) {
|
||||||
LoggingFacade.INSTANCE.logSevere( null, ex );
|
LoggingFacade.INSTANCE.logSevere( null, ex );
|
||||||
throw new RuntimeException( ex );
|
throw new RuntimeException( ex );
|
||||||
@@ -98,8 +101,8 @@ public class JavaCompatibility
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return (String) getClippedStringMethod.invoke( null, c, fm, string, availTextWidth );
|
return (String) getClippedStringMethod.invoke( c, fm, string, availTextWidth );
|
||||||
} catch( IllegalAccessException | IllegalArgumentException | InvocationTargetException ex ) {
|
} catch( Throwable ex ) {
|
||||||
LoggingFacade.INSTANCE.logSevere( null, ex );
|
LoggingFacade.INSTANCE.logSevere( null, ex );
|
||||||
throw new RuntimeException( ex );
|
throw new RuntimeException( ex );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,6 +73,22 @@ public class NativeLibrary
|
|||||||
: false;
|
: false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load native library using {@link System#loadLibrary(String)}.
|
||||||
|
* Searches for the library in classloader of caller
|
||||||
|
* (using {@link ClassLoader#findLibrary(String)}) and in paths specified
|
||||||
|
* in system properties {@code sun.boot.library.path} and {@code java.library.path}.
|
||||||
|
*
|
||||||
|
* @param libraryName name of the native library (without "lib" prefix and without extension)
|
||||||
|
* @param supported whether the native library is supported on the current platform
|
||||||
|
* @since 2.6
|
||||||
|
*/
|
||||||
|
public NativeLibrary( String libraryName, boolean supported ) {
|
||||||
|
this.loaded = supported
|
||||||
|
? loadLibraryFromSystem( libraryName )
|
||||||
|
: false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the native library is loaded.
|
* Returns whether the native library is loaded.
|
||||||
* <p>
|
* <p>
|
||||||
@@ -92,7 +108,7 @@ public class NativeLibrary
|
|||||||
? classLoader.getResource( libraryName )
|
? classLoader.getResource( libraryName )
|
||||||
: NativeLibrary.class.getResource( "/" + libraryName );
|
: NativeLibrary.class.getResource( "/" + libraryName );
|
||||||
if( libraryUrl == null ) {
|
if( libraryUrl == null ) {
|
||||||
log( "Library '" + libraryName + "' not found", null );
|
LoggingFacade.INSTANCE.logSevere( "Library '" + libraryName + "' not found", null );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,7 +141,7 @@ public class NativeLibrary
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch( Throwable ex ) {
|
} catch( Throwable ex ) {
|
||||||
log( null, ex );
|
LoggingFacade.INSTANCE.logSevere( ex.getMessage(), ex );
|
||||||
|
|
||||||
if( tempFile != null )
|
if( tempFile != null )
|
||||||
deleteOrMarkForDeletion( tempFile );
|
deleteOrMarkForDeletion( tempFile );
|
||||||
@@ -138,7 +154,24 @@ public class NativeLibrary
|
|||||||
System.load( libraryFile.getAbsolutePath() );
|
System.load( libraryFile.getAbsolutePath() );
|
||||||
return true;
|
return true;
|
||||||
} catch( Throwable ex ) {
|
} catch( Throwable ex ) {
|
||||||
log( null, ex );
|
LoggingFacade.INSTANCE.logSevere( ex.getMessage(), ex );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean loadLibraryFromSystem( String libraryName ) {
|
||||||
|
try {
|
||||||
|
System.loadLibrary( libraryName );
|
||||||
|
return true;
|
||||||
|
} catch( Throwable ex ) {
|
||||||
|
String message = ex.getMessage();
|
||||||
|
|
||||||
|
// do not log error if library was not found
|
||||||
|
// thrown in ClassLoader.loadLibrary(Class<?> fromClass, String name, boolean isAbsolute)
|
||||||
|
if( ex instanceof UnsatisfiedLinkError && message != null && message.contains( "java.library.path" ) )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
LoggingFacade.INSTANCE.logSevere( message, ex );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -158,10 +191,6 @@ public class NativeLibrary
|
|||||||
: System.mapLibraryName( libraryName );
|
: System.mapLibraryName( libraryName );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void log( String msg, Throwable thrown ) {
|
|
||||||
LoggingFacade.INSTANCE.logSevere( msg, thrown );
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Path createTempFile( String libraryName ) throws IOException {
|
private static Path createTempFile( String libraryName ) throws IOException {
|
||||||
int sep = libraryName.lastIndexOf( '/' );
|
int sep = libraryName.lastIndexOf( '/' );
|
||||||
String name = (sep >= 0) ? libraryName.substring( sep + 1 ) : libraryName;
|
String name = (sep >= 0) ? libraryName.substring( sep + 1 ) : libraryName;
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.formdev.flatlaf.util;
|
package com.formdev.flatlaf.util;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
@@ -102,6 +103,13 @@ debug*/
|
|||||||
int imageWidth = image.getWidth( null );
|
int imageWidth = image.getWidth( null );
|
||||||
int imageHeight = image.getHeight( null );
|
int imageHeight = image.getHeight( null );
|
||||||
|
|
||||||
|
// paint red rectangle if image has invalid size (e.g. not found)
|
||||||
|
if( imageWidth < 0 || imageHeight < 0 ) {
|
||||||
|
g.setColor( Color.red );
|
||||||
|
g.fillRect( x, y, getIconWidth(), getIconHeight() );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// scale image if necessary to destination size
|
// scale image if necessary to destination size
|
||||||
if( imageWidth != destImageWidth || imageHeight != destImageHeight ) {
|
if( imageWidth != destImageWidth || imageHeight != destImageHeight ) {
|
||||||
// determine scaling method; default is "quality"
|
// determine scaling method; default is "quality"
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ public class SystemInfo
|
|||||||
public static final long javaVersion;
|
public static final long javaVersion;
|
||||||
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;
|
||||||
|
/** @since 2.3 */ public static final boolean isJava_12_orLater;
|
||||||
public static final boolean isJava_15_orLater;
|
public static final boolean isJava_15_orLater;
|
||||||
/** @since 2 */ public static final boolean isJava_17_orLater;
|
/** @since 2 */ public static final boolean isJava_17_orLater;
|
||||||
/** @since 2 */ public static final boolean isJava_18_orLater;
|
/** @since 2 */ public static final boolean isJava_18_orLater;
|
||||||
@@ -66,6 +67,9 @@ public class SystemInfo
|
|||||||
/** @since 1.1.2 */ public static final boolean isWebswing;
|
/** @since 1.1.2 */ public static final boolean isWebswing;
|
||||||
/** @since 1.1.1 */ public static final boolean isWinPE;
|
/** @since 1.1.1 */ public static final boolean isWinPE;
|
||||||
|
|
||||||
|
// features
|
||||||
|
/** @since 2.3 */ public static final boolean isMacFullWindowContentSupported;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
// platforms
|
// platforms
|
||||||
String osName = System.getProperty( "os.name" ).toLowerCase( Locale.ENGLISH );
|
String osName = System.getProperty( "os.name" ).toLowerCase( Locale.ENGLISH );
|
||||||
@@ -92,6 +96,7 @@ public class SystemInfo
|
|||||||
javaVersion = scanVersion( System.getProperty( "java.version" ) );
|
javaVersion = scanVersion( System.getProperty( "java.version" ) );
|
||||||
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_12_orLater = (javaVersion >= toVersion( 12, 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 ));
|
isJava_17_orLater = (javaVersion >= toVersion( 17, 0, 0, 0 ));
|
||||||
isJava_18_orLater = (javaVersion >= toVersion( 18, 0, 0, 0 ));
|
isJava_18_orLater = (javaVersion >= toVersion( 18, 0, 0, 0 ));
|
||||||
@@ -108,6 +113,12 @@ public class SystemInfo
|
|||||||
isProjector = Boolean.getBoolean( "org.jetbrains.projector.server.enable" );
|
isProjector = Boolean.getBoolean( "org.jetbrains.projector.server.enable" );
|
||||||
isWebswing = (System.getProperty( "webswing.rootDir" ) != null);
|
isWebswing = (System.getProperty( "webswing.rootDir" ) != null);
|
||||||
isWinPE = isWindows && "X:\\Windows\\System32".equalsIgnoreCase( System.getProperty( "user.dir" ) );
|
isWinPE = isWindows && "X:\\Windows\\System32".equalsIgnoreCase( System.getProperty( "user.dir" ) );
|
||||||
|
|
||||||
|
// features
|
||||||
|
// available since Java 12; backported to Java 11.0.8 and 8u292
|
||||||
|
isMacFullWindowContentSupported =
|
||||||
|
javaVersion >= toVersion( 11, 0, 8, 0 ) ||
|
||||||
|
(javaVersion >= toVersion( 1, 8, 0, 292 ) && !isJava_9_orLater);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long scanVersion( String version ) {
|
public static long scanVersion( String version ) {
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ light.font = +0
|
|||||||
semibold.font = +0
|
semibold.font = +0
|
||||||
|
|
||||||
# monospaced
|
# monospaced
|
||||||
[win]monospaced.font = Consolas, "Courier New", Monospaced
|
[win]monospaced.font = Monospaced
|
||||||
[mac]monospaced.font = Menlo, Monospaced
|
[mac]monospaced.font = Menlo, Monospaced
|
||||||
[linux]monospaced.font = "Liberation Mono", "Ubuntu Mono", Monospaced
|
[linux]monospaced.font = "Liberation Mono", "Ubuntu Mono", Monospaced
|
||||||
monospaced.font = Monospaced
|
monospaced.font = Monospaced
|
||||||
@@ -442,8 +442,8 @@ 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
|
||||||
MenuItem.underlineSelectionBackground = @menuHoverBackground
|
MenuItem.underlineSelectionBackground = @menuHoverBackground
|
||||||
@@ -785,15 +785,21 @@ TitlePane.useWindowDecorations = true
|
|||||||
TitlePane.menuBarEmbedded = true
|
TitlePane.menuBarEmbedded = true
|
||||||
TitlePane.unifiedBackground = true
|
TitlePane.unifiedBackground = true
|
||||||
TitlePane.showIcon = true
|
TitlePane.showIcon = true
|
||||||
|
TitlePane.showIconInDialogs = true
|
||||||
TitlePane.noIconLeftGap = 8
|
TitlePane.noIconLeftGap = 8
|
||||||
TitlePane.iconSize = 16,16
|
TitlePane.iconSize = 16,16
|
||||||
TitlePane.iconMargins = 3,8,3,8
|
TitlePane.iconMargins = 3,8,3,8
|
||||||
TitlePane.titleMargins = 3,0,3,0
|
TitlePane.titleMargins = 3,0,3,0
|
||||||
|
TitlePane.titleMinimumWidth = 60
|
||||||
TitlePane.buttonSize = 44,30
|
TitlePane.buttonSize = 44,30
|
||||||
|
TitlePane.buttonMinimumWidth = 30
|
||||||
TitlePane.buttonMaximizedHeight = 22
|
TitlePane.buttonMaximizedHeight = 22
|
||||||
TitlePane.centerTitle = false
|
TitlePane.centerTitle = false
|
||||||
TitlePane.centerTitleIfMenuBarEmbedded = true
|
TitlePane.centerTitleIfMenuBarEmbedded = true
|
||||||
TitlePane.menuBarTitleGap = 20
|
TitlePane.showIconBesideTitle = false
|
||||||
|
TitlePane.menuBarTitleGap = 40
|
||||||
|
TitlePane.menuBarTitleMinimumGap = 12
|
||||||
|
TitlePane.menuBarResizeHeight = 4
|
||||||
TitlePane.closeIcon = com.formdev.flatlaf.icons.FlatWindowCloseIcon
|
TitlePane.closeIcon = com.formdev.flatlaf.icons.FlatWindowCloseIcon
|
||||||
TitlePane.iconifyIcon = com.formdev.flatlaf.icons.FlatWindowIconifyIcon
|
TitlePane.iconifyIcon = com.formdev.flatlaf.icons.FlatWindowIconifyIcon
|
||||||
TitlePane.maximizeIcon = com.formdev.flatlaf.icons.FlatWindowMaximizeIcon
|
TitlePane.maximizeIcon = com.formdev.flatlaf.icons.FlatWindowMaximizeIcon
|
||||||
@@ -829,6 +835,7 @@ ToggleButton.tab.underlineHeight = 2
|
|||||||
ToggleButton.tab.underlineColor = $TabbedPane.underlineColor
|
ToggleButton.tab.underlineColor = $TabbedPane.underlineColor
|
||||||
ToggleButton.tab.disabledUnderlineColor = $TabbedPane.disabledUnderlineColor
|
ToggleButton.tab.disabledUnderlineColor = $TabbedPane.disabledUnderlineColor
|
||||||
ToggleButton.tab.selectedBackground = $?TabbedPane.selectedBackground
|
ToggleButton.tab.selectedBackground = $?TabbedPane.selectedBackground
|
||||||
|
ToggleButton.tab.selectedForeground = $?TabbedPane.selectedForeground
|
||||||
ToggleButton.tab.hoverBackground = $TabbedPane.hoverColor
|
ToggleButton.tab.hoverBackground = $TabbedPane.hoverColor
|
||||||
ToggleButton.tab.focusBackground = $TabbedPane.focusColor
|
ToggleButton.tab.focusBackground = $TabbedPane.focusColor
|
||||||
|
|
||||||
|
|||||||
@@ -201,6 +201,8 @@ ToggleButton.endBackground = $ToggleButton.background
|
|||||||
[Monocai]RadioButtonMenuItem.acceleratorForeground = @Monocai.acceleratorForeground
|
[Monocai]RadioButtonMenuItem.acceleratorForeground = @Monocai.acceleratorForeground
|
||||||
[Monocai]RadioButtonMenuItem.acceleratorSelectionForeground = @Monocai.acceleratorSelectionForeground
|
[Monocai]RadioButtonMenuItem.acceleratorSelectionForeground = @Monocai.acceleratorSelectionForeground
|
||||||
|
|
||||||
|
[Monokai_Pro]TitledBorder.titleColor = @foreground
|
||||||
|
|
||||||
[Nord]MenuItem.checkBackground = @ijMenuCheckBackgroundL10
|
[Nord]MenuItem.checkBackground = @ijMenuCheckBackgroundL10
|
||||||
[Nord]MenuItem.underlineSelectionCheckBackground = @ijMenuCheckBackgroundL10
|
[Nord]MenuItem.underlineSelectionCheckBackground = @ijMenuCheckBackgroundL10
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
@@ -0,0 +1,65 @@
|
|||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
|
||||||
|
#---- FileChooser ----
|
||||||
|
|
||||||
|
#fields
|
||||||
|
FileChooser.lookInLabel.textAndMnemonic = Buscar &en:
|
||||||
|
FileChooser.saveInLabelText = Guardar en:
|
||||||
|
FileChooser.fileNameLabel.textAndMnemonic = &Nombre de fichero:
|
||||||
|
FileChooser.folderNameLabel.textAndMnemonic = &Nombre de carpeta:
|
||||||
|
FileChooser.filesOfTypeLabel.textAndMnemonic = Ficheros de &Tipo:
|
||||||
|
|
||||||
|
# toolbar
|
||||||
|
FileChooser.upFolderToolTipText = Subir un nivel
|
||||||
|
FileChooser.upFolderAccessibleName = Subir
|
||||||
|
FileChooser.homeFolderToolTipText = Inicio
|
||||||
|
FileChooser.homeFolderAccessibleName = Inicio
|
||||||
|
FileChooser.newFolderToolTipText = Crear nueva carpeta
|
||||||
|
FileChooser.newFolderAccessibleName = Nueva carpeta
|
||||||
|
FileChooser.listViewButtonToolTipText = Lista
|
||||||
|
FileChooser.listViewButtonAccessibleName = Lista
|
||||||
|
FileChooser.detailsViewButtonToolTipText = Detalles
|
||||||
|
FileChooser.detailsViewButtonAccessibleName = Detalles
|
||||||
|
|
||||||
|
# details table header
|
||||||
|
FileChooser.fileNameHeaderText = Nombre
|
||||||
|
FileChooser.fileSizeHeaderText = Tama\u00F1o
|
||||||
|
FileChooser.fileTypeHeaderText = Tipo
|
||||||
|
FileChooser.fileDateHeaderText = Modificado
|
||||||
|
FileChooser.fileAttrHeaderText = Atributos
|
||||||
|
|
||||||
|
# popup menu
|
||||||
|
FileChooser.viewMenuLabelText = Ver
|
||||||
|
FileChooser.refreshActionLabelText = Refrescar
|
||||||
|
FileChooser.newFolderActionLabelText = Nueva carpeta
|
||||||
|
FileChooser.listViewActionLabelText = Lista
|
||||||
|
FileChooser.detailsViewActionLabelText = Detalles
|
||||||
|
|
||||||
|
|
||||||
|
#---- SplitPaneDivider ----
|
||||||
|
|
||||||
|
SplitPaneDivider.collapseLeftToolTipText = Contraer Panel Izquierdo
|
||||||
|
SplitPaneDivider.collapseRightToolTipText = Contraer panel Derecho
|
||||||
|
SplitPaneDivider.collapseTopToolTipText = Contraer panel Superior
|
||||||
|
SplitPaneDivider.collapseBottomToolTipText = Contraer Panel Inferior
|
||||||
|
SplitPaneDivider.expandLeftToolTipText = Expandir Panel Izquierdo
|
||||||
|
SplitPaneDivider.expandRightToolTipText = Expandir Panel Derecho
|
||||||
|
SplitPaneDivider.expandTopToolTipText = Expandir Panel Superior
|
||||||
|
SplitPaneDivider.expandBottomToolTipText = Expandir Panel Inferior
|
||||||
|
|
||||||
|
|
||||||
|
#---- TabbedPane ----
|
||||||
|
|
||||||
|
TabbedPane.moreTabsButtonToolTipText = Mostrar Pesta\u00F1as Ocultas
|
||||||
@@ -96,19 +96,26 @@ public class TestFlatStyleableInfo
|
|||||||
"minimumWidth", int.class,
|
"minimumWidth", int.class,
|
||||||
|
|
||||||
"focusedBackground", Color.class,
|
"focusedBackground", Color.class,
|
||||||
|
"focusedForeground", Color.class,
|
||||||
"hoverBackground", Color.class,
|
"hoverBackground", Color.class,
|
||||||
|
"hoverForeground", Color.class,
|
||||||
"pressedBackground", Color.class,
|
"pressedBackground", Color.class,
|
||||||
|
"pressedForeground", Color.class,
|
||||||
"selectedBackground", Color.class,
|
"selectedBackground", Color.class,
|
||||||
"selectedForeground", Color.class,
|
"selectedForeground", Color.class,
|
||||||
"disabledBackground", Color.class,
|
"disabledBackground", Color.class,
|
||||||
"disabledText", Color.class,
|
"disabledText", Color.class,
|
||||||
"disabledSelectedBackground", Color.class,
|
"disabledSelectedBackground", Color.class,
|
||||||
|
"disabledSelectedForeground", Color.class,
|
||||||
|
|
||||||
"default.background", Color.class,
|
"default.background", Color.class,
|
||||||
"default.foreground", Color.class,
|
"default.foreground", Color.class,
|
||||||
"default.focusedBackground", Color.class,
|
"default.focusedBackground", Color.class,
|
||||||
|
"default.focusedForeground", Color.class,
|
||||||
"default.hoverBackground", Color.class,
|
"default.hoverBackground", Color.class,
|
||||||
|
"default.hoverForeground", Color.class,
|
||||||
"default.pressedBackground", Color.class,
|
"default.pressedBackground", Color.class,
|
||||||
|
"default.pressedForeground", Color.class,
|
||||||
"default.boldText", boolean.class,
|
"default.boldText", boolean.class,
|
||||||
|
|
||||||
"paintShadow", boolean.class,
|
"paintShadow", boolean.class,
|
||||||
@@ -118,8 +125,13 @@ public class TestFlatStyleableInfo
|
|||||||
|
|
||||||
"toolbar.spacingInsets", Insets.class,
|
"toolbar.spacingInsets", Insets.class,
|
||||||
"toolbar.hoverBackground", Color.class,
|
"toolbar.hoverBackground", Color.class,
|
||||||
|
"toolbar.hoverForeground", Color.class,
|
||||||
"toolbar.pressedBackground", Color.class,
|
"toolbar.pressedBackground", Color.class,
|
||||||
|
"toolbar.pressedForeground", Color.class,
|
||||||
"toolbar.selectedBackground", Color.class,
|
"toolbar.selectedBackground", Color.class,
|
||||||
|
"toolbar.selectedForeground", Color.class,
|
||||||
|
"toolbar.disabledSelectedBackground", Color.class,
|
||||||
|
"toolbar.disabledSelectedForeground", Color.class,
|
||||||
|
|
||||||
"buttonType", String.class,
|
"buttonType", String.class,
|
||||||
"squareSize", boolean.class,
|
"squareSize", boolean.class,
|
||||||
@@ -272,6 +284,8 @@ public class TestFlatStyleableInfo
|
|||||||
Map<String, Class<?>> expected = expectedMap(
|
Map<String, Class<?>> expected = expectedMap(
|
||||||
"itemMargins", Insets.class,
|
"itemMargins", Insets.class,
|
||||||
"hoverBackground", Color.class,
|
"hoverBackground", Color.class,
|
||||||
|
"selectionBackground", Color.class,
|
||||||
|
"selectionForeground", Color.class,
|
||||||
"underlineSelectionBackground", Color.class,
|
"underlineSelectionBackground", Color.class,
|
||||||
"underlineSelectionColor", Color.class,
|
"underlineSelectionColor", Color.class,
|
||||||
"underlineSelectionHeight", int.class,
|
"underlineSelectionHeight", int.class,
|
||||||
@@ -710,6 +724,7 @@ public class TestFlatStyleableInfo
|
|||||||
"tabSeparatorsFullHeight", boolean.class,
|
"tabSeparatorsFullHeight", boolean.class,
|
||||||
"hasFullBorder", boolean.class,
|
"hasFullBorder", boolean.class,
|
||||||
"tabsOpaque", boolean.class,
|
"tabsOpaque", boolean.class,
|
||||||
|
"rotateTabRuns", boolean.class,
|
||||||
|
|
||||||
"tabType", String.class,
|
"tabType", String.class,
|
||||||
"tabsPopupPolicy", String.class,
|
"tabsPopupPolicy", String.class,
|
||||||
@@ -863,8 +878,11 @@ public class TestFlatStyleableInfo
|
|||||||
"tab.underlineColor", Color.class,
|
"tab.underlineColor", Color.class,
|
||||||
"tab.disabledUnderlineColor", Color.class,
|
"tab.disabledUnderlineColor", Color.class,
|
||||||
"tab.selectedBackground", Color.class,
|
"tab.selectedBackground", Color.class,
|
||||||
|
"tab.selectedForeground", Color.class,
|
||||||
"tab.hoverBackground", Color.class,
|
"tab.hoverBackground", Color.class,
|
||||||
"tab.focusBackground", Color.class
|
"tab.hoverForeground", Color.class,
|
||||||
|
"tab.focusBackground", Color.class,
|
||||||
|
"tab.focusForeground", Color.class
|
||||||
);
|
);
|
||||||
|
|
||||||
// FlatToggleButtonUI extends FlatButtonUI
|
// FlatToggleButtonUI extends FlatButtonUI
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -221,19 +221,26 @@ public class TestFlatStyling
|
|||||||
ui.applyStyle( b, "minimumWidth: 100" );
|
ui.applyStyle( b, "minimumWidth: 100" );
|
||||||
|
|
||||||
ui.applyStyle( b, "focusedBackground: #fff" );
|
ui.applyStyle( b, "focusedBackground: #fff" );
|
||||||
|
ui.applyStyle( b, "focusedForeground: #fff" );
|
||||||
ui.applyStyle( b, "hoverBackground: #fff" );
|
ui.applyStyle( b, "hoverBackground: #fff" );
|
||||||
|
ui.applyStyle( b, "hoverForeground: #fff" );
|
||||||
ui.applyStyle( b, "pressedBackground: #fff" );
|
ui.applyStyle( b, "pressedBackground: #fff" );
|
||||||
|
ui.applyStyle( b, "pressedForeground: #fff" );
|
||||||
ui.applyStyle( b, "selectedBackground: #fff" );
|
ui.applyStyle( b, "selectedBackground: #fff" );
|
||||||
ui.applyStyle( b, "selectedForeground: #fff" );
|
ui.applyStyle( b, "selectedForeground: #fff" );
|
||||||
ui.applyStyle( b, "disabledBackground: #fff" );
|
ui.applyStyle( b, "disabledBackground: #fff" );
|
||||||
ui.applyStyle( b, "disabledText: #fff" );
|
ui.applyStyle( b, "disabledText: #fff" );
|
||||||
ui.applyStyle( b, "disabledSelectedBackground: #fff" );
|
ui.applyStyle( b, "disabledSelectedBackground: #fff" );
|
||||||
|
ui.applyStyle( b, "disabledSelectedForeground: #fff" );
|
||||||
|
|
||||||
ui.applyStyle( b, "default.background: #fff" );
|
ui.applyStyle( b, "default.background: #fff" );
|
||||||
ui.applyStyle( b, "default.foreground: #fff" );
|
ui.applyStyle( b, "default.foreground: #fff" );
|
||||||
ui.applyStyle( b, "default.focusedBackground: #fff" );
|
ui.applyStyle( b, "default.focusedBackground: #fff" );
|
||||||
|
ui.applyStyle( b, "default.focusedForeground: #fff" );
|
||||||
ui.applyStyle( b, "default.hoverBackground: #fff" );
|
ui.applyStyle( b, "default.hoverBackground: #fff" );
|
||||||
|
ui.applyStyle( b, "default.hoverForeground: #fff" );
|
||||||
ui.applyStyle( b, "default.pressedBackground: #fff" );
|
ui.applyStyle( b, "default.pressedBackground: #fff" );
|
||||||
|
ui.applyStyle( b, "default.pressedForeground: #fff" );
|
||||||
ui.applyStyle( b, "default.boldText: true" );
|
ui.applyStyle( b, "default.boldText: true" );
|
||||||
|
|
||||||
ui.applyStyle( b, "paintShadow: true" );
|
ui.applyStyle( b, "paintShadow: true" );
|
||||||
@@ -243,8 +250,13 @@ public class TestFlatStyling
|
|||||||
|
|
||||||
ui.applyStyle( b, "toolbar.spacingInsets: 1,2,3,4" );
|
ui.applyStyle( b, "toolbar.spacingInsets: 1,2,3,4" );
|
||||||
ui.applyStyle( b, "toolbar.hoverBackground: #fff" );
|
ui.applyStyle( b, "toolbar.hoverBackground: #fff" );
|
||||||
|
ui.applyStyle( b, "toolbar.hoverForeground: #fff" );
|
||||||
ui.applyStyle( b, "toolbar.pressedBackground: #fff" );
|
ui.applyStyle( b, "toolbar.pressedBackground: #fff" );
|
||||||
|
ui.applyStyle( b, "toolbar.pressedForeground: #fff" );
|
||||||
ui.applyStyle( b, "toolbar.selectedBackground: #fff" );
|
ui.applyStyle( b, "toolbar.selectedBackground: #fff" );
|
||||||
|
ui.applyStyle( b, "toolbar.selectedForeground: #fff" );
|
||||||
|
ui.applyStyle( b, "toolbar.disabledSelectedBackground: #fff" );
|
||||||
|
ui.applyStyle( b, "toolbar.disabledSelectedForeground: #fff" );
|
||||||
|
|
||||||
ui.applyStyle( b, "buttonType: help" );
|
ui.applyStyle( b, "buttonType: help" );
|
||||||
ui.applyStyle( b, "squareSize: true" );
|
ui.applyStyle( b, "squareSize: true" );
|
||||||
@@ -424,6 +436,8 @@ public class TestFlatStyling
|
|||||||
|
|
||||||
ui.applyStyle( "itemMargins: 1,2,3,4" );
|
ui.applyStyle( "itemMargins: 1,2,3,4" );
|
||||||
ui.applyStyle( "hoverBackground: #fff" );
|
ui.applyStyle( "hoverBackground: #fff" );
|
||||||
|
ui.applyStyle( "selectionBackground: #fff" );
|
||||||
|
ui.applyStyle( "selectionForeground: #fff" );
|
||||||
ui.applyStyle( "underlineSelectionBackground: #fff" );
|
ui.applyStyle( "underlineSelectionBackground: #fff" );
|
||||||
ui.applyStyle( "underlineSelectionColor: #fff" );
|
ui.applyStyle( "underlineSelectionColor: #fff" );
|
||||||
ui.applyStyle( "underlineSelectionHeight: 3" );
|
ui.applyStyle( "underlineSelectionHeight: 3" );
|
||||||
@@ -879,6 +893,7 @@ public class TestFlatStyling
|
|||||||
ui.applyStyle( "tabSeparatorsFullHeight: false" );
|
ui.applyStyle( "tabSeparatorsFullHeight: false" );
|
||||||
ui.applyStyle( "hasFullBorder: false" );
|
ui.applyStyle( "hasFullBorder: false" );
|
||||||
ui.applyStyle( "tabsOpaque: false" );
|
ui.applyStyle( "tabsOpaque: false" );
|
||||||
|
ui.applyStyle( "rotateTabRuns: false" );
|
||||||
|
|
||||||
ui.applyStyle( "tabType: card" );
|
ui.applyStyle( "tabType: card" );
|
||||||
ui.applyStyle( "tabsPopupPolicy: asNeeded" );
|
ui.applyStyle( "tabsPopupPolicy: asNeeded" );
|
||||||
@@ -1073,8 +1088,11 @@ public class TestFlatStyling
|
|||||||
ui.applyStyle( b, "tab.underlineColor: #fff" );
|
ui.applyStyle( b, "tab.underlineColor: #fff" );
|
||||||
ui.applyStyle( b, "tab.disabledUnderlineColor: #fff" );
|
ui.applyStyle( b, "tab.disabledUnderlineColor: #fff" );
|
||||||
ui.applyStyle( b, "tab.selectedBackground: #fff" );
|
ui.applyStyle( b, "tab.selectedBackground: #fff" );
|
||||||
|
ui.applyStyle( b, "tab.selectedForeground: #fff" );
|
||||||
ui.applyStyle( b, "tab.hoverBackground: #fff" );
|
ui.applyStyle( b, "tab.hoverBackground: #fff" );
|
||||||
|
ui.applyStyle( b, "tab.hoverForeground: #fff" );
|
||||||
ui.applyStyle( b, "tab.focusBackground: #fff" );
|
ui.applyStyle( b, "tab.focusBackground: #fff" );
|
||||||
|
ui.applyStyle( b, "tab.focusForeground: #fff" );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
3
flatlaf-core/svg/ArrowButton-chevron.svg
Normal file
3
flatlaf-core/svg/ArrowButton-chevron.svg
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="8" height="4" viewBox="0 0 8 4">
|
||||||
|
<polyline fill="none" stroke="#6E6E6E" points="0 4 4 0 8 4"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 151 B |
3
flatlaf-core/svg/ArrowButton-triangle.svg
Normal file
3
flatlaf-core/svg/ArrowButton-triangle.svg
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="9" height="5" viewBox="0 0 9 5">
|
||||||
|
<polygon fill="#6E6E6E" fill-rule="evenodd" points="0 5 4.5 0 9 5"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 158 B |
3
flatlaf-core/svg/AscendingSortIcon-chevron.svg
Normal file
3
flatlaf-core/svg/AscendingSortIcon-chevron.svg
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="10" height="5" viewBox="0 0 10 5">
|
||||||
|
<polyline fill="none" stroke="#6E6E6E" points="1 4 5 0 9 4"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 153 B |
3
flatlaf-core/svg/AscendingSortIcon-triangle.svg
Normal file
3
flatlaf-core/svg/AscendingSortIcon-triangle.svg
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="10" height="5" viewBox="0 0 10 5">
|
||||||
|
<polygon fill="#6E6E6E" fill-rule="evenodd" points=".5 5 5 0 9.5 5"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 161 B |
Binary file not shown.
3
flatlaf-core/svg/MenuArrowIcon-chevron.svg
Normal file
3
flatlaf-core/svg/MenuArrowIcon-chevron.svg
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="6" height="10" viewBox="0 0 6 10">
|
||||||
|
<polyline fill="none" stroke="#6E6E6E" points="1 1 5 5 1 9"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 153 B |
3
flatlaf-core/svg/MenuArrowIcon-triangle.svg
Normal file
3
flatlaf-core/svg/MenuArrowIcon-triangle.svg
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="6" height="10" viewBox="0 0 6 10">
|
||||||
|
<polygon fill="#6E6E6E" fill-rule="evenodd" points="0 .5 5 5 0 9.5"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 161 B |
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user