aboutsummaryrefslogtreecommitdiffstats
path: root/eclipse/plugins/com.android.ide.eclipse.tests/unittests
diff options
context:
space:
mode:
authorTor Norbye <tnorbye@google.com>2010-11-15 09:55:52 -0800
committerTor Norbye <tnorbye@google.com>2010-11-15 13:38:31 -0800
commit5d08915fe9014124566a2cdd7c1aa4219e01acea (patch)
tree2c25da4db7d27b0f86cd62fe6eff490dc16d0317 /eclipse/plugins/com.android.ide.eclipse.tests/unittests
parent7aa052149875bf58fe9ff3990e6e01140e983afe (diff)
downloadsdk-5d08915fe9014124566a2cdd7c1aa4219e01acea.zip
sdk-5d08915fe9014124566a2cdd7c1aa4219e01acea.tar.gz
sdk-5d08915fe9014124566a2cdd7c1aa4219e01acea.tar.bz2
Add drop shadow to dragged items
Add in a drop shadow to items dragged from the palette. The primary reason we need this is that some views (in some themes) only render light content on top of a transparent background, which makes them nearly impossible to see on a gray background (e.g. over the palette, when you initiate the drag). The drop shadow helps add contrast. It also makes the drag look better since it helps the drag preview image stand out from the background and visually appear to be lifted on top of it. Since we're doing more image processing now, I moved the existing non-SWT image manipulation methods into a separate ImageUtils class. This changeset also fixes the way we pick the color to crop out when using older layout libraries (without transparency support). We now pick a pixel closer to the bounds of the rendered view such that we for example can handle themes like the dialog theme. Change-Id: Ifcbb840ef715bf26a9609f6996a4f136de5ca754
Diffstat (limited to 'eclipse/plugins/com.android.ide.eclipse.tests/unittests')
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/ImageUtilsTest.java191
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/SwtUtilsTest.java162
2 files changed, 206 insertions, 147 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/ImageUtilsTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/ImageUtilsTest.java
new file mode 100644
index 0000000..e4ddde3
--- /dev/null
+++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/ImageUtilsTest.java
@@ -0,0 +1,191 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php
+ *
+ * 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 com.android.ide.eclipse.adt.internal.editors.layout.gle2;
+
+import com.android.ide.common.api.Rect;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.image.BufferedImage;
+
+import junit.framework.TestCase;
+
+public class ImageUtilsTest extends TestCase {
+ public void testCropBlank() throws Exception {
+ BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
+ Graphics g = image.getGraphics();
+ g.setColor(new Color(0, true));
+ g.fillRect(0, 0, image.getWidth(), image.getHeight());
+ g.dispose();
+
+ BufferedImage crop = ImageUtils.cropBlank(image, null);
+ assertNull(crop);
+ }
+
+ public void testCropBlankPre() throws Exception {
+ BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
+ Graphics g = image.getGraphics();
+ g.setColor(new Color(0, true));
+ g.fillRect(0, 0, image.getWidth(), image.getHeight());
+ g.dispose();
+
+ BufferedImage crop = ImageUtils.cropBlank(image, new Rect(5, 5, 80, 80));
+ assertNull(crop);
+ }
+
+ public void testCropNonblank() throws Exception {
+ BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
+ Graphics g = image.getGraphics();
+ g.setColor(new Color(0, false));
+ g.fillRect(0, 0, image.getWidth(), image.getHeight());
+ g.dispose();
+
+ BufferedImage crop = ImageUtils.cropBlank(image, null);
+ assertNotNull(crop);
+ assertEquals(image.getWidth(), crop.getWidth());
+ assertEquals(image.getHeight(), crop.getHeight());
+ }
+
+ public void testCropSomething() throws Exception {
+ BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
+ Graphics g = image.getGraphics();
+ g.setColor(new Color(0, true));
+ g.fillRect(0, 0, image.getWidth(), image.getHeight());
+ g.setColor(new Color(0xFF00FF00, true));
+ g.fillRect(25, 25, 50, 50);
+ g.dispose();
+
+ BufferedImage crop = ImageUtils.cropBlank(image, null);
+ assertNotNull(crop);
+ assertEquals(50, crop.getWidth());
+ assertEquals(50, crop.getHeight());
+ assertEquals(0xFF00FF00, crop.getRGB(0, 0));
+ assertEquals(0xFF00FF00, crop.getRGB(49, 49));
+ }
+
+ public void testCropSomethingPre() throws Exception {
+ BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
+ Graphics g = image.getGraphics();
+ g.setColor(new Color(0, true));
+ g.fillRect(0, 0, image.getWidth(), image.getHeight());
+ g.setColor(new Color(0xFF00FF00, true));
+ g.fillRect(25, 25, 50, 50);
+ g.dispose();
+
+ BufferedImage crop = ImageUtils.cropBlank(image, new Rect(0, 0, 100, 100));
+ assertNotNull(crop);
+ assertEquals(50, crop.getWidth());
+ assertEquals(50, crop.getHeight());
+ assertEquals(0xFF00FF00, crop.getRGB(0, 0));
+ assertEquals(0xFF00FF00, crop.getRGB(49, 49));
+ }
+
+ public void testCropSomethingPre2() throws Exception {
+ BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
+ Graphics g = image.getGraphics();
+ g.setColor(new Color(0, true));
+ g.fillRect(0, 0, image.getWidth(), image.getHeight());
+ g.setColor(new Color(0xFF00FF00, true));
+ g.fillRect(25, 25, 50, 50);
+ g.dispose();
+
+ BufferedImage crop = ImageUtils.cropBlank(image, new Rect(5, 5, 80, 80));
+ assertNotNull(crop);
+ assertEquals(50, crop.getWidth());
+ assertEquals(50, crop.getHeight());
+ assertEquals(0xFF00FF00, crop.getRGB(0, 0));
+ assertEquals(0xFF00FF00, crop.getRGB(49, 49));
+ }
+
+ public void testCropColor() throws Exception {
+ BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
+ Graphics g = image.getGraphics();
+ g.setColor(new Color(0xFF00FF00, true));
+ g.fillRect(0, 0, image.getWidth(), image.getHeight());
+ g.dispose();
+
+ BufferedImage crop = ImageUtils.cropColor(image, 0xFF00FF00, null);
+ assertNull(crop);
+ }
+
+ public void testCropNonColor() throws Exception {
+ BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
+ Graphics g = image.getGraphics();
+ g.setColor(new Color(0xFF00FF00, true));
+ g.fillRect(0, 0, image.getWidth(), image.getHeight());
+ g.dispose();
+
+ BufferedImage crop = ImageUtils.cropColor(image, 0xFFFF0000, null);
+ assertNotNull(crop);
+ assertEquals(image.getWidth(), crop.getWidth());
+ assertEquals(image.getHeight(), crop.getHeight());
+ }
+
+ public void testCropColorSomething() throws Exception {
+ BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
+ Graphics g = image.getGraphics();
+ g.setColor(new Color(0xFF00FF00, true));
+ g.fillRect(0, 0, image.getWidth(), image.getHeight());
+ g.setColor(new Color(0xFFFF0000, true));
+ g.fillRect(25, 25, 50, 50);
+ g.dispose();
+
+ BufferedImage crop = ImageUtils.cropColor(image, 0xFF00FF00, null);
+ assertEquals(50, crop.getWidth());
+ assertEquals(50, crop.getHeight());
+ assertEquals(0xFFFF0000, crop.getRGB(0, 0));
+ assertEquals(0xFFFF0000, crop.getRGB(49, 49));
+ }
+
+ public void testNullOk() throws Exception {
+ ImageUtils.cropBlank(null, null);
+ ImageUtils.cropColor(null, 0, null);
+ }
+
+
+ public void testNothingTodo() throws Exception {
+ BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
+ Graphics g = image.getGraphics();
+ g.setColor(new Color(0xFF00FF00, true));
+ g.fillRect(0, 0, image.getWidth(), image.getHeight());
+ g.dispose();
+
+ BufferedImage crop = ImageUtils.cropColor(image, 0xFFFF0000, new Rect(40, 40, 0, 0));
+ assertNull(crop);
+ }
+
+ public void testContainsDarkPixels() throws Exception {
+ BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
+ Graphics g = image.getGraphics();
+ g.setColor(new Color(0, true));
+ g.fillRect(0, 0, image.getWidth(), image.getHeight());
+ g.dispose();
+
+ assertFalse(ImageUtils.containsDarkPixels(image));
+
+ image.setRGB(50, 50, 0xFFFFFFFF);
+ assertFalse(ImageUtils.containsDarkPixels(image));
+ image.setRGB(50, 50, 0xFFAAAAAA);
+ assertFalse(ImageUtils.containsDarkPixels(image));
+ image.setRGB(50, 50, 0xFF00FF00);
+ assertFalse(ImageUtils.containsDarkPixels(image));
+ image.setRGB(50, 50, 0xFFFF8800);
+ assertFalse(ImageUtils.containsDarkPixels(image));
+ image.setRGB(50, 50, 0xFF333333);
+ assertTrue(ImageUtils.containsDarkPixels(image));
+
+ }
+}
diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/SwtUtilsTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/SwtUtilsTest.java
index 30bb82e..e383796 100644
--- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/SwtUtilsTest.java
+++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/SwtUtilsTest.java
@@ -16,8 +16,6 @@
package com.android.ide.eclipse.adt.internal.editors.layout.gle2;
-import com.android.ide.common.api.Rect;
-
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.widgets.Display;
@@ -30,136 +28,6 @@ import java.awt.image.BufferedImage;
import junit.framework.TestCase;
public class SwtUtilsTest extends TestCase {
- public void testCropBlank() throws Exception {
- BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
- Graphics g = image.getGraphics();
- g.setColor(new Color(0, true));
- g.fillRect(0, 0, image.getWidth(), image.getHeight());
- g.dispose();
-
- BufferedImage crop = SwtUtils.cropBlank(image, null);
- assertNull(crop);
- }
-
- public void testCropBlankPre() throws Exception {
- BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
- Graphics g = image.getGraphics();
- g.setColor(new Color(0, true));
- g.fillRect(0, 0, image.getWidth(), image.getHeight());
- g.dispose();
-
- BufferedImage crop = SwtUtils.cropBlank(image, new Rect(5, 5, 80, 80));
- assertNull(crop);
- }
-
- public void testCropNonblank() throws Exception {
- BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
- Graphics g = image.getGraphics();
- g.setColor(new Color(0, false));
- g.fillRect(0, 0, image.getWidth(), image.getHeight());
- g.dispose();
-
- BufferedImage crop = SwtUtils.cropBlank(image, null);
- assertNotNull(crop);
- assertEquals(image.getWidth(), crop.getWidth());
- assertEquals(image.getHeight(), crop.getHeight());
- }
-
- public void testCropSomething() throws Exception {
- BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
- Graphics g = image.getGraphics();
- g.setColor(new Color(0, true));
- g.fillRect(0, 0, image.getWidth(), image.getHeight());
- g.setColor(new Color(0xFF00FF00, true));
- g.fillRect(25, 25, 50, 50);
- g.dispose();
-
- BufferedImage crop = SwtUtils.cropBlank(image, null);
- assertNotNull(crop);
- assertEquals(50, crop.getWidth());
- assertEquals(50, crop.getHeight());
- assertEquals(0xFF00FF00, crop.getRGB(0, 0));
- assertEquals(0xFF00FF00, crop.getRGB(49, 49));
- }
-
- public void testCropSomethingPre() throws Exception {
- BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
- Graphics g = image.getGraphics();
- g.setColor(new Color(0, true));
- g.fillRect(0, 0, image.getWidth(), image.getHeight());
- g.setColor(new Color(0xFF00FF00, true));
- g.fillRect(25, 25, 50, 50);
- g.dispose();
-
- BufferedImage crop = SwtUtils.cropBlank(image, new Rect(0, 0, 100, 100));
- assertNotNull(crop);
- assertEquals(50, crop.getWidth());
- assertEquals(50, crop.getHeight());
- assertEquals(0xFF00FF00, crop.getRGB(0, 0));
- assertEquals(0xFF00FF00, crop.getRGB(49, 49));
- }
-
- public void testCropSomethingPre2() throws Exception {
- BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
- Graphics g = image.getGraphics();
- g.setColor(new Color(0, true));
- g.fillRect(0, 0, image.getWidth(), image.getHeight());
- g.setColor(new Color(0xFF00FF00, true));
- g.fillRect(25, 25, 50, 50);
- g.dispose();
-
- BufferedImage crop = SwtUtils.cropBlank(image, new Rect(5, 5, 80, 80));
- assertNotNull(crop);
- assertEquals(50, crop.getWidth());
- assertEquals(50, crop.getHeight());
- assertEquals(0xFF00FF00, crop.getRGB(0, 0));
- assertEquals(0xFF00FF00, crop.getRGB(49, 49));
- }
-
- public void testCropColor() throws Exception {
- BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
- Graphics g = image.getGraphics();
- g.setColor(new Color(0xFF00FF00, true));
- g.fillRect(0, 0, image.getWidth(), image.getHeight());
- g.dispose();
-
- BufferedImage crop = SwtUtils.cropColor(image, 0xFF00FF00, null);
- assertNull(crop);
- }
-
- public void testCropNonColor() throws Exception {
- BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
- Graphics g = image.getGraphics();
- g.setColor(new Color(0xFF00FF00, true));
- g.fillRect(0, 0, image.getWidth(), image.getHeight());
- g.dispose();
-
- BufferedImage crop = SwtUtils.cropColor(image, 0xFFFF0000, null);
- assertNotNull(crop);
- assertEquals(image.getWidth(), crop.getWidth());
- assertEquals(image.getHeight(), crop.getHeight());
- }
-
- public void testCropColorSomething() throws Exception {
- BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
- Graphics g = image.getGraphics();
- g.setColor(new Color(0xFF00FF00, true));
- g.fillRect(0, 0, image.getWidth(), image.getHeight());
- g.setColor(new Color(0xFFFF0000, true));
- g.fillRect(25, 25, 50, 50);
- g.dispose();
-
- BufferedImage crop = SwtUtils.cropColor(image, 0xFF00FF00, null);
- assertEquals(50, crop.getWidth());
- assertEquals(50, crop.getHeight());
- assertEquals(0xFFFF0000, crop.getRGB(0, 0));
- assertEquals(0xFFFF0000, crop.getRGB(49, 49));
- }
-
- public void testNullOk() throws Exception {
- SwtUtils.cropBlank(null, null);
- SwtUtils.cropColor(null, 0, null);
- }
public void testImageConvertNoAlpha() throws Exception {
BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
@@ -170,7 +38,7 @@ public class SwtUtilsTest extends TestCase {
Shell shell = new Shell();
Display display = shell.getDisplay();
- Image swtImage = SwtUtils.convertImage(display, image, false, -1);
+ Image swtImage = SwtUtils.convertToSwt(display, image, false, -1);
assertNotNull(swtImage);
ImageData data = swtImage.getImageData();
assertEquals(image.getWidth(), data.width);
@@ -181,6 +49,17 @@ public class SwtUtilsTest extends TestCase {
assertEquals(image.getRGB(x, y) & 0xFFFFFF, data.getPixel(x, y));
}
}
+
+ // Convert back to AWT and compare with original AWT image
+ BufferedImage awtImage = SwtUtils.convertToAwt(swtImage);
+ assertNotNull(awtImage);
+ for (int y = 0; y < data.height; y++) {
+ for (int x = 0; x < data.width; x++) {
+ assertEquals(image.getRGB(x, y), awtImage.getRGB(x, y));
+ }
+ }
+
+
}
public void testImageConvertGlobalAlpha() throws Exception {
@@ -192,7 +71,7 @@ public class SwtUtilsTest extends TestCase {
Shell shell = new Shell();
Display display = shell.getDisplay();
- Image swtImage = SwtUtils.convertImage(display, image, false, 128);
+ Image swtImage = SwtUtils.convertToSwt(display, image, false, 128);
assertNotNull(swtImage);
ImageData data = swtImage.getImageData();
assertEquals(image.getWidth(), data.width);
@@ -215,7 +94,7 @@ public class SwtUtilsTest extends TestCase {
Shell shell = new Shell();
Display display = shell.getDisplay();
- Image swtImage = SwtUtils.convertImage(display, image, true, -1);
+ Image swtImage = SwtUtils.convertToSwt(display, image, true, -1);
assertNotNull(swtImage);
ImageData data = swtImage.getImageData();
assertEquals(image.getWidth(), data.width);
@@ -239,7 +118,7 @@ public class SwtUtilsTest extends TestCase {
Shell shell = new Shell();
Display display = shell.getDisplay();
- Image swtImage = SwtUtils.convertImage(display, image, true, 32);
+ Image swtImage = SwtUtils.convertToSwt(display, image, true, 32);
assertNotNull(swtImage);
ImageData data = swtImage.getImageData();
assertEquals(image.getWidth(), data.width);
@@ -255,15 +134,4 @@ public class SwtUtilsTest extends TestCase {
}
}
- public void testNothingTodo() throws Exception {
- BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
- Graphics g = image.getGraphics();
- g.setColor(new Color(0xFF00FF00, true));
- g.fillRect(0, 0, image.getWidth(), image.getHeight());
- g.dispose();
-
- BufferedImage crop = SwtUtils.cropColor(image, 0xFFFF0000, new Rect(40, 40, 0, 0));
- assertNull(crop);
- }
-
}