/[classpath]/classpath/java/awt/Window.java
ViewVC logotype

Diff of /classpath/java/awt/Window.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.8 by mark, Sun Jan 13 15:45:15 2002 UTC revision 1.9 by tromey, Wed Jan 16 04:20:15 2002 UTC
# Line 1  Line 1 
1  /* Window.java -- Toplevel window object  /* Copyright (C) 1999, 2000, 2002  Free Software Foundation
2    
3     Copyright (C) 1999 Free Software Foundation, Inc.     Copyright (C) 1999 Free Software Foundation, Inc.
4    
5  This file is part of GNU Classpath.  This file is part of GNU Classpath.
# Line 24  resulting executable to be covered by th Line 25  resulting executable to be covered by th
25  This exception does not however invalidate any other reasons why the  This exception does not however invalidate any other reasons why the
26  executable file might be covered by the GNU General Public License. */  executable file might be covered by the GNU General Public License. */
27    
   
28  package java.awt;  package java.awt;
   
29  import java.awt.event.WindowEvent;  import java.awt.event.WindowEvent;
30  import java.awt.event.WindowListener;  import java.awt.event.WindowListener;
31  import java.awt.peer.WindowPeer;  import java.awt.peer.WindowPeer;
 import java.awt.peer.ContainerPeer;  
