mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-12 06:57:13 -06:00
Compare commits
39 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
873e8604ce | ||
|
|
2cfcd0facf | ||
|
|
b49eff348d | ||
|
|
42d801f123 | ||
|
|
5e33182de3 | ||
|
|
012d86066d | ||
|
|
ff510095a3 | ||
|
|
10283d022f | ||
|
|
d55abd1b00 | ||
|
|
87845fc6f5 | ||
|
|
340c0d647c | ||
|
|
49a574a8d7 | ||
|
|
9216997bba | ||
|
|
267567d0a0 | ||
|
|
230bc28ddd | ||
|
|
57c9ffc2ba | ||
|
|
d0ac7867ae | ||
|
|
b6cd31b734 | ||
|
|
8806cc8e93 | ||
|
|
2da0ca736f | ||
|
|
5288e0f54e | ||
|
|
c87f5cb05f | ||
|
|
17074eb16d | ||
|
|
43429ddc39 | ||
|
|
7ef598ded6 | ||
|
|
37c70f6c9e | ||
|
|
26a2446a4d | ||
|
|
771c949d74 | ||
|
|
23d448d4fc | ||
|
|
86577c5fef | ||
|
|
3a69b41646 | ||
|
|
2d26b6fa94 | ||
|
|
144f79f0f9 | ||
|
|
8ea23fc533 | ||
|
|
ae714502fb | ||
|
|
07d6755ddb | ||
|
|
177996ee81 | ||
|
|
3847b14033 | ||
|
|
423805be3a |
@@ -5,6 +5,7 @@ jdk:
|
|||||||
- openjdk8
|
- openjdk8
|
||||||
- openjdk9
|
- openjdk9
|
||||||
- openjdk11
|
- openjdk11
|
||||||
|
- openjdk13
|
||||||
|
|
||||||
before_cache:
|
before_cache:
|
||||||
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
|
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
|
||||||
@@ -24,5 +25,5 @@ deploy:
|
|||||||
skip_cleanup: true # to upload artifacts created during the build
|
skip_cleanup: true # to upload artifacts created during the build
|
||||||
on:
|
on:
|
||||||
branch: master
|
branch: master
|
||||||
jdk: openjdk8
|
jdk: openjdk11
|
||||||
tags: true
|
tags: true
|
||||||
|
|||||||
39
CHANGELOG.md
39
CHANGELOG.md
@@ -1,6 +1,45 @@
|
|||||||
FlatLaf Change Log
|
FlatLaf Change Log
|
||||||
==================
|
==================
|
||||||
|
|
||||||
|
## 0.13
|
||||||
|
|
||||||
|
- Added developer information to Maven POM for Maven Central publishing.
|
||||||
|
|
||||||
|
|
||||||
|
## 0.12
|
||||||
|
|
||||||
|
- Support Linux. (issue #2)
|
||||||
|
- Added `Flat*Laf.install()` methods.
|
||||||
|
- macOS: Use native screen menu bar if system property
|
||||||
|
`apple.laf.useScreenMenuBar` is `true`.
|
||||||
|
- Windows: Update fonts (and scaling) when user changes Windows text size
|
||||||
|
(Settings > Ease of Access > Display > Make text bigger).
|
||||||
|
|
||||||
|
|
||||||
|
## 0.11
|
||||||
|
|
||||||
|
- Changed Maven groupId to `com.formdev` and artifactId to `flatlaf`.
|
||||||
|
|
||||||
|
|
||||||
|
## 0.10
|
||||||
|
|
||||||
|
- Use new chevron arrows in "Flat Light" and "Flat Dark" themes, but keep
|
||||||
|
triangle arrows in "Flat IntelliJ" and "Flat Darcula" themes. (issue #7)
|
||||||
|
- Use bold font for default buttons in "Flat IntelliJ" and "Flat Darcula"
|
||||||
|
themes.
|
||||||
|
- Hide label, button and tab mnemonics by default and show them only when
|
||||||
|
<kbd>Alt</kbd> is pressed. (issue #4)
|
||||||
|
- If a JButton has an icon and no text, then it does not get a minimum width
|
||||||
|
(usually 72 pixel) and the left and right insets are same as top/bottom insets
|
||||||
|
so that it becomes square (if the icon is square).
|
||||||
|
- Changed styling of default button in "Flat Light" theme (wide blue border
|
||||||
|
instead of blue background).
|
||||||
|
- Added Java 9 module descriptor `module-info.class` to `flatlaf.jar` (in
|
||||||
|
`META-INF/versions/9`). But FlatLaf remains Java 8 compatible. (issue #1)
|
||||||
|
- Support specifying custom scale factor in system properties `flatlaf.uiScale`
|
||||||
|
or `sun.java2d.uiScale`. E.g. `-Dflatlaf.uiScale=1.5`. (Java 8 only)
|
||||||
|
|
||||||
|
|
||||||
## 0.9
|
## 0.9
|
||||||
|
|
||||||
- Initial release
|
- Initial release
|
||||||
|
|||||||
24
README.md
24
README.md
@@ -4,8 +4,9 @@ FlatLaf - Flat Look and Feel
|
|||||||
**FlatLaf** is a modern open-source cross-platform Look and Feel for Java
|
**FlatLaf** is a modern open-source cross-platform Look and Feel for Java
|
||||||
desktop applications.
|
desktop applications.
|
||||||
|
|
||||||
It is mostly "flat" (no shadows or gradients), clean, simple and elegant. It
|
It looks mostly "flat" (no shadows or gradients), clean, simple and elegant.
|
||||||
comes with **Light** and **Dark** themes and is made for **HiDPI** displays.
|
FlatLaf comes with **Light**, **Dark**, **IntelliJ** and **Darcula** themes,
|
||||||
|
scales on **HiDPI** displays and runs on Java 8 or newer.
|
||||||
|
|
||||||
The look is heavily inspired by **Darcula** and **IntelliJ** themes from
|
The look is heavily inspired by **Darcula** and **IntelliJ** themes from
|
||||||
IntelliJ IDEA 2019.2+ and uses mostly the same colors and icons.
|
IntelliJ IDEA 2019.2+ and uses mostly the same colors and icons.
|
||||||
@@ -18,19 +19,22 @@ IntelliJ IDEA 2019.2+ and uses mostly the same colors and icons.
|
|||||||
Demo
|
Demo
|
||||||
----
|
----
|
||||||
|
|
||||||
Download
|
[](https://download.formdev.com/flatlaf/flatlaf-demo-latest.jar)
|
||||||
[flatlaf-demo-0.1.jar](https://download.formdev.com/flatlaf/flatlaf-demo-0.1.jar)
|
|
||||||
and run it with `java -jar flatlaf-demo-0.1.jar` (or double-click it). Requires
|
Run demo with `java -jar flatlaf-demo-<version>.jar` (or double-click it).
|
||||||
Java 8 or newer.
|
Requires Java 8 or newer.
|
||||||
|
|
||||||
|
|
||||||
Download
|
Download
|
||||||
--------
|
--------
|
||||||
|
|
||||||
Coming soon
|
[](https://bintray.com/jformdesigner/flatlaf/flatlaf/_latestVersion)
|
||||||
|
|
||||||
|
Download from JCenter and Maven Central is coming soon.
|
||||||
|
|
||||||
|
|
||||||
License
|
Documentation
|
||||||
-------
|
-------------
|
||||||
|
|
||||||
FlatLaf is open source licensed under the [Apache 2.0 License](LICENSE)
|
For more information and documentation visit
|
||||||
|
[FlatLaf Home](https://www.formdev.com/flatlaf/)
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
version = "0.9"
|
version = "0.13"
|
||||||
|
|
||||||
// check required Java version
|
// check required Java version
|
||||||
if( JavaVersion.current() < JavaVersion.VERSION_1_8 )
|
if( JavaVersion.current() < JavaVersion.VERSION_1_8 )
|
||||||
|
|||||||
@@ -26,6 +26,18 @@ repositories {
|
|||||||
jcenter()
|
jcenter()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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" ) )
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
testImplementation( "com.miglayout:miglayout-swing:5.2" )
|
testImplementation( "com.miglayout:miglayout-swing:5.2" )
|
||||||
testImplementation( "com.jgoodies:jgoodies-forms:1.9.0" )
|
testImplementation( "com.jgoodies:jgoodies-forms:1.9.0" )
|
||||||
@@ -37,8 +49,26 @@ java {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tasks {
|
tasks {
|
||||||
|
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["module-info"].output )
|
||||||
|
include( "module-info.class" )
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
javadoc {
|
javadoc {
|
||||||
@@ -67,8 +97,8 @@ tasks {
|
|||||||
publishing {
|
publishing {
|
||||||
publications {
|
publications {
|
||||||
create<MavenPublication>( "maven" ) {
|
create<MavenPublication>( "maven" ) {
|
||||||
artifactId = "flatlaf-core"
|
artifactId = "flatlaf"
|
||||||
groupId = "com.formdev.flatlaf"
|
groupId = "com.formdev"
|
||||||
|
|
||||||
from( components["java"] )
|
from( components["java"] )
|
||||||
|
|
||||||
@@ -87,6 +117,14 @@ publishing {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
developers {
|
||||||
|
developer {
|
||||||
|
name.set( "Karl Tauber" )
|
||||||
|
organization.set( "FormDev Software GmbH" )
|
||||||
|
organizationUrl.set( "https://www.formdev.com/" )
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
scm {
|
scm {
|
||||||
url.set( "https://github.com/JFormDesigner/FlatLaf" )
|
url.set( "https://github.com/JFormDesigner/FlatLaf" )
|
||||||
}
|
}
|
||||||
@@ -103,7 +141,7 @@ bintray {
|
|||||||
|
|
||||||
with( pkg ) {
|
with( pkg ) {
|
||||||
repo = "flatlaf"
|
repo = "flatlaf"
|
||||||
name = "flatlaf-core"
|
name = "flatlaf"
|
||||||
setLicenses( "Apache-2.0" )
|
setLicenses( "Apache-2.0" )
|
||||||
vcsUrl = "https://github.com/JFormDesigner/FlatLaf"
|
vcsUrl = "https://github.com/JFormDesigner/FlatLaf"
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,10 @@ package com.formdev.flatlaf;
|
|||||||
public class FlatDarculaLaf
|
public class FlatDarculaLaf
|
||||||
extends FlatDarkLaf
|
extends FlatDarkLaf
|
||||||
{
|
{
|
||||||
|
public static boolean install( ) {
|
||||||
|
return install( new FlatDarculaLaf() );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "Flat Darcula";
|
return "Flat Darcula";
|
||||||
|
|||||||
@@ -24,6 +24,10 @@ package com.formdev.flatlaf;
|
|||||||
public class FlatDarkLaf
|
public class FlatDarkLaf
|
||||||
extends FlatLaf
|
extends FlatLaf
|
||||||
{
|
{
|
||||||
|
public static boolean install( ) {
|
||||||
|
return install( new FlatDarkLaf() );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "Flat Dark";
|
return "Flat Dark";
|
||||||
|
|||||||
@@ -24,6 +24,10 @@ package com.formdev.flatlaf;
|
|||||||
public class FlatIntelliJLaf
|
public class FlatIntelliJLaf
|
||||||
extends FlatLightLaf
|
extends FlatLightLaf
|
||||||
{
|
{
|
||||||
|
public static boolean install( ) {
|
||||||
|
return install( new FlatIntelliJLaf() );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "Flat IntelliJ";
|
return "Flat IntelliJ";
|
||||||
|
|||||||
@@ -16,11 +16,21 @@
|
|||||||
|
|
||||||
package com.formdev.flatlaf;
|
package com.formdev.flatlaf;
|
||||||
|
|
||||||
|
import java.awt.AWTEvent;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
import java.awt.Component;
|
||||||
|
import java.awt.Container;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
|
import java.awt.EventQueue;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
|
import java.awt.KeyboardFocusManager;
|
||||||
import java.awt.Toolkit;
|
import java.awt.Toolkit;
|
||||||
|
import java.awt.Window;
|
||||||
|
import java.awt.event.AWTEventListener;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
|
import java.beans.PropertyChangeEvent;
|
||||||
|
import java.beans.PropertyChangeListener;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -29,7 +39,14 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import javax.swing.AbstractButton;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JTabbedPane;
|
||||||
|
import javax.swing.LookAndFeel;
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
import javax.swing.UIDefaults;
|
import javax.swing.UIDefaults;
|
||||||
|
import javax.swing.UIManager;
|
||||||
|
import javax.swing.UnsupportedLookAndFeelException;
|
||||||
import javax.swing.UIDefaults.LazyValue;
|
import javax.swing.UIDefaults.LazyValue;
|
||||||
import javax.swing.plaf.ColorUIResource;
|
import javax.swing.plaf.ColorUIResource;
|
||||||
import javax.swing.plaf.DimensionUIResource;
|
import javax.swing.plaf.DimensionUIResource;
|
||||||
@@ -41,6 +58,7 @@ import com.formdev.flatlaf.ui.FlatEmptyBorder;
|
|||||||
import com.formdev.flatlaf.ui.FlatLineBorder;
|
import com.formdev.flatlaf.ui.FlatLineBorder;
|
||||||
import com.formdev.flatlaf.util.ScaledNumber;
|
import com.formdev.flatlaf.util.ScaledNumber;
|
||||||
import com.formdev.flatlaf.util.SystemInfo;
|
import com.formdev.flatlaf.util.SystemInfo;
|
||||||
|
import com.formdev.flatlaf.util.UIScale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base class for all Flat LaFs.
|
* The base class for all Flat LaFs.
|
||||||
@@ -57,6 +75,22 @@ public abstract class FlatLaf
|
|||||||
|
|
||||||
private BasicLookAndFeel base;
|
private BasicLookAndFeel base;
|
||||||
|
|
||||||
|
private String desktopPropertyName;
|
||||||
|
private PropertyChangeListener desktopPropertyListener;
|
||||||
|
|
||||||
|
private AWTEventListener mnemonicListener;
|
||||||
|
private static boolean altKeyPressed;
|
||||||
|
|
||||||
|
public static boolean install( LookAndFeel newLookAndFeel ) {
|
||||||
|
try {
|
||||||
|
UIManager.setLookAndFeel( newLookAndFeel );
|
||||||
|
return true;
|
||||||
|
} catch( Exception ex ) {
|
||||||
|
System.err.println( "Failed to initialize look and feel " + newLookAndFeel.getClass().getName() );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getID() {
|
public String getID() {
|
||||||
return getName();
|
return getName();
|
||||||
@@ -77,10 +111,48 @@ public abstract class FlatLaf
|
|||||||
getBase().initialize();
|
getBase().initialize();
|
||||||
|
|
||||||
super.initialize();
|
super.initialize();
|
||||||
|
|
||||||
|
// add mnemonic listener
|
||||||
|
mnemonicListener = e -> {
|
||||||
|
if( e instanceof KeyEvent && ((KeyEvent)e).getKeyCode() == KeyEvent.VK_ALT )
|
||||||
|
altKeyChanged( e.getID() == KeyEvent.KEY_PRESSED );
|
||||||
|
};
|
||||||
|
Toolkit.getDefaultToolkit().addAWTEventListener( mnemonicListener, AWTEvent.KEY_EVENT_MASK );
|
||||||
|
|
||||||
|
// listen to desktop property changes to update UI if system font or scaling changes
|
||||||
|
if( SystemInfo.IS_WINDOWS ) {
|
||||||
|
// Windows 10 allows increasing font size independent of scaling:
|
||||||
|
// Settings > Ease of Access > Display > Make text bigger (100% - 225%)
|
||||||
|
desktopPropertyName = "win.messagebox.font";
|
||||||
|
} else if( SystemInfo.IS_LINUX ) {
|
||||||
|
// Linux/Gnome allows extra scaling and larger text:
|
||||||
|
// Settings > Devices > Displays > Scale (100% or 200%)
|
||||||
|
// Settings > Universal access > Large Text (off or on, 125%)
|
||||||
|
desktopPropertyName = "gnome.Xft/DPI";
|
||||||
|
}
|
||||||
|
if( desktopPropertyName != null ) {
|
||||||
|
desktopPropertyListener = e -> {
|
||||||
|
reSetLookAndFeel();
|
||||||
|
};
|
||||||
|
Toolkit.getDefaultToolkit().addPropertyChangeListener( desktopPropertyName, desktopPropertyListener );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void uninitialize() {
|
public void uninitialize() {
|
||||||
|
// remove desktop property listener
|
||||||
|
if( desktopPropertyListener != null ) {
|
||||||
|
Toolkit.getDefaultToolkit().removePropertyChangeListener( desktopPropertyName, desktopPropertyListener );
|
||||||
|
desktopPropertyName = null;
|
||||||
|
desktopPropertyListener = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove mnemonic listener
|
||||||
|
if( mnemonicListener != null ) {
|
||||||
|
Toolkit.getDefaultToolkit().removeAWTEventListener( mnemonicListener );
|
||||||
|
mnemonicListener = null;
|
||||||
|
}
|
||||||
|
|
||||||
if( base != null )
|
if( base != null )
|
||||||
base.uninitialize();
|
base.uninitialize();
|
||||||
|
|
||||||
@@ -128,9 +200,17 @@ public abstract class FlatLaf
|
|||||||
defaults.put( "Spinner.disabledBackground", control );
|
defaults.put( "Spinner.disabledBackground", control );
|
||||||
defaults.put( "Spinner.disabledForeground", control );
|
defaults.put( "Spinner.disabledForeground", control );
|
||||||
|
|
||||||
|
// remember MenuBarUI from Mac Aqua LaF if Mac screen menubar is enabled
|
||||||
|
boolean useScreenMenuBar = SystemInfo.IS_MAC && "true".equals( System.getProperty( "apple.laf.useScreenMenuBar" ) );
|
||||||
|
Object aquaMenuBarUI = useScreenMenuBar ? defaults.get( "MenuBarUI" ) : null;
|
||||||
|
|
||||||
initFonts( defaults );
|
initFonts( defaults );
|
||||||
loadDefaultsFromProperties( defaults );
|
loadDefaultsFromProperties( defaults );
|
||||||
|
|
||||||
|
// use Aqua MenuBarUI if Mac screen menubar is enabled
|
||||||
|
if( useScreenMenuBar )
|
||||||
|
defaults.put( "MenuBarUI", aquaMenuBarUI );
|
||||||
|
|
||||||
return defaults;
|
return defaults;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,12 +233,15 @@ public abstract class FlatLaf
|
|||||||
uiFont = (font instanceof FontUIResource) ? (FontUIResource) font : new FontUIResource( font );
|
uiFont = (font instanceof FontUIResource) ? (FontUIResource) font : new FontUIResource( font );
|
||||||
|
|
||||||
} else if( SystemInfo.IS_LINUX ) {
|
} else if( SystemInfo.IS_LINUX ) {
|
||||||
System.err.println( "WARNING: FlatLaf is not yet tested on Linux!" );
|
Font font = LinuxFontPolicy.getFont();
|
||||||
|
uiFont = (font instanceof FontUIResource) ? (FontUIResource) font : new FontUIResource( font );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( uiFont == null )
|
if( uiFont == null )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
uiFont = UIScale.applyCustomScaleFactor( uiFont );
|
||||||
|
|
||||||
// override fonts
|
// override fonts
|
||||||
for( Object key : defaults.keySet() ) {
|
for( Object key : defaults.keySet() ) {
|
||||||
if( key instanceof String && ((String)key).endsWith( ".font" ) )
|
if( key instanceof String && ((String)key).endsWith( ".font" ) )
|
||||||
@@ -285,15 +368,15 @@ public abstract class FlatLaf
|
|||||||
key.endsWith( "Margins" ) || key.endsWith( "Insets" ) )
|
key.endsWith( "Margins" ) || key.endsWith( "Insets" ) )
|
||||||
return parseInsets( value );
|
return parseInsets( value );
|
||||||
|
|
||||||
// size
|
|
||||||
if( key.endsWith( "Size" ) && !key.equals( "SplitPane.dividerSize" ))
|
|
||||||
return parseSize( value );
|
|
||||||
|
|
||||||
// scaled number
|
// scaled number
|
||||||
ScaledNumber scaledNumber = parseScaledNumber( key, value );
|
ScaledNumber scaledNumber = parseScaledNumber( key, value );
|
||||||
if( scaledNumber != null )
|
if( scaledNumber != null )
|
||||||
return scaledNumber;
|
return scaledNumber;
|
||||||
|
|
||||||
|
// size
|
||||||
|
if( key.endsWith( "Size" ) && !key.equals( "SplitPane.dividerSize" ))
|
||||||
|
return parseSize( value );
|
||||||
|
|
||||||
// width, height
|
// width, height
|
||||||
if( key.endsWith( "Width" ) || key.endsWith( "Height" ) )
|
if( key.endsWith( "Width" ) || key.endsWith( "Height" ) )
|
||||||
return parseInteger( value, true );
|
return parseInteger( value, true );
|
||||||
@@ -400,7 +483,9 @@ public abstract class FlatLaf
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ScaledNumber parseScaledNumber( String key, String value ) {
|
private ScaledNumber parseScaledNumber( String key, String value ) {
|
||||||
if( !key.equals( "OptionPane.buttonMinimumWidth" ) )
|
if( !key.equals( "OptionPane.buttonMinimumWidth" ) &&
|
||||||
|
!key.equals( "SplitPane.oneTouchButtonSize" ) &&
|
||||||
|
!key.equals( "SplitPane.oneTouchButtonOffset" ) )
|
||||||
return null; // not supported
|
return null; // not supported
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -424,4 +509,90 @@ public abstract class FlatLaf
|
|||||||
|
|
||||||
return strs;
|
return strs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void reSetLookAndFeel() {
|
||||||
|
EventQueue.invokeLater( () -> {
|
||||||
|
try {
|
||||||
|
// re-set current LaF
|
||||||
|
LookAndFeel lookAndFeel = UIManager.getLookAndFeel();
|
||||||
|
UIManager.setLookAndFeel( lookAndFeel );
|
||||||
|
|
||||||
|
// must fire property change events ourself because old and new LaF are the same
|
||||||
|
PropertyChangeEvent e = new PropertyChangeEvent( UIManager.class, "lookAndFeel", lookAndFeel, lookAndFeel );
|
||||||
|
for( PropertyChangeListener l : UIManager.getPropertyChangeListeners() )
|
||||||
|
l.propertyChange( e );
|
||||||
|
|
||||||
|
// update UI
|
||||||
|
updateUI();
|
||||||
|
} catch( UnsupportedLookAndFeelException ex ) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update UI of all application windows.
|
||||||
|
* Invoke after changing LaF.
|
||||||
|
*/
|
||||||
|
public static void updateUI() {
|
||||||
|
for( Window w : Window.getWindows() )
|
||||||
|
SwingUtilities.updateComponentTreeUI( w );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isShowMnemonics() {
|
||||||
|
return altKeyPressed || !UIManager.getBoolean( "Component.hideMnemonics" );
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void altKeyChanged( boolean pressed ) {
|
||||||
|
if( pressed == altKeyPressed )
|
||||||
|
return;
|
||||||
|
|
||||||
|
altKeyPressed = pressed;
|
||||||
|
|
||||||
|
// check whether it is necessary to repaint
|
||||||
|
if( !UIManager.getBoolean( "Component.hideMnemonics" ) )
|
||||||
|
return;
|
||||||
|
|
||||||
|
// get focus owner
|
||||||
|
Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
|
||||||
|
if( focusOwner == null )
|
||||||
|
return;
|
||||||
|
|
||||||
|
// get focused window
|
||||||
|
Window window = SwingUtilities.windowForComponent( focusOwner );
|
||||||
|
if( window == null )
|
||||||
|
return;
|
||||||
|
|
||||||
|
// repaint components with mnemonics in focused window
|
||||||
|
repaintMnemonics( window );
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void repaintMnemonics( Container container ) {
|
||||||
|
for( Component c : container.getComponents() ) {
|
||||||
|
if( hasMnemonic( c ) )
|
||||||
|
c.repaint();
|
||||||
|
|
||||||
|
if( c instanceof Container )
|
||||||
|
repaintMnemonics( (Container) c );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean hasMnemonic( Component c ) {
|
||||||
|
if( c instanceof JLabel && ((JLabel)c).getDisplayedMnemonicIndex() >= 0 )
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if( c instanceof AbstractButton && ((AbstractButton)c).getDisplayedMnemonicIndex() >= 0 )
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if( c instanceof JTabbedPane ) {
|
||||||
|
JTabbedPane tabPane = (JTabbedPane) c;
|
||||||
|
int tabCount = tabPane.getTabCount();
|
||||||
|
for( int i = 0; i < tabCount; i++ ) {
|
||||||
|
if( tabPane.getDisplayedMnemonicIndexAt( i ) >= 0 )
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,10 @@ package com.formdev.flatlaf;
|
|||||||
public class FlatLightLaf
|
public class FlatLightLaf
|
||||||
extends FlatLaf
|
extends FlatLaf
|
||||||
{
|
{
|
||||||
|
public static boolean install( ) {
|
||||||
|
return install( new FlatLightLaf() );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "Flat Light";
|
return "Flat Light";
|
||||||
|
|||||||
@@ -0,0 +1,248 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019 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
|
||||||
|
*
|
||||||
|
* http://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;
|
||||||
|
|
||||||
|
import java.awt.Font;
|
||||||
|
import java.awt.GraphicsEnvironment;
|
||||||
|
import java.awt.Toolkit;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.StringTokenizer;
|
||||||
|
import javax.swing.text.StyleContext;
|
||||||
|
import com.formdev.flatlaf.util.SystemInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Karl Tauber
|
||||||
|
*/
|
||||||
|
class LinuxFontPolicy
|
||||||
|
{
|
||||||
|
static Font getFont() {
|
||||||
|
return SystemInfo.IS_KDE ? getKDEFont() : getGnomeFont();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the default font for Gnome.
|
||||||
|
*/
|
||||||
|
private static Font getGnomeFont() {
|
||||||
|
// see class com.sun.java.swing.plaf.gtk.PangoFonts background information
|
||||||
|
|
||||||
|
Object fontName = Toolkit.getDefaultToolkit().getDesktopProperty( "gnome.Gtk/FontName" );
|
||||||
|
if( !(fontName instanceof String) )
|
||||||
|
fontName = "sans 10";
|
||||||
|
|
||||||
|
String family = "";
|
||||||
|
int style = Font.PLAIN;
|
||||||
|
int size = 10;
|
||||||
|
|
||||||
|
StringTokenizer st = new StringTokenizer( (String) fontName );
|
||||||
|
while( st.hasMoreTokens() ) {
|
||||||
|
String word = st.nextToken();
|
||||||
|
|
||||||
|
if( word.equalsIgnoreCase( "italic" ) )
|
||||||
|
style |= Font.ITALIC;
|
||||||
|
else if( word.equalsIgnoreCase( "bold" ) )
|
||||||
|
style |= Font.BOLD;
|
||||||
|
else if( Character.isDigit( word.charAt( 0 ) ) ) {
|
||||||
|
try {
|
||||||
|
size = Integer.parseInt( word );
|
||||||
|
} catch( NumberFormatException ex ) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
family = family.isEmpty() ? word : (family + ' ' + word);
|
||||||
|
}
|
||||||
|
|
||||||
|
// scale font size
|
||||||
|
double dsize = size * getGnomeFontScale();
|
||||||
|
size = (int) (dsize + 0.5);
|
||||||
|
if( size < 1 )
|
||||||
|
size = 1;
|
||||||
|
|
||||||
|
// handle logical font names
|
||||||
|
String logicalFamily = mapFcName( family.toLowerCase() );
|
||||||
|
if( logicalFamily != null )
|
||||||
|
family = logicalFamily;
|
||||||
|
|
||||||
|
return createFont( family, style, size, dsize );
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Font createFont( String family, int style, int size, double dsize ) {
|
||||||
|
// using StyleContext.getFont() here because it uses
|
||||||
|
// sun.font.FontUtilities.getCompositeFontUIResource()
|
||||||
|
Font font = new StyleContext().getFont( family, style, size );
|
||||||
|
|
||||||
|
// set font size in floating points
|
||||||
|
font = font.deriveFont( style, (float) dsize );
|
||||||
|
|
||||||
|
return font;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double getGnomeFontScale() {
|
||||||
|
// see class com.sun.java.swing.plaf.gtk.PangoFonts background information
|
||||||
|
|
||||||
|
Object value = Toolkit.getDefaultToolkit().getDesktopProperty( "gnome.Xft/DPI" );
|
||||||
|
if( value instanceof Integer ) {
|
||||||
|
int dpi = ((Integer)value).intValue() / 1024;
|
||||||
|
if( dpi == -1 )
|
||||||
|
dpi = 96;
|
||||||
|
if( dpi < 50 )
|
||||||
|
dpi = 50;
|
||||||
|
return dpi / 72.0;
|
||||||
|
} else {
|
||||||
|
return GraphicsEnvironment.getLocalGraphicsEnvironment()
|
||||||
|
.getDefaultScreenDevice().getDefaultConfiguration()
|
||||||
|
.getNormalizingTransform().getScaleY();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* map GTK/fontconfig names to equivalent JDK logical font name
|
||||||
|
*/
|
||||||
|
private static String mapFcName( String name ) {
|
||||||
|
switch( name ) {
|
||||||
|
case "sans": return "sansserif";
|
||||||
|
case "sans-serif": return "sansserif";
|
||||||
|
case "serif": return "serif";
|
||||||
|
case "monospace": return "monospaced";
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the default font for KDE for KDE configuration files.
|
||||||
|
*
|
||||||
|
* The Swing fonts are not updated when the user changes system font size
|
||||||
|
* (System Settings > Fonts > Force Font DPI). A application restart is necessary.
|
||||||
|
* This is the same behavior as in native KDE applications.
|
||||||
|
*
|
||||||
|
* The "display scale factor" (kdeglobals: [KScreen] > ScaleFactor) is not used
|
||||||
|
* KDE also does not use it to calculate font size. Only forceFontDPI is used by KDE.
|
||||||
|
* If user changes "display scale factor" (System Settings > Display and Monitors >
|
||||||
|
* Displays > Scale Display), the forceFontDPI is also changed to reflect the scale factor.
|
||||||
|
*/
|
||||||
|
private static Font getKDEFont() {
|
||||||
|
List<String> kdeglobals = readConfig( "kdeglobals" );
|
||||||
|
List<String> kcmfonts = readConfig( "kcmfonts" );
|
||||||
|
|
||||||
|
String generalFont = getConfigEntry( kdeglobals, "General", "font" );
|
||||||
|
String forceFontDPI = getConfigEntry( kcmfonts, "General", "forceFontDPI" );
|
||||||
|
|
||||||
|
String family = "sansserif";
|
||||||
|
int style = Font.PLAIN;
|
||||||
|
int size = 10;
|
||||||
|
|
||||||
|
if( generalFont != null ) {
|
||||||
|
List<String> strs = FlatLaf.split( generalFont, ',' );
|
||||||
|
try {
|
||||||
|
family = strs.get( 0 );
|
||||||
|
size = Integer.parseInt( strs.get( 1 ) );
|
||||||
|
if( "75".equals( strs.get( 4 ) ) )
|
||||||
|
style |= Font.BOLD;
|
||||||
|
if( "1".equals( strs.get( 5 ) ) )
|
||||||
|
style |= Font.ITALIC;
|
||||||
|
} catch( RuntimeException ex ) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// font dpi
|
||||||
|
int dpi = 96;
|
||||||
|
if( forceFontDPI != null ) {
|
||||||
|
try {
|
||||||
|
dpi = Integer.parseInt( forceFontDPI );
|
||||||
|
if( dpi <= 0 )
|
||||||
|
dpi = 96;
|
||||||
|
if( dpi < 50 )
|
||||||
|
dpi = 50;
|
||||||
|
} catch( NumberFormatException ex ) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// scale font size
|
||||||
|
double fontScale = dpi / 72.0;
|
||||||
|
double dsize = size * fontScale;
|
||||||
|
size = (int) (dsize + 0.5);
|
||||||
|
if( size < 1 )
|
||||||
|
size = 1;
|
||||||
|
|
||||||
|
return createFont( family, style, size, dsize );
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<String> readConfig( String filename ) {
|
||||||
|
File userHome = new File( System.getProperty( "user.home" ) );
|
||||||
|
|
||||||
|
// search for config file
|
||||||
|
String[] configDirs = {
|
||||||
|
".config", // KDE 5
|
||||||
|
".kde4/share/config", // KDE 4
|
||||||
|
".kde/share/config"// KDE 3
|
||||||
|
};
|
||||||
|
File file = null;
|
||||||
|
for( String configDir : configDirs ) {
|
||||||
|
file = new File( userHome, configDir + "/" + filename );
|
||||||
|
if( file.isFile() )
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if( !file.isFile() )
|
||||||
|
return Collections.emptyList();
|
||||||
|
|
||||||
|
// read config file
|
||||||
|
ArrayList<String> lines = new ArrayList<>( 200 );
|
||||||
|
try( BufferedReader reader = new BufferedReader( new FileReader( file ) ) ) {
|
||||||
|
String line = null;
|
||||||
|
while( (line = reader.readLine()) != null )
|
||||||
|
lines.add( line );
|
||||||
|
} catch( IOException ex ) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
return lines;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getConfigEntry( List<String> config, String group, String key ) {
|
||||||
|
int groupLength = group.length();
|
||||||
|
int keyLength = key.length();
|
||||||
|
boolean inGroup = false;
|
||||||
|
for( String line : config ) {
|
||||||
|
if( !inGroup ) {
|
||||||
|
if( line.length() >= groupLength + 2 &&
|
||||||
|
line.charAt( 0 ) == '[' &&
|
||||||
|
line.charAt( groupLength + 1 ) == ']' &&
|
||||||
|
line.indexOf( group ) == 1 )
|
||||||
|
{
|
||||||
|
inGroup = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if( line.startsWith( "[" ) )
|
||||||
|
return null;
|
||||||
|
|
||||||
|
if( line.length() >= keyLength + 2 &&
|
||||||
|
line.charAt( keyLength ) == '=' &&
|
||||||
|
line.startsWith( key ) )
|
||||||
|
{
|
||||||
|
return line.substring( keyLength + 1 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,9 +16,11 @@
|
|||||||
|
|
||||||
package com.formdev.flatlaf.icons;
|
package com.formdev.flatlaf.icons;
|
||||||
|
|
||||||
|
import java.awt.BasicStroke;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.geom.Path2D;
|
||||||
import javax.swing.JMenu;
|
import javax.swing.JMenu;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import com.formdev.flatlaf.ui.FlatUIUtils;
|
import com.formdev.flatlaf.ui.FlatUIUtils;
|
||||||
@@ -26,6 +28,7 @@ import com.formdev.flatlaf.ui.FlatUIUtils;
|
|||||||
/**
|
/**
|
||||||
* "arrow" icon for {@link javax.swing.JMenu}.
|
* "arrow" icon for {@link javax.swing.JMenu}.
|
||||||
*
|
*
|
||||||
|
* @uiDefault Component.arrowType String triangle (default) or chevron
|
||||||
* @uiDefault Menu.icon.arrowColor Color
|
* @uiDefault Menu.icon.arrowColor Color
|
||||||
* @uiDefault Menu.icon.disabledArrowColor Color
|
* @uiDefault Menu.icon.disabledArrowColor Color
|
||||||
* @uiDefault Menu.selectionForeground Color
|
* @uiDefault Menu.selectionForeground Color
|
||||||
@@ -35,12 +38,13 @@ import com.formdev.flatlaf.ui.FlatUIUtils;
|
|||||||
public class FlatMenuArrowIcon
|
public class FlatMenuArrowIcon
|
||||||
extends FlatAbstractIcon
|
extends FlatAbstractIcon
|
||||||
{
|
{
|
||||||
|
protected final boolean chevron = "chevron".equals( UIManager.getString( "Component.arrowType" ) );
|
||||||
protected final Color arrowColor = UIManager.getColor( "Menu.icon.arrowColor" );
|
protected final Color arrowColor = UIManager.getColor( "Menu.icon.arrowColor" );
|
||||||
protected final Color disabledArrowColor = UIManager.getColor( "Menu.icon.disabledArrowColor" );
|
protected final Color disabledArrowColor = UIManager.getColor( "Menu.icon.disabledArrowColor" );
|
||||||
protected final Color selectionForeground = UIManager.getColor( "Menu.selectionForeground" );
|
protected final Color selectionForeground = UIManager.getColor( "Menu.selectionForeground" );
|
||||||
|
|
||||||
public FlatMenuArrowIcon() {
|
public FlatMenuArrowIcon() {
|
||||||
super( 5, 10, null );
|
super( 6, 10, null );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -49,8 +53,16 @@ public class FlatMenuArrowIcon
|
|||||||
g.rotate( Math.toRadians( 180 ), width / 2., height / 2. );
|
g.rotate( Math.toRadians( 180 ), width / 2., height / 2. );
|
||||||
|
|
||||||
g.setColor( getArrowColor( c ) );
|
g.setColor( getArrowColor( c ) );
|
||||||
|
if( chevron ) {
|
||||||
|
// chevron arrow
|
||||||
|
Path2D path = FlatUIUtils.createPath( false, 1,1, 5,5, 1,9 );
|
||||||
|
g.setStroke( new BasicStroke( 1f ) );
|
||||||
|
g.draw( path );
|
||||||
|
} else {
|
||||||
|
// triangle arrow
|
||||||
g.fill( FlatUIUtils.createPath( 0,0.5, 0,9.5, 5,5 ) );
|
g.fill( FlatUIUtils.createPath( 0,0.5, 0,9.5, 5,5 ) );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Color getArrowColor( Component c ) {
|
private Color getArrowColor( Component c ) {
|
||||||
if( c instanceof JMenu && ((JMenu)c).isSelected() )
|
if( c instanceof JMenu && ((JMenu)c).isSelected() )
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.formdev.flatlaf.icons;
|
package com.formdev.flatlaf.icons;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
@@ -24,6 +25,7 @@ import com.formdev.flatlaf.ui.FlatUIUtils;
|
|||||||
/**
|
/**
|
||||||
* "collapsed" icon for {@link javax.swing.JTree}.
|
* "collapsed" icon for {@link javax.swing.JTree}.
|
||||||
*
|
*
|
||||||
|
* @uiDefault Component.arrowType String triangle (default) or chevron
|
||||||
* @uiDefault Tree.icon.collapsedColor Color
|
* @uiDefault Tree.icon.collapsedColor Color
|
||||||
*
|
*
|
||||||
* @author Karl Tauber
|
* @author Karl Tauber
|
||||||
@@ -31,15 +33,32 @@ import com.formdev.flatlaf.ui.FlatUIUtils;
|
|||||||
public class FlatTreeCollapsedIcon
|
public class FlatTreeCollapsedIcon
|
||||||
extends FlatAbstractIcon
|
extends FlatAbstractIcon
|
||||||
{
|
{
|
||||||
|
private final boolean chevron;
|
||||||
|
|
||||||
public FlatTreeCollapsedIcon() {
|
public FlatTreeCollapsedIcon() {
|
||||||
super( 11, 11, UIManager.getColor( "Tree.icon.collapsedColor" ) );
|
this( UIManager.getColor( "Tree.icon.collapsedColor" ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
FlatTreeCollapsedIcon( Color color ) {
|
||||||
|
super( 11, 11, color );
|
||||||
|
chevron = "chevron".equals( UIManager.getString( "Component.arrowType" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paintIcon( Component c, Graphics2D g ) {
|
protected void paintIcon( Component c, Graphics2D g ) {
|
||||||
if( !c.getComponentOrientation().isLeftToRight() )
|
rotate( c, g );
|
||||||
g.rotate( Math.toRadians( 180 ), width / 2., height / 2. );
|
|
||||||
|
|
||||||
|
if( chevron ) {
|
||||||
|
// chevron arrow
|
||||||
|
g.fill( FlatUIUtils.createPath( 3,1, 3,2.5, 6,5.5, 3,8.5, 3,10, 4.5,10, 9,5.5, 4.5,1 ) );
|
||||||
|
} else {
|
||||||
|
// triangle arrow
|
||||||
g.fill( FlatUIUtils.createPath( 2,1, 2,10, 10,5.5 ) );
|
g.fill( FlatUIUtils.createPath( 2,1, 2,10, 10,5.5 ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void rotate( Component c, Graphics2D g ) {
|
||||||
|
if( !c.getComponentOrientation().isLeftToRight() )
|
||||||
|
g.rotate( Math.toRadians( 180 ), width / 2., height / 2. );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ package com.formdev.flatlaf.icons;
|
|||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import com.formdev.flatlaf.ui.FlatUIUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* "expanded" icon for {@link javax.swing.JTree}.
|
* "expanded" icon for {@link javax.swing.JTree}.
|
||||||
@@ -29,14 +28,14 @@ import com.formdev.flatlaf.ui.FlatUIUtils;
|
|||||||
* @author Karl Tauber
|
* @author Karl Tauber
|
||||||
*/
|
*/
|
||||||
public class FlatTreeExpandedIcon
|
public class FlatTreeExpandedIcon
|
||||||
extends FlatAbstractIcon
|
extends FlatTreeCollapsedIcon
|
||||||
{
|
{
|
||||||
public FlatTreeExpandedIcon() {
|
public FlatTreeExpandedIcon() {
|
||||||
super( 11, 11, UIManager.getColor( "Tree.icon.expandedColor" ) );
|
super( UIManager.getColor( "Tree.icon.expandedColor" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paintIcon( Component c, Graphics2D g ) {
|
void rotate( Component c, Graphics2D g ) {
|
||||||
g.fill( FlatUIUtils.createPath( 1,2, 10,2, 5.5,10 ) );
|
g.rotate( Math.toRadians( 90 ), width / 2., height / 2. );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package com.formdev.flatlaf.ui;
|
package com.formdev.flatlaf.ui;
|
||||||
|
|
||||||
import static com.formdev.flatlaf.util.UIScale.scale;
|
import static com.formdev.flatlaf.util.UIScale.scale;
|
||||||
|
import java.awt.BasicStroke;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
@@ -37,6 +38,7 @@ public class FlatArrowButton
|
|||||||
extends BasicArrowButton
|
extends BasicArrowButton
|
||||||
implements UIResource
|
implements UIResource
|
||||||
{
|
{
|
||||||
|
private final boolean chevron;
|
||||||
private final Color foreground;
|
private final Color foreground;
|
||||||
private final Color disabledForeground;
|
private final Color disabledForeground;
|
||||||
private final Color hoverForeground;
|
private final Color hoverForeground;
|
||||||
@@ -47,11 +49,12 @@ public class FlatArrowButton
|
|||||||
|
|
||||||
private boolean hover;
|
private boolean hover;
|
||||||
|
|
||||||
public FlatArrowButton( int direction, Color foreground, Color disabledForeground,
|
public FlatArrowButton( int direction, String type, Color foreground, Color disabledForeground,
|
||||||
Color hoverForeground, Color hoverBackground )
|
Color hoverForeground, Color hoverBackground )
|
||||||
{
|
{
|
||||||
super( direction, Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE );
|
super( direction, Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE );
|
||||||
|
|
||||||
|
this.chevron = "chevron".equals( type );
|
||||||
this.foreground = foreground;
|
this.foreground = foreground;
|
||||||
this.disabledForeground = disabledForeground;
|
this.disabledForeground = disabledForeground;
|
||||||
this.hoverForeground = hoverForeground;
|
this.hoverForeground = hoverForeground;
|
||||||
@@ -77,6 +80,10 @@ public class FlatArrowButton
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean isHover() {
|
||||||
|
return hover;
|
||||||
|
}
|
||||||
|
|
||||||
public int getXOffset() {
|
public int getXOffset() {
|
||||||
return xOffset;
|
return xOffset;
|
||||||
}
|
}
|
||||||
@@ -113,7 +120,7 @@ public class FlatArrowButton
|
|||||||
boolean enabled = isEnabled();
|
boolean enabled = isEnabled();
|
||||||
|
|
||||||
// paint hover background
|
// paint hover background
|
||||||
if( enabled && hover && hoverBackground != null ) {
|
if( enabled && isHover() && hoverBackground != null ) {
|
||||||
g.setColor( hoverBackground );
|
g.setColor( hoverBackground );
|
||||||
g.fillRect( 0, 0, width, height );
|
g.fillRect( 0, 0, width, height );
|
||||||
}
|
}
|
||||||
@@ -121,26 +128,41 @@ public class FlatArrowButton
|
|||||||
int direction = getDirection();
|
int direction = getDirection();
|
||||||
boolean vert = (direction == NORTH || direction == SOUTH);
|
boolean vert = (direction == NORTH || direction == SOUTH);
|
||||||
|
|
||||||
int w = scale( 9 );
|
int w = scale( chevron ? 8 : 9 );
|
||||||
int h = scale( 5 );
|
int h = scale( chevron ? 4 : 5 );
|
||||||
int x = Math.round( (width - (vert ? w : h)) / 2f + scale( (float) xOffset ) );
|
int rw = vert ? w : h;
|
||||||
int y = Math.round( (height - (vert ? h : w)) / 2f + scale( (float) yOffset ) );
|
int rh = vert ? h : w;
|
||||||
|
int x = Math.round( (width - rw) / 2f + scale( (float) xOffset ) );
|
||||||
|
int y = Math.round( (height - rh) / 2f + scale( (float) yOffset ) );
|
||||||
|
|
||||||
|
// optimization for small chevron arrows (e.g. OneTouchButtons in SplitPane)
|
||||||
|
if( x + rw >= width && x > 0 )
|
||||||
|
x--;
|
||||||
|
if( y + rh >= height && y > 0 )
|
||||||
|
y--;
|
||||||
|
|
||||||
// paint arrow
|
// paint arrow
|
||||||
g.setColor( enabled
|
g.setColor( enabled
|
||||||
? (hover && hoverForeground != null ? hoverForeground : foreground)
|
? (isHover() && hoverForeground != null ? hoverForeground : foreground)
|
||||||
: disabledForeground );
|
: disabledForeground );
|
||||||
g.translate( x, y );
|
g.translate( x, y );
|
||||||
g2.fill( createArrowShape( direction, w, h ) );
|
Shape arrowShape = createArrowShape( direction, chevron, w, h );
|
||||||
|
if( chevron ) {
|
||||||
|
g2.setStroke( new BasicStroke( scale( 1f ) ) );
|
||||||
|
g2.draw( arrowShape );
|
||||||
|
} else {
|
||||||
|
// triangle
|
||||||
|
g2.fill( arrowShape );
|
||||||
|
}
|
||||||
g.translate( -x, -y );
|
g.translate( -x, -y );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Shape createArrowShape( int direction, int w, int h ) {
|
public static Shape createArrowShape( int direction, boolean chevron, int w, int h ) {
|
||||||
switch( direction ) {
|
switch( direction ) {
|
||||||
case NORTH: return FlatUIUtils.createPath( 0,h, w,h, (w / 2f),0 );
|
case NORTH: return FlatUIUtils.createPath( !chevron, 0,h, (w / 2f),0, w,h );
|
||||||
case SOUTH: return FlatUIUtils.createPath( 0,0, w,0, (w / 2f),h );
|
case SOUTH: return FlatUIUtils.createPath( !chevron, 0,0, (w / 2f),h, w,0 );
|
||||||
case WEST: return FlatUIUtils.createPath( h,0, h,w, 0,(w / 2f) );
|
case WEST: return FlatUIUtils.createPath( !chevron, h,0, 0,(w / 2f), h,w );
|
||||||
case EAST: return FlatUIUtils.createPath( 0,0, 0,w, h,(w / 2f) );
|
case EAST: return FlatUIUtils.createPath( !chevron, 0,0, h,(w / 2f), 0,w );
|
||||||
default: return new Path2D.Float();
|
default: return new Path2D.Float();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ import javax.swing.text.JTextComponent;
|
|||||||
* {@link FlatUIUtils#paintParentBackground} to paint the empty space correctly.
|
* {@link FlatUIUtils#paintParentBackground} to paint the empty space correctly.
|
||||||
*
|
*
|
||||||
* @uiDefault Component.focusWidth int
|
* @uiDefault Component.focusWidth int
|
||||||
|
* @uiDefault Component.innerFocusWidth int
|
||||||
* @uiDefault Component.focusColor Color
|
* @uiDefault Component.focusColor Color
|
||||||
* @uiDefault Component.borderColor Color
|
* @uiDefault Component.borderColor Color
|
||||||
* @uiDefault Component.disabledBorderColor Color
|
* @uiDefault Component.disabledBorderColor Color
|
||||||
@@ -59,6 +60,7 @@ public class FlatBorder
|
|||||||
extends BasicBorders.MarginBorder
|
extends BasicBorders.MarginBorder
|
||||||
{
|
{
|
||||||
protected final int focusWidth = UIManager.getInt( "Component.focusWidth" );
|
protected final int focusWidth = UIManager.getInt( "Component.focusWidth" );
|
||||||
|
protected final int innerFocusWidth = UIManager.getInt( "Component.innerFocusWidth" );
|
||||||
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" );
|
||||||
@@ -71,16 +73,17 @@ public class FlatBorder
|
|||||||
FlatUIUtils.setRenderingHints( g2 );
|
FlatUIUtils.setRenderingHints( g2 );
|
||||||
|
|
||||||
float focusWidth = getFocusWidth();
|
float focusWidth = getFocusWidth();
|
||||||
float lineWidth = getLineWidth();
|
float borderWidth = getBorderWidth( c );
|
||||||
float arc = getArc();
|
float arc = getArc();
|
||||||
|
|
||||||
if( isFocused( c ) ) {
|
if( isFocused( c ) ) {
|
||||||
g2.setColor( getFocusColor( c ) );
|
g2.setColor( getFocusColor( c ) );
|
||||||
FlatUIUtils.paintOutlineBorder( g2, x, y, width, height, focusWidth, lineWidth, arc );
|
FlatUIUtils.paintOutlineBorder( g2, x, y, width, height, focusWidth,
|
||||||
|
getLineWidth() + scale( (float) innerFocusWidth ), arc );
|
||||||
}
|
}
|
||||||
|
|
||||||
g2.setPaint( getBorderColor( c ) );
|
g2.setPaint( getBorderColor( c ) );
|
||||||
FlatUIUtils.drawRoundRectangle( g2, x, y, width, height, focusWidth, lineWidth, arc );
|
FlatUIUtils.drawRoundRectangle( g2, x, y, width, height, focusWidth, borderWidth, arc );
|
||||||
} finally {
|
} finally {
|
||||||
g2.dispose();
|
g2.dispose();
|
||||||
}
|
}
|
||||||
@@ -149,6 +152,10 @@ public class FlatBorder
|
|||||||
return scale( 1f );
|
return scale( 1f );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected float getBorderWidth( Component c ) {
|
||||||
|
return getLineWidth();
|
||||||
|
}
|
||||||
|
|
||||||
protected float getArc() {
|
protected float getArc() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,8 +20,11 @@ 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.Graphics;
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Insets;
|
||||||
import java.awt.Paint;
|
import java.awt.Paint;
|
||||||
|
import javax.swing.JButton;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
|
import javax.swing.plaf.UIResource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Border for {@link javax.swing.JButton}.
|
* Border for {@link javax.swing.JButton}.
|
||||||
@@ -34,6 +37,7 @@ import javax.swing.UIManager;
|
|||||||
* @uiDefault Button.default.hoverBorderColor Color optional
|
* @uiDefault Button.default.hoverBorderColor Color optional
|
||||||
* @uiDefault Button.default.focusedBorderColor Color
|
* @uiDefault Button.default.focusedBorderColor Color
|
||||||
* @uiDefault Button.default.focusColor Color
|
* @uiDefault Button.default.focusColor Color
|
||||||
|
* @uiDefault Button.default.borderWidth int
|
||||||
* @uiDefault Button.arc int
|
* @uiDefault Button.arc int
|
||||||
*
|
*
|
||||||
* @author Karl Tauber
|
* @author Karl Tauber
|
||||||
@@ -49,6 +53,7 @@ public class FlatButtonBorder
|
|||||||
protected final Color defaultHoverBorderColor = UIManager.getColor( "Button.default.hoverBorderColor" );
|
protected final Color defaultHoverBorderColor = UIManager.getColor( "Button.default.hoverBorderColor" );
|
||||||
protected final Color defaultFocusedBorderColor = UIManager.getColor( "Button.default.focusedBorderColor" );
|
protected final Color defaultFocusedBorderColor = UIManager.getColor( "Button.default.focusedBorderColor" );
|
||||||
protected final Color defaultFocusColor = UIManager.getColor( "Button.default.focusColor" );
|
protected final Color defaultFocusColor = UIManager.getColor( "Button.default.focusColor" );
|
||||||
|
protected final int defaultBorderWidth = UIManager.getInt( "Button.default.borderWidth" );
|
||||||
protected final int arc = UIManager.getInt( "Button.arc" );
|
protected final int arc = UIManager.getInt( "Button.arc" );
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -73,6 +78,22 @@ public class FlatButtonBorder
|
|||||||
null );
|
null );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Insets getBorderInsets( Component c, Insets insets ) {
|
||||||
|
insets = super.getBorderInsets( c, insets );
|
||||||
|
|
||||||
|
// use smaller left and right insets for icon-only buttons (so that they are square)
|
||||||
|
if( FlatButtonUI.isIconOnlyButton( c ) && ((JButton)c).getMargin() instanceof UIResource )
|
||||||
|
insets.left = insets.right = Math.min( insets.top, insets.bottom );
|
||||||
|
|
||||||
|
return insets;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected float getBorderWidth( Component c ) {
|
||||||
|
return FlatButtonUI.isDefaultButton( c ) ? scale( (float) defaultBorderWidth ) : super.getBorderWidth( c );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected float getArc() {
|
protected float getArc() {
|
||||||
return scale( (float) arc );
|
return scale( (float) arc );
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ 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.Dimension;
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Font;
|
||||||
import java.awt.FontMetrics;
|
import java.awt.FontMetrics;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
@@ -35,7 +36,9 @@ import javax.swing.LookAndFeel;
|
|||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.border.Border;
|
import javax.swing.border.Border;
|
||||||
import javax.swing.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
|
import javax.swing.plaf.UIResource;
|
||||||
import javax.swing.plaf.basic.BasicButtonUI;
|
import javax.swing.plaf.basic.BasicButtonUI;
|
||||||
|
import com.formdev.flatlaf.FlatLaf;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides the Flat LaF UI delegate for {@link javax.swing.JButton}.
|
* Provides the Flat LaF UI delegate for {@link javax.swing.JButton}.
|
||||||
@@ -55,6 +58,7 @@ import javax.swing.plaf.basic.BasicButtonUI;
|
|||||||
* @uiDefault Button.default.focusedBackground Color optional
|
* @uiDefault Button.default.focusedBackground Color optional
|
||||||
* @uiDefault Button.default.hoverBackground Color optional
|
* @uiDefault Button.default.hoverBackground Color optional
|
||||||
* @uiDefault Button.default.pressedBackground Color optional
|
* @uiDefault Button.default.pressedBackground Color optional
|
||||||
|
* @uiDefault Button.default.boldText boolean
|
||||||
* @uiDefault Button.toolbar.hoverBackground Color
|
* @uiDefault Button.toolbar.hoverBackground Color
|
||||||
* @uiDefault Button.toolbar.pressedBackground Color
|
* @uiDefault Button.toolbar.pressedBackground Color
|
||||||
*
|
*
|
||||||
@@ -78,6 +82,7 @@ public class FlatButtonUI
|
|||||||
protected Color defaultFocusedBackground;
|
protected Color defaultFocusedBackground;
|
||||||
protected Color defaultHoverBackground;
|
protected Color defaultHoverBackground;
|
||||||
protected Color defaultPressedBackground;
|
protected Color defaultPressedBackground;
|
||||||
|
protected boolean defaultBoldText;
|
||||||
|
|
||||||
protected Color toolbarHoverBackground;
|
protected Color toolbarHoverBackground;
|
||||||
protected Color toolbarPressedBackground;
|
protected Color toolbarPressedBackground;
|
||||||
@@ -116,6 +121,7 @@ public class FlatButtonUI
|
|||||||
defaultFocusedBackground = UIManager.getColor( "Button.default.focusedBackground" );
|
defaultFocusedBackground = UIManager.getColor( "Button.default.focusedBackground" );
|
||||||
defaultHoverBackground = UIManager.getColor( "Button.default.hoverBackground" );
|
defaultHoverBackground = UIManager.getColor( "Button.default.hoverBackground" );
|
||||||
defaultPressedBackground = UIManager.getColor( "Button.default.pressedBackground" );
|
defaultPressedBackground = UIManager.getColor( "Button.default.pressedBackground" );
|
||||||
|
defaultBoldText = UIManager.getBoolean( "Button.default.boldText" );
|
||||||
|
|
||||||
toolbarHoverBackground = UIManager.getColor( prefix + "toolbar.hoverBackground" );
|
toolbarHoverBackground = UIManager.getColor( prefix + "toolbar.hoverBackground" );
|
||||||
toolbarPressedBackground = UIManager.getColor( prefix + "toolbar.pressedBackground" );
|
toolbarPressedBackground = UIManager.getColor( prefix + "toolbar.pressedBackground" );
|
||||||
@@ -146,6 +152,13 @@ public class FlatButtonUI
|
|||||||
return c instanceof JButton && ((JButton)c).isDefaultButton();
|
return c instanceof JButton && ((JButton)c).isDefaultButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static boolean isIconOnlyButton( Component c ) {
|
||||||
|
String text;
|
||||||
|
return c instanceof JButton &&
|
||||||
|
((JButton)c).getIcon() != null &&
|
||||||
|
((text = ((JButton)c).getText()) == null || text.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
static boolean isHelpButton( Component c ) {
|
static boolean isHelpButton( Component c ) {
|
||||||
return c instanceof JButton && clientPropertyEquals( (JButton) c, BUTTON_TYPE, BUTTON_TYPE_HELP );
|
return c instanceof JButton && clientPropertyEquals( (JButton) c, BUTTON_TYPE, BUTTON_TYPE_HELP );
|
||||||
}
|
}
|
||||||
@@ -191,12 +204,23 @@ public class FlatButtonUI
|
|||||||
if( isHelpButton( b ) )
|
if( isHelpButton( b ) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if( defaultBoldText && isDefaultButton( b ) && b.getFont() instanceof UIResource ) {
|
||||||
|
Font boldFont = g.getFont().deriveFont( Font.BOLD );
|
||||||
|
g.setFont( boldFont );
|
||||||
|
|
||||||
|
int boldWidth = b.getFontMetrics( boldFont ).stringWidth( text );
|
||||||
|
if( boldWidth > textRect.width ) {
|
||||||
|
textRect.x -= (boldWidth - textRect.width) / 2;
|
||||||
|
textRect.width = boldWidth;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
paintText( g, b, textRect, text, b.isEnabled() ? getForeground( b ) : disabledText );
|
paintText( g, b, textRect, text, b.isEnabled() ? getForeground( b ) : disabledText );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void paintText( Graphics g, AbstractButton b, Rectangle textRect, String text, Color foreground ) {
|
static void paintText( Graphics g, AbstractButton b, Rectangle textRect, String text, Color foreground ) {
|
||||||
FontMetrics fm = b.getFontMetrics( b.getFont() );
|
FontMetrics fm = b.getFontMetrics( b.getFont() );
|
||||||
int mnemonicIndex = b.getDisplayedMnemonicIndex();
|
int mnemonicIndex = FlatLaf.isShowMnemonics() ? b.getDisplayedMnemonicIndex() : -1;
|
||||||
|
|
||||||
g.setColor( foreground );
|
g.setColor( foreground );
|
||||||
FlatUIUtils.drawStringUnderlineCharAt( b, g, text, mnemonicIndex,
|
FlatUIUtils.drawStringUnderlineCharAt( b, g, text, mnemonicIndex,
|
||||||
@@ -259,8 +283,11 @@ 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( !isToolBarButton( c ) )
|
|
||||||
|
// apply minimum width, if not in toolbar and not a icon-only button
|
||||||
|
if( !isToolBarButton( c ) && !isIconOnlyButton( c ) )
|
||||||
prefSize.width = Math.max( prefSize.width, scale( minimumWidth + (focusWidth * 2) ) );
|
prefSize.width = Math.max( prefSize.width, scale( minimumWidth + (focusWidth * 2) ) );
|
||||||
|
|
||||||
return prefSize;
|
return prefSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import java.awt.Rectangle;
|
|||||||
import java.awt.Shape;
|
import java.awt.Shape;
|
||||||
import java.awt.event.FocusEvent;
|
import java.awt.event.FocusEvent;
|
||||||
import java.awt.event.FocusListener;
|
import java.awt.event.FocusListener;
|
||||||
|
import java.awt.event.MouseListener;
|
||||||
import java.awt.geom.Rectangle2D;
|
import java.awt.geom.Rectangle2D;
|
||||||
import java.beans.PropertyChangeEvent;
|
import java.beans.PropertyChangeEvent;
|
||||||
import java.beans.PropertyChangeListener;
|
import java.beans.PropertyChangeListener;
|
||||||
@@ -57,6 +58,7 @@ import com.formdev.flatlaf.util.UIScale;
|
|||||||
*
|
*
|
||||||
* @uiDefault Component.focusWidth int
|
* @uiDefault Component.focusWidth int
|
||||||
* @uiDefault Component.arc int
|
* @uiDefault Component.arc int
|
||||||
|
* @uiDefault Component.arrowType String triangle (default) or chevron
|
||||||
* @uiDefault Component.borderColor Color
|
* @uiDefault Component.borderColor Color
|
||||||
* @uiDefault Component.disabledBorderColor Color
|
* @uiDefault Component.disabledBorderColor Color
|
||||||
* @uiDefault ComboBox.disabledBackground Color
|
* @uiDefault ComboBox.disabledBackground Color
|
||||||
@@ -74,6 +76,7 @@ public class FlatComboBoxUI
|
|||||||
{
|
{
|
||||||
protected int focusWidth;
|
protected int focusWidth;
|
||||||
protected int arc;
|
protected int arc;
|
||||||
|
protected String arrowType;
|
||||||
protected Color borderColor;
|
protected Color borderColor;
|
||||||
protected Color disabledBorderColor;
|
protected Color disabledBorderColor;
|
||||||
|
|
||||||
@@ -86,16 +89,42 @@ public class FlatComboBoxUI
|
|||||||
protected Color buttonDisabledArrowColor;
|
protected Color buttonDisabledArrowColor;
|
||||||
protected Color buttonHoverArrowColor;
|
protected Color buttonHoverArrowColor;
|
||||||
|
|
||||||
|
private MouseListener hoverListener;
|
||||||
|
private boolean hover;
|
||||||
|
|
||||||
public static ComponentUI createUI( JComponent c ) {
|
public static ComponentUI createUI( JComponent c ) {
|
||||||
return new FlatComboBoxUI();
|
return new FlatComboBoxUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void installListeners() {
|
||||||
|
super.installListeners();
|
||||||
|
|
||||||
|
hoverListener = new FlatUIUtils.HoverListener( null, h -> {
|
||||||
|
if( !comboBox.isEditable() ) {
|
||||||
|
hover = h;
|
||||||
|
if( arrowButton != null )
|
||||||
|
arrowButton.repaint();
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
comboBox.addMouseListener( hoverListener );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void uninstallListeners() {
|
||||||
|
super.uninstallListeners();
|
||||||
|
|
||||||
|
comboBox.removeMouseListener( hoverListener );
|
||||||
|
hoverListener = null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void installDefaults() {
|
protected void installDefaults() {
|
||||||
super.installDefaults();
|
super.installDefaults();
|
||||||
|
|
||||||
focusWidth = UIManager.getInt( "Component.focusWidth" );
|
focusWidth = UIManager.getInt( "Component.focusWidth" );
|
||||||
arc = UIManager.getInt( "Component.arc" );
|
arc = UIManager.getInt( "Component.arc" );
|
||||||
|
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" );
|
||||||
|
|
||||||
@@ -224,8 +253,14 @@ public class FlatComboBoxUI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected JButton createArrowButton() {
|
protected JButton createArrowButton() {
|
||||||
return new FlatArrowButton( SwingConstants.SOUTH, buttonArrowColor,
|
return new FlatArrowButton( SwingConstants.SOUTH, arrowType, buttonArrowColor,
|
||||||
buttonDisabledArrowColor, buttonHoverArrowColor, null );
|
buttonDisabledArrowColor, buttonHoverArrowColor, null )
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
protected boolean isHover() {
|
||||||
|
return super.isHover() || (!comboBox.isEditable() ? hover : false);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import javax.swing.SwingUtilities;
|
|||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
import javax.swing.plaf.basic.BasicLabelUI;
|
import javax.swing.plaf.basic.BasicLabelUI;
|
||||||
|
import com.formdev.flatlaf.FlatLaf;
|
||||||
import com.formdev.flatlaf.util.UIScale;
|
import com.formdev.flatlaf.util.UIScale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -71,9 +72,16 @@ public class FlatLabelUI
|
|||||||
defaults_initialized = false;
|
defaults_initialized = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void paintEnabledText( JLabel l, Graphics g, String s, int textX, int textY ) {
|
||||||
|
int mnemIndex = FlatLaf.isShowMnemonics() ? l.getDisplayedMnemonicIndex() : -1;
|
||||||
|
g.setColor( l.getForeground() );
|
||||||
|
FlatUIUtils.drawStringUnderlineCharAt( l, g, s, mnemIndex, textX, textY );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paintDisabledText( JLabel l, Graphics g, String s, int textX, int textY ) {
|
protected void paintDisabledText( JLabel l, Graphics g, String s, int textX, int textY ) {
|
||||||
int mnemIndex = l.getDisplayedMnemonicIndex();
|
int mnemIndex = FlatLaf.isShowMnemonics() ? l.getDisplayedMnemonicIndex() : -1;
|
||||||
g.setColor( disabledForeground );
|
g.setColor( disabledForeground );
|
||||||
FlatUIUtils.drawStringUnderlineCharAt( l, g, s, mnemIndex, textX, textY );
|
FlatUIUtils.drawStringUnderlineCharAt( l, g, s, mnemIndex, textX, textY );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ import javax.swing.plaf.basic.BasicSpinnerUI;
|
|||||||
* @uiDefault Component.focusWidth int
|
* @uiDefault Component.focusWidth int
|
||||||
* @uiDefault Component.arc int
|
* @uiDefault Component.arc int
|
||||||
* @uiDefault Component.minimumWidth int
|
* @uiDefault Component.minimumWidth int
|
||||||
|
* @uiDefault Component.arrowType String triangle (default) or chevron
|
||||||
* @uiDefault Component.borderColor Color
|
* @uiDefault Component.borderColor Color
|
||||||
* @uiDefault Component.disabledBorderColor Color
|
* @uiDefault Component.disabledBorderColor Color
|
||||||
* @uiDefault Spinner.disabledBackground Color
|
* @uiDefault Spinner.disabledBackground Color
|
||||||
@@ -68,6 +69,7 @@ public class FlatSpinnerUI
|
|||||||
protected int focusWidth;
|
protected int focusWidth;
|
||||||
protected int arc;
|
protected int arc;
|
||||||
protected int minimumWidth;
|
protected int minimumWidth;
|
||||||
|
protected String arrowType;
|
||||||
protected Color borderColor;
|
protected Color borderColor;
|
||||||
protected Color disabledBorderColor;
|
protected Color disabledBorderColor;
|
||||||
protected Color disabledBackground;
|
protected Color disabledBackground;
|
||||||
@@ -89,6 +91,7 @@ public class FlatSpinnerUI
|
|||||||
focusWidth = UIManager.getInt( "Component.focusWidth" );
|
focusWidth = UIManager.getInt( "Component.focusWidth" );
|
||||||
arc = UIManager.getInt( "Component.arc" );
|
arc = UIManager.getInt( "Component.arc" );
|
||||||
minimumWidth = UIManager.getInt( "Component.minimumWidth" );
|
minimumWidth = UIManager.getInt( "Component.minimumWidth" );
|
||||||
|
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" );
|
||||||
disabledBackground = UIManager.getColor( "Spinner.disabledBackground" );
|
disabledBackground = UIManager.getColor( "Spinner.disabledBackground" );
|
||||||
@@ -209,7 +212,7 @@ public class FlatSpinnerUI
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Component createArrowButton( int direction, String name ) {
|
private Component createArrowButton( int direction, String name ) {
|
||||||
FlatArrowButton button = new FlatArrowButton( direction, buttonArrowColor,
|
FlatArrowButton button = new FlatArrowButton( direction, arrowType, buttonArrowColor,
|
||||||
buttonDisabledArrowColor, buttonHoverArrowColor, null );
|
buttonDisabledArrowColor, buttonHoverArrowColor, null );
|
||||||
button.setName( name );
|
button.setName( name );
|
||||||
button.setYOffset( (direction == SwingConstants.NORTH) ? 1 : -1 );
|
button.setYOffset( (direction == SwingConstants.NORTH) ? 1 : -1 );
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import com.formdev.flatlaf.util.UIScale;
|
|||||||
/**
|
/**
|
||||||
* Provides the Flat LaF UI delegate for {@link javax.swing.JSplitPane}.
|
* Provides the Flat LaF UI delegate for {@link javax.swing.JSplitPane}.
|
||||||
*
|
*
|
||||||
|
* @uiDefault Component.arrowType String triangle (default) or chevron
|
||||||
* @uiDefault SplitPane.background Color
|
* @uiDefault SplitPane.background Color
|
||||||
* @uiDefault SplitPane.foreground Color unused
|
* @uiDefault SplitPane.foreground Color unused
|
||||||
* @uiDefault SplitPane.dividerSize int
|
* @uiDefault SplitPane.dividerSize int
|
||||||
@@ -46,6 +47,7 @@ import com.formdev.flatlaf.util.UIScale;
|
|||||||
public class FlatSplitPaneUI
|
public class FlatSplitPaneUI
|
||||||
extends BasicSplitPaneUI
|
extends BasicSplitPaneUI
|
||||||
{
|
{
|
||||||
|
protected String arrowType;
|
||||||
private Boolean continuousLayout;
|
private Boolean continuousLayout;
|
||||||
private Color oneTouchArrowColor;
|
private Color oneTouchArrowColor;
|
||||||
private Color oneTouchHoverArrowColor;
|
private Color oneTouchHoverArrowColor;
|
||||||
@@ -56,6 +58,8 @@ public class FlatSplitPaneUI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void installDefaults() {
|
protected void installDefaults() {
|
||||||
|
arrowType = UIManager.getString( "Component.arrowType" );
|
||||||
|
|
||||||
// get one-touch colors before invoking super.installDefaults() because they are
|
// get one-touch colors before invoking super.installDefaults() because they are
|
||||||
// used in there on LaF switching
|
// used in there on LaF switching
|
||||||
oneTouchArrowColor = UIManager.getColor( "SplitPaneDivider.oneTouchArrowColor" );
|
oneTouchArrowColor = UIManager.getColor( "SplitPaneDivider.oneTouchArrowColor" );
|
||||||
@@ -108,7 +112,7 @@ public class FlatSplitPaneUI
|
|||||||
private final boolean left;
|
private final boolean left;
|
||||||
|
|
||||||
public FlatOneTouchButton( boolean left ) {
|
public FlatOneTouchButton( boolean left ) {
|
||||||
super( SwingConstants.NORTH, oneTouchArrowColor, null, oneTouchHoverArrowColor, null );
|
super( SwingConstants.NORTH, arrowType, oneTouchArrowColor, null, oneTouchHoverArrowColor, null );
|
||||||
setCursor( Cursor.getPredefinedCursor( Cursor.DEFAULT_CURSOR ) );
|
setCursor( Cursor.getPredefinedCursor( Cursor.DEFAULT_CURSOR ) );
|
||||||
|
|
||||||
this.left = left;
|
this.left = left;
|
||||||
|
|||||||
@@ -33,12 +33,14 @@ import javax.swing.plaf.ComponentUI;
|
|||||||
import javax.swing.plaf.UIResource;
|
import javax.swing.plaf.UIResource;
|
||||||
import javax.swing.plaf.basic.BasicTabbedPaneUI;
|
import javax.swing.plaf.basic.BasicTabbedPaneUI;
|
||||||
import javax.swing.text.View;
|
import javax.swing.text.View;
|
||||||
|
import com.formdev.flatlaf.FlatLaf;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides the Flat LaF UI delegate for {@link javax.swing.JTabbedPane}.
|
* Provides the Flat LaF UI delegate for {@link javax.swing.JTabbedPane}.
|
||||||
*
|
*
|
||||||
* @clientProperty JTabbedPane.hasFullBorder boolean
|
* @clientProperty JTabbedPane.hasFullBorder boolean
|
||||||
*
|
*
|
||||||
|
* @uiDefault Component.arrowType String triangle (default) or chevron
|
||||||
* @uiDefault TabbedPane.font Font
|
* @uiDefault TabbedPane.font Font
|
||||||
* @uiDefault TabbedPane.background Color
|
* @uiDefault TabbedPane.background Color
|
||||||
* @uiDefault TabbedPane.foreground Color
|
* @uiDefault TabbedPane.foreground Color
|
||||||
@@ -144,7 +146,8 @@ public class FlatTabbedPaneUI
|
|||||||
@Override
|
@Override
|
||||||
protected JButton createScrollButton( int direction ) {
|
protected JButton createScrollButton( int direction ) {
|
||||||
// this method is invoked before installDefaults(), so we can not use color fields here
|
// this method is invoked before installDefaults(), so we can not use color fields here
|
||||||
return new FlatArrowButton( direction, UIManager.getColor("TabbedPane.shadow"),
|
return new FlatArrowButton( direction, UIManager.getString( "Component.arrowType" ),
|
||||||
|
UIManager.getColor( "TabbedPane.shadow" ),
|
||||||
UIManager.getColor( "TabbedPane.disabledForeground" ), null,
|
UIManager.getColor( "TabbedPane.disabledForeground" ), null,
|
||||||
UIManager.getColor( "TabbedPane.hoverColor" ) );
|
UIManager.getColor( "TabbedPane.hoverColor" ) );
|
||||||
}
|
}
|
||||||
@@ -261,7 +264,7 @@ public class FlatTabbedPaneUI
|
|||||||
} else
|
} else
|
||||||
color = disabledForeground;
|
color = disabledForeground;
|
||||||
|
|
||||||
int mnemIndex = tabPane.getDisplayedMnemonicIndexAt( tabIndex );
|
int mnemIndex = FlatLaf.isShowMnemonics() ? tabPane.getDisplayedMnemonicIndexAt( tabIndex ) : -1;
|
||||||
|
|
||||||
g.setColor( color );
|
g.setColor( color );
|
||||||
FlatUIUtils.drawStringUnderlineCharAt( tabPane, g, title, mnemIndex,
|
FlatUIUtils.drawStringUnderlineCharAt( tabPane, g, title, mnemIndex,
|
||||||
|
|||||||
@@ -181,10 +181,15 @@ public class FlatUIUtils
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Path2D createPath( double... points ) {
|
public static Path2D createPath( double... points ) {
|
||||||
|
return createPath( true, points );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Path2D createPath( boolean close, double... points ) {
|
||||||
Path2D path = new Path2D.Float();
|
Path2D path = new Path2D.Float();
|
||||||
path.moveTo( points[0], points[1] );
|
path.moveTo( points[0], points[1] );
|
||||||
for( int i = 2; i < points.length; i += 2 )
|
for( int i = 2; i < points.length; i += 2 )
|
||||||
path.lineTo( points[i], points[i + 1] );
|
path.lineTo( points[i], points[i + 1] );
|
||||||
|
if( close )
|
||||||
path.closePath();
|
path.closePath();
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,9 @@ public class SystemInfo
|
|||||||
// Java VMs
|
// Java VMs
|
||||||
public static final boolean IS_JETBRAINS_JVM;
|
public static final boolean IS_JETBRAINS_JVM;
|
||||||
|
|
||||||
|
// UI toolkits
|
||||||
|
public static final boolean IS_KDE;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
// platforms
|
// platforms
|
||||||
String osName = System.getProperty( "os.name" ).toLowerCase( Locale.ENGLISH );
|
String osName = System.getProperty( "os.name" ).toLowerCase( Locale.ENGLISH );
|
||||||
@@ -58,6 +61,9 @@ public class SystemInfo
|
|||||||
// Java VMs
|
// Java VMs
|
||||||
IS_JETBRAINS_JVM = System.getProperty( "java.vm.vendor", "Unknown" )
|
IS_JETBRAINS_JVM = System.getProperty( "java.vm.vendor", "Unknown" )
|
||||||
.toLowerCase( Locale.ENGLISH ).contains( "jetbrains" );
|
.toLowerCase( Locale.ENGLISH ).contains( "jetbrains" );
|
||||||
|
|
||||||
|
// UI toolkits
|
||||||
|
IS_KDE = (IS_LINUX && System.getenv( "KDE_FULL_SESSION" ) != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static long scanVersion( String version ) {
|
private static long scanVersion( String version ) {
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import java.lang.reflect.Method;
|
|||||||
import javax.swing.LookAndFeel;
|
import javax.swing.LookAndFeel;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.plaf.DimensionUIResource;
|
import javax.swing.plaf.DimensionUIResource;
|
||||||
|
import javax.swing.plaf.FontUIResource;
|
||||||
import javax.swing.plaf.InsetsUIResource;
|
import javax.swing.plaf.InsetsUIResource;
|
||||||
import javax.swing.plaf.UIResource;
|
import javax.swing.plaf.UIResource;
|
||||||
|
|
||||||
@@ -47,8 +48,7 @@ import javax.swing.plaf.UIResource;
|
|||||||
*
|
*
|
||||||
* 2) user scaling mode
|
* 2) user scaling mode
|
||||||
*
|
*
|
||||||
* This mode is for Java 8 compatibility and can be removed when changing minimum
|
* This mode is mainly for Java 8 compatibility, but is also used on Linux.
|
||||||
* required Java version to 9.
|
|
||||||
* The user scale factor is computed based on the used font.
|
* The user scale factor is computed based on the used font.
|
||||||
* The JRE does not scale anything.
|
* The JRE does not scale anything.
|
||||||
* So we have to invoke {@link #scale(float)} where necessary.
|
* So we have to invoke {@link #scale(float)} where necessary.
|
||||||
@@ -65,7 +65,7 @@ public class UIScale
|
|||||||
|
|
||||||
private static Boolean jreHiDPI;
|
private static Boolean jreHiDPI;
|
||||||
|
|
||||||
private static boolean isJreHiDPIEnabled() {
|
public static boolean isSystemScalingEnabled() {
|
||||||
if( jreHiDPI != null )
|
if( jreHiDPI != null )
|
||||||
return jreHiDPI;
|
return jreHiDPI;
|
||||||
|
|
||||||
@@ -93,19 +93,24 @@ public class UIScale
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static double getSystemScaleFactor( Graphics2D g ) {
|
public static double getSystemScaleFactor( Graphics2D g ) {
|
||||||
return isJreHiDPIEnabled() ? g.getDeviceConfiguration().getDefaultTransform().getScaleX() : 1;
|
return isSystemScalingEnabled() ? g.getDeviceConfiguration().getDefaultTransform().getScaleX() : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double getSystemScaleFactor( GraphicsConfiguration gc ) {
|
public static double getSystemScaleFactor( GraphicsConfiguration gc ) {
|
||||||
return isJreHiDPIEnabled() ? gc.getDefaultTransform().getScaleX() : 1;
|
return isSystemScalingEnabled() ? gc.getDefaultTransform().getScaleX() : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---- user scaling (Java 8) ----------------------------------------------
|
//---- user scaling (Java 8) ----------------------------------------------
|
||||||
|
|
||||||
private static float scaleFactor = 1;
|
private static float scaleFactor = 1;
|
||||||
|
private static boolean initialized;
|
||||||
|
|
||||||
static {
|
private static void initialize() {
|
||||||
if( isEnabled() ) {
|
if( initialized )
|
||||||
|
return;
|
||||||
|
initialized = true;
|
||||||
|
|
||||||
|
if( isUserScalingEnabled() ) {
|
||||||
// listener to update scale factor if LaF changed or if Label.font changed
|
// listener to update scale factor if LaF changed or if Label.font changed
|
||||||
// (e.g. option "Override default fonts" in IntelliJ IDEA)
|
// (e.g. option "Override default fonts" in IntelliJ IDEA)
|
||||||
PropertyChangeListener listener = new PropertyChangeListener() {
|
PropertyChangeListener listener = new PropertyChangeListener() {
|
||||||
@@ -129,7 +134,7 @@ public class UIScale
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void updateScaleFactor() {
|
private static void updateScaleFactor() {
|
||||||
if( !isEnabled() )
|
if( !isUserScalingEnabled() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// use font size to calculate scale factor (instead of DPI)
|
// use font size to calculate scale factor (instead of DPI)
|
||||||
@@ -138,6 +143,10 @@ public class UIScale
|
|||||||
// (e.g. can avoid large icons with small text)
|
// (e.g. can avoid large icons with small text)
|
||||||
Font font = UIManager.getFont( "Label.font" );
|
Font font = UIManager.getFont( "Label.font" );
|
||||||
|
|
||||||
|
setUserScaleFactor( computeScaleFactor( font ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
private static float computeScaleFactor( Font font ) {
|
||||||
// default font size
|
// default font size
|
||||||
float fontSizeDivider = 12f;
|
float fontSizeDivider = 12f;
|
||||||
|
|
||||||
@@ -148,15 +157,15 @@ public class UIScale
|
|||||||
if( "Tahoma".equals( font.getFamily() ) )
|
if( "Tahoma".equals( font.getFamily() ) )
|
||||||
fontSizeDivider = 11f;
|
fontSizeDivider = 11f;
|
||||||
} else if( SystemInfo.IS_LINUX ) {
|
} else if( SystemInfo.IS_LINUX ) {
|
||||||
// default font size for Unity and Gnome is 15
|
// default font size for Unity and Gnome is 15 and for KDE it is 13
|
||||||
fontSizeDivider = 15f;
|
fontSizeDivider = SystemInfo.IS_KDE ? 13f : 15f;
|
||||||
}
|
}
|
||||||
|
|
||||||
setUserScaleFactor( font.getSize() / fontSizeDivider );
|
return font.getSize() / fontSizeDivider;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isEnabled() {
|
private static boolean isUserScalingEnabled() {
|
||||||
if( isJreHiDPIEnabled() )
|
if( isSystemScalingEnabled() && !SystemInfo.IS_LINUX )
|
||||||
return false; // disable user scaling if JRE scales
|
return false; // disable user scaling if JRE scales
|
||||||
|
|
||||||
// same as in IntelliJ IDEA
|
// same as in IntelliJ IDEA
|
||||||
@@ -164,7 +173,58 @@ public class UIScale
|
|||||||
return (hidpi != null) ? Boolean.parseBoolean( hidpi ) : true;
|
return (hidpi != null) ? Boolean.parseBoolean( hidpi ) : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applies a custom scale factor given in system properties "flatlaf.uiScale"
|
||||||
|
* or "sun.java2d.uiScale" to the given font.
|
||||||
|
*/
|
||||||
|
public static FontUIResource applyCustomScaleFactor( FontUIResource font ) {
|
||||||
|
if( UIScale.isSystemScalingEnabled() )
|
||||||
|
return font;
|
||||||
|
|
||||||
|
String uiScale = System.getProperty( "flatlaf.uiScale" );
|
||||||
|
if( uiScale == null )
|
||||||
|
uiScale = System.getProperty( "sun.java2d.uiScale" );
|
||||||
|
|
||||||
|
float scaleFactor = parseScaleFactor( uiScale );
|
||||||
|
if( scaleFactor <= 0 )
|
||||||
|
return font;
|
||||||
|
|
||||||
|
float fontScaleFactor = computeScaleFactor( font );
|
||||||
|
if( scaleFactor == fontScaleFactor )
|
||||||
|
return font;
|
||||||
|
|
||||||
|
int newFontSize = Math.round( (font.getSize() / fontScaleFactor) * scaleFactor );
|
||||||
|
return new FontUIResource( font.getFamily(), font.getStyle(), newFontSize );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Similar to sun.java2d.SunGraphicsEnvironment.getScaleFactor(String)
|
||||||
|
*/
|
||||||
|
private static float parseScaleFactor( String s ) {
|
||||||
|
if( s == null )
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
float units = 1;
|
||||||
|
if( s.endsWith( "x" ) )
|
||||||
|
s = s.substring( 0, s.length() - 1 );
|
||||||
|
else if( s.endsWith( "dpi" ) ) {
|
||||||
|
units = 96;
|
||||||
|
s = s.substring( 0, s.length() - 3 );
|
||||||
|
} else if( s.endsWith( "%" ) ) {
|
||||||
|
units = 100;
|
||||||
|
s = s.substring( 0, s.length() - 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
float scale = Float.parseFloat( s );
|
||||||
|
return scale > 0 ? scale / units : -1;
|
||||||
|
} catch( NumberFormatException ex ) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static float getUserScaleFactor() {
|
public static float getUserScaleFactor() {
|
||||||
|
initialize();
|
||||||
return scaleFactor;
|
return scaleFactor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,10 +241,12 @@ public class UIScale
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static float scale( float value ) {
|
public static float scale( float value ) {
|
||||||
|
initialize();
|
||||||
return (scaleFactor == 1) ? value : (value * scaleFactor);
|
return (scaleFactor == 1) ? value : (value * scaleFactor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int scale( int value ) {
|
public static int scale( int value ) {
|
||||||
|
initialize();
|
||||||
return (scaleFactor == 1) ? value : Math.round( value * scaleFactor );
|
return (scaleFactor == 1) ? value : Math.round( value * scaleFactor );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,23 +254,28 @@ public class UIScale
|
|||||||
* Similar as scale(int) but always "rounds down".
|
* Similar as scale(int) but always "rounds down".
|
||||||
*/
|
*/
|
||||||
public static int scale2( int value ) {
|
public static int scale2( int value ) {
|
||||||
|
initialize();
|
||||||
return (scaleFactor == 1) ? value : (int) (value * scaleFactor);
|
return (scaleFactor == 1) ? value : (int) (value * scaleFactor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float unscale( float value ) {
|
public static float unscale( float value ) {
|
||||||
|
initialize();
|
||||||
return (scaleFactor == 1f) ? value : (value / scaleFactor);
|
return (scaleFactor == 1f) ? value : (value / scaleFactor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int unscale( int value ) {
|
public static int unscale( int value ) {
|
||||||
|
initialize();
|
||||||
return (scaleFactor == 1f) ? value : Math.round( value / scaleFactor );
|
return (scaleFactor == 1f) ? value : Math.round( value / scaleFactor );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void scaleGraphics( Graphics2D g ) {
|
public static void scaleGraphics( Graphics2D g ) {
|
||||||
|
initialize();
|
||||||
if( scaleFactor != 1f )
|
if( scaleFactor != 1f )
|
||||||
g.scale( scaleFactor, scaleFactor );
|
g.scale( scaleFactor, scaleFactor );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Dimension scale( Dimension dimension ) {
|
public static Dimension scale( Dimension dimension ) {
|
||||||
|
initialize();
|
||||||
return (dimension == null || scaleFactor == 1f)
|
return (dimension == null || scaleFactor == 1f)
|
||||||
? dimension
|
? dimension
|
||||||
: (dimension instanceof UIResource
|
: (dimension instanceof UIResource
|
||||||
@@ -217,6 +284,7 @@ public class UIScale
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Insets scale( Insets insets ) {
|
public static Insets scale( Insets insets ) {
|
||||||
|
initialize();
|
||||||
return (insets == null || scaleFactor == 1f)
|
return (insets == null || scaleFactor == 1f)
|
||||||
? insets
|
? insets
|
||||||
: (insets instanceof UIResource
|
: (insets instanceof UIResource
|
||||||
|
|||||||
27
flatlaf-core/src/main/module-info/module-info.java
Normal file
27
flatlaf-core/src/main/module-info/module-info.java
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019 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
|
||||||
|
*
|
||||||
|
* http://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 {
|
||||||
|
requires java.desktop;
|
||||||
|
|
||||||
|
exports com.formdev.flatlaf;
|
||||||
|
exports com.formdev.flatlaf.icons;
|
||||||
|
exports com.formdev.flatlaf.ui;
|
||||||
|
exports com.formdev.flatlaf.util;
|
||||||
|
}
|
||||||
@@ -18,9 +18,16 @@
|
|||||||
# which is licensed under the Apache 2.0 license. Copyright 2000-2019 JetBrains s.r.o.
|
# which is licensed under the Apache 2.0 license. Copyright 2000-2019 JetBrains s.r.o.
|
||||||
# See: https://github.com/JetBrains/intellij-community/
|
# See: https://github.com/JetBrains/intellij-community/
|
||||||
|
|
||||||
|
#---- Button ----
|
||||||
|
|
||||||
|
Button.default.boldText=true
|
||||||
|
|
||||||
|
|
||||||
#---- Component ----
|
#---- Component ----
|
||||||
|
|
||||||
Component.focusWidth=2
|
Component.focusWidth=2
|
||||||
|
Component.innerFocusWidth=0
|
||||||
|
Component.arrowType=triangle
|
||||||
|
|
||||||
|
|
||||||
#---- RadioButton ----
|
#---- RadioButton ----
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ 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.toolbar.hoverBackground=4c5052
|
Button.toolbar.hoverBackground=4c5052
|
||||||
Button.toolbar.pressedBackground=555a5d
|
Button.toolbar.pressedBackground=555a5d
|
||||||
|
|||||||
@@ -22,6 +22,17 @@
|
|||||||
|
|
||||||
Button.focusedBackground=null
|
Button.focusedBackground=null
|
||||||
|
|
||||||
|
Button.default.background=4A86C7
|
||||||
|
Button.default.foreground=f0f0f0
|
||||||
|
Button.default.focusedBackground=null
|
||||||
|
Button.default.hoverBackground=5B91CC
|
||||||
|
Button.default.pressedBackground=6E9ED2
|
||||||
|
Button.default.borderColor=3167ad
|
||||||
|
Button.default.hoverBorderColor=a8cef6
|
||||||
|
Button.default.focusedBorderColor=a8cef6
|
||||||
|
Button.default.focusColor=97c3f3
|
||||||
|
Button.default.boldText=true
|
||||||
|
|
||||||
|
|
||||||
#---- CheckBox ----
|
#---- CheckBox ----
|
||||||
|
|
||||||
@@ -37,6 +48,8 @@ CheckBox.icon.selectedPressedBackground=72A1D4
|
|||||||
#---- Component ----
|
#---- Component ----
|
||||||
|
|
||||||
Component.focusWidth=2
|
Component.focusWidth=2
|
||||||
|
Component.innerFocusWidth=0
|
||||||
|
Component.arrowType=triangle
|
||||||
|
|
||||||
|
|
||||||
#---- RadioButton ----
|
#---- RadioButton ----
|
||||||
|
|||||||
@@ -70,6 +70,8 @@ Button.iconTextGap=4
|
|||||||
Button.rollover=true
|
Button.rollover=true
|
||||||
Button.defaultButtonFollowsFocus=false
|
Button.defaultButtonFollowsFocus=false
|
||||||
|
|
||||||
|
Button.default.borderWidth=1
|
||||||
|
|
||||||
|
|
||||||
#---- CheckBox ----
|
#---- CheckBox ----
|
||||||
|
|
||||||
@@ -103,8 +105,11 @@ ComboBox.padding=2,6,2,6
|
|||||||
#---- Component ----
|
#---- Component ----
|
||||||
|
|
||||||
Component.focusWidth=0
|
Component.focusWidth=0
|
||||||
|
Component.innerFocusWidth=0
|
||||||
Component.arc=5
|
Component.arc=5
|
||||||
Component.minimumWidth=64
|
Component.minimumWidth=64
|
||||||
|
Component.arrowType=chevron
|
||||||
|
Component.hideMnemonics=true
|
||||||
|
|
||||||
|
|
||||||
#---- EditorPane ----
|
#---- EditorPane ----
|
||||||
@@ -306,6 +311,8 @@ SplitPane.dividerSize=5
|
|||||||
SplitPane.continuousLayout=true
|
SplitPane.continuousLayout=true
|
||||||
SplitPane.border=null
|
SplitPane.border=null
|
||||||
SplitPane.centerOneTouchButtons=true
|
SplitPane.centerOneTouchButtons=true
|
||||||
|
SplitPane.oneTouchButtonSize=6
|
||||||
|
SplitPane.oneTouchButtonOffset=2
|
||||||
|
|
||||||
SplitPaneDivider.border=null
|
SplitPaneDivider.border=null
|
||||||
SplitPaneDivider.oneTouchArrowColor=@@ComboBox.buttonArrowColor
|
SplitPaneDivider.oneTouchArrowColor=@@ComboBox.buttonArrowColor
|
||||||
|
|||||||
@@ -72,14 +72,16 @@ Button.disabledBorderColor=cfcfcf
|
|||||||
Button.focusedBorderColor=87afda
|
Button.focusedBorderColor=87afda
|
||||||
Button.hoverBorderColor=@@Button.focusedBorderColor
|
Button.hoverBorderColor=@@Button.focusedBorderColor
|
||||||
|
|
||||||
Button.default.background=4A86C7
|
Button.default.background=@@Button.background
|
||||||
Button.default.foreground=f0f0f0
|
Button.default.foreground=@foreground
|
||||||
Button.default.hoverBackground=5B91CC
|
Button.default.focusedBackground=@@Button.focusedBackground
|
||||||
Button.default.pressedBackground=6E9ED2
|
Button.default.hoverBackground=@@Button.hoverBackground
|
||||||
Button.default.borderColor=3167ad
|
Button.default.pressedBackground=@@Button.pressedBackground
|
||||||
Button.default.hoverBorderColor=a8cef6
|
Button.default.borderColor=4D89C9
|
||||||
Button.default.focusedBorderColor=a8cef6
|
Button.default.hoverBorderColor=@@Button.hoverBorderColor
|
||||||
Button.default.focusColor=97c3f3
|
Button.default.focusedBorderColor=@@Button.focusedBorderColor
|
||||||
|
Button.default.focusColor=@@Component.focusColor
|
||||||
|
Button.default.borderWidth=2
|
||||||
|
|
||||||
Button.toolbar.hoverBackground=dfdfdf
|
Button.toolbar.hoverBackground=dfdfdf
|
||||||
Button.toolbar.pressedBackground=d8d8d8
|
Button.toolbar.pressedBackground=d8d8d8
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ public class FlatComponentsTest
|
|||||||
FlatComponentsTest.TestDefaultButton button5 = new FlatComponentsTest.TestDefaultButton();
|
FlatComponentsTest.TestDefaultButton button5 = new FlatComponentsTest.TestDefaultButton();
|
||||||
JButton button3 = new JButton();
|
JButton button3 = new JButton();
|
||||||
JButton button12 = new JButton();
|
JButton button12 = new JButton();
|
||||||
|
JButton button13 = new JButton();
|
||||||
JLabel toggleButtonLabel = new JLabel();
|
JLabel toggleButtonLabel = new JLabel();
|
||||||
JToggleButton toggleButton1 = new JToggleButton();
|
JToggleButton toggleButton1 = new JToggleButton();
|
||||||
JToggleButton toggleButton2 = new JToggleButton();
|
JToggleButton toggleButton2 = new JToggleButton();
|
||||||
@@ -246,6 +247,10 @@ public class FlatComponentsTest
|
|||||||
button12.setEnabled(false);
|
button12.setEnabled(false);
|
||||||
add(button12, "cell 4 1");
|
add(button12, "cell 4 1");
|
||||||
|
|
||||||
|
//---- button13 ----
|
||||||
|
button13.setIcon(UIManager.getIcon("Tree.closedIcon"));
|
||||||
|
add(button13, "cell 5 1");
|
||||||
|
|
||||||
//---- toggleButtonLabel ----
|
//---- toggleButtonLabel ----
|
||||||
toggleButtonLabel.setText("JToggleButton:");
|
toggleButtonLabel.setText("JToggleButton:");
|
||||||
add(toggleButtonLabel, "cell 0 2");
|
add(toggleButtonLabel, "cell 0 2");
|
||||||
|
|||||||
@@ -76,6 +76,12 @@ new FormModel {
|
|||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
"value": "cell 4 1"
|
"value": "cell 4 1"
|
||||||
} )
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JButton" ) {
|
||||||
|
name: "button13"
|
||||||
|
"icon": new com.jformdesigner.model.SwingIcon( 2, "Tree.closedIcon" )
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 5 1"
|
||||||
|
} )
|
||||||
add( new FormComponent( "javax.swing.JLabel" ) {
|
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||||
name: "toggleButtonLabel"
|
name: "toggleButtonLabel"
|
||||||
"text": "JToggleButton:"
|
"text": "JToggleButton:"
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import java.awt.Dimension;
|
|||||||
import java.awt.EventQueue;
|
import java.awt.EventQueue;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
@@ -41,6 +42,7 @@ import javax.swing.border.LineBorder;
|
|||||||
import javax.swing.plaf.UIResource;
|
import javax.swing.plaf.UIResource;
|
||||||
import javax.swing.text.JTextComponent;
|
import javax.swing.text.JTextComponent;
|
||||||
import com.formdev.flatlaf.ui.FlatToolTipUI;
|
import com.formdev.flatlaf.ui.FlatToolTipUI;
|
||||||
|
import com.formdev.flatlaf.ui.FlatUIUtils;
|
||||||
import com.formdev.flatlaf.util.UIScale;
|
import com.formdev.flatlaf.util.UIScale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -103,7 +105,7 @@ public class FlatInspector
|
|||||||
private void inspect( int x, int y ) {
|
private void inspect( int x, int y ) {
|
||||||
Container contentPane = rootPane.getContentPane();
|
Container contentPane = rootPane.getContentPane();
|
||||||
Component c = SwingUtilities.getDeepestComponentAt( contentPane, x, y );
|
Component c = SwingUtilities.getDeepestComponentAt( contentPane, x, y );
|
||||||
if( c == contentPane || c.getParent() == contentPane )
|
if( c == contentPane || (c != null && c.getParent() == contentPane) )
|
||||||
c = null;
|
c = null;
|
||||||
|
|
||||||
if( c == lastComponent )
|
if( c == lastComponent )
|
||||||
@@ -137,6 +139,12 @@ public class FlatInspector
|
|||||||
g.setColor( getBackground() );
|
g.setColor( getBackground() );
|
||||||
g.fillRect( 0, 0, getWidth(), getHeight() );
|
g.fillRect( 0, 0, getWidth(), getHeight() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void paintBorder( Graphics g ) {
|
||||||
|
FlatUIUtils.setRenderingHints( (Graphics2D) g );
|
||||||
|
super.paintBorder( g );
|
||||||
|
}
|
||||||
};
|
};
|
||||||
c.setBackground( new Color( 255, 0, 0, 32 ) );
|
c.setBackground( new Color( 255, 0, 0, 32 ) );
|
||||||
c.setBorder( new LineBorder( Color.red ) );
|
c.setBorder( new LineBorder( Color.red ) );
|
||||||
|
|||||||
@@ -17,13 +17,21 @@
|
|||||||
package com.formdev.flatlaf;
|
package com.formdev.flatlaf;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.awt.event.ComponentAdapter;
|
||||||
|
import java.awt.event.ComponentEvent;
|
||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
|
import java.awt.event.WindowAdapter;
|
||||||
|
import java.awt.event.WindowEvent;
|
||||||
|
import java.beans.PropertyChangeEvent;
|
||||||
|
import java.beans.PropertyChangeListener;
|
||||||
import java.util.prefs.Preferences;
|
import java.util.prefs.Preferences;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import javax.swing.plaf.ColorUIResource;
|
import javax.swing.plaf.ColorUIResource;
|
||||||
import javax.swing.plaf.metal.MetalLookAndFeel;
|
import javax.swing.plaf.metal.MetalLookAndFeel;
|
||||||
import javax.swing.plaf.nimbus.NimbusLookAndFeel;
|
import javax.swing.plaf.nimbus.NimbusLookAndFeel;
|
||||||
|
import com.formdev.flatlaf.ui.FlatUIUtils;
|
||||||
import com.formdev.flatlaf.util.SystemInfo;
|
import com.formdev.flatlaf.util.SystemInfo;
|
||||||
|
import com.formdev.flatlaf.util.UIScale;
|
||||||
import net.miginfocom.swing.*;
|
import net.miginfocom.swing.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -34,47 +42,53 @@ public class FlatTestFrame
|
|||||||
{
|
{
|
||||||
private static final String PREFS_ROOT_PATH = "/flatlaf-test";
|
private static final String PREFS_ROOT_PATH = "/flatlaf-test";
|
||||||
private static final String KEY_LAF = "laf";
|
private static final String KEY_LAF = "laf";
|
||||||
|
private static final String KEY_SCALE_FACTOR = "scaleFactor";
|
||||||
|
|
||||||
|
private final String title;
|
||||||
private JComponent content;
|
private JComponent content;
|
||||||
private FlatInspector inspector;
|
private FlatInspector inspector;
|
||||||
|
|
||||||
public static FlatTestFrame create( String[] args, String title ) {
|
public static FlatTestFrame create( String[] args, String title ) {
|
||||||
|
Preferences prefs = Preferences.userRoot().node( PREFS_ROOT_PATH );
|
||||||
|
|
||||||
|
// set scale factor
|
||||||
|
if( System.getProperty( "flatlaf.uiScale", System.getProperty( "sun.java2d.uiScale" ) ) == null ) {
|
||||||
|
String scaleFactor = prefs.get( KEY_SCALE_FACTOR, null );
|
||||||
|
if( scaleFactor != null )
|
||||||
|
System.setProperty( "flatlaf.uiScale", scaleFactor );
|
||||||
|
}
|
||||||
|
|
||||||
// set look and feel
|
// set look and feel
|
||||||
try {
|
try {
|
||||||
if( args.length > 0 )
|
if( args.length > 0 )
|
||||||
UIManager.setLookAndFeel( args[0] );
|
UIManager.setLookAndFeel( args[0] );
|
||||||
else {
|
else {
|
||||||
String lafClassName = Preferences.userRoot().node( PREFS_ROOT_PATH )
|
String lafClassName = prefs.get( KEY_LAF, FlatLightLaf.class.getName() );
|
||||||
.get( KEY_LAF, FlatLightLaf.class.getName() );
|
|
||||||
UIManager.setLookAndFeel( lafClassName );
|
UIManager.setLookAndFeel( lafClassName );
|
||||||
}
|
}
|
||||||
} catch( Exception ex ) {
|
} catch( Exception ex ) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
|
|
||||||
// fallback
|
// fallback
|
||||||
try {
|
FlatLightLaf.install();
|
||||||
UIManager.setLookAndFeel( new FlatLightLaf() );
|
|
||||||
} catch( Exception ex2 ) {
|
|
||||||
ex2.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// create frame
|
// create frame
|
||||||
FlatTestFrame frame = new FlatTestFrame();
|
return new FlatTestFrame( title );
|
||||||
frame.setTitle( title + " (Java " + System.getProperty( "java.version" ) + ")" );
|
|
||||||
return frame;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private FlatTestFrame() {
|
private FlatTestFrame( String title ) {
|
||||||
|
this.title = title;
|
||||||
|
|
||||||
initComponents();
|
initComponents();
|
||||||
|
|
||||||
// initialize look and feels combo box
|
// initialize look and feels combo box
|
||||||
DefaultComboBoxModel<LafInfo> lafModel = new DefaultComboBoxModel<>();
|
DefaultComboBoxModel<LafInfo> lafModel = new DefaultComboBoxModel<>();
|
||||||
lafModel.addElement( new LafInfo( "Flat Light (F1)", FlatLightLaf.class.getName() ) );
|
lafModel.addElement( new LafInfo( "Flat Light (F1)", FlatLightLaf.class.getName() ) );
|
||||||
lafModel.addElement( new LafInfo( "Flat Dark (F2)", FlatDarkLaf.class.getName() ) );
|
lafModel.addElement( new LafInfo( "Flat Dark (F2)", FlatDarkLaf.class.getName() ) );
|
||||||
lafModel.addElement( new LafInfo( "Flat Test (F3)", FlatTestLaf.class.getName() ) );
|
lafModel.addElement( new LafInfo( "Flat IntelliJ (F3)", FlatIntelliJLaf.class.getName() ) );
|
||||||
lafModel.addElement( new LafInfo( "Flat IntelliJ (F4)", FlatIntelliJLaf.class.getName() ) );
|
lafModel.addElement( new LafInfo( "Flat Darcula (F4)", FlatDarculaLaf.class.getName() ) );
|
||||||
lafModel.addElement( new LafInfo( "Flat Darcula (F5)", FlatDarculaLaf.class.getName() ) );
|
lafModel.addElement( new LafInfo( "Flat Test (F8)", FlatTestLaf.class.getName() ) );
|
||||||
|
|
||||||
UIManager.LookAndFeelInfo[] lookAndFeels = UIManager.getInstalledLookAndFeels();
|
UIManager.LookAndFeelInfo[] lookAndFeels = UIManager.getInstalledLookAndFeels();
|
||||||
for( UIManager.LookAndFeelInfo lookAndFeel : lookAndFeels ) {
|
for( UIManager.LookAndFeelInfo lookAndFeel : lookAndFeels ) {
|
||||||
@@ -85,7 +99,8 @@ public class FlatTestFrame
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
if( (SystemInfo.IS_WINDOWS && className.equals( "com.sun.java.swing.plaf.windows.WindowsLookAndFeel" )) ||
|
if( (SystemInfo.IS_WINDOWS && className.equals( "com.sun.java.swing.plaf.windows.WindowsLookAndFeel" )) ||
|
||||||
(SystemInfo.IS_MAC && className.equals( "com.apple.laf.AquaLookAndFeel") ) )
|
(SystemInfo.IS_MAC && className.equals( "com.apple.laf.AquaLookAndFeel") ) ||
|
||||||
|
(SystemInfo.IS_LINUX && className.equals( "com.sun.java.swing.plaf.gtk.GTKLookAndFeel") ) )
|
||||||
name += " (F9)";
|
name += " (F9)";
|
||||||
else if( className.equals( MetalLookAndFeel.class.getName() ) )
|
else if( className.equals( MetalLookAndFeel.class.getName() ) )
|
||||||
name += " (F10)";
|
name += " (F10)";
|
||||||
@@ -106,17 +121,25 @@ public class FlatTestFrame
|
|||||||
|
|
||||||
lookAndFeelComboBox.setModel( lafModel );
|
lookAndFeelComboBox.setModel( lafModel );
|
||||||
|
|
||||||
// register F1, F2 and F3 keys to switch to Light, Dark or Test LaF
|
updateScaleFactorComboBox();
|
||||||
|
String scaleFactor = System.getProperty( "flatlaf.uiScale", System.getProperty( "sun.java2d.uiScale" ) );
|
||||||
|
if( scaleFactor != null )
|
||||||
|
scaleFactorComboBox.setSelectedItem( scaleFactor );
|
||||||
|
|
||||||
|
// register F1, F2, ... keys to switch to Light, Dark or other LaFs
|
||||||
registerSwitchToLookAndFeel( KeyEvent.VK_F1, FlatLightLaf.class.getName() );
|
registerSwitchToLookAndFeel( KeyEvent.VK_F1, FlatLightLaf.class.getName() );
|
||||||
registerSwitchToLookAndFeel( KeyEvent.VK_F2, FlatDarkLaf.class.getName() );
|
registerSwitchToLookAndFeel( KeyEvent.VK_F2, FlatDarkLaf.class.getName() );
|
||||||
registerSwitchToLookAndFeel( KeyEvent.VK_F3, FlatTestLaf.class.getName() );
|
registerSwitchToLookAndFeel( KeyEvent.VK_F3, FlatIntelliJLaf.class.getName() );
|
||||||
registerSwitchToLookAndFeel( KeyEvent.VK_F4, FlatIntelliJLaf.class.getName() );
|
registerSwitchToLookAndFeel( KeyEvent.VK_F4, FlatDarculaLaf.class.getName() );
|
||||||
registerSwitchToLookAndFeel( KeyEvent.VK_F5, FlatDarculaLaf.class.getName() );
|
|
||||||
|
registerSwitchToLookAndFeel( KeyEvent.VK_F8, FlatTestLaf.class.getName() );
|
||||||
|
|
||||||
if( SystemInfo.IS_WINDOWS )
|
if( SystemInfo.IS_WINDOWS )
|
||||||
registerSwitchToLookAndFeel( KeyEvent.VK_F9, "com.sun.java.swing.plaf.windows.WindowsLookAndFeel" );
|
registerSwitchToLookAndFeel( KeyEvent.VK_F9, "com.sun.java.swing.plaf.windows.WindowsLookAndFeel" );
|
||||||
else if( SystemInfo.IS_MAC )
|
else if( SystemInfo.IS_MAC )
|
||||||
registerSwitchToLookAndFeel( KeyEvent.VK_F9, "com.apple.laf.AquaLookAndFeel" );
|
registerSwitchToLookAndFeel( KeyEvent.VK_F9, "com.apple.laf.AquaLookAndFeel" );
|
||||||
|
else if( SystemInfo.IS_LINUX )
|
||||||
|
registerSwitchToLookAndFeel( KeyEvent.VK_F9, "com.sun.java.swing.plaf.gtk.GTKLookAndFeel" );
|
||||||
registerSwitchToLookAndFeel( KeyEvent.VK_F10, MetalLookAndFeel.class.getName() );
|
registerSwitchToLookAndFeel( KeyEvent.VK_F10, MetalLookAndFeel.class.getName() );
|
||||||
registerSwitchToLookAndFeel( KeyEvent.VK_F11, NimbusLookAndFeel.class.getName() );
|
registerSwitchToLookAndFeel( KeyEvent.VK_F11, NimbusLookAndFeel.class.getName() );
|
||||||
|
|
||||||
@@ -130,6 +153,47 @@ public class FlatTestFrame
|
|||||||
|
|
||||||
// close frame
|
// close frame
|
||||||
closeButton.addActionListener(e -> dispose());
|
closeButton.addActionListener(e -> dispose());
|
||||||
|
|
||||||
|
// update title
|
||||||
|
addWindowListener( new WindowAdapter() {
|
||||||
|
@Override
|
||||||
|
public void windowOpened( WindowEvent e ) {
|
||||||
|
updateTitle();
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
|
||||||
|
// update title when moved to another screen
|
||||||
|
addComponentListener( new ComponentAdapter() {
|
||||||
|
@Override
|
||||||
|
public void componentMoved( ComponentEvent e ) {
|
||||||
|
updateTitle();
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
|
||||||
|
UIManager.addPropertyChangeListener( e -> {
|
||||||
|
if( "lookAndFeel".equals( e.getPropertyName() ) ) {
|
||||||
|
EventQueue.invokeLater( () -> {
|
||||||
|
// update title because user scale factor may change
|
||||||
|
updateTitle();
|
||||||
|
|
||||||
|
// enable/disable scale factor combobox
|
||||||
|
updateScaleFactorComboBox();
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateTitle() {
|
||||||
|
double systemScaleFactor = UIScale.getSystemScaleFactor( getGraphicsConfiguration() );
|
||||||
|
float userScaleFactor = UIScale.getUserScaleFactor();
|
||||||
|
String newTitle = title + " (Java " + System.getProperty( "java.version" )
|
||||||
|
+ (systemScaleFactor != 1 ? ("; system scale factor " + systemScaleFactor) : "")
|
||||||
|
+ (userScaleFactor != 1 ? ("; user scale factor " + userScaleFactor) : "")
|
||||||
|
+ (systemScaleFactor == 1 && userScaleFactor == 1 ? "; no scaling" : "")
|
||||||
|
+ ")";
|
||||||
|
|
||||||
|
if( !newTitle.equals( getTitle() ) )
|
||||||
|
setTitle( newTitle );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerSwitchToLookAndFeel( int keyCode, String lafClassName ) {
|
private void registerSwitchToLookAndFeel( int keyCode, String lafClassName ) {
|
||||||
@@ -169,22 +233,48 @@ public class FlatTestFrame
|
|||||||
if( newLaf.className.equals( UIManager.getLookAndFeel().getClass().getName() ) )
|
if( newLaf.className.equals( UIManager.getLookAndFeel().getClass().getName() ) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// hide popup to avoid occasional StackOverflowError when updating UI
|
||||||
|
lookAndFeelComboBox.setPopupVisible( false );
|
||||||
|
|
||||||
Preferences.userRoot().node( PREFS_ROOT_PATH ).put( KEY_LAF, newLaf.className );
|
Preferences.userRoot().node( PREFS_ROOT_PATH ).put( KEY_LAF, newLaf.className );
|
||||||
|
|
||||||
|
applyLookAndFeel( newLaf.className, false );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void applyLookAndFeel( String lafClassName, boolean pack ) {
|
||||||
EventQueue.invokeLater( () -> {
|
EventQueue.invokeLater( () -> {
|
||||||
try {
|
try {
|
||||||
// change look and feel
|
// change look and feel
|
||||||
UIManager.setLookAndFeel( newLaf.className );
|
UIManager.setLookAndFeel( lafClassName );
|
||||||
|
|
||||||
// update all components
|
// update all components
|
||||||
SwingUtilities.updateComponentTreeUI( this );
|
FlatLaf.updateUI();
|
||||||
|
|
||||||
// increase size of frame if necessary
|
// increase size of frame if necessary
|
||||||
|
if( pack )
|
||||||
|
pack();
|
||||||
|
else {
|
||||||
int width = getWidth();
|
int width = getWidth();
|
||||||
int height = getHeight();
|
int height = getHeight();
|
||||||
Dimension prefSize = getPreferredSize();
|
Dimension prefSize = getPreferredSize();
|
||||||
if( prefSize.width > width || prefSize.height > height )
|
if( prefSize.width > width || prefSize.height > height )
|
||||||
setSize( Math.max( prefSize.width, width ), Math.max( prefSize.height, height ) );
|
setSize( Math.max( prefSize.width, width ), Math.max( prefSize.height, height ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
// limit frame size to screen size
|
||||||
|
Rectangle screenBounds = getGraphicsConfiguration().getBounds();
|
||||||
|
screenBounds = FlatUIUtils.subtractInsets( screenBounds, getToolkit().getScreenInsets( getGraphicsConfiguration() ) );
|
||||||
|
Dimension frameSize = getSize();
|
||||||
|
if( frameSize.width > screenBounds.width || frameSize.height > screenBounds.height )
|
||||||
|
setSize( Math.min( frameSize.width, screenBounds.width ), Math.min( frameSize.height, screenBounds.height ) );
|
||||||
|
|
||||||
|
// move frame to left/top if necessary
|
||||||
|
if( getX() + getWidth() > screenBounds.x + screenBounds.width ||
|
||||||
|
getY() + getHeight() > screenBounds.y + screenBounds.height )
|
||||||
|
{
|
||||||
|
setLocation( Math.min( getX(), screenBounds.x + screenBounds.width - getWidth() ),
|
||||||
|
Math.min( getY(), screenBounds.y + screenBounds.height - getHeight() ) );
|
||||||
|
}
|
||||||
|
|
||||||
if( inspector != null )
|
if( inspector != null )
|
||||||
inspector.update();
|
inspector.update();
|
||||||
@@ -289,6 +379,31 @@ public class FlatTestFrame
|
|||||||
inspector.setEnabled( inspectCheckBox.isSelected() );
|
inspector.setEnabled( inspectCheckBox.isSelected() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void scaleFactorChanged() {
|
||||||
|
String scaleFactor = (String) scaleFactorComboBox.getSelectedItem();
|
||||||
|
if( "default".equals( scaleFactor ) )
|
||||||
|
scaleFactor = null;
|
||||||
|
|
||||||
|
// hide popup to avoid occasional StackOverflowError when updating UI
|
||||||
|
scaleFactorComboBox.setPopupVisible( false );
|
||||||
|
|
||||||
|
Preferences prefs = Preferences.userRoot().node( PREFS_ROOT_PATH );
|
||||||
|
|
||||||
|
if( scaleFactor != null ) {
|
||||||
|
System.setProperty( "flatlaf.uiScale", scaleFactor );
|
||||||
|
prefs.put( KEY_SCALE_FACTOR, scaleFactor );
|
||||||
|
} else {
|
||||||
|
System.clearProperty( "flatlaf.uiScale" );
|
||||||
|
prefs.remove( KEY_SCALE_FACTOR );
|
||||||
|
}
|
||||||
|
|
||||||
|
applyLookAndFeel( UIManager.getLookAndFeel().getClass().getName(), true );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateScaleFactorComboBox() {
|
||||||
|
scaleFactorComboBox.setEnabled( !UIScale.isSystemScalingEnabled() && UIManager.getLookAndFeel() instanceof FlatLaf );
|
||||||
|
}
|
||||||
|
|
||||||
private void initComponents() {
|
private void initComponents() {
|
||||||
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
|
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
|
||||||
dialogPane = new JPanel();
|
dialogPane = new JPanel();
|
||||||
@@ -299,6 +414,7 @@ public class FlatTestFrame
|
|||||||
rightToLeftCheckBox = new JCheckBox();
|
rightToLeftCheckBox = new JCheckBox();
|
||||||
enabledCheckBox = new JCheckBox();
|
enabledCheckBox = new JCheckBox();
|
||||||
inspectCheckBox = new JCheckBox();
|
inspectCheckBox = new JCheckBox();
|
||||||
|
scaleFactorComboBox = new JComboBox<>();
|
||||||
closeButton = new JButton();
|
closeButton = new JButton();
|
||||||
|
|
||||||
//======== this ========
|
//======== this ========
|
||||||
@@ -332,6 +448,7 @@ public class FlatTestFrame
|
|||||||
"[fill]" +
|
"[fill]" +
|
||||||
"[fill]" +
|
"[fill]" +
|
||||||
"[fill]" +
|
"[fill]" +
|
||||||
|
"[fill]" +
|
||||||
"[grow,fill]" +
|
"[grow,fill]" +
|
||||||
"[button,fill]",
|
"[button,fill]",
|
||||||
// rows
|
// rows
|
||||||
@@ -366,9 +483,27 @@ public class FlatTestFrame
|
|||||||
inspectCheckBox.addActionListener(e -> inspectChanged());
|
inspectCheckBox.addActionListener(e -> inspectChanged());
|
||||||
buttonBar.add(inspectCheckBox, "cell 4 0");
|
buttonBar.add(inspectCheckBox, "cell 4 0");
|
||||||
|
|
||||||
|
//---- scaleFactorComboBox ----
|
||||||
|
scaleFactorComboBox.setModel(new DefaultComboBoxModel<>(new String[] {
|
||||||
|
"default",
|
||||||
|
"1",
|
||||||
|
"1.25",
|
||||||
|
"1.5",
|
||||||
|
"1.75",
|
||||||
|
"2.0",
|
||||||
|
"2.25",
|
||||||
|
"2.5",
|
||||||
|
"3",
|
||||||
|
"3.5",
|
||||||
|
"4"
|
||||||
|
}));
|
||||||
|
scaleFactorComboBox.setMaximumRowCount(20);
|
||||||
|
scaleFactorComboBox.addActionListener(e -> scaleFactorChanged());
|
||||||
|
buttonBar.add(scaleFactorComboBox, "cell 5 0");
|
||||||
|
|
||||||
//---- closeButton ----
|
//---- closeButton ----
|
||||||
closeButton.setText("Close");
|
closeButton.setText("Close");
|
||||||
buttonBar.add(closeButton, "cell 6 0");
|
buttonBar.add(closeButton, "cell 7 0");
|
||||||
}
|
}
|
||||||
dialogPane.add(buttonBar, BorderLayout.SOUTH);
|
dialogPane.add(buttonBar, BorderLayout.SOUTH);
|
||||||
}
|
}
|
||||||
@@ -385,6 +520,7 @@ public class FlatTestFrame
|
|||||||
private JCheckBox rightToLeftCheckBox;
|
private JCheckBox rightToLeftCheckBox;
|
||||||
private JCheckBox enabledCheckBox;
|
private JCheckBox enabledCheckBox;
|
||||||
private JCheckBox inspectCheckBox;
|
private JCheckBox inspectCheckBox;
|
||||||
|
private JComboBox<String> scaleFactorComboBox;
|
||||||
private JButton closeButton;
|
private JButton closeButton;
|
||||||
// JFormDesigner - End of variables declaration //GEN-END:variables
|
// JFormDesigner - End of variables declaration //GEN-END:variables
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ new FormModel {
|
|||||||
} )
|
} )
|
||||||
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
|
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
|
||||||
"$layoutConstraints": "insets dialog"
|
"$layoutConstraints": "insets dialog"
|
||||||
"$columnConstraints": "[fill][fill][fill][fill][fill][grow,fill][button,fill]"
|
"$columnConstraints": "[fill][fill][fill][fill][fill][fill][grow,fill][button,fill]"
|
||||||
"$rowSpecs": "[fill]"
|
"$rowSpecs": "[fill]"
|
||||||
} ) {
|
} ) {
|
||||||
name: "buttonBar"
|
name: "buttonBar"
|
||||||
@@ -67,11 +67,35 @@ new FormModel {
|
|||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
"value": "cell 4 0"
|
"value": "cell 4 0"
|
||||||
} )
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JComboBox" ) {
|
||||||
|
name: "scaleFactorComboBox"
|
||||||
|
"model": new javax.swing.DefaultComboBoxModel {
|
||||||
|
selectedItem: "default"
|
||||||
|
addElement( "default" )
|
||||||
|
addElement( "1" )
|
||||||
|
addElement( "1.25" )
|
||||||
|
addElement( "1.5" )
|
||||||
|
addElement( "1.75" )
|
||||||
|
addElement( "2.0" )
|
||||||
|
addElement( "2.25" )
|
||||||
|
addElement( "2.5" )
|
||||||
|
addElement( "3" )
|
||||||
|
addElement( "3.5" )
|
||||||
|
addElement( "4" )
|
||||||
|
}
|
||||||
|
"maximumRowCount": 20
|
||||||
|
auxiliary() {
|
||||||
|
"JavaCodeGenerator.typeParameters": "String"
|
||||||
|
}
|
||||||
|
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "scaleFactorChanged", false ) )
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 5 0"
|
||||||
|
} )
|
||||||
add( new FormComponent( "javax.swing.JButton" ) {
|
add( new FormComponent( "javax.swing.JButton" ) {
|
||||||
name: "closeButton"
|
name: "closeButton"
|
||||||
"text": "Close"
|
"text": "Close"
|
||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
"value": "cell 6 0"
|
"value": "cell 7 0"
|
||||||
} )
|
} )
|
||||||
}, new FormLayoutConstraints( class java.lang.String ) {
|
}, new FormLayoutConstraints( class java.lang.String ) {
|
||||||
"value": "South"
|
"value": "South"
|
||||||
@@ -81,7 +105,7 @@ new FormModel {
|
|||||||
} )
|
} )
|
||||||
}, 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( 510, 300 )
|
"size": new java.awt.Dimension( 640, 300 )
|
||||||
} )
|
} )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ dependencies {
|
|||||||
implementation( project( ":flatlaf-core" ) )
|
implementation( project( ":flatlaf-core" ) )
|
||||||
implementation( "com.miglayout:miglayout-swing:5.2" )
|
implementation( "com.miglayout:miglayout-swing:5.2" )
|
||||||
implementation( "com.jgoodies:jgoodies-forms:1.9.0" )
|
implementation( "com.jgoodies:jgoodies-forms:1.9.0" )
|
||||||
implementation( "guru.nidi.com.kitfox:svgSalamander:1.1.2" )
|
implementation( "com.formdev:svgSalamander:1.1.2.1" )
|
||||||
}
|
}
|
||||||
|
|
||||||
java {
|
java {
|
||||||
@@ -42,6 +42,8 @@ tasks {
|
|||||||
attributes( "Main-Class" to "com.formdev.flatlaf.demo.FlatLafDemo" )
|
attributes( "Main-Class" to "com.formdev.flatlaf.demo.FlatLafDemo" )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exclude( "META-INF/versions/**" )
|
||||||
|
|
||||||
// include all dependencies in jar
|
// include all dependencies in jar
|
||||||
from( {
|
from( {
|
||||||
configurations.runtimeClasspath.get().filter { it.name.endsWith( "jar" ) }.map { zipTree( it ) }
|
configurations.runtimeClasspath.get().filter { it.name.endsWith( "jar" ) }.map { zipTree( it ) }
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ class BasicComponentsPanel
|
|||||||
JButton button2 = new JButton();
|
JButton button2 = new JButton();
|
||||||
JButton button3 = new JButton();
|
JButton button3 = new JButton();
|
||||||
JButton button4 = new JButton();
|
JButton button4 = new JButton();
|
||||||
|
JButton button13 = new JButton();
|
||||||
JLabel checkBoxLabel = new JLabel();
|
JLabel checkBoxLabel = new JLabel();
|
||||||
JCheckBox checkBox1 = new JCheckBox();
|
JCheckBox checkBox1 = new JCheckBox();
|
||||||
JCheckBox checkBox2 = new JCheckBox();
|
JCheckBox checkBox2 = new JCheckBox();
|
||||||
@@ -169,6 +170,10 @@ class BasicComponentsPanel
|
|||||||
button4.setEnabled(false);
|
button4.setEnabled(false);
|
||||||
add(button4, "cell 4 1");
|
add(button4, "cell 4 1");
|
||||||
|
|
||||||
|
//---- button13 ----
|
||||||
|
button13.setIcon(UIManager.getIcon("Tree.closedIcon"));
|
||||||
|
add(button13, "cell 5 1");
|
||||||
|
|
||||||
//---- checkBoxLabel ----
|
//---- checkBoxLabel ----
|
||||||
checkBoxLabel.setText("JCheckBox");
|
checkBoxLabel.setText("JCheckBox");
|
||||||
add(checkBoxLabel, "cell 0 2");
|
add(checkBoxLabel, "cell 0 2");
|
||||||
|
|||||||
@@ -69,6 +69,12 @@ new FormModel {
|
|||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
"value": "cell 4 1"
|
"value": "cell 4 1"
|
||||||
} )
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JButton" ) {
|
||||||
|
name: "button13"
|
||||||
|
"icon": new com.jformdesigner.model.SwingIcon( 2, "Tree.closedIcon" )
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 5 1"
|
||||||
|
} )
|
||||||
add( new FormComponent( "javax.swing.JLabel" ) {
|
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||||
name: "checkBoxLabel"
|
name: "checkBoxLabel"
|
||||||
"text": "JCheckBox"
|
"text": "JCheckBox"
|
||||||
|
|||||||
@@ -17,6 +17,8 @@
|
|||||||
package com.formdev.flatlaf.demo;
|
package com.formdev.flatlaf.demo;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.awt.event.ComponentAdapter;
|
||||||
|
import java.awt.event.ComponentEvent;
|
||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
import java.awt.event.WindowAdapter;
|
import java.awt.event.WindowAdapter;
|
||||||
import java.awt.event.WindowEvent;
|
import java.awt.event.WindowEvent;
|
||||||
@@ -56,7 +58,8 @@ class ControlBar
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
if( (SystemInfo.IS_WINDOWS && className.equals( "com.sun.java.swing.plaf.windows.WindowsLookAndFeel" )) ||
|
if( (SystemInfo.IS_WINDOWS && className.equals( "com.sun.java.swing.plaf.windows.WindowsLookAndFeel" )) ||
|
||||||
(SystemInfo.IS_MAC && className.equals( "com.apple.laf.AquaLookAndFeel") ) )
|
(SystemInfo.IS_MAC && className.equals( "com.apple.laf.AquaLookAndFeel") ) ||
|
||||||
|
(SystemInfo.IS_LINUX && className.equals( "com.sun.java.swing.plaf.gtk.GTKLookAndFeel") ) )
|
||||||
name += " (F9)";
|
name += " (F9)";
|
||||||
else if( className.equals( MetalLookAndFeel.class.getName() ) )
|
else if( className.equals( MetalLookAndFeel.class.getName() ) )
|
||||||
name += " (F10)";
|
name += " (F10)";
|
||||||
@@ -76,6 +79,15 @@ class ControlBar
|
|||||||
lafModel.setSelectedItem( lafModel.getElementAt( sel ) );
|
lafModel.setSelectedItem( lafModel.getElementAt( sel ) );
|
||||||
|
|
||||||
lookAndFeelComboBox.setModel( lafModel );
|
lookAndFeelComboBox.setModel( lafModel );
|
||||||
|
|
||||||
|
UIManager.addPropertyChangeListener( e -> {
|
||||||
|
if( "lookAndFeel".equals( e.getPropertyName() ) ) {
|
||||||
|
EventQueue.invokeLater( () -> {
|
||||||
|
// update info label because user scale factor may change
|
||||||
|
updateInfoLabel();
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
void initialize( JFrame frame, JTabbedPane tabbedPane ) {
|
void initialize( JFrame frame, JTabbedPane tabbedPane ) {
|
||||||
@@ -92,6 +104,8 @@ class ControlBar
|
|||||||
registerSwitchToLookAndFeel( KeyEvent.VK_F9, "com.sun.java.swing.plaf.windows.WindowsLookAndFeel" );
|
registerSwitchToLookAndFeel( KeyEvent.VK_F9, "com.sun.java.swing.plaf.windows.WindowsLookAndFeel" );
|
||||||
else if( SystemInfo.IS_MAC )
|
else if( SystemInfo.IS_MAC )
|
||||||
registerSwitchToLookAndFeel( KeyEvent.VK_F9, "com.apple.laf.AquaLookAndFeel" );
|
registerSwitchToLookAndFeel( KeyEvent.VK_F9, "com.apple.laf.AquaLookAndFeel" );
|
||||||
|
else if( SystemInfo.IS_LINUX )
|
||||||
|
registerSwitchToLookAndFeel( KeyEvent.VK_F9, "com.sun.java.swing.plaf.gtk.GTKLookAndFeel" );
|
||||||
registerSwitchToLookAndFeel( KeyEvent.VK_F10, MetalLookAndFeel.class.getName() );
|
registerSwitchToLookAndFeel( KeyEvent.VK_F10, MetalLookAndFeel.class.getName() );
|
||||||
registerSwitchToLookAndFeel( KeyEvent.VK_F11, NimbusLookAndFeel.class.getName() );
|
registerSwitchToLookAndFeel( KeyEvent.VK_F11, NimbusLookAndFeel.class.getName() );
|
||||||
|
|
||||||
@@ -106,15 +120,19 @@ class ControlBar
|
|||||||
// make the "close" button the default button
|
// make the "close" button the default button
|
||||||
frame.getRootPane().setDefaultButton( closeButton );
|
frame.getRootPane().setDefaultButton( closeButton );
|
||||||
|
|
||||||
// move focus to "close" button
|
// update info label and move focus to "close" button
|
||||||
frame.addWindowListener( new WindowAdapter() {
|
frame.addWindowListener( new WindowAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void windowOpened( WindowEvent e ) {
|
public void windowOpened( WindowEvent e ) {
|
||||||
updateInfoLabel();
|
updateInfoLabel();
|
||||||
closeButton.requestFocusInWindow();
|
closeButton.requestFocusInWindow();
|
||||||
}
|
}
|
||||||
|
} );
|
||||||
|
|
||||||
|
// update info label when moved to another screen
|
||||||
|
frame.addComponentListener( new ComponentAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void windowActivated( WindowEvent e ) {
|
public void componentMoved( ComponentEvent e ) {
|
||||||
updateInfoLabel();
|
updateInfoLabel();
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
@@ -123,11 +141,14 @@ class ControlBar
|
|||||||
private void updateInfoLabel() {
|
private void updateInfoLabel() {
|
||||||
double systemScaleFactor = UIScale.getSystemScaleFactor( getGraphicsConfiguration() );
|
double systemScaleFactor = UIScale.getSystemScaleFactor( getGraphicsConfiguration() );
|
||||||
float userScaleFactor = UIScale.getUserScaleFactor();
|
float userScaleFactor = UIScale.getUserScaleFactor();
|
||||||
infoLabel.setText( "(Java " + System.getProperty( "java.version" )
|
String newInfo = "(Java " + System.getProperty( "java.version" )
|
||||||
+ (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" : "")
|
||||||
+ ")" );
|
+ ")";
|
||||||
|
|
||||||
|
if( !newInfo.equals( infoLabel.getText() ) )
|
||||||
|
infoLabel.setText( newInfo );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerSwitchToLookAndFeel( int keyCode, String lafClassName ) {
|
private void registerSwitchToLookAndFeel( int keyCode, String lafClassName ) {
|
||||||
@@ -161,11 +182,8 @@ class ControlBar
|
|||||||
// change look and feel
|
// change look and feel
|
||||||
UIManager.setLookAndFeel( newLaf.className );
|
UIManager.setLookAndFeel( newLaf.className );
|
||||||
|
|
||||||
// update info label because user scale factor may change
|
|
||||||
updateInfoLabel();
|
|
||||||
|
|
||||||
// update all components
|
// update all components
|
||||||
SwingUtilities.updateComponentTreeUI( frame );
|
FlatLaf.updateUI();
|
||||||
|
|
||||||
// increase size of frame if necessary
|
// increase size of frame if necessary
|
||||||
int width = frame.getWidth();
|
int width = frame.getWidth();
|
||||||
|
|||||||
@@ -46,11 +46,7 @@ public class FlatLafDemo
|
|||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
|
|
||||||
// fallback
|
// fallback
|
||||||
try {
|
FlatLightLaf.install();
|
||||||
UIManager.setLookAndFeel( new FlatLightLaf() );
|
|
||||||
} catch( Exception ex2 ) {
|
|
||||||
ex2.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// create frame
|
// create frame
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 43 KiB After Width: | Height: | Size: 43 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 42 KiB After Width: | Height: | Size: 42 KiB |
Reference in New Issue
Block a user