mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-06 12:00:04 +02:00
GP-1981 registering Theme options for colors and fonts
This commit is contained in:
parent
45c52e3cb9
commit
5c84d3e143
28 changed files with 299 additions and 259 deletions
|
@ -395,7 +395,7 @@ public class Gui {
|
|||
*/
|
||||
public static void setColor(String id, Color color) {
|
||||
if (color == null) {
|
||||
|
||||
throw new IllegalArgumentException("Can't set theme value to null!");
|
||||
}
|
||||
if (color instanceof GColor gColor) {
|
||||
if (id.equals(gColor.getId())) {
|
||||
|
|
|
@ -26,7 +26,8 @@ import javax.swing.KeyStroke;
|
|||
import javax.swing.SwingUtilities;
|
||||
|
||||
import generic.theme.*;
|
||||
import ghidra.util.*;
|
||||
import ghidra.util.HelpLocation;
|
||||
import ghidra.util.Msg;
|
||||
import ghidra.util.datastruct.WeakDataStructureFactory;
|
||||
import ghidra.util.datastruct.WeakSet;
|
||||
import ghidra.util.exception.AssertException;
|
||||
|
@ -140,24 +141,10 @@ public abstract class AbstractOptions implements Options {
|
|||
}
|
||||
|
||||
if (type == OptionType.COLOR_TYPE) {
|
||||
if (defaultValue instanceof GColor gColor) {
|
||||
registerThemeColor(optionName, gColor.getId(), help, description, editor);
|
||||
return;
|
||||
}
|
||||
warnNonThemeValue("Registering non theme color: " + optionName);
|
||||
warnShouldUseTheme("Color");
|
||||
}
|
||||
if (type == OptionType.FONT_TYPE) {
|
||||
if (defaultValue instanceof String fontId) {
|
||||
registerThemeFont(optionName, fontId, help, description);
|
||||
return;
|
||||
}
|
||||
String message = "Registering non theme font: " + optionName;
|
||||
if (SystemUtilities.isInDevelopmentMode()) {
|
||||
Msg.warn(this, message, ReflectionUtilities.createJavaFilteredThrowable());
|
||||
}
|
||||
else {
|
||||
Msg.warn(this, message);
|
||||
}
|
||||
warnShouldUseTheme("font");
|
||||
}
|
||||
|
||||
if (!type.isCompatible(defaultValue)) {
|
||||
|
@ -187,28 +174,30 @@ public abstract class AbstractOptions implements Options {
|
|||
valueMap.put(optionName, option);
|
||||
}
|
||||
|
||||
protected void warnNonThemeValue(String message) {
|
||||
if (SystemUtilities.isInDevelopmentMode()) {
|
||||
Msg.warn(this, message, ReflectionUtilities.createJavaFilteredThrowable());
|
||||
}
|
||||
else {
|
||||
Msg.warn(this, message);
|
||||
}
|
||||
private void warnShouldUseTheme(String optionType) {
|
||||
Throwable throwable =
|
||||
ReflectionUtilities.createThrowableWithStackOlderThan(AbstractOptions.class,
|
||||
SubOptions.class);
|
||||
String call = throwable.getStackTrace()[0].toString();
|
||||
Msg.warn(this, "Registering a direct " + optionType + " in the options is deprecated." +
|
||||
" Use registerTheme" + optionType + "Binding() instead!\n Called from " + call + "\n");
|
||||
}
|
||||
|
||||
private void registerThemeColor(String optionName, String colorId, HelpLocation help,
|
||||
String description, PropertyEditor editor) {
|
||||
@Override
|
||||
public void registerThemeColorBinding(String optionName, String colorId, HelpLocation help,
|
||||
String description) {
|
||||
Option currentOption = getExistingComptibleOption(optionName, OptionType.COLOR_TYPE);
|
||||
if (currentOption != null && currentOption instanceof ThemeColorOption) {
|
||||
currentOption.updateRegistration(description, help, null, editor);
|
||||
currentOption.updateRegistration(description, help, null, null);
|
||||
return;
|
||||
}
|
||||
description += " (Theme Color: " + colorId + ")";
|
||||
Option option = new ThemeColorOption(optionName, colorId, description, help, editor);
|
||||
Option option = new ThemeColorOption(optionName, colorId, description, help);
|
||||
valueMap.put(optionName, option);
|
||||
}
|
||||
|
||||
private void registerThemeFont(String optionName, String fontId, HelpLocation help,
|
||||
@Override
|
||||
public void registerThemeFontBinding(String optionName, String fontId, HelpLocation help,
|
||||
String description) {
|
||||
if (Gui.getFont(fontId) == null) {
|
||||
throw new IllegalArgumentException("Invalid theme font id: \"" + fontId + "\"");
|
||||
|
|
|
@ -149,6 +149,29 @@ public interface Options {
|
|||
public void registerOption(String optionName, OptionType type, Object defaultValue,
|
||||
HelpLocation help, String description, PropertyEditor editor);
|
||||
|
||||
/**
|
||||
* Register/binds the option to a theme color id. Changing the option's color via the options
|
||||
* Gui will result in directly changing the theme color of the given color id.
|
||||
* @param optionName the name of the color option
|
||||
* @param colorId the theme color id whose color value is changed when the option's color is changed
|
||||
* @param help the HelpLocation for this option
|
||||
* @param description a description of the option
|
||||
*/
|
||||
public void registerThemeColorBinding(String optionName, String colorId, HelpLocation help,
|
||||
String description);
|
||||
|
||||
/**
|
||||
* Register/binds the option to a theme font id. Changing the option's font via the options
|
||||
* Gui will result in directly changing the theme color of the given font id.
|
||||
* @param optionName the name of the font option
|
||||
* @param fontId the theme color id whose color value is changed when the option's color
|
||||
* is changed
|
||||
* @param help the HelpLocation for this option
|
||||
* @param description a description of the option
|
||||
*/
|
||||
public void registerThemeFontBinding(String optionName, String fontId, HelpLocation help,
|
||||
String description);
|
||||
|
||||
/**
|
||||
* Register the options editor that will handle the editing for all the options or a sub group of options.
|
||||
* @param editor the custom editor panel to be used to edit the options or sub group of options.
|
||||
|
|
|
@ -92,6 +92,18 @@ public class SubOptions implements Options {
|
|||
options.registerOption(prefix + optionName, type, defaultValue, help, description, editor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerThemeColorBinding(String optionName, String colorId, HelpLocation help,
|
||||
String description) {
|
||||
options.registerThemeColorBinding(prefix + optionName, colorId, help, description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerThemeFontBinding(String optionName, String fontId, HelpLocation help,
|
||||
String description) {
|
||||
options.registerThemeFontBinding(prefix + optionName, fontId, help, description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putObject(String optionName, Object obj) {
|
||||
options.putObject(prefix + optionName, obj);
|
||||
|
|
|
@ -16,11 +16,11 @@
|
|||
package ghidra.framework.options;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.beans.PropertyEditor;
|
||||
|
||||
import generic.theme.GColor;
|
||||
import generic.theme.Gui;
|
||||
import ghidra.util.HelpLocation;
|
||||
import ghidra.util.Msg;
|
||||
|
||||
/**
|
||||
* Options implementation for theme color options. A ThemeColorOption is an option that, when
|
||||
|
@ -32,18 +32,20 @@ public class ThemeColorOption extends Option {
|
|||
private String colorId;
|
||||
|
||||
public ThemeColorOption(String optionName, String colorId, String description,
|
||||
HelpLocation help, PropertyEditor editor) {
|
||||
super(optionName, OptionType.COLOR_TYPE, description, help, null, true, editor);
|
||||
HelpLocation help) {
|
||||
super(optionName, OptionType.COLOR_TYPE, description, help, null, true, null);
|
||||
this.colorId = colorId;
|
||||
if (!Gui.hasColor(colorId)) {
|
||||
Msg.warn(this,
|
||||
"Registered a theme color option with a non-defined theme color id of \"" +
|
||||
colorId + "\"");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getCurrentValue() {
|
||||
GColor gColor = new GColor(colorId);
|
||||
if (gColor.isUnresolved()) {
|
||||
return null;
|
||||
}
|
||||
return gColor;
|
||||
return new GColor(colorId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -19,6 +19,7 @@ import java.awt.Font;
|
|||
|
||||
import generic.theme.Gui;
|
||||
import ghidra.util.HelpLocation;
|
||||
import ghidra.util.Msg;
|
||||
|
||||
/**
|
||||
* Options implementation for theme font options. A ThemeFontOption is an option that, when
|
||||
|
@ -33,6 +34,12 @@ public class ThemeFontOption extends Option {
|
|||
HelpLocation help) {
|
||||
super(optionName, OptionType.FONT_TYPE, description, help, null, true, null);
|
||||
this.fontId = fontId;
|
||||
if (!Gui.hasFont(fontId)) {
|
||||
Msg.warn(this,
|
||||
"Registered a theme font option with a non-defined theme font id of \"" +
|
||||
fontId + "\"");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue