1 /* 2 * Copyright 1996-2008 Sun Microsystems, Inc. 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. Sun designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 * CA 95054 USA or visit www.sun.com if you need additional information or 23 * have any 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 create(WComponentPeer parent); 57 native void showModal(); 58 native void endModal(); 59 60 void initialize() { 61 Dialog target = (Dialog)this.target; 62 // Need to set target's background to default _before_ a call 63 // to super.initialize. 64 if (needDefaultBackground) { 65 target.setBackground(defaultBackground); 66 } 67 68 super.initialize(); 69 70 if (target.getTitle() != null) { 71 setTitle(target.getTitle()); 72 } 73 setResizable(target.isResizable()); 74 } 75 76 protected void realShow() { 77 Dialog dlg = (Dialog)target; 78 if (dlg.getModalityType() != Dialog.ModalityType.MODELESS) { 79 showModal(); 80 } else { 81 super.realShow(); 82 } 83 } 84 85 public void hide() { 86 Dialog dlg = (Dialog)target; 87 if (dlg.getModalityType() != Dialog.ModalityType.MODELESS) { 88 endModal(); 89 } else { 90 super.hide(); 91 } 92 } 93 94 public void blockWindows(java.util.List<Window> toBlock) { 95 for (Window w : toBlock) { 96 WWindowPeer wp = (WWindowPeer)ComponentAccessor.getPeer(w); 97 if (wp != null) { 98 wp.setModalBlocked((Dialog)target, true); 99 } 100 } 101 } 102 103 public Dimension getMinimumSize() { 104 if (((Dialog)target).isUndecorated()) { 105 return super.getMinimumSize(); 106 } else { 107 return new Dimension(getSysMinWidth(), getSysMinHeight()); 108 } 109 } 110 111 @Override 112 boolean isTargetUndecorated() { 113 return ((Dialog)target).isUndecorated(); 114 } 115 116 public void reshape(int x, int y, int width, int height) { 117 if (((Dialog)target).isUndecorated()) { 118 super.reshape(x, y, width, height); 119 } else { 120 reshapeFrame(x, y, width, height); 121 } 122 } 123 124 /* Native create() peeks at target's background and if it's null 125 * calls this method to arrage for default background to be set on 126 * target. Can't make the check in Java, since getBackground will 127 * return owner's background if target has none set. 128 */ 129 private void setDefaultColor() { 130 // Can't call target.setBackground directly, since we are 131 // called on toolkit thread. Can't schedule a Runnable on the 132 // EventHandlerThread because of the race condition. So just 133 // set a flag and call target.setBackground in initialize. 134 needDefaultBackground = true; 135 } 136 137 native void pSetIMMOption(String option); 138 void notifyIMMOptionChange(){ 139 InputMethodManager.getInstance().notifyChangeRequest((Component)target); 140 } 141 }