javaquery/canvas/src/main/java/net/java/html/canvas/GraphicsEnvironment.java
author toni.epple@eppleton.de
Fri, 17 May 2013 14:09:01 +0200
branchcanvas
changeset 1119 73041c26cf4d
parent 1118 e198f1a3814f
permissions -rw-r--r--
Added some license headers
     1 /**
     2  * Back 2 Browser Bytecode Translator Copyright (C) 2012 Jaroslav Tulach
     3  * <jaroslav.tulach@apidesign.org>
     4  *
     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.
     8  *
     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
    12  * details.
    13  *
    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.
    17  */
    18 package net.java.html.canvas;
    19 
    20 import java.util.ServiceLoader;
    21 
    22 /**
    23  *
    24  * @author antonepple
    25  */
    26 public abstract class GraphicsEnvironment {
    27 
    28     private static GraphicsEnvironment DEFAULT;
    29 
    30     public GraphicsEnvironment getDefault() {
    31         if (DEFAULT == null) {
    32             ServiceLoader<GraphicsEnvironment> loader = ServiceLoader.load(GraphicsEnvironment.class);
    33             DEFAULT = loader.iterator().next();
    34         }
    35         return DEFAULT == null ? getDummyInstance() : DEFAULT;
    36     }
    37 
    38     public abstract Image getImageForPath(String path);
    39     
    40     public abstract LinearGradient createLinearGradient();
    41     
    42     public abstract Pattern createPattern();
    43     
    44     public abstract RadialGradient createRadialGradient();
    45     
    46     public abstract TextMetrics createTextMetrics();
    47     
    48     private GraphicsEnvironment getDummyInstance() {
    49         
    50         return new GraphicsEnvironment() {
    51 
    52             @Override
    53             public Image getImageForPath(String path) {
    54                return new Image() {
    55 
    56                    @Override
    57                    public int getHeight() {
    58                      return 0;
    59                    }
    60 
    61                    @Override
    62                    public int getWidth() {
    63                        return 0;
    64                    }
    65                };
    66             }
    67 
    68             @Override
    69             public LinearGradient createLinearGradient() {
    70                 return new LinearGradient() {
    71 
    72                     @Override
    73                     public void addColorStop(double position, String color) {
    74                       
    75                     }
    76                 };
    77             }
    78 
    79             @Override
    80             public Pattern createPattern() {
    81                return new Pattern() {
    82 };
    83             }
    84 
    85             @Override
    86             public RadialGradient createRadialGradient() {
    87                 return new RadialGradient() {
    88 
    89                     @Override
    90                     public void addColorStop(double position, String color) {
    91                         
    92                     }
    93                 };
    94             }
    95 
    96             @Override
    97             public TextMetrics createTextMetrics() {
    98                 return new TextMetrics() {
    99 
   100                     @Override
   101                     public double getHeight() {
   102                         return 0;
   103                     }
   104 
   105                     @Override
   106                     public double getWidth() {
   107                         return 0;
   108                     }
   109                 };
   110             }
   111         };
   112     }
   113     
   114     
   115 }