~ubuntu-branches/debian/stretch/insubstantial/stretch

« back to all changes in this revision

Viewing changes to substance/src/main/java/org/pushingpixels/substance/internal/utils/SubstanceTextUtilities.java

  • Committer: Package Import Robot
  • Author(s): Felix Natter
  • Date: 2016-01-18 20:58:45 UTC
  • Revision ID: package-import@ubuntu.com-20160118205845-crbmrkda61qsi5qa
Tags: upstream-7.3+dfsg2
ImportĀ upstreamĀ versionĀ 7.3+dfsg2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2005-2010 Substance Kirill Grouchnikov. All Rights Reserved.
 
3
 *
 
4
 * Redistribution and use in source and binary forms, with or without
 
5
 * modification, are permitted provided that the following conditions are met:
 
6
 *
 
7
 *  o Redistributions of source code must retain the above copyright notice,
 
8
 *    this list of conditions and the following disclaimer.
 
9
 *
 
10
 *  o Redistributions in binary form must reproduce the above copyright notice,
 
11
 *    this list of conditions and the following disclaimer in the documentation
 
12
 *    and/or other materials provided with the distribution.
 
13
 *
 
14
 *  o Neither the name of Substance Kirill Grouchnikov nor the names of
 
15
 *    its contributors may be used to endorse or promote products derived
 
16
 *    from this software without specific prior written permission.
 
17
 *
 
18
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 
19
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 
20
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 
21
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 
22
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 
23
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 
24
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 
25
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 
26
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 
27
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 
28
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
29
 */
 
30
package org.pushingpixels.substance.internal.utils;
 
31
 
 
32
import java.awt.*;
 
33
import java.awt.geom.AffineTransform;
 
34
import java.awt.image.*;
 
35
 
 
36
import javax.swing.*;
 
37
import javax.swing.border.Border;
 
38
import javax.swing.border.CompoundBorder;
 
39
import javax.swing.plaf.ComponentUI;
 
40
import javax.swing.plaf.basic.BasicGraphicsUtils;
 
41
import javax.swing.text.JTextComponent;
 
42
 
 
43
import org.pushingpixels.lafwidget.LafWidgetUtilities;
 
44
import org.pushingpixels.lafwidget.text.LockBorder;
 
45
import org.pushingpixels.lafwidget.utils.RenderingUtils;
 
46
import org.pushingpixels.substance.api.*;
 
47
import org.pushingpixels.substance.api.watermark.SubstanceWatermark;
 
48
import org.pushingpixels.substance.internal.animation.StateTransitionTracker;
 
49
import org.pushingpixels.substance.internal.animation.TransitionAwareUI;
 
50
import org.pushingpixels.substance.internal.painter.BackgroundPaintingUtils;
 
51
import org.pushingpixels.substance.internal.utils.border.SubstanceTextComponentBorder;
 
52
 
 
53
/**
 
54
 * Text-related utilities. This class if for internal use only.
 
55
 * 
 
56
 * @author Kirill Grouchnikov
 
57
 */
 
