2 * Back 2 Browser Bytecode Translator Copyright (C) 2012 Jaroslav Tulach
3 * <jaroslav.tulach@apidesign.org>
5 * This program is free software: you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation, version 2 of the License.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14 * You should have received a copy of the GNU General Public License along with
15 * this program. Look for COPYING file in the top folder. If not, see
16 * http://opensource.org/licenses/GPL-2.0.
18 package net.java.html.canvas;
20 import java.util.ServiceLoader;
26 public abstract class GraphicsEnvironment {
28 private static GraphicsEnvironment DEFAULT;
30 public GraphicsEnvironment getDefault() {
31 if (DEFAULT == null) {
32 ServiceLoader<GraphicsEnvironment> loader = ServiceLoader.load(GraphicsEnvironment.class);
33 DEFAULT = loader.iterator().next();
35 return DEFAULT == null ? getDummyInstance() : DEFAULT;
38 public abstract Image getImageForPath(String path);
40 public abstract LinearGradient createLinearGradient();
42 public abstract Pattern createPattern();
44 public abstract RadialGradient createRadialGradient();
46 public abstract TextMetrics createTextMetrics();
48 private GraphicsEnvironment getDummyInstance() {
50 return new GraphicsEnvironment() {
53 public Image getImageForPath(String path) {
57 public int getHeight() {
62 public int getWidth() {
69 public LinearGradient createLinearGradient() {
70 return new LinearGradient() {
73 public void addColorStop(double position, String color) {
80 public Pattern createPattern() {
81 return new Pattern() {
86 public RadialGradient createRadialGradient() {
87 return new RadialGradient() {
90 public void addColorStop(double position, String color) {
97 public TextMetrics createTextMetrics() {
98 return new TextMetrics() {
101 public double getHeight() {
106 public double getWidth() {