|
1 /* |
|
2 TUIO Java Demo - part of the reacTIVision project |
|
3 http://reactivision.sourceforge.net/ |
|
4 |
|
5 Copyright (c) 2005-2009 Martin Kaltenbrunner <mkalten@iua.upf.edu> |
|
6 |
|
7 This program is free software; you can redistribute it and/or modify |
|
8 it under the terms of the GNU General Public License as published by |
|
9 the Free Software Foundation; either version 2 of the License, or |
|
10 (at your option) any later version. |
|
11 |
|
12 This program is distributed in the hope that it will be useful, |
|
13 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15 GNU General Public License for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with this program; if not, write to the Free Software |
|
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
20 */ |
|
21 |
|
22 import java.awt.*; |
|
23 import java.awt.geom.*; |
|
24 import java.awt.event.*; |
|
25 import java.awt.image.*; |
|
26 import java.util.*; |
|
27 import javax.swing.*; |
|
28 import TUIO.*; |
|
29 |
|
30 public class TuioDemo { |
|
31 |
|
32 private final int window_width = 640; |
|
33 private final int window_height = 480; |
|
34 |
|
35 private boolean fullscreen = false; |
|
36 |
|
37 private TuioDemoComponent demo; |
|
38 private JFrame frame; |
|
39 private GraphicsDevice device; |
|
40 |
|
41 public TuioDemo() { |
|
42 demo = new TuioDemoComponent(); |
|
43 device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); |
|
44 setupWindow(); |
|
45 showWindow(); |
|
46 } |
|
47 |
|
48 public TuioListener getTuioListener() { |
|
49 return demo; |
|
50 } |
|
51 |
|
52 public void setupWindow() { |
|
53 |
|
54 frame = new JFrame(); |
|
55 frame.add(demo); |
|
56 |
|
57 frame.setTitle("TuioDemo"); |
|
58 frame.setResizable(false); |
|
59 |
|
60 frame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent evt) { |
|
61 System.exit(0); |
|
62 } }); |
|
63 |
|
64 frame.addKeyListener( new KeyAdapter() { public void keyPressed(KeyEvent evt) { |
|
65 if (evt.getKeyCode()==KeyEvent.VK_ESCAPE) System.exit(0); |
|
66 else if (evt.getKeyCode()==KeyEvent.VK_F1) { |
|
67 destroyWindow(); |
|
68 setupWindow(); |
|
69 fullscreen = !fullscreen; |
|
70 showWindow(); |
|
71 } |
|
72 else if (evt.getKeyCode()==KeyEvent.VK_V) demo.verbose=!demo.verbose; |
|
73 } }); |
|
74 } |
|
75 |
|
76 public void destroyWindow() { |
|
77 |
|
78 frame.setVisible(false); |
|
79 if (fullscreen) { |
|
80 device.setFullScreenWindow(null); |
|
81 } |
|
82 frame = null; |
|
83 } |
|
84 |
|
85 public void showWindow() { |
|
86 |
|
87 if (fullscreen) { |
|
88 int width = (int)Toolkit.getDefaultToolkit().getScreenSize().getWidth(); |
|
89 int height = (int)Toolkit.getDefaultToolkit().getScreenSize().getHeight(); |
|
90 demo.setSize(width,height); |
|
91 |
|
92 frame.setSize(width,height); |
|
93 frame.setUndecorated(true); |
|
94 device.setFullScreenWindow(frame); |
|
95 } else { |
|
96 int width = window_width; |
|
97 int height = window_height; |
|
98 demo.setSize(width,height); |
|
99 |
|
100 frame.pack(); |
|
101 Insets insets = frame.getInsets(); |
|
102 frame.setSize(width,height +insets.top); |
|
103 |
|
104 } |
|
105 |
|
106 frame.setVisible(true); |
|
107 frame.repaint(); |
|
108 |
|
109 } |
|
110 |
|
111 public static void main(String argv[]) { |
|
112 |
|
113 TuioDemo demo = new TuioDemo(); |
|
114 TuioClient client = null; |
|
115 |
|
116 switch (argv.length) { |
|
117 case 1: |
|
118 try { |
|
119 client = new TuioClient( Integer.parseInt(argv[0])); |
|
120 } catch (Exception e) { |
|
121 System.out.println("usage: java TuioDemo [port]"); |
|
122 System.exit(0); |
|
123 } |
|
124 break; |
|
125 case 0: |
|
126 client = new TuioClient(); |
|
127 break; |
|
128 default: |
|
129 System.out.println("usage: java TuioDemo [port]"); |
|
130 System.exit(0); |
|
131 break; |
|
132 } |
|
133 |
|
134 if (client!=null) { |
|
135 client.addTuioListener(demo.getTuioListener()); |
|
136 client.connect(); |
|
137 } else { |
|
138 System.out.println("usage: java TuioDemo [port]"); |
|
139 System.exit(0); |
|
140 } |
|
141 } |
|
142 |
|
143 } |