1 7 8 package com.sun.java.swing.plaf.windows; 9 10 import com.sun.java.swing.SwingUtilities2; 11 12 import java.awt.*; 13 14 import javax.swing.*; 15 16 import com.sun.java.swing.plaf.windows.TMSchema.*; 17 18 26 public class WindowsGraphicsUtils { 27 28 38 public static void paintText(Graphics g, AbstractButton b, 39 Rectangle textRect, String text, 40 int textShiftOffset) { 41 ButtonModel model = b.getModel(); 42 FontMetrics fm = SwingUtilities2.getFontMetrics(b, g); 43 44 int mnemIndex = b.getDisplayedMnemonicIndex(); 45 if (WindowsLookAndFeel.isMnemonicHidden() == true) { 47 mnemIndex = -1; 48 } 49 50 51 Color color = b.getForeground(); 52 if(model.isEnabled()) { 53 54 if(!(b instanceof JMenuItem && model.isArmed()) 55 && !(b instanceof JMenu && (model.isSelected() || model.isRollover()))) { 56 61 g.setColor(b.getForeground()); 62 } 63 SwingUtilities2.drawStringUnderlineCharAt(b, g,text, mnemIndex, 64 textRect.x + textShiftOffset, 65 textRect.y + fm.getAscent() + textShiftOffset); 66 } else { 67 color = UIManager.getColor("Button.disabledForeground"); 68 Color shadow = UIManager.getColor("Button.disabledShadow"); 69 70 XPStyle xp = XPStyle.getXP(); 71 if (xp != null) { 72 Part part = WindowsButtonUI.getXPButtonType(b); 73 color = xp.getColor(b, part, State.DISABLED, Prop.TEXTCOLOR, 74 color); 75 if (part == Part.TP_BUTTON) { 79 Color enabledColor = xp.getColor(b, part, State.NORMAL, 80 Prop.TEXTCOLOR, color); 81 if (color != null && color.equals(enabledColor)) { 82 color = xp.getColor(b, Part.TP_BUTTON, State.DISABLED, 83 Prop.TEXTCOLOR, color); 84 } 85 } 86 } else { 87 if (shadow == null) { 89 shadow = b.getBackground().darker(); 90 } 91 g.setColor(shadow); 92 SwingUtilities2.drawStringUnderlineCharAt(b, g,text, 93 mnemIndex, 94 textRect.x, 95 textRect.y + fm.getAscent()); 96 } 97 if (color == null) { 98 color = b.getBackground().brighter(); 99 } 100 g.setColor(color); 101 SwingUtilities2.drawStringUnderlineCharAt(b, g,text, 102 mnemIndex, 103 textRect.x - 1, 104 textRect.y + fm.getAscent() - 1); 105 } 106 } 107 108 static boolean isLeftToRight(Component c) { 109 return c.getComponentOrientation().isLeftToRight(); 110 } 111 } 112 113 | Popular Tags |