1 /*
   2  * Copyright (c) 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 
  26 package sun.lwawt;
  27 
  28 import java.awt.Graphics;
  29 import java.awt.GraphicsConfiguration;
  30 import java.awt.Insets;
  31 import java.awt.Point;
  32 import java.awt.Rectangle;
  33 import java.awt.Transparency;
  34 import java.awt.Window;
  35 import java.awt.dnd.DropTarget;
  36 
  37 import sun.awt.CausedFocusEvent;
  38 import sun.awt.LightweightFrame;
  39 import sun.awt.image.OffScreenImage;
  40 import sun.swing.JLightweightFrame;
  41 import sun.swing.SwingAccessor;
  42 
  43 public class LWLightweightFramePeer extends LWWindowPeer {
  44 
  45     public LWLightweightFramePeer(LightweightFrame target,
  46                                   PlatformComponent platformComponent,
  47                                   PlatformWindow platformWindow)
  48     {
  49         super(target, platformComponent, platformWindow, LWWindowPeer.PeerType.LW_FRAME);
  50     }
  51 
  52     private LightweightFrame getLwTarget() {
  53         return (LightweightFrame)getTarget();
  54     }
  55 
  56     @Override
  57     public Graphics getGraphics() {
  58         return getLwTarget().getGraphics();
  59     }
  60 
  61     @Override
  62     protected void setVisibleImpl(final boolean visible) {
  63     }
  64 
  65     @Override
  66     public boolean requestWindowFocus(CausedFocusEvent.Cause cause) {
  67         if (!focusAllowedFor()) {
  68             return false;
  69         }
  70         if (getPlatformWindow().rejectFocusRequest(cause)) {
  71             return false;
  72         }
  73 
  74         Window opposite = LWKeyboardFocusManagerPeer.getInstance().
  75             getCurrentFocusedWindow();
  76 
  77         changeFocusedWindow(true, opposite);
  78 
  79         return true;
  80     }
  81 
  82     @Override
  83     public Point getLocationOnScreen() {
  84         Rectangle bounds = getBounds();
  85         return new Point(bounds.x, bounds.y); // todo
  86     }
  87 
  88     @Override
  89     public Insets getInsets() {
  90         return new Insets(0, 0, 0, 0);
  91     }
  92 
  93     @Override
  94     public void setBounds(int x, int y, int w, int h, int op) {
  95         setBounds(x, y, w, h, op, true, false);
  96     }
  97 
  98     @Override
  99     public void addDropTarget(DropTarget dt) {
 100     }
 101 
 102     @Override
 103     public void removeDropTarget(DropTarget dt) {
 104     }
 105 
 106     @Override
 107     public void grab() {
 108         getLwTarget().grabFocus();
 109     }
 110 
 111     @Override
 112     public void ungrab() {
 113         getLwTarget().ungrabFocus();
 114     }
 115 
 116     @Override
 117     public void updateCursorImmediately() {
 118         SwingAccessor.getJLightweightFrameAccessor().updateCursor((JLightweightFrame)getLwTarget());
 119     }
 120     
 121     @Override
 122     public OffScreenImage createHiDPIImage(int width, int height) {
 123         OffScreenImage img =  OffScreenImage.create(getLwTarget(), (GraphicsConfiguration)getLWGC(),
 124                                                     width, height, Transparency.OPAQUE,
 125                                                     getLwTarget().getScaleFactor());
 126         return img;
 127     }
 128     
 129     @Override
 130     public void notifyScaleFactorChanged() {
 131         displayChanged();
 132     }
 133 }