Compare commits

...

103 Commits
0.34 ... 0.36

Author SHA1 Message Date
Karl Tauber
e7cdc9cf8c release 0.36 2020-06-09 12:33:27 +02:00
Karl Tauber
2443547b3b FlatTestFrame: removed no longer needed nested JRootPane (was used for UI inspector) 2020-06-08 16:03:04 +02:00
Karl Tauber
8424300b5f Demo: faster repainting when enabling/disabling components 2020-06-08 15:58:52 +02:00
Karl Tauber
81822cf7f6 Demo: added UI inspector 2020-06-08 15:45:19 +02:00
Karl Tauber
907956994f Extras: FlatInspector:
- do not increase inspection level when activated with keyboard shortcut
- added some javadoc
- added to CHANGELOG.md and flatlaf-extras/README.md
2020-06-08 15:44:52 +02:00
Karl Tauber
9246cc0607 Extras: added FlatInspector (moved from flatlaf-testing) 2020-06-08 15:03:34 +02:00
Karl Tauber
9f81d147d1 Demo on macOS: enabled screen menu bar by default, except if explicitly disabled 2020-06-08 14:29:47 +02:00
Karl Tauber
b9bd26b2fb FlatSVGIcon: support mapping custom colors 2020-06-08 14:11:06 +02:00
Karl Tauber
1838174678 added "use" tab to javadoc 2020-06-08 12:53:48 +02:00
Karl Tauber
2aad301938 Spinner: fixed arrow positions 2020-06-07 18:27:55 +02:00
Karl Tauber
e18e8e3158 Popup: made Popup.show(), hide() and component listener more robust when used in unusual ways (issue #106) 2020-06-07 15:25:11 +02:00
Karl Tauber
049dae6584 Button: support non-square icon-only buttons (issue #110) 2020-06-03 15:55:14 +02:00
Karl Tauber
6a8bf2acc5 FlatInspector: fixed highlight figure bounds of windows; limit used inspection level to existing components 2020-06-02 16:07:11 +02:00
Karl Tauber
c45a769aa3 update JFrame/JDialog background color when switching Laf 2020-06-02 15:46:36 +02:00
Karl Tauber
e0b0617ad2 macOS Catalina: Use Helvetica Neue font 2020-05-30 21:44:52 +02:00
Karl Tauber
14ec6f6471 FlatInspector: increase/decrease inspection level with Ctrl/Shift keys 2020-05-30 17:35:54 +02:00
Karl Tauber
c4a1341aa9 FlatInspector:
- support ending inspection with ESC key
- inspect component at current mouse location when enabling inspector
2020-05-30 16:53:20 +02:00
Karl Tauber
fc68dfd7bc FlatInspector: support inspecting whole window including menubar and custom window decoration 2020-05-30 15:19:07 +02:00
Karl Tauber
b203ad63ee IntelliJ Themes: updated themes to newest versions (used IJThemesUpdater) 2020-05-28 12:17:46 +02:00
Karl Tauber
a560be11ed InternalFrame: renamed FlatInternalFrameMinimizeIcon to FlatInternalFrameRestoreIcon; added some missing @uiDefault to internal frame icons 2020-05-28 11:50:34 +02:00
Karl Tauber
ebd6375672 Spinner: optimized up/down chevron arrow positions 2020-05-25 13:05:59 +02:00
Karl Tauber
502731d3b0 Spinner: optimized up/down arrow positions 2020-05-24 19:05:28 +02:00
Karl Tauber
283535c429 Demo: use Command modifier to change font size on macOS 2020-05-24 15:26:54 +02:00
Karl Tauber
5cef1f6730 Testing: added font size spinner to control bar; also support Ctrl+0, Ctrl++ and Ctrl+- to change font size 2020-05-24 15:26:07 +02:00
Karl Tauber
7d14fbe739 Testing: do not fail startup when LaF initialization throws UnsupportedClassVersionError (may occur when switching from Java 9+ to Java 8) 2020-05-24 14:48:05 +02:00
Karl Tauber
e9e1e350eb Spinner:
- repaint if JSpinner component gained/lost focus
- paint focus border if JSpinner component is focused
- if spinner gained focus, transfer it to the editor text field
2020-05-24 14:44:36 +02:00
Karl Tauber
566e42cc40 revalidate layout when minimum width client property is changed 2020-05-23 22:57:39 +02:00
Karl Tauber
0abfb5922a ComboBox: minimum width is now 72 pixels (was ~50 for non-editable and ~130 for editable comboboxes) 2020-05-23 22:25:18 +02:00
Karl Tauber
4af8d2f1c5 ComboBox: support custom borders in combobox editors (issue #102) 2020-05-23 18:26:59 +02:00
Karl Tauber
d2d4f73834 ScrollBar: use derived colors for track and thumb (issue #103) 2020-05-23 16:40:09 +02:00
Karl Tauber
53fce4e81d ScrollBar: rotate track/thumb insets for horizontal orientation because they are given for vertical orientation (issue #103) 2020-05-23 14:16:12 +02:00
Karl Tauber
08c439b46e ScrollBar: use rounded thumb on macOS (issue #103) 2020-05-23 13:58:05 +02:00
Karl Tauber
934eb9fc1d ScrollBar: use rounded thumb on Linux (issue #103) 2020-05-23 13:51:25 +02:00
Karl Tauber
fd208a3879 ScrollBar: made styling more flexible by supporting insets and arc for track and thumb (issue #103) 2020-05-23 13:32:31 +02:00
Karl Tauber
10b131e111 Demo: show Java vendor in bottom control bar 2020-05-23 11:28:28 +02:00
Karl Tauber
c4c6faa943 Ubuntu Linux: fixed poorly rendered font (2nd attempt) (issue #105) 2020-05-23 11:06:24 +02:00
Karl Tauber
c7a8d1e1b7 Linux: changing system font did not update FlatLaf font 2020-05-22 18:22:46 +02:00
Karl Tauber
b36ac1b824 UI defaults: added GTKLookAndFeel dump made on Fedora 31 (Adweita theme) 2020-05-21 18:38:46 +02:00
Karl Tauber
bc6cb492f1 Ubuntu Linux: fixed poorly rendered font (issue #105) 2020-05-21 17:11:58 +02:00
Karl Tauber
ce503cedc3 Demo: improved "Font" menu:
- add current font family and size to menu
- filter out unavailable fonts
- select active font family and size
- disable font menu items if non-FlatLaf LaF is active

also show current font in bottom control bar

(issue #105)
2020-05-21 12:24:40 +02:00
Karl Tauber
c900c9cc82 reduce derived colors calculations 2020-05-20 14:49:56 +02:00
Karl Tauber
87b73f26f5 replaced FlatUIUtils.setColor() with deriveColor() for more flexibility 2020-05-20 14:24:22 +02:00
Karl Tauber
be529655d6 UIDefaultsLoader: on color functions use "autoInverse" option by default if "derived" option is set 2020-05-20 00:40:05 +02:00
Karl Tauber
2a0403a988 support CompoundBorder as component border with FlatBorder on the outside 2020-05-19 23:24:00 +02:00
Karl Tauber
815e23b930 ScrollBar: make hoverTrack and hoverThumb fields protected to allow subclasses implement own painting (issue #103) 2020-05-19 19:24:48 +02:00
Karl Tauber
f1c08e7769 FlatTestFrame: added Substance Business skin for testing light UI 2020-05-19 18:42:22 +02:00
Karl Tauber
571f028ca3 FlatComponentsTest: moved components that change something into own "control" panel 2020-05-19 11:31:52 +02:00
Karl Tauber
16d51fe6b4 ComboBox and Spinner: move arrow slightly to the left if round borders are used on the component 2020-05-18 23:26:34 +02:00
Karl Tauber
ddf9ed06ab release 0.35 2020-05-18 21:22:31 +02:00
Karl Tauber
1907f80024 Demo: fixed compiler warnings and improved error/warning hints 2020-05-18 21:07:11 +02:00
Karl Tauber
8c0ccdd227 Drop shadows on Windows: support medium-weight popups (issue #94) 2020-05-18 13:13:57 +02:00
Karl Tauber
dc098025b6 FileChooser: make top-right buttons look like toolbar buttons 2020-05-18 10:51:23 +02:00
Karl Tauber
c11222b5c7 FlatHtmlTest: added more HTML samples 2020-05-17 22:50:40 +02:00
Karl Tauber
03bc6eb69b FlatTestFrame: '2.0' --> '2' 2020-05-17 18:46:21 +02:00
Karl Tauber
1aa339de02 make component outline border wider if focus width is zero 2020-05-17 17:59:26 +02:00
Karl Tauber
531bb2a968 UIDefaultsDump: dump only differences for macOS
(to avoid the need for updating multiple dumps when changing UI defaults)
2020-05-17 17:52:12 +02:00
Karl Tauber
800dbf3ba9 support different component border colors to indicate errors, warnings or custom state (set client property JComponent.outline to error, warning or any java.awt.Color) 2020-05-17 13:43:19 +02:00
Karl Tauber
ff545e6ecd UIDefaultsLoader: support using a derived color function within another derived color function and create a derived color that joins the color functions 2020-05-17 12:14:14 +02:00
Karl Tauber
961fe38c7e UIDefaultsDump: dump color functions 2020-05-16 22:25:23 +02:00
Karl Tauber
19426394e2 UIDefaultsLoader: added saturate() and desaturate() color functions 2020-05-16 18:59:05 +02:00
Karl Tauber
069a4e8f0b ToolTip: fixed left/right insets of multi-line tooltips so that they are the same as in single-line tooltips (BasicToolTipUI adds 3 to the left and right) 2020-05-16 14:33:55 +02:00
Karl Tauber
a76b02b828 fixed broken FlatTestLaf.properties 2020-05-16 14:19:41 +02:00
Karl Tauber
fbb9bf5f0c Extras: TriStateCheckBox: fixed painting third state in LaFs that do not support third state 2020-05-16 12:29:35 +02:00
Karl Tauber
f632c355e8 FileChooser: scale file icons (issue #100) 2020-05-16 11:03:40 +02:00
Karl Tauber
e75caf5833 FileChooser: use system icons (issue #100) 2020-05-15 17:20:52 +02:00
Karl Tauber
b0c8f2cefd TextComponents: reduced duplicate code; fixed parameter order 2020-05-15 15:00:32 +02:00
Karl Tauber
2136d9f13d PasswordField: do not apply minimum width if columns property > 0 2020-05-15 14:06:33 +02:00
Karl Tauber
83fdeb7e0c ComboBox, Spinner and TextField: support round border style (set client property JComponent.roundRect to true) 2020-05-15 13:38:45 +02:00
Karl Tauber
26c77b3118 Button, ComboBox, TextField and DatePicker UI delegates now get Component.focusWidth and Button.arc/Component.arc/TextComponent.arc from component border 2020-05-15 11:32:53 +02:00
Karl Tauber
578d445ecb FlatBorder: moved scaling from getter methods to paintBorder() and getBorderInsets() 2020-05-14 23:35:11 +02:00
Karl Tauber
3bbc9517af Popup: fixed background flashing effect when drop shadows are disabled (issue #94) 2020-05-14 14:48:12 +02:00
Karl Tauber
a4d7f278cf Drop shadows on Windows: fix location of light weight popup in case it has left or top drop shadow (issue #94) 2020-05-14 11:44:00 +02:00
Karl Tauber
bf0ffc6ac2 Drop shadows: support enabling/disabling drop shadows per component (issue #94) 2020-05-14 11:39:09 +02:00
Karl Tauber
ace07cd9cb Drop shadows on Windows: fixed sub-pixel text rendering issue for heavy weight popups (issue #94) 2020-05-14 11:11:11 +02:00
Karl T
a341179426 Merge pull request #101 from cristatus/patch-2
Fix menu background flashing effect
2020-05-14 10:46:15 +02:00
Amit Mendapara
298f0dfd63 Fix menu background flashing effect
When using dark theme on light platform theme, there was a
background flashing effect on popups.

See #94
2020-05-14 11:43:59 +05:30
Karl Tauber
b8f953cd26 Drop shadows on Windows: use light weight popups by default (issue #94)
this fixes the sub-pixel text rendering issue (on Windows) for popups that fit into the owner window
2020-05-13 18:41:26 +02:00
Karl Tauber
a9cfe69ba7 FileChooser: fixed missing labels in file chooser when running on Java 9 or later (issue #98) 2020-05-13 12:50:41 +02:00
Karl Tauber
b3e0b99e8d Button and ToggleButton: support round button style (set client property JButton.buttonType to roundRect) 2020-05-13 11:45:01 +02:00
Karl Tauber
5bd40baed2 Extras: TriStateCheckBox: paint magenta rectangle when used in LaFs that do not support third state 2020-05-12 23:26:52 +02:00
Karl Tauber
d3a70b8bb2 CheckBox and RadioButton: Opaque flag is no longer ignored when checkbox is used as table cell renderer (issue #77)
this fix replaces/improves fix made in commit 3ba8133890
2020-05-12 22:35:05 +02:00
Karl Tauber
71e698603d ComboBox: fixed painting background outside of border if Component.arc is set to a large value 2020-05-12 22:29:59 +02:00
Karl Tauber
659ead903c TextField: avoid garbage in corners if TextComponent.arc is set to a large value 2020-05-12 18:58:17 +02:00
Karl Tauber
070c435f40 paint nicely rounded buttons, comboboxes, spinners and text fields when setting Button.arc, Component.arc or TextComponent.arc to a large value (e.g. 1000) 2020-05-12 17:48:35 +02:00
Karl Tauber
b668a526e3 changed "Flat" to "FlatLaf" in look and feel names and descriptions 2020-05-12 16:47:46 +02:00
Karl Tauber
01287d0669 Popup: allow disabling native drop shadows for popups on macOS 2020-05-12 16:42:55 +02:00
Karl T
ff481d759f Merge pull request #99 from cristatus/patch-1
Fix popup shadow issue on Linux

https://github.com/JFormDesigner/FlatLaf/issues/94#issuecomment-626344149
2020-05-10 19:25:17 +02:00
Amit Mendapara
71248f1708 Fix popup shadow issue on Linux
Linux adds drop shadow to heavy weight popups. So there is no
need to draw shadow manually.
2020-05-10 22:46:57 +05:30
Karl Tauber
0a0f834f23 Drop shadows:
- reworked drop shadows implementation to support 4-sided shadows
- use 4-sided shadow for internal frames
- made shadows configurable in UI defaults
- made shadows dark in dark themes

(issue #94)
2020-05-10 15:38:50 +02:00
Karl Tauber
06cad7ecd8 Popup: make sure that popup background is filled (issue #94) 2020-05-09 23:50:48 +02:00
Karl Tauber
ceba3e2f95 CHANGELOG.md: added Java 9 module descriptor to extras and swingx JARs 2020-05-09 15:59:29 +02:00
Karl Tauber
61c2fd8794 build.gradle.kts: use MigLayout 5.3-SNAPSHOT for better scaling
Demo: exclude module-info.class from fat JAR
2020-05-09 15:42:18 +02:00
Karl Tauber
db933fee4f build.gradle.kts: flatlaf-extras and flatlaf-swingx are now Java modules
flatlaf-jide-oss is not a Java module because jide-oss.jar does not run on the module path (tries to access private Windows LaF classes)
2020-05-09 15:32:25 +02:00
Karl Tauber
2656c2dc40 build.gradle.kts: moved publishing related configuration to precompiled script plugin 2020-05-09 13:54:16 +02:00
Karl Tauber
01cfe33865 build.gradle.kts: moved module-info and java9 related configuration to precompiled script plugins 2020-05-09 11:16:40 +02:00
Karl Tauber
d79a31cc79 build.gradle.kts: use withSourcesJar() and withJavadocJar()
this adds resources to sources.jar
2020-05-09 02:09:03 +02:00
Karl Tauber
9efab8b892 travis: added openjdk14 and removed openjdk13 2020-05-09 00:30:38 +02:00
Karl Tauber
aae845247a update to Gradle 6.4
./gradlew wrapper --gradle-version=6.4
2020-05-09 00:16:07 +02:00
Karl Tauber
3f45a9a75f Merge remote-tracking branch 'origin/drop-shadows' into master 2020-05-08 19:02:13 +02:00
Karl Tauber
c9016155ae Demo: added "Options > Always show mnemonics" to menu 2020-05-08 18:58:02 +02:00
Karl Tauber
1019e8f4af Extras: added FlatSVGIcon and download section 2020-05-08 18:50:02 +02:00
Karl Tauber
465dc8a66c Popup: added drop shadows to all popups (menu, combobox and tooltip) on all platforms (issue #94) 2020-05-08 11:02:20 +02:00
Karl Tauber
0a181f6407 InternalFrame: added drop shadows (issue #94)
also made borders of internal frames in dark themes darker
2020-05-07 00:07:02 +02:00
126 changed files with 6732 additions and 3627 deletions

View File

@@ -5,7 +5,7 @@ jdk:
- openjdk8 - openjdk8
- openjdk9 - openjdk9
- openjdk11 - openjdk11
- openjdk13 - openjdk14
before_cache: before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock

View File

@@ -1,6 +1,44 @@
FlatLaf Change Log FlatLaf Change Log
================== ==================
## 0.36
- ScrollBar: Made styling more flexible by supporting insets and arc for track
and thumb. (issue #103)
- ComboBox: Minimum width is now 72 pixels (was ~50 for non-editable and ~130
for editable comboboxes).
- ComboBox: Support custom borders in combobox editors. (issue #102)
- Button: Support non-square icon-only buttons. (issue #110)
- Ubuntu Linux: Fixed poorly rendered font. (issue #105)
- macOS Catalina: Use Helvetica Neue font.
- `FlatInspector` added (see [FlatLaf Extras](flatlaf-extras)).
## 0.35
- Added drop shadows to popup menus, combobox popups, tooltips and internal
frames. (issue #94)
- Support different component border colors to indicate errors, warnings or
custom state (set client property `JComponent.outline` to `error`, `warning`
or any `java.awt.Color`).
- Button and ToggleButton: Support round button style (set client property
`JButton.buttonType` to `roundRect`).
- ComboBox, Spinner and TextField: Support round border style (set client
property `JComponent.roundRect` to `true`).
- Paint nicely rounded buttons, comboboxes, spinners and text fields when
setting `Button.arc`, `Component.arc` or `TextComponent.arc` to a large value
(e.g. 1000).
- Added Java 9 module descriptor to `flatlaf-extras-<version>.jar` and
`flatlaf-swingx-<version>.jar`.
- CheckBox and RadioButton: Flag `opaque` is no longer ignored when checkbox or
radio button is used as table cell renderer. (issue #77)
- FileChooser: Use system icons. (issue #100)
- FileChooser: Fixed missing labels in file chooser when running on Java 9 or
later. (issue #98)
- PasswordField: Do not apply minimum width if `columns` property is greater
than zero.
## 0.34 ## 0.34
- Menus: New menu item renderer brings stable left margins, right aligned - Menus: New menu item renderer brings stable left margins, right aligned

View File

@@ -69,9 +69,10 @@ docs).
Addons Addons
------ ------
- [IntelliJ Themes Pack](flatlaf-intellij-themes)
- [Extras](flatlaf-extras)
- [SwingX](flatlaf-swingx) - [SwingX](flatlaf-swingx)
- [JIDE Common Layer](flatlaf-jide-oss) - [JIDE Common Layer](flatlaf-jide-oss)
- [IntelliJ Themes Pack](flatlaf-intellij-themes)
Projects using FlatLaf Projects using FlatLaf

View File

@@ -14,8 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
val releaseVersion = "0.34" val releaseVersion = "0.36"
val developmentVersion = "0.35-SNAPSHOT" val developmentVersion = "0.37-SNAPSHOT"
version = if( java.lang.Boolean.getBoolean( "release" ) ) releaseVersion else developmentVersion version = if( java.lang.Boolean.getBoolean( "release" ) ) releaseVersion else developmentVersion

34
buildSrc/build.gradle.kts Normal file
View File

@@ -0,0 +1,34 @@
/*
* Copyright 2020 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 {
`kotlin-dsl`
}
// required for kotlin-dsl or embedded-kotlin plugins
repositories {
jcenter()
}
dependencies {
// NOTE: keep plugin versions in sync with settings.gradle.kts
// "com.jfrog.bintray" plugin
implementation( "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4" )
// "com.jfrog.artifactory" plugin
implementation( "org.jfrog.buildinfo:build-info-extractor-gradle:4.13.0" )
}

View File

@@ -0,0 +1,44 @@
/*
* Copyright 2020 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
}
if( JavaVersion.current() >= JavaVersion.VERSION_1_9 ) {
sourceSets {
create( "java9" ) {
java {
setSrcDirs( listOf( "src/main/java9" ) )
}
}
}
tasks {
named<JavaCompile>( "compileJava9Java" ) {
sourceCompatibility = "9"
targetCompatibility = "9"
}
jar {
manifest.attributes( "Multi-Release" to "true" )
into( "META-INF/versions/9" ) {
from( sourceSets["java9"].output )
}
}
}
}

View File

@@ -0,0 +1,64 @@
/*
* Copyright 2020 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 ModuleInfoExtension {
var paths: ArrayList<String> = ArrayList()
fun dependsOn( vararg paths: String ) {
this.paths.addAll( paths )
}
}
val extension = project.extensions.create<ModuleInfoExtension>( "flatlafModuleInfo" )
plugins {
java
}
if( JavaVersion.current() >= JavaVersion.VERSION_1_9 ) {
sourceSets {
create( "module-info" ) {
java {
// include "src/main/java" here to get compile errors if classes are
// used from other modules that are not specified in module dependencies
setSrcDirs( listOf( "src/main/module-info", "src/main/java" ) )
}
}
}
tasks {
named<JavaCompile>( "compileModuleInfoJava" ) {
sourceCompatibility = "9"
targetCompatibility = "9"
dependsOn( extension.paths )
options.compilerArgs.add( "--module-path" )
options.compilerArgs.add( configurations.runtimeClasspath.get().asPath )
}
jar {
manifest.attributes( "Multi-Release" to "true" )
into( "META-INF/versions/9" ) {
from( sourceSets["module-info"].output ) {
include( "module-info.class" )
}
}
}
}
}

View File

@@ -0,0 +1,116 @@
/*
* Copyright 2020 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 PublishExtension {
var artifactId: String? = null
var name: String? = null
var description: String? = null
}
val extension = project.extensions.create<PublishExtension>( "flatlafPublish" )
plugins {
`maven-publish`
id( "com.jfrog.bintray" )
id( "com.jfrog.artifactory" )
}
publishing {
publications {
create<MavenPublication>( "maven" ) {
afterEvaluate {
artifactId = extension.artifactId
}
groupId = "com.formdev"
from( components["java"] )
pom {
afterEvaluate {
this@pom.name.set( extension.name )
this@pom.description.set( extension.description )
}
url.set( "https://github.com/JFormDesigner/FlatLaf" )
licenses {
license {
name.set( "The Apache License, Version 2.0" )
url.set( "https://www.apache.org/licenses/LICENSE-2.0.txt" )
}
}
developers {
developer {
name.set( "Karl Tauber" )
organization.set( "FormDev Software GmbH" )
organizationUrl.set( "https://www.formdev.com/" )
}
}
scm {
url.set( "https://github.com/JFormDesigner/FlatLaf" )
}
}
}
}
}
bintray {
user = rootProject.extra["bintray.user"] as String?
key = rootProject.extra["bintray.key"] as String?
setPublications( "maven" )
with( pkg ) {
repo = "flatlaf"
afterEvaluate {
this@with.name = extension.artifactId
}
setLicenses( "Apache-2.0" )
vcsUrl = "https://github.com/JFormDesigner/FlatLaf"
with( version ) {
name = project.version.toString()
}
publish = rootProject.extra["bintray.publish"] as Boolean
dryRun = rootProject.extra["bintray.dryRun"] as Boolean
}
}
artifactory {
setContextUrl( "https://oss.jfrog.org" )
publish( closureOf<org.jfrog.gradle.plugin.artifactory.dsl.PublisherConfig> {
repository( delegateClosureOf<groovy.lang.GroovyObject> {
setProperty( "repoKey", "oss-snapshot-local" )
setProperty( "username", rootProject.extra["bintray.user"] as String? )
setProperty( "password", rootProject.extra["bintray.key"] as String? )
} )
defaults( delegateClosureOf<groovy.lang.GroovyObject> {
invokeMethod( "publications", "maven" )
setProperty( "publishArtifacts", true )
setProperty( "publishPom", true )
} )
} )
resolve( delegateClosureOf<org.jfrog.gradle.plugin.artifactory.dsl.ResolverConfig> {
setProperty( "repoKey", "jcenter" )
} )
}

View File

@@ -16,58 +16,20 @@
plugins { plugins {
`java-library` `java-library`
`maven-publish` `flatlaf-module-info`
id( "com.jfrog.bintray" ) `flatlaf-java9`
id( "com.jfrog.artifactory" ) `flatlaf-publish`
} }
if( JavaVersion.current() >= JavaVersion.VERSION_1_9 ) { java {
sourceSets { withSourcesJar()
create( "java9" ) { withJavadocJar()
java {
setSrcDirs( listOf( "src/main/java9" ) )
}
}
create( "module-info" ) {
java {
// include "src/main/java" here to get compile errors if classes are
// used from other modules that are not specified in module dependencies
setSrcDirs( listOf( "src/main/module-info", "src/main/java" ) )
}
}
}
} }
tasks { tasks {
assemble {
dependsOn(
"sourcesJar",
"javadocJar"
)
}
if( JavaVersion.current() >= JavaVersion.VERSION_1_9 ) {
named<JavaCompile>( "compileModuleInfoJava" ) {
sourceCompatibility = "9"
targetCompatibility = "9"
}
}
jar { jar {
archiveBaseName.set( "flatlaf" ) archiveBaseName.set( "flatlaf" )
if( JavaVersion.current() >= JavaVersion.VERSION_1_9 ) {
manifest.attributes( "Multi-Release" to "true" )
into( "META-INF/versions/9" ) {
from( sourceSets["java9"].output )
}
from( sourceSets["module-info"].output ) {
include( "module-info.class" )
}
}
doLast { doLast {
ReorderJarEntries.reorderJarEntries( outputs.files.singleFile ); ReorderJarEntries.reorderJarEntries( outputs.files.singleFile );
} }
@@ -76,105 +38,24 @@ tasks {
javadoc { javadoc {
options { options {
this as StandardJavadocDocletOptions this as StandardJavadocDocletOptions
use( true )
tags = listOf( "uiDefault", "clientProperty" ) tags = listOf( "uiDefault", "clientProperty" )
addStringOption( "Xdoclint:all,-missing", "-Xdoclint:all,-missing" ) addStringOption( "Xdoclint:all,-missing", "-Xdoclint:all,-missing" )
} }
isFailOnError = false isFailOnError = false
} }
register( "sourcesJar", Jar::class ) { named<Jar>("sourcesJar" ) {
archiveBaseName.set( "flatlaf" ) archiveBaseName.set( "flatlaf" )
archiveClassifier.set( "sources" )
from( sourceSets.main.get().allJava )
} }
register( "javadocJar", Jar::class ) { named<Jar>("javadocJar" ) {
archiveBaseName.set( "flatlaf" ) archiveBaseName.set( "flatlaf" )
archiveClassifier.set( "javadoc" )
from( javadoc )
} }
} }
publishing { flatlafPublish {
publications { artifactId = "flatlaf"
create<MavenPublication>( "maven" ) { name = "FlatLaf"
artifactId = "flatlaf" description = "Flat Look and Feel"
groupId = "com.formdev"
from( components["java"] )
artifact( tasks["sourcesJar"] )
artifact( tasks["javadocJar"] )
pom {
name.set( "FlatLaf" )
description.set( "Flat Look and Feel" )
url.set( "https://github.com/JFormDesigner/FlatLaf" )
licenses {
license {
name.set( "The Apache License, Version 2.0" )
url.set( "https://www.apache.org/licenses/LICENSE-2.0.txt" )
}
}
developers {
developer {
name.set( "Karl Tauber" )
organization.set( "FormDev Software GmbH" )
organizationUrl.set( "https://www.formdev.com/" )
}
}
scm {
url.set( "https://github.com/JFormDesigner/FlatLaf" )
}
}
}
}
}
bintray {
user = rootProject.extra["bintray.user"] as String?
key = rootProject.extra["bintray.key"] as String?
setPublications( "maven" )
with( pkg ) {
repo = "flatlaf"
name = "flatlaf"
setLicenses( "Apache-2.0" )
vcsUrl = "https://github.com/JFormDesigner/FlatLaf"
with( version ) {
name = project.version.toString()
}
publish = rootProject.extra["bintray.publish"] as Boolean
dryRun = rootProject.extra["bintray.dryRun"] as Boolean
}
}
artifactory {
setContextUrl( "https://oss.jfrog.org" )
publish( closureOf<org.jfrog.gradle.plugin.artifactory.dsl.PublisherConfig> {
repository( delegateClosureOf<groovy.lang.GroovyObject> {
setProperty( "repoKey", "oss-snapshot-local" )
setProperty( "username", rootProject.extra["bintray.user"] as String? )
setProperty( "password", rootProject.extra["bintray.key"] as String? )
} )
defaults( delegateClosureOf<groovy.lang.GroovyObject> {
invokeMethod( "publications", "maven" )
setProperty( "publishArtifacts", true )
setProperty( "publishPom", true )
} )
} )
resolve( delegateClosureOf<org.jfrog.gradle.plugin.artifactory.dsl.ResolverConfig> {
setProperty( "repoKey", "jcenter" )
} )
} }

View File

@@ -30,7 +30,8 @@ public interface FlatClientProperties
* <p> * <p>
* <strong>Components</strong> {@link javax.swing.JButton} and {@link javax.swing.JToggleButton}<br> * <strong>Components</strong> {@link javax.swing.JButton} and {@link javax.swing.JToggleButton}<br>
* <strong>Value type</strong> {@link java.lang.String}<br> * <strong>Value type</strong> {@link java.lang.String}<br>
* <strong>Allowed Values</strong> {@link #BUTTON_TYPE_SQUARE} and {@link #BUTTON_TYPE_HELP} * <strong>Allowed Values</strong> {@link #BUTTON_TYPE_SQUARE}, {@link #BUTTON_TYPE_ROUND_RECT},
* {@link #BUTTON_TYPE_TAB}, {@link #BUTTON_TYPE_HELP} and {@link BUTTON_TYPE_TOOLBAR_BUTTON}
*/ */
String BUTTON_TYPE = "JButton.buttonType"; String BUTTON_TYPE = "JButton.buttonType";
@@ -43,6 +44,15 @@ public interface FlatClientProperties
*/ */
String BUTTON_TYPE_SQUARE = "square"; String BUTTON_TYPE_SQUARE = "square";
/**
* Paint the button with round edges.
* <p>
* <strong>Components</strong> {@link javax.swing.JButton} and {@link javax.swing.JToggleButton}
*
* @see #BUTTON_TYPE
*/
String BUTTON_TYPE_ROUND_RECT = "roundRect";
/** /**
* Paint the toggle button in tab style. * Paint the toggle button in tab style.
* <p> * <p>
@@ -61,6 +71,15 @@ public interface FlatClientProperties
*/ */
String BUTTON_TYPE_HELP = "help"; String BUTTON_TYPE_HELP = "help";
/**
* Paint the button in toolbar style.
* <p>
* <strong>Components</strong> {@link javax.swing.JButton} and {@link javax.swing.JToggleButton}
*
* @see #BUTTON_TYPE
*/
String BUTTON_TYPE_TOOLBAR_BUTTON = "toolBarButton";
/** /**
* Specifies selected state of a checkbox. * Specifies selected state of a checkbox.
* <p> * <p>
@@ -80,7 +99,8 @@ public interface FlatClientProperties
/** /**
* Specifies minimum width of a component. * Specifies minimum width of a component.
* <p> * <p>
* <strong>Component</strong> {@link javax.swing.JButton}, {@link javax.swing.JToggleButton} and {@link javax.swing.text.JTextComponent}<br> * <strong>Component</strong> {@link javax.swing.JButton}, {@link javax.swing.JToggleButton},
* {@link javax.swing.JComboBox}, {@link javax.swing.JSpinner} and {@link javax.swing.text.JTextComponent}<br>
* <strong>Value type</strong> {@link java.lang.Integer}<br> * <strong>Value type</strong> {@link java.lang.Integer}<br>
*/ */
String MINIMUM_WIDTH = "JComponent.minimumWidth"; String MINIMUM_WIDTH = "JComponent.minimumWidth";
@@ -93,6 +113,52 @@ public interface FlatClientProperties
*/ */
String MINIMUM_HEIGHT = "JComponent.minimumHeight"; String MINIMUM_HEIGHT = "JComponent.minimumHeight";
/**
* Specifies the outline color of the component border.
* <p>
* <strong>Components</strong> {@link javax.swing.JButton}, {@link javax.swing.JComboBox},
* {@link javax.swing.JFormattedTextField}, {@link javax.swing.JPasswordField},
* {@link javax.swing.JScrollPane}, {@link javax.swing.JSpinner},
* {@link javax.swing.JTextField} and {@link javax.swing.JToggleButton}<br>
* <strong>Value type</strong> {@link java.lang.String} or {@link java.awt.Color} or {@link java.awt.Color}[2]<br>
* <strong>Allowed Values</strong> {@link #OUTLINE_ERROR}, {@link #OUTLINE_WARNING},
* any color (type {@link java.awt.Color}) or an array of two colors (type {@link java.awt.Color}[2])
* where the first color is for focused state and the second for unfocused state
*/
String OUTLINE = "JComponent.outline";
/**
* Paint the component border in another color (usually reddish) to indicate an error.
*
* @see #OUTLINE
*/
String OUTLINE_ERROR = "error";
/**
* Paint the component border in another color (usually yellowish) to indicate a warning.
*
* @see #OUTLINE
*/
String OUTLINE_WARNING = "warning";
/**
* Paint the component with round edges.
* <p>
* <strong>Components</strong> {@link javax.swing.JComboBox}, {@link javax.swing.JSpinner},
* {@link javax.swing.JTextField}, {@link javax.swing.JFormattedTextField} and {@link javax.swing.JPasswordField}
* <strong>Value type</strong> {@link java.lang.Boolean}
*/
String COMPONENT_ROUND_RECT = "JComponent.roundRect";
/**
* Specifies whether a drop shadow is painted if the component is shown in a popup
* or if the component is the owner of another component that is shown in a popup.
* <p>
* <strong>Component</strong> {@link javax.swing.JComponent}<br>
* <strong>Value type</strong> {@link java.lang.Boolean}
*/
String POPUP_DROP_SHADOW_PAINTED = "Popup.dropShadowPainted";
/** /**
* Specifies whether the progress bar has always the larger height even if no string is painted. * Specifies whether the progress bar has always the larger height even if no string is painted.
* <p> * <p>
@@ -240,4 +306,14 @@ public interface FlatClientProperties
Object value = c.getClientProperty( key ); Object value = c.getClientProperty( key );
return (value instanceof Color) ? (Color) value : defaultValue; return (value instanceof Color) ? (Color) value : defaultValue;
} }
static int clientPropertyChoice( JComponent c, String key, String... choices ) {
Object value = c.getClientProperty( key );
for( int i = 0; i < choices.length; i++ ) {
if( choices[i].equals( value ) )
return i;
}
return -1;
}
} }

View File

@@ -32,11 +32,11 @@ public class FlatDarculaLaf
@Override @Override
public String getName() { public String getName() {
return "Flat Darcula"; return "FlatLaf Darcula";
} }
@Override @Override
public String getDescription() { public String getDescription() {
return "Flat Darcula Look and Feel"; return "FlatLaf Darcula Look and Feel";
} }
} }

View File

@@ -32,12 +32,12 @@ public class FlatDarkLaf
@Override @Override
public String getName() { public String getName() {
return "Flat Dark"; return "FlatLaf Dark";
} }
@Override @Override
public String getDescription() { public String getDescription() {
return "Flat Dark Look and Feel"; return "FlatLaf Dark Look and Feel";
} }
@Override @Override

View File

@@ -32,11 +32,11 @@ public class FlatIntelliJLaf
@Override @Override
public String getName() { public String getName() {
return "Flat IntelliJ"; return "FlatLaf IntelliJ";
} }
@Override @Override
public String getDescription() { public String getDescription() {
return "Flat IntelliJ Look and Feel"; return "FlatLaf IntelliJ Look and Feel";
} }
} }

View File

@@ -56,6 +56,7 @@ import javax.swing.plaf.UIResource;
import javax.swing.plaf.basic.BasicLookAndFeel; import javax.swing.plaf.basic.BasicLookAndFeel;
import javax.swing.text.StyleContext; import javax.swing.text.StyleContext;
import javax.swing.text.html.HTMLEditorKit; import javax.swing.text.html.HTMLEditorKit;
import com.formdev.flatlaf.ui.FlatPopupFactory;
import com.formdev.flatlaf.util.GrayFilter; import com.formdev.flatlaf.util.GrayFilter;
import com.formdev.flatlaf.util.MultiResolutionImageSupport; import com.formdev.flatlaf.util.MultiResolutionImageSupport;
import com.formdev.flatlaf.util.SystemInfo; import com.formdev.flatlaf.util.SystemInfo;
@@ -73,11 +74,13 @@ public abstract class FlatLaf
private static final String DESKTOPFONTHINTS = "awt.font.desktophints"; private static final String DESKTOPFONTHINTS = "awt.font.desktophints";
private String desktopPropertyName; private String desktopPropertyName;
private String desktopPropertyName2;
private PropertyChangeListener desktopPropertyListener; private PropertyChangeListener desktopPropertyListener;
private static boolean aquaLoaded; private static boolean aquaLoaded;
private static boolean updateUIPending; private static boolean updateUIPending;
private PopupFactory oldPopupFactory;
private MnemonicHandler mnemonicHandler; private MnemonicHandler mnemonicHandler;
private Consumer<UIDefaults> postInitialization; private Consumer<UIDefaults> postInitialization;
@@ -144,6 +147,10 @@ public abstract class FlatLaf
super.initialize(); super.initialize();
// install popup factory
oldPopupFactory = PopupFactory.getSharedInstance();
PopupFactory.setSharedInstance( new FlatPopupFactory() );
// install mnemonic handler // install mnemonic handler
mnemonicHandler = new MnemonicHandler(); mnemonicHandler = new MnemonicHandler();
mnemonicHandler.install(); mnemonicHandler.install();
@@ -154,15 +161,19 @@ public abstract class FlatLaf
// Settings > Ease of Access > Display > Make text bigger (100% - 225%) // Settings > Ease of Access > Display > Make text bigger (100% - 225%)
desktopPropertyName = "win.messagebox.font"; desktopPropertyName = "win.messagebox.font";
} else if( SystemInfo.IS_LINUX ) { } else if( SystemInfo.IS_LINUX ) {
// Linux/Gnome allows changing font in "Tweaks" app
desktopPropertyName = "gnome.Gtk/FontName";
// Linux/Gnome allows extra scaling and larger text: // Linux/Gnome allows extra scaling and larger text:
// Settings > Devices > Displays > Scale (100% or 200%) // Settings > Devices > Displays > Scale (100% or 200%)
// Settings > Universal access > Large Text (off or on, 125%) // Settings > Universal access > Large Text (off or on, 125%)
desktopPropertyName = "gnome.Xft/DPI"; // "Tweaks" app > Fonts > Scaling Factor (0,5 - 3)
desktopPropertyName2 = "gnome.Xft/DPI";
} }
if( desktopPropertyName != null ) { if( desktopPropertyName != null ) {
desktopPropertyListener = e -> { desktopPropertyListener = e -> {
String propertyName = e.getPropertyName(); String propertyName = e.getPropertyName();
if( desktopPropertyName.equals( propertyName ) ) if( desktopPropertyName.equals( propertyName ) || propertyName.equals( desktopPropertyName2 ) )
reSetLookAndFeel(); reSetLookAndFeel();
else if( DESKTOPFONTHINTS.equals( propertyName ) ) { else if( DESKTOPFONTHINTS.equals( propertyName ) ) {
if( UIManager.getLookAndFeel() instanceof FlatLaf ) { if( UIManager.getLookAndFeel() instanceof FlatLaf ) {
@@ -173,6 +184,8 @@ public abstract class FlatLaf
}; };
Toolkit toolkit = Toolkit.getDefaultToolkit(); Toolkit toolkit = Toolkit.getDefaultToolkit();
toolkit.addPropertyChangeListener( desktopPropertyName, desktopPropertyListener ); toolkit.addPropertyChangeListener( desktopPropertyName, desktopPropertyListener );
if( desktopPropertyName2 != null )
toolkit.addPropertyChangeListener( desktopPropertyName2, desktopPropertyListener );
toolkit.addPropertyChangeListener( DESKTOPFONTHINTS, desktopPropertyListener ); toolkit.addPropertyChangeListener( DESKTOPFONTHINTS, desktopPropertyListener );
} }
@@ -195,11 +208,20 @@ public abstract class FlatLaf
if( desktopPropertyListener != null ) { if( desktopPropertyListener != null ) {
Toolkit toolkit = Toolkit.getDefaultToolkit(); Toolkit toolkit = Toolkit.getDefaultToolkit();
toolkit.removePropertyChangeListener( desktopPropertyName, desktopPropertyListener ); toolkit.removePropertyChangeListener( desktopPropertyName, desktopPropertyListener );
if( desktopPropertyName2 != null )
toolkit.removePropertyChangeListener( desktopPropertyName2, desktopPropertyListener );
toolkit.removePropertyChangeListener( DESKTOPFONTHINTS, desktopPropertyListener ); toolkit.removePropertyChangeListener( DESKTOPFONTHINTS, desktopPropertyListener );
desktopPropertyName = null; desktopPropertyName = null;
desktopPropertyName2 = null;
desktopPropertyListener = null; desktopPropertyListener = null;
} }
// uninstall popup factory
if( oldPopupFactory != null ) {
PopupFactory.setSharedInstance( oldPopupFactory );
oldPopupFactory = null;
}
// uninstall mnemonic handler // uninstall mnemonic handler
if( mnemonicHandler != null ) { if( mnemonicHandler != null ) {
mnemonicHandler.uninstall(); mnemonicHandler.uninstall();
@@ -256,8 +278,8 @@ public abstract class FlatLaf
public UIDefaults getDefaults() { public UIDefaults getDefaults() {
UIDefaults defaults = super.getDefaults(); UIDefaults defaults = super.getDefaults();
// add Metal resource bundle, which is required for FlatFileChooserUI // add resource bundle for localized texts
defaults.addResourceBundle( "com.sun.swing.internal.plaf.metal.resources.metal" ); defaults.addResourceBundle( "com.formdev.flatlaf.resources.Bundle" );
// initialize some defaults (for overriding) that are used in UI delegates, // initialize some defaults (for overriding) that are used in UI delegates,
// but are not set in BasicLookAndFeel // but are not set in BasicLookAndFeel
@@ -355,7 +377,10 @@ public abstract class FlatLaf
} else if( SystemInfo.IS_MAC ) { } else if( SystemInfo.IS_MAC ) {
String fontName; String fontName;
if( SystemInfo.IS_MAC_OS_10_11_EL_CAPITAN_OR_LATER ) { if( SystemInfo.IS_MAC_OS_10_15_CATALINA_OR_LATER ) {
// use Helvetica Neue font
fontName = "Helvetica Neue";
} else if( SystemInfo.IS_MAC_OS_10_11_EL_CAPITAN_OR_LATER ) {
// use San Francisco Text font // use San Francisco Text font
fontName = ".SF NS Text"; fontName = ".SF NS Text";
} else { } else {
@@ -397,7 +422,7 @@ public abstract class FlatLaf
// using StyleContext.getFont() here because it uses // using StyleContext.getFont() here because it uses
// sun.font.FontUtilities.getCompositeFontUIResource() // sun.font.FontUtilities.getCompositeFontUIResource()
// and creates a composite font that is able to display all Unicode characters // and creates a composite font that is able to display all Unicode characters
Font font = new StyleContext().getFont( family, style, size ); Font font = StyleContext.getDefaultStyleContext().getFont( family, style, size );
return (font instanceof FontUIResource) ? (FontUIResource) font : new FontUIResource( font ); return (font instanceof FontUIResource) ? (FontUIResource) font : new FontUIResource( font );
} }

View File

@@ -32,12 +32,12 @@ public class FlatLightLaf
@Override @Override
public String getName() { public String getName() {
return "Flat Light"; return "FlatLaf Light";
} }
@Override @Override
public String getDescription() { public String getDescription() {
return "Flat Light Look and Feel"; return "FlatLaf Light Look and Feel";
} }
@Override @Override

View File

@@ -467,6 +467,12 @@ public class IntelliJTheme
uiKeyMapping.put( "ComboBox.ArrowButton.iconColor", "ComboBox.buttonArrowColor" ); uiKeyMapping.put( "ComboBox.ArrowButton.iconColor", "ComboBox.buttonArrowColor" );
uiKeyMapping.put( "ComboBox.ArrowButton.nonEditableBackground", "ComboBox.buttonBackground" ); uiKeyMapping.put( "ComboBox.ArrowButton.nonEditableBackground", "ComboBox.buttonBackground" );
// Component
uiKeyMapping.put( "Component.inactiveErrorFocusColor", "Component.error.borderColor" );
uiKeyMapping.put( "Component.errorFocusColor", "Component.error.focusedBorderColor" );
uiKeyMapping.put( "Component.inactiveWarningFocusColor", "Component.warning.borderColor" );
uiKeyMapping.put( "Component.warningFocusColor", "Component.warning.focusedBorderColor" );
// Link // Link
uiKeyMapping.put( "Link.activeForeground", "Component.linkColor" ); uiKeyMapping.put( "Link.activeForeground", "Component.linkColor" );

View File

@@ -74,6 +74,13 @@ class LinuxFontPolicy
family = family.isEmpty() ? word : (family + ' ' + word); family = family.isEmpty() ? word : (family + ' ' + word);
} }
// Ubuntu font is rendered poorly (except if running in JetBrains VM)
// --> use Liberation Sans font
if( family.startsWith( "Ubuntu" ) &&
!SystemInfo.IS_JETBRAINS_JVM &&
!Boolean.parseBoolean( System.getProperty( "flatlaf.useUbuntuFont" ) ) )
family = "Liberation Sans";
// scale font size // scale font size
double dsize = size * getGnomeFontScale(); double dsize = size * getGnomeFontScale();
size = (int) (dsize + 0.5); size = (int) (dsize + 0.5);

View File

@@ -40,6 +40,7 @@ import javax.swing.plaf.InsetsUIResource;
import com.formdev.flatlaf.ui.FlatEmptyBorder; import com.formdev.flatlaf.ui.FlatEmptyBorder;
import com.formdev.flatlaf.ui.FlatLineBorder; import com.formdev.flatlaf.ui.FlatLineBorder;
import com.formdev.flatlaf.util.ColorFunctions; import com.formdev.flatlaf.util.ColorFunctions;
import com.formdev.flatlaf.util.ColorFunctions.ColorFunction;
import com.formdev.flatlaf.util.DerivedColor; import com.formdev.flatlaf.util.DerivedColor;
import com.formdev.flatlaf.util.GrayFilter; import com.formdev.flatlaf.util.GrayFilter;
import com.formdev.flatlaf.util.HSLColor; import com.formdev.flatlaf.util.HSLColor;
@@ -511,8 +512,10 @@ class UIDefaultsLoader
case "rgba": return parseColorRgbOrRgba( true, params, resolver, reportError ); case "rgba": return parseColorRgbOrRgba( true, params, resolver, reportError );
case "hsl": return parseColorHslOrHsla( false, params ); case "hsl": return parseColorHslOrHsla( false, params );
case "hsla": return parseColorHslOrHsla( true, params ); case "hsla": return parseColorHslOrHsla( true, params );
case "lighten": return parseColorLightenOrDarken( true, params, resolver, reportError ); case "lighten": return parseColorHSLIncreaseDecrease( 2, true, params, resolver, reportError );
case "darken": return parseColorLightenOrDarken( false, params, resolver, reportError ); case "darken": return parseColorHSLIncreaseDecrease( 2, false, params, resolver, reportError );
case "saturate": return parseColorHSLIncreaseDecrease( 1, true, params, resolver, reportError );
case "desaturate": return parseColorHSLIncreaseDecrease( 1, false, params, resolver, reportError );
} }
throw new IllegalArgumentException( "unknown color function '" + value + "'" ); throw new IllegalArgumentException( "unknown color function '" + value + "'" );
@@ -565,13 +568,14 @@ class UIDefaultsLoader
} }
/** /**
* Syntax: lighten(color,amount[,options]) or darken(color,amount[,options]) * Syntax: lighten(color,amount[,options]) or darken(color,amount[,options]) or
* saturate(color,amount[,options]) or desaturate(color,amount[,options])
* - color: a color (e.g. #f00) or a color function * - color: a color (e.g. #f00) or a color function
* - amount: percentage 0-100% * - amount: percentage 0-100%
* - options: [relative] [autoInverse] [lazy] [derived] * - options: [relative] [autoInverse] [noAutoInverse] [lazy] [derived]
*/ */
private static Object parseColorLightenOrDarken( boolean lighten, List<String> params, private static Object parseColorHSLIncreaseDecrease( int hslIndex, boolean increase,
Function<String, String> resolver, boolean reportError ) List<String> params, Function<String, String> resolver, boolean reportError )
{ {
String colorStr = params.get( 0 ); String colorStr = params.get( 0 );
int amount = parsePercentage( params.get( 1 ) ); int amount = parsePercentage( params.get( 1 ) );
@@ -586,16 +590,15 @@ class UIDefaultsLoader
autoInverse = options.contains( "autoInverse" ); autoInverse = options.contains( "autoInverse" );
lazy = options.contains( "lazy" ); lazy = options.contains( "lazy" );
derived = options.contains( "derived" ); derived = options.contains( "derived" );
// use autoInverse by default for derived colors, except if noAutoInverse is set
if( derived && !options.contains( "noAutoInverse" ) )
autoInverse = true;
} }
ColorFunctions.ColorFunction function = lighten // create function
? new ColorFunctions.Lighten( amount, relative, autoInverse ) ColorFunction function = new ColorFunctions.HSLIncreaseDecrease(
: new ColorFunctions.Darken( amount, relative, autoInverse ); hslIndex, increase, amount, relative, autoInverse );
if( derived ) {
ColorUIResource color = (ColorUIResource) parseColorOrFunction( resolver.apply( colorStr ), resolver, reportError );
return new DerivedColor( ColorFunctions.applyFunctions( color, function ), function );
}
if( lazy ) { if( lazy ) {
return (LazyValue) t -> { return (LazyValue) t -> {
@@ -606,8 +609,29 @@ class UIDefaultsLoader
}; };
} }
ColorUIResource color = (ColorUIResource) parseColorOrFunction( resolver.apply( colorStr ), resolver, reportError ); // parse base color
return new ColorUIResource( ColorFunctions.applyFunctions( color, function ) ); String resolvedColorStr = resolver.apply( colorStr );
ColorUIResource baseColor = (ColorUIResource) parseColorOrFunction( resolvedColorStr, resolver, reportError );
// apply this function to base color
Color newColor = ColorFunctions.applyFunctions( baseColor, function );
if( derived ) {
ColorFunction[] functions;
if( baseColor instanceof DerivedColor && resolvedColorStr == colorStr ) {
// if the base color is also derived, join the color functions
// but only if base color function is specified directly in this function
ColorFunction[] baseFunctions = ((DerivedColor)baseColor).getFunctions();
functions = new ColorFunction[baseFunctions.length + 1];
System.arraycopy( baseFunctions, 0, functions, 0, baseFunctions.length );
functions[baseFunctions.length] = function;
} else
functions = new ColorFunction[] { function };
return new DerivedColor( newColor, functions );
}
return new ColorUIResource( newColor );
} }
private static int parsePercentage( String value ) { private static int parsePercentage( String value ) {

View File

@@ -111,13 +111,13 @@ public class FlatCheckBoxIcon
paintBorder( g2 ); paintBorder( g2 );
// paint background // paint background
FlatUIUtils.setColor( g2, FlatButtonUI.buttonStateColor( c, g2.setColor( FlatUIUtils.deriveColor( FlatButtonUI.buttonStateColor( c,
selected ? selectedBackground : background, selected ? selectedBackground : background,
disabledBackground, disabledBackground,
focusedBackground, focusedBackground,
selected && selectedHoverBackground != null ? selectedHoverBackground : hoverBackground, selected && selectedHoverBackground != null ? selectedHoverBackground : hoverBackground,
selected && selectedPressedBackground != null ? selectedPressedBackground : pressedBackground ), selected && selectedPressedBackground != null ? selectedPressedBackground : pressedBackground ),
background ); background ) );
paintBackground( g2 ); paintBackground( g2 );
// paint checkmark // paint checkmark

View File

@@ -100,12 +100,12 @@ public class FlatHelpButtonIcon
g2.fill( new Ellipse2D.Float( focusWidth + 0.5f, focusWidth + 0.5f, 21, 21 ) ); g2.fill( new Ellipse2D.Float( focusWidth + 0.5f, focusWidth + 0.5f, 21, 21 ) );
// paint background // paint background
FlatUIUtils.setColor( g2, FlatButtonUI.buttonStateColor( c, g2.setColor( FlatUIUtils.deriveColor( FlatButtonUI.buttonStateColor( c,
background, background,
disabledBackground, disabledBackground,
focusedBackground, focusedBackground,
hoverBackground, hoverBackground,
pressedBackground ), background ); pressedBackground ), background ) );
g2.fill( new Ellipse2D.Float( focusWidth + 1.5f, focusWidth + 1.5f, 19, 19 ) ); g2.fill( new Ellipse2D.Float( focusWidth + 1.5f, focusWidth + 1.5f, 19, 19 ) );
// paint question mark // paint question mark

View File

@@ -27,6 +27,7 @@ import com.formdev.flatlaf.ui.FlatUIUtils;
/** /**
* Base class for internal frame icons. * Base class for internal frame icons.
* *
* @uiDefault InternalFrame.buttonSize Dimension
* @uiDefault InternalFrame.buttonHoverBackground Color * @uiDefault InternalFrame.buttonHoverBackground Color
* @uiDefault InternalFrame.buttonPressedBackground Color * @uiDefault InternalFrame.buttonPressedBackground Color
* *
@@ -53,7 +54,7 @@ public abstract class FlatInternalFrameAbstractIcon
protected void paintBackground( Component c, Graphics2D g ) { protected void paintBackground( Component c, Graphics2D g ) {
Color background = FlatButtonUI.buttonStateColor( c, null, null, null, hoverBackground, pressedBackground ); Color background = FlatButtonUI.buttonStateColor( c, null, null, null, hoverBackground, pressedBackground );
if( background != null ) { if( background != null ) {
FlatUIUtils.setColor( g, background, c.getBackground() ); g.setColor( FlatUIUtils.deriveColor( background, c.getBackground() ) );
g.fillRect( 0, 0, width, height ); g.fillRect( 0, 0, width, height );
} }
} }

View File

@@ -28,8 +28,11 @@ import com.formdev.flatlaf.ui.FlatButtonUI;
/** /**
* "close" icon for {@link javax.swing.JInternalFrame}. * "close" icon for {@link javax.swing.JInternalFrame}.
* *
* @uiDefault InternalFrame.buttonHoverBackground Color * @uiDefault InternalFrame.buttonSize Dimension
* @uiDefault InternalFrame.buttonPressedBackground Color * @uiDefault InternalFrame.closeHoverBackground Color
* @uiDefault InternalFrame.closePressedBackground Color
* @uiDefault InternalFrame.closeHoverForeground Color
* @uiDefault InternalFrame.closePressedForeground Color
* *
* @author Karl Tauber * @author Karl Tauber
*/ */

View File

@@ -24,14 +24,14 @@ import java.awt.geom.Rectangle2D;
import com.formdev.flatlaf.ui.FlatUIUtils; import com.formdev.flatlaf.ui.FlatUIUtils;
/** /**
* "minimize" (actually "restore") icon for {@link javax.swing.JInternalFrame}. * "restore" (or "minimize") icon for {@link javax.swing.JInternalFrame}.
* *
* @author Karl Tauber * @author Karl Tauber
*/ */
public class FlatInternalFrameMinimizeIcon public class FlatInternalFrameRestoreIcon
extends FlatInternalFrameAbstractIcon extends FlatInternalFrameAbstractIcon
{ {
public FlatInternalFrameMinimizeIcon() { public FlatInternalFrameRestoreIcon() {
} }
@Override @Override

View File

@@ -19,6 +19,7 @@ package com.formdev.flatlaf.ui;
import static com.formdev.flatlaf.util.UIScale.scale; import static com.formdev.flatlaf.util.UIScale.scale;
import java.awt.BasicStroke; import java.awt.BasicStroke;
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.Graphics2D; import java.awt.Graphics2D;
@@ -26,6 +27,7 @@ import java.awt.Shape;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.geom.Path2D; import java.awt.geom.Path2D;
import javax.swing.JComponent;
import javax.swing.plaf.UIResource; import javax.swing.plaf.UIResource;
import javax.swing.plaf.basic.BasicArrowButton; import javax.swing.plaf.basic.BasicArrowButton;
@@ -111,6 +113,10 @@ public class FlatArrowButton
this.yOffset = yOffset; this.yOffset = yOffset;
} }
protected Color deriveHoverBackground( Color hoverBackground ) {
return hoverBackground;
}
@Override @Override
public Dimension getPreferredSize() { public Dimension getPreferredSize() {
return scale( super.getPreferredSize() ); return scale( super.getPreferredSize() );
@@ -132,31 +138,44 @@ public class FlatArrowButton
// paint hover background // paint hover background
if( enabled && isHover() && hoverBackground != null ) { if( enabled && isHover() && hoverBackground != null ) {
g.setColor( hoverBackground ); g.setColor( deriveHoverBackground( hoverBackground ) );
g.fillRect( 0, 0, width, height ); g.fillRect( 0, 0, width, height );
} }
int direction = getDirection(); int direction = getDirection();
boolean vert = (direction == NORTH || direction == SOUTH); boolean vert = (direction == NORTH || direction == SOUTH);
// compute width/height
int w = scale( arrowWidth + (chevron ? 0 : 1) ); int w = scale( arrowWidth + (chevron ? 0 : 1) );
int h = scale( (arrowWidth / 2) + (chevron ? 0 : 1) ); int h = scale( (arrowWidth / 2) + (chevron ? 0 : 1) );
// rotate width/height
int rw = vert ? w : h; int rw = vert ? w : h;
int rh = vert ? h : w; int rh = vert ? h : w;
// chevron lines end 1px outside of width/height
if( chevron ) {
// add 1px to width/height for position calculation only
rw++;
rh++;
}
int x = Math.round( (width - rw) / 2f + scale( (float) xOffset ) ); int x = Math.round( (width - rw) / 2f + scale( (float) xOffset ) );
int y = Math.round( (height - rh) / 2f + scale( (float) yOffset ) ); int y = Math.round( (height - rh) / 2f + scale( (float) yOffset ) );
// optimization for small chevron arrows (e.g. OneTouchButtons in SplitPane) // move arrow for round borders
if( x + rw >= width && x > 0 ) Container parent = getParent();
x--; if( vert && parent instanceof JComponent && FlatUIUtils.hasRoundBorder( (JComponent) parent ) )
if( y + rh >= height && y > 0 ) x -= scale( parent.getComponentOrientation().isLeftToRight() ? 1 : -1 );
y--;
// paint arrow // paint arrow
g.setColor( enabled g.setColor( enabled
? (isHover() && hoverForeground != null ? hoverForeground : foreground) ? (isHover() && hoverForeground != null ? hoverForeground : foreground)
: disabledForeground ); : disabledForeground );
g.translate( x, y ); g.translate( x, y );
/*debug
debugPaint( g2, vert, rw, rh );
debug*/
Shape arrowShape = createArrowShape( direction, chevron, w, h ); Shape arrowShape = createArrowShape( direction, chevron, w, h );
if( chevron ) { if( chevron ) {
g2.setStroke( new BasicStroke( scale( 1f ) ) ); g2.setStroke( new BasicStroke( scale( 1f ) ) );
@@ -177,4 +196,22 @@ public class FlatArrowButton
default: return new Path2D.Float(); default: return new Path2D.Float();
} }
} }
/*debug
private void debugPaint( Graphics g, boolean vert, int w, int h ) {
Color oldColor = g.getColor();
g.setColor( Color.red );
g.drawRect( 0, 0, w - 1, h - 1 );
int xy1 = -2;
int xy2 = h + 1;
for( int i = 0; i < 20; i++ ) {
g.drawRect( vert ? 0 : xy1, vert ? xy1 : 0, 0, 0 );
g.drawRect( vert ? 0 : xy2, vert ? xy2 : 0, 0, 0 );
xy1 -= 2;
xy2 += 2;
}
g.setColor( oldColor );
}
debug*/
} }

View File

@@ -36,6 +36,8 @@ import javax.swing.SwingUtilities;
import javax.swing.UIManager; import javax.swing.UIManager;
import javax.swing.plaf.basic.BasicBorders; import javax.swing.plaf.basic.BasicBorders;
import javax.swing.text.JTextComponent; import javax.swing.text.JTextComponent;
import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.util.DerivedColor;
/** /**
* Border for various components (e.g. {@link javax.swing.JTextField}). * Border for various components (e.g. {@link javax.swing.JTextField}).
@@ -54,6 +56,12 @@ import javax.swing.text.JTextComponent;
* @uiDefault Component.disabledBorderColor Color * @uiDefault Component.disabledBorderColor Color
* @uiDefault Component.focusedBorderColor Color * @uiDefault Component.focusedBorderColor Color
* *
* @uiDefault Component.error.borderColor Color
* @uiDefault Component.error.focusedBorderColor Color
* @uiDefault Component.warning.borderColor Color
* @uiDefault Component.warning.focusedBorderColor Color
* @uiDefault Component.custom.borderColor Color
*
* @author Karl Tauber * @author Karl Tauber
*/ */
public class FlatBorder public class FlatBorder
@@ -61,11 +69,18 @@ public class FlatBorder
{ {
protected final int focusWidth = UIManager.getInt( "Component.focusWidth" ); protected final int focusWidth = UIManager.getInt( "Component.focusWidth" );
protected final float innerFocusWidth = FlatUIUtils.getUIFloat( "Component.innerFocusWidth", 0 ); protected final float innerFocusWidth = FlatUIUtils.getUIFloat( "Component.innerFocusWidth", 0 );
protected final float innerOutlineWidth = FlatUIUtils.getUIFloat( "Component.innerOutlineWidth", 0 );
protected final Color focusColor = UIManager.getColor( "Component.focusColor" ); protected final Color focusColor = UIManager.getColor( "Component.focusColor" );
protected final Color borderColor = UIManager.getColor( "Component.borderColor" ); protected final Color borderColor = UIManager.getColor( "Component.borderColor" );
protected final Color disabledBorderColor = UIManager.getColor( "Component.disabledBorderColor" ); protected final Color disabledBorderColor = UIManager.getColor( "Component.disabledBorderColor" );
protected final Color focusedBorderColor = UIManager.getColor( "Component.focusedBorderColor" ); protected final Color focusedBorderColor = UIManager.getColor( "Component.focusedBorderColor" );
protected final Color errorBorderColor = UIManager.getColor( "Component.error.borderColor" );
protected final Color errorFocusedBorderColor = UIManager.getColor( "Component.error.focusedBorderColor" );
protected final Color warningBorderColor = UIManager.getColor( "Component.warning.borderColor" );
protected final Color warningFocusedBorderColor = UIManager.getColor( "Component.warning.focusedBorderColor" );
protected final Color customBorderColor = UIManager.getColor( "Component.custom.borderColor" );
@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();
@@ -73,25 +88,53 @@ public class FlatBorder
FlatUIUtils.setRenderingHints( g2 ); FlatUIUtils.setRenderingHints( g2 );
boolean isCellEditor = isTableCellEditor( c ); boolean isCellEditor = isTableCellEditor( c );
float focusWidth = isCellEditor ? 0 : getFocusWidth( c ); float focusWidth = isCellEditor ? 0 : scale( (float) getFocusWidth( c ) );
float borderWidth = getBorderWidth( c ); float borderWidth = scale( (float) getBorderWidth( c ) );
float arc = isCellEditor ? 0 : getArc( c ); float arc = isCellEditor ? 0 : scale( (float) getArc( c ) );
Color outlineColor = getOutlineColor( c );
if( isFocused( c ) ) { if( outlineColor != null || isFocused( c ) ) {
float innerFocusWidth = !(c instanceof JScrollPane) ? this.innerFocusWidth : 0; float innerFocusWidth = !(c instanceof JScrollPane)
? (outlineColor != null ? innerOutlineWidth : this.innerFocusWidth)
: 0;
g2.setColor( getFocusColor( c ) ); g2.setColor( (outlineColor != null) ? outlineColor : getFocusColor( c ) );
FlatUIUtils.paintComponentOuterBorder( g2, x, y, width, height, focusWidth, FlatUIUtils.paintComponentOuterBorder( g2, x, y, width, height, focusWidth,
getLineWidth( c ) + scale( innerFocusWidth ), arc ); scale( (float) getLineWidth( c ) ) + scale( innerFocusWidth ), arc );
} }
g2.setPaint( getBorderColor( c ) ); g2.setPaint( (outlineColor != null) ? outlineColor : getBorderColor( c ) );
FlatUIUtils.paintComponentBorder( g2, x, y, width, height, focusWidth, borderWidth, arc ); FlatUIUtils.paintComponentBorder( g2, x, y, width, height, focusWidth, borderWidth, arc );
} finally { } finally {
g2.dispose(); g2.dispose();
} }
} }
protected Color getOutlineColor( Component c ) {
if( !(c instanceof JComponent) )
return null;
Object outline = ((JComponent)c).getClientProperty( FlatClientProperties.OUTLINE );
if( outline instanceof String ) {
switch( (String) outline ) {
case FlatClientProperties.OUTLINE_ERROR:
return isFocused( c ) ? errorFocusedBorderColor : errorBorderColor;
case FlatClientProperties.OUTLINE_WARNING:
return isFocused( c ) ? warningFocusedBorderColor : warningBorderColor;
}
} else if( outline instanceof Color ) {
Color color = (Color) outline;
// use color functions to compute color for unfocused state
if( !isFocused( c ) && customBorderColor instanceof DerivedColor )
color = ((DerivedColor)customBorderColor).derive( color );
return color;
} else if( outline instanceof Color[] && ((Color[])outline).length >= 2 )
return ((Color[])outline)[isFocused( c ) ? 0 : 1];
return null;
}
protected Color getFocusColor( Component c ) { protected Color getFocusColor( Component c ) {
return focusColor; return focusColor;
} }
@@ -135,6 +178,9 @@ public class FlatBorder
Component editorComponent = ((JComboBox<?>)c).getEditor().getEditorComponent(); Component editorComponent = ((JComboBox<?>)c).getEditor().getEditorComponent();
return (editorComponent != null) ? FlatUIUtils.isPermanentFocusOwner( editorComponent ) : false; return (editorComponent != null) ? FlatUIUtils.isPermanentFocusOwner( editorComponent ) : false;
} else if( c instanceof JSpinner ) { } else if( c instanceof JSpinner ) {
if( FlatUIUtils.isPermanentFocusOwner( c ) )
return true;
JComponent editor = ((JSpinner)c).getEditor(); JComponent editor = ((JSpinner)c).getEditor();
if( editor instanceof JSpinner.DefaultEditor ) { if( editor instanceof JSpinner.DefaultEditor ) {
JTextField textField = ((JSpinner.DefaultEditor)editor).getTextField(); JTextField textField = ((JSpinner.DefaultEditor)editor).getTextField();
@@ -153,7 +199,8 @@ public class FlatBorder
@Override @Override
public Insets getBorderInsets( Component c, Insets insets ) { public Insets getBorderInsets( Component c, Insets insets ) {
boolean isCellEditor = isTableCellEditor( c ); boolean isCellEditor = isTableCellEditor( c );
float ow = (isCellEditor ? 0 : getFocusWidth( c )) + getLineWidth( c ); float focusWidth = isCellEditor ? 0 : scale( (float) getFocusWidth( c ) );
float ow = focusWidth + scale( (float) getLineWidth( c ) );
insets = super.getBorderInsets( c, insets ); insets = super.getBorderInsets( c, insets );
insets.top = Math.round( scale( (float) insets.top ) + ow ); insets.top = Math.round( scale( (float) insets.top ) + ow );
@@ -163,19 +210,33 @@ public class FlatBorder
return insets; return insets;
} }
protected float getFocusWidth( Component c ) { /**
return scale( (float) focusWidth ); * Returns the (unscaled) thickness of the outer focus border.
*/
protected int getFocusWidth( Component c ) {
return focusWidth;
} }
protected float getLineWidth( Component c ) { /**
return scale( 1f ); * Returns the (unscaled) line thickness used to compute the border insets.
* This may be different to {@link #getBorderWidth}.
*/
protected int getLineWidth( Component c ) {
return 1;
} }
protected float getBorderWidth( Component c ) { /**
* Returns the (unscaled) line thickness used to paint the border.
* This may be different to {@link #getLineWidth}.
*/
protected int getBorderWidth( Component c ) {
return getLineWidth( c ); return getLineWidth( c );
} }
protected float getArc( Component c ) { /**
* Returns the (unscaled) arc diameter of the border.
*/
protected int getArc( Component c ) {
return 0; return 0;
} }
} }

View File

@@ -16,7 +16,6 @@
package com.formdev.flatlaf.ui; package com.formdev.flatlaf.ui;
import static com.formdev.flatlaf.util.UIScale.scale;
import java.awt.Color; import java.awt.Color;
import java.awt.Component; import java.awt.Component;
import java.awt.GradientPaint; import java.awt.GradientPaint;
@@ -115,8 +114,8 @@ public class FlatButtonBorder
} else { } else {
insets = super.getBorderInsets( c, insets ); insets = super.getBorderInsets( c, insets );
// use smaller left and right insets for icon-only buttons (so that they are square) // use smaller left and right insets for icon-only or single-character buttons (so that they are square)
if( FlatButtonUI.isIconOnlyButton( c ) && ((AbstractButton)c).getMargin() instanceof UIResource ) if( FlatButtonUI.isIconOnlyOrSingleCharacterButton( c ) && ((AbstractButton)c).getMargin() instanceof UIResource )
insets.left = insets.right = Math.min( insets.top, insets.bottom ); insets.left = insets.right = Math.min( insets.top, insets.bottom );
} }
@@ -124,17 +123,21 @@ public class FlatButtonBorder
} }
@Override @Override
protected float getFocusWidth( Component c ) { protected int getFocusWidth( Component c ) {
return FlatToggleButtonUI.isTabButton( c ) ? 0 : super.getFocusWidth(c ); return FlatToggleButtonUI.isTabButton( c ) ? 0 : super.getFocusWidth( c );
} }
@Override @Override
protected float getBorderWidth( Component c ) { protected int getBorderWidth( Component c ) {
return FlatButtonUI.isDefaultButton( c ) ? scale( (float) defaultBorderWidth ) : super.getBorderWidth( c ); return FlatButtonUI.isDefaultButton( c ) ? defaultBorderWidth : super.getBorderWidth( c );
} }
@Override @Override
protected float getArc( Component c ) { protected int getArc( Component c ) {
return FlatButtonUI.isSquareButton( c ) ? 0 : scale( (float) arc ); switch( FlatButtonUI.getButtonType( c ) ) {
case FlatButtonUI.TYPE_SQUARE: return 0;
case FlatButtonUI.TYPE_ROUND_RECT: return Short.MAX_VALUE;
default: return arc;
}
} }
} }

View File

@@ -39,7 +39,6 @@ import javax.swing.JToggleButton;
import javax.swing.JToolBar; import javax.swing.JToolBar;
import javax.swing.LookAndFeel; import javax.swing.LookAndFeel;
import javax.swing.UIManager; import javax.swing.UIManager;
import javax.swing.border.Border;
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.BasicButtonListener; import javax.swing.plaf.basic.BasicButtonListener;
@@ -61,8 +60,6 @@ import com.formdev.flatlaf.util.UIScale;
* *
* <!-- FlatButtonUI --> * <!-- FlatButtonUI -->
* *
* @uiDefault Component.focusWidth int
* @uiDefault Button.arc int
* @uiDefault Button.minimumWidth int * @uiDefault Button.minimumWidth int
* @uiDefault Button.iconTextGap int * @uiDefault Button.iconTextGap int
* @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
@@ -92,8 +89,6 @@ import com.formdev.flatlaf.util.UIScale;
public class FlatButtonUI public class FlatButtonUI
extends BasicButtonUI extends BasicButtonUI
{ {
protected int focusWidth;
protected int arc;
protected int minimumWidth; protected int minimumWidth;
protected int iconTextGap; protected int iconTextGap;
@@ -139,8 +134,6 @@ public class FlatButtonUI
if( !defaults_initialized ) { if( !defaults_initialized ) {
String prefix = getPropertyPrefix(); String prefix = getPropertyPrefix();
focusWidth = UIManager.getInt( "Component.focusWidth" );
arc = UIManager.getInt( "Button.arc" );
minimumWidth = UIManager.getInt( prefix + "minimumWidth" ); minimumWidth = UIManager.getInt( prefix + "minimumWidth" );
iconTextGap = FlatUIUtils.getUIInt( prefix + "iconTextGap", 4 ); iconTextGap = FlatUIUtils.getUIInt( prefix + "iconTextGap", 4 );
@@ -187,7 +180,7 @@ public class FlatButtonUI
LookAndFeel.installProperty( b, "opaque", false ); LookAndFeel.installProperty( b, "opaque", false );
LookAndFeel.installProperty( b, "iconTextGap", scale( iconTextGap ) ); LookAndFeel.installProperty( b, "iconTextGap", scale( iconTextGap ) );
MigLayoutVisualPadding.install( b, getFocusWidth( b ) ); MigLayoutVisualPadding.install( b );
} }
@Override @Override
@@ -215,6 +208,11 @@ public class FlatButtonUI
case MINIMUM_HEIGHT: case MINIMUM_HEIGHT:
b.revalidate(); b.revalidate();
break; break;
case BUTTON_TYPE:
b.revalidate();
b.repaint();
break;
} }
} }
@@ -226,7 +224,11 @@ public class FlatButtonUI
return c instanceof JButton && ((JButton)c).isDefaultButton(); return c instanceof JButton && ((JButton)c).isDefaultButton();
} }
static boolean isIconOnlyButton( Component c ) { /**
* Returns true if the button has an icon but no text,
* or it it does not have an icon and the text is either "..." or one character.
*/
static boolean isIconOnlyOrSingleCharacterButton( Component c ) {
if( !(c instanceof JButton) && !(c instanceof JToggleButton) ) if( !(c instanceof JButton) && !(c instanceof JToggleButton) )
return false; return false;
@@ -236,8 +238,15 @@ public class FlatButtonUI
(icon == null && text != null && ("...".equals( text ) || text.length() == 1)); (icon == null && text != null && ("...".equals( text ) || text.length() == 1));
} }
static boolean isSquareButton( Component c ) { // same indices as in parameters to clientPropertyChoice()
return c instanceof AbstractButton && clientPropertyEquals( (AbstractButton) c, BUTTON_TYPE, BUTTON_TYPE_SQUARE ); static final int TYPE_OTHER = -1;
static final int TYPE_SQUARE = 0;
static final int TYPE_ROUND_RECT = 1;
static int getButtonType( Component c ) {
return (c instanceof AbstractButton)
? clientPropertyChoice( (AbstractButton) c, BUTTON_TYPE, BUTTON_TYPE_SQUARE, BUTTON_TYPE_ROUND_RECT )
: TYPE_OTHER;
} }
static boolean isHelpButton( Component c ) { static boolean isHelpButton( Component c ) {
@@ -245,7 +254,8 @@ public class FlatButtonUI
} }
static boolean isToolBarButton( Component c ) { static boolean isToolBarButton( Component c ) {
return c.getParent() instanceof JToolBar; return c.getParent() instanceof JToolBar ||
(c instanceof AbstractButton && clientPropertyEquals( (AbstractButton) c, BUTTON_TYPE, BUTTON_TYPE_TOOLBAR_BUTTON ));
} }
@Override @Override
@@ -272,11 +282,10 @@ public class FlatButtonUI
try { try {
FlatUIUtils.setRenderingHints( g2 ); FlatUIUtils.setRenderingHints( g2 );
Border border = c.getBorder();
boolean isToolBarButton = isToolBarButton( c ); boolean isToolBarButton = isToolBarButton( c );
float focusWidth = (border instanceof FlatBorder && !isToolBarButton) ? scale( (float) getFocusWidth( c ) ) : 0; float focusWidth = isToolBarButton ? 0 : FlatUIUtils.getBorderFocusWidth( c );
float arc = ((border instanceof FlatButtonBorder && !isSquareButton( c )) || isToolBarButton) float arc = FlatUIUtils.getBorderArc( c );
? scale( (float) this.arc ) : 0;
boolean def = isDefaultButton( c ); boolean def = isDefaultButton( c );
int x = 0; int x = 0;
@@ -308,7 +317,7 @@ public class FlatButtonUI
if( background == startBg && endBg != null && !startBg.equals( endBg ) ) if( background == startBg && endBg != null && !startBg.equals( endBg ) )
g2.setPaint( new GradientPaint( 0, 0, startBg, 0, height, endBg ) ); g2.setPaint( new GradientPaint( 0, 0, startBg, 0, height, endBg ) );
else else
FlatUIUtils.setColor( g2, background, def ? defaultBackground : c.getBackground() ); g2.setColor( FlatUIUtils.deriveColor( background, def ? defaultBackground : c.getBackground() ) );
FlatUIUtils.paintComponentBackground( g2, x, y, width, height, focusWidth, arc ); FlatUIUtils.paintComponentBackground( g2, x, y, width, height, focusWidth, arc );
} finally { } finally {
@@ -401,23 +410,21 @@ public class FlatButtonUI
return new Dimension( helpButtonIcon.getIconWidth(), helpButtonIcon.getIconHeight() ); return new Dimension( helpButtonIcon.getIconWidth(), helpButtonIcon.getIconHeight() );
Dimension prefSize = super.getPreferredSize( c ); Dimension prefSize = super.getPreferredSize( c );
if ( prefSize == null ) if( prefSize == null )
return null; return null;
// make button square if it is a icon-only button // make button square if it is a single-character button
// or apply minimum width, if not in toolbar and not a icon-only button // or apply minimum width, if not in toolbar and not a icon-only or single-character button
if( isIconOnlyButton( c ) ) if( isIconOnlyOrSingleCharacterButton( c ) ) {
prefSize.width = Math.max( prefSize.width, prefSize.height ); // make only single-character buttons square to allow non-square icon-only buttons
else if( !isToolBarButton( c ) && c.getBorder() instanceof FlatButtonBorder ) { if( ((AbstractButton)c).getIcon() == null )
int focusWidth = getFocusWidth( c ); prefSize.width = Math.max( prefSize.width, prefSize.height );
prefSize.width = Math.max( prefSize.width, scale( FlatUIUtils.minimumWidth( c, minimumWidth ) + (focusWidth * 2) ) ); } else if( !isToolBarButton( c ) && c.getBorder() instanceof FlatButtonBorder ) {
prefSize.height = Math.max( prefSize.height, scale( FlatUIUtils.minimumHeight( c, 0 ) + (focusWidth * 2) ) ); float focusWidth = FlatUIUtils.getBorderFocusWidth( c );
prefSize.width = Math.max( prefSize.width, scale( FlatUIUtils.minimumWidth( c, minimumWidth ) ) + Math.round( focusWidth * 2 ) );
prefSize.height = Math.max( prefSize.height, scale( FlatUIUtils.minimumHeight( c, 0 ) ) + Math.round( focusWidth * 2 ) );
} }
return prefSize; return prefSize;
} }
protected int getFocusWidth( JComponent c ) {
return focusWidth;
}
} }

View File

@@ -39,6 +39,7 @@ import java.beans.PropertyChangeListener;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import javax.swing.AbstractAction; import javax.swing.AbstractAction;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.ComboBoxEditor;
import javax.swing.DefaultListCellRenderer; import javax.swing.DefaultListCellRenderer;
import javax.swing.InputMap; import javax.swing.InputMap;
import javax.swing.JButton; import javax.swing.JButton;
@@ -46,6 +47,7 @@ import javax.swing.JComboBox;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JList; import javax.swing.JList;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.KeyStroke; import javax.swing.KeyStroke;
import javax.swing.ListCellRenderer; import javax.swing.ListCellRenderer;
import javax.swing.LookAndFeel; import javax.swing.LookAndFeel;
@@ -76,8 +78,8 @@ import com.formdev.flatlaf.util.UIScale;
* *
* <!-- FlatComboBoxUI --> * <!-- FlatComboBoxUI -->
* *
* @uiDefault Component.focusWidth int * @uiDefault ComboBox.minimumWidth int
* @uiDefault Component.arc int * @uiDefault ComboBox.editorColumns int
* @uiDefault Component.arrowType String triangle (default) or chevron * @uiDefault Component.arrowType String triangle (default) or chevron
* @uiDefault Component.isIntelliJTheme boolean * @uiDefault Component.isIntelliJTheme boolean
* @uiDefault Component.borderColor Color * @uiDefault Component.borderColor Color
@@ -96,8 +98,8 @@ import com.formdev.flatlaf.util.UIScale;
public class FlatComboBoxUI public class FlatComboBoxUI
extends BasicComboBoxUI extends BasicComboBoxUI
{ {
protected int focusWidth; protected int minimumWidth;
protected int arc; protected int editorColumns;
protected String arrowType; protected String arrowType;
protected boolean isIntelliJTheme; protected boolean isIntelliJTheme;
protected Color borderColor; protected Color borderColor;
@@ -150,8 +152,8 @@ public class FlatComboBoxUI
LookAndFeel.installProperty( comboBox, "opaque", false ); LookAndFeel.installProperty( comboBox, "opaque", false );
focusWidth = UIManager.getInt( "Component.focusWidth" ); minimumWidth = UIManager.getInt( "ComboBox.minimumWidth" );
arc = UIManager.getInt( "Component.arc" ); editorColumns = UIManager.getInt( "ComboBox.editorColumns" );
arrowType = UIManager.getString( "Component.arrowType" ); arrowType = UIManager.getString( "Component.arrowType" );
isIntelliJTheme = UIManager.getBoolean( "Component.isIntelliJTheme" ); isIntelliJTheme = UIManager.getBoolean( "Component.isIntelliJTheme" );
borderColor = UIManager.getColor( "Component.borderColor" ); borderColor = UIManager.getColor( "Component.borderColor" );
@@ -170,7 +172,7 @@ public class FlatComboBoxUI
// scale // scale
padding = UIScale.scale( padding ); padding = UIScale.scale( padding );
MigLayoutVisualPadding.install( comboBox, focusWidth ); MigLayoutVisualPadding.install( comboBox );
} }
@Override @Override
@@ -249,6 +251,10 @@ public class FlatComboBoxUI
editor.applyComponentOrientation( o ); editor.applyComponentOrientation( o );
} else if( editor != null && FlatClientProperties.PLACEHOLDER_TEXT.equals( propertyName ) ) } else if( editor != null && FlatClientProperties.PLACEHOLDER_TEXT.equals( propertyName ) )
editor.repaint(); editor.repaint();
else if( FlatClientProperties.COMPONENT_ROUND_RECT.equals( propertyName ) )
comboBox.repaint();
else if( FlatClientProperties.MINIMUM_WIDTH.equals( propertyName ) )
comboBox.revalidate();
} }
}; };
} }
@@ -258,18 +264,30 @@ public class FlatComboBoxUI
return new FlatComboPopup( comboBox ); return new FlatComboPopup( comboBox );
} }
@Override
protected ComboBoxEditor createEditor() {
ComboBoxEditor comboBoxEditor = super.createEditor();
Component editor = comboBoxEditor.getEditorComponent();
if( editor instanceof JTextField ) {
JTextField textField = (JTextField) editor;
textField.setColumns( editorColumns );
// assign a non-null and non-javax.swing.plaf.UIResource border to the text field,
// otherwise it is replaced with default text field border when switching LaF
// because javax.swing.plaf.basic.BasicComboBoxEditor.BorderlessTextField.setBorder()
// uses "border instanceof javax.swing.plaf.basic.BasicComboBoxEditor.UIResource"
// instead of "border instanceof javax.swing.plaf.UIResource"
textField.setBorder( BorderFactory.createEmptyBorder() );
}
return comboBoxEditor;
}
@Override @Override
protected void configureEditor() { protected void configureEditor() {
super.configureEditor(); super.configureEditor();
// assign a non-javax.swing.plaf.UIResource border to the text field,
// otherwise it is replaced with default text field border when switching LaF
// because javax.swing.plaf.basic.BasicComboBoxEditor.BorderlessTextField.setBorder()
// uses "border instanceof javax.swing.plaf.basic.BasicComboBoxEditor.UIResource"
// instead of "border instanceof javax.swing.plaf.UIResource"
if( editor instanceof JTextComponent )
((JTextComponent)editor).setBorder( BorderFactory.createEmptyBorder() );
// explicitly make non-opaque // explicitly make non-opaque
if( editor instanceof JComponent ) if( editor instanceof JComponent )
((JComponent)editor).setOpaque( false ); ((JComponent)editor).setOpaque( false );
@@ -318,8 +336,11 @@ public class FlatComboBoxUI
@Override @Override
public void update( Graphics g, JComponent c ) { public void update( Graphics g, JComponent c ) {
float focusWidth = FlatUIUtils.getBorderFocusWidth( c );
float arc = FlatUIUtils.getBorderArc( c );
// fill background if opaque to avoid garbage if user sets opaque to true // fill background if opaque to avoid garbage if user sets opaque to true
if( c.isOpaque() && (focusWidth > 0 || arc != 0) ) if( c.isOpaque() && (focusWidth > 0 || arc > 0) )
FlatUIUtils.paintParentBackground( g, c ); FlatUIUtils.paintParentBackground( g, c );
Graphics2D g2 = (Graphics2D) g; Graphics2D g2 = (Graphics2D) g;
@@ -327,8 +348,6 @@ public class FlatComboBoxUI
int width = c.getWidth(); int width = c.getWidth();
int height = c.getHeight(); int height = c.getHeight();
float focusWidth = (c.getBorder() instanceof FlatBorder) ? scale( (float) this.focusWidth ) : 0;
float arc = (c.getBorder() instanceof FlatRoundBorder) ? scale( (float) this.arc ) : 0;
int arrowX = arrowButton.getX(); int arrowX = arrowButton.getX();
int arrowWidth = arrowButton.getWidth(); int arrowWidth = arrowButton.getWidth();
boolean enabled = comboBox.isEnabled(); boolean enabled = comboBox.isEnabled();
@@ -394,14 +413,20 @@ public class FlatComboBoxUI
@Override @Override
public void paintCurrentValueBackground( Graphics g, Rectangle bounds, boolean hasFocus ) { public void paintCurrentValueBackground( Graphics g, Rectangle bounds, boolean hasFocus ) {
g.setColor( comboBox.isEnabled() ? comboBox.getBackground() : getDisabledBackground( comboBox ) ); // not necessary because already painted in update()
g.fillRect( bounds.x, bounds.y, bounds.width, bounds.height );
} }
private Color getDisabledBackground( JComponent c ) { private Color getDisabledBackground( JComponent c ) {
return isIntelliJTheme ? FlatUIUtils.getParentBackground( c ) : disabledBackground; return isIntelliJTheme ? FlatUIUtils.getParentBackground( c ) : disabledBackground;
} }
@Override
public Dimension getMinimumSize( JComponent c ) {
Dimension minimumSize = super.getMinimumSize( c );
minimumSize.width = Math.max( minimumSize.width, scale( FlatUIUtils.minimumWidth( c, minimumWidth ) ) );
return minimumSize;
}
@Override @Override
protected Dimension getDefaultSize() { protected Dimension getDefaultSize() {
@SuppressWarnings( "unchecked" ) @SuppressWarnings( "unchecked" )
@@ -422,6 +447,18 @@ public class FlatComboBoxUI
Dimension displaySize = super.getDisplaySize(); Dimension displaySize = super.getDisplaySize();
// recalculate width without hardcoded 100 under special conditions
if( displaySize.width == 100 + padding.left + padding.right &&
comboBox.isEditable() &&
comboBox.getItemCount() == 0 &&
comboBox.getPrototypeDisplayValue() == null )
{
int width = getDefaultSize().width;
width = Math.max( width, editor.getPreferredSize().width );
width += padding.left + padding.right;
displaySize = new Dimension( width, displaySize.height );
}
uninstallCellPaddingBorder( renderer ); uninstallCellPaddingBorder( renderer );
return displaySize; return displaySize;
} }

View File

@@ -0,0 +1,223 @@
/*
* Copyright 2020 FormDev Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.formdev.flatlaf.ui;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Insets;
import java.awt.RadialGradientPaint;
import java.awt.image.BufferedImage;
import com.formdev.flatlaf.util.HiDPIUtils;
import com.formdev.flatlaf.util.UIScale;
/**
* Paints a drop shadow border around the component.
* Supports 1-sided, 2-side, 3-sided or 4-sided drop shadows.
* <p>
* The shadow insets allow specifying drop shadow thickness for each side.
* A zero or negative value hides the drop shadow on that side.
* A negative value can be used to indent the drop shadow on corners.
* E.g. -4 on left indents drop shadow at top-left and bottom-left corners by 4 pixels.
*
* @author Karl Tauber
*/
public class FlatDropShadowBorder
extends FlatEmptyBorder
{
private final Color shadowColor;
private final Insets shadowInsets;
private final float shadowOpacity;
private final int shadowSize;
private Image shadowImage;
private Color lastShadowColor;
private double lastSystemScaleFactor;
private float lastUserScaleFactor;
public FlatDropShadowBorder() {
this( null );
}
public FlatDropShadowBorder( Color shadowColor ) {
this( shadowColor, 4, 0.5f );
}
public FlatDropShadowBorder( Color shadowColor, int shadowSize, float shadowOpacity ) {
this( shadowColor, new Insets( -shadowSize, -shadowSize, shadowSize, shadowSize ), shadowOpacity );
}
public FlatDropShadowBorder( Color shadowColor, Insets shadowInsets, float shadowOpacity ) {
super( Math.max( shadowInsets.top, 0 ), Math.max( shadowInsets.left, 0 ),
Math.max( shadowInsets.bottom, 0 ), Math.max( shadowInsets.right, 0 ) );
this.shadowColor = shadowColor;
this.shadowInsets = shadowInsets;
this.shadowOpacity = shadowOpacity;
shadowSize = Math.max(
Math.max( shadowInsets.left, shadowInsets.right ),
Math.max( shadowInsets.top, shadowInsets.bottom ) );
}
@Override
public void paintBorder( Component c, Graphics g, int x, int y, int width, int height ) {
if( shadowSize <= 0 )
return;
HiDPIUtils.paintAtScale1x( (Graphics2D) g, x, y, width, height, this::paintImpl );
}
private void paintImpl( Graphics2D g, int x, int y, int width, int height, double scaleFactor ) {
Color shadowColor = (this.shadowColor != null) ? this.shadowColor : g.getColor();
int shadowSize = scale( this.shadowSize, scaleFactor );
// create and cache shadow image
float userScaleFactor = UIScale.getUserScaleFactor();
if( shadowImage == null ||
!shadowColor.equals( lastShadowColor ) ||
lastSystemScaleFactor != scaleFactor ||
lastUserScaleFactor != userScaleFactor )
{
shadowImage = createShadowImage( shadowColor, shadowSize, shadowOpacity,
(float) (scaleFactor * userScaleFactor) );
lastShadowColor = shadowColor;
lastSystemScaleFactor = scaleFactor;
lastUserScaleFactor = userScaleFactor;
}
/*debug
int m = shadowImage.getWidth( null );
Color oldColor = g.getColor();
g.setColor( Color.lightGray );
g.drawRect( x - m - 1, y - m - 1, m + 1, m + 1 );
g.setColor( Color.white );
g.fillRect( x - m, y - m, m, m );
g.drawImage( shadowImage, x - m, y - m, null );
g.setColor( oldColor );
debug*/
int left = scale( shadowInsets.left, scaleFactor );
int right = scale( shadowInsets.right, scaleFactor );
int top = scale( shadowInsets.top, scaleFactor );
int bottom = scale( shadowInsets.bottom, scaleFactor );
// shadow outer coordinates
int x1o = x - Math.min( left, 0 );
int y1o = y - Math.min( top, 0 );
int x2o = x + width + Math.min( right, 0 );
int y2o = y + height + Math.min( bottom, 0 );
// shadow inner coordinates
int x1i = x1o + shadowSize;
int y1i = y1o + shadowSize;
int x2i = x2o - shadowSize;
int y2i = y2o - shadowSize;
int wh = (shadowSize * 2) - 1;
int center = shadowSize - 1;
// left-top edge
if( left > 0 || top > 0 ) {
g.drawImage( shadowImage, x1o, y1o, x1i, y1i,
0, 0, center, center, null );
}
// top shadow
if( top > 0 ) {
g.drawImage( shadowImage, x1i, y1o, x2i, y1i,
center, 0, center + 1, center, null );
}
// right-top edge
if( right > 0 || top > 0 ) {
g.drawImage( shadowImage, x2i, y1o, x2o, y1i,
center, 0, wh, center, null );
}
// left shadow
if( left > 0 ) {
g.drawImage( shadowImage, x1o, y1i, x1i, y2i,
0, center, center, center + 1, null );
}
// right shadow
if( right > 0 ) {
g.drawImage( shadowImage, x2i, y1i, x2o, y2i,
center, center, wh, center + 1, null );
}
// left-bottom edge
if( left > 0 || bottom > 0 ) {
g.drawImage( shadowImage, x1o, y2i, x1i, y2o,
0, center, center, wh, null );
}
// bottom shadow
if( bottom > 0 ) {
g.drawImage( shadowImage, x1i, y2i, x2i, y2o,
center, center, center + 1, wh, null );
}
// right-bottom edge
if( right > 0 || bottom > 0 ) {
g.drawImage( shadowImage, x2i, y2i, x2o, y2o,
center, center, wh, wh, null );
}
}
private int scale( int value, double scaleFactor ) {
return (int) Math.ceil( UIScale.scale( value ) * scaleFactor );
}
private static BufferedImage createShadowImage( Color shadowColor, int shadowSize,
float shadowOpacity, float scaleFactor )
{
int shadowRGB = shadowColor.getRGB() & 0xffffff;
int shadowAlpha = (int) (255 * shadowOpacity);
Color startColor = new Color( shadowRGB | ((shadowAlpha & 0xff) << 24), true );
Color midColor = new Color( shadowRGB | (((shadowAlpha / 2) & 0xff) << 24), true );
Color endColor = new Color( shadowRGB, true );
/*debug
startColor = Color.red;
midColor = Color.green;
endColor = Color.blue;
debug*/
int wh = (shadowSize * 2) - 1;
int center = shadowSize - 1;
RadialGradientPaint p = new RadialGradientPaint( center, center,
shadowSize - (0.75f * scaleFactor),
new float[] { 0, 0.35f, 1 },
new Color[] { startColor, midColor, endColor } );
BufferedImage image = new BufferedImage( wh, wh, BufferedImage.TYPE_INT_ARGB );
Graphics2D g = image.createGraphics();
try {
g.setPaint( p );
g.fillRect( 0, 0, wh, wh );
} finally {
g.dispose();
}
return image;
}
}

View File

@@ -19,6 +19,7 @@ package com.formdev.flatlaf.ui;
import static com.formdev.flatlaf.util.UIScale.scale; import static com.formdev.flatlaf.util.UIScale.scale;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Graphics; import java.awt.Graphics;
import java.beans.PropertyChangeEvent;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JEditorPane; import javax.swing.JEditorPane;
import javax.swing.UIManager; import javax.swing.UIManager;
@@ -26,6 +27,7 @@ import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.UIResource; import javax.swing.plaf.UIResource;
import javax.swing.plaf.basic.BasicEditorPaneUI; import javax.swing.plaf.basic.BasicEditorPaneUI;
import javax.swing.text.JTextComponent; import javax.swing.text.JTextComponent;
import com.formdev.flatlaf.FlatClientProperties;
/** /**
* Provides the Flat LaF UI delegate for {@link javax.swing.JEditorPane}. * Provides the Flat LaF UI delegate for {@link javax.swing.JEditorPane}.
@@ -83,22 +85,36 @@ public class FlatEditorPaneUI
getComponent().putClientProperty( JEditorPane.HONOR_DISPLAY_PROPERTIES, oldHonorDisplayProperties ); getComponent().putClientProperty( JEditorPane.HONOR_DISPLAY_PROPERTIES, oldHonorDisplayProperties );
} }
@Override
protected void propertyChange( PropertyChangeEvent e ) {
super.propertyChange( e );
propertyChange( getComponent(), e );
}
static void propertyChange( JTextComponent c, PropertyChangeEvent e ) {
switch( e.getPropertyName() ) {
case FlatClientProperties.MINIMUM_WIDTH:
c.revalidate();
break;
}
}
@Override @Override
public Dimension getPreferredSize( JComponent c ) { public Dimension getPreferredSize( JComponent c ) {
return applyMinimumWidth( super.getPreferredSize( c ) ); return applyMinimumWidth( c, super.getPreferredSize( c ), minimumWidth );
} }
@Override @Override
public Dimension getMinimumSize( JComponent c ) { public Dimension getMinimumSize( JComponent c ) {
return applyMinimumWidth( super.getMinimumSize( c ) ); return applyMinimumWidth( c, super.getMinimumSize( c ), minimumWidth );
} }
private Dimension applyMinimumWidth( Dimension size ) { static Dimension applyMinimumWidth( JComponent c, Dimension size, int minimumWidth ) {
// Assume that text area is in a scroll pane (that displays the border) // Assume that text area is in a scroll pane (that displays the border)
// and subtract 1px border line width. // and subtract 1px border line width.
// Using "(scale( 1 ) * 2)" instead of "scale( 2 )" to deal with rounding // Using "(scale( 1 ) * 2)" instead of "scale( 2 )" to deal with rounding
// issues. E.g. at scale factor 1.5 the first returns 4, but the second 3. // issues. E.g. at scale factor 1.5 the first returns 4, but the second 3.
int minimumWidth = FlatUIUtils.minimumWidth( getComponent(), this.minimumWidth ); minimumWidth = FlatUIUtils.minimumWidth( c, minimumWidth );
size.width = Math.max( size.width, scale( minimumWidth ) - (scale( 1 ) * 2) ); size.width = Math.max( size.width, scale( minimumWidth ) - (scale( 1 ) * 2) );
return size; return size;
} }

View File

@@ -16,11 +16,27 @@
package com.formdev.flatlaf.ui; package com.formdev.flatlaf.ui;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Insets;
import java.io.File;
import javax.swing.AbstractButton;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JFileChooser; import javax.swing.JFileChooser;
import javax.swing.JPanel;
import javax.swing.JToggleButton;
import javax.swing.UIManager;
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 com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.util.ScaledImageIcon;
import com.formdev.flatlaf.util.UIScale; import com.formdev.flatlaf.util.UIScale;
/** /**
@@ -86,6 +102,7 @@ import com.formdev.flatlaf.util.UIScale;
* @uiDefault FileChooser.folderNameLabelText String * @uiDefault FileChooser.folderNameLabelText String
* @uiDefault FileChooser.filesOfTypeLabelMnemonic String * @uiDefault FileChooser.filesOfTypeLabelMnemonic String
* @uiDefault FileChooser.filesOfTypeLabelText String * @uiDefault FileChooser.filesOfTypeLabelText String
*
* @uiDefault FileChooser.upFolderToolTipText String * @uiDefault FileChooser.upFolderToolTipText String
* @uiDefault FileChooser.upFolderAccessibleName String * @uiDefault FileChooser.upFolderAccessibleName String
* @uiDefault FileChooser.homeFolderToolTipText String * @uiDefault FileChooser.homeFolderToolTipText String
@@ -97,11 +114,27 @@ import com.formdev.flatlaf.util.UIScale;
* @uiDefault FileChooser.detailsViewButtonToolTipText String * @uiDefault FileChooser.detailsViewButtonToolTipText String
* @uiDefault FileChooser.detailsViewButtonAccessibleName String * @uiDefault FileChooser.detailsViewButtonAccessibleName String
* *
* <!-- FilePane -->
*
* @uiDefault FileChooser.fileNameHeaderText String
* @uiDefault FileChooser.fileSizeHeaderText String
* @uiDefault FileChooser.fileTypeHeaderText String
* @uiDefault FileChooser.fileDateHeaderText String
* @uiDefault FileChooser.fileAttrHeaderText String
*
* @uiDefault FileChooser.viewMenuLabelText String
* @uiDefault FileChooser.refreshActionLabelText String
* @uiDefault FileChooser.newFolderActionLabelText String
* @uiDefault FileChooser.listViewActionLabelText String
* @uiDefault FileChooser.detailsViewActionLabelText String
*
* @author Karl Tauber * @author Karl Tauber
*/ */
public class FlatFileChooserUI public class FlatFileChooserUI
extends MetalFileChooserUI extends MetalFileChooserUI
{ {
private final FlatFileView fileView = new FlatFileView();
public static ComponentUI createUI( JComponent c ) { public static ComponentUI createUI( JComponent c ) {
return new FlatFileChooserUI( (JFileChooser) c ); return new FlatFileChooserUI( (JFileChooser) c );
} }
@@ -110,6 +143,40 @@ public class FlatFileChooserUI
super( filechooser ); super( filechooser );
} }
@Override
public void installComponents( JFileChooser fc ) {
super.installComponents( fc );
patchUI( fc );
}
private void patchUI( JFileChooser fc ) {
// turn top-right buttons into toolbar buttons
Component topPanel = fc.getComponent( 0 );
if( (topPanel instanceof JPanel) &&
(((JPanel)topPanel).getLayout() instanceof BorderLayout) )
{
Component topButtonPanel = ((JPanel)topPanel).getComponent( 0 );
if( (topButtonPanel instanceof JPanel) &&
(((JPanel)topButtonPanel).getLayout() instanceof BoxLayout) )
{
Insets margin = UIManager.getInsets( "Button.margin" );
Component[] comps = ((JPanel)topButtonPanel).getComponents();
for( int i = comps.length - 1; i >= 0; i-- ) {
Component c = comps[i];
if( c instanceof JButton || c instanceof JToggleButton ) {
AbstractButton b = (AbstractButton)c;
b.putClientProperty( FlatClientProperties.BUTTON_TYPE,
FlatClientProperties.BUTTON_TYPE_TOOLBAR_BUTTON );
b.setMargin( margin );
b.setFocusable( false );
} else if( c instanceof Box.Filler )
((JPanel)topButtonPanel).remove( i );
}
}
}
}
@Override @Override
public Dimension getPreferredSize( JComponent c ) { public Dimension getPreferredSize( JComponent c ) {
return UIScale.scale( super.getPreferredSize( c ) ); return UIScale.scale( super.getPreferredSize( c ) );
@@ -119,4 +186,50 @@ public class FlatFileChooserUI
public Dimension getMinimumSize( JComponent c ) { public Dimension getMinimumSize( JComponent c ) {
return UIScale.scale( super.getMinimumSize( c ) ); return UIScale.scale( super.getMinimumSize( c ) );
} }
@Override
public FileView getFileView( JFileChooser fc ) {
return fileView;
}
@Override
public void clearIconCache() {
fileView.clearIconCache();
}
//---- class FlatFileView -------------------------------------------------
private class FlatFileView
extends BasicFileView
{
@Override
public Icon getIcon( File f ) {
// get cached icon
Icon icon = getCachedIcon( f );
if( icon != null )
return icon;
// get system icon
if( f != null ) {
icon = getFileChooser().getFileSystemView().getSystemIcon( f );
if( icon != null ) {
if( icon instanceof ImageIcon )
icon = new ScaledImageIcon( (ImageIcon) icon );
cacheIcon( f, icon );
return icon;
}
}
// get default icon
icon = super.getIcon( f );
if( icon instanceof ImageIcon ) {
icon = new ScaledImageIcon( (ImageIcon) icon );
cacheIcon( f, icon );
}
return icon;
}
}
} }

View File

@@ -112,6 +112,16 @@ public class FlatInternalFrameUI
private final Color activeBorderColor = UIManager.getColor( "InternalFrame.activeBorderColor" ); private final Color activeBorderColor = UIManager.getColor( "InternalFrame.activeBorderColor" );
private final Color inactiveBorderColor = UIManager.getColor( "InternalFrame.inactiveBorderColor" ); private final Color inactiveBorderColor = UIManager.getColor( "InternalFrame.inactiveBorderColor" );
private final int borderLineWidth = FlatUIUtils.getUIInt( "InternalFrame.borderLineWidth", 1 ); private final int borderLineWidth = FlatUIUtils.getUIInt( "InternalFrame.borderLineWidth", 1 );
private final boolean dropShadowPainted = UIManager.getBoolean( "InternalFrame.dropShadowPainted" );
private final FlatDropShadowBorder activeDropShadowBorder = new FlatDropShadowBorder(
UIManager.getColor( "InternalFrame.activeDropShadowColor" ),
UIManager.getInsets( "InternalFrame.activeDropShadowInsets" ),
FlatUIUtils.getUIFloat( "InternalFrame.activeDropShadowOpacity", 0.5f ) );
private final FlatDropShadowBorder inactiveDropShadowBorder = new FlatDropShadowBorder(
UIManager.getColor( "InternalFrame.inactiveDropShadowColor" ),
UIManager.getInsets( "InternalFrame.inactiveDropShadowInsets" ),
FlatUIUtils.getUIFloat( "InternalFrame.inactiveDropShadowOpacity", 0.5f ) );
public FlatInternalFrameBorder() { public FlatInternalFrameBorder() {
super( UIManager.getInsets( "InternalFrame.borderMargins" ) ); super( UIManager.getInsets( "InternalFrame.borderMargins" ) );
@@ -137,16 +147,31 @@ public class FlatInternalFrameUI
Insets insets = getBorderInsets( c ); Insets insets = getBorderInsets( c );
float lineWidth = scale( (float) borderLineWidth ); float lineWidth = scale( (float) borderLineWidth );
float rx = x + insets.left - lineWidth;
float ry = y + insets.top - lineWidth;
float rwidth = width - insets.left - insets.right + (lineWidth * 2);
float rheight = height - insets.top - insets.bottom + (lineWidth * 2);
Graphics2D g2 = (Graphics2D) g.create(); Graphics2D g2 = (Graphics2D) g.create();
try { try {
FlatUIUtils.setRenderingHints( g2 ); FlatUIUtils.setRenderingHints( g2 );
g2.setColor( f.isSelected() ? activeBorderColor : inactiveBorderColor ); g2.setColor( f.isSelected() ? activeBorderColor : inactiveBorderColor );
g2.fill( FlatUIUtils.createRectangle(
x + insets.left - lineWidth, // paint drop shadow
y + insets.top - lineWidth, if( dropShadowPainted ) {
width - insets.left - insets.right + (lineWidth * 2), FlatDropShadowBorder dropShadowBorder = f.isSelected()
height - insets.top - insets.bottom + (lineWidth * 2), ? activeDropShadowBorder : inactiveDropShadowBorder;
lineWidth ) );
Insets dropShadowInsets = dropShadowBorder.getBorderInsets();
dropShadowBorder.paintBorder( c, g2,
(int) rx - dropShadowInsets.left,
(int) ry - dropShadowInsets.top,
(int) rwidth + dropShadowInsets.left + dropShadowInsets.right,
(int) rheight + dropShadowInsets.top + dropShadowInsets.bottom );
}
// paint border
g2.fill( FlatUIUtils.createRectangle( rx, ry, rwidth, rheight, lineWidth ) );
} finally { } finally {
g2.dispose(); g2.dispose();
} }

View File

@@ -151,7 +151,7 @@ public class FlatMenuUI
if( model.isRollover() && !model.isArmed() && !model.isSelected() && if( model.isRollover() && !model.isArmed() && !model.isSelected() &&
model.isEnabled() && ((JMenu)menuItem).isTopLevelMenu() ) model.isEnabled() && ((JMenu)menuItem).isTopLevelMenu() )
{ {
FlatUIUtils.setColor( g, hoverBackground, menuItem.getBackground() ); g.setColor( FlatUIUtils.deriveColor( hoverBackground, menuItem.getBackground() ) );
g.fillRect( 0, 0, menuItem.getWidth(), menuItem.getHeight() ); g.fillRect( 0, 0, menuItem.getWidth(), menuItem.getHeight() );
} else } else
super.paintBackground( g, selectionBackground ); super.paintBackground( g, selectionBackground );

View File

@@ -16,7 +16,6 @@
package com.formdev.flatlaf.ui; package com.formdev.flatlaf.ui;
import static com.formdev.flatlaf.util.UIScale.scale;
import java.awt.Color; import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Graphics; import java.awt.Graphics;
@@ -34,7 +33,6 @@ import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicPasswordFieldUI; import javax.swing.plaf.basic.BasicPasswordFieldUI;
import javax.swing.text.Caret; import javax.swing.text.Caret;
import javax.swing.text.JTextComponent; import javax.swing.text.JTextComponent;
import com.formdev.flatlaf.FlatClientProperties;
/** /**
* Provides the Flat LaF UI delegate for {@link javax.swing.JPasswordField}. * Provides the Flat LaF UI delegate for {@link javax.swing.JPasswordField}.
@@ -57,8 +55,6 @@ import com.formdev.flatlaf.FlatClientProperties;
* *
* <!-- FlatPasswordFieldUI --> * <!-- FlatPasswordFieldUI -->
* *
* @uiDefault TextComponent.arc int
* @uiDefault Component.focusWidth int
* @uiDefault Component.minimumWidth int * @uiDefault Component.minimumWidth int
* @uiDefault Component.isIntelliJTheme boolean * @uiDefault Component.isIntelliJTheme boolean
* @uiDefault PasswordField.placeholderForeground Color * @uiDefault PasswordField.placeholderForeground Color
@@ -70,8 +66,6 @@ import com.formdev.flatlaf.FlatClientProperties;
public class FlatPasswordFieldUI public class FlatPasswordFieldUI
extends BasicPasswordFieldUI extends BasicPasswordFieldUI
{ {
protected int arc;
protected int focusWidth;
protected int minimumWidth; protected int minimumWidth;
protected boolean isIntelliJTheme; protected boolean isIntelliJTheme;
protected Color placeholderForeground; protected Color placeholderForeground;
@@ -89,16 +83,14 @@ public class FlatPasswordFieldUI
super.installDefaults(); super.installDefaults();
String prefix = getPropertyPrefix(); String prefix = getPropertyPrefix();
arc = UIManager.getInt( "TextComponent.arc" );
focusWidth = UIManager.getInt( "Component.focusWidth" );
minimumWidth = UIManager.getInt( "Component.minimumWidth" ); minimumWidth = UIManager.getInt( "Component.minimumWidth" );
isIntelliJTheme = UIManager.getBoolean( "Component.isIntelliJTheme" ); isIntelliJTheme = UIManager.getBoolean( "Component.isIntelliJTheme" );
placeholderForeground = UIManager.getColor( prefix + ".placeholderForeground" ); placeholderForeground = UIManager.getColor( prefix + ".placeholderForeground" );
capsLockIcon = UIManager.getIcon( "PasswordField.capsLockIcon" ); capsLockIcon = UIManager.getIcon( "PasswordField.capsLockIcon" );
LookAndFeel.installProperty( getComponent(), "opaque", focusWidth == 0 ); LookAndFeel.installProperty( getComponent(), "opaque", false );
MigLayoutVisualPadding.install( getComponent(), focusWidth ); MigLayoutVisualPadding.install( getComponent() );
} }
@Override @Override
@@ -153,14 +145,12 @@ public class FlatPasswordFieldUI
@Override @Override
protected void propertyChange( PropertyChangeEvent e ) { protected void propertyChange( PropertyChangeEvent e ) {
super.propertyChange( e ); super.propertyChange( e );
FlatTextFieldUI.propertyChange( getComponent(), e );
if( FlatClientProperties.PLACEHOLDER_TEXT.equals( e.getPropertyName() ) )
getComponent().repaint();
} }
@Override @Override
protected void paintSafely( Graphics g ) { protected void paintSafely( Graphics g ) {
FlatTextFieldUI.paintBackground( g, getComponent(), focusWidth, arc, isIntelliJTheme ); FlatTextFieldUI.paintBackground( g, getComponent(), isIntelliJTheme );
FlatTextFieldUI.paintPlaceholder( g, getComponent(), placeholderForeground ); FlatTextFieldUI.paintPlaceholder( g, getComponent(), placeholderForeground );
paintCapsLock( g ); paintCapsLock( g );
super.paintSafely( g ); super.paintSafely( g );
@@ -184,18 +174,11 @@ public class FlatPasswordFieldUI
@Override @Override
public Dimension getPreferredSize( JComponent c ) { public Dimension getPreferredSize( JComponent c ) {
return applyMinimumWidth( super.getPreferredSize( c ), c ); return FlatTextFieldUI.applyMinimumWidth( c, super.getPreferredSize( c ), minimumWidth );
} }
@Override @Override
public Dimension getMinimumSize( JComponent c ) { public Dimension getMinimumSize( JComponent c ) {
return applyMinimumWidth( super.getMinimumSize( c ), c ); return FlatTextFieldUI.applyMinimumWidth( c, super.getMinimumSize( c ), minimumWidth );
}
private Dimension applyMinimumWidth( Dimension size, JComponent c ) {
int minimumWidth = FlatUIUtils.minimumWidth( getComponent(), this.minimumWidth );
int focusWidth = (c.getBorder() instanceof FlatBorder) ? this.focusWidth : 0;
size.width = Math.max( size.width, scale( minimumWidth + (focusWidth * 2) ) );
return size;
} }
} }

View File

@@ -0,0 +1,375 @@
/*
* Copyright 2020 FormDev Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.formdev.flatlaf.ui;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.Panel;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Window;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import javax.swing.JComponent;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;
import javax.swing.Popup;
import javax.swing.PopupFactory;
import javax.swing.RootPaneContainer;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.border.Border;
import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.util.SystemInfo;
/**
* A popup factory that adds drop shadows to popups on Windows.
* On macOS and Linux, heavy weight popups (without drop shadow) are produced and the
* operating system automatically adds drop shadows.
*
* @author Karl Tauber
*/
public class FlatPopupFactory
extends PopupFactory
{
private Method java8getPopupMethod;
private Method java9getPopupMethod;
@Override
public Popup getPopup( Component owner, Component contents, int x, int y )
throws IllegalArgumentException
{
if( !isDropShadowPainted( owner, contents ) )
return new NonFlashingPopup( super.getPopup( owner, contents, x, y ), contents );
// macOS and Linux adds drop shadow to heavy weight popups
if( SystemInfo.IS_MAC || SystemInfo.IS_LINUX ) {
Popup popup = getHeavyWeightPopup( owner, contents, x, y );
if( popup == null )
popup = super.getPopup( owner, contents, x, y );
return new NonFlashingPopup( popup, contents );
}
// create drop shadow popup
return new DropShadowPopup( super.getPopup( owner, contents, x, y ), owner, contents );
}
private boolean isDropShadowPainted( Component owner, Component contents ) {
Boolean b = isDropShadowPainted( owner );
if( b != null )
return b;
b = isDropShadowPainted( contents );
if( b != null )
return b;
return UIManager.getBoolean( "Popup.dropShadowPainted" );
}
private Boolean isDropShadowPainted( Component c ) {
if( !(c instanceof JComponent) )
return null;
Object value = ((JComponent)c).getClientProperty( FlatClientProperties.POPUP_DROP_SHADOW_PAINTED );
return (value instanceof Boolean ) ? (Boolean) value : null;
}
/**
* There is no API in Java 8 to force creation of heavy weight popups,
* but it is possible with reflection. Java 9 provides a new method.
*
* When changing FlatLaf system requirements to Java 9+,
* then this method can be replaced with:
* return getPopup( owner, contents, x, y, true );
*/
private Popup getHeavyWeightPopup( Component owner, Component contents, int x, int y )
throws IllegalArgumentException
{
try {
if( SystemInfo.IS_JAVA_9_OR_LATER ) {
if( java9getPopupMethod == null ) {
java9getPopupMethod = PopupFactory.class.getDeclaredMethod(
"getPopup", Component.class, Component.class, int.class, int.class, boolean.class );
}
return (Popup) java9getPopupMethod.invoke( this, owner, contents, x, y, true );
} else {
// Java 8
if( java8getPopupMethod == null ) {
java8getPopupMethod = PopupFactory.class.getDeclaredMethod(
"getPopup", Component.class, Component.class, int.class, int.class, int.class );
java8getPopupMethod.setAccessible( true );
}
return (Popup) java8getPopupMethod.invoke( this, owner, contents, x, y, /*HEAVY_WEIGHT_POPUP*/ 2 );
}
} catch( NoSuchMethodException | SecurityException | IllegalAccessException | InvocationTargetException ex ) {
// ignore
return null;
}
}
//---- class NonFlashingPopup ---------------------------------------------
private class NonFlashingPopup
extends Popup
{
private Popup delegate;
// heavy weight
protected Window popupWindow;
private Color oldPopupWindowBackground;
NonFlashingPopup( Popup delegate, Component contents ) {
this.delegate = delegate;
popupWindow = SwingUtilities.windowForComponent( contents );
if( popupWindow != null ) {
// heavy weight popup
// fix background flashing which may occur on some platforms
// (e.g. macOS and Linux) when using dark theme
oldPopupWindowBackground = popupWindow.getBackground();
popupWindow.setBackground( contents.getBackground() );
}
}
@Override
public void show() {
if( delegate != null )
delegate.show();
}
@Override
public void hide() {
if( delegate != null ) {
delegate.hide();
delegate = null;
}
if( popupWindow != null ) {
// restore background so that it can not affect other LaFs (when switching)
// because popup windows are cached and reused
popupWindow.setBackground( oldPopupWindowBackground );
popupWindow = null;
}
}
}
//---- class DropShadowPopup ----------------------------------------------
private class DropShadowPopup
extends NonFlashingPopup
{
private final Component owner;
// light weight
private JComponent lightComp;
private Border oldBorder;
private boolean oldOpaque;
// medium weight
private boolean mediumWeightShown;
private Panel mediumWeightPanel;
private JPanel dropShadowPanel;
private ComponentListener mediumPanelListener;
// heavy weight
private Popup dropShadowDelegate;
private Window dropShadowWindow;
private Color oldDropShadowWindowBackground;
DropShadowPopup( Popup delegate, Component owner, Component contents ) {
super( delegate, contents );
this.owner = owner;
Dimension size = contents.getPreferredSize();
if( size.width <= 0 || size.height <= 0 )
return;
if( popupWindow != null ) {
// heavy weight popup
// Since Java has a problem with sub-pixel text rendering on translucent
// windows, we can not make the popup window translucent for the drop shadow.
// (see https://bugs.openjdk.java.net/browse/JDK-8215980)
// The solution is to create a second translucent window that paints
// the drop shadow and is positioned behind the popup window.
// create panel that paints the drop shadow
JPanel dropShadowPanel = new JPanel();
dropShadowPanel.setBorder( createDropShadowBorder() );
dropShadowPanel.setOpaque( false );
// set preferred size of drop shadow panel
Dimension prefSize = popupWindow.getPreferredSize();
Insets insets = dropShadowPanel.getInsets();
dropShadowPanel.setPreferredSize( new Dimension(
prefSize.width + insets.left + insets.right,
prefSize.height + insets.top + insets.bottom ) );
// create heavy weight popup for drop shadow
int x = popupWindow.getX() - insets.left;
int y = popupWindow.getY() - insets.top;
dropShadowDelegate = getHeavyWeightPopup( owner, dropShadowPanel, x, y );
// make drop shadow popup window translucent
dropShadowWindow = SwingUtilities.windowForComponent( dropShadowPanel );
if( dropShadowWindow != null ) {
oldDropShadowWindowBackground = dropShadowWindow.getBackground();
dropShadowWindow.setBackground( new Color( 0, true ) );
}
} else {
mediumWeightPanel = (Panel) SwingUtilities.getAncestorOfClass( Panel.class, contents );
if( mediumWeightPanel != null ) {
// medium weight popup
dropShadowPanel = new JPanel();
dropShadowPanel.setBorder( createDropShadowBorder() );
dropShadowPanel.setOpaque( false );
dropShadowPanel.setSize( FlatUIUtils.addInsets( mediumWeightPanel.getSize(), dropShadowPanel.getInsets() ) );
} else {
// light weight popup
Container p = contents.getParent();
if( !(p instanceof JComponent) )
return;
lightComp = (JComponent) p;
oldBorder = lightComp.getBorder();
oldOpaque = lightComp.isOpaque();
lightComp.setBorder( createDropShadowBorder() );
lightComp.setOpaque( false );
lightComp.setSize( lightComp.getPreferredSize() );
}
}
}
private Border createDropShadowBorder() {
return new FlatDropShadowBorder(
UIManager.getColor( "Popup.dropShadowColor" ),
UIManager.getInsets( "Popup.dropShadowInsets" ),
FlatUIUtils.getUIFloat( "Popup.dropShadowOpacity", 0.5f ) );
}
@Override
public void show() {
if( dropShadowDelegate != null )
dropShadowDelegate.show();
if( mediumWeightPanel != null )
showMediumWeightDropShadow();
super.show();
// fix location of light weight popup in case it has left or top drop shadow
if( lightComp != null ) {
Insets insets = lightComp.getInsets();
if( insets.left != 0 || insets.top != 0 )
lightComp.setLocation( lightComp.getX() - insets.left, lightComp.getY() - insets.top );
}
}
@Override
public void hide() {
if( dropShadowDelegate != null ) {
dropShadowDelegate.hide();
dropShadowDelegate = null;
}
if( mediumWeightPanel != null ) {
hideMediumWeightDropShadow();
dropShadowPanel = null;
mediumWeightPanel = null;
}
super.hide();
if( dropShadowWindow != null ) {
dropShadowWindow.setBackground( oldDropShadowWindowBackground );
dropShadowWindow = null;
}
if( lightComp != null ) {
lightComp.setBorder( oldBorder );
lightComp.setOpaque( oldOpaque );
lightComp = null;
}
}
private void showMediumWeightDropShadow() {
if( mediumWeightShown )
return;
mediumWeightShown = true;
Window window = SwingUtilities.windowForComponent( owner );
if( window == null )
return;
if( !(window instanceof RootPaneContainer) )
return;
dropShadowPanel.setVisible( false );
JLayeredPane layeredPane = ((RootPaneContainer)window).getLayeredPane();
layeredPane.add( dropShadowPanel, JLayeredPane.POPUP_LAYER, 0 );
mediumPanelListener = new ComponentListener() {
@Override
public void componentShown( ComponentEvent e ) {
if( dropShadowPanel != null )
dropShadowPanel.setVisible( true );
}
@Override
public void componentHidden( ComponentEvent e ) {
if( dropShadowPanel != null )
dropShadowPanel.setVisible( false );
}
@Override
public void componentMoved( ComponentEvent e ) {
if( dropShadowPanel != null && mediumWeightPanel != null ) {
Point location = mediumWeightPanel.getLocation();
Insets insets = dropShadowPanel.getInsets();
dropShadowPanel.setLocation( location.x - insets.left, location.y - insets.top );
}
}
@Override
public void componentResized( ComponentEvent e ) {
if( dropShadowPanel != null )
dropShadowPanel.setSize( FlatUIUtils.addInsets( mediumWeightPanel.getSize(), dropShadowPanel.getInsets() ) );
}
};
mediumWeightPanel.addComponentListener( mediumPanelListener );
}
private void hideMediumWeightDropShadow() {
mediumWeightPanel.removeComponentListener( mediumPanelListener );
Container parent = dropShadowPanel.getParent();
if( parent != null ) {
Rectangle bounds = dropShadowPanel.getBounds();
parent.remove( dropShadowPanel );
parent.repaint( bounds.x, bounds.y, bounds.width, bounds.height );
}
}
}
}

View File

@@ -19,7 +19,6 @@ package com.formdev.flatlaf.ui;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.plaf.ComponentUI; import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicPopupMenuUI; import javax.swing.plaf.basic.BasicPopupMenuUI;
import com.formdev.flatlaf.util.SystemInfo;
/** /**
* Provides the Flat LaF UI delegate for {@link javax.swing.JPopupMenu}. * Provides the Flat LaF UI delegate for {@link javax.swing.JPopupMenu}.
@@ -36,28 +35,7 @@ import com.formdev.flatlaf.util.SystemInfo;
public class FlatPopupMenuUI public class FlatPopupMenuUI
extends BasicPopupMenuUI extends BasicPopupMenuUI
{ {
private boolean oldLightWeightPopupEnabled;
public static ComponentUI createUI( JComponent c ) { public static ComponentUI createUI( JComponent c ) {
return new FlatPopupMenuUI(); return new FlatPopupMenuUI();
} }
@Override
public void installDefaults() {
super.installDefaults();
// use heavy-weight popups on macOS to get nice drop shadow from OS
if( SystemInfo.IS_MAC ) {
oldLightWeightPopupEnabled = popupMenu.isLightWeightPopupEnabled();
popupMenu.setLightWeightPopupEnabled( false );
}
}
@Override
protected void uninstallDefaults() {
super.uninstallDefaults();
if( SystemInfo.IS_MAC )
popupMenu.setLightWeightPopupEnabled( oldLightWeightPopupEnabled );
}
} }

View File

@@ -23,7 +23,6 @@ import java.awt.Graphics;
import java.awt.Insets; import java.awt.Insets;
import java.awt.Rectangle; import java.awt.Rectangle;
import javax.swing.AbstractButton; import javax.swing.AbstractButton;
import javax.swing.CellRendererPane;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.LookAndFeel; import javax.swing.LookAndFeel;
import javax.swing.UIManager; import javax.swing.UIManager;
@@ -122,11 +121,10 @@ public class FlatRadioButtonUI
public void paint( Graphics g, JComponent c ) { public void paint( Graphics g, JComponent c ) {
// fill background even if not opaque if // fill background even if not opaque if
// - contentAreaFilled is true and // - contentAreaFilled is true and
// - used as cell renderer (because of selection background) // - if background was explicitly set to a non-UIResource color
// - or if background was explicitly set to a non-UIResource color
if( !c.isOpaque() && if( !c.isOpaque() &&
((AbstractButton)c).isContentAreaFilled() && ((AbstractButton)c).isContentAreaFilled() &&
(c.getParent() instanceof CellRendererPane || !(c.getBackground() instanceof UIResource))) !(c.getBackground() instanceof UIResource) )
{ {
g.setColor( c.getBackground() ); g.setColor( c.getBackground() );
g.fillRect( 0, 0, c.getWidth(), c.getHeight() ); g.fillRect( 0, 0, c.getWidth(), c.getHeight() );

View File

@@ -16,8 +16,15 @@
package com.formdev.flatlaf.ui; package com.formdev.flatlaf.ui;
import java.awt.Color;
import java.awt.Container;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JRootPane;
import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI; import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.UIResource;
import javax.swing.plaf.basic.BasicRootPaneUI; import javax.swing.plaf.basic.BasicRootPaneUI;
/** /**
@@ -35,4 +42,21 @@ public class FlatRootPaneUI
instance = new FlatRootPaneUI(); instance = new FlatRootPaneUI();
return instance; return instance;
} }
@Override
protected void installDefaults( JRootPane c ) {
super.installDefaults( c );
// Update background color of JFrame or JDialog parent to avoid bad border
// on HiDPI screens when switching from light to dark Laf.
// The background of JFrame is initialized in JFrame.frameInit() and
// the background of JDialog in JDialog.dialogInit(),
// but it was not updated when switching Laf.
Container parent = c.getParent();
if( parent instanceof JFrame || parent instanceof JDialog ) {
Color background = parent.getBackground();
if( background == null || background instanceof UIResource )
parent.setBackground( UIManager.getColor( "control" ) );
}
}
} }

View File

@@ -16,7 +16,6 @@
package com.formdev.flatlaf.ui; package com.formdev.flatlaf.ui;
import static com.formdev.flatlaf.util.UIScale.scale;
import java.awt.Component; import java.awt.Component;
import javax.swing.UIManager; import javax.swing.UIManager;
@@ -33,7 +32,7 @@ public class FlatRoundBorder
protected final int arc = UIManager.getInt( "Component.arc" ); protected final int arc = UIManager.getInt( "Component.arc" );
@Override @Override
protected float getArc( Component c ) { protected int getArc( Component c ) {
return scale( (float) arc ); return FlatUIUtils.isRoundRect( c ) ? Short.MAX_VALUE : arc;
} }
} }

View File

@@ -19,6 +19,8 @@ package com.formdev.flatlaf.ui;
import java.awt.Color; import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
@@ -28,6 +30,7 @@ import java.util.Objects;
import javax.swing.InputMap; import javax.swing.InputMap;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.swing.UIManager; import javax.swing.UIManager;
@@ -52,8 +55,13 @@ import com.formdev.flatlaf.util.UIScale;
* *
* <!-- FlatScrollBarUI --> * <!-- FlatScrollBarUI -->
* *
* @uiDefault ScrollBar.trackInsets Insets
* @uiDefault ScrollBar.thumbInsets Insets
* @uiDefault ScrollBar.trackArc int
* @uiDefault ScrollBar.thumbArc int
* @uiDefault ScrollBar.hoverTrackColor Color * @uiDefault ScrollBar.hoverTrackColor Color
* @uiDefault ScrollBar.hoverThumbColor Color * @uiDefault ScrollBar.hoverThumbColor Color
* @uiDefault ScrollBar.hoverThumbWithTrack boolean
* @uiDefault Component.arrowType String triangle (default) or chevron * @uiDefault Component.arrowType String triangle (default) or chevron
* @uiDefault ScrollBar.showButtons boolean * @uiDefault ScrollBar.showButtons boolean
* @uiDefault ScrollBar.buttonArrowColor Color * @uiDefault ScrollBar.buttonArrowColor Color
@@ -64,8 +72,13 @@ import com.formdev.flatlaf.util.UIScale;
public class FlatScrollBarUI public class FlatScrollBarUI
extends BasicScrollBarUI extends BasicScrollBarUI
{ {
protected Insets trackInsets;
protected Insets thumbInsets;
protected int trackArc;
protected int thumbArc;
protected Color hoverTrackColor; protected Color hoverTrackColor;
protected Color hoverThumbColor; protected Color hoverThumbColor;
protected boolean hoverThumbWithTrack;
protected boolean showButtons; protected boolean showButtons;
protected String arrowType; protected String arrowType;
@@ -73,8 +86,8 @@ public class FlatScrollBarUI
protected Color buttonDisabledArrowColor; protected Color buttonDisabledArrowColor;
private MouseAdapter hoverListener; private MouseAdapter hoverListener;
private boolean hoverTrack; protected boolean hoverTrack;
private boolean hoverThumb; protected boolean hoverThumb;
public static ComponentUI createUI( JComponent c ) { public static ComponentUI createUI( JComponent c ) {
return new FlatScrollBarUI(); return new FlatScrollBarUI();
@@ -102,8 +115,13 @@ public class FlatScrollBarUI
protected void installDefaults() { protected void installDefaults() {
super.installDefaults(); super.installDefaults();
trackInsets = UIManager.getInsets( "ScrollBar.trackInsets" );
thumbInsets = UIManager.getInsets( "ScrollBar.thumbInsets" );
trackArc = UIManager.getInt( "ScrollBar.trackArc" );
thumbArc = UIManager.getInt( "ScrollBar.thumbArc" );
hoverTrackColor = UIManager.getColor( "ScrollBar.hoverTrackColor" ); hoverTrackColor = UIManager.getColor( "ScrollBar.hoverTrackColor" );
hoverThumbColor = UIManager.getColor( "ScrollBar.hoverThumbColor" ); hoverThumbColor = UIManager.getColor( "ScrollBar.hoverThumbColor" );
hoverThumbWithTrack = UIManager.getBoolean( "ScrollBar.hoverThumbWithTrack" );
showButtons = UIManager.getBoolean( "ScrollBar.showButtons" ); showButtons = UIManager.getBoolean( "ScrollBar.showButtons" );
arrowType = UIManager.getString( "Component.arrowType" ); arrowType = UIManager.getString( "Component.arrowType" );
@@ -115,6 +133,8 @@ public class FlatScrollBarUI
protected void uninstallDefaults() { protected void uninstallDefaults() {
super.uninstallDefaults(); super.uninstallDefaults();
trackInsets = null;
thumbInsets = null;
hoverTrackColor = null; hoverTrackColor = null;
hoverThumbColor = null; hoverThumbColor = null;
@@ -171,6 +191,11 @@ public class FlatScrollBarUI
FlatArrowButton button = new FlatArrowButton( orientation, FlatArrowButton button = new FlatArrowButton( orientation,
arrowType, buttonArrowColor, buttonDisabledArrowColor, null, hoverTrackColor ) arrowType, buttonArrowColor, buttonDisabledArrowColor, null, hoverTrackColor )
{ {
@Override
protected Color deriveHoverBackground( Color hoverBackground ) {
return getTrackColor( scrollbar, true ) ;
}
@Override @Override
public Dimension getPreferredSize() { public Dimension getPreferredSize() {
if( isShowButtons() ) { if( isShowButtons() ) {
@@ -203,6 +228,45 @@ public class FlatScrollBarUI
return (showButtons != null) ? Objects.equals( showButtons, true ) : this.showButtons; return (showButtons != null) ? Objects.equals( showButtons, true ) : this.showButtons;
} }
@Override
public void paint( Graphics g, JComponent c ) {
FlatUIUtils.setRenderingHints( (Graphics2D) g );
super.paint( g, c );
}
@Override
protected void paintTrack( Graphics g, JComponent c, Rectangle trackBounds ) {
g.setColor( getTrackColor( c, hoverTrack ) );
paintTrackOrThumb( g, c, trackBounds, trackInsets, trackArc );
}
@Override
protected void paintThumb( Graphics g, JComponent c, Rectangle thumbBounds ) {
if( thumbBounds.isEmpty() || !scrollbar.isEnabled() )
return;
g.setColor( getThumbColor( c, hoverThumb ) );
paintTrackOrThumb( g, c, thumbBounds, thumbInsets, thumbArc );
}
protected void paintTrackOrThumb( Graphics g, JComponent c, Rectangle bounds, Insets insets, int arc ) {
// rotate insets for horizontal orientation because they are given for vertical orientation
if( scrollbar.getOrientation() == JScrollBar.HORIZONTAL )
insets = new Insets( insets.right, insets.top, insets.left, insets.bottom );
// subtract insets from bounds
bounds = FlatUIUtils.subtractInsets( bounds, UIScale.scale( insets ) );
if( arc <= 0 ) {
// paint rectangle
g.fillRect( bounds.x, bounds.y, bounds.width, bounds.height );
} else {
// paint round rectangle
arc = Math.min( UIScale.scale( arc ), Math.min( bounds.width, bounds.height ) );
g.fillRoundRect( bounds.x, bounds.y, bounds.width, bounds.height, arc, arc );
}
}
@Override @Override
protected void paintDecreaseHighlight( Graphics g ) { protected void paintDecreaseHighlight( Graphics g ) {
// do not paint // do not paint
@@ -213,19 +277,15 @@ public class FlatScrollBarUI
// do not paint // do not paint
} }
@Override protected Color getTrackColor( JComponent c, boolean hover ) {
protected void paintTrack( Graphics g, JComponent c, Rectangle trackBounds ) { Color trackColor = FlatUIUtils.deriveColor( this.trackColor, c.getBackground() );
g.setColor( hoverTrack ? hoverTrackColor : trackColor ); return hover ? FlatUIUtils.deriveColor( hoverTrackColor, trackColor ) : trackColor;
g.fillRect( trackBounds.x, trackBounds.y, trackBounds.width, trackBounds.height );
} }
@Override protected Color getThumbColor( JComponent c, boolean hover ) {
protected void paintThumb( Graphics g, JComponent c, Rectangle thumbBounds ) { Color trackColor = FlatUIUtils.deriveColor( this.trackColor, c.getBackground() );
if( thumbBounds.isEmpty() || !scrollbar.isEnabled() ) Color thumbColor = FlatUIUtils.deriveColor( this.thumbColor, trackColor );
return; return hover ? FlatUIUtils.deriveColor( hoverThumbColor, thumbColor ) : thumbColor;
g.setColor( hoverThumb ? hoverThumbColor : thumbColor );
g.fillRect( thumbBounds.x, thumbBounds.y, thumbBounds.width, thumbBounds.height );
} }
@Override @Override
@@ -276,7 +336,7 @@ public class FlatScrollBarUI
boolean inThumb = getThumbBounds().contains( x, y ); boolean inThumb = getThumbBounds().contains( x, y );
if( inTrack != hoverTrack || inThumb != hoverThumb ) { if( inTrack != hoverTrack || inThumb != hoverThumb ) {
hoverTrack = inTrack; hoverTrack = inTrack;
hoverThumb = inThumb; hoverThumb = inThumb || (hoverThumbWithTrack && inTrack);
repaint(); repaint();
} }
} }

View File

@@ -83,7 +83,7 @@ public class FlatScrollPaneUI
int focusWidth = UIManager.getInt( "Component.focusWidth" ); int focusWidth = UIManager.getInt( "Component.focusWidth" );
LookAndFeel.installProperty( c, "opaque", focusWidth == 0 ); LookAndFeel.installProperty( c, "opaque", focusWidth == 0 );
MigLayoutVisualPadding.install( scrollpane, focusWidth ); MigLayoutVisualPadding.install( scrollpane );
} }
@Override @Override

View File

@@ -201,7 +201,7 @@ public class FlatSliderUI
} }
if( coloredTrack != null ) { if( coloredTrack != null ) {
FlatUIUtils.setColor( g, FlatUIUtils.isPermanentFocusOwner( slider ) ? focusColor : (hover ? hoverColor : thumbColor), thumbColor ); g.setColor( FlatUIUtils.deriveColor( FlatUIUtils.isPermanentFocusOwner( slider ) ? focusColor : (hover ? hoverColor : thumbColor), thumbColor ) );
((Graphics2D)g).fill( coloredTrack ); ((Graphics2D)g).fill( coloredTrack );
} }
@@ -211,10 +211,10 @@ public class FlatSliderUI
@Override @Override
public void paintThumb( Graphics g ) { public void paintThumb( Graphics g ) {
FlatUIUtils.setColor( g, slider.isEnabled() g.setColor( FlatUIUtils.deriveColor( slider.isEnabled()
? (FlatUIUtils.isPermanentFocusOwner( slider ) ? focusColor : (hover ? hoverColor : thumbColor)) ? (FlatUIUtils.isPermanentFocusOwner( slider ) ? focusColor : (hover ? hoverColor : thumbColor))
: disabledForeground, : disabledForeground,
thumbColor ); thumbColor ) );
if( isRoundThumb() ) if( isRoundThumb() )
g.fillOval( thumbRect.x, thumbRect.y, thumbRect.width, thumbRect.height ); g.fillOval( thumbRect.x, thumbRect.y, thumbRect.width, thumbRect.height );

View File

@@ -40,6 +40,7 @@ import javax.swing.SwingConstants;
import javax.swing.UIManager; import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI; import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicSpinnerUI; import javax.swing.plaf.basic.BasicSpinnerUI;
import com.formdev.flatlaf.FlatClientProperties;
/** /**
* Provides the Flat LaF UI delegate for {@link javax.swing.JSpinner}. * Provides the Flat LaF UI delegate for {@link javax.swing.JSpinner}.
@@ -56,8 +57,6 @@ import javax.swing.plaf.basic.BasicSpinnerUI;
* *
* <!-- FlatSpinnerUI --> * <!-- FlatSpinnerUI -->
* *
* @uiDefault Component.focusWidth int
* @uiDefault Component.arc int
* @uiDefault Component.minimumWidth int * @uiDefault Component.minimumWidth int
* @uiDefault Component.arrowType String triangle (default) or chevron * @uiDefault Component.arrowType String triangle (default) or chevron
* @uiDefault Component.isIntelliJTheme boolean * @uiDefault Component.isIntelliJTheme boolean
@@ -78,8 +77,6 @@ public class FlatSpinnerUI
{ {
private Handler handler; private Handler handler;
protected int focusWidth;
protected int arc;
protected int minimumWidth; protected int minimumWidth;
protected String arrowType; protected String arrowType;
protected boolean isIntelliJTheme; protected boolean isIntelliJTheme;
@@ -103,8 +100,6 @@ public class FlatSpinnerUI
LookAndFeel.installProperty( spinner, "opaque", false ); LookAndFeel.installProperty( spinner, "opaque", false );
focusWidth = UIManager.getInt( "Component.focusWidth" );
arc = UIManager.getInt( "Component.arc" );
minimumWidth = UIManager.getInt( "Component.minimumWidth" ); minimumWidth = UIManager.getInt( "Component.minimumWidth" );
arrowType = UIManager.getString( "Component.arrowType" ); arrowType = UIManager.getString( "Component.arrowType" );
isIntelliJTheme = UIManager.getBoolean( "Component.isIntelliJTheme" ); isIntelliJTheme = UIManager.getBoolean( "Component.isIntelliJTheme" );
@@ -121,7 +116,7 @@ public class FlatSpinnerUI
// scale // scale
padding = scale( padding ); padding = scale( padding );
MigLayoutVisualPadding.install( spinner, focusWidth ); MigLayoutVisualPadding.install( spinner );
} }
@Override @Override
@@ -146,6 +141,7 @@ public class FlatSpinnerUI
super.installListeners(); super.installListeners();
addEditorFocusListener( spinner.getEditor() ); addEditorFocusListener( spinner.getEditor() );
spinner.addFocusListener( getHandler() );
spinner.addPropertyChangeListener( getHandler() ); spinner.addPropertyChangeListener( getHandler() );
} }
@@ -154,6 +150,7 @@ public class FlatSpinnerUI
super.uninstallListeners(); super.uninstallListeners();
removeEditorFocusListener( spinner.getEditor() ); removeEditorFocusListener( spinner.getEditor() );
spinner.removeFocusListener( getHandler() );
spinner.removePropertyChangeListener( getHandler() ); spinner.removePropertyChangeListener( getHandler() );
handler = null; handler = null;
@@ -211,7 +208,7 @@ public class FlatSpinnerUI
} }
} }
private JTextField getEditorTextField( JComponent editor ) { private static JTextField getEditorTextField( JComponent editor ) {
return editor instanceof JSpinner.DefaultEditor return editor instanceof JSpinner.DefaultEditor
? ((JSpinner.DefaultEditor)editor).getTextField() ? ((JSpinner.DefaultEditor)editor).getTextField()
: null; : null;
@@ -246,8 +243,11 @@ public class FlatSpinnerUI
@Override @Override
public void update( Graphics g, JComponent c ) { public void update( Graphics g, JComponent c ) {
float focusWidth = FlatUIUtils.getBorderFocusWidth( c );
float arc = FlatUIUtils.getBorderArc( c );
// fill background if opaque to avoid garbage if user sets opaque to true // fill background if opaque to avoid garbage if user sets opaque to true
if( c.isOpaque() && (focusWidth > 0 || arc != 0) ) if( c.isOpaque() && (focusWidth > 0 || arc > 0) )
FlatUIUtils.paintParentBackground( g, c ); FlatUIUtils.paintParentBackground( g, c );
Graphics2D g2 = (Graphics2D) g; Graphics2D g2 = (Graphics2D) g;
@@ -255,8 +255,6 @@ public class FlatSpinnerUI
int width = c.getWidth(); int width = c.getWidth();
int height = c.getHeight(); int height = c.getHeight();
float focusWidth = (c.getBorder() instanceof FlatBorder) ? scale( (float) this.focusWidth ) : 0;
float arc = (c.getBorder() instanceof FlatRoundBorder) ? scale( (float) this.arc ) : 0;
Component nextButton = getHandler().nextButton; Component nextButton = getHandler().nextButton;
int arrowX = nextButton.getX(); int arrowX = nextButton.getX();
int arrowWidth = nextButton.getWidth(); int arrowWidth = nextButton.getWidth();
@@ -328,8 +326,9 @@ public class FlatSpinnerUI
// the arrows width is the same as the inner height so that the arrows area is square // the arrows width is the same as the inner height so that the arrows area is square
int minimumWidth = FlatUIUtils.minimumWidth( spinner, FlatSpinnerUI.this.minimumWidth ); int minimumWidth = FlatUIUtils.minimumWidth( spinner, FlatSpinnerUI.this.minimumWidth );
int innerHeight = editorSize.height + padding.top + padding.bottom; int innerHeight = editorSize.height + padding.top + padding.bottom;
float focusWidth = FlatUIUtils.getBorderFocusWidth( spinner );
return new Dimension( return new Dimension(
Math.max( insets.left + insets.right + editorSize.width + padding.left + padding.right + innerHeight, scale( minimumWidth + (focusWidth * 2) ) ), Math.max( insets.left + insets.right + editorSize.width + padding.left + padding.right + innerHeight, scale( minimumWidth ) + Math.round( focusWidth * 2 ) ),
insets.top + insets.bottom + innerHeight ); insets.top + insets.bottom + innerHeight );
} }
@@ -368,12 +367,14 @@ public class FlatSpinnerUI
if( editor != null ) if( editor != null )
editor.setBounds( FlatUIUtils.subtractInsets( editorRect, padding ) ); editor.setBounds( FlatUIUtils.subtractInsets( editorRect, padding ) );
int nextHeight = Math.round( buttonsRect.height / 2f ); int nextHeight = (buttonsRect.height / 2) + (buttonsRect.height % 2); // round up
if( nextButton != null ) if( nextButton != null )
nextButton.setBounds( buttonsRect.x, buttonsRect.y, buttonsRect.width, nextHeight ); nextButton.setBounds( buttonsRect.x, buttonsRect.y, buttonsRect.width, nextHeight );
if( previousButton != null ) { if( previousButton != null ) {
previousButton.setBounds( buttonsRect.x, buttonsRect.y + nextHeight, // for precise layout of arrows, the "previous" button has the same height
buttonsRect.width, buttonsRect.height - nextHeight ); // as the "next" button and may overlap on uneven buttonsRect.height
int previousY = buttonsRect.y + buttonsRect.height - nextHeight;
previousButton.setBounds( buttonsRect.x, previousY, buttonsRect.width, nextHeight );
} }
} }
@@ -382,6 +383,13 @@ public class FlatSpinnerUI
@Override @Override
public void focusGained( FocusEvent e ) { public void focusGained( FocusEvent e ) {
spinner.repaint(); spinner.repaint();
// if spinner gained focus, transfer it to the editor text field
if( e.getComponent() == spinner ) {
JTextField textField = getEditorTextField( spinner.getEditor() );
if( textField != null )
textField.requestFocusInWindow();
}
} }
@Override @Override
@@ -398,6 +406,14 @@ public class FlatSpinnerUI
case "enabled": case "enabled":
updateEditorColors(); updateEditorColors();
break; break;
case FlatClientProperties.COMPONENT_ROUND_RECT:
spinner.repaint();
break;
case FlatClientProperties.MINIMUM_WIDTH:
spinner.revalidate();
break;
} }
} }
} }

View File

@@ -20,11 +20,13 @@ import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.event.FocusEvent; import java.awt.event.FocusEvent;
import java.awt.event.FocusListener; import java.awt.event.FocusListener;
import javax.swing.JCheckBox;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.LookAndFeel; import javax.swing.LookAndFeel;
import javax.swing.UIManager; import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI; import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicTableUI; import javax.swing.plaf.basic.BasicTableUI;
import javax.swing.table.TableCellRenderer;
import com.formdev.flatlaf.util.UIScale; import com.formdev.flatlaf.util.UIScale;
/** /**
@@ -132,6 +134,12 @@ public class FlatTableUI
oldIntercellSpacing = table.getIntercellSpacing(); oldIntercellSpacing = table.getIntercellSpacing();
table.setIntercellSpacing( intercellSpacing ); table.setIntercellSpacing( intercellSpacing );
} }
// checkbox is non-opaque in FlatLaf and therefore would not paint selection
// --> make checkbox renderer opaque (but opaque in Metal or Windows LaF)
TableCellRenderer booleanRenderer = table.getDefaultRenderer( Boolean.class );
if( booleanRenderer instanceof JCheckBox )
((JCheckBox)booleanRenderer).setOpaque( true );
} }
@Override @Override

View File

@@ -16,10 +16,10 @@
package com.formdev.flatlaf.ui; package com.formdev.flatlaf.ui;
import static com.formdev.flatlaf.util.UIScale.scale;
import java.awt.Color; import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Graphics; import java.awt.Graphics;
import java.beans.PropertyChangeEvent;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JTextArea; import javax.swing.JTextArea;
import javax.swing.UIManager; import javax.swing.UIManager;
@@ -83,6 +83,12 @@ public class FlatTextAreaUI
inactiveBackground = null; inactiveBackground = null;
} }
@Override
protected void propertyChange( PropertyChangeEvent e ) {
super.propertyChange( e );
FlatEditorPaneUI.propertyChange( getComponent(), e );
}
@Override @Override
protected void paintBackground( Graphics g ) { protected void paintBackground( Graphics g ) {
JTextComponent c = getComponent(); JTextComponent c = getComponent();
@@ -100,25 +106,19 @@ public class FlatTextAreaUI
@Override @Override
public Dimension getPreferredSize( JComponent c ) { public Dimension getPreferredSize( JComponent c ) {
return applyMinimumWidth( super.getPreferredSize( c ), c ); return applyMinimumWidth( c, super.getPreferredSize( c ) );
} }
@Override @Override
public Dimension getMinimumSize( JComponent c ) { public Dimension getMinimumSize( JComponent c ) {
return applyMinimumWidth( super.getMinimumSize( c ), c ); return applyMinimumWidth( c, super.getMinimumSize( c ) );
} }
private Dimension applyMinimumWidth( Dimension size, JComponent c ) { private Dimension applyMinimumWidth( JComponent c, Dimension size ) {
// do not apply minimum width if JTextArea.columns is set // do not apply minimum width if JTextArea.columns is set
if( c instanceof JTextArea && ((JTextArea)c).getColumns() > 0 ) if( c instanceof JTextArea && ((JTextArea)c).getColumns() > 0 )
return size; return size;
// Assume that text area is in a scroll pane (that displays the border) return FlatEditorPaneUI.applyMinimumWidth( c, size, minimumWidth );
// and subtract 1px border line width.
// Using "(scale( 1 ) * 2)" instead of "scale( 2 )" to deal with rounding
// issues. E.g. at scale factor 1.5 the first returns 4, but the second 3.
int minimumWidth = FlatUIUtils.minimumWidth( getComponent(), this.minimumWidth );
size.width = Math.max( size.width, scale( minimumWidth ) - (scale( 1 ) * 2) );
return size;
} }
} }

View File

@@ -16,14 +16,13 @@
package com.formdev.flatlaf.ui; package com.formdev.flatlaf.ui;
import static com.formdev.flatlaf.util.UIScale.scale;
import java.awt.Component; import java.awt.Component;
import javax.swing.UIManager; import javax.swing.UIManager;
/** /**
* Border for various text components (e.g. {@link javax.swing.JTextField}). * Border for various text components (e.g. {@link javax.swing.JTextField}).
* *
* @uiDefault Component.arc int * @uiDefault TextComponent.arc int
* *
* @author Karl Tauber * @author Karl Tauber
*/ */
@@ -33,7 +32,7 @@ public class FlatTextBorder
protected final int arc = UIManager.getInt( "TextComponent.arc" ); protected final int arc = UIManager.getInt( "TextComponent.arc" );
@Override @Override
protected float getArc( Component c ) { protected int getArc( Component c ) {
return scale( (float) arc ); return FlatUIUtils.isRoundRect( c ) ? Short.MAX_VALUE : arc;
} }
} }

View File

@@ -32,7 +32,6 @@ import javax.swing.JSpinner;
import javax.swing.JTextField; import javax.swing.JTextField;
import javax.swing.LookAndFeel; import javax.swing.LookAndFeel;
import javax.swing.UIManager; import javax.swing.UIManager;
import javax.swing.border.Border;
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.BasicTextFieldUI; import javax.swing.plaf.basic.BasicTextFieldUI;
@@ -60,8 +59,6 @@ import com.formdev.flatlaf.FlatClientProperties;
* *
* <!-- FlatTextFieldUI --> * <!-- FlatTextFieldUI -->
* *
* @uiDefault TextComponent.arc int
* @uiDefault Component.focusWidth int
* @uiDefault Component.minimumWidth int * @uiDefault Component.minimumWidth int
* @uiDefault Component.isIntelliJTheme boolean * @uiDefault Component.isIntelliJTheme boolean
* @uiDefault TextField.placeholderForeground Color * @uiDefault TextField.placeholderForeground Color
@@ -72,8 +69,6 @@ import com.formdev.flatlaf.FlatClientProperties;
public class FlatTextFieldUI public class FlatTextFieldUI
extends BasicTextFieldUI extends BasicTextFieldUI
{ {
protected int arc;
protected int focusWidth;
protected int minimumWidth; protected int minimumWidth;
protected boolean isIntelliJTheme; protected boolean isIntelliJTheme;
protected Color placeholderForeground; protected Color placeholderForeground;
@@ -89,15 +84,13 @@ public class FlatTextFieldUI
super.installDefaults(); super.installDefaults();
String prefix = getPropertyPrefix(); String prefix = getPropertyPrefix();
arc = UIManager.getInt( "TextComponent.arc" );
focusWidth = UIManager.getInt( "Component.focusWidth" );
minimumWidth = UIManager.getInt( "Component.minimumWidth" ); minimumWidth = UIManager.getInt( "Component.minimumWidth" );
isIntelliJTheme = UIManager.getBoolean( "Component.isIntelliJTheme" ); isIntelliJTheme = UIManager.getBoolean( "Component.isIntelliJTheme" );
placeholderForeground = UIManager.getColor( prefix + ".placeholderForeground" ); placeholderForeground = UIManager.getColor( prefix + ".placeholderForeground" );
LookAndFeel.installProperty( getComponent(), "opaque", focusWidth == 0 ); LookAndFeel.installProperty( getComponent(), "opaque", false );
MigLayoutVisualPadding.install( getComponent(), focusWidth ); MigLayoutVisualPadding.install( getComponent() );
} }
@Override @Override
@@ -133,14 +126,25 @@ public class FlatTextFieldUI
@Override @Override
protected void propertyChange( PropertyChangeEvent e ) { protected void propertyChange( PropertyChangeEvent e ) {
super.propertyChange( e ); super.propertyChange( e );
propertyChange( getComponent(), e );
}
if( FlatClientProperties.PLACEHOLDER_TEXT.equals( e.getPropertyName() ) ) static void propertyChange( JTextComponent c, PropertyChangeEvent e ) {
getComponent().repaint(); switch( e.getPropertyName() ) {
case FlatClientProperties.PLACEHOLDER_TEXT:
case FlatClientProperties.COMPONENT_ROUND_RECT:
c.repaint();
break;
case FlatClientProperties.MINIMUM_WIDTH:
c.revalidate();
break;
}
} }
@Override @Override
protected void paintSafely( Graphics g ) { protected void paintSafely( Graphics g ) {
paintBackground( g, getComponent(), focusWidth, arc, isIntelliJTheme ); paintBackground( g, getComponent(), isIntelliJTheme );
paintPlaceholder( g, getComponent(), placeholderForeground ); paintPlaceholder( g, getComponent(), placeholderForeground );
super.paintSafely( g ); super.paintSafely( g );
} }
@@ -150,19 +154,20 @@ public class FlatTextFieldUI
// background is painted elsewhere // background is painted elsewhere
} }
static void paintBackground( Graphics g, JTextComponent c, int focusWidth, int arc, boolean isIntelliJTheme ) { static void paintBackground( Graphics g, JTextComponent c, boolean isIntelliJTheme ) {
Border border = c.getBorder();
// do not paint background if: // do not paint background if:
// - not opaque and // - not opaque and
// - border is not a flat border and // - border is not a flat border and
// - opaque was explicitly set (to false) // - opaque was explicitly set (to false)
// (same behaviour as in AquaTextFieldUI) // (same behaviour as in AquaTextFieldUI)
if( !c.isOpaque() && !(border instanceof FlatBorder) && FlatUIUtils.hasOpaqueBeenExplicitlySet( c ) ) if( !c.isOpaque() && FlatUIUtils.getOutsideFlatBorder( c ) == null && FlatUIUtils.hasOpaqueBeenExplicitlySet( c ) )
return; return;
float focusWidth = FlatUIUtils.getBorderFocusWidth( c );
float arc = FlatUIUtils.getBorderArc( c );
// fill background if opaque to avoid garbage if user sets opaque to true // fill background if opaque to avoid garbage if user sets opaque to true
if( c.isOpaque() && focusWidth > 0 ) if( c.isOpaque() && (focusWidth > 0 || arc > 0) )
FlatUIUtils.paintParentBackground( g, c ); FlatUIUtils.paintParentBackground( g, c );
// paint background // paint background
@@ -170,16 +175,13 @@ public class FlatTextFieldUI
try { try {
FlatUIUtils.setRenderingHints( g2 ); FlatUIUtils.setRenderingHints( g2 );
float fFocusWidth = (border instanceof FlatBorder) ? scale( (float) focusWidth ) : 0;
float fArc = (border instanceof FlatTextBorder) ? scale( (float) arc ) : 0;
Color background = c.getBackground(); Color background = c.getBackground();
g2.setColor( !(background instanceof UIResource) g2.setColor( !(background instanceof UIResource)
? background ? background
: (isIntelliJTheme && (!c.isEnabled() || !c.isEditable()) : (isIntelliJTheme && (!c.isEnabled() || !c.isEditable())
? FlatUIUtils.getParentBackground( c ) ? FlatUIUtils.getParentBackground( c )
: background) ); : background) );
FlatUIUtils.paintComponentBackground( g2, 0, 0, c.getWidth(), c.getHeight(), fFocusWidth, fArc ); FlatUIUtils.paintComponentBackground( g2, 0, 0, c.getWidth(), c.getHeight(), focusWidth, arc );
} finally { } finally {
g2.dispose(); g2.dispose();
} }
@@ -212,28 +214,29 @@ public class FlatTextFieldUI
@Override @Override
public Dimension getPreferredSize( JComponent c ) { public Dimension getPreferredSize( JComponent c ) {
return applyMinimumWidth( super.getPreferredSize( c ), c ); return applyMinimumWidth( c, super.getPreferredSize( c ), minimumWidth );
} }
@Override @Override
public Dimension getMinimumSize( JComponent c ) { public Dimension getMinimumSize( JComponent c ) {
return applyMinimumWidth( super.getMinimumSize( c ), c ); return applyMinimumWidth( c, super.getMinimumSize( c ), minimumWidth );
} }
private Dimension applyMinimumWidth( Dimension size, JComponent c ) { static Dimension applyMinimumWidth( JComponent c, Dimension size, int minimumWidth ) {
// do not apply minimum width if JTextField.columns is set // do not apply minimum width if JTextField.columns is set
if( c instanceof JTextField && ((JTextField)c).getColumns() > 0 ) if( c instanceof JTextField && ((JTextField)c).getColumns() > 0 )
return size; return size;
// do not apply minimum width if used in combobox or spinner
Container parent = c.getParent(); Container parent = c.getParent();
if( parent instanceof JComboBox || if( parent instanceof JComboBox ||
parent instanceof JSpinner || parent instanceof JSpinner ||
(parent != null && parent.getParent() instanceof JSpinner) ) (parent != null && parent.getParent() instanceof JSpinner) )
return size; return size;
int minimumWidth = FlatUIUtils.minimumWidth( getComponent(), this.minimumWidth ); minimumWidth = FlatUIUtils.minimumWidth( c, minimumWidth );
int focusWidth = (c.getBorder() instanceof FlatBorder) ? this.focusWidth : 0; float focusWidth = FlatUIUtils.getBorderFocusWidth( c );
size.width = Math.max( size.width, scale( minimumWidth + (focusWidth * 2) ) ); size.width = Math.max( size.width, scale( minimumWidth ) + Math.round( focusWidth * 2 ) );
return size; return size;
} }
} }

View File

@@ -16,9 +16,9 @@
package com.formdev.flatlaf.ui; package com.formdev.flatlaf.ui;
import static com.formdev.flatlaf.util.UIScale.scale;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Graphics; import java.awt.Graphics;
import java.beans.PropertyChangeEvent;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JEditorPane; import javax.swing.JEditorPane;
import javax.swing.UIManager; import javax.swing.UIManager;
@@ -83,24 +83,20 @@ public class FlatTextPaneUI
getComponent().putClientProperty( JEditorPane.HONOR_DISPLAY_PROPERTIES, oldHonorDisplayProperties ); getComponent().putClientProperty( JEditorPane.HONOR_DISPLAY_PROPERTIES, oldHonorDisplayProperties );
} }
@Override
protected void propertyChange( PropertyChangeEvent e ) {
super.propertyChange( e );
FlatEditorPaneUI.propertyChange( getComponent(), e );
}
@Override @Override
public Dimension getPreferredSize( JComponent c ) { public Dimension getPreferredSize( JComponent c ) {
return applyMinimumWidth( super.getPreferredSize( c ) ); return FlatEditorPaneUI.applyMinimumWidth( c, super.getPreferredSize( c ), minimumWidth );
} }
@Override @Override
public Dimension getMinimumSize( JComponent c ) { public Dimension getMinimumSize( JComponent c ) {
return applyMinimumWidth( super.getMinimumSize( c ) ); return FlatEditorPaneUI.applyMinimumWidth( c, super.getMinimumSize( c ), minimumWidth );
}
private Dimension applyMinimumWidth( Dimension size ) {
// Assume that text area is in a scroll pane (that displays the border)
// and subtract 1px border line width.
// Using "(scale( 1 ) * 2)" instead of "scale( 2 )" to deal with rounding
// issues. E.g. at scale factor 1.5 the first returns 4, but the second 3.
int minimumWidth = FlatUIUtils.minimumWidth( getComponent(), this.minimumWidth );
size.width = Math.max( size.width, scale( minimumWidth ) - (scale( 1 ) * 2) );
return size;
} }
@Override @Override

View File

@@ -138,7 +138,7 @@ public class FlatToggleButtonUI
case BUTTON_TYPE: case BUTTON_TYPE:
if( BUTTON_TYPE_TAB.equals( e.getOldValue() ) || BUTTON_TYPE_TAB.equals( e.getNewValue() ) ) { if( BUTTON_TYPE_TAB.equals( e.getOldValue() ) || BUTTON_TYPE_TAB.equals( e.getNewValue() ) ) {
MigLayoutVisualPadding.uninstall( b ); MigLayoutVisualPadding.uninstall( b );
MigLayoutVisualPadding.install( b, getFocusWidth( b ) ); MigLayoutVisualPadding.install( b );
b.revalidate(); b.revalidate();
} }
@@ -212,9 +212,4 @@ public class FlatToggleButtonUI
return super.getForeground( c ); return super.getForeground( c );
} }
@Override
protected int getFocusWidth( JComponent c ) {
return isTabButton( c ) ? 0 : super.getFocusWidth( c );
}
} }

View File

@@ -103,7 +103,7 @@ public class FlatToolTipUI
for( String line : lines ) for( String line : lines )
width = Math.max( width, SwingUtilities.computeStringWidth( fm, line ) ); width = Math.max( width, SwingUtilities.computeStringWidth( fm, line ) );
return new Dimension( insets.left + width + insets.right, insets.top + height + insets.bottom ); return new Dimension( insets.left + width + insets.right + 6, insets.top + height + insets.bottom );
} else } else
return super.getPreferredSize( c ); return super.getPreferredSize( c );
} }
@@ -119,8 +119,8 @@ public class FlatToolTipUI
List<String> lines = StringUtils.split( ((JToolTip)c).getTipText(), '\n' ); List<String> lines = StringUtils.split( ((JToolTip)c).getTipText(), '\n' );
int x = insets.left; int x = insets.left + 3;
int x2 = c.getWidth() - insets.right; int x2 = c.getWidth() - insets.right - 3;
int y = insets.top - fm.getDescent(); int y = insets.top - fm.getDescent();
int lineHeight = fm.getHeight(); int lineHeight = fm.getHeight();
JComponent comp = ((JToolTip)c).getComponent(); JComponent comp = ((JToolTip)c).getComponent();

