Simplify the theme setup code
This commit is contained in:
parent
6b7d19dadb
commit
0fd6bcdad3
57
pom.xml
57
pom.xml
|
@ -28,6 +28,7 @@
|
||||||
<okhttp.version>4.9.3</okhttp.version>
|
<okhttp.version>4.9.3</okhttp.version>
|
||||||
<flatlaf.version>2.0</flatlaf.version>
|
<flatlaf.version>2.0</flatlaf.version>
|
||||||
<flatlaf-extras.version>2.0</flatlaf-extras.version>
|
<flatlaf-extras.version>2.0</flatlaf-extras.version>
|
||||||
|
<flatlaf-intellij-themes.version>2.0</flatlaf-intellij-themes.version>
|
||||||
<hutool-all.version>5.7.16</hutool-all.version>
|
<hutool-all.version>5.7.16</hutool-all.version>
|
||||||
<fastjson.version>1.2.78</fastjson.version>
|
<fastjson.version>1.2.78</fastjson.version>
|
||||||
<oshi-core.version>6.1.0</oshi-core.version>
|
<oshi-core.version>6.1.0</oshi-core.version>
|
||||||
|
@ -104,6 +105,12 @@
|
||||||
<version>${flatlaf-extras.version}</version>
|
<version>${flatlaf-extras.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.formdev</groupId>
|
||||||
|
<artifactId>flatlaf-intellij-themes</artifactId>
|
||||||
|
<version>${flatlaf-intellij-themes.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.hutool</groupId>
|
<groupId>cn.hutool</groupId>
|
||||||
<artifactId>hutool-all</artifactId>
|
<artifactId>hutool-all</artifactId>
|
||||||
|
@ -160,7 +167,7 @@
|
||||||
|
|
||||||
<!-- setup generation properties -->
|
<!-- setup generation properties -->
|
||||||
<setupMode>installForAllUsers</setupMode>
|
<setupMode>installForAllUsers</setupMode>
|
||||||
<createDesktopIconTask>true</createDesktopIconTask>
|
<createDesktopIconTask>true</createDesktopIconTask>
|
||||||
<disableDirPage>false</disableDirPage>
|
<disableDirPage>false</disableDirPage>
|
||||||
<disableFinishedPage>false</disableFinishedPage>
|
<disableFinishedPage>false</disableFinishedPage>
|
||||||
<setupLanguages>
|
<setupLanguages>
|
||||||
|
@ -170,30 +177,30 @@
|
||||||
</winConfig>
|
</winConfig>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
<!-- <execution>-->
|
<!-- <execution>-->
|
||||||
<!-- <id>bundling-for-linux</id>-->
|
<!-- <id>bundling-for-linux</id>-->
|
||||||
<!-- <phase>package</phase>-->
|
<!-- <phase>package</phase>-->
|
||||||
<!-- <goals>-->
|
<!-- <goals>-->
|
||||||
<!-- <goal>package</goal>-->
|
<!-- <goal>package</goal>-->
|
||||||
<!-- </goals>-->
|
<!-- </goals>-->
|
||||||
<!-- <configuration>-->
|
<!-- <configuration>-->
|
||||||
<!-- <platform>linux</platform>-->
|
<!-- <platform>linux</platform>-->
|
||||||
<!-- <createTarball>true</createTarball>-->
|
<!-- <createTarball>true</createTarball>-->
|
||||||
<!--<!– <jdkPath>X:\\path\to\linux\jdk</jdkPath>–>-->
|
<!--<!– <jdkPath>X:\\path\to\linux\jdk</jdkPath>–>-->
|
||||||
<!-- </configuration>-->
|
<!-- </configuration>-->
|
||||||
<!-- </execution>-->
|
<!-- </execution>-->
|
||||||
<!-- <execution>-->
|
<!-- <execution>-->
|
||||||
<!-- <id>bundling-for-mac</id>-->
|
<!-- <id>bundling-for-mac</id>-->
|
||||||
<!-- <phase>package</phase>-->
|
<!-- <phase>package</phase>-->
|
||||||
<!-- <goals>-->
|
<!-- <goals>-->
|
||||||
<!-- <goal>package</goal>-->
|
<!-- <goal>package</goal>-->
|
||||||
<!-- </goals>-->
|
<!-- </goals>-->
|
||||||
<!-- <configuration>-->
|
<!-- <configuration>-->
|
||||||
<!-- <platform>mac</platform>-->
|
<!-- <platform>mac</platform>-->
|
||||||
<!-- <createTarball>true</createTarball>-->
|
<!-- <createTarball>true</createTarball>-->
|
||||||
<!-- <!– <jdkPath>X:\\path\to\mac\jdk</jdkPath>–>-->
|
<!-- <!– <jdkPath>X:\\path\to\mac\jdk</jdkPath>–>-->
|
||||||
<!-- </configuration>-->
|
<!-- </configuration>-->
|
||||||
<!-- </execution>-->
|
<!-- </execution>-->
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package com.luoboduner.moo.info;
|
package com.luoboduner.moo.info;
|
||||||
|
|
||||||
import com.formdev.flatlaf.extras.FlatDesktop;
|
import com.formdev.flatlaf.extras.FlatDesktop;
|
||||||
|
import com.formdev.flatlaf.extras.FlatInspector;
|
||||||
|
import com.formdev.flatlaf.extras.FlatUIDefaultsInspector;
|
||||||
import com.formdev.flatlaf.util.SystemInfo;
|
import com.formdev.flatlaf.util.SystemInfo;
|
||||||
import com.luoboduner.moo.info.ui.Init;
|
import com.luoboduner.moo.info.ui.Init;
|
||||||
import com.luoboduner.moo.info.ui.dialog.AboutDialog;
|
import com.luoboduner.moo.info.ui.dialog.AboutDialog;
|
||||||
|
@ -69,6 +71,11 @@ public class App {
|
||||||
}
|
}
|
||||||
|
|
||||||
Init.initTheme();
|
Init.initTheme();
|
||||||
|
|
||||||
|
// install inspectors
|
||||||
|
FlatInspector.install( "ctrl shift alt X" );
|
||||||
|
FlatUIDefaultsInspector.install( "ctrl shift alt Y" );
|
||||||
|
|
||||||
mainFrame = new MainFrame();
|
mainFrame = new MainFrame();
|
||||||
mainFrame.init();
|
mainFrame.init();
|
||||||
JPanel loadingPanel = new LoadingForm().getLoadingPanel();
|
JPanel loadingPanel = new LoadingForm().getLoadingPanel();
|
||||||
|
|
|
@ -3,9 +3,11 @@ package com.luoboduner.moo.info.ui;
|
||||||
import cn.hutool.core.thread.ThreadUtil;
|
import cn.hutool.core.thread.ThreadUtil;
|
||||||
import cn.hutool.log.Log;
|
import cn.hutool.log.Log;
|
||||||
import cn.hutool.log.LogFactory;
|
import cn.hutool.log.LogFactory;
|
||||||
import com.formdev.flatlaf.FlatLightLaf;
|
import com.formdev.flatlaf.*;
|
||||||
import com.formdev.flatlaf.IntelliJTheme;
|
|
||||||
import com.formdev.flatlaf.extras.FlatSVGIcon;
|
import com.formdev.flatlaf.extras.FlatSVGIcon;
|
||||||
|
import com.formdev.flatlaf.intellijthemes.FlatCyanLightIJTheme;
|
||||||
|
import com.formdev.flatlaf.intellijthemes.FlatDarkPurpleIJTheme;
|
||||||
|
import com.formdev.flatlaf.intellijthemes.FlatLightFlatIJTheme;
|
||||||
import com.luoboduner.moo.info.App;
|
import com.luoboduner.moo.info.App;
|
||||||
import com.luoboduner.moo.info.ui.component.TopMenuBar;
|
import com.luoboduner.moo.info.ui.component.TopMenuBar;
|
||||||
import com.luoboduner.moo.info.ui.form.*;
|
import com.luoboduner.moo.info.ui.form.*;
|
||||||
|
@ -13,7 +15,6 @@ import com.luoboduner.moo.info.util.SystemUtil;
|
||||||
import com.luoboduner.moo.info.util.UIUtil;
|
import com.luoboduner.moo.info.util.UIUtil;
|
||||||
import com.luoboduner.moo.info.util.UpgradeUtil;
|
import com.luoboduner.moo.info.util.UpgradeUtil;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import javax.swing.plaf.FontUIResource;
|
import javax.swing.plaf.FontUIResource;
|
||||||
|
@ -86,24 +87,6 @@ public class Init {
|
||||||
* init look and feel
|
* init look and feel
|
||||||
*/
|
*/
|
||||||
public static void initTheme() {
|
public static void initTheme() {
|
||||||
if (SystemUtil.isMacM1()) {
|
|
||||||
try {
|
|
||||||
UIManager.setLookAndFeel("com.formdev.flatlaf.FlatDarculaLaf");
|
|
||||||
logger.warn("FlatDarculaLaf theme set.");
|
|
||||||
} catch (Exception e) {
|
|
||||||
try {
|
|
||||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
|
||||||
} catch (Exception e2) {
|
|
||||||
logger.error(ExceptionUtils.getStackTrace(e2));
|
|
||||||
}
|
|
||||||
logger.error(ExceptionUtils.getStackTrace(e));
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (App.config.isUnifiedBackground()) {
|
|
||||||
UIManager.put("TitlePane.unifiedBackground", true);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
switch (App.config.getTheme()) {
|
switch (App.config.getTheme()) {
|
||||||
|
@ -111,92 +94,43 @@ public class Init {
|
||||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||||
break;
|
break;
|
||||||
case "Flat Light":
|
case "Flat Light":
|
||||||
if (SystemUtil.isJBR()) {
|
FlatLightLaf.setup();
|
||||||
JFrame.setDefaultLookAndFeelDecorated(true);
|
|
||||||
JDialog.setDefaultLookAndFeelDecorated(true);
|
|
||||||
}
|
|
||||||
FlatLightLaf.install();
|
|
||||||
break;
|
break;
|
||||||
case "Flat IntelliJ":
|
case "Flat IntelliJ":
|
||||||
if (SystemUtil.isJBR()) {
|
FlatIntelliJLaf.setup();
|
||||||
JFrame.setDefaultLookAndFeelDecorated(true);
|
|
||||||
JDialog.setDefaultLookAndFeelDecorated(true);
|
|
||||||
}
|
|
||||||
UIManager.setLookAndFeel("com.formdev.flatlaf.FlatIntelliJLaf");
|
|
||||||
break;
|
break;
|
||||||
case "Flat Dark":
|
case "Flat Dark":
|
||||||
if (SystemUtil.isJBR()) {
|
FlatDarkLaf.setup();
|
||||||
JFrame.setDefaultLookAndFeelDecorated(true);
|
|
||||||
JDialog.setDefaultLookAndFeelDecorated(true);
|
|
||||||
}
|
|
||||||
UIManager.setLookAndFeel("com.formdev.flatlaf.FlatDarkLaf");
|
|
||||||
break;
|
|
||||||
case "Darcula":
|
|
||||||
case "Darcula(Recommended)":
|
|
||||||
case "Flat Darcula(Recommended)":
|
|
||||||
if (SystemUtil.isJBR()) {
|
|
||||||
JFrame.setDefaultLookAndFeelDecorated(true);
|
|
||||||
JDialog.setDefaultLookAndFeelDecorated(true);
|
|
||||||
}
|
|
||||||
UIManager.setLookAndFeel("com.formdev.flatlaf.FlatDarculaLaf");
|
|
||||||
|
|
||||||
UIManager.put("PopupMenu.background", UIManager.getColor("Panel.background"));
|
|
||||||
|
|
||||||
/**
|
|
||||||
If you don't like/want it, you can disable it with:
|
|
||||||
UIManager.put( "TitlePane.useWindowDecorations", false );
|
|
||||||
|
|
||||||
It is also possible to disable only the embedded menu bar (and keep the dark title pane) with:
|
|
||||||
UIManager.put( "TitlePane.menuBarEmbedded", false );
|
|
||||||
|
|
||||||
It is also possible to disable this on command line with following VM options:
|
|
||||||
-Dflatlaf.useWindowDecorations=false
|
|
||||||
-Dflatlaf.menuBarEmbedded=false
|
|
||||||
|
|
||||||
If you have following code in your app, you can remove it (no longer necessary):
|
|
||||||
// enable window decorations
|
|
||||||
JFrame.setDefaultLookAndFeelDecorated( true );
|
|
||||||
JDialog.setDefaultLookAndFeelDecorated( true );
|
|
||||||
**/
|
|
||||||
break;
|
break;
|
||||||
case "Dark purple":
|
case "Dark purple":
|
||||||
if (SystemUtil.isJBR()) {
|
FlatDarkPurpleIJTheme.setup();
|
||||||
JFrame.setDefaultLookAndFeelDecorated(true);
|
|
||||||
JDialog.setDefaultLookAndFeelDecorated(true);
|
|
||||||
}
|
|
||||||
IntelliJTheme.setup(App.class.getResourceAsStream(
|
|
||||||
"/theme/DarkPurple.theme.json"));
|
|
||||||
break;
|
break;
|
||||||
case "IntelliJ Cyan":
|
case "IntelliJ Cyan":
|
||||||
if (SystemUtil.isJBR()) {
|
FlatCyanLightIJTheme.setup();
|
||||||
JFrame.setDefaultLookAndFeelDecorated(true);
|
|
||||||
JDialog.setDefaultLookAndFeelDecorated(true);
|
|
||||||
}
|
|
||||||
IntelliJTheme.setup(App.class.getResourceAsStream(
|
|
||||||
"/theme/Cyan.theme.json"));
|
|
||||||
break;
|
break;
|
||||||
case "IntelliJ Light":
|
case "IntelliJ Light":
|
||||||
if (SystemUtil.isJBR()) {
|
FlatLightFlatIJTheme.setup();
|
||||||
JFrame.setDefaultLookAndFeelDecorated(true);
|
|
||||||
JDialog.setDefaultLookAndFeelDecorated(true);
|
|
||||||
}
|
|
||||||
IntelliJTheme.setup(App.class.getResourceAsStream(
|
|
||||||
"/theme/Light.theme.json"));
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (SystemUtil.isJBR()) {
|
FlatDarculaLaf.setup();
|
||||||
JFrame.setDefaultLookAndFeelDecorated(true);
|
|
||||||
JDialog.setDefaultLookAndFeelDecorated(true);
|
|
||||||
}
|
|
||||||
UIManager.setLookAndFeel("com.formdev.flatlaf.FlatDarculaLaf");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (UIUtil.isDarkLaf()) {
|
if (UIUtil.isDarkLaf()) {
|
||||||
// FlatSVGIcon.ColorFilter.getInstance().setMapper(color -> color.brighter().brighter());
|
// FlatSVGIcon.ColorFilter.getInstance().setMapper(color -> color.brighter().brighter());
|
||||||
} else {
|
} else {
|
||||||
FlatSVGIcon.ColorFilter.getInstance().setMapper(color -> color.darker().darker());
|
FlatSVGIcon.ColorFilter.getInstance().setMapper(color -> color.darker().darker());
|
||||||
|
// SwingUtilities.windowForComponent(App.mainFrame).repaint();
|
||||||
}
|
}
|
||||||
// SwingUtilities.windowForComponent(App.mainFrame).repaint();
|
|
||||||
|
if (App.config.isUnifiedBackground()) {
|
||||||
|
UIManager.put("TitlePane.unifiedBackground", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// top menubar background
|
||||||
|
UIManager.put("PopupMenu.background", UIManager.getColor("Panel.background"));
|
||||||
|
// arrow type
|
||||||
|
UIManager.put("Component.arrowType", "chevron");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error(e);
|
logger.error(e);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue