Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI colors #765

Open
wants to merge 13 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/main/java/edu/rpi/legup/Legup.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
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 {

/**
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/edu/rpi/legup/app/LegupPreferences.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
Expand All @@ -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));
Expand All @@ -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 {
Expand Down Expand Up @@ -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)));
}

/**
Expand Down Expand Up @@ -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;
}
}
11 changes: 6 additions & 5 deletions src/main/java/edu/rpi/legup/ui/DynamicView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/edu/rpi/legup/ui/HomePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
30 changes: 21 additions & 9 deletions src/main/java/edu/rpi/legup/ui/LegupUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
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.*;
import java.io.File;
import java.security.InvalidParameterException;
import java.util.Objects;
import javax.swing.*;
Expand All @@ -17,7 +20,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;

Expand All @@ -43,16 +47,24 @@ 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");
}

fileDialog = new FileDialog(this);
// fileDialog = new FileDialog(this);
fileChooser = new JFileChooser();
fileChooser.setCurrentDirectory(new File(LegupPreferences.WORK_DIRECTORY));

initPanels();
displayPanel(0);
Expand Down Expand Up @@ -97,9 +109,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) {
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/edu/rpi/legup/ui/PreferencesDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -34,6 +35,7 @@ public class PreferencesDialog extends JDialog {
colorBlind;

private JTextField workDirectory;
private JTextField colorThemeFile;

private static Image folderIcon;

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
Expand Down
27 changes: 16 additions & 11 deletions src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -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;
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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) {
Expand Down
Loading
Loading