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.old;
20  
21  import java.awt.BorderLayout;
22  import java.awt.Color;
23  import java.awt.Container;
24  import java.awt.Dimension;
25  import java.awt.Image;
26  import java.awt.event.WindowAdapter;
27  import java.awt.event.WindowEvent;
28  import java.io.IOException;
29  import java.util.prefs.BackingStoreException;
30  import java.util.prefs.Preferences;
31  
32  import javax.imageio.ImageIO;
33  import javax.swing.Box;
34  import javax.swing.JFrame;
35  import javax.swing.JLabel;
36  import javax.swing.JMenuBar;
37  import javax.swing.JTabbedPane;
38  import javax.swing.SwingConstants;
39  
40  import org.jcurl.core.ui.TaskExecutor.SwingEDT;
41  import org.jcurl.demo.tactics.BroomPromptSwingBean;
42  import org.jcurl.demo.tactics.TrajectoryPiccoloBean;
43  
44  /**
45   * @author <a href="mailto:JCurl@mro.name">M. Rohrmoser </a>
46   * @version $Id: MainApp.java 1031 2009-07-23 15:06:05Z mro $
47   */
48  public class MainApp extends JFrame {
49  
50  	private static final long serialVersionUID = 3398372625156897223L;
51  
52  	public static void main(final String[] args) {
53  		final JFrame f = new MainApp();
54  		f.setSize(600, 800);
55  		f.setVisible(true);
56  		// zoom to the house smoothely
57  		ActionRegistry.invoke(MenuView.class, "zoomHouse", SwingEDT.class);
58  		if (false) {
59  			try {
60  				Thread.sleep(500);
61  			} catch (final InterruptedException e1) {
62  				return;
63  			}
64  			// load hammy by default
65  			ActionRegistry.invoke(MenuFile.Controller.class, "showHammy",
66  					SwingEDT.class);
67  		}
68  		if (false) {
69  			final Preferences p = Preferences.userNodeForPackage(MainApp.class);
70  			p.putLong("lastStartMillis", System.currentTimeMillis());
71  			try {
72  				p.flush();
73  			} catch (final BackingStoreException e) {
74  				throw new RuntimeException("Unhandled", e);
75  			}
76  		}
77  		if (false) {
78  			System.out.println("Packages: ");
79  			for (final Package p : Package.getPackages())
80  				System.out.println(p.toString());
81  		}
82  	}
83  
84  	private MainApp() {
85  		{
86  			final Image i;
87  			if (true)
88  				try {
89  					i = ImageIO.read(this.getClass().getResource(
90  							"/" + "org/jcurl/demo/tactics/resources" + "/"
91  									+ "favicon-32x32.png"));
92  				} catch (final IOException e) {
93  					throw new RuntimeException("Unhandled", e);
94  				}
95  			setIconImage(i);
96  		}
97  		setTitle("JCurl Shot Planner - JCurl.mro.name");
98  		final JMenuBar mb = new JMenuBar();
99  		final TrajectoryPiccoloBean tp = new TrajectoryPiccoloBean();
100 		tp.setBackground(new Color(0xE8E8FF));
101 		final ActionRegistry ah = ActionRegistry.getInstance();
102 		{
103 			final MenuFile.Controller con = new MenuFile.Controller(this, tp,
104 					tp);
105 			ah.registerController(con);
106 			addWindowListener(new WindowAdapter() {
107 				@Override
108 				public void windowClosing(final WindowEvent e) {
109 					con.exitFile();
110 				}
111 			});
112 			mb.add(ah.createJMenu(con));
113 			ah.findAction(con, "clear").setEnabled(true);
114 			ah.findAction(con, "showHammy").setEnabled(true);
115 			ah.findAction(con, "openFile").setEnabled(true);
116 			ah.findAction(con, "newFile").setEnabled(true);
117 			ah.findAction(con, "screenShot").setEnabled(true);
118 			// ah.findAction(con, "exportSvg").setEnabled(true);
119 			ah.findAction(con, "exitFile").setEnabled(true);
120 			ah.findAction(con, "saveAsFile").setEnabled(true);
121 		}
122 		{
123 			final MenuEdit.Controller con = new MenuEdit.Controller();
124 			ah.registerController(con);
125 			mb.add(ah.createJMenu(con));
126 		}
127 		{
128 			final MenuView con = new MenuView();
129 			ah.registerController(con);
130 			mb.add(ah.createJMenu(con));
131 			con.setModel(tp);
132 		}
133 		{
134 			final MenuHelp con = new MenuHelp();
135 			ah.registerController(con);
136 			mb.add(ah.createJMenu(con));
137 			ah.findAction(con, "helpAbout").setEnabled(true);
138 		}
139 		setJMenuBar(mb);
140 		final Container c = getContentPane();
141 		c.setLayout(new BorderLayout());
142 		c.add(tp, BorderLayout.CENTER);
143 
144 		// add the swing widget based trajectory manipulation
145 		final Box b = Box.createVerticalBox();
146 
147 		final JTabbedPane t = new JTabbedPane(SwingConstants.TOP,
148 				JTabbedPane.SCROLL_TAB_LAYOUT);
149 		final BroomPromptSwingBean ts = new BroomPromptSwingBean();
150 		t.add("Rock", ts);
151 		t.setMnemonicAt(0, 'R');
152 		t.add("Ice", new JLabel("TODO: Ice settings"));
153 		t.setMnemonicAt(1, 'I');
154 		t.add("Collission", new JLabel("TODO: Collission settings"));
155 		t.setMnemonicAt(2, 'C');
156 
157 		b.add(t);
158 		b.add(new Box.Filler(new Dimension(0, 0), new Dimension(1,
159 				Integer.MAX_VALUE), new Dimension(Integer.MAX_VALUE,
160 				Integer.MAX_VALUE)));
161 
162 		c.add(b, BorderLayout.EAST);
163 
164 		pack();
165 	}
166 }