Skip to content

Commit

Permalink
Feature: Look and Feel Plugin: Dark theme for the Nimbus look and feel.
Browse files Browse the repository at this point in the history
  The theme is based on Wayne Zhang's pull request
  #12
  and was integrated into SQuirreL's Look and Feel Plugin.
  Thanks to Wayne Zhang for the theme.
  • Loading branch information
gerdwagner committed Jul 11, 2023
1 parent a696ed1 commit dc29e02
Show file tree
Hide file tree
Showing 5 changed files with 328 additions and 21 deletions.
6 changes: 6 additions & 0 deletions sql12/core/doc/changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ Not yet released, available in our GIT repository, snapshots and future releases

Enhancements:

Look and Feel Plugin: Dark theme for the Nimbus look and feel.
The theme is based on Wayne Zhang's pull request
https://github.com/squirrel-sql-client/squirrel-sql-code/pull/12
and was integrated into SQuirreL's Look and Feel Plugin.
Thanks to Wayne Zhang for the theme.

#156 The table cell data popup and the Object tree source tabs support searching.
See the find button at the lower right of the table cell data popup.
See the find bar at the bottom of the Object tree source tabs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,22 @@
import net.sourceforge.squirrel_sql.client.IApplication;
import net.sourceforge.squirrel_sql.client.plugin.PluginResources;
import net.sourceforge.squirrel_sql.fw.gui.FontInfo;
import net.sourceforge.squirrel_sql.fw.util.FileWrapper;
import net.sourceforge.squirrel_sql.fw.util.FileWrapperFactory;
import net.sourceforge.squirrel_sql.fw.util.FileWrapperFactoryImpl;
import net.sourceforge.squirrel_sql.fw.util.SquirrelLookAndFeelHandler;
import net.sourceforge.squirrel_sql.fw.util.SquirrelURLClassLoader;
import net.sourceforge.squirrel_sql.fw.util.Utilities;
import net.sourceforge.squirrel_sql.fw.util.*;
import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
import net.sourceforge.squirrel_sql.plugins.laf.flatlaf.FlatLookAndFeelController;
import net.sourceforge.squirrel_sql.plugins.laf.jtattoo.JTattooLookAndFeelController;
import net.sourceforge.squirrel_sql.plugins.laf.nimbus.NimbusLookAndFeelController;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.LookAndFeel;
import javax.swing.SwingUtilities;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.*;
import javax.swing.UIManager.LookAndFeelInfo;
import java.awt.Frame;
import java.awt.*;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.Properties;
import java.util.*;

