GUI change Save Menu and Create Button
- Save is now a menu and Create/Resolve/Quit buttons
This commit is contained in:
@@ -23,24 +23,11 @@ import java.io.FileOutputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Scanner;
|
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
import javax.swing.AbstractAction;
|
import javax.swing.*;
|
||||||
import javax.swing.Action;
|
|
||||||
import javax.swing.BoxLayout;
|
|
||||||
import javax.swing.JButton;
|
|
||||||
import javax.swing.JComponent;
|
|
||||||
import javax.swing.JCheckBox;
|
|
||||||
import javax.swing.JFrame;
|
|
||||||
import javax.swing.JLabel;
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.swing.JScrollPane;
|
|
||||||
import javax.swing.JSlider;
|
|
||||||
import javax.swing.JTextField;
|
|
||||||
import javax.swing.KeyStroke;
|
|
||||||
import javax.swing.event.ChangeEvent;
|
import javax.swing.event.ChangeEvent;
|
||||||
import javax.swing.event.ChangeListener;
|
import javax.swing.event.ChangeListener;
|
||||||
|
|
||||||
@@ -71,40 +58,40 @@ public class Display extends JFrame
|
|||||||
|
|
||||||
Drawing drawing = new Drawing();
|
Drawing drawing = new Drawing();
|
||||||
|
|
||||||
Display(LabyModel model,int W, int H, MazeParams params)
|
Display(LabyModel model,int W, int H, MazeParams params)
|
||||||
{
|
{
|
||||||
super(labels.getString("title"));
|
super(labels.getString("title"));
|
||||||
if (params != null)
|
if (params != null)
|
||||||
{
|
{
|
||||||
// fixedParams = new MazeParamsFixed(params.getSaveDir(),params.getWidth(),params.getHeight(),params.getMaxDepth());
|
// fixedParams = new MazeParamsFixed(params.getSaveDir(),params.getWidth(),params.getHeight(),params.getMaxDepth());
|
||||||
this.params = params;
|
this.params = params;
|
||||||
}
|
|
||||||
this.model = model;
|
|
||||||
maze = createMazeComponent(model,W,H);
|
|
||||||
|
|
||||||
Container con = this.getContentPane();
|
|
||||||
JScrollPane scrollableMaze = new JScrollPane(maze);
|
|
||||||
scrollableMaze.addMouseMotionListener(maze);
|
|
||||||
con.add(scrollableMaze, BorderLayout.CENTER);
|
|
||||||
controler = new MazeControler(params);
|
|
||||||
con.add(controler.getMoveControl(), BorderLayout.NORTH);
|
|
||||||
con.add(controler.getGenerationControl(), BorderLayout.SOUTH);
|
|
||||||
|
|
||||||
addComponentListener(new ComponentAdapter() {
|
|
||||||
@Override
|
|
||||||
public void componentResized(ComponentEvent e) {
|
|
||||||
if ( autoSize )
|
|
||||||
{
|
|
||||||
maze.getAutoSize();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
this.model = model;
|
||||||
|
maze = createMazeComponent(model,W,H);
|
||||||
|
|
||||||
model.setMazeListener(maze);
|
Container con = this.getContentPane();
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
JScrollPane scrollableMaze = new JScrollPane(maze);
|
||||||
setBounds(W, H, W, H);
|
scrollableMaze.addMouseMotionListener(maze);
|
||||||
setVisible(true);
|
con.add(scrollableMaze, BorderLayout.CENTER);
|
||||||
}
|
controler = new MazeControler(params);
|
||||||
|
con.add(controler.getMoveControl(), BorderLayout.NORTH);
|
||||||
|
con.add(controler.getGenerationControl(), BorderLayout.SOUTH);
|
||||||
|
|
||||||
|
addComponentListener(new ComponentAdapter() {
|
||||||
|
@Override
|
||||||
|
public void componentResized(ComponentEvent e) {
|
||||||
|
if ( autoSize )
|
||||||
|
{
|
||||||
|
maze.getAutoSize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
model.setMazeListener(maze);
|
||||||
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
setBounds(W, H, W, H);
|
||||||
|
setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
private static MazeComponent createMazeComponent(LabyModel model, int W, int H)
|
private static MazeComponent createMazeComponent(LabyModel model, int W, int H)
|
||||||
{
|
{
|
||||||
@@ -119,8 +106,8 @@ public class Display extends JFrame
|
|||||||
if (params != null)
|
if (params != null)
|
||||||
{
|
{
|
||||||
params = controler.getSettings().getParams();
|
params = controler.getSettings().getParams();
|
||||||
// keep current model...
|
// DON'T keep current model...
|
||||||
// model = new LabyModel(params, new java.util.Random());
|
model = new LabyModel(params, new java.util.Random());
|
||||||
maze.resetWallsProvider(model);
|
maze.resetWallsProvider(model);
|
||||||
model.setMazeListener(maze);
|
model.setMazeListener(maze);
|
||||||
|
|
||||||
@@ -361,71 +348,61 @@ public class Display extends JFrame
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class MazeSettings extends JPanel
|
private class MazeSettings extends JPanel
|
||||||
{
|
|
||||||
MazeParams params;
|
|
||||||
|
|
||||||
JTextField textWidth = null;
|
|
||||||
JTextField textHeight = null;
|
|
||||||
JTextField textDepth = null;
|
|
||||||
|
|
||||||
// TODO set width and height and depth of maze with gui
|
|
||||||
public MazeSettings(MazeParams params)
|
|
||||||
{
|
{
|
||||||
super();
|
MazeParams params;
|
||||||
this.params = params;
|
|
||||||
createSettingsGui();
|
|
||||||
}
|
|
||||||
|
|
||||||
void createSettingsGui()
|
JTextField textWidth = null;
|
||||||
{
|
JTextField textHeight = null;
|
||||||
if ( params != null )
|
JTextField textDepth = null;
|
||||||
|
|
||||||
|
// TODO set width and height and depth of maze with gui
|
||||||
|
public MazeSettings(MazeParams params)
|
||||||
{
|
{
|
||||||
JButton buttonCreate = new JButton(labels.getString("create"));
|
super();
|
||||||
buttonCreate.addActionListener(new ActionListener()
|
this.params = params;
|
||||||
{
|
createSettingsGui();
|
||||||
public void actionPerformed(ActionEvent evt)
|
|
||||||
{
|
|
||||||
recreateModel();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
add(buttonCreate);
|
|
||||||
|
|
||||||
JButton buttonReset = new JButton("reset");//labels.getString("reset"));
|
|
||||||
buttonReset.addActionListener(new ActionListener()
|
|
||||||
{
|
|
||||||
public void actionPerformed(ActionEvent evt)
|
|
||||||
{
|
|
||||||
resetModel();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
add(buttonReset);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
if ( params != null )
|
|
||||||
|
void createSettingsGui()
|
||||||
{
|
{
|
||||||
JLabel widthLabel = new JLabel(labels.getString("width"));
|
if ( params != null )
|
||||||
textWidth = new JTextField("0" + params.getWidth());
|
{
|
||||||
add(widthLabel);
|
JButton buttonReset = new JButton("reset");//labels.getString("reset"));
|
||||||
add(textWidth);
|
buttonReset.addActionListener(new ActionListener()
|
||||||
JLabel heightLabel = new JLabel(labels.getString("height"));
|
{
|
||||||
textHeight = new JTextField("0" + params.getHeight());
|
public void actionPerformed(ActionEvent evt)
|
||||||
add(heightLabel);
|
{
|
||||||
add(textHeight);
|
resetModel();
|
||||||
JLabel depthLabel = new JLabel(labels.getString("depth"));
|
}
|
||||||
textDepth = new JTextField("0" + params.getMaxDepth());
|
});
|
||||||
add(depthLabel);
|
add(buttonReset);
|
||||||
add(textDepth);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public MazeParams getParams()
|
}
|
||||||
{
|
if ( params != null )
|
||||||
return new MazeParamsFixed(params.getSaveDir(),
|
{
|
||||||
Integer.parseInt(textWidth.getText()),
|
JLabel widthLabel = new JLabel(labels.getString("width"));
|
||||||
Integer.parseInt(textHeight.getText()),
|
textWidth = new JTextField("0" + params.getWidth());
|
||||||
Integer.parseInt(textDepth.getText()));
|
add(widthLabel);
|
||||||
}
|
add(textWidth);
|
||||||
|
JLabel heightLabel = new JLabel(labels.getString("height"));
|
||||||
|
textHeight = new JTextField("0" + params.getHeight());
|
||||||
|
add(heightLabel);
|
||||||
|
add(textHeight);
|
||||||
|
JLabel depthLabel = new JLabel(labels.getString("depth"));
|
||||||
|
textDepth = new JTextField("0" + params.getMaxDepth());
|
||||||
|
add(depthLabel);
|
||||||
|
add(textDepth);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public MazeParams getParams()
|
||||||
|
{
|
||||||
|
return new MazeParamsFixed(params.getSaveDir(),
|
||||||
|
Integer.parseInt(textWidth.getText()),
|
||||||
|
Integer.parseInt(textHeight.getText()),
|
||||||
|
Integer.parseInt(textDepth.getText()));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -448,69 +425,80 @@ public class Display extends JFrame
|
|||||||
p.setName(pName);
|
p.setName(pName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private JPanel createSavingBar()
|
private JMenu createSavingMenu()
|
||||||
{
|
{
|
||||||
final JTextField saveName = new JTextField("newlaby ");
|
final JTextField saveName = new JTextField("newlaby ");
|
||||||
final JButton savePngButton = new JButton(labels.getString("save") +" png");
|
final JButton savePngButton = new JButton(labels.getString("save") +" png");
|
||||||
Action savePngAction = new AbstractAction() {
|
Action savePngAction = new AbstractAction() {
|
||||||
public void actionPerformed(ActionEvent evt)
|
public void actionPerformed(ActionEvent evt)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
System.out.println("save png");
|
System.out.println("save png");
|
||||||
setMazeName(saveName.getText());
|
setMazeName(saveName.getText());
|
||||||
savePng();
|
savePng();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
savePngButton.addActionListener(savePngAction);
|
savePngButton.addActionListener(savePngAction);
|
||||||
final JButton saveSvgButton = new JButton(labels.getString("save") +" svg");
|
final JButton saveSvgButton = new JButton(labels.getString("save") +" svg");
|
||||||
Action saveSvgAction = new AbstractAction() {
|
Action saveSvgAction = new AbstractAction() {
|
||||||
public void actionPerformed(ActionEvent evt)
|
public void actionPerformed(ActionEvent evt)
|
||||||
{
|
{
|
||||||
writeSentence("save png");
|
writeSentence("save png");
|
||||||
setMazeName(saveName.getText());
|
setMazeName(saveName.getText());
|
||||||
saveSvg();
|
saveSvg();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
saveSvgButton.addActionListener(saveSvgAction);
|
saveSvgButton.addActionListener(saveSvgAction);
|
||||||
final JButton saveButton = new JButton(labels.getString("save") +" raw");
|
final JButton saveButton = new JButton(labels.getString("save") +" raw");
|
||||||
Action saveAction = new AbstractAction() {
|
Action saveAction = new AbstractAction() {
|
||||||
public void actionPerformed(ActionEvent evt)
|
public void actionPerformed(ActionEvent evt)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
System.out.println("save");
|
System.out.println("save");
|
||||||
setMazeName(saveName.getText());
|
setMazeName(saveName.getText());
|
||||||
MazeParamsFixed p = (MazeParamsFixed) params;
|
MazeParamsFixed p = (MazeParamsFixed) params;
|
||||||
save(p,model);
|
save(p,model);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
saveButton.addActionListener(saveAction);
|
saveButton.addActionListener(saveAction);
|
||||||
final JButton saveImcButton = new JButton(labels.getString("save") +" imc");
|
final JButton saveImcButton = new JButton(labels.getString("save") +" imc");
|
||||||
Action saveImcAction = new AbstractAction() {
|
Action saveImcAction = new AbstractAction() {
|
||||||
public void actionPerformed(ActionEvent evt)
|
public void actionPerformed(ActionEvent evt)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
System.out.println("save imc");
|
System.out.println("save imc");
|
||||||
setMazeName(saveName.getText());
|
setMazeName(saveName.getText());
|
||||||
saveImc();
|
saveImc();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
saveImcButton.addActionListener(saveImcAction);
|
saveImcButton.addActionListener(saveImcAction);
|
||||||
|
|
||||||
JPanel savePanel = new JPanel(new FlowLayout());
|
JMenu saveMenu = new JMenu("Save");
|
||||||
savePanel.add(saveName);
|
saveMenu.add(saveName);
|
||||||
savePanel.add(saveSvgButton);
|
saveMenu.add(saveSvgButton);
|
||||||
savePanel.add(savePngButton);
|
saveMenu.add(savePngButton);
|
||||||
savePanel.add(saveButton);
|
saveMenu.add(saveButton);
|
||||||
savePanel.add(saveImcButton);
|
saveMenu.add(saveImcButton);
|
||||||
|
|
||||||
|
return saveMenu;
|
||||||
|
|
||||||
return savePanel;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private JPanel createResolveQuitBar()
|
private JPanel createResolveQuitBar()
|
||||||
{
|
{
|
||||||
JPanel resolveQuitBar = new JPanel(new FlowLayout());
|
JPanel resolveQuitBar = new JPanel(new FlowLayout());
|
||||||
JButton resolveButton = new JButton(labels.getString("resolve"));
|
|
||||||
|
JButton buttonCreate = new JButton(labels.getString("create"));
|
||||||
|
buttonCreate.addActionListener(new ActionListener()
|
||||||
|
{
|
||||||
|
public void actionPerformed(ActionEvent evt)
|
||||||
|
{
|
||||||
|
recreateModel();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
resolveQuitBar.add(buttonCreate);
|
||||||
|
|
||||||
|
JButton resolveButton = new JButton(labels.getString("resolve"));
|
||||||
resolveButton.addActionListener(new ActionListener()
|
resolveButton.addActionListener(new ActionListener()
|
||||||
{
|
{
|
||||||
public void actionPerformed(ActionEvent evt)
|
public void actionPerformed(ActionEvent evt)
|
||||||
@@ -547,7 +535,9 @@ public class Display extends JFrame
|
|||||||
BoxLayout layout = new BoxLayout(this,BoxLayout.Y_AXIS);
|
BoxLayout layout = new BoxLayout(this,BoxLayout.Y_AXIS);
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
|
|
||||||
add(createSavingBar());
|
JMenuBar menuBar = new JMenuBar();
|
||||||
|
menuBar.add(createSavingMenu());
|
||||||
|
add(menuBar);
|
||||||
|
|
||||||
add(createResolveQuitBar());
|
add(createResolveQuitBar());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user