1 /*
   2  * Copyright (c) 2013, 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.Insets;
  30 import java.awt.Point;
  31 import java.awt.Rectangle;
  32 import java.awt.Window;
  33 import java.awt.dnd.DropTarget;
  34 
  35 import sun.awt.CausedFocusEvent;
  36 import sun.awt.LightweightFrame;
  37 
  38 public class LWLightweightFramePeer extends LWWindowPeer {
  39 
  40     public LWLightweightFramePeer(LightweightFrame target,
  41                                   PlatformComponent platformComponent,
  42                                   PlatformWindow platformWindow)
  43     {
  44         super(target, platformComponent, platformWindow, LWWindowPeer.PeerType.LW_FRAME);
  45     }
  46 
  47     private LightweightFrame getLwTarget() {
  48         return (LightweightFrame)getTarget();
  49     }
  50 
  51     @Override
  52     public Graphics getGraphics() {
  53         return getLwTarget().getGraphics();
  54     }
  55 
  56     @Override
  57     protected void setVisibleImpl(final boolean visible) {
  58     }
  59 
  60     @Override
  61     public boolean requestWindowFocus(CausedFocusEvent.Cause cause) {
  62         if (!focusAllowedFor()) {
  63             return false;
  64         }
  65         if (getPlatformWindow().rejectFocusRequest(cause)) {
  66             return false;
  67         }
  68 
  69         Window opposite = LWKeyboardFocusManagerPeer.getInstance().
  70             getCurrentFocusedWindow();
  71 
  72         changeFocusedWindow(true, opposite);
  73 
  74         return true;
  75     }
  76 
  77     @Override
  78     public Point getLocationOnScreen() {
  79         Rectangle bounds = getBounds();
  80         return new Point(bounds.x, bounds.y); // todo
  81     }
  82 
  83     @Override
  84     public Insets getInsets() {
  85         return new Insets(0, 0, 0, 0);
  86     }
  87 
  88     @Override
  89     public void setBounds(int x, int y, int w, int h, int op) {
  90         setBounds(x, y, w, h, op, true, false);
  91     }
  92 
  93     @Override
  94     public void updateCursorImmediately() {
  95         // TODO: tries to switch to the awt/fx toolkit thread and causes a deadlock on macosx
  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 }