View File

@@ -39,6 +39,8 @@ import java.util.function.Consumer;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.LookAndFeel; import javax.swing.LookAndFeel;
import javax.swing.UIManager; import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.border.CompoundBorder;
import javax.swing.plaf.UIResource; import javax.swing.plaf.UIResource;
import com.formdev.flatlaf.FlatClientProperties; import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.util.DerivedColor; import com.formdev.flatlaf.util.DerivedColor;
@@ -142,6 +144,47 @@ public class FlatUIUtils
return (KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner() == c); return (KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner() == c);
} }
public static boolean isRoundRect( Component c ) {
return c instanceof JComponent && FlatClientProperties.clientPropertyBoolean(
(JComponent) c, FlatClientProperties.COMPONENT_ROUND_RECT, false );
}
/**
* Returns the scaled thickness of the outer focus border for the given component.
*/
public static float getBorderFocusWidth( JComponent c ) {
FlatBorder border = getOutsideFlatBorder( c );
return (border != null)
? UIScale.scale( (float) border.getFocusWidth( c ) )
: 0;
}
/**
* Returns the scaled arc diameter of the border for the given component.
*/
public static float getBorderArc( JComponent c ) {
FlatBorder border = getOutsideFlatBorder( c );
return (border != null)
? UIScale.scale( (float) border.getArc( c ) )
: 0;
}
public static boolean hasRoundBorder( JComponent c ) {
return getBorderArc( c ) >= c.getHeight();
}
public static FlatBorder getOutsideFlatBorder( JComponent c ) {
Border border = c.getBorder();
for(;;) {
if( border instanceof FlatBorder )
return (FlatBorder) border;
else if( border instanceof CompoundBorder )
border = ((CompoundBorder)border).getOutsideBorder();
else
return null;
}
}
/** /**
* Sets rendering hints used for painting. * Sets rendering hints used for painting.
*/ */
@@ -151,10 +194,10 @@ public class FlatUIUtils
MAC_USE_QUARTZ ? RenderingHints.VALUE_STROKE_PURE : RenderingHints.VALUE_STROKE_NORMALIZE ); MAC_USE_QUARTZ ? RenderingHints.VALUE_STROKE_PURE : RenderingHints.VALUE_STROKE_NORMALIZE );
} }
public static void setColor( Graphics g, Color color, Color baseColor ) { public static Color deriveColor( Color color, Color baseColor ) {
if( color instanceof DerivedColor ) return (color instanceof DerivedColor)
color = ((DerivedColor)color).derive( baseColor ); ? ((DerivedColor)color).derive( baseColor )
g.setColor( color ); : color;
} }
/** /**
@@ -195,14 +238,9 @@ public class FlatUIUtils
if( arc > 0 && arc < UIScale.scale( 10 ) ) if( arc > 0 && arc < UIScale.scale( 10 ) )
outerArc -= UIScale.scale( 2f ); outerArc -= UIScale.scale( 2f );
if( outerArc < 0 )
outerArc = 0;
if( innerArc < 0 )
innerArc = 0;
Path2D path = new Path2D.Float( Path2D.WIND_EVEN_ODD ); Path2D path = new Path2D.Float( Path2D.WIND_EVEN_ODD );
path.append( new RoundRectangle2D.Float( x, y, width, height, outerArc, outerArc ), false ); path.append( createComponentRectangle( x, y, width, height, outerArc ), false );
path.append( new RoundRectangle2D.Float( x + ow, y + ow, width - (ow * 2), height - (ow * 2), innerArc, innerArc ), false ); path.append( createComponentRectangle( x + ow, y + ow, width - (ow * 2), height - (ow * 2), innerArc ), false );
g.fill( path ); g.fill( path );
} }
@@ -236,19 +274,16 @@ public class FlatUIUtils
private static void paintComponentBorderImpl( Graphics2D g, int x, int y, int width, int height, private static void paintComponentBorderImpl( Graphics2D g, int x, int y, int width, int height,
float focusWidth, float lineWidth, float arc ) float focusWidth, float lineWidth, float arc )
{ {
float x1 = x + focusWidth;
float y1 = y + focusWidth;
float width1 = width - focusWidth * 2;
float height1 = height - focusWidth * 2;
float arc2 = arc - (lineWidth * 2); float arc2 = arc - (lineWidth * 2);
if( arc < 0 ) Shape r1 = createComponentRectangle( x1, y1, width1, height1, arc );
arc = 0; Shape r2 = createComponentRectangle(
if( arc2 < 0 ) x1 + lineWidth, y1 + lineWidth,
arc2 = 0; width1 - lineWidth * 2, height1 - lineWidth * 2, arc2 );
RoundRectangle2D.Float r1 = new RoundRectangle2D.Float(
x + focusWidth, y + focusWidth,
width - focusWidth * 2, height - focusWidth * 2, arc, arc );
RoundRectangle2D.Float r2 = new RoundRectangle2D.Float(
r1.x + lineWidth, r1.y + lineWidth,
r1.width - lineWidth * 2, r1.height - lineWidth * 2, arc2, arc2 );
Path2D border = new Path2D.Float( Path2D.WIND_EVEN_ODD ); Path2D border = new Path2D.Float( Path2D.WIND_EVEN_ODD );
border.append( r1, false ); border.append( r1, false );
@@ -286,12 +321,21 @@ public class FlatUIUtils
private static void paintComponentBackgroundImpl( Graphics2D g, int x, int y, int width, int height, private static void paintComponentBackgroundImpl( Graphics2D g, int x, int y, int width, int height,
float focusWidth, float arc ) float focusWidth, float arc )
{ {
if( arc < 0 ) g.fill( createComponentRectangle(
arc = 0;
g.fill( new RoundRectangle2D.Float(
x + focusWidth, y + focusWidth, x + focusWidth, y + focusWidth,
width - focusWidth * 2, height - focusWidth * 2, arc, arc ) ); width - focusWidth * 2, height - focusWidth * 2, arc ) );
}
/**
* Creates a (rounded) rectangle used to paint components (border, background, etc).
* The given arc diameter is limited to min(width,height).
*/
public static Shape createComponentRectangle( float x, float y, float w, float h, float arc ) {
if( arc <= 0 )
return new Rectangle2D.Float( x, y, w, h );
arc = Math.min( arc, Math.min( w, h ) );
return new RoundRectangle2D.Float( x, y, w, h, arc, arc );
} }
/** /**
@@ -360,14 +404,12 @@ public class FlatUIUtils
if( arcTopLeft <= 0 && arcTopRight <= 0 && arcBottomLeft <= 0 && arcBottomRight <= 0 ) if( arcTopLeft <= 0 && arcTopRight <= 0 && arcBottomLeft <= 0 && arcBottomRight <= 0 )
return new Rectangle2D.Float( x, y, width, height ); return new Rectangle2D.Float( x, y, width, height );
if( arcTopLeft < 0 ) // limit arcs to min(width,height)
arcTopLeft = 0; float maxArc = Math.min( width, height ) / 2;
if( arcTopRight < 0 ) arcTopLeft = (arcTopLeft > 0) ? Math.min( arcTopLeft, maxArc ) : 0;
arcTopRight = 0; arcTopRight = (arcTopRight > 0) ? Math.min( arcTopRight, maxArc ) : 0;
if( arcBottomLeft < 0 ) arcBottomLeft = (arcBottomLeft > 0) ? Math.min( arcBottomLeft, maxArc ) : 0;
arcBottomLeft = 0; arcBottomRight = (arcBottomRight > 0) ? Math.min( arcBottomRight, maxArc ) : 0;
if( arcBottomRight < 0 )
arcBottomRight = 0;
float x2 = x + width; float x2 = x + width;
float y2 = y + height; float y2 = y + height;

View File

@@ -69,14 +69,17 @@ public class MigLayoutVisualPadding
/** /**
* Convenience method that checks whether component border is a FlatBorder. * Convenience method that checks whether component border is a FlatBorder.
*/ */
public static void install( JComponent c, int focusWidth ) { public static void install( JComponent c ) {
if( !migLayoutAvailable ) if( !migLayoutAvailable )
return; return;
install( c, c2 -> { install( c, c2 -> {
return (c2.getBorder() instanceof FlatBorder) FlatBorder border = FlatUIUtils.getOutsideFlatBorder( c2 );
? new Insets( focusWidth, focusWidth, focusWidth, focusWidth ) if( border != null ) {
: null; int focusWidth = border.getFocusWidth( c2 );
return new Insets( focusWidth, focusWidth, focusWidth, focusWidth );
} else
return null;
}, "border" ); }, "border" );
} }

