< prev index next >

src/java.desktop/share/classes/com/sun/java/swing/plaf/windows/WindowsGraphicsUtils.java

Print this page




  76         }
  77     }
  78 
  79     static void paintClassicText(AbstractButton b, Graphics g, int x, int y,
  80                                  String text, int mnemIndex) {
  81         ButtonModel model = b.getModel();
  82 
  83         /* Draw the Text */
  84         Color color = b.getForeground();
  85         if(model.isEnabled()) {
  86             /*** paint the text normally */
  87             if(!(b instanceof JMenuItem && model.isArmed())
  88                 && !(b instanceof JMenu && (model.isSelected() || model.isRollover()))) {
  89                 /* We shall not set foreground color for selected menu or
  90                  * armed menuitem. Foreground must be set in appropriate
  91                  * Windows* class because these colors passes from
  92                  * BasicMenuItemUI as protected fields and we can't
  93                  * reach them from this class */
  94                 g.setColor(b.getForeground());
  95             }
  96             SwingUtilities2.drawStringUnderlineCharAt(b, g,text, mnemIndex, x, y);

  97         } else {        /*** paint the text disabled ***/
  98             color = getDisabledTextColor(b);
  99             if (color == null) {
 100                 color = UIManager.getColor("Button.shadow");
 101             }
 102             Color shadow = UIManager.getColor("Button.disabledShadow");
 103             if(model.isArmed()) {
 104                 color = UIManager.getColor("Button.disabledForeground");
 105             } else {
 106                 if (shadow == null) {
 107                     shadow = b.getBackground().darker();
 108                 }
 109                 g.setColor(shadow);
 110                 SwingUtilities2.drawStringUnderlineCharAt(b, g, text, mnemIndex,
 111                                                           x + 1, y + 1);
 112             }
 113             if (color == null) {
 114                 color = b.getBackground().brighter();
 115             }
 116             g.setColor(color);
 117             SwingUtilities2.drawStringUnderlineCharAt(b, g, text, mnemIndex, x, y);
 118         }
 119     }
 120 
 121     private static Color getDisabledTextColor(AbstractButton b) {
 122         if (b instanceof JCheckBox) {
 123             return UIManager.getColor("CheckBox.disabledText");
 124         } else if (b instanceof JRadioButton) {
 125             return UIManager.getColor("RadioButton.disabledText");
 126         } else if (b instanceof JToggleButton) {
 127             return  UIManager.getColor("ToggleButton.disabledText");
 128         } else if (b instanceof JButton) {
 129             return UIManager.getColor("Button.disabledText");
 130         }
 131         return null;
 132     }
 133 
 134     static void paintXPText(AbstractButton b, Graphics g, int x, int y,
 135                             String text, int mnemIndex) {
 136         Part part = WindowsButtonUI.getXPButtonType(b);
 137         State state = WindowsButtonUI.getXPButtonState(b);


 159             // same as the enabled color
 160             if (part == Part.TP_BUTTON && state == State.DISABLED) {
 161                 Color enabledColor = xp.getColor(b, part, State.NORMAL,
 162                                      Prop.TEXTCOLOR, b.getForeground());
 163                 if(textColor.equals(enabledColor)) {
 164                     textColor = xp.getColor(b, Part.BP_PUSHBUTTON, state,
 165                                 Prop.TEXTCOLOR, textColor);
 166                 }
 167             }
 168             // only draw shadow if developer hasn't changed the foreground color
 169             // and if the current style has text shadows.
 170             TypeEnum shadowType = xp.getTypeEnum(b, part,
 171                                                  state, Prop.TEXTSHADOWTYPE);
 172             if (shadowType == TypeEnum.TST_SINGLE ||
 173                         shadowType == TypeEnum.TST_CONTINUOUS) {
 174                 Color shadowColor = xp.getColor(b, part, state,
 175                                                 Prop.TEXTSHADOWCOLOR, Color.black);
 176                 Point offset = xp.getPoint(b, part, state, Prop.TEXTSHADOWOFFSET);
 177                 if (offset != null) {
 178                     g.setColor(shadowColor);
 179                     SwingUtilities2.drawStringUnderlineCharAt(b, g, text, mnemIndex,
 180                                                               x + offset.x,
 181                                                               y + offset.y);
 182                 }
 183             }
 184         }
 185 
 186         g.setColor(textColor);
 187         SwingUtilities2.drawStringUnderlineCharAt(b, g, text, mnemIndex, x, y);
 188     }
 189 
 190     static boolean isLeftToRight(Component c) {
 191         return c.getComponentOrientation().isLeftToRight();
 192     }
 193 
 194     /*
 195      * Repaints all the components with the mnemonics in the given window and
 196      * all its owned windows.
 197      */
 198     static void repaintMnemonicsInWindow(Window w) {
 199         if(w == null || !w.isShowing()) {
 200             return;
 201         }
 202 
 203         Window[] ownedWindows = w.getOwnedWindows();
 204         for(int i=0;i<ownedWindows.length;i++) {
 205             repaintMnemonicsInWindow(ownedWindows[i]);
 206         }
 207 




  76         }
  77     }
  78 
  79     static void paintClassicText(AbstractButton b, Graphics g, int x, int y,
  80                                  String text, int mnemIndex) {
  81         ButtonModel model = b.getModel();
  82 
  83         /* Draw the Text */
  84         Color color = b.getForeground();
  85         if(model.isEnabled()) {
  86             /*** paint the text normally */
  87             if(!(b instanceof JMenuItem && model.isArmed())
  88                 && !(b instanceof JMenu && (model.isSelected() || model.isRollover()))) {
  89                 /* We shall not set foreground color for selected menu or
  90                  * armed menuitem. Foreground must be set in appropriate
  91                  * Windows* class because these colors passes from
  92                  * BasicMenuItemUI as protected fields and we can't
  93                  * reach them from this class */
  94                 g.setColor(b.getForeground());
  95             }
  96             SwingUtilities2.getTextUIDrawing(b)
  97                     .drawStringUnderlineCharAt(b, g,text, mnemIndex, x, y);
  98         } else {        /*** paint the text disabled ***/
  99             color = getDisabledTextColor(b);
 100             if (color == null) {
 101                 color = UIManager.getColor("Button.shadow");
 102             }
 103             Color shadow = UIManager.getColor("Button.disabledShadow");
 104             if(model.isArmed()) {
 105                 color = UIManager.getColor("Button.disabledForeground");
 106             } else {
 107                 if (shadow == null) {
 108                     shadow = b.getBackground().darker();
 109                 }
 110                 g.setColor(shadow);
 111                 SwingUtilities2.getTextUIDrawing(b).drawStringUnderlineCharAt(b, g, text, mnemIndex,
 112                                                           x + 1, y + 1);
 113             }
 114             if (color == null) {
 115                 color = b.getBackground().brighter();
 116             }
 117             g.setColor(color);
 118             SwingUtilities2.getTextUIDrawing(b).drawStringUnderlineCharAt(b, g, text, mnemIndex, x, y);
 119         }
 120     }
 121 
 122     private static Color getDisabledTextColor(AbstractButton b) {
 123         if (b instanceof JCheckBox) {
 124             return UIManager.getColor("CheckBox.disabledText");
 125         } else if (b instanceof JRadioButton) {
 126             return UIManager.getColor("RadioButton.disabledText");
 127         } else if (b instanceof JToggleButton) {
 128             return  UIManager.getColor("ToggleButton.disabledText");
 129         } else if (b instanceof JButton) {
 130             return UIManager.getColor("Button.disabledText");
 131         }
 132         return null;
 133     }
 134 
 135     static void paintXPText(AbstractButton b, Graphics g, int x, int y,
 136                             String text, int mnemIndex) {
 137         Part part = WindowsButtonUI.getXPButtonType(b);
 138         State state = WindowsButtonUI.getXPButtonState(b);


 160             // same as the enabled color
 161             if (part == Part.TP_BUTTON && state == State.DISABLED) {
 162                 Color enabledColor = xp.getColor(b, part, State.NORMAL,
 163                                      Prop.TEXTCOLOR, b.getForeground());
 164                 if(textColor.equals(enabledColor)) {
 165                     textColor = xp.getColor(b, Part.BP_PUSHBUTTON, state,
 166                                 Prop.TEXTCOLOR, textColor);
 167                 }
 168             }
 169             // only draw shadow if developer hasn't changed the foreground color
 170             // and if the current style has text shadows.
 171             TypeEnum shadowType = xp.getTypeEnum(b, part,
 172                                                  state, Prop.TEXTSHADOWTYPE);
 173             if (shadowType == TypeEnum.TST_SINGLE ||
 174                         shadowType == TypeEnum.TST_CONTINUOUS) {
 175                 Color shadowColor = xp.getColor(b, part, state,
 176                                                 Prop.TEXTSHADOWCOLOR, Color.black);
 177                 Point offset = xp.getPoint(b, part, state, Prop.TEXTSHADOWOFFSET);
 178                 if (offset != null) {
 179                     g.setColor(shadowColor);
 180                     SwingUtilities2.getTextUIDrawing(b).drawStringUnderlineCharAt(b, g, text, mnemIndex,
 181                                                               x + offset.x,
 182                                                               y + offset.y);
 183                 }
 184             }
 185         }
 186 
 187         g.setColor(textColor);
 188         SwingUtilities2.getTextUIDrawing(b).drawStringUnderlineCharAt(b, g, text, mnemIndex, x, y);
 189     }
 190 
 191     static boolean isLeftToRight(Component c) {
 192         return c.getComponentOrientation().isLeftToRight();
 193     }
 194 
 195     /*
 196      * Repaints all the components with the mnemonics in the given window and
 197      * all its owned windows.
 198      */
 199     static void repaintMnemonicsInWindow(Window w) {
 200         if(w == null || !w.isShowing()) {
 201             return;
 202         }
 203 
 204         Window[] ownedWindows = w.getOwnedWindows();
 205         for(int i=0;i<ownedWindows.length;i++) {
 206             repaintMnemonicsInWindow(ownedWindows[i]);
 207         }
 208 


< prev index next >