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 (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * 23 * ident "%Z%%M% %I% %E% SMI" 24 * 25 * Copyright (c) 1999 by Sun Microsystems, Inc. 26 * All rights reserved. 27 * 28 * pmFrame.java 29 * Extends JFrame to support better focus handling 30 */ 31 32 package com.sun.admin.pm.client; 33 34 import java.awt.*; 35 import java.awt.event.*; 36 import java.net.*; 37 import javax.swing.*; 38 39 import com.sun.admin.pm.server.*; 40 41 class pmFrame extends JFrame { 42 43 // this comp gets focus on frame open 44 Component defaultComponent = null; 45 46 // file path of icon; this does not provide for localization 47 private static final String iconName = "images/appicon.gif"; 48 49 // if true, clean up pmButton state on frame close 50 private boolean clearButtonsOnClose; 51 pmFrame(String s)52 public pmFrame(String s) { 53 super(s); 54 55 // default: do NOT clear default button state when frame is closed 56 clearButtonsOnClose = false; 57 58 this.addFocusListener(new FocusListener() { 59 public void focusGained(FocusEvent e) { 60 Debug.message("CLNT: pmFrame focus gained: " + e); 61 if (defaultComponent != null) { 62 Debug.message("CLNT: pmFrame focus to default comp"); 63 defaultComponent.requestFocus(); 64 } else 65 Debug.message("CLNT: pmFrame no default comp"); 66 } 67 public void focusLost(FocusEvent e) { 68 Debug.message("CLNT: frame focus lost: " + e); 69 } 70 }); 71 72 this.addWindowListener(new WindowAdapter() { 73 public void windowClosing(WindowEvent e) { 74 Debug.info("frame Window closing"); 75 cleanupButtons(); 76 } 77 public void windowClosed(WindowEvent e) { 78 Debug.info("frame Window closed"); 79 cleanupButtons(); 80 } 81 }); 82 83 try { 84 Class thisClass = this.getClass(); 85 URL iconUrl = thisClass.getResource(iconName); 86 // System.out.println("Icon: " + iconUrl); 87 if (iconUrl == null) 88 Debug.warning("Unable to resolve URL for icon " + iconName); 89 else { 90 Toolkit tk = Toolkit.getDefaultToolkit(); 91 Image img = tk.getImage(iconUrl); 92 this.setIconImage(img); 93 } 94 95 } catch (Exception x) { 96 Debug.warning(x.toString()); 97 } 98 } 99 100 setDefaultComponent(Component c)101 public void setDefaultComponent(Component c) { 102 defaultComponent = c; 103 } 104 105 106 // If the frame is a minimized icon, make it un-minimized first setVisible(boolean isVisible)107 public void setVisible(boolean isVisible) { 108 if (isVisible == true) { 109 try { 110 // this will fail in jdk 1.1 but work fine in 1.2 111 setState(NORMAL); 112 } catch (Exception ssx) { 113 // restores an iconified window in JDK 1.1 114 removeNotify(); 115 addNotify(); 116 } 117 } else 118 cleanupButtons(); 119 super.setVisible(isVisible); 120 } 121 cleanupButtons()122 public void cleanupButtons() { 123 // drop this rootPane from pmButton's hashtable 124 if (clearButtonsOnClose) 125 pmButton.unreference(this.getRootPane()); 126 } 127 setClearButtonsOnClose(boolean b)128 protected void setClearButtonsOnClose(boolean b) { 129 clearButtonsOnClose = b; 130 } 131 132 133 } 134