Home » openjdk-7 » java » awt » [javadoc | source]

    1   /*
    2    *  Licensed to the Apache Software Foundation (ASF) under one or more
    3    *  contributor license agreements.  See the NOTICE file distributed with
    4    *  this work for additional information regarding copyright ownership.
    5    *  The ASF licenses this file to You under the Apache License, Version 2.0
    6    *  (the "License"); you may not use this file except in compliance with
    7    *  the License.  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    *  Unless required by applicable law or agreed to in writing, software
   12    *  distributed under the License is distributed on an "AS IS" BASIS,
   13    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    *  See the License for the specific language governing permissions and
   15    *  limitations under the License.
   16    */
   17   /**
   18    * @author Dmitry A. Durnev
   19    *
   20    */
   21   package java.awt;
   22   
   23   import org.apache.harmony.awt.wtk.NativeWindow;
   24   
   25   /**
   26    * Heavyweight component specific behaviour
   27    */
   28   
   29   class HWBehavior implements ComponentBehavior {
   30   
   31       private final Component component;
   32       private NativeWindow nativeWindow;
   33   
   34       HWBehavior(Component comp) {
   35           component = comp;
   36           Toolkit.checkHeadless();
   37           // implicitly disable IM for all heavyweight components
   38           // TextComponents must set this flag back to true
   39           component.dispatchToIM = false;
   40       }
   41   
   42       public boolean isOpaque() {
   43           // heavyweights are always opaque
   44           return true;
   45       }
   46   
   47       public boolean isLightweight() {
   48           return false;
   49       }
   50   
   51       public void setVisible(boolean b) {
   52           if (nativeWindow != null) {
   53               nativeWindow.setVisible(b);
   54           }
   55       }
   56   
   57       public NativeWindow getNativeWindow() {
   58           return nativeWindow;
   59       }
   60   
   61       public void addNotify() {
   62           nativeWindow = createNativeWindow();
   63           nativeWindow.setVisible(component.isVisible());
   64           updateFocus();
   65       }
   66   
   67       protected NativeWindow createNativeWindow() {
   68           return component.toolkit.createNativeWindow(component);
   69       }
   70   
   71       private void updateFocus() {
   72           if (component.isShowing()) {
   73               Window wnd = component.getWindowAncestor();
   74               if ((wnd == null) ||
   75                   (!wnd.isFocused() && !wnd.isActive())) {
   76                   return;
   77               }
   78   
   79               KeyboardFocusManager.getCurrentKeyboardFocusManager().
   80               requestFocusInWindow(wnd, true);
   81           }
   82       }
   83   
   84       public Graphics getGraphics(int translationX, int translationY,
   85                                   int width, int height) {
   86   
   87           return component.toolkit.getGraphicsFactory().
   88                   getGraphics2D(nativeWindow, translationX, translationY,
   89                         width, height);
   90       }
   91   
   92       public void setBounds(int x, int y, int w, int h, int bMask) {
   93           if (nativeWindow != null) {
   94               Point loc = new Point(x, y);
   95               if (!(component instanceof Window)) {
   96                   Component parent = component.getHWAncestor();
   97                   loc = MouseDispatcher.convertPoint(component, 0, 0, parent);
   98               }
   99   
  100               nativeWindow.setBounds(loc.x, loc.y, w, h, bMask);
  101   
  102           }
  103       }
  104   
  105       public boolean isDisplayable() {
  106           return (nativeWindow != null);
  107       }
  108   
  109       public void setEnabled(boolean value) {
  110           if (nativeWindow != null) {
  111               nativeWindow.setEnabled(value);
  112           }
  113       }
  114   
  115       public void removeNotify() {
  116           if (nativeWindow == null) {
  117               return;
  118           }
  119           component.toolkit.removeNativeWindow(nativeWindow);
  120           NativeWindow temp = nativeWindow;
  121           nativeWindow = null;
  122   
  123           if (!(component instanceof Window)) {
  124               // dispose only if HW ancestor is not disposed already
  125               Component hwAncestor = component.getHWAncestor();
  126               if ((hwAncestor == null) || !hwAncestor.isDisplayable()) {
  127                   return;
  128               }
  129           }
  130           temp.dispose();
  131   
  132       }
  133   
  134       public void onMove(int x, int y) {
  135           setBounds(component.x, component.y, component.w,
  136                     component.h, NativeWindow.BOUNDS_NOSIZE);
  137   
  138       }
  139   
  140       public void setZOrder(int newIndex, int oldIndex) {
  141           NativeWindow win = null;
  142           Container par = component.getParent();
  143           if (par != null) {
  144               int size = par.getComponentCount();
  145               for (int i = Math.min(newIndex - 1, size - 1);  i >= 0; i--) {
  146                   Component comp = par.getComponent(i);
  147                   if (!comp.isLightweight() && comp.isDisplayable()) {
  148                       win = comp.getNativeWindow();
  149                       break;
  150                   }
  151               }
  152           }
  153           if (nativeWindow != null) {
  154               nativeWindow.placeAfter(win);
  155           }
  156       }
  157   
  158       public boolean setFocus(boolean focus, Component opposite) {
  159           if (nativeWindow != null) {
  160               return nativeWindow.setFocus(focus);
  161           }
  162           return false;
  163       }
  164   }

Home » openjdk-7 » java » awt » [javadoc | source]