Add editing functionalities
This commit is contained in:
1 parent
81df80e7ea
commit
43feeaf93f
9 files changed
+298
-16
No files matched your search
@@ -0,0 +1,25 @@
|
||||
package ui;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.JMenuItem;
|
||||
|
||||
public class AddLineMenuItem extends JMenuItem
|
||||
implements ActionListener {
|
||||
|
||||
private final MazeApp mazeApp;
|
||||
|
||||
public AddLineMenuItem(MazeApp mazeApp) {
|
||||
|
||||
super("Add line");
|
||||
this.mazeApp = mazeApp;
|
||||
addActionListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
|
||||
this.mazeApp.getMazeAppModel().addEmptyLine();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package ui;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.Action;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JMenuItem;
|
||||
|
||||
public class AddRowMenuItem extends JMenuItem
|
||||
implements ActionListener {
|
||||
|
||||
private final MazeApp mazeApp;
|
||||
|
||||
public AddRowMenuItem(MazeApp mazeApp) {
|
||||
|
||||
super("Add row");
|
||||
this.mazeApp = mazeApp;
|
||||
addActionListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
|
||||
this.mazeApp.getMazeAppModel().addEmptyColumn();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package ui;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.Action;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
public class ClearMazeMenuItem extends JMenuItem
|
||||
implements ActionListener {
|
||||
|
||||
private final MazeApp mazeApp;
|
||||
|
||||
public ClearMazeMenuItem(MazeApp mazeApp) {
|
||||
|
||||
super("Clear maze");
|
||||
this.mazeApp = mazeApp;
|
||||
this.setAccelerator(KeyStroke.getKeyStroke("control D"));
|
||||
addActionListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
||||
int numberOfLines = mazeApp.getMazeAppModel()
|
||||
.getMaze().getDimensionY();
|
||||
int numberOfRows = mazeApp.getMazeAppModel()
|
||||
.getMaze().getDimensionX();
|
||||
this.mazeApp.getMazeAppModel()
|
||||
.newClearMaze(numberOfLines, numberOfRows);
|
||||
System.out.println("test");
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,10 @@ public class MazeMenu extends JMenu {
|
||||
private final MazeApp mazeApp;
|
||||
private final DrawShortestPathMenuItem drawMenuItem;
|
||||
private final ClearShortestPathMenuItem clearMenuItem;
|
||||
private final NewClearMazeMenuItem newClearMazeMenuItem;
|
||||
private final ClearMazeMenuItem clearMazeMenuItem;
|
||||
private final AddRowMenuItem addRowMenuItem;
|
||||
private final AddLineMenuItem addLineMenuItem;
|
||||
|
||||
public MazeMenu(MazeApp mazeApp) {
|
||||
|
||||
@@ -15,5 +19,9 @@ public class MazeMenu extends JMenu {
|
||||
|
||||
add(drawMenuItem = new DrawShortestPathMenuItem(mazeApp));
|
||||
add(clearMenuItem = new ClearShortestPathMenuItem(mazeApp));
|
||||
add(newClearMazeMenuItem = new NewClearMazeMenuItem(mazeApp));
|
||||
add(clearMazeMenuItem = new ClearMazeMenuItem(mazeApp));
|
||||
add(addRowMenuItem = new AddRowMenuItem(mazeApp));
|
||||
add(addLineMenuItem = new AddLineMenuItem(mazeApp));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package ui;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
public class NewClearMazeMenuItem extends JMenuItem
|
||||
implements ActionListener {
|
||||
|
||||
private final MazeApp mazeApp;
|
||||
private NewMazeSpinnerBox spinnerBox;
|
||||
|
||||
public NewClearMazeMenuItem(MazeApp mazeApp) {
|
||||
|
||||
super("New clear maze");
|
||||
this.mazeApp = mazeApp;
|
||||
this.spinnerBox = new NewMazeSpinnerBox(mazeApp);
|
||||
this.setAccelerator(KeyStroke.getKeyStroke("control N"));
|
||||
addActionListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
|
||||
spinnerBox.createAndShowGUI();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package ui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JSpinner;
|
||||
import javax.swing.SpinnerModel;
|
||||
import javax.swing.SpinnerNumberModel;
|
||||
import javax.swing.SpringLayout;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
|
||||
public class NewMazeSpinnerBox extends JPanel
|
||||
implements ActionListener,
|
||||
ChangeListener {
|
||||
|
||||
private final MazeApp mazeApp;
|
||||
private JDialog spinnerDialog;
|
||||
private int numberOfLines;
|
||||
private int numberOfRows;
|
||||
private SpinnerModel lineSpinnerModel;
|
||||
private SpinnerModel rowSpinnerModel;
|
||||
|
||||
public NewMazeSpinnerBox(MazeApp mazeApp) {
|
||||
|
||||
|
||||
this.mazeApp = mazeApp;
|
||||
JPanel spinnerDialog = new JPanel(new SpringLayout());
|
||||
String[] labels = {"Number of lines :", "Number of rows :"};
|
||||
int len = labels.length;
|
||||
int initialValue = 3;
|
||||
int maximumValue = 200;
|
||||
|
||||
this.lineSpinnerModel =
|
||||
new SpinnerNumberModel(initialValue, //initial value
|
||||
initialValue, //min
|
||||
maximumValue, //max
|
||||
1);
|
||||
this.lineSpinnerModel.addChangeListener(this);
|
||||
JSpinner lineSpinner = addLabeledSpinner(this, labels[0], lineSpinnerModel);
|
||||
|
||||
this.rowSpinnerModel =
|
||||
new SpinnerNumberModel(initialValue, //initial value
|
||||
initialValue, //min
|
||||
maximumValue, //max
|
||||
1);
|
||||
this.rowSpinnerModel.addChangeListener(this);
|
||||
JSpinner rowSpinner = addLabeledSpinner(this, labels[0], rowSpinnerModel);
|
||||
}
|
||||
|
||||
static protected JSpinner addLabeledSpinner(Container c,
|
||||
String label,
|
||||
SpinnerModel model) {
|
||||
|
||||
JLabel l = new JLabel(label);
|
||||
c.add(l);
|
||||
|
||||
JSpinner spinner = new JSpinner(model);
|
||||
l.setLabelFor(spinner);
|
||||
c.add(spinner);
|
||||
|
||||
return spinner;
|
||||
}
|
||||
|
||||
public void createAndShowGUI() {
|
||||
|
||||
spinnerDialog = new JDialog(spinnerDialog, "Create a new empty maze");
|
||||
spinnerDialog.setLayout(new BorderLayout());
|
||||
spinnerDialog.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
|
||||
|
||||
spinnerDialog.add(new NewMazeSpinnerBox(this.mazeApp),
|
||||
BorderLayout.CENTER);
|
||||
|
||||
JButton OKButton = new JButton("OK");
|
||||
OKButton.addActionListener(this);
|
||||
spinnerDialog.add(OKButton, BorderLayout.SOUTH);
|
||||
|
||||
spinnerDialog.pack();
|
||||
spinnerDialog.setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
spinnerDialog.dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent arg0) {
|
||||
this.mazeApp.getMazeAppModel()
|
||||
.newClearMaze((int) this.lineSpinnerModel.getValue(),
|
||||
(int) this.rowSpinnerModel.getValue());
|
||||
}
|
||||
}
|
||||
@@ -4,9 +4,9 @@ import javax.swing.*;
|
||||
import maze.Maze;
|
||||
import java.awt.*;
|
||||
|
||||
public class WindowPanel extends JPanel
|
||||
{
|
||||
private final MazeDrawing drawingPanelGrid;
|
||||
public class WindowPanel extends JPanel {
|
||||
|
||||
private final MazeDrawing drawingPanelGrid;
|
||||
|
||||
public WindowPanel(MazeApp mazeApp) {
|
||||
|
||||
|
||||
Reference in new issue
Block a user