Blame view

WiimoteWhiteboard/src/org/mote/wiimote/whiteboard/WiimoteWhiteboard.java~ 5.19 KB
593e0a0e   rlentieu   ajout fichiers pr...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
  package org.mote.wiimote.whiteboard;
  
  import java.util.Locale;
  import java.util.logging.Level;
  import java.util.logging.Logger;
  
  import javax.swing.JFrame;
  import javax.swing.JOptionPane;
  
  import org.jdesktop.application.Action;
  import org.jdesktop.application.Application;
  import org.jdesktop.application.SingleFrameApplication;
  import org.mote.wiimote.whiteboard.calibration.CalibrationPersistence;
  import org.mote.wiimote.whiteboard.calibration.WiimoteCalibration;
  import org.mote.wiimote.whiteboard.calibration.WiimoteCalibration.CalibrationEvent;
  import org.mote.wiimote.whiteboard.gui.AboutWindow;
  import org.mote.wiimote.whiteboard.gui.HelpHandler;
  import org.mote.wiimote.whiteboard.gui.LogWindow;
  import org.mote.wiimote.whiteboard.gui.MainPanel;
  import org.mote.wiimote.whiteboard.gui.MenuBar;
  import org.mote.wiimote.whiteboard.gui.PreferencesWindow;
  import org.mote.wiimote.whiteboard.mouse.Mouse;
  import org.mote.wiimote.whiteboard.preferences.WWPreferences;
  import org.mote.wiimote.whiteboard.tuio.TuioTransmitter;
  import org.mote.wiimote.whiteboard.util.BareBonesBrowserLaunch;
  import org.mote.wiimote.whiteboard.util.UpdateNotifier;
  import org.mote.wiimote.whiteboard.util.Util;
  import org.mote.wiimote.whiteboard.util.WiiRemoteJErrorHandler;
  
  import wiiremotej.WiiRemoteJ;
  import apple.dts.samplecode.osxadapter.OSXAdapter;
  
  public class WiimoteWhiteboard extends SingleFrameApplication {
  	
  	public static void main(String args[]) {
  		if (Util.MAC_OS_X && !Util.INSIDE_APP_BUNDLE) {
  			System.setProperty("apple.laf.useScreenMenuBar", "true");
  			System.setProperty("com.apple.mrj.application.apple.menu.about.name", getProperty("id"));
  		}
  		System.setProperty("bluecove.jsr82.psm_minimum_off", "true");
  
  		String lang = WWPreferences.getPreferences().getLanguage();
  		if (lang.length() > 0) {
  			String[] langParts = lang.split("_");
  			switch (langParts.length) {
  				case 1:
  					Locale.setDefault(new Locale(langParts[0]));
  					break;
  				case 2:
  					Locale.setDefault(new Locale(langParts[0], langParts[1]));
  					break;
  			}
  		}
  		Application.launch(WiimoteWhiteboard.class, args);
  	}
  		
  	@Override
  	protected void startup() {
  		try {
  			new Thread(new Runnable() {
  				public void run() {
  					// blocking
  					if (WWPreferences.getPreferences().checkForUpdates())
  						UpdateNotifier.checkForUpdate(getProperty("version"));
  				}
  			}).start();
  			
  			Logger.getLogger("wiimotewhiteboard").setUseParentHandlers(false);
  
  			final JFrame f = getMainFrame();
  			LogWindow lw = new LogWindow();
  			
  			final WiimoteCalibration calibration = new WiimoteCalibration();
  			WiimoteDataHandler dh = new WiimoteDataHandler(calibration);
  			
  //			new IRDotLogger(dh);
  			
  			MainPanel mp = new MainPanel(dh, calibration);
  			AboutWindow af = new AboutWindow();
  			HelpHandler hh = new HelpHandler();
  			PreferencesWindow pf = new PreferencesWindow(mp, hh);
  			f.setJMenuBar(new MenuBar(pf, af, hh, lw));
  			registerForMacOSXEvents(pf, af);
  			
  			// update Mouse's screen
  			calibration.addCalibrationEventListener(new WiimoteCalibration.CalibrationEventListener() {
  				public void calibrationEvent(CalibrationEvent e) {
  					if (e == CalibrationEvent.SCREEN_CHANGED)
  					Mouse.setScreen(calibration.getScreen());
  				}
  			});
  
  			// add persistence as last listener because it indirectly generates new calibration events
  			new CalibrationPersistence(calibration);
  			// TODO save last used screen?
  			calibration.setScreen(WiimoteCalibration.DEFAULT_SCREEN);
  			
  			new TuioTransmitter(dh, calibration);
  			
  			WiiRemoteJ.setConsoleLoggingErrors();
  			Logger.getLogger("wiiremotej").setLevel(Level.ALL);
  			Logger.getLogger("wiiremotej").addHandler(new WiiRemoteJErrorHandler(dh));
  			
  			try {
  				// restore session manually before 'show' on the main panel is
  				// called. this is a fix to the problem that the session is not
  				// restored; apparently because mainFrame is not resizable
  				getContext().getSessionStorage().restore(f, "mainFrame.session.xml");
  			} catch (Exception e) {}
  			
  			show(mp);
  			// f.pack() is called in 'show' above if f.isValid() == false
  			f.pack();
  			
  		} catch (Exception e) {
  			e.printStackTrace();
  			getLogger().log(Level.SEVERE, "Error on startup", e);
  			JOptionPane.showMessageDialog(null, e.getMessage(), getProperty("id"), JOptionPane.ERROR_MESSAGE);
  			exit();
  		}
  	}
  	
  	/*
  	 * MAC OS X HOOKS
  	 */	
  	private void registerForMacOSXEvents(PreferencesWindow pf, AboutWindow af) {
  		if (Util.MAC_OS_X) {
  	        try {
  				OSXAdapter.setQuitHandler(this, WiimoteWhiteboard.class.getDeclaredMethod("quitApp", (Class[])null));				
  				if (!Util.INSIDE_APP_BUNDLE) {
  					OSXAdapter.setAboutHandler(af, AboutWindow.class.getDeclaredMethod("about", (Class[])null));
  				}
  				OSXAdapter.setPreferencesHandler(pf, PreferencesWindow.class.getDeclaredMethod("preferences", (Class[])null));
  			} catch (Exception e) {
  				e.printStackTrace();
  			}
  		}
  	}
  	
  	@Action
  	public boolean quitApp() {
  		exit();
  		return false;
  	}
  	
  	@Action
  	public void donate() {
  		BareBonesBrowserLaunch.openURL(getProperty("donateURL"));
  	}
  	
  	public static String getProperty(String key) {
  		return Util.getResourceMap(WiimoteWhiteboard.class).getString("Application."+key);
  	}
  	
  	public static Logger getLogger() {
  		return Logger.getLogger("wiimotewhiteboard");
  	}
  	
  }