1 /*
   2  * Copyright (c) 1999, 2010, 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 
  26 package sun.awt.windows;
  27 
  28 import java.awt.*;
  29 import java.awt.peer.DialogPeer;
  30 import java.awt.peer.ComponentPeer;
  31 import java.awt.dnd.DropTarget;
  32 import java.util.Vector;
  33 import sun.awt.AppContext;
  34 import sun.awt.CausedFocusEvent;
  35 import sun.awt.AWTAccessor;
  36 
  37 public class WPrintDialogPeer extends WWindowPeer implements DialogPeer {
  38 
  39     static {
  40         initIDs();
  41     }
  42 
  43     private WComponentPeer parent;
  44 
  45     private Vector<WWindowPeer> blockedWindows = new Vector<WWindowPeer>();
  46 
  47     WPrintDialogPeer(WPrintDialog target) {
  48         super(target);
  49     }
  50 
  51     void create(WComponentPeer parent) {
  52         this.parent = parent;
  53     }
  54 
  55     // fix for CR 6178323:
  56     // don't use checkCreation() from WComponentPeer to avoid hwnd check
  57     protected void checkCreation() {
  58     }
  59 
  60     protected void disposeImpl() {
  61         WToolkit.targetDisposedPeer(target, this);
  62     }
  63 
  64     private native boolean _show();
  65 
  66     public void show() {
  67         new Thread(new Runnable() {
  68             public void run() {
  69                 try {
  70                     ((WPrintDialog)target).setRetVal(_show());
  71                 } catch (Exception e) {
  72                     // No exception should be thrown by native dialog code,
  73                     // but if it is we need to trap it so the thread does
  74                     // not hide is called and the thread doesn't hang.
  75                 }
  76                 ((WPrintDialog)target).hide();
  77             }
  78         }).start();
  79     }
  80 
  81     synchronized void setHWnd(long hwnd) {
  82         this.hwnd = hwnd;
  83         for (WWindowPeer window : blockedWindows) {
  84             if (hwnd != 0) {
  85                 window.modalDisable((Dialog)target, hwnd);
  86             } else {
  87                 window.modalEnable((Dialog)target);
  88             }
  89         }
  90     }
  91 
  92     synchronized void blockWindow(WWindowPeer window) {
  93         blockedWindows.add(window);
  94         if (hwnd != 0) {
  95             window.modalDisable((Dialog)target, hwnd);
  96         }
  97     }
  98     synchronized void unblockWindow(WWindowPeer window) {
  99         blockedWindows.remove(window);
 100         if (hwnd != 0) {
 101             window.modalEnable((Dialog)target);
 102         }
 103     }
 104 
 105     public void blockWindows(java.util.List<Window> toBlock) {
 106         for (Window w : toBlock) {
 107             WWindowPeer wp = (WWindowPeer)AWTAccessor.getComponentAccessor().getPeer(w);
 108             if (wp != null) {
 109                 blockWindow(wp);
 110             }
 111         }
 112     }
 113 
 114     public native void toFront();
 115     public native void toBack();
 116 
 117     // unused methods.  Overridden to disable this functionality as
 118     // it requires HWND which is not available for FileDialog
 119     void initialize() {}
 120     public void setAlwaysOnTop(boolean b) {}
 121     public void setResizable(boolean resizable) {}
 122     public void hide() {}
 123     public void enable() {}
 124     public void disable() {}
 125     public void reshape(int x, int y, int width, int height) {}
 126     public boolean handleEvent(Event e) { return false; }
 127     public void setForeground(Color c) {}
 128     public void setBackground(Color c) {}
 129     public void setFont(Font f) {}
 130     public void updateMinimumSize() {}
 131     public void updateIconImages() {}
 132     public boolean requestFocus(boolean temporary, boolean focusedWindowChangeAllowed) {
 133         return false;
 134     }
 135 
 136     public boolean requestFocus
 137          (Component lightweightChild, boolean temporary,
 138           boolean focusedWindowChangeAllowed, long time, CausedFocusEvent.Cause cause)
 139     {
 140 
 141         return false;
 142     }
 143 
 144     public void updateFocusableWindowState() {}
 145     void start() {}
 146     public void beginValidate() {}
 147     public void endValidate() {}
 148     void invalidate(int x, int y, int width, int height) {}
 149     public void addDropTarget(DropTarget dt) {}
 150     public void removeDropTarget(DropTarget dt) {}
 151     public void setZOrder(ComponentPeer above) {}
 152 
 153     /**
 154      * Initialize JNI field and method ids
 155      */
 156     private static native void initIDs();
 157 
 158     // The effects are not supported for system dialogs.
 159     public void applyShape(sun.java2d.pipe.Region shape) {}
 160     public void setOpacity(float opacity) {}
 161     public void setOpaque(boolean isOpaque) {}
 162     public void updateWindow(java.awt.image.BufferedImage backBuffer) {}
 163 
 164     // the file/print dialogs are native dialogs and
 165     // the native system does their own rendering
 166     @Override
 167     public void createScreenSurface(boolean isResize) {}
 168     @Override
 169     public void replaceSurfaceData() {}
 170 }