1 /* 2 * Copyright (c) 1999, 2000, 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 26 package java.awt; 27 28 import java.awt.peer.LightweightPeer; 29 import sun.awt.SunGraphicsCallback; 30 31 32 abstract class GraphicsCallback extends SunGraphicsCallback { 33 34 static final class PaintCallback extends GraphicsCallback { 35 private static PaintCallback instance = new PaintCallback(); 36 PaintCallback()37 private PaintCallback() {} run(Component comp, Graphics cg)38 public void run(Component comp, Graphics cg) { 39 comp.paint(cg); 40 } getInstance()41 static PaintCallback getInstance() { 42 return instance; 43 } 44 } 45 static final class PrintCallback extends GraphicsCallback { 46 private static PrintCallback instance = new PrintCallback(); 47 PrintCallback()48 private PrintCallback() {} run(Component comp, Graphics cg)49 public void run(Component comp, Graphics cg) { 50 comp.print(cg); 51 } getInstance()52 static PrintCallback getInstance() { 53 return instance; 54 } 55 } 56 static final class PaintAllCallback extends GraphicsCallback { 57 private static PaintAllCallback instance = new PaintAllCallback(); 58 PaintAllCallback()59 private PaintAllCallback() {} run(Component comp, Graphics cg)60 public void run(Component comp, Graphics cg) { 61 comp.paintAll(cg); 62 } getInstance()63 static PaintAllCallback getInstance() { 64 return instance; 65 } 66 } 67 static final class PrintAllCallback extends GraphicsCallback { 68 private static PrintAllCallback instance = new PrintAllCallback(); 69 PrintAllCallback()70 private PrintAllCallback() {} run(Component comp, Graphics cg)71 public void run(Component comp, Graphics cg) { 72 comp.printAll(cg); 73 } getInstance()74 static PrintAllCallback getInstance() { 75 return instance; 76 } 77 } 78 static final class PeerPaintCallback extends GraphicsCallback { 79 private static PeerPaintCallback instance = new PeerPaintCallback(); 80 PeerPaintCallback()81 private PeerPaintCallback() {} run(Component comp, Graphics cg)82 public void run(Component comp, Graphics cg) { 83 comp.validate(); 84 if (comp.peer instanceof LightweightPeer) { 85 comp.lightweightPaint(cg); 86 } else { 87 comp.peer.paint(cg); 88 } 89 } getInstance()90 static PeerPaintCallback getInstance() { 91 return instance; 92 } 93 } 94 static final class PeerPrintCallback extends GraphicsCallback { 95 private static PeerPrintCallback instance = new PeerPrintCallback(); 96 PeerPrintCallback()97 private PeerPrintCallback() {} run(Component comp, Graphics cg)98 public void run(Component comp, Graphics cg) { 99 comp.validate(); 100 if (comp.peer instanceof LightweightPeer) { 101 comp.lightweightPrint(cg); 102 } else { 103 comp.peer.print(cg); 104 } 105 } getInstance()106 static PeerPrintCallback getInstance() { 107 return instance; 108 } 109 } 110 static final class PaintHeavyweightComponentsCallback 111 extends GraphicsCallback 112 { 113 private static PaintHeavyweightComponentsCallback instance = 114 new PaintHeavyweightComponentsCallback(); 115 PaintHeavyweightComponentsCallback()116 private PaintHeavyweightComponentsCallback() {} run(Component comp, Graphics cg)117 public void run(Component comp, Graphics cg) { 118 if (comp.peer instanceof LightweightPeer) { 119 comp.paintHeavyweightComponents(cg); 120 } else { 121 comp.paintAll(cg); 122 } 123 } getInstance()124 static PaintHeavyweightComponentsCallback getInstance() { 125 return instance; 126 } 127 } 128 static final class PrintHeavyweightComponentsCallback 129 extends GraphicsCallback 130 { 131 private static PrintHeavyweightComponentsCallback instance = 132 new PrintHeavyweightComponentsCallback(); 133 PrintHeavyweightComponentsCallback()134 private PrintHeavyweightComponentsCallback() {} run(Component comp, Graphics cg)135 public void run(Component comp, Graphics cg) { 136 if (comp.peer instanceof LightweightPeer) { 137 comp.printHeavyweightComponents(cg); 138 } else { 139 comp.printAll(cg); 140 } 141 } getInstance()142 static PrintHeavyweightComponentsCallback getInstance() { 143 return instance; 144 } 145 } 146 } 147