Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-1981 - Checkpoint - Added an action to show the current theme states for the hovered item

ghidragon164fe7b5b623
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/gui/ThemeManagerPlugin.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/gui/ThemeManagerPlugin.java
index 0189241c05..67cc09949d 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/gui/ThemeManagerPlugin.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/gui/ThemeManagerPlugin.java
@@ -15,17 +15,17 @@
*/
package ghidra.app.plugin.gui;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
+import java.util.stream.Collectors;
import docking.action.builder.ActionBuilder;
import docking.options.editor.StringWithChoicesEditor;
-import docking.theme.*;
+import docking.theme.GTheme;
+import docking.theme.Gui;
import docking.theme.gui.GThemeDialog;
import docking.tool.ToolConstants;
import ghidra.app.CorePluginPackage;
import ghidra.app.plugin.PluginCategoryNames;
-import ghidra.docking.util.LookAndFeelUtils;
import ghidra.framework.main.FrontEndOnly;
import ghidra.framework.main.FrontEndTool;
import ghidra.framework.options.*;
@@ -61,9 +61,6 @@ public class ThemeManagerPlugin extends Plugin implements FrontEndOnly, OptionsC
@Override
protected void init() {
- new ActionBuilder("Dump UI Properties", getName()).menuPath("Edit", "Dump UI Properies")
- .onAction(e -> LookAndFeelUtils.dumpUIProperties())
- .buildAndInstall(tool);
new ActionBuilder("Show Properties", getName()).menuPath("Edit", "Theme Properties")
.onAction(e -> showThemeProperties())
@@ -81,7 +78,10 @@ public class ThemeManagerPlugin extends Plugin implements FrontEndOnly, OptionsC
ToolOptions opt = tool.getOptions(OPTIONS_TITLE);
GTheme activeTheme = Gui.getActiveTheme();
- List<String> themeNames = Gui.getAllThemeNames();
+ Set<GTheme> themes = Gui.getSupportedThemes();
+ List<String> themeNames =
+ themes.stream().map(t -> t.getName()).collect(Collectors.toList());
+ Collections.sort(themeNames);
opt.registerOption(THEME_OPTIONS_NAME, OptionType.STRING_TYPE, activeTheme.getName(),
new HelpLocation(ToolConstants.TOOL_HELP_TOPIC, "Look_And_Feel"),
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/action/ComponentThemeInspectorAction.java b/Ghidra/Framework/Docking/src/main/java/docking/action/ComponentThemeInspectorAction.java
new file mode 100644
index 0000000000..0b43938cd8
--- /dev/null
+++ b/Ghidra/Framework/Docking/src/main/java/docking/action/ComponentThemeInspectorAction.java
@@ -0,0 +1,273 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * 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 docking.action;
+
+import java.awt.*;
+import java.awt.event.KeyEvent;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import javax.swing.*;
+import javax.swing.table.TableCellRenderer;
+import javax.swing.tree.TreeCellRenderer;
+import javax.swing.tree.TreePath;
+
+import org.apache.commons.lang3.StringUtils;
+
+import docking.*;
+import ghidra.util.Msg;
+
+public class ComponentThemeInspectorAction extends DockingAction {
+
+ public ComponentThemeInspectorAction() {
+ super("Component Theme Inspector", DockingWindowManager.DOCKING_WINDOWS_OWNER, false);
+ createReservedKeyBinding(
+ KeyStroke.getKeyStroke(KeyEvent.VK_F9, DockingUtils.CONTROL_KEY_MODIFIER_MASK));
+
+ // System action; no help needed
+ DockingWindowManager.getHelpService().excludeFromHelp(this);
+ }
+
+ private Object getMouseOverObject() {
+
+ PointerInfo pointerInfo = MouseInfo.getPointerInfo();
+ Point mouseLocation = pointerInfo.getLocation();
+ Object lastObject = DockingWindowManager.getMouseOverObject();
+
+ if (!(lastObject instanceof Component)) {
+ return lastObject;
+ }
+
+ Component c = (Component) lastObject;
+ Window w;
+ if (c instanceof Window) {
+ w = (Window) c;
+ }
+ else {
+ w = SwingUtilities.windowForComponent(c);
+ }
+
+ if (w != null) {
+
+ SwingUtilities.convertPointFromScreen(mouseLocation, w);
+ Component deepestComponent =
+ SwingUtilities.getDeepestComponentAt(w, mouseLocation.x, mouseLocation.y);
+ if (deepestComponent != null) {
+ return deepestComponent;
+ }
+ }
+
+ return lastObject;
+ }
+
+ @Override
+ public void actionPerformed(ActionContext context) {
+
+ Object object = getMouseOverObject();
+ if (!(object instanceof Component)) {
+ Msg.debug(this, "Mouse not over a component: " + object);
+ return;
+ }
+
+ Entry entry = null;
+ Component component = (Component) object;
+ List<Entry> tree = new ArrayList<>();
+ while (component != null) {
+
+ Entry next;
+ if (component instanceof JTable) {
+ next = new TableEntry((JTable) component);
+ }
+ else if (component instanceof JTree) {
+ next = new TreeEntry((JTree) component);
+ }
+ else {
+ next = new Entry(component);
+ }
+
+ if (entry != null) {
+ entry.parent = next;
+ }
+ entry = next;
+
+ tree.add(entry);
+ component = component.getParent();
+ }
+
+ Collections.reverse(tree);
+
+ StringBuilder buffy = new StringBuilder("\n");
+ for (int i = 0; i < tree.size() - 1; i++) {
+ Entry e = tree.get(i);
+ e.toString(buffy, i + 1); // +1 to start printing at 1, as an ordinal
+ }
+
+ buffy.append('\n');
+ Entry hoveredEntry = tree.get(tree.size() - 1);
+ hoveredEntry.toString(buffy, 0); // no indent for the hovered item so it is easy to see
+ buffy.append('\n');
+ Msg.debug(this, buffy);
+ }
+
+ private void print(StringBuilder buffy, Component component, int indent) {
+
+ Color bg = component.getBackground();
+ Color fg = component.getForeground();
+ String id;
+ String clazz = component.getClass().getSimpleName();
+ if (clazz.isEmpty()) {
+ clazz = component.getClass().getName();
+ }
+ String name = component.getName();
+ if (name == null) {
+ id = clazz;
+ }
+ else {
+ id = clazz + "; name = " + name;
+ }
+
+ String indentMarker = "";
+ String spacer = "";
+ if (indent > 0) {
+ indentMarker = Integer.toString(indent) + ") ";
+
+ String asString = Integer.toString(indent);
+ int length = asString.length();
+ spacer = StringUtils.repeat(' ', length + 2); // +2 for the text ") "
+ }
+ else {
+ // no indent; custom spacing of attributes
+ spacer = "\t";
+ }
+
+ String tabs = '\n' + StringUtils.repeat(' ', (indent * 3));
+ buffy.append(tabs)
+ .append(indentMarker)
+ .append(id)
+ .append(tabs)
+ .append(spacer)
+ .append("bg: ")
+ .append(bg)
+ .append(tabs)
+ .append(spacer)
+ .append("fg: ")
+ .append(fg)
+ .append('\n');
+ }
+
+ private void debugComponent(Component component) {
+ // stub for debugging
+ }
+
+ private void debugTable(TableCellRenderer renderer, Component component,
+ Component rendererComponent) {
+ // stub for debugging
+ }
+
+ @Override
+ public boolean isEnabledForContext(ActionContext context) {
+ return true;
+ }
+
+ private class Entry {
+
+ private Entry parent;
+ protected Component component;
+ protected Point mouseLocation;
+
+ Entry(Component component) {
+ this.component = component;
+
+ PointerInfo pointerInfo = MouseInfo.getPointerInfo();
+ mouseLocation = pointerInfo.getLocation();
+ SwingUtilities.convertPointFromScreen(mouseLocation, component);
+ }
+
+ public void toString(StringBuilder buffy, int indent) {
+ debugComponent(component);
+ print(buffy, component, indent);
+ }
+
+ protected boolean isLeaf(int indent) {
+ return indent == 0;
+ }
+ }
+
+ private class TableEntry extends Entry {
+ private JTable table;
+
+ TableEntry(JTable table) {
+ super(table);
+ this.table = table;
+ }
+
+ @Override
+ public void toString(StringBuilder buffy, int indent) {
+ print(buffy, component, indent);
+
+ if (!isLeaf(indent)) {
+ return;
+ }
+
+ // print extra data for the leaf component, as that is the hovered component
+ int row = table.rowAtPoint(mouseLocation);
+ int col = table.columnAtPoint(mouseLocation);
+
+ if (row != -1 && col != -1) {
+ TableCellRenderer renderer = table.getCellRenderer(row, col);
+ Component rendererComponent = table.prepareRenderer(renderer, row, col);
+ debugTable(renderer, component, rendererComponent);
+
+ print(buffy, rendererComponent, indent);
+ }
+ }
+ }
+
+ private class TreeEntry extends Entry {
+ private JTree tree;
+
+ TreeEntry(JTree tree) {
+ super(tree);
+ this.tree = tree;
+ }
+
+ @Override
+ public void toString(StringBuilder buffy, int indent) {
+ print(buffy, component, indent);
+
+ if (!isLeaf(indent)) {
+ return;
+ }
+
+ // print extra data for the leaf component, as that is the hovered component
+ TreeCellRenderer renderer = tree.getCellRenderer();
+ int row = tree.getClosestRowForLocation(mouseLocation.x, mouseLocation.y);
+
+ if (row != -1) {
+ TreePath path = tree.getPathForRow(row);
+ Object pathValue = path.getLastPathComponent();
+ Component rendererComponent =
+ renderer.getTreeCellRendererComponent(tree, pathValue, tree.isRowSelected(row),
+ tree.isExpanded(row), tree.getModel().isLeaf(pathValue), row,
+ true);
+
+ print(buffy, rendererComponent, indent);
+ }
+ }
+
+ }
+}
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/actions/ToolActions.java b/Ghidra/Framework/Docking/src/main/java/docking/actions/ToolActions.java
index 7a7d2ebd00..56eac03a77 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/actions/ToolActions.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/actions/ToolActions.java
@@ -99,6 +99,7 @@ public class ToolActions implements DockingToolActions, PropertyChangeListener {
if (SystemUtilities.isInDevelopmentMode()) {
keyBindingsManager.addReservedAction(new ShowFocusInfoAction());
keyBindingsManager.addReservedAction(new ShowFocusCycleAction());
+ keyBindingsManager.addReservedAction(new ComponentThemeInspectorAction());
}
}
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/theme/DefaultTheme.java b/Ghidra/Framework/Docking/src/main/java/docking/theme/DefaultTheme.java
index 2a4328a5a0..fb1d4e5cd4 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/theme/DefaultTheme.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/theme/DefaultTheme.java
@@ -15,11 +15,9 @@
*/
package docking.theme;
-import ghidra.docking.util.LookAndFeelUtils;
-
public class DefaultTheme extends DiscoverableGTheme {
public DefaultTheme() {
- super("Default", LookAndFeelUtils.getDefaultLookAndFeelName());
+ super("Default", LookAndFeelType.SYSTEM);
}
}
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/theme/DiscoverableGTheme.java b/Ghidra/Framework/Docking/src/main/java/docking/theme/DiscoverableGTheme.java
index aa4ff910e2..22084aa40b 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/theme/DiscoverableGTheme.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/theme/DiscoverableGTheme.java
@@ -20,12 +20,12 @@ import ghidra.util.classfinder.ExtensionPoint;
public abstract class DiscoverableGTheme extends GTheme implements ExtensionPoint {
static final String CLASS_PREFIX = "Class:";
- protected DiscoverableGTheme(String name, String lookAndFeelName) {
- super(name, lookAndFeelName, false);
+ protected DiscoverableGTheme(String name, LookAndFeelType lookAndFeel) {
+ super(name, lookAndFeel, false);
}
- protected DiscoverableGTheme(String name, String lookAndFeelName, boolean isDark) {
- super(name, lookAndFeelName, isDark);
+ protected DiscoverableGTheme(String name, LookAndFeelType lookAndFeel, boolean isDark) {
+ super(name, lookAndFeel, isDark);
}
@Override
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/theme/FileGTheme.java b/Ghidra/Framework/Docking/src/main/java/docking/theme/FileGTheme.java
index 9a6286091e..c3a7064aef 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/theme/FileGTheme.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/theme/FileGTheme.java
@@ -27,7 +27,7 @@ public class FileGTheme extends GTheme {
}
FileGTheme(File file, ThemeReader reader) {
- super(reader.getThemeName(), reader.getLookAndFeelName(), reader.isDark());
+ super(reader.getThemeName(), reader.getLookAndFeelType(), reader.isDark());
this.file = file;
reader.loadValues(this);
}
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/theme/GColor.java b/Ghidra/Framework/Docking/src/main/java/docking/theme/GColor.java
index 824e55beae..32f36b7a09 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/theme/GColor.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/theme/GColor.java
@@ -28,6 +28,7 @@ public class GColor extends Color implements Refreshable {
private static WeakStore<GColor> inUseColors = new WeakStore<>();
private String id;
private Color delegate;
+ private Short alpha;
public static void refreshAll() {
for (GColor gcolor : inUseColors.getValues()) {
@@ -49,12 +50,12 @@ public class GColor extends Color implements Refreshable {
private GColor(String id, int alpha) {
this(id);
-
+ this.alpha = (short) alpha;
delegate = new Color(delegate.getRed(), delegate.getGreen(), delegate.getBlue(), alpha);
}
- public GColor withAlpha(int alpha) {
- return new GColor(id, alpha);
+ public GColor withAlpha(int newAlpha) {
+ return new GColor(id, newAlpha);
}
public String getId() {
@@ -102,12 +103,16 @@ public class GColor extends Color implements Refreshable {
@Override
public int hashCode() {
- return id.hashCode();
+ return Objects.hash(id, alpha);
}
@Override
public String toString() {
- return getClass().getName() + " [id = " + id + ", " + delegate.toString() + "]";
+ Color c = delegate;
+ String rgb =
+ "(" + c.getRed() + "," + c.getGreen() + "," + c.getBlue() + "," + c.getAlpha() + ")";
+ return getClass().getSimpleName() + " [id = " + id + ", color = " +
+ c.getClass().getSimpleName() + rgb + "]";
}
@Override
@@ -122,7 +127,7 @@ public class GColor extends Color implements Refreshable {
return false;
}
GColor other = (GColor) obj;
- return Objects.equals(id, other.id);
+ return Objects.equals(id, other.id) && Objects.equals(alpha, other.alpha);
}
@Override
@@ -175,11 +180,12 @@ public class GColor extends Color implements Refreshable {
public void refresh() {
Color color = Gui.getRawColor(id, false);
if (color != null) {
- int alpha = delegate.getAlpha();
- delegate = new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha);
- }
- else {
- System.out.println("Hey");
+ if (alpha != null) {
+ delegate = new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha);
+ }
+ else {
+ delegate = color;
+ }
}
}
}
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/theme/GTheme.java b/Ghidra/Framework/Docking/src/main/java/docking/theme/GTheme.java
index 630129c58c..d1f28cc2ea 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/theme/GTheme.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/theme/GTheme.java
@@ -20,7 +20,6 @@ import java.awt.Font;
import java.io.*;
import java.util.*;
-import ghidra.docking.util.LookAndFeelUtils;
import ghidra.util.WebColors;
/**
@@ -33,24 +32,24 @@ public class GTheme extends GThemeValueMap {
static final String THEME_IS_DARK_KEY = "dark";
private final String name;
- private final String lookAndFeelName;
+ private final LookAndFeelType lookAndFeel;
private final boolean isDark;
public GTheme(String name) {
- this(name, LookAndFeelUtils.SYSTEM, false);
+ this(name, LookAndFeelType.SYSTEM, false);
}
/**
* Creates a new empty GTheme with the given name
* @param name the name for the new GTheme
- * @param lookAndFeelName the look and feel used by this theme
+ * @param lookAndFeel the look and feel type used by this theme
* @param isDark true if this theme uses dark backgrounds instead of the standard
* light backgrounds
*/
- protected GTheme(String name, String lookAndFeelName, boolean isDark) {
+ protected GTheme(String name, LookAndFeelType lookAndFeel, boolean isDark) {
this.name = name;
- this.lookAndFeelName = lookAndFeelName;
+ this.lookAndFeel = lookAndFeel;
this.isDark = isDark;
}
@@ -66,8 +65,8 @@ public class GTheme extends GThemeValueMap {
* Returns the name of the LookAndFeel associated with this GTheme
* @return the name of the LookAndFeel associated with this GTheme
*/
- public String getLookAndFeelName() {
- return lookAndFeelName;
+ public LookAndFeelType getLookAndFeelType() {
+ return lookAndFeel;
}
/**
@@ -162,8 +161,7 @@ public class GTheme extends GThemeValueMap {
return false;
}
GTheme other = (GTheme) obj;
- return Objects.equals(name, other.name) &&
- Objects.equals(lookAndFeelName, other.lookAndFeelName) &&
+ return Objects.equals(name, other.name) && Objects.equals(lookAndFeel, other.lookAndFeel) &&
Objects.equals(isDark, other.isDark);
}
@@ -206,7 +204,7 @@ public class GTheme extends GThemeValueMap {
writer.write(THEME_NAME_KEY + " = " + name);
writer.newLine();
- writer.write(THEME_LOOK_AND_FEEL_KEY + " = " + lookAndFeelName);
+ writer.write(THEME_LOOK_AND_FEEL_KEY + " = " + lookAndFeel.getName());
writer.newLine();
if (isDark()) {
@@ -278,4 +276,8 @@ public class GTheme extends GThemeValueMap {
}
return outputString;
}
+
+ public boolean hasSupportedLookAndFeel() {
+ return lookAndFeel.isSupported();
+ }
}
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/theme/Gui.java b/Ghidra/Framework/Docking/src/main/java/docking/theme/Gui.java
index 454ca05583..bcd1b461e0 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/theme/Gui.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/theme/Gui.java
@@ -19,13 +19,11 @@ import java.awt.*;
import java.io.*;
import java.util.*;
import java.util.List;
-import java.util.stream.Collectors;
import javax.swing.*;
import javax.swing.plaf.UIResource;
import docking.framework.ApplicationInformationDisplayFactory;
-import ghidra.docking.util.LookAndFeelUtils;
import ghidra.framework.Application;
import ghidra.framework.preferences.Preferences;
import ghidra.util.Msg;
@@ -67,7 +65,7 @@ public class Gui {
public static void initialize() {
loadThemeDefaults();
setTheme(getThemeFromPreferences());
- LookAndFeelUtils.installGlobalOverrides();
+// LookAndFeelUtils.installGlobalOverrides();
platformSpecificFixups();
}
@@ -84,9 +82,17 @@ public class Gui {
}
public static void setTheme(GTheme theme) {
- activeTheme = theme;
- LookAndFeelUtils.setLookAndFeel(theme.getLookAndFeelName());
- refresh();
+ if (theme.hasSupportedLookAndFeel()) {
+ activeTheme = theme;
+ LookAndFeelType lookAndFeel = theme.getLookAndFeelType();
+ try {
+ lookAndFeel.install();
+ }
+ catch (Exception e) {
+ Msg.error(Gui.class, "Error setting LookAndFeel: " + lookAndFeel.getName());
+ }
+ refresh();
+ }
}
private static void refresh() {
@@ -149,19 +155,25 @@ public class Gui {
return Collections.unmodifiableSet(allThemes);
}
+ public static Set<GTheme> getSupportedThemes() {
+ if (allThemes == null) {
+ allThemes = findThemes();
+ }
+ Set<GTheme> supported = new HashSet<>();
+ for (GTheme theme : allThemes) {
+ if (theme.hasSupportedLookAndFeel()) {
+ supported.add(theme);
+ }
+ }
+ return supported;
+ }
+
public static GTheme getTheme(String themeName) {
Optional<GTheme> first =
getAllThemes().stream().filter(t -> t.getName().equals(themeName)).findFirst();
return first.get();
}
- public static List<String> getAllThemeNames() {
- List<String> themeNames =
- getAllThemes().stream().map(t -> t.getName()).collect(Collectors.toList());
- Collections.sort(themeNames);
- return themeNames;
- }
-
public static Color darker(Color color) {
if (activeTheme.isDark()) {
return color.brighter();
@@ -193,8 +205,8 @@ public class Gui {
return activeTheme;
}
- public static String getLookAndFeelName() {
- return activeTheme.getLookAndFeelName();
+ public static LookAndFeelType getLookAndFeelType() {
+ return activeTheme.getLookAndFeelType();
}
private static void platformSpecificFixups() {
@@ -369,6 +381,7 @@ public class Gui {
GColor.refreshAll();
for (Window window : Window.getWindows()) {
window.repaint();
+// SynthLookAndFeel.updateStyles(window);
}
}
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/theme/LookAndFeelType.java b/Ghidra/Framework/Docking/src/main/java/docking/theme/LookAndFeelType.java
new file mode 100644
index 0000000000..4df2aae601
--- /dev/null
+++ b/Ghidra/Framework/Docking/src/main/java/docking/theme/LookAndFeelType.java
@@ -0,0 +1,80 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * 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 docking.theme;
+
+import com.formdev.flatlaf.*;
+
+import docking.theme.laf.*;
+import ghidra.framework.OperatingSystem;
+import ghidra.framework.Platform;
+
+public enum LookAndFeelType {
+ METAL("Metal", new MetalLookAndFeelInstaller()),
+ NIMBUS("Nimbus", new NimbusLookAndFeelInstaller()),
+ GTK("GTK+", new GTKLookAndFeelInstaller()),
+ MOTIF("CDE/Motif", new MotifLookAndFeelInstaller()),
+ FLAT_LIGHT("Flat Light", new FlatLookAndFeelInstaller(new FlatLightLaf())),
+ FLAT_DARK("Flat Dark", new FlatLookAndFeelInstaller(new FlatDarkLaf())),
+ FLAT_DARCULA("Flat Light", new FlatLookAndFeelInstaller(new FlatDarculaLaf())),
+ WINDOWS("Windows", new WindowsLookAndFeelInstaller()),
+ WINDOWS_CLASSIC("Windows Classic", new WindowsClassicLookAndFeelInstaller()),
+ MAC("Mac OS X", new MacLookAndFeelInstaller()),
+ SYSTEM("System", getSystemLookAndFeelInstaller());
+
+ private String name;
+ private LookAndFeelInstaller installer;
+
+ private LookAndFeelType(String name, LookAndFeelInstaller installer) {
+ this.name = name;
+ this.installer = installer;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public static LookAndFeelType fromName(String name) {
+ for (LookAndFeelType type : values()) {
+ if (type.getName().equals(name)) {
+ return type;
+ }
+ }
+ return null;
+ }
+
+ private static LookAndFeelInstaller getSystemLookAndFeelInstaller() {
+ OperatingSystem OS = Platform.CURRENT_PLATFORM.getOperatingSystem();
+ if (OS == OperatingSystem.LINUX) {
+ return NIMBUS.installer;
+ }
+ else if (OS == OperatingSystem.MAC_OS_X) {
+ return MAC.installer;
+ }
+ else if (OS == OperatingSystem.WINDOWS) {
+ return WINDOWS.installer;
+ }
+ return NIMBUS.installer;
+ }
+
+ public boolean isSupported() {
+ return installer.isSupportedForCurrentPlatform();
+ }
+
+ public void install() throws Exception {
+ installer.install();
+ }
+
+}
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/theme/ThemeReader.java b/Ghidra/Framework/Docking/src/main/java/docking/theme/ThemeReader.java
index 4554ea655d..cfafcb885a 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/theme/ThemeReader.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/theme/ThemeReader.java
@@ -22,7 +22,7 @@ public class ThemeReader extends ThemePropertyFileReader {
private Section themeSection;
private String themeName;
- private String lookAndFeelName;
+ private LookAndFeelType lookAndFeel;
private boolean isDark;
public ThemeReader(File file) throws IOException {
@@ -33,13 +33,14 @@ public class ThemeReader extends ThemePropertyFileReader {
protected void processNoSection(Section section) throws IOException {
themeSection = section;
themeName = section.getValue(GTheme.THEME_NAME_KEY);
- lookAndFeelName = section.getValue(GTheme.THEME_LOOK_AND_FEEL_KEY);
if (themeName == null) {
- throw new IOException("Missing theme name and/or lookAndFeel name!");
+ throw new IOException("Missing theme name!");
}
- if (lookAndFeelName == null) {
- error(section.getLineNumber(), "Invalid theme - missing theme name!");
- return;
+ String lookAndFeelName = section.getValue(GTheme.THEME_LOOK_AND_FEEL_KEY);
+ lookAndFeel = LookAndFeelType.fromName(lookAndFeelName);
+ if (lookAndFeel == null) {
+ throw new IOException(
+ "Invalid or missing lookAndFeel name: \"" + lookAndFeelName + "\"");
}
isDark = Boolean.parseBoolean(section.getValue(GTheme.THEME_IS_DARK_KEY));
}
@@ -58,12 +59,12 @@ public class ThemeReader extends ThemePropertyFileReader {
return themeName;
}
- public String getLookAndFeelName() {
- return lookAndFeelName;
- }
-
public boolean isDark() {
return isDark;
}
+ public LookAndFeelType getLookAndFeelType() {
+ return lookAndFeel;
+ }
+
}
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/theme/ThemeValue.java b/Ghidra/Framework/Docking/src/main/java/docking/theme/ThemeValue.java
index 3d3edc7de9..5772e9bb97 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/theme/ThemeValue.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/theme/ThemeValue.java
@@ -90,6 +90,9 @@ public abstract class ThemeValue<T> implements Comparable<ThemeValue<T>> {
}
public int compareValue(ThemeValue<T> o) {
+ if (o == null) {
+ return -1;
+ }
if (refId != null) {
return o.refId != null ? refId.compareTo(o.refId) : -1;
}
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/theme/builtin/CDEMotifTheme.java b/Ghidra/Framework/Docking/src/main/java/docking/theme/builtin/CDEMotifTheme.java
index 725a620f28..0cee78efe4 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/theme/builtin/CDEMotifTheme.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/theme/builtin/CDEMotifTheme.java
@@ -16,12 +16,12 @@
package docking.theme.builtin;
import docking.theme.DiscoverableGTheme;
-import ghidra.docking.util.LookAndFeelUtils;
+import docking.theme.LookAndFeelType;
public class CDEMotifTheme extends DiscoverableGTheme {
public CDEMotifTheme() {
- super("CDE/Motif", LookAndFeelUtils.MOTIF_LOOK_AND_FEEL);
+ super("Motif", LookAndFeelType.MOTIF);
}
}
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/theme/builtin/FlatDarculaTheme.java b/Ghidra/Framework/Docking/src/main/java/docking/theme/builtin/FlatDarculaTheme.java
index 4bdc24c621..b0f2e1c54b 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/theme/builtin/FlatDarculaTheme.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/theme/builtin/FlatDarculaTheme.java
@@ -16,10 +16,10 @@
package docking.theme.builtin;
import docking.theme.DiscoverableGTheme;
-import ghidra.docking.util.LookAndFeelUtils;
+import docking.theme.LookAndFeelType;
public class FlatDarculaTheme extends DiscoverableGTheme {
public FlatDarculaTheme() {
- super("Flat Darcula", LookAndFeelUtils.FLAT_DARCULA_LOOK_AND_FEEL, true);
+ super("Flat Darcula", LookAndFeelType.FLAT_DARCULA, true);
}
}
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/theme/builtin/FlatDarkTheme.java b/Ghidra/Framework/Docking/src/main/java/docking/theme/builtin/FlatDarkTheme.java
index f459efa515..3ebfd04738 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/theme/builtin/FlatDarkTheme.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/theme/builtin/FlatDarkTheme.java
@@ -16,10 +16,10 @@
package docking.theme.builtin;
import docking.theme.DiscoverableGTheme;
-import ghidra.docking.util.LookAndFeelUtils;
+import docking.theme.LookAndFeelType;
public class FlatDarkTheme extends DiscoverableGTheme {
public FlatDarkTheme() {
- super("Flat Dark", LookAndFeelUtils.FLAT_DARK_LOOK_AND_FEEL, true);
+ super("Flat Dark", LookAndFeelType.FLAT_DARK, true);
}
}
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/theme/builtin/FlatLightTheme.java b/Ghidra/Framework/Docking/src/main/java/docking/theme/builtin/FlatLightTheme.java
index 6197016058..77bddc9393 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/theme/builtin/FlatLightTheme.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/theme/builtin/FlatLightTheme.java
@@ -16,12 +16,12 @@
package docking.theme.builtin;
import docking.theme.DiscoverableGTheme;
-import ghidra.docking.util.LookAndFeelUtils;
+import docking.theme.LookAndFeelType;
public class FlatLightTheme extends DiscoverableGTheme {
public FlatLightTheme() {
- super("Flat Light", LookAndFeelUtils.FLAT_LIGHT_LOOK_AND_FEEL);
+ super("Flat Light", LookAndFeelType.FLAT_LIGHT);
}
}
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/theme/builtin/GdkTheme.java b/Ghidra/Framework/Docking/src/main/java/docking/theme/builtin/GTKTheme.java
similarity index 79%
rename from Ghidra/Framework/Docking/src/main/java/docking/theme/builtin/GdkTheme.java
rename to Ghidra/Framework/Docking/src/main/java/docking/theme/builtin/GTKTheme.java
index 30b122c7c1..ebf2d3c800 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/theme/builtin/GdkTheme.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/theme/builtin/GTKTheme.java
@@ -16,12 +16,12 @@
package docking.theme.builtin;
import docking.theme.DiscoverableGTheme;
-import ghidra.docking.util.LookAndFeelUtils;
+import docking.theme.LookAndFeelType;
-public class GdkTheme extends DiscoverableGTheme {
+public class GTKTheme extends DiscoverableGTheme {
- public GdkTheme() {
- super("GDK+", LookAndFeelUtils.GDK_LOOK_AND_FEEL);
+ public GTKTheme() {
+ super("GDK+", LookAndFeelType.GTK);
}
}
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/theme/builtin/MacTheme.java b/Ghidra/Framework/Docking/src/main/java/docking/theme/builtin/MacTheme.java
new file mode 100644
index 0000000000..19462cfe40
--- /dev/null
+++ b/Ghidra/Framework/Docking/src/main/java/docking/theme/builtin/MacTheme.java
@@ -0,0 +1,26 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * 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 docking.theme.builtin;
+
+import docking.theme.DiscoverableGTheme;
+import docking.theme.LookAndFeelType;
+
+public class MacTheme extends DiscoverableGTheme {
+
+ public MacTheme() {
+ super("Mac OS X", LookAndFeelType.MAC);
+ }
+}
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/theme/builtin/MetalTheme.java b/Ghidra/Framework/Docking/src/main/java/docking/theme/builtin/MetalTheme.java
index dc6f7938f6..9beff7ef2b 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/theme/builtin/MetalTheme.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/theme/builtin/MetalTheme.java
@@ -16,12 +16,12 @@
package docking.theme.builtin;
import docking.theme.DiscoverableGTheme;
-import ghidra.docking.util.LookAndFeelUtils;
+import docking.theme.LookAndFeelType;
public class MetalTheme extends DiscoverableGTheme {
public MetalTheme() {
- super("Metal", LookAndFeelUtils.METAL_LOOK_AND_FEEL);
+ super("Metal", LookAndFeelType.METAL);
}
}
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/theme/builtin/NimbusTheme.java b/Ghidra/Framework/Docking/src/main/java/docking/theme/builtin/NimbusTheme.java
index d64daf4fff..42c2c30e8f 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/theme/builtin/NimbusTheme.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/theme/builtin/NimbusTheme.java
@@ -16,11 +16,12 @@
package docking.theme.builtin;
import docking.theme.DiscoverableGTheme;
+import docking.theme.LookAndFeelType;
public class NimbusTheme extends DiscoverableGTheme {
public NimbusTheme() {
- super("Nimbus", "Nimbus");
+ super("Nimbus", LookAndFeelType.NIMBUS);
}
}
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/theme/builtin/WindowsClassicTheme.java b/Ghidra/Framework/Docking/src/main/java/docking/theme/builtin/WindowsClassicTheme.java
index eee25d50f9..a243582b1d 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/theme/builtin/WindowsClassicTheme.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/theme/builtin/WindowsClassicTheme.java
@@ -16,11 +16,11 @@
package docking.theme.builtin;
import docking.theme.DiscoverableGTheme;
-import ghidra.docking.util.LookAndFeelUtils;
+import docking.theme.LookAndFeelType;
public class WindowsClassicTheme extends DiscoverableGTheme {
public WindowsClassicTheme() {
- super("Windows Classic", LookAndFeelUtils.WINDOWS_CLASSIC);
+ super("Windows Classic", LookAndFeelType.WINDOWS_CLASSIC);
}
}
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/theme/builtin/WindowsTheme.java b/Ghidra/Framework/Docking/src/main/java/docking/theme/builtin/WindowsTheme.java
index 4b1b8e2a23..cce9011803 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/theme/builtin/WindowsTheme.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/theme/builtin/WindowsTheme.java
@@ -16,11 +16,11 @@
package docking.theme.builtin;
import docking.theme.DiscoverableGTheme;
-import ghidra.docking.util.LookAndFeelUtils;
+import docking.theme.LookAndFeelType;
public class WindowsTheme extends DiscoverableGTheme {
public WindowsTheme() {
- super("Windows", LookAndFeelUtils.WINDOWS);
+ super("Windows", LookAndFeelType.WINDOWS);
}
}
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/theme/gui/GThemeColorEditorDialog.java b/Ghidra/Framework/Docking/src/main/java/docking/theme/gui/GThemeColorEditorDialog.java
index 63915b2ade..1dd8a7e226 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/theme/gui/GThemeColorEditorDialog.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/theme/gui/GThemeColorEditorDialog.java
@@ -74,23 +74,25 @@ public class GThemeColorEditorDialog extends DialogComponentProvider {
@Override
protected void okCallback() {
- close();
if (!currentColorValue.equals(originalColorValue)) {
themeDialog.colorChangeAccepted();
}
currentColorValue = null;
originalColorValue = null;
+ close();
+ themeDialog.colorEditorClosed();
}
@Override
protected void cancelCallback() {
- retoreOriginalColor();
- close();
+ restoreOriginalColor();
currentColorValue = null;
originalColorValue = null;
+ close();
+ themeDialog.colorEditorClosed();
}
- private void retoreOriginalColor() {
+ private void restoreOriginalColor() {
Gui.setColor(originalColorValue);
}
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/theme/gui/GThemeDialog.java b/Ghidra/Framework/Docking/src/main/java/docking/theme/gui/GThemeDialog.java
index fba55af36f..92de7c3196 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/theme/gui/GThemeDialog.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/theme/gui/GThemeDialog.java
@@ -17,12 +17,15 @@ package docking.theme.gui;
import java.awt.*;
import java.awt.event.*;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
import javax.swing.*;
import docking.DialogComponentProvider;
-import docking.theme.ColorValue;
-import docking.theme.Gui;
+import docking.theme.*;
import docking.widgets.combobox.GhidraComboBox;
import docking.widgets.table.GFilterTable;
import docking.widgets.table.GTable;
@@ -95,7 +98,12 @@ public class GThemeDialog extends DialogComponentProvider {
private Component buildThemeCombo() {
JPanel panel = new JPanel();
- GhidraComboBox<String> combo = new GhidraComboBox<>(Gui.getAllThemeNames());
+ Set<GTheme> supportedThemes = Gui.getSupportedThemes();
+ List<String> themeNames =
+ supportedThemes.stream().map(t -> t.getName()).collect(Collectors.toList());
+ Collections.sort(themeNames);
+
+ GhidraComboBox<String> combo = new GhidraComboBox<>(themeNames);
combo.setSelectedItem(Gui.getActiveTheme().getName());
combo.addItemListener(this::themeComboChanged);
@@ -185,4 +193,8 @@ public class GThemeDialog extends DialogComponentProvider {
colorTableModel.reload();
}
+ void colorEditorClosed() {
+ dialog = null;
+ }
+
}
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/theme/gui/ThemeColorTableModel.java b/Ghidra/Framework/Docking/src/main/java/docking/theme/gui/ThemeColorTableModel.java
index 0c884bd2be..e298f03712 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/theme/gui/ThemeColorTableModel.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/theme/gui/ThemeColorTableModel.java
@@ -128,9 +128,18 @@ public class ThemeColorTableModel extends GDynamicColumnTableModel<ColorValue, O
}
public Comparator<ColorValue> getComparator() {
- return (v1, v2) -> valueSupplier.get()
- .getColor(v1.getId())
- .compareValue(valueSupplier.get().getColor(v2.getId()));
+ return (v1, v2) -> {
+ GThemeValueMap valueMap = valueSupplier.get();
+ ColorValue v1Color = valueMap.getColor(v1.getId());
+ ColorValue v2Color = valueMap.getColor(v2.getId());
+ if (v1Color == null && v2Color == null) {
+ return 0;
+ }
+ if (v1Color == null) {
+ return 1;
+ }
+ return v1Color.compareValue(v2Color);
+ };
}
@Override
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/theme/laf/FlatLookAndFeelInstaller.java b/Ghidra/Framework/Docking/src/main/java/docking/theme/laf/FlatLookAndFeelInstaller.java
index 3e06478592..4c75a06ab1 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/theme/laf/FlatLookAndFeelInstaller.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/theme/laf/FlatLookAndFeelInstaller.java
@@ -32,4 +32,9 @@ public class FlatLookAndFeelInstaller extends LookAndFeelInstaller {
UIManager.setLookAndFeel(lookAndFeel);
}
+ @Override
+ public boolean isSupportedForCurrentPlatform() {
+ return true;
+ }
+
}
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/theme/laf/GDKLookAndFeelInstaller.java b/Ghidra/Framework/Docking/src/main/java/docking/theme/laf/GTKLookAndFeelInstaller.java
similarity index 69%
rename from Ghidra/Framework/Docking/src/main/java/docking/theme/laf/GDKLookAndFeelInstaller.java
rename to Ghidra/Framework/Docking/src/main/java/docking/theme/laf/GTKLookAndFeelInstaller.java
index 28a9ad4f60..2b8bce53af 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/theme/laf/GDKLookAndFeelInstaller.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/theme/laf/GTKLookAndFeelInstaller.java
@@ -18,25 +18,42 @@ package docking.theme.laf;
import java.awt.Color;
import java.util.List;
-import javax.swing.UIDefaults;
-import javax.swing.UnsupportedLookAndFeelException;
-import javax.swing.plaf.nimbus.NimbusLookAndFeel;
+import javax.swing.*;
+import javax.swing.plaf.synth.SynthLookAndFeel;
import docking.theme.*;
import ghidra.docking.util.LookAndFeelUtils;
-public class GDKLookAndFeelInstaller extends LookAndFeelInstaller {
+public class GTKLookAndFeelInstaller extends LookAndFeelInstaller {
+
+ @Override
+ protected void installJavaDefaults() {
+ // do nothing - already handled by wrapped GTK lookAndFeel
+ }
@Override
protected void installLookAndFeel() throws UnsupportedLookAndFeelException {
+ String name = LookAndFeelType.GTK.getName();
+ try {
+ UIManager.setLookAndFeel(findLookAndFeelClassName(name));
+ LookAndFeel gtk = UIManager.getLookAndFeel();
+ UIManager.setLookAndFeel(new WrappingLookAndFeel(gtk));
+ }
+ catch (Exception e) {
+ throw new UnsupportedLookAndFeelException(name + " not supported on this platform");
+ }
+ }
+ @Override
+ public boolean isSupportedForCurrentPlatform() {
+ return isSupported(LookAndFeelType.GTK.getName());
}
/**
* Extends the NimbusLookAndFeel to intercept the {@link #getDefaults()}. To get Nimbus
* to use our indirect values, we have to get in early.
*/
- static class ExtendedGDKKLookAndFeel extends NimbusLookAndFeel {
+ static class ExtendedGTKLookAndFeel extends SynthLookAndFeel {
@Override
public UIDefaults getDefaults() {
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/theme/laf/GenericLookAndFeelInstaller.java b/Ghidra/Framework/Docking/src/main/java/docking/theme/laf/GenericLookAndFeelInstaller.java
deleted file mode 100644
index 17506ba713..0000000000
--- a/Ghidra/Framework/Docking/src/main/java/docking/theme/laf/GenericLookAndFeelInstaller.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/* ###
- * IP: GHIDRA
- *
- * 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 docking.theme.laf;
-
-import javax.swing.UIManager;
-import javax.swing.UIManager.LookAndFeelInfo;
-
-import ghidra.docking.util.LookAndFeelUtils;
-import ghidra.util.Msg;
-
-public class GenericLookAndFeelInstaller extends LookAndFeelInstaller {
- private String name;
-
- public GenericLookAndFeelInstaller(String name) {
- this.name = name;
- }
-
- @Override
- protected void installLookAndFeel() throws Exception {
- String className = findLookAndFeelClassName(name);
- UIManager.setLookAndFeel(className);
- }
-
- private static String findLookAndFeelClassName(String lookAndFeelName) {
- if (lookAndFeelName.equalsIgnoreCase(LookAndFeelUtils.SYSTEM_LOOK_AND_FEEL)) {
- return UIManager.getSystemLookAndFeelClassName();
- }
-
- LookAndFeelInfo[] installedLookAndFeels = UIManager.getInstalledLookAndFeels();
- for (LookAndFeelInfo info : installedLookAndFeels) {
- String className = info.getClassName();
- if (lookAndFeelName.equals(className) || lookAndFeelName.equals(info.getName())) {
- return className;
- }
- }
-
- Msg.debug(LookAndFeelUtils.class,
- "Unable to find requested Look and Feel: " + lookAndFeelName);
- return UIManager.getSystemLookAndFeelClassName();
- }
-
-}
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/theme/laf/LookAndFeelInstaller.java b/Ghidra/Framework/Docking/src/main/java/docking/theme/laf/LookAndFeelInstaller.java
index 91d27ca0f9..f8225c01ad 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/theme/laf/LookAndFeelInstaller.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/theme/laf/LookAndFeelInstaller.java
@@ -16,14 +16,17 @@
package docking.theme.laf;
import java.awt.Color;
-import java.util.List;
+import java.awt.Font;
+import java.util.*;
+import java.util.Map.Entry;
-import javax.swing.UIDefaults;
-import javax.swing.UIManager;
+import javax.swing.*;
+import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.plaf.UIResource;
import docking.theme.*;
import ghidra.docking.util.LookAndFeelUtils;
+import ghidra.util.*;
public abstract class LookAndFeelInstaller {
@@ -32,8 +35,18 @@ public abstract class LookAndFeelInstaller {
installLookAndFeel();
installJavaDefaults();
fixupLookAndFeelIssues();
+ installGlobalProperties();
}
+ private void installGlobalProperties() {
+ installGlobalLookAndFeelAttributes();
+ installGlobalFontSizeOverride();
+ installCustomLookAndFeelActions();
+ installPopupMenuSettingsOverride();
+ }
+
+ public abstract boolean isSupportedForCurrentPlatform();
+
protected abstract void installLookAndFeel() throws Exception;
protected void fixupLookAndFeelIssues() {
@@ -99,4 +112,125 @@ public abstract class LookAndFeelInstaller {
// }
}
+ protected String findLookAndFeelClassName(String lookAndFeelName) {
+ LookAndFeelInfo[] installedLookAndFeels = UIManager.getInstalledLookAndFeels();
+ for (LookAndFeelInfo info : installedLookAndFeels) {
+ String className = info.getClassName();
+ if (lookAndFeelName.equals(className) || lookAndFeelName.equals(info.getName())) {
+ return className;
+ }
+ }
+
+ Msg.debug(LookAndFeelUtils.class,
+ "Unable to find requested Look and Feel: " + lookAndFeelName);
+ return UIManager.getSystemLookAndFeelClassName();
+ }
+
+ protected boolean isSupported(String lookAndFeelName) {
+ LookAndFeelInfo[] installedLookAndFeels = UIManager.getInstalledLookAndFeels();
+ for (LookAndFeelInfo info : installedLookAndFeels) {
+ if (lookAndFeelName.equals(info.getName())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ protected void setKeyBinding(String existingKsText, String newKsText, String[] prefixValues) {
+
+ KeyStroke existingKs = KeyStroke.getKeyStroke(existingKsText);
+ KeyStroke newKs = KeyStroke.getKeyStroke(newKsText);
+
+ for (String properyPrefix : prefixValues) {
+
+ UIDefaults defaults = UIManager.getDefaults();
+ Object object = defaults.get(properyPrefix + ".focusInputMap");
+ InputMap inputMap = (InputMap) object;
+ Object action = inputMap.get(existingKs);
+ inputMap.put(newKs, action);
+ }
+ }
+
+ private void installGlobalLookAndFeelAttributes() {
+ // Fix up the default fonts that Java 1.5.0 changed to Courier, which looked terrible.
+ Font f = new Font("Monospaced", Font.PLAIN, 12);
+ UIManager.put("PasswordField.font", f);
+ UIManager.put("TextArea.font", f);
+
+ // We like buttons that change on hover, so force that to happen (see Tracker SCR 3966)
+ UIManager.put("Button.rollover", Boolean.TRUE);
+ UIManager.put("ToolBar.isRollover", Boolean.TRUE);
+ }
+
+ private void installPopupMenuSettingsOverride() {
+ // Java 1.6 UI consumes MousePressed event when dismissing popup menu
+ // which prevents application components from getting this event.
+ UIManager.put("PopupMenu.consumeEventOnClose", Boolean.FALSE);
+ }
+
+ private void installGlobalFontSizeOverride() {
+
+ // only set a global size if the property is set
+ Integer overrideFontInteger = SystemUtilities.getFontSizeOverrideValue();
+ if (overrideFontInteger == null) {
+ return;
+ }
+
+ setGlobalFontSizeOverride(overrideFontInteger);
+ }
+
+ private void installCustomLookAndFeelActions() {
+ // these prefixes are for text components
+ String[] UIPrefixValues =
+ { "TextField", "FormattedTextField", "TextArea", "TextPane", "EditorPane" };
+
+ DeleteToStartOfWordAction deleteToStartOfWordAction = new DeleteToStartOfWordAction();
+ registerAction(deleteToStartOfWordAction, DeleteToStartOfWordAction.KEY_STROKE,
+ UIPrefixValues);
+
+ DeleteToEndOfWordAction deleteToEndOfWordAction = new DeleteToEndOfWordAction();
+ registerAction(deleteToEndOfWordAction, DeleteToEndOfWordAction.KEY_STROKE, UIPrefixValues);
+
+ BeginningOfLineAction beginningOfLineAction = new BeginningOfLineAction();
+ registerAction(beginningOfLineAction, BeginningOfLineAction.KEY_STROKE, UIPrefixValues);
+
+ EndOfLineAction endOfLineAction = new EndOfLineAction();
+ registerAction(endOfLineAction, EndOfLineAction.KEY_STROKE, UIPrefixValues);
+
+ SelectBeginningOfLineAction selectBeginningOfLineAction = new SelectBeginningOfLineAction();
+ registerAction(selectBeginningOfLineAction, SelectBeginningOfLineAction.KEY_STROKE,
+ UIPrefixValues);
+
+ SelectEndOfLineAction selectEndOfLineAction = new SelectEndOfLineAction();
+ registerAction(selectEndOfLineAction, SelectEndOfLineAction.KEY_STROKE, UIPrefixValues);
+ }
+
+ /** Allows you to globally set the font size (don't use this method!) */
+ private void setGlobalFontSizeOverride(int fontSize) {
+ UIDefaults defaults = UIManager.getDefaults();
+
+ Set<Entry<Object, Object>> set = defaults.entrySet();
+ Iterator<Entry<Object, Object>> iterator = set.iterator();
+ while (iterator.hasNext()) {
+ Entry<Object, Object> entry = iterator.next();
+ Object key = entry.getKey();
+
+ if (key.toString().toLowerCase().indexOf("font") != -1) {
+ Font currentFont = defaults.getFont(key);
+ if (currentFont != null) {
+ Font newFont = currentFont.deriveFont((float) fontSize);
+ UIManager.put(key, newFont);
+ }
+ }
+ }
+ }
+
+ private void registerAction(Action action, KeyStroke keyStroke, String[] prefixValues) {
+ for (String properyPrefix : prefixValues) {
+ UIDefaults defaults = UIManager.getDefaults();
+ Object object = defaults.get(properyPrefix + ".focusInputMap");
+ InputMap inputMap = (InputMap) object;
+ inputMap.put(keyStroke, action);
+ }
+ }
}
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/theme/laf/MacLookAndFeelInstaller.java b/Ghidra/Framework/Docking/src/main/java/docking/theme/laf/MacLookAndFeelInstaller.java
new file mode 100644
index 0000000000..3ea38de18d
--- /dev/null
+++ b/Ghidra/Framework/Docking/src/main/java/docking/theme/laf/MacLookAndFeelInstaller.java
@@ -0,0 +1,35 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * 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 docking.theme.laf;
+
+import javax.swing.UIManager;
+
+import docking.theme.LookAndFeelType;
+
+public class MacLookAndFeelInstaller extends LookAndFeelInstaller {
+
+ @Override
+ public boolean isSupportedForCurrentPlatform() {
+ return isSupported(LookAndFeelType.MAC.getName());
+ }
+
+ @Override
+ protected void installLookAndFeel() throws Exception {
+ String name = LookAndFeelType.MAC.getName();
+ UIManager.setLookAndFeel(findLookAndFeelClassName(name));
+ }
+
+}
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/theme/laf/MetalLookAndFeelInstaller.java b/Ghidra/Framework/Docking/src/main/java/docking/theme/laf/MetalLookAndFeelInstaller.java
index f2e53353ea..006713de04 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/theme/laf/MetalLookAndFeelInstaller.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/theme/laf/MetalLookAndFeelInstaller.java
@@ -26,4 +26,9 @@ public class MetalLookAndFeelInstaller extends LookAndFeelInstaller {
UIManager.setLookAndFeel(new MetalLookAndFeel());
}
+ @Override
+ public boolean isSupportedForCurrentPlatform() {
+ return true;
+ }
+
}
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/theme/laf/MotifLookAndFeelInstaller.java b/Ghidra/Framework/Docking/src/main/java/docking/theme/laf/MotifLookAndFeelInstaller.java
new file mode 100644
index 0000000000..6f1cd2462c
--- /dev/null
+++ b/Ghidra/Framework/Docking/src/main/java/docking/theme/laf/MotifLookAndFeelInstaller.java
@@ -0,0 +1,50 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * 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 docking.theme.laf;
+
+import javax.swing.UIManager;
+
+import docking.theme.LookAndFeelType;
+
+public class MotifLookAndFeelInstaller extends LookAndFeelInstaller {
+
+ @Override
+ public boolean isSupportedForCurrentPlatform() {
+ return true;
+ }
+
+ @Override
+ protected void installLookAndFeel() throws Exception {
+ String name = LookAndFeelType.MOTIF.getName();
+ UIManager.setLookAndFeel(findLookAndFeelClassName(name));
+ }
+
+ @Override
+ protected void fixupLookAndFeelIssues() {
+ //
+ // The Motif LaF does not bind copy/paste/cut to Control-C/V/X by default. Rather, they
+ // only use the COPY/PASTE/CUT keys. The other LaFs bind both shortcuts.
+ //
+
+ // these prefixes are for text components
+ String[] UIPrefixValues =
+ { "TextField", "FormattedTextField", "TextArea", "TextPane", "EditorPane" };
+
+ setKeyBinding("COPY", "ctrl C", UIPrefixValues);
+ setKeyBinding("PASTE", "ctrl V", UIPrefixValues);
+ setKeyBinding("CUT", "ctrl X", UIPrefixValues);
+ }
+}
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/theme/laf/NimbusLookAndFeelInstaller.java b/Ghidra/Framework/Docking/src/main/java/docking/theme/laf/NimbusLookAndFeelInstaller.java
index b30c335329..e1f18dd74b 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/theme/laf/NimbusLookAndFeelInstaller.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/theme/laf/NimbusLookAndFeelInstaller.java
@@ -16,6 +16,7 @@
package docking.theme.laf;
import java.awt.Color;
+import java.awt.Dimension;
import java.util.List;
import javax.swing.*;
@@ -31,11 +32,28 @@ public class NimbusLookAndFeelInstaller extends LookAndFeelInstaller {
UIManager.setLookAndFeel(new GNimbusLookAndFeel());
}
+ @Override
+ public boolean isSupportedForCurrentPlatform() {
+ return true;
+ }
+
@Override
protected void installJavaDefaults() {
// do nothing - already handled by extended NimbusLookAndFeel
}
+ @Override
+ protected void fixupLookAndFeelIssues() {
+ super.fixupLookAndFeelIssues();
+
+ // fix scroll bar grabber disappearing. See https://bugs.openjdk.java.net/browse/JDK-8134828
+ // This fix looks like it should not cause harm even if the bug is fixed on the jdk side.
+ UIDefaults defaults = UIManager.getDefaults();
+ defaults.put("ScrollBar.minimumThumbSize", new Dimension(30, 30));
+
+ // (see NimbusDefaults for key values that can be changed here)
+ }
+
/**
* Extends the NimbusLookAndFeel to intercept the {@link #getDefaults()}. To get Nimbus
* to use our indirect values, we have to get in early.
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/theme/laf/WindowsClassicLookAndFeelInstaller.java b/Ghidra/Framework/Docking/src/main/java/docking/theme/laf/WindowsClassicLookAndFeelInstaller.java
new file mode 100644
index 0000000000..04e383e3dd
--- /dev/null
+++ b/Ghidra/Framework/Docking/src/main/java/docking/theme/laf/WindowsClassicLookAndFeelInstaller.java
@@ -0,0 +1,35 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * 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 docking.theme.laf;
+
+import javax.swing.UIManager;
+
+import docking.theme.LookAndFeelType;
+
+public class WindowsClassicLookAndFeelInstaller extends LookAndFeelInstaller {
+
+ @Override
+ public boolean isSupportedForCurrentPlatform() {
+ return isSupported(LookAndFeelType.WINDOWS_CLASSIC.getName());
+ }
+
+ @Override
+ protected void installLookAndFeel() throws Exception {
+ String name = LookAndFeelType.WINDOWS_CLASSIC.getName();
+ UIManager.setLookAndFeel(findLookAndFeelClassName(name));
+ }
+
+}
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/theme/laf/WindowsLookAndFeelInstaller.java b/Ghidra/Framework/Docking/src/main/java/docking/theme/laf/WindowsLookAndFeelInstaller.java
new file mode 100644
index 0000000000..87c0ad8439
--- /dev/null
+++ b/Ghidra/Framework/Docking/src/main/java/docking/theme/laf/WindowsLookAndFeelInstaller.java
@@ -0,0 +1,35 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * 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 docking.theme.laf;
+
+import javax.swing.UIManager;
+
+import docking.theme.LookAndFeelType;
+
+public class WindowsLookAndFeelInstaller extends LookAndFeelInstaller {
+
+ @Override
+ public boolean isSupportedForCurrentPlatform() {
+ return isSupported(LookAndFeelType.WINDOWS.getName());
+ }
+
+ @Override
+ protected void installLookAndFeel() throws Exception {
+ String name = LookAndFeelType.WINDOWS.getName();
+ UIManager.setLookAndFeel(findLookAndFeelClassName(name));
+ }
+
+}
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/theme/laf/WrappingLookAndFeel.java b/Ghidra/Framework/Docking/src/main/java/docking/theme/laf/WrappingLookAndFeel.java
new file mode 100644
index 0000000000..885ad7c4c9
--- /dev/null
+++ b/Ghidra/Framework/Docking/src/main/java/docking/theme/laf/WrappingLookAndFeel.java
@@ -0,0 +1,118 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * 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 docking.theme.laf;
+
+import java.awt.Color;
+import java.awt.Component;
+import java.util.List;
+
+import javax.swing.*;
+
+import docking.theme.*;
+import ghidra.docking.util.LookAndFeelUtils;
+
+public class WrappingLookAndFeel extends LookAndFeel {
+ private LookAndFeel delegate;
+
+ WrappingLookAndFeel(LookAndFeel delegate) {
+ this.delegate = delegate;
+ }
+
+ @Override
+ public UIDefaults getDefaults() {
+ GThemeValueMap javaDefaults = new GThemeValueMap();
+
+ UIDefaults defaults = delegate.getDefaults();
+ List<String> colorIds = LookAndFeelUtils.getLookAndFeelIdsForType(defaults, Color.class);
+ for (String id : colorIds) {
+ Color color = defaults.getColor(id);
+ ColorValue value = new ColorValue(id, color);
+ javaDefaults.addColor(value);
+ }
+ Gui.setJavaDefaults(javaDefaults);
+ for (String id : colorIds) {
+ defaults.put(id, Gui.getGColorUiResource(id));
+ }
+ defaults.put("Label.textForeground", Gui.getGColorUiResource("Label.foreground"));
+ GColor.refreshAll();
+ return defaults;
+ }
+
+ @Override
+ public String getName() {
+ return delegate.getName();
+ }
+
+ @Override
+ public String getID() {
+ return delegate.getID();
+ }
+
+ @Override
+ public String getDescription() {
+ return delegate.getDescription();
+ }
+
+ @Override
+ public boolean isNativeLookAndFeel() {
+ return delegate.isNativeLookAndFeel();
+ }
+
+ @Override
+ public boolean isSupportedLookAndFeel() {
+ return delegate.isSupportedLookAndFeel();
+ }
+
+ @Override
+ public LayoutStyle getLayoutStyle() {
+ return delegate.getLayoutStyle();
+ }
+
+ @Override
+ public void provideErrorFeedback(Component component) {
+ delegate.provideErrorFeedback(component);
+ }
+
+ @Override
+ public Icon getDisabledIcon(JComponent component, Icon icon) {
+ return delegate.getDisabledIcon(component, icon);
+ }
+
+ @Override
+ public Icon getDisabledSelectedIcon(JComponent component, Icon icon) {
+ return delegate.getDisabledSelectedIcon(component, icon);
+ }
+
+ @Override
+ public boolean getSupportsWindowDecorations() {
+ return delegate.getSupportsWindowDecorations();
+ }
+
+ @Override
+ public void initialize() {
+ delegate.initialize();
+ }
+
+ @Override
+ public void uninitialize() {
+ delegate.uninitialize();
+ }
+
+ @Override
+ public String toString() {
+ return "Wrapped: " + delegate.toString();
+ }
+}
diff --git a/Ghidra/Framework/Docking/src/main/java/ghidra/docking/util/LookAndFeelUtils.java b/Ghidra/Framework/Docking/src/main/java/ghidra/docking/util/LookAndFeelUtils.java
index 1d188ce69d..be987aa5ab 100644
--- a/Ghidra/Framework/Docking/src/main/java/ghidra/docking/util/LookAndFeelUtils.java
+++ b/Ghidra/Framework/Docking/src/main/java/ghidra/docking/util/LookAndFeelUtils.java
@@ -15,151 +15,39 @@
*/
package ghidra.docking.util;
-import java.awt.*;
-import java.util.*;
+import java.util.ArrayList;
import java.util.List;
-import java.util.Map.Entry;
import javax.swing.*;
-import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.plaf.ComponentUI;
import org.apache.commons.collections4.IteratorUtils;
-import com.formdev.flatlaf.*;
-
-import docking.theme.laf.*;
-import ghidra.framework.OperatingSystem;
-import ghidra.framework.Platform;
-import ghidra.framework.preferences.Preferences;
-import ghidra.util.*;
+import docking.theme.LookAndFeelType;
/**
* A utility class to manage LookAndFeel (LaF) settings.
*/
public class LookAndFeelUtils {
- /**
- * Default Look and feel for the current platform.
- */
- public final static String SYSTEM_LOOK_AND_FEEL = "System";
-
- /**
- * Metal is the non-system, generic Java Look and Feel.
- */
- public final static String METAL_LOOK_AND_FEEL = "Metal";
-
- /**
- * The most stable Linux LaF, based on anecdotal observation.
- */
- public static final String NIMBUS_LOOK_AND_FEEL = "Nimbus";
-
- public static final String GDK_LOOK_AND_FEEL = "GTK+";
-
- /**
- * The Motif LaF name.
- */
- public static final String MOTIF_LOOK_AND_FEEL = "CDE/Motif";
- /**
- * The flatlaf implementation of light mode.
- */
- public static final String FLAT_LIGHT_LOOK_AND_FEEL = "Flat Light";
- /**
- * The Flatlaf implementation of dark mode.
- */
- public static final String FLAT_DARK_LOOK_AND_FEEL = "Flat Dark";
- /**
- * The Flatlaf implementation of darcula mode.
- */
- public static final String FLAT_DARCULA_LOOK_AND_FEEL = "Flat Darcula";
-
- public static final String WINDOWS = "Windows";
- public static final String WINDOWS_CLASSIC = "Windows Classic";
-
- public static final String SYSTEM = "System";
-
private LookAndFeelUtils() {
// utils class, cannot create
}
- /**
- * Loads settings from {@link Preferences}.
- */
- public static void installGlobalOverrides() {
-
- //
- // Users can change this via the SystemUtilities.FONT_SIZE_OVERRIDE_PROPERTY_NAME
- // system property.
- //
- Integer fontOverride = SystemUtilities.getFontSizeOverrideValue();
- if (fontOverride != null) {
- setGlobalFontSizeOverride(fontOverride);
- }
- }
-
- /**
- * Returns the currently installed LaF.
- * @return the currently installed LaF.
- */
- public static String getInstalledLookAndFeelName() {
- return UIManager.getLookAndFeel().getName();
- }
-
- /**
- * Set the look and feel (LAF) indicated by the string passed in as a parameter.
- * The string value can be either the class name of the LAF, as returned by
- * <code>LookAndFeelInfo.getClassName()</code> or the name as returned by
- * <code>LookAndFeelInfo.getName()</code>.
- * <p>
- * Note: to be effective, this call needs to be made before any components have been created
- * and shown.
- *
- * @param lookAndFeelName the string indicating which look and feel is desired (see above)
- */
- public static void setLookAndFeel(String lookAndFeelName) {
- SystemUtilities.runSwingNow(() -> {
- try {
- installLookAndFeelByName(lookAndFeelName);
-
- // some custom values for any given LAF
- installGlobalLookAndFeelAttributes();
- installGlobalFontSizeOverride();
- installCustomLookAndFeelActions();
- installPopupMenuSettingsOverride();
- }
- catch (Exception exc) {
- Msg.error(LookAndFeelUtils.class, "Error loading Look and Feel: " + exc, exc);
- }
- });
- }
-
- public static void setLookAndFeel(LookAndFeel laf) {
- SystemUtilities.runSwingNow(() -> {
- try {
- UIManager.setLookAndFeel(laf);
- fixupLookAndFeelIssues();
-
- // some custom values for any given LAF
- installGlobalLookAndFeelAttributes();
- installGlobalFontSizeOverride();
- installCustomLookAndFeelActions();
- installPopupMenuSettingsOverride();
- }
- catch (Exception exc) {
- Msg.error(LookAndFeelUtils.class, "Error loading Look and Feel: " + exc, exc);
- }
- });
-
- }
-
- public static void dumpUIProperties() {
- List<String> colorKeys = getLookAndFeelIdsForType(UIManager.getDefaults(), Color.class);
- Collections.sort(colorKeys);
- for (String string : colorKeys) {
- Msg.debug(LookAndFeelUtils.class, string + "\t\t" + UIManager.get(string));
- }
-
- }
+// /**
+// * Loads settings from {@link Preferences}.
+// */
+// public static void installGlobalOverrides() {
+//
+// //
+// // Users can change this via the SystemUtilities.FONT_SIZE_OVERRIDE_PROPERTY_NAME
+// // system property.
+// //
+// Integer fontOverride = SystemUtilities.getFontSizeOverrideValue();
+// if (fontOverride != null) {
+// setGlobalFontSizeOverride(fontOverride);
+// }
+// }
public static List<String> getLookAndFeelIdsForType(UIDefaults defaults, Class<?> clazz) {
List<String> colorKeys = new ArrayList<>();
@@ -175,197 +63,6 @@ public class LookAndFeelUtils {
return colorKeys;
}
- /**
- * Returns all installed LaFs. This will vary by OS.
- * @return all installed LaFs.
- */
- public static List<String> getLookAndFeelNames() {
- List<String> list = new ArrayList<>();
- list.add(LookAndFeelUtils.SYSTEM_LOOK_AND_FEEL);
- list.add(LookAndFeelUtils.FLAT_LIGHT_LOOK_AND_FEEL);
- list.add(LookAndFeelUtils.FLAT_DARK_LOOK_AND_FEEL);
-
- LookAndFeelInfo[] installedLookAndFeels = UIManager.getInstalledLookAndFeels();
- for (LookAndFeelInfo info : installedLookAndFeels) {
- list.add(info.getName());
- }
- return list;
- }
-
- private static void installLookAndFeelByName(String lookAndFeelName) throws Exception {
-
- LookAndFeelInstaller installer = getLookAndFeelInstaller(lookAndFeelName);
- installer.install();
- fixupLookAndFeelIssues();
- }
-
- private static LookAndFeelInstaller getLookAndFeelInstaller(String lookAndFeelName) {
- switch (lookAndFeelName) {
- case NIMBUS_LOOK_AND_FEEL:
- return new NimbusLookAndFeelInstaller();
- case METAL_LOOK_AND_FEEL:
- return new MetalLookAndFeelInstaller();
- case FLAT_LIGHT_LOOK_AND_FEEL:
- return new FlatLookAndFeelInstaller(new FlatLightLaf());
- case FLAT_DARK_LOOK_AND_FEEL:
- return new FlatLookAndFeelInstaller(new FlatDarkLaf());
- case FLAT_DARCULA_LOOK_AND_FEEL:
- return new FlatLookAndFeelInstaller(new FlatDarculaLaf());
- default:
- return new GenericLookAndFeelInstaller(lookAndFeelName);
- }
- }
-
- /**
- * Fixes issues in the currently running look and feel.
- */
- private static void fixupLookAndFeelIssues() {
- LookAndFeel lookAndFeel = UIManager.getLookAndFeel();
- switch (lookAndFeel.getName()) {
- case NIMBUS_LOOK_AND_FEEL:
- // fix scroll bar grabber disappearing. See https://bugs.openjdk.java.net/browse/JDK-8134828
- // This fix looks like it should not cause harm even if the bug is fixed on the jdk side.
- UIDefaults defaults = UIManager.getDefaults();
- defaults.put("ScrollBar.minimumThumbSize", new Dimension(30, 30));
-
- // (see NimbusDefaults for key values that can be changed here)
- break;
- case MOTIF_LOOK_AND_FEEL:
-
- doFixupMissingCopyPasteKeyBindings();
-
- // (see MotifDefaults for key values that can be changed here)
- break;
- }
- }
-
- private static void doFixupMissingCopyPasteKeyBindings() {
-
- //
- // The Motif LaF does not bind copy/paste/cut to Control-C/V/X by default. Rather, they
- // only use the COPY/PASTE/CUT keys. The other LaFs bind both shortcuts.
- //
-
- // these prefixes are for text components
- String[] UIPrefixValues =
- { "TextField", "FormattedTextField", "TextArea", "TextPane", "EditorPane" };
-
- setKeyBinding("COPY", "ctrl C", UIPrefixValues);
- setKeyBinding("PASTE", "ctrl V", UIPrefixValues);
- setKeyBinding("CUT", "ctrl X", UIPrefixValues);
- }
-
- private static void installGlobalLookAndFeelAttributes() {
- // Fix up the default fonts that Java 1.5.0 changed to Courier, which looked terrible.
- Font f = new Font("Monospaced", Font.PLAIN, 12);
- UIManager.put("PasswordField.font", f);
- UIManager.put("TextArea.font", f);
-
- // We like buttons that change on hover, so force that to happen (see Tracker SCR 3966)
- UIManager.put("Button.rollover", Boolean.TRUE);
- UIManager.put("ToolBar.isRollover", Boolean.TRUE);
- }
-
- private static void installPopupMenuSettingsOverride() {
- // Java 1.6 UI consumes MousePressed event when dismissing popup menu
- // which prevents application components from getting this event.
- UIManager.put("PopupMenu.consumeEventOnClose", Boolean.FALSE);
- }
-
- private static void installGlobalFontSizeOverride() {
-
- // only set a global size if the property is set
- Integer overrideFontInteger = SystemUtilities.getFontSizeOverrideValue();
- if (overrideFontInteger == null) {
- return;
- }
-
- setGlobalFontSizeOverride(overrideFontInteger);
- }
-
- private static void installCustomLookAndFeelActions() {
- // these prefixes are for text components
- String[] UIPrefixValues =
- { "TextField", "FormattedTextField", "TextArea", "TextPane", "EditorPane" };
-
- DeleteToStartOfWordAction deleteToStartOfWordAction = new DeleteToStartOfWordAction();
- registerAction(deleteToStartOfWordAction, DeleteToStartOfWordAction.KEY_STROKE,
- UIPrefixValues);
-
- DeleteToEndOfWordAction deleteToEndOfWordAction = new DeleteToEndOfWordAction();
- registerAction(deleteToEndOfWordAction, DeleteToEndOfWordAction.KEY_STROKE, UIPrefixValues);
-
- BeginningOfLineAction beginningOfLineAction = new BeginningOfLineAction();
- registerAction(beginningOfLineAction, BeginningOfLineAction.KEY_STROKE, UIPrefixValues);
-
- EndOfLineAction endOfLineAction = new EndOfLineAction();
- registerAction(endOfLineAction, EndOfLineAction.KEY_STROKE, UIPrefixValues);
-
- SelectBeginningOfLineAction selectBeginningOfLineAction = new SelectBeginningOfLineAction();
- registerAction(selectBeginningOfLineAction, SelectBeginningOfLineAction.KEY_STROKE,
- UIPrefixValues);
-
- SelectEndOfLineAction selectEndOfLineAction = new SelectEndOfLineAction();
- registerAction(selectEndOfLineAction, SelectEndOfLineAction.KEY_STROKE, UIPrefixValues);
- }
-
- private static void registerAction(Action action, KeyStroke keyStroke, String[] prefixValues) {
- for (String properyPrefix : prefixValues) {
- UIDefaults defaults = UIManager.getDefaults();
- Object object = defaults.get(properyPrefix + ".focusInputMap");
- InputMap inputMap = (InputMap) object;
- inputMap.put(keyStroke, action);
- }
- }
-
- private static void setKeyBinding(String existingKsText, String newKsText,
- String[] prefixValues) {
-
- KeyStroke existingKs = KeyStroke.getKeyStroke(existingKsText);
- KeyStroke newKs = KeyStroke.getKeyStroke(newKsText);
-
- for (String properyPrefix : prefixValues) {
-
- UIDefaults defaults = UIManager.getDefaults();
- Object object = defaults.get(properyPrefix + ".focusInputMap");
- InputMap inputMap = (InputMap) object;
- Object action = inputMap.get(existingKs);
- inputMap.put(newKs, action);
- }
- }
-
- /** Allows you to globally set the font size (don't use this method!) */
- private static void setGlobalFontSizeOverride(int fontSize) {
- UIDefaults defaults = UIManager.getDefaults();
-
- Set<Entry<Object, Object>> set = defaults.entrySet();
- Iterator<Entry<Object, Object>> iterator = set.iterator();
- while (iterator.hasNext()) {
- Entry<Object, Object> entry = iterator.next();
- Object key = entry.getKey();
-
- if (key.toString().toLowerCase().indexOf("font") != -1) {
- Font currentFont = defaults.getFont(key);
- if (currentFont != null) {
- Font newFont = currentFont.deriveFont((float) fontSize);
- UIManager.put(key, newFont);
- }
- }
- }
- }
-
- /**
- * Returns the name of the default LookAndFeel for the current OS.
- * @return the name
- */
- public static String getDefaultLookAndFeelName() {
- OperatingSystem OS = Platform.CURRENT_PLATFORM.getOperatingSystem();
- if (OS == OperatingSystem.LINUX) {
- return NIMBUS_LOOK_AND_FEEL;
- }
- return SYSTEM_LOOK_AND_FEEL;
- }
-
/**
* Returns true if the given UI object is using the Aqua Look and Feel.
* @param UI the UI to examine.
@@ -383,31 +80,7 @@ public class LookAndFeelUtils {
*/
public static boolean isUsingNimbusUI() {
LookAndFeel lookAndFeel = UIManager.getLookAndFeel();
- return NIMBUS_LOOK_AND_FEEL.equals(lookAndFeel.getName());
- }
-
- private static String findLookAndFeelClassName(String lookAndFeelName) {
- if (lookAndFeelName.equalsIgnoreCase(SYSTEM_LOOK_AND_FEEL)) {
- return UIManager.getSystemLookAndFeelClassName();
- }
- else if (lookAndFeelName.equalsIgnoreCase(FLAT_LIGHT_LOOK_AND_FEEL)) {
- return "com.formdev.flatlaf.FlatLightLaf";
- }
- else if (lookAndFeelName.equalsIgnoreCase(FLAT_DARK_LOOK_AND_FEEL)) {
- return "com.formdev.flatlaf.FlatDarkLaf";
- }
-
- LookAndFeelInfo[] installedLookAndFeels = UIManager.getInstalledLookAndFeels();
- for (LookAndFeelInfo info : installedLookAndFeels) {
- String className = info.getClassName();
- if (lookAndFeelName.equals(className) || lookAndFeelName.equals(info.getName())) {
- return className;
- }
- }
-
- Msg.debug(LookAndFeelUtils.class,
- "Unable to find requested Look and Feel: " + lookAndFeelName);
- return UIManager.getSystemLookAndFeelClassName();
+ return LookAndFeelType.NIMBUS.equals(lookAndFeel.getName());
}
}
diff --git a/Ghidra/Framework/Docking/src/test/java/docking/theme/GThemeTest.java b/Ghidra/Framework/Docking/src/test/java/docking/theme/GThemeTest.java
index 1bb02e2dc1..8170e8caa7 100644
--- a/Ghidra/Framework/Docking/src/test/java/docking/theme/GThemeTest.java
+++ b/Ghidra/Framework/Docking/src/test/java/docking/theme/GThemeTest.java
@@ -95,7 +95,7 @@ public class GThemeTest extends AbstractGenericTest {
theme = theme.saveToFile(file); // saveToFile returns new theme instance
assertEquals("abc", theme.getName());
- assertEquals("System", theme.getLookAndFeelName());
+ assertEquals(LookAndFeelType.SYSTEM, theme.getLookAndFeelType());
assertEquals(Color.RED, theme.getColor("color.a.1").get(theme));
assertEquals(Color.BLUE, theme.getColor("color.a.2").get(theme));
diff --git a/Ghidra/Framework/Project/src/main/java/ghidra/framework/main/datatable/ProjectDataTableDnDHandler.java b/Ghidra/Framework/Project/src/main/java/ghidra/framework/main/datatable/ProjectDataTableDnDHandler.java
index 3eacbe12e7..aac93747bd 100644
--- a/Ghidra/Framework/Project/src/main/java/ghidra/framework/main/datatable/ProjectDataTableDnDHandler.java
+++ b/Ghidra/Framework/Project/src/main/java/ghidra/framework/main/datatable/ProjectDataTableDnDHandler.java
@@ -28,8 +28,6 @@ import javax.swing.CellRendererPane;
import javax.swing.table.*;
import docking.widgets.table.GTable;
-import ghidra.framework.OperatingSystem;
-import ghidra.framework.Platform;
import ghidra.framework.main.datatree.DataTreeDragNDropHandler;
import ghidra.framework.model.DomainFile;
@@ -159,9 +157,6 @@ public class ProjectDataTableDnDHandler implements DragSourceListener, DragGestu
}
private Image getDragImage(List<DomainFileInfo> files) {
- if (Platform.CURRENT_PLATFORM.getOperatingSystem() != OperatingSystem.MAC_OS_X) {
- return null;
- }
Container parent = table.getParent();
Dimension size = parent.getSize(); // assuming this is JViewport
@@ -243,7 +238,7 @@ public class ProjectDataTableDnDHandler implements DragSourceListener, DragGestu
}
private List<DomainFileInfo> createSelectionList(GTable tableToSelect) {
- ArrayList<DomainFileInfo> list = new ArrayList<DomainFileInfo>();
+ ArrayList<DomainFileInfo> list = new ArrayList<>();
int[] rows = table.getSelectedRows();
@@ -273,7 +268,7 @@ public class ProjectDataTableDnDHandler implements DragSourceListener, DragGestu
}
private Object getDomainFileList() {
- List<DomainFile> domainFileList = new ArrayList<DomainFile>();
+ List<DomainFile> domainFileList = new ArrayList<>();
for (DomainFileInfo domainFileInfo : list) {
domainFileList.add(domainFileInfo.getDomainFile());
}