Game-of-Life-WSU-CEG4180  v0.1
RefactoringtheGameofLife
GameOfLifeControlsEvent.java
Go to the documentation of this file.
1 /* This page is part of the Game of Life source code */
2 
3 package org.bitstorm.gameoflife;
4 
5 import java.awt.Event;
6 
7 /**
8  * Event class for GameOfLifeControls.
9  * Can pass speed, cellSize and shapeName.
10  * Objects from this class are generated by GameOfLifeControls
11  * @see GameOfLifeControls
12  * @author Edwin Martin
13  */
14 public class GameOfLifeControlsEvent extends Event {
15  private int speed;
16  private int zoom;
17  private String shapeName;
18 
19  /**
20  * Construct a GameOfLifeControls.ControlsEvent
21  * @param source source of event
22  */
23  public GameOfLifeControlsEvent(Object source) {
24  super(source, 0, null);
25  }
26 
27  /**
28  * Constructs a event due to the speed changed.
29  * @param source source of the event
30  * @param speed new speed
31  * @return new event object
32  */
33  public static GameOfLifeControlsEvent getSpeedChangedEvent( Object source, int speed ) {
35  event.setSpeed(speed);
36  return event;
37  }
38 
39  /**
40  * Constructs a event due to the zoom changed.
41  * @param source source of the event
42  * @param zoom new zoom (cell size in pixels)
43  * @return new event object
44  */
45  public static GameOfLifeControlsEvent getZoomChangedEvent( Object source, int zoom ) {
47  event.setZoom(zoom);
48  return event;
49  }
50 
51  /**
52  * Constructs a event due to the shape changed.
53  * @param source source of the event
54  * @param shapeName name of selected shape
55  * @return new event object
56  */
57  public static GameOfLifeControlsEvent getShapeSelectedEvent( Object source, String shapeName ) {
59  event.setShapeName(shapeName);
60  return event;
61  }
62 
63  /**
64  * Gets speed of Game
65  * @return speed (10 is fast, 1000 is slow)
66  */
67  public int getSpeed() {
68  return speed;
69  }
70 
71  /**
72  * Sets speed of Game
73  * @param speed (10 is fast, 1000 is slow)
74  */
75  public void setSpeed( int speed ) {
76  this.speed = speed;
77  }
78 
79  /**
80  * Gets size of cell
81  * @return speed (10 is big, 2 is small)
82  */
83  public int getZoom() {
84  return zoom;
85  }
86 
87  /**
88  * Sets zoom of Game
89  * @param zoom size of cell in pixels
90  */
91  public void setZoom( int zoom ) {
92  this.zoom = zoom;
93  }
94 
95  /**
96  * Gets name of shape
97  * @return name of selected shape
98  */
99  public String getShapeName() {
100  return shapeName;
101  }
102 
103  /**
104  * Sets name of shape
105  * @param shapeName name of shape
106  */
107  public void setShapeName( String shapeName ) {
108  this.shapeName = shapeName;
109  }
110 
111 }
static GameOfLifeControlsEvent getShapeSelectedEvent(Object source, String shapeName)
static GameOfLifeControlsEvent getSpeedChangedEvent(Object source, int speed)
static GameOfLifeControlsEvent getZoomChangedEvent(Object source, int zoom)