Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/xerox/VTM/engine/AccEView.java


1   /*   FILE: AccEView.java
2    *   DATE OF CREATION:   Jun 08 2000
3    *   AUTHOR :            Emmanuel Pietriga (emmanuel.pietriga@xrce.xerox.com)
4    *   MODIF:              Thu Feb 20 16:30:17 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  package com.xerox.VTM.engine;
21  
22  import java.util.Vector;
23  import javax.swing.*;
24  import java.awt.event.*;
25  import java.awt.*;
26  import java.awt.event.*;
27  
28  
29    /**
30     * An external view is a window and can be composed of one or several cameras superimposed (uses a standard JFrame)
31     * this one is hardware accelerated (at least under Win32) using VolatileImage available since JDK 1.4.0 (does not accelerate bitmaps)
32     * @author Emmanuel Pietriga
33     **/
34  
35  public class AccEView extends View implements KeyListener{
36  
37      JFrame frame;
38  
39      boolean isFullScreen=false;
40      DisplayMode oldDM;  //remember old display mode before going into full screen mode
41      Dimension origDim;
42      JMenuBar jmb;
43  
44      /**
45       *@param v list of cameras
46       *@param t view name
47       *@param panelWidth width of window in pixels
48       *@param panelHeight height of window in pixels
49       *@param bar true -> add a status bar to this view (below main panel)
50       *@param visible should the view be made visible automatically or not
51       *@param vsm root VTM class
52       */
53      protected AccEView(Vector v,String t,int panelWidth,int panelHeight,boolean bar,boolean visible,VirtualSpaceManager vsm){
54    frame=new JFrame();
55    frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
56    mouse=new VCursor(this);
57    name=t;
58    parent=vsm;
59    detectMultipleFullFills=vsm.defaultMultiFill;
60    initCameras(v);   //vector -> cast elements as "Camera"
61    GridBagLayout gridBag=new GridBagLayout();
62    GridBagConstraints constraints=new GridBagConstraints();
63    Container cpane=frame.getContentPane();
64    cpane.setLayout(gridBag);
65    if (bar){
66        buildConstraints(constraints,0,0,1,1,100,90);
67        constraints.fill=GridBagConstraints.BOTH;
68        constraints.anchor=GridBagConstraints.CENTER;
69        panel=new AccViewPanel(v,this);
70        panel.setSize(panelWidth,panelHeight);
71        gridBag.setConstraints(panel,constraints);
72        cpane.add(panel);
73        buildConstraints(constraints,0,1,1,1,0,0);
74        constraints.anchor=GridBagConstraints.WEST;
75        statusBar=new JLabel(" ");
76        gridBag.setConstraints(statusBar,constraints);
77        cpane.add(statusBar);
78    }
79    else {
80        buildConstraints(constraints,0,0,1,1,100,90);
81        constraints.fill=GridBagConstraints.BOTH;
82        constraints.anchor=GridBagConstraints.CENTER;
83        panel=new AccViewPanel(v,this);
84        panel.setSize(panelWidth,panelHeight);
85        gridBag.setConstraints(panel,constraints);
86        cpane.add(panel);
87    }
88    frame.setTitle(t);
89    WindowListener l=new WindowAdapter(){
90      public void windowClosing(WindowEvent e){close();}
91      public void windowActivated(WindowEvent e){activate();}
92      public void windowDeactivated(WindowEvent e){deactivate();}
93      public void windowIconified(WindowEvent e){iconify();}
94      public void windowDeiconified(WindowEvent e){deiconify();}
95        };
96    frame.addWindowListener(l);
97    frame.addKeyListener(this);
98    frame.pack();
99    frame.setSize(panelWidth,panelHeight);
100   if (visible){frame.setVisible(true);}
101     }
102 
103     /**
104      *@param v list of cameras
105      *@param t view name
106      *@param panelWidth width of window in pixels
107      *@param panelHeight height of window in pixels
108      *@param bar true -> add a status bar to this view (below main panel)
109      *@param visible should the view be made visible automatically or not
110      *@param vsm root VTM class
111      *@param mnb a menu bar, already configured with actionListeners already attached to items (it is just added to the view)
112      */
113     public AccEView(Vector v,String t,int panelWidth,int panelHeight,boolean bar,boolean visible,VirtualSpaceManager vsm,JMenuBar mnb){
114   frame=new JFrame();
115   frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
116   frame.setJMenuBar(mnb);
117   this.jmb=mnb;
118   mouse=new VCursor(this);
119   name=t;
120   parent=vsm;
121   initCameras(v);   //vector -> cast elements as "Camera"
122   GridBagLayout gridBag=new GridBagLayout();
123   GridBagConstraints constraints=new GridBagConstraints();
124   Container cpane=frame.getContentPane();
125   cpane.setLayout(gridBag);
126   if (bar){
127       buildConstraints(constraints,0,0,1,1,100,90);
128       constraints.fill=GridBagConstraints.BOTH;
129       constraints.anchor=GridBagConstraints.CENTER;
130       panel=new AccViewPanel(v,this);
131       panel.setSize(panelWidth,panelHeight);
132       gridBag.setConstraints(panel,constraints);
133       cpane.add(panel);
134       buildConstraints(constraints,0,1,1,1,0,0);
135       constraints.anchor=GridBagConstraints.WEST;
136       statusBar=new JLabel(" ");
137       gridBag.setConstraints(statusBar,constraints);
138       cpane.add(statusBar);
139   }
140   else {
141       buildConstraints(constraints,0,0,1,1,100,90);
142       constraints.fill=GridBagConstraints.BOTH;
143       constraints.anchor=GridBagConstraints.CENTER;
144       panel=new AccViewPanel(v,this);
145       panel.setSize(panelWidth,panelHeight);
146       gridBag.setConstraints(panel,constraints);
147       cpane.add(panel);
148   }
149   frame.setTitle(t);
150   WindowListener l=new WindowAdapter(){
151     public void windowClosing(WindowEvent e){close();}
152     public void windowActivated(WindowEvent e){activate();}
153     public void windowDeactivated(WindowEvent e){deactivate();}
154     public void windowIconified(WindowEvent e){iconify();}
155     public void windowDeiconified(WindowEvent e){deiconify();}
156       };
157   frame.addWindowListener(l);
158   frame.addKeyListener(this);
159   frame.pack();
160   frame.setSize(panelWidth,panelHeight);
161   if (visible){frame.setVisible(true);}
162     }
163 
164     /**get the java.awt.Container for this view*/
165     public Container getFrame(){return frame;}
166 
167     /**tells whether this frame is selected or not - not used*/
168     public boolean isSelected(){
169   if (this.frame==parent.activeJFrame){return true;}else{return false;}
170     } 
171 
172     /**set the window location*/
173     public void setLocation(int x,int y){frame.setLocation(x,y);}
174 
175     /**set the window title*/
176     public void setTitle(String t){frame.setTitle(t);}
177 
178     /**set the window size*/
179     public void setSize(int x,int y){frame.setSize(x,y);}
180 
181     /**can the window be resized or not*/
182     public void setResizable(boolean b){frame.setResizable(b);}
183 
184     /**Shows or hides this view*/
185     public void setVisible(boolean b){
186   frame.setVisible(b);
187   if (b){this.activate();}
188   else {this.deactivate();}
189     }
190 
191     /**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*/
192     public void toFront(){frame.toFront();}
193 
194     /**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*/
195     public void toBack(){frame.toBack();}
196 
197     /**destroy this view*/
198     public void destroyView(){
199   panel.stop();
200   parent.destroyView(this.name);
201   frame.dispose();
202     }
203 
204     /**
205      *Go in full screen mode and display this View's content
206      *@param b true to go in full screen mode, false to exit full screen mode
207      *@param dm the java.awt.DisplayMode used in full screen mode (current OS mode is null - no change) ; use GraphicsDevice.getDisplayModes() to get a list of available display modes - not taken into account if b=false (automatically reverts back to the original mode)
208      */
209     public void goFullScreen(boolean b,DisplayMode dm){
210   if (b){
211       if (!isFullScreen){
212     GraphicsDevice gd=GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
213     if (gd.isFullScreenSupported()){
214         oldDM=gd.getDisplayMode();
215         origDim=frame.getSize();
216         try {
217       gd.setFullScreenWindow(frame);
218       isFullScreen=true;
219       if (gd.isDisplayChangeSupported()){
220           frame.dispose();
221           if (jmb!=null){frame.setJMenuBar(null);}
222           try {frame.setUndecorated(true);}
223           catch (IllegalComponentStateException ex7){System.err.println("EView.goFullScreen(): Error while exiting full screen mode : ");ex7.printStackTrace();}
224           
225           frame.setSize(dm.getWidth(),dm.getHeight());
226           frame.setResizable(false);
227           frame.show();
228           gd.setDisplayMode(dm);
229           frame.validate();
230       }
231         }
232         catch (Exception ex) {
233       if (gd.isDisplayChangeSupported()){gd.setDisplayMode(oldDM);}
234       gd.setFullScreenWindow(null);
235       System.err.println("ZVTM.AccEView: Error while trying to enter full screen mode");
236       ex.printStackTrace();
237         }
238     }
239       }
240   }
241   else {
242       GraphicsDevice gd=GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
243       if (gd.isFullScreenSupported()){
244     if (isFullScreen){
245         if (oldDM!=null && gd.isDisplayChangeSupported()){gd.setDisplayMode(oldDM);}
246         frame.dispose();
247         try {frame.setUndecorated(false);}
248         catch (IllegalComponentStateException ex){System.err.println("EView.goFullScreen(): Error while exiting full screen mode : ");ex.printStackTrace();}
249         if (jmb!=null){frame.setJMenuBar(jmb);}
250         gd.setFullScreenWindow(null);
251         isFullScreen=false;
252         frame.show();
253         frame.setResizable(true);
254         frame.setSize(origDim);
255     }
256       }
257   }
258     }
259 
260     public boolean isFullScreen(){return isFullScreen;}
261 
262     /**detect key typed and send to application event handler*/
263     public void keyTyped(KeyEvent e){
264   if ((e.getKeyCode()!=KeyEvent.VK_SHIFT) && (e.getKeyCode()!=KeyEvent.VK_CONTROL)) {//do not send ctrl and shift events on their own
265       if (e.isShiftDown()) {
266     if (e.isControlDown()) {panel.evH.Ktype(panel,e.getKeyChar(),e.getKeyCode(),AppEventHandler.CTRL_SHIFT_MOD);}
267     else {panel.evH.Ktype(panel,e.getKeyChar(),e.getKeyCode(),AppEventHandler.SHIFT_MOD);}
268       }
269       else {
270     if (e.isControlDown()) {panel.evH.Ktype(panel,e.getKeyChar(),e.getKeyCode(),AppEventHandler.CTRL_MOD);}
271     else {panel.evH.Ktype(panel,e.getKeyChar(),e.getKeyCode(),AppEventHandler.NO_MODIFIER);}
272       }
273   }
274     }
275 
276     /**detect key pressed and send to application event handler*/
277     public void keyPressed(KeyEvent e){
278   if ((e.getKeyCode()!=KeyEvent.VK_SHIFT) && (e.getKeyCode()!=KeyEvent.VK_CONTROL)) {//do not send ctrl and shift events on their own
279       if (e.isShiftDown()) {
280     if (e.isControlDown()) {panel.evH.Kpress(panel,e.getKeyChar(),e.getKeyCode(),AppEventHandler.CTRL_SHIFT_MOD);}
281     else {panel.evH.Kpress(panel,e.getKeyChar(),e.getKeyCode(),AppEventHandler.SHIFT_MOD);}
282       }
283       else {
284     if (e.isControlDown()) {panel.evH.Kpress(panel,e.getKeyChar(),e.getKeyCode(),AppEventHandler.CTRL_MOD);}
285     else {panel.evH.Kpress(panel,e.getKeyChar(),e.getKeyCode(),AppEventHandler.NO_MODIFIER);}
286       }
287   }
288     }
289 
290     /**detect key released and send to application event handler*/
291     public void keyReleased(KeyEvent e) {
292   if ((e.getKeyCode()!=KeyEvent.VK_SHIFT) && (e.getKeyCode()!=KeyEvent.VK_CONTROL)) {//do not send ctrl and shift events on their own
293       if (e.isShiftDown()) {
294     if (e.isControlDown()) {panel.evH.Krelease(panel,e.getKeyChar(),e.getKeyCode(),AppEventHandler.CTRL_SHIFT_MOD);}
295     else {panel.evH.Krelease(panel,e.getKeyChar(),e.getKeyCode(),AppEventHandler.SHIFT_MOD);}
296       }
297       else {
298     if (e.isControlDown()) {panel.evH.Krelease(panel,e.getKeyChar(),e.getKeyCode(),AppEventHandler.CTRL_MOD);}
299     else {panel.evH.Krelease(panel,e.getKeyChar(),e.getKeyCode(),AppEventHandler.NO_MODIFIER);}
300       }
301   }
302     }
303 
304     /**used only in Internal Views to get focus in view for key events (called automatically when the mouse enters the (Acc)IView)*/
305     public void requestFocus(){}
306 
307 }