/Users/lyon/j4p/src/javagroup/util/WindowResource.java

1    /* 
2     * Copyright (C) 1997 Luke Gorrie 
3     * 
4     * This library is free software; you can redistribute it and/or 
5     * modify it under the terms of the GNU Library General Public 
6     * License as published by the Free Software Foundation; either 
7     * version 2 of the License, or (at your option) any later version. 
8     * 
9     * This library is distributed in the hope that it will be useful, 
10    * but WITHOUT ANY WARRANTY; without even the implied warranty of 
11    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12    * Library General Public License for more details. 
13    * 
14    * You should have received a copy of the GNU Library General Public 
15    * License along with this library; if not, write to the 
16    * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, 
17    * MA 02139, USA. 
18    */ 
19    
20   package javagroup.util; 
21    
22   import java.awt.*; 
23   import java.awt.event.WindowAdapter; 
24   import java.awt.event.WindowEvent; 
25    
26   /** 
27    * Window-specific implementation of Resource. 
28    * 
29    * @author Luke Gorrie 
30    */ 
31   public class WindowResource extends Resource { 
32    
33       protected Window _window; 
34    
35       public WindowResource(Window window) { 
36           _window = window; 
37       } 
38    
39       public Window getWindow() { 
40           return _window; 
41       } 
42    
43       public void dispose() { 
44           if (_window == null) 
45               return; 
46    
47           try { 
48               _window.dispose(); 
49               _window = null; 
50           } catch (Exception e) { 
51               // ignore exceptions 
52           } 
53           super.dispose(); 
54       } 
55    
56       public String toString() { 
57           return "WindowResource: " + _window.toString(); 
58       } 
59    
60       final class WindowDisposalListener extends WindowAdapter { 
61    
62           protected WindowResource _resource; 
63    
64           public WindowDisposalListener(WindowResource window) { 
65               _resource = window; 
66    
67               _resource.getWindow().addWindowListener(this); 
68           } 
69    
70           public void windowClosed(WindowEvent event) { 
71               _resource.dispose(); 
72           } 
73    
74       } 
75    
76   } 
77    
78