/**
* Register of Look and Feels.
Expand Down Expand Up @@ -411,6 +395,7 @@ private void installLookAndFeelControllers(LAFPlugin plugin)
{
s_log.error("Error installing SkinLookAndFeelController", ex);
}

try
{
PlasticLookAndFeelController ctrl = new PlasticLookAndFeelController(plugin, this);
Expand All @@ -424,6 +409,7 @@ private void installLookAndFeelControllers(LAFPlugin plugin)
{
s_log.error("Error installing PlasticLookAndFeelController", ex);
}

try
{
MetalLookAndFeelController ctrl = new MetalLookAndFeelController(plugin, this);
Expand All @@ -433,6 +419,17 @@ private void installLookAndFeelControllers(LAFPlugin plugin)
{
s_log.error("Error installing PlasticLookAndFeelController", ex);
}

try
{
NimbusLookAndFeelController ctrl = new NimbusLookAndFeelController(plugin, this);
_lafControllers.put(NimbusLookAndFeelController.NIMBUS_LAF_CLASS_NAME, ctrl);
}
catch (Throwable ex)
{
s_log.error("Error installing PlasticLookAndFeelController", ex);
}

try
{
_lafControllers.put(TonicLookAndFeelController.TONIC_LAF_CLASS_NAME, new TonicLookAndFeelController(
Expand All @@ -442,6 +439,7 @@ private void installLookAndFeelControllers(LAFPlugin plugin)
{
s_log.error("Error installing SkinLookAndFeelController", ex);
}

try
{
_lafControllers.put(RadianceLookAndFeelController.RADIANCE_LAF_PLACEHOLDER_CLASS_NAME,
Expand All @@ -451,6 +449,7 @@ private void installLookAndFeelControllers(LAFPlugin plugin)
{
s_log.error("Error installing SubstanceLookAndFeelController", ex);
}

try
{
_lafControllers.put(JTattooLookAndFeelController.JTATTOO_LAF_PLACEHOLDER_CLASS_NAME,
Expand All @@ -460,6 +459,7 @@ private void installLookAndFeelControllers(LAFPlugin plugin)
{
s_log.error("Error installing JTattooLookAndFeelController", ex);
}

try
{
_lafControllers.put(FlatLookAndFeelController.FLAT_LAF_PLACEHOLDER_CLASS_NAME,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
package net.sourceforge.squirrel_sql.plugins.laf.nimbus;

import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;

import javax.swing.*;
import javax.swing.plaf.nimbus.NimbusLookAndFeel;
import java.awt.*;

/**
* Encapsulate Nimbus dark theme configuration logic
*
* @author Wayne Zhang
*/
public class NimbusDarkTheme
{
private final static ILogger s_log = LoggerController.createLogger(NimbusLookAndFeelController.class);

public static void configDarkTheme()
{
if (UIManager.getLookAndFeel() instanceof NimbusLookAndFeel)
{
configColor("control", Color.gray);
configColor("info", Color.gray);
configColor("nimbusBase", new Color(18, 30, 49));
configColor("nimbusAlertYellow", new Color(248, 187, 0));
configColor("nimbusDisabledText", new Color(100, 100, 100));
configColor("nimbusFocus", new Color(115, 164, 209));
configColor("nimbusGreen", new Color(176, 179, 50));
configColor("nimbusInfoBlue", new Color(66, 139, 221));
configColor("nimbusLightBackground", new Color(18, 30, 49));
configColor("nimbusOrange", new Color(191, 98, 4));
configColor("nimbusRed", new Color(169, 46, 34));
configColor("nimbusSelectedText", Color.white);
configColor("nimbusSelectionBackground", new Color(104, 93, 156));
configColor("text", new Color(230, 230, 230));
configColor("Tree.foreground", new Color(255, 255, 255));

try
{
configTreeIcon();
}
catch (Exception e)
{
s_log.error("Failed to load JTree icons from Java's standard location", e);
}
}
}

/**
* Configure color for the given theme key, for example, disabled text. It
* will load configuration on system properties first, give it a change to
* override configuration by system properties without change this class.
*
* @param key key of the theme attribute
* @param defaultValue the default color if it is not defined by system
* property
*/
private static void configColor(String key, Color defaultValue)
{
Color color = defaultValue;
String systemPropertyColor = System.getProperty(key);
if (systemPropertyColor != null && !systemPropertyColor.isEmpty())
{
try
{
color = buildColor(systemPropertyColor);
}
catch (Exception e)
{
s_log.error("Failed to build colors. Default colors will be used", e);
}
}

UIManager.put(key, color);
}


/**
* Build Color object by parsing color value
*
* @param colorValue color value, in format (R,G,B) or R,G,B
* @return
*/
private static Color buildColor(String colorValue)
{
if (colorValue == null || colorValue.isEmpty())
{
throw new RuntimeException("Color value empty");
}

String cv = colorValue.trim();
if (cv.startsWith("("))
{
cv = cv.substring(1).trim();
}
if (cv.endsWith(")"))
{
cv = cv.substring(0, cv.length() - 1).trim();
}

String[] rgb = cv.split(",");
if (rgb.length != 3)
{
throw new RuntimeException("Color (" + colorValue + ") format error");
}

return new Color(Integer.valueOf(rgb[0].trim()),
Integer.valueOf(rgb[1].trim()),
Integer.valueOf(rgb[2].trim())
);
}

/**
* Rest theme to system default
*
* @param window parent window need to refresh when theme changed.
*/
public static void resetDefaultTheme(Window window)
{
if (UIManager.getLookAndFeel() instanceof NimbusLookAndFeel)
{
SwingUtilities.invokeLater(() ->
{
UIManager.getDefaults().putAll(UIManager.getLookAndFeel().getDefaults());

// referesh Window to apply the theme change!
SwingUtilities.updateComponentTreeUI(window);
});
}
}

/**
* NetBeans project/files tree expand/close icon color is too dark, it is
* not visible almost.
* <p>
* Set to icons copied from Eclipse dark mode.
*/
private static void configTreeIcon()
{
// clear the default, default value used for unknow reason
UIManager.getDefaults().remove("Tree.collapsedIcon");
UIManager.getDefaults().remove("Tree.expandedIcon");

UIManager.put("Tree.collapsedIcon", loadImage("close.gif"));
UIManager.put("Tree.expandedIcon", loadImage("open.gif"));
}

private static ImageIcon loadImage(String file)
{
//URL fileUrl = NimbusDarkTheme.class.getResource(file);
//
//return new ImageIcon(fileUrl);

return new ImageIcon(file);
}
}
Loading

0 comments on commit dc29e02

Please sign in to comment.