Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
<!-- NB: Deploy releases to the SciJava Maven repository. -->
<releaseProfiles>sign,deploy-to-scijava</releaseProfiles>

<flatlaf.version>2.4</flatlaf.version>
<jdatepicker.version>1.3.2</jdatepicker.version>
<object-inspector.version>0.1</object-inspector.version>
</properties>
Expand Down Expand Up @@ -157,6 +158,11 @@
<groupId>org.jfree</groupId>
<artifactId>jfreesvg</artifactId>
</dependency>
<dependency>
<groupId>com.formdev</groupId>
<artifactId>flatlaf</artifactId>
<version>${flatlaf.version}</version>
</dependency>
<dependency>
<groupId>com.github.sbridges.object-inspector</groupId>
<artifactId>object-inspector</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.UnsupportedLookAndFeelException;

import com.formdev.flatlaf.FlatLightLaf;
import com.formdev.flatlaf.FlatDarkLaf;
import com.formdev.flatlaf.FlatIntelliJLaf;
import com.formdev.flatlaf.FlatDarculaLaf;

import org.scijava.display.Display;
import org.scijava.display.DisplayService;
import org.scijava.log.LogService;
Expand Down Expand Up @@ -131,8 +136,15 @@ public void run() {

protected void initLookAndFeel() {
final String lafClass = UIManager.getLookAndFeel().getClass().getName();
LookAndFeelInfo[] lookAndFeels = UIManager.getInstalledLookAndFeels();

// Make UIManager aware of FlatLaf look and feels, as needed
if (!isRegistered(lookAndFeels, FlatLightLaf.NAME)) FlatLightLaf.installLafInfo();
if (!isRegistered(lookAndFeels, FlatDarkLaf.NAME)) FlatDarkLaf.installLafInfo();
if (!isRegistered(lookAndFeels, FlatDarculaLaf.NAME)) FlatDarculaLaf.installLafInfo();
if (!isRegistered(lookAndFeels, FlatIntelliJLaf.NAME)) FlatIntelliJLaf.installLafInfo();
lookAndFeels = UIManager.getInstalledLookAndFeels(); // retrieve updated list

final LookAndFeelInfo[] lookAndFeels = UIManager.getInstalledLookAndFeels();
final ArrayList<String> lookAndFeelChoices = new ArrayList<>();
for (final LookAndFeelInfo lafInfo : lookAndFeels) {
final String lafName = lafInfo.getName();
Expand All @@ -149,6 +161,15 @@ protected void initLookAndFeel() {

// -- Helper methods --

/** Assesses whether lookAndFeels contains the laf associated with lafName*/
private boolean isRegistered(final LookAndFeelInfo[] lookAndFeels, final String lafName) {
for (final LookAndFeelInfo lafInfo : lookAndFeels) {
if (lafInfo.getName().equals(lafName))
return true;
}
return false;
}

/** Tells all known Swing components to change to the new Look &amp; Feel. */
private void refreshSwingComponents() {
// TODO: Change this hacky logic to call a clean UIService API
Expand Down Expand Up @@ -202,6 +223,41 @@ private DisplayService displayService() {
return getContext().service(DisplayService.class);
}

/**
* Sets the application look and feel.
* <p>
* Useful for setting up the look and feel early on in application startup
* routine (e.g., through a macro or script)
* </p>
*
* @param lookAndFeel the look and feel. Supported values include "FlatLaf
* Light", "FlatLaf Dark", "FlatLaf Darcula", "FlatLaf
* IntelliJ", and JVM defaults
* ("javax.swing.plaf.metal.MetalLookAndFeel", etc.)
*/
public static void setupLookAndFeel(final String lookAndFeel) {
switch (lookAndFeel) {
case FlatLightLaf.NAME:
FlatLightLaf.setup();
return;
case FlatDarkLaf.NAME:
FlatDarkLaf.setup();
return;
case FlatDarculaLaf.NAME:
FlatDarculaLaf.setup();
return;
case FlatIntelliJLaf.NAME:
FlatIntelliJLaf.setup();
return;
default:
try {
UIManager.setLookAndFeel(lookAndFeel);
} catch (final Exception ex) {
ex.printStackTrace();
}
}
}

// -- Deprecated methods --

@Deprecated
Expand Down