You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@royale.apache.org by GitBox <gi...@apache.org> on 2020/07/02 01:33:31 UTC

[GitHub] [royale-asjs] mjesteve opened a new pull request #880: ErrorImage Bead for IImage implement

mjesteve opened a new pull request #880:
URL: https://github.com/apache/royale-asjs/pull/880


   The ErrorImage class is a bead that can be used to display an alternate image, in the event that the specified image cannot be loaded.
   It will be supported by controls that load the ImageModel bead and implement the IImage interface.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [royale-asjs] yishayw commented on a change in pull request #880: ErrorImage Bead for IImage implement

Posted by GitBox <gi...@apache.org>.
yishayw commented on a change in pull request #880:
URL: https://github.com/apache/royale-asjs/pull/880#discussion_r448796915



##########
File path: frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/ErrorImage.as
##########
@@ -0,0 +1,151 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.royale.html.beads {
+
+    import org.apache.royale.core.IBead;
+    import org.apache.royale.core.IStrand;
+    import org.apache.royale.events.Event;
+
+    import org.apache.royale.events.EventDispatcher;
+	import org.apache.royale.core.IImage;
+    import org.apache.royale.core.IImageModel;
+  
+  /**
+	 *  The ErrorImage class is a bead that can be used to 
+     *  display an alternate image, in the event that the specified image 
+     *  cannot be loaded.
+     * 
+     *  It will be supported by controls that load the ImageModel bead and 
+     *  implement the IImage interface
+	 *  
+	 *  @langversion 3.0
+	 *  @playerversion Flash 10.2
+	 *  @playerversion AIR 2.6
+	 *  @productversion Royale 0.9.8
+	 */
+
+    public class ErrorImage implements IBead {
+
+        protected var _strand:IStrand;
+
+        public function ErrorImage() {            
+        }
+
+        private var _src:String;
+		/**
+		 *  The source of the image
+		 */
+        public function get src():String {
+            return _src;
+        }
+
+        public function set src(value:String):void {
+            _src = value;
+        }
+        
+		COMPILE::JS{
+        private var _hostElement:HTMLImageElement;
+		protected function get hostElement():HTMLImageElement
+		{
+			return _hostElement;
+		}
+        }
+        protected function get hostModel():IImageModel
+        {             
+            return _strand.getBeadByType(IImageModel) as IImageModel;
+        }
+
+        /**
+         *  @copy org.apache.royale.core.IBead#strand
+         *
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.9.8
+         */
+        public function set strand(value:IStrand):void 
+        {
+            _strand = value;
+
+	        COMPILE::JS {
+
+                if(_strand is IImage)
+                {
+                    _hostElement = (_strand as IImage).imageElement as HTMLImageElement;
+                    if(_hostElement){
+                        
+                        _hostElement.addEventListener('error', errorHandler);
+
+                        if(_emptyIsError)
+                        {
+                            (_strand as EventDispatcher).addEventListener("beadsAdded", beadsAddedHandler);
+                        }
+                    }   
+                }
+            }
+        }
+
+		COMPILE::JS
+        private function beadsAddedHandler(event:Event):void
+        {
+            (_strand as EventDispatcher).removeEventListener("beadsAdded", beadsAddedHandler);
+
+            if(hostModel)
+                hostModel.addEventListener("urlChanged",srcChangedHandler);
+            srcChangedHandler(null);
+        }
+
+        private var _emptyIsError:Boolean = false;

Review comment:
       pulic attributes should be documented

##########
File path: frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/ErrorImage.as
##########
@@ -0,0 +1,151 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.royale.html.beads {
+
+    import org.apache.royale.core.IBead;
+    import org.apache.royale.core.IStrand;
+    import org.apache.royale.events.Event;
+
+    import org.apache.royale.events.EventDispatcher;
+	import org.apache.royale.core.IImage;
+    import org.apache.royale.core.IImageModel;
+  
+  /**
+	 *  The ErrorImage class is a bead that can be used to 
+     *  display an alternate image, in the event that the specified image 
+     *  cannot be loaded.
+     * 
+     *  It will be supported by controls that load the ImageModel bead and 
+     *  implement the IImage interface
+	 *  
+	 *  @langversion 3.0
+	 *  @playerversion Flash 10.2
+	 *  @playerversion AIR 2.6
+	 *  @productversion Royale 0.9.8
+	 */
+
+    public class ErrorImage implements IBead {
+
+        protected var _strand:IStrand;
+
+        public function ErrorImage() {            
+        }
+
+        private var _src:String;
+		/**
+		 *  The source of the image
+		 */
+        public function get src():String {
+            return _src;
+        }
+
+        public function set src(value:String):void {
+            _src = value;
+        }
+        
+		COMPILE::JS{
+        private var _hostElement:HTMLImageElement;
+		protected function get hostElement():HTMLImageElement
+		{
+			return _hostElement;
+		}
+        }
+        protected function get hostModel():IImageModel
+        {             
+            return _strand.getBeadByType(IImageModel) as IImageModel;
+        }
+
+        /**
+         *  @copy org.apache.royale.core.IBead#strand
+         *
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.9.8
+         */
+        public function set strand(value:IStrand):void 
+        {
+            _strand = value;
+
+	        COMPILE::JS {
+
+                if(_strand is IImage)
+                {
+                    _hostElement = (_strand as IImage).imageElement as HTMLImageElement;
+                    if(_hostElement){
+                        
+                        _hostElement.addEventListener('error', errorHandler);
+
+                        if(_emptyIsError)
+                        {
+                            (_strand as EventDispatcher).addEventListener("beadsAdded", beadsAddedHandler);
+                        }
+                    }   
+                }
+            }
+        }
+
+		COMPILE::JS
+        private function beadsAddedHandler(event:Event):void
+        {
+            (_strand as EventDispatcher).removeEventListener("beadsAdded", beadsAddedHandler);
+
+            if(hostModel)
+                hostModel.addEventListener("urlChanged",srcChangedHandler);
+            srcChangedHandler(null);
+        }
+
+        private var _emptyIsError:Boolean = false;
+        public function get emptyIsError():Boolean {
+            return _emptyIsError;
+        }
+        public function set emptyIsError(value:Boolean):void {
+            _emptyIsError = value;
+        }
+
+		COMPILE::JS
+        private function errorHandler(event:Event):void {
+        
+            if (hostElement.src != _src)
+            {
+                hostElement.src = _src;
+            }
+        }
+		
+        private function srcChangedHandler(event:Event):void
+        {
+            if(hostModel && !hostModel.url){
+                
+                COMPILE::JS {

Review comment:
       COMPILE::JS blocks are generally used for platform specific operations. In this case it doesn't look like there's anything js specific in the block.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [royale-asjs] mjesteve commented on pull request #880: ErrorImage Bead for IImage implement

Posted by GitBox <gi...@apache.org>.
mjesteve commented on pull request #880:
URL: https://github.com/apache/royale-asjs/pull/880#issuecomment-653091188


   Do I cancel this branch and put all the changes in the PR of 881?
   Pending:
   - addEventListener 'addbead': As I was saying, the addToParent, in UIBase, loads "first the beads added directly in the mxml tag" and then loads the model. At that point in the code the model is not loaded yet. What am I doing wrong? (I'm going to ask it in the list because I've been looking at it and I don't see any other option)
   
   - COMPILE: JS {}: I try to detect the rest.
   
   Thank you.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [royale-asjs] yishayw commented on pull request #880: ErrorImage Bead for IImage implement

Posted by GitBox <gi...@apache.org>.
yishayw commented on pull request #880:
URL: https://github.com/apache/royale-asjs/pull/880#issuecomment-653500944


   I see. In that case listening to the beadsAdded event makes sense. Sorry for the noise.
   ________________________________
   From: mjesteve <no...@github.com>
   Sent: Thursday, July 2, 2020 3:57 PM
   To: apache/royale-asjs <ro...@noreply.github.com>
   Cc: yishayw <yi...@hotmail.com>; Review requested <re...@noreply.github.com>
   Subject: Re: [apache/royale-asjs] ErrorImage Bead for IImage implement (#880)
   
   
   Do I cancel this branch and put all the changes in the PR of 881?
   Pending:
   
     *   addEventListener 'addbead': As I was saying, the addToParent, in UIBase, loads "first the beads added directly in the mxml tag" and then loads the model. At that point in the code the model is not loaded yet. What am I doing wrong? (I'm going to ask it in the list because I've been looking at it and I don't see any other option)
   
     *   COMPILE: JS {}: I try to detect the rest.
   
   Thank you.
   
   —
   You are receiving this because your review was requested.
   Reply to this email directly, view it on GitHub<https://github.com/apache/royale-asjs/pull/880#issuecomment-653091188>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAQBE7KQHHKHVT2SJ3BVRJ3RZSU7NANCNFSM4OOLOOMQ>.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [royale-asjs] carlosrovira commented on pull request #880: ErrorImage Bead for IImage implement

Posted by GitBox <gi...@apache.org>.
carlosrovira commented on pull request #880:
URL: https://github.com/apache/royale-asjs/pull/880#issuecomment-652880892


   Hi just saw there's another PR #881, should we close this one?
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [royale-asjs] yishayw merged pull request #880: ErrorImage Bead for IImage implement

Posted by GitBox <gi...@apache.org>.
yishayw merged pull request #880:
URL: https://github.com/apache/royale-asjs/pull/880


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [royale-asjs] yishayw commented on a change in pull request #880: ErrorImage Bead for IImage implement

Posted by GitBox <gi...@apache.org>.
yishayw commented on a change in pull request #880:
URL: https://github.com/apache/royale-asjs/pull/880#discussion_r448784635



##########
File path: frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/ErrorImage.as
##########
@@ -0,0 +1,151 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.royale.html.beads {
+
+    import org.apache.royale.core.IBead;
+    import org.apache.royale.core.IStrand;
+    import org.apache.royale.events.Event;
+
+    import org.apache.royale.events.EventDispatcher;
+	import org.apache.royale.core.IImage;
+    import org.apache.royale.core.IImageModel;
+  
+  /**
+	 *  The ErrorImage class is a bead that can be used to 
+     *  display an alternate image, in the event that the specified image 
+     *  cannot be loaded.
+     * 
+     *  It will be supported by controls that load the ImageModel bead and 
+     *  implement the IImage interface
+	 *  
+	 *  @langversion 3.0
+	 *  @playerversion Flash 10.2
+	 *  @playerversion AIR 2.6
+	 *  @productversion Royale 0.9.8
+	 */
+
+    public class ErrorImage implements IBead {
+
+        protected var _strand:IStrand;
+
+        public function ErrorImage() {            
+        }
+
+        private var _src:String;
+		/**
+		 *  The source of the image
+		 */
+        public function get src():String {
+            return _src;
+        }
+
+        public function set src(value:String):void {
+            _src = value;
+        }
+        
+		COMPILE::JS{
+        private var _hostElement:HTMLImageElement;
+		protected function get hostElement():HTMLImageElement
+		{
+			return _hostElement;
+		}
+        }
+        protected function get hostModel():IImageModel
+        {             
+            return _strand.getBeadByType(IImageModel) as IImageModel;
+        }
+
+        /**
+         *  @copy org.apache.royale.core.IBead#strand
+         *
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.9.8
+         */
+        public function set strand(value:IStrand):void 
+        {
+            _strand = value;
+
+	        COMPILE::JS {
+
+                if(_strand is IImage)
+                {
+                    _hostElement = (_strand as IImage).imageElement as HTMLImageElement;
+                    if(_hostElement){
+                        
+                        _hostElement.addEventListener('error', errorHandler);
+
+                        if(_emptyIsError)
+                        {
+                            (_strand as EventDispatcher).addEventListener("beadsAdded", beadsAddedHandler);

Review comment:
       Listening to "beadsAdded" is only necessary if this bead is added before its dependencies, in this case the strand's model. Model is usually the first bead to be loaded anyway so this can be simplified by copying the code from beadsAddedHandler here instead.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [royale-asjs] yishayw commented on a change in pull request #880: ErrorImage Bead for IImage implement

Posted by GitBox <gi...@apache.org>.
yishayw commented on a change in pull request #880:
URL: https://github.com/apache/royale-asjs/pull/880#discussion_r448920597



##########
File path: frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/ErrorImage.as
##########
@@ -0,0 +1,151 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.royale.html.beads {
+
+    import org.apache.royale.core.IBead;
+    import org.apache.royale.core.IStrand;
+    import org.apache.royale.events.Event;
+
+    import org.apache.royale.events.EventDispatcher;
+	import org.apache.royale.core.IImage;
+    import org.apache.royale.core.IImageModel;
+  
+  /**
+	 *  The ErrorImage class is a bead that can be used to 
+     *  display an alternate image, in the event that the specified image 
+     *  cannot be loaded.
+     * 
+     *  It will be supported by controls that load the ImageModel bead and 
+     *  implement the IImage interface
+	 *  
+	 *  @langversion 3.0
+	 *  @playerversion Flash 10.2
+	 *  @playerversion AIR 2.6
+	 *  @productversion Royale 0.9.8
+	 */
+
+    public class ErrorImage implements IBead {
+
+        protected var _strand:IStrand;
+
+        public function ErrorImage() {            
+        }
+
+        private var _src:String;
+		/**
+		 *  The source of the image
+		 */
+        public function get src():String {
+            return _src;
+        }
+
+        public function set src(value:String):void {
+            _src = value;
+        }
+        
+		COMPILE::JS{
+        private var _hostElement:HTMLImageElement;
+		protected function get hostElement():HTMLImageElement
+		{
+			return _hostElement;
+		}
+        }
+        protected function get hostModel():IImageModel
+        {             
+            return _strand.getBeadByType(IImageModel) as IImageModel;
+        }
+
+        /**
+         *  @copy org.apache.royale.core.IBead#strand
+         *
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.9.8
+         */
+        public function set strand(value:IStrand):void 
+        {
+            _strand = value;
+
+	        COMPILE::JS {
+
+                if(_strand is IImage)
+                {
+                    _hostElement = (_strand as IImage).imageElement as HTMLImageElement;
+                    if(_hostElement){
+                        
+                        _hostElement.addEventListener('error', errorHandler);
+
+                        if(_emptyIsError)
+                        {
+                            (_strand as EventDispatcher).addEventListener("beadsAdded", beadsAddedHandler);
+                        }
+                    }   
+                }
+            }
+        }
+
+		COMPILE::JS
+        private function beadsAddedHandler(event:Event):void
+        {
+            (_strand as EventDispatcher).removeEventListener("beadsAdded", beadsAddedHandler);
+
+            if(hostModel)
+                hostModel.addEventListener("urlChanged",srcChangedHandler);
+            srcChangedHandler(null);
+        }
+
+        private var _emptyIsError:Boolean = false;

Review comment:
       Good start, but you need to add some annotations to make it visible to IDEs and API Docs. E.g. 
   
   		/**
   		 *  Indicates whether the "empty or null" values will be treated as errors and replaced by the indicated src
   		 *
   		 *  @langversion 3.0
   		 *  @playerversion Flash 10.2
   		 *  @playerversion AIR 2.6
   		 *  @productversion Royale 0.9.8
   		 */




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org