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

Print this page


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


  97         return tableHeaderBorder;
  98     }
  99 
 100     public static Border getInternalFrameBorder() {
 101         UIDefaults table = UIManager.getLookAndFeelDefaults();
 102         Border internalFrameBorder = new
 103             BorderUIResource.CompoundBorderUIResource(
 104                 BorderFactory.createBevelBorder(BevelBorder.RAISED,
 105                     table.getColor("InternalFrame.borderColor"),
 106                     table.getColor("InternalFrame.borderHighlight"),
 107                     table.getColor("InternalFrame.borderDarkShadow"),
 108                     table.getColor("InternalFrame.borderShadow")),
 109                 new WindowsBorders.InternalFrameLineBorder(
 110                     table.getColor("InternalFrame.activeBorderColor"),
 111                     table.getColor("InternalFrame.inactiveBorderColor"),
 112                     table.getInt("InternalFrame.borderWidth")));
 113 
 114         return internalFrameBorder;
 115     }
 116 

 117     public static class ProgressBarBorder extends AbstractBorder implements UIResource {
 118         protected Color shadow;
 119         protected Color highlight;
 120 
 121         public ProgressBarBorder(Color shadow, Color highlight) {
 122             this.highlight = highlight;
 123             this.shadow = shadow;
 124         }
 125 
 126         public void paintBorder(Component c, Graphics g, int x, int y,
 127                                 int width, int height) {
 128             g.setColor(shadow);
 129             g.drawLine(x,y, width-1,y); // draw top
 130             g.drawLine(x,y, x,height-1); // draw left
 131             g.setColor(highlight);
 132             g.drawLine(x,height-1, width-1,height-1); // draw bottom
 133             g.drawLine(width-1,y, width-1,height-1); // draw right
 134         }
 135 
 136         public Insets getBorderInsets(Component c, Insets insets) {
 137             insets.set(1,1,1,1);
 138             return insets;
 139         }
 140     }
 141 
 142     /**
 143      * A border for the ToolBar. If the ToolBar is floatable then the handle grip is drawn
 144      * <p>
 145      * @since 1.4
 146      */

 147     public static class ToolBarBorder extends AbstractBorder implements UIResource, SwingConstants {
 148         protected Color shadow;
 149         protected Color highlight;
 150 
 151         public ToolBarBorder(Color shadow, Color highlight) {
 152             this.highlight = highlight;
 153             this.shadow = shadow;
 154         }
 155 
 156         public void paintBorder(Component c, Graphics g, int x, int y,
 157                                 int width, int height) {
 158             if (!(c instanceof JToolBar)) {
 159                 return;
 160             }
 161             g.translate(x, y);
 162 
 163             XPStyle xp = XPStyle.getXP();
 164             if (xp != null) {
 165                 Border xpBorder = xp.getBorder(c, Part.TP_TOOLBAR);
 166                 if (xpBorder != null) {


 230             if (((JToolBar)c).isFloatable()) {
 231                 int gripInset = (XPStyle.getXP() != null) ? 12 : 9;
 232                 if (((JToolBar)c).getOrientation() == HORIZONTAL) {
 233                     if (c.getComponentOrientation().isLeftToRight()) {
 234                         insets.left = gripInset;
 235                     } else {
 236                         insets.right = gripInset;
 237                     }
 238                 } else {
 239                     insets.top = gripInset;
 240                 }
 241             }
 242             return insets;
 243         }
 244     }
 245 
 246     /**
 247      * This class is an implementation of a dashed border.
 248      * @since 1.4
 249      */

 250     public static class DashedBorder extends LineBorder implements UIResource {
 251         public DashedBorder(Color color) {
 252             super(color);
 253         }
 254 
 255         public DashedBorder(Color color, int thickness)  {
 256             super(color, thickness);
 257         }
 258 
 259         public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
 260             Color oldColor = g.getColor();
 261             int i;
 262 
 263             g.setColor(lineColor);
 264             for(i = 0; i < thickness; i++)  {
 265                 BasicGraphicsUtils.drawDashedRect(g, x+i, y+i, width-i-i, height-i-i);
 266             }
 267             g.setColor(oldColor);
 268         }
 269     }
 270 
 271     /**
 272      * A dashed border that paints itself in the complementary color
 273      * of the component's background color.
 274      */

 275     static class ComplementDashedBorder extends LineBorder implements UIResource {
 276         private Color origColor;
 277         private Color paintColor;
 278 
 279         public ComplementDashedBorder() {
 280             super(null);
 281         }
 282 
 283         public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
 284             Color color = c.getBackground();
 285 
 286             if (origColor != color) {
 287                 origColor = color;
 288                 paintColor = new Color(~origColor.getRGB());
 289             }
 290 
 291             g.setColor(paintColor);
 292             BasicGraphicsUtils.drawDashedRect(g, x, y, width, height);
 293         }
 294     }
 295 
 296     /**
 297      * This class is an implementation of the InternalFrameLine border.
 298      * @since 1.4
 299      */

 300     public static class InternalFrameLineBorder extends LineBorder implements
 301             UIResource {
 302         protected Color activeColor;
 303         protected Color inactiveColor;
 304 
 305         public InternalFrameLineBorder(Color activeBorderColor,
 306                                        Color inactiveBorderColor,
 307                                        int thickness) {
 308             super(activeBorderColor, thickness);
 309             activeColor = activeBorderColor;
 310             inactiveColor = inactiveBorderColor;
 311         }
 312 
 313         public void paintBorder(Component c, Graphics g, int x, int y,
 314                 int width, int height) {
 315 
 316             JInternalFrame jif = null;
 317             if (c instanceof JInternalFrame) {
 318                 jif = (JInternalFrame)c;
 319             } else if (c instanceof JInternalFrame.JDesktopIcon) {
   1 /*
   2  * Copyright (c) 1998, 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


  97         return tableHeaderBorder;
  98     }
  99 
 100     public static Border getInternalFrameBorder() {
 101         UIDefaults table = UIManager.getLookAndFeelDefaults();
 102         Border internalFrameBorder = new
 103             BorderUIResource.CompoundBorderUIResource(
 104                 BorderFactory.createBevelBorder(BevelBorder.RAISED,
 105                     table.getColor("InternalFrame.borderColor"),
 106                     table.getColor("InternalFrame.borderHighlight"),
 107                     table.getColor("InternalFrame.borderDarkShadow"),
 108                     table.getColor("InternalFrame.borderShadow")),
 109                 new WindowsBorders.InternalFrameLineBorder(
 110                     table.getColor("InternalFrame.activeBorderColor"),
 111                     table.getColor("InternalFrame.inactiveBorderColor"),
 112                     table.getInt("InternalFrame.borderWidth")));
 113 
 114         return internalFrameBorder;
 115     }
 116 
 117     @SuppressWarnings("serial") // Superclass is not serializable across versions
 118     public static class ProgressBarBorder extends AbstractBorder implements UIResource {
 119         protected Color shadow;
 120         protected Color highlight;
 121 
 122         public ProgressBarBorder(Color shadow, Color highlight) {
 123             this.highlight = highlight;
 124             this.shadow = shadow;
 125         }
 126 
 127         public void paintBorder(Component c, Graphics g, int x, int y,
 128                                 int width, int height) {
 129             g.setColor(shadow);
 130             g.drawLine(x,y, width-1,y); // draw top
 131             g.drawLine(x,y, x,height-1); // draw left
 132             g.setColor(highlight);
 133             g.drawLine(x,height-1, width-1,height-1); // draw bottom
 134             g.drawLine(width-1,y, width-1,height-1); // draw right
 135         }
 136 
 137         public Insets getBorderInsets(Component c, Insets insets) {
 138             insets.set(1,1,1,1);
 139             return insets;
 140         }
 141     }
 142 
 143     /**
 144      * A border for the ToolBar. If the ToolBar is floatable then the handle grip is drawn
 145      * <p>
 146      * @since 1.4
 147      */
 148     @SuppressWarnings("serial") // Superclass is not serializable across versions
 149     public static class ToolBarBorder extends AbstractBorder implements UIResource, SwingConstants {
 150         protected Color shadow;
 151         protected Color highlight;
 152 
 153         public ToolBarBorder(Color shadow, Color highlight) {
 154             this.highlight = highlight;
 155             this.shadow = shadow;
 156         }
 157 
 158         public void paintBorder(Component c, Graphics g, int x, int y,
 159                                 int width, int height) {
 160             if (!(c instanceof JToolBar)) {
 161                 return;
 162             }
 163             g.translate(x, y);
 164 
 165             XPStyle xp = XPStyle.getXP();
 166             if (xp != null) {
 167                 Border xpBorder = xp.getBorder(c, Part.TP_TOOLBAR);
 168                 if (xpBorder != null) {


 232             if (((JToolBar)c).isFloatable()) {
 233                 int gripInset = (XPStyle.getXP() != null) ? 12 : 9;
 234                 if (((JToolBar)c).getOrientation() == HORIZONTAL) {
 235                     if (c.getComponentOrientation().isLeftToRight()) {
 236                         insets.left = gripInset;
 237                     } else {
 238                         insets.right = gripInset;
 239                     }
 240                 } else {
 241                     insets.top = gripInset;
 242                 }
 243             }
 244             return insets;
 245         }
 246     }
 247 
 248     /**
 249      * This class is an implementation of a dashed border.
 250      * @since 1.4
 251      */
 252     @SuppressWarnings("serial") // Superclass is not serializable across versions
 253     public static class DashedBorder extends LineBorder implements UIResource {
 254         public DashedBorder(Color color) {
 255             super(color);
 256         }
 257 
 258         public DashedBorder(Color color, int thickness)  {
 259             super(color, thickness);
 260         }
 261 
 262         public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
 263             Color oldColor = g.getColor();
 264             int i;
 265 
 266             g.setColor(lineColor);
 267             for(i = 0; i < thickness; i++)  {
 268                 BasicGraphicsUtils.drawDashedRect(g, x+i, y+i, width-i-i, height-i-i);
 269             }
 270             g.setColor(oldColor);
 271         }
 272     }
 273 
 274     /**
 275      * A dashed border that paints itself in the complementary color
 276      * of the component's background color.
 277      */
 278     @SuppressWarnings("serial") // Superclass is not serializable across versions
 279     static class ComplementDashedBorder extends LineBorder implements UIResource {
 280         private Color origColor;
 281         private Color paintColor;
 282 
 283         public ComplementDashedBorder() {
 284             super(null);
 285         }
 286 
 287         public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
 288             Color color = c.getBackground();
 289 
 290             if (origColor != color) {
 291                 origColor = color;
 292                 paintColor = new Color(~origColor.getRGB());
 293             }
 294 
 295             g.setColor(paintColor);
 296             BasicGraphicsUtils.drawDashedRect(g, x, y, width, height);
 297         }
 298     }
 299 
 300     /**
 301      * This class is an implementation of the InternalFrameLine border.
 302      * @since 1.4
 303      */
 304     @SuppressWarnings("serial") // Superclass is not serializable across versions
 305     public static class InternalFrameLineBorder extends LineBorder implements
 306             UIResource {
 307         protected Color activeColor;
 308         protected Color inactiveColor;
 309 
 310         public InternalFrameLineBorder(Color activeBorderColor,
 311                                        Color inactiveBorderColor,
 312                                        int thickness) {
 313             super(activeBorderColor, thickness);
 314             activeColor = activeBorderColor;
 315             inactiveColor = inactiveBorderColor;
 316         }
 317 
 318         public void paintBorder(Component c, Graphics g, int x, int y,
 319                 int width, int height) {
 320 
 321             JInternalFrame jif = null;
 322             if (c instanceof JInternalFrame) {
 323                 jif = (JInternalFrame)c;
 324             } else if (c instanceof JInternalFrame.JDesktopIcon) {