1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  *
24  * ident	"%Z%%M%	%I%	%E% SMI"
25  *
26  * Copyright(c) 1999 by Sun Microsystems, Inc.
27  * All rights reserved.
28  *
29  * pmDialog.java
30  * Extends JDialog to provide for better default location.
31  */
32 
33 package com.sun.admin.pm.client;
34 
35 import java.net.*;
36 import java.awt.*;
37 import javax.swing.*;
38 import java.awt.event.*;
39 
40 import com.sun.admin.pm.server.Debug;
41 
42 public class pmDialog extends JDialog implements pmDialogConstraints {
43 
pmDialog(Frame owner)44     public pmDialog(Frame owner) {
45 	this(owner, null, false);
46     }
47 
pmDialog(Frame owner, boolean modal)48     public pmDialog(Frame owner, boolean modal) {
49 	this(owner, null, modal);
50     }
51 
pmDialog(Frame owner, String title)52     public pmDialog(Frame owner, String title) {
53 	this(owner, title, false);
54     }
55 
pmDialog(Frame f, String title, boolean modal)56     public pmDialog(Frame f, String title, boolean modal) {
57 
58 	super(f, title, modal);
59 
60 	// determine a nice location relative to parent frame
61 	Point newLocation = new Point(0, 0);	// default
62 
63 	if (f == null) {
64 	    // centered on screen
65 	    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
66 	    newLocation = new Point(screenSize.width / 2 - xoffset,
67 				    screenSize.height / 2 - yoffset);
68 
69 	} else {
70 	    // centered over parent frame
71 	    Rectangle parentBounds = f.getBounds();
72 	    newLocation = new Point(
73 			    parentBounds.x + parentBounds.width / 2 - xoffset,
74 			    parentBounds.y + parentBounds.height / 2 - yoffset);
75             f.addWindowListener(new WindowAdapter() {
76                 public void windowClosing(WindowEvent e) {
77                     Debug.info("dialog Window closing");
78                     cleanupButtons();
79                 }
80                 public void windowClosed(WindowEvent e) {
81                     Debug.info("dialog Window closed");
82                     cleanupButtons();
83                 }
84                 public void windowDeactivated(WindowEvent e) {
85                     Debug.info("dialog Window deactivated");
86                     // possible java bug: too many of these events generated!
87                     // cleanupButtons();
88                 }
89             });
90 	}
91 	setLocation(newLocation);
92 
93 	// cannot set dialog icons under 1.1....
94 	/*
95          * try {
96          *  String iconName = new String("images/appicon.gif");
97 	 *  Class thisClass = this.getClass();
98 	 *  URL iconUrl = thisClass.getResource(iconName);
99 	 *  if (iconUrl == null)
100 	 *	Debug.warning("Unable to resolve URL for icon " + iconName);
101 	 *  else {
102 	 * 	Toolkit tk = Toolkit.getDefaultToolkit();
103 	 * 	Image img = tk.getImage(iconUrl);
104 	 * 	// this.setIconImage(img);
105 	 *    }
106          * } catch (Exception x) {
107          *      Debug.warning(x.toString());
108          * }
109 	 */
110 
111     }
112 
cleanupButtons()113     public void cleanupButtons() {
114         // drop this rootPane from pmButton's hashtable
115         pmButton.unreference(this.getRootPane());
116     }
117 
setVisible(boolean b)118     public void setVisible(boolean b) {
119         if (b == false)
120             cleanupButtons();
121         super.setVisible(b);
122     }
123 
124 }
125 
126