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;
|
package org.artisanlogiciel.games.maze.gui;
|
||||||
|
|
||||||
import org.artisanlogiciel.games.maze.*;
|
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.MazePersistRaw;
|
||||||
|
import org.artisanlogiciel.games.maze.persist.MazePersistWorldEdit;
|
||||||
import org.artisanlogiciel.games.maze.solve.SolvingModel;
|
import org.artisanlogiciel.games.maze.solve.SolvingModel;
|
||||||
import org.artisanlogiciel.games.stl.Maze3dParams;
|
import org.artisanlogiciel.games.stl.Maze3dParams;
|
||||||
import org.artisanlogiciel.games.stl.Wall3dStream;
|
import org.artisanlogiciel.games.stl.Wall3dStream;
|
||||||
@@ -10,7 +10,6 @@ import org.artisanlogiciel.graphics.Drawing;
|
|||||||
import org.artisanlogiciel.graphics.SvgWriter;
|
import org.artisanlogiciel.graphics.SvgWriter;
|
||||||
import org.artisanlogiciel.osm.OsmReader;
|
import org.artisanlogiciel.osm.OsmReader;
|
||||||
import org.artisanlogiciel.osm.convert.OsmToDrawing;
|
import org.artisanlogiciel.osm.convert.OsmToDrawing;
|
||||||
import org.artisanlogiciel.util.UTF8Control;
|
|
||||||
import org.artisanlogiciel.xpm.Xpm;
|
import org.artisanlogiciel.xpm.Xpm;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
@@ -25,7 +24,6 @@ import java.awt.event.ComponentEvent;
|
|||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.ResourceBundle;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display is Main JFrame for this tool
|
* Display is Main JFrame for this tool
|
||||||
@@ -36,7 +34,6 @@ implements StatusListener
|
|||||||
// to please eclipse, not supposed to be serialized
|
// to please eclipse, not supposed to be serialized
|
||||||
private static final long serialVersionUID = 8500214871372184418L;
|
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();
|
LabyLayers layers = new LabyLayers();
|
||||||
int layer = 0;
|
int layer = 0;
|
||||||
@@ -54,7 +51,7 @@ implements StatusListener
|
|||||||
Maze3dSettings stlsettings;
|
Maze3dSettings stlsettings;
|
||||||
|
|
||||||
Display(LabyModel model, int W, int H, MazeParams params) {
|
Display(LabyModel model, int W, int H, MazeParams params) {
|
||||||
super(labels.getString("title"));
|
super(MazeDefault.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;
|
||||||
@@ -64,13 +61,13 @@ implements StatusListener
|
|||||||
|
|
||||||
Container con = this.getContentPane();
|
Container con = this.getContentPane();
|
||||||
JScrollPane scrollableMaze = new JScrollPane(maze);
|
JScrollPane scrollableMaze = new JScrollPane(maze);
|
||||||
scrollableMaze.addMouseMotionListener(maze);
|
|
||||||
con.add(scrollableMaze, BorderLayout.CENTER);
|
con.add(scrollableMaze, BorderLayout.CENTER);
|
||||||
controler = new MazeControler(params);
|
controler = new MazeControler(params);
|
||||||
con.add(controler.getMoveControl(), BorderLayout.NORTH);
|
con.add(controler.getMoveControl(), BorderLayout.NORTH);
|
||||||
con.add(controler.getGenerationControl(), BorderLayout.SOUTH);
|
con.add(controler.getGenerationControl(), BorderLayout.SOUTH);
|
||||||
|
|
||||||
addComponentListener(new ComponentAdapter() {
|
/*
|
||||||
|
scrollableMaze.addComponentListener(new ComponentAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void componentResized(ComponentEvent e) {
|
public void componentResized(ComponentEvent e) {
|
||||||
if (autoSize) {
|
if (autoSize) {
|
||||||
@@ -78,6 +75,8 @@ implements StatusListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
model.setMazeListener(maze);
|
model.setMazeListener(maze);
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
@@ -86,17 +85,16 @@ implements StatusListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
private MazeComponent createMazeComponent(LabyModel model, int W, int H) {
|
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);
|
MazeComponent comp = new MazeComponent(model, cp, this);
|
||||||
Xpm xpm = new Xpm();
|
Xpm xpm = new Xpm();
|
||||||
// HARDCODED FOR FIRST TEST FIXME !!!
|
|
||||||
try {
|
try {
|
||||||
xpm.parse(new FileInputStream("lab/titou20.xpm"));
|
xpm.parse(new FileInputStream(MazeDefault.getInstance().getXpmBackground()));
|
||||||
comp.setXpm(xpm);
|
comp.setXpm(xpm);
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
{
|
{
|
||||||
System.err.println("Hardcoded background to fix");
|
System.err.println("Missing background file " + e);
|
||||||
}
|
}
|
||||||
return comp;
|
return comp;
|
||||||
}
|
}
|
||||||
@@ -310,7 +308,7 @@ implements StatusListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
private JMenu createLoadingMenu() {
|
private JMenu createLoadingMenu() {
|
||||||
JMenu loadMenu = new JMenu(labels.getString("load") );
|
JMenu loadMenu = new JMenu(MazeDefault.labels.getString("load") );
|
||||||
|
|
||||||
final JTextField loadName = new JTextField("newlaby");
|
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);
|
loadRawButton.addActionListener(loadRawAction);
|
||||||
loadMenu.add(loadRawButton);
|
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);
|
loadImcButton.addActionListener(loadImcAction);
|
||||||
|
|
||||||
loadMenu.add(loadImcButton);
|
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);
|
loadDrawingButton.addActionListener(loadDrawingAction);
|
||||||
|
|
||||||
loadMenu.add(loadDrawingButton);
|
loadMenu.add(loadDrawingButton);
|
||||||
@@ -481,7 +479,7 @@ implements StatusListener
|
|||||||
|
|
||||||
stlsettings = new Maze3dSettings(new Maze3dParams());
|
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(saveName);
|
||||||
saveMenu.add(saveSvgButton);
|
saveMenu.add(saveSvgButton);
|
||||||
saveMenu.add(savePngButton);
|
saveMenu.add(savePngButton);
|
||||||
@@ -497,7 +495,7 @@ implements StatusListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
private JButton newActionButton(String actionName, String format, Action action) {
|
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);
|
saveTextButton.addActionListener(action);
|
||||||
return saveTextButton;
|
return saveTextButton;
|
||||||
}
|
}
|
||||||
@@ -513,7 +511,7 @@ implements StatusListener
|
|||||||
private JPanel createResolveQuitBar() {
|
private JPanel createResolveQuitBar() {
|
||||||
JPanel resolveQuitBar = new JPanel(new FlowLayout());
|
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() {
|
buttonCreate.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent evt) {
|
public void actionPerformed(ActionEvent evt) {
|
||||||
recreateModel();
|
recreateModel();
|
||||||
@@ -521,7 +519,7 @@ implements StatusListener
|
|||||||
});
|
});
|
||||||
resolveQuitBar.add(buttonCreate);
|
resolveQuitBar.add(buttonCreate);
|
||||||
|
|
||||||
JButton resolveButton = new JButton(labels.getString("resolve"));
|
JButton resolveButton = new JButton(MazeDefault.labels.getString("resolve"));
|
||||||
resolveButton.addActionListener(new ActionListener() {
|
resolveButton.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent evt) {
|
public void actionPerformed(ActionEvent evt) {
|
||||||
//
|
//
|
||||||
@@ -532,7 +530,7 @@ implements StatusListener
|
|||||||
|
|
||||||
resolveQuitBar.add(resolveButton);
|
resolveQuitBar.add(resolveButton);
|
||||||
|
|
||||||
JButton reverseButton = new JButton(labels.getString("reverse"));
|
JButton reverseButton = new JButton(MazeDefault.labels.getString("reverse"));
|
||||||
reverseButton.addActionListener(new ActionListener() {
|
reverseButton.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent evt) {
|
public void actionPerformed(ActionEvent evt) {
|
||||||
//
|
//
|
||||||
@@ -544,7 +542,7 @@ implements StatusListener
|
|||||||
resolveQuitBar.add(reverseButton);
|
resolveQuitBar.add(reverseButton);
|
||||||
|
|
||||||
|
|
||||||
final JButton quitButton = new JButton(labels.getString("quit"));
|
final JButton quitButton = new JButton(MazeDefault.labels.getString("quit"));
|
||||||
Action quitAction = new AbstractAction() {
|
Action quitAction = new AbstractAction() {
|
||||||
public void actionPerformed(ActionEvent evt) {
|
public void actionPerformed(ActionEvent evt) {
|
||||||
//
|
//
|
||||||
@@ -556,7 +554,7 @@ implements StatusListener
|
|||||||
|
|
||||||
resolveQuitBar.add(quitButton);
|
resolveQuitBar.add(quitButton);
|
||||||
|
|
||||||
JButton buttonReset = new JButton("reset");//labels.getString("reset"));
|
JButton buttonReset = new JButton("reset");//MazeDefault.labels.getString("reset"));
|
||||||
buttonReset.addActionListener(new ActionListener() {
|
buttonReset.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent evt) {
|
public void actionPerformed(ActionEvent evt) {
|
||||||
resetModel();
|
resetModel();
|
||||||
@@ -591,7 +589,7 @@ implements StatusListener
|
|||||||
goNorth();
|
goNorth();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
JButton north = addDirection(this, labels.getString("north"), "UP", goNorth);
|
JButton north = addDirection(this, MazeDefault.labels.getString("north"), "UP", goNorth);
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
Action goEast = new AbstractAction() {
|
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")
|
@SuppressWarnings("serial")
|
||||||
Action goWest = new AbstractAction() {
|
Action goWest = new AbstractAction() {
|
||||||
@@ -612,7 +610,7 @@ implements StatusListener
|
|||||||
goWest();
|
goWest();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
JButton west = addDirection(this, labels.getString("west"), "LEFT", goWest);
|
JButton west = addDirection(this, MazeDefault.labels.getString("west"), "LEFT", goWest);
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
Action goSouth = new AbstractAction() {
|
Action goSouth = new AbstractAction() {
|
||||||
@@ -622,7 +620,7 @@ implements StatusListener
|
|||||||
goSouth();
|
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(north, BorderLayout.NORTH);
|
||||||
controlMovesPanel.add(west, BorderLayout.WEST);
|
controlMovesPanel.add(west, BorderLayout.WEST);
|
||||||
@@ -988,7 +986,7 @@ implements StatusListener
|
|||||||
|
|
||||||
setupDisplay(model, W, H, null);
|
setupDisplay(model, W, H, null);
|
||||||
} else {
|
} else {
|
||||||
MazeParamsFixed params = new MazeParamsFixed(new File("lab"), 20, 20, 12,1024L);
|
MazeParamsFixed params = new MazeParamsFixed(MazeDefault.getInstance().getParams());
|
||||||
model = new LabyModel(params);
|
model = new LabyModel(params);
|
||||||
|
|
||||||
setupDisplay(model, W, H, params);
|
setupDisplay(model, W, H, params);
|
||||||
|
|||||||
@@ -1,20 +1,22 @@
|
|||||||
package org.artisanlogiciel.games.maze.gui;
|
package org.artisanlogiciel.games.maze.gui;
|
||||||
|
|
||||||
|
import org.artisanlogiciel.games.maze.gui.component.IntegerField;
|
||||||
|
import org.artisanlogiciel.games.maze.gui.component.Panel;
|
||||||
import org.artisanlogiciel.games.stl.Maze3dParams;
|
import org.artisanlogiciel.games.stl.Maze3dParams;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
public class Maze3dSettings
|
public class Maze3dSettings
|
||||||
extends JPanel
|
extends Panel
|
||||||
{
|
{
|
||||||
// grid size
|
// grid size
|
||||||
JTextField xl;
|
IntegerField xl;
|
||||||
JTextField yl;
|
IntegerField yl;
|
||||||
JTextField zl;
|
IntegerField zl;
|
||||||
|
|
||||||
JTextField w;
|
IntegerField w;
|
||||||
JTextField lg;
|
IntegerField lg;
|
||||||
JTextField hg;
|
IntegerField hg;
|
||||||
|
|
||||||
JCheckBox reverse;
|
JCheckBox reverse;
|
||||||
|
|
||||||
@@ -28,42 +30,39 @@ public class Maze3dSettings
|
|||||||
|
|
||||||
void createSettingsGui() {
|
void createSettingsGui() {
|
||||||
if (params != null) {
|
if (params != null) {
|
||||||
JLabel widthLabel = new JLabel(Display.labels.getString("width"));
|
|
||||||
xl = new JTextField("0" + params.getXl());
|
IntegerField xl = new IntegerField("width",params.getXl());
|
||||||
add(widthLabel);
|
addField(xl);
|
||||||
add(xl);
|
|
||||||
JLabel heightLabel = new JLabel(Display.labels.getString("height"));
|
IntegerField zl = new IntegerField("height",params.getZl());
|
||||||
zl = new JTextField("0" + params.getZl());
|
addField(zl);
|
||||||
add(heightLabel);
|
|
||||||
add(zl);
|
IntegerField yl = new IntegerField("depth",params.getYl());
|
||||||
JLabel depthLabel = new JLabel(Display.labels.getString("depth"));
|
addField(yl);
|
||||||
yl = new JTextField("0" + params.getYl());
|
|
||||||
add(depthLabel);
|
|
||||||
add(yl);
|
|
||||||
|
|
||||||
reverse = new JCheckBox("reverse",params.isReverse());
|
reverse = new JCheckBox("reverse",params.isReverse());
|
||||||
add(reverse);
|
add(reverse);
|
||||||
|
|
||||||
w = new JTextField("0" + params.getW());
|
w = new IntegerField(params.getW());
|
||||||
add(w);
|
addField(w);
|
||||||
|
|
||||||
// lowground hightground
|
// lowground hightground
|
||||||
lg = new JTextField("0" + params.getLg());
|
lg = new IntegerField(params.getLg());
|
||||||
add(lg);
|
addField(lg);
|
||||||
hg = new JTextField("0" + params.getHg());
|
hg = new IntegerField(params.getHg());
|
||||||
add(hg);
|
addField(hg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Maze3dParams createParams()
|
Maze3dParams createParams()
|
||||||
{
|
{
|
||||||
return new Maze3dParams(
|
return new Maze3dParams(
|
||||||
Integer.parseInt(xl.getText()),
|
xl.getValue(),
|
||||||
Integer.parseInt(yl.getText()),
|
yl.getValue(),
|
||||||
Integer.parseInt(zl.getText()),
|
zl.getValue(),
|
||||||
Integer.parseInt(w.getText()),
|
w.getValue(),
|
||||||
Integer.parseInt(lg.getText()),
|
lg.getValue(),
|
||||||
Integer.parseInt(hg.getText()),
|
hg.getValue(),
|
||||||
reverse.isSelected());
|
reverse.isSelected());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,26 +8,22 @@ import org.artisanlogiciel.games.maze.solve.DirectionPosition;
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class MazeCellParameters {
|
public class MazeCellParameters {
|
||||||
double width = 10; // width of one cell
|
int offsetX; // x offset of upper corner left in pixels
|
||||||
double height = 10; // height of one cell
|
int offsetY; // y offset of upper corner left in pixers
|
||||||
int offsetX = 5; // x offset of upper corner left
|
|
||||||
int offsetY = 5; // y offset of upper corner left
|
|
||||||
|
|
||||||
int mapWidth = 0;
|
int mapWidth;
|
||||||
int mapHeight = 0;
|
int mapHeight;
|
||||||
|
|
||||||
|
// computed see adaptTo
|
||||||
|
double width; // width of one cell in pixels
|
||||||
|
double height; // height of one cell in pixels
|
||||||
|
|
||||||
public MazeCellParameters(int mapw, int maph, int W, int H, int x, int y) {
|
public MazeCellParameters(int mapw, int maph, int W, int H, int x, int y) {
|
||||||
double w = (W - x) / mapw;
|
|
||||||
double h = (H - y) / maph;
|
|
||||||
mapWidth = mapw;
|
mapWidth = mapw;
|
||||||
mapHeight = maph;
|
mapHeight = maph;
|
||||||
if (w < 5)
|
|
||||||
w = 5;
|
|
||||||
if (h < 5)
|
|
||||||
h = 5;
|
|
||||||
setCellSize(w, h);
|
|
||||||
offsetX = x;
|
offsetX = x;
|
||||||
offsetY = y;
|
offsetY = y;
|
||||||
|
adaptTo(W,H);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetMazeWidthHeight(int mapw, int maph) {
|
public void resetMazeWidthHeight(int mapw, int maph) {
|
||||||
@@ -38,8 +34,6 @@ public class MazeCellParameters {
|
|||||||
public void adaptTo(double W, double H) {
|
public void adaptTo(double W, double H) {
|
||||||
double w = (W - offsetX) / mapWidth;
|
double w = (W - offsetX) / mapWidth;
|
||||||
double h = (H - offsetY) / mapHeight;
|
double h = (H - offsetY) / mapHeight;
|
||||||
mapWidth = mapWidth;
|
|
||||||
mapHeight = mapHeight;
|
|
||||||
if (w < 5)
|
if (w < 5)
|
||||||
w = 5;
|
w = 5;
|
||||||
if (h < 5)
|
if (h < 5)
|
||||||
@@ -47,6 +41,13 @@ public class MazeCellParameters {
|
|||||||
setCellSize(w, h);
|
setCellSize(w, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// for a given (x,y) pixel return cell position.
|
||||||
|
Position toMazeCoordinates(int x, int y) {
|
||||||
|
int pX = (int) ((double) (x - getOffsetX()) / getWidth());
|
||||||
|
int pY = (int) ((double) (y - getOffsetY()) / getHeight());
|
||||||
|
return new Position(pX, pY);
|
||||||
|
}
|
||||||
|
|
||||||
public void setCellSize(double w, double h) {
|
public void setCellSize(double w, double h) {
|
||||||
width = w;
|
width = w;
|
||||||
height = h;
|
height = h;
|
||||||
|
|||||||
@@ -20,7 +20,9 @@ public class MazeComponent
|
|||||||
extends JComponent
|
extends JComponent
|
||||||
implements MazeCreationListener,
|
implements MazeCreationListener,
|
||||||
MazeResolutionListener,
|
MazeResolutionListener,
|
||||||
MouseMotionListener {
|
MouseMotionListener,
|
||||||
|
Scrollable
|
||||||
|
{
|
||||||
private static final long serialVersionUID = 3163272907991176390L;
|
private static final long serialVersionUID = 3163272907991176390L;
|
||||||
|
|
||||||
// WallsProvider map;
|
// WallsProvider map;
|
||||||
@@ -41,8 +43,8 @@ public class MazeComponent
|
|||||||
Xpm xpm = null;
|
Xpm xpm = null;
|
||||||
|
|
||||||
Date lastDrag = null;
|
Date lastDrag = null;
|
||||||
// FIXME HARCDODED delay after which a draging to draw a continous line is ended, a new line will then start.
|
// delay after which a draging to draw a continuous line is ended, a new line will then start.
|
||||||
long dragTimeout = 200;
|
long dragTimeout = MazeDefault.dragTimeout;
|
||||||
|
|
||||||
// not set by default for debug, will show any path
|
// not set by default for debug, will show any path
|
||||||
boolean showAll = false;
|
boolean showAll = false;
|
||||||
@@ -72,17 +74,19 @@ public class MazeComponent
|
|||||||
{
|
{
|
||||||
this.xpm = xpm;
|
this.xpm = xpm;
|
||||||
}
|
}
|
||||||
|
|
||||||
// for a given (x,y) pixel return cell position.
|
// for a given (x,y) pixel return cell position.
|
||||||
// if rightmost position of view not (0,0) this is not working.
|
|
||||||
Position getPosition(int x, int y) {
|
Position getPosition(int x, int y) {
|
||||||
int pX = (int) ((double) (x - cp.getOffsetX()) / cp.getWidth());
|
// if rightmost position of this view not (0,0) this is not working.
|
||||||
int pY = (int) ((double) (y - cp.getOffsetY()) / cp.getHeight());
|
// that's why MousListener should be attache to this MazeComponent and not to Scrollable one...
|
||||||
return new Position(pX, pY);
|
return cp.toMazeCoordinates(x,y);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseDragged(MouseEvent e) {
|
public void mouseDragged(MouseEvent e) {
|
||||||
boolean add = ((e.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK) != 0);
|
boolean add = ((e.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK) != 0);
|
||||||
|
// where pixel -> maze coordinate is done
|
||||||
Position newPosition = getPosition(e.getX(), e.getY());
|
Position newPosition = getPosition(e.getX(), e.getY());
|
||||||
Date now = new Date(System.currentTimeMillis());
|
Date now = new Date(System.currentTimeMillis());
|
||||||
if (lastDrag == null) {
|
if (lastDrag == null) {
|
||||||
@@ -117,6 +121,8 @@ public class MazeComponent
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// button 1 : add direction; button 2 : replace with direction.
|
||||||
|
// Position is Already in maze coordinates (ie not pixels)
|
||||||
public void addPosition(Position newPosition, boolean add) {
|
public void addPosition(Position newPosition, boolean add) {
|
||||||
// should find the cell ...
|
// should find the cell ...
|
||||||
DirectionPosition last = null;
|
DirectionPosition last = null;
|
||||||
@@ -134,7 +140,6 @@ public class MazeComponent
|
|||||||
while (!last.getPosition().equals(newPosition)) {
|
while (!last.getPosition().equals(newPosition)) {
|
||||||
path = LabyModel.getDirection(last.getPosition(), newPosition);
|
path = LabyModel.getDirection(last.getPosition(), newPosition);
|
||||||
last.setDirection(path);
|
last.setDirection(path);
|
||||||
// button 1 : add direction; button 2 : rep lace with direction.
|
|
||||||
if (add) {
|
if (add) {
|
||||||
map.addDirection(last.getPosition().getX(), last.getPosition().getY(), path);
|
map.addDirection(last.getPosition().getX(), last.getPosition().getY(), path);
|
||||||
} else {
|
} else {
|
||||||
@@ -219,6 +224,7 @@ public class MazeComponent
|
|||||||
gX = map.getWidth() - 1;
|
gX = map.getWidth() - 1;
|
||||||
gY = map.getHeight() - 1;
|
gY = map.getHeight() - 1;
|
||||||
this.statusListener = statusListener;
|
this.statusListener = statusListener;
|
||||||
|
addMouseMotionListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// public void resetWallsProvider(WallsProvider map)
|
// public void resetWallsProvider(WallsProvider map)
|
||||||
@@ -242,7 +248,8 @@ public class MazeComponent
|
|||||||
|
|
||||||
public int getAutoSize() {
|
public int getAutoSize() {
|
||||||
Rectangle r = getBounds();
|
Rectangle r = getBounds();
|
||||||
cp.adaptTo((int) r.getWidth(), (int) r.getHeight());
|
// cp.resetMazeWidthHeight( (int)r.getWidth(), (int) r.getHeight());
|
||||||
|
cp.adaptTo(r.getWidth(), r.getHeight());
|
||||||
// should redraw ...
|
// should redraw ...
|
||||||
invalidate();
|
invalidate();
|
||||||
repaint();
|
repaint();
|
||||||
@@ -412,4 +419,29 @@ public class MazeComponent
|
|||||||
public void resetResolution() {
|
public void resetResolution() {
|
||||||
solvedPath = null;
|
solvedPath = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dimension getPreferredScrollableViewportSize() {
|
||||||
|
return cp.getDimension();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getScrollableUnitIncrement(Rectangle rectangle, int i, int i1) {
|
||||||
|
return ( i == SwingConstants.VERTICAL ) ? (int) cp.getHeight() : (int) cp.getWidth();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getScrollableBlockIncrement(Rectangle rectangle, int i, int i1) {
|
||||||
|
return ( i == SwingConstants.VERTICAL ) ? (int) cp.getHeight() : (int) cp.getWidth();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getScrollableTracksViewportWidth() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getScrollableTracksViewportHeight() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
49
java/org/artisanlogiciel/games/maze/gui/MazeDefault.java
Normal file
49
java/org/artisanlogiciel/games/maze/gui/MazeDefault.java
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
package org.artisanlogiciel.games.maze.gui;
|
||||||
|
|
||||||
|
import org.artisanlogiciel.games.maze.MazeParams;
|
||||||
|
import org.artisanlogiciel.games.maze.MazeParamsFixed;
|
||||||
|
import org.artisanlogiciel.util.UTF8Control;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* All defaults
|
||||||
|
* Any Hardcoded value should end here
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class MazeDefault {
|
||||||
|
|
||||||
|
public final static ResourceBundle labels = ResourceBundle.getBundle("LabelsBundle", Locale.getDefault(), Display.class.getClassLoader(), new UTF8Control());
|
||||||
|
|
||||||
|
private final static MazeDefault instance;
|
||||||
|
|
||||||
|
static {
|
||||||
|
instance = new MazeDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
// HARDCODED Default
|
||||||
|
private MazeParamsFixed mParams = new MazeParamsFixed(new File("lab"), 300, 300, 20,1024L);
|
||||||
|
// private MazeCellParameters mazeCellParameters = new MazeCellParameters();
|
||||||
|
|
||||||
|
// delay after which a draging to draw a continuous line is ended, a new line will then start.
|
||||||
|
public static final long dragTimeout = 200;
|
||||||
|
|
||||||
|
public static MazeDefault getInstance()
|
||||||
|
{
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MazeParams getParams()
|
||||||
|
{
|
||||||
|
return mParams;
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getXpmBackground()
|
||||||
|
{
|
||||||
|
return new File("lab/titou20.xpm");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -2,19 +2,21 @@ package org.artisanlogiciel.games.maze.gui;
|
|||||||
|
|
||||||
import org.artisanlogiciel.games.maze.MazeParams;
|
import org.artisanlogiciel.games.maze.MazeParams;
|
||||||
import org.artisanlogiciel.games.maze.MazeParamsFixed;
|
import org.artisanlogiciel.games.maze.MazeParamsFixed;
|
||||||
|
import org.artisanlogiciel.games.maze.gui.component.IntegerField;
|
||||||
|
import org.artisanlogiciel.games.maze.gui.component.Panel;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import javax.swing.event.ChangeEvent;
|
import javax.swing.event.ChangeEvent;
|
||||||
import javax.swing.event.ChangeListener;
|
import javax.swing.event.ChangeListener;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class MazeSettings extends JPanel {
|
public class MazeSettings extends Panel {
|
||||||
MazeParams params;
|
MazeParams params;
|
||||||
|
|
||||||
JTextField textWidth = null;
|
IntegerField fieldWidth = null;
|
||||||
JTextField textHeight = null;
|
IntegerField fieldHeight = null;
|
||||||
JTextField textDepth = null;
|
IntegerField fieldDepth = null;
|
||||||
JTextField textSeed = null;
|
IntegerField fieldSeed = null;
|
||||||
JCheckBox onewaywallCB = null;
|
JCheckBox onewaywallCB = null;
|
||||||
|
|
||||||
// TODO set width and height and depth of maze with gui
|
// TODO set width and height and depth of maze with gui
|
||||||
@@ -25,35 +27,39 @@ public class MazeSettings extends JPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void createSettingsGui() {
|
void createSettingsGui() {
|
||||||
|
|
||||||
|
MazeParams defaultParams = MazeDefault.getInstance().getParams();
|
||||||
|
|
||||||
if (params != null) {
|
if (params != null) {
|
||||||
|
|
||||||
final JSlider slider = new JSlider(1, 100);
|
final JSlider slider = new JSlider(1,
|
||||||
|
Math.max(
|
||||||
|
Math.max(defaultParams.getHeight(),defaultParams.getHeight()),
|
||||||
|
Math.max(defaultParams.getWidth(),params.getWidth())));
|
||||||
|
|
||||||
slider.addChangeListener(new ChangeListener() {
|
slider.addChangeListener(new ChangeListener() {
|
||||||
public void stateChanged(ChangeEvent e) {
|
public void stateChanged(ChangeEvent e) {
|
||||||
// settextWidthWallSize(slider.getValue());
|
// settextWidthWallSize(slider.getValue());
|
||||||
String valueStr = "" + slider.getValue();
|
String valueStr = "" + slider.getValue();
|
||||||
textWidth.setText(valueStr);
|
fieldWidth.getTextField().setText(valueStr);
|
||||||
textHeight.setText(valueStr);
|
fieldHeight.getTextField().setText(valueStr);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
add(slider);
|
add(slider);
|
||||||
JLabel widthLabel = new JLabel(Display.labels.getString("width"));
|
fieldWidth = new IntegerField("width",params.getWidth());
|
||||||
textWidth = new JTextField("0" + params.getWidth());
|
addField(fieldWidth);
|
||||||
add(widthLabel);
|
|
||||||
add(textWidth);
|
fieldHeight = new IntegerField("height",params.getHeight());
|
||||||
JLabel heightLabel = new JLabel(Display.labels.getString("height"));
|
addField(fieldHeight);
|
||||||
textHeight = new JTextField("0" + params.getHeight());
|
|
||||||
add(heightLabel);
|
fieldDepth = new IntegerField("depth",params.getMaxDepth());
|
||||||
add(textHeight);
|
addField(fieldDepth);
|
||||||
JLabel depthLabel = new JLabel(Display.labels.getString("depth"));
|
|
||||||
textDepth = new JTextField("0" + params.getMaxDepth());
|
JLabel seedLabel = new JLabel();
|
||||||
add(depthLabel);
|
fieldSeed = new IntegerField("seed", params.getSeed());
|
||||||
add(textDepth);
|
addField(fieldSeed);
|
||||||
JLabel seedLabel = new JLabel(Display.labels.getString("seed"));
|
|
||||||
textSeed = new JTextField( "" + params.getSeed(),16);
|
|
||||||
add(seedLabel);
|
|
||||||
add(textSeed);
|
|
||||||
onewaywallCB = new JCheckBox("one way wall", false);
|
onewaywallCB = new JCheckBox("one way wall", false);
|
||||||
add(onewaywallCB);
|
add(onewaywallCB);
|
||||||
}
|
}
|
||||||
@@ -61,12 +67,12 @@ public class MazeSettings extends JPanel {
|
|||||||
|
|
||||||
public MazeParams resetParams() {
|
public MazeParams resetParams() {
|
||||||
params = new MazeParamsFixed(params.getSaveDir(),
|
params = new MazeParamsFixed(params.getSaveDir(),
|
||||||
Integer.parseInt(textWidth.getText()),
|
fieldWidth.getValue(),
|
||||||
Integer.parseInt(textHeight.getText()),
|
fieldHeight.getValue(),
|
||||||
Integer.parseInt(textDepth.getText()),
|
fieldDepth.getValue(),
|
||||||
new Random().nextLong()
|
new Random().nextLong()
|
||||||
);
|
);
|
||||||
textSeed.setText("" + params.getSeed());
|
fieldSeed.getTextField().setText("" + params.getSeed());
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package org.artisanlogiciel.games.maze.gui.component;
|
||||||
|
|
||||||
|
import org.artisanlogiciel.games.maze.gui.Display;
|
||||||
|
import org.artisanlogiciel.games.maze.gui.MazeDefault;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
public class IntegerField
|
||||||
|
{
|
||||||
|
JLabel mLabel;
|
||||||
|
JTextField mTextField;
|
||||||
|
long mDefaultValue;
|
||||||
|
|
||||||
|
public IntegerField(String label, long defaultValue)
|
||||||
|
{
|
||||||
|
mDefaultValue = defaultValue;
|
||||||
|
// DEPENDENCY
|
||||||
|
mLabel = new JLabel(MazeDefault.labels.getString(label));
|
||||||
|
mTextField = new JTextField("" + defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IntegerField(int defaultValue)
|
||||||
|
{
|
||||||
|
mDefaultValue = defaultValue;
|
||||||
|
mLabel = new JLabel("");
|
||||||
|
mTextField = new JTextField("" + defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public JLabel getLabel()
|
||||||
|
{
|
||||||
|
return mLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JTextField getTextField()
|
||||||
|
{
|
||||||
|
return mTextField;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getValue()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return Integer.parseInt(mTextField.getText());
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
mTextField.setText("" + mDefaultValue);
|
||||||
|
}
|
||||||
|
return (int) mDefaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getLongValue()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return Long.parseLong(mTextField.getText());
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
mTextField.setText("" + mDefaultValue);
|
||||||
|
}
|
||||||
|
return (int) mDefaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
14
java/org/artisanlogiciel/games/maze/gui/component/Panel.java
Normal file
14
java/org/artisanlogiciel/games/maze/gui/component/Panel.java
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package org.artisanlogiciel.games.maze.gui.component;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
public class Panel
|
||||||
|
extends JPanel {
|
||||||
|
|
||||||
|
protected void addField(IntegerField pField)
|
||||||
|
{
|
||||||
|
add(pField.getLabel());
|
||||||
|
add(pField.getTextField());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user