Debian Codegraph @

src/com/jidesoft/plaf/windows/WindowsGraphicsUtilsPort.java

raw
1 /*
2 * @(#)WindowsGraphicsUtilsPort.java 12/15/2017
3 *
4 * Copyright 2002 - 2017 JIDE Software Inc. All rights reserved.
5 */
6
7 package com.jidesoft.plaf.windows;
8
9 import com.jidesoft.swing.JideSwingUtilities;
10 import com.jidesoft.utils.SystemInfo;
11
12 import javax.swing.*;
13 import java.awt.*;
14
15 public class WindowsGraphicsUtilsPort {
16 /**
17 * Renders a text String in Windows without the mnemonic.
18 * This is here because the WindowsUI hierarchy doesn't match the Component hierarchy. All
19 * the overriden paintText methods of the ButtonUI delegates will call this static method.
20 *
21 * @param g Graphics context
22 * @param b Current button to render
23 * @param textRect Bounding rectangle to render the text.
24 * @param text String to render
25 */
26 public static void paintText(Graphics g, AbstractButton b,
27 Rectangle textRect, String text,
28 int textShiftOffset) {
29 FontMetrics fm = JideSwingUtilities.getFontMetrics(b, g);
30
31 int mnemIndex = b.getDisplayedMnemonicIndex();
32 // W2K Feature: Check to see if the Underscore should be rendered.
33 if (SystemInfo.isMnemonicHidden()) {
34 mnemIndex = -1;
35 }
36
37 paintClassicText(b, g, textRect.x + textShiftOffset,
38 textRect.y + fm.getAscent() + textShiftOffset,
39 text, mnemIndex);
40 }
41
42 static void paintClassicText(AbstractButton b, Graphics g, int x, int y,
43 String text, int mnemIndex) {
44 ButtonModel model = b.getModel();
45
46 /* Draw the Text */
47 Color color = b.getForeground();
48 if (model.isEnabled()) {
49 /*** paint the text normally */
50 if (!(b instanceof JMenuItem && model.isArmed())
51 && !(b instanceof JMenu && (model.isSelected() || model.isRollover()))) {
52 /* We shall not set foreground color for selected menu or
53 * armed menuitem. Foreground must be set in appropriate
54 * Windows* class because these colors passes from
55 * BasicMenuItemUI as protected fields and we can't
56 * reach them from this class */
57 g.setColor(b.getForeground());
58 }
59 JideSwingUtilities.drawStringUnderlineCharAt(b, g, text, mnemIndex, x, y);
60 }
61 else { /*** paint the text disabled ***/
62 color = getDisabledTextColor(b);
63 if (color == null) {
64 color = UIManager.getColor("Button.shadow");
65 }
66 Color shadow = UIManager.getColor("Button.disabledShadow");
67 if (model.isArmed()) {
68 color = UIManager.getColor("Button.disabledForeground");
69 }
70 else {
71 if (shadow == null) {
72 shadow = b.getBackground().darker();
73 }
74 g.setColor(shadow);
75 JideSwingUtilities.drawStringUnderlineCharAt(b, g, text, mnemIndex,
76 x + 1, y + 1);
77 }
78 if (color == null) {
79 color = b.getBackground().brighter();
80 }
81 g.setColor(color);
82 JideSwingUtilities.drawStringUnderlineCharAt(b, g, text, mnemIndex, x, y);
83 }
84 }
85
86 private static Color getDisabledTextColor(AbstractButton b) {
87 if (b instanceof JCheckBox) {
88 return UIManager.getColor("CheckBox.disabledText");
89 }
90 else if (b instanceof JRadioButton) {
91 return UIManager.getColor("RadioButton.disabledText");
92 }
93 else if (b instanceof JToggleButton) {
94 return UIManager.getColor("ToggleButton.disabledText");
95 }
96 else if (b instanceof JButton) {
97 return UIManager.getColor("Button.disabledText");
98 }
99 return null;
100 }
101
102 }