add drawing imc import as a path that will be openned in maze
- importing an imc will create a open path folowwing the given drawing ( very slow due to addStatus string notification ? )
This commit is contained in:
@@ -17,10 +17,7 @@ import java.awt.event.InputEvent;
|
|||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.event.MouseMotionListener;
|
import java.awt.event.MouseMotionListener;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.Date;
|
import java.util.*;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.ResourceBundle;
|
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
@@ -379,8 +376,27 @@ public class Display extends JFrame {
|
|||||||
};
|
};
|
||||||
JButton loadRawButton = new JButton(labels.getString("load" ) + " raw");
|
JButton loadRawButton = new JButton(labels.getString("load" ) + " raw");
|
||||||
loadRawButton.addActionListener(loadRawAction);
|
loadRawButton.addActionListener(loadRawAction);
|
||||||
|
|
||||||
loadMenu.add(loadRawButton);
|
loadMenu.add(loadRawButton);
|
||||||
|
|
||||||
|
Action loadImcAction = new AbstractAction() {
|
||||||
|
public void actionPerformed(ActionEvent evt) {
|
||||||
|
//
|
||||||
|
addStatus("load Imc");
|
||||||
|
|
||||||
|
String filename = loadName.getText();
|
||||||
|
|
||||||
|
if ((filename.length() > 0)) {
|
||||||
|
setMazeName(filename);
|
||||||
|
loadImc(false);
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
JButton loadImcButton = new JButton(labels.getString("load" ) + " imc");
|
||||||
|
loadImcButton.addActionListener(loadImcAction);
|
||||||
|
|
||||||
|
loadMenu.add(loadImcButton);
|
||||||
return loadMenu;
|
return loadMenu;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -656,6 +672,38 @@ public class Display extends JFrame {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void loadImc(boolean add) {
|
||||||
|
if ( maze != null ) {
|
||||||
|
new Thread() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
File infile = new File(params.getSaveDir(), params.getName() + ".imc");
|
||||||
|
FileInputStream inputStream = null;
|
||||||
|
try {
|
||||||
|
inputStream = new FileInputStream(infile);
|
||||||
|
// TODO
|
||||||
|
// model = new MazePersistRaw().parseInputStream("raw",inputStream);
|
||||||
|
Drawing drawing = new Drawing();
|
||||||
|
drawing.loadLinesExpanded(new DataInputStream(inputStream));
|
||||||
|
maze.addDrawing(drawing,add);
|
||||||
|
} catch (IOException io) {
|
||||||
|
io.printStackTrace(System.err);
|
||||||
|
statusField.setText("[ERROR] Can't load " + infile.getAbsolutePath());
|
||||||
|
} finally {
|
||||||
|
if (inputStream != null) {
|
||||||
|
// cleanup
|
||||||
|
try {
|
||||||
|
inputStream.close();
|
||||||
|
} catch (Exception any) {
|
||||||
|
// don't care really
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private JButton addDirection(final JPanel panel, final String direction, String key, Action goAction) {
|
private JButton addDirection(final JPanel panel, final String direction, String key, Action goAction) {
|
||||||
String actionName = "go" + direction;
|
String actionName = "go" + direction;
|
||||||
JButton button = new JButton(direction);
|
JButton button = new JButton(direction);
|
||||||
@@ -843,13 +891,13 @@ public class Display extends JFrame {
|
|||||||
Date now = new Date(System.currentTimeMillis());
|
Date now = new Date(System.currentTimeMillis());
|
||||||
if (lastDrag == null )
|
if (lastDrag == null )
|
||||||
{
|
{
|
||||||
drawingPath = null;
|
resetDrawingPath();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ( now.getTime() - lastDrag.getTime() > dragTimeout )
|
if ( now.getTime() - lastDrag.getTime() > dragTimeout )
|
||||||
{
|
{
|
||||||
drawingPath = null;
|
resetDrawingPath();
|
||||||
addStatus("move timeout");
|
addStatus("move timeout");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -857,6 +905,28 @@ public class Display extends JFrame {
|
|||||||
addPosition(newPosition,add);
|
addPosition(newPosition,add);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void resetDrawingPath()
|
||||||
|
{
|
||||||
|
drawingPath = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addDrawing(Drawing drawing, boolean add)
|
||||||
|
{
|
||||||
|
for (DrawingLine line : drawing.getInternLines())
|
||||||
|
{
|
||||||
|
addDrawingLine(line, add);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void addDrawingLine(DrawingLine line, boolean add)
|
||||||
|
{
|
||||||
|
resetDrawingPath();
|
||||||
|
ArrayList<Point> points = line.getPoints();
|
||||||
|
for (Point p : points)
|
||||||
|
{
|
||||||
|
addPosition(new Position(p.x,p.y), add);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
|||||||
Reference in New Issue
Block a user