GP-1981 - Theming - Refactors for module conversions

This commit is contained in:
dragonmacher
2022-09-02 18:41:20 -04:00
committed by ghidragon
parent a99841e6d4
commit 803a9e9864
12 changed files with 48 additions and 26 deletions

View File

@@ -135,12 +135,12 @@ public class InstructionSearchPlugin extends ProgramPlugin {
if (selection.getNumAddresses() == 0) {
dialog.displayMessage(
"Select instructions from the listing (and hit reload) to populate the table.",
Messages.FG_MESSAGE_NORMAL);
Messages.NORMAL);
return false;
}
if (!isSelectionSizeValid(selection)) {
dialog.displayMessage("Invalid selection. Cannot select more than " +
MAX_SELECTION_SIZE + " instructions and/or data items.", Messages.FG_MESSAGE_ERROR);
MAX_SELECTION_SIZE + " instructions and/or data items.", Messages.ERROR);
return false;
}
@@ -150,7 +150,7 @@ public class InstructionSearchPlugin extends ProgramPlugin {
}
}
catch (InvalidInputException e) {
dialog.displayMessage(e.getMessage(), Messages.FG_MESSAGE_ERROR);
dialog.displayMessage(e.getMessage(), Messages.ERROR);
return false;
}

View File

@@ -293,7 +293,7 @@ public class InsertBytesWidget extends DialogComponentProvider implements KeyLis
// exit.
if (allBytes.size() < instruction.getLength()) {
msgPanel.setMessageText("Input invalid: unknown disassembly error.",
Messages.FG_MESSAGE_ERROR);
Messages.ERROR);
return;
}
allBytes.subList(0, instruction.getLength()).clear();
@@ -304,7 +304,7 @@ public class InsertBytesWidget extends DialogComponentProvider implements KeyLis
// If there's an exception, just stop and let the user figure out what went
// wrong - no need to continue.
msgPanel.setMessageText("Input invalid: unknown disassembly error.",
Messages.FG_MESSAGE_ERROR);
Messages.ERROR);
Msg.debug(this, "Error disassembling instruction", e);
return;

View File

@@ -141,7 +141,7 @@ public class InstructionSearchDialog extends DialogComponentProvider implements
if (selection == null && getMessagePanel() != null) {
getMessagePanel().setMessageText(
"Select instructions from the listing (and hit reload) to populate the table.",
Messages.FG_MESSAGE_NORMAL);
Messages.NORMAL);
}
if (selection != null && plugin.isSelectionValid(selection, this)) {

View File

@@ -521,7 +521,7 @@ public class InstructionTable extends AbstractInstructionTable {
dialog.getMessagePanel()
.setMessageText(
"Instruction was loaded manually, no address in the listing to navigate to.",
Messages.FG_MESSAGE_NORMAL);
Messages.NORMAL);
}
}
}

View File

@@ -137,7 +137,7 @@ class SearchInstructionsTask extends Task {
// If we've gone through all the ranges and there are still no results, show an
// error message.
searchDialog.getMessagePanel()
.setMessageText("No results found", Messages.FG_MESSAGE_NORMAL);
.setMessageText("No results found", Messages.NORMAL);
return;
}

View File

@@ -4,6 +4,9 @@ color.bg = white // note: this is the text/widget bg color
color.fg = black
color.fg.error = red
color.fg.disabled = lightGray
color.bg.uneditable = system.color.bg.application // TODO see if there exists an LaF setting for this
color.bg.filtered = yellow
color.fg.hint = lightgray
color.fg.help.selector.h1 = #000080
color.fg.help.selector.h2 = #984C4C
@@ -50,11 +53,11 @@ color.bg.tableheader.gradient.end.primary = rgb(126, 186, 233)
color.bg.textfield.hint.valid = color.bg
color.bg.textfield.hint.invalid = rgb(255,225,225)
color.fg.textfield.hint = color.fg
color.fg.textfield.hint = color.fg.hint
color.bg.tree.drag.no.selection = rgb(204, 204, 255)
color.bg.filterfield = yellow
color.bg.filterfield = color.bg.filtered
color.fg.filterfield = black
color.bg.selection.help = lightSteelBlue
@@ -116,6 +119,8 @@ color.bg = #46494B // color used by flatlaf dark theme
color.fg = lightgray
color.fg.error = indianRed
color.fg.disabled = gray
color.bg.filtered = beige
color.fg.hint = darkgray
color.fg.help.selector.h1 = #66AAF4
color.fg.help.selector.h2 = #9999F9
@@ -144,7 +149,7 @@ color.cursor.unfocussed = darkGray
color.bg.textfield.hint.invalid = maroon
color.bg.filterfield = beige
color.bg.filterfield = color.bg.filtered
color.fg.filterfield = darkSlateGray
color.bg.selection = teal

View File