32  import java.awt.peer.ComponentPeer;  import java.awt.peer.ComponentPeer;
33    import java.util.EventListener;
34  import java.util.Locale;  import java.util.Locale;
35    import java.util.ResourceBundle;
36    
37  /**  /**
38    * This class represents a top-level window with no decorations.   * This class represents a top-level window with no decorations.
39    *   *
40    * @author Aaron M. Renn (arenn@urbanophile.com)   * @author Aaron M. Renn (arenn@urbanophile.com)
41    */   * @author Warren Levy  <warrenl@cygnus.com>
 public class Window extends Container implements java.io.Serializable  
 {  
   
 // FIXME: Serialization  
   
 /*  
  * Static Variables  
42   */   */
43    public class Window extends Container
 private static final String defaultWarningString = "Warning: Applet Window";  
   
 /*************************************************************************/  
   
 /*  
  * Instance Variables  
  */  
   
 /**  
   * @serial A string that is displayed if this window is being popped up  
   * by an unsecure applet or application.  
   */  
 private String warningString = defaultWarningString;  
   
 // List of listeners for window events.  
 private WindowListener window_listeners;  
   
 /*************************************************************************/  
   
 /*  
  * Constructors  
  */  
   
 /**  
   * Initializes a new instance of <code>Window</code> with the specified  
   * parent.  The window will initially be invisible.  
   *  
   * @param parent The owning <code>Frame</code> of this window.  
   */  
 public  
 Window(Frame parent)  
 {  
   setParent(parent);  
   
   // FIXME: SecurityManager check for toplevel window.  
   // FIXME: How should we add to parent/create peer?  This is not really  
   // a child component of the parent container.  
   if (parent != null)  
     {  
       parent.ownedWindows.addElement(this);  
     }  
   is_notified = true;  
 }  
   
 /*************************************************************************/  
   
 /*  
  * Instance Methods  
  */  
   
 /**  
   * Returns the warning string that will be displayed if this window is  
   * popped up by an unsecure applet or application.  
   *  
   * @return The unsecure window warning message.  
   */  
 public final String  
 getWarningString()  
 {  
   return(warningString);  
 }  
   
 /*************************************************************************/  
   
 /**  
   * Adds the specified listener to the list of <code>WindowListeners</code>  
   * that will receive events for this window.  
   *  
   * @param listener The <code>WindowListener</code> to add.  
   */  
 public synchronized void  
 addWindowListener(WindowListener listener)  
 {  
   window_listeners = AWTEventMulticaster.add(window_listeners, listener);  
 }  
   
 /*************************************************************************/  
   
 /**  
   * Removes the specified listener from the list of  
   * <code>WindowListeners</code> that will receive events for this window.  
   *  
   * @param listener The <code>WindowListener</code> to remove.  
   */  
 public synchronized void  
 removeWindowListener(WindowListener listener)  
44  {  {
45    window_listeners = AWTEventMulticaster.remove(window_listeners, listener);    // Serialized fields, from Sun's serialization spec.
46  }    // private FocusManager focusMgr;  // FIXME: what is this?  
47      private String warningString = null;
48  /*************************************************************************/    private int state = 0;
49      private int windowSerializedDataVersion = 0; // FIXME
50  /**  
51    * Processes the specified event for this window.  If the event is an    private transient WindowListener windowListener;
52    * instance of <code>WindowEvent</code>, then <code>processWindowEvent()</code>    private transient GraphicsConfiguration graphicsConfiguration;
53    * is called to process the event, otherwise the superclass version of  
54    * this method is invoked.    /**
55    *     * This (package access) constructor is used by subclasses that want
56    * @param event The event to process.     * to build windows that do not have parents.  Eg. toplevel
57    */     * application frames.  Subclasses cannot call super(null), since
58  protected void     * null is an illegal argument.
59  processEvent(AWTEvent event)     */
60  {    Window()
61    if (event instanceof WindowEvent)    {
62      processWindowEvent((WindowEvent)event);      setVisible(false);
63    else      setLayout((LayoutManager) new BorderLayout());
64      super.processEvent(event);    }
65  }  
66      Window(GraphicsConfiguration gc)
67  /*************************************************************************/    {
68        this();
69  /**      graphicsConfiguration = gc;
70    * Dispatches this event to any listeners that are listening for    }
71    * <code>WindowEvents</code> on this window.  This method only gets      
72    * invoked if it is enabled via <code>enableEvents()</code> or if    /**
73    * a listener has been added.     * Initializes a new instance of <code>Window</code> with the specified
74    *     * parent.  The window will initially be invisible.
75    * @param event The event to process.     *
76    */     * @param parent The owning <code>Frame</code> of this window.
77  protected void     */
78  processWindowEvent(WindowEvent event)    public Window(Frame owner)
79  {    {
80    if (window_listeners != null)      this((Window) owner);
81      switch(event.getID())    }
82    
83      /** @since 1.2 */
84      public Window(Window owner)
85      {
86        this();
87        if (owner == null)
88          throw new IllegalArgumentException("owner must not be null");
89        
90        this.parent = owner;
91    
92        // FIXME: add to owner's "owned window" list
93        //owner.owned.add(this); // this should be a weak reference
94      }
95      
96      /** @since 1.3 */
97      public Window(Window owner, GraphicsConfiguration gc)
98      {
99        this(owner);
100    
101        /*  FIXME: Security check
102        SecurityManager.checkTopLevelWindow(...)
103    
104        if (gc != null
105            && gc.getDevice().getType() != GraphicsDevice.TYPE_RASTER_SCREEN)
106          throw new IllegalArgumentException ("gc must be from a screen device");
107    
108        if (gc == null)
109          graphicsConfiguration = GraphicsEnvironment.getLocalGraphicsEnvironment()
110                                 .getDefaultScreenDevice()
111                                 .getDefaultConfiguration();
112        else
113        */    
114        graphicsConfiguration = gc;
115      }
116    
117      GraphicsConfiguration getGraphicsConfigurationImpl()
118      {
119        if (graphicsConfiguration != null)
120            return graphicsConfiguration;
121    
122        return super.getGraphicsConfigurationImpl();
123      }
124    
125      protected void finalize() throws Throwable
126      {
127        // FIXME: remove from owner's "owned window" list (Weak References)
128        super.finalize();
129      }
130    
131      /**
132       * Creates the native peer for this window.
133       */
134      public void addNotify()
135      {
136        if (peer == null)
137          peer = getToolkit ().createWindow (this);
138        super.addNotify ();
139      }
140    
141      /**
142       * Relays out this window's child components at their preferred size.
143       *
144       * @specnote pack() doesn't appear to be called internally by show(), so
145       *             we duplicate some of the functionality.
146       */
147      public void pack()
148      {
149        if (parent != null
150            && !parent.isDisplayable())
151          parent.addNotify();
152        if (peer == null)
153          addNotify();
154    
155        setSize(getPreferredSize());
156        
157        validate();
158      }
159    
160      /**
161       * Makes this window visible and brings it to the front.
162       */
163      public void show ()
164      {
165        if (peer == null)
166          addNotify();
167    
168        super.show();
169        toFront();
170      }
171    
172      public void hide()
173      {
174        // FIXME: call hide() on amy "owned" children here.
175        super.hide();
176      }
177    
178      /**
179       * Called to free any resource associated with this window.
180       */
181      public void dispose()
182      {
183        hide();
184    
185        Window[] list = getOwnedWindows();
186        for (int i=0; i<list.length; i++)
187          list[i].dispose();
188    
189        for (int i = 0; i < ncomponents; ++i)
190          component[i].removeNotify();
191        this.removeNotify();
192      }
193    
194      /**
195       * Sends this window to the back so that all other windows display in
196       * front of it.
197       */
198      public void toBack ()
199      {
200        if (peer != null)
201        {        {
202          case WindowEvent.WINDOW_ACTIVATED:          WindowPeer wp = (WindowPeer) peer;
203            window_listeners.windowActivated(event);          wp.toBack ();
           break;  
   
         case WindowEvent.WINDOW_DEACTIVATED:  
           window_listeners.windowDeactivated(event);  
           break;  
   
         case WindowEvent.WINDOW_ICONIFIED:  
           window_listeners.windowIconified(event);  
           break;  
   
         case WindowEvent.WINDOW_DEICONIFIED:  
           window_listeners.windowDeiconified(event);  
           break;  
   
         case WindowEvent.WINDOW_OPENED:  
           window_listeners.windowOpened(event);  
           break;  
   
         case WindowEvent.WINDOW_CLOSING:  
           window_listeners.windowClosing(event);  
           break;  
   
         case WindowEvent.WINDOW_CLOSED:  
           window_listeners.windowClosed(event);  
           break;  
   
         default:  
           break;  
204        }        }
205  }    }
   
 /*************************************************************************/  
   
 /**  
   * Post a Java 1.0 event to the event queue.  
   *  
   * @param event The event to post.  
   
 public boolean  
 postEvent(Event event)  
 {  
   return(false);  
 }  
   */  
 /*************************************************************************/  
206    
207  /**    /**
208    * Sets the cursor for this window to the specifiec cursor.     * Brings this window to the front so that it displays in front of
209    *     * any other windows.
210    * @param cursor The new cursor for this window.     */
211    */    public void toFront ()
212  public synchronized void    {
213  setCursor(Cursor cursor)      if (peer != null)
214  {        {
215    super.setCursor(cursor);          WindowPeer wp = (WindowPeer) peer;
216  }          wp.toFront ();
217          }
218  /*************************************************************************/    }
   
 /**  
   * Makes this window visible and brings it to the front.  
   */  
 public void  
 show()  
 {  
   if (getPeer() == null)  
     addNotify();  
   
   super.show();  
   toFront();  
 }  
   
 /*************************************************************************/  
   
 /**  
   * Tests whether or not this window is visible on the screen.  
   *  
   * @return <code>true</code> if this window is visible, <code>false</code>  
   * otherwise.  
   */  
 public boolean  
 isShowing()  
 {  
   return(super.isShowing());  
 }  
   
 /*************************************************************************/  
   
 /**  
   * Brings this window to the front so that it displays in front of  
   * any other windows.  
   */  
 public void  
 toFront()  
 {  
   ((WindowPeer)getPeer()).toFront();  
 }  
   
 /*************************************************************************/  
   
 /**  
   * Sends this window to the back so that all other windows display in  
   * front of it.  
   */  
 public void  
 toBack()  
 {  
   ((WindowPeer)getPeer()).toBack();  
 }  
   
 /*************************************************************************/  
   
 /**  
   * Returns the toolkit used to create this window.  
   *  
   * @return The toolkit used to create this window.  
   */  
 public Toolkit  
 getToolkit()  
 {  
   return(super.getToolkit());  
 }  
   
 /*************************************************************************/  
   
 /**  
   * Returns the locale that this window is configured for.  
   *  
   * @return The locale this window is configured for.  
   */  
 public Locale  
 getLocale()  
 {  
   return(super.getLocale());  
 }  
   
 /*************************************************************************/  
   
 /**  
   * Returns the child window that has focus if this window is active.  
   * This method returns <code>null</code> if this window is not active  
   * or no children have focus.  
   *  
   * @return The component that has focus, or <code>null</code> if no  
   * component has focus.  
   */  
 public Component  
 getFocusOwner()  
 {  
   // FIXME: Implement  
   return(null);  
 }  
   
 /*************************************************************************/  
   
 /**  
   * Relays out this window's child components at their preferred size.  
   */  
 public void  
 pack()  
 {  
   Dimension dim = getPreferredSize();  
   setSize(dim);  
   doLayout();  
 }  
219    
220  /*************************************************************************/    /**
221       * Returns the toolkit used to create this window.
222       *
223       * @return The toolkit used to create this window.
224       *
225       * @specnote Unlike Component.getToolkit, this implementation always
226       *           returns the value of Toolkit.getDefaultToolkit().
227       */
228      public Toolkit getToolkit()
229      {
230        return Toolkit.getDefaultToolkit ();    
231      }
232    
233      /**
234       * Returns the warning string that will be displayed if this window is
235       * popped up by an unsecure applet or application.
236       *
237       * @return The unsecure window warning message.
238       */
239      public final String getWarningString()
240      {
241        boolean secure = true;
242        /* boolean secure = SecurityManager.checkTopLevelWindow(...) */
243    
244  /**      if (!secure)
245    * Creates the native peer for this window.        {
246    */          if (warningString != null)
247  public void            return warningString;
248  addNotify()          else
249  {            {
250    setPeer((ComponentPeer)getToolkit().createWindow(this));              String warning = System.getProperty("awt.appletWarning");
251  }              return warning;
252              }
253          }
254        return null;
255      }
256    
257  /*************************************************************************/    /**
258       * Returns the locale that this window is configured for.
259       *
260       * @return The locale this window is configured for.
261       */
262      public Locale getLocale ()
263      {
264        return locale == null ? Locale.getDefault () : locale;
265      }
266    
267      /*
268      /** @since 1.2
269      public InputContext getInputContext()
270      {
271        // FIXME
272      }
273      */
274    
275      /**
276       * Sets the cursor for this window to the specifiec cursor.
277       *
278       * @param cursor The new cursor for this window.
279       */
280      public void setCursor(Cursor cursor)
281      {
282        super.setCursor(cursor);
283      }
284    
285      public Window getOwner()
286      {
287        return (Window) parent;
288      }
289    
290      /** @since 1.2 */
291      public Window[] getOwnedWindows()
292      {
293        // FIXME: return array containing all the windows this window currently
294        // owns.
295        return null;
296      }
297    
298      /**
299       * Adds the specified listener to the list of <code>WindowListeners</code>
300       * that will receive events for this window.
301       *
302       * @param listener The <code>WindowListener</code> to add.
303       */
304      public synchronized void addWindowListener (WindowListener listener)
305      {
306        windowListener = AWTEventMulticaster.add (windowListener, listener);
307      }
308    
309      /**
310       * Removes the specified listener from the list of
311       * <code>WindowListeners</code> that will receive events for this window.
312       *
313       * @param listener The <code>WindowListener</code> to remove.
314       */
315      public synchronized void removeWindowListener (WindowListener listener)
316      {
317        windowListener = AWTEventMulticaster.remove (windowListener, listener);
318      }
319    
320      /** @since 1.3 */
321      public EventListener[] getListeners(Class listenerType)
322      {
323        if (listenerType == WindowListener.class)
324          return getListenersImpl(listenerType, windowListener);
325        else return super.getListeners(listenerType);
326      }
327    
328      void dispatchEventImpl(AWTEvent e)
329      {
330        // Make use of event id's in order to avoid multiple instanceof tests.
331        if (e.id <= WindowEvent.WINDOW_LAST
332            && e.id >= WindowEvent.WINDOW_FIRST
333            && (windowListener != null
334                || (eventMask & AWTEvent.WINDOW_EVENT_MASK) != 0))
335          processEvent(e);
336        else
337          super.dispatchEventImpl(e);
338      }
339    
340      /**
341       * Processes the specified event for this window.  If the event is an
342       * instance of <code>WindowEvent</code>, then
343       * <code>processWindowEvent()</code> is called to process the event,
344       * otherwise the superclass version of this method is invoked.
345       *
346       * @param event The event to process.
347       */
348      protected void processEvent (AWTEvent evt)
349      {
350        if (evt instanceof WindowEvent)
351          processWindowEvent ((WindowEvent) evt);
352        else
353          super.processEvent (evt);
354      }
355    
356      /**
357       * Dispatches this event to any listeners that are listening for
358       * <code>WindowEvents</code> on this window.  This method only gets
359       * invoked if it is enabled via <code>enableEvents()</code> or if
360       * a listener has been added.
361       *
362       * @param event The event to process.
363       */
364      protected void processWindowEvent (WindowEvent evt)
365      {
366        if (windowListener != null)
367          {
368            switch (evt.getID ())
369              {
370              case WindowEvent.WINDOW_ACTIVATED:
371                windowListener.windowActivated (evt);
372                break;
373              case WindowEvent.WINDOW_CLOSED:
374                windowListener.windowClosed (evt);
375                break;
376              case WindowEvent.WINDOW_CLOSING:
377                windowListener.windowClosing (evt);
378                break;
379              case WindowEvent.WINDOW_DEACTIVATED:
380                windowListener.windowDeactivated (evt);
381                break;
382              case WindowEvent.WINDOW_DEICONIFIED:
383                windowListener.windowDeiconified (evt);
384                break;
385              case WindowEvent.WINDOW_ICONIFIED:
386                windowListener.windowIconified (evt);
387                break;
388              case WindowEvent.WINDOW_OPENED:
389                windowListener.windowOpened (evt);
390                break;
391              }
392          }
393      }
394    
395  /**    /**
396    * Called to free any resource associated with this window.     * Returns the child window that has focus if this window is active.
397    */     * This method returns <code>null</code> if this window is not active
398  public void     * or no children have focus.
399  dispose()     *
400  {     * @return The component that has focus, or <code>null</code> if no
401    // Destroy all component peers.     * component has focus.
402    Component[] c = getComponents();     */
403    if (c.length > 0)    public Component getFocusOwner()
404      for (int i = 0; i < c.length; i++)    {
405        c[i].removeNotify();      // FIXME
406        return null;
407      }
408    
409      /**
410       * Post a Java 1.0 event to the event queue.
411       *
412       * @param event The event to post.
413       */
414      public boolean postEvent(Event e)
415      {
416        // FIXME
417        return false;
418      }
419    
420      /**
421       * Tests whether or not this window is visible on the screen.
422       *
423       * @return <code>true</code> if this window is visible, <code>false</code>
424       * otherwise.
425       */
426      public boolean isShowing()
427      {
428        return super.isShowing();
429      }
430    
431      /** @since 1.2 */
432      public void applyResourceBundle(ResourceBundle rb)
433      {
434        // FIXME
435      }
436    
437      /** @since 1.2 */
438      public void applyResourceBundle(String rbName)
439      {
440        ResourceBundle rb = ResourceBundle.getBundle(rbName);
441        if (rb != null)
442          applyResourceBundle(rb);    
443      }
444    
445      /*
446      public AccessibleContext getAccessibleContext()
447      {
448        // FIXME
449      }
450      */
451    
452      /**
453       * Get graphics configuration.  The implementation for Window will
454       * not ask any parent containers, since Window is a toplevel
455       * window and not actually embedded in the parent component.
456       */
457      public GraphicsConfiguration getGraphicsConfiguration()
458      {
459        if (graphicsConfiguration != null) return graphicsConfiguration;
460        if (peer != null) return peer.getGraphicsConfiguration();
461        return null;
462      }
463    
   removeNotify();  
464  }  }
   
 } // class Window  
   

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26