2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libjava / javax / swing / Popup.java
blobb1cb4460a4959a2ed285aa58a90a47781ba8dd82
1 /* Popup.java --
2 Copyright (C) 2003 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
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.
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. */
39 package javax.swing;
41 import java.awt.Component;
44 /**
45 * Manages a popup window that displays a Component on top of
46 * everything else.
48 * <p>To obtain an instance of <code>Popup</code>, use the
49 * {@link javax.swing.PopupFactory}.
51 * @since 1.4
53 * @author Sascha Brawer (brawer@dandelis.ch)
55 public class Popup
57 /**
58 * Constructs a new <code>Popup</code> given its owner,
59 * contents and the screen position where the popup
60 * will appear.
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.
66 * @param contents the contents that will be displayed inside
67 * the <code>Popup</code>.
69 * @param x the horizontal position where the Popup will appear.
71 * @param y the vertical position where the Popup will appear.
73 * @throws IllegalArgumentException if <code>contents</code>
74 * is <code>null</code>.
76 protected Popup(Component owner, Component contents,
77 int x, int y)
79 if (contents == null)
80 throw new IllegalArgumentException();
82 // The real stuff happens in the implementation of subclasses,
83 // for instance JWindowPopup.
87 /**
88 * Constructs a new <code>Popup</code>.
90 protected Popup()
95 /**
96 * Displays the <code>Popup</code> on the screen. Nothing happens
97 * if it is currently shown.
99 public void show()
101 // Implemented by subclasses, for instance JWindowPopup.
106 * Removes the <code>Popup</code> from the screen. Nothing happens
107 * if it is currently hidden.
109 public void hide()
111 // Implemented by subclasses, for instance JWindowPopup.
116 * A <code>Popup</code> that uses a <code>JWindow</code> for
117 * displaying its contents.
119 * @see PopupFactory#getPopup
121 * @author Sascha Brawer (brawer@dandelis.ch)
123 static class JWindowPopup
124 extends Popup
127 * The <code>JWindow</code> used for displaying the contents
128 * of the popup.
130 JWindow window;
134 * Constructs a new <code>JWindowPopup</code> given its owner,
135 * contents and the screen position where the popup
136 * will appear.
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.
142 * @param contents the contents that will be displayed inside
143 * the <code>Popup</code>.
145 * @param x the horizontal position where the Popup will appear.
147 * @param y the vertical position where the Popup will appear.
149 * @throws IllegalArgumentException if <code>contents</code>
150 * is <code>null</code>.
152 public JWindowPopup(Component owner, Component contents,
153 int x, int y)
155 /* Checks whether contents is null. */
156 super(owner, contents, x, y);
158 window = new JWindow();
159 window.getRootPane().add(contents);
160 window.setLocation(x, y);
161 window.pack();
166 * Displays the popup&#x2019;s <code>JWindow</code> on the screen.
167 * Nothing happens if it is already visible.
169 public void show()
171 window.show();
176 * Removes the popup&#x2019;s <code>JWindow</code> from the
177 * screen. Nothing happens if it is currently not visible.
179 public void hide()
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().
186 window.dispose();