Skip to content

Commit

Permalink
FlatPropertiesLaf: support macOS themes as base themes
Browse files Browse the repository at this point in the history
  • Loading branch information
DevCharly committed Dec 4, 2024
1 parent e9a2184 commit 7e59a7f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ FlatLaf Change Log
- Linux: Fixed slightly different font size (or letter width) used to paint HTML
text when default font family is _Cantarell_ (e.g. on Fedora). (issue #912)

#### Other Changes

- Class `FlatPropertiesLaf` now supports FlatLaf macOS themes as base themes.


## 3.5.2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
import java.util.ArrayList;
import java.util.Locale;
import java.util.Properties;
import com.formdev.flatlaf.themes.FlatMacDarkLaf;
import com.formdev.flatlaf.themes.FlatMacLightLaf;

/**
* A Flat LaF that is able to load UI defaults from properties passed to the constructor.
* <p>
* Specify the base theme in the properties with {@code @baseTheme=<baseTheme>}.
* Allowed values for {@code <baseTheme>} are {@code light} (the default), {@code dark},
* {@code intellij} or {@code darcula}.
* {@code intellij}, {@code darcula}, {@code maclight} or {@code macdark}.
* <p>
* The properties are applied after loading the base theme and may overwrite base properties.
* All features of FlatLaf properties files are available.
Expand Down Expand Up @@ -71,7 +73,8 @@ public FlatPropertiesLaf( String name, Properties properties ) {
this.properties = properties;

baseTheme = properties.getProperty( "@baseTheme", "light" );
dark = "dark".equalsIgnoreCase( baseTheme ) || "darcula".equalsIgnoreCase( baseTheme );
dark = "dark".equalsIgnoreCase( baseTheme ) || "darcula".equalsIgnoreCase( baseTheme ) ||
"macdark".equalsIgnoreCase( baseTheme );
}

@Override
Expand Down Expand Up @@ -116,6 +119,16 @@ protected ArrayList<Class<?>> getLafClassesForDefaultsLoading() {
lafClasses.add( FlatDarkLaf.class );
lafClasses.add( FlatDarculaLaf.class );
break;

case "maclight":
lafClasses.add( FlatLightLaf.class );
lafClasses.add( FlatMacLightLaf.class );
break;

case "macdark":
lafClasses.add( FlatDarkLaf.class );
lafClasses.add( FlatMacDarkLaf.class );
break;
}
return lafClasses;
}
Expand Down
2 changes: 1 addition & 1 deletion flatlaf-demo/DemoLaf.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# when the Demo window is activated.


# base theme (light, dark, intellij or darcula)
# base theme (light, dark, intellij, darcula, maclight or macdark)
@baseTheme = light

# add you theme defaults here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ Set<String> getAllKeys() {
}

static boolean isDark( String baseTheme ) {
return "dark".equals( baseTheme ) || "darcula".equals( baseTheme );
return "dark".equals( baseTheme ) || "darcula".equals( baseTheme ) || "macdark".equals( baseTheme );
}

private String getBaseTheme() {
Expand Down

0 comments on commit 7e59a7f

Please sign in to comment.