1 /*
   2  * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  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 package com.sun.java.swing.plaf.windows;
  26 
  27 import javax.swing.JWindow;
  28 import java.awt.Window;
  29 import java.awt.Graphics;
  30 
  31 /**
  32  * A class which tags a window with a particular semantic usage,
  33  * either tooltip, menu, sub-menu, popup-menu, or comobobox-popup.
  34  * This is used as a temporary solution for getting native AWT support
  35  * for transition effects in Windows 98 and Windows 2000.  The native
  36  * code will interpret the windowType property and automatically
  37  * implement appropriate animation when the window is shown/hidden.
  38  * <p>
  39  * Note that support for transition effects may be supported with a
  40  * different mechanism in the future and so this class is
  41  * package-private and targeted for Swing implementation use only.
  42  * <p>
  43  * <strong>Warning:</strong>
  44  * Serialized objects of this class will not be compatible with
  45  * future Swing releases.  The current serialization support is appropriate
  46  * for short term storage or RMI between applications running the same
  47  * version of Swing.  A future release of Swing will provide support for
  48  * long term persistence.
  49  *
  50  * @author Amy Fowler
  51  */
  52 @SuppressWarnings("serial") // Superclass is not serializable across versions
  53 class WindowsPopupWindow extends JWindow {
  54 
  55     static final int UNDEFINED_WINDOW_TYPE      = 0;
  56     static final int TOOLTIP_WINDOW_TYPE        = 1;
  57     static final int MENU_WINDOW_TYPE           = 2;
  58     static final int SUBMENU_WINDOW_TYPE        = 3;
  59     static final int POPUPMENU_WINDOW_TYPE      = 4;
  60     static final int COMBOBOX_POPUP_WINDOW_TYPE = 5;
  61 
  62     private int windowType;
  63 
  64     WindowsPopupWindow(Window parent) {
  65         super(parent);
  66         setFocusableWindowState(false);
  67     }
  68 
  69     void setWindowType(int type) {
  70         windowType = type;
  71     }
  72 
  73     int getWindowType() {
  74         return windowType;
  75     }
  76 
  77     public void update(Graphics g) {
  78         paint(g);
  79     }
  80 
  81     @SuppressWarnings("deprecation")
  82     public void hide() {
  83         super.hide();
  84         /** We need to call removeNotify() here because hide() does
  85          * something only if Component.visible is true. When the app
  86          * frame is miniaturized, the parent frame of this frame is
  87          * invisible, causing AWT to believe that this frame
  88          *  is invisible and causing hide() to do nothing
  89          */
  90         removeNotify();
  91     }
  92 
  93     @SuppressWarnings("deprecation")
  94     public void show() {
  95         super.show();
  96         this.pack();
  97     }
  98 }