src/share/classes/com/sun/java/swing/plaf/motif/MotifIconFactory.java

Print this page


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


  33 import java.awt.Component;
  34 import java.awt.Dimension;
  35 import java.awt.Graphics;
  36 import java.awt.Polygon;
  37 
  38 import java.io.Serializable;
  39 
  40 /**
  41  * Icon factory for the CDE/Motif Look and Feel
  42  * <p>
  43  * <strong>Warning:</strong>
  44  * Serialized objects of this class will not be compatible with
  45  * future Swing releases.  The current serialization support is appropriate
  46  * for short term storage or RMI between applications running the same
  47  * version of Swing.  A future release of Swing will provide support for
  48  * long term persistence.
  49  *
  50  * 1.20 04/27/99
  51  * @author Georges Saab
  52  */

  53 public class MotifIconFactory implements Serializable
  54 {
  55     private static Icon checkBoxIcon;
  56     private static Icon radioButtonIcon;
  57     private static Icon menuItemCheckIcon;
  58     private static Icon menuItemArrowIcon;
  59     private static Icon menuArrowIcon;
  60 
  61     public static Icon getMenuItemCheckIcon() {
  62         return null;
  63     }
  64 
  65     public static Icon getMenuItemArrowIcon() {
  66         if (menuItemArrowIcon == null) {
  67             menuItemArrowIcon = new MenuItemArrowIcon();
  68         }
  69         return menuItemArrowIcon;
  70     }
  71 
  72     public static Icon getMenuArrowIcon() {
  73         if (menuArrowIcon == null) {
  74             menuArrowIcon = new MenuArrowIcon();
  75         }
  76         return menuArrowIcon;
  77     }
  78 
  79     public static Icon getCheckBoxIcon() {
  80         if (checkBoxIcon == null) {
  81             checkBoxIcon = new CheckBoxIcon();
  82         }
  83         return checkBoxIcon;
  84     }
  85 
  86     public static Icon getRadioButtonIcon() {
  87         if (radioButtonIcon == null) {
  88             radioButtonIcon = new RadioButtonIcon();
  89         }
  90         return radioButtonIcon;
  91     }
  92 

  93     private static class CheckBoxIcon implements Icon, UIResource, Serializable  {
  94         final static int csize = 13;
  95 
  96         private Color control = UIManager.getColor("control");
  97         private Color foreground = UIManager.getColor("CheckBox.foreground");
  98         private Color shadow = UIManager.getColor("controlShadow");
  99         private Color highlight = UIManager.getColor("controlHighlight");
 100         private Color lightShadow = UIManager.getColor("controlLightShadow");
 101 
 102         public void paintIcon(Component c, Graphics g, int x, int y) {
 103             AbstractButton b = (AbstractButton) c;
 104             ButtonModel model = b.getModel();
 105 
 106             boolean flat = false;
 107 
 108             if(b instanceof JCheckBox) {
 109                 flat = ((JCheckBox)b).isBorderPaintedFlat();
 110             }
 111 
 112             boolean isPressed = model.isPressed();


 247                 if (check) {
 248                     // draw check
 249                     g.setColor(foreground);
 250                     g.drawLine(csize-2,1,csize-2,2);
 251                     g.drawLine(csize-3,2,csize-3,3);
 252                     g.drawLine(csize-4,3,csize-4,4);
 253                     g.drawLine(csize-5,4,csize-5,6);
 254                     g.drawLine(csize-6,5,csize-6,8);
 255                     g.drawLine(csize-7,6,csize-7,10);
 256                     g.drawLine(csize-8,7,csize-8,10);
 257                     g.drawLine(csize-9,6,csize-9,9);
 258                     g.drawLine(csize-10,5,csize-10,8);
 259                     g.drawLine(csize-11,5,csize-11,7);
 260                     g.drawLine(csize-12,6,csize-12,6);
 261                 }
 262                 g.translate(-x, -y);
 263                 g.setColor(oldColor);
 264             }
 265     } // end class CheckBoxIcon
 266 

 267     private static class RadioButtonIcon implements Icon, UIResource, Serializable {
 268         private Color dot = UIManager.getColor("activeCaptionBorder");
 269         private Color highlight = UIManager.getColor("controlHighlight");
 270         private Color shadow = UIManager.getColor("controlShadow");
 271 
 272         public void paintIcon(Component c, Graphics g, int x, int y) {
 273             // fill interior
 274             AbstractButton b = (AbstractButton) c;
 275             ButtonModel model = b.getModel();
 276 
 277             int w = getIconWidth();
 278             int h = getIconHeight();
 279 
 280             boolean isPressed = model.isPressed();
 281             boolean isArmed = model.isArmed();
 282             boolean isEnabled = model.isEnabled();
 283             boolean isSelected = model.isSelected();
 284 
 285             boolean checkIn = ((isPressed &&
 286                                 !isArmed   &&


 338                 g.drawLine(x+9,y+12,x+10,y+12);
 339                 g.drawLine(x+11,y+11,x+11,y+11);
 340                 g.drawLine(x+12,y+10,x+12,y+10);
 341                 g.drawLine(x+13,y+9,x+13,y+4);
 342                 g.drawLine(x+12,y+3,x+12,y+3);
 343                 g.drawLine(x+11,y+2,x+11,y+2);
 344                 g.drawLine(x+10,y+1,x+10,y+1);
 345 
 346             }
 347         }
 348 
 349         public int getIconWidth() {
 350             return 14;
 351         }
 352 
 353         public int getIconHeight() {
 354             return 14;
 355         }
 356     } // end class RadioButtonIcon
 357 

 358     private static class MenuItemCheckIcon implements Icon, UIResource, Serializable
 359     {
 360         public void paintIcon(Component c,Graphics g, int x, int y)
 361             {
 362             }
 363         public int getIconWidth() { return 0; }
 364         public int getIconHeight() { return 0; }
 365     }  // end class MenuItemCheckIcon
 366 
 367 

 368     private static class MenuItemArrowIcon implements Icon, UIResource, Serializable
 369     {
 370         public void paintIcon(Component c,Graphics g, int x, int y)
 371             {
 372             }
 373         public int getIconWidth() { return 0; }
 374         public int getIconHeight() { return 0; }
 375     }  // end class MenuItemArrowIcon
 376 

 377     private static class MenuArrowIcon implements Icon, UIResource, Serializable
 378     {
 379         private Color focus = UIManager.getColor("windowBorder");
 380         private Color shadow = UIManager.getColor("controlShadow");
 381         private Color highlight = UIManager.getColor("controlHighlight");
 382 
 383         public void paintIcon(Component c, Graphics g, int x, int y) {
 384             AbstractButton b = (AbstractButton) c;
 385             ButtonModel model = b.getModel();
 386 
 387             // These variables are kind of pointless as the following code
 388             // assumes the icon will be 10 x 10 regardless of their value.
 389             int w = getIconWidth();
 390             int h = getIconHeight();
 391 
 392             Color oldColor = g.getColor();
 393 
 394             if (model.isSelected()){
 395                 if( MotifGraphicsUtils.isLeftToRight(c) ){
 396                     g.setColor(shadow);


   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


  33 import java.awt.Component;
  34 import java.awt.Dimension;
  35 import java.awt.Graphics;
  36 import java.awt.Polygon;
  37 
  38 import java.io.Serializable;
  39 
  40 /**
  41  * Icon factory for the CDE/Motif Look and Feel
  42  * <p>
  43  * <strong>Warning:</strong>
  44  * Serialized objects of this class will not be compatible with
  45  * future Swing releases.  The current serialization support is appropriate
  46  * for short term storage or RMI between applications running the same
  47  * version of Swing.  A future release of Swing will provide support for
  48  * long term persistence.
  49  *
  50  * 1.20 04/27/99
  51  * @author Georges Saab
  52  */
  53 @SuppressWarnings("serial") // Same-version serialization only
  54 public class MotifIconFactory implements Serializable
  55 {
  56     private static Icon checkBoxIcon;
  57     private static Icon radioButtonIcon;
  58     private static Icon menuItemCheckIcon;
  59     private static Icon menuItemArrowIcon;
  60     private static Icon menuArrowIcon;
  61 
  62     public static Icon getMenuItemCheckIcon() {
  63         return null;
  64     }
  65 
  66     public static Icon getMenuItemArrowIcon() {
  67         if (menuItemArrowIcon == null) {
  68             menuItemArrowIcon = new MenuItemArrowIcon();
  69         }
  70         return menuItemArrowIcon;
  71     }
  72 
  73     public static Icon getMenuArrowIcon() {
  74         if (menuArrowIcon == null) {
  75             menuArrowIcon = new MenuArrowIcon();
  76         }
  77         return menuArrowIcon;
  78     }
  79 
  80     public static Icon getCheckBoxIcon() {
  81         if (checkBoxIcon == null) {
  82             checkBoxIcon = new CheckBoxIcon();
  83         }
  84         return checkBoxIcon;
  85     }
  86 
  87     public static Icon getRadioButtonIcon() {
  88         if (radioButtonIcon == null) {
  89             radioButtonIcon = new RadioButtonIcon();
  90         }
  91         return radioButtonIcon;
  92     }
  93 
  94     @SuppressWarnings("serial") // Same-version serialization only
  95     private static class CheckBoxIcon implements Icon, UIResource, Serializable  {
  96         final static int csize = 13;
  97 
  98         private Color control = UIManager.getColor("control");
  99         private Color foreground = UIManager.getColor("CheckBox.foreground");
 100         private Color shadow = UIManager.getColor("controlShadow");
 101         private Color highlight = UIManager.getColor("controlHighlight");
 102         private Color lightShadow = UIManager.getColor("controlLightShadow");
 103 
 104         public void paintIcon(Component c, Graphics g, int x, int y) {
 105             AbstractButton b = (AbstractButton) c;
 106             ButtonModel model = b.getModel();
 107 
 108             boolean flat = false;
 109 
 110             if(b instanceof JCheckBox) {
 111                 flat = ((JCheckBox)b).isBorderPaintedFlat();
 112             }
 113 
 114             boolean isPressed = model.isPressed();


 249                 if (check) {
 250                     // draw check
 251                     g.setColor(foreground);
 252                     g.drawLine(csize-2,1,csize-2,2);
 253                     g.drawLine(csize-3,2,csize-3,3);
 254                     g.drawLine(csize-4,3,csize-4,4);
 255                     g.drawLine(csize-5,4,csize-5,6);
 256                     g.drawLine(csize-6,5,csize-6,8);
 257                     g.drawLine(csize-7,6,csize-7,10);
 258                     g.drawLine(csize-8,7,csize-8,10);
 259                     g.drawLine(csize-9,6,csize-9,9);
 260                     g.drawLine(csize-10,5,csize-10,8);
 261                     g.drawLine(csize-11,5,csize-11,7);
 262                     g.drawLine(csize-12,6,csize-12,6);
 263                 }
 264                 g.translate(-x, -y);
 265                 g.setColor(oldColor);
 266             }
 267     } // end class CheckBoxIcon
 268 
 269     @SuppressWarnings("serial") // Same-version serialization only
 270     private static class RadioButtonIcon implements Icon, UIResource, Serializable {
 271         private Color dot = UIManager.getColor("activeCaptionBorder");
 272         private Color highlight = UIManager.getColor("controlHighlight");
 273         private Color shadow = UIManager.getColor("controlShadow");
 274 
 275         public void paintIcon(Component c, Graphics g, int x, int y) {
 276             // fill interior
 277             AbstractButton b = (AbstractButton) c;
 278             ButtonModel model = b.getModel();
 279 
 280             int w = getIconWidth();
 281             int h = getIconHeight();
 282 
 283             boolean isPressed = model.isPressed();
 284             boolean isArmed = model.isArmed();
 285             boolean isEnabled = model.isEnabled();
 286             boolean isSelected = model.isSelected();
 287 
 288             boolean checkIn = ((isPressed &&
 289                                 !isArmed   &&


 341                 g.drawLine(x+9,y+12,x+10,y+12);
 342                 g.drawLine(x+11,y+11,x+11,y+11);
 343                 g.drawLine(x+12,y+10,x+12,y+10);
 344                 g.drawLine(x+13,y+9,x+13,y+4);
 345                 g.drawLine(x+12,y+3,x+12,y+3);
 346                 g.drawLine(x+11,y+2,x+11,y+2);
 347                 g.drawLine(x+10,y+1,x+10,y+1);
 348 
 349             }
 350         }
 351 
 352         public int getIconWidth() {
 353             return 14;
 354         }
 355 
 356         public int getIconHeight() {
 357             return 14;
 358         }
 359     } // end class RadioButtonIcon
 360 
 361     @SuppressWarnings("serial") // Same-version serialization only
 362     private static class MenuItemCheckIcon implements Icon, UIResource, Serializable
 363     {
 364         public void paintIcon(Component c,Graphics g, int x, int y)
 365             {
 366             }
 367         public int getIconWidth() { return 0; }
 368         public int getIconHeight() { return 0; }
 369     }  // end class MenuItemCheckIcon
 370 
 371 
 372     @SuppressWarnings("serial") // Same-version serialization only
 373     private static class MenuItemArrowIcon implements Icon, UIResource, Serializable
 374     {
 375         public void paintIcon(Component c,Graphics g, int x, int y)
 376             {
 377             }
 378         public int getIconWidth() { return 0; }
 379         public int getIconHeight() { return 0; }
 380     }  // end class MenuItemArrowIcon
 381 
 382     @SuppressWarnings("serial") // Same-version serialization only
 383     private static class MenuArrowIcon implements Icon, UIResource, Serializable
 384     {
 385         private Color focus = UIManager.getColor("windowBorder");
 386         private Color shadow = UIManager.getColor("controlShadow");
 387         private Color highlight = UIManager.getColor("controlHighlight");
 388 
 389         public void paintIcon(Component c, Graphics g, int x, int y) {
 390             AbstractButton b = (AbstractButton) c;
 391             ButtonModel model = b.getModel();
 392 
 393             // These variables are kind of pointless as the following code
 394             // assumes the icon will be 10 x 10 regardless of their value.
 395             int w = getIconWidth();
 396             int h = getIconHeight();
 397 
 398             Color oldColor = g.getColor();
 399 
 400             if (model.isSelected()){
 401                 if( MotifGraphicsUtils.isLeftToRight(c) ){
 402                     g.setColor(shadow);