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

Print this page


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


 288                     if (getBoolean(c, part, null, Prop.BORDERONLY)) {
 289                         border = new XPImageBorder(c, part);
 290                     } else if (part == Part.CP_COMBOBOX) {
 291                         border = new EmptyBorder(1, 1, 1, 1);
 292                     } else {
 293                         if(part == Part.TP_BUTTON) {
 294                             border = new XPEmptyBorder(new Insets(3,3,3,3));
 295                         } else {
 296                             border = new XPEmptyBorder(m);
 297                         }
 298                     }
 299                 }
 300             }
 301             if (border != null) {
 302                 borderMap.put(skin.string, border);
 303             }
 304         }
 305         return border;
 306     }
 307 

 308     private class XPFillBorder extends LineBorder implements UIResource {
 309         XPFillBorder(Color color, int thickness) {
 310             super(color, thickness);
 311         }
 312 
 313         public Insets getBorderInsets(Component c, Insets insets)       {
 314             Insets margin = null;
 315             //
 316             // Ideally we'd have an interface defined for classes which
 317             // support margins (to avoid this hackery), but we've
 318             // decided against it for simplicity
 319             //
 320            if (c instanceof AbstractButton) {
 321                margin = ((AbstractButton)c).getMargin();
 322            } else if (c instanceof JToolBar) {
 323                margin = ((JToolBar)c).getMargin();
 324            } else if (c instanceof JTextComponent) {
 325                margin = ((JTextComponent)c).getMargin();
 326            }
 327            insets.top    = (margin != null? margin.top : 0)    + thickness;
 328            insets.left   = (margin != null? margin.left : 0)   + thickness;
 329            insets.bottom = (margin != null? margin.bottom : 0) + thickness;
 330            insets.right =  (margin != null? margin.right : 0)  + thickness;
 331 
 332            return insets;
 333         }
 334     }
 335 

 336     private class XPStatefulFillBorder extends XPFillBorder {
 337         private final Part part;
 338         private final Prop prop;
 339         XPStatefulFillBorder(Color color, int thickness, Part part, Prop prop) {
 340             super(color, thickness);
 341             this.part = part;
 342             this.prop = prop;
 343         }
 344 
 345         public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
 346             State state = State.NORMAL;
 347             // special casing for comboboxes.
 348             // there may be more special cases in the future
 349             if(c instanceof JComboBox) {
 350                 JComboBox cb = (JComboBox)c;
 351                 // note. in the future this should be replaced with a call
 352                 // to BasicLookAndFeel.getUIOfType()
 353                 if(cb.getUI() instanceof WindowsComboBoxUI) {
 354                     WindowsComboBoxUI wcb = (WindowsComboBoxUI)cb.getUI();
 355                     state = wcb.getXPComboBoxState(cb);
 356                 }
 357             }
 358             lineColor = getColor(c, part, state, prop, Color.black);
 359             super.paintBorder(c, g, x, y, width, height);
 360         }
 361     }
 362 

 363     private class XPImageBorder extends AbstractBorder implements UIResource {
 364         Skin skin;
 365 
 366         XPImageBorder(Component c, Part part) {
 367             this.skin = getSkin(c, part);
 368         }
 369 
 370         public void paintBorder(Component c, Graphics g,
 371                                 int x, int y, int width, int height) {
 372             skin.paintSkin(g, x, y, width, height, null);
 373         }
 374 
 375         public Insets getBorderInsets(Component c, Insets insets)       {
 376             Insets margin = null;
 377             Insets borderInsets = skin.getContentMargin();
 378             if(borderInsets == null) {
 379                 borderInsets = new Insets(0, 0, 0, 0);
 380             }
 381             //
 382             // Ideally we'd have an interface defined for classes which
 383             // support margins (to avoid this hackery), but we've
 384             // decided against it for simplicity
 385             //
 386            if (c instanceof AbstractButton) {
 387                margin = ((AbstractButton)c).getMargin();
 388            } else if (c instanceof JToolBar) {
 389                margin = ((JToolBar)c).getMargin();
 390            } else if (c instanceof JTextComponent) {
 391                margin = ((JTextComponent)c).getMargin();
 392            }
 393            insets.top    = (margin != null? margin.top : 0)    + borderInsets.top;
 394            insets.left   = (margin != null? margin.left : 0)   + borderInsets.left;
 395            insets.bottom = (margin != null? margin.bottom : 0) + borderInsets.bottom;
 396            insets.right  = (margin != null? margin.right : 0)  + borderInsets.right;
 397 
 398            return insets;
 399         }
 400     }
 401 

 402     private class XPEmptyBorder extends EmptyBorder implements UIResource {
 403         XPEmptyBorder(Insets m) {
 404             super(m.top+2, m.left+2, m.bottom+2, m.right+2);
 405         }
 406 
 407         public Insets getBorderInsets(Component c, Insets insets)       {
 408             insets = super.getBorderInsets(c, insets);
 409 
 410             Insets margin = null;
 411             if (c instanceof AbstractButton) {
 412                 Insets m = ((AbstractButton)c).getMargin();
 413                 // if this is a toolbar button then ignore getMargin()
 414                 // and subtract the padding added by the constructor
 415                 if(c.getParent() instanceof JToolBar
 416                    && ! (c instanceof JRadioButton)
 417                    && ! (c instanceof JCheckBox)
 418                    && m instanceof InsetsUIResource) {
 419                     insets.top -= 2;
 420                     insets.left -= 2;
 421                     insets.bottom -= 2;


 657             }
 658             BufferedImage bi = (BufferedImage)image;
 659 
 660             WritableRaster raster = bi.getRaster();
 661             DataBufferInt dbi = (DataBufferInt)raster.getDataBuffer();
 662             // Note that stealData() requires a markDirty() afterwards
 663             // since we modify the data in it.
 664             ThemeReader.paintBackground(SunWritableRaster.stealData(dbi, 0),
 665                                         part.getControlName(c), part.getValue(),
 666                                         State.getValue(part, state),
 667                                         0, 0, w, h, w);
 668             SunWritableRaster.markDirty(dbi);
 669         }
 670 
 671         protected Image createImage(Component c, int w, int h,
 672                                     GraphicsConfiguration config, Object[] args) {
 673             return new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
 674         }
 675     }
 676 

 677     static class GlyphButton extends JButton {
 678         private Skin skin;
 679 
 680         public GlyphButton(Component parent, Part part) {
 681             XPStyle xp = getXP();
 682             skin = xp.getSkin(parent, part);
 683             setBorder(null);
 684             setContentAreaFilled(false);
 685             setMinimumSize(new Dimension(5, 5));
 686             setPreferredSize(new Dimension(16, 16));
 687             setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
 688         }
 689 
 690         public boolean isFocusTraversable() {
 691             return false;
 692         }
 693 
 694         protected State getState() {
 695             State state = State.NORMAL;
 696             if (!isEnabled()) {


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


 288                     if (getBoolean(c, part, null, Prop.BORDERONLY)) {
 289                         border = new XPImageBorder(c, part);
 290                     } else if (part == Part.CP_COMBOBOX) {
 291                         border = new EmptyBorder(1, 1, 1, 1);
 292                     } else {
 293                         if(part == Part.TP_BUTTON) {
 294                             border = new XPEmptyBorder(new Insets(3,3,3,3));
 295                         } else {
 296                             border = new XPEmptyBorder(m);
 297                         }
 298                     }
 299                 }
 300             }
 301             if (border != null) {
 302                 borderMap.put(skin.string, border);
 303             }
 304         }
 305         return border;
 306     }
 307 
 308     @SuppressWarnings("serial") // Superclass is not serializable across versions
 309     private class XPFillBorder extends LineBorder implements UIResource {
 310         XPFillBorder(Color color, int thickness) {
 311             super(color, thickness);
 312         }
 313 
 314         public Insets getBorderInsets(Component c, Insets insets)       {
 315             Insets margin = null;
 316             //
 317             // Ideally we'd have an interface defined for classes which
 318             // support margins (to avoid this hackery), but we've
 319             // decided against it for simplicity
 320             //
 321            if (c instanceof AbstractButton) {
 322                margin = ((AbstractButton)c).getMargin();
 323            } else if (c instanceof JToolBar) {
 324                margin = ((JToolBar)c).getMargin();
 325            } else if (c instanceof JTextComponent) {
 326                margin = ((JTextComponent)c).getMargin();
 327            }
 328            insets.top    = (margin != null? margin.top : 0)    + thickness;
 329            insets.left   = (margin != null? margin.left : 0)   + thickness;
 330            insets.bottom = (margin != null? margin.bottom : 0) + thickness;
 331            insets.right =  (margin != null? margin.right : 0)  + thickness;
 332 
 333            return insets;
 334         }
 335     }
 336 
 337     @SuppressWarnings("serial") // Superclass is not serializable across versions
 338     private class XPStatefulFillBorder extends XPFillBorder {
 339         private final Part part;
 340         private final Prop prop;
 341         XPStatefulFillBorder(Color color, int thickness, Part part, Prop prop) {
 342             super(color, thickness);
 343             this.part = part;
 344             this.prop = prop;
 345         }
 346 
 347         public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
 348             State state = State.NORMAL;
 349             // special casing for comboboxes.
 350             // there may be more special cases in the future
 351             if(c instanceof JComboBox) {
 352                 JComboBox cb = (JComboBox)c;
 353                 // note. in the future this should be replaced with a call
 354                 // to BasicLookAndFeel.getUIOfType()
 355                 if(cb.getUI() instanceof WindowsComboBoxUI) {
 356                     WindowsComboBoxUI wcb = (WindowsComboBoxUI)cb.getUI();
 357                     state = wcb.getXPComboBoxState(cb);
 358                 }
 359             }
 360             lineColor = getColor(c, part, state, prop, Color.black);
 361             super.paintBorder(c, g, x, y, width, height);
 362         }
 363     }
 364 
 365     @SuppressWarnings("serial") // Superclass is not serializable across versions
 366     private class XPImageBorder extends AbstractBorder implements UIResource {
 367         Skin skin;
 368 
 369         XPImageBorder(Component c, Part part) {
 370             this.skin = getSkin(c, part);
 371         }
 372 
 373         public void paintBorder(Component c, Graphics g,
 374                                 int x, int y, int width, int height) {
 375             skin.paintSkin(g, x, y, width, height, null);
 376         }
 377 
 378         public Insets getBorderInsets(Component c, Insets insets)       {
 379             Insets margin = null;
 380             Insets borderInsets = skin.getContentMargin();
 381             if(borderInsets == null) {
 382                 borderInsets = new Insets(0, 0, 0, 0);
 383             }
 384             //
 385             // Ideally we'd have an interface defined for classes which
 386             // support margins (to avoid this hackery), but we've
 387             // decided against it for simplicity
 388             //
 389            if (c instanceof AbstractButton) {
 390                margin = ((AbstractButton)c).getMargin();
 391            } else if (c instanceof JToolBar) {
 392                margin = ((JToolBar)c).getMargin();
 393            } else if (c instanceof JTextComponent) {
 394                margin = ((JTextComponent)c).getMargin();
 395            }
 396            insets.top    = (margin != null? margin.top : 0)    + borderInsets.top;
 397            insets.left   = (margin != null? margin.left : 0)   + borderInsets.left;
 398            insets.bottom = (margin != null? margin.bottom : 0) + borderInsets.bottom;
 399            insets.right  = (margin != null? margin.right : 0)  + borderInsets.right;
 400 
 401            return insets;
 402         }
 403     }
 404 
 405     @SuppressWarnings("serial") // Superclass is not serializable across versions
 406     private class XPEmptyBorder extends EmptyBorder implements UIResource {
 407         XPEmptyBorder(Insets m) {
 408             super(m.top+2, m.left+2, m.bottom+2, m.right+2);
 409         }
 410 
 411         public Insets getBorderInsets(Component c, Insets insets)       {
 412             insets = super.getBorderInsets(c, insets);
 413 
 414             Insets margin = null;
 415             if (c instanceof AbstractButton) {
 416                 Insets m = ((AbstractButton)c).getMargin();
 417                 // if this is a toolbar button then ignore getMargin()
 418                 // and subtract the padding added by the constructor
 419                 if(c.getParent() instanceof JToolBar
 420                    && ! (c instanceof JRadioButton)
 421                    && ! (c instanceof JCheckBox)
 422                    && m instanceof InsetsUIResource) {
 423                     insets.top -= 2;
 424                     insets.left -= 2;
 425                     insets.bottom -= 2;


 661             }
 662             BufferedImage bi = (BufferedImage)image;
 663 
 664             WritableRaster raster = bi.getRaster();
 665             DataBufferInt dbi = (DataBufferInt)raster.getDataBuffer();
 666             // Note that stealData() requires a markDirty() afterwards
 667             // since we modify the data in it.
 668             ThemeReader.paintBackground(SunWritableRaster.stealData(dbi, 0),
 669                                         part.getControlName(c), part.getValue(),
 670                                         State.getValue(part, state),
 671                                         0, 0, w, h, w);
 672             SunWritableRaster.markDirty(dbi);
 673         }
 674 
 675         protected Image createImage(Component c, int w, int h,
 676                                     GraphicsConfiguration config, Object[] args) {
 677             return new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
 678         }
 679     }
 680 
 681     @SuppressWarnings("serial") // Superclass is not serializable across versions
 682     static class GlyphButton extends JButton {
 683         private Skin skin;
 684 
 685         public GlyphButton(Component parent, Part part) {
 686             XPStyle xp = getXP();
 687             skin = xp.getSkin(parent, part);
 688             setBorder(null);
 689             setContentAreaFilled(false);
 690             setMinimumSize(new Dimension(5, 5));
 691             setPreferredSize(new Dimension(16, 16));
 692             setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
 693         }
 694 
 695         public boolean isFocusTraversable() {
 696             return false;
 697         }
 698 
 699         protected State getState() {
 700             State state = State.NORMAL;
 701             if (!isEnabled()) {