View File

@@ -49,20 +49,26 @@ public class ColorFunctions
void apply( float[] hsl ); void apply( float[] hsl );
} }
//---- class Lighten ------------------------------------------------------ //---- class HSLIncreaseDecrease ------------------------------------------
/** /**
* Increase the lightness of a color in the HSL color space by an absolute * Increase or decrease hue, saturation or luminance of a color in the HSL color space
* or relative amount. * by an absolute or relative amount.
*/ */
public static class Lighten public static class HSLIncreaseDecrease
implements ColorFunction implements ColorFunction
{ {
private final float amount; public final int hslIndex;
private final boolean relative; public final boolean increase;
private final boolean autoInverse; public final float amount;
public final boolean relative;
public final boolean autoInverse;
public Lighten( float amount, boolean relative, boolean autoInverse ) { public HSLIncreaseDecrease( int hslIndex, boolean increase,
float amount, boolean relative, boolean autoInverse )
{
this.hslIndex = hslIndex;
this.increase = increase;
this.amount = amount; this.amount = amount;
this.relative = relative; this.relative = relative;
this.autoInverse = autoInverse; this.autoInverse = autoInverse;
@@ -70,33 +76,17 @@ public class ColorFunctions
@Override @Override
public void apply( float[] hsl ) { public void apply( float[] hsl ) {
float amount2 = autoInverse && shouldInverse( hsl ) ? -amount : amount; float amount2 = increase ? amount : -amount;
hsl[2] = clamp( relative amount2 = autoInverse && shouldInverse( hsl ) ? -amount2 : amount2;
? (hsl[2] * ((100 + amount2) / 100)) hsl[hslIndex] = clamp( relative
: (hsl[2] + amount2) ); ? (hsl[hslIndex] * ((100 + amount2) / 100))
: (hsl[hslIndex] + amount2) );
} }
protected boolean shouldInverse( float[] hsl ) { protected boolean shouldInverse( float[] hsl ) {
return hsl[2] >= 50; return increase
} ? hsl[hslIndex] >= 50
} : hsl[hslIndex] < 50;
//---- class Darken -------------------------------------------------------
/**
* Decrease the lightness of a color in the HSL color space by an absolute
* or relative amount.
*/
public static class Darken
extends Lighten
{
public Darken( float amount, boolean relative, boolean autoInverse ) {
super( -amount, relative, autoInverse );
}
@Override
protected boolean shouldInverse( float[] hsl ) {
return hsl[2] < 50;
} }
} }
} }

