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 @SuppressWarnings("deprecation") 91 public void hide() { 92 Dialog dlg = (Dialog)target; 93 if (dlg.getModalityType() != Dialog.ModalityType.MODELESS) { 94 endModal(); 95 } else { 96 super.hide(); 97 } 98 } 99 100 public void blockWindows(java.util.List<Window> toBlock) { 101 for (Window w : toBlock) { 102 WWindowPeer wp = (WWindowPeer)AWTAccessor.getComponentAccessor().getPeer(w); 103 if (wp != null) { 104 wp.setModalBlocked((Dialog)target, true); 105 } 106 } 107 } 108 109 public Dimension getMinimumSize() { 110 if (((Dialog)target).isUndecorated()) { 111 return super.getMinimumSize(); 112 } else { 113 return new Dimension(getSysMinWidth(), getSysMinHeight()); 114 } 115 } 116 117 @Override 118 boolean isTargetUndecorated() { 119 return ((Dialog)target).isUndecorated(); 120 } 121 122 public void reshape(int x, int y, int width, int height) { 123 if (((Dialog)target).isUndecorated()) { 124 super.reshape(x, y, width, height); 125 } else { 126 reshapeFrame(x, y, width, height); 127 } 128 } 129 130 /* Native create() peeks at target's background and if it's null 131 * calls this method to arrage for default background to be set on 132 * target. Can't make the check in Java, since getBackground will 133 * return owner's background if target has none set. 134 */ 135 private void setDefaultColor() { 136 // Can't call target.setBackground directly, since we are 137 // called on toolkit thread. Can't schedule a Runnable on the 138 // EventHandlerThread because of the race condition. So just 139 // set a flag and call target.setBackground in initialize. 140 needDefaultBackground = true; 141 } 142 143 native void pSetIMMOption(String option); 144 void notifyIMMOptionChange(){ 145 InputMethodManager.getInstance().notifyChangeRequest((Component)target); 146 } 147 }