Skip to content

Commit

Permalink
working on tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Leiser authored and Kevin Leiser committed Jun 22, 2018
1 parent 0a30cbc commit 9260b56
Show file tree
Hide file tree
Showing 30 changed files with 633 additions and 202 deletions.
427 changes: 290 additions & 137 deletions .idea/workspace.xml

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file modified out/production/HW6/cs3500/animator/controller/ControllerGUI.class
Binary file not shown.
Binary file modified out/production/HW6/cs3500/animator/controller/ControllerText.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified out/production/HW6/cs3500/animator/view/ViewFactory.class
Binary file not shown.
Binary file modified out/production/HW6/cs3500/animator/view/ViewText.class
Binary file not shown.
18 changes: 11 additions & 7 deletions out/production/HW6/hw7 README
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ The following changes were made to our code from the previous assignment:
UnsupportedOperationException's.
- Changed model to store shapes in LinkedHashMap rather than HashMap since draw order
wasn't conserved in HashMap.

- set the Timer to be a member variable of ViewGUI so that it can be seen by classes that
extend it.
- Added more IllegalArgumentExceptions where applicable.

The following classes were added:
- IGuiBasedView
- InteractiveViewGUI
- HybridController
- InteractiveController
- InteractiveViewGUI - GUI class that has features that end-user can adjust on screen.
- HybridController - Controller which works for both interactive gui and text views.
- InteractiveController - Controller which works with interactive views for
interactive animations.
- IListener - Interface whose objects listens for actions to which they react.

Other changes that were made:
- Added looping functionality to ViewGUI
- set the Timer to be a member variable of ViewGUI so that it can be seen by classes that
extend it

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified out/test/HW6/cs3500/animator/view/ViewSVGTest.class
Binary file not shown.
14 changes: 10 additions & 4 deletions src/cs3500/animator/controller/ControllerFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import cs3500.animator.model.animation.IAnimationModel;
import cs3500.animator.view.IView;
import cs3500.animator.view.InteractiveViewGUI;
import cs3500.animator.view.HybridView;
import cs3500.animator.view.TextBasedView;
import cs3500.animator.view.ViewGUI;

