Skip to content

Commit 25e04da

Browse files
author
Ultimate Pea
authored
Merge pull request #21 from UCSDOalads/branchByDYB
add ZoomIn and ZoomOut and ZoomAction
2 parents 85d739b + a60e7f9 commit 25e04da

5 files changed

Lines changed: 113 additions & 0 deletions

File tree

src/actions/ZoomAction.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package actions;
2+
3+
import paintcomponents.PaintComponent;
4+
import ui.PaintPanel;
5+
6+
public abstract class ZoomAction extends PaintAction{
7+
8+
private double zoomValue;
9+
private int centerX, centerY;
10+
11+
public ZoomAction(PaintPanel panel) {
12+
super(panel);
13+
centerX = panel.getWidth() / 2;
14+
centerY = panel.getHeight() / 2;
15+
}
16+
17+
public boolean canPerformAction() {
18+
return true;
19+
}
20+
21+
public void performAction() {
22+
for ( PaintComponent com: panel.getPaintComponents() ) {
23+
int xDifference = com.getX() - centerX;
24+
int yDifference = com.getY() - centerY;
25+
com.translate((int)(xDifference * getZoomValue()), (int)(yDifference * getZoomValue()));
26+
}
27+
panel.repaint();
28+
}
29+
30+
public int getCenterX() {
31+
return centerX;
32+
}
33+
34+
public void setCenterX(int centerX) {
35+
this.centerX = centerX;
36+
}
37+
38+
public int getCenterY() {
39+
return centerY;
40+
}
41+
42+
public void setCenterY(int centerY) {
43+
this.centerY = centerY;
44+
}
45+
46+
public double getZoomValue() {
47+
return zoomValue;
48+
}
49+
50+
public void setZoomValue(double value) {
51+
zoomValue = value;
52+
}
53+
54+
}

src/actions/ZoomInAction.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package actions;
2+
3+
import actions.menu.ActionsMenuBarTitles;
4+
import ui.PaintPanel;
5+
6+
public class ZoomInAction extends ZoomAction {
7+
8+
public ZoomInAction (PaintPanel panel) {
9+
super(panel);
10+
this.setZoomValue(0.5);
11+
}
12+
13+
@Override
14+
public void performAction() {
15+
super.performAction();
16+
}
17+
18+
@Override
19+
public String locationString() {
20+
return ActionsMenuBarTitles.Edit().Zoom_In().toString();
21+
}
22+
}

src/actions/ZoomOutAction.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package actions;
2+
3+
import ui.PaintPanel;
4+
import actions.menu.ActionsMenuBarTitles;
5+
6+
public class ZoomOutAction extends ZoomAction {
7+
8+
public ZoomOutAction (PaintPanel panel) {
9+
super(panel);
10+
this.setZoomValue(-0.5);
11+
}
12+
13+
@Override
14+
public void performAction() {
15+
super.performAction();
16+
}
17+
18+
@Override
19+
public String locationString() {
20+
return ActionsMenuBarTitles.Edit().Zoom_Out().toString();
21+
}
22+
23+
}

src/actions/menu/ActionsMenuBar.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import actions.PaintAction;
3030
import actions.RemovePaintComponent;
3131
import actions.UpdateDataDisplayBoxAction;
32+
import actions.ZoomInAction;
33+
import actions.ZoomOutAction;
3234

3335
public class ActionsMenuBar extends JMenuBar implements SelectionToolListener{
3436

@@ -55,6 +57,8 @@ public ActionsMenuBar(PaintPanel panel){
5557
//edit
5658
addAction(new EditRedoAction(panel));
5759
addAction(new EditUndoAction(panel));
60+
addAction(new ZoomInAction(panel));
61+
addAction(new ZoomOutAction(panel));
5862

5963
//haskell
6064
addAction(new AddHaskellComponent(panel));
@@ -66,6 +70,7 @@ public ActionsMenuBar(PaintPanel panel){
6670

6771
// remove
6872
addAction(new RemovePaintComponent(panel));
73+
6974

7075
}
7176

src/actions/menu/ActionsMenuBarTitles.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,15 @@ public Object Open() {
117117
append("Open...");
118118
return this;
119119
}
120+
121+
public ActionsMenuBarTitles Zoom_In() {
122+
append("Zoom In");
123+
return this;
124+
}
120125

126+
public ActionsMenuBarTitles Zoom_Out() {
127+
append("Zoom Out");
128+
return this;
129+
}
121130

122131
}

0 commit comments

Comments
 (0)