More and more often I come across existing web-graphics that needs to be reused in desktop-applications. Webdesigners are gradually shifting towards creating a sprite containing multiple images and using css to choose which image to show.

I would like to propose a small change to ImageView to support this behavior, so that one can easier reuse existing web-graphics in desktop-applications. Provided is a patch that shows what I mean.

Here is an example of it's usage. Take a look at the following picture:

http://askjems.no/files/gfx/viewmodes_sprite.png

Showing the first "icon" in this image can be done by restricting the maximum height to the height of each "icon":

int iconHeight = 27;
imageView.setPreferredHeight(iconHeight);

My patch will allow you to do this to show the second "icon":

imageView.getStyles().put("offsetY", iconHeight);

Third icon:

imageView.getStyles().put("offsetY", iconHeight * 2);

offsetX is also supported, for multi column sprites. Does that make sense/look valuable?

-- Edvin
Index: wtk/src/org/apache/pivot/wtk/skin/ImageViewSkin.java
===================================================================
--- wtk/src/org/apache/pivot/wtk/skin/ImageViewSkin.java        (revision 
997279)
+++ wtk/src/org/apache/pivot/wtk/skin/ImageViewSkin.java        (revision )
@@ -49,6 +49,8 @@
 
     private int imageX = 0;
     private int imageY = 0;
+    private int offsetX = 0;
+    private int offsetY = 0;
     private float scaleX = 1;
     private float scaleY = 1;
 
@@ -248,6 +250,8 @@
                 
imageGraphics.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 
opacity));
             }
 
+            if (offsetX != 0 || offsetY != 0)
+                imageGraphics.translate(offsetX * -1, offsetY * -1);
             image.paint(imageGraphics);
             imageGraphics.dispose();
         }
@@ -334,6 +338,22 @@
         repaintComponent();
     }
 
+    public int getOffsetX() {
+        return offsetX;
+    }
+
+    public void setOffsetX(int offsetX) {
+        this.offsetX = offsetX;
+    }
+
+    public int getOffsetY() {
+        return offsetY;
+    }
+
+    public void setOffsetY(int offsetY) {
+        this.offsetY = offsetY;
+    }
+
     public boolean getFill() {
         return fill;
     }

Reply via email to