Skip to content

Commit 32f370f

Browse files
committed
Merge
2 parents c355d0e + 49d6271 commit 32f370f

6 files changed

Lines changed: 29 additions & 8 deletions

File tree

src/com/modsim/gui/GUI.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,10 @@ public void zoomOutToView()
265265
view.zoom(view.getWidth()/2, view.getHeight()/2, -1.0);
266266
}
267267

268-
268+
public void resetView()
269+
{
270+
view.resetView();
271+
}
269272

270273

271274
/**

src/com/modsim/gui/Menu.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ private void addViewMenu() {
8383
JMenu view = new JMenu("View");
8484
view.setMnemonic(KeyEvent.VK_V);
8585
view.add(Ops.toggleAA);
86+
view.add(Ops.resetView);
8687
app_menu.add(view);
8788
}
8889

src/com/modsim/gui/view/View.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,16 @@
2626
*/
2727
public class View extends JPanel {
2828

29-
public int zoomI = 3;
29+
public int init_zoomI = 3;
30+
public double init_camX = 0, init_camY = 0;
31+
32+
public int zoomI = init_zoomI;
3033
public double zoom = zoomI * ZOOM_MULTIPLIER;
3134

3235
public static final double ZOOM_MULTIPLIER = 0.15;
3336
public static final int ZOOM_LIMIT = 12;
3437

35-
public double camX = 0, camY = 0;
38+
public double camX = init_camX, camY = init_camY;
3639
public AffineTransform wToV = new AffineTransform();
3740

3841
private static final long serialVersionUID = 1L;
@@ -338,4 +341,15 @@ public void flagDynamicRedraw() {
338341
}
339342
}
340343
}
344+
345+
public void resetView() {
346+
//center view
347+
camX = init_camX;
348+
camY = init_camY;
349+
//reset zoom
350+
zoomI = init_zoomI;
351+
zoom = zoomI * ZOOM_MULTIPLIER;
352+
//redraw
353+
flagStaticRedraw();
354+
}
341355
}

src/com/modsim/operations/Ops.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public static void fileNew() {
136136
// Core application actions
137137
public static final DesignAction undo, redo, copy, paste, delete, rotateCW, rotateCCW, rotate180,
138138
labelEdit, labelBig, labelSmall,
139-
pause, run, step, toggleRun, zoomIn, zoomOut, toggleAA, open, save, saveAs, fileNew, quit;
139+
pause, run, step, toggleRun, zoomIn, zoomOut, resetView, toggleAA, open, save, saveAs, fileNew, quit;
140140

141141
static {
142142
// Keyboard shortcuts
@@ -248,7 +248,7 @@ public static void fileNew() {
248248
//Zoom controls
249249
zoomIn = new DesignAction(event -> Main.ui.zoomInToView(), "Zoom In");
250250
zoomOut = new DesignAction(event -> Main.ui.zoomOutToView(), "Zoom Out");
251-
251+
resetView = new DesignAction(event -> Main.ui.resetView(), "Reset View");
252252

253253
// View controls
254254
toggleAA = new DesignAction(event -> Main.ui.view.useAA = !Main.ui.view.useAA,

src/com/modsim/util/XMLReader.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ public static void readFile(File xmlFile) {
4444
// View load
4545
Element view = (Element) doc.getElementsByTagName("view").item(0);
4646
View v = Main.ui.view;
47-
v.camX = Double.parseDouble(view.getAttribute("camX"));
48-
v.camY = Double.parseDouble(view.getAttribute("camY"));
49-
v.zoomI = Integer.parseInt(view.getAttribute("zoom"));
47+
v.init_camX = v.camX = Double.parseDouble(view.getAttribute("camX"));
48+
v.init_camY = v.camY = Double.parseDouble(view.getAttribute("camY"));
49+
v.init_zoomI = v.zoomI = Integer.parseInt(view.getAttribute("zoom"));
5050
v.zoom = View.ZOOM_MULTIPLIER * v.zoomI;
5151
v.calcXForm();
5252

src/com/modsim/util/XMLWriter.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import javax.xml.parsers.DocumentBuilder;
1111
import javax.xml.parsers.DocumentBuilderFactory;
12+
import javax.xml.transform.OutputKeys;
1213
import javax.xml.transform.Transformer;
1314
import javax.xml.transform.TransformerFactory;
1415
import javax.xml.transform.dom.DOMSource;
@@ -177,6 +178,8 @@ public static void writeFile(File xmlFile) {
177178
// Saving operation
178179
TransformerFactory tf = TransformerFactory.newInstance();
179180
Transformer t = tf.newTransformer();
181+
t.setOutputProperty(OutputKeys.INDENT, "yes");
182+
t.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
180183
DOMSource src = new DOMSource(doc);
181184
StreamResult r = new StreamResult(xmlFile);
182185

0 commit comments

Comments
 (0)