1 /*
   2  * Copyright (c) 1996, 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 sun.awt.windows;
  26 
  27 import java.awt.*;
  28 import java.awt.peer.*;
  29 
  30 import sun.awt.*;
  31 import sun.awt.im.*;
  32 
  33 final class WDialogPeer extends WWindowPeer implements DialogPeer {
  34     // Toolkit & peer internals
  35 
  36     WDialogPeer(Dialog target) {
  37         super(target);
  38 
  39         InputMethodManager imm = InputMethodManager.getInstance();
  40         String menuString = imm.getTriggerMenuString();
  41         if (menuString != null)
  42         {
  43             pSetIMMOption(menuString);
  44         }
  45     }
  46 
  47     native void createAwtDialog(WComponentPeer parent);
  48     @Override
  49     void create(WComponentPeer parent) {
  50         preCreate(parent);
  51         createAwtDialog(parent);
  52     }
  53 
  54     native void showModal();
  55     native void endModal();
  56 
  57     @Override
  58     void initialize() {
  59         Dialog target = (Dialog)this.target;
  60     
  61         super.initialize();
  62 
  63         if (target.getTitle() != null) {
  64             setTitle(target.getTitle());
  65         }
  66         setResizable(target.isResizable());
  67     }
  68 
  69     @Override
  70     protected void realShow() {
  71         Dialog dlg = (Dialog)target;
  72         if (dlg.getModalityType() != Dialog.ModalityType.MODELESS) {
  73             showModal();
  74         } else {
  75             super.realShow();
  76         }
  77     }
  78 
  79     @Override
  80     @SuppressWarnings("deprecation")
  81     void hide() {
  82         Dialog dlg = (Dialog)target;
  83         if (dlg.getModalityType() != Dialog.ModalityType.MODELESS) {
  84             endModal();
  85         } else {
  86             super.hide();
  87         }
  88     }
  89 
  90     @Override
  91     public void blockWindows(java.util.List<Window> toBlock) {
  92         for (Window w : toBlock) {
  93             WWindowPeer wp = AWTAccessor.getComponentAccessor().getPeer(w);
  94             if (wp != null) {
  95                 wp.setModalBlocked((Dialog)target, true);
  96             }
  97         }
  98     }
  99 
 100     @Override
 101     public Dimension getMinimumSize() {
 102         if (((Dialog)target).isUndecorated()) {
 103             return super.getMinimumSize();
 104         } else {
 105             return new Dimension(getSysMinWidth(), getSysMinHeight());
 106         }
 107     }
 108 
 109     @Override
 110     boolean isTargetUndecorated() {
 111         return ((Dialog)target).isUndecorated();
 112     }
 113 
 114     @Override
 115     public void reshape(int x, int y, int width, int height) {
 116         if (((Dialog)target).isUndecorated()) {
 117             super.reshape(x, y, width, height);
 118         } else {
 119             reshapeFrame(x, y, width, height);
 120         }
 121     }
 122 
 123     native void pSetIMMOption(String option);
 124     void notifyIMMOptionChange(){
 125       InputMethodManager.getInstance().notifyChangeRequest((Component)target);
 126     }
 127 }