Skip to content

Commit

Permalink
Merge pull request #246 from charlestian23/dev
Browse files Browse the repository at this point in the history
Updated cosmetics and fixed visual bugs
  • Loading branch information
charlestian23 authored Aug 9, 2022
2 parents 3b5ea50 + 1845287 commit 9b63078
Show file tree
Hide file tree
Showing 13 changed files with 183 additions and 64 deletions.
51 changes: 48 additions & 3 deletions src/main/java/edu/rpi/legup/app/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,65 @@ public Config() throws InvalidConfigException {
*
* @return Vector of Puzzle names which are Strings
*/
public List<String> getPuzzleNames() {
return new ArrayList<>(puzzles.keySet());
public List<String> getPuzzleClassNames() {
return new LinkedList<>(puzzles.keySet());
}

/**
* Returns a list of the names of the puzzles which can have puzzles created and edited
* within the proof editor.
* @return the aforementioned list of Strings
*/
public List<String> getFileCreationEnabledPuzzles() {
LinkedList<String> puzzles = new LinkedList<String>();
for (String puzzle : this.puzzles.keySet()) {
for (String puzzle : this.getPuzzleClassNames()) {
if (!this.fileCreationDisabledStatuses.get(puzzle)) {
puzzles.add(puzzle);
}
}
return puzzles;
}

/**
* Converts the class name of the puzzles to their display names. Some examples of the conversion:
* convertClassNameToDisplayName("TreeTent") will return "Tree Tent"
* convertClassNameToDisplayName("Nurikabe") will return "Nurikabe"
*
* @param className the name of the class
* @return
*/
public static String convertClassNameToDisplayName(String className) {
String displayName = "";
for (int i = 0; i < className.length(); i++)
{
if (Character.isUpperCase(className.charAt(i)) && i != 0)
displayName += " ";
displayName += className.charAt(i);
}
return displayName;
}

public static String convertDisplayNameToClassName(String displayName) {
String className = "";
for (int i = 0; i < displayName.length(); i++)
if (displayName.charAt(i) != ' ')
className += displayName;
return className;
}

public List<String> getPuzzleNames() {
List<String> names = new LinkedList<String>();
for (String puzzle : this.getPuzzleClassNames())
names.add(Config.convertClassNameToDisplayName(puzzle));
return names;
}

public List<String> getFileCreationEnabledPuzzleNames() {
List<String> names = new LinkedList<String>();
for (String puzzle : this.getFileCreationEnabledPuzzles())
names.add(Config.convertClassNameToDisplayName(puzzle));
return names;
}

/**
* Gets a {@link edu.rpi.legup.model.Puzzle} class for a puzzle name
Expand Down
10 changes: 3 additions & 7 deletions src/main/java/edu/rpi/legup/ui/CreatePuzzleDialog.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.rpi.legup.ui;

import edu.rpi.legup.app.Config;
import edu.rpi.legup.app.GameBoardFacade;
import edu.rpi.legup.controller.CursorController;

Expand Down Expand Up @@ -105,12 +106,12 @@ public CreatePuzzleDialog(JFrame parent, HomePanel homePanel) {
public void initPuzzles() {
this.games = GameBoardFacade.getInstance().getConfig().getFileCreationEnabledPuzzles().toArray(new String[0]);
Arrays.sort(this.games);
gameBox = new JComboBox(games);
gameBox = new JComboBox(GameBoardFacade.getInstance().getConfig().getFileCreationEnabledPuzzleNames().toArray(new String[0]));
}

public void actionPerformed(ActionEvent e) {
if (e.getSource() == ok) {
String game = (String) gameBox.getSelectedItem();
String game = Config.convertDisplayNameToClassName((String) gameBox.getSelectedItem());
try {
this.homePanel.openEditorWithNewPuzzle(game, Integer.valueOf(this.rows.getText()), Integer.valueOf(this.columns.getText()));
setVisible(false);
Expand All @@ -125,9 +126,4 @@ public void actionPerformed(ActionEvent e) {
}
}
}

private boolean isValidDimensions() {
// Needs to be implemented
return false;
}
}
85 changes: 59 additions & 26 deletions src/main/java/edu/rpi/legup/ui/DynamicView.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,75 @@ public class DynamicView extends JPanel {
private static final Font INFO_FONT = MaterialFonts.REGULAR;
private static final Color INFO_COLOR = MaterialColors.GRAY_900;

public DynamicView(ScrollView scrollView) {
public DynamicView(ScrollView scrollView, DynamicViewType type) {
this.scrollView = scrollView;

setLayout(new BorderLayout());

add(scrollView, CENTER);
add(setUpZoomer(), SOUTH);
add(setUpZoomer(type), SOUTH);
}

private JPanel setUpZoomer() {
/**
* Sets up the zoomer for the given DynamicViewType
* @param type The DynamicView that we are setting up the zoomer for (so
* the zoomer for the board view or the zoomer for the proof
* tree view)
* @return A JPanel containing the zoomer
*/
private JPanel setUpZoomer(DynamicViewType type) {
if (type == DynamicViewType.BOARD)
return setUpBoardZoomer();
else if (type == DynamicViewType.PROOF_TREE)
return setUpProofTreeZoomer();

// Should never reach here; if you reach here, that's a problem!
return null;
}

/**
* Sets up the zoomer for the board view
* @return A JPanel containing the zoomer
*/
private JPanel setUpBoardZoomer() {
final String label = "Resize Board";
ActionListener listener = (ActionListener) -> this.fitBoardViewToScreen();
return this.setUpZoomerHelper(label, listener);
}

/**
* Sets up the zoomer for the proof tree view
* @return A JPanel containing the zoomer
*/
private JPanel setUpProofTreeZoomer() {
final String label = "Resize Proof";
ActionListener listener = (ActionListener) -> GameBoardFacade.getInstance().getLegupUI().getProofEditor().fitTreeViewToScreen();
return this.setUpZoomerHelper(label, listener);
}

/**
* Creates the zoomer
* @param label A string containing the label to be displayed
* on the fit to screen button
* @param listener A listener that determines what the resize
* button will do
* @return A JPanel containing the zoomer
*/
private JPanel setUpZoomerHelper(final String label, ActionListener listener) {
zoomWrapper = new JPanel();
try {
zoomer = new JPanel();
JButton resizeButton = new JButton("Resize");

// Create and add the resize button to the zoomer
JButton resizeButton = new JButton(label);
resizeButton.setEnabled(true);
resizeButton.setSize(100, 50);
resizeButton.addActionListener(listener);
zoomer.add(resizeButton);

JLabel zoomLabel = new JLabel("100%");
zoomLabel.setFont(MaterialFonts.getRegularFont(16f));
zoomer.add(resizeButton);
resizeButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// System.out.println("The resize bottom be click");
reset();
}
});

JSlider zoomSlider = new JSlider(25, 400, 100);

JButton plus = new JButton(new ImageIcon(ImageIO.read(
Expand All @@ -72,16 +116,6 @@ public void actionPerformed(ActionEvent e) {
minus.setFont(MaterialFonts.getRegularFont(10f));
minus.addActionListener((ActionEvent e) -> zoomSlider.setValue(zoomSlider.getValue() - 25));
this.scrollView.setWheelScrollingEnabled(true);
/*this.scrollView.getViewport().addMouseWheelListener(new MouseAdapter() {
public void mouseWheelMoved(MouseWheelEvent e) {
if (e.isControlDown()) {
scrollView.zoom(e.getWheelRotation() * 2, e.getPoint());
} else {
scrollView.zoom(e.getWheelRotation(), e.getPoint());
}
zoomSlider.setValue((int) (scrollView.getScale() * 100));
}
});*/

zoomSlider.setPreferredSize(new Dimension(160, 30));

Expand Down Expand Up @@ -163,10 +197,9 @@ public void reset() {
board1.setModifiable(true);
Dimension bi = new Dimension(1200, 900);
this.getScrollView().zoomFit();
// System.out.println("get into the reset"+UIhight+" "+this.getHeight()+" "+this.getWidth());
// this.getScrollView().zoomTo(UIhight);
// System.out.println("Finish into the reset");

}

protected void fitBoardViewToScreen() {
scrollView.zoomFit();
}
}
6 changes: 6 additions & 0 deletions src/main/java/edu/rpi/legup/ui/DynamicViewType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package edu.rpi.legup.ui;

public enum DynamicViewType {
BOARD,
PROOF_TREE
}
29 changes: 18 additions & 11 deletions src/main/java/edu/rpi/legup/ui/HomePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import java.io.IOException;
import java.net.URI;
import java.net.URL;

public class HomePanel extends LegupPanel {
private final static Logger LOGGER = LogManager.getLogger(HomePanel.class.getName());
Expand Down Expand Up @@ -103,7 +104,8 @@ private void initButtons() {
}
};

ImageIcon button0Icon = new ImageIcon("src/main/resources/edu/rpi/legup/images/Legup/homepanel/proof_file.png");
URL button0IconLocation = ClassLoader.getSystemClassLoader().getResource("edu/rpi/legup/images/Legup/homepanel/proof_file.png");
ImageIcon button0Icon = new ImageIcon(button0IconLocation);
this.buttons[0].setIcon(resizeButtonIcon(button0Icon, this.buttonSize, this.buttonSize));
this.buttons[0].setHorizontalTextPosition(AbstractButton.CENTER);
this.buttons[0].setVerticalTextPosition(AbstractButton.BOTTOM);
Expand All @@ -115,7 +117,8 @@ private void initButtons() {
setMaximumSize(getSize());
}
};
ImageIcon button1Icon = new ImageIcon("src/main/resources/edu/rpi/legup/images/Legup/homepanel/new_puzzle_file.png");
URL button1IconLocation = ClassLoader.getSystemClassLoader().getResource("edu/rpi/legup/images/Legup/homepanel/new_puzzle_file.png");
ImageIcon button1Icon = new ImageIcon(button1IconLocation);
this.buttons[1].setIcon(resizeButtonIcon(button1Icon, this.buttonSize, this.buttonSize));
this.buttons[1].setHorizontalTextPosition(AbstractButton.CENTER);
this.buttons[1].setVerticalTextPosition(AbstractButton.BOTTOM);
Expand All @@ -127,7 +130,8 @@ private void initButtons() {
setMaximumSize(getSize());
}
};
ImageIcon button2Icon = new ImageIcon("src/main/resources/edu/rpi/legup/images/Legup/homepanel/puzzle_file.png");
URL button2IconLocation = ClassLoader.getSystemClassLoader().getResource("edu/rpi/legup/images/Legup/homepanel/puzzle_file.png");
ImageIcon button2Icon = new ImageIcon(button2IconLocation);
this.buttons[2].setIcon(resizeButtonIcon(button2Icon, this.buttonSize, this.buttonSize));
this.buttons[2].setHorizontalTextPosition(AbstractButton.CENTER);
this.buttons[2].setVerticalTextPosition(AbstractButton.BOTTOM);
Expand All @@ -137,30 +141,33 @@ private void initButtons() {
//this.buttons[i].setPreferredSize(new Dimension(100, 100));
this.buttons[i].setBounds(200, 200, 700, 700);
}

this.buttons[3] = new JButton("Batch Grader");
this.buttons[3].setHorizontalTextPosition(AbstractButton.CENTER);
this.buttons[3].setVerticalTextPosition(AbstractButton.BOTTOM);
}

private void initText() {
this.text = new JLabel[3];
// Note: until an auto-changing version label is implemented in the future, I removed
// the version text from the home screen to avoid confusion

// this.text = new JLabel[3];
this.text = new JLabel[2];

JLabel welcome = new JLabel("Welcome to Legup");
welcome.setFont(new Font("Roboto", Font.BOLD, 23));
welcome.setAlignmentX(Component.CENTER_ALIGNMENT);

JLabel version = new JLabel("Version 3.0.0"); // This should be autochanged in the future
version.setFont(new Font("Roboto", Font.ITALIC, 10));
version.setAlignmentX(Component.CENTER_ALIGNMENT);

JLabel credits = new JLabel("A project by Dr. Bram van Heuveln");
credits.setFont(new Font("Roboto", Font.PLAIN, 12));
credits.setAlignmentX(Component.CENTER_ALIGNMENT);

JLabel version = new JLabel("Version 3.0.0"); // This should be autochanged in the future
version.setFont(new Font("Roboto", Font.ITALIC, 10));
version.setAlignmentX(Component.CENTER_ALIGNMENT);

this.text[0] = welcome;
this.text[1] = version;
this.text[2] = credits;
this.text[1] = credits;
// this.text[2] = version;
}

private void render() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/edu/rpi/legup/ui/PickGameDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public PickGameDialog(JFrame parent, boolean pickBothAtOnce) {
}

public void initPuzzles() {
Object[] o = GameBoardFacade.getInstance().getConfig().getPuzzleNames().toArray();
Object[] o = GameBoardFacade.getInstance().getConfig().getPuzzleClassNames().toArray();

games = new String[o.length];

Expand Down
19 changes: 16 additions & 3 deletions src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import edu.rpi.legup.ui.boardview.BoardView;
import edu.rpi.legup.ui.proofeditorui.rulesview.RuleFrame;
import edu.rpi.legup.ui.proofeditorui.treeview.TreePanel;
import edu.rpi.legup.ui.proofeditorui.treeview.TreeView;
import edu.rpi.legup.ui.proofeditorui.treeview.TreeViewSelection;
import edu.rpi.legup.user.Submission;
import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -51,7 +52,7 @@ public class ProofEditorPanel extends LegupPanel implements IHistoryListener {
private JMenu file;
private JMenuItem newPuzzle, resetPuzzle, saveProof, preferences, exit;
private JMenu edit;
private JMenuItem undo, redo;
private JMenuItem undo, redo, fitBoardToScreen, fitTreeToScreen;

private JMenu view;

Expand Down Expand Up @@ -121,6 +122,8 @@ public JMenuBar getMenuBar() {
edit = new JMenu("Edit");
undo = new JMenuItem("Undo");
redo = new JMenuItem("Redo");
fitBoardToScreen = new JMenuItem("Fit Board to Screen");
fitTreeToScreen = new JMenuItem("Fit Tree to Screen");

view = new JMenu("View");

Expand Down Expand Up @@ -285,6 +288,12 @@ public JMenuBar getMenuBar() {
redo.setAccelerator(KeyStroke.getKeyStroke('Z', InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK));
}

edit.add(fitBoardToScreen);
fitBoardToScreen.addActionListener((ActionEvent) -> dynamicBoardView.fitBoardViewToScreen());

edit.add(fitTreeToScreen);
fitTreeToScreen.addActionListener((ActionEvent) -> this.fitTreeViewToScreen());

mBar.add(proof);

about.add(aboutLegup);
Expand Down Expand Up @@ -423,7 +432,7 @@ protected void setupContent() {

treePanel = new TreePanel();

dynamicBoardView = new DynamicView(new ScrollView(new BoardController()));
dynamicBoardView = new DynamicView(new ScrollView(new BoardController()), DynamicViewType.BOARD);
TitledBorder titleBoard = BorderFactory.createTitledBorder("Board");
titleBoard.setTitleJustification(TitledBorder.CENTER);
dynamicBoardView.setBorder(titleBoard);
Expand Down Expand Up @@ -571,7 +580,7 @@ private void repaintAll() {
public void setPuzzleView(Puzzle puzzle) {
this.boardView = puzzle.getBoardView();

dynamicBoardView = new DynamicView(boardView);
dynamicBoardView = new DynamicView(boardView, DynamicViewType.BOARD);
this.topHalfPanel.setRightComponent(dynamicBoardView);
this.topHalfPanel.setVisible(true);
String boardType = boardView.getBoard().getClass().getSimpleName();
Expand Down Expand Up @@ -834,4 +843,8 @@ public void errorEncountered(String error) {
public void showStatus(String status, boolean error, int timer) {
// TODO: implement
}

protected void fitTreeViewToScreen() {
this.treePanel.getTreeView().zoomFit();
}
}
Loading

0 comments on commit 9b63078

Please sign in to comment.