Move (most) hardcoded defaults to MazeDefault
- harcoded values centralized - IntegerField for JTextField containing numbers - fix, can draw even if topleft position is not (0,0) ( ie if scrollbar were used )
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
package org.artisanlogiciel.games.maze.gui;
|
||||
|
||||
import org.artisanlogiciel.games.maze.*;
|
||||
import org.artisanlogiciel.games.maze.persist.MazePersistWorldEdit;
|
||||
import org.artisanlogiciel.games.maze.persist.MazePersistRaw;
|
||||
import org.artisanlogiciel.games.maze.persist.MazePersistWorldEdit;
|
||||
import org.artisanlogiciel.games.maze.solve.SolvingModel;
|
||||
import org.artisanlogiciel.games.stl.Maze3dParams;
|
||||
import org.artisanlogiciel.games.stl.Wall3dStream;
|
||||
@@ -10,7 +10,6 @@ import org.artisanlogiciel.graphics.Drawing;
|
||||
import org.artisanlogiciel.graphics.SvgWriter;
|
||||
import org.artisanlogiciel.osm.OsmReader;
|
||||
import org.artisanlogiciel.osm.convert.OsmToDrawing;
|
||||
import org.artisanlogiciel.util.UTF8Control;
|
||||
import org.artisanlogiciel.xpm.Xpm;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
@@ -25,7 +24,6 @@ import java.awt.event.ComponentEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.*;
|
||||
import java.util.Locale;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* Display is Main JFrame for this tool
|
||||
@@ -36,7 +34,6 @@ implements StatusListener
|
||||
// to please eclipse, not supposed to be serialized
|
||||
private static final long serialVersionUID = 8500214871372184418L;
|
||||
|
||||
public final static ResourceBundle labels = ResourceBundle.getBundle("LabelsBundle", Locale.getDefault(), Display.class.getClassLoader(), new UTF8Control());
|
||||
|
||||
LabyLayers layers = new LabyLayers();
|
||||
int layer = 0;
|
||||
@@ -54,7 +51,7 @@ implements StatusListener
|
||||
Maze3dSettings stlsettings;
|
||||
|
||||
Display(LabyModel model, int W, int H, MazeParams params) {
|
||||
super(labels.getString("title"));
|
||||
super(MazeDefault.labels.getString("title"));
|
||||
if (params != null) {
|
||||
// fixedParams = new MazeParamsFixed(params.getSaveDir(),params.getWidth(),params.getHeight(),params.getMaxDepth());
|
||||
this.params = params;
|
||||
@@ -64,13 +61,13 @@ implements StatusListener
|
||||
|
||||
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() {
|
||||
/*
|
||||
scrollableMaze.addComponentListener(new ComponentAdapter() {
|
||||
@Override
|
||||
public void componentResized(ComponentEvent e) {
|
||||
if (autoSize) {
|
||||
@@ -78,6 +75,8 @@ implements StatusListener
|
||||
}
|
||||
}
|
||||
});
|
||||
*/
|
||||
|
||||
|
||||
model.setMazeListener(maze);
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
@@ -86,17 +85,16 @@ implements StatusListener
|
||||
}
|
||||
|
||||
private MazeComponent createMazeComponent(LabyModel model, int W, int H) {
|
||||
MazeCellParameters cp = new MazeCellParameters(model.getWidth(), model.getHeight(), W, H, 3, 3);
|
||||
MazeCellParameters cp = new MazeCellParameters(model.getWidth(), model.getHeight(), W, H, 0, 0);
|
||||
MazeComponent comp = new MazeComponent(model, cp, this);
|
||||
Xpm xpm = new Xpm();
|
||||
// HARDCODED FOR FIRST TEST FIXME !!!
|
||||
try {
|
||||
xpm.parse(new FileInputStream("lab/titou20.xpm"));
|
||||
xpm.parse(new FileInputStream(MazeDefault.getInstance().getXpmBackground()));
|
||||
comp.setXpm(xpm);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.err.println("Hardcoded background to fix");
|
||||
System.err.println("Missing background file " + e);
|
||||
}
|
||||
return comp;
|
||||
}
|
||||
@@ -310,7 +308,7 @@ implements StatusListener
|
||||
}
|
||||
|
||||
private JMenu createLoadingMenu() {
|
||||
JMenu loadMenu = new JMenu(labels.getString("load") );
|
||||
JMenu loadMenu = new JMenu(MazeDefault.labels.getString("load") );
|
||||
|
||||
final JTextField loadName = new JTextField("newlaby");
|
||||
|
||||
@@ -331,7 +329,7 @@ implements StatusListener
|
||||
|
||||
}
|
||||
};
|
||||
JButton loadRawButton = new JButton(labels.getString("load" ) + " raw");
|
||||
JButton loadRawButton = new JButton(MazeDefault.labels.getString("load" ) + " raw");
|
||||
loadRawButton.addActionListener(loadRawAction);
|
||||
loadMenu.add(loadRawButton);
|
||||
|
||||
@@ -350,7 +348,7 @@ implements StatusListener
|
||||
|
||||
}
|
||||
};
|
||||
JButton loadImcButton = new JButton(labels.getString("load" ) + " imc");
|
||||
JButton loadImcButton = new JButton(MazeDefault.labels.getString("load" ) + " imc");
|
||||
loadImcButton.addActionListener(loadImcAction);
|
||||
|
||||
loadMenu.add(loadImcButton);
|
||||
@@ -370,7 +368,7 @@ implements StatusListener
|
||||
|
||||
}
|
||||
};
|
||||
JButton loadDrawingButton = new JButton(labels.getString("load" ) + " Drawing");
|
||||
JButton loadDrawingButton = new JButton(MazeDefault.labels.getString("load" ) + " Drawing");
|
||||
loadDrawingButton.addActionListener(loadDrawingAction);
|
||||
|
||||
loadMenu.add(loadDrawingButton);
|
||||
@@ -481,7 +479,7 @@ implements StatusListener
|
||||
|
||||
stlsettings = new Maze3dSettings(new Maze3dParams());
|
||||
|
||||
JMenu saveMenu = new JMenu(labels.getString("save") );
|
||||
JMenu saveMenu = new JMenu(MazeDefault.labels.getString("save") );
|
||||
saveMenu.add(saveName);
|
||||
saveMenu.add(saveSvgButton);
|
||||
saveMenu.add(savePngButton);
|
||||
@@ -497,7 +495,7 @@ implements StatusListener
|
||||
}
|
||||
|
||||
private JButton newActionButton(String actionName, String format, Action action) {
|
||||
final JButton saveTextButton = new JButton(labels.getString(actionName) + " " + format);
|
||||
final JButton saveTextButton = new JButton(MazeDefault.labels.getString(actionName) + " " + format);
|
||||
saveTextButton.addActionListener(action);
|
||||
return saveTextButton;
|
||||
}
|
||||
@@ -513,7 +511,7 @@ implements StatusListener
|
||||
private JPanel createResolveQuitBar() {
|
||||
JPanel resolveQuitBar = new JPanel(new FlowLayout());
|
||||
|
||||
JButton buttonCreate = new JButton(labels.getString("create"));
|
||||
JButton buttonCreate = new JButton(MazeDefault.labels.getString("create"));
|
||||
buttonCreate.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
recreateModel();
|
||||
@@ -521,7 +519,7 @@ implements StatusListener
|
||||
});
|
||||
resolveQuitBar.add(buttonCreate);
|
||||
|
||||
JButton resolveButton = new JButton(labels.getString("resolve"));
|
||||
JButton resolveButton = new JButton(MazeDefault.labels.getString("resolve"));
|
||||
resolveButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
//
|
||||
@@ -532,7 +530,7 @@ implements StatusListener
|
||||
|
||||
resolveQuitBar.add(resolveButton);
|
||||
|
||||
JButton reverseButton = new JButton(labels.getString("reverse"));
|
||||
JButton reverseButton = new JButton(MazeDefault.labels.getString("reverse"));
|
||||
reverseButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
//
|
||||
@@ -544,7 +542,7 @@ implements StatusListener
|
||||
resolveQuitBar.add(reverseButton);
|
||||
|
||||
|
||||
final JButton quitButton = new JButton(labels.getString("quit"));
|
||||
final JButton quitButton = new JButton(MazeDefault.labels.getString("quit"));
|
||||
Action quitAction = new AbstractAction() {
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
//
|
||||
@@ -556,7 +554,7 @@ implements StatusListener
|
||||
|
||||
resolveQuitBar.add(quitButton);
|
||||
|
||||
JButton buttonReset = new JButton("reset");//labels.getString("reset"));
|
||||
JButton buttonReset = new JButton("reset");//MazeDefault.labels.getString("reset"));
|
||||
buttonReset.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
resetModel();
|
||||
@@ -591,7 +589,7 @@ implements StatusListener
|
||||
goNorth();
|
||||
}
|
||||
};
|
||||
JButton north = addDirection(this, labels.getString("north"), "UP", goNorth);
|
||||
JButton north = addDirection(this, MazeDefault.labels.getString("north"), "UP", goNorth);
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
Action goEast = new AbstractAction() {
|
||||
@@ -602,7 +600,7 @@ implements StatusListener
|
||||
}
|
||||
};
|
||||
|
||||
JButton east = addDirection(this, labels.getString("east"), "RIGHT", goEast);
|
||||
JButton east = addDirection(this, MazeDefault.labels.getString("east"), "RIGHT", goEast);
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
Action goWest = new AbstractAction() {
|
||||
@@ -612,7 +610,7 @@ implements StatusListener
|
||||
goWest();
|
||||
}
|
||||
};
|
||||
JButton west = addDirection(this, labels.getString("west"), "LEFT", goWest);
|
||||
JButton west = addDirection(this, MazeDefault.labels.getString("west"), "LEFT", goWest);
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
Action goSouth = new AbstractAction() {
|
||||
@@ -622,7 +620,7 @@ implements StatusListener
|
||||
goSouth();
|
||||
}
|
||||
};
|
||||
JButton south = addDirection(this, labels.getString("south"), "DOWN", goSouth);
|
||||
JButton south = addDirection(this, MazeDefault.labels.getString("south"), "DOWN", goSouth);
|
||||
|
||||
controlMovesPanel.add(north, BorderLayout.NORTH);
|
||||
controlMovesPanel.add(west, BorderLayout.WEST);
|
||||
@@ -988,7 +986,7 @@ implements StatusListener
|
||||
|
||||
setupDisplay(model, W, H, null);
|
||||
} else {
|
||||
MazeParamsFixed params = new MazeParamsFixed(new File("lab"), 20, 20, 12,1024L);
|
||||
MazeParamsFixed params = new MazeParamsFixed(MazeDefault.getInstance().getParams());
|
||||
model = new LabyModel(params);
|
||||
|
||||
setupDisplay(model, W, H, params);
|
||||
|
||||
Reference in New Issue
Block a user