View Javadoc

1   /*
2    * jcurl java curling software 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  package org.jcurl.demo.tactics.sg;
20  
21  import java.awt.BasicStroke;
22  import java.awt.Paint;
23  import java.awt.RenderingHints;
24  import java.awt.Shape;
25  import java.awt.Stroke;
26  
27  import org.jcurl.core.api.RockProps;
28  import org.jcurl.core.ui.GenTrajectoryFactory;
29  import org.jcurl.core.ui.IceShapes;
30  import org.jcurl.core.ui.JCurlShaper;
31  import org.jcurl.math.R1RNFunction;
32  import org.jcurl.math.Shaper;
33  
34  import com.sun.scenario.scenegraph.SGGroup;
35  import com.sun.scenario.scenegraph.SGShape;
36  import com.sun.scenario.scenegraph.SGAbstractShape.Mode;
37  
38  /**
39   * Create an unpickable {@link SGGroup} for a combined curve describing the path
40   * of one rock.
41   * 
42   * @author <a href="mailto:JCurl@mro.name">M. Rohrmoser </a>
43   * @version $Id:PTrajectoryFactory.java 795 2008-03-19 13:40:42Z mrohrmoser $
44   */
45  public abstract class SGTrajectoryFactory extends GenTrajectoryFactory<SGGroup> {
46  	public static class Fancy extends SGTrajectoryFactory {
47  
48  		private static final Paint dark = IceShapes.trace(
49  				new IceShapes.RockColors().dark, 255);
50  		private static final Paint light = IceShapes.trace(
51  				new IceShapes.RockColors().light, 255);
52  		/** sampling style along the {@link R1RNFunction} */
53  		private static final Shaper sh = new JCurlShaper();
54  		/** start + stop + intermediate */
55  		private static final Stroke stroke = new BasicStroke(
56  				2 * RockProps.DEFAULT.getRadius(), BasicStroke.CAP_ROUND,
57  				BasicStroke.JOIN_ROUND, 0);
58  
59  		@Override
60  		protected void addSegment(final R1RNFunction src, final double tmin,
61  				final double tmax, final boolean isDark, final SGGroup dst) {
62  			final Shape s = sh.toShape(src, tmin, tmax);
63  			if (s == null)
64  				return;
65  			// create a high-quality scenegraph entity
66  			final SGShape c = new SGShape();
67  			c.setShape(s);
68  			c.setDrawStroke(stroke);
69  			c.setDrawPaint(isDark ? dark : light);
70  			c.setAntialiasingHint(RenderingHints.VALUE_ANTIALIAS_ON);
71  			c.setMode(Mode.STROKE);
72  			dst.add(c);
73  		}
74  	}
75  
76  	@Override
77  	protected SGGroup post(final SGGroup parent) {
78  		parent.setVisible(true);
79  		return parent;
80  	}
81  
82  	@Override
83  	protected SGGroup pre(SGGroup parent) {
84  		if (parent == null)
85  			parent = new SGGroup();
86  		parent.setVisible(false);
87  		// remove all children of dst:
88  		for (int i = parent.getChildren().size() - 1; i >= 0; i--)
89  			parent.remove(i);
90  		return parent;
91  	}
92  }