< prev index next >

core/JemmyCore/src/org/jemmy/image/pixel/ResizeComparator.java

Print this page




  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package org.jemmy.image.pixel;
  26 
  27 import org.jemmy.Dimension;
  28 import org.jemmy.image.Image;
  29 import org.jemmy.image.ImageComparator;
  30 
  31 /**
  32  *
  33  * @author shura
  34  */
  35 public abstract class ResizeComparator implements ImageComparator {
  36 
  37     private ImageComparator subComparator;
  38     private Mode mode;
  39 
  40     /**
  41      *
  42      */
  43     public enum Mode {
  44 
  45         /**
  46          *
  47          */
  48         LEFT,
  49         /**
  50          *
  51          */
  52         RIGTH,
  53         /**
  54          *
  55          */
  56         MAX
  57     };
  58 
  59     /**
  60      *
  61      * @param subComparator
  62      * @param mode
  63      */
  64     public ResizeComparator(ImageComparator subComparator, Mode mode) {
  65         this.subComparator = subComparator;
  66         this.mode = mode;
  67     }
  68 
  69     /**
  70      *
  71      * @param subComparator
  72      */
  73     public ResizeComparator(ImageComparator subComparator) {
  74         this(subComparator, Mode.MAX);
  75     }
  76 
  77     /**
  78      *
  79      * @return
  80      */
  81     public ImageComparator getSubComparator() {
  82         return subComparator;
  83     }
  84 
  85     /**
  86      *
  87      * @param subComparator
  88      */
  89     public void setSubComparator(ImageComparator subComparator) {
  90         this.subComparator = subComparator;
  91     }
  92 
  93     /**
  94      *
  95      * @param image1
  96      * @param image2
  97      * @return
  98      */
  99     public Image compare(Image image1, Image image2) {
 100         if(image1 == null || image2 == null) {
 101             return (image1 == null) ? image2 : image1;
 102         }
 103         Dimension size;
 104         switch (mode) {
 105             case LEFT:
 106                 size = getSize(image1);
 107                 break;
 108             case RIGTH:
 109                 size = getSize(image2);
 110                 break;
 111             case MAX:
 112                 Dimension size1 = getSize(image1);
 113                 Dimension size2 = getSize(image2);
 114                 size = new Dimension(Math.max(size1.width, size2.width),
 115                         Math.max(size1.height, size2.height));
 116                 break;
 117             default:
 118                 throw new IllegalStateException("mode is not recognized");
 119         }
 120         Image r1 = resize(image1, size);
 121         Image r2 = resize(image2, size);
 122         if(r1 == null) {
 123             return image1;
 124         }
 125         if(r2 == null) {
 126             return image2;
 127         }
 128         return subComparator.compare(r1, r2);
 129     }
 130 
 131     /**
 132      *
 133      * @param image
 134      * @param size
 135      * @return
 136      */
 137     abstract public Image resize(Image image, Dimension size);
 138 
 139     /**
 140      *
 141      * @param image
 142      * @return
 143      */
 144     abstract public Dimension getSize(Image image);
 145 
 146     /**
 147      *
 148      * @return
 149      */
 150     public String getID() {
 151         return ResizeComparator.class.getName() + "(" + subComparator.getID() + ")";
 152     }
 153 }


  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package org.jemmy.image.pixel;
  26 
  27 import org.jemmy.Dimension;
  28 import org.jemmy.image.Image;
  29 import org.jemmy.image.ImageComparator;
  30 
  31 /**

  32  * @author shura
  33  */
  34 public abstract class ResizeComparator implements ImageComparator {
  35 
  36     private ImageComparator subComparator;
  37     private Mode mode;
  38 



  39     public enum Mode {




  40         LEFT,



  41         RIGTH,



  42         MAX
  43     };
  44 





  45     public ResizeComparator(ImageComparator subComparator, Mode mode) {
  46         this.subComparator = subComparator;
  47         this.mode = mode;
  48     }
  49 




  50     public ResizeComparator(ImageComparator subComparator) {
  51         this(subComparator, Mode.MAX);
  52     }
  53 




  54     public ImageComparator getSubComparator() {
  55         return subComparator;
  56     }
  57 




  58     public void setSubComparator(ImageComparator subComparator) {
  59         this.subComparator = subComparator;
  60     }
  61 






  62     public Image compare(Image image1, Image image2) {
  63         if(image1 == null || image2 == null) {
  64             return (image1 == null) ? image2 : image1;
  65         }
  66         Dimension size;
  67         switch (mode) {
  68             case LEFT:
  69                 size = getSize(image1);
  70                 break;
  71             case RIGTH:
  72                 size = getSize(image2);
  73                 break;
  74             case MAX:
  75                 Dimension size1 = getSize(image1);
  76                 Dimension size2 = getSize(image2);
  77                 size = new Dimension(Math.max(size1.width, size2.width),
  78                         Math.max(size1.height, size2.height));
  79                 break;
  80             default:
  81                 throw new IllegalStateException("mode is not recognized");
  82         }
  83         Image r1 = resize(image1, size);
  84         Image r2 = resize(image2, size);
  85         if(r1 == null) {
  86             return image1;
  87         }
  88         if(r2 == null) {
  89             return image2;
  90         }
  91         return subComparator.compare(r1, r2);
  92     }
  93 






  94     abstract public Image resize(Image image, Dimension size);
  95 





  96     abstract public Dimension getSize(Image image);
  97 




  98     public String getID() {
  99         return ResizeComparator.class.getName() + "(" + subComparator.getID() + ")";
 100     }
 101 }
< prev index next >