Expand All @@ -20,10 +20,16 @@ public class ControllerFactory {
* @param fps the speed of the cs3500.animator.model.animation in frames per second.
* @param outfile the output file location. This is only used for view types text and svg
* @return a new, configured controller.
* @throws IllegalArgumentException if model or view are invalid/null.
*/
public static IController getController(String type, IView view, IAnimationModel model, int fps,
String outfile) {
if (fps == 0) {
String outfile) throws IllegalArgumentException {

if (view == null || model == null) {
throw new IllegalArgumentException("views and models cannot be null");
}

if (fps <= 0) {
fps = 1;
}

Expand All @@ -36,7 +42,7 @@ public static IController getController(String type, IView view, IAnimationModel
} else if (type.equalsIgnoreCase("gui")) {
return new ControllerGUI(model, (ViewGUI) view, fps);
} else if (type.equalsIgnoreCase("hybrid")) {
return new HybridController(model, (InteractiveViewGUI) view, fps, outfile);
return new HybridController(model, (HybridView) view, fps, outfile);
} else {
throw new IllegalArgumentException("Invalid view type");
}
Expand Down
20 changes: 18 additions & 2 deletions src/cs3500/animator/controller/ControllerGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,37 @@
public class ControllerGUI extends AbstractController {
protected ViewGUI guiView;
protected Timer timer;
boolean looping;
protected boolean looping;

/**
* Constructor for the GUI controller. Reads data from model and tells the view what to print.
* @param model model to be used to get cs3500.animator.model.animation information.
* @param guiView View to display cs3500.animator.model.animation in a GUI.
* @param frameRatePerSec frame rate at which the cs3500.animator.model.animation will run.
* Set to 1 if negative.
* @throws IllegalArgumentException if view or model are null.
*/
public ControllerGUI(IAnimationModel model, ViewGUI guiView, int frameRatePerSec) {
public ControllerGUI(IAnimationModel model, ViewGUI guiView, int frameRatePerSec)
throws IllegalArgumentException {
if (model == null || guiView == null) {
throw new IllegalArgumentException("model and view cannot be null.");
}

if (frameRatePerSec <= 0) {
frameRatePerSec = 1;
}

this.guiView = guiView;
this.model = model;
this.frameRate = frameRatePerSec;
looping = true;
}

/**
* Protected default constructor so child classes can have their own constructors.
*/
protected ControllerGUI() {}

@Override
public void run() {
AnimatedShapeToDrawableConverter shapeToDrawableConverter
Expand Down
12 changes: 11 additions & 1 deletion src/cs3500/animator/controller/ControllerText.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,18 @@ public class ControllerText extends AbstractController {
* Creates a controller for a text view output of an cs3500.animator.model.animation.
* @param model model representing cs3500.animator.model.animation.
* @param view view to be presenting cs3500.animator.model.animation.
* @param frameRate desired framerate of animation. Set to 1 fps if param is <= 0.
* @throws IllegalArgumentException if model/view are null.
*/
public ControllerText(IAnimationModel model, TextBasedView view, int frameRate) {
public ControllerText(IAnimationModel model, TextBasedView view, int frameRate)
throws IllegalArgumentException {
if (model == null || view == null) {
throw new IllegalArgumentException("model and view cannot be null.");
}

if (frameRate <= 0) {
frameRate = 1;
}

this.model = model;
this.view = view;
Expand Down
32 changes: 11 additions & 21 deletions src/cs3500/animator/controller/HybridController.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package cs3500.animator.controller;

import java.awt.event.ActionEvent;

import cs3500.animator.model.animation.IAnimationModel;
import cs3500.animator.view.InteractiveViewGUI;
import cs3500.animator.view.TextBasedView;
import cs3500.animator.view.HybridView;
import cs3500.animator.view.ViewSVG;

/**
Expand All @@ -17,15 +14,21 @@ public class HybridController extends InteractiveController {
/**
* Constructor for the GUI controller. Reads data from model and tells the view what to print.
*
* @param model model to be used to get cs3500.animator.model.animation information.
* @param interactiveView View to display cs3500.animator.model.animation in a GUI.
* @param model model to be used to get cs3500.animator.model.animation information.
* @param hybridView View to display cs3500.animator.model.animation in a GUI.
* @param frameRatePerSec frame rate at which the cs3500.animator.model.animation will run.
*/
public HybridController(IAnimationModel model, InteractiveViewGUI interactiveView, int frameRatePerSec, String outputFile) {
super(model, interactiveView, frameRatePerSec);
public HybridController(IAnimationModel model, HybridView hybridView, int frameRatePerSec, String outputFile) {
super(model, hybridView, frameRatePerSec);
this.outputFile = outputFile;
}

/**
* Protected default constructor allows child classes to have their own constructors.
*/
protected HybridController() {
}

@Override
public void action(GuiEventType type) {
super.action(type);
Expand All @@ -36,17 +39,4 @@ public void action(GuiEventType type) {
fileOutputController.run();
}
}

/**
* This function instantiates fileOutputController, and uses a ViewSVG to output the animation
* description to a file.
* @param filename the desired file location.
*/
public void export(String filename) {
TextBasedView outputView = new ViewSVG();
outputView.setFilename(filename);

fileOutputController = new ControllerText(model, outputView, frameRate);
fileOutputController.run();
}
}
4 changes: 2 additions & 2 deletions src/cs3500/animator/controller/IListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ enum GuiEventType { RESTART, CHANGE_SPEED, START_STOP, TOGGLE_LOOPING, EXPORT }

/**
* This fires when an event that requires a variable value happens (i.e. change speed).
* @param type
* @param value
* @param type type of gui event.
* @param value value that the setting will be changed to.
*/
void change(GuiEventType type, int value);
}
24 changes: 15 additions & 9 deletions src/cs3500/animator/controller/InteractiveController.java
Original file line number Diff line number Diff line change
@@ -1,38 +1,42 @@
package cs3500.animator.controller;

import cs3500.animator.model.animation.IAnimationModel;
import cs3500.animator.view.InteractiveViewGUI;
import cs3500.animator.view.HybridView;

public class InteractiveController extends ControllerGUI implements IListener {

InteractiveViewGUI interactiveView;
protected GuiEventType recentEvent;
protected HybridView hybridView;

/**
* Constructor for the GUI controller. Reads data from model and tells the view what to print.
*
* @param model model to be used to get cs3500.animator.model.animation information.
* @param interactiveView View to display cs3500.animator.model.animation in a GUI.
* @param hybridView View to display cs3500.animator.model.animation in a GUI.
* @param frameRatePerSec frame rate at which the cs3500.animator.model.animation will run.
*/
public InteractiveController(IAnimationModel model, InteractiveViewGUI interactiveView,
public InteractiveController(IAnimationModel model, HybridView hybridView,
int frameRatePerSec) {
super(model, interactiveView, frameRatePerSec);
this.interactiveView = interactiveView;
super(model, hybridView, frameRatePerSec);
this.hybridView = hybridView;

setAsActionListener();
setAsChangeListener();
}

protected InteractiveController() {}

public void setAsActionListener() {
interactiveView.setActionListener(this);
hybridView.setActionListener(this);
}

public void setAsChangeListener() {
interactiveView.setChangeListener(this);
hybridView.setChangeListener(this);
}

@Override
public void action(GuiEventType type) {
recentEvent = type;
if(type.equals(GuiEventType.START_STOP)) {
if (timer.isRunning()) {
timer.stop();
Expand All @@ -50,9 +54,11 @@ public void action(GuiEventType type) {
@Override
public void change(GuiEventType type, int value) {
if (type.equals(GuiEventType.CHANGE_SPEED)) {
frameRate = value;

int delay = 1000 / frameRate;
timer.setDelay(delay);
} else {
throw new IllegalArgumentException("change event type must be a change event");
}
}
}
10 changes: 9 additions & 1 deletion src/cs3500/animator/model/animation/AbstractChange.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,19 @@ public String getDescription() {

@Override
public void setStartShape(IShape shape) {
if (shape == null) {
throw new IllegalArgumentException("Shape cannot be null");
}
startShape = shape;
}

@Override
public void setEndShape(IShape shape) {
public void setEndShape(IShape shape)
{
if (shape == null) {
throw new IllegalArgumentException("Shape cannot be null");
}

endShape = shape;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package cs3500.animator.view;

import java.awt.*;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;
import javax.swing.JButton;
import javax.swing.JSlider;
import javax.swing.JPanel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

Expand All @@ -15,14 +17,14 @@
* animation to change settings regarding the animation, such as speed, looping, restart, and
* start/stop.
*/
public class InteractiveViewGUI extends ViewGUI implements ActionListener, ChangeListener {
private JSlider slider;
private JButton stopStartButton;
private JButton restartButton;
private JButton toggleLoopingButton;
private JButton exportButton;
public class HybridView extends ViewGUI implements ActionListener, ChangeListener {
protected JSlider slider;
protected JButton stopStartButton;
protected JButton restartButton;
protected JButton toggleLoopingButton;
protected JButton exportButton;

private IListener listener;
protected IListener listener;

private final int FPS_MIN = 1;
private final int FPS_MAX = 60;
Expand All @@ -32,7 +34,7 @@ public class InteractiveViewGUI extends ViewGUI implements ActionListener, Chang
* Creates a new InteractiveViewGUI object. This type of view can display animations whose
* settings can be adjusted by the client.
*/
public InteractiveViewGUI() {
public HybridView() {
super();

JPanel panel = new JPanel();
Expand Down
2 changes: 1 addition & 1 deletion src/cs3500/animator/view/ViewFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static IView getView(String type) {
} else if (type.equalsIgnoreCase("gui")) {
return new ViewGUI();
} else if (type.equalsIgnoreCase("hybrid")) {
return new InteractiveViewGUI();
return new HybridView();
} else {
throw new IllegalArgumentException("Invalid view type");
}
Expand Down
18 changes: 11 additions & 7 deletions src/hw7 README
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ The following changes were made to our code from the previous assignment:
UnsupportedOperationException's.
- Changed model to store shapes in LinkedHashMap rather than HashMap since draw order
wasn't conserved in HashMap.

- set the Timer to be a member variable of ViewGUI so that it can be seen by classes that
extend it.
- Added more IllegalArgumentExceptions where applicable.

The following classes were added:
- IGuiBasedView
- InteractiveViewGUI
- HybridController
- InteractiveController
- InteractiveViewGUI - GUI class that has features that end-user can adjust on screen.
- HybridController - Controller which works for both interactive gui and text views.
- InteractiveController - Controller which works with interactive views for
interactive animations.
- IListener - Interface whose objects listens for actions to which they react.

Other changes that were made:
- Added looping functionality to ViewGUI
- set the Timer to be a member variable of ViewGUI so that it can be seen by classes that
extend it

Loading

0 comments on commit 9260b56

Please sign in to comment.