Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions src/actions/ZoomAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package actions;

import paintcomponents.PaintComponent;
import ui.PaintPanel;

public abstract class ZoomAction extends PaintAction{

private double zoomValue;
private int centerX, centerY;

public ZoomAction(PaintPanel panel) {
super(panel);
centerX = panel.getWidth() / 2;
centerY = panel.getHeight() / 2;
}

public boolean canPerformAction() {
return true;
}

public void performAction() {
for ( PaintComponent com: panel.getPaintComponents() ) {
int xDifference = com.getX() - centerX;
int yDifference = com.getY() - centerY;
com.translate((int)(xDifference * getZoomValue()), (int)(yDifference * getZoomValue()));
}
panel.repaint();
}

public int getCenterX() {
return centerX;
}

public void setCenterX(int centerX) {
this.centerX = centerX;
}

public int getCenterY() {
return centerY;
}

public void setCenterY(int centerY) {
this.centerY = centerY;
}

public double getZoomValue() {
return zoomValue;
}

public void setZoomValue(double value) {
zoomValue = value;
}

}
22 changes: 22 additions & 0 deletions src/actions/ZoomInAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package actions;

import actions.menu.ActionsMenuBarTitles;
import ui.PaintPanel;

public class ZoomInAction extends ZoomAction {

public ZoomInAction (PaintPanel panel) {
super(panel);
this.setZoomValue(0.5);
}

@Override
public void performAction() {
super.performAction();
}

@Override
public String locationString() {
return ActionsMenuBarTitles.Edit().Zoom_In().toString();
}
}
23 changes: 23 additions & 0 deletions src/actions/ZoomOutAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package actions;

import ui.PaintPanel;
import actions.menu.ActionsMenuBarTitles;

public class ZoomOutAction extends ZoomAction {

public ZoomOutAction (PaintPanel panel) {
super(panel);
this.setZoomValue(-0.5);
}

@Override
public void performAction() {
super.performAction();
}

@Override
public String locationString() {
return ActionsMenuBarTitles.Edit().Zoom_Out().toString();
}

}
5 changes: 5 additions & 0 deletions src/actions/menu/ActionsMenuBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import actions.PaintAction;
import actions.RemovePaintComponent;
import actions.UpdateDataDisplayBoxAction;
import actions.ZoomInAction;
import actions.ZoomOutAction;

public class ActionsMenuBar extends JMenuBar implements SelectionToolListener{

Expand All @@ -55,6 +57,8 @@ public ActionsMenuBar(PaintPanel panel){
//edit
addAction(new EditRedoAction(panel));
addAction(new EditUndoAction(panel));
addAction(new ZoomInAction(panel));
addAction(new ZoomOutAction(panel));

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

// remove
addAction(new RemovePaintComponent(panel));


}

Expand Down
9 changes: 9 additions & 0 deletions src/actions/menu/ActionsMenuBarTitles.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ public Object Open() {
append("Open...");
return this;
}

public ActionsMenuBarTitles Zoom_In() {
append("Zoom In");
return this;
}

public ActionsMenuBarTitles Zoom_Out() {
append("Zoom Out");
return this;
}

}