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  import java.awt.geom.AffineTransform;
27  import java.awt.geom.Rectangle2D;
28  
29  import org.jcurl.core.api.Factory;
30  import org.jcurl.core.api.RockSet;
31  import org.jcurl.core.helpers.NotImplementedYetException;
32  import org.jcurl.core.ui.IceShapes;
33  
34  import com.sun.scenario.scenegraph.SGClip;
35  import com.sun.scenario.scenegraph.SGGroup;
36  import com.sun.scenario.scenegraph.SGNode;
37  import com.sun.scenario.scenegraph.SGShape;
38  import com.sun.scenario.scenegraph.SGText;
39  import com.sun.scenario.scenegraph.SGTransform;
40  import com.sun.scenario.scenegraph.SGAbstractShape.Mode;
41  
42  /**
43   * Creates a pickable node displaying one rock, assuming a <b>RIGHT HANDED</b>
44   * parent coordinate system.
45   * 
46   * @author <a href="mailto:JCurl@mro.name">M. Rohrmoser </a>
47   * @version $Id:PRockFactory.java 795 2008-03-19 13:40:42Z mrohrmoser $
48   */
49  public abstract class SGRockFactory implements Factory {
50  
51  	public static class Fancy extends SGRockFactory {
52  
53  		protected static final IceShapes.RockColors colors = new IceShapes.RockColors();
54  
55  		@Override
56  		public SGNode newInstance(final int i8, final boolean isDark) {
57  			final SGGroup r = new SGGroup();
58  			r.add(node(IceShapes.ROCK_OUTER, colors.granite, null, null));
59  			r.add(node(IceShapes.ROCK_INNER, isDark ? colors.dark
60  					: colors.light, null, null));
61  			{
62  				final SGText t = new SGText();
63  				t.setAntialiasingHint(RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
64  				t.setText(IceShapes.ROCK_LABELS[i8]);
65  				t.setFont(IceShapes.ROCK_LABEL);
66  				t.setDrawPaint(colors.label);
67  
68  				// Make coord-sys left-handed again, as the ice is assumed to be
69  				// right-handed:
70  				final AffineTransform tr = AffineTransform.getScaleInstance(1,
71  						-1);
72  				final Rectangle2D tb = t.getBounds();
73  				tr.translate(-0.015 * tb.getWidth(), 0.015 * tb.getHeight());
74  				tr.scale(1.0 / 5.0, 1.0 / 5.0); // implicit FontSize
75  				final SGClip c = new SGClip();
76  				c.setAntialiased(true);
77  				c.setShape(IceShapes.ROCK_INNER);
78  				c.setChild(SGTransform.createAffine(tr, t));
79  				r.add(c);
80  			}
81  			return r;
82  		}
83  	}
84  
85  	public static class Simple extends Fancy {
86  		private static final Stroke stroke = new BasicStroke(0.010F);
87  
88  		public Simple() {
89  			super();
90  		}
91  
92  		@Override
93  		public SGNode newInstance(final int i8, final boolean isDark) {
94  			// final PRockNode r = new PRockNode(i8, isDark, rock);
95  			// // fill to also make the body, not only the edge
96  			// // pickable:
97  			// r.addChild(node(outer, isDark ? colors.dark : colors.light,
98  			// stroke,
99  			// Color.BLACK));
100 			// r.getChild(0).setPickable(true);
101 			// return r;
102 			throw new NotImplementedYetException();
103 		}
104 	}
105 
106 	static final double EPSILON = 1e-11;
107 
108 	protected static SGShape node(final Shape s, final Paint p,
109 			final Stroke str, final Paint sp) {
110 		final SGShape n = new SGShape();
111 		n.setAntialiasingHint(RenderingHints.VALUE_ANTIALIAS_ON);
112 		n.setShape(s);
113 		if (sp != null)
114 			n.setDrawPaint(sp);
115 		if (p != null)
116 			n.setFillPaint(p);
117 		// n.setPickable(false);
118 		n.setMode(Mode.FILL);
119 		return n;
120 	}
121 
122 	public SGNode newInstance(final int i16) {
123 		return newInstance(RockSet.toIdx8(i16), RockSet.isDark(i16));
124 	}
125 
126 	protected abstract SGNode newInstance(int i8, boolean isDark);
127 }