GNU Classpath (0.18) | ||
Frames | No Frames |
1: /* Popup.java -- 2: Copyright (C) 2003 Free Software Foundation, Inc. 3: 4: This file is part of GNU Classpath. 5: 6: GNU Classpath is free software; you can redistribute it and/or modify 7: it under the terms of the GNU General Public License as published by 8: the Free Software Foundation; either version 2, or (at your option) 9: any later version. 10: 11: GNU Classpath is distributed in the hope that it will be useful, but 12: WITHOUT ANY WARRANTY; without even the implied warranty of 13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14: General Public License for more details. 15: 16: You should have received a copy of the GNU General Public License 17: along with GNU Classpath; see the file COPYING. If not, write to the 18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 19: 02110-1301 USA. 20: 21: Linking this library statically or dynamically with other modules is 22: making a combined work based on this library. Thus, the terms and 23: conditions of the GNU General Public License cover the whole 24: combination. 25: 26: As a special exception, the copyright holders of this library give you 27: permission to link this library with independent modules to produce an 28: executable, regardless of the license terms of these independent 29: modules, and to copy and distribute the resulting executable under 30: terms of your choice, provided that you also meet, for each linked 31: independent module, the terms and conditions of the license of that 32: module. An independent module is a module which is not derived from 33: or based on this library. If you modify this library, you may extend 34: this exception to your version of the library, but you are not 35: obligated to do so. If you do not wish to do so, delete this 36: exception statement from your version. */ 37: 38: 39: package javax.swing; 40: 41: import java.awt.Component; 42: 43: 44: /** 45: * Manages a popup window that displays a Component on top of 46: * everything else. 47: * 48: * <p>To obtain an instance of <code>Popup</code>, use the 49: * {@link javax.swing.PopupFactory}. 50: * 51: * @since 1.4 52: * 53: * @author Sascha Brawer (brawer@dandelis.ch) 54: */ 55: public class Popup 56: { 57: /** 58: * Constructs a new <code>Popup</code> given its owner, 59: * contents and the screen position where the popup 60: * will appear. 61: * 62: * @param owner the Component to which <code>x</code> and 63: * <code>y</code> are relative, or <code>null</code> for 64: * placing the popup relative to the origin of the screen. 65: * 66: * @param contents the contents that will be displayed inside 67: * the <code>Popup</code>. 68: * 69: * @param x the horizontal position where the Popup will appear. 70: * 71: * @param y the vertical position where the Popup will appear. 72: * 73: * @throws IllegalArgumentException if <code>contents</code> 74: * is <code>null</code>. 75: */ 76: protected Popup(Component owner, Component contents, 77: int x, int y) 78: { 79: if (contents == null) 80: throw new IllegalArgumentException(); 81: 82: // The real stuff happens in the implementation of subclasses, 83: // for instance JWindowPopup. 84: } 85: 86: 87: /** 88: * Constructs a new <code>Popup</code>. 89: */ 90: protected Popup() 91: { 92: } 93: 94: 95: /** 96: * Displays the <code>Popup</code> on the screen. Nothing happens 97: * if it is currently shown. 98: */ 99: public void show() 100: { 101: // Implemented by subclasses, for instance JWindowPopup. 102: } 103: 104: 105: /** 106: * Removes the <code>Popup</code> from the screen. Nothing happens 107: * if it is currently hidden. 108: */ 109: public void hide() 110: { 111: // Implemented by subclasses, for instance JWindowPopup. 112: } 113: 114: 115: /** 116: * A <code>Popup</code> that uses a <code>JWindow</code> for 117: * displaying its contents. 118: * 119: * @see PopupFactory#getPopup 120: * 121: * @author Sascha Brawer (brawer@dandelis.ch) 122: */ 123: static class JWindowPopup 124: extends Popup 125: { 126: /** 127: * The <code>JWindow</code> used for displaying the contents 128: * of the popup. 129: */ 130: JWindow window; 131: 132: 133: /** 134: * Constructs a new <code>JWindowPopup</code> given its owner, 135: * contents and the screen position where the popup 136: * will appear. 137: * 138: * @param owner the Component to which <code>x</code> and 139: * <code>y</code> are relative, or <code>null</code> for 140: * placing the popup relative to the origin of the screen. 141: * 142: * @param contents the contents that will be displayed inside 143: * the <code>Popup</code>. 144: * 145: * @param x the horizontal position where the Popup will appear. 146: * 147: * @param y the vertical position where the Popup will appear. 148: * 149: * @throws IllegalArgumentException if <code>contents</code> 150: * is <code>null</code>. 151: */ 152: public JWindowPopup(Component owner, Component contents, 153: int x, int y) 154: { 155: /* Checks whether contents is null. */ 156: super(owner, contents, x, y); 157: 158: window = new JWindow(); 159: window.getRootPane().add(contents); 160: window.setLocation(x, y); 161: window.pack(); 162: } 163: 164: 165: /** 166: * Displays the popup's <code>JWindow</code> on the screen. 167: * Nothing happens if it is already visible. 168: */ 169: public void show() 170: { 171: window.show(); 172: } 173: 174: 175: /** 176: * Removes the popup's <code>JWindow</code> from the 177: * screen. Nothing happens if it is currently not visible. 178: */ 179: public void hide() 180: { 181: /* Calling dispose() instead of hide() will conserve native 182: * system resources, for example memory in an X11 server. 183: * They will automatically be re-allocated by a call to 184: * show(). 185: */ 186: window.dispose(); 187: } 188: } 189: }
GNU Classpath (0.18) |