58
public class SubstanceTextUtilities {
 
59
        public static final String ENFORCE_FG_COLOR = "substancelaf.internal.textUtilities.enforceFgColor";
 
60
 
 
61
        /**
 
62
         * Paints text with drop shadow.
 
63
         * 
 
64
         * @param c
 
65
         *            Component.
 
66
         * @param g
 
67
         *            Graphics context.
 
68
         * @param foregroundColor
 
69
         *            Foreground color.
 
70
         * @param text
 
71
         *            Text to paint.
 
72
         * @param width
 
73
         *            Text rectangle width.
 
74
         * @param height
 
75
         *            Text rectangle height.
 
76
         * @param xOffset
 
77
         *            Text rectangle X offset.
 
78
         * @param yOffset
 
79
         *            Text rectangle Y offset.
 
80
         */
 
81
        public static void paintTextWithDropShadow(JComponent c, Graphics g,
 
82
                        Color foregroundColor, String text, int width, int height,
 
83
                        int xOffset, int yOffset) {
 
84
                Graphics2D graphics = (Graphics2D) g.create();
 
85
                RenderingUtils.installDesktopHints(graphics, c);
 
86
 
 
87
                // blur the text shadow
 
88
                BufferedImage blurred = SubstanceCoreUtilities.getBlankImage(width,
 
89
                                height);
 
90
                Graphics2D gBlurred = (Graphics2D) blurred.getGraphics();
 
91
                gBlurred.setFont(graphics.getFont());
 
92
                gBlurred.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
 
93
                                RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
 
94
                // Color neg =
 
95
                // SubstanceColorUtilities.getNegativeColor(foregroundColor);
 
96
                float luminFactor = SubstanceColorUtilities
 
97
                                .getColorStrength(foregroundColor);
 
98
                gBlurred.setColor(SubstanceColorUtilities
 
99
                                .getNegativeColor(foregroundColor));
 
100
                ConvolveOp convolve = new ConvolveOp(new Kernel(3, 3, new float[] {
 
101
                                .02f, .05f, .02f, .05f, .02f, .05f, .02f, .05f, .02f }),
 
102
                                ConvolveOp.EDGE_NO_OP, null);
 
103
                gBlurred.drawString(text, xOffset, yOffset - 1);
 
104
                blurred = convolve.filter(blurred, null);
 
105
 
 
106
                graphics.setComposite(LafWidgetUtilities.getAlphaComposite(c,
 
107
                                luminFactor, g));
 
108
                graphics.drawImage(blurred, 0, 0, null);
 
109
                graphics.setComposite(LafWidgetUtilities.getAlphaComposite(c, g));
 
110
 
 
111
                FontMetrics fm = graphics.getFontMetrics();
 
112
                SubstanceTextUtilities.paintText(graphics, c, new Rectangle(xOffset,
 
113
                                yOffset - fm.getAscent(), width - xOffset, fm.getHeight()),
 
114
                                text, -1, graphics.getFont(), foregroundColor, graphics
 
115
                                                .getClipBounds());
 
116
 
 
117
                graphics.dispose();
 
118
        }
 
119
 
 
120
        /**
 
121
         * Paints the specified text.
 
122
         * 
 
123
         * @param g
 
124
         *            Graphics context.
 
125
         * @param comp
 
126
         *            Component.
 
127
         * @param textRect
 
128
         *            Text rectangle.
 
129
         * @param text
 
130
         *            Text to paint.
 
131
         * @param mnemonicIndex
 
132
         *            Mnemonic index.
 
133
         * @param font
 
134
         *            Font to use.
 
135
         * @param color
 
136
         *            Color to use.
 
137
         * @param clip
 
138
         *            Optional clip. Can be <code>null</code>.
 
139
         * @param transform
 
140
         *            Optional transform to apply. Can be <code>null</code>.
 
141
         */
 
142
        private static void paintText(Graphics g, JComponent comp,
 
143
                        Rectangle textRect, String text, int mnemonicIndex,
 
144
                        java.awt.Font font, java.awt.Color color, java.awt.Rectangle clip,
 
145
                        java.awt.geom.AffineTransform transform) {
 
146
                if ((text == null) || (text.length() == 0))
 
147
                        return;
 
148
 
 
149
                Graphics2D g2d = (Graphics2D) g.create();
 
150
                // workaroundBug6576507(g2d);
 
151
                // RenderingUtils.installDesktopHints(g2d);
 
152
 
 
153
                g2d.setFont(font);
 
154
                g2d.setColor(color);
 
155
                // fix for issue 420 - call clip() instead of setClip() to
 
156
                // respect the currently set clip shape
 
157
                if (clip != null)
 
158
                        g2d.clip(clip);
 
159
                if (transform != null)
 
160
                        g2d.transform(transform);
 
161
                BasicGraphicsUtils.drawStringUnderlineCharAt(g2d, text, mnemonicIndex,
 
162
                                textRect.x, textRect.y + g2d.getFontMetrics().getAscent());
 
163
                g2d.dispose();
 
164
        }
 
165
 
 
166
        /**
 
167
         * Paints the specified text.
 
168
         * 
 
169
         * @param g
 
170
         *            Graphics context.
 
171
         * @param comp
 
172
         *            Component.
 
173
         * @param textRect
 
174
         *            Text rectangle.
 
175
         * @param text
 
176
         *            Text to paint.
 
177
         * @param mnemonicIndex
 
178
         *            Mnemonic index.
 
179
         * @param font
 
180
         *            Font to use.
 
181
         * @param color
 
182
         *            Color to use.
 
183
         * @param clip
 
184
         *            Optional clip. Can be <code>null</code>.
 
185
         */
 
186
        public static void paintText(Graphics g, JComponent comp,
 
187
                        Rectangle textRect, String text, int mnemonicIndex,
 
188
                        java.awt.Font font, java.awt.Color color, java.awt.Rectangle clip) {
 
189
                SubstanceTextUtilities.paintText(g, comp, textRect, text,
 
190
                                mnemonicIndex, font, color, clip, null);
 
191
        }
 
192
 
 
193
        /**
 
194
         * Paints the specified vertical text.
 
195
         * 
 
196
         * @param g
 
197
         *            Graphics context.
 
198
         * @param comp
 
199
         *            Component.
 
200
         * @param textRect
 
201
         *            Text rectangle.
 
202
         * @param text
 
203
         *            Text to paint.
 
204
         * @param mnemonicIndex
 
205
         *            Mnemonic index.
 
206
         * @param font
 
207
         *            Font to use.
 
208
         * @param color
 
209
         *            Color to use.
 
210
         * @param clip
 
211
         *            Optional clip. Can be <code>null</code>.
 
212
         * @param isFromBottomToTop
 
213
         *            If <code>true</code>, the text will be painted from bottom to
 
214
         *            top, otherwise the text will be painted from top to bottom.
 
215
         */
 
216
        public static void paintVerticalText(Graphics g, JComponent comp,
 
217
                        Rectangle textRect, String text, int mnemonicIndex,
 
218
                        java.awt.Font font, java.awt.Color color, java.awt.Rectangle clip,
 
219
                        boolean isFromBottomToTop) {
 
220
                if ((text == null) || (text.length() == 0))
 
221
                        return;
 
222
 
 
223
                AffineTransform at;
 
224
 
 
225
                if (!isFromBottomToTop) {
 
226
                        at = AffineTransform.getTranslateInstance(textRect.x
 
227
                                        + textRect.width, textRect.y);
 
228
                        at.rotate(Math.PI / 2);
 
229
                } else {
 
230
                        at = AffineTransform.getTranslateInstance(textRect.x, textRect.y
 
231
                                        + textRect.height);
 
232
                        at.rotate(-Math.PI / 2);
 
233
                }
 
234
                Rectangle newRect = new Rectangle(0, 0, textRect.width, textRect.height);
 
235
 
 
236
                SubstanceTextUtilities.paintText(g, comp, newRect, text, mnemonicIndex,
 
237
                                font, color, clip, at);
 
238
        }
 
239
 
 
240
        /**
 
241
         * Paints the text of the specified button.
 
242
         * 
 
243
         * @param g
 
244
         *            Graphic context.
 
245
         * @param button
 
246
         *            Button
 
247
         * @param textRect
 
248
         *            Text rectangle
 
249
         * @param text
 
250
         *            Text to paint
 
251
         * @param mnemonicIndex
 
252
         *            Mnemonic index.
 
253
         */
 
254
        public static void paintText(Graphics g, AbstractButton button,
 
255
                        Rectangle textRect, String text, int mnemonicIndex) {
 
256
                paintText(g, button, button.getModel(), textRect, text, mnemonicIndex);
 
257
        }
 
258
 
 
259
        /**
 
260
         * Paints the text of the specified button.
 
261
         * 
 
262
         * @param g
 
263
         *            Graphic context.
 
264
         * @param button
 
265
         *            Button
 
266
         * @param model
 
267
         *            Button model.
 
268
         * @param textRect
 
269
         *            Text rectangle
 
270
         * @param text
 
271
         *            Text to paint
 
272
         * @param mnemonicIndex
 
273
         *            Mnemonic index.
 
274
         */
 
275
        public static void paintText(Graphics g, AbstractButton button,
 
276
                        ButtonModel model, Rectangle textRect, String text,
 
277
                        int mnemonicIndex) {
 
278
                TransitionAwareUI transitionAwareUI = (TransitionAwareUI) button
 
279
                                .getUI();
 
280
                StateTransitionTracker stateTransitionTracker = transitionAwareUI
 
281
                                .getTransitionTracker();
 
282
 
 
283
                float buttonAlpha = SubstanceColorSchemeUtilities.getAlpha(button,
 
284
                                ComponentState.getState(button));
 
285
 
 
286
                if (button instanceof JMenuItem) {
 
287
                        paintMenuItemText(g, (JMenuItem) button, textRect, text,
 
288
                                        mnemonicIndex, stateTransitionTracker.getModelStateInfo(),
 
289
                                        buttonAlpha);
 
290
                } else {
 
291
                        paintText(g, button, textRect, text, mnemonicIndex,
 
292
                                        stateTransitionTracker.getModelStateInfo(), buttonAlpha);
 
293
                }
 
294
        }
 
295
 
 
296
        /**
 
297
         * Paints the specified text.
 
298
         * 
 
299
         * @param g
 
300
         *            Graphics context.
 
301
         * @param component
 
302
         *            Component.
 
303
         * @param textRect
 
304
         *            Text rectangle.
 
305
         * @param text
 
306
         *            Text to paint.
 
307
         * @param mnemonicIndex
 
308
         *            Mnemonic index.
 
309
         * @param state
 
310
         *            Component state.
 
311
         * @param textAlpha
 
312
         *            Alpha channel for painting the text.
 
313
         */
 
314
        public static void paintText(Graphics g, JComponent component,
 
315
                        Rectangle textRect, String text, int mnemonicIndex,
 
316
                        ComponentState state, float textAlpha) {
 
317
                Color fgColor = getForegroundColor(component, text, state, textAlpha);
 
318
 
 
319
                SubstanceTextUtilities.paintText(g, component, textRect, text,
 
320
                                mnemonicIndex, component.getFont(), fgColor, null);
 
321
        }
 
322
 
 
323
        public static void paintText(Graphics g, JComponent component,
 
324
                        Rectangle textRect, String text, int mnemonicIndex,
 
325
                        StateTransitionTracker.ModelStateInfo modelStateInfo,
 
326
                        float textAlpha) {
 
327
                Color fgColor = getForegroundColor(component, text, modelStateInfo,
 
328
                                textAlpha);
 
329
 
 
330
                SubstanceTextUtilities.paintText(g, component, textRect, text,
 
331
                                mnemonicIndex, component.getFont(), fgColor, null);
 
332
        }
 
333
 
 
334
        public static void paintMenuItemText(Graphics g, JMenuItem menuItem,
 
335
                        Rectangle textRect, String text, int mnemonicIndex,
 
336
                        StateTransitionTracker.ModelStateInfo modelStateInfo,
 
337
                        float textAlpha) {
 
338
                Color fgColor = getMenuComponentForegroundColor(menuItem, text,
 
339
                                modelStateInfo, textAlpha);
 
340
 
 
341
                SubstanceTextUtilities.paintText(g, menuItem, textRect, text,
 
342
                                mnemonicIndex, menuItem.getFont(), fgColor, null);
 
343
        }
 
344
 
 
345
        /**
 
346
         * Returns the foreground color for the specified component.
 
347
         * 
 
348
         * @param component
 
349
         *            Component.
 
350
         * @param text
 
351
         *            Text. If empty or <code>null</code>, the result is
 
352
         *            <code>null</code>.
 
353
         * @param state
 
354
         *            Component state.
 
355
         * @param textAlpha
 
356
         *            Alpha channel for painting the text. If value is less than
 
357
         *            1.0, the result is an opaque color which is an interpolation
 
358
         *            between the "real" foreground color and the background color
 
359
         *            of the component. This is done to ensure that native text
 
360
         *            rasterization will be performed on 6u10+ on Windows.
 
361
         * @return The foreground color for the specified component.
 
362
         */
 
363
        public static Color getForegroundColor(JComponent component, String text,
 
364
                        ComponentState state, float textAlpha) {
 
365
                if ((text == null) || (text.length() == 0))
 
366
                        return null;
 
367
 
 
368
                boolean toEnforceFgColor = (SwingUtilities.getAncestorOfClass(
 
369
                                CellRendererPane.class, component) != null)
 
370
                                || Boolean.TRUE.equals(component
 
371
                                                .getClientProperty(ENFORCE_FG_COLOR));
 
372
 
 
373
                Color fgColor = toEnforceFgColor ? component.getForeground()
 
374
                                : SubstanceColorSchemeUtilities
 
375
                                                .getColorScheme(component, state).getForegroundColor();
 
376
 
 
377
                // System.out.println(text + ":" + prevState.name() + "->" +
 
378
                // state.name() + ":" + fgColor);
 
379
                if (textAlpha < 1.0f) {
 
380
                        Color bgFillColor = SubstanceColorUtilities
 
381
                                        .getBackgroundFillColor(component);
 
382
            if (bgFillColor != null) {
 
383
                            fgColor = SubstanceColorUtilities.getInterpolatedColor(fgColor,
 
384
                                        bgFillColor, textAlpha);
 
385
            }
 
386
                }
 
387
                return fgColor;
 
388
        }
 
389
 
 
390
        /**
 
391
         * Returns the foreground color for the specified component.
 
392
         * 
 
393
         * @param component
 
394
         *            Component.
 
395
         * @param text
 
396
         *            Text. If empty or <code>null</code>, the result is
 
397
         *            <code>null</code>.
 
398
         * @param textAlpha
 
399
         *            Alpha channel for painting the text. If value is less than
 
400
         *            1.0, the result is an opaque color which is an interpolation
 
401
         *            between the "real" foreground color and the background color
 
402
         *            of the component. This is done to ensure that native text
 
403
         *            rasterization will be performed on 6u10 on Windows.
 
404
         * @return The foreground color for the specified component.
 
405
         */
 
406
        public static Color getForegroundColor(JComponent component, String text,
 
407
                        StateTransitionTracker.ModelStateInfo modelStateInfo,
 
408
                        float textAlpha) {
 
409
                if ((text == null) || (text.length() == 0))
 
410
                        return null;
 
411
 
 
412
                boolean toEnforceFgColor = (SwingUtilities.getAncestorOfClass(
 
413
                                CellRendererPane.class, component) != null)
 
414
                                || Boolean.TRUE.equals(component
 
415
                                                .getClientProperty(ENFORCE_FG_COLOR));
 
416
 
 
417
                Color fgColor;
 
418
                if (toEnforceFgColor) {
 
419
                        fgColor = component.getForeground();
 
420
                } else {
 
421
                        fgColor = SubstanceColorUtilities.getForegroundColor(component,
 
422
                                        modelStateInfo);
 
423
                }
 
424
 
 
425
                // System.out.println(text + ":" + prevState.name() + "->" +
 
426
                // state.name() + ":" + fgColor);
 
427
                if (textAlpha < 1.0f) {
 
428
                        Color bgFillColor = SubstanceColorUtilities
 
429
                                        .getBackgroundFillColor(component);
 
430
                        fgColor = SubstanceColorUtilities.getInterpolatedColor(fgColor,
 
431
                                        bgFillColor, textAlpha);
 
432
                }
 
433
                return fgColor;
 
434
        }
 
435
 
 
436
        /**
 
437
         * Returns the foreground color for the specified menu component.
 
438
         * 
 
439
         * @param menuComponent
 
440
         *            Menu component.
 
441
         * @param text
 
442
         *            Text. If empty or <code>null</code>, the result is
 
443
         *            <code>null</code>.
 
444
         * @param modelStateInfo
 
445
         *            Model state info for the specified component.
 
446
         * @param textAlpha
 
447
         *            Alpha channel for painting the text. If value is less than
 
448
         *            1.0, the result is an opaque color which is an interpolation
 
449
         *            between the "real" foreground color and the background color
 
450
         *            of the component. This is done to ensure that native text
 
451
         *            rasterization will be performed on 6u10 on Windows.
 
452
         * @return The foreground color for the specified component.
 
453
         */
 
454
        public static Color getMenuComponentForegroundColor(Component menuComponent,
 
455
                        String text, StateTransitionTracker.ModelStateInfo modelStateInfo,
 
456
                        float textAlpha) {
 
457
                if ((text == null) || (text.length() == 0))
 
458
                        return null;
 
459
 
 
460
                Color fgColor = SubstanceColorUtilities
 
461
                                .getMenuComponentForegroundColor(menuComponent, modelStateInfo);
 
462
 
 
463
                if (textAlpha < 1.0f) {
 
464
                        Color bgFillColor = SubstanceColorUtilities
 
465
                                        .getBackgroundFillColor(menuComponent);
 
466
                        fgColor = SubstanceColorUtilities.getInterpolatedColor(fgColor,
 
467
                                        bgFillColor, textAlpha);
 
468
                }
 
469
                return fgColor;
 
470
        }
 
471
 
 
472
        /**
 
473
         * Paints background of the specified text component.
 
474
         * 
 
475
         * @param g
 
476
         *            Graphics context.
 
477
         * @param comp
 
478
         *            Component.
 
479
         */
 
480
        public static void paintTextCompBackground(Graphics g, JComponent comp) {
 
481
                Color backgroundFillColor = getTextBackgroundFillColor(comp);
 
482
 
 
483
                boolean toPaintWatermark = (SubstanceLookAndFeel.getCurrentSkin(comp)
 
484
                                .getWatermark() != null)
 
485
                                && (SubstanceCoreUtilities.toDrawWatermark(comp) || !comp
 
486
                                                .isOpaque());
 
487
                paintTextCompBackground(g, comp, backgroundFillColor, toPaintWatermark);
 
488
        }
 
489
 
 
490
        public static Color getTextBackgroundFillColor(JComponent comp) {
 
491
                Color backgroundFillColor = SubstanceColorUtilities
 
492
                                .getBackgroundFillColor(comp);
 
493
                JTextComponent componentForTransitions = SubstanceCoreUtilities
 
494
                                .getTextComponentForTransitions(comp);
 
495
 
 
496
                if (componentForTransitions != null) {
 
497
                        ComponentUI ui = componentForTransitions.getUI();
 
498
                        if (ui instanceof TransitionAwareUI) {
 
499
                                TransitionAwareUI trackable = (TransitionAwareUI) ui;
 
500
                                StateTransitionTracker stateTransitionTracker = trackable
 
501
                                                .getTransitionTracker();
 
502
 
 
503
                                Color outerTextComponentBorderColor = SubstanceColorUtilities
 
504
                                                .getOuterTextComponentBorderColor(backgroundFillColor);
 
505
                                outerTextComponentBorderColor = SubstanceColorUtilities
 
506
                                                .getInterpolatedColor(outerTextComponentBorderColor,
 
507
                                                                backgroundFillColor, 0.6);
 
508
 
 
509
                                float selectionStrength = stateTransitionTracker
 
510
                                                .getFacetStrength(ComponentStateFacet.SELECTION);
 
511
                                float rolloverStrength = stateTransitionTracker
 
512
                                                .getFacetStrength(ComponentStateFacet.ROLLOVER);
 
513
                                backgroundFillColor = SubstanceColorUtilities
 
514
                                                .getInterpolatedColor(outerTextComponentBorderColor,
 
515
                                                                backgroundFillColor, Math.max(
 
516
                                                                                selectionStrength, rolloverStrength));
 
517
                        }
 
518
                }
 
519
                return backgroundFillColor;
 
520
        }
 
521
 
 
522
        /**
 
523
         * Paints background of the specified text component.
 
524
         * 
 
525
         * @param g
 
526
         *            Graphics context.
 
527
         * @param comp
 
528
         *            Component.
 
529
         * @param backgr
 
530
         *            Background color.
 
531
         * @param toOverlayWatermark
 
532
         *            If <code>true</code>, this method will paint the watermark
 
533
         *            overlay on top of the background fill.
 
534
         */
 
535
        private static void paintTextCompBackground(Graphics g, JComponent comp,
 
536
                        Color backgr, boolean toOverlayWatermark) {
 
537
                Graphics2D g2d = (Graphics2D) g.create();
 
538
 
 
539
                int componentFontSize = SubstanceSizeUtils.getComponentFontSize(comp);
 
540
                int borderDelta = (int) Math.floor(SubstanceSizeUtils
 
541
                                .getBorderStrokeWidth(componentFontSize));
 
542
                Border compBorder = comp.getBorder();
 
543
 
 
544
                if (compBorder instanceof LockBorder) {
 
545
                        compBorder = ((LockBorder) compBorder).getOriginalBorder();
 
546
                }
 
547
                boolean isSubstanceBorder = compBorder instanceof SubstanceTextComponentBorder;
 
548
 
 
549
                if (!isSubstanceBorder) {
 
550
                        Border border = compBorder;
 
551
                        while (border instanceof CompoundBorder) {
 
552
                                Border outer = ((CompoundBorder) border).getOutsideBorder();
 
553
                                if (outer instanceof SubstanceTextComponentBorder) {
 
554
                                        isSubstanceBorder = true;
 
555
                                        break;
 
556
                                }
 
557
                                Border inner = ((CompoundBorder) border).getInsideBorder();
 
558
                                if (inner instanceof SubstanceTextComponentBorder) {
 
559
                                        isSubstanceBorder = true;
 
560
                                        break;
 
561
                                }
 
562
                                border = inner;
 
563
                        }
 
564
                }
 
565
 
 
566
                Shape contour = isSubstanceBorder ? SubstanceOutlineUtilities
 
567
                                .getBaseOutline(
 
568
                                                comp.getWidth(),
 
569
                                                comp.getHeight(),
 
570
                                                Math
 
571
                                                                .max(
 
572
                                                                                0,
 
573
                                                                                2.0f
 
574
                                                                                                * SubstanceSizeUtils
 
575
                                                                                                                .getClassicButtonCornerRadius(componentFontSize)
 
576
                                                                                                - borderDelta), null,
 
577
                                                borderDelta)
 
578
                                : new Rectangle(0, 0, comp.getWidth(), comp.getHeight());
 
579
 
 
580
                BackgroundPaintingUtils.update(g, comp, false);
 
581
                SubstanceWatermark watermark = SubstanceCoreUtilities.getSkin(comp)
 
582
                                .getWatermark();
 
583
                if (watermark != null) {
 
584
                        watermark.drawWatermarkImage(g2d, comp, 0, 0, comp.getWidth(), comp
 
585
                                        .getHeight());
 
586
                }
 
587
                g2d.setColor(backgr);
 
588
                g2d.fill(contour);
 
589
 
 
590
                if (toOverlayWatermark) {
 
591
                        if (watermark != null) {
 
592
                                g2d.clip(contour);
 
593
                                watermark.drawWatermarkImage(g2d, comp, 0, 0, comp.getWidth(),
 
594
                                                comp.getHeight());
 
595
                        }
 
596
                }
 
597
 
 
598
                g2d.dispose();
 
599
        }
 
600
}