View Javadoc

1   /*
2    * jcurl curling simulation framework https://JCurl.mro.name Copyright (C)
3    * 2005-2009 M. Rohrmoser
4    * 
5    * This program is free software; you can redistribute it and/or modify it under
6    * the terms of the GNU General Public License as published by the Free Software
7    * Foundation; either version 2 of the License, or (at your option) any later
8    * version.
9    * 
10   * This program is distributed in the hope that it will be useful, but WITHOUT
11   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12   * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13   * details.
14   * 
15   * You should have received a copy of the GNU General Public License along with
16   * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
17   * Place, Suite 330, Boston, MA 02111-1307 USA
18   */
19  
20  package org.jcurl.demo.tactics;
21  
22  import java.awt.Cursor;
23  import java.awt.geom.RectangularShape;
24  
25  import javax.swing.JComponent;
26  import javax.swing.event.ChangeListener;
27  
28  import org.jcurl.core.api.ComputedTrajectorySet;
29  import org.jcurl.core.api.RockSet;
30  import org.jcurl.core.api.RockType.Pos;
31  import org.jcurl.core.ui.BroomPromptModel;
32  import org.jcurl.core.ui.ChangeManager;
33  import org.jcurl.core.ui.TrajectoryBroomPromptWrapper;
34  
35  /**
36   * Common code of the Piccolo and Scenario implementation.
37   * 
38   * @param <T>
39   *            tranformable node type (rocks)
40   * @param <G>
41   *            grouping node type (trajectories)
42   * 
43   * @author <a href="mailto:JCurl@mro.name">M. Rohrmoser </a>
44   * @version $Id$
45   */
46  public abstract class TrajectoryBean<T, G> extends JComponent implements
47  		HasChanger, Zoomable, ChangeListener {
48  	protected static final String ATTR_IDX16 = "idx16";
49  	protected static final String ATTR_ROCK = "rock";
50  	protected static final String ATTR_ROCKSET = "rockset";
51  	protected static final String ATTR_TRIGGER_CURVE_UPDATE = "trigger_curve_update";
52  	protected static final Cursor CURSOR = new Cursor(Cursor.HAND_CURSOR);
53  	private ChangeManager changer;
54  	protected ComputedTrajectorySet curves = null;
55  	protected transient RectangularShape tmpViewPort = null;
56  	protected final TrajectoryBroomPromptWrapper tt = new TrajectoryBroomPromptWrapper();
57  
58  	protected void addCL(final RockSet<Pos> s) {
59  		if (s == null)
60  			return;
61  		for (int i16 = RockSet.ROCKS_PER_SET - 1; i16 >= 0; i16--)
62  			s.getRock(i16).addChangeListener(this);
63  	}
64  
65  	/** keep the recent viewport visible */
66  	@Override
67  	public void doLayout() {
68  		super.doLayout();
69  		if (tmpViewPort != null)
70  			setZoom(tmpViewPort, 0);
71  	}
72  
73  	public abstract BroomPromptModel getBroom();
74  
75  	public ChangeManager getChanger() {
76  		return ChangeManager.getTrivial(changer);
77  	}
78  
79  	public ComputedTrajectorySet getCurves() {
80  		return curves;
81  	}
82  
83  	public RectangularShape getZoom() {
84  		if (tmpViewPort == null)
85  			return null;// pico.getCamera().getViewBounds();
86  		return tmpViewPort;
87  	}
88  
89  	protected void removeCL(final RockSet<Pos> s) {
90  		if (s == null)
91  			return;
92  		for (int i16 = RockSet.ROCKS_PER_SET - 1; i16 >= 0; i16--)
93  			s.getRock(i16).removeChangeListener(this);
94  	}
95  
96  	public void setChanger(final ChangeManager changer) {
97  		final ChangeManager old = this.changer;
98  		if (old == changer)
99  			return;
100 		firePropertyChange("changer", old, this.changer = changer);
101 	}
102 
103 	public abstract void setCurves(ComputedTrajectorySet model);
104 
105 	public void setZoom(final RectangularShape viewport) {
106 		setZoom(viewport, -1);
107 	}
108 
109 }