From 46b7abb4eb2626c730ddc44ac02e02c657bbba36 Mon Sep 17 00:00:00 2001 From: FisherLuba <145061313+FisherLuba@users.noreply.github.com> Date: Tue, 19 Mar 2024 16:28:57 -0400 Subject: [PATCH 01/10] Begin work on better color theming such as for color blindness so users can specify their own colors for #426. --- src/main/java/edu/rpi/legup/Legup.java | 2 + src/main/java/edu/rpi/legup/ui/HomePanel.java | 2 +- src/main/java/edu/rpi/legup/ui/LegupUI.java | 14 ++- .../edu/rpi/legup/ui/ProofEditorPanel.java | 27 +++--- .../edu/rpi/legup/ui/PuzzleEditorPanel.java | 56 +++++++----- .../rpi/legup/ui/color/ColorPreferences.java | 91 +++++++++++++++++++ src/main/resources/color-theme.txt | 2 + 7 files changed, 156 insertions(+), 38 deletions(-) create mode 100644 src/main/java/edu/rpi/legup/ui/color/ColorPreferences.java create mode 100644 src/main/resources/color-theme.txt diff --git a/src/main/java/edu/rpi/legup/Legup.java b/src/main/java/edu/rpi/legup/Legup.java index 79471286b..a9acc759e 100644 --- a/src/main/java/edu/rpi/legup/Legup.java +++ b/src/main/java/edu/rpi/legup/Legup.java @@ -1,6 +1,7 @@ package edu.rpi.legup; import edu.rpi.legup.app.GameBoardFacade; +import edu.rpi.legup.ui.color.ColorPreferences; import edu.rpi.legup.utility.Logger; public class Legup { @@ -14,5 +15,6 @@ public static void main(String[] args) { Logger.initLogger(); GameBoardFacade.getInstance(); GameBoardFacade.setupConfig(); + ColorPreferences.loadColorScheme(); } } diff --git a/src/main/java/edu/rpi/legup/ui/HomePanel.java b/src/main/java/edu/rpi/legup/ui/HomePanel.java index 11f51eb0e..8c09cc97a 100644 --- a/src/main/java/edu/rpi/legup/ui/HomePanel.java +++ b/src/main/java/edu/rpi/legup/ui/HomePanel.java @@ -66,7 +66,7 @@ public void actionPerformed(ActionEvent e) { } }; - public HomePanel(FileDialog fileDialog, JFrame frame, LegupUI legupUI) { + public HomePanel(JFrame frame, LegupUI legupUI) { this.legupUI = legupUI; this.frame = frame; setLayout(new GridLayout(1, 2)); diff --git a/src/main/java/edu/rpi/legup/ui/LegupUI.java b/src/main/java/edu/rpi/legup/ui/LegupUI.java index eb8b1663c..d7ad16049 100644 --- a/src/main/java/edu/rpi/legup/ui/LegupUI.java +++ b/src/main/java/edu/rpi/legup/ui/LegupUI.java @@ -8,6 +8,7 @@ import edu.rpi.legup.ui.proofeditorui.treeview.TreePanel; import java.awt.*; import java.awt.event.*; +import java.io.File; import java.security.InvalidParameterException; import java.util.Objects; import javax.swing.*; @@ -17,7 +18,8 @@ public class LegupUI extends JFrame implements WindowListener { private static final Logger LOGGER = LogManager.getLogger(LegupUI.class.getName()); - protected FileDialog fileDialog; +// protected FileDialog fileDialog; + protected JFileChooser fileChooser; protected JPanel window; protected LegupPanel[] panels; @@ -52,7 +54,9 @@ public LegupUI() { System.err.println("Not supported ui look and feel"); } - fileDialog = new FileDialog(this); +// fileDialog = new FileDialog(this); + fileChooser = new JFileChooser(); + fileChooser.setCurrentDirectory(new File(LegupPreferences.WORK_DIRECTORY)); initPanels(); displayPanel(0); @@ -97,9 +101,9 @@ private void initPanels() { add(window); panels = new LegupPanel[3]; - panels[0] = new HomePanel(this.fileDialog, this, this); - panels[1] = new ProofEditorPanel(this.fileDialog, this, this); - panels[2] = new PuzzleEditorPanel(this.fileDialog, this, this); + panels[0] = new HomePanel(this, this); + panels[1] = new ProofEditorPanel(this.fileChooser, this, this); + panels[2] = new PuzzleEditorPanel(this.fileChooser, this, this); } protected void displayPanel(int option) { diff --git a/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java b/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java index 956f83ba4..b9b3284e2 100644 --- a/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java +++ b/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java @@ -29,6 +29,7 @@ import java.io.IOException; import java.net.URI; import java.net.URL; +import java.nio.file.Path; import java.util.List; import java.util.Objects; import javax.swing.*; @@ -40,7 +41,7 @@ public class ProofEditorPanel extends LegupPanel implements IHistoryListener { private static final Logger LOGGER = LogManager.getLogger(ProofEditorPanel.class.getName()); private JMenuBar mBar; private TreePanel treePanel; - private FileDialog fileDialog; + private JFileChooser fileChooser; private JFrame frame; private RuleFrame ruleFrame; private DynamicView dynamicBoardView; @@ -111,8 +112,8 @@ public class ProofEditorPanel extends LegupPanel implements IHistoryListener { protected JMenuItem testAI = new JMenuItem("Test AI!"); protected JMenuItem hintAI = new JMenuItem("Hint"); - public ProofEditorPanel(FileDialog fileDialog, JFrame frame, LegupUI legupUI) { - this.fileDialog = fileDialog; + public ProofEditorPanel(JFileChooser fileChooser, JFrame frame, LegupUI legupUI) { + this.fileChooser = fileChooser; this.frame = frame; this.legupUI = legupUI; setLayout(new BorderLayout()); @@ -581,21 +582,25 @@ private void saveProofAs() { return; } - fileDialog.setMode(FileDialog.SAVE); - fileDialog.setTitle("Save As"); + fileChooser.setDialogType(JFileChooser.SAVE_DIALOG); +// fileChooser.setMode(JFileChooser.SAVE); +// fileChooser.setTitle("Save As"); + fileChooser.setDialogTitle("Save as"); String curFileName = GameBoardFacade.getInstance().getCurFileName(); if (curFileName == null) { - fileDialog.setDirectory( - LegupPreferences.getInstance().getUserPref(LegupPreferences.WORK_DIRECTORY)); + fileChooser.setCurrentDirectory( +// fileChooser.setDirectory( + Path.of(LegupPreferences.getInstance().getUserPref(LegupPreferences.WORK_DIRECTORY)).toFile()); } else { File curFile = new File(curFileName); - fileDialog.setDirectory(curFile.getParent()); +// fileChooser.setDirectory(curFile.getParent()); + fileChooser.setCurrentDirectory(curFile.getParentFile()); } - fileDialog.setVisible(true); + fileChooser.setVisible(true); String fileName = null; - if (fileDialog.getDirectory() != null && fileDialog.getFile() != null) { - fileName = fileDialog.getDirectory() + File.separator + fileDialog.getFile(); + if (fileChooser.getCurrentDirectory() != null && fileChooser.getSelectedFile() != null) { + fileName = fileChooser.getCurrentDirectory() + File.separator + fileChooser.getSelectedFile(); } if (fileName != null) { diff --git a/src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java b/src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java index b3cd30ffb..812587426 100644 --- a/src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java +++ b/src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.net.URI; import java.net.URL; +import java.nio.file.Path; import java.util.Objects; import javax.swing.*; import javax.swing.border.TitledBorder; @@ -44,7 +45,7 @@ public class PuzzleEditorPanel extends LegupPanel implements IHistoryListener { private BoardView boardView; private TitledBorder boardBorder; // private JSplitPane splitPanel, topHalfPanel; - private FileDialog fileDialog; + private JFileChooser fileChooser; private JMenuItem undo, redo, fitBoardToScreen; private ElementFrame elementFrame; private JPanel treePanel; @@ -52,8 +53,8 @@ public class PuzzleEditorPanel extends LegupPanel implements IHistoryListener { private EditorElementController editorElementController; static final int[] TOOLBAR_SEPARATOR_BEFORE = {2, 4, 8}; - public PuzzleEditorPanel(FileDialog fileDialog, JFrame frame, LegupUI legupUI) { - this.fileDialog = fileDialog; + public PuzzleEditorPanel(JFileChooser fileChooser, JFrame frame, LegupUI legupUI) { + this.fileChooser = fileChooser; this.frame = frame; this.legupUI = legupUI; setLayout(new BorderLayout()); @@ -384,20 +385,25 @@ public Object[] promptPuzzle() { return new Object[0]; } } - if (fileDialog == null) { - fileDialog = new FileDialog(this.frame); + if (fileChooser == null) { +// fileChooser = new JFileChooser(this.frame); + fileChooser = new JFileChooser(); } LegupPreferences preferences = LegupPreferences.getInstance(); String preferredDirectory = preferences.getUserPref(LegupPreferences.WORK_DIRECTORY); - fileDialog.setMode(FileDialog.LOAD); - fileDialog.setTitle("Select Puzzle"); - fileDialog.setDirectory(preferredDirectory); - fileDialog.setVisible(true); +// fileChooser.setMode(JFileChooser.LOAD); + fileChooser.setDialogType(JFileChooser.OPEN_DIALOG); +// fileChooser.setTitle("Select Puzzle"); + fileChooser.setDialogTitle("Select Puzzle"); +// fileChooser.setDirectory(preferredDirectory); + fileChooser.setCurrentDirectory(Path.of(preferredDirectory).toFile()); + fileChooser.showOpenDialog(this); + fileChooser.setVisible(true); String fileName = null; File puzzleFile = null; - if (fileDialog.getDirectory() != null && fileDialog.getFile() != null) { - fileName = fileDialog.getDirectory() + File.separator + fileDialog.getFile(); + if (fileChooser.getCurrentDirectory() != null && fileChooser.getSelectedFile() != null) { + fileName = fileChooser.getCurrentDirectory() + File.separator + fileChooser.getSelectedFile(); puzzleFile = new File(fileName); } else { // The attempt to prompt a puzzle ended gracefully (cancel) @@ -538,25 +544,33 @@ private String savePuzzle() { } } - if (fileDialog == null) { - fileDialog = new FileDialog(this.frame); + if (fileChooser == null) { +// fileChooser = new JFileChooser(this.frame); + fileChooser = new JFileChooser(); + fileChooser.showOpenDialog(this); + fileChooser.setVisible(true); } - fileDialog.setMode(FileDialog.SAVE); - fileDialog.setTitle("Save Proof"); +// fileChooser.setMode(JFileChooser.SAVE); + fileChooser.setDialogType(JFileChooser.SAVE_DIALOG); +// fileChooser.setTitle("Save Proof"); + fileChooser.setDialogTitle("Save Proof"); String curFileName = GameBoardFacade.getInstance().getCurFileName(); if (curFileName == null) { - fileDialog.setDirectory( - LegupPreferences.getInstance().getUserPref(LegupPreferences.WORK_DIRECTORY)); +// fileChooser.setDirectory( + fileChooser.setCurrentDirectory( + Path.of(LegupPreferences.getInstance().getUserPref(LegupPreferences.WORK_DIRECTORY)).toFile()); } else { File curFile = new File(curFileName); - fileDialog.setDirectory(curFile.getParent()); +// fileChooser.setDirectory(curFile.getParent()); + fileChooser.setCurrentDirectory(curFile.getParentFile()); } - fileDialog.setVisible(true); + fileChooser.showOpenDialog(this); + fileChooser.setVisible(true); String fileName = null; - if (fileDialog.getDirectory() != null && fileDialog.getFile() != null) { - fileName = fileDialog.getDirectory() + File.separator + fileDialog.getFile(); + if (fileChooser.getCurrentDirectory() != null && fileChooser.getSelectedFile() != null) { + fileName = fileChooser.getCurrentDirectory() + File.separator + fileChooser.getSelectedFile(); } if (fileName != null) { diff --git a/src/main/java/edu/rpi/legup/ui/color/ColorPreferences.java b/src/main/java/edu/rpi/legup/ui/color/ColorPreferences.java new file mode 100644 index 000000000..87a3c41e5 --- /dev/null +++ b/src/main/java/edu/rpi/legup/ui/color/ColorPreferences.java @@ -0,0 +1,91 @@ +package edu.rpi.legup.ui.color; + +import java.awt.*; +import java.io.*; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardOpenOption; +import java.util.*; +import java.util.List; +import java.util.stream.Collectors; + +public class ColorPreferences { + + private static final String COLOR_THEME_FILE_NAME = "color-theme.txt"; + + private static final Map COLOR_MAP = new EnumMap<>(UIColor.class); + + public enum UIColor { + + CORRECT, + INCORRECT + + ; + + public String configKey() { + return this.toString().toLowerCase().replace('_', '-'); + } + + public Color get() { + return COLOR_MAP.get(this); + } + } + + public static void loadColorScheme() { + final File file = Path.of(COLOR_THEME_FILE_NAME).toFile(); + final InputStream input = ClassLoader.getSystemClassLoader().getResourceAsStream(COLOR_THEME_FILE_NAME); + BufferedReader reader; + boolean copyResourceToFile = false; + if (!file.exists()) { + try { + file.createNewFile(); + copyResourceToFile = true; + } + catch (IOException e) { + System.err.println("Could not create " + COLOR_THEME_FILE_NAME); + } + if (input == null) { + throw new RuntimeException("Could not find resource " + COLOR_THEME_FILE_NAME); + } + reader = new BufferedReader(new InputStreamReader(input)); + } + else { + try { + reader = new BufferedReader(new FileReader(file)); + } + catch (FileNotFoundException e) { + throw new RuntimeException("Could not find file " + file.getAbsoluteFile()); + } + } + final List lines = reader.lines().toList(); + if (copyResourceToFile) { + final Path path = file.toPath(); + lines.forEach(line -> { + try { + Files.writeString(path, line + System.lineSeparator(), StandardOpenOption.APPEND); + } + catch (IOException e) { + throw new RuntimeException(e); + } + }); + } + + COLOR_MAP.putAll(lines.stream() + .filter(l -> !l.startsWith("//")) // Use // for comments + .map(l -> l.split(":")) + .filter(a -> a.length == 2) + .peek(a -> System.out.println(Arrays.toString(a))) + .collect(Collectors.toMap(e -> UIColor.valueOf(e[0]), e -> colorFromString(e[1].strip())))); + System.out.println("Colors: " + COLOR_MAP); + } + + public static Color colorFromString(String color) { + try { + return (Color) Color.class.getField(color).get(null); + } + catch (NullPointerException | NoSuchFieldException | IllegalAccessException | ClassCastException e) { + return Color.getColor(color); + } + } + +} diff --git a/src/main/resources/color-theme.txt b/src/main/resources/color-theme.txt new file mode 100644 index 000000000..6de0cd9d8 --- /dev/null +++ b/src/main/resources/color-theme.txt @@ -0,0 +1,2 @@ +CORRECT: BLUE +INCORRECT: RED \ No newline at end of file From 85f4fc3041b2a6e81ad57b8a38bc464ff286f325 Mon Sep 17 00:00:00 2001 From: FisherLuba <145061313+FisherLuba@users.noreply.github.com> Date: Tue, 19 Mar 2024 17:48:22 -0400 Subject: [PATCH 02/10] Add colors to color-theme.txt and LegupLookAndFeel.java --- src/main/java/edu/rpi/legup/Legup.java | 2 + .../legup/ui/boardview/DataSelectionView.java | 5 +- .../rpi/legup/ui/boardview/ElementView.java | 5 +- .../rpi/legup/ui/color/ColorPreferences.java | 124 ++++++++- .../ui/lookandfeel/LegupLookAndFeel.java | 257 ++++++++++++------ src/main/resources/color-theme.txt | 90 +++++- 6 files changed, 381 insertions(+), 102 deletions(-) diff --git a/src/main/java/edu/rpi/legup/Legup.java b/src/main/java/edu/rpi/legup/Legup.java index a9acc759e..f714994fd 100644 --- a/src/main/java/edu/rpi/legup/Legup.java +++ b/src/main/java/edu/rpi/legup/Legup.java @@ -4,6 +4,8 @@ import edu.rpi.legup.ui.color.ColorPreferences; import edu.rpi.legup.utility.Logger; +import java.awt.*; + public class Legup { /** diff --git a/src/main/java/edu/rpi/legup/ui/boardview/DataSelectionView.java b/src/main/java/edu/rpi/legup/ui/boardview/DataSelectionView.java index cedfa08fe..25bd4d155 100644 --- a/src/main/java/edu/rpi/legup/ui/boardview/DataSelectionView.java +++ b/src/main/java/edu/rpi/legup/ui/boardview/DataSelectionView.java @@ -1,14 +1,17 @@ package edu.rpi.legup.ui.boardview; import edu.rpi.legup.controller.ElementController; +import edu.rpi.legup.ui.color.ColorPreferences; + import java.awt.*; import javax.swing.*; import javax.swing.border.BevelBorder; +import edu.rpi.legup.ui.color.ColorPreferences.*; public class DataSelectionView extends JPopupMenu { public DataSelectionView(ElementController controller) { - setBackground(Color.GRAY); + setBackground(UIColor.DATA_SELECTION_BACKGROUND.get()); setBorder(new BevelBorder(BevelBorder.RAISED)); } } diff --git a/src/main/java/edu/rpi/legup/ui/boardview/ElementView.java b/src/main/java/edu/rpi/legup/ui/boardview/ElementView.java index 83b2cb099..de961efd3 100644 --- a/src/main/java/edu/rpi/legup/ui/boardview/ElementView.java +++ b/src/main/java/edu/rpi/legup/ui/boardview/ElementView.java @@ -1,6 +1,8 @@ package edu.rpi.legup.ui.boardview; import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.ui.color.ColorPreferences; + import java.awt.*; import java.awt.geom.AffineTransform; import java.awt.geom.PathIterator; @@ -8,6 +10,7 @@ import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import javax.swing.*; +import edu.rpi.legup.ui.color.ColorPreferences.UIColor; public abstract class ElementView implements Shape { protected int index; @@ -79,7 +82,7 @@ public void drawElement(Graphics2D graphics2D) { new Rectangle2D.Double( location.x + 0.5f, location.y + 0.5f, size.width - 2, size.height - 2)); - graphics2D.setColor(Color.BLACK); + graphics2D.setColor(UIColor.ELEMENT_VIEW_DEFAULT.get()); FontMetrics metrics = graphics2D.getFontMetrics(graphics2D.getFont()); String value = String.valueOf(puzzleElement.getData()); int xText = location.x + (size.width - metrics.stringWidth(value)) / 2; diff --git a/src/main/java/edu/rpi/legup/ui/color/ColorPreferences.java b/src/main/java/edu/rpi/legup/ui/color/ColorPreferences.java index 87a3c41e5..1bdd7f075 100644 --- a/src/main/java/edu/rpi/legup/ui/color/ColorPreferences.java +++ b/src/main/java/edu/rpi/legup/ui/color/ColorPreferences.java @@ -1,12 +1,14 @@ package edu.rpi.legup.ui.color; +import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialColors; + import java.awt.*; import java.io.*; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardOpenOption; -import java.util.*; import java.util.List; +import java.util.*; import java.util.stream.Collectors; public class ColorPreferences { @@ -18,9 +20,93 @@ public class ColorPreferences { public enum UIColor { CORRECT, - INCORRECT - - ; + INCORRECT, + DATA_SELECTION_BACKGROUND, + ELEMENT_VIEW_DEFAULT, + BUTTON_HIGHLIGHT_DEFAULT, + BUTTON_BACKGROUND_DEFAULT, + BUTTON_FOREGROUND_DEFAULT, + CHECKBOX_BACKGROUND_DEFAULT, + CHECKBOX_FOREGROUND_DEFAULT, + COMBOBOX_BACKGROUND_DEFAULT, + COMBOBOX_FOREGROUND_DEFAULT, + COMBOBOX_BUTTON_BACKGROUND_DEFAULT, + COMBOBOX_SELECTION_BACKGROUND_DEFAULT, + COMBOBOX_SELECTION_FOREGROUND_DEFAULT, + COMBOBOX_SELECTED_IN_DROP_DOWN_BACKGROUND_DEFAULT, + LABEL_BACKGROUND_DEFAULT, + LABEL_FOREGROUND_DEFAULT, + MENU_BACKGROUND_DEFAULT, + MENU_FOREGROUND_DEFAULT, + MENU_SELECTION_BACKGROUND_DEFAULT, + MENU_SELECTION_FOREGROUND_DEFAULT, + MENU_DISABLED_FOREGROUND_DEFAULT, + MENU_BAR_BACKGROUND_DEFAULT, + MENU_BAR_FOREGROUND_DEFAULT, + MENU_ITEM_DISABLED_FOREGROUND_DEFAULT, + MENU_ITEM_SELECTION_BACKGROUND_DEFAULT, + MENU_ITEM_SELECTION_FOREGROUND_DEFAULT, + MENU_ITEM_BACKGROUND_DEFAULT, + MENU_ITEM_FOREGROUND_DEFAULT, + OPTION_PANE_BACKGROUND_DEFAULT, + PANEL_BACKGROUND_COLOR_DEFAULT, + POPUP_MENU_BACKGROUND_DEFAULT, + POPUP_MENU_FOREGROUND_DEFAULT, + RADIO_BUTTON_BACKGROUND_DEFAULT, + RADIO_BUTTON_FOREGROUND_DEFAULT, + SPINNER_BACKGROUND_DEFAULT, + SPINNER_FOREGROUND_DEFAULT, + SPINNER_ARROW_BUTTON_BACKGROUND_DEFAULT, + SCROLL_BAR_TRACK_DEFAULT, + SCROLL_BAR_THUMB_DEFAULT, + SCROLL_BAR_THUMB_DARK_SHADOW_DEFAULT, + SCROLL_BAR_THUMB_HIGHLIGHT_DEFAULT, + SCROLL_BAR_THUMB_SHADOW_DEFAULT, + SCROLL_BAR_ARROW_BUTTON_BACKGROUND_DEFAULT, + SCROLL_PANE_BACKGROUND_DEFAULT, + SLIDER_BACKGROUND_DEFAULT, + SLIDER_FOREGROUND_DEFAULT, + SLIDER_TRACK_COLOR_DEFAULT, + SPLIT_PANE_BACKGROUND_DEFAULT, + TABBED_PANE_BACKGROUND_DEFAULT, + TABBED_PANE_FOREGROUND_DEFAULT, + TABBED_PANE_HIGHLIGHT_DEFAULT, + TABBED_PANE_BORDER_HIGHLIGHT_DEFAULT, + TABLE_SELECTION_BACKGROUND_DEFAULT, + TABLE_SELECTION_FOREGROUND_DEFAULT, + TABLE_BACKGROUND_DEFAULT, + TABLE_GRID_COLOR_DEFAULT, + TABLE_HEADER_BACKGROUND_DEFAULT, + TEXT_AREA_BACKGROUND_DEFAULT, + TEXT_AREA_FOREGROUND_DEFAULT, + TOGGLE_BUTTON_BACKGROUND_DEFAULT, + TOGGLE_BUTTON_FOREGROUND_DEFAULT, + TOOL_BAR_BACKGROUND_DEFAULT, + TOOL_BAR_FOREGROUND_DEFAULT, + TOOL_BAR_DOCKING_BACKGROUND_DEFAULT, + TOOL_BAR_FLOATING_BACKGROUND_DEFAULT, + TREE_SELECTION_FOREGROUND_DEFAULT, + TREE_FOREGROUND_DEFAULT, + TREE_SELECTION_BACKGROUND_DEFAULT, + TREE_BACKGROUND_DEFAULT, + RADIO_BUTTON_MENU_ITEM_FOREGROUND_DEFAULT, + RADIO_BUTTON_MENU_ITEM_SELECTION_FOREGROUND_DEFAULT, + RADIO_BUTTON_MENU_ITEM_SELECTION_BACKGROUND_DEFAULT, + CHECKBOX_MENU_ITEM_SELECTION_BACKGROUND_DEFAULT, + CHECKBOX_MENU_ITEM_FOREGROUND_DEFAULT, + CHECKBOX_MENU_ITEM_SELECTION_FOREGROUND_DEFAULT, + TEXT_PANE_BACKGROUND_DEFAULT, + TEXT_PANE_SELECTION_BACKGROUND_DEFAULT, + TEXT_PANE_INACTIVE_FOREGROUND_DEFAULT, + EDITOR_PANE_BACKGROUND_DEFAULT, + EDITOR_PANE_SELECTION_BACKGROUND_DEFAULT, + EDITOR_PANE_INACTIVE_FOREGROUND_DEFAULT, + SEPARATOR_BACKGROUND_DEFAULT, + SEPARATOR_FOREGROUND_DEFAULT, + TOOL_TIP_BACKGROUND_DEFAULT, + TOOL_TIP_FOREGROUND_DEFAULT, + COLOR_CHOOSER_BACKGROUND_DEFAULT, + COLOR_CHOOSER_FOREGROUND_DEFAULT; public String configKey() { return this.toString().toLowerCase().replace('_', '-'); @@ -70,12 +156,18 @@ public static void loadColorScheme() { }); } - COLOR_MAP.putAll(lines.stream() - .filter(l -> !l.startsWith("//")) // Use // for comments - .map(l -> l.split(":")) - .filter(a -> a.length == 2) - .peek(a -> System.out.println(Arrays.toString(a))) - .collect(Collectors.toMap(e -> UIColor.valueOf(e[0]), e -> colorFromString(e[1].strip())))); + Set temp = new HashSet<>(); + + COLOR_MAP.putAll( + lines.stream() + .filter(l -> !l.startsWith("//")) // Use // for comments + .map(l -> l.split(":")) + .filter(a -> a.length == 2) + .peek(a -> System.out.println("Contains key: " + a[0] + " " + !temp.add(UIColor.valueOf(a[0].replace("-", "_").toUpperCase())))) + .map(e -> Map.entry(UIColor.valueOf(e[0].replace("-", "_").toUpperCase()), colorFromString(e[1].strip()))) + .peek(e -> System.out.println("Key: " + e.getKey() + " value: " + e.getValue())) + .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue()))); +// .collect(Collectors.toMap(e -> UIColor.valueOf(e[0].replace("-", "_").toUpperCase()), e -> colorFromString(e[1].strip())))); System.out.println("Colors: " + COLOR_MAP); } @@ -83,8 +175,16 @@ public static Color colorFromString(String color) { try { return (Color) Color.class.getField(color).get(null); } - catch (NullPointerException | NoSuchFieldException | IllegalAccessException | ClassCastException e) { - return Color.getColor(color); + catch (NullPointerException | NoSuchFieldException | IllegalAccessException | ClassCastException ignored) { + try { + return (Color) MaterialColors.class.getField(color).get(null); + } + catch (NullPointerException | NoSuchFieldException | IllegalAccessException | ClassCastException ignored2) { + if (color.startsWith("#")) { + return new Color(HexFormat.fromHexDigits(color.replace("#", ""))); + } + return Color.getColor(color); + } } } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/LegupLookAndFeel.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/LegupLookAndFeel.java index 8469343f3..99462be77 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/LegupLookAndFeel.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/LegupLookAndFeel.java @@ -8,6 +8,7 @@ import java.awt.*; import javax.swing.*; import javax.swing.plaf.basic.BasicLookAndFeel; +import edu.rpi.legup.ui.color.ColorPreferences.UIColor; public class LegupLookAndFeel extends BasicLookAndFeel { /** @@ -143,127 +144,181 @@ protected void initClassDefaults(UIDefaults table) { protected void initComponentDefaults(UIDefaults table) { super.initComponentDefaults(table); - table.put("Button.highlight", MaterialColors.GRAY_300); +// table.put("Button.highlight", MaterialColors.GRAY_300); + table.put("Button.highlight", UIColor.BUTTON_HIGHLIGHT_DEFAULT.get()); table.put("Button.opaque", false); table.put("Button.border", BorderFactory.createEmptyBorder(7, 17, 7, 17)); - table.put("Button.background", MaterialColors.GRAY_200); - table.put("Button.foreground", Color.BLACK); +// table.put("Button.background", MaterialColors.GRAY_200); + table.put("Button.background", UIColor.BUTTON_BACKGROUND_DEFAULT.get()); +// table.put("Button.foreground", Color.BLACK); + table.put("Button.foreground", UIColor.BUTTON_FOREGROUND_DEFAULT.get()); table.put("Button.font", MaterialFonts.MEDIUM); table.put("CheckBox.font", MaterialFonts.REGULAR); - table.put("CheckBox.background", Color.WHITE); - table.put("CheckBox.foreground", Color.BLACK); +// table.put("CheckBox.background", Color.WHITE); + table.put("CheckBox.background", UIColor.CHECKBOX_BACKGROUND_DEFAULT.get()); +// table.put("CheckBox.foreground", Color.BLACK); + table.put("CheckBox.foreground", UIColor.CHECKBOX_FOREGROUND_DEFAULT.get()); table.put("CheckBox.icon", new ImageIcon(MaterialImages.UNCHECKED_BOX)); table.put("CheckBox.selectedIcon", new ImageIcon(MaterialImages.PAINTED_CHECKED_BOX)); table.put("ComboBox.font", MaterialFonts.REGULAR); - table.put("ComboBox.background", Color.WHITE); - table.put("ComboBox.foreground", Color.BLACK); +// table.put("ComboBox.background", Color.WHITE); + table.put("ComboBox.background", UIColor.COMBOBOX_BACKGROUND_DEFAULT.get()); +// table.put("ComboBox.foreground", Color.BLACK); + table.put("ComboBox.foreground", UIColor.COMBOBOX_FOREGROUND_DEFAULT.get()); table.put( "ComboBox.border", BorderFactory.createCompoundBorder( MaterialBorders.LIGHT_LINE_BORDER, BorderFactory.createEmptyBorder(0, 5, 0, 0))); - table.put("ComboBox.buttonBackground", MaterialColors.GRAY_300); - table.put("ComboBox.selectionBackground", Color.WHITE); - table.put("ComboBox.selectionForeground", Color.BLACK); - table.put("ComboBox.selectedInDropDownBackground", MaterialColors.GRAY_200); +// table.put("ComboBox.buttonBackground", MaterialColors.GRAY_300); + table.put("ComboBox.buttonBackground", UIColor.COMBOBOX_BUTTON_BACKGROUND_DEFAULT.get()); +// table.put("ComboBox.selectionBackground", Color.WHITE); + table.put("ComboBox.selectionBackground", UIColor.COMBOBOX_SELECTION_BACKGROUND_DEFAULT.get()); +// table.put("ComboBox.selectionForeground", Color.BLACK); + table.put("ComboBox.selectionForeground", UIColor.COMBOBOX_SELECTION_FOREGROUND_DEFAULT.get()); +// table.put("ComboBox.selectedInDropDownBackground", MaterialColors.GRAY_200); + table.put("ComboBox.selectedInDropDownBackground", UIColor.COMBOBOX_SELECTED_IN_DROP_DOWN_BACKGROUND_DEFAULT.get()); table.put("Label.font", MaterialFonts.REGULAR); - table.put("Label.background", Color.WHITE); - table.put("Label.foreground", Color.BLACK); +// table.put("Label.background", Color.WHITE); + table.put("Label.background", UIColor.LABEL_BACKGROUND_DEFAULT.get()); +// table.put("Label.foreground", Color.BLACK); + table.put("Label.foreground", UIColor.LABEL_FOREGROUND_DEFAULT.get()); table.put("Label.border", BorderFactory.createEmptyBorder()); table.put("Menu.font", MaterialFonts.BOLD); table.put("Menu.border", BorderFactory.createEmptyBorder(5, 5, 5, 5)); - table.put("Menu.background", Color.WHITE); - table.put("Menu.foreground", Color.BLACK); +// table.put("Menu.background", Color.WHITE); + table.put("Menu.background", UIColor.MENU_BACKGROUND_DEFAULT.get()); +// table.put("Menu.foreground", Color.BLACK); + table.put("Menu.foreground", UIColor.MENU_FOREGROUND_DEFAULT.get()); table.put("Menu.opaque", true); - table.put("Menu.selectionBackground", MaterialColors.GRAY_200); - table.put("Menu.selectionForeground", Color.BLACK); - table.put("Menu.disabledForeground", new Color(0, 0, 0, 100)); +// table.put("Menu.selectionBackground", MaterialColors.GRAY_200); + table.put("Menu.selectionBackground", UIColor.MENU_SELECTION_BACKGROUND_DEFAULT.get()); +// table.put("Menu.selectionForeground", Color.BLACK); + table.put("Menu.selectionForeground", UIColor.MENU_SELECTION_FOREGROUND_DEFAULT.get()); +// table.put("Menu.disabledForeground", new Color(0, 0, 0, 100)); + table.put("Menu.disabledForeground", UIColor.MENU_DISABLED_FOREGROUND_DEFAULT.get()); table.put("Menu.menuPopupOffsetY", 3); table.put("MenuBar.font", MaterialFonts.BOLD); - table.put("MenuBar.background", Color.WHITE); +// table.put("MenuBar.background", Color.WHITE); + table.put("MenuBar.background", UIColor.MENU_BAR_BACKGROUND_DEFAULT.get()); table.put("MenuBar.border", MaterialBorders.LIGHT_SHADOW_BORDER); - table.put("MenuBar.foreground", Color.BLACK); - - table.put("MenuItem.disabledForeground", new Color(0, 0, 0, 100)); - table.put("MenuItem.selectionBackground", MaterialColors.GRAY_200); - table.put("MenuItem.selectionForeground", Color.BLACK); +// table.put("MenuBar.foreground", Color.BLACK); + table.put("MenuBar.foreground", UIColor.MENU_BAR_FOREGROUND_DEFAULT.get()); + +// table.put("MenuItem.disabledForeground", new Color(0, 0, 0, 100)); + table.put("MenuItem.disabledForeground", UIColor.MENU_ITEM_DISABLED_FOREGROUND_DEFAULT.get()); +// table.put("MenuItem.selectionBackground", MaterialColors.GRAY_200); + table.put("MenuItem.selectionBackground", UIColor.MENU_ITEM_SELECTION_BACKGROUND_DEFAULT.get()); +// table.put("MenuItem.selectionForeground", Color.BLACK); + table.put("MenuItem.selectionForeground", UIColor.MENU_ITEM_SELECTION_FOREGROUND_DEFAULT.get()); table.put("MenuItem.font", MaterialFonts.MEDIUM); - table.put("MenuItem.background", Color.WHITE); - table.put("MenuItem.foreground", Color.BLACK); +// table.put("MenuItem.background", Color.WHITE); + table.put("MenuItem.background", UIColor.MENU_ITEM_BACKGROUND_DEFAULT.get()); +// table.put("MenuItem.foreground", Color.BLACK); + table.put("MenuItem.foreground", UIColor.MENU_ITEM_FOREGROUND_DEFAULT.get()); table.put("MenuItem.border", BorderFactory.createEmptyBorder(5, 0, 5, 0)); - table.put("OptionPane.background", Color.WHITE); +// table.put("OptionPane.background", Color.WHITE); + table.put("OptionPane.background", UIColor.OPTION_PANE_BACKGROUND_DEFAULT.get()); table.put("OptionPane.border", MaterialBorders.DEFAULT_SHADOW_BORDER); table.put("OptionPane.font", MaterialFonts.REGULAR); table.put("Panel.font", MaterialFonts.REGULAR); - table.put("Panel.background", Color.WHITE); +// table.put("Panel.background", Color.WHITE); + table.put("Panel.background", UIColor.PANEL_BACKGROUND_COLOR_DEFAULT.get()); table.put("Panel.border", BorderFactory.createEmptyBorder()); table.put("PopupMenu.border", MaterialBorders.LIGHT_LINE_BORDER); - table.put("PopupMenu.background", Color.WHITE); - table.put("PopupMenu.foreground", Color.BLACK); +// table.put("PopupMenu.background", Color.WHITE); + table.put("PopupMenu.background", UIColor.POPUP_MENU_BACKGROUND_DEFAULT.get()); +// table.put("PopupMenu.foreground", Color.BLACK); + table.put("PopupMenu.foreground", UIColor.POPUP_MENU_FOREGROUND_DEFAULT.get()); table.put("RadioButton.font", MaterialFonts.REGULAR); - table.put("RadioButton.background", Color.WHITE); - table.put("RadioButton.foreground", Color.BLACK); +// table.put("RadioButton.background", Color.WHITE); + table.put("RadioButton.background", UIColor.RADIO_BUTTON_BACKGROUND_DEFAULT.get()); +// table.put("RadioButton.foreground", Color.BLACK); + table.put("RadioButton.foreground", UIColor.RADIO_BUTTON_FOREGROUND_DEFAULT.get()); table.put("RadioButton.icon", new ImageIcon(MaterialImages.RADIO_BUTTON_OFF)); table.put("RadioButton.selectedIcon", new ImageIcon(MaterialImages.RADIO_BUTTON_ON)); table.put("Spinner.font", MaterialFonts.REGULAR); - table.put("Spinner.background", Color.WHITE); - table.put("Spinner.foreground", Color.BLACK); +// table.put("Spinner.background", Color.WHITE); + table.put("Spinner.background", UIColor.SPINNER_BACKGROUND_DEFAULT.get()); +// table.put("Spinner.foreground", Color.BLACK); + table.put("Spinner.foreground", UIColor.SPINNER_FOREGROUND_DEFAULT.get()); table.put("Spinner.border", MaterialBorders.LIGHT_LINE_BORDER); - table.put("Spinner.arrowButtonBackground", MaterialColors.GRAY_200); +// table.put("Spinner.arrowButtonBackground", MaterialColors.GRAY_200); + table.put("Spinner.arrowButtonBackground", UIColor.SPINNER_ARROW_BUTTON_BACKGROUND_DEFAULT.get()); table.put("Spinner.arrowButtonBorder", BorderFactory.createEmptyBorder()); table.put("ScrollBar.font", MaterialFonts.REGULAR); - table.put("ScrollBar.track", MaterialColors.GRAY_200); - table.put("ScrollBar.thumb", MaterialColors.GRAY_300); - table.put("ScrollBar.thumbDarkShadow", MaterialColors.GRAY_300); - table.put("ScrollBar.thumbHighlight", MaterialColors.GRAY_300); - table.put("ScrollBar.thumbShadow", MaterialColors.GRAY_300); - table.put("ScrollBar.arrowButtonBackground", MaterialColors.GRAY_300); +// table.put("ScrollBar.track", MaterialColors.GRAY_200); + table.put("ScrollBar.track", UIColor.SCROLL_BAR_TRACK_DEFAULT.get()); +// table.put("ScrollBar.thumb", MaterialColors.GRAY_300); + table.put("ScrollBar.thumb", UIColor.SCROLL_BAR_THUMB_DEFAULT.get()); +// table.put("ScrollBar.thumbDarkShadow", MaterialColors.GRAY_300); + table.put("ScrollBar.thumbDarkShadow", UIColor.SCROLL_BAR_THUMB_DARK_SHADOW_DEFAULT.get()); +// table.put("ScrollBar.thumbHighlight", MaterialColors.GRAY_300); + table.put("ScrollBar.thumbHighlight", UIColor.SCROLL_BAR_THUMB_HIGHLIGHT_DEFAULT.get()); +// table.put("ScrollBar.thumbShadow", MaterialColors.GRAY_300); + table.put("ScrollBar.thumbShadow", UIColor.SCROLL_BAR_THUMB_SHADOW_DEFAULT.get()); +// table.put("ScrollBar.arrowButtonBackground", MaterialColors.GRAY_300); + table.put("ScrollBar.arrowButtonBackground", UIColor.SCROLL_BAR_ARROW_BUTTON_BACKGROUND_DEFAULT.get()); table.put("ScrollBar.arrowButtonBorder", BorderFactory.createEmptyBorder()); - table.put("ScrollPane.background", Color.WHITE); +// table.put("ScrollPane.background", Color.WHITE); + table.put("ScrollPane.background", UIColor.SCROLL_PANE_BACKGROUND_DEFAULT.get()); table.put("ScrollPane.border", BorderFactory.createEmptyBorder()); table.put("ScrollPane.font", MaterialFonts.REGULAR); table.put("Slider.font", MaterialFonts.REGULAR); - table.put("Slider.background", Color.WHITE); - table.put("Slider.foreground", MaterialColors.GRAY_700); - table.put("Slider.trackColor", Color.BLACK); +// table.put("Slider.background", Color.WHITE); + table.put("Slider.background", UIColor.SLIDER_BACKGROUND_DEFAULT.get()); +// table.put("Slider.foreground", MaterialColors.GRAY_700); + table.put("Slider.foreground", UIColor.SLIDER_FOREGROUND_DEFAULT.get()); +// table.put("Slider.trackColor", Color.BLACK); + table.put("Slider.trackColor", UIColor.SLIDER_TRACK_COLOR_DEFAULT.get()); // table.put ("Slider.border", // BorderFactory.createCompoundBorder(MaterialBorders.LIGHT_LINE_BORDER, // BorderFactory.createEmptyBorder (5, 5, 5, 5))); table.put("SplitPane.border", MaterialBorders.LIGHT_LINE_BORDER); - table.put("SplitPane.background", Color.WHITE); +// table.put("SplitPane.background", Color.WHITE); + table.put("SplitPane.background", UIColor.SPLIT_PANE_BACKGROUND_DEFAULT.get()); table.put("SplitPane.dividerSize", 10); table.put("SplitPaneDivider.border", MaterialBorders.LIGHT_SHADOW_BORDER); table.put("TabbedPane.font", MaterialFonts.REGULAR); - table.put("TabbedPane.background", Color.WHITE); - table.put("TabbedPane.foreground", Color.BLACK); +// table.put("TabbedPane.background", Color.WHITE); + table.put("TabbedPane.background", UIColor.TABBED_PANE_BACKGROUND_DEFAULT.get()); +// table.put("TabbedPane.foreground", Color.BLACK); + table.put("TabbedPane.foreground", UIColor.TABBED_PANE_FOREGROUND_DEFAULT.get()); table.put("TabbedPane.border", BorderFactory.createEmptyBorder()); table.put("TabbedPane.shadow", null); table.put("TabbedPane.darkShadow", null); - table.put("TabbedPane.highlight", MaterialColors.GRAY_200); - table.put("TabbedPane.borderHighlightColor", MaterialColors.GRAY_300); - - table.put("Table.selectionBackground", MaterialColors.GRAY_100); - table.put("Table.selectionForeground", Color.BLACK); - table.put("Table.background", Color.WHITE); +// table.put("TabbedPane.highlight", MaterialColors.GRAY_200); + table.put("TabbedPane.highlight", UIColor.TABBED_PANE_HIGHLIGHT_DEFAULT.get()); +// table.put("TabbedPane.borderHighlightColor", MaterialColors.GRAY_300); + table.put("TabbedPane.borderHighlightColor", UIColor.TABBED_PANE_BORDER_HIGHLIGHT_DEFAULT.get()); + +// table.put("Table.selectionBackground", MaterialColors.GRAY_100); + table.put("Table.selectionBackground", UIColor.TABLE_SELECTION_BACKGROUND_DEFAULT.get()); +// table.put("Table.selectionForeground", Color.BLACK); + table.put("Table.selectionForeground", UIColor.TABLE_SELECTION_FOREGROUND_DEFAULT.get()); +// table.put("Table.background", Color.WHITE); + table.put("Table.background", UIColor.TABLE_BACKGROUND_DEFAULT.get()); table.put("Table.font", MaterialFonts.REGULAR); table.put("Table.border", MaterialBorders.LIGHT_LINE_BORDER); - table.put("Table.gridColor", MaterialColors.GRAY_200); - table.put("TableHeader.background", MaterialColors.GRAY_200); +// table.put("Table.gridColor", MaterialColors.GRAY_200); + table.put("Table.gridColor", UIColor.TABLE_GRID_COLOR_DEFAULT.get()); +// table.put("TableHeader.background", MaterialColors.GRAY_200); + table.put("TableHeader.background", UIColor.TABLE_HEADER_BACKGROUND_DEFAULT.get()); table.put("TableHeader.font", MaterialFonts.BOLD); table.put( "TableHeader.cellBorder", @@ -271,39 +326,54 @@ protected void initComponentDefaults(UIDefaults table) { MaterialBorders.LIGHT_LINE_BORDER, BorderFactory.createEmptyBorder(5, 5, 5, 5))); - table.put("TextArea.background", MaterialColors.GRAY_200); +// table.put("TextArea.background", MaterialColors.GRAY_200); + table.put("TextArea.background", UIColor.TEXT_AREA_BACKGROUND_DEFAULT.get()); table.put("TextArea.border", BorderFactory.createEmptyBorder()); - table.put("TextArea.foreground", Color.BLACK); +// table.put("TextArea.foreground", Color.BLACK); + table.put("TextArea.foreground", UIColor.TEXT_AREA_FOREGROUND_DEFAULT.get()); table.put("ToggleButton.border", BorderFactory.createEmptyBorder()); table.put("ToggleButton.font", MaterialFonts.REGULAR); - table.put("ToggleButton.background", Color.WHITE); - table.put("ToggleButton.foreground", Color.BLACK); +// table.put("ToggleButton.background", Color.WHITE); + table.put("ToggleButton.background", UIColor.TOGGLE_BUTTON_BACKGROUND_DEFAULT.get()); +// table.put("ToggleButton.foreground", Color.BLACK); + table.put("ToggleButton.foreground", UIColor.TOGGLE_BUTTON_FOREGROUND_DEFAULT.get()); table.put("ToggleButton.icon", new ImageIcon(MaterialImages.TOGGLE_BUTTON_OFF)); table.put("ToggleButton.selectedIcon", new ImageIcon(MaterialImages.TOGGLE_BUTTON_ON)); table.put("ToolBar.font", MaterialFonts.REGULAR); - table.put("ToolBar.background", Color.WHITE); - table.put("ToolBar.foreground", Color.BLACK); +// table.put("ToolBar.background", Color.WHITE); + table.put("ToolBar.background", UIColor.TOOL_BAR_BACKGROUND_DEFAULT.get()); +// table.put("ToolBar.foreground", Color.BLACK); + table.put("ToolBar.foreground", UIColor.TOOL_BAR_FOREGROUND_DEFAULT.get()); table.put("ToolBar.border", MaterialBorders.LIGHT_SHADOW_BORDER); - table.put("ToolBar.dockingBackground", MaterialColors.LIGHT_GREEN_A100); - table.put("ToolBar.floatingBackground", MaterialColors.GRAY_200); +// table.put("ToolBar.dockingBackground", MaterialColors.LIGHT_GREEN_A100); + table.put("ToolBar.dockingBackground", UIColor.TOOL_BAR_DOCKING_BACKGROUND_DEFAULT.get()); +// table.put("ToolBar.floatingBackground", MaterialColors.GRAY_200); + table.put("ToolBar.floatingBackground", UIColor.TOOL_BAR_FLOATING_BACKGROUND_DEFAULT.get()); table.put("Tree.font", MaterialFonts.REGULAR); - table.put("Tree.selectionForeground", Color.BLACK); - table.put("Tree.foreground", Color.BLACK); - table.put("Tree.selectionBackground", MaterialColors.GRAY_200); - table.put("Tree.background", Color.WHITE); +// table.put("Tree.selectionForeground", Color.BLACK); + table.put("Tree.selectionForeground", UIColor.TREE_SELECTION_FOREGROUND_DEFAULT.get()); +// table.put("Tree.foreground", Color.BLACK); + table.put("Tree.foreground", UIColor.TREE_FOREGROUND_DEFAULT.get()); +// table.put("Tree.selectionBackground", MaterialColors.GRAY_200); + table.put("Tree.selectionBackground", UIColor.TREE_SELECTION_BACKGROUND_DEFAULT.get()); +// table.put("Tree.background", Color.WHITE); + table.put("Tree.background", UIColor.TREE_BACKGROUND_DEFAULT.get()); table.put("Tree.closedIcon", new ImageIcon(MaterialImages.RIGHT_ARROW)); table.put("Tree.openIcon", new ImageIcon(MaterialImages.DOWN_ARROW)); table.put("Tree.selectionBorderColor", null); - table.put("RadioButtonMenuItem.foreground", Color.BLACK); - table.put("RadioButtonMenuItem.selectionForeground", Color.BLACK); +// table.put("RadioButtonMenuItem.foreground", Color.BLACK); + table.put("RadioButtonMenuItem.foreground", UIColor.RADIO_BUTTON_FOREGROUND_DEFAULT.get()); +// table.put("RadioButtonMenuItem.selectionForeground", Color.BLACK); + table.put("RadioButtonMenuItem.selectionForeground", UIColor.RADIO_BUTTON_MENU_ITEM_SELECTION_FOREGROUND_DEFAULT.get()); // If it changes the background of the menuitem it must change this too, irrespective of its // setting table.put("RadioButtonMenuItem.background", UIManager.getColor("MenuItem.background")); - table.put("RadioButtonMenuItem.selectionBackground", MaterialColors.GRAY_200); +// table.put("RadioButtonMenuItem.selectionBackground", MaterialColors.GRAY_200); + table.put("RadioButtonMenuItem.selectionBackground", UIColor.RADIO_BUTTON_MENU_ITEM_SELECTION_BACKGROUND_DEFAULT.get()); table.put("RadioButtonMenuItem.border", BorderFactory.createEmptyBorder(5, 5, 5, 5)); table.put("RadioButtonMenuItem.checkIcon", new ImageIcon(MaterialImages.RADIO_BUTTON_OFF)); table.put( @@ -313,9 +383,12 @@ protected void initComponentDefaults(UIDefaults table) { // If it changes the background of the menuitem it must change this too, irrespective of its // setting table.put("CheckBoxMenuItem.background", UIManager.getColor("MenuItem.background")); - table.put("CheckBoxMenuItem.selectionBackground", MaterialColors.GRAY_200); - table.put("CheckBoxMenuItem.foreground", Color.BLACK); - table.put("CheckBoxMenuItem.selectionForeground", Color.BLACK); +// table.put("CheckBoxMenuItem.selectionBackground", MaterialColors.GRAY_200); + table.put("CheckBoxMenuItem.selectionBackground", UIColor.CHECKBOX_MENU_ITEM_SELECTION_BACKGROUND_DEFAULT.get()); +// table.put("CheckBoxMenuItem.foreground", Color.BLACK); + table.put("CheckBoxMenuItem.foreground", UIColor.CHECKBOX_MENU_ITEM_FOREGROUND_DEFAULT.get()); +// table.put("CheckBoxMenuItem.selectionForeground", Color.BLACK); + table.put("CheckBoxMenuItem.selectionForeground", UIColor.CHECKBOX_MENU_ITEM_SELECTION_FOREGROUND_DEFAULT.get()); table.put("CheckBoxMenuItem.border", BorderFactory.createEmptyBorder(5, 5, 5, 5)); table.put("CheckBoxMenuItem.checkIcon", new ImageIcon(MaterialImages.UNCHECKED_BOX)); table.put( @@ -323,25 +396,37 @@ protected void initComponentDefaults(UIDefaults table) { new ImageIcon(MaterialImages.PAINTED_CHECKED_BOX)); table.put("TextPane.border", MaterialBorders.LIGHT_LINE_BORDER); - table.put("TextPane.background", MaterialColors.GRAY_50); - table.put("TextPane.selectionBackground", MaterialColors.LIGHT_BLUE_200); - table.put("TextPane.inactiveForeground", MaterialColors.GRAY_500); +// table.put("TextPane.background", MaterialColors.GRAY_50); + table.put("TextPane.background", UIColor.TEXT_PANE_BACKGROUND_DEFAULT.get()); +// table.put("TextPane.selectionBackground", MaterialColors.LIGHT_BLUE_200); + table.put("TextPane.selectionBackground", UIColor.TEXT_PANE_SELECTION_BACKGROUND_DEFAULT.get()); +// table.put("TextPane.inactiveForeground", MaterialColors.GRAY_500); + table.put("TextPane.inactiveForeground", UIColor.TEXT_PANE_INACTIVE_FOREGROUND_DEFAULT.get()); table.put("TextPane.font", MaterialFonts.REGULAR); table.put("EditorPane.border", MaterialBorders.LIGHT_LINE_BORDER); - table.put("EditorPane.background", MaterialColors.GRAY_50); - table.put("EditorPane.selectionBackground", MaterialColors.LIGHT_BLUE_200); - table.put("EditorPane.inactiveForeground", MaterialColors.GRAY_500); +// table.put("EditorPane.background", MaterialColors.GRAY_50); + table.put("EditorPane.background", UIColor.EDITOR_PANE_BACKGROUND_DEFAULT.get()); +// table.put("EditorPane.selectionBackground", MaterialColors.LIGHT_BLUE_200); + table.put("EditorPane.selectionBackground", UIColor.EDITOR_PANE_SELECTION_BACKGROUND_DEFAULT.get()); +// table.put("EditorPane.inactiveForeground", MaterialColors.GRAY_500); + table.put("EditorPane.inactiveForeground", UIColor.EDITOR_PANE_INACTIVE_FOREGROUND_DEFAULT.get()); table.put("EditorPane.font", MaterialFonts.REGULAR); - table.put("Separator.background", MaterialColors.GRAY_300); - table.put("Separator.foreground", MaterialColors.GRAY_300); +// table.put("Separator.background", MaterialColors.GRAY_300); + table.put("Separator.background", UIColor.SEPARATOR_BACKGROUND_DEFAULT.get()); +// table.put("Separator.foreground", MaterialColors.GRAY_300); + table.put("Separator.foreground", UIColor.SEPARATOR_FOREGROUND_DEFAULT.get()); - table.put("ToolTip.background", MaterialColors.GRAY_500); - table.put("ToolTip.foreground", MaterialColors.GRAY_50); +// table.put("ToolTip.background", MaterialColors.GRAY_500); + table.put("ToolTip.background", UIColor.TOOL_TIP_BACKGROUND_DEFAULT.get()); +// table.put("ToolTip.foreground", MaterialColors.GRAY_50); + table.put("ToolTip.foreground", UIColor.TOOL_TIP_FOREGROUND_DEFAULT.get()); table.put("ToolTip.border", BorderFactory.createEmptyBorder(5, 5, 5, 5)); - table.put("ColorChooser.background", MaterialColors.WHITE); - table.put("ColorChooser.foreground", MaterialColors.BLACK); +// table.put("ColorChooser.background", MaterialColors.WHITE); + table.put("ColorChooser.background", UIColor.COLOR_CHOOSER_BACKGROUND_DEFAULT.get()); +// table.put("ColorChooser.foreground", MaterialColors.BLACK); + table.put("ColorChooser.foreground", UIColor.COLOR_CHOOSER_FOREGROUND_DEFAULT.get()); } } diff --git a/src/main/resources/color-theme.txt b/src/main/resources/color-theme.txt index 6de0cd9d8..20161e1a9 100644 --- a/src/main/resources/color-theme.txt +++ b/src/main/resources/color-theme.txt @@ -1,2 +1,88 @@ -CORRECT: BLUE -INCORRECT: RED \ No newline at end of file +correct: BLUE +incorrect: RED +data-selection-background: GRAY +element-view-default: BLACK +button-highlight-default: GRAY_300 +button-background-default: GRAY_200 +button-foreground-default: BLACK +checkbox-background-default: WHITE +checkbox-foreground-default: BLACK +combobox-background-default: WHITE +combobox-foreground-default: BOX +combobox-button-background-default: GRAY_300 +combobox-selection-background-default: WHITE +combobox-selection-foreground-default: BLACK +combobox-selected-in-drop-down-background-default: GRAY_200 +label-background-default: WHITE +label-foreground-default: BLACK +menu-background-default: WHITE +menu-foreground-default: BLACK +menu-selection-background-default: GRAY_200 +menu-selection-foreground-default: BLACK +menu-disabled-foreground-default: #000 +menu-bar-background-default: WHITE +menu-bar-foreground-default: BLACK +menu-item-disabled-foreground-default: #000 +menu-item-selection-background-default: GRAY_200 +menu-item-selection-foreground-default: BLACK +menu-item-background-default: WHITE +menu-item-foreground-default: BLACK +option-pane-background-default: WHITE +panel-background-color-default: WHITE +popup-menu-background-default: WHITE +popup-menu-foreground-default: BLACK +radio-button-background-default: WHITE +radio-button-foreground-default: BLACK +spinner-background-default: WHITE +spinner-foreground-default: BLACK +spinner-arrow-button-background-default: GRAY_200 +scroll-bar-track-default: GRAY_200 +scroll-bar-thumb-default: GRAY_300 +scroll-bar-thumb-dark-shadow-default: GRAY_300 +scroll-bar-thumb-highlight-default: GRAY_300 +scroll-bar-thumb-shadow-default: GRAY_300 +scroll-bar-arrow-button-background-default: GRAY_300 +scroll-pane-background-default: WHITE +slider-background-default: WHITE +slider-foreground-default: GRAY_700 +slider-track-color-default: BLACK +split-pane-background-default: WHITE +tabbed-pane-background-default: WHITE +tabbed-pane-foreground-default: BLACK +tabbed-pane-highlight-default: GRAY_200 +tabbed-pane-border-highlight-default: GRAY_300 +table-selection-background-default: GRAY_100 +table-selection-foreground-default: BLACK +table-background-default: WHITE +table-grid-color-default: GRAY_200 +table-header-background-default: GRAY_200 +text-area-background-default: GRAY_200 +text-area-foreground-default: BLACK +toggle-button-background-default: WHITE +toggle-button-foreground-default: BLACK +tool-bar-background-default: WHITE +tool-bar-foreground-default: BLACK +tool-bar-docking-background-default: LIGHT_GREEN_A100 +tool-bar-floating-background-default: GRAY_200 +tree-selection-foreground-default: BLACK +tree-foreground-default: BLACK +tree-selection-background-default: GRAY_200 +tree-background-default: WHITE +radio-button-menu-item-foreground-default: BLACK +radio-button-menu-item-selection-foreground-default: BLACK +radio-button-menu-item-selection-background-default: GRAY_200 +checkbox-menu-item-selection-background-default: GRAY_200 +checkbox-menu-item-foreground-default: BLACK +checkbox-menu-item-selection-foreground-default: BLACK +text-pane-background-default: GRAY_50 +text-pane-selection-background-default: LIGHT_BLUE_200 +text-pane-inactive-foreground-default: GRAY_500 +editor-pane-background-default: GRAY_50 +editor-pane-selection-background-default: LIGHT_BLUE_200 +editor-pane-inactive-foreground-default: GRAY_500 +separator-background-default: GRAY_300 +separator-foreground-default: GRAY_300 +tool-tip-background-default: GRAY_500 +tool-tip-foreground-default: GRAY_50 +color-chooser-background-default: WHITE +color-chooser-foreground-default: BLACK \ No newline at end of file From 54413d766b4e32971531436cef91563e7d55278e Mon Sep 17 00:00:00 2001 From: FisherLuba <145061313+FisherLuba@users.noreply.github.com> Date: Fri, 22 Mar 2024 17:47:22 -0400 Subject: [PATCH 03/10] Make color theme file work, and change working directory to use user.dir so that it uses the LEGUP folder --- src/main/java/edu/rpi/legup/Legup.java | 8 +- .../edu/rpi/legup/app/LegupPreferences.java | 14 +- .../java/edu/rpi/legup/ui/DynamicView.java | 11 +- src/main/java/edu/rpi/legup/ui/LegupUI.java | 16 +- .../edu/rpi/legup/ui/PreferencesDialog.java | 30 +++ .../rpi/legup/ui/boardview/ElementView.java | 2 +- .../rpi/legup/ui/color/ColorPreferences.java | 206 +++++++++--------- .../ui/lookandfeel/LegupLookAndFeel.java | 178 ++++++++------- .../components/MaterialButtonUI.java | 6 +- .../components/MaterialPasswordFieldUI.java | 5 +- .../components/MaterialProgressBarUI.java | 7 +- .../components/MaterialTextFieldUI.java | 5 +- .../materialdesign/MaterialBorders.java | 5 +- .../materialdesign/MaterialColors.java | 1 + .../java/edu/rpi/legup/utility/Logger.java | 2 +- src/main/resources/color-theme.txt | 88 -------- src/main/resources/dark-color-theme.txt | 99 +++++++++ src/main/resources/light-color-theme.txt | 99 +++++++++ 18 files changed, 485 insertions(+), 297 deletions(-) delete mode 100644 src/main/resources/color-theme.txt create mode 100644 src/main/resources/dark-color-theme.txt create mode 100644 src/main/resources/light-color-theme.txt diff --git a/src/main/java/edu/rpi/legup/Legup.java b/src/main/java/edu/rpi/legup/Legup.java index f714994fd..1d55761ca 100644 --- a/src/main/java/edu/rpi/legup/Legup.java +++ b/src/main/java/edu/rpi/legup/Legup.java @@ -2,8 +2,15 @@ import edu.rpi.legup.app.GameBoardFacade; import edu.rpi.legup.ui.color.ColorPreferences; +import edu.rpi.legup.ui.lookandfeel.LegupLookAndFeel; import edu.rpi.legup.utility.Logger; +import javax.swing.*; +import javax.swing.plaf.basic.BasicLookAndFeel; +import javax.swing.plaf.metal.MetalLookAndFeel; +import javax.swing.plaf.multi.MultiLookAndFeel; +import javax.swing.plaf.nimbus.NimbusLookAndFeel; +import javax.swing.plaf.synth.SynthLookAndFeel; import java.awt.*; public class Legup { @@ -17,6 +24,5 @@ public static void main(String[] args) { Logger.initLogger(); GameBoardFacade.getInstance(); GameBoardFacade.setupConfig(); - ColorPreferences.loadColorScheme(); } } diff --git a/src/main/java/edu/rpi/legup/app/LegupPreferences.java b/src/main/java/edu/rpi/legup/app/LegupPreferences.java index 12433d7e4..b051ed805 100644 --- a/src/main/java/edu/rpi/legup/app/LegupPreferences.java +++ b/src/main/java/edu/rpi/legup/app/LegupPreferences.java @@ -1,5 +1,8 @@ package edu.rpi.legup.app; +import edu.rpi.legup.ui.color.ColorPreferences; + +import java.io.File; import java.util.HashMap; import java.util.Map; import java.util.prefs.Preferences; @@ -8,7 +11,7 @@ public class LegupPreferences { private static LegupPreferences instance; - private static String SAVED_PATH = ""; + private static String savedPath = ""; private static final Preferences preferences = Preferences.userNodeForPackage(LegupPreferences.class); @@ -25,10 +28,11 @@ public class LegupPreferences { public static final String ALLOW_DEFAULT_RULES = "allow-default-rules"; public static final String AUTO_GENERATE_CASES = "auto-generate-cases"; public static final String IMMEDIATE_FEEDBACK = "immediate-feedback"; + public static final String COLOR_THEME_FILE = "color-theme-file"; public static final String COLOR_BLIND = "color-blind"; static { - defaultPreferencesMap.put(WORK_DIRECTORY, System.getProperty("user.home")); + defaultPreferencesMap.put(WORK_DIRECTORY, System.getProperty("user.dir")); defaultPreferencesMap.put(START_FULL_SCREEN, Boolean.toString(false)); defaultPreferencesMap.put(AUTO_UPDATE, Boolean.toString(true)); defaultPreferencesMap.put(DARK_MODE, Boolean.toString(false)); @@ -38,6 +42,7 @@ public class LegupPreferences { defaultPreferencesMap.put(AUTO_GENERATE_CASES, Boolean.toString(true)); defaultPreferencesMap.put(IMMEDIATE_FEEDBACK, Boolean.toString(true)); defaultPreferencesMap.put(COLOR_BLIND, Boolean.toString(false)); + defaultPreferencesMap.put(COLOR_THEME_FILE, System.getProperty("user.dir") + File.separator + ColorPreferences.LIGHT_COLOR_THEME_FILE_NAME); } static { @@ -70,6 +75,7 @@ public class LegupPreferences { preferences.get(IMMEDIATE_FEEDBACK, defaultPreferencesMap.get(IMMEDIATE_FEEDBACK))); preferencesMap.put( COLOR_BLIND, preferences.get(COLOR_BLIND, defaultPreferencesMap.get(COLOR_BLIND))); + preferencesMap.put(COLOR_THEME_FILE, preferences.get(COLOR_THEME_FILE, defaultPreferencesMap.get(COLOR_THEME_FILE))); } /** @@ -121,10 +127,10 @@ public boolean getUserPrefAsBool(String key) { } public String getSavedPath() { - return SAVED_PATH; + return savedPath; } public void setSavedPath(String path) { - SAVED_PATH = path; + savedPath = path; } } diff --git a/src/main/java/edu/rpi/legup/ui/DynamicView.java b/src/main/java/edu/rpi/legup/ui/DynamicView.java index 8d3024c86..462e4238e 100644 --- a/src/main/java/edu/rpi/legup/ui/DynamicView.java +++ b/src/main/java/edu/rpi/legup/ui/DynamicView.java @@ -5,7 +5,8 @@ import edu.rpi.legup.app.GameBoardFacade; import edu.rpi.legup.model.Puzzle; import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialColors; +//import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialColors; +import edu.rpi.legup.ui.color.ColorPreferences.UIColor; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialFonts; import java.awt.*; import java.awt.event.*; @@ -24,10 +25,10 @@ public class DynamicView extends JPanel { private JLabel status; private static final Font ERROR_FONT = MaterialFonts.ITALIC; - private static final Color ERROR_COLOR = MaterialColors.RED_700; +// private static final Color ERROR_COLOR = MaterialColors.RED_700; private static final Font INFO_FONT = MaterialFonts.REGULAR; - private static final Color INFO_COLOR = MaterialColors.GRAY_900; +// private static final Color INFO_COLOR = MaterialColors.GRAY_900; public DynamicView(ScrollView scrollView, DynamicViewType type) { this.scrollView = scrollView; @@ -199,13 +200,13 @@ public JPanel getZoomer() { public void updateInfo(String message) { status.setFont(INFO_FONT); - status.setForeground(INFO_COLOR); + status.setForeground(UIColor.INFO.get()); status.setText(message); } public void updateError(String message) { status.setFont(ERROR_FONT); - status.setForeground(ERROR_COLOR); + status.setForeground(UIColor.ERROR.get()); status.setText(message); } diff --git a/src/main/java/edu/rpi/legup/ui/LegupUI.java b/src/main/java/edu/rpi/legup/ui/LegupUI.java index d7ad16049..c09c85e4d 100644 --- a/src/main/java/edu/rpi/legup/ui/LegupUI.java +++ b/src/main/java/edu/rpi/legup/ui/LegupUI.java @@ -5,6 +5,8 @@ import edu.rpi.legup.app.GameBoardFacade; import edu.rpi.legup.app.LegupPreferences; import edu.rpi.legup.ui.boardview.BoardView; +import edu.rpi.legup.ui.color.ColorPreferences; +import edu.rpi.legup.ui.lookandfeel.LegupLookAndFeel; import edu.rpi.legup.ui.proofeditorui.treeview.TreePanel; import java.awt.*; import java.awt.event.*; @@ -45,10 +47,16 @@ public LegupUI() { LegupPreferences prefs = LegupPreferences.getInstance(); try { - if (Boolean.valueOf(prefs.getUserPref(LegupPreferences.DARK_MODE))) { - UIManager.setLookAndFeel(new FlatDarkLaf()); - } else { - UIManager.setLookAndFeel(new FlatLightLaf()); + final String colorFileName = prefs.getUserPref(LegupPreferences.COLOR_THEME_FILE); + if (colorFileName.endsWith(".txt")) { + UIManager.setLookAndFeel(new LegupLookAndFeel(colorFileName)); + }else { + if (Boolean.valueOf(prefs.getUserPref(LegupPreferences.DARK_MODE))) { + UIManager.setLookAndFeel(new LegupLookAndFeel(ColorPreferences.DARK_COLOR_THEME_FILE_NAME)); + } + else { + UIManager.setLookAndFeel(new LegupLookAndFeel(ColorPreferences.LIGHT_COLOR_THEME_FILE_NAME)); + } } } catch (UnsupportedLookAndFeelException e) { System.err.println("Not supported ui look and feel"); diff --git a/src/main/java/edu/rpi/legup/ui/PreferencesDialog.java b/src/main/java/edu/rpi/legup/ui/PreferencesDialog.java index 475f4bb68..7f7b84ee4 100644 --- a/src/main/java/edu/rpi/legup/ui/PreferencesDialog.java +++ b/src/main/java/edu/rpi/legup/ui/PreferencesDialog.java @@ -5,6 +5,7 @@ import edu.rpi.legup.app.LegupPreferences; import edu.rpi.legup.model.Puzzle; import edu.rpi.legup.model.rules.Rule; +import edu.rpi.legup.ui.color.ColorPreferences; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialBorders; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialFonts; import edu.rpi.legup.ui.proofeditorui.rulesview.RuleFrame; @@ -34,6 +35,7 @@ public class PreferencesDialog extends JDialog { colorBlind; private JTextField workDirectory; + private JTextField colorThemeFile; private static Image folderIcon; @@ -290,6 +292,33 @@ private JScrollPane createGeneralTab() { new Dimension(Integer.MAX_VALUE, showMistakesRow.getPreferredSize().height)); contentPane.add(colorBlindRow); + JPanel colorThemeRow = new JPanel(); + colorThemeRow.setLayout(new BorderLayout()); + JLabel colorThemeDirLabel = new JLabel("Color Theme File"); + colorThemeDirLabel.setToolTipText("This is the color theme LEGUP will use."); + colorThemeRow.add(colorThemeDirLabel, BorderLayout.WEST); + colorThemeFile = new JTextField(prefs.getUserPref(LegupPreferences.WORK_DIRECTORY) + "/" + ColorPreferences.LIGHT_COLOR_THEME_FILE_NAME); + colorThemeRow.add(colorThemeFile, BorderLayout.CENTER); + JButton openColorThemeFile = new JButton(new ImageIcon(folderIcon)); + openColorThemeFile.addActionListener( + a -> { + JFileChooser chooser = new JFileChooser(); + chooser.setCurrentDirectory(new File(colorThemeDirLabel.getText())); + chooser.setDialogTitle("Choose color theme file"); + chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); + chooser.setAcceptAllFileFilterUsed(false); + chooser.setVisible(true); + + if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { + File newFile = chooser.getSelectedFile(); + colorThemeFile.setText(newFile.toString()); + } + }); + colorThemeRow.add(openColorThemeFile, BorderLayout.EAST); + colorThemeRow.setMaximumSize(new Dimension(Integer.MAX_VALUE, colorThemeRow.getPreferredSize().height)); + contentPane.add(colorThemeRow); + + scrollPane.setViewportView(contentPane); return scrollPane; } @@ -424,6 +453,7 @@ public void applyPreferences() { prefs.setUserPref( LegupPreferences.IMMEDIATE_FEEDBACK, Boolean.toString(immFeedback.isSelected())); prefs.setUserPref(LegupPreferences.COLOR_BLIND, Boolean.toString(colorBlind.isSelected())); + prefs.setUserPref(LegupPreferences.COLOR_THEME_FILE, colorThemeFile.getText()); if (rulesFrame != null) { rulesFrame.getCasePanel().updateRules(); diff --git a/src/main/java/edu/rpi/legup/ui/boardview/ElementView.java b/src/main/java/edu/rpi/legup/ui/boardview/ElementView.java index de961efd3..2f5760b15 100644 --- a/src/main/java/edu/rpi/legup/ui/boardview/ElementView.java +++ b/src/main/java/edu/rpi/legup/ui/boardview/ElementView.java @@ -82,7 +82,7 @@ public void drawElement(Graphics2D graphics2D) { new Rectangle2D.Double( location.x + 0.5f, location.y + 0.5f, size.width - 2, size.height - 2)); - graphics2D.setColor(UIColor.ELEMENT_VIEW_DEFAULT.get()); + graphics2D.setColor(UIColor.ELEMENT_VIEW.get()); FontMetrics metrics = graphics2D.getFontMetrics(graphics2D.getFont()); String value = String.valueOf(puzzleElement.getData()); int xText = location.x + (size.width - metrics.stringWidth(value)) / 2; diff --git a/src/main/java/edu/rpi/legup/ui/color/ColorPreferences.java b/src/main/java/edu/rpi/legup/ui/color/ColorPreferences.java index 1bdd7f075..34d786979 100644 --- a/src/main/java/edu/rpi/legup/ui/color/ColorPreferences.java +++ b/src/main/java/edu/rpi/legup/ui/color/ColorPreferences.java @@ -1,5 +1,7 @@ package edu.rpi.legup.ui.color; +//import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialColors; + import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialColors; import java.awt.*; @@ -13,7 +15,8 @@ public class ColorPreferences { - private static final String COLOR_THEME_FILE_NAME = "color-theme.txt"; + public static final String LIGHT_COLOR_THEME_FILE_NAME = "light-color-theme.txt"; + public static final String DARK_COLOR_THEME_FILE_NAME = "dark-color-theme.txt"; private static final Map COLOR_MAP = new EnumMap<>(UIColor.class); @@ -21,105 +24,117 @@ public enum UIColor { CORRECT, INCORRECT, + ERROR, + INFO, + UI_MOVEMENT, + PASSWORD_FIELD_BACKGROUND, + PASSWORD_FIELD_UNFOCUSED_BACKGROUND, + PROGRESS_BAR_BACKGROUND, + PROGRESS_BAR_FOREGROUND, + TEXT_FIELD_BACKGROUND, + TEXT_FIELD_UNFOCUSED_BACKGROUND, + LIGHT_LINE_BORDER, + THICK_LINE_BORDER, DATA_SELECTION_BACKGROUND, - ELEMENT_VIEW_DEFAULT, - BUTTON_HIGHLIGHT_DEFAULT, - BUTTON_BACKGROUND_DEFAULT, - BUTTON_FOREGROUND_DEFAULT, - CHECKBOX_BACKGROUND_DEFAULT, - CHECKBOX_FOREGROUND_DEFAULT, - COMBOBOX_BACKGROUND_DEFAULT, - COMBOBOX_FOREGROUND_DEFAULT, - COMBOBOX_BUTTON_BACKGROUND_DEFAULT, - COMBOBOX_SELECTION_BACKGROUND_DEFAULT, - COMBOBOX_SELECTION_FOREGROUND_DEFAULT, - COMBOBOX_SELECTED_IN_DROP_DOWN_BACKGROUND_DEFAULT, - LABEL_BACKGROUND_DEFAULT, - LABEL_FOREGROUND_DEFAULT, - MENU_BACKGROUND_DEFAULT, - MENU_FOREGROUND_DEFAULT, - MENU_SELECTION_BACKGROUND_DEFAULT, - MENU_SELECTION_FOREGROUND_DEFAULT, - MENU_DISABLED_FOREGROUND_DEFAULT, - MENU_BAR_BACKGROUND_DEFAULT, - MENU_BAR_FOREGROUND_DEFAULT, - MENU_ITEM_DISABLED_FOREGROUND_DEFAULT, - MENU_ITEM_SELECTION_BACKGROUND_DEFAULT, - MENU_ITEM_SELECTION_FOREGROUND_DEFAULT, - MENU_ITEM_BACKGROUND_DEFAULT, - MENU_ITEM_FOREGROUND_DEFAULT, - OPTION_PANE_BACKGROUND_DEFAULT, - PANEL_BACKGROUND_COLOR_DEFAULT, - POPUP_MENU_BACKGROUND_DEFAULT, - POPUP_MENU_FOREGROUND_DEFAULT, - RADIO_BUTTON_BACKGROUND_DEFAULT, - RADIO_BUTTON_FOREGROUND_DEFAULT, - SPINNER_BACKGROUND_DEFAULT, - SPINNER_FOREGROUND_DEFAULT, - SPINNER_ARROW_BUTTON_BACKGROUND_DEFAULT, - SCROLL_BAR_TRACK_DEFAULT, - SCROLL_BAR_THUMB_DEFAULT, - SCROLL_BAR_THUMB_DARK_SHADOW_DEFAULT, - SCROLL_BAR_THUMB_HIGHLIGHT_DEFAULT, - SCROLL_BAR_THUMB_SHADOW_DEFAULT, - SCROLL_BAR_ARROW_BUTTON_BACKGROUND_DEFAULT, - SCROLL_PANE_BACKGROUND_DEFAULT, - SLIDER_BACKGROUND_DEFAULT, - SLIDER_FOREGROUND_DEFAULT, - SLIDER_TRACK_COLOR_DEFAULT, - SPLIT_PANE_BACKGROUND_DEFAULT, - TABBED_PANE_BACKGROUND_DEFAULT, - TABBED_PANE_FOREGROUND_DEFAULT, - TABBED_PANE_HIGHLIGHT_DEFAULT, - TABBED_PANE_BORDER_HIGHLIGHT_DEFAULT, - TABLE_SELECTION_BACKGROUND_DEFAULT, - TABLE_SELECTION_FOREGROUND_DEFAULT, - TABLE_BACKGROUND_DEFAULT, - TABLE_GRID_COLOR_DEFAULT, - TABLE_HEADER_BACKGROUND_DEFAULT, - TEXT_AREA_BACKGROUND_DEFAULT, - TEXT_AREA_FOREGROUND_DEFAULT, - TOGGLE_BUTTON_BACKGROUND_DEFAULT, - TOGGLE_BUTTON_FOREGROUND_DEFAULT, - TOOL_BAR_BACKGROUND_DEFAULT, - TOOL_BAR_FOREGROUND_DEFAULT, - TOOL_BAR_DOCKING_BACKGROUND_DEFAULT, - TOOL_BAR_FLOATING_BACKGROUND_DEFAULT, - TREE_SELECTION_FOREGROUND_DEFAULT, - TREE_FOREGROUND_DEFAULT, - TREE_SELECTION_BACKGROUND_DEFAULT, - TREE_BACKGROUND_DEFAULT, - RADIO_BUTTON_MENU_ITEM_FOREGROUND_DEFAULT, - RADIO_BUTTON_MENU_ITEM_SELECTION_FOREGROUND_DEFAULT, - RADIO_BUTTON_MENU_ITEM_SELECTION_BACKGROUND_DEFAULT, - CHECKBOX_MENU_ITEM_SELECTION_BACKGROUND_DEFAULT, - CHECKBOX_MENU_ITEM_FOREGROUND_DEFAULT, - CHECKBOX_MENU_ITEM_SELECTION_FOREGROUND_DEFAULT, - TEXT_PANE_BACKGROUND_DEFAULT, - TEXT_PANE_SELECTION_BACKGROUND_DEFAULT, - TEXT_PANE_INACTIVE_FOREGROUND_DEFAULT, - EDITOR_PANE_BACKGROUND_DEFAULT, - EDITOR_PANE_SELECTION_BACKGROUND_DEFAULT, - EDITOR_PANE_INACTIVE_FOREGROUND_DEFAULT, - SEPARATOR_BACKGROUND_DEFAULT, - SEPARATOR_FOREGROUND_DEFAULT, - TOOL_TIP_BACKGROUND_DEFAULT, - TOOL_TIP_FOREGROUND_DEFAULT, - COLOR_CHOOSER_BACKGROUND_DEFAULT, - COLOR_CHOOSER_FOREGROUND_DEFAULT; + ELEMENT_VIEW, + BUTTON_HIGHLIGHT, + BUTTON_BACKGROUND, + BUTTON_FOREGROUND, + CHECKBOX_BACKGROUND, + CHECKBOX_FOREGROUND, + COMBOBOX_BACKGROUND, + COMBOBOX_FOREGROUND, + COMBOBOX_BUTTON_BACKGROUND, + COMBOBOX_SELECTION_BACKGROUND, + COMBOBOX_SELECTION_FOREGROUND, + COMBOBOX_SELECTED_IN_DROP_DOWN_BACKGROUND, + LABEL_BACKGROUND, + LABEL_FOREGROUND, + MENU_BACKGROUND, + MENU_FOREGROUND, + MENU_SELECTION_BACKGROUND, + MENU_SELECTION_FOREGROUND, + MENU_DISABLED_FOREGROUND, + MENU_BAR_BACKGROUND, + MENU_BAR_FOREGROUND, + MENU_ITEM_DISABLED_FOREGROUND, + MENU_ITEM_SELECTION_BACKGROUND, + MENU_ITEM_SELECTION_FOREGROUND, + MENU_ITEM_BACKGROUND, + MENU_ITEM_FOREGROUND, + OPTION_PANE_BACKGROUND, + PANEL_BACKGROUND_COLOR, + POPUP_MENU_BACKGROUND, + POPUP_MENU_FOREGROUND, + RADIO_BUTTON_BACKGROUND, + RADIO_BUTTON_FOREGROUND, + SPINNER_BACKGROUND, + SPINNER_FOREGROUND, + SPINNER_ARROW_BUTTON_BACKGROUND, + SCROLL_BAR_TRACK, + SCROLL_BAR_THUMB, + SCROLL_BAR_THUMB_DARK_SHADOW, + SCROLL_BAR_THUMB_HIGHLIGHT, + SCROLL_BAR_THUMB_SHADOW, + SCROLL_BAR_ARROW_BUTTON_BACKGROUND, + SCROLL_PANE_BACKGROUND, + SLIDER_BACKGROUND, + SLIDER_FOREGROUND, + SLIDER_TRACK_COLOR, + SPLIT_PANE_BACKGROUND, + TABBED_PANE_BACKGROUND, + TABBED_PANE_FOREGROUND, + TABBED_PANE_HIGHLIGHT, + TABBED_PANE_BORDER_HIGHLIGHT, + TABLE_SELECTION_BACKGROUND, + TABLE_SELECTION_FOREGROUND, + TABLE_BACKGROUND, + TABLE_GRID_COLOR, + TABLE_HEADER_BACKGROUND, + TEXT_AREA_BACKGROUND, + TEXT_AREA_FOREGROUND, + TOGGLE_BUTTON_BACKGROUND, + TOGGLE_BUTTON_FOREGROUND, + TOOL_BAR_BACKGROUND, + TOOL_BAR_FOREGROUND, + TOOL_BAR_DOCKING_BACKGROUND, + TOOL_BAR_FLOATING_BACKGROUND, + TREE_SELECTION_FOREGROUND, + TREE_FOREGROUND, + TREE_SELECTION_BACKGROUND, + TREE_BACKGROUND, + RADIO_BUTTON_MENU_ITEM_FOREGROUND, + RADIO_BUTTON_MENU_ITEM_SELECTION_FOREGROUND, + RADIO_BUTTON_MENU_ITEM_SELECTION_BACKGROUND, + CHECKBOX_MENU_ITEM_SELECTION_BACKGROUND, + CHECKBOX_MENU_ITEM_FOREGROUND, + CHECKBOX_MENU_ITEM_SELECTION_FOREGROUND, + TEXT_PANE_BACKGROUND, + TEXT_PANE_SELECTION_BACKGROUND, + TEXT_PANE_INACTIVE_FOREGROUND, + EDITOR_PANE_BACKGROUND, + EDITOR_PANE_SELECTION_BACKGROUND, + EDITOR_PANE_INACTIVE_FOREGROUND, + SEPARATOR_BACKGROUND, + SEPARATOR_FOREGROUND, + TOOL_TIP_BACKGROUND, + TOOL_TIP_FOREGROUND, + COLOR_CHOOSER_BACKGROUND, + COLOR_CHOOSER_FOREGROUND; public String configKey() { return this.toString().toLowerCase().replace('_', '-'); } public Color get() { - return COLOR_MAP.get(this); + return Objects.requireNonNull(COLOR_MAP.get(this), "Could not get " + this.name() + " color."); } } - public static void loadColorScheme() { - final File file = Path.of(COLOR_THEME_FILE_NAME).toFile(); - final InputStream input = ClassLoader.getSystemClassLoader().getResourceAsStream(COLOR_THEME_FILE_NAME); + public static void loadColorScheme(String fileName) { + final Path path = Path.of(fileName); + final File file = path.toFile(); + final InputStream input = ClassLoader.getSystemClassLoader().getResourceAsStream(path.getFileName().toString()); BufferedReader reader; boolean copyResourceToFile = false; if (!file.exists()) { @@ -128,10 +143,10 @@ public static void loadColorScheme() { copyResourceToFile = true; } catch (IOException e) { - System.err.println("Could not create " + COLOR_THEME_FILE_NAME); + System.err.println("Could not create " + fileName); } if (input == null) { - throw new RuntimeException("Could not find resource " + COLOR_THEME_FILE_NAME); + throw new RuntimeException("Could not find resource " + fileName); } reader = new BufferedReader(new InputStreamReader(input)); } @@ -145,7 +160,6 @@ public static void loadColorScheme() { } final List lines = reader.lines().toList(); if (copyResourceToFile) { - final Path path = file.toPath(); lines.forEach(line -> { try { Files.writeString(path, line + System.lineSeparator(), StandardOpenOption.APPEND); @@ -163,11 +177,7 @@ public static void loadColorScheme() { .filter(l -> !l.startsWith("//")) // Use // for comments .map(l -> l.split(":")) .filter(a -> a.length == 2) - .peek(a -> System.out.println("Contains key: " + a[0] + " " + !temp.add(UIColor.valueOf(a[0].replace("-", "_").toUpperCase())))) - .map(e -> Map.entry(UIColor.valueOf(e[0].replace("-", "_").toUpperCase()), colorFromString(e[1].strip()))) - .peek(e -> System.out.println("Key: " + e.getKey() + " value: " + e.getValue())) - .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue()))); -// .collect(Collectors.toMap(e -> UIColor.valueOf(e[0].replace("-", "_").toUpperCase()), e -> colorFromString(e[1].strip())))); + .collect(Collectors.toMap(e -> UIColor.valueOf(e[0].replace("-", "_").toUpperCase()), e -> colorFromString(e[1].strip())))); System.out.println("Colors: " + COLOR_MAP); } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/LegupLookAndFeel.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/LegupLookAndFeel.java index 99462be77..06c8b379c 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/LegupLookAndFeel.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/LegupLookAndFeel.java @@ -1,5 +1,6 @@ package edu.rpi.legup.ui.lookandfeel; +import edu.rpi.legup.ui.color.ColorPreferences; import edu.rpi.legup.ui.lookandfeel.components.*; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialBorders; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialColors; @@ -11,6 +12,14 @@ import edu.rpi.legup.ui.color.ColorPreferences.UIColor; public class LegupLookAndFeel extends BasicLookAndFeel { + + private final String colorThemeFileName; + + public LegupLookAndFeel(String colorThemeFileName) { + this.colorThemeFileName = colorThemeFileName; + ColorPreferences.loadColorScheme(colorThemeFileName); + } + /** * Return a short string that identifies this look and feel, e.g. "CDE/Motif". This string * should be appropriate for a menu item. Distinct look and feels should have different names, @@ -145,180 +154,181 @@ protected void initComponentDefaults(UIDefaults table) { super.initComponentDefaults(table); // table.put("Button.highlight", MaterialColors.GRAY_300); - table.put("Button.highlight", UIColor.BUTTON_HIGHLIGHT_DEFAULT.get()); + + table.put("Button.highlight", UIColor.BUTTON_HIGHLIGHT.get()); table.put("Button.opaque", false); table.put("Button.border", BorderFactory.createEmptyBorder(7, 17, 7, 17)); // table.put("Button.background", MaterialColors.GRAY_200); - table.put("Button.background", UIColor.BUTTON_BACKGROUND_DEFAULT.get()); + table.put("Button.background", UIColor.BUTTON_BACKGROUND.get()); // table.put("Button.foreground", Color.BLACK); - table.put("Button.foreground", UIColor.BUTTON_FOREGROUND_DEFAULT.get()); + table.put("Button.foreground", UIColor.BUTTON_FOREGROUND.get()); table.put("Button.font", MaterialFonts.MEDIUM); table.put("CheckBox.font", MaterialFonts.REGULAR); // table.put("CheckBox.background", Color.WHITE); - table.put("CheckBox.background", UIColor.CHECKBOX_BACKGROUND_DEFAULT.get()); + table.put("CheckBox.background", UIColor.CHECKBOX_BACKGROUND.get()); // table.put("CheckBox.foreground", Color.BLACK); - table.put("CheckBox.foreground", UIColor.CHECKBOX_FOREGROUND_DEFAULT.get()); + table.put("CheckBox.foreground", UIColor.CHECKBOX_FOREGROUND.get()); table.put("CheckBox.icon", new ImageIcon(MaterialImages.UNCHECKED_BOX)); table.put("CheckBox.selectedIcon", new ImageIcon(MaterialImages.PAINTED_CHECKED_BOX)); table.put("ComboBox.font", MaterialFonts.REGULAR); // table.put("ComboBox.background", Color.WHITE); - table.put("ComboBox.background", UIColor.COMBOBOX_BACKGROUND_DEFAULT.get()); + table.put("ComboBox.background", UIColor.COMBOBOX_BACKGROUND.get()); // table.put("ComboBox.foreground", Color.BLACK); - table.put("ComboBox.foreground", UIColor.COMBOBOX_FOREGROUND_DEFAULT.get()); + table.put("ComboBox.foreground", UIColor.COMBOBOX_FOREGROUND.get()); table.put( "ComboBox.border", BorderFactory.createCompoundBorder( MaterialBorders.LIGHT_LINE_BORDER, BorderFactory.createEmptyBorder(0, 5, 0, 0))); // table.put("ComboBox.buttonBackground", MaterialColors.GRAY_300); - table.put("ComboBox.buttonBackground", UIColor.COMBOBOX_BUTTON_BACKGROUND_DEFAULT.get()); + table.put("ComboBox.buttonBackground", UIColor.COMBOBOX_BUTTON_BACKGROUND.get()); // table.put("ComboBox.selectionBackground", Color.WHITE); - table.put("ComboBox.selectionBackground", UIColor.COMBOBOX_SELECTION_BACKGROUND_DEFAULT.get()); + table.put("ComboBox.selectionBackground", UIColor.COMBOBOX_SELECTION_BACKGROUND.get()); // table.put("ComboBox.selectionForeground", Color.BLACK); - table.put("ComboBox.selectionForeground", UIColor.COMBOBOX_SELECTION_FOREGROUND_DEFAULT.get()); + table.put("ComboBox.selectionForeground", UIColor.COMBOBOX_SELECTION_FOREGROUND.get()); // table.put("ComboBox.selectedInDropDownBackground", MaterialColors.GRAY_200); - table.put("ComboBox.selectedInDropDownBackground", UIColor.COMBOBOX_SELECTED_IN_DROP_DOWN_BACKGROUND_DEFAULT.get()); + table.put("ComboBox.selectedInDropDownBackground", UIColor.COMBOBOX_SELECTED_IN_DROP_DOWN_BACKGROUND.get()); table.put("Label.font", MaterialFonts.REGULAR); // table.put("Label.background", Color.WHITE); - table.put("Label.background", UIColor.LABEL_BACKGROUND_DEFAULT.get()); + table.put("Label.background", UIColor.LABEL_BACKGROUND.get()); // table.put("Label.foreground", Color.BLACK); - table.put("Label.foreground", UIColor.LABEL_FOREGROUND_DEFAULT.get()); + table.put("Label.foreground", UIColor.LABEL_FOREGROUND.get()); table.put("Label.border", BorderFactory.createEmptyBorder()); table.put("Menu.font", MaterialFonts.BOLD); table.put("Menu.border", BorderFactory.createEmptyBorder(5, 5, 5, 5)); // table.put("Menu.background", Color.WHITE); - table.put("Menu.background", UIColor.MENU_BACKGROUND_DEFAULT.get()); + table.put("Menu.background", UIColor.MENU_BACKGROUND.get()); // table.put("Menu.foreground", Color.BLACK); - table.put("Menu.foreground", UIColor.MENU_FOREGROUND_DEFAULT.get()); + table.put("Menu.foreground", UIColor.MENU_FOREGROUND.get()); table.put("Menu.opaque", true); // table.put("Menu.selectionBackground", MaterialColors.GRAY_200); - table.put("Menu.selectionBackground", UIColor.MENU_SELECTION_BACKGROUND_DEFAULT.get()); + table.put("Menu.selectionBackground", UIColor.MENU_SELECTION_BACKGROUND.get()); // table.put("Menu.selectionForeground", Color.BLACK); - table.put("Menu.selectionForeground", UIColor.MENU_SELECTION_FOREGROUND_DEFAULT.get()); + table.put("Menu.selectionForeground", UIColor.MENU_SELECTION_FOREGROUND.get()); // table.put("Menu.disabledForeground", new Color(0, 0, 0, 100)); - table.put("Menu.disabledForeground", UIColor.MENU_DISABLED_FOREGROUND_DEFAULT.get()); + table.put("Menu.disabledForeground", UIColor.MENU_DISABLED_FOREGROUND.get()); table.put("Menu.menuPopupOffsetY", 3); table.put("MenuBar.font", MaterialFonts.BOLD); // table.put("MenuBar.background", Color.WHITE); - table.put("MenuBar.background", UIColor.MENU_BAR_BACKGROUND_DEFAULT.get()); + table.put("MenuBar.background", UIColor.MENU_BAR_BACKGROUND.get()); table.put("MenuBar.border", MaterialBorders.LIGHT_SHADOW_BORDER); // table.put("MenuBar.foreground", Color.BLACK); - table.put("MenuBar.foreground", UIColor.MENU_BAR_FOREGROUND_DEFAULT.get()); + table.put("MenuBar.foreground", UIColor.MENU_BAR_FOREGROUND.get()); // table.put("MenuItem.disabledForeground", new Color(0, 0, 0, 100)); - table.put("MenuItem.disabledForeground", UIColor.MENU_ITEM_DISABLED_FOREGROUND_DEFAULT.get()); + table.put("MenuItem.disabledForeground", UIColor.MENU_ITEM_DISABLED_FOREGROUND.get()); // table.put("MenuItem.selectionBackground", MaterialColors.GRAY_200); - table.put("MenuItem.selectionBackground", UIColor.MENU_ITEM_SELECTION_BACKGROUND_DEFAULT.get()); + table.put("MenuItem.selectionBackground", UIColor.MENU_ITEM_SELECTION_BACKGROUND.get()); // table.put("MenuItem.selectionForeground", Color.BLACK); - table.put("MenuItem.selectionForeground", UIColor.MENU_ITEM_SELECTION_FOREGROUND_DEFAULT.get()); + table.put("MenuItem.selectionForeground", UIColor.MENU_ITEM_SELECTION_FOREGROUND.get()); table.put("MenuItem.font", MaterialFonts.MEDIUM); // table.put("MenuItem.background", Color.WHITE); - table.put("MenuItem.background", UIColor.MENU_ITEM_BACKGROUND_DEFAULT.get()); + table.put("MenuItem.background", UIColor.MENU_ITEM_BACKGROUND.get()); // table.put("MenuItem.foreground", Color.BLACK); - table.put("MenuItem.foreground", UIColor.MENU_ITEM_FOREGROUND_DEFAULT.get()); + table.put("MenuItem.foreground", UIColor.MENU_ITEM_FOREGROUND.get()); table.put("MenuItem.border", BorderFactory.createEmptyBorder(5, 0, 5, 0)); // table.put("OptionPane.background", Color.WHITE); - table.put("OptionPane.background", UIColor.OPTION_PANE_BACKGROUND_DEFAULT.get()); + table.put("OptionPane.background", UIColor.OPTION_PANE_BACKGROUND.get()); table.put("OptionPane.border", MaterialBorders.DEFAULT_SHADOW_BORDER); table.put("OptionPane.font", MaterialFonts.REGULAR); table.put("Panel.font", MaterialFonts.REGULAR); // table.put("Panel.background", Color.WHITE); - table.put("Panel.background", UIColor.PANEL_BACKGROUND_COLOR_DEFAULT.get()); + table.put("Panel.background", UIColor.PANEL_BACKGROUND_COLOR.get()); table.put("Panel.border", BorderFactory.createEmptyBorder()); table.put("PopupMenu.border", MaterialBorders.LIGHT_LINE_BORDER); // table.put("PopupMenu.background", Color.WHITE); - table.put("PopupMenu.background", UIColor.POPUP_MENU_BACKGROUND_DEFAULT.get()); + table.put("PopupMenu.background", UIColor.POPUP_MENU_BACKGROUND.get()); // table.put("PopupMenu.foreground", Color.BLACK); - table.put("PopupMenu.foreground", UIColor.POPUP_MENU_FOREGROUND_DEFAULT.get()); + table.put("PopupMenu.foreground", UIColor.POPUP_MENU_FOREGROUND.get()); table.put("RadioButton.font", MaterialFonts.REGULAR); // table.put("RadioButton.background", Color.WHITE); - table.put("RadioButton.background", UIColor.RADIO_BUTTON_BACKGROUND_DEFAULT.get()); + table.put("RadioButton.background", UIColor.RADIO_BUTTON_BACKGROUND.get()); // table.put("RadioButton.foreground", Color.BLACK); - table.put("RadioButton.foreground", UIColor.RADIO_BUTTON_FOREGROUND_DEFAULT.get()); + table.put("RadioButton.foreground", UIColor.RADIO_BUTTON_FOREGROUND.get()); table.put("RadioButton.icon", new ImageIcon(MaterialImages.RADIO_BUTTON_OFF)); table.put("RadioButton.selectedIcon", new ImageIcon(MaterialImages.RADIO_BUTTON_ON)); table.put("Spinner.font", MaterialFonts.REGULAR); // table.put("Spinner.background", Color.WHITE); - table.put("Spinner.background", UIColor.SPINNER_BACKGROUND_DEFAULT.get()); + table.put("Spinner.background", UIColor.SPINNER_BACKGROUND.get()); // table.put("Spinner.foreground", Color.BLACK); - table.put("Spinner.foreground", UIColor.SPINNER_FOREGROUND_DEFAULT.get()); + table.put("Spinner.foreground", UIColor.SPINNER_FOREGROUND.get()); table.put("Spinner.border", MaterialBorders.LIGHT_LINE_BORDER); // table.put("Spinner.arrowButtonBackground", MaterialColors.GRAY_200); - table.put("Spinner.arrowButtonBackground", UIColor.SPINNER_ARROW_BUTTON_BACKGROUND_DEFAULT.get()); + table.put("Spinner.arrowButtonBackground", UIColor.SPINNER_ARROW_BUTTON_BACKGROUND.get()); table.put("Spinner.arrowButtonBorder", BorderFactory.createEmptyBorder()); table.put("ScrollBar.font", MaterialFonts.REGULAR); // table.put("ScrollBar.track", MaterialColors.GRAY_200); - table.put("ScrollBar.track", UIColor.SCROLL_BAR_TRACK_DEFAULT.get()); + table.put("ScrollBar.track", UIColor.SCROLL_BAR_TRACK.get()); // table.put("ScrollBar.thumb", MaterialColors.GRAY_300); - table.put("ScrollBar.thumb", UIColor.SCROLL_BAR_THUMB_DEFAULT.get()); + table.put("ScrollBar.thumb", UIColor.SCROLL_BAR_THUMB.get()); // table.put("ScrollBar.thumbDarkShadow", MaterialColors.GRAY_300); - table.put("ScrollBar.thumbDarkShadow", UIColor.SCROLL_BAR_THUMB_DARK_SHADOW_DEFAULT.get()); + table.put("ScrollBar.thumbDarkShadow", UIColor.SCROLL_BAR_THUMB_DARK_SHADOW.get()); // table.put("ScrollBar.thumbHighlight", MaterialColors.GRAY_300); - table.put("ScrollBar.thumbHighlight", UIColor.SCROLL_BAR_THUMB_HIGHLIGHT_DEFAULT.get()); + table.put("ScrollBar.thumbHighlight", UIColor.SCROLL_BAR_THUMB_HIGHLIGHT.get()); // table.put("ScrollBar.thumbShadow", MaterialColors.GRAY_300); - table.put("ScrollBar.thumbShadow", UIColor.SCROLL_BAR_THUMB_SHADOW_DEFAULT.get()); + table.put("ScrollBar.thumbShadow", UIColor.SCROLL_BAR_THUMB_SHADOW.get()); // table.put("ScrollBar.arrowButtonBackground", MaterialColors.GRAY_300); - table.put("ScrollBar.arrowButtonBackground", UIColor.SCROLL_BAR_ARROW_BUTTON_BACKGROUND_DEFAULT.get()); + table.put("ScrollBar.arrowButtonBackground", UIColor.SCROLL_BAR_ARROW_BUTTON_BACKGROUND.get()); table.put("ScrollBar.arrowButtonBorder", BorderFactory.createEmptyBorder()); // table.put("ScrollPane.background", Color.WHITE); - table.put("ScrollPane.background", UIColor.SCROLL_PANE_BACKGROUND_DEFAULT.get()); + table.put("ScrollPane.background", UIColor.SCROLL_PANE_BACKGROUND.get()); table.put("ScrollPane.border", BorderFactory.createEmptyBorder()); table.put("ScrollPane.font", MaterialFonts.REGULAR); table.put("Slider.font", MaterialFonts.REGULAR); // table.put("Slider.background", Color.WHITE); - table.put("Slider.background", UIColor.SLIDER_BACKGROUND_DEFAULT.get()); + table.put("Slider.background", UIColor.SLIDER_BACKGROUND.get()); // table.put("Slider.foreground", MaterialColors.GRAY_700); - table.put("Slider.foreground", UIColor.SLIDER_FOREGROUND_DEFAULT.get()); + table.put("Slider.foreground", UIColor.SLIDER_FOREGROUND.get()); // table.put("Slider.trackColor", Color.BLACK); - table.put("Slider.trackColor", UIColor.SLIDER_TRACK_COLOR_DEFAULT.get()); + table.put("Slider.trackColor", UIColor.SLIDER_TRACK_COLOR.get()); // table.put ("Slider.border", // BorderFactory.createCompoundBorder(MaterialBorders.LIGHT_LINE_BORDER, // BorderFactory.createEmptyBorder (5, 5, 5, 5))); table.put("SplitPane.border", MaterialBorders.LIGHT_LINE_BORDER); // table.put("SplitPane.background", Color.WHITE); - table.put("SplitPane.background", UIColor.SPLIT_PANE_BACKGROUND_DEFAULT.get()); + table.put("SplitPane.background", UIColor.SPLIT_PANE_BACKGROUND.get()); table.put("SplitPane.dividerSize", 10); table.put("SplitPaneDivider.border", MaterialBorders.LIGHT_SHADOW_BORDER); table.put("TabbedPane.font", MaterialFonts.REGULAR); // table.put("TabbedPane.background", Color.WHITE); - table.put("TabbedPane.background", UIColor.TABBED_PANE_BACKGROUND_DEFAULT.get()); + table.put("TabbedPane.background", UIColor.TABBED_PANE_BACKGROUND.get()); // table.put("TabbedPane.foreground", Color.BLACK); - table.put("TabbedPane.foreground", UIColor.TABBED_PANE_FOREGROUND_DEFAULT.get()); + table.put("TabbedPane.foreground", UIColor.TABBED_PANE_FOREGROUND.get()); table.put("TabbedPane.border", BorderFactory.createEmptyBorder()); table.put("TabbedPane.shadow", null); table.put("TabbedPane.darkShadow", null); // table.put("TabbedPane.highlight", MaterialColors.GRAY_200); - table.put("TabbedPane.highlight", UIColor.TABBED_PANE_HIGHLIGHT_DEFAULT.get()); + table.put("TabbedPane.highlight", UIColor.TABBED_PANE_HIGHLIGHT.get()); // table.put("TabbedPane.borderHighlightColor", MaterialColors.GRAY_300); - table.put("TabbedPane.borderHighlightColor", UIColor.TABBED_PANE_BORDER_HIGHLIGHT_DEFAULT.get()); + table.put("TabbedPane.borderHighlightColor", UIColor.TABBED_PANE_BORDER_HIGHLIGHT.get()); // table.put("Table.selectionBackground", MaterialColors.GRAY_100); - table.put("Table.selectionBackground", UIColor.TABLE_SELECTION_BACKGROUND_DEFAULT.get()); + table.put("Table.selectionBackground", UIColor.TABLE_SELECTION_BACKGROUND.get()); // table.put("Table.selectionForeground", Color.BLACK); - table.put("Table.selectionForeground", UIColor.TABLE_SELECTION_FOREGROUND_DEFAULT.get()); + table.put("Table.selectionForeground", UIColor.TABLE_SELECTION_FOREGROUND.get()); // table.put("Table.background", Color.WHITE); - table.put("Table.background", UIColor.TABLE_BACKGROUND_DEFAULT.get()); + table.put("Table.background", UIColor.TABLE_BACKGROUND.get()); table.put("Table.font", MaterialFonts.REGULAR); table.put("Table.border", MaterialBorders.LIGHT_LINE_BORDER); // table.put("Table.gridColor", MaterialColors.GRAY_200); - table.put("Table.gridColor", UIColor.TABLE_GRID_COLOR_DEFAULT.get()); + table.put("Table.gridColor", UIColor.TABLE_GRID_COLOR.get()); // table.put("TableHeader.background", MaterialColors.GRAY_200); - table.put("TableHeader.background", UIColor.TABLE_HEADER_BACKGROUND_DEFAULT.get()); + table.put("TableHeader.background", UIColor.TABLE_HEADER_BACKGROUND.get()); table.put("TableHeader.font", MaterialFonts.BOLD); table.put( "TableHeader.cellBorder", @@ -327,53 +337,53 @@ protected void initComponentDefaults(UIDefaults table) { BorderFactory.createEmptyBorder(5, 5, 5, 5))); // table.put("TextArea.background", MaterialColors.GRAY_200); - table.put("TextArea.background", UIColor.TEXT_AREA_BACKGROUND_DEFAULT.get()); + table.put("TextArea.background", UIColor.TEXT_AREA_BACKGROUND.get()); table.put("TextArea.border", BorderFactory.createEmptyBorder()); // table.put("TextArea.foreground", Color.BLACK); - table.put("TextArea.foreground", UIColor.TEXT_AREA_FOREGROUND_DEFAULT.get()); + table.put("TextArea.foreground", UIColor.TEXT_AREA_FOREGROUND.get()); table.put("ToggleButton.border", BorderFactory.createEmptyBorder()); table.put("ToggleButton.font", MaterialFonts.REGULAR); // table.put("ToggleButton.background", Color.WHITE); - table.put("ToggleButton.background", UIColor.TOGGLE_BUTTON_BACKGROUND_DEFAULT.get()); + table.put("ToggleButton.background", UIColor.TOGGLE_BUTTON_BACKGROUND.get()); // table.put("ToggleButton.foreground", Color.BLACK); - table.put("ToggleButton.foreground", UIColor.TOGGLE_BUTTON_FOREGROUND_DEFAULT.get()); + table.put("ToggleButton.foreground", UIColor.TOGGLE_BUTTON_FOREGROUND.get()); table.put("ToggleButton.icon", new ImageIcon(MaterialImages.TOGGLE_BUTTON_OFF)); table.put("ToggleButton.selectedIcon", new ImageIcon(MaterialImages.TOGGLE_BUTTON_ON)); table.put("ToolBar.font", MaterialFonts.REGULAR); // table.put("ToolBar.background", Color.WHITE); - table.put("ToolBar.background", UIColor.TOOL_BAR_BACKGROUND_DEFAULT.get()); + table.put("ToolBar.background", UIColor.TOOL_BAR_BACKGROUND.get()); // table.put("ToolBar.foreground", Color.BLACK); - table.put("ToolBar.foreground", UIColor.TOOL_BAR_FOREGROUND_DEFAULT.get()); + table.put("ToolBar.foreground", UIColor.TOOL_BAR_FOREGROUND.get()); table.put("ToolBar.border", MaterialBorders.LIGHT_SHADOW_BORDER); // table.put("ToolBar.dockingBackground", MaterialColors.LIGHT_GREEN_A100); - table.put("ToolBar.dockingBackground", UIColor.TOOL_BAR_DOCKING_BACKGROUND_DEFAULT.get()); + table.put("ToolBar.dockingBackground", UIColor.TOOL_BAR_DOCKING_BACKGROUND.get()); // table.put("ToolBar.floatingBackground", MaterialColors.GRAY_200); - table.put("ToolBar.floatingBackground", UIColor.TOOL_BAR_FLOATING_BACKGROUND_DEFAULT.get()); + table.put("ToolBar.floatingBackground", UIColor.TOOL_BAR_FLOATING_BACKGROUND.get()); table.put("Tree.font", MaterialFonts.REGULAR); // table.put("Tree.selectionForeground", Color.BLACK); - table.put("Tree.selectionForeground", UIColor.TREE_SELECTION_FOREGROUND_DEFAULT.get()); + table.put("Tree.selectionForeground", UIColor.TREE_SELECTION_FOREGROUND.get()); // table.put("Tree.foreground", Color.BLACK); - table.put("Tree.foreground", UIColor.TREE_FOREGROUND_DEFAULT.get()); + table.put("Tree.foreground", UIColor.TREE_FOREGROUND.get()); // table.put("Tree.selectionBackground", MaterialColors.GRAY_200); - table.put("Tree.selectionBackground", UIColor.TREE_SELECTION_BACKGROUND_DEFAULT.get()); + table.put("Tree.selectionBackground", UIColor.TREE_SELECTION_BACKGROUND.get()); // table.put("Tree.background", Color.WHITE); - table.put("Tree.background", UIColor.TREE_BACKGROUND_DEFAULT.get()); + table.put("Tree.background", UIColor.TREE_BACKGROUND.get()); table.put("Tree.closedIcon", new ImageIcon(MaterialImages.RIGHT_ARROW)); table.put("Tree.openIcon", new ImageIcon(MaterialImages.DOWN_ARROW)); table.put("Tree.selectionBorderColor", null); // table.put("RadioButtonMenuItem.foreground", Color.BLACK); - table.put("RadioButtonMenuItem.foreground", UIColor.RADIO_BUTTON_FOREGROUND_DEFAULT.get()); + table.put("RadioButtonMenuItem.foreground", UIColor.RADIO_BUTTON_FOREGROUND.get()); // table.put("RadioButtonMenuItem.selectionForeground", Color.BLACK); - table.put("RadioButtonMenuItem.selectionForeground", UIColor.RADIO_BUTTON_MENU_ITEM_SELECTION_FOREGROUND_DEFAULT.get()); + table.put("RadioButtonMenuItem.selectionForeground", UIColor.RADIO_BUTTON_MENU_ITEM_SELECTION_FOREGROUND.get()); // If it changes the background of the menuitem it must change this too, irrespective of its // setting table.put("RadioButtonMenuItem.background", UIManager.getColor("MenuItem.background")); // table.put("RadioButtonMenuItem.selectionBackground", MaterialColors.GRAY_200); - table.put("RadioButtonMenuItem.selectionBackground", UIColor.RADIO_BUTTON_MENU_ITEM_SELECTION_BACKGROUND_DEFAULT.get()); + table.put("RadioButtonMenuItem.selectionBackground", UIColor.RADIO_BUTTON_MENU_ITEM_SELECTION_BACKGROUND.get()); table.put("RadioButtonMenuItem.border", BorderFactory.createEmptyBorder(5, 5, 5, 5)); table.put("RadioButtonMenuItem.checkIcon", new ImageIcon(MaterialImages.RADIO_BUTTON_OFF)); table.put( @@ -384,11 +394,11 @@ protected void initComponentDefaults(UIDefaults table) { // setting table.put("CheckBoxMenuItem.background", UIManager.getColor("MenuItem.background")); // table.put("CheckBoxMenuItem.selectionBackground", MaterialColors.GRAY_200); - table.put("CheckBoxMenuItem.selectionBackground", UIColor.CHECKBOX_MENU_ITEM_SELECTION_BACKGROUND_DEFAULT.get()); + table.put("CheckBoxMenuItem.selectionBackground", UIColor.CHECKBOX_MENU_ITEM_SELECTION_BACKGROUND.get()); // table.put("CheckBoxMenuItem.foreground", Color.BLACK); - table.put("CheckBoxMenuItem.foreground", UIColor.CHECKBOX_MENU_ITEM_FOREGROUND_DEFAULT.get()); + table.put("CheckBoxMenuItem.foreground", UIColor.CHECKBOX_MENU_ITEM_FOREGROUND.get()); // table.put("CheckBoxMenuItem.selectionForeground", Color.BLACK); - table.put("CheckBoxMenuItem.selectionForeground", UIColor.CHECKBOX_MENU_ITEM_SELECTION_FOREGROUND_DEFAULT.get()); + table.put("CheckBoxMenuItem.selectionForeground", UIColor.CHECKBOX_MENU_ITEM_SELECTION_FOREGROUND.get()); table.put("CheckBoxMenuItem.border", BorderFactory.createEmptyBorder(5, 5, 5, 5)); table.put("CheckBoxMenuItem.checkIcon", new ImageIcon(MaterialImages.UNCHECKED_BOX)); table.put( @@ -397,36 +407,36 @@ protected void initComponentDefaults(UIDefaults table) { table.put("TextPane.border", MaterialBorders.LIGHT_LINE_BORDER); // table.put("TextPane.background", MaterialColors.GRAY_50); - table.put("TextPane.background", UIColor.TEXT_PANE_BACKGROUND_DEFAULT.get()); + table.put("TextPane.background", UIColor.TEXT_PANE_BACKGROUND.get()); // table.put("TextPane.selectionBackground", MaterialColors.LIGHT_BLUE_200); - table.put("TextPane.selectionBackground", UIColor.TEXT_PANE_SELECTION_BACKGROUND_DEFAULT.get()); + table.put("TextPane.selectionBackground", UIColor.TEXT_PANE_SELECTION_BACKGROUND.get()); // table.put("TextPane.inactiveForeground", MaterialColors.GRAY_500); - table.put("TextPane.inactiveForeground", UIColor.TEXT_PANE_INACTIVE_FOREGROUND_DEFAULT.get()); + table.put("TextPane.inactiveForeground", UIColor.TEXT_PANE_INACTIVE_FOREGROUND.get()); table.put("TextPane.font", MaterialFonts.REGULAR); table.put("EditorPane.border", MaterialBorders.LIGHT_LINE_BORDER); // table.put("EditorPane.background", MaterialColors.GRAY_50); - table.put("EditorPane.background", UIColor.EDITOR_PANE_BACKGROUND_DEFAULT.get()); + table.put("EditorPane.background", UIColor.EDITOR_PANE_BACKGROUND.get()); // table.put("EditorPane.selectionBackground", MaterialColors.LIGHT_BLUE_200); - table.put("EditorPane.selectionBackground", UIColor.EDITOR_PANE_SELECTION_BACKGROUND_DEFAULT.get()); + table.put("EditorPane.selectionBackground", UIColor.EDITOR_PANE_SELECTION_BACKGROUND.get()); // table.put("EditorPane.inactiveForeground", MaterialColors.GRAY_500); - table.put("EditorPane.inactiveForeground", UIColor.EDITOR_PANE_INACTIVE_FOREGROUND_DEFAULT.get()); + table.put("EditorPane.inactiveForeground", UIColor.EDITOR_PANE_INACTIVE_FOREGROUND.get()); table.put("EditorPane.font", MaterialFonts.REGULAR); // table.put("Separator.background", MaterialColors.GRAY_300); - table.put("Separator.background", UIColor.SEPARATOR_BACKGROUND_DEFAULT.get()); + table.put("Separator.background", UIColor.SEPARATOR_BACKGROUND.get()); // table.put("Separator.foreground", MaterialColors.GRAY_300); - table.put("Separator.foreground", UIColor.SEPARATOR_FOREGROUND_DEFAULT.get()); + table.put("Separator.foreground", UIColor.SEPARATOR_FOREGROUND.get()); // table.put("ToolTip.background", MaterialColors.GRAY_500); - table.put("ToolTip.background", UIColor.TOOL_TIP_BACKGROUND_DEFAULT.get()); + table.put("ToolTip.background", UIColor.TOOL_TIP_BACKGROUND.get()); // table.put("ToolTip.foreground", MaterialColors.GRAY_50); - table.put("ToolTip.foreground", UIColor.TOOL_TIP_FOREGROUND_DEFAULT.get()); + table.put("ToolTip.foreground", UIColor.TOOL_TIP_FOREGROUND.get()); table.put("ToolTip.border", BorderFactory.createEmptyBorder(5, 5, 5, 5)); // table.put("ColorChooser.background", MaterialColors.WHITE); - table.put("ColorChooser.background", UIColor.COLOR_CHOOSER_BACKGROUND_DEFAULT.get()); + table.put("ColorChooser.background", UIColor.COLOR_CHOOSER_BACKGROUND.get()); // table.put("ColorChooser.foreground", MaterialColors.BLACK); - table.put("ColorChooser.foreground", UIColor.COLOR_CHOOSER_FOREGROUND_DEFAULT.get()); + table.put("ColorChooser.foreground", UIColor.COLOR_CHOOSER_FOREGROUND.get()); } } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialButtonUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialButtonUI.java index debe6e215..9d7461ccc 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialButtonUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialButtonUI.java @@ -1,7 +1,8 @@ package edu.rpi.legup.ui.lookandfeel.components; import edu.rpi.legup.ui.lookandfeel.animation.MaterialUIMovement; -import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialColors; +//import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialColors; +import edu.rpi.legup.ui.color.ColorPreferences.UIColor; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialDrawingUtils; import java.awt.Graphics; import javax.swing.AbstractButton; @@ -9,6 +10,7 @@ import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicButtonUI; +import edu.rpi.legup.ui.color.ColorPreferences.UIColor; public class MaterialButtonUI extends BasicButtonUI { @@ -21,7 +23,7 @@ public void installUI(JComponent c) { super.installUI(c); AbstractButton button = (AbstractButton) c; - MaterialUIMovement.add(c, MaterialColors.GRAY_300); + MaterialUIMovement.add(c, UIColor.UI_MOVEMENT.get()); button.setOpaque(UIManager.getBoolean("Button.opaque")); button.setBorder(UIManager.getBorder("Button.border")); button.setBackground(UIManager.getColor("Button.background")); diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialPasswordFieldUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialPasswordFieldUI.java index d4778402b..be9bbfb86 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialPasswordFieldUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialPasswordFieldUI.java @@ -1,6 +1,7 @@ package edu.rpi.legup.ui.lookandfeel.components; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialColors; +import edu.rpi.legup.ui.color.ColorPreferences.UIColor; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialDrawingUtils; import java.awt.Color; import java.awt.FontMetrics; @@ -45,10 +46,10 @@ public void installUI(JComponent c) { JPasswordField passwordField = (JPasswordField) c; passwordField.setOpaque(false); passwordField.setBorder(BorderFactory.createEmptyBorder(5, 2, 10, 0)); - passwordField.setBackground(MaterialColors.LIGHT_BLUE_400); + passwordField.setBackground(UIColor.PASSWORD_FIELD_BACKGROUND.get()); this.focusedBackground = passwordField.getBackground(); - this.unfocusedBackground = MaterialColors.GRAY_200; + this.unfocusedBackground = UIColor.PASSWORD_FIELD_UNFOCUSED_BACKGROUND.get(); this.focusedSelectionBackground = MaterialColors.bleach(focusedBackground, 0.3f); this.unfocusedSelectionBackground = unfocusedBackground; diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialProgressBarUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialProgressBarUI.java index 7f91a779f..edb39c9fa 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialProgressBarUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialProgressBarUI.java @@ -1,7 +1,8 @@ package edu.rpi.legup.ui.lookandfeel.components; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialBorders; -import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialColors; +//import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialColors; +import edu.rpi.legup.ui.color.ColorPreferences.UIColor; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialDrawingUtils; import java.awt.Graphics; import javax.swing.JComponent; @@ -24,8 +25,8 @@ public void installUI(JComponent c) { JProgressBar progressBar = (JProgressBar) c; progressBar.setBorder(MaterialBorders.LIGHT_LINE_BORDER); - progressBar.setBackground(MaterialColors.GRAY_200); - progressBar.setForeground(MaterialColors.LIGHT_BLUE_400); + progressBar.setBackground(UIColor.PROGRESS_BAR_BACKGROUND.get()); + progressBar.setForeground(UIColor.PROGRESS_BAR_FOREGROUND.get()); } @Override diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTextFieldUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTextFieldUI.java index 5cfd2fc88..b980d81f8 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTextFieldUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTextFieldUI.java @@ -1,6 +1,7 @@ package edu.rpi.legup.ui.lookandfeel.components; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialColors; +import edu.rpi.legup.ui.color.ColorPreferences.UIColor; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialDrawingUtils; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialFonts; import java.awt.Color; @@ -54,11 +55,11 @@ public void installUI(JComponent c) { ? BorderFactory.createEmptyBorder(5, 2, 10, 0) : BorderFactory.createEmptyBorder(2, 2, 2, 2)); - textField.setBackground(MaterialColors.LIGHT_BLUE_400); + textField.setBackground(UIColor.TEXT_FIELD_BACKGROUND.get()); textField.setFont(MaterialFonts.REGULAR); this.focusedBackground = textField.getBackground(); - this.unfocusedBackground = MaterialColors.GRAY_200; + this.unfocusedBackground = UIColor.TEXT_FIELD_UNFOCUSED_BACKGROUND.get(); this.focusedSelectionBackground = MaterialColors.bleach(focusedBackground, 0.3f); this.unfocusedSelectionBackground = unfocusedBackground; diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialBorders.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialBorders.java index 8c2e3eeec..cf27e7265 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialBorders.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialBorders.java @@ -1,5 +1,6 @@ package edu.rpi.legup.ui.lookandfeel.materialdesign; +import edu.rpi.legup.ui.color.ColorPreferences.UIColor; import java.awt.Color; import javax.swing.BorderFactory; import javax.swing.border.Border; @@ -7,9 +8,9 @@ public class MaterialBorders { public static final Border LIGHT_LINE_BORDER = - BorderFactory.createLineBorder(MaterialColors.GRAY_200, 1); + BorderFactory.createLineBorder(UIColor.LIGHT_LINE_BORDER.get(), 1); public static final Border THICK_LINE_BORDER = - BorderFactory.createLineBorder(MaterialColors.GRAY_200, 2); + BorderFactory.createLineBorder(UIColor.THICK_LINE_BORDER.get(), 2); public static final Border LIGHT_SHADOW_BORDER = new DropShadowBorder(Color.BLACK, 0, 4, 0.3f, 12, true, true, true, true); diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialColors.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialColors.java index 00cb0720a..3076d8cbd 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialColors.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialColors.java @@ -2,6 +2,7 @@ import java.awt.*; +@SuppressWarnings("unused") public class MaterialColors { public static final Color RED_50 = new Color(255, 235, 238); public static final Color RED_100 = new Color(255, 205, 210); diff --git a/src/main/java/edu/rpi/legup/utility/Logger.java b/src/main/java/edu/rpi/legup/utility/Logger.java index 67048e5b4..42782ca39 100644 --- a/src/main/java/edu/rpi/legup/utility/Logger.java +++ b/src/main/java/edu/rpi/legup/utility/Logger.java @@ -13,7 +13,7 @@ public class Logger { private static final String LEGUP_HOME = - System.getProperty("user.home") + File.separator + ".legup" + File.separator; + System.getProperty("user.dir") + File.separator + ".legup" + File.separator; public static void initLogger() { LoggerContext context = (LoggerContext) LogManager.getContext(false); diff --git a/src/main/resources/color-theme.txt b/src/main/resources/color-theme.txt deleted file mode 100644 index 20161e1a9..000000000 --- a/src/main/resources/color-theme.txt +++ /dev/null @@ -1,88 +0,0 @@ -correct: BLUE -incorrect: RED -data-selection-background: GRAY -element-view-default: BLACK -button-highlight-default: GRAY_300 -button-background-default: GRAY_200 -button-foreground-default: BLACK -checkbox-background-default: WHITE -checkbox-foreground-default: BLACK -combobox-background-default: WHITE -combobox-foreground-default: BOX -combobox-button-background-default: GRAY_300 -combobox-selection-background-default: WHITE -combobox-selection-foreground-default: BLACK -combobox-selected-in-drop-down-background-default: GRAY_200 -label-background-default: WHITE -label-foreground-default: BLACK -menu-background-default: WHITE -menu-foreground-default: BLACK -menu-selection-background-default: GRAY_200 -menu-selection-foreground-default: BLACK -menu-disabled-foreground-default: #000 -menu-bar-background-default: WHITE -menu-bar-foreground-default: BLACK -menu-item-disabled-foreground-default: #000 -menu-item-selection-background-default: GRAY_200 -menu-item-selection-foreground-default: BLACK -menu-item-background-default: WHITE -menu-item-foreground-default: BLACK -option-pane-background-default: WHITE -panel-background-color-default: WHITE -popup-menu-background-default: WHITE -popup-menu-foreground-default: BLACK -radio-button-background-default: WHITE -radio-button-foreground-default: BLACK -spinner-background-default: WHITE -spinner-foreground-default: BLACK -spinner-arrow-button-background-default: GRAY_200 -scroll-bar-track-default: GRAY_200 -scroll-bar-thumb-default: GRAY_300 -scroll-bar-thumb-dark-shadow-default: GRAY_300 -scroll-bar-thumb-highlight-default: GRAY_300 -scroll-bar-thumb-shadow-default: GRAY_300 -scroll-bar-arrow-button-background-default: GRAY_300 -scroll-pane-background-default: WHITE -slider-background-default: WHITE -slider-foreground-default: GRAY_700 -slider-track-color-default: BLACK -split-pane-background-default: WHITE -tabbed-pane-background-default: WHITE -tabbed-pane-foreground-default: BLACK -tabbed-pane-highlight-default: GRAY_200 -tabbed-pane-border-highlight-default: GRAY_300 -table-selection-background-default: GRAY_100 -table-selection-foreground-default: BLACK -table-background-default: WHITE -table-grid-color-default: GRAY_200 -table-header-background-default: GRAY_200 -text-area-background-default: GRAY_200 -text-area-foreground-default: BLACK -toggle-button-background-default: WHITE -toggle-button-foreground-default: BLACK -tool-bar-background-default: WHITE -tool-bar-foreground-default: BLACK -tool-bar-docking-background-default: LIGHT_GREEN_A100 -tool-bar-floating-background-default: GRAY_200 -tree-selection-foreground-default: BLACK -tree-foreground-default: BLACK -tree-selection-background-default: GRAY_200 -tree-background-default: WHITE -radio-button-menu-item-foreground-default: BLACK -radio-button-menu-item-selection-foreground-default: BLACK -radio-button-menu-item-selection-background-default: GRAY_200 -checkbox-menu-item-selection-background-default: GRAY_200 -checkbox-menu-item-foreground-default: BLACK -checkbox-menu-item-selection-foreground-default: BLACK -text-pane-background-default: GRAY_50 -text-pane-selection-background-default: LIGHT_BLUE_200 -text-pane-inactive-foreground-default: GRAY_500 -editor-pane-background-default: GRAY_50 -editor-pane-selection-background-default: LIGHT_BLUE_200 -editor-pane-inactive-foreground-default: GRAY_500 -separator-background-default: GRAY_300 -separator-foreground-default: GRAY_300 -tool-tip-background-default: GRAY_500 -tool-tip-foreground-default: GRAY_50 -color-chooser-background-default: WHITE -color-chooser-foreground-default: BLACK \ No newline at end of file diff --git a/src/main/resources/dark-color-theme.txt b/src/main/resources/dark-color-theme.txt new file mode 100644 index 000000000..c6f91b094 --- /dev/null +++ b/src/main/resources/dark-color-theme.txt @@ -0,0 +1,99 @@ +correct: BLUE +incorrect: RED +error: RED_700 +info: GRAY_900 +ui-movement: GRAY_300 +password-field-background: LIGHT_BLUE_400 +password-field-unfocused-background: GRAY_200 +progress-bar-background: GRAY_200 +progress-bar-foreground: LIGHT_BLUE_400 +text-field-background: LIGHT_BLUE_400 +text-field-unfocused-background: GRAY_200 +light-line-border: GRAY_200 +thick-line-border: GRAY_200 +data-selection-background: GRAY +element-view: BLACK +button-highlight: GRAY_300 +button-background: GRAY_200 +button-foreground: BLACK +checkbox-background: WHITE +checkbox-foreground: BLACK +combobox-background: WHITE +combobox-foreground: BLACK +combobox-button-background: GRAY_300 +combobox-selection-background: WHITE +combobox-selection-foreground: BLACK +combobox-selected-in-drop-down-background: GRAY_200 +label-background: WHITE +label-foreground: BLACK +menu-background: LIGHT_BLUE_100 +menu-foreground: BLACK +menu-selection-background: GRAY_200 +menu-selection-foreground: BLACK +menu-disabled-foreground: #000 +menu-bar-background: WHITE +menu-bar-foreground: BLACK +menu-item-disabled-foreground: #000 +menu-item-selection-background: GRAY_200 +menu-item-selection-foreground: BLACK +menu-item-background: WHITE +menu-item-foreground: BLACK +option-pane-background: WHITE +panel-background-color: WHITE +popup-menu-background: WHITE +popup-menu-foreground: BLACK +radio-button-background: WHITE +radio-button-foreground: BLACK +spinner-background: WHITE +spinner-foreground: BLACK +spinner-arrow-button-background: GRAY_200 +scroll-bar-track: GRAY_200 +scroll-bar-thumb: GRAY_300 +scroll-bar-thumb-dark-shadow: GRAY_300 +scroll-bar-thumb-highlight: GRAY_300 +scroll-bar-thumb-shadow: GRAY_300 +scroll-bar-arrow-button-background: GRAY_300 +scroll-pane-background: WHITE +slider-background: WHITE +slider-foreground: GRAY_700 +slider-track-color: BLACK +split-pane-background: WHITE +tabbed-pane-background: WHITE +tabbed-pane-foreground: BLACK +tabbed-pane-highlight: GRAY_200 +tabbed-pane-border-highlight: GRAY_300 +table-selection-background: GRAY_100 +table-selection-foreground: BLACK +table-background: WHITE +table-grid-color: GRAY_200 +table-header-background: GRAY_200 +text-area-background: GRAY_200 +text-area-foreground: BLACK +toggle-button-background: WHITE +toggle-button-foreground: BLACK +tool-bar-background: WHITE +tool-bar-foreground: BLACK +tool-bar-docking-background: LIGHT_GREEN_A100 +tool-bar-floating-background: GRAY_200 +tree-selection-foreground: BLACK +tree-foreground: BLACK +tree-selection-background: GRAY_200 +tree-background: WHITE +radio-button-menu-item-foreground: BLACK +radio-button-menu-item-selection-foreground: BLACK +radio-button-menu-item-selection-background: GRAY_200 +checkbox-menu-item-selection-background: GRAY_200 +checkbox-menu-item-foreground: BLACK +checkbox-menu-item-selection-foreground: BLACK +text-pane-background: GRAY_50 +text-pane-selection-background: LIGHT_BLUE_200 +text-pane-inactive-foreground: GRAY_500 +editor-pane-background: GRAY_50 +editor-pane-selection-background: LIGHT_BLUE_200 +editor-pane-inactive-foreground: GRAY_500 +separator-background: GRAY_300 +separator-foreground: GRAY_300 +tool-tip-background: GRAY_500 +tool-tip-foreground: GRAY_50 +color-chooser-background: WHITE +color-chooser-foreground: BLACK \ No newline at end of file diff --git a/src/main/resources/light-color-theme.txt b/src/main/resources/light-color-theme.txt new file mode 100644 index 000000000..c6f91b094 --- /dev/null +++ b/src/main/resources/light-color-theme.txt @@ -0,0 +1,99 @@ +correct: BLUE +incorrect: RED +error: RED_700 +info: GRAY_900 +ui-movement: GRAY_300 +password-field-background: LIGHT_BLUE_400 +password-field-unfocused-background: GRAY_200 +progress-bar-background: GRAY_200 +progress-bar-foreground: LIGHT_BLUE_400 +text-field-background: LIGHT_BLUE_400 +text-field-unfocused-background: GRAY_200 +light-line-border: GRAY_200 +thick-line-border: GRAY_200 +data-selection-background: GRAY +element-view: BLACK +button-highlight: GRAY_300 +button-background: GRAY_200 +button-foreground: BLACK +checkbox-background: WHITE +checkbox-foreground: BLACK +combobox-background: WHITE +combobox-foreground: BLACK +combobox-button-background: GRAY_300 +combobox-selection-background: WHITE +combobox-selection-foreground: BLACK +combobox-selected-in-drop-down-background: GRAY_200 +label-background: WHITE +label-foreground: BLACK +menu-background: LIGHT_BLUE_100 +menu-foreground: BLACK +menu-selection-background: GRAY_200 +menu-selection-foreground: BLACK +menu-disabled-foreground: #000 +menu-bar-background: WHITE +menu-bar-foreground: BLACK +menu-item-disabled-foreground: #000 +menu-item-selection-background: GRAY_200 +menu-item-selection-foreground: BLACK +menu-item-background: WHITE +menu-item-foreground: BLACK +option-pane-background: WHITE +panel-background-color: WHITE +popup-menu-background: WHITE +popup-menu-foreground: BLACK +radio-button-background: WHITE +radio-button-foreground: BLACK +spinner-background: WHITE +spinner-foreground: BLACK +spinner-arrow-button-background: GRAY_200 +scroll-bar-track: GRAY_200 +scroll-bar-thumb: GRAY_300 +scroll-bar-thumb-dark-shadow: GRAY_300 +scroll-bar-thumb-highlight: GRAY_300 +scroll-bar-thumb-shadow: GRAY_300 +scroll-bar-arrow-button-background: GRAY_300 +scroll-pane-background: WHITE +slider-background: WHITE +slider-foreground: GRAY_700 +slider-track-color: BLACK +split-pane-background: WHITE +tabbed-pane-background: WHITE +tabbed-pane-foreground: BLACK +tabbed-pane-highlight: GRAY_200 +tabbed-pane-border-highlight: GRAY_300 +table-selection-background: GRAY_100 +table-selection-foreground: BLACK +table-background: WHITE +table-grid-color: GRAY_200 +table-header-background: GRAY_200 +text-area-background: GRAY_200 +text-area-foreground: BLACK +toggle-button-background: WHITE +toggle-button-foreground: BLACK +tool-bar-background: WHITE +tool-bar-foreground: BLACK +tool-bar-docking-background: LIGHT_GREEN_A100 +tool-bar-floating-background: GRAY_200 +tree-selection-foreground: BLACK +tree-foreground: BLACK +tree-selection-background: GRAY_200 +tree-background: WHITE +radio-button-menu-item-foreground: BLACK +radio-button-menu-item-selection-foreground: BLACK +radio-button-menu-item-selection-background: GRAY_200 +checkbox-menu-item-selection-background: GRAY_200 +checkbox-menu-item-foreground: BLACK +checkbox-menu-item-selection-foreground: BLACK +text-pane-background: GRAY_50 +text-pane-selection-background: LIGHT_BLUE_200 +text-pane-inactive-foreground: GRAY_500 +editor-pane-background: GRAY_50 +editor-pane-selection-background: LIGHT_BLUE_200 +editor-pane-inactive-foreground: GRAY_500 +separator-background: GRAY_300 +separator-foreground: GRAY_300 +tool-tip-background: GRAY_500 +tool-tip-foreground: GRAY_50 +color-chooser-background: WHITE +color-chooser-foreground: BLACK \ No newline at end of file From 555154b4c6c9569e5ac9a96bf9ebfdf8a02db059 Mon Sep 17 00:00:00 2001 From: FisherLuba <145061313+FisherLuba@users.noreply.github.com> Date: Tue, 26 Mar 2024 16:36:30 -0400 Subject: [PATCH 04/10] Automatically add new colors that are added in the resources folder to the current color theme file --- .../rpi/legup/ui/color/ColorPreferences.java | 46 +++++++++++++++---- src/main/resources/light-color-theme.txt | 2 +- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/src/main/java/edu/rpi/legup/ui/color/ColorPreferences.java b/src/main/java/edu/rpi/legup/ui/color/ColorPreferences.java index 34d786979..72a1d51b1 100644 --- a/src/main/java/edu/rpi/legup/ui/color/ColorPreferences.java +++ b/src/main/java/edu/rpi/legup/ui/color/ColorPreferences.java @@ -3,6 +3,7 @@ //import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialColors; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialColors; +import org.jetbrains.annotations.Unmodifiable; import java.awt.*; import java.io.*; @@ -131,6 +132,41 @@ public Color get() { } } + private static void checkNewColors(Path path, Set usedColors) { + if (usedColors.size() == UIColor.values().length) { + return; + } + final InputStream input = ClassLoader.getSystemClassLoader().getResourceAsStream(path.getFileName().toString()); + final BufferedReader reader = new BufferedReader(new InputStreamReader(input)); + final Map newColors = loadColors(reader.lines().toList()); + final Map addColors = newColors.entrySet().stream() + .filter(e -> !usedColors.contains(e.getKey())) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + try { + for (final var entry : addColors.entrySet()) { + final Color color = entry.getValue(); + final String hex = String.format("#%02x%02x%02x", color.getRed(), color.getGreen(), color.getBlue()); + Files.writeString( + path, + entry.getKey().configKey() + ": " + hex + "\n", + StandardOpenOption.APPEND + ); + COLOR_MAP.put(entry.getKey(), color); + } + } + catch (IOException e) { + throw new RuntimeException(e); + } + } + + private static @Unmodifiable Map loadColors(List lines) { + return lines.stream() + .filter(l -> !l.startsWith("//")) // Use // for comments + .map(l -> l.split(":")) + .filter(a -> a.length == 2) + .collect(Collectors.toUnmodifiableMap(e -> UIColor.valueOf(e[0].replace("-", "_").toUpperCase()), e -> colorFromString(e[1].strip()))); + } + public static void loadColorScheme(String fileName) { final Path path = Path.of(fileName); final File file = path.toFile(); @@ -170,15 +206,9 @@ public static void loadColorScheme(String fileName) { }); } - Set temp = new HashSet<>(); + COLOR_MAP.putAll(loadColors(lines)); - COLOR_MAP.putAll( - lines.stream() - .filter(l -> !l.startsWith("//")) // Use // for comments - .map(l -> l.split(":")) - .filter(a -> a.length == 2) - .collect(Collectors.toMap(e -> UIColor.valueOf(e[0].replace("-", "_").toUpperCase()), e -> colorFromString(e[1].strip())))); - System.out.println("Colors: " + COLOR_MAP); + checkNewColors(path, COLOR_MAP.keySet()); } public static Color colorFromString(String color) { diff --git a/src/main/resources/light-color-theme.txt b/src/main/resources/light-color-theme.txt index c6f91b094..5c45bc71b 100644 --- a/src/main/resources/light-color-theme.txt +++ b/src/main/resources/light-color-theme.txt @@ -96,4 +96,4 @@ separator-foreground: GRAY_300 tool-tip-background: GRAY_500 tool-tip-foreground: GRAY_50 color-chooser-background: WHITE -color-chooser-foreground: BLACK \ No newline at end of file +color-chooser-foreground: BLACK From 53303e9fef951c37db5f810eb2859580d1b09d0c Mon Sep 17 00:00:00 2001 From: FisherLuba <145061313+FisherLuba@users.noreply.github.com> Date: Fri, 29 Mar 2024 17:31:37 -0400 Subject: [PATCH 05/10] Improve LegupPreferences class to make it easier to change/add preferences in the future. --- .../edu/rpi/legup/app/LegupPreferences.java | 316 +++++++++++++----- .../legup/controller/ElementController.java | 4 +- .../rpi/legup/controller/RuleController.java | 50 +-- .../java/edu/rpi/legup/model/rules/Rule.java | 2 +- .../ShortTruthTableElementView.java | 4 +- .../puzzle/sudoku/SudokuElementView.java | 5 +- src/main/java/edu/rpi/legup/ui/HomePanel.java | 8 +- src/main/java/edu/rpi/legup/ui/LegupUI.java | 10 +- .../edu/rpi/legup/ui/PreferencesDialog.java | 73 ++-- .../edu/rpi/legup/ui/ProofEditorPanel.java | 199 ++++++----- .../edu/rpi/legup/ui/PuzzleEditorPanel.java | 4 +- .../treeview/TreeTransitionView.java | 2 +- 12 files changed, 447 insertions(+), 230 deletions(-) diff --git a/src/main/java/edu/rpi/legup/app/LegupPreferences.java b/src/main/java/edu/rpi/legup/app/LegupPreferences.java index b051ed805..d488b5428 100644 --- a/src/main/java/edu/rpi/legup/app/LegupPreferences.java +++ b/src/main/java/edu/rpi/legup/app/LegupPreferences.java @@ -3,8 +3,9 @@ import edu.rpi.legup.ui.color.ColorPreferences; import java.io.File; -import java.util.HashMap; +import java.util.EnumMap; import java.util.Map; +import java.util.function.Function; import java.util.prefs.Preferences; public class LegupPreferences { @@ -16,66 +17,179 @@ public class LegupPreferences { private static final Preferences preferences = Preferences.userNodeForPackage(LegupPreferences.class); - private static final Map preferencesMap = new HashMap<>(); - private static final Map defaultPreferencesMap = new HashMap<>(); - - public static final String WORK_DIRECTORY = "work-directory"; - public static final String START_FULL_SCREEN = "start-full-screen"; - public static final String AUTO_UPDATE = "auto-update"; - public static final String DARK_MODE = "night-mode"; - public static final String SHOW_MISTAKES = "show-mistakes"; - public static final String SHOW_ANNOTATIONS = "show-annotations"; - public static final String ALLOW_DEFAULT_RULES = "allow-default-rules"; - public static final String AUTO_GENERATE_CASES = "auto-generate-cases"; - public static final String IMMEDIATE_FEEDBACK = "immediate-feedback"; - public static final String COLOR_THEME_FILE = "color-theme-file"; - public static final String COLOR_BLIND = "color-blind"; + private static final Map preferencesMap = new EnumMap<>(LegupPreference.class); + private static final Map defaultPreferencesMap = new EnumMap<>(LegupPreference.class); + + public enum LegupPreference { + WORK_DIRECTORY("work-directory", System.getProperty("user.dir"), o -> o), + START_FULL_SCREEN("start-full-screen", false, Boolean::parseBoolean), + AUTO_UPDATE("auto-update", true, Boolean::parseBoolean), + DARK_MODE("night-mode", false, Boolean::parseBoolean), + USE_CUSTOM_COLOR_THEME("use-custom-color-theme", false, Boolean::parseBoolean), + SHOW_MISTAKES("show-mistakes", true, Boolean::parseBoolean), + SHOW_ANNOTATIONS("show-annotations", true, Boolean::parseBoolean), + ALLOW_DEFAULT_RULES("allow-default-rules", false, Boolean::parseBoolean), + AUTO_GENERATE_CASES("auto-generate-cases", true, Boolean::parseBoolean), + IMMEDIATE_FEEDBACK("immediate-feedback", true, Boolean::parseBoolean), + COLOR_THEME_FILE("color-theme-file", System.getProperty("user.dir") + File.separator + ColorPreferences.LIGHT_COLOR_THEME_FILE_NAME, o -> o), + COLOR_BLIND("color-blind", false, Boolean::parseBoolean); + + private final String id; + private final Object defaultValue; + private final Function stringMapper; + private final Function stringToValueMapper; + + @SuppressWarnings("unchecked") + LegupPreference( + String id, + T defaultValue, + Function stringMapper, + Function stringToValueMapper + ) { + this.id = id; + this.defaultValue = defaultValue; + this.stringMapper = (Function) stringMapper; + this.stringToValueMapper = (Function) stringToValueMapper; + } + + LegupPreference(String id, T defaultValue, Function stringToValueMapper) { + this(id, defaultValue, String::valueOf, stringToValueMapper); + } + + public String id() { + return this.id; + } + + public String defaultStringValue() { + return stringMapper.apply(defaultValue); + } + + @SuppressWarnings("unused") + public Object defaultValue() { + return defaultValue; + } + + public String stringValue() { + return stringMapper.apply(preferencesMap.get(this)); + } + + /** + * Convenience method to return the value of this preference cast to {@code clazz} + * @param clazz + * @return + * @param + */ + public T as(Class clazz) { + return clazz.cast(defaultValue); + } + + public boolean asBoolean() { + return as(Boolean.class); + } + + public boolean asBoolean(String errorMessage) { + return as(Boolean.class, errorMessage); + } + + public T as(Class clazz, String errorMessage) { + try { + return clazz.cast(defaultValue); + } catch (Exception e) { + throw new RuntimeException(errorMessage); + } + } + + @SuppressWarnings("unchecked") + public T convertToValue(String value) { + return (T) stringToValueMapper.apply(value); + } + + public String convertToString(Object value) { + return stringMapper.apply(value); + } + } + +// public static final String WORK_DIRECTORY = "work-directory"; +// public static final String START_FULL_SCREEN = "start-full-screen"; +// public static final String AUTO_UPDATE = "auto-update"; +// public static final String DARK_MODE = "night-mode"; +// public static final String USE_CUSTOM_COLOR_THEME = "use-custom-color-theme"; +// public static final String SHOW_MISTAKES = "show-mistakes"; +// public static final String SHOW_ANNOTATIONS = "show-annotations"; +// public static final String ALLOW_DEFAULT_RULES = "allow-default-rules"; +// public static final String AUTO_GENERATE_CASES = "auto-generate-cases"; +// public static final String IMMEDIATE_FEEDBACK = "immediate-feedback"; +// public static final String COLOR_THEME_FILE = "color-theme-file"; +// public static final String COLOR_BLIND = "color-blind"; + + private static void addDefaultPreference(LegupPreference preference) { + defaultPreferencesMap.put(preference, preference.defaultStringValue()); + } static { - defaultPreferencesMap.put(WORK_DIRECTORY, System.getProperty("user.dir")); - defaultPreferencesMap.put(START_FULL_SCREEN, Boolean.toString(false)); - defaultPreferencesMap.put(AUTO_UPDATE, Boolean.toString(true)); - defaultPreferencesMap.put(DARK_MODE, Boolean.toString(false)); - defaultPreferencesMap.put(SHOW_MISTAKES, Boolean.toString(true)); - defaultPreferencesMap.put(SHOW_ANNOTATIONS, Boolean.toString(false)); - defaultPreferencesMap.put(ALLOW_DEFAULT_RULES, Boolean.toString(false)); - defaultPreferencesMap.put(AUTO_GENERATE_CASES, Boolean.toString(true)); - defaultPreferencesMap.put(IMMEDIATE_FEEDBACK, Boolean.toString(true)); - defaultPreferencesMap.put(COLOR_BLIND, Boolean.toString(false)); - defaultPreferencesMap.put(COLOR_THEME_FILE, System.getProperty("user.dir") + File.separator + ColorPreferences.LIGHT_COLOR_THEME_FILE_NAME); + for (final LegupPreference preference : LegupPreference.values()) { + addDefaultPreference(preference); + } +// defaultPreferencesMap.put(WORK_DIRECTORY, System.getProperty("user.dir")); +// defaultPreferencesMap.put(START_FULL_SCREEN, Boolean.toString(false)); +// defaultPreferencesMap.put(AUTO_UPDATE, Boolean.toString(true)); +// defaultPreferencesMap.put(DARK_MODE, Boolean.toString(false)); +// defaultPreferencesMap.put(USE_CUSTOM_COLOR_THEME, Boolean.toString(false)); +// defaultPreferencesMap.put(SHOW_MISTAKES, Boolean.toString(true)); +// defaultPreferencesMap.put(SHOW_ANNOTATIONS, Boolean.toString(false)); +// defaultPreferencesMap.put(ALLOW_DEFAULT_RULES, Boolean.toString(false)); +// defaultPreferencesMap.put(AUTO_GENERATE_CASES, Boolean.toString(true)); +// defaultPreferencesMap.put(IMMEDIATE_FEEDBACK, Boolean.toString(true)); +// defaultPreferencesMap.put(COLOR_BLIND, Boolean.toString(false)); +// defaultPreferencesMap.put(COLOR_THEME_FILE, System.getProperty("user.dir") + File.separator + ColorPreferences.LIGHT_COLOR_THEME_FILE_NAME); + } + + private static Object getPreferenceOrDefault(LegupPreference preference) { + final String current = preferences.get(preference.id(), null); + if (current == null) { + return preference.defaultValue; + } + return current; + } + + private static void addPreferenceFromDefault(LegupPreference preference) { + preferencesMap.put(preference, getPreferenceOrDefault(preference)); } static { - preferencesMap.put( - WORK_DIRECTORY, - preferences.get(WORK_DIRECTORY, defaultPreferencesMap.get(WORK_DIRECTORY))); - preferencesMap.put( - START_FULL_SCREEN, - preferences.get(START_FULL_SCREEN, defaultPreferencesMap.get(START_FULL_SCREEN))); - preferencesMap.put( - AUTO_UPDATE, preferences.get(AUTO_UPDATE, defaultPreferencesMap.get(AUTO_UPDATE))); - preferencesMap.put( - DARK_MODE, preferences.get(DARK_MODE, defaultPreferencesMap.get(DARK_MODE))); - preferencesMap.put( - SHOW_MISTAKES, - preferences.get(SHOW_MISTAKES, defaultPreferencesMap.get(SHOW_MISTAKES))); - preferencesMap.put( - SHOW_ANNOTATIONS, - preferences.get(SHOW_ANNOTATIONS, defaultPreferencesMap.get(SHOW_ANNOTATIONS))); - preferencesMap.put( - ALLOW_DEFAULT_RULES, - preferences.get( - ALLOW_DEFAULT_RULES, defaultPreferencesMap.get(ALLOW_DEFAULT_RULES))); - preferencesMap.put( - AUTO_GENERATE_CASES, - preferences.get( - AUTO_GENERATE_CASES, defaultPreferencesMap.get(AUTO_GENERATE_CASES))); - preferencesMap.put( - IMMEDIATE_FEEDBACK, - preferences.get(IMMEDIATE_FEEDBACK, defaultPreferencesMap.get(IMMEDIATE_FEEDBACK))); - preferencesMap.put( - COLOR_BLIND, preferences.get(COLOR_BLIND, defaultPreferencesMap.get(COLOR_BLIND))); - preferencesMap.put(COLOR_THEME_FILE, preferences.get(COLOR_THEME_FILE, defaultPreferencesMap.get(COLOR_THEME_FILE))); + for (final LegupPreference preference : LegupPreference.values()) { + addPreferenceFromDefault(preference); + } +// preferencesMap.put( +// WORK_DIRECTORY, +// preferences.get(WORK_DIRECTORY, defaultPreferencesMap.get(WORK_DIRECTORY))); +// preferencesMap.put( +// START_FULL_SCREEN, +// preferences.get(START_FULL_SCREEN, defaultPreferencesMap.get(START_FULL_SCREEN))); +// preferencesMap.put( +// AUTO_UPDATE, preferences.get(AUTO_UPDATE, defaultPreferencesMap.get(AUTO_UPDATE))); +// preferencesMap.put( +// DARK_MODE, preferences.get(DARK_MODE, defaultPreferencesMap.get(DARK_MODE))); +// preferencesMap.put( +// SHOW_MISTAKES, +// preferences.get(SHOW_MISTAKES, defaultPreferencesMap.get(SHOW_MISTAKES))); +// preferencesMap.put( +// SHOW_ANNOTATIONS, +// preferences.get(SHOW_ANNOTATIONS, defaultPreferencesMap.get(SHOW_ANNOTATIONS))); +// preferencesMap.put( +// ALLOW_DEFAULT_RULES, +// preferences.get( +// ALLOW_DEFAULT_RULES, defaultPreferencesMap.get(ALLOW_DEFAULT_RULES))); +// preferencesMap.put( +// AUTO_GENERATE_CASES, +// preferences.get( +// AUTO_GENERATE_CASES, defaultPreferencesMap.get(AUTO_GENERATE_CASES))); +// preferencesMap.put( +// IMMEDIATE_FEEDBACK, +// preferences.get(IMMEDIATE_FEEDBACK, defaultPreferencesMap.get(IMMEDIATE_FEEDBACK))); +// preferencesMap.put( +// COLOR_BLIND, preferences.get(COLOR_BLIND, defaultPreferencesMap.get(COLOR_BLIND))); +// preferencesMap.put(COLOR_THEME_FILE, preferences.get(COLOR_THEME_FILE, defaultPreferencesMap.get(COLOR_THEME_FILE))); } /** @@ -90,40 +204,46 @@ public static LegupPreferences getInstance() { return instance; } - /** Private LegupPreferences Singleton Constructor */ - private LegupPreferences() {} + /** + * Private LegupPreferences Singleton Constructor + */ + private LegupPreferences() { + } /** * Gets the user preference by the string key * - * @param key key name of the preference + * @param preference the preference to get * @return value of the preference */ - public String getUserPref(String key) { - return preferencesMap.get(key); + private Object getUserPref(LegupPreference preference) { + return preferencesMap.get(preference); } /** * Gets the user preference by the string key, value pair * - * @param key key name of the preference - * @param value value of the preference + * @param preference the preference to change + * @param value value of the preference */ - public void setUserPref(String key, String value) { - preferences.put(key, value); - preferencesMap.put(key, value); - } - - public boolean getUserPrefAsBool(String key) { - if (preferencesMap.get(key).equalsIgnoreCase(Boolean.toString(true))) { - return true; - } else { - if (preferencesMap.get(key).equalsIgnoreCase(Boolean.toString(false))) { - return false; - } else { - throw new RuntimeException("Cannot get user preference - " + key); - } - } + public void setUserPref(LegupPreference preference, Object value) { + preferences.put(preference.id(), preference.convertToString(value)); + preferencesMap.put(preference, value); + } + + public boolean getUserPrefAsBool(LegupPreference preference) { + return preference.asBoolean("Cannot get user preference - " + preference.id()); +// if (preferencesMap.get(preference).equalsIgnoreCase(Boolean.toString(true))) { +// return true; +// } +// else { +// if (preferencesMap.get(preference).equalsIgnoreCase(Boolean.toString(false))) { +// return false; +// } +// else { +// throw new RuntimeException("Cannot get user preference - " + preference.id()); +// } +// } } public String getSavedPath() { @@ -133,4 +253,44 @@ public String getSavedPath() { public void setSavedPath(String path) { savedPath = path; } + + public static boolean colorBlind() { + return LegupPreference.COLOR_BLIND.asBoolean(); + } + + public static boolean darkMode() { + return LegupPreference.DARK_MODE.asBoolean(); + } + + public static boolean showAnnotations() { + return LegupPreference.SHOW_ANNOTATIONS.asBoolean(); + } + + public static boolean allowDefaultRules() { + return LegupPreference.ALLOW_DEFAULT_RULES.asBoolean(); + } + + public static String workDirectory() { + return LegupPreference.WORK_DIRECTORY.stringValue(); + } + + public static boolean startFullScreen() { + return LegupPreference.START_FULL_SCREEN.asBoolean(); + } + + public static boolean autoUpdate() { + return LegupPreference.AUTO_UPDATE.asBoolean(); + } + + public static boolean showMistakes() { + return LegupPreference.SHOW_MISTAKES.asBoolean(); + } + + public static boolean autoGenerateCases() { + return LegupPreference.AUTO_GENERATE_CASES.asBoolean(); + } + + public static boolean immediateFeedback() { + return LegupPreference.IMMEDIATE_FEEDBACK.asBoolean(); + } } diff --git a/src/main/java/edu/rpi/legup/controller/ElementController.java b/src/main/java/edu/rpi/legup/controller/ElementController.java index 5840650e1..374d0932b 100644 --- a/src/main/java/edu/rpi/legup/controller/ElementController.java +++ b/src/main/java/edu/rpi/legup/controller/ElementController.java @@ -175,7 +175,7 @@ public void mouseEntered(MouseEvent e) { String error = null; if (elementView != null) { selection.newHover(elementView); - if (LegupPreferences.getInstance().getUserPrefAsBool(LegupPreferences.SHOW_MISTAKES)) { + if (LegupPreferences.LegupPreference.SHOW_MISTAKES.asBoolean()) { PuzzleElement element = elementView.getPuzzleElement(); if (treeElement != null && treeElement.getType() == TreeElementType.TRANSITION @@ -249,7 +249,7 @@ public void mouseMoved(MouseEvent e) { String error = null; if (elementView != null && elementView != selection.getHover()) { selection.newHover(elementView); - if (LegupPreferences.getInstance().getUserPrefAsBool(LegupPreferences.SHOW_MISTAKES)) { + if (LegupPreferences.LegupPreference.SHOW_MISTAKES.asBoolean()) { PuzzleElement element = elementView.getPuzzleElement(); if (treeElement != null && treeElement.getType() == TreeElementType.TRANSITION diff --git a/src/main/java/edu/rpi/legup/controller/RuleController.java b/src/main/java/edu/rpi/legup/controller/RuleController.java index 6e88dc4be..2981fc8da 100644 --- a/src/main/java/edu/rpi/legup/controller/RuleController.java +++ b/src/main/java/edu/rpi/legup/controller/RuleController.java @@ -1,21 +1,26 @@ package edu.rpi.legup.controller; -import static edu.rpi.legup.app.GameBoardFacade.getInstance; - import edu.rpi.legup.app.GameBoardFacade; import edu.rpi.legup.app.LegupPreferences; import edu.rpi.legup.history.*; import edu.rpi.legup.model.Puzzle; import edu.rpi.legup.model.gameboard.CaseBoard; import edu.rpi.legup.model.rules.*; -import edu.rpi.legup.model.tree.*; +import edu.rpi.legup.model.tree.TreeElement; +import edu.rpi.legup.model.tree.TreeElementType; import edu.rpi.legup.ui.proofeditorui.rulesview.RuleButton; import edu.rpi.legup.ui.proofeditorui.rulesview.RulePanel; -import edu.rpi.legup.ui.proofeditorui.treeview.*; +import edu.rpi.legup.ui.proofeditorui.treeview.TreeElementView; +import edu.rpi.legup.ui.proofeditorui.treeview.TreePanel; +import edu.rpi.legup.ui.proofeditorui.treeview.TreeView; +import edu.rpi.legup.ui.proofeditorui.treeview.TreeViewSelection; + import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.List; +import static edu.rpi.legup.app.GameBoardFacade.getInstance; + public class RuleController implements ActionListener { protected Object lastSource; @@ -50,48 +55,54 @@ public void buttonPressed(Rule rule) { if (caseRuleCommand.canExecute()) { caseRuleCommand.execute(); getInstance().getHistory().pushChange(caseRuleCommand); - } else { + } + else { updateErrorString = caseRuleCommand.getError(); } - } else { - if (LegupPreferences.getInstance() - .getUserPref(LegupPreferences.AUTO_GENERATE_CASES) - .equalsIgnoreCase(Boolean.toString(true))) { + } + else { + if (LegupPreferences.LegupPreference.AUTO_GENERATE_CASES.asBoolean()) { CaseBoard caseBoard = caseRule.getCaseBoard(element.getBoard()); if (caseBoard != null && caseBoard.getCount() > 0) { puzzle.notifyBoardListeners( listener -> listener.onCaseBoardAdded(caseBoard)); - } else { + } + else { updateErrorString = "This board cannot be applied with this case rule."; } - } else { + } + else { updateErrorString = "Auto generated case rules are turned off in preferences."; } } - } else { + } + else { ICommand caseRuleCommand = new ValidateCaseRuleCommand(selection, caseRule); if (caseRuleCommand.canExecute()) { caseRuleCommand.execute(); getInstance().getHistory().pushChange(caseRuleCommand); - } else { + } + else { updateErrorString = caseRuleCommand.getError(); } } - } else { + } + else { if (rule.getRuleType() == RuleType.CONTRADICTION) { ICommand validate = new ValidateContradictionRuleCommand(selection, (ContradictionRule) rule); if (validate.canExecute()) { getInstance().getHistory().pushChange(validate); validate.execute(); - } else { + } + else { updateErrorString = validate.getError(); } - } else { + } + else { boolean def = - LegupPreferences.getInstance() - .getUserPrefAsBool(LegupPreferences.ALLOW_DEFAULT_RULES); + LegupPreferences.allowDefaultRules(); ICommand validate = def ? new ApplyDefaultDirectRuleCommand(selection, (DirectRule) rule) @@ -99,7 +110,8 @@ public void buttonPressed(Rule rule) { if (validate.canExecute()) { getInstance().getHistory().pushChange(validate); validate.execute(); - } else { + } + else { updateErrorString = validate.getError(); } } diff --git a/src/main/java/edu/rpi/legup/model/rules/Rule.java b/src/main/java/edu/rpi/legup/model/rules/Rule.java index f70bb2889..1e520fc05 100644 --- a/src/main/java/edu/rpi/legup/model/rules/Rule.java +++ b/src/main/java/edu/rpi/legup/model/rules/Rule.java @@ -83,7 +83,7 @@ public void loadImage() { String name = imageName; LegupPreferences prefs = LegupPreferences.getInstance(); if (name.contains("shorttruthtable") - && prefs.getUserPref(LegupPreferences.COLOR_BLIND).equals("true")) { + && LegupPreferences.colorBlind()) { name = name.replace("ruleimages", "ruleimages_cb"); } this.image = new ImageIcon(ClassLoader.getSystemClassLoader().getResource(name)); diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableElementView.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableElementView.java index 43e1d2299..26d5ac5a1 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableElementView.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableElementView.java @@ -47,14 +47,14 @@ public void drawElement(Graphics2D graphics2D) { LegupPreferences prefs = LegupPreferences.getInstance(); switch (type) { case TRUE: - if (prefs.getUserPref(LegupPreferences.COLOR_BLIND).equals("true")) { + if (LegupPreferences.colorBlind()) { graphics2D.setColor(TRUE_COLOR_COLORBLIND); break; } graphics2D.setColor(TRUE_COLOR); break; case FALSE: - if (prefs.getUserPref(LegupPreferences.COLOR_BLIND).equals("true")) { + if (LegupPreferences.colorBlind()) { graphics2D.setColor(FALSE_COLOR_COLORBLIND); break; } diff --git a/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuElementView.java b/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuElementView.java index c3d236b53..02c9c9db1 100644 --- a/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuElementView.java +++ b/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuElementView.java @@ -53,10 +53,7 @@ public void drawElement(Graphics2D graphics2D) { location.y + ((size.height - metrics.getHeight()) / 2) + metrics.getAscent(); graphics2D.drawString(value, xText, yText); } else { - boolean annotate = - LegupPreferences.getInstance() - .getUserPref(LegupPreferences.SHOW_ANNOTATIONS) - .equalsIgnoreCase(Boolean.toString(true)); + boolean annotate = LegupPreferences.showAnnotations(); if (annotate) { graphics2D.setColor(FONT_COLOR); graphics2D.setFont(ANNOTATE_FONT); diff --git a/src/main/java/edu/rpi/legup/ui/HomePanel.java b/src/main/java/edu/rpi/legup/ui/HomePanel.java index 8c09cc97a..b6c608b09 100644 --- a/src/main/java/edu/rpi/legup/ui/HomePanel.java +++ b/src/main/java/edu/rpi/legup/ui/HomePanel.java @@ -206,7 +206,7 @@ public void checkFolder() { JFileChooser folderBrowser = new JFileChooser(); - folderBrowser.setCurrentDirectory(new File(LegupPreferences.WORK_DIRECTORY)); + folderBrowser.setCurrentDirectory(new File(LegupPreferences.workDirectory())); folderBrowser.setDialogTitle("Select Directory"); folderBrowser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); folderBrowser.setAcceptAllFileFilterUsed(false); @@ -283,7 +283,7 @@ public void checkFolder() { private void use_xml_to_check() { /* Select a folder, go through each .xml file in the subfolders, look for "isSolved" flag */ JFileChooser folderBrowser = new JFileChooser(); - folderBrowser.setCurrentDirectory(new File(LegupPreferences.WORK_DIRECTORY)); + folderBrowser.setCurrentDirectory(new File(LegupPreferences.workDirectory())); folderBrowser.setDialogTitle("Select Directory"); folderBrowser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); folderBrowser.setAcceptAllFileFilterUsed(false); @@ -544,12 +544,12 @@ private void checkProofAll() { LegupPreferences preferences = LegupPreferences.getInstance(); File preferredDirectory = - new File(preferences.getUserPref(LegupPreferences.WORK_DIRECTORY)); + new File(LegupPreferences.workDirectory()); folderBrowser = new JFileChooser(preferredDirectory); folderBrowser.showOpenDialog(this); folderBrowser.setVisible(true); - folderBrowser.setCurrentDirectory(new File(LegupPreferences.WORK_DIRECTORY)); + folderBrowser.setCurrentDirectory(new File(LegupPreferences.workDirectory())); folderBrowser.setDialogTitle("Select Directory"); folderBrowser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); folderBrowser.setAcceptAllFileFilterUsed(false); diff --git a/src/main/java/edu/rpi/legup/ui/LegupUI.java b/src/main/java/edu/rpi/legup/ui/LegupUI.java index c09c85e4d..e153a5db5 100644 --- a/src/main/java/edu/rpi/legup/ui/LegupUI.java +++ b/src/main/java/edu/rpi/legup/ui/LegupUI.java @@ -47,11 +47,11 @@ public LegupUI() { LegupPreferences prefs = LegupPreferences.getInstance(); try { - final String colorFileName = prefs.getUserPref(LegupPreferences.COLOR_THEME_FILE); + final String colorFileName = LegupPreferences.LegupPreference.COLOR_THEME_FILE.stringValue(); if (colorFileName.endsWith(".txt")) { UIManager.setLookAndFeel(new LegupLookAndFeel(colorFileName)); }else { - if (Boolean.valueOf(prefs.getUserPref(LegupPreferences.DARK_MODE))) { + if (LegupPreferences.LegupPreference.DARK_MODE.asBoolean()) { UIManager.setLookAndFeel(new LegupLookAndFeel(ColorPreferences.DARK_COLOR_THEME_FILE_NAME)); } else { @@ -64,7 +64,7 @@ public LegupUI() { // fileDialog = new FileDialog(this); fileChooser = new JFileChooser(); - fileChooser.setCurrentDirectory(new File(LegupPreferences.WORK_DIRECTORY)); + fileChooser.setCurrentDirectory(new File(LegupPreferences.LegupPreference.WORK_DIRECTORY.defaultStringValue())); initPanels(); displayPanel(0); @@ -78,9 +78,7 @@ public LegupUI() { + " Rules.gif"))) .getImage()); - if (LegupPreferences.getInstance() - .getUserPref(LegupPreferences.START_FULL_SCREEN) - .equals(Boolean.toString(true))) { + if (LegupPreferences.LegupPreference.START_FULL_SCREEN.asBoolean()) { setExtendedState(getExtendedState() | JFrame.MAXIMIZED_BOTH); } diff --git a/src/main/java/edu/rpi/legup/ui/PreferencesDialog.java b/src/main/java/edu/rpi/legup/ui/PreferencesDialog.java index 7f7b84ee4..12abc0f45 100644 --- a/src/main/java/edu/rpi/legup/ui/PreferencesDialog.java +++ b/src/main/java/edu/rpi/legup/ui/PreferencesDialog.java @@ -9,14 +9,18 @@ import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialBorders; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialFonts; import edu.rpi.legup.ui.proofeditorui.rulesview.RuleFrame; + +import javax.imageio.ImageIO; +import javax.swing.*; import java.awt.*; -import java.awt.event.*; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; import java.io.File; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; -import javax.imageio.ImageIO; -import javax.swing.*; public class PreferencesDialog extends JDialog { @@ -44,7 +48,8 @@ public class PreferencesDialog extends JDialog { folderIcon = ImageIO.read( PreferencesDialog.class.getResource("/edu/rpi/legup/imgs/folder.png")); - } catch (IOException e) { + } + catch (IOException e) { LOGGER.log(Level.SEVERE, "Unable to locate icons"); } } @@ -106,13 +111,15 @@ public PreferencesDialog(Frame frame) { private void toggleDarkMode(LegupPreferences prefs) { try { - if (Boolean.valueOf(prefs.getUserPref(LegupPreferences.DARK_MODE))) { + if (LegupPreferences.darkMode()) { UIManager.setLookAndFeel(new FlatDarkLaf()); - } else { + } + else { UIManager.setLookAndFeel(new FlatLightLaf()); } com.formdev.flatlaf.FlatLaf.updateUI(); - } catch (UnsupportedLookAndFeelException e) { + } + catch (UnsupportedLookAndFeelException e) { System.err.println("Not supported ui look and feel"); } } @@ -131,7 +138,7 @@ private JScrollPane createGeneralTab() { JLabel workDirLabel = new JLabel("Work Directory"); workDirLabel.setToolTipText("This is where the open and save dialogs will open to."); workRow.add(workDirLabel, BorderLayout.WEST); - workDirectory = new JTextField(prefs.getUserPref(LegupPreferences.WORK_DIRECTORY)); + workDirectory = new JTextField(LegupPreferences.workDirectory()); workRow.add(workDirectory, BorderLayout.CENTER); JButton openDir = new JButton(new ImageIcon(folderIcon)); openDir.addActionListener( @@ -155,7 +162,7 @@ private JScrollPane createGeneralTab() { fullScreen = new JCheckBox( "Full Screen", - Boolean.valueOf(prefs.getUserPref(LegupPreferences.START_FULL_SCREEN))); + LegupPreferences.startFullScreen()); fullScreen.setToolTipText("If checked this starts Legup in full screen."); JPanel fullScreenRow = new JPanel(); fullScreenRow.setLayout(new BorderLayout()); @@ -167,7 +174,7 @@ private JScrollPane createGeneralTab() { autoUpdate = new JCheckBox( "Automatically Check for Updates", - Boolean.valueOf(prefs.getUserPref(LegupPreferences.AUTO_UPDATE))); + LegupPreferences.autoUpdate()); autoUpdate.setToolTipText( "If checked this automatically checks for updates on startup of Legup"); JPanel autoUpdateRow = new JPanel(); @@ -181,7 +188,7 @@ private JScrollPane createGeneralTab() { darkMode = new JCheckBox( "Dark Mode", - Boolean.valueOf(prefs.getUserPref(LegupPreferences.DARK_MODE))); + LegupPreferences.darkMode()); darkMode.setToolTipText("This turns dark mode on and off"); JPanel darkModeRow = new JPanel(); darkModeRow.setLayout(new BorderLayout()); @@ -196,7 +203,7 @@ private JScrollPane createGeneralTab() { showMistakes = new JCheckBox( "Show Mistakes", - Boolean.valueOf(prefs.getUserPref(LegupPreferences.SHOW_MISTAKES))); + LegupPreferences.showMistakes()); showMistakes.setToolTipText( "If checked this show incorrectly applied rule applications in red on the board"); JPanel showMistakesRow = new JPanel(); @@ -209,7 +216,7 @@ private JScrollPane createGeneralTab() { showAnnotations = new JCheckBox( "Show Annotations", - Boolean.valueOf(prefs.getUserPref(LegupPreferences.SHOW_ANNOTATIONS))); + LegupPreferences.showAnnotations()); showAnnotations.setToolTipText( "If checked this show incorrectly applied rule applications in red on the board"); JPanel showAnnotationsRow = new JPanel(); @@ -226,7 +233,7 @@ private JScrollPane createGeneralTab() { allowDefault = new JCheckBox( "Allow Default Rule Applications", - Boolean.valueOf(prefs.getUserPref(LegupPreferences.ALLOW_DEFAULT_RULES))); + LegupPreferences.allowDefaultRules()); allowDefault.setEnabled(false); allowDefault.setToolTipText( "If checked this automatically applies a rule where it can on the board"); @@ -241,7 +248,7 @@ private JScrollPane createGeneralTab() { generateCases = new JCheckBox( "Automatically Generate Cases", - Boolean.valueOf(prefs.getUserPref(LegupPreferences.AUTO_GENERATE_CASES))); + LegupPreferences.autoGenerateCases()); generateCases.setToolTipText( "If checked this automatically generates all cases for a case rule"); JPanel generateCasesRow = new JPanel(); @@ -255,7 +262,7 @@ private JScrollPane createGeneralTab() { immFeedback = new JCheckBox( "Provide Immediate Feedback", - Boolean.valueOf(prefs.getUserPref(LegupPreferences.IMMEDIATE_FEEDBACK))); + LegupPreferences.immediateFeedback()); immFeedback.setToolTipText( "If checked this will update the colors of the tree view elements immediately"); JPanel immFeedbackRow = new JPanel(); @@ -270,7 +277,7 @@ private JScrollPane createGeneralTab() { immFeedback = new JCheckBox( "Instructor Mode", - Boolean.valueOf(prefs.getUserPref(LegupPreferences.IMMEDIATE_FEEDBACK))); + LegupPreferences.immediateFeedback()); immFeedback.setToolTipText("Currently unimplemented, this does nothing right now"); immFeedbackRow.setLayout(new BorderLayout()); immFeedbackRow.add(immFeedback, BorderLayout.WEST); @@ -283,7 +290,7 @@ private JScrollPane createGeneralTab() { colorBlind = new JCheckBox( "Deuteranomaly(red/green colorblindness)", - Boolean.valueOf(prefs.getUserPref(LegupPreferences.COLOR_BLIND))); + LegupPreferences.colorBlind()); JPanel colorBlindRow = new JPanel(); colorBlindRow.setLayout(new BorderLayout()); @@ -297,7 +304,7 @@ private JScrollPane createGeneralTab() { JLabel colorThemeDirLabel = new JLabel("Color Theme File"); colorThemeDirLabel.setToolTipText("This is the color theme LEGUP will use."); colorThemeRow.add(colorThemeDirLabel, BorderLayout.WEST); - colorThemeFile = new JTextField(prefs.getUserPref(LegupPreferences.WORK_DIRECTORY) + "/" + ColorPreferences.LIGHT_COLOR_THEME_FILE_NAME); + colorThemeFile = new JTextField(LegupPreferences.workDirectory() + "/" + ColorPreferences.LIGHT_COLOR_THEME_FILE_NAME); colorThemeRow.add(colorThemeFile, BorderLayout.CENTER); JButton openColorThemeFile = new JButton(new ImageIcon(folderIcon)); openColorThemeFile.addActionListener( @@ -391,10 +398,12 @@ public void keyPressed(KeyEvent e) { String combo = ""; if (e.isControlDown()) { combo += "Ctrl + "; - } else { + } + else { if (e.isShiftDown()) { combo += "Shift + "; - } else { + } + else { if (e.isAltDown()) { combo += "Alt + "; } @@ -437,23 +446,23 @@ private JSeparator createLineSeparator() { public void applyPreferences() { LegupPreferences prefs = LegupPreferences.getInstance(); - prefs.setUserPref(LegupPreferences.WORK_DIRECTORY, workDirectory.getText()); + prefs.setUserPref(LegupPreferences.LegupPreference.WORK_DIRECTORY, workDirectory.getText()); prefs.setUserPref( - LegupPreferences.START_FULL_SCREEN, Boolean.toString(fullScreen.isSelected())); - prefs.setUserPref(LegupPreferences.AUTO_UPDATE, Boolean.toString(autoUpdate.isSelected())); - prefs.setUserPref(LegupPreferences.DARK_MODE, Boolean.toString(darkMode.isSelected())); + LegupPreferences.LegupPreference.START_FULL_SCREEN, fullScreen.isSelected()); + prefs.setUserPref(LegupPreferences.LegupPreference.AUTO_UPDATE, autoUpdate.isSelected()); + prefs.setUserPref(LegupPreferences.LegupPreference.DARK_MODE, darkMode.isSelected()); prefs.setUserPref( - LegupPreferences.SHOW_MISTAKES, Boolean.toString(showMistakes.isSelected())); + LegupPreferences.LegupPreference.SHOW_MISTAKES, showMistakes.isSelected()); prefs.setUserPref( - LegupPreferences.SHOW_ANNOTATIONS, Boolean.toString(showAnnotations.isSelected())); + LegupPreferences.LegupPreference.SHOW_ANNOTATIONS, showAnnotations.isSelected()); prefs.setUserPref( - LegupPreferences.ALLOW_DEFAULT_RULES, Boolean.toString(allowDefault.isSelected())); + LegupPreferences.LegupPreference.ALLOW_DEFAULT_RULES, allowDefault.isSelected()); prefs.setUserPref( - LegupPreferences.AUTO_GENERATE_CASES, Boolean.toString(generateCases.isSelected())); + LegupPreferences.LegupPreference.AUTO_GENERATE_CASES, generateCases.isSelected()); prefs.setUserPref( - LegupPreferences.IMMEDIATE_FEEDBACK, Boolean.toString(immFeedback.isSelected())); - prefs.setUserPref(LegupPreferences.COLOR_BLIND, Boolean.toString(colorBlind.isSelected())); - prefs.setUserPref(LegupPreferences.COLOR_THEME_FILE, colorThemeFile.getText()); + LegupPreferences.LegupPreference.IMMEDIATE_FEEDBACK, immFeedback.isSelected()); + prefs.setUserPref(LegupPreferences.LegupPreference.COLOR_BLIND, colorBlind.isSelected()); + prefs.setUserPref(LegupPreferences.LegupPreference.COLOR_THEME_FILE, colorThemeFile.getText()); if (rulesFrame != null) { rulesFrame.getCasePanel().updateRules(); diff --git a/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java b/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java index b9b3284e2..8773bef4c 100644 --- a/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java +++ b/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java @@ -19,6 +19,11 @@ import edu.rpi.legup.ui.proofeditorui.treeview.TreePanel; import edu.rpi.legup.ui.proofeditorui.treeview.TreeViewSelection; import edu.rpi.legup.user.Submission; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import javax.swing.*; +import javax.swing.border.TitledBorder; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -32,10 +37,6 @@ import java.nio.file.Path; import java.util.List; import java.util.Objects; -import javax.swing.*; -import javax.swing.border.TitledBorder; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; public class ProofEditorPanel extends LegupPanel implements IHistoryListener { private static final Logger LOGGER = LogManager.getLogger(ProofEditorPanel.class.getName()); @@ -84,22 +85,22 @@ public class ProofEditorPanel extends LegupPanel implements IHistoryListener { public static final int AUTO_JUST = 128; static final int[] TOOLBAR_SEPARATOR_BEFORE = {2, 4, 8}; private static final String[] PROFILES = { - "No Assistance", - "Rigorous Proof", - "Casual Proof", - "Assisted Proof", - "Guided Proof", - "Training-Wheels Proof", - "No Restrictions" + "No Assistance", + "Rigorous Proof", + "Casual Proof", + "Assisted Proof", + "Guided Proof", + "Training-Wheels Proof", + "No Restrictions" }; private static final int[] PROF_FLAGS = { - 0, - ALLOW_JUST | REQ_STEP_JUST, - ALLOW_JUST, - ALLOW_HINTS | ALLOW_JUST | AUTO_JUST, - ALLOW_HINTS | ALLOW_JUST | REQ_STEP_JUST, - ALLOW_HINTS | ALLOW_DEFAPP | ALLOW_JUST | IMD_FEEDBACK | INTERN_RO, - ALLOW_HINTS | ALLOW_DEFAPP | ALLOW_FULLAI | ALLOW_JUST + 0, + ALLOW_JUST | REQ_STEP_JUST, + ALLOW_JUST, + ALLOW_HINTS | ALLOW_JUST | AUTO_JUST, + ALLOW_HINTS | ALLOW_JUST | REQ_STEP_JUST, + ALLOW_HINTS | ALLOW_DEFAPP | ALLOW_JUST | IMD_FEEDBACK | INTERN_RO, + ALLOW_HINTS | ALLOW_DEFAPP | ALLOW_FULLAI | ALLOW_JUST }; private JMenu proofMode = new JMenu("Proof Mode"); private JCheckBoxMenuItem[] proofModeItems = new JCheckBoxMenuItem[PROF_FLAGS.length]; @@ -163,7 +164,8 @@ public JMenuBar getMenuBar() { add.setAccelerator( KeyStroke.getKeyStroke( 'A', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); - } else { + } + else { add.setAccelerator(KeyStroke.getKeyStroke('A', InputEvent.CTRL_DOWN_MASK)); } proof.add(add); @@ -174,7 +176,8 @@ public JMenuBar getMenuBar() { delete.setAccelerator( KeyStroke.getKeyStroke( 'D', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); - } else { + } + else { delete.setAccelerator(KeyStroke.getKeyStroke('D', InputEvent.CTRL_DOWN_MASK)); } proof.add(delete); @@ -185,7 +188,8 @@ public JMenuBar getMenuBar() { merge.setAccelerator( KeyStroke.getKeyStroke( 'M', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); - } else { + } + else { merge.setAccelerator(KeyStroke.getKeyStroke('M', InputEvent.CTRL_DOWN_MASK)); } proof.add(merge); @@ -196,7 +200,8 @@ public JMenuBar getMenuBar() { collapse.setAccelerator( KeyStroke.getKeyStroke( 'C', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); - } else { + } + else { collapse.setAccelerator(KeyStroke.getKeyStroke('C', InputEvent.CTRL_DOWN_MASK)); } collapse.setEnabled(false); @@ -205,45 +210,39 @@ public JMenuBar getMenuBar() { allowDefault = new JCheckBoxMenuItem( "Allow Default Rule Applications", - LegupPreferences.getInstance() - .getUserPref(LegupPreferences.ALLOW_DEFAULT_RULES) - .equalsIgnoreCase(Boolean.toString(true))); + LegupPreferences.LegupPreference.ALLOW_DEFAULT_RULES.asBoolean()); allowDefault.addChangeListener( e -> { LegupPreferences.getInstance() .setUserPref( - LegupPreferences.ALLOW_DEFAULT_RULES, - Boolean.toString(allowDefault.isSelected())); + LegupPreferences.LegupPreference.ALLOW_DEFAULT_RULES, + allowDefault.isSelected()); }); proof.add(allowDefault); caseRuleGen = new JCheckBoxMenuItem( "Automatically generate cases for CaseRule", - LegupPreferences.getInstance() - .getUserPref(LegupPreferences.AUTO_GENERATE_CASES) - .equalsIgnoreCase(Boolean.toString(true))); + LegupPreferences.LegupPreference.AUTO_GENERATE_CASES.asBoolean()); caseRuleGen.addChangeListener( e -> { LegupPreferences.getInstance() .setUserPref( - LegupPreferences.AUTO_GENERATE_CASES, - Boolean.toString(caseRuleGen.isSelected())); + LegupPreferences.LegupPreference.AUTO_GENERATE_CASES, + caseRuleGen.isSelected()); }); proof.add(caseRuleGen); imdFeedback = new JCheckBoxMenuItem( "Provide immediate feedback", - LegupPreferences.getInstance() - .getUserPref(LegupPreferences.IMMEDIATE_FEEDBACK) - .equalsIgnoreCase(Boolean.toString(true))); + LegupPreferences.LegupPreference.IMMEDIATE_FEEDBACK.asBoolean()); imdFeedback.addChangeListener( e -> { LegupPreferences.getInstance() .setUserPref( - LegupPreferences.IMMEDIATE_FEEDBACK, - Boolean.toString(imdFeedback.isSelected())); + LegupPreferences.LegupPreference.IMMEDIATE_FEEDBACK, + imdFeedback.isSelected()); }); proof.add(imdFeedback); @@ -258,7 +257,8 @@ public JMenuBar getMenuBar() { newPuzzle.setAccelerator( KeyStroke.getKeyStroke( 'N', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); - } else { + } + else { newPuzzle.setAccelerator(KeyStroke.getKeyStroke('N', InputEvent.CTRL_DOWN_MASK)); } @@ -308,7 +308,8 @@ public JMenuBar getMenuBar() { resetPuzzle.setAccelerator( KeyStroke.getKeyStroke( 'R', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); - } else { + } + else { resetPuzzle.setAccelerator(KeyStroke.getKeyStroke('R', InputEvent.CTRL_DOWN_MASK)); } file.addSeparator(); @@ -321,7 +322,8 @@ public JMenuBar getMenuBar() { saveProofAs.setAccelerator( KeyStroke.getKeyStroke( 'S', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); - } else { + } + else { saveProofAs.setAccelerator(KeyStroke.getKeyStroke('S', InputEvent.CTRL_DOWN_MASK)); } @@ -330,7 +332,8 @@ public JMenuBar getMenuBar() { saveProofChange.setAccelerator( KeyStroke.getKeyStroke( 'A', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); - } else { + } + else { saveProofChange.setAccelerator(KeyStroke.getKeyStroke('A', InputEvent.CTRL_DOWN_MASK)); } @@ -353,7 +356,8 @@ public JMenuBar getMenuBar() { helpTutorial.setAccelerator( KeyStroke.getKeyStroke( 'H', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); - } else { + } + else { helpTutorial.setAccelerator(KeyStroke.getKeyStroke('H', InputEvent.CTRL_DOWN_MASK)); } file.add(helpTutorial); @@ -368,7 +372,8 @@ public JMenuBar getMenuBar() { exit.setAccelerator( KeyStroke.getKeyStroke( 'Q', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); - } else { + } + else { exit.setAccelerator(KeyStroke.getKeyStroke('Q', InputEvent.CTRL_DOWN_MASK)); } mBar.add(edit); @@ -379,7 +384,8 @@ public JMenuBar getMenuBar() { undo.setAccelerator( KeyStroke.getKeyStroke( 'Z', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); - } else { + } + else { undo.setAccelerator(KeyStroke.getKeyStroke('Z', InputEvent.CTRL_DOWN_MASK)); } @@ -411,7 +417,8 @@ public void actionPerformed(ActionEvent e) { 'Z', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() + InputEvent.SHIFT_DOWN_MASK)); - } else { + } + else { redo.getInputMap(WHEN_IN_FOCUSED_WINDOW) .put(KeyStroke.getKeyStroke('Y', InputEvent.CTRL_DOWN_MASK), "redoAction"); redo.getInputMap(WHEN_IN_FOCUSED_WINDOW) @@ -448,7 +455,8 @@ public void actionPerformed(ActionEvent e) { try { java.awt.Desktop.getDesktop() .browse(URI.create("https://github.com/Bram-Hub/LEGUP/wiki")); - } catch (IOException e) { + } + catch (IOException e) { LOGGER.error("Can't open web page"); } }); @@ -476,7 +484,7 @@ public Object[] promptPuzzle() { } LegupPreferences preferences = LegupPreferences.getInstance(); - String preferredDirectory = preferences.getUserPref(LegupPreferences.WORK_DIRECTORY); + String preferredDirectory = LegupPreferences.LegupPreference.WORK_DIRECTORY.stringValue(); if (preferences.getSavedPath() != "") { preferredDirectory = preferences.getSavedPath(); } @@ -501,12 +509,13 @@ public Object[] promptPuzzle() { String lastDirectoryPath = fileName.substring(0, fileName.lastIndexOf(File.separator)); preferences.setSavedPath(lastDirectoryPath); puzzleFile = puzzlePath; - } else { + } + else { // The attempt to prompt a puzzle ended gracefully (cancel) return null; } - return new Object[] {fileName, puzzleFile}; + return new Object[]{fileName, puzzleFile}; } public void loadPuzzle() { @@ -527,7 +536,8 @@ public void loadPuzzle(String fileName, File puzzleFile) { GameBoardFacade.getInstance().loadPuzzle(fileName); String puzzleName = GameBoardFacade.getInstance().getPuzzleModule().getName(); frame.setTitle(puzzleName + " - " + puzzleFile.getName()); - } catch (InvalidFileFormatException e) { + } + catch (InvalidFileFormatException e) { legupUI.displayPanel(0); LOGGER.error(e.getMessage()); if (e.getMessage() @@ -543,7 +553,8 @@ public void loadPuzzle(String fileName, File puzzleFile) { "Error", JOptionPane.ERROR_MESSAGE); loadPuzzle(); - } else { + } + else { JOptionPane.showMessageDialog( null, "File does not exist or it cannot be read", @@ -555,7 +566,9 @@ public void loadPuzzle(String fileName, File puzzleFile) { } } - /** save the proof in the current file */ + /** + * save the proof in the current file + */ private void direct_save() { Puzzle puzzle = GameBoardFacade.getInstance().getPuzzleModule(); if (puzzle == null) { @@ -569,13 +582,16 @@ private void direct_save() { throw new ExportFileException("Puzzle exporter null"); } exporter.exportPuzzle(fileName); - } catch (ExportFileException e) { + } + catch (ExportFileException e) { e.printStackTrace(); } } } - /** Create a new file and save proof to it */ + /** + * Create a new file and save proof to it + */ private void saveProofAs() { Puzzle puzzle = GameBoardFacade.getInstance().getPuzzleModule(); if (puzzle == null) { @@ -590,8 +606,9 @@ private void saveProofAs() { if (curFileName == null) { fileChooser.setCurrentDirectory( // fileChooser.setDirectory( - Path.of(LegupPreferences.getInstance().getUserPref(LegupPreferences.WORK_DIRECTORY)).toFile()); - } else { + Path.of(LegupPreferences.LegupPreference.WORK_DIRECTORY.stringValue()).toFile()); + } + else { File curFile = new File(curFileName); // fileChooser.setDirectory(curFile.getParent()); fileChooser.setCurrentDirectory(curFile.getParentFile()); @@ -610,7 +627,8 @@ private void saveProofAs() { throw new ExportFileException("Puzzle exporter null"); } exporter.exportPuzzle(fileName); - } catch (ExportFileException e) { + } + catch (ExportFileException e) { e.printStackTrace(); } } @@ -648,7 +666,8 @@ private void helpTutorial() { try { // rt.exec("rundll32 url.dll,FileProtocolHandler "+url); java.awt.Desktop.getDesktop().browse(java.net.URI.create(url)); - } catch (IOException e) { + } + catch (IOException e) { e.printStackTrace(); } } @@ -687,7 +706,8 @@ private void saveProofChange() { // Save confirmation JOptionPane.showMessageDialog( null, "Successfully Saved", "Confirm", JOptionPane.INFORMATION_MESSAGE); - } catch (ExportFileException e) { + } + catch (ExportFileException e) { e.printStackTrace(); } } @@ -699,7 +719,9 @@ public boolean noquit(String instr) { return n != JOptionPane.YES_OPTION; } - /** Sets the main content for the edu.rpi.legup.user interface */ + /** + * Sets the main content for the edu.rpi.legup.user interface + */ protected void setupContent() { // JPanel consoleBox = new JPanel(new BorderLayout()); JPanel treeBox = new JPanel(new BorderLayout()); @@ -796,11 +818,14 @@ private void setupToolBar() { // GameBoardFacade.getInstance().getHistory().undo()); // toolBarButtons[ToolbarName.REDO.ordinal()].addActionListener((ActionEvent e) -> // GameBoardFacade.getInstance().getHistory().redo()); - toolBarButtons[ToolbarName.HINT.ordinal()].addActionListener((ActionEvent e) -> {}); + toolBarButtons[ToolbarName.HINT.ordinal()].addActionListener((ActionEvent e) -> { + }); toolBarButtons[ToolbarName.CHECK.ordinal()].addActionListener( (ActionEvent e) -> checkProof()); - toolBarButtons[ToolbarName.SUBMIT.ordinal()].addActionListener((ActionEvent e) -> {}); - toolBarButtons[ToolbarName.DIRECTIONS.ordinal()].addActionListener((ActionEvent e) -> {}); + toolBarButtons[ToolbarName.SUBMIT.ordinal()].addActionListener((ActionEvent e) -> { + }); + toolBarButtons[ToolbarName.DIRECTIONS.ordinal()].addActionListener((ActionEvent e) -> { + }); toolBarButtons[ToolbarName.CHECK_ALL.ordinal()].addActionListener( (ActionEvent e) -> checkProofAll()); @@ -835,7 +860,9 @@ public JButton[] getToolBarButtons() { return toolBarButtons; } - /** Checks the proof for correctness */ + /** + * Checks the proof for correctness + */ private void checkProof() { GameBoardFacade facade = GameBoardFacade.getInstance(); Tree tree = GameBoardFacade.getInstance().getTree(); @@ -855,7 +882,8 @@ private void checkProof() { submission.submit(); }*/ JOptionPane.showMessageDialog(null, "Congratulations! Your proof is correct."); - } else { + } + else { String message = "\nThe game board is not solved."; JOptionPane.showMessageDialog( null, message, "Invalid proof.", JOptionPane.ERROR_MESSAGE); @@ -904,7 +932,9 @@ public void repaintTree() { treePanel.repaintTreeView(GameBoardFacade.getInstance().getTree()); } - /** Checks the proof for all files */ + /** + * Checks the proof for all files + */ private void checkProofAll() { GameBoardFacade facade = GameBoardFacade.getInstance(); @@ -920,12 +950,12 @@ private void checkProofAll() { LegupPreferences preferences = LegupPreferences.getInstance(); File preferredDirectory = - new File(preferences.getUserPref(LegupPreferences.WORK_DIRECTORY)); + new File(LegupPreferences.LegupPreference.WORK_DIRECTORY.stringValue()); folderBrowser = new JFileChooser(preferredDirectory); folderBrowser.showOpenDialog(this); folderBrowser.setVisible(true); - folderBrowser.setCurrentDirectory(new File(LegupPreferences.WORK_DIRECTORY)); + folderBrowser.setCurrentDirectory(new File(LegupPreferences.LegupPreference.WORK_DIRECTORY.stringValue())); folderBrowser.setDialogTitle("Select Directory"); folderBrowser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); folderBrowser.setAcceptAllFileFilterUsed(false); @@ -944,7 +974,8 @@ private void checkProofAll() { String path = folderEntry.getName(); traverseDir(folderEntry, writer, path); } - } catch (IOException ex) { + } + catch (IOException ex) { LOGGER.error(ex.getMessage()); } JOptionPane.showMessageDialog(null, "Batch grading complete."); @@ -996,13 +1027,16 @@ private void traverseDir(File folder, BufferedWriter writer, String path) throws writer.append(puzzle.getName()).append(","); if (puzzle.isPuzzleComplete()) { writer.append("1,Solved\n"); - } else { + } + else { writer.append("0,Unsolved\n"); } - } catch (InvalidFileFormatException e) { + } + catch (InvalidFileFormatException e) { writer.append(fName).append(",Invalid,,Ungradeable\n"); } - } else { + } + else { LOGGER.debug("Failed to run sim"); } } @@ -1038,7 +1072,9 @@ public void onPushChange(ICommand command) { frame.setTitle(puzzleName + " - " + puzzleFile.getName() + " *"); } - /** Called when the history is cleared */ + /** + * Called when the history is cleared + */ @Override public void onClearHistory() { // undo.setEnabled(false); @@ -1051,7 +1087,7 @@ public void onClearHistory() { * Called when an action is redone * * @param isBottom true if there are no more actions to undo, false otherwise - * @param isTop true if there are no more changes to redo, false otherwise + * @param isTop true if there are no more changes to redo, false otherwise */ @Override public void onRedo(boolean isBottom, boolean isTop) { @@ -1063,7 +1099,8 @@ public void onRedo(boolean isBottom, boolean isTop) { String puzzleName = GameBoardFacade.getInstance().getPuzzleModule().getName(); File puzzleFile = new File(GameBoardFacade.getInstance().getCurFileName()); frame.setTitle(puzzleName + " - " + puzzleFile.getName()); - } else { + } + else { String puzzleName = GameBoardFacade.getInstance().getPuzzleModule().getName(); File puzzleFile = new File(GameBoardFacade.getInstance().getCurFileName()); frame.setTitle(puzzleName + " - " + puzzleFile.getName() + " *"); @@ -1074,7 +1111,7 @@ public void onRedo(boolean isBottom, boolean isTop) { * Called when an action is undone * * @param isBottom true if there are no more actions to undo, false otherwise - * @param isTop true if there are no more changes to redo, false otherwise + * @param isTop true if there are no more changes to redo, false otherwise */ @Override public void onUndo(boolean isBottom, boolean isTop) { @@ -1086,12 +1123,15 @@ public void onUndo(boolean isBottom, boolean isTop) { File puzzleFile = new File(GameBoardFacade.getInstance().getCurFileName()); if (isBottom) { frame.setTitle(puzzleName + " - " + puzzleFile.getName()); - } else { + } + else { frame.setTitle(puzzleName + " - " + puzzleFile.getName() + " *"); } } - /** Submits the proof file */ + /** + * Submits the proof file + */ private void submit() { GameBoardFacade facade = GameBoardFacade.getInstance(); Board board = facade.getBoard(); @@ -1111,7 +1151,8 @@ private void submit() { Submission submission = new Submission(board); submission.submit(); } - } else { + } + else { JOptionPane.showConfirmDialog( null, "Your proof is incorrect! Are you sure you wish to submit?", diff --git a/src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java b/src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java index 812587426..5cadc4885 100644 --- a/src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java +++ b/src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java @@ -390,7 +390,7 @@ public Object[] promptPuzzle() { fileChooser = new JFileChooser(); } LegupPreferences preferences = LegupPreferences.getInstance(); - String preferredDirectory = preferences.getUserPref(LegupPreferences.WORK_DIRECTORY); + String preferredDirectory = LegupPreferences.LegupPreference.WORK_DIRECTORY.stringValue(); // fileChooser.setMode(JFileChooser.LOAD); fileChooser.setDialogType(JFileChooser.OPEN_DIALOG); @@ -559,7 +559,7 @@ private String savePuzzle() { if (curFileName == null) { // fileChooser.setDirectory( fileChooser.setCurrentDirectory( - Path.of(LegupPreferences.getInstance().getUserPref(LegupPreferences.WORK_DIRECTORY)).toFile()); + Path.of(LegupPreferences.LegupPreference.WORK_DIRECTORY.stringValue()).toFile()); } else { File curFile = new File(curFileName); // fileChooser.setDirectory(curFile.getParent()); diff --git a/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeTransitionView.java b/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeTransitionView.java index b022ac596..ee918a00d 100644 --- a/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeTransitionView.java +++ b/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeTransitionView.java @@ -98,7 +98,7 @@ public void draw(Graphics2D graphics2D) { } LegupPreferences prefs = LegupPreferences.getInstance(); - boolean colorBlind = prefs.getUserPref(LegupPreferences.COLOR_BLIND).equals("true"); + boolean colorBlind = LegupPreferences.colorBlind(); if (isSelected) { Color c = DEFAULT_COLOR; From 2a936b97f9035ae0f2b582c4100c0d11ecdfd095 Mon Sep 17 00:00:00 2001 From: FisherLuba <145061313+FisherLuba@users.noreply.github.com> Date: Tue, 2 Apr 2024 17:38:48 -0400 Subject: [PATCH 06/10] Improve PreferencesDialog to make adding new preferences easier, and also made custom color theme file work --- .../edu/rpi/legup/app/LegupPreferences.java | 94 +---- src/main/java/edu/rpi/legup/ui/LegupUI.java | 92 +++-- .../edu/rpi/legup/ui/PreferencesDialog.java | 389 +++++++++--------- 3 files changed, 265 insertions(+), 310 deletions(-) diff --git a/src/main/java/edu/rpi/legup/app/LegupPreferences.java b/src/main/java/edu/rpi/legup/app/LegupPreferences.java index d488b5428..5bc481f3b 100644 --- a/src/main/java/edu/rpi/legup/app/LegupPreferences.java +++ b/src/main/java/edu/rpi/legup/app/LegupPreferences.java @@ -18,7 +18,6 @@ public class LegupPreferences { Preferences.userNodeForPackage(LegupPreferences.class); private static final Map preferencesMap = new EnumMap<>(LegupPreference.class); - private static final Map defaultPreferencesMap = new EnumMap<>(LegupPreference.class); public enum LegupPreference { WORK_DIRECTORY("work-directory", System.getProperty("user.dir"), o -> o), @@ -36,7 +35,13 @@ public enum LegupPreference { private final String id; private final Object defaultValue; + /** + * Converts the object to a string so that it can be saved in preferences + */ private final Function stringMapper; + /** + * Converts a string value to an object so it's more convenient to use in code + */ private final Function stringToValueMapper; @SuppressWarnings("unchecked") @@ -80,7 +85,7 @@ public String stringValue() { * @param */ public T as(Class clazz) { - return clazz.cast(defaultValue); + return clazz.cast(stringToValueMapper.apply(stringValue())); } public boolean asBoolean() { @@ -109,41 +114,6 @@ public String convertToString(Object value) { } } -// public static final String WORK_DIRECTORY = "work-directory"; -// public static final String START_FULL_SCREEN = "start-full-screen"; -// public static final String AUTO_UPDATE = "auto-update"; -// public static final String DARK_MODE = "night-mode"; -// public static final String USE_CUSTOM_COLOR_THEME = "use-custom-color-theme"; -// public static final String SHOW_MISTAKES = "show-mistakes"; -// public static final String SHOW_ANNOTATIONS = "show-annotations"; -// public static final String ALLOW_DEFAULT_RULES = "allow-default-rules"; -// public static final String AUTO_GENERATE_CASES = "auto-generate-cases"; -// public static final String IMMEDIATE_FEEDBACK = "immediate-feedback"; -// public static final String COLOR_THEME_FILE = "color-theme-file"; -// public static final String COLOR_BLIND = "color-blind"; - - private static void addDefaultPreference(LegupPreference preference) { - defaultPreferencesMap.put(preference, preference.defaultStringValue()); - } - - static { - for (final LegupPreference preference : LegupPreference.values()) { - addDefaultPreference(preference); - } -// defaultPreferencesMap.put(WORK_DIRECTORY, System.getProperty("user.dir")); -// defaultPreferencesMap.put(START_FULL_SCREEN, Boolean.toString(false)); -// defaultPreferencesMap.put(AUTO_UPDATE, Boolean.toString(true)); -// defaultPreferencesMap.put(DARK_MODE, Boolean.toString(false)); -// defaultPreferencesMap.put(USE_CUSTOM_COLOR_THEME, Boolean.toString(false)); -// defaultPreferencesMap.put(SHOW_MISTAKES, Boolean.toString(true)); -// defaultPreferencesMap.put(SHOW_ANNOTATIONS, Boolean.toString(false)); -// defaultPreferencesMap.put(ALLOW_DEFAULT_RULES, Boolean.toString(false)); -// defaultPreferencesMap.put(AUTO_GENERATE_CASES, Boolean.toString(true)); -// defaultPreferencesMap.put(IMMEDIATE_FEEDBACK, Boolean.toString(true)); -// defaultPreferencesMap.put(COLOR_BLIND, Boolean.toString(false)); -// defaultPreferencesMap.put(COLOR_THEME_FILE, System.getProperty("user.dir") + File.separator + ColorPreferences.LIGHT_COLOR_THEME_FILE_NAME); - } - private static Object getPreferenceOrDefault(LegupPreference preference) { final String current = preferences.get(preference.id(), null); if (current == null) { @@ -160,36 +130,6 @@ private static void addPreferenceFromDefault(LegupPreference preference) { for (final LegupPreference preference : LegupPreference.values()) { addPreferenceFromDefault(preference); } -// preferencesMap.put( -// WORK_DIRECTORY, -// preferences.get(WORK_DIRECTORY, defaultPreferencesMap.get(WORK_DIRECTORY))); -// preferencesMap.put( -// START_FULL_SCREEN, -// preferences.get(START_FULL_SCREEN, defaultPreferencesMap.get(START_FULL_SCREEN))); -// preferencesMap.put( -// AUTO_UPDATE, preferences.get(AUTO_UPDATE, defaultPreferencesMap.get(AUTO_UPDATE))); -// preferencesMap.put( -// DARK_MODE, preferences.get(DARK_MODE, defaultPreferencesMap.get(DARK_MODE))); -// preferencesMap.put( -// SHOW_MISTAKES, -// preferences.get(SHOW_MISTAKES, defaultPreferencesMap.get(SHOW_MISTAKES))); -// preferencesMap.put( -// SHOW_ANNOTATIONS, -// preferences.get(SHOW_ANNOTATIONS, defaultPreferencesMap.get(SHOW_ANNOTATIONS))); -// preferencesMap.put( -// ALLOW_DEFAULT_RULES, -// preferences.get( -// ALLOW_DEFAULT_RULES, defaultPreferencesMap.get(ALLOW_DEFAULT_RULES))); -// preferencesMap.put( -// AUTO_GENERATE_CASES, -// preferences.get( -// AUTO_GENERATE_CASES, defaultPreferencesMap.get(AUTO_GENERATE_CASES))); -// preferencesMap.put( -// IMMEDIATE_FEEDBACK, -// preferences.get(IMMEDIATE_FEEDBACK, defaultPreferencesMap.get(IMMEDIATE_FEEDBACK))); -// preferencesMap.put( -// COLOR_BLIND, preferences.get(COLOR_BLIND, defaultPreferencesMap.get(COLOR_BLIND))); -// preferencesMap.put(COLOR_THEME_FILE, preferences.get(COLOR_THEME_FILE, defaultPreferencesMap.get(COLOR_THEME_FILE))); } /** @@ -233,17 +173,6 @@ public void setUserPref(LegupPreference preference, Object value) { public boolean getUserPrefAsBool(LegupPreference preference) { return preference.asBoolean("Cannot get user preference - " + preference.id()); -// if (preferencesMap.get(preference).equalsIgnoreCase(Boolean.toString(true))) { -// return true; -// } -// else { -// if (preferencesMap.get(preference).equalsIgnoreCase(Boolean.toString(false))) { -// return false; -// } -// else { -// throw new RuntimeException("Cannot get user preference - " + preference.id()); -// } -// } } public String getSavedPath() { @@ -293,4 +222,13 @@ public static boolean autoGenerateCases() { public static boolean immediateFeedback() { return LegupPreference.IMMEDIATE_FEEDBACK.asBoolean(); } + + public static boolean useCustomColorTheme() { + return LegupPreference.USE_CUSTOM_COLOR_THEME.asBoolean(); + } + + public static String colorThemeFile() { + return LegupPreference.COLOR_THEME_FILE.stringValue(); + } + } diff --git a/src/main/java/edu/rpi/legup/ui/LegupUI.java b/src/main/java/edu/rpi/legup/ui/LegupUI.java index e153a5db5..2871639dc 100644 --- a/src/main/java/edu/rpi/legup/ui/LegupUI.java +++ b/src/main/java/edu/rpi/legup/ui/LegupUI.java @@ -5,22 +5,25 @@ import edu.rpi.legup.app.GameBoardFacade; import edu.rpi.legup.app.LegupPreferences; import edu.rpi.legup.ui.boardview.BoardView; -import edu.rpi.legup.ui.color.ColorPreferences; import edu.rpi.legup.ui.lookandfeel.LegupLookAndFeel; import edu.rpi.legup.ui.proofeditorui.treeview.TreePanel; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import javax.swing.*; import java.awt.*; -import java.awt.event.*; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.WindowEvent; +import java.awt.event.WindowListener; import java.io.File; import java.security.InvalidParameterException; import java.util.Objects; -import javax.swing.*; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; public class LegupUI extends JFrame implements WindowListener { private static final Logger LOGGER = LogManager.getLogger(LegupUI.class.getName()); -// protected FileDialog fileDialog; + // protected FileDialog fileDialog; protected JFileChooser fileChooser; protected JPanel window; protected LegupPanel[] panels; @@ -34,33 +37,51 @@ public static String getOS() { String os = System.getProperty("os.name").toLowerCase(); if (os.contains("mac")) { os = "mac"; - } else { + } + else { os = "win"; } return os; } - /** LegupUI Constructor - creates a new LegupUI to setup the menu and toolbar */ - public LegupUI() { - setTitle("LEGUP"); - setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - LegupPreferences prefs = LegupPreferences.getInstance(); - + public static void updateColorTheme() { try { final String colorFileName = LegupPreferences.LegupPreference.COLOR_THEME_FILE.stringValue(); - if (colorFileName.endsWith(".txt")) { + final boolean isTxt = colorFileName.endsWith(".txt"); + boolean useCustomColorTheme = LegupPreferences.useCustomColorTheme(); + System.out.println("Is txt: " + isTxt + " " + useCustomColorTheme); + if (!isTxt && useCustomColorTheme) { + System.err.printf("Invalid color theme file '%s', using default theme.\n", colorFileName); + useCustomColorTheme = false; + } + if (isTxt && useCustomColorTheme) { UIManager.setLookAndFeel(new LegupLookAndFeel(colorFileName)); - }else { - if (LegupPreferences.LegupPreference.DARK_MODE.asBoolean()) { - UIManager.setLookAndFeel(new LegupLookAndFeel(ColorPreferences.DARK_COLOR_THEME_FILE_NAME)); + com.formdev.flatlaf.FlatLaf.updateUI(); + } + else { + if (LegupPreferences.darkMode()) { + UIManager.setLookAndFeel(new FlatDarkLaf()); } else { - UIManager.setLookAndFeel(new LegupLookAndFeel(ColorPreferences.LIGHT_COLOR_THEME_FILE_NAME)); + UIManager.setLookAndFeel(new FlatLightLaf()); } } - } catch (UnsupportedLookAndFeelException e) { - System.err.println("Not supported ui look and feel"); + com.formdev.flatlaf.FlatLaf.updateUI(); + } + catch (UnsupportedLookAndFeelException exception) { + throw new RuntimeException("Not supported ui look and feel", exception); } + } + + /** + * LegupUI Constructor - creates a new LegupUI to setup the menu and toolbar + */ + public LegupUI() { + setTitle("LEGUP"); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + LegupPreferences prefs = LegupPreferences.getInstance(); + + updateColorTheme(); // fileDialog = new FileDialog(this); fileChooser = new JFileChooser(); @@ -71,11 +92,11 @@ public LegupUI() { setIconImage( new ImageIcon( - Objects.requireNonNull( - ClassLoader.getSystemClassLoader() - .getResource( - "edu/rpi/legup/images/Legup/Direct" - + " Rules.gif"))) + Objects.requireNonNull( + ClassLoader.getSystemClassLoader() + .getResource( + "edu/rpi/legup/images/Legup/Direct" + + " Rules.gif"))) .getImage()); if (LegupPreferences.LegupPreference.START_FULL_SCREEN.asBoolean()) { @@ -167,16 +188,19 @@ public boolean noquit(String instr) { } @Override - public void windowOpened(WindowEvent e) {} + public void windowOpened(WindowEvent e) { + } public void windowClosing(WindowEvent e) { if (GameBoardFacade.getInstance().getHistory().getIndex() > -1) { if (noquit("Exiting LEGUP?")) { this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - } else { + } + else { this.setDefaultCloseOperation(EXIT_ON_CLOSE); } - } else { + } + else { this.setDefaultCloseOperation(EXIT_ON_CLOSE); } } @@ -185,13 +209,17 @@ public void windowClosed(WindowEvent e) { System.exit(0); } - public void windowIconified(WindowEvent e) {} + public void windowIconified(WindowEvent e) { + } - public void windowDeiconified(WindowEvent e) {} + public void windowDeiconified(WindowEvent e) { + } - public void windowActivated(WindowEvent e) {} + public void windowActivated(WindowEvent e) { + } - public void windowDeactivated(WindowEvent e) {} + public void windowDeactivated(WindowEvent e) { + } public BoardView getBoardView() { return getProofEditor().getBoardView(); diff --git a/src/main/java/edu/rpi/legup/ui/PreferencesDialog.java b/src/main/java/edu/rpi/legup/ui/PreferencesDialog.java index 12abc0f45..2ba6035d5 100644 --- a/src/main/java/edu/rpi/legup/ui/PreferencesDialog.java +++ b/src/main/java/edu/rpi/legup/ui/PreferencesDialog.java @@ -1,7 +1,5 @@ package edu.rpi.legup.ui; -import com.formdev.flatlaf.FlatDarkLaf; -import com.formdev.flatlaf.FlatLightLaf; import edu.rpi.legup.app.LegupPreferences; import edu.rpi.legup.model.Puzzle; import edu.rpi.legup.model.rules.Rule; @@ -9,6 +7,7 @@ import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialBorders; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialFonts; import edu.rpi.legup.ui.proofeditorui.rulesview.RuleFrame; +import org.intellij.lang.annotations.MagicConstant; import javax.imageio.ImageIO; import javax.swing.*; @@ -19,6 +18,7 @@ import java.awt.event.MouseEvent; import java.io.File; import java.io.IOException; +import java.util.function.Consumer; import java.util.logging.Level; import java.util.logging.Logger; @@ -31,6 +31,7 @@ public class PreferencesDialog extends JDialog { private JCheckBox fullScreen, autoUpdate, darkMode, + customColorTheme, showMistakes, showAnnotations, allowDefault, @@ -109,222 +110,209 @@ public PreferencesDialog(Frame frame) { setVisible(true); } - private void toggleDarkMode(LegupPreferences prefs) { - try { - if (LegupPreferences.darkMode()) { - UIManager.setLookAndFeel(new FlatDarkLaf()); - } - else { - UIManager.setLookAndFeel(new FlatLightLaf()); - } - com.formdev.flatlaf.FlatLaf.updateUI(); - } - catch (UnsupportedLookAndFeelException e) { - System.err.println("Not supported ui look and feel"); - } + private void updateColorTheme(LegupPreferences prefs) { + LegupUI.updateColorTheme(); } - private JScrollPane createGeneralTab() { - LegupPreferences prefs = LegupPreferences.getInstance(); - JScrollPane scrollPane = new JScrollPane(); - JPanel contentPane = new JPanel(); - contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS)); + private JCheckBox addDefaultCheckBox( + String title, + boolean checked, + String description, + JPanel contentPane + ) { + return addCheckBox( + title, + checked, + description, + BorderLayout.WEST, + row -> row.setMaximumSize(new Dimension(Integer.MAX_VALUE, row.getPreferredSize().height)), + contentPane, + Box.createRigidArea(new Dimension(0, 10)) + + ); + } + + private JCheckBox addCheckBox( + String label, + boolean checked, + String hoverText, + @MagicConstant(stringValues = { + BorderLayout.NORTH, BorderLayout.SOUTH, BorderLayout.EAST, BorderLayout.WEST, + BorderLayout.CENTER, BorderLayout.BEFORE_FIRST_LINE, BorderLayout.AFTER_LAST_LINE, + BorderLayout.BEFORE_LINE_BEGINS, BorderLayout.AFTER_LINE_ENDS, BorderLayout.PAGE_START, + BorderLayout.PAGE_END, BorderLayout.LINE_START, BorderLayout.LINE_END + }) String borderLayout, + Consumer rowConsumer, + JPanel contentPane, + Component area) { + final JCheckBox box = + new JCheckBox(label, checked); + box.setToolTipText(hoverText); + JPanel row = new JPanel(); + row.setLayout(new BorderLayout()); + row.add(box, borderLayout); + rowConsumer.accept(row); + contentPane.add(row); + contentPane.add(area); + return box; + } - contentPane.add(createLeftLabel("General Preferences")); + private void addRowLabel(JPanel contentPane, String title) { + contentPane.add(createLeftLabel(title)); contentPane.add(createLineSeparator()); + } - JPanel workRow = new JPanel(); - workRow.setLayout(new BorderLayout()); - JLabel workDirLabel = new JLabel("Work Directory"); - workDirLabel.setToolTipText("This is where the open and save dialogs will open to."); - workRow.add(workDirLabel, BorderLayout.WEST); - workDirectory = new JTextField(LegupPreferences.workDirectory()); - workRow.add(workDirectory, BorderLayout.CENTER); - JButton openDir = new JButton(new ImageIcon(folderIcon)); - openDir.addActionListener( + private JTextField addFileChooser( + JPanel contentPane, + String label, + String hoverText, + String currentFile, + ImageIcon imageIcon, + String chooserLabel, + @MagicConstant(intValues = { + JFileChooser.FILES_ONLY, + JFileChooser.DIRECTORIES_ONLY, + JFileChooser.FILES_AND_DIRECTORIES, + }) int fileSelectionMode + ) { + final JPanel row = new JPanel(); + row.setLayout(new BorderLayout()); + final JLabel fileLabel = new JLabel(label); + fileLabel.setToolTipText(hoverText); + row.add(fileLabel, BorderLayout.WEST); + final JTextField file = new JTextField(currentFile); + row.add(file, BorderLayout.CENTER); + final JButton openFile = new JButton(imageIcon); + openFile.addActionListener( a -> { - JFileChooser chooser = new JFileChooser(); - chooser.setCurrentDirectory(new File(workDirectory.getText())); - chooser.setDialogTitle("Choose work directory"); - chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + final JFileChooser chooser = new JFileChooser(); + chooser.setCurrentDirectory(new File(file.getText())); + chooser.setDialogTitle(chooserLabel); + chooser.setFileSelectionMode(fileSelectionMode); chooser.setAcceptAllFileFilterUsed(false); chooser.setVisible(true); if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { - File newFile = chooser.getSelectedFile(); - workDirectory.setText(newFile.toString()); + final File newFile = chooser.getSelectedFile(); + file.setText(newFile.toString()); } }); - workRow.add(openDir, BorderLayout.EAST); - workRow.setMaximumSize(new Dimension(Integer.MAX_VALUE, workRow.getPreferredSize().height)); - contentPane.add(workRow); + row.add(openFile, BorderLayout.EAST); + row.setMaximumSize(new Dimension(Integer.MAX_VALUE, row.getPreferredSize().height)); + contentPane.add(row); + return file; + } - fullScreen = - new JCheckBox( - "Full Screen", - LegupPreferences.startFullScreen()); - fullScreen.setToolTipText("If checked this starts Legup in full screen."); - JPanel fullScreenRow = new JPanel(); - fullScreenRow.setLayout(new BorderLayout()); - fullScreenRow.add(fullScreen, BorderLayout.WEST); - fullScreenRow.setMaximumSize( - new Dimension(Integer.MAX_VALUE, fullScreenRow.getPreferredSize().height)); - contentPane.add(fullScreenRow); - - autoUpdate = - new JCheckBox( - "Automatically Check for Updates", - LegupPreferences.autoUpdate()); - autoUpdate.setToolTipText( - "If checked this automatically checks for updates on startup of Legup"); - JPanel autoUpdateRow = new JPanel(); - autoUpdateRow.setLayout(new BorderLayout()); - autoUpdateRow.add(autoUpdate, BorderLayout.WEST); - autoUpdateRow.setMaximumSize( - new Dimension(Integer.MAX_VALUE, autoUpdateRow.getPreferredSize().height)); - contentPane.add(autoUpdateRow); - // contentPane.add(Box.createRigidArea(new Dimension(0, 10))); - - darkMode = - new JCheckBox( - "Dark Mode", - LegupPreferences.darkMode()); - darkMode.setToolTipText("This turns dark mode on and off"); - JPanel darkModeRow = new JPanel(); - darkModeRow.setLayout(new BorderLayout()); - darkModeRow.add(darkMode, BorderLayout.WEST); - darkModeRow.setMaximumSize( - new Dimension(Integer.MAX_VALUE, darkModeRow.getPreferredSize().height)); - contentPane.add(darkModeRow); - contentPane.add(Box.createRigidArea(new Dimension(0, 10))); - - contentPane.add(createLeftLabel("Board View Preferences")); - contentPane.add(createLineSeparator()); - showMistakes = - new JCheckBox( - "Show Mistakes", - LegupPreferences.showMistakes()); - showMistakes.setToolTipText( - "If checked this show incorrectly applied rule applications in red on the board"); - JPanel showMistakesRow = new JPanel(); - showMistakesRow.setLayout(new BorderLayout()); - showMistakesRow.add(showMistakes, BorderLayout.WEST); - showMistakesRow.setMaximumSize( - new Dimension(Integer.MAX_VALUE, showMistakesRow.getPreferredSize().height)); - contentPane.add(showMistakesRow); - - showAnnotations = - new JCheckBox( - "Show Annotations", - LegupPreferences.showAnnotations()); - showAnnotations.setToolTipText( - "If checked this show incorrectly applied rule applications in red on the board"); - JPanel showAnnotationsRow = new JPanel(); - showAnnotationsRow.setLayout(new BorderLayout()); - showAnnotationsRow.add(showAnnotations, BorderLayout.WEST); - showAnnotationsRow.setMaximumSize( - new Dimension(Integer.MAX_VALUE, showAnnotationsRow.getPreferredSize().height)); - contentPane.add(showAnnotationsRow); - contentPane.add(Box.createRigidArea(new Dimension(0, 10))); - - contentPane.add(createLeftLabel("Tree View Preferences")); - contentPane.add(createLineSeparator()); + private JScrollPane createGeneralTab() { + LegupPreferences prefs = LegupPreferences.getInstance(); + JScrollPane scrollPane = new JScrollPane(); + JPanel contentPane = new JPanel(); + contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS)); - allowDefault = - new JCheckBox( - "Allow Default Rule Applications", - LegupPreferences.allowDefaultRules()); - allowDefault.setEnabled(false); - allowDefault.setToolTipText( - "If checked this automatically applies a rule where it can on the board"); - - JPanel allowDefaultRow = new JPanel(); - allowDefaultRow.setLayout(new BorderLayout()); - allowDefaultRow.add(allowDefault, BorderLayout.WEST); - allowDefaultRow.setMaximumSize( - new Dimension(Integer.MAX_VALUE, allowDefaultRow.getPreferredSize().height)); - contentPane.add(allowDefaultRow); - - generateCases = - new JCheckBox( - "Automatically Generate Cases", - LegupPreferences.autoGenerateCases()); - generateCases.setToolTipText( - "If checked this automatically generates all cases for a case rule"); - JPanel generateCasesRow = new JPanel(); - generateCasesRow.setLayout(new BorderLayout()); - generateCasesRow.add(generateCases, BorderLayout.WEST); - generateCasesRow.setMaximumSize( - new Dimension(Integer.MAX_VALUE, generateCasesRow.getPreferredSize().height)); - contentPane.add(generateCasesRow); - contentPane.add(Box.createRigidArea(new Dimension(0, 10))); - - immFeedback = - new JCheckBox( - "Provide Immediate Feedback", - LegupPreferences.immediateFeedback()); - immFeedback.setToolTipText( - "If checked this will update the colors of the tree view elements immediately"); - JPanel immFeedbackRow = new JPanel(); - immFeedbackRow.setLayout(new BorderLayout()); - immFeedbackRow.add(immFeedback, BorderLayout.WEST); - immFeedbackRow.setMaximumSize( - new Dimension(Integer.MAX_VALUE, immFeedbackRow.getPreferredSize().height)); - contentPane.add(immFeedbackRow); - - contentPane.add(createLeftLabel("Instructor Preferences")); - contentPane.add(createLineSeparator()); - immFeedback = - new JCheckBox( - "Instructor Mode", - LegupPreferences.immediateFeedback()); - immFeedback.setToolTipText("Currently unimplemented, this does nothing right now"); - immFeedbackRow.setLayout(new BorderLayout()); - immFeedbackRow.add(immFeedback, BorderLayout.WEST); - immFeedbackRow.setMaximumSize( - new Dimension(Integer.MAX_VALUE, immFeedbackRow.getPreferredSize().height)); - contentPane.add(immFeedbackRow); - - contentPane.add(createLeftLabel("Color Preferences")); - contentPane.add(createLineSeparator()); + addRowLabel(contentPane, "General Preferences"); + + workDirectory = addFileChooser( + contentPane, + "Work Directory", + "This is where the open and save dialogs will open to.", + LegupPreferences.workDirectory(), + new ImageIcon(folderIcon), + "Choose work directory", + JFileChooser.DIRECTORIES_ONLY + ); + + fullScreen = addDefaultCheckBox( + "Full Screen", + LegupPreferences.startFullScreen(), + "If checked this starts LEGUP in full screen.", + contentPane + ); + autoUpdate = addDefaultCheckBox( + "Automatically Check for Updates", + LegupPreferences.autoUpdate(), + "If checked this automatically checks for updates on startup of Legup", + contentPane + ); + darkMode = addDefaultCheckBox( + "Dark Mode", + LegupPreferences.darkMode(), + "This turns dark mode on and off", + contentPane + ); + customColorTheme = addDefaultCheckBox( + "Custom Color Theme", + LegupPreferences.useCustomColorTheme(), + "This turns custom color theme on and off", + contentPane + ); + + addRowLabel(contentPane, "Board View Preferences"); + + showMistakes = addDefaultCheckBox( + "Show Mistakes", + LegupPreferences.showMistakes(), + "If checked this show incorrectly applied rule applications in red on the board", + contentPane + ); + showAnnotations = addDefaultCheckBox( + "Show Annotations", + LegupPreferences.showAnnotations(), + "If checked this show incorrectly applied rule applications in red on the board", + contentPane + ); + + addRowLabel(contentPane, "Tree View Preferences"); + + allowDefault = addDefaultCheckBox( + "Allow Default Rule Applications", + LegupPreferences.allowDefaultRules(), + "If checked this automatically applies a rule where it can on the board", + contentPane + ); + generateCases = addDefaultCheckBox( + "Automatically Generate Cases", + LegupPreferences.autoGenerateCases(), + "If checked this automatically generates all cases for a case rule", + contentPane + ); + immFeedback = addDefaultCheckBox( + "Provide Immediate Feedback", + LegupPreferences.immediateFeedback(), + "If checked this will update the colors of the tree view elements immediately", + contentPane + ); + + addRowLabel(contentPane, "Instructor Preferences"); + + immFeedback = addDefaultCheckBox( + "Instructor Mode", + LegupPreferences.immediateFeedback(), + "Currently unimplemented, this does nothing right now", + contentPane + ); + + addRowLabel(contentPane, "Color Preferences"); + + colorBlind = addDefaultCheckBox( + "Deuteranomaly(red/green colorblindness)", + LegupPreferences.colorBlind(), + "", + contentPane + ); colorBlind = new JCheckBox( "Deuteranomaly(red/green colorblindness)", LegupPreferences.colorBlind()); - JPanel colorBlindRow = new JPanel(); - colorBlindRow.setLayout(new BorderLayout()); - colorBlindRow.add(colorBlind, BorderLayout.WEST); - colorBlindRow.setMaximumSize( - new Dimension(Integer.MAX_VALUE, showMistakesRow.getPreferredSize().height)); - contentPane.add(colorBlindRow); - - JPanel colorThemeRow = new JPanel(); - colorThemeRow.setLayout(new BorderLayout()); - JLabel colorThemeDirLabel = new JLabel("Color Theme File"); - colorThemeDirLabel.setToolTipText("This is the color theme LEGUP will use."); - colorThemeRow.add(colorThemeDirLabel, BorderLayout.WEST); - colorThemeFile = new JTextField(LegupPreferences.workDirectory() + "/" + ColorPreferences.LIGHT_COLOR_THEME_FILE_NAME); - colorThemeRow.add(colorThemeFile, BorderLayout.CENTER); - JButton openColorThemeFile = new JButton(new ImageIcon(folderIcon)); - openColorThemeFile.addActionListener( - a -> { - JFileChooser chooser = new JFileChooser(); - chooser.setCurrentDirectory(new File(colorThemeDirLabel.getText())); - chooser.setDialogTitle("Choose color theme file"); - chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); - chooser.setAcceptAllFileFilterUsed(false); - chooser.setVisible(true); - - if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { - File newFile = chooser.getSelectedFile(); - colorThemeFile.setText(newFile.toString()); - } - }); - colorThemeRow.add(openColorThemeFile, BorderLayout.EAST); - colorThemeRow.setMaximumSize(new Dimension(Integer.MAX_VALUE, colorThemeRow.getPreferredSize().height)); - contentPane.add(colorThemeRow); - + colorThemeFile = addFileChooser( + contentPane, + "Color Theme File", + "This is the color theme LEGUP will use.", + LegupPreferences.colorThemeFile(), + new ImageIcon(folderIcon), + "Choose color theme file", + JFileChooser.FILES_ONLY + ); scrollPane.setViewportView(contentPane); return scrollPane; @@ -451,6 +439,7 @@ public void applyPreferences() { LegupPreferences.LegupPreference.START_FULL_SCREEN, fullScreen.isSelected()); prefs.setUserPref(LegupPreferences.LegupPreference.AUTO_UPDATE, autoUpdate.isSelected()); prefs.setUserPref(LegupPreferences.LegupPreference.DARK_MODE, darkMode.isSelected()); + prefs.setUserPref(LegupPreferences.LegupPreference.USE_CUSTOM_COLOR_THEME, customColorTheme.isSelected()); prefs.setUserPref( LegupPreferences.LegupPreference.SHOW_MISTAKES, showMistakes.isSelected()); prefs.setUserPref( @@ -471,6 +460,6 @@ public void applyPreferences() { } // toggle dark mode based on updated NIGHT_MODE variable - toggleDarkMode(prefs); + updateColorTheme(prefs); } } From 797d0cce6552a83f19ea3a6d61a6ec25f4d97a44 Mon Sep 17 00:00:00 2001 From: FisherLuba <145061313+FisherLuba@users.noreply.github.com> Date: Tue, 9 Apr 2024 16:58:10 -0400 Subject: [PATCH 07/10] Replace LegupLookAndFeel with LegupCustomColorScheme which now just edits the current FlatLaf color scheme to add any colors that are in the color theme txt file. --- src/main/java/edu/rpi/legup/Legup.java | 10 - .../java/edu/rpi/legup/ui/DynamicView.java | 4 +- src/main/java/edu/rpi/legup/ui/LegupUI.java | 18 +- .../edu/rpi/legup/ui/ProofEditorPanel.java | 1 - .../legup/ui/boardview/DataSelectionView.java | 2 +- .../rpi/legup/ui/boardview/ElementView.java | 2 +- .../rpi/legup/ui/color/ColorPreferences.java | 57 ++- .../lookandfeel/LegupCustomColorScheme.java | 140 ++++++ .../ui/lookandfeel/LegupLookAndFeel.java | 442 ------------------ .../components/MaterialButtonUI.java | 2 +- .../components/MaterialPasswordFieldUI.java | 4 +- .../components/MaterialProgressBarUI.java | 4 +- .../components/MaterialTextFieldUI.java | 4 +- .../materialdesign/MaterialBorders.java | 4 +- src/main/resources/light-color-theme.txt | 2 +- 15 files changed, 202 insertions(+), 494 deletions(-) create mode 100644 src/main/java/edu/rpi/legup/ui/lookandfeel/LegupCustomColorScheme.java delete mode 100644 src/main/java/edu/rpi/legup/ui/lookandfeel/LegupLookAndFeel.java diff --git a/src/main/java/edu/rpi/legup/Legup.java b/src/main/java/edu/rpi/legup/Legup.java index 1d55761ca..79471286b 100644 --- a/src/main/java/edu/rpi/legup/Legup.java +++ b/src/main/java/edu/rpi/legup/Legup.java @@ -1,18 +1,8 @@ package edu.rpi.legup; import edu.rpi.legup.app.GameBoardFacade; -import edu.rpi.legup.ui.color.ColorPreferences; -import edu.rpi.legup.ui.lookandfeel.LegupLookAndFeel; import edu.rpi.legup.utility.Logger; -import javax.swing.*; -import javax.swing.plaf.basic.BasicLookAndFeel; -import javax.swing.plaf.metal.MetalLookAndFeel; -import javax.swing.plaf.multi.MultiLookAndFeel; -import javax.swing.plaf.nimbus.NimbusLookAndFeel; -import javax.swing.plaf.synth.SynthLookAndFeel; -import java.awt.*; - public class Legup { /** diff --git a/src/main/java/edu/rpi/legup/ui/DynamicView.java b/src/main/java/edu/rpi/legup/ui/DynamicView.java index 462e4238e..1c22cde3f 100644 --- a/src/main/java/edu/rpi/legup/ui/DynamicView.java +++ b/src/main/java/edu/rpi/legup/ui/DynamicView.java @@ -200,13 +200,13 @@ public JPanel getZoomer() { public void updateInfo(String message) { status.setFont(INFO_FONT); - status.setForeground(UIColor.INFO.get()); + status.setForeground(UIColor.INFO.getOrThrow()); status.setText(message); } public void updateError(String message) { status.setFont(ERROR_FONT); - status.setForeground(UIColor.ERROR.get()); + status.setForeground(UIColor.ERROR.getOrThrow()); status.setText(message); } diff --git a/src/main/java/edu/rpi/legup/ui/LegupUI.java b/src/main/java/edu/rpi/legup/ui/LegupUI.java index 2871639dc..03e0f1bb9 100644 --- a/src/main/java/edu/rpi/legup/ui/LegupUI.java +++ b/src/main/java/edu/rpi/legup/ui/LegupUI.java @@ -5,7 +5,7 @@ import edu.rpi.legup.app.GameBoardFacade; import edu.rpi.legup.app.LegupPreferences; import edu.rpi.legup.ui.boardview.BoardView; -import edu.rpi.legup.ui.lookandfeel.LegupLookAndFeel; +import edu.rpi.legup.ui.lookandfeel.LegupCustomColorScheme; import edu.rpi.legup.ui.proofeditorui.treeview.TreePanel; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -49,23 +49,21 @@ public static void updateColorTheme() { final String colorFileName = LegupPreferences.LegupPreference.COLOR_THEME_FILE.stringValue(); final boolean isTxt = colorFileName.endsWith(".txt"); boolean useCustomColorTheme = LegupPreferences.useCustomColorTheme(); - System.out.println("Is txt: " + isTxt + " " + useCustomColorTheme); if (!isTxt && useCustomColorTheme) { System.err.printf("Invalid color theme file '%s', using default theme.\n", colorFileName); useCustomColorTheme = false; } if (isTxt && useCustomColorTheme) { - UIManager.setLookAndFeel(new LegupLookAndFeel(colorFileName)); - com.formdev.flatlaf.FlatLaf.updateUI(); + LegupCustomColorScheme.setupCustomColorScheme(colorFileName); + } + + if (LegupPreferences.darkMode()) { + UIManager.setLookAndFeel(new FlatDarkLaf()); } else { - if (LegupPreferences.darkMode()) { - UIManager.setLookAndFeel(new FlatDarkLaf()); - } - else { - UIManager.setLookAndFeel(new FlatLightLaf()); - } + UIManager.setLookAndFeel(new FlatLightLaf()); } + com.formdev.flatlaf.FlatLaf.updateUI(); } catch (UnsupportedLookAndFeelException exception) { diff --git a/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java b/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java index 8773bef4c..76724bbf1 100644 --- a/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java +++ b/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java @@ -502,7 +502,6 @@ public Object[] promptPuzzle() { fileBrowser.setAcceptAllFileFilterUsed(false); File puzzlePath = fileBrowser.getSelectedFile(); - System.out.println(puzzlePath.getAbsolutePath()); if (puzzlePath != null) { fileName = puzzlePath.getAbsolutePath(); diff --git a/src/main/java/edu/rpi/legup/ui/boardview/DataSelectionView.java b/src/main/java/edu/rpi/legup/ui/boardview/DataSelectionView.java index 25bd4d155..2377fbac9 100644 --- a/src/main/java/edu/rpi/legup/ui/boardview/DataSelectionView.java +++ b/src/main/java/edu/rpi/legup/ui/boardview/DataSelectionView.java @@ -11,7 +11,7 @@ public class DataSelectionView extends JPopupMenu { public DataSelectionView(ElementController controller) { - setBackground(UIColor.DATA_SELECTION_BACKGROUND.get()); + setBackground(UIColor.DATA_SELECTION_BACKGROUND.getOrThrow()); setBorder(new BevelBorder(BevelBorder.RAISED)); } } diff --git a/src/main/java/edu/rpi/legup/ui/boardview/ElementView.java b/src/main/java/edu/rpi/legup/ui/boardview/ElementView.java index 2f5760b15..26d992f33 100644 --- a/src/main/java/edu/rpi/legup/ui/boardview/ElementView.java +++ b/src/main/java/edu/rpi/legup/ui/boardview/ElementView.java @@ -82,7 +82,7 @@ public void drawElement(Graphics2D graphics2D) { new Rectangle2D.Double( location.x + 0.5f, location.y + 0.5f, size.width - 2, size.height - 2)); - graphics2D.setColor(UIColor.ELEMENT_VIEW.get()); + graphics2D.setColor(UIColor.ELEMENT_VIEW.getOrThrow()); FontMetrics metrics = graphics2D.getFontMetrics(graphics2D.getFont()); String value = String.valueOf(puzzleElement.getData()); int xText = location.x + (size.width - metrics.stringWidth(value)) / 2; diff --git a/src/main/java/edu/rpi/legup/ui/color/ColorPreferences.java b/src/main/java/edu/rpi/legup/ui/color/ColorPreferences.java index 72a1d51b1..225b50379 100644 --- a/src/main/java/edu/rpi/legup/ui/color/ColorPreferences.java +++ b/src/main/java/edu/rpi/legup/ui/color/ColorPreferences.java @@ -3,6 +3,7 @@ //import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialColors; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialColors; +import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Unmodifiable; import java.awt.*; @@ -23,21 +24,21 @@ public class ColorPreferences { public enum UIColor { - CORRECT, - INCORRECT, - ERROR, - INFO, - UI_MOVEMENT, - PASSWORD_FIELD_BACKGROUND, - PASSWORD_FIELD_UNFOCUSED_BACKGROUND, - PROGRESS_BAR_BACKGROUND, - PROGRESS_BAR_FOREGROUND, - TEXT_FIELD_BACKGROUND, - TEXT_FIELD_UNFOCUSED_BACKGROUND, - LIGHT_LINE_BORDER, - THICK_LINE_BORDER, - DATA_SELECTION_BACKGROUND, - ELEMENT_VIEW, + CORRECT(Color.GREEN), + INCORRECT(Color.RED), + ERROR(Color.RED), + INFO(Color.GREEN), + UI_MOVEMENT(MaterialColors.GRAY_300), + PASSWORD_FIELD_BACKGROUND(MaterialColors.LIGHT_BLUE_400), + PASSWORD_FIELD_UNFOCUSED_BACKGROUND(MaterialColors.GRAY_200), + PROGRESS_BAR_BACKGROUND(MaterialColors.GRAY_200), + PROGRESS_BAR_FOREGROUND(MaterialColors.LIGHT_BLUE_400), + TEXT_FIELD_BACKGROUND(MaterialColors.LIGHT_BLUE_400), + TEXT_FIELD_UNFOCUSED_BACKGROUND(MaterialColors.GRAY_200), + LIGHT_LINE_BORDER(MaterialColors.GRAY_200), + THICK_LINE_BORDER(MaterialColors.GRAY_200), + DATA_SELECTION_BACKGROUND(Color.GRAY), + ELEMENT_VIEW(Color.BLACK), BUTTON_HIGHLIGHT, BUTTON_BACKGROUND, BUTTON_FOREGROUND, @@ -123,12 +124,34 @@ public enum UIColor { COLOR_CHOOSER_BACKGROUND, COLOR_CHOOSER_FOREGROUND; + private final Color defaultColor; + + UIColor() { + this.defaultColor = null; + } + + UIColor(Color defaultColor) { + this.defaultColor = defaultColor; + } + public String configKey() { return this.toString().toLowerCase().replace('_', '-'); } - public Color get() { - return Objects.requireNonNull(COLOR_MAP.get(this), "Could not get " + this.name() + " color."); + public Optional get() { + return Optional.ofNullable(COLOR_MAP.getOrDefault(this, defaultColor)); + } + + /** + * This method should only be used when this color needs to exist + */ + public Color getOrThrow() throws IllegalStateException { + return this.get().orElseThrow(() -> new IllegalStateException(this + " is a required color!")); + } + + public Optional getAsHex() { + return this.get() + .map(color -> String.format("#%02x%02x%02x", color.getRed(), color.getGreen(), color.getBlue())); } } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/LegupCustomColorScheme.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/LegupCustomColorScheme.java new file mode 100644 index 000000000..76b54b2a3 --- /dev/null +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/LegupCustomColorScheme.java @@ -0,0 +1,140 @@ +package edu.rpi.legup.ui.lookandfeel; + +import com.formdev.flatlaf.FlatLaf; +import edu.rpi.legup.ui.color.ColorPreferences; +import edu.rpi.legup.ui.color.ColorPreferences.UIColor; + +import java.util.HashMap; +import java.util.Map; + +public class LegupCustomColorScheme { + + + private static void addDefaultColor(Map defaults, String key, UIColor color) { + color.getAsHex().ifPresent(hex -> defaults.put(key, hex)); + } + + public static void setupCustomColorScheme(String colorThemeFileName) { + ColorPreferences.loadColorScheme(colorThemeFileName); + + final var extraGlobalDefaults = new HashMap(); + addDefaultColor(extraGlobalDefaults, "Button.highlight", UIColor.BUTTON_HIGHLIGHT); + addDefaultColor(extraGlobalDefaults, "Button.background", UIColor.BUTTON_BACKGROUND); + addDefaultColor(extraGlobalDefaults, "Button.foreground", UIColor.BUTTON_FOREGROUND); + + addDefaultColor(extraGlobalDefaults, "CheckBox.background", UIColor.CHECKBOX_BACKGROUND); + addDefaultColor(extraGlobalDefaults, "CheckBox.foreground", UIColor.CHECKBOX_FOREGROUND); + + addDefaultColor(extraGlobalDefaults, "ComboBox.background", UIColor.COMBOBOX_BACKGROUND); + addDefaultColor(extraGlobalDefaults, "ComboBox.foreground", UIColor.COMBOBOX_FOREGROUND); + addDefaultColor(extraGlobalDefaults, "ComboBox.buttonBackground", UIColor.COMBOBOX_BUTTON_BACKGROUND); + addDefaultColor(extraGlobalDefaults, "ComboBox.selectionBackground", UIColor.COMBOBOX_SELECTION_BACKGROUND); + addDefaultColor(extraGlobalDefaults, "ComboBox.selectionForeground", UIColor.COMBOBOX_SELECTION_FOREGROUND); + addDefaultColor(extraGlobalDefaults, "ComboBox.selectedInDropDownBackground", UIColor.COMBOBOX_SELECTED_IN_DROP_DOWN_BACKGROUND); + + addDefaultColor(extraGlobalDefaults, "Label.background", UIColor.LABEL_BACKGROUND); + addDefaultColor(extraGlobalDefaults, "Label.foreground", UIColor.LABEL_FOREGROUND); + + addDefaultColor(extraGlobalDefaults, "Menu.background", UIColor.MENU_BACKGROUND); + addDefaultColor(extraGlobalDefaults, "Menu.foreground", UIColor.MENU_FOREGROUND); + addDefaultColor(extraGlobalDefaults, "Menu.selectionBackground", UIColor.MENU_SELECTION_BACKGROUND); + addDefaultColor(extraGlobalDefaults, "Menu.selectionForeground", UIColor.MENU_SELECTION_FOREGROUND); + addDefaultColor(extraGlobalDefaults, "Menu.disabledForeground", UIColor.MENU_DISABLED_FOREGROUND); + + addDefaultColor(extraGlobalDefaults, "MenuBar.background", UIColor.MENU_BAR_BACKGROUND); + addDefaultColor(extraGlobalDefaults, "MenuBar.foreground", UIColor.MENU_BAR_FOREGROUND); + + addDefaultColor(extraGlobalDefaults, "MenuItem.disabledForeground", UIColor.MENU_ITEM_DISABLED_FOREGROUND); + addDefaultColor(extraGlobalDefaults, "MenuItem.selectionBackground", UIColor.MENU_ITEM_SELECTION_BACKGROUND); + addDefaultColor(extraGlobalDefaults, "MenuItem.selectionForeground", UIColor.MENU_ITEM_SELECTION_FOREGROUND); + addDefaultColor(extraGlobalDefaults, "MenuItem.background", UIColor.MENU_ITEM_BACKGROUND); + addDefaultColor(extraGlobalDefaults, "MenuItem.foreground", UIColor.MENU_ITEM_FOREGROUND); + + addDefaultColor(extraGlobalDefaults, "OptionPane.background", UIColor.OPTION_PANE_BACKGROUND); + + addDefaultColor(extraGlobalDefaults, "Panel.background", UIColor.PANEL_BACKGROUND_COLOR); + + addDefaultColor(extraGlobalDefaults, "PopupMenu.background", UIColor.POPUP_MENU_BACKGROUND); + addDefaultColor(extraGlobalDefaults, "PopupMenu.foreground", UIColor.POPUP_MENU_FOREGROUND); + + addDefaultColor(extraGlobalDefaults, "RadioButton.background", UIColor.RADIO_BUTTON_BACKGROUND); + addDefaultColor(extraGlobalDefaults, "RadioButton.foreground", UIColor.RADIO_BUTTON_FOREGROUND); + + addDefaultColor(extraGlobalDefaults, "Spinner.background", UIColor.SPINNER_BACKGROUND); + addDefaultColor(extraGlobalDefaults, "Spinner.foreground", UIColor.SPINNER_FOREGROUND); + addDefaultColor(extraGlobalDefaults, "Spinner.arrowButtonBackground", UIColor.SPINNER_ARROW_BUTTON_BACKGROUND); + + addDefaultColor(extraGlobalDefaults, "ScrollBar.track", UIColor.SCROLL_BAR_TRACK); + addDefaultColor(extraGlobalDefaults, "ScrollBar.thumb", UIColor.SCROLL_BAR_THUMB); + addDefaultColor(extraGlobalDefaults, "ScrollBar.thumbDarkShadow", UIColor.SCROLL_BAR_THUMB_DARK_SHADOW); + addDefaultColor(extraGlobalDefaults, "ScrollBar.thumbHighlight", UIColor.SCROLL_BAR_THUMB_HIGHLIGHT); + addDefaultColor(extraGlobalDefaults, "ScrollBar.thumbShadow", UIColor.SCROLL_BAR_THUMB_SHADOW); + addDefaultColor(extraGlobalDefaults, "ScrollBar.arrowButtonBackground", UIColor.SCROLL_BAR_ARROW_BUTTON_BACKGROUND); + + addDefaultColor(extraGlobalDefaults, "ScrollPane.background", UIColor.SCROLL_PANE_BACKGROUND); + + addDefaultColor(extraGlobalDefaults, "Slider.background", UIColor.SLIDER_BACKGROUND); + addDefaultColor(extraGlobalDefaults, "Slider.foreground", UIColor.SLIDER_FOREGROUND); + addDefaultColor(extraGlobalDefaults, "Slider.trackColor", UIColor.SLIDER_TRACK_COLOR); + + addDefaultColor(extraGlobalDefaults, "SplitPane.background", UIColor.SPLIT_PANE_BACKGROUND); + + addDefaultColor(extraGlobalDefaults, "TabbedPane.background", UIColor.TABBED_PANE_BACKGROUND); + addDefaultColor(extraGlobalDefaults, "TabbedPane.foreground", UIColor.TABBED_PANE_FOREGROUND); + addDefaultColor(extraGlobalDefaults, "TabbedPane.highlight", UIColor.TABBED_PANE_HIGHLIGHT); + addDefaultColor(extraGlobalDefaults, "TabbedPane.borderHighlightColor", UIColor.TABBED_PANE_BORDER_HIGHLIGHT); + + addDefaultColor(extraGlobalDefaults, "Table.selectionBackground", UIColor.TABLE_SELECTION_BACKGROUND); + addDefaultColor(extraGlobalDefaults, "Table.selectionForeground", UIColor.TABLE_SELECTION_FOREGROUND); + addDefaultColor(extraGlobalDefaults, "Table.background", UIColor.TABLE_BACKGROUND); + addDefaultColor(extraGlobalDefaults, "Table.gridColor", UIColor.TABLE_GRID_COLOR); + addDefaultColor(extraGlobalDefaults, "TableHeader.background", UIColor.TABLE_HEADER_BACKGROUND); + + addDefaultColor(extraGlobalDefaults, "TextArea.background", UIColor.TEXT_AREA_BACKGROUND); + addDefaultColor(extraGlobalDefaults, "TextArea.foreground", UIColor.TEXT_AREA_FOREGROUND); + + addDefaultColor(extraGlobalDefaults, "ToggleButton.background", UIColor.TOGGLE_BUTTON_BACKGROUND); + addDefaultColor(extraGlobalDefaults, "ToggleButton.foreground", UIColor.TOGGLE_BUTTON_FOREGROUND); + + addDefaultColor(extraGlobalDefaults, "ToolBar.background", UIColor.TOOL_BAR_BACKGROUND); + addDefaultColor(extraGlobalDefaults, "ToolBar.foreground", UIColor.TOOL_BAR_FOREGROUND); + addDefaultColor(extraGlobalDefaults, "ToolBar.dockingBackground", UIColor.TOOL_BAR_DOCKING_BACKGROUND); + addDefaultColor(extraGlobalDefaults, "ToolBar.floatingBackground", UIColor.TOOL_BAR_FLOATING_BACKGROUND); + + addDefaultColor(extraGlobalDefaults, "Tree.selectionForeground", UIColor.TREE_SELECTION_FOREGROUND); + addDefaultColor(extraGlobalDefaults, "Tree.foreground", UIColor.TREE_FOREGROUND); + addDefaultColor(extraGlobalDefaults, "Tree.selectionBackground", UIColor.TREE_SELECTION_BACKGROUND); + addDefaultColor(extraGlobalDefaults, "Tree.background", UIColor.TREE_BACKGROUND); + + addDefaultColor(extraGlobalDefaults, "RadioButtonMenuItem.foreground", UIColor.RADIO_BUTTON_FOREGROUND); + addDefaultColor(extraGlobalDefaults, "RadioButtonMenuItem.selectionForeground", UIColor.RADIO_BUTTON_MENU_ITEM_SELECTION_FOREGROUND); + // If it changes the background of the menuitem it must change this too, irrespective of its + // setting + addDefaultColor(extraGlobalDefaults, "RadioButtonMenuItem.selectionBackground", UIColor.RADIO_BUTTON_MENU_ITEM_SELECTION_BACKGROUND); + + // If it changes the background of the menuitem it must change this too, irrespective of its + // setting + addDefaultColor(extraGlobalDefaults, "CheckBoxMenuItem.selectionBackground", UIColor.CHECKBOX_MENU_ITEM_SELECTION_BACKGROUND); + addDefaultColor(extraGlobalDefaults, "CheckBoxMenuItem.foreground", UIColor.CHECKBOX_MENU_ITEM_FOREGROUND); + addDefaultColor(extraGlobalDefaults, "CheckBoxMenuItem.selectionForeground", UIColor.CHECKBOX_MENU_ITEM_SELECTION_FOREGROUND); + + addDefaultColor(extraGlobalDefaults, "TextPane.background", UIColor.TEXT_PANE_BACKGROUND); + addDefaultColor(extraGlobalDefaults, "TextPane.selectionBackground", UIColor.TEXT_PANE_SELECTION_BACKGROUND); + addDefaultColor(extraGlobalDefaults, "TextPane.inactiveForeground", UIColor.TEXT_PANE_INACTIVE_FOREGROUND); + + addDefaultColor(extraGlobalDefaults, "EditorPane.background", UIColor.EDITOR_PANE_BACKGROUND); + addDefaultColor(extraGlobalDefaults, "EditorPane.selectionBackground", UIColor.EDITOR_PANE_SELECTION_BACKGROUND); + addDefaultColor(extraGlobalDefaults, "EditorPane.inactiveForeground", UIColor.EDITOR_PANE_INACTIVE_FOREGROUND); + + addDefaultColor(extraGlobalDefaults, "Separator.background", UIColor.SEPARATOR_BACKGROUND); + addDefaultColor(extraGlobalDefaults, "Separator.foreground", UIColor.SEPARATOR_FOREGROUND); + + addDefaultColor(extraGlobalDefaults, "ToolTip.background", UIColor.TOOL_TIP_BACKGROUND); + addDefaultColor(extraGlobalDefaults, "ToolTip.foreground", UIColor.TOOL_TIP_FOREGROUND); + + addDefaultColor(extraGlobalDefaults, "ColorChooser.background", UIColor.COLOR_CHOOSER_BACKGROUND); + addDefaultColor(extraGlobalDefaults, "ColorChooser.foreground", UIColor.COLOR_CHOOSER_FOREGROUND); + + FlatLaf.setGlobalExtraDefaults(extraGlobalDefaults); + } +} diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/LegupLookAndFeel.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/LegupLookAndFeel.java deleted file mode 100644 index 06c8b379c..000000000 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/LegupLookAndFeel.java +++ /dev/null @@ -1,442 +0,0 @@ -package edu.rpi.legup.ui.lookandfeel; - -import edu.rpi.legup.ui.color.ColorPreferences; -import edu.rpi.legup.ui.lookandfeel.components.*; -import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialBorders; -import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialColors; -import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialFonts; -import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialImages; -import java.awt.*; -import javax.swing.*; -import javax.swing.plaf.basic.BasicLookAndFeel; -import edu.rpi.legup.ui.color.ColorPreferences.UIColor; - -public class LegupLookAndFeel extends BasicLookAndFeel { - - private final String colorThemeFileName; - - public LegupLookAndFeel(String colorThemeFileName) { - this.colorThemeFileName = colorThemeFileName; - ColorPreferences.loadColorScheme(colorThemeFileName); - } - - /** - * Return a short string that identifies this look and feel, e.g. "CDE/Motif". This string - * should be appropriate for a menu item. Distinct look and feels should have different names, - * e.g. a subclass of MotifLookAndFeel that changes the way a few components are rendered should - * be called "CDE/Motif My Way"; something that would be useful to a user trying to select a - * L&F from a list of names. - * - * @return short identifier for the look and feel - */ - @Override - public String getName() { - return "Legup"; - } - - /** - * Return a string that identifies this look and feel. This string will be used by - * applications/services that want to recognize well known look and feel implementations. - * Presently the well known names are "Motif", "Windows", "Mac", "Metal". Note that a - * LookAndFeel derived from a well known superclass that doesn't make any fundamental changes to - * the look or feel shouldn't override this method. - * - * @return identifier for the look and feel - */ - @Override - public String getID() { - return "Legup Look and Feel"; - } - - /** - * Return a one line description of this look and feel implementation, e.g. "The CDE/Motif Look - * and Feel". This string is intended for the user, e.g. in the title of a window or in a - * ToolTip message. - * - * @return short description for the look and feel - */ - @Override - public String getDescription() { - return "Material design look and feel for Legup"; - } - - /** - * If the underlying platform has a "native" look and feel, and this is an implementation of it, - * return {@code true}. For example, when the underlying platform is Solaris running CDE a - * CDE/Motif look and feel implementation would return {@code true}. - * - * @return {@code true} if this look and feel represents the underlying platform look and feel - */ - @Override - public boolean isNativeLookAndFeel() { - return true; - } - - /** - * Return {@code true} if the underlying platform supports and or permits this look and feel. - * This method returns {@code false} if the look and feel depends on special resources or legal - * agreements that aren't defined for the current platform. - * - * @return {@code true} if this is a supported look and feel - * @see UIManager#setLookAndFeel - */ - @Override - public boolean isSupportedLookAndFeel() { - return true; - } - - /** - * Initializes the look and feel. While this method is public, it should only be invoked by the - * {@code UIManager} when a look and feel is installed as the current look and feel. This method - * is invoked before the {@code UIManager} invokes {@code getDefaults}. This method is intended - * to perform any initialization for the look and feel. Subclasses should do any one-time setup - * they need here, rather than in a static initializer, because look and feel class objects may - * be loaded just to discover that {@code isSupportedLookAndFeel()} returns {@code false}. - * - * @see #uninitialize - * @see UIManager#setLookAndFeel - */ - @Override - public void initialize() { - super.initialize(); - } - - /** - * Populates {@code table} with mappings from {@code uiClassID} to the fully qualified name of - * the ui class. The value for a particular {@code uiClassID} is {@code - * "javax.swing.plaf.basic.Basic + uiClassID"}. For example, the value for the {@code uiClassID} - * {@code TreeUI} is {@code "javax.swing.plaf.basic.BasicTreeUI"}. - * - * @param table the {@code UIDefaults} instance the entries are added to - * @throws NullPointerException if {@code table} is {@code null} - * @see LookAndFeel - * @see #getDefaults - */ - @Override - protected void initClassDefaults(UIDefaults table) { - super.initClassDefaults(table); - - table.put("ButtonUI", MaterialButtonUI.class.getCanonicalName()); - table.put("TextFieldUI", MaterialTextFieldUI.class.getCanonicalName()); - table.put("PasswordFieldUI", MaterialPasswordFieldUI.class.getCanonicalName()); - table.put("TableUI", MaterialTableUI.class.getCanonicalName()); - table.put("TableHeaderUI", MaterialTableHeaderUI.class.getCanonicalName()); - table.put("TreeUI", MaterialTreeUI.class.getCanonicalName()); - table.put("SpinnerUI", MaterialSpinnerUI.class.getCanonicalName()); - table.put("PanelUI", MaterialPanelUI.class.getCanonicalName()); - table.put("LabelUI", MaterialLabelUI.class.getCanonicalName()); - table.put("MenuItemUI", MaterialMenuItemUI.class.getCanonicalName()); - // table.put ("MenuBarUI", .class.getCanonicalName()); - table.put("MenuUI", MaterialMenuUI.class.getCanonicalName()); - table.put("CheckBoxUI", MaterialCheckBoxUI.class.getCanonicalName()); - table.put("RadioButtonUI", MaterialRadioButtonUI.class.getCanonicalName()); - table.put("TabbedPaneUI", MaterialTabbedPaneUI.class.getCanonicalName()); - table.put("ToggleButtonUI", MaterialToggleButtonUI.class.getCanonicalName()); - table.put("ScrollBarUI", MaterialScrollBarUI.class.getCanonicalName()); - table.put("ComboBoxUI", MaterialComboBoxUI.class.getCanonicalName()); - table.put("PopupMenuUI", MaterialPopupMenuUI.class.getCanonicalName()); - table.put("ToolBarUI", MaterialToolBarUI.class.getCanonicalName()); - table.put("SliderUI", MaterialSliderUI.class.getCanonicalName()); - table.put("ProgressBarUI", MaterialProgressBarUI.class.getCanonicalName()); - table.put("RadioButtonMenuItemUI", MaterialRadioButtonMenuItemUI.class.getCanonicalName()); - table.put("CheckBoxMenuItemUI", MaterialCheckBoxMenuItemUI.class.getCanonicalName()); - table.put("TextPaneUI", MaterialTextPaneUI.class.getCanonicalName()); - table.put("EditorPaneUI", MaterialEditorPaneUI.class.getCanonicalName()); - table.put("SeparatorUI", MaterialSeparatorUI.class.getCanonicalName()); - table.put("FileChooserUI", MaterialFileChooserUI.class.getCanonicalName()); - table.put("ToolTipUI", MaterialToolTipUI.class.getCanonicalName()); - table.put("SplitPaneUI", MaterialSplitPaneUI.class.getCanonicalName()); - // table.put ("ColorChooserUI", ); - } - - @Override - protected void initComponentDefaults(UIDefaults table) { - super.initComponentDefaults(table); - -// table.put("Button.highlight", MaterialColors.GRAY_300); - - table.put("Button.highlight", UIColor.BUTTON_HIGHLIGHT.get()); - table.put("Button.opaque", false); - table.put("Button.border", BorderFactory.createEmptyBorder(7, 17, 7, 17)); -// table.put("Button.background", MaterialColors.GRAY_200); - table.put("Button.background", UIColor.BUTTON_BACKGROUND.get()); -// table.put("Button.foreground", Color.BLACK); - table.put("Button.foreground", UIColor.BUTTON_FOREGROUND.get()); - table.put("Button.font", MaterialFonts.MEDIUM); - - table.put("CheckBox.font", MaterialFonts.REGULAR); -// table.put("CheckBox.background", Color.WHITE); - table.put("CheckBox.background", UIColor.CHECKBOX_BACKGROUND.get()); -// table.put("CheckBox.foreground", Color.BLACK); - table.put("CheckBox.foreground", UIColor.CHECKBOX_FOREGROUND.get()); - table.put("CheckBox.icon", new ImageIcon(MaterialImages.UNCHECKED_BOX)); - table.put("CheckBox.selectedIcon", new ImageIcon(MaterialImages.PAINTED_CHECKED_BOX)); - - table.put("ComboBox.font", MaterialFonts.REGULAR); -// table.put("ComboBox.background", Color.WHITE); - table.put("ComboBox.background", UIColor.COMBOBOX_BACKGROUND.get()); -// table.put("ComboBox.foreground", Color.BLACK); - table.put("ComboBox.foreground", UIColor.COMBOBOX_FOREGROUND.get()); - table.put( - "ComboBox.border", - BorderFactory.createCompoundBorder( - MaterialBorders.LIGHT_LINE_BORDER, - BorderFactory.createEmptyBorder(0, 5, 0, 0))); -// table.put("ComboBox.buttonBackground", MaterialColors.GRAY_300); - table.put("ComboBox.buttonBackground", UIColor.COMBOBOX_BUTTON_BACKGROUND.get()); -// table.put("ComboBox.selectionBackground", Color.WHITE); - table.put("ComboBox.selectionBackground", UIColor.COMBOBOX_SELECTION_BACKGROUND.get()); -// table.put("ComboBox.selectionForeground", Color.BLACK); - table.put("ComboBox.selectionForeground", UIColor.COMBOBOX_SELECTION_FOREGROUND.get()); -// table.put("ComboBox.selectedInDropDownBackground", MaterialColors.GRAY_200); - table.put("ComboBox.selectedInDropDownBackground", UIColor.COMBOBOX_SELECTED_IN_DROP_DOWN_BACKGROUND.get()); - - table.put("Label.font", MaterialFonts.REGULAR); -// table.put("Label.background", Color.WHITE); - table.put("Label.background", UIColor.LABEL_BACKGROUND.get()); -// table.put("Label.foreground", Color.BLACK); - table.put("Label.foreground", UIColor.LABEL_FOREGROUND.get()); - table.put("Label.border", BorderFactory.createEmptyBorder()); - - table.put("Menu.font", MaterialFonts.BOLD); - table.put("Menu.border", BorderFactory.createEmptyBorder(5, 5, 5, 5)); -// table.put("Menu.background", Color.WHITE); - table.put("Menu.background", UIColor.MENU_BACKGROUND.get()); -// table.put("Menu.foreground", Color.BLACK); - table.put("Menu.foreground", UIColor.MENU_FOREGROUND.get()); - table.put("Menu.opaque", true); -// table.put("Menu.selectionBackground", MaterialColors.GRAY_200); - table.put("Menu.selectionBackground", UIColor.MENU_SELECTION_BACKGROUND.get()); -// table.put("Menu.selectionForeground", Color.BLACK); - table.put("Menu.selectionForeground", UIColor.MENU_SELECTION_FOREGROUND.get()); -// table.put("Menu.disabledForeground", new Color(0, 0, 0, 100)); - table.put("Menu.disabledForeground", UIColor.MENU_DISABLED_FOREGROUND.get()); - table.put("Menu.menuPopupOffsetY", 3); - - table.put("MenuBar.font", MaterialFonts.BOLD); -// table.put("MenuBar.background", Color.WHITE); - table.put("MenuBar.background", UIColor.MENU_BAR_BACKGROUND.get()); - table.put("MenuBar.border", MaterialBorders.LIGHT_SHADOW_BORDER); -// table.put("MenuBar.foreground", Color.BLACK); - table.put("MenuBar.foreground", UIColor.MENU_BAR_FOREGROUND.get()); - -// table.put("MenuItem.disabledForeground", new Color(0, 0, 0, 100)); - table.put("MenuItem.disabledForeground", UIColor.MENU_ITEM_DISABLED_FOREGROUND.get()); -// table.put("MenuItem.selectionBackground", MaterialColors.GRAY_200); - table.put("MenuItem.selectionBackground", UIColor.MENU_ITEM_SELECTION_BACKGROUND.get()); -// table.put("MenuItem.selectionForeground", Color.BLACK); - table.put("MenuItem.selectionForeground", UIColor.MENU_ITEM_SELECTION_FOREGROUND.get()); - table.put("MenuItem.font", MaterialFonts.MEDIUM); -// table.put("MenuItem.background", Color.WHITE); - table.put("MenuItem.background", UIColor.MENU_ITEM_BACKGROUND.get()); -// table.put("MenuItem.foreground", Color.BLACK); - table.put("MenuItem.foreground", UIColor.MENU_ITEM_FOREGROUND.get()); - table.put("MenuItem.border", BorderFactory.createEmptyBorder(5, 0, 5, 0)); - -// table.put("OptionPane.background", Color.WHITE); - table.put("OptionPane.background", UIColor.OPTION_PANE_BACKGROUND.get()); - table.put("OptionPane.border", MaterialBorders.DEFAULT_SHADOW_BORDER); - table.put("OptionPane.font", MaterialFonts.REGULAR); - - table.put("Panel.font", MaterialFonts.REGULAR); -// table.put("Panel.background", Color.WHITE); - table.put("Panel.background", UIColor.PANEL_BACKGROUND_COLOR.get()); - table.put("Panel.border", BorderFactory.createEmptyBorder()); - - table.put("PopupMenu.border", MaterialBorders.LIGHT_LINE_BORDER); -// table.put("PopupMenu.background", Color.WHITE); - table.put("PopupMenu.background", UIColor.POPUP_MENU_BACKGROUND.get()); -// table.put("PopupMenu.foreground", Color.BLACK); - table.put("PopupMenu.foreground", UIColor.POPUP_MENU_FOREGROUND.get()); - - table.put("RadioButton.font", MaterialFonts.REGULAR); -// table.put("RadioButton.background", Color.WHITE); - table.put("RadioButton.background", UIColor.RADIO_BUTTON_BACKGROUND.get()); -// table.put("RadioButton.foreground", Color.BLACK); - table.put("RadioButton.foreground", UIColor.RADIO_BUTTON_FOREGROUND.get()); - table.put("RadioButton.icon", new ImageIcon(MaterialImages.RADIO_BUTTON_OFF)); - table.put("RadioButton.selectedIcon", new ImageIcon(MaterialImages.RADIO_BUTTON_ON)); - - table.put("Spinner.font", MaterialFonts.REGULAR); -// table.put("Spinner.background", Color.WHITE); - table.put("Spinner.background", UIColor.SPINNER_BACKGROUND.get()); -// table.put("Spinner.foreground", Color.BLACK); - table.put("Spinner.foreground", UIColor.SPINNER_FOREGROUND.get()); - table.put("Spinner.border", MaterialBorders.LIGHT_LINE_BORDER); -// table.put("Spinner.arrowButtonBackground", MaterialColors.GRAY_200); - table.put("Spinner.arrowButtonBackground", UIColor.SPINNER_ARROW_BUTTON_BACKGROUND.get()); - table.put("Spinner.arrowButtonBorder", BorderFactory.createEmptyBorder()); - - table.put("ScrollBar.font", MaterialFonts.REGULAR); -// table.put("ScrollBar.track", MaterialColors.GRAY_200); - table.put("ScrollBar.track", UIColor.SCROLL_BAR_TRACK.get()); -// table.put("ScrollBar.thumb", MaterialColors.GRAY_300); - table.put("ScrollBar.thumb", UIColor.SCROLL_BAR_THUMB.get()); -// table.put("ScrollBar.thumbDarkShadow", MaterialColors.GRAY_300); - table.put("ScrollBar.thumbDarkShadow", UIColor.SCROLL_BAR_THUMB_DARK_SHADOW.get()); -// table.put("ScrollBar.thumbHighlight", MaterialColors.GRAY_300); - table.put("ScrollBar.thumbHighlight", UIColor.SCROLL_BAR_THUMB_HIGHLIGHT.get()); -// table.put("ScrollBar.thumbShadow", MaterialColors.GRAY_300); - table.put("ScrollBar.thumbShadow", UIColor.SCROLL_BAR_THUMB_SHADOW.get()); -// table.put("ScrollBar.arrowButtonBackground", MaterialColors.GRAY_300); - table.put("ScrollBar.arrowButtonBackground", UIColor.SCROLL_BAR_ARROW_BUTTON_BACKGROUND.get()); - table.put("ScrollBar.arrowButtonBorder", BorderFactory.createEmptyBorder()); - -// table.put("ScrollPane.background", Color.WHITE); - table.put("ScrollPane.background", UIColor.SCROLL_PANE_BACKGROUND.get()); - table.put("ScrollPane.border", BorderFactory.createEmptyBorder()); - table.put("ScrollPane.font", MaterialFonts.REGULAR); - - table.put("Slider.font", MaterialFonts.REGULAR); -// table.put("Slider.background", Color.WHITE); - table.put("Slider.background", UIColor.SLIDER_BACKGROUND.get()); -// table.put("Slider.foreground", MaterialColors.GRAY_700); - table.put("Slider.foreground", UIColor.SLIDER_FOREGROUND.get()); -// table.put("Slider.trackColor", Color.BLACK); - table.put("Slider.trackColor", UIColor.SLIDER_TRACK_COLOR.get()); - // table.put ("Slider.border", - // BorderFactory.createCompoundBorder(MaterialBorders.LIGHT_LINE_BORDER, - // BorderFactory.createEmptyBorder (5, 5, 5, 5))); - - table.put("SplitPane.border", MaterialBorders.LIGHT_LINE_BORDER); -// table.put("SplitPane.background", Color.WHITE); - table.put("SplitPane.background", UIColor.SPLIT_PANE_BACKGROUND.get()); - table.put("SplitPane.dividerSize", 10); - table.put("SplitPaneDivider.border", MaterialBorders.LIGHT_SHADOW_BORDER); - - table.put("TabbedPane.font", MaterialFonts.REGULAR); -// table.put("TabbedPane.background", Color.WHITE); - table.put("TabbedPane.background", UIColor.TABBED_PANE_BACKGROUND.get()); -// table.put("TabbedPane.foreground", Color.BLACK); - table.put("TabbedPane.foreground", UIColor.TABBED_PANE_FOREGROUND.get()); - table.put("TabbedPane.border", BorderFactory.createEmptyBorder()); - table.put("TabbedPane.shadow", null); - table.put("TabbedPane.darkShadow", null); -// table.put("TabbedPane.highlight", MaterialColors.GRAY_200); - table.put("TabbedPane.highlight", UIColor.TABBED_PANE_HIGHLIGHT.get()); -// table.put("TabbedPane.borderHighlightColor", MaterialColors.GRAY_300); - table.put("TabbedPane.borderHighlightColor", UIColor.TABBED_PANE_BORDER_HIGHLIGHT.get()); - -// table.put("Table.selectionBackground", MaterialColors.GRAY_100); - table.put("Table.selectionBackground", UIColor.TABLE_SELECTION_BACKGROUND.get()); -// table.put("Table.selectionForeground", Color.BLACK); - table.put("Table.selectionForeground", UIColor.TABLE_SELECTION_FOREGROUND.get()); -// table.put("Table.background", Color.WHITE); - table.put("Table.background", UIColor.TABLE_BACKGROUND.get()); - table.put("Table.font", MaterialFonts.REGULAR); - table.put("Table.border", MaterialBorders.LIGHT_LINE_BORDER); -// table.put("Table.gridColor", MaterialColors.GRAY_200); - table.put("Table.gridColor", UIColor.TABLE_GRID_COLOR.get()); -// table.put("TableHeader.background", MaterialColors.GRAY_200); - table.put("TableHeader.background", UIColor.TABLE_HEADER_BACKGROUND.get()); - table.put("TableHeader.font", MaterialFonts.BOLD); - table.put( - "TableHeader.cellBorder", - BorderFactory.createCompoundBorder( - MaterialBorders.LIGHT_LINE_BORDER, - BorderFactory.createEmptyBorder(5, 5, 5, 5))); - -// table.put("TextArea.background", MaterialColors.GRAY_200); - table.put("TextArea.background", UIColor.TEXT_AREA_BACKGROUND.get()); - table.put("TextArea.border", BorderFactory.createEmptyBorder()); -// table.put("TextArea.foreground", Color.BLACK); - table.put("TextArea.foreground", UIColor.TEXT_AREA_FOREGROUND.get()); - - table.put("ToggleButton.border", BorderFactory.createEmptyBorder()); - table.put("ToggleButton.font", MaterialFonts.REGULAR); -// table.put("ToggleButton.background", Color.WHITE); - table.put("ToggleButton.background", UIColor.TOGGLE_BUTTON_BACKGROUND.get()); -// table.put("ToggleButton.foreground", Color.BLACK); - table.put("ToggleButton.foreground", UIColor.TOGGLE_BUTTON_FOREGROUND.get()); - table.put("ToggleButton.icon", new ImageIcon(MaterialImages.TOGGLE_BUTTON_OFF)); - table.put("ToggleButton.selectedIcon", new ImageIcon(MaterialImages.TOGGLE_BUTTON_ON)); - - table.put("ToolBar.font", MaterialFonts.REGULAR); -// table.put("ToolBar.background", Color.WHITE); - table.put("ToolBar.background", UIColor.TOOL_BAR_BACKGROUND.get()); -// table.put("ToolBar.foreground", Color.BLACK); - table.put("ToolBar.foreground", UIColor.TOOL_BAR_FOREGROUND.get()); - table.put("ToolBar.border", MaterialBorders.LIGHT_SHADOW_BORDER); -// table.put("ToolBar.dockingBackground", MaterialColors.LIGHT_GREEN_A100); - table.put("ToolBar.dockingBackground", UIColor.TOOL_BAR_DOCKING_BACKGROUND.get()); -// table.put("ToolBar.floatingBackground", MaterialColors.GRAY_200); - table.put("ToolBar.floatingBackground", UIColor.TOOL_BAR_FLOATING_BACKGROUND.get()); - - table.put("Tree.font", MaterialFonts.REGULAR); -// table.put("Tree.selectionForeground", Color.BLACK); - table.put("Tree.selectionForeground", UIColor.TREE_SELECTION_FOREGROUND.get()); -// table.put("Tree.foreground", Color.BLACK); - table.put("Tree.foreground", UIColor.TREE_FOREGROUND.get()); -// table.put("Tree.selectionBackground", MaterialColors.GRAY_200); - table.put("Tree.selectionBackground", UIColor.TREE_SELECTION_BACKGROUND.get()); -// table.put("Tree.background", Color.WHITE); - table.put("Tree.background", UIColor.TREE_BACKGROUND.get()); - table.put("Tree.closedIcon", new ImageIcon(MaterialImages.RIGHT_ARROW)); - table.put("Tree.openIcon", new ImageIcon(MaterialImages.DOWN_ARROW)); - table.put("Tree.selectionBorderColor", null); - -// table.put("RadioButtonMenuItem.foreground", Color.BLACK); - table.put("RadioButtonMenuItem.foreground", UIColor.RADIO_BUTTON_FOREGROUND.get()); -// table.put("RadioButtonMenuItem.selectionForeground", Color.BLACK); - table.put("RadioButtonMenuItem.selectionForeground", UIColor.RADIO_BUTTON_MENU_ITEM_SELECTION_FOREGROUND.get()); - // If it changes the background of the menuitem it must change this too, irrespective of its - // setting - table.put("RadioButtonMenuItem.background", UIManager.getColor("MenuItem.background")); -// table.put("RadioButtonMenuItem.selectionBackground", MaterialColors.GRAY_200); - table.put("RadioButtonMenuItem.selectionBackground", UIColor.RADIO_BUTTON_MENU_ITEM_SELECTION_BACKGROUND.get()); - table.put("RadioButtonMenuItem.border", BorderFactory.createEmptyBorder(5, 5, 5, 5)); - table.put("RadioButtonMenuItem.checkIcon", new ImageIcon(MaterialImages.RADIO_BUTTON_OFF)); - table.put( - "RadioButtonMenuItem.selectedCheckIcon", - new ImageIcon(MaterialImages.RADIO_BUTTON_ON)); - - // If it changes the background of the menuitem it must change this too, irrespective of its - // setting - table.put("CheckBoxMenuItem.background", UIManager.getColor("MenuItem.background")); -// table.put("CheckBoxMenuItem.selectionBackground", MaterialColors.GRAY_200); - table.put("CheckBoxMenuItem.selectionBackground", UIColor.CHECKBOX_MENU_ITEM_SELECTION_BACKGROUND.get()); -// table.put("CheckBoxMenuItem.foreground", Color.BLACK); - table.put("CheckBoxMenuItem.foreground", UIColor.CHECKBOX_MENU_ITEM_FOREGROUND.get()); -// table.put("CheckBoxMenuItem.selectionForeground", Color.BLACK); - table.put("CheckBoxMenuItem.selectionForeground", UIColor.CHECKBOX_MENU_ITEM_SELECTION_FOREGROUND.get()); - table.put("CheckBoxMenuItem.border", BorderFactory.createEmptyBorder(5, 5, 5, 5)); - table.put("CheckBoxMenuItem.checkIcon", new ImageIcon(MaterialImages.UNCHECKED_BOX)); - table.put( - "CheckBoxMenuItem.selectedCheckIcon", - new ImageIcon(MaterialImages.PAINTED_CHECKED_BOX)); - - table.put("TextPane.border", MaterialBorders.LIGHT_LINE_BORDER); -// table.put("TextPane.background", MaterialColors.GRAY_50); - table.put("TextPane.background", UIColor.TEXT_PANE_BACKGROUND.get()); -// table.put("TextPane.selectionBackground", MaterialColors.LIGHT_BLUE_200); - table.put("TextPane.selectionBackground", UIColor.TEXT_PANE_SELECTION_BACKGROUND.get()); -// table.put("TextPane.inactiveForeground", MaterialColors.GRAY_500); - table.put("TextPane.inactiveForeground", UIColor.TEXT_PANE_INACTIVE_FOREGROUND.get()); - table.put("TextPane.font", MaterialFonts.REGULAR); - - table.put("EditorPane.border", MaterialBorders.LIGHT_LINE_BORDER); -// table.put("EditorPane.background", MaterialColors.GRAY_50); - table.put("EditorPane.background", UIColor.EDITOR_PANE_BACKGROUND.get()); -// table.put("EditorPane.selectionBackground", MaterialColors.LIGHT_BLUE_200); - table.put("EditorPane.selectionBackground", UIColor.EDITOR_PANE_SELECTION_BACKGROUND.get()); -// table.put("EditorPane.inactiveForeground", MaterialColors.GRAY_500); - table.put("EditorPane.inactiveForeground", UIColor.EDITOR_PANE_INACTIVE_FOREGROUND.get()); - table.put("EditorPane.font", MaterialFonts.REGULAR); - -// table.put("Separator.background", MaterialColors.GRAY_300); - table.put("Separator.background", UIColor.SEPARATOR_BACKGROUND.get()); -// table.put("Separator.foreground", MaterialColors.GRAY_300); - table.put("Separator.foreground", UIColor.SEPARATOR_FOREGROUND.get()); - -// table.put("ToolTip.background", MaterialColors.GRAY_500); - table.put("ToolTip.background", UIColor.TOOL_TIP_BACKGROUND.get()); -// table.put("ToolTip.foreground", MaterialColors.GRAY_50); - table.put("ToolTip.foreground", UIColor.TOOL_TIP_FOREGROUND.get()); - table.put("ToolTip.border", BorderFactory.createEmptyBorder(5, 5, 5, 5)); - -// table.put("ColorChooser.background", MaterialColors.WHITE); - table.put("ColorChooser.background", UIColor.COLOR_CHOOSER_BACKGROUND.get()); -// table.put("ColorChooser.foreground", MaterialColors.BLACK); - table.put("ColorChooser.foreground", UIColor.COLOR_CHOOSER_FOREGROUND.get()); - } -} diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialButtonUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialButtonUI.java index 9d7461ccc..0850221a1 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialButtonUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialButtonUI.java @@ -23,7 +23,7 @@ public void installUI(JComponent c) { super.installUI(c); AbstractButton button = (AbstractButton) c; - MaterialUIMovement.add(c, UIColor.UI_MOVEMENT.get()); + MaterialUIMovement.add(c, UIColor.UI_MOVEMENT.getOrThrow()); button.setOpaque(UIManager.getBoolean("Button.opaque")); button.setBorder(UIManager.getBorder("Button.border")); button.setBackground(UIManager.getColor("Button.background")); diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialPasswordFieldUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialPasswordFieldUI.java index be9bbfb86..668164923 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialPasswordFieldUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialPasswordFieldUI.java @@ -46,10 +46,10 @@ public void installUI(JComponent c) { JPasswordField passwordField = (JPasswordField) c; passwordField.setOpaque(false); passwordField.setBorder(BorderFactory.createEmptyBorder(5, 2, 10, 0)); - passwordField.setBackground(UIColor.PASSWORD_FIELD_BACKGROUND.get()); + passwordField.setBackground(UIColor.PASSWORD_FIELD_BACKGROUND.getOrThrow()); this.focusedBackground = passwordField.getBackground(); - this.unfocusedBackground = UIColor.PASSWORD_FIELD_UNFOCUSED_BACKGROUND.get(); + this.unfocusedBackground = UIColor.PASSWORD_FIELD_UNFOCUSED_BACKGROUND.getOrThrow(); this.focusedSelectionBackground = MaterialColors.bleach(focusedBackground, 0.3f); this.unfocusedSelectionBackground = unfocusedBackground; diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialProgressBarUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialProgressBarUI.java index edb39c9fa..2143eaaed 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialProgressBarUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialProgressBarUI.java @@ -25,8 +25,8 @@ public void installUI(JComponent c) { JProgressBar progressBar = (JProgressBar) c; progressBar.setBorder(MaterialBorders.LIGHT_LINE_BORDER); - progressBar.setBackground(UIColor.PROGRESS_BAR_BACKGROUND.get()); - progressBar.setForeground(UIColor.PROGRESS_BAR_FOREGROUND.get()); + progressBar.setBackground(UIColor.PROGRESS_BAR_BACKGROUND.getOrThrow()); + progressBar.setForeground(UIColor.PROGRESS_BAR_FOREGROUND.getOrThrow()); } @Override diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTextFieldUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTextFieldUI.java index b980d81f8..f724f5b66 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTextFieldUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTextFieldUI.java @@ -55,11 +55,11 @@ public void installUI(JComponent c) { ? BorderFactory.createEmptyBorder(5, 2, 10, 0) : BorderFactory.createEmptyBorder(2, 2, 2, 2)); - textField.setBackground(UIColor.TEXT_FIELD_BACKGROUND.get()); + textField.setBackground(UIColor.TEXT_FIELD_BACKGROUND.getOrThrow()); textField.setFont(MaterialFonts.REGULAR); this.focusedBackground = textField.getBackground(); - this.unfocusedBackground = UIColor.TEXT_FIELD_UNFOCUSED_BACKGROUND.get(); + this.unfocusedBackground = UIColor.TEXT_FIELD_UNFOCUSED_BACKGROUND.getOrThrow(); this.focusedSelectionBackground = MaterialColors.bleach(focusedBackground, 0.3f); this.unfocusedSelectionBackground = unfocusedBackground; diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialBorders.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialBorders.java index cf27e7265..68ad0e95c 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialBorders.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialBorders.java @@ -8,9 +8,9 @@ public class MaterialBorders { public static final Border LIGHT_LINE_BORDER = - BorderFactory.createLineBorder(UIColor.LIGHT_LINE_BORDER.get(), 1); + BorderFactory.createLineBorder(UIColor.LIGHT_LINE_BORDER.getOrThrow(), 1); public static final Border THICK_LINE_BORDER = - BorderFactory.createLineBorder(UIColor.THICK_LINE_BORDER.get(), 2); + BorderFactory.createLineBorder(UIColor.THICK_LINE_BORDER.getOrThrow(), 2); public static final Border LIGHT_SHADOW_BORDER = new DropShadowBorder(Color.BLACK, 0, 4, 0.3f, 12, true, true, true, true); diff --git a/src/main/resources/light-color-theme.txt b/src/main/resources/light-color-theme.txt index 5c45bc71b..a346dcf1f 100644 --- a/src/main/resources/light-color-theme.txt +++ b/src/main/resources/light-color-theme.txt @@ -14,7 +14,7 @@ thick-line-border: GRAY_200 data-selection-background: GRAY element-view: BLACK button-highlight: GRAY_300 -button-background: GRAY_200 +button-background: WHITE button-foreground: BLACK checkbox-background: WHITE checkbox-foreground: BLACK From 1f743bdf2db4aabf46432c074c2e293d9c76c35e Mon Sep 17 00:00:00 2001 From: FisherLuba <145061313+FisherLuba@users.noreply.github.com> Date: Tue, 9 Apr 2024 17:40:09 -0400 Subject: [PATCH 08/10] Fix global defaults not being removed when unchecking use custom color scheme. --- src/main/java/edu/rpi/legup/ui/LegupUI.java | 4 ++++ src/main/resources/light-color-theme.txt | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/edu/rpi/legup/ui/LegupUI.java b/src/main/java/edu/rpi/legup/ui/LegupUI.java index 03e0f1bb9..16539ee8c 100644 --- a/src/main/java/edu/rpi/legup/ui/LegupUI.java +++ b/src/main/java/edu/rpi/legup/ui/LegupUI.java @@ -1,6 +1,7 @@ package edu.rpi.legup.ui; import com.formdev.flatlaf.FlatDarkLaf; +import com.formdev.flatlaf.FlatLaf; import com.formdev.flatlaf.FlatLightLaf; import edu.rpi.legup.app.GameBoardFacade; import edu.rpi.legup.app.LegupPreferences; @@ -18,6 +19,7 @@ import java.awt.event.WindowListener; import java.io.File; import java.security.InvalidParameterException; +import java.util.Collections; import java.util.Objects; public class LegupUI extends JFrame implements WindowListener { @@ -55,6 +57,8 @@ public static void updateColorTheme() { } if (isTxt && useCustomColorTheme) { LegupCustomColorScheme.setupCustomColorScheme(colorFileName); + } else { + FlatLaf.setGlobalExtraDefaults(Collections.emptyMap()); } if (LegupPreferences.darkMode()) { diff --git a/src/main/resources/light-color-theme.txt b/src/main/resources/light-color-theme.txt index a346dcf1f..5c45bc71b 100644 --- a/src/main/resources/light-color-theme.txt +++ b/src/main/resources/light-color-theme.txt @@ -14,7 +14,7 @@ thick-line-border: GRAY_200 data-selection-background: GRAY element-view: BLACK button-highlight: GRAY_300 -button-background: WHITE +button-background: GRAY_200 button-foreground: BLACK checkbox-background: WHITE checkbox-foreground: BLACK From 2dcfc26ee9abe1f8d8b82c689a6555f1313f71c0 Mon Sep 17 00:00:00 2001 From: FisherLuba <145061313+FisherLuba@users.noreply.github.com> Date: Tue, 16 Apr 2024 16:20:00 -0400 Subject: [PATCH 09/10] Grouped dark mode, color theme, and colorblind preferences together. Also hid color theme file option if custom color theme is not selected. --- .../edu/rpi/legup/ui/PreferencesDialog.java | 61 ++++++++++++------- .../rpi/legup/ui/color/ColorPreferences.java | 1 - 2 files changed, 40 insertions(+), 22 deletions(-) diff --git a/src/main/java/edu/rpi/legup/ui/PreferencesDialog.java b/src/main/java/edu/rpi/legup/ui/PreferencesDialog.java index 2ba6035d5..901aa2aef 100644 --- a/src/main/java/edu/rpi/legup/ui/PreferencesDialog.java +++ b/src/main/java/edu/rpi/legup/ui/PreferencesDialog.java @@ -3,7 +3,6 @@ import edu.rpi.legup.app.LegupPreferences; import edu.rpi.legup.model.Puzzle; import edu.rpi.legup.model.rules.Rule; -import edu.rpi.legup.ui.color.ColorPreferences; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialBorders; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialFonts; import edu.rpi.legup.ui.proofeditorui.rulesview.RuleFrame; @@ -39,8 +38,8 @@ public class PreferencesDialog extends JDialog { immFeedback, colorBlind; - private JTextField workDirectory; - private JTextField colorThemeFile; + private FileChooserComponents workDirectory; + private FileChooserComponents colorThemeFile; private static Image folderIcon; @@ -162,7 +161,25 @@ private void addRowLabel(JPanel contentPane, String title) { contentPane.add(createLineSeparator()); } - private JTextField addFileChooser( + private record FileChooserComponents(JTextField file, JButton openFile, JLabel label) { + + private void setEnabled(boolean enabled) { + file.setVisible(enabled); + openFile.setVisible(enabled); + label.setVisible(enabled); + } + + private void disable() { + setEnabled(false); + } + + private void enable() { + setEnabled(true); + } + + } + + private FileChooserComponents addFileChooser( JPanel contentPane, String label, String hoverText, @@ -200,7 +217,7 @@ private JTextField addFileChooser( row.add(openFile, BorderLayout.EAST); row.setMaximumSize(new Dimension(Integer.MAX_VALUE, row.getPreferredSize().height)); contentPane.add(row); - return file; + return new FileChooserComponents(file, openFile, fileLabel); } private JScrollPane createGeneralTab() { @@ -233,19 +250,6 @@ private JScrollPane createGeneralTab() { "If checked this automatically checks for updates on startup of Legup", contentPane ); - darkMode = addDefaultCheckBox( - "Dark Mode", - LegupPreferences.darkMode(), - "This turns dark mode on and off", - contentPane - ); - customColorTheme = addDefaultCheckBox( - "Custom Color Theme", - LegupPreferences.useCustomColorTheme(), - "This turns custom color theme on and off", - contentPane - ); - addRowLabel(contentPane, "Board View Preferences"); showMistakes = addDefaultCheckBox( @@ -303,7 +307,21 @@ private JScrollPane createGeneralTab() { new JCheckBox( "Deuteranomaly(red/green colorblindness)", LegupPreferences.colorBlind()); - + darkMode = addDefaultCheckBox( + "Dark Mode", + LegupPreferences.darkMode(), + "This turns dark mode on and off", + contentPane + ); + customColorTheme = addDefaultCheckBox( + "Custom Color Theme", + LegupPreferences.useCustomColorTheme(), + "This turns custom color theme on and off", + contentPane + ); + customColorTheme.addActionListener(event -> { + colorThemeFile.setEnabled(customColorTheme.isSelected()); + }); colorThemeFile = addFileChooser( contentPane, "Color Theme File", @@ -313,6 +331,7 @@ private JScrollPane createGeneralTab() { "Choose color theme file", JFileChooser.FILES_ONLY ); + colorThemeFile.setEnabled(customColorTheme.isSelected()); scrollPane.setViewportView(contentPane); return scrollPane; @@ -434,7 +453,7 @@ private JSeparator createLineSeparator() { public void applyPreferences() { LegupPreferences prefs = LegupPreferences.getInstance(); - prefs.setUserPref(LegupPreferences.LegupPreference.WORK_DIRECTORY, workDirectory.getText()); + prefs.setUserPref(LegupPreferences.LegupPreference.WORK_DIRECTORY, workDirectory.file.getText()); prefs.setUserPref( LegupPreferences.LegupPreference.START_FULL_SCREEN, fullScreen.isSelected()); prefs.setUserPref(LegupPreferences.LegupPreference.AUTO_UPDATE, autoUpdate.isSelected()); @@ -451,7 +470,7 @@ public void applyPreferences() { prefs.setUserPref( LegupPreferences.LegupPreference.IMMEDIATE_FEEDBACK, immFeedback.isSelected()); prefs.setUserPref(LegupPreferences.LegupPreference.COLOR_BLIND, colorBlind.isSelected()); - prefs.setUserPref(LegupPreferences.LegupPreference.COLOR_THEME_FILE, colorThemeFile.getText()); + prefs.setUserPref(LegupPreferences.LegupPreference.COLOR_THEME_FILE, colorThemeFile.file.getText()); if (rulesFrame != null) { rulesFrame.getCasePanel().updateRules(); diff --git a/src/main/java/edu/rpi/legup/ui/color/ColorPreferences.java b/src/main/java/edu/rpi/legup/ui/color/ColorPreferences.java index 225b50379..5261da69e 100644 --- a/src/main/java/edu/rpi/legup/ui/color/ColorPreferences.java +++ b/src/main/java/edu/rpi/legup/ui/color/ColorPreferences.java @@ -3,7 +3,6 @@ //import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialColors; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialColors; -import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Unmodifiable; import java.awt.*; From d4c244bea790efa3bf3ca70730a4a578d0cc335b Mon Sep 17 00:00:00 2001 From: FisherLuba Date: Sat, 1 Jun 2024 11:25:19 -0400 Subject: [PATCH 10/10] Fix using current directory appended to file path when creating a new puzzle --- src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java b/src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java index 5cadc4885..c3681d904 100644 --- a/src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java +++ b/src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java @@ -570,7 +570,7 @@ private String savePuzzle() { String fileName = null; if (fileChooser.getCurrentDirectory() != null && fileChooser.getSelectedFile() != null) { - fileName = fileChooser.getCurrentDirectory() + File.separator + fileChooser.getSelectedFile(); + fileName = fileChooser.getSelectedFile().getAbsolutePath(); } if (fileName != null) { @@ -584,6 +584,7 @@ private String savePuzzle() { e.printStackTrace(); } } + return fileName; }