From 99716e57d3837ea55009b1aad53674fcc4163875 Mon Sep 17 00:00:00 2001 From: philippe lhardy Date: Wed, 21 Oct 2020 14:03:25 +0200 Subject: [PATCH] don't redrawn each cell when loading and by redraw at end - hide status update - don't redraw each point during file loading --- .../games/maze/gui/Display.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/java/org/artisanlogiciel/games/maze/gui/Display.java b/java/org/artisanlogiciel/games/maze/gui/Display.java index c89b15f..559288e 100644 --- a/java/org/artisanlogiciel/games/maze/gui/Display.java +++ b/java/org/artisanlogiciel/games/maze/gui/Display.java @@ -51,6 +51,7 @@ public class Display extends JFrame { MazeControler controler; LabyModel model; boolean autoSize; + boolean statusEnable = true; MazeParams params = null; JTextField statusField = null; @@ -333,7 +334,9 @@ public class Display extends JFrame { void addStatus(String pStatus) { - statusField.setText(pStatus); + if ( statusEnable ) { + statusField.setText(pStatus); + } } @@ -685,7 +688,9 @@ public class Display extends JFrame { // model = new MazePersistRaw().parseInputStream("raw",inputStream); Drawing drawing = new Drawing(); drawing.loadLinesExpanded(new DataInputStream(inputStream)); + statusEnable = false; maze.addDrawing(drawing,add); + statusEnable = true; } catch (IOException io) { io.printStackTrace(System.err); statusField.setText("[ERROR] Can't load " + infile.getAbsolutePath()); @@ -878,6 +883,7 @@ public class Display extends JFrame { boolean showAll = false; // 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) { int pX = (int) ((double) (x - cp.getOffsetX()) / cp.getWidth()); int pY = (int) ((double) (y - cp.getOffsetY()) / cp.getHeight()); @@ -903,6 +909,7 @@ public class Display extends JFrame { } lastDrag = now; addPosition(newPosition,add); + changed(null, null, map); } public void resetDrawingPath() @@ -916,6 +923,7 @@ public class Display extends JFrame { { addDrawingLine(line, add); } + changed(null, null, map); } public void addDrawingLine(DrawingLine line, boolean add) { @@ -934,7 +942,9 @@ public class Display extends JFrame { if (drawingPath == null) { drawingPath = new LinkedList<>(); last = new DirectionPosition((short) 0, newPosition); - addStatus("Mouse dragged Cell " + newPosition + " Button " + add ); + if ( statusEnable) { + addStatus("Mouse dragged Cell " + newPosition + " Button " + add); + } drawingPath.addLast(last); } else { // setShowAll(true); @@ -953,9 +963,10 @@ public class Display extends JFrame { last = last.moveToAdjacentDirection(); drawingPath.addLast(last); } - addStatus("Mouse dragged from Cell " + first.getPosition() + "To" + newPosition + " Button " + add ); + if (statusEnable) { + addStatus("Mouse dragged from Cell " + first.getPosition() + "To" + newPosition + " Button " + add); + } } - changed(null, null, map); } @Override