src/share/classes/com/sun/java/swing/plaf/windows/WindowsPopupMenuUI.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2006, 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


 177 
 178     /**
 179      * Checks if PopupMenu is leftToRight
 180      * The orientation is derived from the children of the component.
 181      * It is leftToRight if all the children are leftToRight
 182      *
 183      * @param c component to return orientation for
 184      * @return true if all the children are leftToRight
 185      */
 186     private static boolean isLeftToRight(JComponent c) {
 187         boolean leftToRight = true;
 188         for (int i = c.getComponentCount() - 1; i >=0 && leftToRight; i-- ) {
 189             leftToRight =
 190                 c.getComponent(i).getComponentOrientation().isLeftToRight();
 191         }
 192         return leftToRight;
 193     }
 194 
 195     @Override
 196     public void paint(Graphics g, JComponent c) {
 197         if (WindowsMenuItemUI.isVistaPainting()) {
 198             XPStyle xp = XPStyle.getXP();

 199             Skin skin = xp.getSkin(c, Part.MP_POPUPBACKGROUND);
 200             skin.paintSkin(g, 0, 0, c.getWidth(),c.getHeight(), State.NORMAL);
 201             int textOffset = getTextOffset(c);
 202             if (textOffset >= 0
 203                     /* paint gutter only for leftToRight case */
 204                     && isLeftToRight(c)) {
 205                 skin = xp.getSkin(c, Part.MP_POPUPGUTTER);
 206                 int gutterWidth = getGutterWidth();
 207                 int gutterOffset =
 208                     textOffset - getSpanAfterGutter() - gutterWidth;
 209                 c.putClientProperty(GUTTER_OFFSET_KEY,
 210                     Integer.valueOf(gutterOffset));
 211                 Insets insets = c.getInsets();
 212                 skin.paintSkin(g, gutterOffset, insets.top,
 213                     gutterWidth, c.getHeight() - insets.bottom - insets.top,
 214                     State.NORMAL);
 215             } else {
 216                 if (c.getClientProperty(GUTTER_OFFSET_KEY) != null) {
 217                     c.putClientProperty(GUTTER_OFFSET_KEY, null);
 218                 }
   1 /*
   2  * Copyright (c) 1997, 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


 177 
 178     /**
 179      * Checks if PopupMenu is leftToRight
 180      * The orientation is derived from the children of the component.
 181      * It is leftToRight if all the children are leftToRight
 182      *
 183      * @param c component to return orientation for
 184      * @return true if all the children are leftToRight
 185      */
 186     private static boolean isLeftToRight(JComponent c) {
 187         boolean leftToRight = true;
 188         for (int i = c.getComponentCount() - 1; i >=0 && leftToRight; i-- ) {
 189             leftToRight =
 190                 c.getComponent(i).getComponentOrientation().isLeftToRight();
 191         }
 192         return leftToRight;
 193     }
 194 
 195     @Override
 196     public void paint(Graphics g, JComponent c) {

 197         XPStyle xp = XPStyle.getXP();
 198         if (WindowsMenuItemUI.isVistaPainting(xp)) {
 199             Skin skin = xp.getSkin(c, Part.MP_POPUPBACKGROUND);
 200             skin.paintSkin(g, 0, 0, c.getWidth(),c.getHeight(), State.NORMAL);
 201             int textOffset = getTextOffset(c);
 202             if (textOffset >= 0
 203                     /* paint gutter only for leftToRight case */
 204                     && isLeftToRight(c)) {
 205                 skin = xp.getSkin(c, Part.MP_POPUPGUTTER);
 206                 int gutterWidth = getGutterWidth();
 207                 int gutterOffset =
 208                     textOffset - getSpanAfterGutter() - gutterWidth;
 209                 c.putClientProperty(GUTTER_OFFSET_KEY,
 210                     Integer.valueOf(gutterOffset));
 211                 Insets insets = c.getInsets();
 212                 skin.paintSkin(g, gutterOffset, insets.top,
 213                     gutterWidth, c.getHeight() - insets.bottom - insets.top,
 214                     State.NORMAL);
 215             } else {
 216                 if (c.getClientProperty(GUTTER_OFFSET_KEY) != null) {
 217                     c.putClientProperty(GUTTER_OFFSET_KEY, null);
 218                 }