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

File Explorer Changes #318

Merged
merged 7 commits into from
Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions src/main/java/edu/rpi/legup/puzzle/masyu/MasyuCell.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public MasyuType getType() {
return MasyuType.BLACK;
case 2:
return MasyuType.WHITE;
case 3:
return MasyuType.LINE;
default:
return null;
}
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/edu/rpi/legup/puzzle/masyu/MasyuController.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,22 @@ public void mouseReleased(MouseEvent e) {
masyuLine.clear();
}

/**
* Alters the cells as they are being dragged over or clicked
* @param e Mouse event being used
* @param data Data of selected cell
*/
@Override
public void changeCell(MouseEvent e, PuzzleElement data) {

MasyuCell cell = (MasyuCell) data;
if(cell.getData() == 1 || cell.getData() == 2) {
return;
}
if(cell.getData() == 0) {
data.setData(3);
}
else {
data.setData(0);
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/edu/rpi/legup/puzzle/masyu/MasyuType.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package edu.rpi.legup.puzzle.masyu;

public enum MasyuType {
UNKNOWN, BLACK, WHITE
UNKNOWN, BLACK, WHITE, LINE
}
25 changes: 15 additions & 10 deletions src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ public JMenuBar getMenuBar() {
return mBar;
}

// File opener
public Object[] promptPuzzle() {
GameBoardFacade facade = GameBoardFacade.getInstance();
if (facade.getBoard() != null) {
Expand All @@ -324,19 +325,21 @@ public Object[] promptPuzzle() {
}
}

if (fileDialog == null) {
fileDialog = new FileDialog(this.frame);
}
LegupPreferences preferences = LegupPreferences.getInstance();
File preferredDirectory = new File(preferences.getUserPref(LegupPreferences.WORK_DIRECTORY));
folderBrowser = new JFileChooser(preferredDirectory);
folderBrowser.setDialogTitle("Select Proof File");
folderBrowser.showOpenDialog(this);
folderBrowser.setFileSelectionMode(JFileChooser.FILES_ONLY);
folderBrowser.setAcceptAllFileFilterUsed(true);
folderBrowser.setVisible(true);
String preferredDirectory = preferences.getUserPref(LegupPreferences.WORK_DIRECTORY);

fileDialog.setMode(FileDialog.LOAD);
fileDialog.setTitle("Select Proof File");
fileDialog.setDirectory(preferredDirectory);
fileDialog.setVisible(true);
String fileName = null;
File puzzleFile = folderBrowser.getSelectedFile();
if (folderBrowser.getCurrentDirectory() != null && folderBrowser.getSelectedFile().getName() != null) {
fileName = puzzleFile.getAbsolutePath() + File.separator;
File puzzleFile = null;

if (fileDialog.getDirectory() != null && fileDialog.getFile() != null) {
fileName = fileDialog.getDirectory() + File.separator + fileDialog.getFile();
puzzleFile = new File(fileName);
}

Expand All @@ -361,9 +364,11 @@ public void loadPuzzle(String fileName, File puzzleFile) {
LOGGER.error(e.getMessage());
if (e.getMessage().contains("Proof Tree construction error: could not find rule by ID")) { // TO DO: make error message not hardcoded
JOptionPane.showMessageDialog(null, "This file runs on an outdated version of Legup\nand is not compatible with the current version.", "Error", JOptionPane.ERROR_MESSAGE);
loadPuzzle();
}
else {
JOptionPane.showMessageDialog(null, "File does not exist or it cannot be read", "Error", JOptionPane.ERROR_MESSAGE);
loadPuzzle();
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ public void loadPuzzleFromHome(String game, int rows, int columns) throws Illega
}
}

// File opener
public Object[] promptPuzzle() {
GameBoardFacade facade = GameBoardFacade.getInstance();
if (facade.getBoard() != null) {
Expand All @@ -246,8 +247,12 @@ public Object[] promptPuzzle() {
if (fileDialog == null) {
fileDialog = new FileDialog(this.frame);
}
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);
String fileName = null;
File puzzleFile = null;
Expand Down Expand Up @@ -275,6 +280,8 @@ public void loadPuzzle(String fileName, File puzzleFile) {
}
catch (InvalidFileFormatException e) {
LOGGER.error(e.getMessage());
JOptionPane.showMessageDialog(null, "File does not exist or it cannot be read", "Error", JOptionPane.ERROR_MESSAGE);
loadPuzzle();
}
}
}
Expand Down