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 saving function to save the proof in the current file #326

Merged
merged 9 commits into from
Oct 21, 2022
37 changes: 33 additions & 4 deletions src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class ProofEditorPanel extends LegupPanel implements IHistoryListener {

private JButton[] toolBarButtons;
private JMenu file;
private JMenuItem newPuzzle, resetPuzzle, saveProof, preferences, exit;
private JMenuItem newPuzzle, resetPuzzle, saveProof, preferences, exit, directSave;
private JMenu edit;
private JMenuItem undo, redo, fitBoardToScreen, fitTreeToScreen;

Expand Down Expand Up @@ -114,8 +114,8 @@ public JMenuBar getMenuBar() {
file = new JMenu("File");
newPuzzle = new JMenuItem("Open");
resetPuzzle = new JMenuItem("Reset Puzzle");
// genPuzzle = new JMenuItem("Puzzle Generators");
saveProof = new JMenuItem("Save Proof");
saveProof = new JMenuItem("Save Proof As");
directSave= new JMenuItem("Direct Save Proof");
preferences = new JMenuItem("Preferences");
exit = new JMenuItem("Exit");

Expand Down Expand Up @@ -250,7 +250,14 @@ public JMenuBar getMenuBar() {
else {
saveProof.setAccelerator(KeyStroke.getKeyStroke('S', InputEvent.CTRL_DOWN_MASK));
}

file.add(directSave);
directSave.addActionListener((ActionEvent) -> direct_save());
if (os.equals("mac")) {
directSave.setAccelerator(KeyStroke.getKeyStroke('D', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
}
else {
directSave.setAccelerator(KeyStroke.getKeyStroke('D', InputEvent.CTRL_DOWN_MASK));
}
file.add(preferences);
preferences.addActionListener(a -> {
PreferencesDialog preferencesDialog = new PreferencesDialog(this.frame);
Expand Down Expand Up @@ -374,6 +381,28 @@ public void loadPuzzle(String fileName, File puzzleFile) {
}
}

/**
* direct Saves the current prdoof in current file
*/
private void direct_save(){
Puzzle puzzle = GameBoardFacade.getInstance().getPuzzleModule();
if (puzzle == null) {
return;
}
String fileName = GameBoardFacade.getInstance().getCurFileName();
if (fileName != null) {
try {
PuzzleExporter exporter = puzzle.getExporter();
if (exporter == null) {
throw new ExportFileException("Puzzle exporter null");
}
exporter.exportPuzzle(fileName);
}
catch (ExportFileException e) {
e.printStackTrace();
}
}
}
/**
* Saves a proof
*/
Expand Down
34 changes: 33 additions & 1 deletion src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,17 @@ public void setMenuBar() {
newPuzzle.setAccelerator(KeyStroke.getKeyStroke('N', InputEvent.CTRL_DOWN_MASK));
}
// file>save
JMenuItem savePuzzle = new JMenuItem("Save");
JMenuItem savePuzzle = new JMenuItem("Save Proof As");
savePuzzle.addActionListener((ActionEvent) -> savePuzzle());
JMenuItem directSavePuzzle = new JMenuItem("Direct Save Proof ");
directSavePuzzle.addActionListener((ActionEvent) -> direct_save());
if (os.equals("mac")) {
newPuzzle.setAccelerator(KeyStroke.getKeyStroke('D', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
}
else {
newPuzzle.setAccelerator(KeyStroke.getKeyStroke('D', InputEvent.CTRL_DOWN_MASK));
}

JMenuItem exit = new JMenuItem("Exit");
exit.addActionListener((ActionEvent) -> this.legupUI.displayPanel(0));
if (os.equals("mac")) {
Expand All @@ -115,6 +124,7 @@ public void setMenuBar() {
}
menus[0].add(newPuzzle);
menus[0].add(savePuzzle);
menus[0].add(directSavePuzzle);
menus[0].add(exit);

// EDIT
Expand Down Expand Up @@ -353,6 +363,26 @@ public void setPuzzleView(Puzzle puzzle) {
/**
* Saves a puzzle
*/

private void direct_save(){
Puzzle puzzle = GameBoardFacade.getInstance().getPuzzleModule();
if (puzzle == null) {
return;
}
String fileName = GameBoardFacade.getInstance().getCurFileName();
if (fileName != null) {
try {
PuzzleExporter exporter = puzzle.getExporter();
if (exporter == null) {
throw new ExportFileException("Puzzle exporter null");
}
exporter.exportPuzzle(fileName);
}
catch (ExportFileException e) {
e.printStackTrace();
}
}
}
private void savePuzzle() {
Puzzle puzzle = GameBoardFacade.getInstance().getPuzzleModule();
if (puzzle == null) {
Expand Down Expand Up @@ -398,4 +428,6 @@ public DynamicView getDynamicBoardView() {
return dynamicBoardView;
}



}