001: /*
002: * Copyright 2002-2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025: package com.sun.java.swing.plaf.gtk;
026:
027: import javax.swing.*;
028: import javax.swing.plaf.synth.*;
029: import java.awt.Color;
030: import java.awt.Graphics;
031: import java.awt.Rectangle;
032:
033: /**
034: * @version 1.25, 05/05/07
035: * @author Joshua Outwater
036: */
037: class GTKGraphicsUtils extends SynthGraphicsUtils {
038: public void paintText(SynthContext context, Graphics g,
039: String text, int x, int y, int mnemonicIndex) {
040: if (text == null || text.length() <= 0) {
041: // We don't need to paint empty strings
042: return;
043: }
044:
045: if (context.getRegion() == Region.INTERNAL_FRAME_TITLE_PANE) {
046: // Metacity handles painting of text on internal frame title,
047: // ignore this.
048: return;
049: }
050: int componentState = context.getComponentState();
051: if ((componentState & SynthConstants.DISABLED) == SynthConstants.DISABLED) {
052: Color orgColor = g.getColor();
053: g.setColor(context.getStyle().getColor(context,
054: GTKColorType.WHITE));
055: x += 1;
056: y += 1;
057: super .paintText(context, g, text, x, y, mnemonicIndex);
058:
059: g.setColor(orgColor);
060: x -= 1;
061: y -= 1;
062: super .paintText(context, g, text, x, y, mnemonicIndex);
063: } else {
064: String themeName = GTKLookAndFeel.getGtkThemeName();
065: if (themeName != null
066: && themeName.startsWith("blueprint")
067: && shouldShadowText(context.getRegion(),
068: componentState)) {
069:
070: g.setColor(Color.BLACK);
071: super .paintText(context, g, text, x + 1, y + 1,
072: mnemonicIndex);
073: g.setColor(Color.WHITE);
074: }
075:
076: super .paintText(context, g, text, x, y, mnemonicIndex);
077: }
078: }
079:
080: /**
081: * Paints text at the specified location. This will not attempt to
082: * render the text as html nor will it offset by the insets of the
083: * component.
084: *
085: * @param ss SynthContext
086: * @param g Graphics used to render string in.
087: * @param text Text to render
088: * @param bounds Bounds of the text to be drawn.
089: * @param mnemonicIndex Index to draw string at.
090: */
091: public void paintText(SynthContext context, Graphics g,
092: String text, Rectangle bounds, int mnemonicIndex) {
093: if (text == null || text.length() <= 0) {
094: // We don't need to paint empty strings
095: return;
096: }
097:
098: Region id = context.getRegion();
099: if ((id == Region.RADIO_BUTTON || id == Region.CHECK_BOX || id == Region.TABBED_PANE_TAB)
100: && (context.getComponentState() & SynthConstants.FOCUSED) != 0) {
101: JComponent source = context.getComponent();
102: if (!(source instanceof AbstractButton)
103: || ((AbstractButton) source).isFocusPainted()) {
104:
105: // The "bounds" parameter encompasses only the actual text;
106: // when drawing the focus, we need to expand that bounding
107: // box by "focus-line-width" plus "focus-padding". Note that
108: // the layout process for these components will have already
109: // taken these values into account, so there should always
110: // be enough space allocated for drawing the focus indicator.
111: int synthState = context.getComponentState();
112: GTKStyle style = (GTKStyle) context.getStyle();
113: int focusSize = style.getClassSpecificIntValue(context,
114: "focus-line-width", 1);
115: int focusPad = style.getClassSpecificIntValue(context,
116: "focus-padding", 1);
117: int totalFocus = focusSize + focusPad;
118: int x = bounds.x - totalFocus;
119: int y = bounds.y - totalFocus;
120: int w = bounds.width + (2 * totalFocus);
121: int h = bounds.height + (2 * totalFocus);
122:
123: Color color = g.getColor();
124: GTKPainter.INSTANCE.paintFocus(context, g, id,
125: synthState, "checkbutton", x, y, w, h);
126: g.setColor(color);
127: }
128: }
129: super .paintText(context, g, text, bounds, mnemonicIndex);
130: }
131:
132: private static boolean shouldShadowText(Region id, int state) {
133: int gtkState = GTKLookAndFeel.synthStateToGTKState(id, state);
134: return ((gtkState == SynthConstants.MOUSE_OVER) && (id == Region.MENU
135: || id == Region.MENU_ITEM
136: || id == Region.CHECK_BOX_MENU_ITEM || id == Region.RADIO_BUTTON_MENU_ITEM));
137: }
138: }
|