2658
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
|
2658
|
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
|
5506
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
2658
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
5506
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
2658
|
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 |
*
|
5506
|
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.
|
2658
|
24 |
*/
|
|
25 |
|
|
26 |
package javax.swing.plaf.nimbus;
|
|
27 |
|
|
28 |
import javax.swing.plaf.nimbus.AbstractRegionPainter.PaintContext.CacheMode;
|
|
29 |
import java.awt.Dimension;
|
|
30 |
import java.awt.Graphics2D;
|
|
31 |
import java.awt.Insets;
|
|
32 |
import javax.swing.JComponent;
|
|
33 |
|
|
34 |
/**
|
|
35 |
* A special painter implementation for tool bar separators in Nimbus.
|
|
36 |
* The designer tool doesn't have support for painters which render
|
|
37 |
* repeated patterns, but that's exactly what the toolbar separator design
|
|
38 |
* is for Nimbus. This custom painter is designed to handle this situation.
|
|
39 |
* When support is added to the design tool / code generator to deal with
|
|
40 |
* repeated patterns, then we can remove this class.
|
|
41 |
* <p>
|
|
42 |
*/
|
|
43 |
final class ToolBarSeparatorPainter extends AbstractRegionPainter {
|
|
44 |
private static final int SPACE = 3;
|
|
45 |
private static final int INSET = 2;
|
|
46 |
|
|
47 |
@Override
|
|
48 |
protected PaintContext getPaintContext() {
|
|
49 |
//the paint context returned will have a few dummy values. The
|
|
50 |
//implementation of doPaint doesn't bother with the "decode" methods
|
|
51 |
//but calculates where to paint the circles manually. As such, we
|
|
52 |
//only need to indicate in our PaintContext that we don't want this
|
|
53 |
//to ever be cached
|
|
54 |
return new PaintContext(
|
|
55 |
new Insets(1, 0, 1, 0),
|
|
56 |
new Dimension(38, 7),
|
|
57 |
false, CacheMode.NO_CACHING, 1, 1);
|
|
58 |
}
|
|
59 |
|
|
60 |
@Override
|
|
61 |
protected void doPaint(Graphics2D g, JComponent c, int width, int height, Object[] extendedCacheKeys) {
|
|
62 |
//it is assumed that in the normal orientation the separator renders
|
|
63 |
//horizontally. Other code rotates it as necessary for a vertical
|
|
64 |
//separator.
|
|
65 |
g.setColor(c.getForeground());
|
|
66 |
int y = height / 2;
|
|
67 |
for (int i=INSET; i<=width-INSET; i+=SPACE) {
|
|
68 |
g.fillRect(i, y, 1, 1);
|
|
69 |
}
|
|
70 |
}
|
|
71 |
}
|