flex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Harbs <harbs.li...@gmail.com>
Subject Re: git commit: [flex-asjs] [refs/heads/refactor-sprite] - Added Binary to Images
Date Mon, 08 Aug 2016 15:26:27 GMT
I started out creating a second event, but that caused code duplication for no reason.

On Aug 8, 2016, at 6:03 PM, Piotr Zarzycki <piotrzarzycki21@gmail.com> wrote:

> Hi Harbs,
> 
> I think the name of the event "urlChanged" - do not say anymore what actually has changed.

> What do you think to have more general name? "imageSourceChanged" or "imageDataChanged".
Second idea is to have separate events for changed source binary and url.
> 
> Piotr
> 
> 
> On Mon, Aug 8, 2016, 16:48 <harbs@apache.org> wrote:
> Repository: flex-asjs
> Updated Branches:
>   refs/heads/refactor-sprite a1b8ce133 -> c5a470bf8
> 
> 
> Added Binary to Images
> 
> 
> Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
> Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/c5a470bf
> Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/c5a470bf
> Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/c5a470bf
> 
> Branch: refs/heads/refactor-sprite
> Commit: c5a470bf88377d5e68a9cbd5c429ad430afe0a03
> Parents: a1b8ce1
> Author: Harbs <harbs@in-tools.com>
> Authored: Mon Aug 8 17:48:01 2016 +0300
> Committer: Harbs <harbs@in-tools.com>
> Committed: Mon Aug 8 17:48:01 2016 +0300
> 
> ----------------------------------------------------------------------
>  .../src/products/ProductItemRenderer.as         |  2 +-
>  .../projects/Core/src/main/flex/CoreClasses.as  |  1 +
>  .../flex/org/apache/flex/core/IImageModel.as    | 17 +++++-
>  .../main/flex/org/apache/flex/utils/URLUtils.as | 59 ++++++++++++++++++++
>  .../src/main/flex/org/apache/flex/html/Image.as | 29 ++++++++--
>  .../org/apache/flex/html/beads/ImageView.as     | 26 +++++++--
>  .../apache/flex/html/beads/models/ImageModel.as | 46 ++++++++++++---
>  .../src/products/ProductItemRenderer.as         |  2 +-
>  .../src/products/ProductItemRenderer.as         |  2 +-
>  9 files changed, 162 insertions(+), 22 deletions(-)
> ----------------------------------------------------------------------
> 
> 
> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c5a470bf/examples/flexjs/DataGridExample/src/products/ProductItemRenderer.as
> ----------------------------------------------------------------------
> diff --git a/examples/flexjs/DataGridExample/src/products/ProductItemRenderer.as b/examples/flexjs/DataGridExample/src/products/ProductItemRenderer.as
> index 4edc5b7..0a954b0 100644
> --- a/examples/flexjs/DataGridExample/src/products/ProductItemRenderer.as
> +++ b/examples/flexjs/DataGridExample/src/products/ProductItemRenderer.as
> @@ -48,7 +48,7 @@ package products
>                 {
>                         super.data = value;
> 
> -                       image.source = value.image;
> +                       image.url = value.image;
>                 }
> 
>                 override public function adjustSize():void
> 
> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c5a470bf/frameworks/projects/Core/src/main/flex/CoreClasses.as
> ----------------------------------------------------------------------
> diff --git a/frameworks/projects/Core/src/main/flex/CoreClasses.as b/frameworks/projects/Core/src/main/flex/CoreClasses.as
> index 11061f5..1e8622b 100644
> --- a/frameworks/projects/Core/src/main/flex/CoreClasses.as
> +++ b/frameworks/projects/Core/src/main/flex/CoreClasses.as
> @@ -141,6 +141,7 @@ internal class CoreClasses
>         import org.apache.flex.utils.Timer; Timer;
>         import org.apache.flex.utils.UIDUtil; UIDUtil;
>         import org.apache.flex.utils.UIUtils; UIUtils;
> +       import org.apache.flex.utils.URLUtils; URLUtils;
> 
>         import org.apache.flex.core.ClassFactory; ClassFactory;
>      import org.apache.flex.states.AddItems; AddItems;
> 
> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c5a470bf/frameworks/projects/Core/src/main/flex/org/apache/flex/core/IImageModel.as
> ----------------------------------------------------------------------
> diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/core/IImageModel.as
b/frameworks/projects/Core/src/main/flex/org/apache/flex/core/IImageModel.as
> index 1551d0f..a810d71 100644
> --- a/frameworks/projects/Core/src/main/flex/org/apache/flex/core/IImageModel.as
> +++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/core/IImageModel.as
> @@ -19,6 +19,7 @@
>  package org.apache.flex.core
>  {
>         import org.apache.flex.events.IEventDispatcher;
> +    import org.apache.flex.utils.BinaryData;
> 
>      /**
>       *  The IImageModel interface describes the minimum set of properties
> @@ -42,7 +43,19 @@ package org.apache.flex.core
>           *  @playerversion AIR 2.6
>           *  @productversion FlexJS 0.0
>           */
> -               function get source():String;
> -               function set source(value:String):void;
> +               function get url():String;
> +               function set url(value:String):void;
> +
> +        /**
> +         *  The BinaryData of the image.
> +         *  This is used to set the image using binary content retrieved using HTTP
requests or File APIs.
> +         *
> +         *  @langversion 3.0
> +         *  @playerversion Flash 10.2
> +         *  @playerversion AIR 2.6
> +         *  @productversion FlexJS 0.7
> +         */
> +        function get binary():BinaryData;
> +        function set binary(value:BinaryData):void;
>         }
>  }
> 
> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c5a470bf/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/URLUtils.as
> ----------------------------------------------------------------------
> diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/URLUtils.as
b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/URLUtils.as
> new file mode 100644
> index 0000000..d7ac18a
> --- /dev/null
> +++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/URLUtils.as
> @@ -0,0 +1,59 @@
> +////////////////////////////////////////////////////////////////////////////////
> +//
> +//  Licensed to the Apache Software Foundation (ASF) under one or more
> +//  contributor license agreements.  See the NOTICE file distributed with
> +//  this work for additional information regarding copyright ownership.
> +//  The ASF licenses this file to You under the Apache License, Version 2.0
> +//  (the "License"); you may not use this file except in compliance with
> +//  the License.  You may obtain a copy of the License at
> +//
> +//      http://www.apache.org/licenses/LICENSE-2.0
> +//
> +//  Unless required by applicable law or agreed to in writing, software
> +//  distributed under the License is distributed on an "AS IS" BASIS,
> +//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> +//  See the License for the specific language governing permissions and
> +//  limitations under the License.
> +//
> +////////////////////////////////////////////////////////////////////////////////
> +package org.apache.flex.utils
> +{
> +       /**
> +        *  The URLUtils class is a collection of static functions that wrap dealing
with object URLs in the browser.
> +        *
> +        *  @langversion 3.0
> +        *  @playerversion Flash 10.2
> +        *  @playerversion AIR 2.6
> +        *  @productversion FlexJS 0.7
> +        */
> +       COMPILE::JS
> +       public class URLUtils
> +       {
> +               /**
> +                * Creates an object URL for of a blob or a file
> +                * @param  blobOrFile:* The blob of file
> +                * @param  win:*=null   The active window can be optionally specified
> +                * @return              The object URL
> +                */
> +               public static function createObjectURL(blobOrFile:*,win:*=null):String
> +               {
> +                       win = win || window;
> +                       if(win["URL"])
> +                               return win["URL"].createObjectURL(blobOrFile);
> +                       if(win.webkitURL)
> +                               return win.webkitURL.createObjectURL(blobOrFile);
> +
> +                       return "";
> +               }
> +               public static function revokeObjectURL(objectURL:String,win:*=null):void
> +               {
> +                       win = win || window;
> +                       if(win["URL"])
> +                               win["URL"].revokeObjectURL(objectURL);
> +                       if(win.webkitURL)
> +                               win.webkitURL.revokeObjectURL(objectURL);
> +               }
> +       }
> +
> +}
> +
> 
> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c5a470bf/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/Image.as
> ----------------------------------------------------------------------
> diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/Image.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/Image.as
> index ae81c18..07a9a27 100644
> --- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/Image.as
> +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/Image.as
> @@ -20,6 +20,7 @@ package org.apache.flex.html
>  {
>         import org.apache.flex.core.IImageModel;
>         import org.apache.flex.core.UIBase;
> +    import org.apache.flex.utils.BinaryData;
>      COMPILE::JS
>      {
>          import org.apache.flex.core.WrappedHTMLElement;
> @@ -31,7 +32,7 @@ package org.apache.flex.html
>          *  The Image class is a component that displays a bitmap. The Image uses
>          *  the following beads:
>          *
> -        *  org.apache.flex.core.IBeadModel: the data model for the Image, including
the source property.
> +        *  org.apache.flex.core.IBeadModel: the data model for the Image, including
the url/binary property.
>          *  org.apache.flex.core.IBeadView: constructs the visual elements of the component.
>          *
>          *  @langversion 3.0
> @@ -63,13 +64,31 @@ package org.apache.flex.html
>                  *  @productversion FlexJS 0.0
>           *  @flexjsignorecoercion org.apache.flex.core.IImageModel
>                  */
> -               public function get source():String
> +               public function get url():String
>                 {
> -                       return (model as IImageModel).source;
> +                       return (model as IImageModel).url;
>                 }
> -               public function set source(value:String):void
> +               public function set url(value:String):void
>                 {
> -                       (model as IImageModel).source = value;
> +                       (model as IImageModel).url = value;
> +               }
> +
> +               /**
> +                *  The binary bitmap data.
> +                *
> +                *  @langversion 3.0
> +                *  @playerversion Flash 10.2
> +                *  @playerversion AIR 2.6
> +                *  @productversion FlexJS 0.0
> +         *  @flexjsignorecoercion org.apache.flex.core.IImageModel
> +                */
> +               public function get binary():BinaryData
> +               {
> +                       return (model as IImageModel).binary;
> +               }
> +               public function set binary(value:BinaryData):void
> +               {
> +                       (model as IImageModel).binary = value;
>                 }
> 
>          /**
> 
> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c5a470bf/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/ImageView.as
> ----------------------------------------------------------------------
> diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/ImageView.as
b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/ImageView.as
> index 77c970a..8533d02 100644
> --- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/ImageView.as
> +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/ImageView.as
> @@ -29,6 +29,7 @@ package org.apache.flex.html.beads
>      COMPILE::JS
>      {
>          import goog.events;
> +        import org.apache.flex.utils.URLUtils;
>      }
> 
>         import org.apache.flex.core.BeadViewBase;
> @@ -39,6 +40,7 @@ package org.apache.flex.html.beads
>         import org.apache.flex.core.UIBase;
>         import org.apache.flex.events.Event;
>         import org.apache.flex.events.IEventDispatcher;
> +    import org.apache.flex.utils.BinaryData;
> 
>         /**
>          *  The ImageView class creates the visual elements of the org.apache.flex.html.Image
component.
> @@ -68,6 +70,7 @@ package org.apache.flex.html.beads
>                 private var loader:Loader;
> 
>                 private var _model:IImageModel;
> +        private var _objectURL:String;
> 
>                 /**
>                  *  @copy org.apache.flex.core.IBead#strand
> @@ -101,25 +104,40 @@ package org.apache.flex.html.beads
>                 {
>              COMPILE::SWF
>              {
> -                if (_model.source) {
> +                if (_model.url || model.binary) {
>                      loader = new Loader();
>                      loader.contentLoaderInfo.addEventListener("complete",onComplete);
>                      loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,
function (e:IOErrorEvent):void {
>                          trace(e);
>                          e.preventDefault();
>                      });
> -                    loader.load(new URLRequest(_model.source));
> +                    if(model.url)
> +                        loader.load(new URLRequest(_model.url));
> +                    else
> +                    loader.loadBytes(_model.binary.array);
>                  }
>              }
>              COMPILE::JS
>              {
> -                               if (_model.source) {
> +                               if (_model.url || model.binary) {
>                         var host:IUIBase = _strand as IUIBase;
>                         (host.element as HTMLImageElement).addEventListener('load',
>                             loadHandler, false);
>                         host.addEventListener('sizeChanged',
>                             sizeChangedHandler);
> -                       (host.element as HTMLImageElement).src = _model.source;
> +                    var urlStr:String = _model.url;
> +
> +                    if(_model.binary)
> +                    {
> +                        if(_objectURL)
> +                            URLUtils.revokeObjectURL(_objectURL);
> +                    var blob:Blob = new Blob([_model.binary.array]);
> +// I don't think we need to specify the type.
> +//                    var blob = new Blob([response], {type: "image/png"});
> +                    _objectURL = URLUtils.createObjectURL(blob);
> +                        urlStr = _objectURL
> +                    }
> +                       (host.element as HTMLImageElement).src = urlStr;
>                                 }
>              }
>                 }
> 
> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c5a470bf/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/models/ImageModel.as
> ----------------------------------------------------------------------
> diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/models/ImageModel.as
b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/models/ImageModel.as
> index 7742c2b..91155d9 100644
> --- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/models/ImageModel.as
> +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/models/ImageModel.as
> @@ -22,6 +22,7 @@ package org.apache.flex.html.beads.models
>         import org.apache.flex.core.IStrand;
>         import org.apache.flex.events.Event;
>         import org.apache.flex.events.EventDispatcher;
> +    import org.apache.flex.utils.BinaryData;
> 
>         /**
>          *  The ImageModel class bead defines the data associated with an org.apache.flex.html.Image
> @@ -62,26 +63,55 @@ package org.apache.flex.html.beads.models
>                         _strand = value;
>                 }
> 
> -               private var _source:String;
> +               private var _url:String;
> 
>                 /**
> -                *  The source of the image.
> +                *  The url of the image.
>                  *
> -                *  @copy org.apache.flex.core.IImageModel#source
> +                *  @copy org.apache.flex.core.IImageModel#url
>                  *
>                  *  @langversion 3.0
>                  *  @playerversion Flash 10.2
>                  *  @playerversion AIR 2.6
>                  *  @productversion FlexJS 0.0
>                  */
> -               public function get source():String
> +               public function get url():String
>                 {
> -                       return _source;
> +                       return _url;
>                 }
> -               public function set source(value:String):void
> +               public function set url(value:String):void
>                 {
> -                       if (value != _source) {
> -                               _source = value;
> +                       if (value != _url) {
> +                               _url = value;
> +                               if(value)
> +                                       _binary = null;
> +                               dispatchEvent( new Event("urlChanged") );
> +                       }
> +               }
> +
> +               private var _binary:BinaryData;
> +
> +               /**
> +                *  The BinaryData of the image.
> +                *  This is used to set the image using binary content retrieved using
HTTP requests or File APIs.
> +                *
> +                *  @copy org.apache.flex.core.IImageModel#binary
> +                *
> +                *  @langversion 3.0
> +                *  @playerversion Flash 10.2
> +                *  @playerversion AIR 2.6
> +                *  @productversion FlexJS 0.0
> +                */
> +               public function get binary():BinaryData
> +               {
> +                       return _binary;
> +               }
> +               public function set binary(value:BinaryData):void
> +               {
> +                       if (value != _binary) {
> +                               _binary = value;
> +                               if(value)
> +                                       _url = "";
>                                 dispatchEvent( new Event("urlChanged") );
>                         }
>                 }
> 
> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c5a470bf/manualtests/ContainerTest/src/products/ProductItemRenderer.as
> ----------------------------------------------------------------------
> diff --git a/manualtests/ContainerTest/src/products/ProductItemRenderer.as b/manualtests/ContainerTest/src/products/ProductItemRenderer.as
> index f7ca68b..5cb47c9 100644
> --- a/manualtests/ContainerTest/src/products/ProductItemRenderer.as
> +++ b/manualtests/ContainerTest/src/products/ProductItemRenderer.as
> @@ -57,7 +57,7 @@ package products
>                 {
>                         super.data = value;
> 
> -                       image.source = data.image;
> +                       image.url = data.image;
>                         title.text = data.title;
>                         detail.text = data.detail;
>                 }
> 
> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c5a470bf/manualtests/ListsTest/src/products/ProductItemRenderer.as
> ----------------------------------------------------------------------
> diff --git a/manualtests/ListsTest/src/products/ProductItemRenderer.as b/manualtests/ListsTest/src/products/ProductItemRenderer.as
> index c1bab26..2983149 100644
> --- a/manualtests/ListsTest/src/products/ProductItemRenderer.as
> +++ b/manualtests/ListsTest/src/products/ProductItemRenderer.as
> @@ -57,7 +57,7 @@ package products
>                 {
>                         super.data = value;
> 
> -                       image.source = data.image;
> +                       image.url = data.image;
>                         title.text = data.title;
>                         detail.text = data.detail;
>                 }
> 


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message