Skip to content

Commit 39ef009

Browse files
committed
Added new zoom in/out states. Complimented with toolbar buttons.
1 parent 69b4c47 commit 39ef009

8 files changed

Lines changed: 50 additions & 7 deletions

File tree

src/com/modsim/gui/GUI.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,25 @@ private void createViewport() {
195195
hSplit.add(view, JSplitPane.RIGHT);
196196
}
197197

198+
/*
199+
* Accessible method for zooming into view
200+
*/
201+
public void zoomInToView()
202+
{
203+
view.zoomIn(view.getWidth()/2,view.getHeight()/2);
204+
}
205+
206+
/*
207+
* Accessible method for zooming out of view
208+
*/
209+
public void zoomOutToView()
210+
{
211+
view.zoomOut(view.getWidth()/2,view.getHeight()/2);
212+
}
213+
214+
215+
216+
198217
/**
199218
* Creates the context menu
200219
*/

src/com/modsim/gui/ToolBar.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
public class ToolBar {
1313
public JToolBar toolbar = null;
14-
public JButton btnPause, btnRun, btnStep;
14+
public JButton btnPause, btnRun, btnStep, btnZoomIn, btnZoomOut;
1515
public JSlider slideSpeed;
1616

1717
/**
@@ -32,7 +32,7 @@ public ToolBar() {
3232
toolbar.setMargin(margin);
3333

3434
// Buttons
35-
addButtons();
35+
addSimButtons();
3636
toolbar.addSeparator(new Dimension(15, 0));
3737

3838
// Slider
@@ -41,12 +41,15 @@ public ToolBar() {
4141
slideSpeed = new JSlider(JSlider.HORIZONTAL, 0, 60, 10);
4242
toolbar.add(slideSpeed);
4343
slideSpeed.addChangeListener(Ops.sliderSetSpeed);
44+
45+
toolbar.addSeparator(new Dimension(15, 0));
46+
addNavButtons();
4447
}
4548

4649
/**
47-
* Generate the toolbar buttons
50+
* Generate the toolbar simulation buttons
4851
*/
49-
private void addButtons() {
52+
private void addSimButtons() {
5053
btnPause = new JButton(Ops.pause);
5154
btnPause.setHideActionText(true);
5255
toolbar.add(btnPause);
@@ -59,4 +62,18 @@ private void addButtons() {
5962
btnStep.setHideActionText(true);
6063
toolbar.add(btnStep);
6164
}
65+
66+
/**
67+
* Generate the toolbar navigation buttons
68+
*/
69+
private void addNavButtons()
70+
{
71+
btnZoomIn = new JButton(Ops.zoomIn);
72+
btnZoomIn.setHideActionText(true);
73+
toolbar.add(btnZoomIn);
74+
75+
btnZoomOut = new JButton(Ops.zoomOut);
76+
btnZoomOut.setHideActionText(true);
77+
toolbar.add(btnZoomOut);
78+
}
6279
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class View extends JPanel {
2424
public int zoomI = 3;
2525
public double zoom = zoomI * ZOOM_MULTIPLIER;
2626

27-
public static final double ZOOM_MULTIPLIER = 0.2;
27+
public static final double ZOOM_MULTIPLIER = 0.15;
2828
public static final int ZOOM_LIMIT = 12;
2929

3030
public double camX = 0, camY = 0;

src/com/modsim/operations/Ops.java

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

138138
static {
139139
// Keyboard shortcuts
@@ -241,7 +241,12 @@ public static void fileNew() {
241241
Main.sim.stop();
242242
Main.sim.step();
243243
}, "Step Simulation", "Steps the simulation forward by one iteration", period);
244-
244+
245+
//Zoom controls
246+
zoomIn = new DesignAction(event -> Main.ui.zoomInToView(), "Zoom In");
247+
zoomOut = new DesignAction(event -> Main.ui.zoomOutToView(), "Zoom Out");
248+
249+
245250
// View controls
246251
toggleAA = new DesignAction(event -> Main.ui.view.useAA = !Main.ui.view.useAA,
247252
"Toggle anti-aliasing", "Toggles anti-aliased rendering in the viewport: " +

src/com/modsim/package-info.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
package com.modsim;
2+
13
/**
24
* ModuleSim
35
*

src/com/modsim/res/Zoom In.png

18.8 KB
Loading

src/com/modsim/res/Zoom Out.png

18.8 KB
Loading

src/com/modsim/res/navigate.png

18.8 KB
Loading

0 commit comments

Comments
 (0)