View File

@@ -32,12 +32,31 @@ public class DerivedColor
{ {
private final ColorFunction[] functions; private final ColorFunction[] functions;
private boolean hasBaseOfDefaultColor;
private int baseOfDefaultColorRGB;
public DerivedColor( Color defaultColor, ColorFunction... functions ) { public DerivedColor( Color defaultColor, ColorFunction... functions ) {
super( (defaultColor != null) ? defaultColor : Color.red ); super( (defaultColor != null) ? defaultColor : Color.red );
this.functions = functions; this.functions = functions;
} }
public Color derive( Color baseColor ) { public Color derive( Color baseColor ) {
return ColorFunctions.applyFunctions( baseColor, functions ); if( (hasBaseOfDefaultColor && baseOfDefaultColorRGB == baseColor.getRGB()) || baseColor == this )
return this; // return default color
Color result = ColorFunctions.applyFunctions( baseColor, functions );
// if the result is equal to the default color, then the original base color
// was passed and we can cache this to avoid color calculations
if( !hasBaseOfDefaultColor && result.getRGB() == this.getRGB() ) {
hasBaseOfDefaultColor = true;
baseOfDefaultColorRGB = baseColor.getRGB();
}
return result;
}
public ColorFunction[] getFunctions() {
return functions;
} }
} }

