1 /* 2 * Copyright (c) 2002, 2018, 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 23 * questions. 24 */ 25 package com.sun.java.swing.plaf.gtk; 26 27 import javax.swing.*; 28 import javax.swing.plaf.synth.*; 29 import java.awt.Color; 30 import java.awt.Graphics; 31 import java.awt.Rectangle; 32 33 /** 34 * @author Joshua Outwater 35 */ 36 class GTKGraphicsUtils extends SynthGraphicsUtils { 37 public void paintText(SynthContext context, Graphics g, String text, 38 int x, int y, int mnemonicIndex) { 39 if (text == null || text.length() <= 0) { 40 // We don't need to paint empty strings 41 return; 42 } 43 44 if (context.getRegion() == Region.INTERNAL_FRAME_TITLE_PANE) { 45 // Metacity handles painting of text on internal frame title, 46 // ignore this. 47 return; 48 } 49 int componentState = context.getComponentState(); 50 String themeName = GTKLookAndFeel.getGtkThemeName(); 51 if (themeName != null && themeName.startsWith("blueprint") && 52 shouldShadowText(context.getRegion(), componentState)) { 53 54 g.setColor(Color.BLACK); 55 super.paintText(context, g, text, x+1, y+1, mnemonicIndex); 56 g.setColor(Color.WHITE); 57 } 58 super.paintText(context, g, text, x, y, mnemonicIndex); 59 } 60 61 /** 62 * Paints text at the specified location. This will not attempt to 63 * render the text as html nor will it offset by the insets of the 64 * component. 65 * 66 * @param ss SynthContext 67 * @param g Graphics used to render string in. 68 * @param text Text to render 69 * @param bounds Bounds of the text to be drawn. 70 * @param mnemonicIndex Index to draw string at. 71 */ 72 public void paintText(SynthContext context, Graphics g, String text, 73 Rectangle bounds, int mnemonicIndex) { 74 if (text == null || text.length() <= 0) { 75 // We don't need to paint empty strings 76 return; 77 } 78 79 Region id = context.getRegion(); 80 if ((id == Region.RADIO_BUTTON || 81 id == Region.CHECK_BOX || 82 id == Region.TABBED_PANE_TAB) && 83 (context.getComponentState() & SynthConstants.FOCUSED) != 0) 84 { 85 JComponent source = context.getComponent(); 86 if (!(source instanceof AbstractButton) || 87 ((AbstractButton)source).isFocusPainted()) { 88 89 // The "bounds" parameter encompasses only the actual text; 90 // when drawing the focus, we need to expand that bounding 91 // box by "focus-line-width" plus "focus-padding". Note that 92 // the layout process for these components will have already 93 // taken these values into account, so there should always 94 // be enough space allocated for drawing the focus indicator. 95 int synthState = context.getComponentState(); 96 GTKStyle style = (GTKStyle)context.getStyle(); 97 int focusSize = 98 style.getClassSpecificIntValue(context, 99 "focus-line-width", 1); 100 int focusPad = 101 style.getClassSpecificIntValue(context, 102 "focus-padding", 1); 103 int totalFocus = focusSize + focusPad; 104 int x = bounds.x - totalFocus; 105 int y = bounds.y - totalFocus; 106 int w = bounds.width + (2 * totalFocus); 107 int h = bounds.height + (2 * totalFocus); 108 109 Color color = g.getColor(); 110 GTKPainter.INSTANCE.paintFocus(context, g, id, 111 synthState, "checkbutton", 112 x, y, w, h); 113 g.setColor(color); 114 } 115 } 116 super.paintText(context, g, text, bounds, mnemonicIndex); 117 } 118 119 private static boolean shouldShadowText(Region id, int state) { 120 int gtkState = GTKLookAndFeel.synthStateToGTKState(id, state); 121 return((gtkState == SynthConstants.MOUSE_OVER) && 122 (id == Region.MENU || 123 id == Region.MENU_ITEM || 124 id == Region.CHECK_BOX_MENU_ITEM || 125 id == Region.RADIO_BUTTON_MENU_ITEM)); 126 } 127 }