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.zui;
20  
21  import java.awt.Color;
22  import java.awt.geom.Rectangle2D;
23  import java.beans.PropertyChangeEvent;
24  import java.beans.PropertyChangeListener;
25  
26  import javax.swing.JFrame;
27  import javax.swing.SwingUtilities;
28  import javax.swing.WindowConstants;
29  import javax.swing.event.ChangeEvent;
30  import javax.swing.event.ChangeListener;
31  
32  import org.apache.commons.logging.Log;
33  import org.jcurl.core.api.IceSize;
34  import org.jcurl.core.api.RockProps;
35  import org.jcurl.core.api.Unit;
36  import org.jcurl.core.log.JCLoggerFactory;
37  import org.jcurl.core.ui.BroomPromptModel;
38  import org.jcurl.core.ui.DefaultBroomPromptModel;
39  import org.jcurl.zui.piccolo.BroomPromptSimple;
40  import org.jcurl.zui.piccolo.PIceFactory;
41  
42  import edu.umd.cs.piccolo.PCamera;
43  import edu.umd.cs.piccolo.PCanvas;
44  import edu.umd.cs.piccolo.PNode;
45  import edu.umd.cs.piccolo.activities.PInterpolatingActivity;
46  import edu.umd.cs.piccolo.util.PPaintContext;
47  
48  public class BroomPromptDemo {
49  	/** All from back to back */
50  	static final Rectangle2D completeP;
51  	/** House area plus 1 rock margin plus "out" rock space. */
52  	static final Rectangle2D houseP;
53  	private static final Log log = JCLoggerFactory
54  			.getLogger(BroomPromptDemo.class);
55  	/**
56  	 * Inter-hog area area plus house area plus 1 rock margin plus "out" rock
57  	 * space.
58  	 */
59  	static final Rectangle2D sheetP;
60  
61  	/** 12-foot circle plus 1 rock */
62  	static final Rectangle2D twelveP;
63  
64  	static {
65  		final double r2 = 2 * RockProps.DEFAULT.getRadius();
66  		final double x = IceSize.SIDE_2_CENTER + r2;
67  		houseP = new Rectangle2D.Double(-x, -(IceSize.HOG_2_TEE + r2), 2 * x,
68  				IceSize.HOG_2_TEE + IceSize.BACK_2_TEE + 3 * r2 + 2 * r2);
69  		final double c12 = r2 + Unit.f2m(6.0);
70  		twelveP = new Rectangle2D.Double(-c12, -c12, 2 * c12, 2 * c12);
71  		sheetP = new Rectangle2D.Double(-x, -(IceSize.HOG_2_HOG
72  				+ IceSize.HOG_2_TEE + r2), 2 * x, IceSize.HOG_2_HOG
73  				+ IceSize.HOG_2_TEE + IceSize.BACK_2_TEE + 3 * r2 + 2 * r2);
74  		completeP = new Rectangle2D.Double(-x, -(IceSize.HOG_2_TEE
75  				+ IceSize.HOG_2_HOG + IceSize.HACK_2_HOG + r2), 2 * x,
76  				IceSize.HOG_2_HOG + 2 * IceSize.HACK_2_HOG);
77  	}
78  
79  	private static PCamera animateToBounds(final PCamera c,
80  			final Rectangle2D r, final long duration) {
81  		final PInterpolatingActivity pi = c.animateViewToCenterBounds(r, true,
82  				duration);
83  		return c;
84  	}
85  
86  	public static void main(final String[] args) {
87  		SwingUtilities.invokeLater(new Runnable() {
88  			public void run() {
89  				final JFrame application = new JFrame();
90  				application.setTitle("JCurl BroomPrompt");
91  				application
92  						.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
93  				final PCanvas pc = new PCanvas();
94  				pc
95  						.setAnimatingRenderQuality(PPaintContext.HIGH_QUALITY_RENDERING);
96  				pc
97  						.setInteractingRenderQuality(PPaintContext.HIGH_QUALITY_RENDERING);
98  				// pc.getRoot().getDefaultInputManager().setKeyboardFocus(
99  				// new KeyboardZoom(pc.getCamera()));
100 				pc.setBackground(new Color(0xE8E8FF));
101 
102 				final PNode ice = new PIceFactory.Fancy().newInstance();
103 				pc.getLayer().addChild(ice);
104 				application.getContentPane().add(pc);
105 				application.setSize(500, 800);
106 				application.setVisible(true);
107 				animateToBounds(pc.getCamera(), twelveP, 500);
108 				final BroomPromptSimple bp;
109 				ice.addChild(bp = new BroomPromptSimple());
110 				final BroomPromptModel bpm;
111 				bp.setModel(bpm = new DefaultBroomPromptModel());
112 				bpm.addPropertyChangeListener(new PropertyChangeListener() {
113 					public void propertyChange(final PropertyChangeEvent evt) {
114 						// FIXME why doesn't fire this?
115 						log.info(evt);
116 					}
117 				});
118 				bpm.getSplitTimeMillis().addChangeListener(
119 						new ChangeListener() {
120 							public void stateChanged(final ChangeEvent e) {
121 								log.info(e);
122 							}
123 						});
124 				bpm.setIdx16(1);
125 				bpm.setOutTurn(false);
126 				bp
127 						.animateToPositionScaleRotation(1, 2, 1,
128 								-0.1 * Math.PI, 5000);
129 			}
130 		});
131 	}
132 }