View File

@@ -17,6 +17,8 @@
package com.formdev.flatlaf.util; package com.formdev.flatlaf.util;
import java.awt.Image; import java.awt.Image;
import java.util.Collections;
import java.util.List;
import java.util.function.Function; import java.util.function.Function;
/** /**
@@ -41,4 +43,12 @@ public class MultiResolutionImageSupport
public static Image map( Image image, Function<Image, Image> mapper ) { public static Image map( Image image, Function<Image, Image> mapper ) {
return mapper.apply( image ); return mapper.apply( image );
} }
public static Image getResolutionVariant( Image image, int destImageWidth, int destImageHeight ) {
return image;
}
public static List<Image> getResolutionVariants( Image image ) {
return Collections.singletonList( image );
}
} }

View File

@@ -0,0 +1,172 @@
/*
* Copyright 2020 FormDev Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.formdev.flatlaf.util;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import javax.swing.Icon;
import javax.swing.ImageIcon;
/**
* Scales the given image icon using the system and user scale factors and
* paints the icon at system scale factor 1x. This gives best scaling quality.
* If the given image icon supports multiple resolutions, the best resolution
* variant is used. The last scaled image is cached for faster repainting.
*
* @author Karl Tauber
*/
public class ScaledImageIcon
implements Icon
{
private final ImageIcon imageIcon;
private double lastSystemScaleFactor;
private float lastUserScaleFactor;
private Image lastImage;
public ScaledImageIcon( ImageIcon imageIcon ) {
this.imageIcon = imageIcon;
}
@Override
public int getIconWidth() {
return UIScale.scale( imageIcon.getIconWidth() );
}
@Override
public int getIconHeight() {
return UIScale.scale( imageIcon.getIconHeight() );
}
@Override
public void paintIcon( Component c, Graphics g, int x, int y ) {
/*debug
g.setColor( Color.red );
g.drawRect( x, y, getIconWidth(), getIconHeight() );
debug*/
// scale factor
double systemScaleFactor = UIScale.getSystemScaleFactor( (Graphics2D) g );
float userScaleFactor = UIScale.getUserScaleFactor();
double scaleFactor = systemScaleFactor * userScaleFactor;
// paint input image icon if not necessary to scale
if( scaleFactor == 1 ) {
imageIcon.paintIcon( c, g, x, y );
return;
}
// paint cached scaled icon
if( systemScaleFactor == lastSystemScaleFactor &&
userScaleFactor == lastUserScaleFactor &&
lastImage != null )
{
paintLastImage( g, x, y );
return;
}
// destination image size
int destImageWidth = (int) Math.round( imageIcon.getIconWidth() * scaleFactor );
int destImageHeight = (int) Math.round( imageIcon.getIconHeight() * scaleFactor );
// get resolution variant of image if it is a multi-resolution image
Image image = MultiResolutionImageSupport.getResolutionVariant(
imageIcon.getImage(), destImageWidth, destImageHeight );
// size of image
int imageWidth = image.getWidth( null );
int imageHeight = image.getHeight( null );
// scale image if necessary to destination size
if( imageWidth != destImageWidth || imageHeight != destImageHeight ) {
// determine scaling method; default is "quality"
Object scalingInterpolation = RenderingHints.VALUE_INTERPOLATION_BICUBIC;
float imageScaleFactor = (float) destImageWidth / (float) imageWidth;
if( ((int) imageScaleFactor) == imageScaleFactor &&
imageScaleFactor > 1f &&
imageWidth <= 16 &&
imageHeight <= 16 )
{
// use "speed" scaling for small icons if the scale factor is an integer
// to avoid blurred icons
scalingInterpolation = RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR;
}
// scale image
BufferedImage bufferedImage = image2bufferedImage( image );
image = scaleImage( bufferedImage, destImageWidth, destImageHeight, scalingInterpolation );
}
// cache image
lastSystemScaleFactor = systemScaleFactor;
lastUserScaleFactor = userScaleFactor;
lastImage = image;
// paint image
paintLastImage( g, x, y );
}
private void paintLastImage( Graphics g, int x, int y ) {
if( lastSystemScaleFactor > 1 ) {
HiDPIUtils.paintAtScale1x( (Graphics2D) g, x, y, 100, 100, // width and height are not used
(g2, x2, y2, width2, height2, scaleFactor2) -> {
g2.drawImage( lastImage, x2, y2, null );
} );
} else
g.drawImage( lastImage, x, y, null );
}
/**
* Scales the given image to the target dimensions.
*
* This is the same what imgscalr library (https://github.com/rkalla/imgscalr)
* would do when invoking Scalr.resize().
*/
private BufferedImage scaleImage( BufferedImage image, int targetWidth, int targetHeight,
Object scalingInterpolation )
{
BufferedImage bufferedImage = new BufferedImage( targetWidth, targetHeight, BufferedImage.TYPE_INT_ARGB );
Graphics2D g = bufferedImage.createGraphics();
try {
g.setRenderingHint( RenderingHints.KEY_INTERPOLATION, scalingInterpolation );
g.drawImage( image, 0, 0, targetWidth, targetHeight, null );
} finally {
g.dispose();
}
return bufferedImage;
}
private BufferedImage image2bufferedImage( Image image ) {
if( image instanceof BufferedImage )
return (BufferedImage) image;
BufferedImage bufferedImage = new BufferedImage( image.getWidth( null ),
image.getHeight( null ), BufferedImage.TYPE_INT_ARGB );
Graphics2D g = bufferedImage.createGraphics();
try {
g.drawImage( image, 0, 0, null );
} finally {
g.dispose();
}
return bufferedImage;
}
}

