File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 2929import actions .PaintAction ;
3030import actions .RemovePaintComponent ;
3131import actions .UpdateDataDisplayBoxAction ;
32+ import actions .ZoomInAction ;
33+ import actions .ZoomOutAction ;
3234
3335public 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
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments