View Javadoc

1   /*
2    * jcurl java curling software framework https://JCurl.mro.name
3    * Copyright (C) 2005-2009 M. Rohrmoser
4    * 
5    * This program is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU General Public License as published by the
7    * Free Software Foundation; either version 2 of the License, or (at your
8    * option) any later version.
9    * 
10   * This program is distributed in the hope that it will be useful, but
11   * WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13   * Public License for more details.
14   * 
15   * You should have received a copy of the GNU General Public License along
16   * with this program; if not, write to the Free Software Foundation, Inc.,
17   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18   */
19  package org.jcurl.mr.gui;
20  
21  import org.jcurl.core.api.Collider;
22  import org.jcurl.core.api.ComputedTrajectorySet;
23  import org.jcurl.core.api.Curler;
24  import org.jcurl.core.api.Measure;
25  import org.jcurl.core.api.MutableObject;
26  import org.jcurl.core.api.RockSet;
27  import org.jcurl.core.api.Unit;
28  import org.jcurl.core.api.RockType.Pos;
29  import org.jcurl.core.impl.CollissionSimple;
30  import org.jcurl.core.impl.CurlerNoCurl;
31  import org.jcurl.core.impl.CurveManager;
32  
33  /**
34   * Higher level Data Model - more abstract than {@link ComputedTrajectorySet}.
35   * 
36   * @author <a href="mailto:JCurl@mro.name">M. Rohrmoser </a>
37   * @version $Id: Model.java 1031 2009-07-23 15:06:05Z mro $
38   */
39  public class Model extends MutableObject {
40  
41  	// private static final Log log = JCLoggerFactory.getLogger(Model.class);
42  
43  	private static final long serialVersionUID = -8598083673757204804L;
44  
45  	private int activeRock;
46  
47  	private Measure broomX = null;
48  
49  	private Measure interval;
50  
51  	private ComputedTrajectorySet trajectory;
52  
53  	public Model() {
54  		trajectory = new CurveManager();
55  		trajectory.setCollider(new CollissionSimple());
56  		trajectory.setCurler(new CurlerNoCurl(23, 0));
57  		// setBroomX(new DimVal(0, Dim.METER));
58  		// setInterval(new DimVal(2.5, Dim.SECOND));
59  		// setDrawCurl(new DimVal(3, Dim.FOOT));
60  		// setDrawTime(new DimVal(25, Dim.SECOND));
61  	}
62  
63  	@Override
64  	public boolean equals(final Object obj) {
65  		if (this == obj)
66  			return true;
67  		if (getClass() != obj.getClass())
68  			return false;
69  		final Model other = (Model) obj;
70  		if (activeRock != other.activeRock)
71  			return false;
72  		if (broomX == null) {
73  			if (other.broomX != null)
74  				return false;
75  		} else if (!broomX.equals(other.broomX))
76  			return false;
77  		if (interval == null) {
78  			if (other.interval != null)
79  				return false;
80  		} else if (!interval.equals(other.interval))
81  			return false;
82  		if (trajectory == null) {
83  			if (other.trajectory != null)
84  				return false;
85  		} else if (!trajectory.equals(other.trajectory))
86  			return false;
87  		return true;
88  	}
89  
90  	public int getActiveRock() {
91  		return activeRock;
92  	}
93  
94  	public Measure getBroomX() {
95  		return broomX;
96  	}
97  
98  	public Collider getCollider() {
99  		return getTrajectory().getCollider();
100 	}
101 
102 	public Curler getCurler() {
103 		return getTrajectory().getCurler();
104 	}
105 
106 	public Measure getDrawCurl() {
107 		return new Measure(getTrajectory().getCurler().getDrawToTeeCurl(),
108 				Unit.METER);
109 	}
110 
111 	public Measure getDrawTime() {
112 		return new Measure(getTrajectory().getCurler().getDrawToTeeTime(),
113 				Unit.SECOND);
114 	}
115 
116 	public RockSet<Pos> getInitialPos() {
117 		return getTrajectory().getInitialPos();
118 	}
119 
120 	public Measure getInterval() {
121 		return interval;
122 	}
123 
124 	public ComputedTrajectorySet getTrajectory() {
125 		return trajectory;
126 	}
127 
128 	@Override
129 	public int hashCode() {
130 		final int PRIME = 31;
131 		int result = 1;
132 		result = PRIME * result + activeRock;
133 		result = PRIME * result + (broomX == null ? 0 : broomX.hashCode());
134 		result = PRIME * result + (interval == null ? 0 : interval.hashCode());
135 		result = PRIME * result
136 				+ (trajectory == null ? 0 : trajectory.hashCode());
137 		return result;
138 	}
139 
140 	public void setActiveRock(final int activeRock) {
141 		propChange
142 				.firePropertyChange("activeRock", getActiveRock(), activeRock);
143 		this.activeRock = activeRock & 0xF;
144 	}
145 
146 	public void setBroomX(final Measure broomX) {
147 		if (broomX == null)
148 			return;
149 		if (this.broomX == broomX)
150 			return;
151 		propChange.firePropertyChange("broomX", getBroomX(), broomX);
152 		this.broomX = broomX;
153 	}
154 
155 	public void setCollider(final Collider collider) {
156 		if (collider == null)
157 			return;
158 		propChange.firePropertyChange("collider", getCollider(), collider);
159 		getTrajectory().setCollider(collider);
160 	}
161 
162 	public void setCurler(final Curler curler) {
163 		if (curler == null)
164 			return;
165 		propChange.firePropertyChange("curler", getCurler(), curler);
166 		getTrajectory().setCurler(curler);
167 	}
168 
169 	public void setDrawCurl(final Measure drawCurl) {
170 		propChange.firePropertyChange("drawCurl", getDrawCurl(), drawCurl);
171 		getTrajectory().getCurler().setDrawToTeeCurl(
172 				drawCurl.to(Unit.METER).value);
173 	}
174 
175 	public void setDrawTime(final Measure drawTime) {
176 		propChange.firePropertyChange("drawTime", getDrawTime(), drawTime);
177 		getTrajectory().getCurler().setDrawToTeeTime(
178 				drawTime.to(Unit.SECOND).value);
179 	}
180 
181 	public void setInitialPos(final RockSet<Pos> initialPos) {
182 		if (initialPos == null)
183 			return;
184 		propChange
185 				.firePropertyChange("initialPos", getInitialPos(), initialPos);
186 		getTrajectory().setInitialPos(initialPos);
187 	}
188 
189 	public void setInterval(final Measure interval) {
190 		propChange.firePropertyChange("interval", getInterval(), interval);
191 		this.interval = interval.to(Unit.SECOND);
192 	}
193 
194 	public void setTrajectory(final ComputedTrajectorySet trajectory) {
195 		if (trajectory == null)
196 			return;
197 		propChange
198 				.firePropertyChange("trajectory", getTrajectory(), trajectory);
199 		this.trajectory = trajectory;
200 	}
201 }