View File

@@ -33,6 +33,7 @@ public class SystemInfo
// OS versions // OS versions
public static final boolean IS_MAC_OS_10_11_EL_CAPITAN_OR_LATER; public static final boolean IS_MAC_OS_10_11_EL_CAPITAN_OR_LATER;
public static final boolean IS_MAC_OS_10_15_CATALINA_OR_LATER;
// Java versions // Java versions
public static final boolean IS_JAVA_9_OR_LATER; public static final boolean IS_JAVA_9_OR_LATER;
@@ -53,6 +54,7 @@ public class SystemInfo
// OS versions // OS versions
long osVersion = scanVersion( System.getProperty( "os.version" ) ); long osVersion = scanVersion( System.getProperty( "os.version" ) );
IS_MAC_OS_10_11_EL_CAPITAN_OR_LATER = (IS_MAC && osVersion >= toVersion( 10, 11, 0, 0 )); IS_MAC_OS_10_11_EL_CAPITAN_OR_LATER = (IS_MAC && osVersion >= toVersion( 10, 11, 0, 0 ));
IS_MAC_OS_10_15_CATALINA_OR_LATER = (IS_MAC && osVersion >= toVersion( 10, 15, 0, 0 ));
// Java versions // Java versions
long javaVersion = scanVersion( System.getProperty( "java.version" ) ); long javaVersion = scanVersion( System.getProperty( "java.version" ) );

View File

@@ -21,6 +21,7 @@ import java.awt.image.AbstractMultiResolutionImage;
import java.awt.image.BaseMultiResolutionImage; import java.awt.image.BaseMultiResolutionImage;
import java.awt.image.MultiResolutionImage; import java.awt.image.MultiResolutionImage;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.IdentityHashMap; import java.util.IdentityHashMap;
import java.util.List; import java.util.List;
import java.util.function.Function; import java.util.function.Function;
@@ -51,6 +52,18 @@ public class MultiResolutionImageSupport
: mapper.apply( image ); : mapper.apply( image );
} }
public static Image getResolutionVariant( Image image, int destImageWidth, int destImageHeight ) {
return (image instanceof MultiResolutionImage)
? ((MultiResolutionImage)image).getResolutionVariant( destImageWidth, destImageHeight )
: image;
}
public static List<Image> getResolutionVariants( Image image ) {
return (image instanceof MultiResolutionImage)
? ((MultiResolutionImage)image).getResolutionVariants()
: Collections.singletonList( image );
}
//---- class MappedMultiResolutionImage ----------------------------------- //---- class MappedMultiResolutionImage -----------------------------------
private static class MappedMultiResolutionImage private static class MappedMultiResolutionImage

View File

@@ -26,5 +26,7 @@ module com.formdev.flatlaf {
exports com.formdev.flatlaf.ui; exports com.formdev.flatlaf.ui;
exports com.formdev.flatlaf.util; exports com.formdev.flatlaf.util;
opens com.formdev.flatlaf.resources;
uses com.formdev.flatlaf.FlatDefaultsAddon; uses com.formdev.flatlaf.FlatDefaultsAddon;
} }

View File

@@ -27,6 +27,7 @@ Button.default.boldText=true
Component.focusWidth=2 Component.focusWidth=2
Component.innerFocusWidth=0 Component.innerFocusWidth=0
Component.innerOutlineWidth=0
Component.arrowType=triangle Component.arrowType=triangle

View File

@@ -72,8 +72,8 @@ controlDkShadow=lighten($controlShadow,10%)
#---- Button ---- #---- Button ----
Button.background=#4c5052 Button.background=#4c5052
Button.hoverBackground=lighten($Button.background,3%,derived autoInverse) Button.hoverBackground=lighten($Button.background,3%,derived)
Button.pressedBackground=lighten($Button.background,6%,derived autoInverse) Button.pressedBackground=lighten($Button.background,6%,derived)
Button.borderColor=#5e6060 Button.borderColor=#5e6060
Button.disabledBorderColor=#5e6060 Button.disabledBorderColor=#5e6060
@@ -82,16 +82,16 @@ Button.hoverBorderColor=$Button.focusedBorderColor
Button.default.background=#365880 Button.default.background=#365880
Button.default.foreground=#bbbbbb Button.default.foreground=#bbbbbb
Button.default.hoverBackground=lighten($Button.default.background,3%,derived autoInverse) Button.default.hoverBackground=lighten($Button.default.background,3%,derived)
Button.default.pressedBackground=lighten($Button.default.background,6%,derived autoInverse) Button.default.pressedBackground=lighten($Button.default.background,6%,derived)
Button.default.borderColor=#4c708c Button.default.borderColor=#4c708c
Button.default.hoverBorderColor=#537699 Button.default.hoverBorderColor=#537699
Button.default.focusedBorderColor=#537699 Button.default.focusedBorderColor=#537699
Button.default.focusColor=#43688c Button.default.focusColor=#43688c
Button.default.boldText=true Button.default.boldText=true
Button.toolbar.hoverBackground=lighten($Button.background,1%,derived autoInverse) Button.toolbar.hoverBackground=lighten($Button.background,1%,derived)
Button.toolbar.pressedBackground=lighten($Button.background,4%,derived autoInverse) Button.toolbar.pressedBackground=lighten($Button.background,4%,derived)
#---- CheckBox ---- #---- CheckBox ----
@@ -104,8 +104,8 @@ CheckBox.icon.hoverBorderColor=$CheckBox.icon.focusedBorderColor
CheckBox.icon.selectedFocusedBorderColor=#466D94 CheckBox.icon.selectedFocusedBorderColor=#466D94
CheckBox.icon.background=#43494A CheckBox.icon.background=#43494A
CheckBox.icon.disabledBackground=@background CheckBox.icon.disabledBackground=@background
CheckBox.icon.hoverBackground=lighten($CheckBox.icon.background,3%,derived autoInverse) CheckBox.icon.hoverBackground=lighten($CheckBox.icon.background,3%,derived)
CheckBox.icon.pressedBackground=lighten($CheckBox.icon.background,6%,derived autoInverse) CheckBox.icon.pressedBackground=lighten($CheckBox.icon.background,6%,derived)
CheckBox.icon.selectedBackground=#43494A CheckBox.icon.selectedBackground=#43494A
CheckBox.icon.checkmarkColor=#A7A7A7 CheckBox.icon.checkmarkColor=#A7A7A7
CheckBox.icon.disabledCheckmarkColor=#606060 CheckBox.icon.disabledCheckmarkColor=#606060
@@ -130,6 +130,12 @@ Component.focusColor=#3d6185
Component.linkColor=#589df6 Component.linkColor=#589df6
Component.grayFilter=-20,-70,100 Component.grayFilter=-20,-70,100
Component.error.borderColor=desaturate($Component.error.focusedBorderColor,25%)
Component.error.focusedBorderColor=#8b3c3c
Component.warning.borderColor=darken(desaturate($Component.warning.focusedBorderColor,20%),10%)
Component.warning.focusedBorderColor=#ac7920
Component.custom.borderColor=desaturate(#f00,50%,relative derived noAutoInverse)
#---- Desktop ---- #---- Desktop ----
@@ -148,16 +154,19 @@ InternalFrame.activeTitleForeground=@foreground
InternalFrame.inactiveTitleBackground=darken(@background,5%) InternalFrame.inactiveTitleBackground=darken(@background,5%)
InternalFrame.inactiveTitleForeground=@disabledText InternalFrame.inactiveTitleForeground=@disabledText
InternalFrame.activeBorderColor=lighten($Component.borderColor,10%) InternalFrame.activeBorderColor=darken(@background,7%)
InternalFrame.inactiveBorderColor=$Component.borderColor InternalFrame.inactiveBorderColor=darken(@background,3%)
InternalFrame.buttonHoverBackground=lighten($InternalFrame.activeTitleBackground,10%,derived autoInverse) InternalFrame.buttonHoverBackground=lighten($InternalFrame.activeTitleBackground,10%,derived)
InternalFrame.buttonPressedBackground=lighten($InternalFrame.activeTitleBackground,20%,derived autoInverse) InternalFrame.buttonPressedBackground=lighten($InternalFrame.activeTitleBackground,20%,derived)
InternalFrame.closeHoverBackground=lazy(Actions.Red) InternalFrame.closeHoverBackground=lazy(Actions.Red)
InternalFrame.closePressedBackground=darken(Actions.Red,10%,lazy) InternalFrame.closePressedBackground=darken(Actions.Red,10%,lazy)
InternalFrame.closeHoverForeground=#fff InternalFrame.closeHoverForeground=#fff
InternalFrame.closePressedForeground=#fff InternalFrame.closePressedForeground=#fff
InternalFrame.activeDropShadowOpacity=0.5
InternalFrame.inactiveDropShadowOpacity=0.75
#---- List ---- #---- List ----
@@ -187,6 +196,12 @@ MenuItemCheckBox.icon.disabledCheckmarkColor=#606060
PasswordField.capsLockIconColor=#ffffff64 PasswordField.capsLockIconColor=#ffffff64
#---- Popup ----
Popup.dropShadowColor=#000
Popup.dropShadowOpacity=0.25
#---- PopupMenu ---- #---- PopupMenu ----
PopupMenu.borderColor=#5e5e5e PopupMenu.borderColor=#5e5e5e
@@ -202,10 +217,10 @@ ProgressBar.selectionBackground=@foreground
#---- ScrollBar ---- #---- ScrollBar ----
ScrollBar.track=#3F4244 ScrollBar.track=lighten(@background,1%,derived noAutoInverse)
ScrollBar.thumb=lighten($ScrollBar.track,10%) ScrollBar.thumb=lighten($ScrollBar.track,10%,derived noAutoInverse)
ScrollBar.hoverTrackColor=lighten($ScrollBar.track,4%) ScrollBar.hoverTrackColor=lighten($ScrollBar.track,4%,derived noAutoInverse)
ScrollBar.hoverThumbColor=lighten($ScrollBar.thumb,10%) ScrollBar.hoverThumbColor=lighten($ScrollBar.thumb,10%,derived noAutoInverse)
#---- Separator ---- #---- Separator ----
@@ -218,7 +233,7 @@ Separator.foreground=#515151
Slider.trackColor=#646464 Slider.trackColor=#646464
Slider.thumbColor=#A6A6A6 Slider.thumbColor=#A6A6A6
Slider.tickColor=#888888 Slider.tickColor=#888888
Slider.hoverColor=darken($Slider.thumbColor,15%,derived autoInverse) Slider.hoverColor=darken($Slider.thumbColor,15%,derived)
Slider.disabledForeground=#4c5052 Slider.disabledForeground=#4c5052
@@ -253,11 +268,11 @@ TableHeader.bottomSeparatorColor=$TableHeader.separatorColor
#---- ToggleButton ---- #---- ToggleButton ----
ToggleButton.selectedBackground=lighten($ToggleButton.background,10%,derived autoInverse) ToggleButton.selectedBackground=lighten($ToggleButton.background,10%,derived)
ToggleButton.selectedForeground=@foreground ToggleButton.selectedForeground=@foreground
ToggleButton.disabledSelectedBackground=lighten($ToggleButton.background,3%,derived autoInverse) ToggleButton.disabledSelectedBackground=lighten($ToggleButton.background,3%,derived)
ToggleButton.toolbar.selectedBackground=lighten($ToggleButton.background,7%,derived autoInverse) ToggleButton.toolbar.selectedBackground=lighten($ToggleButton.background,7%,derived)
#---- ToolTip ---- #---- ToolTip ----

View File

@@ -48,6 +48,7 @@ CheckBox.icon.selectedPressedBackground=#72A1D4
Component.focusWidth=2 Component.focusWidth=2
Component.innerFocusWidth=0 Component.innerFocusWidth=0
Component.innerOutlineWidth=0
Component.arrowType=triangle Component.arrowType=triangle

View File

@@ -178,6 +178,8 @@ ColorChooser.swatchesDefaultRecentColor=$control
ComboBox.border=com.formdev.flatlaf.ui.FlatRoundBorder ComboBox.border=com.formdev.flatlaf.ui.FlatRoundBorder
ComboBox.padding=2,6,2,6 ComboBox.padding=2,6,2,6
ComboBox.minimumWidth=72
ComboBox.editorColumns=0
[mac]ComboBox.showPopupOnNavigation=true [mac]ComboBox.showPopupOnNavigation=true
@@ -185,6 +187,7 @@ ComboBox.padding=2,6,2,6
Component.focusWidth=0 Component.focusWidth=0
Component.innerFocusWidth={float}0.5 Component.innerFocusWidth={float}0.5
Component.innerOutlineWidth={float}1
Component.arc=5 Component.arc=5
Component.minimumWidth=64 Component.minimumWidth=64
Component.arrowType=chevron Component.arrowType=chevron
@@ -258,9 +261,16 @@ InternalFrame.buttonSize=24,24
InternalFrame.closeIcon=com.formdev.flatlaf.icons.FlatInternalFrameCloseIcon InternalFrame.closeIcon=com.formdev.flatlaf.icons.FlatInternalFrameCloseIcon
InternalFrame.iconifyIcon=com.formdev.flatlaf.icons.FlatInternalFrameIconifyIcon InternalFrame.iconifyIcon=com.formdev.flatlaf.icons.FlatInternalFrameIconifyIcon
InternalFrame.maximizeIcon=com.formdev.flatlaf.icons.FlatInternalFrameMaximizeIcon InternalFrame.maximizeIcon=com.formdev.flatlaf.icons.FlatInternalFrameMaximizeIcon
InternalFrame.minimizeIcon=com.formdev.flatlaf.icons.FlatInternalFrameMinimizeIcon InternalFrame.minimizeIcon=com.formdev.flatlaf.icons.FlatInternalFrameRestoreIcon
InternalFrame.windowBindings=null InternalFrame.windowBindings=null
# drop shadow
InternalFrame.dropShadowPainted=true
InternalFrame.activeDropShadowColor=null
InternalFrame.activeDropShadowInsets=5,5,6,6
InternalFrame.inactiveDropShadowColor=null
InternalFrame.inactiveDropShadowInsets=3,3,4,4
#---- InternalFrameTitlePane ---- #---- InternalFrameTitlePane ----
@@ -362,6 +372,12 @@ PasswordField.echoChar=\u2022
PasswordField.capsLockIcon=com.formdev.flatlaf.icons.FlatCapsLockIcon PasswordField.capsLockIcon=com.formdev.flatlaf.icons.FlatCapsLockIcon
#---- Popup ----
Popup.dropShadowPainted=true
Popup.dropShadowInsets=-4,-4,4,4
#---- PopupMenu ---- #---- PopupMenu ----
PopupMenu.border=com.formdev.flatlaf.ui.FlatPopupMenuBorder PopupMenu.border=com.formdev.flatlaf.ui.FlatPopupMenuBorder
@@ -410,12 +426,24 @@ RadioButtonMenuItem.background=@menuBackground
#---- ScrollBar ---- #---- ScrollBar ----
ScrollBar.width=10 ScrollBar.width=10
ScrollBar.trackInsets=0,0,0,0
ScrollBar.thumbInsets=0,0,0,0
ScrollBar.trackArc=0
ScrollBar.thumbArc=0
ScrollBar.hoverThumbWithTrack=false
ScrollBar.showButtons=false ScrollBar.showButtons=false
ScrollBar.squareButtons=false ScrollBar.squareButtons=false
ScrollBar.buttonArrowColor=$ComboBox.buttonArrowColor ScrollBar.buttonArrowColor=$ComboBox.buttonArrowColor
ScrollBar.buttonDisabledArrowColor=$ComboBox.buttonDisabledArrowColor ScrollBar.buttonDisabledArrowColor=$ComboBox.buttonDisabledArrowColor
ScrollBar.allowsAbsolutePositioning=true ScrollBar.allowsAbsolutePositioning=true
[mac]ScrollBar.thumbInsets=2,2,2,2
[mac]ScrollBar.thumbArc=999
[mac]ScrollBar.hoverThumbWithTrack=true
[linux]ScrollBar.thumbInsets=2,2,2,2
[linux]ScrollBar.thumbArc=999
#---- ScrollPane ---- #---- ScrollPane ----

View File

@@ -73,8 +73,8 @@ controlDkShadow=darken($controlShadow,15%)
Button.background=#ffffff Button.background=#ffffff
Button.focusedBackground=#e3f1fa Button.focusedBackground=#e3f1fa
Button.hoverBackground=darken($Button.background,3%,derived autoInverse) Button.hoverBackground=darken($Button.background,3%,derived)
Button.pressedBackground=darken($Button.background,10%,derived autoInverse) Button.pressedBackground=darken($Button.background,10%,derived)
Button.borderColor=$Component.borderColor Button.borderColor=$Component.borderColor
Button.disabledBorderColor=$Component.disabledBorderColor Button.disabledBorderColor=$Component.disabledBorderColor
@@ -92,8 +92,8 @@ Button.default.focusedBorderColor=$Button.focusedBorderColor
Button.default.focusColor=$Component.focusColor Button.default.focusColor=$Component.focusColor
Button.default.borderWidth=2 Button.default.borderWidth=2
Button.toolbar.hoverBackground=darken($Button.background,12%,derived autoInverse) Button.toolbar.hoverBackground=darken($Button.background,12%,derived)
Button.toolbar.pressedBackground=darken($Button.background,15%,derived autoInverse) Button.toolbar.pressedBackground=darken($Button.background,15%,derived)
#---- CheckBox ---- #---- CheckBox ----
@@ -132,6 +132,12 @@ Component.focusColor=#97c3f3
Component.linkColor=#2470B3 Component.linkColor=#2470B3
Component.grayFilter=25,-25,100 Component.grayFilter=25,-25,100
Component.error.borderColor=lighten(desaturate($Component.error.focusedBorderColor,20%),25%)
Component.error.focusedBorderColor=#e53e4d
Component.warning.borderColor=lighten(saturate($Component.warning.focusedBorderColor,25%),20%)
Component.warning.focusedBorderColor=#e2a53a
Component.custom.borderColor=lighten(desaturate(#f00,20%,derived noAutoInverse),25%,derived noAutoInverse)
#---- Desktop ---- #---- Desktop ----
@@ -158,13 +164,16 @@ InternalFrame.inactiveTitleForeground=@disabledText
InternalFrame.activeBorderColor=darken($Component.borderColor,20%) InternalFrame.activeBorderColor=darken($Component.borderColor,20%)
InternalFrame.inactiveBorderColor=$Component.borderColor InternalFrame.inactiveBorderColor=$Component.borderColor
InternalFrame.buttonHoverBackground=darken($InternalFrame.activeTitleBackground,10%,derived autoInverse) InternalFrame.buttonHoverBackground=darken($InternalFrame.activeTitleBackground,10%,derived)
InternalFrame.buttonPressedBackground=darken($InternalFrame.activeTitleBackground,20%,derived autoInverse) InternalFrame.buttonPressedBackground=darken($InternalFrame.activeTitleBackground,20%,derived)
InternalFrame.closeHoverBackground=lazy(Actions.Red) InternalFrame.closeHoverBackground=lazy(Actions.Red)
InternalFrame.closePressedBackground=darken(Actions.Red,10%,lazy) InternalFrame.closePressedBackground=darken(Actions.Red,10%,lazy)
InternalFrame.closeHoverForeground=#fff InternalFrame.closeHoverForeground=#fff
InternalFrame.closePressedForeground=#fff InternalFrame.closePressedForeground=#fff
InternalFrame.activeDropShadowOpacity=0.25
InternalFrame.inactiveDropShadowOpacity=0.5
#---- List ---- #---- List ----
@@ -194,6 +203,12 @@ MenuItemCheckBox.icon.disabledCheckmarkColor=#ABABAB
PasswordField.capsLockIconColor=#00000064 PasswordField.capsLockIconColor=#00000064
#---- Popup ----
Popup.dropShadowColor=#000
Popup.dropShadowOpacity=0.15
#---- PopupMenu ---- #---- PopupMenu ----
PopupMenu.borderColor=#adadad PopupMenu.borderColor=#adadad
@@ -209,10 +224,10 @@ ProgressBar.selectionBackground=@foreground
#---- ScrollBar ---- #---- ScrollBar ----
ScrollBar.track=#F5F5F5 ScrollBar.track=lighten(@background,1%,derived noAutoInverse)
ScrollBar.thumb=darken($ScrollBar.track,10%) ScrollBar.thumb=darken($ScrollBar.track,10%,derived noAutoInverse)
ScrollBar.hoverTrackColor=darken($ScrollBar.track,3%) ScrollBar.hoverTrackColor=darken($ScrollBar.track,3%,derived noAutoInverse)
ScrollBar.hoverThumbColor=darken($ScrollBar.thumb,10%) ScrollBar.hoverThumbColor=darken($ScrollBar.thumb,10%,derived noAutoInverse)
#---- Separator ---- #---- Separator ----
@@ -225,7 +240,7 @@ Separator.foreground=#d1d1d1
Slider.trackColor=#c4c4c4 Slider.trackColor=#c4c4c4
Slider.thumbColor=#6e6e6e Slider.thumbColor=#6e6e6e
Slider.tickColor=#888888 Slider.tickColor=#888888
Slider.hoverColor=lighten($Slider.thumbColor,15%,derived autoInverse) Slider.hoverColor=lighten($Slider.thumbColor,15%,derived)
Slider.disabledForeground=#c0c0c0 Slider.disabledForeground=#c0c0c0
@@ -260,9 +275,9 @@ TableHeader.bottomSeparatorColor=$TableHeader.separatorColor
#---- ToggleButton ---- #---- ToggleButton ----
ToggleButton.selectedBackground=darken($ToggleButton.background,20%,derived autoInverse) ToggleButton.selectedBackground=darken($ToggleButton.background,20%,derived)
ToggleButton.selectedForeground=@foreground ToggleButton.selectedForeground=@foreground
ToggleButton.disabledSelectedBackground=darken($ToggleButton.background,13%,derived autoInverse) ToggleButton.disabledSelectedBackground=darken($ToggleButton.background,13%,derived)
ToggleButton.toolbar.selectedBackground=$ToggleButton.selectedBackground ToggleButton.toolbar.selectedBackground=$ToggleButton.selectedBackground

View File

@@ -39,8 +39,8 @@ HelpButton.hoverBorderColor=null
ToggleButton.startBackground=$ToggleButton.background ToggleButton.startBackground=$ToggleButton.background
ToggleButton.endBackground=$ToggleButton.background ToggleButton.endBackground=$ToggleButton.background
[dark]ToggleButton.selectedBackground=lighten($ToggleButton.background,15%,derived autoInverse) [dark]ToggleButton.selectedBackground=lighten($ToggleButton.background,15%,derived)
[dark]ToggleButton.disabledSelectedBackground=lighten($ToggleButton.background,5%,derived autoInverse) [dark]ToggleButton.disabledSelectedBackground=lighten($ToggleButton.background,5%,derived)
#---- theme specific ---- #---- theme specific ----

View File

@@ -0,0 +1,48 @@
#
# 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=Look &In:
FileChooser.saveInLabelText=Save In:
FileChooser.fileNameLabel.textAndMnemonic=File &Name:
FileChooser.folderNameLabel.textAndMnemonic=Folder &name:
FileChooser.filesOfTypeLabel.textAndMnemonic=Files of &Type:
# toolbar
FileChooser.upFolderToolTipText=Up One Level
FileChooser.upFolderAccessibleName=Up
FileChooser.homeFolderToolTipText=Home
FileChooser.homeFolderAccessibleName=Home
FileChooser.newFolderToolTipText=Create New Folder
FileChooser.newFolderAccessibleName=New Folder
FileChooser.listViewButtonToolTipText=List
FileChooser.listViewButtonAccessibleName=List
FileChooser.detailsViewButtonToolTipText=Details
FileChooser.detailsViewButtonAccessibleName=Details
# details table header
FileChooser.fileNameHeaderText=Name
FileChooser.fileSizeHeaderText=Size
FileChooser.fileTypeHeaderText=Type
FileChooser.fileDateHeaderText=Modified
FileChooser.fileAttrHeaderText=Attributes
# popup menu
FileChooser.viewMenuLabelText=View
FileChooser.refreshActionLabelText=Refresh
FileChooser.newFolderActionLabelText=New Folder
FileChooser.listViewActionLabelText=List
FileChooser.detailsViewActionLabelText=Details

View File

@@ -0,0 +1,48 @@
#
# 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=Suchen &in:
FileChooser.saveInLabelText=Speichern in:
FileChooser.fileNameLabel.textAndMnemonic=&Dateiname:
FileChooser.folderNameLabel.textAndMnemonic=Ordner&name:
FileChooser.filesOfTypeLabel.textAndMnemonic=Datei&typ:
# toolbar
FileChooser.upFolderToolTipText=Eine Ebene h\u00F6her
FileChooser.upFolderAccessibleName=Nach oben
FileChooser.homeFolderToolTipText=Home
FileChooser.homeFolderAccessibleName=Home
FileChooser.newFolderToolTipText=Neuen Ordner erstellen
FileChooser.newFolderAccessibleName=Neuer Ordner
FileChooser.listViewButtonToolTipText=Liste
FileChooser.listViewButtonAccessibleName=Liste
FileChooser.detailsViewButtonToolTipText=Details
FileChooser.detailsViewButtonAccessibleName=Details
# details table header
FileChooser.fileNameHeaderText=Name
FileChooser.fileSizeHeaderText=Gr\u00F6\u00DFe
FileChooser.fileTypeHeaderText=Typ
FileChooser.fileDateHeaderText=\u00C4nderungsdatum
FileChooser.fileAttrHeaderText=Attribute
# popup menu
FileChooser.viewMenuLabelText=Ansicht
FileChooser.refreshActionLabelText=Aktualisieren
FileChooser.newFolderActionLabelText=Neuer Ordner
FileChooser.listViewActionLabelText=Liste
FileChooser.detailsViewActionLabelText=Details

View File

@@ -0,0 +1,48 @@
#
# 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=Rechercher &dans:
FileChooser.saveInLabelText=Enregistrer dans:
FileChooser.fileNameLabel.textAndMnemonic=&Nom du fichier:
FileChooser.folderNameLabel.textAndMnemonic=&Nom du dossier:
FileChooser.filesOfTypeLabel.textAndMnemonic=&Type de fichier:
# toolbar
FileChooser.upFolderToolTipText=Remonte d'un niveau
FileChooser.upFolderAccessibleName=Monter
FileChooser.homeFolderToolTipText=R\u00E9pertoire de base
FileChooser.homeFolderAccessibleName=R\u00E9pertoire de base
FileChooser.newFolderToolTipText=Cr\u00E9e un dossier
FileChooser.newFolderAccessibleName=Nouveau dossier
FileChooser.listViewButtonToolTipText=Liste
FileChooser.listViewButtonAccessibleName=Liste
FileChooser.detailsViewButtonToolTipText=D\u00E9tails
FileChooser.detailsViewButtonAccessibleName=D\u00E9tails
# details table header
FileChooser.fileNameHeaderText=Nom
FileChooser.fileSizeHeaderText=Taille
FileChooser.fileTypeHeaderText=Type
FileChooser.fileDateHeaderText=Modifi\u00E9
FileChooser.fileAttrHeaderText=Attributs
# popup menu
FileChooser.viewMenuLabelText=Affichage
FileChooser.refreshActionLabelText=Actualiser
FileChooser.newFolderActionLabelText=Nouveau dossier
FileChooser.listViewActionLabelText=Liste
FileChooser.detailsViewActionLabelText=D\u00E9tails

View File

@@ -27,11 +27,18 @@ plugins {
id( "com.jfrog.artifactory" ) id( "com.jfrog.artifactory" )
} }
repositories {
maven {
// for using MigLayout snapshot
url = uri( "https://oss.sonatype.org/content/repositories/snapshots/" )
}
}
dependencies { dependencies {
implementation( project( ":flatlaf-core" ) ) implementation( project( ":flatlaf-core" ) )
implementation( project( ":flatlaf-extras" ) ) implementation( project( ":flatlaf-extras" ) )
implementation( project( ":flatlaf-intellij-themes" ) ) implementation( project( ":flatlaf-intellij-themes" ) )
implementation( "com.miglayout:miglayout-swing:5.2" ) implementation( "com.miglayout:miglayout-swing:5.3-SNAPSHOT" )
implementation( "com.jgoodies:jgoodies-forms:1.9.0" ) implementation( "com.jgoodies:jgoodies-forms:1.9.0" )
} }
@@ -49,6 +56,7 @@ tasks {
} }
exclude( "module-info.class" ) exclude( "module-info.class" )
exclude( "META-INF/versions/*/module-info.class" )
// include all dependencies in jar // include all dependencies in jar
from( { from( {

View File

@@ -114,6 +114,14 @@ class BasicComponentsPanel
JScrollPane scrollPane12 = new JScrollPane(); JScrollPane scrollPane12 = new JScrollPane();
JTextPane textPane4 = new JTextPane(); JTextPane textPane4 = new JTextPane();
JTextPane textPane5 = new JTextPane(); JTextPane textPane5 = new JTextPane();
JLabel label3 = new JLabel();
JTextField textField5 = new JTextField();
JComboBox<String> comboBox7 = new JComboBox<>();
JSpinner spinner3 = new JSpinner();
JLabel label4 = new JLabel();
JTextField textField7 = new JTextField();
JComboBox<String> comboBox8 = new JComboBox<>();
JSpinner spinner4 = new JSpinner();
JPopupMenu popupMenu1 = new JPopupMenu(); JPopupMenu popupMenu1 = new JPopupMenu();
JMenuItem cutMenuItem = new JMenuItem(); JMenuItem cutMenuItem = new JMenuItem();
JMenuItem copyMenuItem = new JMenuItem(); JMenuItem copyMenuItem = new JMenuItem();
@@ -141,6 +149,8 @@ class BasicComponentsPanel
"[]" + "[]" +
"[]" + "[]" +
"[]" + "[]" +
"[]para" +
"[]" +
"[]")); "[]"));
//---- labelLabel ---- //---- labelLabel ----
@@ -179,9 +189,8 @@ class BasicComponentsPanel
add(button5, "cell 3 1"); add(button5, "cell 3 1");
//---- button6 ---- //---- button6 ----
button6.setText("square"); button6.setText("round");
button6.setEnabled(false); button6.putClientProperty("JButton.buttonType", "roundRect");
button6.putClientProperty("JButton.buttonType", "square");
add(button6, "cell 4 1"); add(button6, "cell 4 1");
//---- button3 ---- //---- button3 ----
@@ -597,6 +606,45 @@ class BasicComponentsPanel
textPane5.setText("no scroll pane"); textPane5.setText("no scroll pane");
add(textPane5, "cell 5 11,growx"); add(textPane5, "cell 5 11,growx");
//---- label3 ----
label3.setText("Error hints:");
add(label3, "cell 0 12");
//---- textField5 ----
textField5.putClientProperty("JComponent.outline", "error");
add(textField5, "cell 1 12,growx");
//---- comboBox7 ----
comboBox7.putClientProperty("JComponent.outline", "error");
comboBox7.setModel(new DefaultComboBoxModel<>(new String[] {
"editable"
}));
comboBox7.setEditable(true);
add(comboBox7, "cell 2 12,growx");
//---- spinner3 ----
spinner3.putClientProperty("JComponent.outline", "error");
add(spinner3, "cell 3 12,growx");
//---- label4 ----
label4.setText("Warning hints:");
add(label4, "cell 0 13");
//---- textField7 ----
textField7.putClientProperty("JComponent.outline", "warning");
add(textField7, "cell 1 13,growx");
//---- comboBox8 ----
comboBox8.putClientProperty("JComponent.outline", "warning");
comboBox8.setModel(new DefaultComboBoxModel<>(new String[] {
"not editable"
}));
add(comboBox8, "cell 2 13,growx");
//---- spinner4 ----
spinner4.putClientProperty("JComponent.outline", "warning");
add(spinner4, "cell 3 13,growx");
//======== popupMenu1 ======== //======== popupMenu1 ========
{ {

View File

@@ -1,4 +1,4 @@
JFDML JFormDesigner: "7.0.0.0.194" Java: "13.0.1" encoding: "UTF-8" JFDML JFormDesigner: "7.0.1.0.272" Java: "13.0.2" encoding: "UTF-8"
new FormModel { new FormModel {
contentType: "form/swing" contentType: "form/swing"
@@ -9,7 +9,7 @@ new FormModel {
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) { add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
"$layoutConstraints": "hidemode 3" "$layoutConstraints": "hidemode 3"
"$columnConstraints": "[][][][][][]" "$columnConstraints": "[][][][][][]"
"$rowConstraints": "[][][][][][][][][][][][]" "$rowConstraints": "[][][][][][][][][][][][]para[][]"
} ) { } ) {
name: "this" name: "this"
add( new FormComponent( "javax.swing.JLabel" ) { add( new FormComponent( "javax.swing.JLabel" ) {
@@ -63,9 +63,8 @@ new FormModel {
} ) } )
add( new FormComponent( "javax.swing.JButton" ) { add( new FormComponent( "javax.swing.JButton" ) {
name: "button6" name: "button6"
"text": "square" "text": "round"
"enabled": false "$client.JButton.buttonType": "roundRect"
"$client.JButton.buttonType": "square"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 4 1" "value": "cell 4 1"
} ) } )
@@ -592,9 +591,66 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 5 11,growx" "value": "cell 5 11,growx"
} ) } )
add( new FormComponent( "javax.swing.JLabel" ) {
name: "label3"
"text": "Error hints:"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 12"
} )
add( new FormComponent( "javax.swing.JTextField" ) {
name: "textField5"
"$client.JComponent.outline": "error"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 12,growx"
} )
add( new FormComponent( "javax.swing.JComboBox" ) {
name: "comboBox7"
"$client.JComponent.outline": "error"
"model": new javax.swing.DefaultComboBoxModel {
selectedItem: "editable"
addElement( "editable" )
}
"editable": true
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 2 12,growx"
} )
add( new FormComponent( "javax.swing.JSpinner" ) {
name: "spinner3"
"$client.JComponent.outline": "error"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 3 12,growx"
} )
add( new FormComponent( "javax.swing.JLabel" ) {
name: "label4"
"text": "Warning hints:"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 13"
} )
add( new FormComponent( "javax.swing.JTextField" ) {
name: "textField7"
"$client.JComponent.outline": "warning"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 13,growx"
} )
add( new FormComponent( "javax.swing.JComboBox" ) {
name: "comboBox8"
"$client.JComponent.outline": "warning"
"model": new javax.swing.DefaultComboBoxModel {
selectedItem: "not editable"
addElement( "not editable" )
}
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 2 13,growx"
} )
add( new FormComponent( "javax.swing.JSpinner" ) {
name: "spinner4"
"$client.JComponent.outline": "warning"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 3 13,growx"
} )
}, new FormLayoutConstraints( null ) { }, new FormLayoutConstraints( null ) {
"location": new java.awt.Point( 0, 0 ) "location": new java.awt.Point( 0, 0 )
"size": new java.awt.Dimension( 790, 440 ) "size": new java.awt.Dimension( 920, 440 )
} ) } )
add( new FormContainer( "javax.swing.JPopupMenu", new FormLayoutManager( class javax.swing.JPopupMenu ) ) { add( new FormContainer( "javax.swing.JPopupMenu", new FormLayoutManager( class javax.swing.JPopupMenu ) ) {
name: "popupMenu1" name: "popupMenu1"

View File

@@ -37,7 +37,7 @@ import net.miginfocom.swing.*;
class ControlBar class ControlBar
extends JPanel extends JPanel
{ {
private JFrame frame; private DemoFrame frame;
private JTabbedPane tabbedPane; private JTabbedPane tabbedPane;
ControlBar() { ControlBar() {
@@ -78,6 +78,9 @@ class ControlBar
// update info label because user scale factor may change // update info label because user scale factor may change
updateInfoLabel(); updateInfoLabel();
// update "Font" menu
frame.updateFontMenuItems();
// this is necessary because embedded JOptionPane's "steal" the default button // this is necessary because embedded JOptionPane's "steal" the default button
frame.getRootPane().setDefaultButton( closeButton ); frame.getRootPane().setDefaultButton( closeButton );
} ); } );
@@ -90,7 +93,15 @@ class ControlBar
} ); } );
} }
void initialize( JFrame frame, JTabbedPane tabbedPane ) { @Override
public void updateUI() {
super.updateUI();
if( infoLabel != null )
updateInfoLabel();
}
void initialize( DemoFrame frame, JTabbedPane tabbedPane ) {
this.frame = frame; this.frame = frame;
this.tabbedPane = tabbedPane; this.tabbedPane = tabbedPane;
@@ -139,12 +150,20 @@ class ControlBar
} }
private void updateInfoLabel() { private void updateInfoLabel() {
String javaVendor = System.getProperty( "java.vendor" );
if( "Oracle Corporation".equals( javaVendor ) )
javaVendor = null;
double systemScaleFactor = UIScale.getSystemScaleFactor( getGraphicsConfiguration() ); double systemScaleFactor = UIScale.getSystemScaleFactor( getGraphicsConfiguration() );
float userScaleFactor = UIScale.getUserScaleFactor(); float userScaleFactor = UIScale.getUserScaleFactor();
Font font = UIManager.getFont( "Label.font" );
String newInfo = "(Java " + System.getProperty( "java.version" ) String newInfo = "(Java " + System.getProperty( "java.version" )
+ (javaVendor != null ? ("; " + javaVendor) : "")
+ (systemScaleFactor != 1 ? ("; system scale factor " + systemScaleFactor) : "") + (systemScaleFactor != 1 ? ("; system scale factor " + systemScaleFactor) : "")
+ (userScaleFactor != 1 ? ("; user scale factor " + userScaleFactor) : "") + (userScaleFactor != 1 ? ("; user scale factor " + userScaleFactor) : "")
+ (systemScaleFactor == 1 && userScaleFactor == 1 ? "; no scaling" : "") + (systemScaleFactor == 1 && userScaleFactor == 1 ? "; no scaling" : "")
+ "; " + font.getFamily() + " " + font.getSize()
+ (font.isBold() ? " BOLD" : "")
+ (font.isItalic() ? " ITALIC" : "")
+ ")"; + ")";
if( !newInfo.equals( infoLabel.getText() ) ) if( !newInfo.equals( infoLabel.getText() ) )
@@ -177,6 +196,10 @@ class ControlBar
// change look and feel // change look and feel
UIManager.setLookAndFeel( lafClassName ); UIManager.setLookAndFeel( lafClassName );
// clear custom default font when switching to non-FlatLaf LaF
if( !(UIManager.getLookAndFeel() instanceof FlatLaf) )
UIManager.put( "defaultFont", null );
// update all components // update all components
FlatLaf.updateUI(); FlatLaf.updateUI();
@@ -208,6 +231,9 @@ class ControlBar
private void enabledChanged() { private void enabledChanged() {
enabledDisable( tabbedPane, enabledCheckBox.isSelected() ); enabledDisable( tabbedPane, enabledCheckBox.isSelected() );
// repainting whole tabbed pane is faster than repainting many individual components
tabbedPane.repaint();
} }
private void enabledDisable( Container container, boolean enabled ) { private void enabledDisable( Container container, boolean enabled ) {

View File

@@ -18,8 +18,11 @@ package com.formdev.flatlaf.demo;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import java.util.ArrayList;
import java.util.Arrays;
import javax.swing.*; import javax.swing.*;
import javax.swing.text.DefaultEditorKit; import javax.swing.text.DefaultEditorKit;
import javax.swing.text.StyleContext;
import com.formdev.flatlaf.FlatLaf; import com.formdev.flatlaf.FlatLaf;
import com.formdev.flatlaf.demo.extras.*; import com.formdev.flatlaf.demo.extras.*;
import com.formdev.flatlaf.demo.intellijthemes.*; import com.formdev.flatlaf.demo.intellijthemes.*;
@@ -32,10 +35,18 @@ import net.miginfocom.swing.*;
class DemoFrame class DemoFrame
extends JFrame extends JFrame
{ {
private final String[] availableFontFamilyNames;
private int initialFontMenuItemCount = -1;
DemoFrame() { DemoFrame() {
int tabIndex = DemoPrefs.getState().getInt( FlatLafDemo.KEY_TAB, 0 ); int tabIndex = DemoPrefs.getState().getInt( FlatLafDemo.KEY_TAB, 0 );
availableFontFamilyNames = GraphicsEnvironment.getLocalGraphicsEnvironment()
.getAvailableFontFamilyNames().clone();
Arrays.sort( availableFontFamilyNames );
initComponents(); initComponents();
updateFontMenuItems();
controlBar.initialize( this, tabbedPane ); controlBar.initialize( this, tabbedPane );
if( tabIndex >= 0 && tabIndex < tabbedPane.getTabCount() && tabIndex != tabbedPane.getSelectedIndex() ) if( tabIndex >= 0 && tabIndex < tabbedPane.getTabCount() && tabIndex != tabbedPane.getSelectedIndex() )
@@ -64,11 +75,16 @@ class DemoFrame
UIManager.put( "MenuItem.selectionType", underlineMenuSelectionMenuItem.isSelected() ? "underline" : null ); UIManager.put( "MenuItem.selectionType", underlineMenuSelectionMenuItem.isSelected() ? "underline" : null );
} }
private void alwaysShowMnemonics() {
UIManager.put( "Component.hideMnemonics", !alwaysShowMnemonicsMenuItem.isSelected() );
repaint();
}
private void fontFamilyChanged( ActionEvent e ) { private void fontFamilyChanged( ActionEvent e ) {
String fontFamily = e.getActionCommand(); String fontFamily = e.getActionCommand();
Font font = UIManager.getFont( "defaultFont" ); Font font = UIManager.getFont( "defaultFont" );
Font newFont = new Font( fontFamily, font.getStyle(), font.getSize() ); Font newFont = StyleContext.getDefaultStyleContext().getFont( fontFamily, font.getStyle(), font.getSize() );
UIManager.put( "defaultFont", newFont ); UIManager.put( "defaultFont", newFont );
FlatLaf.updateUI(); FlatLaf.updateUI();
@@ -86,6 +102,7 @@ class DemoFrame
private void restoreFont() { private void restoreFont() {
UIManager.put( "defaultFont", null ); UIManager.put( "defaultFont", null );
updateFontMenuItems();
FlatLaf.updateUI(); FlatLaf.updateUI();
} }
@@ -94,17 +111,80 @@ class DemoFrame
Font newFont = font.deriveFont( (float) (font.getSize() + 1) ); Font newFont = font.deriveFont( (float) (font.getSize() + 1) );
UIManager.put( "defaultFont", newFont ); UIManager.put( "defaultFont", newFont );
updateFontMenuItems();
FlatLaf.updateUI(); FlatLaf.updateUI();
} }
private void decrFont() { private void decrFont() {
Font font = UIManager.getFont( "defaultFont" ); Font font = UIManager.getFont( "defaultFont" );
Font newFont = font.deriveFont( (float) Math.max( font.getSize() - 1, 8 ) ); Font newFont = font.deriveFont( (float) Math.max( font.getSize() - 1, 10 ) );
UIManager.put( "defaultFont", newFont ); UIManager.put( "defaultFont", newFont );
updateFontMenuItems();
FlatLaf.updateUI(); FlatLaf.updateUI();
} }
void updateFontMenuItems() {
if( initialFontMenuItemCount < 0 )
initialFontMenuItemCount = fontMenu.getItemCount();
else {
// remove old font items
for( int i = fontMenu.getItemCount() - 1; i >= initialFontMenuItemCount; i-- )
fontMenu.remove( i );
}
// get current font
Font currentFont = UIManager.getFont( "Label.font" );
String currentFamily = currentFont.getFamily();
String currentSize = Integer.toString( currentFont.getSize() );
// add font families
fontMenu.addSeparator();
ArrayList<String> families = new ArrayList<>( Arrays.asList(
"Arial", "Cantarell", "Comic Sans MS", "Courier New", "DejaVu Sans",
"Dialog", "Liberation Sans", "Monospaced", "Noto Sans", "Roboto",
"SansSerif", "Segoe UI", "Serif", "Tahoma", "Ubuntu", "Verdana" ) );
if( !families.contains( currentFamily ) )
families.add( currentFamily );
families.sort( String.CASE_INSENSITIVE_ORDER );
ButtonGroup familiesGroup = new ButtonGroup();
for( String family : families ) {
if( Arrays.binarySearch( availableFontFamilyNames, family ) < 0 )
continue; // not available
JCheckBoxMenuItem item = new JCheckBoxMenuItem( family );
item.setSelected( family.equals( currentFamily ) );
item.addActionListener( this::fontFamilyChanged );
fontMenu.add( item );
familiesGroup.add( item );
}
// add font sizes
fontMenu.addSeparator();
ArrayList<String> sizes = new ArrayList<>( Arrays.asList(
"10", "12", "14", "16", "18", "20", "24", "28" ) );
if( !sizes.contains( currentSize ) )
sizes.add( currentSize );
sizes.sort( String.CASE_INSENSITIVE_ORDER );
ButtonGroup sizesGroup = new ButtonGroup();
for( String size : sizes ) {
JCheckBoxMenuItem item = new JCheckBoxMenuItem( size );
item.setSelected( size.equals( currentSize ) );
item.addActionListener( this::fontSizeChanged );
fontMenu.add( item );
sizesGroup.add( item );
}
// enabled/disable items
boolean enabled = UIManager.getLookAndFeel() instanceof FlatLaf;
for( Component item : fontMenu.getMenuComponents() )
item.setEnabled( enabled );
}
private void initComponents() { private void initComponents() {
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
JMenuBar menuBar1 = new JMenuBar(); JMenuBar menuBar1 = new JMenuBar();
@@ -140,6 +220,7 @@ class DemoFrame
JMenuItem decrFontMenuItem = new JMenuItem(); JMenuItem decrFontMenuItem = new JMenuItem();
JMenu optionsMenu = new JMenu(); JMenu optionsMenu = new JMenu();
underlineMenuSelectionMenuItem = new JCheckBoxMenuItem(); underlineMenuSelectionMenuItem = new JCheckBoxMenuItem();
alwaysShowMnemonicsMenuItem = new JCheckBoxMenuItem();
JMenu helpMenu = new JMenu(); JMenu helpMenu = new JMenu();
JMenuItem aboutMenuItem = new JMenuItem(); JMenuItem aboutMenuItem = new JMenuItem();
JToolBar toolBar1 = new JToolBar(); JToolBar toolBar1 = new JToolBar();
@@ -350,19 +431,19 @@ class DemoFrame
//---- restoreFontMenuItem ---- //---- restoreFontMenuItem ----
restoreFontMenuItem.setText("Restore Font"); restoreFontMenuItem.setText("Restore Font");
restoreFontMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_0, KeyEvent.CTRL_MASK)); restoreFontMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_0, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
restoreFontMenuItem.addActionListener(e -> restoreFont()); restoreFontMenuItem.addActionListener(e -> restoreFont());
fontMenu.add(restoreFontMenuItem); fontMenu.add(restoreFontMenuItem);
//---- incrFontMenuItem ---- //---- incrFontMenuItem ----
incrFontMenuItem.setText("Increase Font Size"); incrFontMenuItem.setText("Increase Font Size");
incrFontMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, KeyEvent.CTRL_MASK)); incrFontMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
incrFontMenuItem.addActionListener(e -> incrFont()); incrFontMenuItem.addActionListener(e -> incrFont());
fontMenu.add(incrFontMenuItem); fontMenu.add(incrFontMenuItem);
//---- decrFontMenuItem ---- //---- decrFontMenuItem ----
decrFontMenuItem.setText("Decrease Font Size"); decrFontMenuItem.setText("Decrease Font Size");
decrFontMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, KeyEvent.CTRL_MASK)); decrFontMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
decrFontMenuItem.addActionListener(e -> decrFont()); decrFontMenuItem.addActionListener(e -> decrFont());
fontMenu.add(decrFontMenuItem); fontMenu.add(decrFontMenuItem);
} }
@@ -376,6 +457,11 @@ class DemoFrame
underlineMenuSelectionMenuItem.setText("Use underline menu selection"); underlineMenuSelectionMenuItem.setText("Use underline menu selection");
underlineMenuSelectionMenuItem.addActionListener(e -> underlineMenuSelection()); underlineMenuSelectionMenuItem.addActionListener(e -> underlineMenuSelection());
optionsMenu.add(underlineMenuSelectionMenuItem); optionsMenu.add(underlineMenuSelectionMenuItem);
//---- alwaysShowMnemonicsMenuItem ----
alwaysShowMnemonicsMenuItem.setText("Always show mnemonics");
alwaysShowMnemonicsMenuItem.addActionListener(e -> alwaysShowMnemonics());
optionsMenu.add(alwaysShowMnemonicsMenuItem);
} }
menuBar1.add(optionsMenu); menuBar1.add(optionsMenu);
@@ -482,31 +568,12 @@ class DemoFrame
cutMenuItem.addActionListener( new DefaultEditorKit.CutAction() ); cutMenuItem.addActionListener( new DefaultEditorKit.CutAction() );
copyMenuItem.addActionListener( new DefaultEditorKit.CopyAction() ); copyMenuItem.addActionListener( new DefaultEditorKit.CopyAction() );
pasteMenuItem.addActionListener( new DefaultEditorKit.PasteAction() ); pasteMenuItem.addActionListener( new DefaultEditorKit.PasteAction() );
// add font families
fontMenu.addSeparator();
String[] fontFamilies = { "Arial", "Comic Sans MS", "Courier New", "Dialog",
"Monospaced", "SansSerif", "Serif", "Tahoma", "Verdana" };
for( String fontFamily : fontFamilies ) {
JMenuItem fontItem = new JMenuItem( fontFamily );
fontItem.addActionListener( this::fontFamilyChanged );
fontMenu.add( fontItem );
}
// add font sizes
fontMenu.addSeparator();
int[] fontSizes = { 8, 10, 12, 14, 16, 18, 20, 24, 28 };
for( int fontSize : fontSizes ) {
String fontSizeStr = Integer.toString( fontSize );
JMenuItem fontItem = new JMenuItem( fontSizeStr );
fontItem.addActionListener( this::fontSizeChanged );
fontMenu.add( fontItem );
}
} }
// JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables
private JMenu fontMenu; private JMenu fontMenu;
private JCheckBoxMenuItem underlineMenuSelectionMenuItem; private JCheckBoxMenuItem underlineMenuSelectionMenuItem;
private JCheckBoxMenuItem alwaysShowMnemonicsMenuItem;
private JTabbedPane tabbedPane; private JTabbedPane tabbedPane;
private ControlBar controlBar; private ControlBar controlBar;
// JFormDesigner - End of variables declaration //GEN-END:variables // JFormDesigner - End of variables declaration //GEN-END:variables

