toni@1119: /** toni@1119: * Back 2 Browser Bytecode Translator Copyright (C) 2012 Jaroslav Tulach toni@1119: * toni@1119: * toni@1119: * This program is free software: you can redistribute it and/or modify it under toni@1119: * the terms of the GNU General Public License as published by the Free Software toni@1119: * Foundation, version 2 of the License. toni@1119: * toni@1119: * This program is distributed in the hope that it will be useful, but WITHOUT toni@1119: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS toni@1119: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more toni@1119: * details. toni@1119: * toni@1119: * You should have received a copy of the GNU General Public License along with toni@1119: * this program. Look for COPYING file in the top folder. If not, see toni@1119: * http://opensource.org/licenses/GPL-2.0. toni@1118: */ toni@1118: package net.java.html.canvas; toni@1118: toni@1118: import java.util.ServiceLoader; toni@1118: toni@1118: /** toni@1118: * toni@1118: * @author antonepple toni@1118: */ toni@1118: public abstract class GraphicsEnvironment { toni@1118: toni@1118: private static GraphicsEnvironment DEFAULT; toni@1118: toni@1118: public GraphicsEnvironment getDefault() { toni@1118: if (DEFAULT == null) { toni@1118: ServiceLoader loader = ServiceLoader.load(GraphicsEnvironment.class); toni@1118: DEFAULT = loader.iterator().next(); toni@1118: } toni@1118: return DEFAULT == null ? getDummyInstance() : DEFAULT; toni@1118: } toni@1118: toni@1118: public abstract Image getImageForPath(String path); toni@1118: toni@1118: public abstract LinearGradient createLinearGradient(); toni@1118: toni@1118: public abstract Pattern createPattern(); toni@1118: toni@1118: public abstract RadialGradient createRadialGradient(); toni@1118: toni@1118: public abstract TextMetrics createTextMetrics(); toni@1118: toni@1118: private GraphicsEnvironment getDummyInstance() { toni@1118: toni@1118: return new GraphicsEnvironment() { toni@1118: toni@1118: @Override toni@1118: public Image getImageForPath(String path) { toni@1118: return new Image() { toni@1118: toni@1118: @Override toni@1118: public int getHeight() { toni@1118: return 0; toni@1118: } toni@1118: toni@1118: @Override toni@1118: public int getWidth() { toni@1118: return 0; toni@1118: } toni@1118: }; toni@1118: } toni@1118: toni@1118: @Override toni@1118: public LinearGradient createLinearGradient() { toni@1118: return new LinearGradient() { toni@1118: toni@1118: @Override toni@1118: public void addColorStop(double position, String color) { toni@1118: toni@1118: } toni@1118: }; toni@1118: } toni@1118: toni@1118: @Override toni@1118: public Pattern createPattern() { toni@1118: return new Pattern() { toni@1118: }; toni@1118: } toni@1118: toni@1118: @Override toni@1118: public RadialGradient createRadialGradient() { toni@1118: return new RadialGradient() { toni@1118: toni@1118: @Override toni@1118: public void addColorStop(double position, String color) { toni@1118: toni@1118: } toni@1118: }; toni@1118: } toni@1118: toni@1118: @Override toni@1118: public TextMetrics createTextMetrics() { toni@1118: return new TextMetrics() { toni@1118: toni@1118: @Override toni@1118: public double getHeight() { toni@1118: return 0; toni@1118: } toni@1118: toni@1118: @Override toni@1118: public double getWidth() { toni@1118: return 0; toni@1118: } toni@1118: }; toni@1118: } toni@1118: }; toni@1118: } toni@1118: toni@1118: toni@1118: }