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
toni@1119
     1
/**
toni@1119
     2
 * Back 2 Browser Bytecode Translator Copyright (C) 2012 Jaroslav Tulach
toni@1119
     3
 * <jaroslav.tulach@apidesign.org>
toni@1119
     4
 *
toni@1119
     5
 * This program is free software: you can redistribute it and/or modify it under
toni@1119
     6
 * the terms of the GNU General Public License as published by the Free Software
toni@1119
     7
 * Foundation, version 2 of the License.
toni@1119
     8
 *
toni@1119
     9
 * This program is distributed in the hope that it will be useful, but WITHOUT
toni@1119
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
toni@1119
    11
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
toni@1119
    12
 * details.
toni@1119
    13
 *
toni@1119
    14
 * You should have received a copy of the GNU General Public License along with
toni@1119
    15
 * this program. Look for COPYING file in the top folder. If not, see
toni@1119
    16
 * http://opensource.org/licenses/GPL-2.0.
toni@1118
    17
 */
toni@1118
    18
package net.java.html.canvas;
toni@1118
    19
toni@1118
    20
import java.util.ServiceLoader;
toni@1118
    21
toni@1118
    22
/**
toni@1118
    23
 *
toni@1118
    24
 * @author antonepple
toni@1118
    25
 */
toni@1118
    26
public abstract class GraphicsEnvironment {
toni@1118
    27
toni@1118
    28
    private static GraphicsEnvironment DEFAULT;
toni@1118
    29
toni@1118
    30
    public GraphicsEnvironment getDefault() {
toni@1118
    31
        if (DEFAULT == null) {
toni@1118
    32
            ServiceLoader<GraphicsEnvironment> loader = ServiceLoader.load(GraphicsEnvironment.class);
toni@1118
    33
            DEFAULT = loader.iterator().next();
toni@1118
    34
        }
toni@1118
    35
        return DEFAULT == null ? getDummyInstance() : DEFAULT;
toni@1118
    36
    }
toni@1118
    37
toni@1118
    38
    public abstract Image getImageForPath(String path);
toni@1118
    39
    
toni@1118
    40
    public abstract LinearGradient createLinearGradient();
toni@1118
    41
    
toni@1118
    42
    public abstract Pattern createPattern();
toni@1118
    43
    
toni@1118
    44
    public abstract RadialGradient createRadialGradient();
toni@1118
    45
    
toni@1118
    46
    public abstract TextMetrics createTextMetrics();
toni@1118
    47
    
toni@1118
    48
    private GraphicsEnvironment getDummyInstance() {
toni@1118
    49
        
toni@1118
    50
        return new GraphicsEnvironment() {
toni@1118
    51
toni@1118
    52
            @Override
toni@1118
    53
            public Image getImageForPath(String path) {
toni@1118
    54
               return new Image() {
toni@1118
    55
toni@1118
    56
                   @Override
toni@1118
    57
                   public int getHeight() {
toni@1118
    58
                     return 0;
toni@1118
    59
                   }
toni@1118
    60
toni@1118
    61
                   @Override
toni@1118
    62
                   public int getWidth() {
toni@1118
    63
                       return 0;
toni@1118
    64
                   }
toni@1118
    65
               };
toni@1118
    66
            }
toni@1118
    67
toni@1118
    68
            @Override
toni@1118
    69
            public LinearGradient createLinearGradient() {
toni@1118
    70
                return new LinearGradient() {
toni@1118
    71
toni@1118
    72
                    @Override
toni@1118
    73
                    public void addColorStop(double position, String color) {
toni@1118
    74
                      
toni@1118
    75
                    }
toni@1118
    76
                };
toni@1118
    77
            }
toni@1118
    78
toni@1118
    79
            @Override
toni@1118
    80
            public Pattern createPattern() {
toni@1118
    81
               return new Pattern() {
toni@1118
    82
};
toni@1118
    83
            }
toni@1118
    84
toni@1118
    85
            @Override
toni@1118
    86
            public RadialGradient createRadialGradient() {
toni@1118
    87
                return new RadialGradient() {
toni@1118
    88
toni@1118
    89
                    @Override
toni@1118
    90
                    public void addColorStop(double position, String color) {
toni@1118
    91
                        
toni@1118
    92
                    }
toni@1118
    93
                };
toni@1118
    94
            }
toni@1118
    95
toni@1118
    96
            @Override
toni@1118
    97
            public TextMetrics createTextMetrics() {
toni@1118
    98
                return new TextMetrics() {
toni@1118
    99
toni@1118
   100
                    @Override
toni@1118
   101
                    public double getHeight() {
toni@1118
   102
                        return 0;
toni@1118
   103
                    }
toni@1118
   104
toni@1118
   105
                    @Override
toni@1118
   106
                    public double getWidth() {
toni@1118
   107
                        return 0;
toni@1118
   108
                    }
toni@1118
   109
                };
toni@1118
   110
            }
toni@1118
   111
        };
toni@1118
   112
    }
toni@1118
   113
    
toni@1118
   114
    
toni@1118
   115
}