aboutsummaryrefslogtreecommitdiffstats
path: root/draw9patch
diff options
context:
space:
mode:
authorRaphael Moll <ralf@android.com>2013-03-12 10:39:00 -0700
committerRaphael Moll <ralf@android.com>2013-03-13 20:34:20 -0700
commitf6a5b596f5473558ecc859e8af931a9f1b80a7ea (patch)
tree885f0080f18c5ba1a94781b9d61077d2c67e3add /draw9patch
parentbc982e5d2a6ffc0fa5c76eaf39e77e4ec415e637 (diff)
downloadsdk-f6a5b596f5473558ecc859e8af931a9f1b80a7ea.zip
sdk-f6a5b596f5473558ecc859e8af931a9f1b80a7ea.tar.gz
sdk-f6a5b596f5473558ecc859e8af931a9f1b80a7ea.tar.bz2
SDK: Delete projects moved to tools/base or tools/swt.
Change-Id: Iba15f82cb00d19217382c78d8ff37dda1e97ea59
Diffstat (limited to 'draw9patch')
-rw-r--r--draw9patch/.gitignore3
-rw-r--r--draw9patch/Android.mk29
-rw-r--r--draw9patch/MODULE_LICENSE_APACHE20
-rw-r--r--draw9patch/NOTICE190
-rw-r--r--draw9patch/etc/Android.mk21
-rwxr-xr-xdraw9patch/etc/draw9patch63
-rwxr-xr-xdraw9patch/etc/draw9patch.bat46
-rw-r--r--draw9patch/etc/manifest.txt1
-rw-r--r--draw9patch/src/main/java/com/android/draw9patch/Application.java55
-rw-r--r--draw9patch/src/main/java/com/android/draw9patch/graphics/GraphicsUtilities.java96
-rw-r--r--draw9patch/src/main/java/com/android/draw9patch/ui/CorruptPatch.java100
-rw-r--r--draw9patch/src/main/java/com/android/draw9patch/ui/GradientPanel.java47
-rw-r--r--draw9patch/src/main/java/com/android/draw9patch/ui/ImageEditorPanel.java387
-rw-r--r--draw9patch/src/main/java/com/android/draw9patch/ui/ImageTransferHandler.java92
-rw-r--r--draw9patch/src/main/java/com/android/draw9patch/ui/ImageViewer.java1190
-rw-r--r--draw9patch/src/main/java/com/android/draw9patch/ui/MainFrame.java179
-rw-r--r--draw9patch/src/main/java/com/android/draw9patch/ui/OpenFilePanel.java51
-rw-r--r--draw9patch/src/main/java/com/android/draw9patch/ui/Pair.java32
-rw-r--r--draw9patch/src/main/java/com/android/draw9patch/ui/PatchInfo.java225
-rw-r--r--draw9patch/src/main/java/com/android/draw9patch/ui/PngFileFilter.java32
-rw-r--r--draw9patch/src/main/java/com/android/draw9patch/ui/StretchesViewer.java326
-rw-r--r--draw9patch/src/main/java/com/android/draw9patch/ui/action/BackgroundAction.java28
-rw-r--r--draw9patch/src/main/java/com/android/draw9patch/ui/action/ExitAction.java44
-rw-r--r--draw9patch/src/main/java/com/android/draw9patch/ui/action/OpenAction.java43
-rw-r--r--draw9patch/src/main/java/com/android/draw9patch/ui/action/SaveAction.java43
-rw-r--r--draw9patch/src/main/resources/images/checker.pngbin1889 -> 0 bytes
-rw-r--r--draw9patch/src/main/resources/images/drop.pngbin5479 -> 0 bytes
-rw-r--r--draw9patch/src/test/java/com/android/draw9patch/ui/PatchInfoTest.java129
28 files changed, 0 insertions, 3452 deletions
diff --git a/draw9patch/.gitignore b/draw9patch/.gitignore
deleted file mode 100644
index ee936c7..0000000
--- a/draw9patch/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-*.iml
-out
-.idea
diff --git a/draw9patch/Android.mk b/draw9patch/Android.mk
deleted file mode 100644
index 444e582..0000000
--- a/draw9patch/Android.mk
+++ /dev/null
@@ -1,29 +0,0 @@
-# Copyright (C) 2008 The Android Open Source Project
-#
-# Licensed 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.
-
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := $(call all-java-files-under, src/main/java)
-LOCAL_JAVA_RESOURCE_DIRS := src/main/resources
-
-LOCAL_JAR_MANIFEST := etc/manifest.txt
-
-LOCAL_MODULE := draw9patch
-LOCAL_MODULE_TAGS := debug
-
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-# Build all sub-directories
-include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/draw9patch/MODULE_LICENSE_APACHE2 b/draw9patch/MODULE_LICENSE_APACHE2
deleted file mode 100644
index e69de29..0000000
--- a/draw9patch/MODULE_LICENSE_APACHE2
+++ /dev/null
diff --git a/draw9patch/NOTICE b/draw9patch/NOTICE
deleted file mode 100644
index c5b1efa..0000000
--- a/draw9patch/NOTICE
+++ /dev/null
@@ -1,190 +0,0 @@
-
- Copyright (c) 2005-2008, The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
-
- 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.
-
-
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
diff --git a/draw9patch/etc/Android.mk b/draw9patch/etc/Android.mk
deleted file mode 100644
index c2b1f78..0000000
--- a/draw9patch/etc/Android.mk
+++ /dev/null
@@ -1,21 +0,0 @@
-# Copyright (C) 2008 The Android Open Source Project
-#
-# Licensed 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.
-
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_PREBUILT_EXECUTABLES := draw9patch
-LOCAL_MODULE_TAGS := debug
-include $(BUILD_HOST_PREBUILT)
-
diff --git a/draw9patch/etc/draw9patch b/draw9patch/etc/draw9patch
deleted file mode 100755
index 5d272a6..0000000
--- a/draw9patch/etc/draw9patch
+++ /dev/null
@@ -1,63 +0,0 @@
-#!/bin/sh
-# Copyright 2008, The Android Open Source Project
-#
-# Licensed 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.
-
-# Set up prog to be the path of this script, including following symlinks,
-# and set up progdir to be the fully-qualified pathname of its directory.
-prog="$0"
-while [ -h "${prog}" ]; do
- newProg=`/bin/ls -ld "${prog}"`
- newProg=`expr "${newProg}" : ".* -> \(.*\)$"`
- if expr "x${newProg}" : 'x/' >/dev/null; then
- prog="${newProg}"
- else
- progdir=`dirname "${prog}"`
- prog="${progdir}/${newProg}"
- fi
-done
-oldwd=`pwd`
-progdir=`dirname "${prog}"`
-cd "${progdir}"
-progdir=`pwd`
-prog="${progdir}"/`basename "${prog}"`
-cd "${oldwd}"
-
-jarfile=draw9patch.jar
-frameworkdir="$progdir"
-if [ ! -r "$frameworkdir/$jarfile" ]
-then
- frameworkdir=`dirname "$progdir"`/tools/lib
- libdir=`dirname "$progdir"`/tools/lib
-fi
-if [ ! -r "$frameworkdir/$jarfile" ]
-then
- frameworkdir=`dirname "$progdir"`/framework
- libdir=`dirname "$progdir"`/lib
-fi
-if [ ! -r "$frameworkdir/$jarfile" ]
-then
- echo `basename "$prog"`": can't find $jarfile"
- exit 1
-fi
-
-if [ "$OSTYPE" = "cygwin" ] ; then
- jarpath=`cygpath -w "$frameworkdir/$jarfile"`
- progdir=`cygpath -w "$progdir"`
-else
- jarpath="$frameworkdir/$jarfile"
-fi
-
-# need to use "java.ext.dirs" because "-jar" causes classpath to be ignored
-# might need more memory, e.g. -Xmx128M
-exec java -Djava.ext.dirs="$frameworkdir" -jar "$jarpath" "$@"
diff --git a/draw9patch/etc/draw9patch.bat b/draw9patch/etc/draw9patch.bat
deleted file mode 100755
index b6826fc..0000000
--- a/draw9patch/etc/draw9patch.bat
+++ /dev/null
@@ -1,46 +0,0 @@
-@echo off
-rem Copyright (C) 2008 The Android Open Source Project
-rem
-rem Licensed under the Apache License, Version 2.0 (the "License");
-rem you may not use this file except in compliance with the License.
-rem You may obtain a copy of the License at
-rem
-rem http://www.apache.org/licenses/LICENSE-2.0
-rem
-rem Unless required by applicable law or agreed to in writing, software
-rem distributed under the License is distributed on an "AS IS" BASIS,
-rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-rem See the License for the specific language governing permissions and
-rem limitations under the License.
-
-rem don't modify the caller's environment
-setlocal
-
-rem Set up prog to be the path of this script, including following symlinks,
-rem and set up progdir to be the fully-qualified pathname of its directory.
-set prog=%~f0
-
-rem Change current directory and drive to where the script is, to avoid
-rem issues with directories containing whitespaces.
-cd /d %~dp0
-
-rem Check we have a valid Java.exe in the path.
-set java_exe=
-call lib\find_java.bat
-if not defined java_exe goto :EOF
-
-set jarfile=draw9patch.jar
-set frameworkdir=
-set libdir=
-
-if exist %frameworkdir%%jarfile% goto JarFileOk
- set frameworkdir=lib\
-
-if exist %frameworkdir%%jarfile% goto JarFileOk
- set frameworkdir=..\framework\
-
-:JarFileOk
-
-set jarpath=%frameworkdir%%jarfile%
-
-call %java_exe% -Djava.ext.dirs=%frameworkdir% -jar %jarpath% %*
diff --git a/draw9patch/etc/manifest.txt b/draw9patch/etc/manifest.txt
deleted file mode 100644
index 2616706..0000000
--- a/draw9patch/etc/manifest.txt
+++ /dev/null
@@ -1 +0,0 @@
-Main-Class: com.android.draw9patch.Application
diff --git a/draw9patch/src/main/java/com/android/draw9patch/Application.java b/draw9patch/src/main/java/com/android/draw9patch/Application.java
deleted file mode 100644
index 68c792a..0000000
--- a/draw9patch/src/main/java/com/android/draw9patch/Application.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed 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 com.android.draw9patch;
-
-import com.android.draw9patch.ui.MainFrame;
-
-import javax.swing.SwingUtilities;
-import javax.swing.UIManager;
-import javax.swing.UnsupportedLookAndFeelException;
-
-public class Application {
- private static void initUserInterface() {
- System.setProperty("apple.laf.useScreenMenuBar", "true");
- System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Draw 9-patch");
-
- try {
- UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- } catch (InstantiationException e) {
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- } catch (UnsupportedLookAndFeelException e) {
- e.printStackTrace();
- }
- }
-
- public static void main(final String... args) {
- initUserInterface();
- SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- String arg = args.length > 0 ? args[0] : null;
- MainFrame frame = new MainFrame(arg);
- frame.setDefaultCloseOperation(MainFrame.EXIT_ON_CLOSE);
- frame.setLocationRelativeTo(null);
- frame.setVisible(true);
- }
- });
- }
-}
diff --git a/draw9patch/src/main/java/com/android/draw9patch/graphics/GraphicsUtilities.java b/draw9patch/src/main/java/com/android/draw9patch/graphics/GraphicsUtilities.java
deleted file mode 100644
index c6c182c..0000000
--- a/draw9patch/src/main/java/com/android/draw9patch/graphics/GraphicsUtilities.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed 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 com.android.draw9patch.graphics;
-
-import javax.imageio.ImageIO;
-import java.awt.image.BufferedImage;
-import java.awt.image.Raster;
-import java.awt.GraphicsConfiguration;
-import java.awt.GraphicsEnvironment;
-import java.awt.Graphics;
-import java.awt.Transparency;
-import java.net.URL;
-import java.io.IOException;
-
-public class GraphicsUtilities {
- public static BufferedImage loadCompatibleImage(URL resource) throws IOException {
- BufferedImage image = ImageIO.read(resource);
- return toCompatibleImage(image);
- }
-
- public static BufferedImage createCompatibleImage(int width, int height) {
- return getGraphicsConfiguration().createCompatibleImage(width, height);
- }
-
- public static BufferedImage toCompatibleImage(BufferedImage image) {
- if (isHeadless()) {
- return image;
- }
-
- if (image.getColorModel().equals(getGraphicsConfiguration().getColorModel())) {
- return image;
- }
-
- BufferedImage compatibleImage = getGraphicsConfiguration().createCompatibleImage(
- image.getWidth(), image.getHeight(), image.getTransparency());
- Graphics g = compatibleImage.getGraphics();
- g.drawImage(image, 0, 0, null);
- g.dispose();
-
- return compatibleImage;
- }
-
- public static BufferedImage createCompatibleImage(BufferedImage image, int width, int height) {
- return getGraphicsConfiguration().createCompatibleImage(width, height,
- image.getTransparency());
- }
-
- private static GraphicsConfiguration getGraphicsConfiguration() {
- GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
- return environment.getDefaultScreenDevice().getDefaultConfiguration();
- }
-
- private static boolean isHeadless() {
- return GraphicsEnvironment.isHeadless();
- }
-
- public static BufferedImage createTranslucentCompatibleImage(int width, int height) {
- return getGraphicsConfiguration().createCompatibleImage(width, height,
- Transparency.TRANSLUCENT);
- }
-
- public static int[] getPixels(BufferedImage img, int x, int y, int w, int h, int[] pixels) {
- if (w == 0 || h == 0) {
- return new int[0];
- }
-
- if (pixels == null) {
- pixels = new int[w * h];
- } else if (pixels.length < w * h) {
- throw new IllegalArgumentException("Pixels array must have a length >= w * h");
- }
-
- int imageType = img.getType();
- if (imageType == BufferedImage.TYPE_INT_ARGB || imageType == BufferedImage.TYPE_INT_RGB) {
- Raster raster = img.getRaster();
- return (int[]) raster.getDataElements(x, y, w, h, pixels);
- }
-
- // Unmanages the image
- return img.getRGB(x, y, w, h, pixels, 0, w);
- }
-}
diff --git a/draw9patch/src/main/java/com/android/draw9patch/ui/CorruptPatch.java b/draw9patch/src/main/java/com/android/draw9patch/ui/CorruptPatch.java
deleted file mode 100644
index 4f0763a..0000000
--- a/draw9patch/src/main/java/com/android/draw9patch/ui/CorruptPatch.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed 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 com.android.draw9patch.ui;
-
-import com.android.draw9patch.graphics.GraphicsUtilities;
-
-import java.awt.Rectangle;
-import java.awt.image.BufferedImage;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-public class CorruptPatch {
- public static List<Rectangle> findBadPatches(BufferedImage image, PatchInfo patchInfo) {
- List<Rectangle> corruptedPatches = new ArrayList<Rectangle>();
-
- for (Rectangle patch : patchInfo.patches) {
- if (corruptPatch(image, patch)) {
- corruptedPatches.add(patch);
- }
- }
-
- for (Rectangle patch : patchInfo.horizontalPatches) {
- if (corruptHorizontalPatch(image, patch)) {
- corruptedPatches.add(patch);
- }
- }
-
- for (Rectangle patch : patchInfo.verticalPatches) {
- if (corruptVerticalPatch(image, patch)) {
- corruptedPatches.add(patch);
- }
- }
-
- return corruptedPatches;
- }
-
- private static boolean corruptPatch(BufferedImage image, Rectangle patch) {
- int[] pixels = GraphicsUtilities.getPixels(image, patch.x, patch.y,
- patch.width, patch.height, null);
-
- if (pixels.length > 0) {
- int reference = pixels[0];
- for (int pixel : pixels) {
- if (pixel != reference) {
- return true;
- }
- }
- }
-
- return false;
- }
-
- private static boolean corruptHorizontalPatch(BufferedImage image, Rectangle patch) {
- int[] reference = new int[patch.height];
- int[] column = new int[patch.height];
- reference = GraphicsUtilities.getPixels(image, patch.x, patch.y,
- 1, patch.height, reference);
-
- for (int i = 1; i < patch.width; i++) {
- column = GraphicsUtilities.getPixels(image, patch.x + i, patch.y,
- 1, patch.height, column);
- if (!Arrays.equals(reference, column)) {
- return true;
- }
- }
-
- return false;
- }
-
- private static boolean corruptVerticalPatch(BufferedImage image, Rectangle patch) {
- int[] reference = new int[patch.width];
- int[] row = new int[patch.width];
- reference = GraphicsUtilities.getPixels(image, patch.x, patch.y,
- patch.width, 1, reference);
-
- for (int i = 1; i < patch.height; i++) {
- row = GraphicsUtilities.getPixels(image, patch.x, patch.y + i, patch.width, 1, row);
- if (!Arrays.equals(reference, row)) {
- return true;
- }
- }
-
- return false;
- }
-}
diff --git a/draw9patch/src/main/java/com/android/draw9patch/ui/GradientPanel.java b/draw9patch/src/main/java/com/android/draw9patch/ui/GradientPanel.java
deleted file mode 100644
index bc1465f..0000000
--- a/draw9patch/src/main/java/com/android/draw9patch/ui/GradientPanel.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed 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 com.android.draw9patch.ui;
-
-import java.awt.Graphics;
-import java.awt.Graphics2D;
-import java.awt.Paint;
-import java.awt.GradientPaint;
-import java.awt.Color;
-import java.awt.Rectangle;
-import java.awt.BorderLayout;
-import javax.swing.JPanel;
-
-class GradientPanel extends JPanel {
- private static final int DARK_BLUE = 0x202737;
-
- GradientPanel() {
- super(new BorderLayout());
- }
-
- @Override
- protected void paintComponent(Graphics g) {
- Graphics2D g2 = (Graphics2D) g;
- Rectangle clip = g2.getClipBounds();
- Paint paint = g2.getPaint();
-
- g2.setPaint(new GradientPaint(0.0f, getHeight() * 0.22f, new Color(DARK_BLUE),
- 0.0f, getHeight() * 0.9f, Color.BLACK));
- g2.fillRect(clip.x, clip.y, clip.width, clip.height);
-
- g2.setPaint(paint);
- }
-}
diff --git a/draw9patch/src/main/java/com/android/draw9patch/ui/ImageEditorPanel.java b/draw9patch/src/main/java/com/android/draw9patch/ui/ImageEditorPanel.java
deleted file mode 100644
index 3529542..0000000
--- a/draw9patch/src/main/java/com/android/draw9patch/ui/ImageEditorPanel.java
+++ /dev/null
@@ -1,387 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed 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 com.android.draw9patch.ui;
-
-import com.android.draw9patch.graphics.GraphicsUtilities;
-
-import java.awt.BorderLayout;
-import java.awt.Color;
-import java.awt.Graphics2D;
-import java.awt.GridBagConstraints;
-import java.awt.GridBagLayout;
-import java.awt.Insets;
-import java.awt.TexturePaint;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.geom.Rectangle2D;
-import java.awt.image.BufferedImage;
-import java.awt.image.RenderedImage;
-import java.io.File;
-import java.io.IOException;
-import java.net.URL;
-
-import javax.swing.Box;
-import javax.swing.JCheckBox;
-import javax.swing.JComponent;
-import javax.swing.JFileChooser;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-import javax.swing.JScrollPane;
-import javax.swing.JSlider;
-import javax.swing.JSplitPane;
-import javax.swing.event.AncestorEvent;
-import javax.swing.event.AncestorListener;
-import javax.swing.event.ChangeEvent;
-import javax.swing.event.ChangeListener;
-
-public class ImageEditorPanel extends JPanel {
- private static final String EXTENSION_9PATCH = ".9.png";
-
- private String name;
- private BufferedImage image;
- private boolean is9Patch;
-
- private ImageViewer viewer;
- private StretchesViewer stretchesViewer;
- private JLabel xLabel;
- private JLabel yLabel;
-
- private TexturePaint texture;
- private JSlider zoomSlider;
-
- public ImageEditorPanel(MainFrame mainFrame, BufferedImage image, String name) {
- this.image = image;
- this.name = name;
-
- if (mainFrame != null) {
- setTransferHandler(new ImageTransferHandler(mainFrame));
- }
-
- setOpaque(false);
- setLayout(new BorderLayout());
-
- loadSupport();
- buildImageViewer();
- buildStatusPanel();
-
- checkImage();
-
- addAncestorListener(new AncestorListener() {
- @Override
- public void ancestorAdded(AncestorEvent event) {
- }
-
- @Override
- public void ancestorRemoved(AncestorEvent event) {
- }
-
- @Override
- public void ancestorMoved(AncestorEvent event) {
- // allow the image viewer to set the optimal zoom level and ensure that the
- // zoom slider's setting is in sync with the image viewer's zoom
- removeAncestorListener(this);
- synchronizeImageViewerZoomLevel();
- }
- });
- }
-
- private void synchronizeImageViewerZoomLevel() {
- zoomSlider.setValue(viewer.getZoom());
- }
-
- public ImageViewer getViewer() {
- return viewer;
- }
-
- private void loadSupport() {
- try {
- URL resource = getClass().getResource("/images/checker.png");
- BufferedImage checker = GraphicsUtilities.loadCompatibleImage(resource);
- texture = new TexturePaint(checker, new Rectangle2D.Double(0, 0,
- checker.getWidth(), checker.getHeight()));
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- private void buildImageViewer() {
- viewer = new ImageViewer(this, texture, image, new ImageViewer.StatusBar() {
- @Override
- public void setPointerLocation(int x, int y) {
- xLabel.setText(x + " px");
- yLabel.setText(y + " px");
- }
- });
-
- JSplitPane splitter = new JSplitPane();
- splitter.setContinuousLayout(true);
- splitter.setResizeWeight(0.8);
- splitter.setBorder(null);
-
- JScrollPane scroller = new JScrollPane(viewer);
- scroller.setOpaque(false);
- scroller.setBorder(null);
- scroller.getViewport().setBorder(null);
- scroller.getViewport().setOpaque(false);
-
- splitter.setLeftComponent(scroller);
- splitter.setRightComponent(buildStretchesViewer());
-
- add(splitter);
- }
-
- private JComponent buildStretchesViewer() {
- stretchesViewer = new StretchesViewer(this, viewer, texture);
- JScrollPane scroller = new JScrollPane(stretchesViewer);
- scroller.setBorder(null);
- scroller.getViewport().setBorder(null);
- scroller.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
- scroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
- return scroller;
- }
-
- private void buildStatusPanel() {
- JPanel status = new JPanel(new GridBagLayout());
- status.setOpaque(false);
-
- JLabel label = new JLabel();
- label.setForeground(Color.WHITE);
- label.setText("Zoom: ");
- label.putClientProperty("JComponent.sizeVariant", "small");
- status.add(label, new GridBagConstraints(0, 0, 1, 1, 0.0f, 0.0f,
- GridBagConstraints.LINE_END, GridBagConstraints.NONE,
- new Insets(0, 6, 0, 0), 0, 0));
-
- label = new JLabel();
- label.setForeground(Color.WHITE);
- label.setText("100%");
- label.putClientProperty("JComponent.sizeVariant", "small");
- status.add(label, new GridBagConstraints(1, 0, 1, 1, 0.0f, 0.0f,
- GridBagConstraints.LINE_END, GridBagConstraints.NONE,
- new Insets(0, 0, 0, 0), 0, 0));
-
- zoomSlider = new JSlider(ImageViewer.MIN_ZOOM, ImageViewer.MAX_ZOOM,
- ImageViewer.DEFAULT_ZOOM);
- zoomSlider.setSnapToTicks(true);
- zoomSlider.putClientProperty("JComponent.sizeVariant", "small");
- zoomSlider.addChangeListener(new ChangeListener() {
- public void stateChanged(ChangeEvent evt) {
- viewer.setZoom(((JSlider) evt.getSource()).getValue());
- }
- });
- status.add(zoomSlider, new GridBagConstraints(2, 0, 1, 1, 0.0f, 0.0f,
- GridBagConstraints.LINE_START, GridBagConstraints.NONE,
- new Insets(0, 0, 0, 0), 0, 0));
-
- JLabel maxZoomLabel = new JLabel();
- maxZoomLabel.setForeground(Color.WHITE);
- maxZoomLabel.putClientProperty("JComponent.sizeVariant", "small");
- maxZoomLabel.setText("800%");
- status.add(maxZoomLabel, new GridBagConstraints(3, 0, 1, 1, 0.0f, 0.0f,
- GridBagConstraints.LINE_START, GridBagConstraints.NONE,
- new Insets(0, 0, 0, 0), 0, 0));
-
- label = new JLabel();
- label.setForeground(Color.WHITE);
- label.setText("Patch scale: ");
- label.putClientProperty("JComponent.sizeVariant", "small");
- status.add(label, new GridBagConstraints(0, 1, 1, 1, 0.0f, 0.0f,
- GridBagConstraints.LINE_START, GridBagConstraints.NONE,
- new Insets(0, 6, 0, 0), 0, 0));
-
- label = new JLabel();
- label.setForeground(Color.WHITE);
- label.setText("2x");
- label.putClientProperty("JComponent.sizeVariant", "small");
- status.add(label, new GridBagConstraints(1, 1, 1, 1, 0.0f, 0.0f,
- GridBagConstraints.LINE_END, GridBagConstraints.NONE,
- new Insets(0, 0, 0, 0), 0, 0));
-
- JSlider jSlider = new JSlider(200, 600, (int) (StretchesViewer.DEFAULT_SCALE * 100.0f));
- jSlider.setSnapToTicks(true);
- jSlider.putClientProperty("JComponent.sizeVariant", "small");
- jSlider.addChangeListener(new ChangeListener() {
- public void stateChanged(ChangeEvent evt) {
- stretchesViewer.setScale(((JSlider) evt.getSource()).getValue() / 100.0f);
- }
- });
- status.add(jSlider, new GridBagConstraints(2, 1, 1, 1, 0.0f, 0.0f,
- GridBagConstraints.LINE_START, GridBagConstraints.NONE,
- new Insets(0, 0, 0, 0), 0, 0));
-
- maxZoomLabel = new JLabel();
- maxZoomLabel.setForeground(Color.WHITE);
- maxZoomLabel.putClientProperty("JComponent.sizeVariant", "small");
- maxZoomLabel.setText("6x");
- status.add(maxZoomLabel, new GridBagConstraints(3, 1, 1, 1, 0.0f, 0.0f,
- GridBagConstraints.LINE_START, GridBagConstraints.NONE,
- new Insets(0, 0, 0, 0), 0, 0));
-
- JCheckBox showLock = new JCheckBox("Show lock");
- showLock.setOpaque(false);
- showLock.setForeground(Color.WHITE);
- showLock.setSelected(false);
- showLock.putClientProperty("JComponent.sizeVariant", "small");
- showLock.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent event) {
- viewer.setLockVisible(((JCheckBox) event.getSource()).isSelected());
- }
- });
- status.add(showLock, new GridBagConstraints(4, 0, 1, 1, 0.0f, 0.0f,
- GridBagConstraints.LINE_START, GridBagConstraints.NONE,
- new Insets(0, 12, 0, 0), 0, 0));
-
- JCheckBox showPatches = new JCheckBox("Show patches");
- showPatches.setOpaque(false);
- showPatches.setForeground(Color.WHITE);
- showPatches.putClientProperty("JComponent.sizeVariant", "small");
- showPatches.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent event) {
- viewer.setPatchesVisible(((JCheckBox) event.getSource()).isSelected());
- }
- });
- status.add(showPatches, new GridBagConstraints(4, 1, 1, 1, 0.0f, 0.0f,
- GridBagConstraints.LINE_START, GridBagConstraints.NONE,
- new Insets(0, 12, 0, 0), 0, 0));
-
- JCheckBox showPadding = new JCheckBox("Show content");
- showPadding.setOpaque(false);
- showPadding.setForeground(Color.WHITE);
- showPadding.putClientProperty("JComponent.sizeVariant", "small");
- showPadding.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent event) {
- stretchesViewer.setPaddingVisible(((JCheckBox) event.getSource()).isSelected());
- }
- });
- status.add(showPadding, new GridBagConstraints(5, 0, 1, 1, 0.0f, 0.0f,
- GridBagConstraints.LINE_START, GridBagConstraints.NONE,
- new Insets(0, 12, 0, 0), 0, 0));
-
- status.add(Box.createHorizontalGlue(), new GridBagConstraints(6, 0, 1, 1, 1.0f, 1.0f,
- GridBagConstraints.LINE_START, GridBagConstraints.BOTH,
- new Insets(0, 0, 0, 0), 0, 0));
-
- label = new JLabel("X: ");
- label.setForeground(Color.WHITE);
- label.putClientProperty("JComponent.sizeVariant", "small");
- status.add(label, new GridBagConstraints(7, 0, 1, 1, 0.0f, 0.0f,
- GridBagConstraints.LINE_END, GridBagConstraints.NONE,
- new Insets(0, 0, 0, 0), 0, 0));
-
- xLabel = new JLabel("0px");
- xLabel.setForeground(Color.WHITE);
- xLabel.putClientProperty("JComponent.sizeVariant", "small");
- status.add(xLabel, new GridBagConstraints(8, 0, 1, 1, 0.0f, 0.0f,
- GridBagConstraints.LINE_END, GridBagConstraints.NONE,
- new Insets(0, 0, 0, 6), 0, 0));
-
- label = new JLabel("Y: ");
- label.setForeground(Color.WHITE);
- label.putClientProperty("JComponent.sizeVariant", "small");
- status.add(label, new GridBagConstraints(7, 1, 1, 1, 0.0f, 0.0f,
- GridBagConstraints.LINE_END, GridBagConstraints.NONE,
- new Insets(0, 0, 0, 0), 0, 0));
-
- yLabel = new JLabel("0px");
- yLabel.setForeground(Color.WHITE);
- yLabel.putClientProperty("JComponent.sizeVariant", "small");
- status.add(yLabel, new GridBagConstraints(8, 1, 1, 1, 0.0f, 0.0f,
- GridBagConstraints.LINE_END, GridBagConstraints.NONE,
- new Insets(0, 0, 0, 6), 0, 0));
-
- add(status, BorderLayout.SOUTH);
- }
-
- private void checkImage() {
- is9Patch = name.endsWith(EXTENSION_9PATCH);
- if (!is9Patch) {
- convertTo9Patch();
- } else {
- ensure9Patch();
- }
- }
-
- private void ensure9Patch() {
- int width = image.getWidth();
- int height = image.getHeight();
- for (int i = 0; i < width; i++) {
- int pixel = image.getRGB(i, 0);
- if (pixel != 0 && pixel != PatchInfo.BLACK_TICK && pixel != PatchInfo.RED_TICK) {
- image.setRGB(i, 0, 0);
- }
- pixel = image.getRGB(i, height - 1);
- if (pixel != 0 && pixel != PatchInfo.BLACK_TICK && pixel != PatchInfo.RED_TICK) {
- image.setRGB(i, height - 1, 0);
- }
- }
- for (int i = 0; i < height; i++) {
- int pixel = image.getRGB(0, i);
- if (pixel != 0 && pixel != PatchInfo.BLACK_TICK && pixel != PatchInfo.RED_TICK) {
- image.setRGB(0, i, 0);
- }
- pixel = image.getRGB(width - 1, i);
- if (pixel != 0 && pixel != PatchInfo.BLACK_TICK && pixel != PatchInfo.RED_TICK) {
- image.setRGB(width - 1, i, 0);
- }
- }
- }
-
- private void convertTo9Patch() {
- BufferedImage buffer = GraphicsUtilities.createTranslucentCompatibleImage(
- image.getWidth() + 2, image.getHeight() + 2);
-
- Graphics2D g2 = buffer.createGraphics();
- g2.drawImage(image, 1, 1, null);
- g2.dispose();
-
- image = buffer;
- viewer.setImage(image);
- name = name.substring(0, name.lastIndexOf('.')) + ".9.png";
- }
-
- File chooseSaveFile() {
- if (is9Patch) {
- return new File(name);
- } else {
- JFileChooser chooser = new JFileChooser(
- name.substring(0, name.lastIndexOf(File.separatorChar)));
- chooser.setFileFilter(new PngFileFilter());
- int choice = chooser.showSaveDialog(this);
- if (choice == JFileChooser.APPROVE_OPTION) {
- File file = chooser.getSelectedFile();
- if (!file.getAbsolutePath().endsWith(EXTENSION_9PATCH)) {
- String path = file.getAbsolutePath();
- if (path.endsWith(".png")) {
- path = path.substring(0, path.lastIndexOf(".png")) + EXTENSION_9PATCH;
- } else {
- path = path + EXTENSION_9PATCH;
- }
- name = path;
- is9Patch = true;
- return new File(path);
- }
- is9Patch = true;
- return file;
- }
- }
- return null;
- }
-
- RenderedImage getImage() {
- return image;
- }
-}
diff --git a/draw9patch/src/main/java/com/android/draw9patch/ui/ImageTransferHandler.java b/draw9patch/src/main/java/com/android/draw9patch/ui/ImageTransferHandler.java
deleted file mode 100644
index bb1cdb3..0000000
--- a/draw9patch/src/main/java/com/android/draw9patch/ui/ImageTransferHandler.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed 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 com.android.draw9patch.ui;
-
-import javax.swing.TransferHandler;
-import javax.swing.JComponent;
-import java.awt.datatransfer.Transferable;
-import java.awt.datatransfer.DataFlavor;
-import java.awt.datatransfer.UnsupportedFlavorException;
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-import java.net.MalformedURLException;
-
-class ImageTransferHandler extends TransferHandler {
- private final MainFrame mainFrame;
-
- ImageTransferHandler(MainFrame mainFrame) {
- this.mainFrame = mainFrame;
- }
-
- @Override
- public boolean importData(JComponent component, Transferable transferable) {
- try {
- for (DataFlavor flavor : transferable.getTransferDataFlavors()) {
- if (flavor.isFlavorJavaFileListType()) {
- Object data = transferable.getTransferData(DataFlavor.javaFileListFlavor);
- //noinspection unchecked
- final File file = ((List<File>) data).get(0);
- mainFrame.open(file).execute();
- return true;
- } else if (flavor.isFlavorTextType()) {
- if (flavor.getRepresentationClass() == String.class) {
- String mime = flavor.getMimeType();
- DataFlavor flave = new DataFlavor(mime);
- Object data = transferable.getTransferData(flave);
- final String path = convertPath(data.toString());
- mainFrame.open(new File(path)).execute();
- return true;
- }
- }
- }
- } catch (UnsupportedFlavorException e) {
- // Ignore
- } catch (MalformedURLException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- return false;
- }
-
- private static String convertPath(String path) {
- if (path.startsWith("file://")) path = path.substring("file://".length());
- if (path.indexOf('\n') != -1) path = path.substring(0, path.indexOf('\n'));
- if (path.indexOf('\r') != -1) path = path.substring(0, path.indexOf('\r'));
- return path;
- }
-
- @Override
- public boolean canImport(TransferSupport support) {
- boolean isCopySupported
- = (COPY & support.getSourceDropActions()) == COPY;
- if (!isCopySupported) {
- return false;
- }
- for (DataFlavor flavor : support.getDataFlavors()) {
- if (flavor.isFlavorJavaFileListType() || flavor.isFlavorTextType()) {
- support.setDropAction(COPY);
- return true;
- }
- }
- return false;
- }
-}
diff --git a/draw9patch/src/main/java/com/android/draw9patch/ui/ImageViewer.java b/draw9patch/src/main/java/com/android/draw9patch/ui/ImageViewer.java
deleted file mode 100644
index 58b20b7..0000000
--- a/draw9patch/src/main/java/com/android/draw9patch/ui/ImageViewer.java
+++ /dev/null
@@ -1,1190 +0,0 @@
-/*
- *
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed 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 com.android.draw9patch.ui;
-
-import java.awt.AWTEvent;
-import java.awt.BasicStroke;
-import java.awt.BorderLayout;
-import java.awt.Color;
-import java.awt.Container;
-import java.awt.Cursor;
-import java.awt.Dimension;
-import java.awt.Graphics;
-import java.awt.Graphics2D;
-import java.awt.GridBagConstraints;
-import java.awt.GridBagLayout;
-import java.awt.Insets;
-import java.awt.Point;
-import java.awt.Rectangle;
-import java.awt.RenderingHints;
-import java.awt.Shape;
-import java.awt.TexturePaint;
-import java.awt.Toolkit;
-import java.awt.event.AWTEventListener;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.ComponentAdapter;
-import java.awt.event.ComponentEvent;
-import java.awt.event.KeyEvent;
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
-import java.awt.event.MouseMotionAdapter;
-import java.awt.geom.Area;
-import java.awt.geom.Line2D;
-import java.awt.geom.RoundRectangle2D;
-import java.awt.image.BufferedImage;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import javax.swing.JButton;
-import javax.swing.JComponent;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-import javax.swing.border.EmptyBorder;
-import javax.swing.event.AncestorEvent;
-import javax.swing.event.AncestorListener;
-
-public class ImageViewer extends JComponent {
- private final Color CORRUPTED_COLOR = new Color(1.0f, 0.0f, 0.0f, 0.7f);
- private final Color LOCK_COLOR = new Color(0.0f, 0.0f, 0.0f, 0.7f);
- private final Color STRIPES_COLOR = new Color(1.0f, 0.0f, 0.0f, 0.5f);
- private final Color BACK_COLOR = new Color(0xc0c0c0);
- private final Color HELP_COLOR = new Color(0xffffe1);
- private final Color PATCH_COLOR = new Color(1.0f, 0.37f, 0.99f, 0.5f);
- private final Color PATCH_ONEWAY_COLOR = new Color(0.37f, 1.0f, 0.37f, 0.5f);
- private final Color HIGHLIGHT_REGION_COLOR = new Color(0.5f, 0.5f, 0.5f, 0.5f);
-
- private static final float STRIPES_WIDTH = 4.0f;
- private static final double STRIPES_SPACING = 6.0;
- private static final int STRIPES_ANGLE = 45;
-
- /** The fraction of the window size that the 9patch should occupy. */
- private static final float IDEAL_IMAGE_FRACTION_OF_WINDOW = 0.7f;
-
- /** Default zoom level for the 9patch image. */
- public static final int DEFAULT_ZOOM = 8;
-
- /** Minimum zoom level for the 9patch image. */
- public static final int MIN_ZOOM = 1;
-
- /** Maximum zoom level for the 9patch image. */
- public static final int MAX_ZOOM = 16;
-
- /** Current 9patch zoom level, {@link #MIN_ZOOM} <= zoom <= {@link #MAX_ZOOM} */
- private int zoom = DEFAULT_ZOOM;
- private boolean showPatches;
- private boolean showLock = false;
-
- private final TexturePaint texture;
- private final Container container;
- private final StatusBar statusBar;
-
- private final Dimension size;
-
- private boolean locked;
-
- private int lastPositionX;
- private int lastPositionY;
- private boolean showCursor;
-
- private JLabel helpLabel;
- private boolean eraseMode;
-
- private JButton checkButton;
- private List<Rectangle> corruptedPatches;
- private boolean showBadPatches;
-
- private JPanel helpPanel;
- private boolean drawingLine;
- private int lineFromX;
- private int lineFromY;
- private int lineToX;
- private int lineToY;
- private boolean showDrawingLine;
-
- private final List<Rectangle> hoverHighlightRegions = new ArrayList<Rectangle>();
- private String toolTipText;
-
- /**
- * Indicates whether we are currently in edit mode.
- * All fields with the prefix 'edit' are valid only when in edit mode.
- */
- private boolean isEditMode;
-
- /** Region being edited. */
- private UpdateRegion editRegion;
-
- /**
- * The start and end points corresponding to the region being edited.
- * During an edit sequence, the start point is constant and the end varies based on the
- * mouse location.
- */
- private final Pair<Integer> editSegment = new Pair<Integer>(0, 0);
-
- /** Regions to highlight based on the current edit. */
- private final List<Rectangle> editHighlightRegions = new ArrayList<Rectangle>();
-
- /** The actual patch location in the image being edited. */
- private Rectangle editPatchRegion = new Rectangle();
-
- private BufferedImage image;
- private PatchInfo patchInfo;
-
- /** The types of edit actions that can be performed on the image. */
- private enum DrawMode {
- PATCH, // drawing a patch or a padding
- LAYOUT_BOUND, // drawing layout bounds
- ERASE, // erasing whatever has been drawn
- }
-
- /**
- * Current drawing mode. The mode is changed by using either the Shift or Ctrl keys while
- * drawing.
- */
- private DrawMode currentMode = DrawMode.PATCH;
-
- ImageViewer(Container container, TexturePaint texture, BufferedImage image,
- StatusBar statusBar) {
- this.container = container;
- this.texture = texture;
- this.image = image;
- this.statusBar = statusBar;
-
- setLayout(new GridBagLayout());
- helpPanel = new JPanel(new BorderLayout());
- helpPanel.setBorder(new EmptyBorder(0, 6, 0, 6));
- helpPanel.setBackground(HELP_COLOR);
- helpLabel = new JLabel("Press Shift to erase pixels."
- + " Press Control to draw layout bounds");
- helpLabel.putClientProperty("JComponent.sizeVariant", "small");
- helpPanel.add(helpLabel, BorderLayout.WEST);
- checkButton = new JButton("Show bad patches");
- checkButton.putClientProperty("JComponent.sizeVariant", "small");
- checkButton.putClientProperty("JButton.buttonType", "roundRect");
- helpPanel.add(checkButton, BorderLayout.EAST);
-
- add(helpPanel, new GridBagConstraints(0, 0, 1, 1,
- 1.0f, 1.0f, GridBagConstraints.FIRST_LINE_START, GridBagConstraints.HORIZONTAL,
- new Insets(0, 0, 0, 0), 0, 0));
-
- setOpaque(true);
-
- // Exact size will be set by setZoom() in AncestorListener#ancestorMoved.
- size = new Dimension(0, 0);
-
- addAncestorListener(new AncestorListener() {
- @Override
- public void ancestorRemoved(AncestorEvent event) {
- }
- @Override
- public void ancestorMoved(AncestorEvent event) {
- removeAncestorListener(this);
- setDefaultZoom();
- }
- @Override
- public void ancestorAdded(AncestorEvent event) {
- }
- });
-
- updatePatchInfo();
-
- addMouseListener(new MouseAdapter() {
- @Override
- public void mousePressed(MouseEvent event) {
- // Update the drawing mode looking at the current state of modifier (shift/ctrl)
- // keys. This is done here instead of retrieving it again in MouseDragged
- // below, because on linux, calling MouseEvent.getButton() for the drag
- // event returns 0, which appears to be technically correct (no button
- // changed state).
- updateDrawMode(event);
-
- int x = imageXCoordinate(event.getX());
- int y = imageYCoordinate(event.getY());
-
- startDrawingLine(x, y);
-
- if (currentMode == DrawMode.PATCH) {
- startEditingRegion(x, y);
- } else {
- hoverHighlightRegions.clear();
- setCursor(Cursor.getDefaultCursor());
- repaint();
- }
- }
-
- @Override
- public void mouseReleased(MouseEvent event) {
- int x = imageXCoordinate(event.getX());
- int y = imageYCoordinate(event.getY());
-
- endDrawingLine();
- endEditingRegion(x, y);
-
- resetDrawMode();
- }
- });
- addMouseMotionListener(new MouseMotionAdapter() {
- @Override
- public void mouseDragged(MouseEvent event) {
- int x = imageXCoordinate(event.getX());
- int y = imageYCoordinate(event.getY());
-
- if (!checkLockedRegion(x, y)) {
- // use the stored button, see note above
- moveLine(x, y);
- }
-
- updateEditRegion(x, y);
- }
-
- @Override
- public void mouseMoved(MouseEvent event) {
- int x = imageXCoordinate(event.getX());
- int y = imageYCoordinate(event.getY());
-
- checkLockedRegion(x, y);
-
- updateHoverRegion(x, y);
- repaint();
- }
- });
-
- addComponentListener(new ComponentAdapter() {
- @Override
- public void componentResized(ComponentEvent e) {
- hoverHighlightRegions.clear();
- updateSize();
- repaint();
- }
- });
-
- Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
- public void eventDispatched(AWTEvent event) {
- enableEraseMode((KeyEvent) event);
- }
- }, AWTEvent.KEY_EVENT_MASK);
-
- checkButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent event) {
- if (!showBadPatches) {
- corruptedPatches = CorruptPatch.findBadPatches(ImageViewer.this.image,
- patchInfo);
- checkButton.setText("Hide bad patches");
- } else {
- checkButton.setText("Show bad patches");
- corruptedPatches = null;
- }
- repaint();
- showBadPatches = !showBadPatches;
- }
- });
- }
-
- private void updateDrawMode(MouseEvent event) {
- if (event.isShiftDown()) {
- currentMode = DrawMode.ERASE;
- } else if (event.isControlDown()) {
- currentMode = DrawMode.LAYOUT_BOUND;
- } else {
- currentMode = DrawMode.PATCH;
- }
- }
-
- private void resetDrawMode() {
- currentMode = DrawMode.PATCH;
- }
-
- private enum UpdateRegion {
- LEFT_PATCH,
- TOP_PATCH,
- RIGHT_PADDING,
- BOTTOM_PADDING,
- }
-
- private static class UpdateRegionInfo {
- public final UpdateRegion region;
- public final Pair<Integer> segment;
-
- private UpdateRegionInfo(UpdateRegion region, Pair<Integer> segment) {
- this.region = region;
- this.segment = segment;
- }
- }
-
- private UpdateRegionInfo findVerticalPatch(int x, int y) {
- List<Pair<Integer>> markers;
- UpdateRegion region;
-
- // Given the mouse x location, we need to determine if we need to map this edit to
- // the patch info at the left, or the padding info at the right. We make this decision
- // based on whichever is closer, so if the mouse x is in the left half of the image,
- // we are editing the left patch, else the right padding.
- if (x < image.getWidth() / 2) {
- markers = patchInfo.verticalPatchMarkers;
- region = UpdateRegion.LEFT_PATCH;
- } else {
- markers = patchInfo.verticalPaddingMarkers;
- region = UpdateRegion.RIGHT_PADDING;
- }
-
- return getContainingPatch(markers, y, region);
- }
-
- private UpdateRegionInfo findHorizontalPatch(int x, int y) {
- List<Pair<Integer>> markers;
- UpdateRegion region;
-
- if (y < image.getHeight() / 2) {
- markers = patchInfo.horizontalPatchMarkers;
- region = UpdateRegion.TOP_PATCH;
- } else {
- markers = patchInfo.horizontalPaddingMarkers;
- region = UpdateRegion.BOTTOM_PADDING;
- }
-
- return getContainingPatch(markers, x, region);
- }
-
- private UpdateRegionInfo getContainingPatch(List<Pair<Integer>> patches, int a,
- UpdateRegion region) {
- for (Pair<Integer> p: patches) {
- if (p.first <= a && p.second > a) {
- return new UpdateRegionInfo(region, p);
- }
-
- if (p.first > a) {
- break;
- }
- }
-
- return new UpdateRegionInfo(region, null);
- }
-
- private void updateHoverRegion(int x, int y) {
- // find regions to highlight based on the horizontal and vertical patches that
- // cover this (x, y)
- UpdateRegionInfo vertical = findVerticalPatch(x, y);
- UpdateRegionInfo horizontal = findHorizontalPatch(x, y);
- computeHoverHighlightRegions(vertical, horizontal);
- computeHoverRegionTooltip(vertical, horizontal);
-
- // change cursor if (x,y) is at the edge of either of the regions
- UpdateRegionInfo updateRegion = pickUpdateRegion(x, y, vertical, horizontal);
- setCursorForRegion(x, y, updateRegion);
- }
-
- private void startEditingRegion(int x, int y) {
- hoverHighlightRegions.clear();
- isEditMode = false;
- editRegion = null;
-
- UpdateRegionInfo vertical = findVerticalPatch(x, y);
- UpdateRegionInfo horizontal = findHorizontalPatch(x, y);
- UpdateRegionInfo updateRegion = pickUpdateRegion(x, y, vertical, horizontal);
- setCursorForRegion(x, y, updateRegion);
-
- if (updateRegion != null) { // edit an existing patch
- editRegion = updateRegion.region;
- isEditMode = true;
-
- Edge e = null;
- switch (this.editRegion) {
- case LEFT_PATCH:
- case RIGHT_PADDING:
- e = getClosestEdge(y, updateRegion.segment);
- break;
- case TOP_PATCH:
- case BOTTOM_PADDING:
- e = getClosestEdge(x, updateRegion.segment);
- break;
- default:
- assert false : this.editRegion;
- }
-
- int first = updateRegion.segment.first;
- int second = updateRegion.segment.second;
-
- // The edge being edited should always be the end point in editSegment.
- boolean start = e == Edge.START;
- editSegment.first = start ? second : first;
- editSegment.second = start ? first : second;
-
- // clear the current patch data
- flushEditPatchData(0);
- } else if ((editRegion = findNewPatchRegion(x, y)) != null) { // create a new patch
- isEditMode = true;
-
- boolean verticalPatch = editRegion == UpdateRegion.LEFT_PATCH
- || editRegion == UpdateRegion.RIGHT_PADDING;
-
- x = clamp(x, 1, image.getWidth() - 1);
- y = clamp(y, 1, image.getHeight() - 1);
-
- editSegment.first = editSegment.second = verticalPatch ? y : x;
- }
-
- if (isEditMode) {
- computeEditHighlightRegions();
- }
-
- repaint();
- }
-
- private void endEditingRegion(int x, int y) {
- if (!isEditMode) {
- return;
- }
-
- x = clamp(x, 1, image.getWidth() - 1);
- y = clamp(y, 1, image.getHeight() - 1);
-
- switch (editRegion) {
- case LEFT_PATCH:
- case RIGHT_PADDING:
- editSegment.second = y;
- break;
- case TOP_PATCH:
- case BOTTOM_PADDING:
- editSegment.second = x;
- break;
- default:
- assert false : editRegion;
- }
-
- flushEditPatchData(PatchInfo.BLACK_TICK);
-
- hoverHighlightRegions.clear();
- setCursor(Cursor.getDefaultCursor());
- patchesChanged();
- repaint();
-
- isEditMode = false;
- editRegion = null;
- }
-
- private void updateEditRegion(int x, int y) {
- if (!isEditMode) {
- return;
- }
-
- x = clamp(x, 1, image.getWidth() - 1);
- y = clamp(y, 1, image.getHeight() - 1);
-
- switch (editRegion) {
- case LEFT_PATCH:
- case RIGHT_PADDING:
- editSegment.second = y;
- break;
- case TOP_PATCH:
- case BOTTOM_PADDING:
- editSegment.second = x;
- break;
- }
-
- computeEditHighlightRegions();
- repaint();
- }
-
- private int clamp(int i, int min, int max) {
- if (i < min) {
- return min;
- }
-
- if (i > max) {
- return max;
- }
-
- return i;
- }
-
- /** Returns the type of patch that should be created given the initial mouse location. */
- private UpdateRegion findNewPatchRegion(int x, int y) {
- boolean verticalPatch = y >= 0 && y <= image.getHeight();
- boolean horizontalPatch = x >= 0 && x <= image.getWidth();
-
- // Heuristic: If the pointer is within the vertical bounds of the image,
- // then we create a patch on the left or right depending on which side of the image
- // the pointer is on
- if (verticalPatch) {
- if (x < 0) {
- return UpdateRegion.LEFT_PATCH;
- } else if (x > image.getWidth()) {
- return UpdateRegion.RIGHT_PADDING;
- }
- }
-
- // Similarly, if it is within the horizontal bounds of the image,
- // then create a patch at the top or bottom depending on its location relative to the image
- if (horizontalPatch) {
- if (y < 0) {
- return UpdateRegion.TOP_PATCH;
- } else if (y > image.getHeight()) {
- return UpdateRegion.BOTTOM_PADDING;
- }
- }
-
- return null;
- }
-
- private void computeHoverHighlightRegions(UpdateRegionInfo vertical,
- UpdateRegionInfo horizontal) {
- hoverHighlightRegions.clear();
- if (vertical != null && vertical.segment != null) {
- hoverHighlightRegions.addAll(
- getHorizontalHighlightRegions(0,
- vertical.segment.first,
- image.getWidth(),
- vertical.segment.second - vertical.segment.first));
- }
- if (horizontal != null && horizontal.segment != null) {
- hoverHighlightRegions.addAll(
- getVerticalHighlightRegions(horizontal.segment.first,
- 0,
- horizontal.segment.second - horizontal.segment.first,
- image.getHeight()));
- }
- }
-
- private void computeHoverRegionTooltip(UpdateRegionInfo vertical, UpdateRegionInfo horizontal) {
- StringBuilder sb = new StringBuilder(50);
-
- if (vertical != null && vertical.segment != null) {
- if (vertical.region == UpdateRegion.LEFT_PATCH) {
- sb.append("Vertical Patch: ");
- } else {
- sb.append("Vertical Padding: ");
- }
- sb.append(String.format("%d - %d px",
- vertical.segment.first, vertical.segment.second));
- }
-
- if (horizontal != null && horizontal.segment != null) {
- if (sb.length() > 0) {
- sb.append(", ");
- }
- if (horizontal.region == UpdateRegion.TOP_PATCH) {
- sb.append("Horizontal Patch: ");
- } else {
- sb.append("Horizontal Padding: ");
- }
- sb.append(String.format("%d - %d px",
- horizontal.segment.first, horizontal.segment.second));
- }
-
- toolTipText = sb.length() > 0 ? sb.toString() : null;
- }
-
- private void computeEditHighlightRegions() {
- editHighlightRegions.clear();
-
- int f = editSegment.first;
- int s = editSegment.second;
- int min = Math.min(f, s);
- int diff = Math.abs(f - s);
-
- int imageWidth = image.getWidth();
- int imageHeight = image.getHeight();
-
- switch (editRegion) {
- case LEFT_PATCH:
- editPatchRegion = displayCoordinates(new Rectangle(0, min, 1, diff));
- editHighlightRegions.addAll(
- getHorizontalHighlightRegions(0, min, imageWidth, diff));
- break;
- case RIGHT_PADDING:
- editPatchRegion = displayCoordinates(new Rectangle(imageWidth - 1, min, 1, diff));
- editHighlightRegions.addAll(
- getHorizontalHighlightRegions(0, min, imageWidth, diff));
- break;
- case TOP_PATCH:
- editPatchRegion = displayCoordinates(new Rectangle(min, 0, diff, 1));
- editHighlightRegions.addAll(
- getVerticalHighlightRegions(min, 0, diff, imageHeight));
- break;
- case BOTTOM_PADDING:
- editPatchRegion = displayCoordinates(new Rectangle(min, imageHeight - 1, diff, 1));
- editHighlightRegions.addAll(
- getVerticalHighlightRegions(min, 0, diff, imageHeight));
- default:
- assert false : editRegion;
- }
- }
-
- private List<Rectangle> getHorizontalHighlightRegions(int x, int y, int w, int h) {
- List<Rectangle> l = new ArrayList<Rectangle>(3);
-
- // highlight the region within the image
- Rectangle r = displayCoordinates(new Rectangle(x, y, w, h));
- l.add(r);
-
- // add a 1 pixel line at the top and bottom that extends outside the image
- l.add(new Rectangle(0, r.y, getWidth(), 1));
- l.add(new Rectangle(0, r.y + r.height, getWidth(), 1));
- return l;
- }
-
- private List<Rectangle> getVerticalHighlightRegions(int x, int y, int w, int h) {
- List<Rectangle> l = new ArrayList<Rectangle>(3);
-
-
- // highlight the region within the image
- Rectangle r = displayCoordinates(new Rectangle(x, y, w, h));
- l.add(r);
-
- // add a 1 pixel line at the top and bottom that extends outside the image
- l.add(new Rectangle(r.x, 0, 1, getHeight()));
- l.add(new Rectangle(r.x + r.width, 0, 1, getHeight()));
-
- return l;
- }
-
- private void setCursorForRegion(int x, int y, UpdateRegionInfo region) {
- if (region != null) {
- Cursor c = getCursor(x, y, region);
- setCursor(c);
- } else {
- setCursor(Cursor.getDefaultCursor());
- }
- }
-
- private Cursor getCursor(int x, int y, UpdateRegionInfo editRegion) {
- Edge e;
- int cursor = Cursor.DEFAULT_CURSOR;
- switch (editRegion.region) {
- case LEFT_PATCH:
- case RIGHT_PADDING:
- e = getClosestEdge(y, editRegion.segment);
- cursor = (e == Edge.START) ? Cursor.N_RESIZE_CURSOR : Cursor.S_RESIZE_CURSOR;
- break;
- case TOP_PATCH:
- case BOTTOM_PADDING:
- e = getClosestEdge(x, editRegion.segment);
- cursor = (e == Edge.START) ? Cursor.W_RESIZE_CURSOR : Cursor.E_RESIZE_CURSOR;
- break;
- default:
- assert false : this.editRegion;
- }
-
- return Cursor.getPredefinedCursor(cursor);
- }
-
- /**
- * Returns whether the horizontal or the vertical region should be updated based on the
- * mouse pointer's location relative to the edges of either region. If no edge is close to
- * the mouse pointer, then it returns null.
- */
- private UpdateRegionInfo pickUpdateRegion(int x, int y, UpdateRegionInfo vertical,
- UpdateRegionInfo horizontal) {
- if (vertical != null && vertical.segment != null) {
- Edge e = getClosestEdge(y, vertical.segment);
- if (e != Edge.NONE) {
- return vertical;
- }
- }
-
- if (horizontal != null && horizontal.segment != null) {
- Edge e = getClosestEdge(x, horizontal.segment);
- if (e != Edge.NONE) {
- return horizontal;
- }
- }
-
- return null;
- }
-
- private enum Edge {
- START,
- END,
- NONE,
- }
-
- private static final int EDGE_DELTA = 1;
- private Edge getClosestEdge(int x, Pair<Integer> range) {
- if (Math.abs(x - range.first) <= EDGE_DELTA) {
- return Edge.START;
- } else if (Math.abs(range.second - x) <= EDGE_DELTA) {
- return Edge.END;
- } else {
- return Edge.NONE;
- }
- }
-
- private int imageYCoordinate(int y) {
- int top = helpPanel.getHeight() + (getHeight() - size.height) / 2;
- return (y - top) / zoom;
- }
-
- private int imageXCoordinate(int x) {
- int left = (getWidth() - size.width) / 2;
- return (x - left) / zoom;
- }
-
- private Point getImageOrigin() {
- int left = (getWidth() - size.width) / 2;
- int top = helpPanel.getHeight() + (getHeight() - size.height) / 2;
- return new Point(left, top);
- }
-
- private Rectangle displayCoordinates(Rectangle r) {
- Point imageOrigin = getImageOrigin();
-
- int x = r.x * zoom + imageOrigin.x;
- int y = r.y * zoom + imageOrigin.y;
- int w = r.width * zoom;
- int h = r.height * zoom;
-
- return new Rectangle(x, y, w, h);
- }
-
- private void updatePatchInfo() {
- patchInfo = new PatchInfo(image);
- }
-
- private void enableEraseMode(KeyEvent event) {
- boolean oldEraseMode = eraseMode;
- eraseMode = event.isShiftDown();
- if (eraseMode != oldEraseMode) {
- if (eraseMode) {
- helpLabel.setText("Release Shift to draw pixels");
- } else {
- helpLabel.setText("Press Shift to erase pixels."
- + " Press Control to draw layout bounds");
- }
- }
- }
-
- private void startDrawingLine(int x, int y) {
- int width = image.getWidth();
- int height = image.getHeight();
- if (((x == 0 || x == width - 1) && (y > 0 && y < height - 1))
- || ((x > 0 && x < width - 1) && (y == 0 || y == height - 1))) {
- drawingLine = true;
- lineFromX = x;
- lineFromY = y;
- lineToX = x;
- lineToY = y;
-
- showDrawingLine = true;
-
- showCursor = false;
-
- repaint();
- }
- }
-
- private void moveLine(int x, int y) {
- if (!drawingLine) {
- return;
- }
-
- int width = image.getWidth();
- int height = image.getHeight();
-
- showDrawingLine = false;
-
- if (((x == lineFromX) && (y > 0 && y < height - 1))
- || ((x > 0 && x < width - 1) && (y == lineFromY))) {
- lineToX = x;
- lineToY = y;
-
- showDrawingLine = true;
- }
-
- repaint();
- }
-
- private void endDrawingLine() {
- if (!drawingLine) {
- return;
- }
-
- drawingLine = false;
-
- if (!showDrawingLine) {
- return;
- }
-
- int color;
- switch (currentMode) {
- case PATCH:
- color = PatchInfo.BLACK_TICK;
- break;
- case LAYOUT_BOUND:
- color = PatchInfo.RED_TICK;
- break;
- case ERASE:
- color = 0;
- break;
- default:
- return;
- }
-
- setPatchData(color, lineFromX, lineFromY, lineToX, lineToY, true);
-
- patchesChanged();
- repaint();
- }
-
- /**
- * Set the color of pixels on the line from (x1, y1) to (x2, y2) to given color.
- * @param inclusive indicates whether the range is inclusive. If true, the last pixel (x2, y2)
- * will be set to the given color as well.
- */
- private void setPatchData(int color, int x1, int y1, int x2, int y2, boolean inclusive) {
- int x = x1;
- int y = y1;
-
- int dx = 0;
- int dy = 0;
-
- if (x2 != x1) {
- dx = x2 > x1 ? 1 : -1;
- } else if (y2 != y1) {
- dy = y2 > y1 ? 1 : -1;
- }
-
- while (x != x2 || y != y2) {
- image.setRGB(x, y, color);
- x += dx;
- y += dy;
- }
-
- if (inclusive) {
- image.setRGB(x, y, color);
- }
- }
-
- /** Flushes current edit data to the image. */
- private void flushEditPatchData(int color) {
- int x1, y1, x2, y2;
- x1 = x2 = y1 = y2 = 0;
- int min = Math.min(editSegment.first, editSegment.second);
- int max = Math.max(editSegment.first, editSegment.second);
- switch (editRegion) {
- case LEFT_PATCH:
- x1 = x2 = 0;
- y1 = min;
- y2 = max;
- break;
- case RIGHT_PADDING:
- x1 = x2 = image.getWidth() - 1;
- y1 = min;
- y2 = max;
- break;
- case TOP_PATCH:
- x1 = min;
- x2 = max;
- y1 = y2 = 0;
- break;
- case BOTTOM_PADDING:
- x1 = min;
- x2 = max;
- y1 = y2 = image.getHeight() - 1;
- break;
- default:
- assert false : editRegion;
- }
-
- setPatchData(color, x1, y1, x2, y2, false);
- }
-
- private void patchesChanged() {
- updatePatchInfo();
- notifyPatchesUpdated();
- if (showBadPatches) {
- corruptedPatches = CorruptPatch.findBadPatches(image, patchInfo);
- }
- }
-
- private boolean checkLockedRegion(int x, int y) {
- int oldX = lastPositionX;
- int oldY = lastPositionY;
- lastPositionX = x;
- lastPositionY = y;
-
- int width = image.getWidth();
- int height = image.getHeight();
-
- statusBar.setPointerLocation(Math.max(0, Math.min(x, width - 1)),
- Math.max(0, Math.min(y, height - 1)));
-
- boolean previousLock = locked;
- locked = x > 0 && x < width - 1 && y > 0 && y < height - 1;
-
- boolean previousCursor = showCursor;
- showCursor =
- !drawingLine &&
- ( ((x == 0 || x == width - 1) && (y > 0 && y < height - 1)) ||
- ((x > 0 && x < width - 1) && (y == 0 || y == height - 1)) );
-
- if (locked != previousLock) {
- repaint();
- } else if (showCursor || (showCursor != previousCursor)) {
- Rectangle clip = new Rectangle(lastPositionX - 1 - zoom / 2,
- lastPositionY - 1 - zoom / 2, zoom + 2, zoom + 2);
- clip = clip.union(new Rectangle(oldX - 1 - zoom / 2,
- oldY - 1 - zoom / 2, zoom + 2, zoom + 2));
- repaint(clip);
- }
-
- return locked;
- }
-
- @Override
- protected void paintComponent(Graphics g) {
- int x = (getWidth() - size.width) / 2;
- int y = helpPanel.getHeight() + (getHeight() - size.height) / 2;
-
- Graphics2D g2 = (Graphics2D) g.create();
- g2.setColor(BACK_COLOR);
- g2.fillRect(0, 0, getWidth(), getHeight());
-
- g2.translate(x, y);
- g2.setPaint(texture);
- g2.fillRect(0, 0, size.width, size.height);
- g2.scale(zoom, zoom);
- g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
- RenderingHints.VALUE_ANTIALIAS_ON);
- g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
- RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
- g2.drawImage(image, 0, 0, null);
-
- if (showPatches) {
- g2.setColor(PATCH_COLOR);
- for (Rectangle patch : patchInfo.patches) {
- g2.fillRect(patch.x, patch.y, patch.width, patch.height);
- }
- g2.setColor(PATCH_ONEWAY_COLOR);
- for (Rectangle patch : patchInfo.horizontalPatches) {
- g2.fillRect(patch.x, patch.y, patch.width, patch.height);
- }
- for (Rectangle patch : patchInfo.verticalPatches) {
- g2.fillRect(patch.x, patch.y, patch.width, patch.height);
- }
- }
-
- if (corruptedPatches != null) {
- g2.setColor(CORRUPTED_COLOR);
- g2.setStroke(new BasicStroke(3.0f / zoom));
- for (Rectangle patch : corruptedPatches) {
- g2.draw(new RoundRectangle2D.Float(patch.x - 2.0f / zoom, patch.y - 2.0f / zoom,
- patch.width + 2.0f / zoom, patch.height + 2.0f / zoom,
- 6.0f / zoom, 6.0f / zoom));
- }
- }
-
- if (showLock && locked) {
- int width = image.getWidth();
- int height = image.getHeight();
-
- g2.setColor(LOCK_COLOR);
- g2.fillRect(1, 1, width - 2, height - 2);
-
- g2.setColor(STRIPES_COLOR);
- g2.translate(1, 1);
- paintStripes(g2, width - 2, height - 2);
- g2.translate(-1, -1);
- }
-
- g2.dispose();
-
- if (drawingLine && showDrawingLine) {
- Graphics cursor = g.create();
- cursor.setXORMode(Color.WHITE);
- cursor.setColor(Color.BLACK);
-
- x = Math.min(lineFromX, lineToX);
- y = Math.min(lineFromY, lineToY);
- int w = Math.abs(lineFromX - lineToX) + 1;
- int h = Math.abs(lineFromY - lineToY) + 1;
-
- x = x * zoom;
- y = y * zoom;
- w = w * zoom;
- h = h * zoom;
-
- int left = (getWidth() - size.width) / 2;
- int top = helpPanel.getHeight() + (getHeight() - size.height)
- / 2;
-
- x += left;
- y += top;
-
- cursor.drawRect(x, y, w, h);
- cursor.dispose();
- }
-
- if (showCursor) {
- Graphics cursor = g.create();
- cursor.setXORMode(Color.WHITE);
- cursor.setColor(Color.BLACK);
- cursor.drawRect(lastPositionX - zoom / 2, lastPositionY - zoom / 2, zoom, zoom);
- cursor.dispose();
- }
-
- g2 = (Graphics2D) g.create();
- g2.setColor(HIGHLIGHT_REGION_COLOR);
- for (Rectangle r: hoverHighlightRegions) {
- g2.fillRect(r.x, r.y, r.width, r.height);
- }
-
- if (!hoverHighlightRegions.isEmpty()) {
- setToolTipText(toolTipText);
- } else {
- setToolTipText(null);
- }
-
- if (isEditMode && editRegion != null) {
- g2.setColor(HIGHLIGHT_REGION_COLOR);
- for (Rectangle r: editHighlightRegions) {
- g2.fillRect(r.x, r.y, r.width, r.height);
- }
- g2.setColor(Color.BLACK);
- g2.fillRect(editPatchRegion.x, editPatchRegion.y,
- editPatchRegion.width, editPatchRegion.height);
- }
-
- g2.dispose();
- }
-
- private void paintStripes(Graphics2D g, int width, int height) {
- //draws pinstripes at the angle specified in this class
- //and at the given distance apart
- Shape oldClip = g.getClip();
- Area area = new Area(new Rectangle(0, 0, width, height));
- if(oldClip != null) {
- area = new Area(oldClip);
- }
- area.intersect(new Area(new Rectangle(0,0,width,height)));
- g.setClip(area);
-
- g.setStroke(new BasicStroke(STRIPES_WIDTH));
-
- double hypLength = Math.sqrt((width * width) +
- (height * height));
-
- double radians = Math.toRadians(STRIPES_ANGLE);
- g.rotate(radians);
-
- double spacing = STRIPES_SPACING;
- spacing += STRIPES_WIDTH;
- int numLines = (int)(hypLength / spacing);
-
- for (int i=0; i<numLines; i++) {
- double x = i * spacing;
- Line2D line = new Line2D.Double(x, -hypLength, x, hypLength);
- g.draw(line);
- }
- g.setClip(oldClip);
- }
-
- @Override
- public Dimension getPreferredSize() {
- return size;
- }
-
- private void setDefaultZoom() {
- int frameWidth = getWidth(), frameHeight = getHeight();
- int z = DEFAULT_ZOOM;
- if (frameWidth > 0 && frameHeight > 0) {
- float w = (float) image.getWidth() / frameWidth;
- float h = (float) image.getHeight() / frameHeight;
-
- float current = Math.max(w, h);
- float ideal = IDEAL_IMAGE_FRACTION_OF_WINDOW;
-
- z = clamp(Math.round(ideal / current), 1, MAX_ZOOM);
- }
- setZoom(z);
- }
-
- void setZoom(int value) {
- zoom = value;
- updateSize();
- if (!size.equals(getSize())) {
- setSize(size);
- container.validate();
- repaint();
- }
- }
-
- int getZoom() {
- return zoom;
- }
-
- private void updateSize() {
- int width = image.getWidth();
- int height = image.getHeight();
-
- if (size.height == 0 || (getHeight() - size.height) == 0) {
- size.setSize(width * zoom, height * zoom + helpPanel.getHeight());
- } else {
- size.setSize(width * zoom, height * zoom);
- }
- }
-
- void setPatchesVisible(boolean visible) {
- showPatches = visible;
- updatePatchInfo();
- repaint();
- }
-
- void setLockVisible(boolean visible) {
- showLock = visible;
- repaint();
- }
-
- public void setImage(BufferedImage image) {
- this.image = image;
- }
-
- public BufferedImage getImage() {
- return image;
- }
-
- public PatchInfo getPatchInfo() {
- return patchInfo;
- }
-
- public interface StatusBar {
- void setPointerLocation(int x, int y);
- }
-
- public interface PatchUpdateListener {
- void patchesUpdated();
- }
-
- private final Set<PatchUpdateListener> listeners = new HashSet<PatchUpdateListener>();
-
- public void addPatchUpdateListener(PatchUpdateListener p) {
- listeners.add(p);
- }
-
- public void removePatchUpdateListener(PatchUpdateListener p) {
- listeners.remove(p);
- }
-
- private void notifyPatchesUpdated() {
- for (PatchUpdateListener p: listeners) {
- p.patchesUpdated();
- }
- }
-} \ No newline at end of file
diff --git a/draw9patch/src/main/java/com/android/draw9patch/ui/MainFrame.java b/draw9patch/src/main/java/com/android/draw9patch/ui/MainFrame.java
deleted file mode 100644
index ff749f4..0000000
--- a/draw9patch/src/main/java/com/android/draw9patch/ui/MainFrame.java
+++ /dev/null
@@ -1,179 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed 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 com.android.draw9patch.ui;
-
-import com.android.draw9patch.graphics.GraphicsUtilities;
-import com.android.draw9patch.ui.action.ExitAction;
-import com.android.draw9patch.ui.action.OpenAction;
-import com.android.draw9patch.ui.action.SaveAction;
-
-import java.awt.HeadlessException;
-import java.awt.image.BufferedImage;
-import java.io.File;
-import java.util.concurrent.ExecutionException;
-
-import javax.imageio.ImageIO;
-import javax.swing.ActionMap;
-import javax.swing.JFileChooser;
-import javax.swing.JFrame;
-import javax.swing.JMenu;
-import javax.swing.JMenuBar;
-import javax.swing.JMenuItem;
-import javax.swing.SwingWorker;
-
-public class MainFrame extends JFrame {
- private ActionMap actionsMap;
- private JMenuItem saveMenuItem;
- private ImageEditorPanel imageEditor;
-
- private static final String TITLE_FORMAT = "Draw 9-patch: %s";
-
- public MainFrame(String path) throws HeadlessException {
- super("Draw 9-patch");
-
- buildActions();
- buildMenuBar();
- buildContent();
-
- if (path == null) {
- showOpenFilePanel();
- } else {
- try {
- File file = new File(path);
- BufferedImage img = GraphicsUtilities.loadCompatibleImage(file.toURI().toURL());
- showImageEditor(img, file.getAbsolutePath());
-
- setTitle(String.format(TITLE_FORMAT, path));
- } catch (Exception ex) {
- showOpenFilePanel();
- }
- }
-
- // pack();
- setSize(1024, 600);
- }
-
- private void buildActions() {
- actionsMap = new ActionMap();
- actionsMap.put(OpenAction.ACTION_NAME, new OpenAction(this));
- actionsMap.put(SaveAction.ACTION_NAME, new SaveAction(this));
- actionsMap.put(ExitAction.ACTION_NAME, new ExitAction(this));
- }
-
- private void buildMenuBar() {
- JMenu fileMenu = new JMenu("File");
- JMenuItem openMenuItem = new JMenuItem();
- saveMenuItem = new JMenuItem();
- JMenuItem exitMenuItem = new JMenuItem();
-
- openMenuItem.setAction(actionsMap.get(OpenAction.ACTION_NAME));
- fileMenu.add(openMenuItem);
-
- saveMenuItem.setAction(actionsMap.get(SaveAction.ACTION_NAME));
- saveMenuItem.setEnabled(false);
- fileMenu.add(saveMenuItem);
-
- exitMenuItem.setAction(actionsMap.get(ExitAction.ACTION_NAME));
- fileMenu.add(exitMenuItem);
-
- JMenuBar menuBar = new JMenuBar();
- menuBar.add(fileMenu);
- setJMenuBar(menuBar);
- }
-
- private void buildContent() {
- setContentPane(new GradientPanel());
- }
-
- private void showOpenFilePanel() {
- add(new OpenFilePanel(this));
- }
-
- public SwingWorker<?, ?> open(File file) {
- if (file == null) {
- JFileChooser chooser = new JFileChooser();
- chooser.setFileFilter(new PngFileFilter());
- int choice = chooser.showOpenDialog(this);
- if (choice == JFileChooser.APPROVE_OPTION) {
- return new OpenTask(chooser.getSelectedFile());
- } else {
- return null;
- }
- } else {
- return new OpenTask(file);
- }
- }
-
- void showImageEditor(BufferedImage image, String name) {
- getContentPane().removeAll();
- imageEditor = new ImageEditorPanel(this, image, name);
- add(imageEditor);
- saveMenuItem.setEnabled(true);
- validate();
- repaint();
- }
-
- public SwingWorker<?, ?> save() {
- if (imageEditor == null) {
- return null;
- }
-
- File file = imageEditor.chooseSaveFile();
- return file != null ? new SaveTask(file) : null;
- }
-
- private class SaveTask extends SwingWorker<Boolean, Void> {
- private final File file;
-
- SaveTask(File file) {
- this.file = file;
- }
-
- protected Boolean doInBackground() throws Exception {
- try {
- ImageIO.write(imageEditor.getImage(), "PNG", file);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return true;
- }
- }
-
- private class OpenTask extends SwingWorker<BufferedImage, Void> {
- private final File file;
-
- OpenTask(File file) {
- this.file = file;
- }
-
- protected BufferedImage doInBackground() throws Exception {
- return GraphicsUtilities.loadCompatibleImage(file.toURI().toURL());
- }
-
- @Override
- protected void done() {
- try {
- showImageEditor(get(), file.getAbsolutePath());
- setTitle(String.format(TITLE_FORMAT, file.getAbsolutePath()));
- } catch (InterruptedException e) {
- e.printStackTrace();
- } catch (ExecutionException e) {
- e.printStackTrace();
- }
- }
- }
-}
diff --git a/draw9patch/src/main/java/com/android/draw9patch/ui/OpenFilePanel.java b/draw9patch/src/main/java/com/android/draw9patch/ui/OpenFilePanel.java
deleted file mode 100644
index a444332..0000000
--- a/draw9patch/src/main/java/com/android/draw9patch/ui/OpenFilePanel.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package com.android.draw9patch.ui;
-
-import com.android.draw9patch.graphics.GraphicsUtilities;
-
-import javax.swing.JComponent;
-import java.awt.image.BufferedImage;
-import java.awt.Graphics;
-import java.io.IOException;
-import java.net.URL;/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed 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.
- */
-
-class OpenFilePanel extends JComponent {
- private BufferedImage dropHere;
-
- OpenFilePanel(MainFrame mainFrame) {
- setOpaque(false);
- loadSupportImage();
- setTransferHandler(new ImageTransferHandler(mainFrame));
- }
-
- private void loadSupportImage() {
- try {
- URL resource = getClass().getResource("/images/drop.png");
- dropHere = GraphicsUtilities.loadCompatibleImage(resource);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- @Override
- protected void paintComponent(Graphics g) {
- int x = (getWidth() - dropHere.getWidth()) / 2;
- int y = (getHeight() - dropHere.getHeight()) / 2;
-
- g.drawImage(dropHere, x, y, null);
- }
-
-}
diff --git a/draw9patch/src/main/java/com/android/draw9patch/ui/Pair.java b/draw9patch/src/main/java/com/android/draw9patch/ui/Pair.java
deleted file mode 100644
index bc38671..0000000
--- a/draw9patch/src/main/java/com/android/draw9patch/ui/Pair.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed 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 com.android.draw9patch.ui;
-
-public class Pair<E> {
- E first;
- E second;
-
- Pair(E first, E second) {
- this.first = first;
- this.second = second;
- }
-
- @Override
- public String toString() {
- return "Pair[" + first + ", " + second + "]";
- }
-}
diff --git a/draw9patch/src/main/java/com/android/draw9patch/ui/PatchInfo.java b/draw9patch/src/main/java/com/android/draw9patch/ui/PatchInfo.java
deleted file mode 100644
index 0cca67b..0000000
--- a/draw9patch/src/main/java/com/android/draw9patch/ui/PatchInfo.java
+++ /dev/null
@@ -1,225 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed 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 com.android.draw9patch.ui;
-
-import com.android.draw9patch.graphics.GraphicsUtilities;
-
-import java.awt.Rectangle;
-import java.awt.image.BufferedImage;
-import java.util.ArrayList;
-import java.util.List;
-
-public class PatchInfo {
- /** Color used to indicate stretch regions and padding. */
- public static final int BLACK_TICK = 0xFF000000;
-
- /** Color used to indicate layout bounds. */
- public static final int RED_TICK = 0xFFFF0000;
-
- /** Areas of the image that are stretchable in both directions. */
- public final List<Rectangle> patches;
-
- /** Areas of the image that are not stretchable in either direction. */
- public final List<Rectangle> fixed;
-
- /** Areas of image stretchable horizontally. */
- public final List<Rectangle> horizontalPatches;
-
- /** Areas of image stretchable vertically. */
- public final List<Rectangle> verticalPatches;
-
- /** Bounds of horizontal patch markers. */
- public final List<Pair<Integer>> horizontalPatchMarkers;
-
- /** Bounds of horizontal padding markers. */
- public final List<Pair<Integer>> horizontalPaddingMarkers;
-
- /** Bounds of vertical patch markers. */
- public final List<Pair<Integer>> verticalPatchMarkers;
-
- /** Bounds of vertical padding markers. */
- public final List<Pair<Integer>> verticalPaddingMarkers;
-
- public final boolean verticalStartWithPatch;
- public final boolean horizontalStartWithPatch;
-
- /** Beginning and end padding in the horizontal direction */
- public final Pair<Integer> horizontalPadding;
-
- /** Beginning and end padding in the vertical direction */
- public final Pair<Integer> verticalPadding;
-
- private BufferedImage image;
-
- public PatchInfo(BufferedImage image) {
- this.image = image;
-
- int width = image.getWidth();
- int height = image.getHeight();
-
- int[] row = GraphicsUtilities.getPixels(image, 0, 0, width, 1, null);
- int[] column = GraphicsUtilities.getPixels(image, 0, 0, 1, height, null);
-
- P left = getPatches(column);
- verticalStartWithPatch = left.startsWithPatch;
- verticalPatchMarkers = left.patches;
-
- P top = getPatches(row);
- horizontalStartWithPatch = top.startsWithPatch;
- horizontalPatchMarkers = top.patches;
-
- fixed = getRectangles(left.fixed, top.fixed);
- patches = getRectangles(left.patches, top.patches);
-
- if (fixed.size() > 0) {
- horizontalPatches = getRectangles(left.fixed, top.patches);
- verticalPatches = getRectangles(left.patches, top.fixed);
- } else {
- if (top.fixed.size() > 0) {
- horizontalPatches = new ArrayList<Rectangle>(0);
- verticalPatches = getVerticalRectangles(top.fixed);
- } else if (left.fixed.size() > 0) {
- horizontalPatches = getHorizontalRectangles(left.fixed);
- verticalPatches = new ArrayList<Rectangle>(0);
- } else {
- horizontalPatches = verticalPatches = new ArrayList<Rectangle>(0);
- }
- }
-
- row = GraphicsUtilities.getPixels(image, 0, height - 1, width, 1, row);
- column = GraphicsUtilities.getPixels(image, width - 1, 0, 1, height, column);
-
- top = PatchInfo.getPatches(row);
- horizontalPaddingMarkers = top.patches;
- horizontalPadding = getPadding(top.fixed);
-
- left = PatchInfo.getPatches(column);
- verticalPaddingMarkers = left.patches;
- verticalPadding = getPadding(left.fixed);
- }
-
- private List<Rectangle> getVerticalRectangles(List<Pair<Integer>> topPairs) {
- List<Rectangle> rectangles = new ArrayList<Rectangle>();
- for (Pair<Integer> top : topPairs) {
- int x = top.first;
- int width = top.second - top.first;
-
- rectangles.add(new Rectangle(x, 1, width, image.getHeight() - 2));
- }
- return rectangles;
- }
-
- private List<Rectangle> getHorizontalRectangles(List<Pair<Integer>> leftPairs) {
- List<Rectangle> rectangles = new ArrayList<Rectangle>();
- for (Pair<Integer> left : leftPairs) {
- int y = left.first;
- int height = left.second - left.first;
-
- rectangles.add(new Rectangle(1, y, image.getWidth() - 2, height));
- }
- return rectangles;
- }
-
- private Pair<Integer> getPadding(List<Pair<Integer>> pairs) {
- if (pairs.size() == 0) {
- return new Pair<Integer>(0, 0);
- } else if (pairs.size() == 1) {
- if (pairs.get(0).first == 1) {
- return new Pair<Integer>(pairs.get(0).second - pairs.get(0).first, 0);
- } else {
- return new Pair<Integer>(0, pairs.get(0).second - pairs.get(0).first);
- }
- } else {
- int index = pairs.size() - 1;
- return new Pair<Integer>(pairs.get(0).second - pairs.get(0).first,
- pairs.get(index).second - pairs.get(index).first);
- }
- }
-
- private List<Rectangle> getRectangles(List<Pair<Integer>> leftPairs,
- List<Pair<Integer>> topPairs) {
- List<Rectangle> rectangles = new ArrayList<Rectangle>();
- for (Pair<Integer> left : leftPairs) {
- int y = left.first;
- int height = left.second - left.first;
- for (Pair<Integer> top : topPairs) {
- int x = top.first;
- int width = top.second - top.first;
-
- rectangles.add(new Rectangle(x, y, width, height));
- }
- }
- return rectangles;
- }
-
- private static class P {
- public final List<Pair<Integer>> fixed;
- public final List<Pair<Integer>> patches;
- public final boolean startsWithPatch;
-
- private P(List<Pair<Integer>> f, List<Pair<Integer>> p, boolean s) {
- fixed = f;
- patches = p;
- startsWithPatch = s;
- }
- }
-
- private static P getPatches(int[] pixels) {
- int lastIndex = 1;
- int lastPixel;
- boolean first = true;
- boolean startWithPatch = false;
-
- List<Pair<Integer>> fixed = new ArrayList<Pair<Integer>>();
- List<Pair<Integer>> patches = new ArrayList<Pair<Integer>>();
-
- // ignore layout bound markers for the purpose of patch calculation
- lastPixel = pixels[1] != PatchInfo.RED_TICK ? pixels[1] : 0;
-
- for (int i = 1; i < pixels.length - 1; i++) {
- // ignore layout bound markers for the purpose of patch calculation
- int pixel = pixels[i] != PatchInfo.RED_TICK ? pixels[i] : 0;
-
- if (pixel != lastPixel) {
- if (lastPixel == BLACK_TICK) {
- if (first) startWithPatch = true;
- patches.add(new Pair<Integer>(lastIndex, i));
- } else {
- fixed.add(new Pair<Integer>(lastIndex, i));
- }
- first = false;
-
- lastIndex = i;
- lastPixel = pixel;
- }
- }
- if (lastPixel == BLACK_TICK) {
- if (first) startWithPatch = true;
- patches.add(new Pair<Integer>(lastIndex, pixels.length - 1));
- } else {
- fixed.add(new Pair<Integer>(lastIndex, pixels.length - 1));
- }
-
- if (patches.size() == 0) {
- patches.add(new Pair<Integer>(1, pixels.length - 1));
- startWithPatch = true;
- fixed.clear();
- }
-
- return new P(fixed, patches, startWithPatch);
- }
-}
diff --git a/draw9patch/src/main/java/com/android/draw9patch/ui/PngFileFilter.java b/draw9patch/src/main/java/com/android/draw9patch/ui/PngFileFilter.java
deleted file mode 100644
index 8f8885a..0000000
--- a/draw9patch/src/main/java/com/android/draw9patch/ui/PngFileFilter.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed 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 com.android.draw9patch.ui;
-
-import javax.swing.filechooser.FileFilter;
-import java.io.File;
-
-class PngFileFilter extends FileFilter {
- @Override
- public boolean accept(File f) {
- return f.isDirectory() || f.getName().toLowerCase().endsWith(".png");
- }
-
- @Override
- public String getDescription() {
- return "PNG Image (*.png)";
- }
-}
diff --git a/draw9patch/src/main/java/com/android/draw9patch/ui/StretchesViewer.java b/draw9patch/src/main/java/com/android/draw9patch/ui/StretchesViewer.java
deleted file mode 100644
index efe0055..0000000
--- a/draw9patch/src/main/java/com/android/draw9patch/ui/StretchesViewer.java
+++ /dev/null
@@ -1,326 +0,0 @@
-/*
- *
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed 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 com.android.draw9patch.ui;
-
-import java.awt.Color;
-import java.awt.Container;
-import java.awt.Dimension;
-import java.awt.Graphics;
-import java.awt.Graphics2D;
-import java.awt.GridBagConstraints;
-import java.awt.GridBagLayout;
-import java.awt.Insets;
-import java.awt.Rectangle;
-import java.awt.RenderingHints;
-import java.awt.TexturePaint;
-import java.awt.image.BufferedImage;
-
-import javax.swing.BorderFactory;
-import javax.swing.JComponent;
-import javax.swing.JPanel;
-
-public class StretchesViewer extends JPanel {
- public static final float DEFAULT_SCALE = 2.0f;
- private static final int MARGIN = 24;
-
- private final Container container;
- private final ImageViewer viewer;
- private final TexturePaint texture;
-
- private BufferedImage image;
- private PatchInfo patchInfo;
-
- private StretchView horizontal;
- private StretchView vertical;
- private StretchView both;
-
- private Dimension size;
-
- private float horizontalPatchesSum;
- private float verticalPatchesSum;
-
- private boolean showPadding;
-
- StretchesViewer(Container container, ImageViewer viewer, TexturePaint texture) {
- this.container = container;
- this.viewer = viewer;
- this.texture = texture;
-
- image = viewer.getImage();
- patchInfo = viewer.getPatchInfo();
-
- viewer.addPatchUpdateListener(new ImageViewer.PatchUpdateListener() {
- @Override
- public void patchesUpdated() {
- computePatches();
- }
- });
-
- setOpaque(false);
- setLayout(new GridBagLayout());
- setBorder(BorderFactory.createEmptyBorder(MARGIN, MARGIN, MARGIN, MARGIN));
-
- horizontal = new StretchView();
- vertical = new StretchView();
- both = new StretchView();
-
- setScale(DEFAULT_SCALE);
-
- add(vertical, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER,
- GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
- add(horizontal, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER,
- GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
- add(both, new GridBagConstraints(0, 2, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER,
- GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
- }
-
- @Override
- protected void paintComponent(Graphics g) {
- Graphics2D g2 = (Graphics2D) g.create();
- g2.setPaint(texture);
- g2.fillRect(0, 0, getWidth(), getHeight());
- g2.dispose();
- }
-
- void setScale(float scale) {
- int patchWidth = image.getWidth() - 2;
- int patchHeight = image.getHeight() - 2;
-
- int scaledWidth = (int) (patchWidth * scale);
- int scaledHeight = (int) (patchHeight * scale);
-
- horizontal.scaledWidth = scaledWidth;
- vertical.scaledHeight = scaledHeight;
- both.scaledWidth = scaledWidth;
- both.scaledHeight = scaledHeight;
-
- size = new Dimension(scaledWidth, scaledHeight);
-
- computePatches();
- }
-
- void computePatches() {
- image = viewer.getImage();
- patchInfo = viewer.getPatchInfo();
-
- boolean measuredWidth = false;
- boolean endRow = true;
-
- int remainderHorizontal = 0;
- int remainderVertical = 0;
-
- if (patchInfo.fixed.size() > 0) {
- int start = patchInfo.fixed.get(0).y;
- for (Rectangle rect : patchInfo.fixed) {
- if (rect.y > start) {
- endRow = true;
- measuredWidth = true;
- }
- if (!measuredWidth) {
- remainderHorizontal += rect.width;
- }
- if (endRow) {
- remainderVertical += rect.height;
- endRow = false;
- start = rect.y;
- }
- }
- }
-
- horizontal.remainderHorizontal = horizontal.scaledWidth - remainderHorizontal;
- vertical.remainderHorizontal = vertical.scaledWidth - remainderHorizontal;
- both.remainderHorizontal = both.scaledWidth - remainderHorizontal;
-
- horizontal.remainderVertical = horizontal.scaledHeight - remainderVertical;
- vertical.remainderVertical = vertical.scaledHeight - remainderVertical;
- both.remainderVertical = both.scaledHeight - remainderVertical;
-
- horizontalPatchesSum = 0;
- if (patchInfo.horizontalPatches.size() > 0) {
- int start = -1;
- for (Rectangle rect : patchInfo.horizontalPatches) {
- if (rect.x > start) {
- horizontalPatchesSum += rect.width;
- start = rect.x;
- }
- }
- } else {
- int start = -1;
- for (Rectangle rect : patchInfo.patches) {
- if (rect.x > start) {
- horizontalPatchesSum += rect.width;
- start = rect.x;
- }
- }
- }
-
- verticalPatchesSum = 0;
- if (patchInfo.verticalPatches.size() > 0) {
- int start = -1;
- for (Rectangle rect : patchInfo.verticalPatches) {
- if (rect.y > start) {
- verticalPatchesSum += rect.height;
- start = rect.y;
- }
- }
- } else {
- int start = -1;
- for (Rectangle rect : patchInfo.patches) {
- if (rect.y > start) {
- verticalPatchesSum += rect.height;
- start = rect.y;
- }
- }
- }
-
- setSize(size);
- container.validate();
- repaint();
- }
-
- void setPaddingVisible(boolean visible) {
- showPadding = visible;
- repaint();
- }
-
- private class StretchView extends JComponent {
- private final Color PADDING_COLOR = new Color(0.37f, 0.37f, 1.0f, 0.5f);
-
- int scaledWidth;
- int scaledHeight;
-
- int remainderHorizontal;
- int remainderVertical;
-
- StretchView() {
- scaledWidth = image.getWidth();
- scaledHeight = image.getHeight();
- }
-
- @Override
- protected void paintComponent(Graphics g) {
- int x = (getWidth() - scaledWidth) / 2;
- int y = (getHeight() - scaledHeight) / 2;
-
- Graphics2D g2 = (Graphics2D) g.create();
- g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
- RenderingHints.VALUE_INTERPOLATION_BILINEAR);
- g.translate(x, y);
-
- x = 0;
- y = 0;
-
- if (patchInfo.patches.size() == 0) {
- g.drawImage(image, 0, 0, scaledWidth, scaledHeight, null);
- g2.dispose();
- return;
- }
-
- int fixedIndex = 0;
- int horizontalIndex = 0;
- int verticalIndex = 0;
- int patchIndex = 0;
-
- boolean hStretch;
- boolean vStretch;
-
- float vWeightSum = 1.0f;
- float vRemainder = remainderVertical;
-
- vStretch = patchInfo.verticalStartWithPatch;
- while (y < scaledHeight - 1) {
- hStretch = patchInfo.horizontalStartWithPatch;
-
- int height = 0;
- float vExtra = 0.0f;
-
- float hWeightSum = 1.0f;
- float hRemainder = remainderHorizontal;
-
- while (x < scaledWidth - 1) {
- Rectangle r;
- if (!vStretch) {
- if (hStretch) {
- r = patchInfo.horizontalPatches.get(horizontalIndex++);
- float extra = r.width / horizontalPatchesSum;
- int width = (int) (extra * hRemainder / hWeightSum);
- hWeightSum -= extra;
- hRemainder -= width;
- g.drawImage(image, x, y, x + width, y + r.height, r.x, r.y,
- r.x + r.width, r.y + r.height, null);
- x += width;
- } else {
- r = patchInfo.fixed.get(fixedIndex++);
- g.drawImage(image, x, y, x + r.width, y + r.height, r.x, r.y,
- r.x + r.width, r.y + r.height, null);
- x += r.width;
- }
- height = r.height;
- } else {
- if (hStretch) {
- r = patchInfo.patches.get(patchIndex++);
- vExtra = r.height / verticalPatchesSum;
- height = (int) (vExtra * vRemainder / vWeightSum);
- float extra = r.width / horizontalPatchesSum;
- int width = (int) (extra * hRemainder / hWeightSum);
- hWeightSum -= extra;
- hRemainder -= width;
- g.drawImage(image, x, y, x + width, y + height, r.x, r.y,
- r.x + r.width, r.y + r.height, null);
- x += width;
- } else {
- r = patchInfo.verticalPatches.get(verticalIndex++);
- vExtra = r.height / verticalPatchesSum;
- height = (int) (vExtra * vRemainder / vWeightSum);
- g.drawImage(image, x, y, x + r.width, y + height, r.x, r.y,
- r.x + r.width, r.y + r.height, null);
- x += r.width;
- }
-
- }
- hStretch = !hStretch;
- }
- x = 0;
- y += height;
- if (vStretch) {
- vWeightSum -= vExtra;
- vRemainder -= height;
- }
- vStretch = !vStretch;
- }
-
- if (showPadding) {
- g.setColor(PADDING_COLOR);
- g.fillRect(patchInfo.horizontalPadding.first,
- patchInfo.verticalPadding.first,
- scaledWidth - patchInfo.horizontalPadding.first
- - patchInfo.horizontalPadding.second,
- scaledHeight - patchInfo.verticalPadding.first
- - patchInfo.verticalPadding.second);
- }
-
- g2.dispose();
- }
-
- @Override
- public Dimension getPreferredSize() {
- return size;
- }
- }
-} \ No newline at end of file
diff --git a/draw9patch/src/main/java/com/android/draw9patch/ui/action/BackgroundAction.java b/draw9patch/src/main/java/com/android/draw9patch/ui/action/BackgroundAction.java
deleted file mode 100644
index 11bf261..0000000
--- a/draw9patch/src/main/java/com/android/draw9patch/ui/action/BackgroundAction.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed 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 com.android.draw9patch.ui.action;
-
-import javax.swing.AbstractAction;
-import javax.swing.SwingWorker;
-
-public abstract class BackgroundAction extends AbstractAction {
- protected void executeBackgroundTask(SwingWorker<?, ?> worker) {
- if (worker != null) {
- worker.execute();
- }
- }
-}
diff --git a/draw9patch/src/main/java/com/android/draw9patch/ui/action/ExitAction.java b/draw9patch/src/main/java/com/android/draw9patch/ui/action/ExitAction.java
deleted file mode 100644
index b6f047d..0000000
--- a/draw9patch/src/main/java/com/android/draw9patch/ui/action/ExitAction.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed 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 com.android.draw9patch.ui.action;
-
-import javax.swing.AbstractAction;
-import javax.swing.KeyStroke;
-import javax.swing.JFrame;
-import java.awt.event.KeyEvent;
-import java.awt.event.ActionEvent;
-import java.awt.Toolkit;
-
-public class ExitAction extends AbstractAction {
- public static final String ACTION_NAME = "exit";
- private JFrame frame;
-
- public ExitAction(JFrame frame) {
- putValue(NAME, "Quit");
- putValue(SHORT_DESCRIPTION, "Quit");
- putValue(LONG_DESCRIPTION, "Quit");
- putValue(MNEMONIC_KEY, KeyEvent.VK_Q);
- putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_Q,
- Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
- this.frame = frame;
- }
-
- public void actionPerformed(ActionEvent e) {
- frame.dispose();
- System.exit(0);
- }
-}
diff --git a/draw9patch/src/main/java/com/android/draw9patch/ui/action/OpenAction.java b/draw9patch/src/main/java/com/android/draw9patch/ui/action/OpenAction.java
deleted file mode 100644
index 45ee5be..0000000
--- a/draw9patch/src/main/java/com/android/draw9patch/ui/action/OpenAction.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed 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 com.android.draw9patch.ui.action;
-
-import com.android.draw9patch.ui.MainFrame;
-
-import javax.swing.KeyStroke;
-import java.awt.event.KeyEvent;
-import java.awt.event.ActionEvent;
-import java.awt.Toolkit;
-
-public class OpenAction extends BackgroundAction {
- public static final String ACTION_NAME = "open";
- private MainFrame frame;
-
- public OpenAction(MainFrame frame) {
- this.frame = frame;
- putValue(NAME, "Open 9-patch...");
- putValue(SHORT_DESCRIPTION, "Open...");
- putValue(LONG_DESCRIPTION, "Open 9-patch...");
- putValue(MNEMONIC_KEY, KeyEvent.VK_O);
- putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_O,
- Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
- }
-
- public void actionPerformed(ActionEvent e) {
- executeBackgroundTask(frame.open(null));
- }
-}
diff --git a/draw9patch/src/main/java/com/android/draw9patch/ui/action/SaveAction.java b/draw9patch/src/main/java/com/android/draw9patch/ui/action/SaveAction.java
deleted file mode 100644
index 5c1dc52..0000000
--- a/draw9patch/src/main/java/com/android/draw9patch/ui/action/SaveAction.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed 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 com.android.draw9patch.ui.action;
-
-import com.android.draw9patch.ui.MainFrame;
-
-import javax.swing.KeyStroke;
-import java.awt.event.KeyEvent;
-import java.awt.event.ActionEvent;
-import java.awt.Toolkit;
-
-public class SaveAction extends BackgroundAction {
- public static final String ACTION_NAME = "save";
- private MainFrame frame;
-
- public SaveAction(MainFrame frame) {
- this.frame = frame;
- putValue(NAME, "Save 9-patch...");
- putValue(SHORT_DESCRIPTION, "Save...");
- putValue(LONG_DESCRIPTION, "Save 9-patch...");
- putValue(MNEMONIC_KEY, KeyEvent.VK_S);
- putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_S,
- Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
- }
-
- public void actionPerformed(ActionEvent e) {
- executeBackgroundTask(frame.save());
- }
-}
diff --git a/draw9patch/src/main/resources/images/checker.png b/draw9patch/src/main/resources/images/checker.png
deleted file mode 100644
index 78908f4..0000000
--- a/draw9patch/src/main/resources/images/checker.png
+++ /dev/null
Binary files differ
diff --git a/draw9patch/src/main/resources/images/drop.png b/draw9patch/src/main/resources/images/drop.png
deleted file mode 100644
index 7a7436a..0000000
--- a/draw9patch/src/main/resources/images/drop.png
+++ /dev/null
Binary files differ
diff --git a/draw9patch/src/test/java/com/android/draw9patch/ui/PatchInfoTest.java b/draw9patch/src/test/java/com/android/draw9patch/ui/PatchInfoTest.java
deleted file mode 100644
index 7350b82..0000000
--- a/draw9patch/src/test/java/com/android/draw9patch/ui/PatchInfoTest.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- *
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed 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 com.android.draw9patch.ui;
-
-import junit.framework.TestCase;
-
-import java.awt.Rectangle;
-import java.awt.image.BufferedImage;
-
-public class PatchInfoTest extends TestCase {
- private BufferedImage createImage(String[] data) {
- int h = data.length;
- int w = data[0].length();
- BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
-
- for (int row = 0; row < h; row++) {
- for (int col = 0; col < w; col++) {
- char c = data[row].charAt(col);
- int color = 0;
- if (c == '*') {
- color = PatchInfo.BLACK_TICK;
- } else if (c == 'R') {
- color = PatchInfo.RED_TICK;
- }
- image.setRGB(col, row, color);
- }
- }
- return image;
- }
-
- public void testPatchInfo() {
- BufferedImage image = createImage(new String[] {
- "0123**6789",
- "1........*",
- "*........*",
- "3........*",
- "412*****89",
- });
- PatchInfo pi = new PatchInfo(image);
-
- // The left and top patch markers don't begin from the first pixel
- assertFalse(pi.horizontalStartWithPatch);
- assertFalse(pi.verticalStartWithPatch);
-
- // There should be one patch in the middle where the left and top patch markers intersect
- assertEquals(1, pi.patches.size());
- assertEquals(new Rectangle(4, 2, 2, 1), pi.patches.get(0));
-
- // There should be 2 horizontal stretchable areas - area below the top marker but excluding
- // the main patch
- assertEquals(2, pi.horizontalPatches.size());
- assertEquals(new Rectangle(4, 1, 2, 1), pi.horizontalPatches.get(0));
- assertEquals(new Rectangle(4, 3, 2, 1), pi.horizontalPatches.get(1));
-
- // Similarly, there should be 2 vertical stretchable areas
- assertEquals(2, pi.verticalPatches.size());
- assertEquals(new Rectangle(1, 2, 3, 1), pi.verticalPatches.get(0));
- assertEquals(new Rectangle(6, 2, 3, 1), pi.verticalPatches.get(1));
-
- // The should be 4 fixed regions - the regions that don't fall under the patches
- assertEquals(4, pi.fixed.size());
-
- // The horizontal padding is described by the bottom bar.
- // In this case, there is a 2 pixel (pixels 1 & 2) padding at start and 1 pixel (pixel 8)
- // padding at end
- assertEquals(2, pi.horizontalPadding.first.intValue());
- assertEquals(1, pi.horizontalPadding.second.intValue());
-
- // The vertical padding is described by the bar at the right.
- // In this case, there is no padding as the content area matches the image area
- assertEquals(0, pi.verticalPadding.first.intValue());
- assertEquals(0, pi.verticalPadding.second.intValue());
- }
-
- public void testPadding() {
- BufferedImage image = createImage(new String[] {
- "0123**6789",
- "1.........",
- "2.........",
- "3........*",
- "4........*",
- "5***456789",
- });
- PatchInfo pi = new PatchInfo(image);
-
- // 0 pixel padding at start and 5 pixel padding at the end (pixels 4 through 8 inclusive)
- assertEquals(0, pi.horizontalPadding.first.intValue());
- assertEquals(5, pi.horizontalPadding.second.intValue());
-
- // 2 pixel padding at the start and 0 at the end
- assertEquals(2, pi.verticalPadding.first.intValue());
- assertEquals(0, pi.verticalPadding.second.intValue());
- }
-
- // make sure that the presence of layout bound markers doesn't affect patch/padding info
- public void testIgnoreLayoutBoundMarkers() {
- BufferedImage image = createImage(new String[] {
- "0RR3**6789",
- "R........R",
- "*.........",
- "*........*",
- "4........*",
- "5***456R89",
- });
- PatchInfo pi = new PatchInfo(image);
-
- assertFalse(pi.horizontalStartWithPatch);
-
- assertEquals(1, pi.patches.size());
- assertEquals(2, pi.verticalPatches.size());
- assertEquals(2, pi.horizontalPatches.size());
- }
-}