src/java.desktop/share/classes/sun/awt/EmbeddedFrame.java

Print this page




  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.awt;
  27 
  28 import java.awt.*;
  29 import java.awt.event.*;
  30 import java.awt.image.*;
  31 import java.awt.peer.*;
  32 import java.beans.PropertyChangeListener;
  33 import java.beans.PropertyChangeEvent;
  34 import java.util.Set;
  35 import java.awt.AWTKeyStroke;
  36 import java.applet.Applet;
  37 import sun.applet.AppletPanel;
  38 
  39 /**
  40  * A generic container used for embedding Java components, usually applets.
  41  * An EmbeddedFrame has two related uses:
  42  *
  43  * . Within a Java-based application, an EmbeddedFrame serves as a sort of
  44  *   firewall, preventing the contained components or applets from using
  45  *   getParent() to find parent components, such as menubars.
  46  *
  47  * . Within a C-based application, an EmbeddedFrame contains a window handle
  48  *   which was created by the application, which serves as the top-level
  49  *   Java window.  EmbeddedFrames created for this purpose are passed-in a
  50  *   handle of an existing window created by the application.  The window
  51  *   handle should be of the appropriate native type for a specific
  52  *   platform, as stored in the pData field of the ComponentPeer.
  53  *
  54  * @author      Thomas Ball
  55  */
  56 public abstract class EmbeddedFrame extends Frame
  57                           implements KeyEventDispatcher, PropertyChangeListener {


 303      */
 304     protected boolean traverseOut(boolean direction) {
 305         return false;
 306     }
 307 
 308     /**
 309      * Block modifying any frame attributes, since they aren't applicable
 310      * for EmbeddedFrames.
 311      */
 312     public void setTitle(String title) {}
 313     public void setIconImage(Image image) {}
 314     public void setIconImages(java.util.List<? extends Image> icons) {}
 315     public void setMenuBar(MenuBar mb) {}
 316     public void setResizable(boolean resizable) {}
 317     public void remove(MenuComponent m) {}
 318 
 319     public boolean isResizable() {
 320         return true;
 321     }
 322 
 323     @SuppressWarnings("deprecation")
 324     public void addNotify() {
 325         synchronized (getTreeLock()) {
 326             if (getPeer() == null) {
 327                 setPeer(new NullEmbeddedFramePeer());
 328             }
 329             super.addNotify();
 330         }
 331     }
 332 
 333     // These three functions consitute RFE 4100710. Do not remove.
 334     @SuppressWarnings("deprecation")
 335     public void setCursorAllowed(boolean isCursorAllowed) {
 336         this.isCursorAllowed = isCursorAllowed;
 337         getPeer().updateCursorImmediately();

 338     }
 339     public boolean isCursorAllowed() {
 340         return isCursorAllowed;
 341     }
 342     public Cursor getCursor() {
 343         return (isCursorAllowed)
 344             ? super.getCursor()
 345             : Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
 346     }
 347 
 348     @SuppressWarnings("deprecation")
 349     protected void setPeer(final ComponentPeer p){
 350         AWTAccessor.getComponentAccessor().setPeer(EmbeddedFrame.this, p);
 351     };
 352 
 353     /**
 354      * Synthesize native message to activate or deactivate EmbeddedFrame window
 355      * depending on the value of parameter <code>b</code>.
 356      * Peers should override this method if they are to implement
 357      * this functionality.
 358      * @param doActivate  if <code>true</code>, activates the window;
 359      * otherwise, deactivates the window
 360      */
 361     public void synthesizeWindowActivation(boolean doActivate) {}
 362 
 363     /**
 364      * Requests the focus to the embedder.
 365      *
 366      * @return {@code true} if focus request was successful, and {@code false} otherwise.
 367      */
 368     public boolean requestFocusToEmbedder() {


 441      * setLocationPrivate() and setBoundsPrivate() were introduced, and they
 442      * work just the same way as setLocation() and setBounds() for usual,
 443      * non-embedded components.
 444      * </p>
 445      * <p>
 446      * Using usual get/setLocation() and get/setBounds() together with new
 447      * get/setLocationPrivate() and get/setBoundsPrivate() is not recommended.
 448      * For example, calling getBoundsPrivate() after setLocation() works fine,
 449      * but getBounds() after setBoundsPrivate() may return unpredictable value.
 450      * </p>
 451      * @param x the new <i>x</i>-coordinate relative to the parent component
 452      * @param y the new <i>y</i>-coordinate relative to the parent component
 453      * @param width the new <code>width</code> of this embedded frame
 454      * @param height the new <code>height</code> of this embedded frame
 455      * @see java.awt.Component#setBounds
 456      * @see #setLocationPrivate
 457      * @see #getLocationPrivate
 458      * @see #getBoundsPrivate
 459      * @since 1.5
 460      */
 461     @SuppressWarnings("deprecation")
 462     protected void setBoundsPrivate(int x, int y, int width, int height) {
 463         final FramePeer peer = (FramePeer)getPeer();
 464         if (peer != null) {
 465             peer.setBoundsPrivate(x, y, width, height);
 466         }
 467     }
 468 
 469     /**
 470      * Gets the bounds of this embedded frame as a rectangle specifying the
 471      * width, height and location relative to the native parent component.
 472      * <p>
 473      * setLocation() and setBounds() for EmbeddedFrame really don't move it
 474      * within the native parent. These methods always put embedded frame to
 475      * (0, 0) for backward compatibility. To allow getting location and size
 476      * of embedded frames getLocationPrivate() and getBoundsPrivate() were
 477      * introduced, and they work just the same way as getLocation() and getBounds()
 478      * for ususal, non-embedded components.
 479      * </p>
 480      * <p>
 481      * Using usual get/setLocation() and get/setBounds() together with new
 482      * get/setLocationPrivate() and get/setBoundsPrivate() is not recommended.
 483      * For example, calling getBoundsPrivate() after setLocation() works fine,
 484      * but getBounds() after setBoundsPrivate() may return unpredictable value.
 485      * </p>
 486      * @return a rectangle indicating this embedded frame's bounds
 487      * @see java.awt.Component#getBounds
 488      * @see #setLocationPrivate
 489      * @see #getLocationPrivate
 490      * @see #setBoundsPrivate
 491      * @since 1.6
 492      */
 493     @SuppressWarnings("deprecation")
 494     protected Rectangle getBoundsPrivate() {
 495         final FramePeer peer = (FramePeer)getPeer();
 496         if (peer != null) {
 497             return peer.getBoundsPrivate();
 498         }
 499         else {
 500             return getBounds();
 501         }
 502     }
 503 
 504     public void toFront() {}
 505     public void toBack() {}
 506 
 507     public abstract void registerAccelerator(AWTKeyStroke stroke);
 508     public abstract void unregisterAccelerator(AWTKeyStroke stroke);
 509 
 510     /**
 511      * Checks if the component is in an EmbeddedFrame. If so,
 512      * returns the applet found in the hierarchy or null if
 513      * not found.
 514      * @return the parent applet or {@ null}
 515      * @since 1.6




  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.awt;
  27 
  28 import java.awt.*;
  29 import java.awt.event.*;

  30 import java.awt.peer.*;
  31 import java.beans.PropertyChangeListener;
  32 import java.beans.PropertyChangeEvent;
  33 import java.util.Set;
  34 import java.awt.AWTKeyStroke;
  35 import java.applet.Applet;

  36 
  37 /**
  38  * A generic container used for embedding Java components, usually applets.
  39  * An EmbeddedFrame has two related uses:
  40  *
  41  * . Within a Java-based application, an EmbeddedFrame serves as a sort of
  42  *   firewall, preventing the contained components or applets from using
  43  *   getParent() to find parent components, such as menubars.
  44  *
  45  * . Within a C-based application, an EmbeddedFrame contains a window handle
  46  *   which was created by the application, which serves as the top-level
  47  *   Java window.  EmbeddedFrames created for this purpose are passed-in a
  48  *   handle of an existing window created by the application.  The window
  49  *   handle should be of the appropriate native type for a specific
  50  *   platform, as stored in the pData field of the ComponentPeer.
  51  *
  52  * @author      Thomas Ball
  53  */
  54 public abstract class EmbeddedFrame extends Frame
  55                           implements KeyEventDispatcher, PropertyChangeListener {


 301      */
 302     protected boolean traverseOut(boolean direction) {
 303         return false;
 304     }
 305 
 306     /**
 307      * Block modifying any frame attributes, since they aren't applicable
 308      * for EmbeddedFrames.
 309      */
 310     public void setTitle(String title) {}
 311     public void setIconImage(Image image) {}
 312     public void setIconImages(java.util.List<? extends Image> icons) {}
 313     public void setMenuBar(MenuBar mb) {}
 314     public void setResizable(boolean resizable) {}
 315     public void remove(MenuComponent m) {}
 316 
 317     public boolean isResizable() {
 318         return true;
 319     }
 320 

 321     public void addNotify() {
 322         synchronized (getTreeLock()) {
 323             if (!isDisplayable()) {
 324                 setPeer(new NullEmbeddedFramePeer());
 325             }
 326             super.addNotify();
 327         }
 328     }
 329 
 330     // These three functions consitute RFE 4100710. Do not remove.

 331     public void setCursorAllowed(boolean isCursorAllowed) {
 332         this.isCursorAllowed = isCursorAllowed;
 333         final FramePeer peer = AWTAccessor.getComponentAccessor().getPeer(this);
 334         peer.updateCursorImmediately();
 335     }
 336     public boolean isCursorAllowed() {
 337         return isCursorAllowed;
 338     }
 339     public Cursor getCursor() {
 340         return (isCursorAllowed)
 341             ? super.getCursor()
 342             : Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
 343     }
 344 

 345     protected void setPeer(final ComponentPeer p){
 346         AWTAccessor.getComponentAccessor().setPeer(EmbeddedFrame.this, p);
 347     };
 348 
 349     /**
 350      * Synthesize native message to activate or deactivate EmbeddedFrame window
 351      * depending on the value of parameter <code>b</code>.
 352      * Peers should override this method if they are to implement
 353      * this functionality.
 354      * @param doActivate  if <code>true</code>, activates the window;
 355      * otherwise, deactivates the window
 356      */
 357     public void synthesizeWindowActivation(boolean doActivate) {}
 358 
 359     /**
 360      * Requests the focus to the embedder.
 361      *
 362      * @return {@code true} if focus request was successful, and {@code false} otherwise.
 363      */
 364     public boolean requestFocusToEmbedder() {


 437      * setLocationPrivate() and setBoundsPrivate() were introduced, and they
 438      * work just the same way as setLocation() and setBounds() for usual,
 439      * non-embedded components.
 440      * </p>
 441      * <p>
 442      * Using usual get/setLocation() and get/setBounds() together with new
 443      * get/setLocationPrivate() and get/setBoundsPrivate() is not recommended.
 444      * For example, calling getBoundsPrivate() after setLocation() works fine,
 445      * but getBounds() after setBoundsPrivate() may return unpredictable value.
 446      * </p>
 447      * @param x the new <i>x</i>-coordinate relative to the parent component
 448      * @param y the new <i>y</i>-coordinate relative to the parent component
 449      * @param width the new <code>width</code> of this embedded frame
 450      * @param height the new <code>height</code> of this embedded frame
 451      * @see java.awt.Component#setBounds
 452      * @see #setLocationPrivate
 453      * @see #getLocationPrivate
 454      * @see #getBoundsPrivate
 455      * @since 1.5
 456      */

 457     protected void setBoundsPrivate(int x, int y, int width, int height) {
 458         final FramePeer peer = AWTAccessor.getComponentAccessor().getPeer(this);
 459         if (peer != null) {
 460             peer.setBoundsPrivate(x, y, width, height);
 461         }
 462     }
 463 
 464     /**
 465      * Gets the bounds of this embedded frame as a rectangle specifying the
 466      * width, height and location relative to the native parent component.
 467      * <p>
 468      * setLocation() and setBounds() for EmbeddedFrame really don't move it
 469      * within the native parent. These methods always put embedded frame to
 470      * (0, 0) for backward compatibility. To allow getting location and size
 471      * of embedded frames getLocationPrivate() and getBoundsPrivate() were
 472      * introduced, and they work just the same way as getLocation() and getBounds()
 473      * for ususal, non-embedded components.
 474      * </p>
 475      * <p>
 476      * Using usual get/setLocation() and get/setBounds() together with new
 477      * get/setLocationPrivate() and get/setBoundsPrivate() is not recommended.
 478      * For example, calling getBoundsPrivate() after setLocation() works fine,
 479      * but getBounds() after setBoundsPrivate() may return unpredictable value.
 480      * </p>
 481      * @return a rectangle indicating this embedded frame's bounds
 482      * @see java.awt.Component#getBounds
 483      * @see #setLocationPrivate
 484      * @see #getLocationPrivate
 485      * @see #setBoundsPrivate
 486      * @since 1.6
 487      */

 488     protected Rectangle getBoundsPrivate() {
 489         final FramePeer peer = AWTAccessor.getComponentAccessor().getPeer(this);
 490         if (peer != null) {
 491             return peer.getBoundsPrivate();
 492         }
 493         else {
 494             return getBounds();
 495         }
 496     }
 497 
 498     public void toFront() {}
 499     public void toBack() {}
 500 
 501     public abstract void registerAccelerator(AWTKeyStroke stroke);
 502     public abstract void unregisterAccelerator(AWTKeyStroke stroke);
 503 
 504     /**
 505      * Checks if the component is in an EmbeddedFrame. If so,
 506      * returns the applet found in the hierarchy or null if
 507      * not found.
 508      * @return the parent applet or {@ null}
 509      * @since 1.6