added caching of style to implementation canvas
authorAnton Epple <toni.epple@eppleton.de>
Fri, 24 May 2013 12:34:38 +0200
branchcanvas
changeset 11427db01893aaf8
parent 1141 69c81bdaf193
child 1144 5bf850c5b7f1
added caching of style to implementation
javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/HTML5GraphicsEnvironment.java
     1.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/HTML5GraphicsEnvironment.java	Fri May 24 12:29:58 2013 +0200
     1.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/HTML5GraphicsEnvironment.java	Fri May 24 12:34:38 2013 +0200
     1.3 @@ -36,7 +36,8 @@
     1.4  
     1.5      Object context;
     1.6      Canvas canvas;
     1.7 -   public  HTML5GraphicsEnvironment(Object contextImpl, Canvas canvas) {
     1.8 +
     1.9 +    public HTML5GraphicsEnvironment(Object contextImpl, Canvas canvas) {
    1.10          this.context = contextImpl;
    1.11          this.canvas = canvas;
    1.12      }
    1.13 @@ -169,21 +170,15 @@
    1.14  ////
    1.15  ////    @JavaScriptBody(args = {"ctx", "img", "x", "y"}, body = "ctx.drawImage(img,x,y);")
    1.16  ////    private native static void drawImageImpl(Object ctx, Object img, double x, double y);
    1.17 -
    1.18 -    @JavaScriptBody(args = {"style"}, body = "this._context().fillStyle=style.valueOf();")
    1.19 -    @Override
    1.20 -    public native void setFillStyle(String style);
    1.21 -
    1.22 -    @JavaScriptBody(args = {}, body = "return this._context().fillStyle;")
    1.23 -    @Override
    1.24 -    public native String getFillStyle();
    1.25 -
    1.26 -    @Override
    1.27 -    public void setFillStyle(Style style) {
    1.28 -        setFillStyleImpl(context, createFillStyle(style));
    1.29 +    public Object setFillStyle(Style style, Object nativeStyle) {
    1.30 +        if (nativeStyle == null) {
    1.31 +            nativeStyle = createNativeStyle(style);
    1.32 +        }
    1.33 +        setFillStyleImpl(context, nativeStyle);
    1.34 +        return nativeStyle;
    1.35      }
    1.36  
    1.37 -    private Object createFillStyle(Style style) {
    1.38 +    private Object createNativeStyle(Style style) {
    1.39          if (style instanceof RadialGradient) {
    1.40              RadialGradientWrapper gradient = createRadialGradientWrapper(
    1.41                      ((RadialGradient) style).getX0(),
    1.42 @@ -212,14 +207,12 @@
    1.43                  addColorStopImpl(style, double1, stops.get(double1));
    1.44              }
    1.45              return gradient;
    1.46 -        } 
    1.47 -        else if (style instanceof Pattern) {
    1.48 +        } else if (style instanceof Pattern) {
    1.49  //            return createPatternWrapper(((Pattern) style).getImage(), ((Pattern) style).getRepeat());
    1.50          }
    1.51          return null;
    1.52      }
    1.53  
    1.54 -
    1.55      @JavaScriptBody(args = {"gradient", "position", "color"}, body =
    1.56              "gradient.addColorStop(position,color)")
    1.57      private static native void addColorStopImpl(Object gradient, double position, String color);
    1.58 @@ -228,12 +221,15 @@
    1.59      private native void setFillStyleImpl(Object context, Object obj);
    1.60  
    1.61      @JavaScriptBody(args = {"style"}, body = "this._context().strokeStyle=style.valueOf();")
    1.62 -    @Override
    1.63      public native void setStrokeStyle(String style);
    1.64  
    1.65      @Override
    1.66 -    public void setStrokeStyle(Style style) {
    1.67 -        setStrokeStyleImpl(context, createFillStyle(style));
    1.68 +    public Object setStrokeStyle(Style style, Object nativeStyle) {
    1.69 +        if (nativeStyle == null){
    1.70 +            nativeStyle = createNativeStyle(style);
    1.71 +        }
    1.72 +        setStrokeStyleImpl(context, nativeStyle);
    1.73 +        return nativeStyle;
    1.74      }
    1.75  
    1.76      @JavaScriptBody(args = {"context", "obj"}, body = "context.strokeStyle=obj;")
    1.77 @@ -256,7 +252,6 @@
    1.78      public native void setShadowOffsetY(double y);
    1.79  
    1.80      @JavaScriptBody(args = {}, body = "return this._context().strokeStyle;")
    1.81 -    @Override
    1.82      public native String getStrokeStyle();
    1.83  
    1.84      @JavaScriptBody(args = {}, body = "return this._context().shadowColor;")
    1.85 @@ -344,7 +339,7 @@
    1.86      @Override
    1.87      public Dimension measureText(String text) {
    1.88          measureTextImpl(text);
    1.89 -        return new Dimension(1,1);
    1.90 +        return new Dimension(1, 1);
    1.91      }
    1.92  
    1.93      @JavaScriptBody(args = {"text"},
    1.94 @@ -395,7 +390,6 @@
    1.95  ////    public void putImageData(ImageData imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight) {
    1.96  ////        putImageDataImpl(((ImageDataWrapper) imageData).object(), x, y, dirtyx, dirtyy, dirtywidth, dirtyheight);
    1.97  ////    }
    1.98 -
    1.99      @JavaScriptBody(args = {"imageData", "x", "y", "dirtyx", "dirtyy", "dirtywidth", "dirtyheight"},
   1.100              body = "this._context().putImageData(imageData,x,y, dirtyx, dirtyy, dirtywidth,dirtyheight);")
   1.101      private native void putImageDataImpl(Object imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight);
   1.102 @@ -429,7 +423,6 @@
   1.103  //
   1.104  //    @JavaScriptBody(args = {"context", "image", "repeat"}, body = "return context.createPattern(image, repeat);")
   1.105  //    private static native Object createPatternImpl(Object context, Image image, String repeat);
   1.106 -
   1.107      public RadialGradientWrapper createRadialGradientWrapper(double x0, double y0, double r0, double x1, double y1, double r1) {
   1.108          return new RadialGradientWrapper(createRadialGradientImpl(context, x0, y0, r0, x1, y1, r1));
   1.109      }
   1.110 @@ -440,27 +433,23 @@
   1.111  ////  
   1.112  ////    @JavaScriptBody(args = {"path"}, body = "var b = new Image(); b.src=path; return b;")
   1.113  ////    public native Image getImageForPath(String path);
   1.114 -
   1.115 -    
   1.116 -    
   1.117      @Override
   1.118      public int getHeight() {
   1.119 -       return canvas.getHeight();
   1.120 +        return canvas.getHeight();
   1.121      }
   1.122  
   1.123      @Override
   1.124      public int getWidth() {
   1.125 -       return canvas.getWidth();
   1.126 +        return canvas.getWidth();
   1.127      }
   1.128  
   1.129      @Override
   1.130      public void setHeight(int height) {
   1.131 -       canvas.setHeight(height);
   1.132 +        canvas.setHeight(height);
   1.133      }
   1.134  
   1.135      @Override
   1.136      public void setWidth(int width) {
   1.137 -       canvas.setWidth(width);
   1.138 +        canvas.setWidth(width);
   1.139      }
   1.140 -
   1.141  }