Source code: com/xerox/VTM/engine/AccIView.java
1 /* FILE: AccIView.java
2 * DATE OF CREATION: Jun 08 2000
3 * AUTHOR : Emmanuel Pietriga (emmanuel.pietriga@xrce.xerox.com)
4 * MODIF: Thu Feb 20 16:30:58 2003 by Emmanuel Pietriga
5 * Copyright (c) Xerox Corporation, XRCE/Contextual Computing, 2002. All Rights Reserved
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library 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 GNU
15 * Lesser General Public License for more details.
16 *
17 * For full terms see the file COPYING.
18 */
19
20
21 package com.xerox.VTM.engine;
22
23 import java.util.Vector;
24 import javax.swing.*;
25 import java.awt.event.*;
26 import java.awt.*;
27 import javax.swing.event.*;
28
29
30 /**
31 * An internal view is a window and can be composed of one or several cameras superimposed (uses a JInternalFrame) - <br>
32 * this one is hardware accelerated (at least under Win32) using VolatileImage available since JDK 1.4.0 (does not accelerate bitmaps)
33 * @author Emmanuel Pietriga
34 **/
35
36 public class AccIView extends View implements InternalFrameListener,KeyListener/*,MouseListener*/{
37
38 JInternalFrame frame;
39 IViewContainer ivc;
40
41 /**
42 *@param v list of cameras
43 *@param t view name
44 *@param panelWidth width of window in pixels
45 *@param panelHeight height of window in pixels
46 *@param bar true -> add a status bar to this view (below main panel)
47 *@param visible should the view be made visible automatically or not
48 *@param vsm root VTM class
49 *@param desktop desktop pane containing the internal frame
50 */
51 public AccIView(Vector v,String t,int panelWidth,int panelHeight,boolean bar,boolean visible,VirtualSpaceManager vsm,IViewContainer i,Integer layer){
52 ivc=i;
53 frame=new JInternalFrame(t,true,true,true,true);
54 frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
55 mouse=new VCursor(this);
56 name=t;
57 parent=vsm;
58 detectMultipleFullFills=vsm.defaultMultiFill;
59 initCameras(v); //vector -> cast elements as "Camera"
60 GridBagLayout gridBag=new GridBagLayout();
61 GridBagConstraints constraints=new GridBagConstraints();
62 Container cpane=frame.getContentPane();
63 cpane.setLayout(gridBag);
64 if (bar){
65 buildConstraints(constraints,0,0,1,1,100,90);
66 constraints.fill=GridBagConstraints.BOTH;
67 constraints.anchor=GridBagConstraints.CENTER;
68 panel=new AccViewPanel(v,this);
69 panel.setSize(panelWidth,panelHeight);
70 gridBag.setConstraints(panel,constraints);
71 cpane.add(panel);
72 buildConstraints(constraints,0,1,1,1,0,0);
73 constraints.anchor=GridBagConstraints.WEST;
74 statusBar=new JLabel(" ");
75 gridBag.setConstraints(statusBar,constraints);
76 cpane.add(statusBar);
77 }
78 else {
79 buildConstraints(constraints,0,0,1,1,100,90);
80 constraints.fill=GridBagConstraints.BOTH;
81 constraints.anchor=GridBagConstraints.CENTER;
82 panel=new AccViewPanel(v,this);
83 panel.setSize(panelWidth,panelHeight);
84 gridBag.setConstraints(panel,constraints);
85 cpane.add(panel);
86 }
87 frame.addInternalFrameListener(this);
88 frame.pack();
89 frame.setSize(panelWidth,panelHeight);
90 if (visible){frame.setVisible(true);}
91 //frame.addMouseListener(this);
92 ivc.addIView(this,layer);
93 frame.addKeyListener(this);
94 try {
95 frame.setSelected(true);
96 } catch (java.beans.PropertyVetoException e) {}
97 }
98
99 /**
100 *@param v list of cameras
101 *@param t view name
102 *@param panelWidth width of window in pixels
103 *@param panelHeight height of window in pixels
104 *@param bar true -> add a status bar to this view (below main panel)
105 *@param visible should the view be made visible automatically or not
106 *@param vsm root VTM class
107 *@param desktop desktop pane containing the internal frame
108 *@param mnb a menu bar, already configured with actionListeners already attached to items (it is just added to the view)
109 */
110 public AccIView(Vector v,String t,int panelWidth,int panelHeight,boolean bar,boolean visible,VirtualSpaceManager vsm,IViewContainer i,JMenuBar mnb,Integer layer){
111 ivc=i;
112 frame=new JInternalFrame(t,true,true,true,true);
113 frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
114 frame.setJMenuBar(mnb);
115 mouse=new VCursor(this);
116 name=t;
117 parent=vsm;
118 initCameras(v); //vector -> cast elements as "Camera"
119 GridBagLayout gridBag=new GridBagLayout();
120 GridBagConstraints constraints=new GridBagConstraints();
121 Container cpane=frame.getContentPane();
122 cpane.setLayout(gridBag);
123 if (bar){
124 buildConstraints(constraints,0,0,1,1,100,90);
125 constraints.fill=GridBagConstraints.BOTH;
126 constraints.anchor=GridBagConstraints.CENTER;
127 panel=new AccViewPanel(v,this);
128 panel.setSize(panelWidth,panelHeight);
129 gridBag.setConstraints(panel,constraints);
130 cpane.add(panel);
131 buildConstraints(constraints,0,1,1,1,0,0);
132 constraints.anchor=GridBagConstraints.WEST;
133 statusBar=new JLabel(" ");
134 gridBag.setConstraints(statusBar,constraints);
135 cpane.add(statusBar);
136 }
137 else {
138 buildConstraints(constraints,0,0,1,1,100,90);
139 constraints.fill=GridBagConstraints.BOTH;
140 constraints.anchor=GridBagConstraints.CENTER;
141 panel=new AccViewPanel(v,this);
142 panel.setSize(panelWidth,panelHeight);
143 gridBag.setConstraints(panel,constraints);
144 cpane.add(panel);
145 }
146 frame.addInternalFrameListener(this);
147 frame.pack();
148 frame.setSize(panelWidth,panelHeight);
149 if (visible){frame.setVisible(true);}
150 //frame.addMouseListener(this);
151 ivc.addIView(this,layer);
152 frame.addKeyListener(this);
153 try {
154 frame.setSelected(true);
155 } catch (java.beans.PropertyVetoException e) {}
156 }
157
158 /**get the java.awt.Container for this view*/
159 public Container getFrame(){return frame;}
160
161 /**tells whether this frame is selected or not - not used*/
162 public boolean isSelected(){
163 return frame.isSelected();
164 }
165
166 /**set the window location*/
167 public void setLocation(int x,int y){frame.setLocation(x,y);}
168
169 /**set the window title*/
170 public void setTitle(String t){frame.setTitle(t);}
171
172 /**set the window size*/
173 public void setSize(int x,int y){frame.setSize(x,y);}
174
175 /**can the window be resized or not*/
176 public void setResizable(boolean b){frame.setResizable(b);}
177
178 /**Shows or hides this view*/
179 public void setVisible(boolean b){
180 frame.setVisible(b);
181 if (b){this.activate();}
182 else {this.deactivate();}
183 }
184
185 /**Brings this window to the front. Places this window at the top of the stacking order and shows it in front of any other windows*/
186 public void toFront(){frame.toFront();}
187
188 /**Sends this window to the back. Places this window at the bottom of the stacking order and makes the corresponding adjustment to other visible windows*/
189 public void toBack(){frame.toBack();}
190
191 /**destroy this view*/
192 public void destroyView(){
193 ivc.removeIView(this);
194 panel.stop();
195 parent.destroyView(this.name);
196 frame.dispose();
197 }
198
199 /**
200 *Go in full screen mode and display this View's content - DOES NOT WORK FOR AccIView or IView - use AccEView or EView (external views)
201 */
202 public void goFullScreen(boolean b,DisplayMode dm){}
203
204 public boolean isFullScreen(){return false;}
205
206 public void internalFrameClosing(InternalFrameEvent e) {close();}
207
208 public void internalFrameClosed(InternalFrameEvent e) {}
209
210 public void internalFrameOpened(InternalFrameEvent e) {}
211
212 public void internalFrameIconified(InternalFrameEvent e) {iconify();}
213
214 public void internalFrameDeiconified(InternalFrameEvent e) {deiconify(); }
215
216 public void internalFrameActivated(InternalFrameEvent e) {activate();}
217
218 public void internalFrameDeactivated(InternalFrameEvent e) {deactivate();}
219
220 /**detect key typed and send to application event handler*/
221 public void keyTyped(KeyEvent e){
222 if ((e.getKeyCode()!=KeyEvent.VK_SHIFT) && (e.getKeyCode()!=KeyEvent.VK_CONTROL)) {//do not send ctrl and shift events on their own
223 if (e.isShiftDown()) {
224 if (e.isControlDown()) {panel.evH.Ktype(panel,e.getKeyChar(),e.getKeyCode(),AppEventHandler.CTRL_SHIFT_MOD);}
225 else {panel.evH.Ktype(panel,e.getKeyChar(),e.getKeyCode(),AppEventHandler.SHIFT_MOD);}
226 }
227 else {
228 if (e.isControlDown()) {panel.evH.Ktype(panel,e.getKeyChar(),e.getKeyCode(),AppEventHandler.CTRL_MOD);}
229 else {panel.evH.Ktype(panel,e.getKeyChar(),e.getKeyCode(),AppEventHandler.NO_MODIFIER);}
230 }
231 }
232 }
233
234 /**detect key pressed and send to application event handler*/
235 public void keyPressed(KeyEvent e){
236 if ((e.getKeyCode()!=KeyEvent.VK_SHIFT) && (e.getKeyCode()!=KeyEvent.VK_CONTROL)) {//do not send ctrl and shift events on their own
237 if (e.isShiftDown()) {
238 if (e.isControlDown()) {panel.evH.Kpress(panel,e.getKeyChar(),e.getKeyCode(),AppEventHandler.CTRL_SHIFT_MOD);}
239 else {panel.evH.Kpress(panel,e.getKeyChar(),e.getKeyCode(),AppEventHandler.SHIFT_MOD);}
240 }
241 else {
242 if (e.isControlDown()) {panel.evH.Kpress(panel,e.getKeyChar(),e.getKeyCode(),AppEventHandler.CTRL_MOD);}
243 else {panel.evH.Kpress(panel,e.getKeyChar(),e.getKeyCode(),AppEventHandler.NO_MODIFIER);}
244 }
245 }
246 }
247
248 /**detect key released and send to application event handler*/
249 public void keyReleased(KeyEvent e) {
250 if ((e.getKeyCode()!=KeyEvent.VK_SHIFT) && (e.getKeyCode()!=KeyEvent.VK_CONTROL)) {//do not send ctrl and shift events on their own
251 if (e.isShiftDown()) {
252 if (e.isControlDown()) {panel.evH.Krelease(panel,e.getKeyChar(),e.getKeyCode(),AppEventHandler.CTRL_SHIFT_MOD);}
253 else {panel.evH.Krelease(panel,e.getKeyChar(),e.getKeyCode(),AppEventHandler.SHIFT_MOD);}
254 }
255 else {
256 if (e.isControlDown()) {panel.evH.Krelease(panel,e.getKeyChar(),e.getKeyCode(),AppEventHandler.CTRL_MOD);}
257 else {panel.evH.Krelease(panel,e.getKeyChar(),e.getKeyCode(),AppEventHandler.NO_MODIFIER);}
258 }
259 }
260 }
261
262 /**used only in Internal Views to get focus in view for key events (called automatically when the mouse enters the (Acc)IView)*/
263 public void requestFocus(){
264 frame.requestFocus();
265 }
266
267 // boolean selectOnEntry=true;
268
269 // public void mouseClicked(MouseEvent e){}
270 // public void mousePressed(MouseEvent e){}
271 // public void mouseReleased(MouseEvent e){}
272 // public void mouseEntered(MouseEvent e){
273 // if (selectOnEntry){
274 // ivc.dsk.setSelectedFrame(frame);
275 // try{frame.setSelected(true);}catch(java.beans.PropertyVetoException ex){}
276 // }
277 // }
278 // public void mouseExited(MouseEvent e){
279 // if (selectOnEntry){
280 // try{frame.setSelected(false);}catch(java.beans.PropertyVetoException ex){}
281 // }
282 // }
283
284 }