View File

@@ -303,19 +303,19 @@ new FormModel {
add( new FormComponent( "javax.swing.JMenuItem" ) { add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "restoreFontMenuItem" name: "restoreFontMenuItem"
"text": "Restore Font" "text": "Restore Font"
"accelerator": static javax.swing.KeyStroke getKeyStroke( 48, 130, false ) "accelerator": static javax.swing.KeyStroke getKeyStroke( 48, 4226, false )
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "restoreFont", false ) ) addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "restoreFont", false ) )
} ) } )
add( new FormComponent( "javax.swing.JMenuItem" ) { add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "incrFontMenuItem" name: "incrFontMenuItem"
"text": "Increase Font Size" "text": "Increase Font Size"
"accelerator": static javax.swing.KeyStroke getKeyStroke( 521, 130, false ) "accelerator": static javax.swing.KeyStroke getKeyStroke( 521, 4226, false )
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "incrFont", false ) ) addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "incrFont", false ) )
} ) } )
add( new FormComponent( "javax.swing.JMenuItem" ) { add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "decrFontMenuItem" name: "decrFontMenuItem"
"text": "Decrease Font Size" "text": "Decrease Font Size"
"accelerator": static javax.swing.KeyStroke getKeyStroke( 45, 130, false ) "accelerator": static javax.swing.KeyStroke getKeyStroke( 45, 4226, false )
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "decrFont", false ) ) addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "decrFont", false ) )
} ) } )
} ) } )
@@ -330,6 +330,14 @@ new FormModel {
} }
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "underlineMenuSelection", false ) ) addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "underlineMenuSelection", false ) )
} ) } )
add( new FormComponent( "javax.swing.JCheckBoxMenuItem" ) {
name: "alwaysShowMnemonicsMenuItem"
"text": "Always show mnemonics"
auxiliary() {
"JavaCodeGenerator.variableLocal": false
}
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "alwaysShowMnemonics", false ) )
} )
} ) } )
add( new FormContainer( "javax.swing.JMenu", new FormLayoutManager( class javax.swing.JMenu ) ) { add( new FormContainer( "javax.swing.JMenu", new FormLayoutManager( class javax.swing.JMenu ) ) {
name: "helpMenu" name: "helpMenu"

View File

@@ -82,7 +82,7 @@ public class DemoPrefs
} else } else
UIManager.setLookAndFeel( lafClassName ); UIManager.setLookAndFeel( lafClassName );
} }
} catch( Exception ex ) { } catch( Throwable ex ) {
ex.printStackTrace(); ex.printStackTrace();
// fallback // fallback

View File

@@ -17,6 +17,7 @@
package com.formdev.flatlaf.demo; package com.formdev.flatlaf.demo;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import com.formdev.flatlaf.extras.FlatInspector;
import com.formdev.flatlaf.util.SystemInfo; import com.formdev.flatlaf.util.SystemInfo;
/** /**
@@ -28,7 +29,8 @@ public class FlatLafDemo
static final String KEY_TAB = "tab"; static final String KEY_TAB = "tab";
public static void main( String[] args ) { public static void main( String[] args ) {
if( SystemInfo.IS_MAC ) // on macOS enable screen menu bar
if( SystemInfo.IS_MAC && System.getProperty( "apple.laf.useScreenMenuBar" ) == null )
System.setProperty( "apple.laf.useScreenMenuBar", "true" ); System.setProperty( "apple.laf.useScreenMenuBar", "true" );
SwingUtilities.invokeLater( () -> { SwingUtilities.invokeLater( () -> {
@@ -37,6 +39,9 @@ public class FlatLafDemo
// set look and feel // set look and feel
DemoPrefs.initLaf( args ); DemoPrefs.initLaf( args );
// install inspector
FlatInspector.install( "ctrl shift alt X" );
// create frame // create frame
DemoFrame frame = new DemoFrame(); DemoFrame frame = new DemoFrame();

View File

@@ -46,21 +46,21 @@
"license": "MIT", "license": "MIT",
"licenseFile": "Gradianto.LICENSE.txt", "licenseFile": "Gradianto.LICENSE.txt",
"sourceCodeUrl": "https://github.com/thvardhan/Gradianto", "sourceCodeUrl": "https://github.com/thvardhan/Gradianto",
"sourceCodePath": "blob/master/resources/Gradianto_dark_fuchsia.theme.json" "sourceCodePath": "blob/master/src/main/resources/Gradianto_dark_fuchsia.theme.json"
}, },
"Gradianto_deep_ocean.theme.json": { "Gradianto_deep_ocean.theme.json": {
"name": "Gradianto Deep Ocean", "name": "Gradianto Deep Ocean",
"license": "MIT", "license": "MIT",
"licenseFile": "Gradianto.LICENSE.txt", "licenseFile": "Gradianto.LICENSE.txt",
"sourceCodeUrl": "https://github.com/thvardhan/Gradianto", "sourceCodeUrl": "https://github.com/thvardhan/Gradianto",
"sourceCodePath": "blob/master/resources/Gradianto_deep_ocean.theme.json" "sourceCodePath": "blob/master/src/main/resources/Gradianto_deep_ocean.theme.json"
}, },
"Gradianto_midnight_blue.theme.json": { "Gradianto_midnight_blue.theme.json": {
"name": "Gradianto Midnight Blue", "name": "Gradianto Midnight Blue",
"license": "MIT", "license": "MIT",
"licenseFile": "Gradianto.LICENSE.txt", "licenseFile": "Gradianto.LICENSE.txt",
"sourceCodeUrl": "https://github.com/thvardhan/Gradianto", "sourceCodeUrl": "https://github.com/thvardhan/Gradianto",
"sourceCodePath": "blob/master/resources/Gradianto_midnight_blue.theme.json" "sourceCodePath": "blob/master/src/main/resources/Gradianto_midnight_blue.theme.json"
}, },
"Gray.theme.json": { "Gray.theme.json": {
"name": "Gray", "name": "Gray",

View File

@@ -3,6 +3,12 @@ FlatLaf Extras
This sub-project provides some additional components and classes: This sub-project provides some additional components and classes:
- [FlatInspector](src/main/java/com/formdev/flatlaf/extras/FlatInspector.java):
A simple UI inspector that shows information about UI component at mouse
location in a tooltip.
- [FlatSVGIcon](src/main/java/com/formdev/flatlaf/extras/FlatSVGIcon.java): An
icon that displays SVG using
[svgSalamander](https://github.com/JFormDesigner/svgSalamander).
- [TriStateCheckBox](src/main/java/com/formdev/flatlaf/extras/TriStateCheckBox.java): - [TriStateCheckBox](src/main/java/com/formdev/flatlaf/extras/TriStateCheckBox.java):
A tri-state check box. A tri-state check box.
@@ -10,4 +16,21 @@ This sub-project provides some additional components and classes:
Download Download
-------- --------
Not yet available. FlatLaf Extras binaries are available on **JCenter** and **Maven Central**.
If you use Maven or Gradle, add a dependency with following coordinates to your
build script:
groupId: com.formdev
artifactId: flatlaf-extras
version: (see button below)
Otherwise download `flatlaf-extras-<version>.jar` here:
[![Download](https://api.bintray.com/packages/jformdesigner/flatlaf/flatlaf-extras/images/download.svg)](https://bintray.com/jformdesigner/flatlaf/flatlaf-extras/_latestVersion)
You also need `flatlaf-<version>.jar` and `svgSalamander-<version>.jar`, which
you can download here:
[![Download](https://api.bintray.com/packages/jformdesigner/flatlaf/flatlaf/images/download.svg)](https://bintray.com/jformdesigner/flatlaf/flatlaf/_latestVersion)
[![Download](https://api.bintray.com/packages/jformdesigner/svgSalamander/svgSalamander/images/download.svg)](https://bintray.com/jformdesigner/svgSalamander/svgSalamander/_latestVersion)

View File

@@ -16,9 +16,8 @@
plugins { plugins {
`java-library` `java-library`
`maven-publish` `flatlaf-module-info`
id( "com.jfrog.bintray" ) `flatlaf-publish`
id( "com.jfrog.artifactory" )
} }
dependencies { dependencies {
@@ -26,113 +25,28 @@ dependencies {
implementation( "com.formdev:svgSalamander:1.1.2.1" ) implementation( "com.formdev:svgSalamander:1.1.2.1" )
} }
tasks { flatlafModuleInfo {
assemble { dependsOn( ":flatlaf-core:jar" )
dependsOn( }
"sourcesJar",
"javadocJar"
)
}
java {
withSourcesJar()
withJavadocJar()
}
tasks {
javadoc { javadoc {
options { options {
this as StandardJavadocDocletOptions this as StandardJavadocDocletOptions
use( true )
tags = listOf( "uiDefault", "clientProperty" ) tags = listOf( "uiDefault", "clientProperty" )
} }
isFailOnError = false isFailOnError = false
} }
register( "sourcesJar", Jar::class ) {
archiveClassifier.set( "sources" )
from( sourceSets.main.get().allJava )
}
register( "javadocJar", Jar::class ) {
archiveClassifier.set( "javadoc" )
from( javadoc )
}
} }
publishing { flatlafPublish {
publications { artifactId = "flatlaf-extras"
create<MavenPublication>( "maven" ) { name = "FlatLaf Extras"
artifactId = "flatlaf-extras" description = "Flat Look and Feel Extras"
groupId = "com.formdev"
from( components["java"] )
artifact( tasks["sourcesJar"] )
artifact( tasks["javadocJar"] )
pom {
name.set( "FlatLaf Extras" )
description.set( "Flat Look and Feel Extras" )
url.set( "https://github.com/JFormDesigner/FlatLaf" )
licenses {
license {
name.set( "The Apache License, Version 2.0" )
url.set( "https://www.apache.org/licenses/LICENSE-2.0.txt" )
}
}
developers {
developer {
name.set( "Karl Tauber" )
organization.set( "FormDev Software GmbH" )
organizationUrl.set( "https://www.formdev.com/" )
}
}
scm {
url.set( "https://github.com/JFormDesigner/FlatLaf" )
}
}
}
}
}
bintray {
user = rootProject.extra["bintray.user"] as String?
key = rootProject.extra["bintray.key"] as String?
setPublications( "maven" )
with( pkg ) {
repo = "flatlaf"
name = "flatlaf-extras"
setLicenses( "Apache-2.0" )
vcsUrl = "https://github.com/JFormDesigner/FlatLaf"
with( version ) {
name = project.version.toString()
}
publish = rootProject.extra["bintray.publish"] as Boolean
dryRun = rootProject.extra["bintray.dryRun"] as Boolean
}
}
artifactory {
setContextUrl( "https://oss.jfrog.org" )
publish( closureOf<org.jfrog.gradle.plugin.artifactory.dsl.PublisherConfig> {
repository( delegateClosureOf<groovy.lang.GroovyObject> {
setProperty( "repoKey", "oss-snapshot-local" )
setProperty( "username", rootProject.extra["bintray.user"] as String? )
setProperty( "password", rootProject.extra["bintray.key"] as String? )
} )
defaults( delegateClosureOf<groovy.lang.GroovyObject> {
invokeMethod( "publications", "maven" )
setProperty( "publishArtifacts", true )
setProperty( "publishPom", true )
} )
} )
resolve( delegateClosureOf<org.jfrog.gradle.plugin.artifactory.dsl.ResolverConfig> {
setProperty( "repoKey", "jcenter" )
} )
} }

View File

@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package com.formdev.flatlaf.testing; package com.formdev.flatlaf.extras;
import java.awt.AWTEvent; import java.awt.AWTEvent;
import java.awt.Color; import java.awt.Color;
@@ -28,15 +28,19 @@ import java.awt.Graphics2D;
import java.awt.Insets; import java.awt.Insets;
import java.awt.KeyboardFocusManager; import java.awt.KeyboardFocusManager;
import java.awt.LayoutManager; import java.awt.LayoutManager;
import java.awt.MouseInfo;
import java.awt.Point; import java.awt.Point;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.Toolkit; import java.awt.Toolkit;
import java.awt.Window; import java.awt.Window;
import java.awt.event.AWTEventListener;
import java.awt.event.InputEvent; import java.awt.event.InputEvent;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter; import java.awt.event.MouseMotionAdapter;
import java.awt.event.MouseMotionListener; import java.awt.event.MouseMotionListener;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import javax.swing.AbstractButton; import javax.swing.AbstractButton;
import javax.swing.JComponent; import javax.swing.JComponent;
@@ -57,6 +61,24 @@ import com.formdev.flatlaf.ui.FlatUIUtils;
import com.formdev.flatlaf.util.UIScale; import com.formdev.flatlaf.util.UIScale;
/** /**
* A simple UI inspector that shows information about UI component at mouse location
* in a tooltip.
* <p>
* To use it in an application install it with:
* <pre>
* FlatInspector.install( "ctrl shift alt X" );
* </pre>
* This can be done e.g. in the main() method and allows enabling (and disabling)
* the UI inspector for the active window with the given keystroke.
* <p>
* When the UI inspector is active some additional keys are available:
* <ul>
* <li>press <kbd>Esc</kbd> key to disable UI inspector</li>
* <li>press <kbd>Ctrl</kbd> key to increase inspection level, which shows
* information about parent of UI component at mouse location</li>
* <li>press <kbd>Shift</kbd> key to decrease inspection level</li>
* </ul>
*
* @author Karl Tauber * @author Karl Tauber
*/ */
public class FlatInspector public class FlatInspector
@@ -68,11 +90,15 @@ public class FlatInspector
private final JRootPane rootPane; private final JRootPane rootPane;
private final MouseMotionListener mouseMotionListener; private final MouseMotionListener mouseMotionListener;
private final AWTEventListener keyListener;
private final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport( this );
private boolean enabled;
private Component lastComponent; private Component lastComponent;
private int lastX; private int lastX;
private int lastY; private int lastY;
private int inspectParentLevel; private int inspectParentLevel;
private boolean wasCtrlOrShiftKeyPressed;
private JComponent highlightFigure; private JComponent highlightFigure;
private JToolTip tip; private JToolTip tip;
@@ -113,14 +139,46 @@ public class FlatInspector
public void mouseMoved( MouseEvent e ) { public void mouseMoved( MouseEvent e ) {
lastX = e.getX(); lastX = e.getX();
lastY = e.getY(); lastY = e.getY();
inspectParentLevel = (e.isControlDown() ? 1 : 0)
+ (e.isShiftDown() ? 2 : 0)
+ (e.isAltDown() ? 4 : 0);
inspect( lastX, lastY ); inspect( lastX, lastY );
} }
}; };
rootPane.getGlassPane().addMouseMotionListener( mouseMotionListener ); rootPane.getGlassPane().addMouseMotionListener( mouseMotionListener );
keyListener = e -> {
KeyEvent keyEvent = (KeyEvent) e;
int keyCode = keyEvent.getKeyCode();
int id = e.getID();
if( id == KeyEvent.KEY_PRESSED ) {
// this avoids that the inspection level is changed when UI inspector
// is enabled with keyboard shortcut (e.g. Ctrl+Shift+Alt+X)
if( keyCode == KeyEvent.VK_CONTROL || keyCode == KeyEvent.VK_SHIFT )
wasCtrlOrShiftKeyPressed = true;
} else if( id == KeyEvent.KEY_RELEASED && wasCtrlOrShiftKeyPressed ) {
if( keyCode == KeyEvent.VK_CONTROL ) {
inspectParentLevel++;
inspect( lastX, lastY );
} else if( keyCode == KeyEvent.VK_SHIFT && inspectParentLevel > 0 ) {
inspectParentLevel--;
inspect( lastX, lastY );
}
}
if( keyCode == KeyEvent.VK_ESCAPE ) {
// consume pressed and released ESC key events to e.g. avoid that dialog is closed
keyEvent.consume();
if( id == KeyEvent.KEY_PRESSED ) {
FlatInspector inspector = (FlatInspector) rootPane.getClientProperty( FlatInspector.class );
if( inspector == FlatInspector.this ) {
uninstall();
rootPane.putClientProperty( FlatInspector.class, null );
} else
setEnabled( false );
}
}
};
} }
private void uninstall() { private void uninstall() {
@@ -129,11 +187,43 @@ public class FlatInspector
rootPane.getGlassPane().removeMouseMotionListener( mouseMotionListener ); rootPane.getGlassPane().removeMouseMotionListener( mouseMotionListener );
} }
public void addPropertyChangeListener( PropertyChangeListener l ) {
propertyChangeSupport.addPropertyChangeListener( l );
}
public void removePropertyChangeListener( PropertyChangeListener l ) {
propertyChangeSupport.removePropertyChangeListener( l );
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled( boolean enabled ) { public void setEnabled( boolean enabled ) {
if( this.enabled == enabled )
return;
this.enabled = enabled;
rootPane.getGlassPane().setVisible( enabled ); rootPane.getGlassPane().setVisible( enabled );
if( !enabled ) { Toolkit toolkit = Toolkit.getDefaultToolkit();
if( enabled )
toolkit.addAWTEventListener( keyListener, AWTEvent.KEY_EVENT_MASK );
else
toolkit.removeAWTEventListener( keyListener );
if( enabled ) {
Point pt = new Point( MouseInfo.getPointerInfo().getLocation() );
SwingUtilities.convertPointFromScreen( pt, rootPane );
lastX = pt.x;
lastY = pt.y;
inspect( lastX, lastY );
} else {
lastComponent = null; lastComponent = null;
inspectParentLevel = 0;
if( highlightFigure != null ) if( highlightFigure != null )
highlightFigure.getParent().remove( highlightFigure ); highlightFigure.getParent().remove( highlightFigure );
@@ -143,6 +233,8 @@ public class FlatInspector
tip.getParent().remove( tip ); tip.getParent().remove( tip );
tip = null; tip = null;
} }
propertyChangeSupport.firePropertyChange( "enabled", !enabled, enabled );
} }
public void update() { public void update() {
@@ -157,11 +249,14 @@ public class FlatInspector
} }
private void inspect( int x, int y ) { private void inspect( int x, int y ) {
Container contentPane = rootPane.getContentPane(); Point pt = SwingUtilities.convertPoint( rootPane.getGlassPane(), x, y, rootPane );
Point pt = SwingUtilities.convertPoint( rootPane.getGlassPane(), x, y, contentPane ); Component c = getDeepestComponentAt( rootPane, pt.x, pt.y );
Component c = SwingUtilities.getDeepestComponentAt( contentPane, pt.x, pt.y );
for( int i = 0; i < inspectParentLevel && c != null; i++ ) { for( int i = 0; i < inspectParentLevel && c != null; i++ ) {
c = c.getParent(); Container parent = c.getParent();
if( parent == null )
break;
c = parent;
} }
if( c == lastComponent ) if( c == lastComponent )
@@ -173,6 +268,38 @@ public class FlatInspector
showToolTip( c, x, y ); showToolTip( c, x, y );
} }
private Component getDeepestComponentAt( Component parent, int x, int y ) {
if( !parent.contains( x, y ) )
return null;
if( parent instanceof Container ) {
for( Component child : ((Container)parent).getComponents() ) {
if( child == null || !child.isVisible() )
continue;
int cx = x - child.getX();
int cy = y - child.getY();
Component c = (child instanceof Container)
? getDeepestComponentAt( child, cx, cy )
: child.getComponentAt( cx, cy );
if( c == null || !c.isVisible() )
continue;
// ignore highlight figure and tooltip
if( c == highlightFigure || c == tip )
continue;
// ignore glass pane
if( c.getParent() instanceof JRootPane && c == ((JRootPane)c.getParent()).getGlassPane() )
continue;
return c;
}
}
return parent;
}
private void highlight( Component c ) { private void highlight( Component c ) {
if( highlightFigure == null ) { if( highlightFigure == null ) {
highlightFigure = createHighlightFigure(); highlightFigure = createHighlightFigure();
@@ -182,9 +309,9 @@ public class FlatInspector
highlightFigure.setVisible( c != null ); highlightFigure.setVisible( c != null );
if( c != null ) { if( c != null ) {
Rectangle bounds = c.getBounds(); highlightFigure.setBounds( new Rectangle(
Rectangle highlightBounds = SwingUtilities.convertRectangle( c.getParent(), bounds, rootPane ); SwingUtilities.convertPoint( c, 0, 0, rootPane ),
highlightFigure.setBounds( highlightBounds ); c.getSize() ) );
} }
} }
@@ -304,13 +431,20 @@ public class FlatInspector
text += "Enabled: " + c.isEnabled() + '\n'; text += "Enabled: " + c.isEnabled() + '\n';
text += "Opaque: " + c.isOpaque() + (c instanceof JComponent && text += "Opaque: " + c.isOpaque() + (c instanceof JComponent &&
FlatUIUtils.hasOpaqueBeenExplicitlySet( (JComponent) c ) ? " EXPLICIT" : "") + '\n'; FlatUIUtils.hasOpaqueBeenExplicitlySet( (JComponent) c ) ? " EXPLICIT" : "") + '\n';
if( c instanceof AbstractButton )
text += "ContentAreaFilled: " + ((AbstractButton)c).isContentAreaFilled() + '\n';
text += "Focusable: " + c.isFocusable() + '\n'; text += "Focusable: " + c.isFocusable() + '\n';
text += "Left-to-right: " + c.getComponentOrientation().isLeftToRight() + '\n'; text += "Left-to-right: " + c.getComponentOrientation().isLeftToRight() + '\n';
text += "Parent: " + c.getParent().getClass().getName(); text += "Parent: " + (c.getParent() != null ? c.getParent().getClass().getName() : "null");
if( inspectParentLevel > 0 ) if( inspectParentLevel > 0 )
text += "\n\nParent level: " + inspectParentLevel; text += "\n\nParent level: " + inspectParentLevel;
if( inspectParentLevel > 0 )
text += "\n(press Ctrl/Shift to increase/decrease level)";
else
text += "\n\n(press Ctrl key to inspect parent)";
return text; return text;
} }

View File

@@ -175,6 +175,7 @@ public class FlatSVGIcon
private static ColorFilter instance; private static ColorFilter instance;
private final Map<Integer, String> rgb2keyMap = new HashMap<>(); private final Map<Integer, String> rgb2keyMap = new HashMap<>();
private final Map<Color, Color> color2colorMap = new HashMap<>();
public static ColorFilter getInstance() { public static ColorFilter getInstance() {
if( instance == null ) if( instance == null )
@@ -187,12 +188,28 @@ public class FlatSVGIcon
rgb2keyMap.put( c.rgb, c.key ); rgb2keyMap.put( c.rgb, c.key );
} }
public void addAll( Map<Color, Color> from2toMap ) {
color2colorMap.putAll( from2toMap );
}
public void add( Color from, Color to ) {
color2colorMap.put( from, to );
}
public void remove( Color from ) {
color2colorMap.remove( from );
}
public Color filter( Color color ) { public Color filter( Color color ) {
Color newColor = color2colorMap.get( color );
if( newColor != null )
return newColor;
String colorKey = rgb2keyMap.get( color.getRGB() & 0xffffff ); String colorKey = rgb2keyMap.get( color.getRGB() & 0xffffff );
if( colorKey == null ) if( colorKey == null )
return color; return color;
Color newColor = UIManager.getColor( colorKey ); newColor = UIManager.getColor( colorKey );
if( newColor == null ) if( newColor == null )
return color; return color;

View File

@@ -16,17 +16,23 @@
package com.formdev.flatlaf.extras; package com.formdev.flatlaf.extras;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ItemEvent; import java.awt.event.ItemEvent;
import javax.swing.JCheckBox; import javax.swing.JCheckBox;
import javax.swing.LookAndFeel;
import javax.swing.UIManager;
import com.formdev.flatlaf.FlatLaf;
/** /**
* A tri-state check box. * A tri-state check box.
* * <p>
* To display the third state, this component requires an LaF that supports painting * To display the third state, this component requires an LaF that supports painting
* the indeterminate state if client property {@code "JButton.selectedState"} has the * the indeterminate state if client property {@code "JButton.selectedState"} has the
* value {@code "indeterminate"}. * value {@code "indeterminate"}.
* * <p>
* FlatLaf and Mac Aqua LaF support the third state. * FlatLaf and Mac Aqua LaF support the third state.
* For other LaFs a magenta rectangle is painted around the component for the third state.
* *
* @author Karl Tauber * @author Karl Tauber
*/ */
@@ -58,7 +64,7 @@ public class TriStateCheckBox
@Override @Override
public void setSelected( boolean b ) { public void setSelected( boolean b ) {
switch( state ) { switch( state ) {
case INDETERMINATE: setState( State.SELECTED ); break; case INDETERMINATE: setState( State.SELECTED ); break;
case SELECTED: setState( State.UNSELECTED ); break; case SELECTED: setState( State.UNSELECTED ); break;
case UNSELECTED: setState( thirdStateEnabled ? State.INDETERMINATE : State.SELECTED ); break; case UNSELECTED: setState( thirdStateEnabled ? State.INDETERMINATE : State.SELECTED ); break;
} }
@@ -104,4 +110,19 @@ public class TriStateCheckBox
public void setSelected( boolean b ) { public void setSelected( boolean b ) {
setState( b ? State.SELECTED : State.UNSELECTED ); setState( b ? State.SELECTED : State.UNSELECTED );
} }
@Override
protected void paintComponent( Graphics g ) {
super.paintComponent( g );
if( state == State.INDETERMINATE && !isThirdStateSupported() ) {
g.setColor( Color.magenta );
g.drawRect( 0, 0, getWidth() - 1, getHeight() - 1 );
}
}
private boolean isThirdStateSupported() {
LookAndFeel laf = UIManager.getLookAndFeel();
return laf instanceof FlatLaf || laf.getClass().getName().equals( "com.apple.laf.AquaLookAndFeel" );
}
} }

View File

@@ -0,0 +1,26 @@
/*
* Copyright 2020 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.
*/
/**
* @author Karl Tauber
*/
module com.formdev.flatlaf.extras {
requires java.desktop;
requires static com.kitfox.svg; // optional at runtime
requires com.formdev.flatlaf;
exports com.formdev.flatlaf.extras;
}

View File

@@ -16,154 +16,36 @@
plugins { plugins {
`java-library` `java-library`
`maven-publish` `flatlaf-module-info`
id( "com.jfrog.bintray" ) `flatlaf-publish`
id( "com.jfrog.artifactory" )
} }
dependencies { dependencies {
implementation( project( ":flatlaf-core" ) ) implementation( project( ":flatlaf-core" ) )
} }
if( JavaVersion.current() >= JavaVersion.VERSION_1_9 ) { flatlafModuleInfo {
sourceSets { dependsOn( ":flatlaf-core:jar" )
create( "module-info" ) { }
java {
// include "src/main/java" here to get compile errors if classes are java {
// used from other modules that are not specified in module dependencies withSourcesJar()
setSrcDirs( listOf( "src/main/module-info", "src/main/java" ) ) withJavadocJar()
}
}
}
} }
tasks { tasks {
assemble {
dependsOn(
"sourcesJar",
"javadocJar"
)
}
if( JavaVersion.current() >= JavaVersion.VERSION_1_9 ) {
named<JavaCompile>( "compileModuleInfoJava" ) {
sourceCompatibility = "9"
targetCompatibility = "9"
dependsOn( ":flatlaf-core:jar" )
options.compilerArgs.add( "--module-path" )
options.compilerArgs.add( project( ":flatlaf-core" ).tasks["jar"].outputs.files.asPath )
}
}
jar {
if( JavaVersion.current() >= JavaVersion.VERSION_1_9 ) {
from( sourceSets["module-info"].output ) {
include( "module-info.class" )
}
}
}
javadoc { javadoc {
options { options {
this as StandardJavadocDocletOptions this as StandardJavadocDocletOptions
use( true )
tags = listOf( "uiDefault", "clientProperty" ) tags = listOf( "uiDefault", "clientProperty" )
} }
isFailOnError = false isFailOnError = false
} }
register( "sourcesJar", Jar::class ) {
archiveClassifier.set( "sources" )
from( sourceSets.main.get().allJava )
}
register( "javadocJar", Jar::class ) {
archiveClassifier.set( "javadoc" )
from( javadoc )
}
} }
publishing { flatlafPublish {
publications { artifactId = "flatlaf-intellij-themes"
create<MavenPublication>( "maven" ) { name = "FlatLaf IntelliJ Themes Pack"
artifactId = "flatlaf-intellij-themes" description = "Flat Look and Feel IntelliJ Themes Pack"
groupId = "com.formdev"
from( components["java"] )
artifact( tasks["sourcesJar"] )
artifact( tasks["javadocJar"] )
pom {
name.set( "FlatLaf IntelliJ Themes Pack" )
description.set( "Flat Look and Feel IntelliJ Themes Pack" )
url.set( "https://github.com/JFormDesigner/FlatLaf" )
licenses {
license {
name.set( "The Apache License, Version 2.0" )
url.set( "https://www.apache.org/licenses/LICENSE-2.0.txt" )
}
}
developers {
developer {
name.set( "Karl Tauber" )
organization.set( "FormDev Software GmbH" )
organizationUrl.set( "https://www.formdev.com/" )
}
}
scm {
url.set( "https://github.com/JFormDesigner/FlatLaf" )
}
}
}
}
}
bintray {
user = rootProject.extra["bintray.user"] as String?
key = rootProject.extra["bintray.key"] as String?
setPublications( "maven" )
with( pkg ) {
repo = "flatlaf"
name = "flatlaf-intellij-themes"
setLicenses( "Apache-2.0" )
vcsUrl = "https://github.com/JFormDesigner/FlatLaf"
with( version ) {
name = project.version.toString()
}
publish = rootProject.extra["bintray.publish"] as Boolean
dryRun = rootProject.extra["bintray.dryRun"] as Boolean
}
}
artifactory {
setContextUrl( "https://oss.jfrog.org" )
publish( closureOf<org.jfrog.gradle.plugin.artifactory.dsl.PublisherConfig> {
repository( delegateClosureOf<groovy.lang.GroovyObject> {
setProperty( "repoKey", "oss-snapshot-local" )
setProperty( "username", rootProject.extra["bintray.user"] as String? )
setProperty( "password", rootProject.extra["bintray.key"] as String? )
} )
defaults( delegateClosureOf<groovy.lang.GroovyObject> {
invokeMethod( "publications", "maven" )
setProperty( "publishArtifacts", true )
setProperty( "publishPom", true )
} )
} )
resolve( delegateClosureOf<org.jfrog.gradle.plugin.artifactory.dsl.ResolverConfig> {
setProperty( "repoKey", "jcenter" )
} )
} }

View File

@@ -159,6 +159,13 @@
"inactiveBackground": "#44475a" "inactiveBackground": "#44475a"
} }
}, },
"ScrollBar": {
"Mac": {
"Transparent": {
"hoverThumbColor": "#bd93f9"
}
}
},
"SearchEverywhere": { "SearchEverywhere": {
"SearchField": { "SearchField": {
"background": "#44475a" "background": "#44475a"

View File

@@ -1,7 +1,7 @@
{ {
"name": "Gradianto Dark Fuchsia", "name": "Gradianto Dark Fuchsia",
"dark": true, "dark": true,
"author": "", "author": "thvardhan",
"editorScheme": "/Gradianto_dark_fuchsia.xml", "editorScheme": "/Gradianto_dark_fuchsia.xml",
"ui": { "ui": {
"*": { "*": {

View File

@@ -1,7 +1,7 @@
{ {
"name": "Gradianto Deep Ocean", "name": "Gradianto Deep Ocean",
"dark": true, "dark": true,
"author": "", "author": "thvardhan",
"editorScheme": "/Gradianto_deep_ocean.xml", "editorScheme": "/Gradianto_deep_ocean.xml",
"ui": { "ui": {
"*": { "*": {
@@ -214,7 +214,7 @@
"tagBackground": "#3d445a", "tagBackground": "#3d445a",
"lightSelectionBackground": "#3c4b7e" "lightSelectionBackground": "#3c4b7e"
}, },
"EditorPane.inactiveBackground": "#040c25" "EditorPane.inactiveBackground": "#25334aff"
}, },
"icons": { "icons": {
"ColorPalette": { "ColorPalette": {

View File

@@ -1,7 +1,7 @@
{ {
"name": "Gradianto Midnight Blue", "name": "Gradianto Midnight Blue",
"dark": true, "dark": true,
"author": "", "author": "thvardhan",
"editorScheme": "/Gradianto_midnight_blue.xml", "editorScheme": "/Gradianto_midnight_blue.xml",
"ui": { "ui": {
"*": { "*": {
@@ -217,7 +217,7 @@
"tagBackground": "#40405a", "tagBackground": "#40405a",
"lightSelectionBackground": "#48387e" "lightSelectionBackground": "#48387e"
}, },
"EditorPane.inactiveBackground": "#1a0225" "EditorPane.inactiveBackground": "#414157ff"
}, },
"icons": { "icons": {
"ColorPalette": { "ColorPalette": {

View File

@@ -5,6 +5,7 @@
"editorScheme": "/gruvbox_dark_hard.xml", "editorScheme": "/gruvbox_dark_hard.xml",
"colors": { "colors": {
"bg0": "#282828", "bg0": "#282828",
"bg0_hh": "#101415",
"bg0_h": "#1d2021", "bg0_h": "#1d2021",
"bg0_s": "#32302f", "bg0_s": "#32302f",
"bg1": "#3c3836", "bg1": "#3c3836",
@@ -51,7 +52,7 @@
"selectionBackgroundInactive": "bg0_s", "selectionBackgroundInactive": "bg0_s",
"selectionInactiveBackground": "bg0_s", "selectionInactiveBackground": "bg0_s",
"selectedBackground": "bg0_h", "selectedBackground": "bg0_hh",
"selectedForeground": "fg0", "selectedForeground": "fg0",
"selectedInactiveBackground": "bg0_s", "selectedInactiveBackground": "bg0_s",
"selectedBackgroundInactive": "bg0_s", "selectedBackgroundInactive": "bg0_s",
@@ -59,7 +60,7 @@
"hoverBackground": "#28282866", "hoverBackground": "#28282866",
"borderColor": "bg2", "borderColor": "bg2",
"disabledBorderColor": "bg0_h", "disabledBorderColor": "bg0_hh",
"separatorColor": "bg2" "separatorColor": "bg2"
}, },
@@ -91,6 +92,7 @@
}, },
"EditorTabs": { "EditorTabs": {
"selectedBackground": "bg0_s", "selectedBackground": "bg0_s",
"underlinedTabBackground": "bg2",
"underlineColor": "blue1", "underlineColor": "blue1",
"inactiveMaskColor": "#28282866" "inactiveMaskColor": "#28282866"
}, },
@@ -101,8 +103,8 @@
}, },
"HeaderTab": { "HeaderTab": {
"selectedInactiveBackground": "bg0_h", "selectedInactiveBackground": "bg0_hh",
"hoverInactiveBackground": "bg0_h" "hoverInactiveBackground": "bg0_hh"
} }
}, },
"Table": { "Table": {

View File

@@ -91,6 +91,7 @@
}, },
"EditorTabs": { "EditorTabs": {
"selectedBackground": "bg0_s", "selectedBackground": "bg0_s",
"underlinedTabBackground": "bg2",
"underlineColor": "blue1", "underlineColor": "blue1",
"inactiveMaskColor": "#28282866" "inactiveMaskColor": "#28282866"
}, },

View File

@@ -91,6 +91,7 @@
}, },
"EditorTabs": { "EditorTabs": {
"selectedBackground": "bg0_s", "selectedBackground": "bg0_s",
"underlinedTabBackground": "bg2",
"underlineColor": "blue1", "underlineColor": "blue1",
"inactiveMaskColor": "#28282866" "inactiveMaskColor": "#28282866"
}, },

View File

@@ -1,5 +1,5 @@
{ {
"name": "Atom One Light", "name": "Atom One Light Contrast",
"dark": false, "dark": false,
"author": "Mallowigi", "author": "Mallowigi",
"editorScheme": "/colors/Atom One Light.xml", "editorScheme": "/colors/Atom One Light.xml",

View File

@@ -24,7 +24,7 @@
"errorForeground": "#cd3359", "errorForeground": "#cd3359",
"borderColor": "#46494f", "borderColor": "#333841",
"disabledBorderColor": "#2d3137", "disabledBorderColor": "#2d3137",
"focusColor": "#21252b", "focusColor": "#21252b",
"focusedBorderColor": "#568AF2", "focusedBorderColor": "#568AF2",
@@ -93,8 +93,6 @@
"foreground": "#abb2bf" "foreground": "#abb2bf"
}, },
"DebuggerPopup.borderColor": "#46494f",
"DefaultTabs": { "DefaultTabs": {
"underlineColor": "#568AF2", "underlineColor": "#568AF2",
"inactiveUnderlineColor": "#4269b9", "inactiveUnderlineColor": "#4269b9",
@@ -104,7 +102,7 @@
"DragAndDrop": { "DragAndDrop": {
"areaForeground": "#abb2bf", "areaForeground": "#abb2bf",
"areaBackground": "#323844", "areaBackground": "#323844",
"areaBorderColor": "#46494f" "areaBorderColor": "#333841"
}, },
"Editor": { "Editor": {
@@ -139,11 +137,6 @@
"visitedForeground": "#6494ed" "visitedForeground": "#6494ed"
}, },
"MenuBar.borderColor": "#46494f",
"Menu.borderColor": "#2d3137",
"NavBar.borderColor": "#46494f",
"Notification": { "Notification": {
"background": "#3d424b", "background": "#3d424b",
"borderColor": "#53565f", "borderColor": "#53565f",
@@ -312,8 +305,7 @@
"Header": { "Header": {
"background": "#414855", "background": "#414855",
"inactiveBackground": "#323844", "inactiveBackground": "#323844"
"borderColor": "#21252b"
}, },
"HeaderTab": { "HeaderTab": {

View File

@@ -16,9 +16,7 @@
plugins { plugins {
`java-library` `java-library`
`maven-publish` `flatlaf-publish`
id( "com.jfrog.bintray" )
id( "com.jfrog.artifactory" )
} }
dependencies { dependencies {
@@ -26,113 +24,24 @@ dependencies {
implementation( "com.jidesoft:jide-oss:3.6.18" ) implementation( "com.jidesoft:jide-oss:3.6.18" )
} }
tasks { java {
assemble { withSourcesJar()
dependsOn( withJavadocJar()
"sourcesJar", }
"javadocJar"
)
}
tasks {
javadoc { javadoc {
options { options {
this as StandardJavadocDocletOptions this as StandardJavadocDocletOptions
use( true )
tags = listOf( "uiDefault", "clientProperty" ) tags = listOf( "uiDefault", "clientProperty" )
} }
isFailOnError = false isFailOnError = false
} }
register( "sourcesJar", Jar::class ) {
archiveClassifier.set( "sources" )
from( sourceSets.main.get().allJava )
}
register( "javadocJar", Jar::class ) {
archiveClassifier.set( "javadoc" )
from( javadoc )
}
} }
publishing { flatlafPublish {
publications { artifactId = "flatlaf-jide-oss"
create<MavenPublication>( "maven" ) { name = "FlatLaf addon for JIDE Common Layer"
artifactId = "flatlaf-jide-oss" description = "Flat Look and Feel addon for JIDE Common Layer"
groupId = "com.formdev"
from( components["java"] )
artifact( tasks["sourcesJar"] )
artifact( tasks["javadocJar"] )
pom {
name.set( "FlatLaf addon for JIDE Common Layer" )
description.set( "Flat Look and Feel addon for JIDE Common Layer" )
url.set( "https://github.com/JFormDesigner/FlatLaf" )
licenses {
license {
name.set( "The Apache License, Version 2.0" )
url.set( "https://www.apache.org/licenses/LICENSE-2.0.txt" )
}
}
developers {
developer {
name.set( "Karl Tauber" )
organization.set( "FormDev Software GmbH" )
organizationUrl.set( "https://www.formdev.com/" )
}
}
scm {
url.set( "https://github.com/JFormDesigner/FlatLaf" )
}
}
}
}
}
bintray {
user = rootProject.extra["bintray.user"] as String?
key = rootProject.extra["bintray.key"] as String?
setPublications( "maven" )
with( pkg ) {
repo = "flatlaf"
name = "flatlaf-jide-oss"
setLicenses( "Apache-2.0" )
vcsUrl = "https://github.com/JFormDesigner/FlatLaf"
with( version ) {
name = project.version.toString()
}
publish = rootProject.extra["bintray.publish"] as Boolean
dryRun = rootProject.extra["bintray.dryRun"] as Boolean
}
}
artifactory {
setContextUrl( "https://oss.jfrog.org" )
publish( closureOf<org.jfrog.gradle.plugin.artifactory.dsl.PublisherConfig> {
repository( delegateClosureOf<groovy.lang.GroovyObject> {
setProperty( "repoKey", "oss-snapshot-local" )
setProperty( "username", rootProject.extra["bintray.user"] as String? )
setProperty( "password", rootProject.extra["bintray.key"] as String? )
} )
defaults( delegateClosureOf<groovy.lang.GroovyObject> {
invokeMethod( "publications", "maven" )
setProperty( "publishArtifacts", true )
setProperty( "publishPom", true )
} )
} )
resolve( delegateClosureOf<org.jfrog.gradle.plugin.artifactory.dsl.ResolverConfig> {
setProperty( "repoKey", "jcenter" )
} )
} }

View File

@@ -16,9 +16,8 @@
plugins { plugins {
`java-library` `java-library`
`maven-publish` `flatlaf-module-info`
id( "com.jfrog.bintray" ) `flatlaf-publish`
id( "com.jfrog.artifactory" )
} }
dependencies { dependencies {
@@ -26,113 +25,28 @@ dependencies {
implementation( "org.swinglabs.swingx:swingx-all:1.6.5-1" ) implementation( "org.swinglabs.swingx:swingx-all:1.6.5-1" )
} }
tasks { flatlafModuleInfo {
assemble { dependsOn( ":flatlaf-core:jar" )
dependsOn( }
"sourcesJar",
"javadocJar"
)
}
java {
withSourcesJar()
withJavadocJar()
}
tasks {
javadoc { javadoc {
options { options {
this as StandardJavadocDocletOptions this as StandardJavadocDocletOptions
use( true )
tags = listOf( "uiDefault", "clientProperty" ) tags = listOf( "uiDefault", "clientProperty" )
} }
isFailOnError = false isFailOnError = false
} }
register( "sourcesJar", Jar::class ) {
archiveClassifier.set( "sources" )
from( sourceSets.main.get().allJava )
}
register( "javadocJar", Jar::class ) {
archiveClassifier.set( "javadoc" )
from( javadoc )
}
} }
publishing { flatlafPublish {
publications { artifactId = "flatlaf-swingx"
create<MavenPublication>( "maven" ) { name = "FlatLaf addon for SwingX"
artifactId = "flatlaf-swingx" description = "Flat Look and Feel addon for SwingX"
groupId = "com.formdev"
from( components["java"] )
artifact( tasks["sourcesJar"] )
artifact( tasks["javadocJar"] )
pom {
name.set( "FlatLaf addon for SwingX" )
description.set( "Flat Look and Feel addon for SwingX" )
url.set( "https://github.com/JFormDesigner/FlatLaf" )
licenses {
license {
name.set( "The Apache License, Version 2.0" )
url.set( "https://www.apache.org/licenses/LICENSE-2.0.txt" )
}
}
developers {
developer {
name.set( "Karl Tauber" )
organization.set( "FormDev Software GmbH" )
organizationUrl.set( "https://www.formdev.com/" )
}
}
scm {
url.set( "https://github.com/JFormDesigner/FlatLaf" )
}
}
}
}
}
bintray {
user = rootProject.extra["bintray.user"] as String?
key = rootProject.extra["bintray.key"] as String?
setPublications( "maven" )
with( pkg ) {
repo = "flatlaf"
name = "flatlaf-swingx"
setLicenses( "Apache-2.0" )
vcsUrl = "https://github.com/JFormDesigner/FlatLaf"
with( version ) {
name = project.version.toString()
}
publish = rootProject.extra["bintray.publish"] as Boolean
dryRun = rootProject.extra["bintray.dryRun"] as Boolean
}
}
artifactory {
setContextUrl( "https://oss.jfrog.org" )
publish( closureOf<org.jfrog.gradle.plugin.artifactory.dsl.PublisherConfig> {
repository( delegateClosureOf<groovy.lang.GroovyObject> {
setProperty( "repoKey", "oss-snapshot-local" )
setProperty( "username", rootProject.extra["bintray.user"] as String? )
setProperty( "password", rootProject.extra["bintray.key"] as String? )
} )
defaults( delegateClosureOf<groovy.lang.GroovyObject> {
invokeMethod( "publications", "maven" )
setProperty( "publishArtifacts", true )
setProperty( "publishPom", true )
} )
} )
resolve( delegateClosureOf<org.jfrog.gradle.plugin.artifactory.dsl.ResolverConfig> {
setProperty( "repoKey", "jcenter" )
} )
} }

View File

@@ -46,8 +46,6 @@ import org.jdesktop.swingx.JXPanel;
import org.jdesktop.swingx.calendar.DatePickerFormatter.DatePickerFormatterUIResource; import org.jdesktop.swingx.calendar.DatePickerFormatter.DatePickerFormatterUIResource;
import org.jdesktop.swingx.plaf.basic.BasicDatePickerUI; import org.jdesktop.swingx.plaf.basic.BasicDatePickerUI;
import com.formdev.flatlaf.ui.FlatArrowButton; import com.formdev.flatlaf.ui.FlatArrowButton;
import com.formdev.flatlaf.ui.FlatBorder;
import com.formdev.flatlaf.ui.FlatRoundBorder;
import com.formdev.flatlaf.ui.FlatUIUtils; import com.formdev.flatlaf.ui.FlatUIUtils;
import com.formdev.flatlaf.ui.MigLayoutVisualPadding; import com.formdev.flatlaf.ui.MigLayoutVisualPadding;
import com.formdev.flatlaf.util.UIScale; import com.formdev.flatlaf.util.UIScale;
@@ -62,8 +60,6 @@ public class FlatDatePickerUI
{ {
protected Insets padding; protected Insets padding;
protected int focusWidth;
protected int arc;
protected String arrowType; protected String arrowType;
protected Color borderColor; protected Color borderColor;
protected Color disabledBorderColor; protected Color disabledBorderColor;
@@ -88,8 +84,6 @@ public class FlatDatePickerUI
padding = UIManager.getInsets( "ComboBox.padding" ); padding = UIManager.getInsets( "ComboBox.padding" );
focusWidth = UIManager.getInt( "Component.focusWidth" );
arc = UIManager.getInt( "Component.arc" );
arrowType = UIManager.getString( "Component.arrowType" ); arrowType = UIManager.getString( "Component.arrowType" );
borderColor = UIManager.getColor( "Component.borderColor" ); borderColor = UIManager.getColor( "Component.borderColor" );
disabledBorderColor = UIManager.getColor( "Component.disabledBorderColor" ); disabledBorderColor = UIManager.getColor( "Component.disabledBorderColor" );
@@ -130,7 +124,7 @@ public class FlatDatePickerUI
LookAndFeel.installBorder( datePicker, "JXDatePicker.border" ); LookAndFeel.installBorder( datePicker, "JXDatePicker.border" );
LookAndFeel.installProperty( datePicker, "opaque", Boolean.TRUE ); LookAndFeel.installProperty( datePicker, "opaque", Boolean.TRUE );
MigLayoutVisualPadding.install( datePicker, focusWidth ); MigLayoutVisualPadding.install( datePicker );
} }
@Override @Override
@@ -228,8 +222,8 @@ public class FlatDatePickerUI
int width = c.getWidth(); int width = c.getWidth();
int height = c.getHeight(); int height = c.getHeight();
float focusWidth = (c.getBorder() instanceof FlatBorder) ? scale( (float) this.focusWidth ) : 0; float focusWidth = FlatUIUtils.getBorderFocusWidth( c );
float arc = (c.getBorder() instanceof FlatRoundBorder) ? scale( (float) this.arc ) : 0; float arc = FlatUIUtils.getBorderArc( c );
int arrowX = popupButton.getX(); int arrowX = popupButton.getX();
int arrowWidth = popupButton.getWidth(); int arrowWidth = popupButton.getWidth();
boolean enabled = c.isEnabled(); boolean enabled = c.isEnabled();

View File

@@ -0,0 +1,36 @@
/*
* Copyright 2020 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.
*/
/**
* @author Karl Tauber
*/
module com.formdev.flatlaf.swingx {
requires java.desktop;
requires swingx.all;
requires com.formdev.flatlaf;
exports com.formdev.flatlaf.swingx;
exports com.formdev.flatlaf.swingx.ui;
// this allows com.formdev.flatlaf.FlatDefaultsAddon to read .properties files
opens com.formdev.flatlaf.swingx
to com.formdev.flatlaf;
provides com.formdev.flatlaf.FlatDefaultsAddon
with com.formdev.flatlaf.swingx.FlatSwingXDefaultsAddon;
provides org.jdesktop.swingx.plaf.LookAndFeelAddons
with com.formdev.flatlaf.swingx.FlatLookAndFeelAddons;
}

View File

@@ -18,6 +18,13 @@ plugins {
`java-library` `java-library`
} }
repositories {
maven {
// for using MigLayout snapshot
url = uri( "https://oss.sonatype.org/content/repositories/snapshots/" )
}
}
dependencies { dependencies {
implementation( project( ":flatlaf-core" ) ) implementation( project( ":flatlaf-core" ) )
implementation( project( ":flatlaf-extras" ) ) implementation( project( ":flatlaf-extras" ) )
@@ -26,7 +33,7 @@ dependencies {
implementation( project( ":flatlaf-intellij-themes" ) ) implementation( project( ":flatlaf-intellij-themes" ) )
implementation( project( ":flatlaf-demo" ) ) implementation( project( ":flatlaf-demo" ) )
implementation( "com.miglayout:miglayout-swing:5.2" ) implementation( "com.miglayout:miglayout-swing:5.3-SNAPSHOT" )
implementation( "com.jgoodies:jgoodies-forms:1.9.0" ) implementation( "com.jgoodies:jgoodies-forms:1.9.0" )
implementation( "org.swinglabs.swingx:swingx-all:1.6.5-1" ) implementation( "org.swinglabs.swingx:swingx-all:1.6.5-1" )
implementation( "org.swinglabs.swingx:swingx-beaninfo:1.6.5-1" ) implementation( "org.swinglabs.swingx:swingx-beaninfo:1.6.5-1" )

View File

@@ -62,7 +62,7 @@ public class FlatChooserTest
"[]", "[]",
// rows // rows
"[top]" + "[top]" +
"[top]" + "[grow,top]" +
"[]")); "[]"));
//---- colorChooserLabel ---- //---- colorChooserLabel ----
@@ -73,7 +73,7 @@ public class FlatChooserTest
//---- fileChooserLabel ---- //---- fileChooserLabel ----
fileChooserLabel.setText("JFileChooser:"); fileChooserLabel.setText("JFileChooser:");
add(fileChooserLabel, "cell 0 1"); add(fileChooserLabel, "cell 0 1");
add(fileChooser1, "cell 1 1"); add(fileChooser1, "cell 1 1,growy");
//---- label1 ---- //---- label1 ----
label1.setText("icons:"); label1.setText("icons:");

View File

@@ -1,4 +1,4 @@
JFDML JFormDesigner: "7.0.0.0.194" Java: "11.0.2" encoding: "UTF-8" JFDML JFormDesigner: "7.0.1.0.272" Java: "13.0.2" encoding: "UTF-8"
new FormModel { new FormModel {
contentType: "form/swing" contentType: "form/swing"
@@ -9,7 +9,7 @@ new FormModel {
add( new FormContainer( "com.formdev.flatlaf.testing.FlatTestPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) { add( new FormContainer( "com.formdev.flatlaf.testing.FlatTestPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
"$layoutConstraints": "ltr,insets dialog,hidemode 3" "$layoutConstraints": "ltr,insets dialog,hidemode 3"
"$columnConstraints": "[][]" "$columnConstraints": "[][]"
"$rowConstraints": "[top][top][]" "$rowConstraints": "[top][grow,top][]"
} ) { } ) {
name: "this" name: "this"
add( new FormComponent( "javax.swing.JLabel" ) { add( new FormComponent( "javax.swing.JLabel" ) {
@@ -32,7 +32,7 @@ new FormModel {
add( new FormComponent( "javax.swing.JFileChooser" ) { add( new FormComponent( "javax.swing.JFileChooser" ) {
name: "fileChooser1" name: "fileChooser1"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 1" "value": "cell 1 1,growy"
} ) } )
add( new FormComponent( "javax.swing.JLabel" ) { add( new FormComponent( "javax.swing.JLabel" ) {
name: "label1" name: "label1"

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