Skip to content

Commit

Permalink
Fixes 502 (#519)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: Ivan Ho <[email protected]>

* 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 <[email protected]>
Co-authored-by: Maitri Bijur <[email protected]>
Co-authored-by: Charles Tian <[email protected]>
Co-authored-by: Ivan Ho <[email protected]>
  • Loading branch information
5 people authored Apr 4, 2023
1 parent a735dc1 commit 271b0c6
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
9 changes: 5 additions & 4 deletions src/main/java/edu/rpi/legup/model/rules/Rule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/edu/rpi/legup/ui/PreferencesDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand All @@ -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");
Expand Down Expand Up @@ -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);
}
Expand Down
8 changes: 1 addition & 7 deletions src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ public void setRules(List<? extends Rule> 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
Expand Down

0 comments on commit 271b0c6

Please sign in to comment.