1 /*
2 * Copyright (c) 1999, 2013, 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
30 import sun.util.logging.PlatformLogger;
31
32 public abstract class SunGraphicsCallback {
33 public static final int HEAVYWEIGHTS = 0x1;
34 public static final int LIGHTWEIGHTS = 0x2;
35 public static final int TWO_PASSES = 0x4;
36
37 private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.SunGraphicsCallback");
38
39 public abstract void run(Component comp, Graphics cg);
40
41 protected void constrainGraphics(Graphics g, Rectangle bounds) {
42 if (g instanceof ConstrainableGraphics) {
43 ((ConstrainableGraphics)g).constrain(bounds.x, bounds.y, bounds.width, bounds.height);
44 } else {
45 g.translate(bounds.x, bounds.y);
46 }
47 g.clipRect(0, 0, bounds.width, bounds.height);
48 }
49
50 @SuppressWarnings("deprecation")
51 public final void runOneComponent(Component comp, Rectangle bounds,
52 Graphics g, Shape clip,
53 int weightFlags) {
54 if (comp == null || comp.getPeer() == null || !comp.isVisible()) {
55 return;
56 }
57 boolean lightweight = comp.isLightweight();
58 if ((lightweight && (weightFlags & LIGHTWEIGHTS) == 0) ||
59 (!lightweight && (weightFlags & HEAVYWEIGHTS) == 0)) {
60 return;
61 }
62
63 if (bounds == null) {
64 bounds = comp.getBounds();
65 }
66
67 if (clip == null || clip.intersects(bounds)) {
68 Graphics cg = g.create();
69 try {
70 constrainGraphics(cg, bounds);
71 cg.setFont(comp.getFont());
72 cg.setColor(comp.getForeground());
73 if (cg instanceof Graphics2D) {
74 ((Graphics2D)cg).setBackground(comp.getBackground());
|
1 /*
2 * Copyright (c) 1999, 2015, 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
30 import sun.util.logging.PlatformLogger;
31
32 public abstract class SunGraphicsCallback {
33 public static final int HEAVYWEIGHTS = 0x1;
34 public static final int LIGHTWEIGHTS = 0x2;
35 public static final int TWO_PASSES = 0x4;
36
37 private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.SunGraphicsCallback");
38
39 public abstract void run(Component comp, Graphics cg);
40
41 protected void constrainGraphics(Graphics g, Rectangle bounds) {
42 if (g instanceof ConstrainableGraphics) {
43 ((ConstrainableGraphics)g).constrain(bounds.x, bounds.y, bounds.width, bounds.height);
44 } else {
45 g.translate(bounds.x, bounds.y);
46 }
47 g.clipRect(0, 0, bounds.width, bounds.height);
48 }
49
50 public final void runOneComponent(Component comp, Rectangle bounds,
51 Graphics g, Shape clip,
52 int weightFlags) {
53 if (comp == null || !comp.isDisplayable() || !comp.isVisible()) {
54 return;
55 }
56 boolean lightweight = comp.isLightweight();
57 if ((lightweight && (weightFlags & LIGHTWEIGHTS) == 0) ||
58 (!lightweight && (weightFlags & HEAVYWEIGHTS) == 0)) {
59 return;
60 }
61
62 if (bounds == null) {
63 bounds = comp.getBounds();
64 }
65
66 if (clip == null || clip.intersects(bounds)) {
67 Graphics cg = g.create();
68 try {
69 constrainGraphics(cg, bounds);
70 cg.setFont(comp.getFont());
71 cg.setColor(comp.getForeground());
72 if (cg instanceof Graphics2D) {
73 ((Graphics2D)cg).setBackground(comp.getBackground());
|