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