From 271b0c6524e6291724aa6146fc4827b8303972e3 Mon Sep 17 00:00:00 2001 From: N-Desmarais <55117352+N-Desmarais@users.noreply.github.com> Date: Tue, 4 Apr 2023 17:22:02 -0400 Subject: [PATCH] Fixes 502 (#519) * Update TreeTentController.java (#518) * Issue 513 (#517) * Revert "Update PuzzleEditorPanel.java" * Update SkyscrapersBoard.java * input and updated descriptions for @return and @throws * Update Puzzle.java * Update ScrollView.java * Update WrapLayout.java * Update NumberTile.java * Update DropShadowBorder.java * Erased irrelevant code * Update Puzzle.java --------- Co-authored-by: Charles Tian <46334090+charlestian23@users.noreply.github.com> Co-authored-by: Ivan Ho <41582274+Corppet@users.noreply.github.com> * Fixes 502 * fixed loadImage() to use a temp name so the settings arent locked to colorblind permanently * made the preferences dialog dispose itself properly * added a reference to the rules frame in the preference dialog * added updateRules() function to ruleFrame that updates rule images --------- Co-authored-by: jason pu Co-authored-by: Maitri Bijur <122646363+Mbijur@users.noreply.github.com> Co-authored-by: Charles Tian <46334090+charlestian23@users.noreply.github.com> Co-authored-by: Ivan Ho <41582274+Corppet@users.noreply.github.com> --- .../java/edu/rpi/legup/model/rules/Rule.java | 9 +++++---- .../edu/rpi/legup/ui/PreferencesDialog.java | 19 +++++++++++++++++++ .../edu/rpi/legup/ui/ProofEditorPanel.java | 8 +------- .../ui/proofeditorui/rulesview/RulePanel.java | 7 +++++++ 4 files changed, 32 insertions(+), 11 deletions(-) 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 2e3c4da60..50f2cf962 100644 --- a/src/main/java/edu/rpi/legup/model/rules/Rule.java +++ b/src/main/java/edu/rpi/legup/model/rules/Rule.java @@ -84,13 +84,14 @@ public Rule(String ruleID, String ruleName, String description, String imageName /** * Loads the image file */ - private void loadImage() { + public void loadImage() { if (imageName != null) { + String name = imageName; LegupPreferences prefs = LegupPreferences.getInstance(); - if (imageName.contains("shorttruthtable") && prefs.getUserPref(LegupPreferences.COLOR_BLIND).equals("true")) { - imageName = imageName.replace("ruleimages", "ruleimages_cb"); + if (name.contains("shorttruthtable") && prefs.getUserPref(LegupPreferences.COLOR_BLIND).equals("true")) { + name = name.replace("ruleimages", "ruleimages_cb"); } - this.image = new ImageIcon(ClassLoader.getSystemClassLoader().getResource(imageName)); + this.image = new ImageIcon(ClassLoader.getSystemClassLoader().getResource(name)); //Resize images to be 100px wide Image image = this.image.getImage(); if (this.image.getIconWidth() < 120) return; diff --git a/src/main/java/edu/rpi/legup/ui/PreferencesDialog.java b/src/main/java/edu/rpi/legup/ui/PreferencesDialog.java index 135b44587..4eee69d4d 100644 --- a/src/main/java/edu/rpi/legup/ui/PreferencesDialog.java +++ b/src/main/java/edu/rpi/legup/ui/PreferencesDialog.java @@ -17,9 +17,14 @@ import com.formdev.flatlaf.FlatLightLaf; import com.formdev.flatlaf.FlatDarkLaf; +import edu.rpi.legup.ui.proofeditorui.rulesview.RuleFrame; +import edu.rpi.legup.ui.proofeditorui.rulesview.RulePanel; public class PreferencesDialog extends JDialog { + + private RuleFrame rulesFrame; + private final static Logger LOGGER = Logger.getLogger(PreferencesDialog.class.getName()); private JCheckBox fullScreen, autoUpdate, darkMode, showMistakes, showAnnotations, allowDefault, generateCases, immFeedback, colorBlind; @@ -37,6 +42,12 @@ public class PreferencesDialog extends JDialog { } } + public static PreferencesDialog CreateDialogForProofEditor(Frame frame, RuleFrame rules) { + PreferencesDialog p = new PreferencesDialog(frame); + p.rulesFrame = rules; + return p; + } + public PreferencesDialog(Frame frame) { super(frame); @@ -58,11 +69,13 @@ public PreferencesDialog(Frame frame) { okButton.addActionListener(l -> { applyPreferences(); this.setVisible(false); + this.dispose(); }); toolbar.add(okButton); JButton cancelButton = new JButton("Cancel"); cancelButton.addActionListener(l -> { this.setVisible(false); + this.dispose(); }); toolbar.add(cancelButton); JButton applyButton = new JButton("Apply"); @@ -350,6 +363,12 @@ public void applyPreferences() { prefs.setUserPref(LegupPreferences.IMMEDIATE_FEEDBACK, Boolean.toString(immFeedback.isSelected())); prefs.setUserPref(LegupPreferences.COLOR_BLIND, Boolean.toString(colorBlind.isSelected())); + if(rulesFrame != null) { + rulesFrame.getCasePanel().updateRules(); + rulesFrame.getDirectRulePanel().updateRules(); + rulesFrame.getContradictionPanel().updateRules(); + } + // toggle dark mode based on updated NIGHT_MODE variable toggleDarkMode(prefs); } diff --git a/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java b/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java index 76b5c8032..3d04d187b 100644 --- a/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java +++ b/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java @@ -1,10 +1,5 @@ package edu.rpi.legup.ui; -import org.xml.sax.*; -import org.xml.sax.helpers.*; - -import javax.xml.parsers.*; - import edu.rpi.legup.app.GameBoardFacade; import edu.rpi.legup.app.LegupPreferences; import edu.rpi.legup.controller.BoardController; @@ -270,7 +265,7 @@ public JMenuBar getMenuBar() { // preference file.add(preferences); preferences.addActionListener(a -> { - PreferencesDialog preferencesDialog = new PreferencesDialog(this.frame); + PreferencesDialog preferencesDialog = PreferencesDialog.CreateDialogForProofEditor(this.frame, this.ruleFrame); }); file.addSeparator(); @@ -761,7 +756,6 @@ public void setPuzzleView(Puzzle puzzle) { ruleFrame.getCasePanel().setRules(puzzle.getCaseRules()); ruleFrame.getContradictionPanel().setRules(puzzle.getContradictionRules()); ruleFrame.getSearchPanel().setSearchBar(puzzle); -// ruleFrame.getSearchPanel().setRules(puzzle.getBasicRules()); toolBarButtons[ToolbarName.CHECK.ordinal()].setEnabled(true); diff --git a/src/main/java/edu/rpi/legup/ui/proofeditorui/rulesview/RulePanel.java b/src/main/java/edu/rpi/legup/ui/proofeditorui/rulesview/RulePanel.java index 8c28215b3..77dff5744 100644 --- a/src/main/java/edu/rpi/legup/ui/proofeditorui/rulesview/RulePanel.java +++ b/src/main/java/edu/rpi/legup/ui/proofeditorui/rulesview/RulePanel.java @@ -71,6 +71,13 @@ public void setRules(List rules) { revalidate(); } + public void updateRules() { + for (Rule rule : rules){ + rule.loadImage(); + } + setRules(rules); + } + /** * Search a certain rule in all the puzzles and set it for the searchBarPanel