1 /*
   2  * Copyright (c) 1996, 2008, 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 sun.awt.windows;
  26 
  27 import java.util.*;
  28 import java.awt.*;
  29 import java.awt.peer.*;
  30 
  31 import sun.awt.*;
  32 import sun.awt.im.*;
  33 
  34 class WDialogPeer extends WWindowPeer implements DialogPeer {
  35     // Toolkit & peer internals
  36 
  37     // Platform default background for dialogs.  Gets set on target if
  38     // target has none explicitly specified.
  39     final static Color defaultBackground =  SystemColor.control;
  40 
  41     // If target doesn't have its background color set, we set its
  42     // background to platform default.
  43     boolean needDefaultBackground;
  44 
  45     WDialogPeer(Dialog target) {
  46         super(target);
  47 
  48         InputMethodManager imm = InputMethodManager.getInstance();
  49         String menuString = imm.getTriggerMenuString();
  50         if (menuString != null)
  51         {
  52             pSetIMMOption(menuString);
  53         }
  54     }
  55 
  56     native void createAwtDialog(WComponentPeer parent);
  57     void create(WComponentPeer parent) {
  58         preCreate(parent);
  59         createAwtDialog(parent);
  60     }
  61 
  62     native void showModal();
  63     native void endModal();
  64 
  65     void initialize() {
  66         Dialog target = (Dialog)this.target;
  67         // Need to set target's background to default _before_ a call
  68         // to super.initialize.
  69         if (needDefaultBackground) {
  70             target.setBackground(defaultBackground);
  71         }
  72 
  73         super.initialize();
  74 
  75         if (target.getTitle() != null) {
  76             setTitle(target.getTitle());
  77         }
  78         setResizable(target.isResizable());
  79     }
  80 
  81     protected void realShow() {
  82         Dialog dlg = (Dialog)target;
  83         if (dlg.getModalityType() != Dialog.ModalityType.MODELESS) {
  84             showModal();
  85         } else {
  86             super.realShow();
  87         }
  88     }
  89 
  90     public void hide() {
  91         Dialog dlg = (Dialog)target;
  92         if (dlg.getModalityType() != Dialog.ModalityType.MODELESS) {
  93             endModal();
  94         } else {
  95             super.hide();
  96         }
  97     }
  98 
  99     public void blockWindows(java.util.List<Window> toBlock) {
 100         for (Window w : toBlock) {
 101             WWindowPeer wp = (WWindowPeer)AWTAccessor.getComponentAccessor().getPeer(w);
 102             if (wp != null) {
 103                 wp.setModalBlocked((Dialog)target, true);
 104             }
 105         }
 106     }
 107 
 108     public Dimension getMinimumSize() {
 109         if (((Dialog)target).isUndecorated()) {
 110             return super.getMinimumSize();
 111         } else {
 112             return new Dimension(getSysMinWidth(), getSysMinHeight());
 113         }
 114     }
 115 
 116     @Override
 117     boolean isTargetUndecorated() {
 118         return ((Dialog)target).isUndecorated();
 119     }
 120 
 121     public void reshape(int x, int y, int width, int height) {
 122         if (((Dialog)target).isUndecorated()) {
 123             super.reshape(x, y, width, height);
 124         } else {
 125             reshapeFrame(x, y, width, height);
 126         }
 127     }
 128 
 129     /* Native create() peeks at target's background and if it's null
 130      * calls this method to arrage for default background to be set on
 131      * target.  Can't make the check in Java, since getBackground will
 132      * return owner's background if target has none set.
 133      */
 134     private void setDefaultColor() {
 135         // Can't call target.setBackground directly, since we are
 136         // called on toolkit thread.  Can't schedule a Runnable on the
 137         // EventHandlerThread because of the race condition.  So just
 138         // set a flag and call target.setBackground in initialize.
 139         needDefaultBackground = true;
 140     }
 141 
 142     native void pSetIMMOption(String option);
 143     void notifyIMMOptionChange(){
 144       InputMethodManager.getInstance().notifyChangeRequest((Component)target);
 145     }
 146 }