@@ -24,7 +24,6 @@ import javax.swing.event.DocumentListener;
import docking.DockingUtils;
import generic.theme.GColor;
import generic.theme.GThemeDefaults.Colors.Palette;
import ghidra.util.SystemUtilities;
import ghidra.util.datastruct.WeakDataStructureFactory;
import ghidra.util.datastruct.WeakSet;
@@ -48,7 +47,7 @@ public class FilterTextField extends JPanel {
private static Color FILTERED_BACKGROUND_COLOR = new GColor("color.bg.filterfield");
private static Color FILTERED_FOREGROUND_COLOR = new GColor("color.fg.filterfield");
/*package*/ static Color UNEDITABLE_BACKGROUND_COLOR = Palette.LIGHT_GRAY;
/*package*/ static Color UNEDITABLE_BACKGROUND_COLOR = new GColor("color.bg.uneditable");
private Color noFlashBgColor;
private Color noFlashFgColor;

View File

@@ -23,6 +23,7 @@ import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import generic.theme.GColor;
import generic.theme.GThemeDefaults.Colors.Messages;
/**
* Simple text field that shows a text hint when the field is empty.
@@ -127,7 +128,7 @@ public class HintTextField extends JTextField {
}
Graphics2D g2 = (Graphics2D) g;
g2.setColor(Color.LIGHT_GRAY);
g2.setColor(Messages.HINT);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
Dimension size = getSize();

View File

@@ -129,11 +129,7 @@ public class GColor extends Color {
@Override
public String toString() {
Color c = delegate;
String rgb =
"(" + c.getRed() + "," + c.getGreen() + "," + c.getBlue() + "," + c.getAlpha() + ")";
return getClass().getSimpleName() + " [id = " + id + ", color = " +
c.getClass().getSimpleName() + rgb + "]";
return toHexString();
}
/**
@@ -144,6 +140,22 @@ public class GColor extends Color {
return WebColors.toString(this, false);
}
public String toDebugString() {
Color c = delegate;
String rgb =
"(" + c.getRed() + "," + c.getGreen() + "," + c.getBlue() + "," + c.getAlpha() + ")";
return getClass().getSimpleName() + " [id = " + id + ", color = " +
c.getClass().getSimpleName() + rgb + "]";
}
public String toDebugHexString() {
Color c = delegate;
String rgb =
"(" + WebColors.toString(c, true) + ")";
return getClass().getSimpleName() + " [id = " + id + ", color = " +
c.getClass().getSimpleName() + rgb + "]";
}
@Override
public int hashCode() {
return Objects.hash(id, alpha);

View File

@@ -44,7 +44,7 @@ public class GThemeDefaults {
public static final GColor BACKGROUND = new GColor("color.bg");
public static final GColor CURSOR = new GColor("color.cursor.focused");
public static final GColor DISABLED = new GColor("color.palette.disabled");
public static final GColor ERROR = new GColor("color.fg.error");
public static final GColor ERROR = new GColor("color.fg.error"); // TODO replace most uses of this with Messages.ERROR
public static final GColor FOREGROUND = new GColor("color.fg");
public static final GColor FOREGROUND_DISABLED = new GColor("color.fg.disabled");
public static final GColor TOOLTIP_BACKGROUND = new GColor("color.bg.tooltip");
@@ -65,10 +65,16 @@ public class GThemeDefaults {
//@formatter:on
}
/**
* 'Messages' is primarily used by system dialogs to display status. That the colors are
* used for foregrounds is implied.
*/
public static class Messages {
//@formatter:off
public static final GColor FG_MESSAGE_NORMAL = new GColor("color.fg.dialog.status.normal");
public static final GColor FG_MESSAGE_ERROR = new GColor("color.fg.dialog.status.error");
public static final GColor NORMAL = new GColor("color.fg.dialog.status.normal");
public static final GColor ERROR = new GColor("color.fg.dialog.status.error");
public static final GColor HINT = new GColor("color.fg.hint");
//@formatter:on
}
@@ -84,6 +90,7 @@ public class GThemeDefaults {
public static final GColor BLACK = getColor("black");
public static final GColor BLUE = getColor("blue");
public static final GColor CYAN = getColor("cyan");
public static final GColor DARK_GRAY = getColor("darkgray");
public static final GColor GOLD = getColor("gold");
public static final GColor GRAY = getColor("gray");
public static final GColor GREEN = getColor("green");
@@ -114,7 +121,5 @@ public class GThemeDefaults {
return new GColor("color.palette." + name);
}
}
}
}

View File

@@ -61,7 +61,7 @@ class EditPluginPathDialog extends DialogComponentProvider {
private final static int SIDE_MARGIN = 5;
private final static Color INVALID_PATH_COLOR = Tables.FG_ERROR_UNSELECTED;
private final static Color INVALID_SELECTED_PATH_COLOR = Tables.FG_ERROR_SELECTED;
private final static Color STATUS_MESSAGE_COLOR = Messages.FG_MESSAGE_NORMAL;
private final static Color STATUS_MESSAGE_COLOR = Messages.NORMAL;
final static String EMPTY_STATUS = " ";
private ExtensionFileFilter JAR_FILTER =

View File

@@ -96,7 +96,7 @@ public class LogPanel extends JPanel implements LogListener {
public void messageLogged(String message, boolean isError) {
messageUpdater.run(() -> {
label.setForeground(isError ? Messages.FG_MESSAGE_ERROR : defaultColor);
label.setForeground(isError ? Messages.ERROR : defaultColor);
String text = message.replace("\n", " ");
label.setText(text);
label.setToolTipText(text);