]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/gfx/AlphaAdjustmentImageDescriptor.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.utils.ui / src / org / simantics / utils / ui / gfx / AlphaAdjustmentImageDescriptor.java
index 104dd88c7c8db4023d51ed30cce98418c23939d8..80b39a73bfe6e5abc855b87b8265e4c9157aec16 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-/*\r
- * 22.12.2006\r
- */\r
-package org.simantics.utils.ui.gfx;\r
-\r
-import org.eclipse.jface.resource.ImageDescriptor;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.graphics.ImageData;\r
-\r
-/**\r
- * AlphaAdjustmentImageDescriptor multiplies alpha by (adjustment value/256)\r
- * <p>\r
- * Usage:\r
- * ImageDescriptor icon;\r
- * icon = AlphaAdjustmentImageDescriptor.adjustAlpha(icon, 128);\r
- * \r
- * @author Toni Kalajainen\r
- */\r
-public class AlphaAdjustmentImageDescriptor extends ImageDescriptor {\r
-    \r
-    public static ImageDescriptor adjustAlpha(ImageDescriptor desc, int alphaAdjustment)\r
-    {\r
-        if (alphaAdjustment==256) return desc;\r
-        return new AlphaAdjustmentImageDescriptor(desc, alphaAdjustment);\r
-    }\r
-    \r
-    int alphaAdjustment;\r
-    ImageDescriptor desc;\r
-    \r
-    /**\r
-     * \r
-     * @param original\r
-     * @param alphaAdjustment 0..256\r
-     */\r
-    public AlphaAdjustmentImageDescriptor(ImageDescriptor original, int alphaAdjustment)\r
-    {\r
-        assert(alphaAdjustment>=0 && alphaAdjustment<=256);\r
-        assert(original!=null);\r
-        this.alphaAdjustment = alphaAdjustment;\r
-        this.desc = original;\r
-    }\r
-\r
-    @SuppressWarnings("deprecation")\r
-    @Override\r
-    public ImageData getImageData() {\r
-        ImageData orig = ImageCache.getInstance().getImage(desc).getImageData();\r
-        ImageData id = new ImageData(orig.width, orig.height, orig.depth, orig.palette);\r
-        id.setAlpha(0,0,0);\r
-        \r
-        if (orig.getTransparencyType()==SWT.TRANSPARENCY_ALPHA ||\r
-            orig.getTransparencyType()==SWT.TRANSPARENCY_NONE)\r
-        {\r
-            for (int x=0; x<orig.width; x++)\r
-                for (int y=0; y<orig.height; y++) {\r
-                    id.setPixel(x, y, orig.getPixel(x, y));\r
-                    int alpha = (orig.getAlpha(x, y) * alphaAdjustment) >> 8;\r
-                    id.setAlpha(x, y, alpha);\r
-                }\r
-        } else\r
-        if (orig.getTransparencyType()==SWT.TRANSPARENCY_MASK ||\r
-            orig.getTransparencyType()==SWT.TRANSPARENCY_PIXEL) {\r
-            ImageData mask = orig.getTransparencyMask();\r
-            for (int x=0; x<orig.width; x++)\r
-                for (int y=0; y<orig.height; y++) {\r
-                    id.setPixel(x, y, orig.getPixel(x, y));\r
-                    int alpha = (mask.getPixel(x, y)==1?alphaAdjustment:0);\r
-                    id.setAlpha(x, y, alpha);\r
-                }\r
-        }\r
-        \r
-        return id;\r
-    }\r
-    \r
-    @Override\r
-    public boolean equals(Object obj) {\r
-        if (!(obj instanceof AlphaAdjustmentImageDescriptor))\r
-            return false;\r
-        AlphaAdjustmentImageDescriptor other = (AlphaAdjustmentImageDescriptor) obj;\r
-        if (!other.desc.equals(desc))\r
-            return false;\r
-        if (other.alphaAdjustment!=alphaAdjustment)\r
-            return false;\r
-        return true;\r
-    }\r
-    \r
-    @Override\r
-    public int hashCode() {\r
-        return desc.hashCode() ^ 0x58fb2 ^ alphaAdjustment;\r
-    }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+/*
+ * 22.12.2006
+ */
+package org.simantics.utils.ui.gfx;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.ImageData;
+
+/**
+ * AlphaAdjustmentImageDescriptor multiplies alpha by (adjustment value/256)
+ * <p>
+ * Usage:
+ * ImageDescriptor icon;
+ * icon = AlphaAdjustmentImageDescriptor.adjustAlpha(icon, 128);
+ * 
+ * @author Toni Kalajainen
+ */
+public class AlphaAdjustmentImageDescriptor extends ImageDescriptor {
+    
+    public static ImageDescriptor adjustAlpha(ImageDescriptor desc, int alphaAdjustment)
+    {
+        if (alphaAdjustment==256) return desc;
+        return new AlphaAdjustmentImageDescriptor(desc, alphaAdjustment);
+    }
+    
+    int alphaAdjustment;
+    ImageDescriptor desc;
+    
+    /**
+     * 
+     * @param original
+     * @param alphaAdjustment 0..256
+     */
+    public AlphaAdjustmentImageDescriptor(ImageDescriptor original, int alphaAdjustment)
+    {
+        assert(alphaAdjustment>=0 && alphaAdjustment<=256);
+        assert(original!=null);
+        this.alphaAdjustment = alphaAdjustment;
+        this.desc = original;
+    }
+
+    @SuppressWarnings("deprecation")
+    @Override
+    public ImageData getImageData() {
+        ImageData orig = ImageCache.getInstance().getImage(desc).getImageData();
+        ImageData id = new ImageData(orig.width, orig.height, orig.depth, orig.palette);
+        id.setAlpha(0,0,0);
+        
+        if (orig.getTransparencyType()==SWT.TRANSPARENCY_ALPHA ||
+            orig.getTransparencyType()==SWT.TRANSPARENCY_NONE)
+        {
+            for (int x=0; x<orig.width; x++)
+                for (int y=0; y<orig.height; y++) {
+                    id.setPixel(x, y, orig.getPixel(x, y));
+                    int alpha = (orig.getAlpha(x, y) * alphaAdjustment) >> 8;
+                    id.setAlpha(x, y, alpha);
+                }
+        } else
+        if (orig.getTransparencyType()==SWT.TRANSPARENCY_MASK ||
+            orig.getTransparencyType()==SWT.TRANSPARENCY_PIXEL) {
+            ImageData mask = orig.getTransparencyMask();
+            for (int x=0; x<orig.width; x++)
+                for (int y=0; y<orig.height; y++) {
+                    id.setPixel(x, y, orig.getPixel(x, y));
+                    int alpha = (mask.getPixel(x, y)==1?alphaAdjustment:0);
+                    id.setAlpha(x, y, alpha);
+                }
+        }
+        
+        return id;
+    }
+    
+    @Override
+    public boolean equals(Object obj) {
+        if (!(obj instanceof AlphaAdjustmentImageDescriptor))
+            return false;
+        AlphaAdjustmentImageDescriptor other = (AlphaAdjustmentImageDescriptor) obj;
+        if (!other.desc.equals(desc))
+            return false;
+        if (other.alphaAdjustment!=alphaAdjustment)
+            return false;
+        return true;
+    }
+    
+    @Override
+    public int hashCode() {
+        return desc.hashCode() ^ 0x58fb2 ^ alphaAdjustment;
+    }
+
+}