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 // Platform default background for dialogs. Gets set on target if 37 // target has none explicitly specified. 38 static final Color defaultBackground = SystemColor.control; 39 40 WDialogPeer(Dialog target) { 41 super(target); 42 43 InputMethodManager imm = InputMethodManager.getInstance(); 44 String menuString = imm.getTriggerMenuString(); 45 if (menuString != null) 46 { 47 pSetIMMOption(menuString); 48 } 49 } 50 51 native void createAwtDialog(WComponentPeer parent); 52 @Override 53 void create(WComponentPeer parent) { 54 preCreate(parent); 55 createAwtDialog(parent); 56 } 57 58 native void showModal(); 59 native void endModal(); 60 61 @Override 62 void initialize() { 63 Dialog target = (Dialog)this.target; 64 // Need to set target's background to default _before_ a call 65 // to super.initialize. 66 if (!target.isBackgroundSet()) { 67 target.setBackground(defaultBackground); 68 } 69 70 super.initialize(); 71 72 if (target.getTitle() != null) { 73 setTitle(target.getTitle()); 74 } 75 setResizable(target.isResizable()); 76 } 77 78 @Override 79 protected void realShow() { 80 Dialog dlg = (Dialog)target; 81 if (dlg.getModalityType() != Dialog.ModalityType.MODELESS) { 82 showModal(); 83 } else { 84 super.realShow(); 85 } 86 } 87 88 @Override 89 @SuppressWarnings("deprecation") 90 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 @Override 100 public void blockWindows(java.util.List<Window> toBlock) { 101 for (Window w : toBlock) { 102 WWindowPeer wp = AWTAccessor.getComponentAccessor().getPeer(w); 103 if (wp != null) { 104 wp.setModalBlocked((Dialog)target, true); 105 } 106 } 107 } 108 109 @Override 110 public Dimension getMinimumSize() { 111 if (((Dialog)target).isUndecorated()) { 112 return super.getMinimumSize(); 113 } else { 114 return new Dimension(getSysMinWidth(), getSysMinHeight()); 115 } 116 } 117 118 @Override 119 boolean isTargetUndecorated() { 120 return ((Dialog)target).isUndecorated(); 121 } 122 123 @Override 124 public void reshape(int x, int y, int width, int height) { 125 if (((Dialog)target).isUndecorated()) { 126 super.reshape(x, y, width, height); 127 } else { 128 reshapeFrame(x, y, width, height); 129 } 130 } 131 132 native void pSetIMMOption(String option); 133 void notifyIMMOptionChange(){ 134 InputMethodManager.getInstance().notifyChangeRequest((Component)target); 135 } 136 }