diff --git a/.classpath b/.classpath
index 595b356..c80e233 100644
--- a/.classpath
+++ b/.classpath
@@ -3,6 +3,6 @@
-
-
+
+
diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md
new file mode 100644
index 0000000..c616fa3
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/bug_report.md
@@ -0,0 +1,31 @@
+---
+name: Bug report
+about: Create a report to help us improve
+title: ''
+labels: bug
+assignees: ''
+
+---
+
+**Describe the bug**
+A clear and concise description of what the bug is.
+
+**To Reproduce**
+Steps to reproduce the behavior:
+1. Go to '...'
+2. Click on '....'
+3. Scroll down to '....'
+4. See error
+
+**Expected behavior**
+A clear and concise description of what you expected to happen.
+
+**Screenshots**
+If applicable, add screenshots to help explain your problem.
+
+**Desktop (please complete the following information):**
+ - OS: [e.g. iOS]
+ - Version [e.g. 22]
+
+**Additional context**
+Add any other context about the problem here.
diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md
new file mode 100644
index 0000000..11fc491
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/feature_request.md
@@ -0,0 +1,20 @@
+---
+name: Feature request
+about: Suggest an idea for this project
+title: ''
+labels: enhancement
+assignees: ''
+
+---
+
+**Is your feature request related to a problem? Please describe.**
+A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
+
+**Describe the solution you'd like**
+A clear and concise description of what you want to happen.
+
+**Describe alternatives you've considered**
+A clear and concise description of any alternative solutions or features you've considered.
+
+**Additional context**
+Add any other context or screenshots about the feature request here.
diff --git a/.gitignore b/.gitignore
index 7a46396..74abb7e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,4 +11,7 @@
/antbin
/launch4j.log
target
-.idea/workspace.xml
+.idea/
+densities.json
+Resizer.eml
+resizer.iml
\ No newline at end of file
diff --git a/.idea/.name b/.idea/.name
deleted file mode 100644
index fea9e65..0000000
--- a/.idea/.name
+++ /dev/null
@@ -1 +0,0 @@
-9patch-resizer
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
deleted file mode 100644
index 217af47..0000000
--- a/.idea/compiler.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/.idea/copyright/Redwarp.xml b/.idea/copyright/Redwarp.xml
deleted file mode 100644
index fb25d3e..0000000
--- a/.idea/copyright/Redwarp.xml
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml
deleted file mode 100644
index a63a6f4..0000000
--- a/.idea/copyright/profiles_settings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
deleted file mode 100644
index e206d70..0000000
--- a/.idea/encodings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
-
-
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
deleted file mode 100644
index cb01329..0000000
--- a/.idea/gradle.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-
-
-
-
diff --git a/.idea/libraries/gson_2_2_4.xml b/.idea/libraries/gson_2_2_4.xml
deleted file mode 100644
index 33a40e6..0000000
--- a/.idea/libraries/gson_2_2_4.xml
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
deleted file mode 100644
index c4ab1ee..0000000
--- a/.idea/misc.xml
+++ /dev/null
@@ -1,211 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/.idea/modules.xml b/.idea/modules.xml
deleted file mode 100644
index 3636d50..0000000
--- a/.idea/modules.xml
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
-
-
-
-
-
-
diff --git a/.idea/scopes/scope_settings.xml b/.idea/scopes/scope_settings.xml
deleted file mode 100644
index 922003b..0000000
--- a/.idea/scopes/scope_settings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml
deleted file mode 100644
index 3b00020..0000000
--- a/.idea/uiDesigner.xml
+++ /dev/null
@@ -1,125 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
deleted file mode 100644
index 275077f..0000000
--- a/.idea/vcs.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-
-
-
-
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..dff5f3a
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1 @@
+language: java
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..b903778
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,201 @@
+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
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "{}"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright 2013-2015 Redwarp
+
+ 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.
\ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..89661e1
--- /dev/null
+++ b/README.md
@@ -0,0 +1,59 @@
+#  9-Patch-Resizer
+
+A resizer tool to automaticaly resize png files and 9 patches in several densities (previously hosted on https://code.google.com/p/9patch-resizer/)
+
+[](https://travis-ci.org/redwarp/9-Patch-Resizer)
+
+## Download
+
+To get the latest build (.jar or .exe file), check the release page on the github project: https://github.com/redwarp/9-Patch-Resizer/releases
+
+The .exe file is just a wrapper around the executable .jar file, use it if you don't feel comfortable with a java archive ^_^
+
+## What is it exactly?
+
+Let's face it : juggling with densities for Android is a bit of a pain, especially when dealing with 9 patch png.
+
+And then comes this tool, that takes a xhdpi PNG file, or 9.png file, and generates ldpi, mdpi and hdpi png files automatically.
+
+As simple as drag and drop can get.
+
+And here is the [changelog](https://github.com/redwarp/9-Patch-Resizer/wiki/Changelog)
+
+Current version : *1.4.2*
+
+You're using 9patch resizer for your apps ? Don't hesitate and leave me a message!
+
+## Links
+
+ * Images and stuff found on http://www.clker.com/ (The online royalty free public domain clip art)
+ * Images are downsized using an optimized incremental scaling algorithm proposed by Chris Campbell (whoever that is) - http://today.java.net/pub/a/today/2007/04/03/perils-of-image-getscaledinstance.html
+
+## Roadmap
+
+I'll be honest, I don't really maintain 9-Patch-Resizer anymore, as 9-patch are somewhat a thing of the past, and I use as many vector drawables as possible lately.
+
+I will of course consider bug fixes, but I might not have the bandwidth for feature requests.
+
+Sorry about that.
+
+- [ ] A proper "Settings" panel, to handle issues such as jpeg compression, etc etc...
+- [ ] A few optimisations
+- [x] Command line support
+- [x] Options to set the input density (if people wan't to downsize from hdpi and not from xdpi for instance)
+- [x] Proper JPG support
+
+## Contributors
+
+ * redwarp
+ * Jean-Baptiste LAB - Made the app working in command line
+
+Join us, and together, we can rule the galaxy as coders and...
+
+## Notable forks
+
+ * Soymonitus did a fork that also handles iOS resources, might come in handy for some people: https://github.com/soymonitus/9-Patch-Resizer
+
+## Anyway...
+
+If for some weird reasons, some of your PNG files aren't resized properly, don't hesitate to send them to me, so that I can investigate !
diff --git a/Resizer.eml b/Resizer.eml
deleted file mode 100644
index 71d5e2b..0000000
--- a/Resizer.eml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
diff --git a/Resizer.iml b/Resizer.iml
deleted file mode 100644
index 46adf0f..0000000
--- a/Resizer.iml
+++ /dev/null
@@ -1,3 +0,0 @@
-
-
-
diff --git a/build.xml b/build_deprecated.xml
similarity index 92%
rename from build.xml
rename to build_deprecated.xml
index 8a4464b..e7e06ce 100644
--- a/build.xml
+++ b/build_deprecated.xml
@@ -5,7 +5,7 @@
-
+
@@ -65,11 +65,11 @@
-
+
-
+
@@ -82,6 +82,6 @@
-
+
diff --git a/launch4j_config.xml b/launch4j_config.xml
deleted file mode 100644
index 3ebd9eb..0000000
--- a/launch4j_config.xml
+++ /dev/null
@@ -1,38 +0,0 @@
-
- false
- gui
- C:\Users\Akaiwarp\workspace\Resizer\Resizer_1.2.jar
- C:\Users\Akaiwarp\workspace\Resizer\Resizer_1.2.exe
-
-
-
- normal
- http://java.com/download
-
- false
- false
-
- C:\Users\Akaiwarp\workspace\Resizer\extra\icon_512.ico
-
- resizer
-
-
-
-
- 1.6.0
-
- preferJre
-
-
- 1.2.0.0
- 1.2
- 9Patch Resizer
- Redwarp - 2012
- 1.2.0.0
- 1.2
- 9Patch Resizer
-
- Resizer
- Resizer.exe
-
-
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..17672d2
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,164 @@
+
+
+
+ 4.0.0
+ net.redwarp.tool
+ resizer
+
+
+ 1.4.2
+ 9Patch Resizer
+
+
+ ${project.version}
+ 4
+
+
+
+
+ com.google.code.gson
+ gson
+ 2.2.4
+ compile
+
+
+
+
+ src
+
+
+ res
+ true
+
+ **/configuration.properties
+
+
+
+
+ res
+ false
+
+ **/configuration.properties
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.1
+
+ 1.6
+ 1.6
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+ 2.4
+
+
+
+ net.redwarp.tool.resizer.Main
+ true
+
+
+
+
+
+ com.github.wvengen
+ proguard-maven-plugin
+ 2.0.8
+
+
+ package
+
+ proguard
+
+
+
+
+ ${project.build.finalName}.jar
+ ${project.build.finalName}-proguard.jar
+ proguard.txt
+ true
+
+ ${java.home}/lib/rt.jar
+
+
+
+
+
+
+
+
+ launch4j
+
+
+
+ com.akathist.maven.plugins.launch4j
+ launch4j-maven-plugin
+ 1.7.4
+
+
+ launch4j
+ package
+
+ launch4j
+
+
+ gui
+ target/Resizer-${project.version}.exe
+ target/resizer-${project.version}-proguard.jar
+
+ net.redwarp.tool.resizer.Main
+ false
+ anything
+
+
+ 1.6.0
+
+ preferJre
+ 64/32
+
+ extra/icon_512.ico
+ normal
+
+ resizer
+
+
+
+ ${project.version}.0
+ ${project.version}
+ 9Patch Resizer
+ Redwarp 2013-2015
+ ${project.version}.0
+ ${project.version}
+ 9Patch Resizer
+ Resizer
+ Resizer.exe
+
+
+
+
+
+
+
+
+
+
diff --git a/proguard.txt b/proguard.txt
index 3b42123..71f3672 100644
--- a/proguard.txt
+++ b/proguard.txt
@@ -1,6 +1,3 @@
--injars Resizer_raw.jar
--outjars Resizer_proguard.jar
--libraryjars /lib/rt.jar
-printmapping obfuscate/myapplication.map
-optimizationpasses 3
diff --git a/res/locale/Strings.properties b/res/locale/Strings.properties
index 47d3ff5..88f4b25 100644
--- a/res/locale/Strings.properties
+++ b/res/locale/Strings.properties
@@ -1,6 +1,6 @@
#Created by JInto - www.guh-software.de
#Sat Jun 09 15:23:03 CEST 2012
-about_text=Resizer is a simple resizer tool for Android.\r\nIt takes a PNG image as input, and automatically renerates folders with 4 densities \: ldpi, mdpi, hdpi and xhdpi.\r\nWhat's more \: Resizer work on 9 patches as well \! Because, let's face it, it's a pain to have to do it by hand.\r\nAll icons were found on http\://www.clker.com/\r\n\r\n(c) Copyright Redwarp 2013. All rights reserved.
+about_text=Resizer is a simple resizer tool for Android.\nIt takes a PNG or JPG image as input, and automatically renerates folders with several densities \: ldpi, mdpi, hdpi, xhdpi, xxhdpi...\nWhat's more \: Resizer work on 9 patches as well \! Because, let's face it, it's a pain to have to do it by hand.\nAll icons were found on http\://www.clker.com/\n\n(c) Copyright Redwarp 2013-2015. All rights reserved.
app_name=9Patch Resizer
column_name=Image name
column_status=Status
@@ -15,6 +15,11 @@ status_error=Error
status_finished=Finished \!
status_in_progress=In progress...
status_pending=Pending...
-xhdpi=Drop xhdpi image here (PNG format, nine patch included)
-input_density="Input density:"
-output_density="Output density:"
\ No newline at end of file
+xhdpi=
Drop %s image here (PNG format, nine patch, JPG included)
+input_density=Input density\:
+output_density=Output density:
+save=Save
+save_tooltip=Hit the save button to keep this settings the next time you launch 9Patch Resizer
+keep_same_density_file=Keep the original file for same density
+keep_same_density_file_tooltip=In case of lossy format such as jpeg, checking this option will make sure that, instead of saving a new image, the original file is copied in it's proper directory. If the input is in xhdpi, it will be copied in the xhdpi folder.
+image_types=Choose .jpg or .png files
diff --git a/res/locale/Strings_fr.properties b/res/locale/Strings_fr.properties
index c1bd8fc..09278be 100644
--- a/res/locale/Strings_fr.properties
+++ b/res/locale/Strings_fr.properties
@@ -1,6 +1,6 @@
#Created by JInto - www.guh-software.de
#Sat Jun 09 15:23:03 CEST 2012
-about_text=Resizer est un outil de redimensionnement pour Android.\r\nIl g\u00E9n\u00E8re automatiquement 4 dossiers de densit\u00E9 \: ldpi, mdpi, hdpi and xhdpi.\r\nMais le plus \: Resizer fonctionne sur les 9 patches \! Il faut l'avouer, c'est p\u00EAte b**ne de le faire \u00E0 la main.\r\nLes icons proviennent de http\://www.clker.com/\r\n\r\n(c) Copyright Redwarp 2013. Tous droits r\u00E9serv\u00E9s.
+about_text=Resizer est un outil de redimensionnement pour Android.\nIl g\u00E9n\u00E8re automatiquement plusieurs dossiers de densit\u00E9 \: ldpi, mdpi, hdpi, xhdpi, xxhdpi...\nMais le plus important \: Resizer fonctionne sur les 9 patches \! Il faut l'avouer, c'est p\u00EAte b**ne de le faire \u00E0 la main.\nLes icons proviennent de http\://www.clker.com/\n\n(c) Copyright Redwarp 2013-2015. Tous droits r\u00E9serv\u00E9s.
app_name=9Patch Resizer
column_name=Nom de l'image
column_status=Status
@@ -15,6 +15,11 @@ status_error=Erreur
status_finished=Termin\u00E9 \!
status_in_progress=En cours...
status_pending=En attente...
-xhdpi=D\u00E9posez des images au format PNG (9 patch inclus)
-input_density="Densit\u00E9 d'entr\u00E9e :"
-output_density="Densit\u00E9s de sortie :"
+xhdpi=
D\u00E9posez des images %s au format PNG (9 patch inclus) ou JPG
+input_density=Densit\u00E9 d'entr\u00E9e \:
+output_density=Densit\u00E9s de sortie \:
+save=Sauvegarder
+save_tooltip=Sauvegardez les r\u00E9glages courants pour les r\u00E9utiliser la prochaine fois que vous lancerez 9Patch Resizer
+keep_same_density_file=Garder le fichier original pour la m\u00EAme densit\u00E9
+keep_same_density_file_tooltip=Pour les formats, tel le jpg, o\u00F9 la compression d\u00E9grade l\'image, cochez cette option s\'assurera que le fichier original est copi\u00E9 dans le fichier de destination source, pour la m\u00EAme densit\u00E9.
+image_types=Choisissez des fichiers .jpg ou .png
diff --git a/res/misc/configuration.properties b/res/misc/configuration.properties
new file mode 100644
index 0000000..15b323e
--- /dev/null
+++ b/res/misc/configuration.properties
@@ -0,0 +1,4 @@
+#Created by JInto - www.guh-software.de
+#Sun Oct 21 22:30:52 CEST 2012
+versionName=${resizer.versionName}
+versionCode=${resizer.versionCode}
\ No newline at end of file
diff --git a/res/misc/densities.json b/res/misc/densities.json
index dd5ec3e..bcb90b2 100644
--- a/res/misc/densities.json
+++ b/res/misc/densities.json
@@ -1,35 +1,41 @@
{
- "densities": [
+ "source": "xxhdpi",
+ "densities": [
{
- "name": "xxhdpi",
- "scale": 3,
- "active": false
- },
- {
- "name": "xhdpi",
- "scale": 2,
- "active": true
- },
- {
- "name": "hdpi",
- "scale": 1.5,
- "active": true
- },
- {
- "name": "tvdpi",
- "scale": 1.33,
- "active": false
- },
- {
- "name": "mdpi",
- "scale": 1,
- "active": true
- },
- {
- "name": "ldpi",
- "scale": 0.75,
- "active": true
- }
- ],
- "source": "xhdpi"
-}
+ "scale": 4,
+ "name": "xxxhdpi",
+ "active": false
+ },
+ {
+ "scale": 3,
+ "name": "xxhdpi",
+ "active": true
+ },
+ {
+ "scale": 2,
+ "name": "xhdpi",
+ "active": true
+ },
+ {
+ "scale": 1.5,
+ "name": "hdpi",
+ "active": true
+ },
+ {
+ "scale": 1.33,
+ "name": "tvdpi",
+ "active": false
+ },
+ {
+ "scale": 1,
+ "name": "mdpi",
+ "active": true
+ },
+ {
+ "scale": 0.75,
+ "name": "ldpi",
+ "active": false
+ }
+ ],
+ "keep_same_density_file": false
+}
\ No newline at end of file
diff --git a/res/misc/preferences.properties b/res/misc/preferences.properties
deleted file mode 100644
index 9aa50dc..0000000
--- a/res/misc/preferences.properties
+++ /dev/null
@@ -1,3 +0,0 @@
-#Created by JInto - www.guh-software.de
-#Sun Oct 21 22:30:52 CEST 2012
-version=1.3
\ No newline at end of file
diff --git a/src/net/iharder/dnd/FileDrop.java b/src/net/iharder/dnd/FileDrop.java
index 1be52c0..98ad639 100644
--- a/src/net/iharder/dnd/FileDrop.java
+++ b/src/net/iharder/dnd/FileDrop.java
@@ -2,7 +2,11 @@
import java.awt.*;
import java.awt.datatransfer.DataFlavor;
-import java.io.*;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.io.Reader;
/**
* This class makes it easy to drag and drop files from the operating system to
diff --git a/src/net/redwarp/tool/resizer/FileProcessor.java b/src/net/redwarp/tool/resizer/FileProcessor.java
new file mode 100644
index 0000000..f7d1c1c
--- /dev/null
+++ b/src/net/redwarp/tool/resizer/FileProcessor.java
@@ -0,0 +1,77 @@
+/*
+ * 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.
+ *
+ * Copyright 2014 Jean-Baptiste Lab
+ */
+package net.redwarp.tool.resizer;
+
+import net.redwarp.tool.resizer.misc.Configuration;
+import net.redwarp.tool.resizer.misc.NameValidator;
+import net.redwarp.tool.resizer.table.Operation;
+import net.redwarp.tool.resizer.table.OperationStatus;
+import net.redwarp.tool.resizer.worker.ImageScaler;
+
+import java.io.File;
+
+public class FileProcessor {
+
+ public interface FileProcessorStatusListener {
+
+ void onSuccess();
+
+ void onFailure(String msg);
+ }
+
+ private ImageScaler scaler;
+ FileProcessorStatusListener listener;
+ String fileName;
+
+ public FileProcessor(String name, FileProcessorStatusListener l) {
+ fileName = name;
+ listener = l;
+ if (NameValidator.isFilenameValid(fileName)) {
+ Operation operation = new Operation(new File(name));
+
+ scaler = new ImageScaler(operation,
+ Configuration.getSettings().getDefaultInputDensity()) {
+ @Override
+ protected void process(java.util.List chunks) {
+ for (Operation operation : chunks) {
+ OperationStatus status = operation.getStatus();
+ if (status == OperationStatus.FINISH) {
+ if (listener != null) {
+ listener.onSuccess();
+ }
+ } else if (status == OperationStatus.ERROR) {
+ if (listener != null) {
+ listener.onFailure(operation.getMessage());
+ }
+ }
+ }
+ }
+ };
+ }
+ }
+
+ public void process() {
+ if (scaler != null) {
+ scaler.post();
+ } else {
+ if (listener != null) {
+ listener.onFailure("processor for argument:" + fileName
+ + " is null");
+ }
+ }
+ }
+
+}
diff --git a/src/net/redwarp/tool/resizer/FileTools.java b/src/net/redwarp/tool/resizer/FileTools.java
index c613dfb..1590f71 100644
--- a/src/net/redwarp/tool/resizer/FileTools.java
+++ b/src/net/redwarp/tool/resizer/FileTools.java
@@ -11,11 +11,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
- * Copyright 2013 Redwarp
+ * Copyright 2013-2015 Redwarp
*/
package net.redwarp.tool.resizer;
-import java.io.*;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
public class FileTools {
public static void copyfile(File input, File output) {
diff --git a/src/net/redwarp/tool/resizer/Main.java b/src/net/redwarp/tool/resizer/Main.java
index 9d947c4..57c272b 100644
--- a/src/net/redwarp/tool/resizer/Main.java
+++ b/src/net/redwarp/tool/resizer/Main.java
@@ -11,34 +11,83 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
- * Copyright 2013 Redwarp
+ * Copyright 2013-2015 Redwarp
*/
package net.redwarp.tool.resizer;
+import net.redwarp.tool.resizer.FileProcessor.FileProcessorStatusListener;
+import net.redwarp.tool.resizer.misc.Configuration;
import net.redwarp.tool.resizer.misc.Localization;
import net.redwarp.tool.resizer.views.MainWindow;
+import java.util.ArrayList;
+
import javax.swing.*;
public class Main {
- public static void main(String[] args) {
- // Apple only stuff
- System.setProperty("apple.laf.useScreenMenuBar", "true");
- System.setProperty("com.apple.mrj.application.apple.menu.about.name",
- Localization.get("app_name"));
-
- 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();
- }
-
- new MainWindow().setVisible(true);
+
+ static class StatusListener implements FileProcessorStatusListener {
+
+ int count = 0;
+ int current = 0;
+ int failureCount = 0;
+
+ public StatusListener(int count) {
+ this.count = count;
+ }
+
+ @Override
+ public void onSuccess() {
+ this.current++;
+ if (this.current == this.count) {
+ System.exit(failureCount);
+ }
+ }
+
+ @Override
+ public void onFailure(String msg) {
+ System.err.print(msg + "\n");
+ this.current++;
+ this.failureCount++;
+ if (this.current == this.count) {
+ System.exit(failureCount);
+ }
+ }
+ }
+
+ public static void main(String[] args) {
+ // Apple only stuff
+ System.setProperty("apple.laf.useScreenMenuBar", "true");
+ System.setProperty("com.apple.mrj.application.apple.menu.about.name",
+ Localization.get("app_name"));
+ Configuration.getSettings().load("./densities.json");
+
+ if (args.length > 0) {
+ StatusListener l = new StatusListener(args.length);
+ ArrayList processors = new ArrayList();
+
+ for (String s : args) {
+ processors.add(new FileProcessor(s, l));
+ }
+ for (FileProcessor p : processors) {
+ p.process();
+ }
+ } else {
+
+ 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();
+ }
+
+ new MainWindow().setVisible(true);
}
+ }
}
diff --git a/src/net/redwarp/tool/resizer/misc/Configuration.java b/src/net/redwarp/tool/resizer/misc/Configuration.java
new file mode 100644
index 0000000..381f955
--- /dev/null
+++ b/src/net/redwarp/tool/resizer/misc/Configuration.java
@@ -0,0 +1,41 @@
+/*
+ * 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.
+ *
+ * Copyright 2013-2015 Redwarp
+ */
+package net.redwarp.tool.resizer.misc;
+
+import java.util.Locale;
+import java.util.ResourceBundle;
+
+public class Configuration {
+
+ private static ResourceBundle bundle = ResourceBundle.getBundle(
+ "misc.configuration", Locale.FRANCE);
+ private static Settings settings = null;
+
+ public static String getVersion() {
+ return bundle.getString("versionName");
+ }
+
+ public static int getVersionCode() {
+ return Integer.valueOf(bundle.getString("versionCode"));
+ }
+
+ public static Settings getSettings() {
+ if (settings == null) {
+ settings = new Settings();
+ }
+ return settings;
+ }
+}
diff --git a/src/net/redwarp/tool/resizer/misc/Localization.java b/src/net/redwarp/tool/resizer/misc/Localization.java
index cdd6f23..f0d4060 100644
--- a/src/net/redwarp/tool/resizer/misc/Localization.java
+++ b/src/net/redwarp/tool/resizer/misc/Localization.java
@@ -11,7 +11,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
- * Copyright 2013 Redwarp
+ * Copyright 2013-2015 Redwarp
*/
package net.redwarp.tool.resizer.misc;
@@ -27,7 +27,7 @@ public static String get(String key) {
try {
return bundle.getString(key);
} catch (MissingResourceException e) {
- return new String(key);
+ return key;
}
}
diff --git a/src/net/redwarp/tool/resizer/misc/Preferences.java b/src/net/redwarp/tool/resizer/misc/NameValidator.java
similarity index 62%
rename from src/net/redwarp/tool/resizer/misc/Preferences.java
rename to src/net/redwarp/tool/resizer/misc/NameValidator.java
index 269e035..432bdaa 100644
--- a/src/net/redwarp/tool/resizer/misc/Preferences.java
+++ b/src/net/redwarp/tool/resizer/misc/NameValidator.java
@@ -11,18 +11,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
- * Copyright 2013 Redwarp
+ * Copyright 2013-2015 Redwarp
*/
-package net.redwarp.tool.resizer.misc;
-
-import java.util.Locale;
-import java.util.ResourceBundle;
-public class Preferences {
- private static ResourceBundle bundle = ResourceBundle.getBundle(
- "misc.preferences", Locale.FRANCE);
+package net.redwarp.tool.resizer.misc;
- public static String getVersion() {
- return bundle.getString("version");
+/**
+ * User: benoit.vermont@airtag.com
+ * Date: 28/10/14
+ * Time: 19:09
+ */
+public class NameValidator {
+ public static boolean isFilenameValid(String filename) {
+ String lowerCaseName = filename.toLowerCase();
+ return (lowerCaseName.endsWith(".png") || lowerCaseName.endsWith(".jpg") || lowerCaseName.endsWith(".jpeg"));
}
}
diff --git a/src/net/redwarp/tool/resizer/misc/Settings.java b/src/net/redwarp/tool/resizer/misc/Settings.java
new file mode 100644
index 0000000..8d4dec3
--- /dev/null
+++ b/src/net/redwarp/tool/resizer/misc/Settings.java
@@ -0,0 +1,176 @@
+/*
+ * 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.
+ *
+ * Copyright 2013-2015 Redwarp
+ */
+
+package net.redwarp.tool.resizer.misc;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import com.google.gson.reflect.TypeToken;
+
+import net.redwarp.tool.resizer.worker.ScreenDensity;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.swing.*;
+
+public class Settings {
+
+ private static final String KEY_DENSITIES = "densities";
+ private static final String KEY_SOURCE = "source";
+ private static final String KEY_KEEP_SAME_DENSITY_FILE = "keep_same_density_file";
+ private static final String KEY_VERSION_CODE = "version_code";
+ public static final String DENSITIES_PATHNAME = "./densities.json";
+
+ private List list = null;
+ private ScreenDensity defaultInputDensity = null;
+ private boolean keepSameDensityFile = false;
+ private int versionCode;
+
+ public void load(String path) {
+ try {
+ Gson gson = new Gson();
+ JsonParser parser = new JsonParser();
+ InputStream preferenceStream;
+ try {
+ preferenceStream = new FileInputStream(new File(path));
+ } catch (Exception e) {
+ preferenceStream =
+ this.getClass().getClassLoader().getResourceAsStream("misc/densities.json");
+ }
+ JsonObject
+ densitiesObject =
+ parser.parse(new InputStreamReader(preferenceStream)).getAsJsonObject();
+ JsonArray densitiesArray = densitiesObject.get(KEY_DENSITIES).getAsJsonArray();
+
+ Type listType = new TypeToken>() {
+ }.getType();
+ list = gson.fromJson(densitiesArray, listType);
+ String defaultDensityName = densitiesObject.get(KEY_SOURCE).getAsString();
+ for (ScreenDensity density : list) {
+ if (density.getName().equals(defaultDensityName)) {
+ defaultInputDensity = density;
+ break;
+ }
+ }
+ if (defaultInputDensity == null) {
+ defaultInputDensity = list.get(0);
+ }
+
+ JsonElement keepSameDensityElement = densitiesObject.get(
+ KEY_KEEP_SAME_DENSITY_FILE);
+ if (keepSameDensityElement != null) {
+ keepSameDensityFile = keepSameDensityElement.getAsBoolean();
+ } else {
+ keepSameDensityFile = false;
+ }
+ } catch (Exception e) {
+ list = new ArrayList();
+ list.add(new ScreenDensity("xhdpi", 2.0f, true));
+ defaultInputDensity = list.get(0);
+ keepSameDensityFile = false;
+// versionCode = Configuration.getVersionCode();
+ }
+ }
+
+ public void save(Runnable postAction) {
+// saveButton.setEnabled(false);
+ JsonObject rootObject = new JsonObject();
+ // Save source
+ rootObject.addProperty(KEY_SOURCE, defaultInputDensity.getName());
+
+ // Save densities
+ Gson gson = new GsonBuilder().setPrettyPrinting().create();
+
+ Type listOfDensityType = new TypeToken>() {
+ }.getType();
+ JsonElement densities = gson.toJsonTree(list, listOfDensityType);
+ rootObject.add(KEY_DENSITIES, densities);
+ rootObject.addProperty(KEY_KEEP_SAME_DENSITY_FILE, keepSameDensityFile);
+ rootObject.addProperty(KEY_VERSION_CODE, Configuration.getVersionCode());
+
+ SaveWorker worker = new SaveWorker(postAction, gson.toJson(rootObject));
+ worker.execute();
+ }
+
+ public List getSupportedScreenDensity() {
+ return list;
+ }
+
+ public boolean shouldKeepSameDensityFile() {
+ return keepSameDensityFile;
+ }
+
+ public ScreenDensity getDefaultInputDensity() {
+ return defaultInputDensity;
+ }
+
+ public void setDefaultInputDensity(ScreenDensity defaultInputDensity) {
+ this.defaultInputDensity = defaultInputDensity;
+ }
+
+ public void setShouldKeepSameDensityFile(boolean shouldKeepSameDensityFile) {
+ this.keepSameDensityFile = shouldKeepSameDensityFile;
+ }
+
+ public static class SaveWorker extends SwingWorker {
+
+ private final String mSavePayload;
+ private final Runnable mPostAction;
+
+ public SaveWorker(Runnable postAction, String savePayload) {
+ mPostAction = postAction;
+ mSavePayload = savePayload;
+ }
+
+
+ @Override
+ protected Void doInBackground() throws Exception {
+ FileOutputStream fos = null;
+ try {
+ fos = new FileOutputStream(DENSITIES_PATHNAME);
+ PrintWriter writer = new PrintWriter(fos);
+ writer.write(mSavePayload);
+
+ writer.close();
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ System.out.println("Couldn't save");
+ }
+
+ return null;
+ }
+
+ @Override
+ protected void done() {
+ if (mPostAction != null) {
+ mPostAction.run();
+ }
+ }
+ }
+}
diff --git a/src/net/redwarp/tool/resizer/table/Operation.java b/src/net/redwarp/tool/resizer/table/Operation.java
index e94298d..f0218c4 100644
--- a/src/net/redwarp/tool/resizer/table/Operation.java
+++ b/src/net/redwarp/tool/resizer/table/Operation.java
@@ -11,7 +11,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
- * Copyright 2013 Redwarp
+ * Copyright 2013-2015 Redwarp
*/
package net.redwarp.tool.resizer.table;
diff --git a/src/net/redwarp/tool/resizer/table/OperationStatus.java b/src/net/redwarp/tool/resizer/table/OperationStatus.java
index 0ecc790..74a98df 100644
--- a/src/net/redwarp/tool/resizer/table/OperationStatus.java
+++ b/src/net/redwarp/tool/resizer/table/OperationStatus.java
@@ -11,7 +11,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
- * Copyright 2013 Redwarp
+ * Copyright 2013-2015 Redwarp
*/
package net.redwarp.tool.resizer.table;
diff --git a/src/net/redwarp/tool/resizer/table/ResultModel.java b/src/net/redwarp/tool/resizer/table/ResultModel.java
index b99a836..d124a52 100644
--- a/src/net/redwarp/tool/resizer/table/ResultModel.java
+++ b/src/net/redwarp/tool/resizer/table/ResultModel.java
@@ -11,17 +11,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
- * Copyright 2013 Redwarp
+ * Copyright 2013-2015 Redwarp
*/
package net.redwarp.tool.resizer.table;
import net.redwarp.tool.resizer.misc.Localization;
-import javax.swing.table.AbstractTableModel;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import javax.swing.table.AbstractTableModel;
+
public class ResultModel extends AbstractTableModel {
private static final long serialVersionUID = -6799282358729483044L;
private List operationList;
diff --git a/src/net/redwarp/tool/resizer/table/ResultTable.java b/src/net/redwarp/tool/resizer/table/ResultTable.java
index 89a742a..1318642 100644
--- a/src/net/redwarp/tool/resizer/table/ResultTable.java
+++ b/src/net/redwarp/tool/resizer/table/ResultTable.java
@@ -11,13 +11,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
- * Copyright 2013 Redwarp
+ * Copyright 2013-2015 Redwarp
*/
package net.redwarp.tool.resizer.table;
-import javax.swing.*;
import java.awt.*;
+import javax.swing.*;
+
public class ResultTable extends JTable {
private static final long serialVersionUID = -8240707430938246389L;
private ResultModel model;
diff --git a/src/net/redwarp/tool/resizer/table/StatusCellRenderer.java b/src/net/redwarp/tool/resizer/table/StatusCellRenderer.java
index 46c88d7..b24831a 100644
--- a/src/net/redwarp/tool/resizer/table/StatusCellRenderer.java
+++ b/src/net/redwarp/tool/resizer/table/StatusCellRenderer.java
@@ -11,15 +11,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
- * Copyright 2013 Redwarp
+ * Copyright 2013-2015 Redwarp
*/
package net.redwarp.tool.resizer.table;
import net.redwarp.tool.resizer.misc.Localization;
+import java.awt.*;
+
import javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
-import java.awt.*;
public class StatusCellRenderer extends DefaultTableCellRenderer {
diff --git a/src/net/redwarp/tool/resizer/views/AboutDialog.java b/src/net/redwarp/tool/resizer/views/AboutDialog.java
index 64d939d..166987e 100644
--- a/src/net/redwarp/tool/resizer/views/AboutDialog.java
+++ b/src/net/redwarp/tool/resizer/views/AboutDialog.java
@@ -11,16 +11,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
- * Copyright 2013 Redwarp
+ * Copyright 2013-2015 Redwarp
*/
package net.redwarp.tool.resizer.views;
+import net.redwarp.tool.resizer.misc.Configuration;
import net.redwarp.tool.resizer.misc.Localization;
-import net.redwarp.tool.resizer.misc.Preferences;
+
+import java.awt.*;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
-import java.awt.*;
public class AboutDialog extends JDialog {
private static final long serialVersionUID = 7783865044667012251L;
@@ -31,7 +32,7 @@ public AboutDialog(JFrame parent) {
this.getContentPane().setLayout(new BorderLayout(0, 0));
JLabel lblResizer = new JLabel(Localization.get("app_name") + " "
- + Preferences.getVersion());
+ + Configuration.getVersion());
lblResizer.setBorder(new EmptyBorder(10, 10, 10, 10));
lblResizer.setVerticalTextPosition(SwingConstants.BOTTOM);
lblResizer.setIconTextGap(10);
diff --git a/src/net/redwarp/tool/resizer/views/MainWindow.java b/src/net/redwarp/tool/resizer/views/MainWindow.java
index ff91b68..cf527f0 100644
--- a/src/net/redwarp/tool/resizer/views/MainWindow.java
+++ b/src/net/redwarp/tool/resizer/views/MainWindow.java
@@ -11,263 +11,358 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
- * Copyright 2013 Redwarp
+ * Copyright 2013-2015 Redwarp
*/
package net.redwarp.tool.resizer.views;
import net.iharder.dnd.FileDrop;
+import net.redwarp.tool.resizer.misc.Configuration;
import net.redwarp.tool.resizer.misc.Localization;
+import net.redwarp.tool.resizer.misc.NameValidator;
import net.redwarp.tool.resizer.table.Operation;
import net.redwarp.tool.resizer.table.ResultTable;
import net.redwarp.tool.resizer.worker.ImageScaler;
import net.redwarp.tool.resizer.worker.ScreenDensity;
-import javax.swing.*;
-import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
import java.io.File;
+import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.List;
+import java.util.Locale;
import java.util.Vector;
+import javax.swing.*;
+import javax.swing.border.EmptyBorder;
+
+
@SuppressWarnings("serial")
public class MainWindow extends JFrame {
- private JPanel inputPanel;
- private JPanel outputPanel;
-
- private ImageIcon blueArrow, redArrow;
- private ImageIcon blueArrowSmall, redArrowSmall;
- private JButton xhdpiButton;
- private JScrollPane scrollPane;
- private JTextArea textArea;
- private ResultTable resultTable;
- private JLabel instructionLabel;
- private JMenuBar menuBar;
- private JMenu mnHelp;
- private JMenu mnEdit;
- private JMenuItem mntmClear;
- private JMenuItem mntmAbout;
- private final Action action = new SwingAction();
-
- public MainWindow() {
- this.setSize(new Dimension(450, 350));
- this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
- this.setTitle(Localization.get("app_name"));
-
- List icons = new ArrayList();
- icons.add(Toolkit.getDefaultToolkit().getImage(
- MainWindow.class.getResource("/img/icon_512.png")));
- icons.add(Toolkit.getDefaultToolkit().getImage(
- MainWindow.class.getResource("/img/icon_256.png")));
- icons.add(Toolkit.getDefaultToolkit().getImage(
- MainWindow.class.getResource("/img/icon_128.png")));
- icons.add(Toolkit.getDefaultToolkit().getImage(
- MainWindow.class.getResource("/img/icon_64.png")));
- icons.add(Toolkit.getDefaultToolkit().getImage(
- MainWindow.class.getResource("/img/icon_32.png")));
- icons.add(Toolkit.getDefaultToolkit().getImage(
- MainWindow.class.getResource("/img/icon_16.png")));
- this.setIconImages(icons);
-
- this.blueArrow = new ImageIcon(
- MainWindow.class.getResource("/img/blue_big.png"));
- this.redArrow = new ImageIcon(
- MainWindow.class.getResource("/img/red_big.png"));
- this.blueArrowSmall = new ImageIcon(
- MainWindow.class.getResource("/img/blue_small.png"));
- this.redArrowSmall = new ImageIcon(
- MainWindow.class.getResource("/img/red_small.png"));
- this.getContentPane().setLayout(new CardLayout(0, 0));
-
- this.inputPanel = new JPanel();
- this.inputPanel.setPreferredSize(new Dimension(10, 140));
- this.getContentPane().add(this.inputPanel, "input");
-
- this.xhdpiButton = new JButton(Localization.get("xhdpi"));
- this.xhdpiButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent arg0) {
- }
- });
- this.inputPanel.setLayout(new BorderLayout(0, 0));
- this.xhdpiButton.setBorderPainted(false);
- this.xhdpiButton.setFocusPainted(false);
- this.xhdpiButton.setVerticalTextPosition(SwingConstants.BOTTOM);
- this.xhdpiButton.setHorizontalTextPosition(SwingConstants.CENTER);
- this.xhdpiButton.setIcon(this.blueArrow);
- this.xhdpiButton.setSelectedIcon(this.redArrow);
- this.xhdpiButton.setBorder(null);
- this.xhdpiButton.setContentAreaFilled(false);
- this.inputPanel.add(this.xhdpiButton, BorderLayout.CENTER);
-
- JPanel optionPanel = new JPanel();
- optionPanel.setLayout(new BoxLayout(optionPanel, BoxLayout.PAGE_AXIS));
- optionPanel.add(Box.createVerticalGlue());
-
- JLabel inputLabel = new JLabel(Localization.get("input_density"));
- inputLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
- optionPanel.add(inputLabel);
- JComboBox inputDensityChoice = new JComboBox(new Vector(ScreenDensity.getSupportedScreenDensity()));
- inputDensityChoice.setSelectedItem(ScreenDensity.getDefaultInputDensity());
- inputDensityChoice.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent actionEvent) {
- JComboBox box = (JComboBox) actionEvent.getSource();
- ScreenDensity selectedDensity = (ScreenDensity) box.getSelectedItem();
- ScreenDensity.setDefaultInputDensity(selectedDensity);
- }
+ private ImageIcon blueArrow, redArrow;
+ private ImageIcon blueArrowSmall, redArrowSmall;
+ private JButton xhdpiButton;
+ private ResultTable resultTable;
+ private JLabel instructionLabel;
+ private JMenuItem mntmClear;
+ private final Action action = new SwingAction();
+ private JComboBox inputDensityChoice;
+ // private JFileChooser fileChooser;
+ private FileDialog fileDialog;
+
+ public MainWindow() {
+ this.setSize(new Dimension(550, 400));
+ this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
+ this.setTitle(Localization.get("app_name"));
+
+ List icons = new ArrayList();
+ icons.add(Toolkit.getDefaultToolkit().getImage(
+ MainWindow.class.getResource("/img/icon_512.png")));
+ icons.add(Toolkit.getDefaultToolkit().getImage(
+ MainWindow.class.getResource("/img/icon_256.png")));
+ icons.add(Toolkit.getDefaultToolkit().getImage(
+ MainWindow.class.getResource("/img/icon_128.png")));
+ icons.add(Toolkit.getDefaultToolkit().getImage(
+ MainWindow.class.getResource("/img/icon_64.png")));
+ icons.add(Toolkit.getDefaultToolkit().getImage(
+ MainWindow.class.getResource("/img/icon_32.png")));
+ icons.add(Toolkit.getDefaultToolkit().getImage(
+ MainWindow.class.getResource("/img/icon_16.png")));
+ this.setIconImages(icons);
+
+ this.blueArrow = new ImageIcon(
+ MainWindow.class.getResource("/img/blue_big.png"));
+ this.redArrow = new ImageIcon(
+ MainWindow.class.getResource("/img/red_big.png"));
+ this.blueArrowSmall = new ImageIcon(
+ MainWindow.class.getResource("/img/blue_small.png"));
+ this.redArrowSmall = new ImageIcon(
+ MainWindow.class.getResource("/img/red_small.png"));
+ this.getContentPane().setLayout(new CardLayout(0, 0));
+
+ fileDialog = new FileDialog(this);
+ fileDialog.setFilenameFilter(new FilenameFilter() {
+ @Override
+ public boolean accept(File dir, String name) {
+ return NameValidator.isFilenameValid(name);
+ }
+ });
+ fileDialog.setMultipleMode(true);
+ fileDialog.setTitle(Localization.get("image_types"));
+
+ this.getContentPane().add(createInputPanel(), "input");
+ this.getContentPane().add(createOutputPanel(), "output");
+
+ this.setMenuBar();
+ }
+
+ private JPanel createOutputPanel() {
+ JPanel outputPanel = new JPanel();
+ outputPanel.setLayout(new BorderLayout(0, 0));
+
+ JTextArea textArea = new JTextArea();
+ textArea.setLineWrap(true);
+ textArea.setEditable(false);
+
+ this.resultTable = new ResultTable();
+ JScrollPane scrollPane = new JScrollPane(this.resultTable);
+ scrollPane
+ .setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
+ scrollPane
+ .setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
+ outputPanel.add(scrollPane, BorderLayout.CENTER);
+
+ FileDrop.Listener dropListener = new FileDrop.Listener() {
+
+ @Override
+ public void filesDropped(Container source, File[] files) {
+ createScaleJobs(files);
+ }
+
+ @Override
+ public void dragEnter(Container source) {
+ MainWindow.this.xhdpiButton.setSelected(true);
+ MainWindow.this.instructionLabel
+ .setIcon(MainWindow.this.redArrowSmall);
+ }
+
+ @Override
+ public void dragExit(Container source) {
+ MainWindow.this.xhdpiButton.setSelected(false);
+ MainWindow.this.instructionLabel
+ .setIcon(MainWindow.this.blueArrowSmall);
+ }
+ };
+ new FileDrop(this.getContentPane(), null, dropListener);
+ new FileDrop(outputPanel, null, dropListener);
+
+ this.instructionLabel = new JLabel("");
+ this.instructionLabel.setIcon(this.blueArrowSmall);
+ this.instructionLabel.setBorder(new EmptyBorder(4, 4, 4, 4));
+ this.instructionLabel.addMouseListener(new MouseAdapter() {
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ displayImagePicker();
+ }
+ });
+
+ outputPanel.add(this.instructionLabel, BorderLayout.SOUTH);
+
+ new FileDrop(textArea, null, dropListener);
+ return outputPanel;
+ }
+
+ private void displayImagePicker() {
+ fileDialog.setVisible(true);
+ File[] files = fileDialog.getFiles();
+ if (files != null) {
+ createScaleJobs(files);
+ }
+ }
+
+ private JPanel createInputPanel() {
+ JPanel inputPanel = new JPanel();
+ inputPanel.setPreferredSize(new Dimension(10, 140));
+
+ this.xhdpiButton =
+ new JButton(String.format(Locale.getDefault(), Localization.get("xhdpi"),
+ Configuration.getSettings().getDefaultInputDensity().getName()));
+ this.xhdpiButton.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent arg0) {
+ }
+ });
+ inputPanel.setLayout(new BorderLayout(0, 0));
+ this.xhdpiButton.setBorderPainted(false);
+ this.xhdpiButton.setFocusPainted(false);
+ this.xhdpiButton.setVerticalTextPosition(SwingConstants.BOTTOM);
+ this.xhdpiButton.setHorizontalTextPosition(SwingConstants.CENTER);
+ this.xhdpiButton.setHorizontalAlignment(SwingConstants.CENTER);
+ this.xhdpiButton.setIcon(this.blueArrow);
+ this.xhdpiButton.setSelectedIcon(this.redArrow);
+ this.xhdpiButton.setBorder(null);
+ this.xhdpiButton.setContentAreaFilled(false);
+ inputPanel.add(this.xhdpiButton, BorderLayout.CENTER);
+
+ this.xhdpiButton.addMouseListener(
+ new MouseAdapter() {
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ displayImagePicker();
+ }
});
- inputDensityChoice.setAlignmentX(Component.LEFT_ALIGNMENT);
- inputDensityChoice.setAlignmentY(Component.BOTTOM_ALIGNMENT);
- inputDensityChoice.setPreferredSize(new Dimension(1, 10));
-
- optionPanel.add(inputDensityChoice);
- optionPanel.add(Box.createVerticalGlue());
-
- JLabel outputLabel = new JLabel(Localization.get("output_density"));
- optionPanel.add(outputLabel);
- for (final ScreenDensity density : ScreenDensity.getSupportedScreenDensity()) {
- final JCheckBox box = new JCheckBox(density.getName());
- box.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent actionEvent) {
- density.setActive(box.isSelected());
- }
- });
- box.setSelected(density.isActive());
- box.setAlignmentX(Component.LEFT_ALIGNMENT);
- optionPanel.add(box);
- }
- optionPanel.add(Box.createVerticalGlue());
- optionPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("Options"), BorderFactory.createEmptyBorder(10, 10, 10, 10)));
-
- this.inputPanel.add(optionPanel, BorderLayout.LINE_START);
-
- this.outputPanel = new JPanel();
- this.getContentPane().add(this.outputPanel, "output");
- this.outputPanel.setLayout(new BorderLayout(0, 0));
-
- this.textArea = new JTextArea();
- this.textArea.setLineWrap(true);
- this.textArea.setEditable(false);
-
- this.resultTable = new ResultTable();
- this.scrollPane = new JScrollPane(this.resultTable);
- this.scrollPane
- .setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
- this.scrollPane
- .setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
- this.outputPanel.add(this.scrollPane, BorderLayout.CENTER);
-
- FileDrop.Listener dropListener = new FileDrop.Listener() {
-
- @Override
- public void filesDropped(Container source, File[] files) {
- for (File input : files) {
- String name = input.getName().toLowerCase();
- if (name.endsWith(".png") || name.endsWith(".jpg")) {
- MainWindow.this.mntmClear.setEnabled(true);
- CardLayout layout = (CardLayout) MainWindow.this
- .getContentPane().getLayout();
- layout.show(MainWindow.this.getContentPane(), "output");
- Operation operation = new Operation(input);
- MainWindow.this.resultTable.addOperation(operation);
-
- ImageScaler scaler = new ImageScaler(operation,
- ScreenDensity.getDefaultInputDensity()) {
- @Override
- protected void process(
- java.util.List chunks) {
- for (Operation operation : chunks) {
- MainWindow.this.resultTable
- .notifyChange(operation);
- }
- }
- };
- scaler.post();
- }
- }
- }
- @Override
- public void dragEnter(Container source) {
- MainWindow.this.xhdpiButton.setSelected(true);
- MainWindow.this.instructionLabel
- .setIcon(MainWindow.this.redArrowSmall);
- }
-
- @Override
- public void dragExit(Container source) {
- MainWindow.this.xhdpiButton.setSelected(false);
- MainWindow.this.instructionLabel
- .setIcon(MainWindow.this.blueArrowSmall);
+ JPanel optionPanel = new JPanel();
+ optionPanel.setLayout(new BoxLayout(optionPanel, BoxLayout.PAGE_AXIS));
+ optionPanel.add(Box.createVerticalGlue());
+
+ JLabel inputLabel = new JLabel(Localization.get("input_density"));
+ inputLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
+ optionPanel.add(inputLabel);
+ inputDensityChoice = new JComboBox(
+ new Vector(Configuration.getSettings().getSupportedScreenDensity()));
+ inputDensityChoice.setSelectedItem(Configuration.getSettings().getDefaultInputDensity());
+ inputDensityChoice.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent actionEvent) {
+ JComboBox box = (JComboBox) actionEvent.getSource();
+ ScreenDensity selectedDensity = (ScreenDensity) box.getSelectedItem();
+ Configuration.getSettings().setDefaultInputDensity(selectedDensity);
+ xhdpiButton.setText(String.format(Locale.getDefault(), Localization.get("xhdpi"),
+ selectedDensity.getName()));
+ }
+ });
+ inputDensityChoice.setAlignmentX(Component.LEFT_ALIGNMENT);
+ inputDensityChoice.setAlignmentY(Component.BOTTOM_ALIGNMENT);
+ inputDensityChoice.setPreferredSize(new Dimension(1, 10));
+
+ optionPanel.add(inputDensityChoice);
+ optionPanel.add(Box.createVerticalGlue());
+
+ JLabel outputLabel = new JLabel(Localization.get("output_density"));
+ optionPanel.add(outputLabel);
+ for (final ScreenDensity density : Configuration.getSettings().getSupportedScreenDensity()) {
+ final JCheckBox box = new JCheckBox(density.getName());
+ box.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent actionEvent) {
+ density.setActive(box.isSelected());
+ }
+ });
+ box.setSelected(density.isActive());
+ box.setAlignmentX(Component.LEFT_ALIGNMENT);
+ optionPanel.add(box);
+ }
+ optionPanel.add(Box.createVerticalGlue());
+
+ final JCheckBox keepDensity = new JCheckBox(Localization.get("keep_same_density_file"));
+ keepDensity.setToolTipText(Localization.get("keep_same_density_file_tooltip"));
+ keepDensity.setSelected(Configuration.getSettings().shouldKeepSameDensityFile());
+ keepDensity.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ Configuration.getSettings().setShouldKeepSameDensityFile(keepDensity.isSelected());
+ }
+ });
+
+ optionPanel.add(keepDensity);
+ optionPanel.add(Box.createVerticalGlue());
+
+ final JButton saveButton = new JButton(Localization.get("save"));
+ saveButton.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ saveButton.setEnabled(false);
+ Configuration.getSettings().save(new Runnable() {
+ @Override
+ public void run() {
+ saveButton.setEnabled(true);
+ }
+ });
+ }
+ });
+ saveButton.setToolTipText(Localization.get("save_tooltip"));
+ optionPanel.add(saveButton);
+ optionPanel.add(Box.createVerticalGlue());
+
+ optionPanel.setBorder(BorderFactory
+ .createCompoundBorder(BorderFactory.createTitledBorder("Options"),
+ BorderFactory
+ .createEmptyBorder(10, 10, 10, 10)));
+
+ optionPanel.setPreferredSize(new Dimension(200, -1));
+
+ inputPanel.add(optionPanel, BorderLayout.LINE_START);
+ return inputPanel;
+ }
+
+ private void createScaleJobs(File[] files) {
+ for (File input : files) {
+ String filename = input.getName();
+ if (NameValidator.isFilenameValid(filename)) {
+ MainWindow.this.mntmClear.setEnabled(true);
+ CardLayout layout = (CardLayout) MainWindow.this
+ .getContentPane().getLayout();
+
+ ScreenDensity selectedDensity = (ScreenDensity) inputDensityChoice.getSelectedItem();
+ instructionLabel.setText(String.format(Locale.getDefault(), Localization.get("xhdpi"),
+ selectedDensity.getName()));
+ layout.show(MainWindow.this.getContentPane(), "output");
+ Operation operation = new Operation(input);
+ MainWindow.this.resultTable.addOperation(operation);
+
+ ImageScaler scaler = new ImageScaler(operation,
+ Configuration.getSettings()
+ .getDefaultInputDensity()) {
+ @Override
+ protected void process(
+ List chunks) {
+ for (Operation operation : chunks) {
+ MainWindow.this.resultTable
+ .notifyChange(operation);
}
+ }
};
- new FileDrop(this.getContentPane(), null, dropListener);
- new FileDrop(this.outputPanel, null, dropListener);
+ scaler.post();
+ }
+ }
+ }
- this.instructionLabel = new JLabel(Localization.get("xhdpi"));
- this.instructionLabel.setIcon(this.blueArrowSmall);
- this.instructionLabel.setBorder(new EmptyBorder(4, 4, 4, 4));
- this.outputPanel.add(this.instructionLabel, BorderLayout.SOUTH);
+ private void setMenuBar() {
+ JMenuBar menuBar = new JMenuBar();
+ this.setJMenuBar(menuBar);
- new FileDrop(this.textArea, null, dropListener);
+ JMenu mnEdit = new JMenu(Localization.get("menu_edit"));
+ menuBar.add(mnEdit);
- this.setMenuBar();
- }
+ this.mntmClear = new JMenuItem(Localization.get("menu_item_clear"));
+ this.mntmClear.setAction(this.action);
+ this.mntmClear.setEnabled(false);
+ mnEdit.add(this.mntmClear);
- private void setMenuBar() {
- this.menuBar = new JMenuBar();
- this.setJMenuBar(this.menuBar);
+ JMenu mnHelp = new JMenu(Localization.get("menu_help"));
+ menuBar.add(mnHelp);
- this.mnEdit = new JMenu(Localization.get("menu_edit"));
- this.menuBar.add(this.mnEdit);
+ JMenuItem mntmAbout = new JMenuItem();
+ mntmAbout.setAction(new AboutAction());
+ mnHelp.add(mntmAbout);
+ }
- this.mntmClear = new JMenuItem(Localization.get("menu_item_clear"));
- this.mntmClear.setAction(this.action);
- this.mntmClear.setEnabled(false);
- this.mnEdit.add(this.mntmClear);
+ private class AboutAction extends AbstractAction {
- this.mnHelp = new JMenu(Localization.get("menu_help"));
- this.menuBar.add(this.mnHelp);
+ public AboutAction() {
+ this.putValue(NAME, Localization.get("menu_item_about"));
+ }
- this.mntmAbout = new JMenuItem();
- this.mntmAbout.setAction(new AboutAction());
- this.mnHelp.add(this.mntmAbout);
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ new AboutDialog(MainWindow.this).setVisible(true);
}
+ }
- private class AboutAction extends AbstractAction {
- public AboutAction() {
- this.putValue(NAME, Localization.get("menu_item_about"));
- }
+ private class SwingAction extends AbstractAction {
- @Override
- public void actionPerformed(ActionEvent e) {
- new AboutDialog(MainWindow.this).setVisible(true);
- }
+ public SwingAction() {
+ this.putValue(NAME, Localization.get("menu_item_clear"));
+ this.putValue(SHORT_DESCRIPTION,
+ Localization.get("menu_item_clear_desc"));
}
- private class SwingAction extends AbstractAction {
- public SwingAction() {
- this.putValue(NAME, Localization.get("menu_item_clear"));
- this.putValue(SHORT_DESCRIPTION,
- Localization.get("menu_item_clear_desc"));
- }
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ MainWindow.this.resultTable.clear();
+ if (MainWindow.this.resultTable.getModel().getRowCount() == 0) {
+ MainWindow.this.mntmClear.setEnabled(false);
- @Override
- public void actionPerformed(ActionEvent e) {
- MainWindow.this.resultTable.clear();
- if (MainWindow.this.resultTable.getModel().getRowCount() == 0) {
- MainWindow.this.mntmClear.setEnabled(false);
-
- CardLayout layout = (CardLayout) MainWindow.this
- .getContentPane().getLayout();
- layout.show(MainWindow.this.getContentPane(), "input");
- }
- }
+ CardLayout layout = (CardLayout) MainWindow.this
+ .getContentPane().getLayout();
+ layout.show(MainWindow.this.getContentPane(), "input");
+ }
}
+ }
}
diff --git a/src/net/redwarp/tool/resizer/worker/ImageScaler.java b/src/net/redwarp/tool/resizer/worker/ImageScaler.java
index 3df68e0..a0c7619 100644
--- a/src/net/redwarp/tool/resizer/worker/ImageScaler.java
+++ b/src/net/redwarp/tool/resizer/worker/ImageScaler.java
@@ -11,16 +11,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
- * Copyright 2013 Redwarp
+ * Copyright 2013-2015 Redwarp
*/
package net.redwarp.tool.resizer.worker;
+import net.redwarp.tool.resizer.misc.Configuration;
import net.redwarp.tool.resizer.misc.Localization;
import net.redwarp.tool.resizer.table.Operation;
import net.redwarp.tool.resizer.table.OperationStatus;
-import javax.imageio.ImageIO;
-import javax.swing.*;
import java.awt.*;
import java.awt.RenderingHints.Key;
import java.awt.image.BufferedImage;
@@ -32,322 +31,359 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
+import javax.imageio.ImageIO;
+import javax.swing.*;
+
public class ImageScaler extends SwingWorker {
- private File inputFile;
- private Operation operation;
- private ScreenDensity inputDensity;
- private static ExecutorService executor = Executors
- .newFixedThreadPool(Runtime.getRuntime().availableProcessors());
- private static Object fileLock = new Object();
- private static Object folderLock = new Object();
-
- public ImageScaler(final Operation operation,
- final ScreenDensity inputDensity) {
- this.operation = operation;
- this.inputFile = operation.getFile();
- this.inputDensity = inputDensity;
- }
- @Override
- protected Void doInBackground() throws Exception {
- try {
- BufferedImage inputImage;
- synchronized (fileLock) {
- inputImage = ImageIO.read(this.inputFile);
- }
- if (inputImage == null) {
- this.operation.setStatus(OperationStatus.ERROR,
- Localization.get("error_wrong_png"));
- this.publish(this.operation);
- return null;
- }
+ private File inputFile;
+ private Operation operation;
+ private ScreenDensity inputDensity;
+ private static ExecutorService executor = Executors
+ .newFixedThreadPool(Runtime.getRuntime().availableProcessors());
+ private static final Object fileLock = new Object();
+ private static final Object folderLock = new Object();
+
+ public ImageScaler(final Operation operation,
+ final ScreenDensity inputDensity) {
+ this.operation = operation;
+ this.inputFile = operation.getFile();
+ this.inputDensity = inputDensity;
+ }
+
+ @Override
+ protected Void doInBackground() throws Exception {
+ try {
+ BufferedImage inputImage;
+ synchronized (fileLock) {
+// inputImage = ImageIO.read(this.inputFile);
+ Image tempImage = Toolkit.getDefaultToolkit().createImage(this.inputFile.getAbsolutePath());
+ ImageIcon tempIcon = new ImageIcon(tempImage);
+ inputImage = new BufferedImage(tempIcon.getIconWidth(), tempIcon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
+ inputImage.getGraphics().drawImage(tempImage, 0, 0, null);
+ }
+ if (inputImage == null) {
+ this.operation.setStatus(OperationStatus.ERROR,
+ Localization.get("error_wrong_png"));
+ this.publish(this.operation);
+ return null;
+ } else {
+// if (inputImage.getType() != BufferedImage.TYPE_INT_ARGB) {
+// BufferedImage tempImage = new BufferedImage(
+// inputImage.getWidth(), inputImage.getHeight(),
+// BufferedImage.TYPE_INT_ARGB);
+// Graphics2D g = tempImage.createGraphics();
+// g.drawImage(inputImage, 0, 0, tempImage.getWidth(),
+// tempImage.getHeight(), 0, 0, inputImage.getWidth(),
+// inputImage.getHeight(), null);
+// g.dispose();
+// inputImage = tempImage;
+// }
+ }
+
+ this.operation.setStatus(OperationStatus.IN_PROGRESS);
+ this.publish(this.operation);
+
+ List densityList = Configuration.getSettings()
+ .getSupportedScreenDensity();
+
+ File parent = this.inputFile.getParentFile();
+ for (ScreenDensity density : densityList) {
+ if (!density.isActive()) {
+ continue;
+ }
+ File outputFolder;
+
+ synchronized (folderLock) {
+ outputFolder = new File(parent, "drawable-"
+ + density.getName());
+ if (!outputFolder.exists()) {
+ outputFolder.mkdir();
+ }
+ }
- this.operation.setStatus(OperationStatus.IN_PROGRESS);
- this.publish(this.operation);
+ String name;
+ Output output = null;
+ int extensionPos = this.inputFile.getName().lastIndexOf('.');
+ if (extensionPos != -1) {
+ String
+ extension =
+ this.inputFile.getName().substring(extensionPos, this.inputFile.getName().length());
+ if (".png".equalsIgnoreCase(extension)) {
+ output = Output.PNG;
+ } else if (".jpg".equalsIgnoreCase(extension) || ".jpeg".equalsIgnoreCase(extension)) {
+ output = Output.JPG;
+ }
+ }
- List densityList = ScreenDensity
- .getSupportedScreenDensity();
-
- File parent = this.inputFile.getParentFile();
- for (ScreenDensity density : densityList) {
- if (density.isActive() == false) {
- continue;
- }
- File outputFolder;
-
- synchronized (folderLock) {
- outputFolder = new File(parent, "drawable-"
- + density.getName());
- if (!outputFolder.exists()) {
- outputFolder.mkdir();
- }
- }
-
- String name;
- int extensionPos = this.inputFile.getName().lastIndexOf('.');
- if (extensionPos != -1) {
- name = this.inputFile.getName().substring(0, extensionPos)
- + ".png";
- } else {
- name = this.inputFile.getName();
- }
-
- File outputFile = new File(outputFolder, name);
- if (outputFile.exists()) {
- outputFile.delete();
- }
-
- // if (density.equals(this.inputDensity)) {
- // FileTools.copyfile(this.inputFile, outputFile);
- // } else {
-
- BufferedImage outputImage;
- if (this.inputFile.getName().endsWith(".9.png")) {
- BufferedImage trimedImage = this.trim9PBorder(inputImage);
-
- float ratio = density.getScale()
- / this.inputDensity.getScale();
- trimedImage = this.rescaleImage(trimedImage,
- (int) (ratio * trimedImage.getWidth()),
- (int) (ratio * trimedImage.getHeight()));
-
- BufferedImage borderImage;
-
- int w = trimedImage.getWidth();
- int h = trimedImage.getHeight();
-
- try {
- borderImage = this.generateBordersImage(inputImage, w,
- h);
- } catch (Wrong9PatchException e) {
- this.operation.setStatus(OperationStatus.ERROR,
- Localization.get("error_wrong_9p"));
- this.publish(this.operation);
- return null;
- }
-
- int[] rgbArray = new int[w * h];
- trimedImage.getRGB(0, 0, w, h, rgbArray, 0, w);
- borderImage.setRGB(1, 1, w, h, rgbArray, 0, w);
- rgbArray = null;
-
- outputImage = borderImage;
- } else {
-
- float ratio = density.getScale()
- / this.inputDensity.getScale();
- outputImage = this.rescaleImage(inputImage,
- (int) (ratio * inputImage.getWidth()),
- (int) (ratio * inputImage.getHeight()));
- }
-
- try {
-
- synchronized (fileLock) {
- ImageIO.write(outputImage, "png", outputFile);
- }
-
- } catch (IOException e) {
- this.operation.setStatus(OperationStatus.ERROR);
- this.publish(this.operation);
- return null;
- }
- }
- // }
- this.operation.setStatus(OperationStatus.FINISH);
- this.publish(this.operation);
- } catch (IOException e) {
- this.operation.setStatus(OperationStatus.ERROR);
- this.publish(this.operation);
+ if (output != null) {
+ name = this.inputFile.getName().substring(0, extensionPos) + "." + output.getFormat();
+ } else {
+ name = this.inputFile.getName();
+ output = Output.PNG;
}
- return null;
- }
+ File outputFile = new File(outputFolder, name);
+ if (outputFile.exists()) {
+ outputFile.delete();
+ }
- public void post() {
- executor.submit(this);
- }
+ BufferedImage outputImage;
+ if (this.inputFile.getName().endsWith(".9.png")) {
+ BufferedImage trimedImage = this.trim9PBorder(inputImage);
- private BufferedImage rescaleImage(BufferedImage image, int targetWidth,
- int targetHeight) {
- if (targetWidth == 0) {
- targetWidth = 1;
- }
- if (targetHeight == 0) {
- targetHeight = 1;
- }
- if (targetWidth * 2 < image.getWidth() - 1) {
- BufferedImage tempImage = this.rescaleImage(image,
- image.getWidth() / 2, image.getHeight() / 2);
- return this.rescaleImage(tempImage, targetWidth, targetHeight);
- } else {
- BufferedImage outputImage = new BufferedImage(targetWidth,
- targetHeight, BufferedImage.TYPE_INT_ARGB);
- Graphics2D graphics = outputImage.createGraphics();
- Map hints = new HashMap();
- hints.put(RenderingHints.KEY_DITHERING,
- RenderingHints.VALUE_DITHER_ENABLE);
- hints.put(RenderingHints.KEY_INTERPOLATION,
- RenderingHints.VALUE_INTERPOLATION_BILINEAR);
- hints.put(RenderingHints.KEY_RENDERING,
- RenderingHints.VALUE_RENDER_QUALITY);
- hints.put(RenderingHints.KEY_ANTIALIASING,
- RenderingHints.VALUE_ANTIALIAS_ON);
- hints.put(RenderingHints.KEY_ALPHA_INTERPOLATION,
- RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
- graphics.setRenderingHints(hints);
-
- graphics.drawImage(image, 0, 0, outputImage.getWidth(),
- outputImage.getHeight(), null);
- graphics.dispose();
-
- return outputImage;
- }
- }
+ float ratio = density.getScale()
+ / this.inputDensity.getScale();
+ trimedImage = this.rescaleImage(trimedImage,
+ (int) (ratio * trimedImage.getWidth()),
+ (int) (ratio * trimedImage.getHeight()));
- private BufferedImage trim9PBorder(BufferedImage inputImage) {
- BufferedImage trimedImage = new BufferedImage(
- inputImage.getWidth() - 2, inputImage.getHeight() - 2,
- BufferedImage.TYPE_INT_ARGB);
- Graphics2D g = trimedImage.createGraphics();
- g.drawImage(inputImage, 0, 0, trimedImage.getWidth(),
- trimedImage.getHeight(), 1, 1, inputImage.getWidth() - 1,
- inputImage.getHeight() - 1, null);
- g.dispose();
- return trimedImage;
- }
+ BufferedImage borderImage;
- private void enforceBorderColors(BufferedImage inputImage) {
- Graphics2D g = inputImage.createGraphics();
- g.setBackground(new Color(0, 0, 0, 0));
- g.clearRect(1, 1, inputImage.getWidth() - 2, inputImage.getHeight() - 2);
- g.dispose();
- int w = inputImage.getWidth();
- int h = inputImage.getHeight();
- int[] rgb = new int[w * h];
+ int w = trimedImage.getWidth();
+ int h = trimedImage.getHeight();
- inputImage.getRGB(0, 0, w, h, rgb, 0, w);
+ try {
+ borderImage = this.generateBordersImage(inputImage, w,
+ h);
+ } catch (Wrong9PatchException e) {
+ this.operation.setStatus(OperationStatus.ERROR,
+ Localization.get("error_wrong_9p"));
+ this.publish(this.operation);
+ return null;
+ }
+
+ int[] rgbArray = new int[w * h];
+ trimedImage.getRGB(0, 0, w, h, rgbArray, 0, w);
+ borderImage.setRGB(1, 1, w, h, rgbArray, 0, w);
+ rgbArray = null;
+
+ outputImage = borderImage;
+ } else {
+
+ float ratio = density.getScale()
+ / this.inputDensity.getScale();
+ outputImage = this.rescaleImage(inputImage,
+ (int) (ratio * inputImage.getWidth()),
+ (int) (ratio * inputImage.getHeight()));
+ }
+
+ try {
- for (int i = 0; i < rgb.length; i++) {
- if ((0xff000000 & rgb[i]) != 0) {
- rgb[i] = 0xff000000;
+ synchronized (fileLock) {
+ // Let's do the worst hack in the universe to speed things up !
+ if (Configuration.getSettings().shouldKeepSameDensityFile() && output == Output.JPG
+ && outputImage.getWidth() == inputImage.getWidth()
+ && outputImage.getHeight() == inputImage.getHeight()) {
+ ImageWriter.copy(inputFile, outputFile);
+ } else {
+ ImageWriter.write(outputImage, output, outputFile);
}
+ }
+
+ } catch (IOException e) {
+ this.operation.setStatus(OperationStatus.ERROR);
+ this.publish(this.operation);
+ return null;
}
- inputImage.setRGB(0, 0, w, h, rgb, 0, w);
- inputImage.setRGB(0, 0, 0x0);
- inputImage.setRGB(0, h - 1, 0x0);
- inputImage.setRGB(w - 1, h - 1, 0x0);
- inputImage.setRGB(w - 1, 0, 0x0);
+ }
+ // }
+ this.operation.setStatus(OperationStatus.FINISH);
+ this.publish(this.operation);
+ } catch (Exception e) {
+ this.operation.setStatus(OperationStatus.ERROR);
+ this.publish(this.operation);
}
- private BufferedImage generateBordersImage(BufferedImage source,
- int trimedWidth, int trimedHeight) throws Wrong9PatchException {
- BufferedImage finalBorder = new BufferedImage(trimedWidth + 2,
- trimedHeight + 2, BufferedImage.TYPE_INT_ARGB);
- int cutW = source.getWidth() - 2;
- int cutH = source.getHeight() - 2;
- {
- // left border
- BufferedImage leftBorder = new BufferedImage(1, cutH,
- BufferedImage.TYPE_INT_ARGB);
- leftBorder.setRGB(0, 0, 1, cutH,
- source.getRGB(0, 1, 1, cutH, null, 0, 1), 0, 1);
- this.verifyBorderImage(leftBorder);
- leftBorder = this.resizeBorder(leftBorder, 1, trimedHeight);
- finalBorder.setRGB(0, 1, 1, trimedHeight,
- leftBorder.getRGB(0, 0, 1, trimedHeight, null, 0, 1), 0, 1);
- }
- {
- // right border
- BufferedImage rightBorder = new BufferedImage(1, cutH,
- BufferedImage.TYPE_INT_ARGB);
- rightBorder.setRGB(0, 0, 1, cutH,
- source.getRGB(cutW + 1, 1, 1, cutH, null, 0, 1), 0, 1);
- this.verifyBorderImage(rightBorder);
- rightBorder = this.resizeBorder(rightBorder, 1, trimedHeight);
- finalBorder
- .setRGB(trimedWidth + 1, 1, 1, trimedHeight, rightBorder
- .getRGB(0, 0, 1, trimedHeight, null, 0, 1), 0, 1);
- }
- {
- // top border
- BufferedImage topBorder = new BufferedImage(cutW, 1,
- BufferedImage.TYPE_INT_ARGB);
- topBorder.setRGB(0, 0, cutW, 1,
- source.getRGB(1, 0, cutW, 1, null, 0, cutW), 0, cutW);
- this.verifyBorderImage(topBorder);
- topBorder = this.resizeBorder(topBorder, trimedWidth, 1);
- finalBorder.setRGB(1, 0, trimedWidth, 1, topBorder.getRGB(0, 0,
- trimedWidth, 1, null, 0, trimedWidth), 0, trimedWidth);
- }
- {
- // bottom border
- BufferedImage bottomBorder = new BufferedImage(cutW, 1,
- BufferedImage.TYPE_INT_ARGB);
- bottomBorder
- .setRGB(0, 0, cutW, 1,
- source.getRGB(1, cutH + 1, cutW, 1, null, 0, cutW),
- 0, cutW);
- this.verifyBorderImage(bottomBorder);
- bottomBorder = this.resizeBorder(bottomBorder, trimedWidth, 1);
- finalBorder.setRGB(1, trimedHeight + 1, trimedWidth, 1,
- bottomBorder.getRGB(0, 0, trimedWidth, 1, null, 0,
- trimedWidth), 0, trimedWidth);
- }
+ return null;
+ }
+
+ public void post() {
+ executor.submit(this);
+ }
- return finalBorder;
+ private BufferedImage rescaleImage(BufferedImage image, int targetWidth,
+ int targetHeight) {
+ if (targetWidth == 0) {
+ targetWidth = 1;
+ }
+ if (targetHeight == 0) {
+ targetHeight = 1;
+ }
+ if (targetWidth * 2 < image.getWidth() - 1) {
+ BufferedImage tempImage = this.rescaleImage(image,
+ image.getWidth() / 2, image.getHeight() / 2);
+ return this.rescaleImage(tempImage, targetWidth, targetHeight);
+ } else {
+ BufferedImage outputImage = new BufferedImage(targetWidth,
+ targetHeight, BufferedImage.TYPE_INT_ARGB);
+ Graphics2D graphics = outputImage.createGraphics();
+ Map hints = new HashMap();
+ hints.put(RenderingHints.KEY_DITHERING,
+ RenderingHints.VALUE_DITHER_ENABLE);
+ hints.put(RenderingHints.KEY_INTERPOLATION,
+ RenderingHints.VALUE_INTERPOLATION_BILINEAR);
+ hints.put(RenderingHints.KEY_RENDERING,
+ RenderingHints.VALUE_RENDER_QUALITY);
+ hints.put(RenderingHints.KEY_ANTIALIASING,
+ RenderingHints.VALUE_ANTIALIAS_ON);
+ hints.put(RenderingHints.KEY_ALPHA_INTERPOLATION,
+ RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
+ graphics.setRenderingHints(hints);
+
+ graphics.drawImage(image, 0, 0, outputImage.getWidth(),
+ outputImage.getHeight(), null);
+ graphics.dispose();
+
+ return outputImage;
+ }
+ }
+
+ private BufferedImage trim9PBorder(BufferedImage inputImage) {
+ BufferedImage trimedImage = new BufferedImage(
+ inputImage.getWidth() - 2, inputImage.getHeight() - 2,
+ BufferedImage.TYPE_INT_ARGB);
+ Graphics2D g = trimedImage.createGraphics();
+ g.drawImage(inputImage, 0, 0, trimedImage.getWidth(),
+ trimedImage.getHeight(), 1, 1, inputImage.getWidth() - 1,
+ inputImage.getHeight() - 1, null);
+ g.dispose();
+ return trimedImage;
+ }
+
+ private void enforceBorderColors(BufferedImage inputImage) {
+ Graphics2D g = inputImage.createGraphics();
+ g.setBackground(new Color(0, 0, 0, 0));
+ g.clearRect(1, 1, inputImage.getWidth() - 2, inputImage.getHeight() - 2);
+ g.dispose();
+ int w = inputImage.getWidth();
+ int h = inputImage.getHeight();
+ int[] rgb = new int[w * h];
+
+ inputImage.getRGB(0, 0, w, h, rgb, 0, w);
+
+ for (int i = 0; i < rgb.length; i++) {
+ if ((0xff000000 & rgb[i]) != 0) {
+ rgb[i] = 0xff000000;
+ }
+ }
+ inputImage.setRGB(0, 0, w, h, rgb, 0, w);
+ inputImage.setRGB(0, 0, 0x0);
+ inputImage.setRGB(0, h - 1, 0x0);
+ inputImage.setRGB(w - 1, h - 1, 0x0);
+ inputImage.setRGB(w - 1, 0, 0x0);
+ }
+
+ private BufferedImage generateBordersImage(BufferedImage source,
+ int trimedWidth, int trimedHeight)
+ throws Wrong9PatchException {
+ BufferedImage finalBorder = new BufferedImage(trimedWidth + 2,
+ trimedHeight + 2, BufferedImage.TYPE_INT_ARGB);
+ int cutW = source.getWidth() - 2;
+ int cutH = source.getHeight() - 2;
+ {
+ // left border
+ BufferedImage leftBorder = new BufferedImage(1, cutH,
+ BufferedImage.TYPE_INT_ARGB);
+ leftBorder.setRGB(0, 0, 1, cutH,
+ source.getRGB(0, 1, 1, cutH, null, 0, 1), 0, 1);
+ this.verifyBorderImage(leftBorder);
+ leftBorder = this.resizeBorder(leftBorder, 1, trimedHeight);
+ finalBorder.setRGB(0, 1, 1, trimedHeight,
+ leftBorder.getRGB(0, 0, 1, trimedHeight, null, 0, 1), 0, 1);
+ }
+ {
+ // right border
+ BufferedImage rightBorder = new BufferedImage(1, cutH,
+ BufferedImage.TYPE_INT_ARGB);
+ rightBorder.setRGB(0, 0, 1, cutH,
+ source.getRGB(cutW + 1, 1, 1, cutH, null, 0, 1), 0, 1);
+ this.verifyBorderImage(rightBorder);
+ rightBorder = this.resizeBorder(rightBorder, 1, trimedHeight);
+ finalBorder
+ .setRGB(trimedWidth + 1, 1, 1, trimedHeight, rightBorder
+ .getRGB(0, 0, 1, trimedHeight, null, 0, 1), 0, 1);
+ }
+ {
+ // top border
+ BufferedImage topBorder = new BufferedImage(cutW, 1,
+ BufferedImage.TYPE_INT_ARGB);
+ topBorder.setRGB(0, 0, cutW, 1,
+ source.getRGB(1, 0, cutW, 1, null, 0, cutW), 0, cutW);
+ this.verifyBorderImage(topBorder);
+ topBorder = this.resizeBorder(topBorder, trimedWidth, 1);
+ finalBorder.setRGB(1, 0, trimedWidth, 1, topBorder.getRGB(0, 0,
+ trimedWidth, 1, null, 0,
+ trimedWidth), 0, trimedWidth);
+ }
+ {
+ // bottom border
+ BufferedImage bottomBorder = new BufferedImage(cutW, 1,
+ BufferedImage.TYPE_INT_ARGB);
+ bottomBorder
+ .setRGB(0, 0, cutW, 1,
+ source.getRGB(1, cutH + 1, cutW, 1, null, 0, cutW),
+ 0, cutW);
+ this.verifyBorderImage(bottomBorder);
+ bottomBorder = this.resizeBorder(bottomBorder, trimedWidth, 1);
+ finalBorder.setRGB(1, trimedHeight + 1, trimedWidth, 1,
+ bottomBorder.getRGB(0, 0, trimedWidth, 1, null, 0,
+ trimedWidth), 0, trimedWidth);
}
- private BufferedImage resizeBorder(final BufferedImage border,
- int targetWidth, int targetHeight) {
- if (targetWidth > border.getWidth()
- || targetHeight > border.getHeight()) {
- BufferedImage endImage = this.rescaleImage(border, targetWidth,
- targetHeight);
- this.enforceBorderColors(endImage);
- return endImage;
- }
+ return finalBorder;
+ }
+
+ private BufferedImage resizeBorder(final BufferedImage border,
+ int targetWidth, int targetHeight) {
+ if (targetWidth > border.getWidth()
+ || targetHeight > border.getHeight()) {
+ BufferedImage endImage = this.rescaleImage(border, targetWidth,
+ targetHeight);
+ this.enforceBorderColors(endImage);
+ return endImage;
+ }
- int w = border.getWidth();
- int h = border.getHeight();
- int[] data = border.getRGB(0, 0, w, h, null, 0, w);
- int[] newData = new int[targetWidth * targetHeight];
-
- float widthRatio = (float) Math.max(targetWidth - 1, 1)
- / (float) Math.max(w - 1, 1);
- float heightRatio = (float) Math.max(targetHeight - 1, 1)
- / (float) Math.max(h - 1, 1);
-
- for (int y = 0; y < h; y++) {
- for (int x = 0; x < w; x++) {
- if ((0xff000000 & data[y * w + x]) != 0) {
- int newX = Math.min(Math.round(x * widthRatio),
- targetWidth - 1);
- int newY = Math.min(Math.round(y * heightRatio),
- targetHeight - 1);
-
- newData[newY * targetWidth + newX] = data[y * w + x];
- }
- }
+ int w = border.getWidth();
+ int h = border.getHeight();
+ int[] data = border.getRGB(0, 0, w, h, null, 0, w);
+ int[] newData = new int[targetWidth * targetHeight];
+
+ float widthRatio = (float) Math.max(targetWidth - 1, 1)
+ / (float) Math.max(w - 1, 1);
+ float heightRatio = (float) Math.max(targetHeight - 1, 1)
+ / (float) Math.max(h - 1, 1);
+
+ for (int y = 0; y < h; y++) {
+ for (int x = 0; x < w; x++) {
+ if ((0xff000000 & data[y * w + x]) != 0) {
+ int newX = Math.min(Math.round(x * widthRatio),
+ targetWidth - 1);
+ int newY = Math.min(Math.round(y * heightRatio),
+ targetHeight - 1);
+
+ newData[newY * targetWidth + newX] = data[y * w + x];
}
-
- BufferedImage img = new BufferedImage(targetWidth, targetHeight,
- BufferedImage.TYPE_INT_ARGB);
- img.setRGB(0, 0, targetWidth, targetHeight, newData, 0, targetWidth);
-
- return img;
+ }
}
- private void verifyBorderImage(BufferedImage border)
- throws Wrong9PatchException {
- int[] rgb = border.getRGB(0, 0, border.getWidth(), border.getHeight(),
- null, 0, border.getWidth());
- for (int i = 0; i < rgb.length; i++) {
- if ((0xff000000 & rgb[i]) != 0) {
- if (rgb[i] != 0xff000000 && rgb[i] != 0xffff0000) {
- throw new Wrong9PatchException();
- }
- }
+ BufferedImage img = new BufferedImage(targetWidth, targetHeight,
+ BufferedImage.TYPE_INT_ARGB);
+ img.setRGB(0, 0, targetWidth, targetHeight, newData, 0, targetWidth);
+
+ return img;
+ }
+
+ private void verifyBorderImage(BufferedImage border)
+ throws Wrong9PatchException {
+ int[] rgb = border.getRGB(0, 0, border.getWidth(), border.getHeight(),
+ null, 0, border.getWidth());
+ for (int i = 0; i < rgb.length; i++) {
+ if ((0xff000000 & rgb[i]) != 0) {
+ if (rgb[i] != 0xff000000 && rgb[i] != 0xffff0000) {
+ throw new Wrong9PatchException();
}
+ }
}
+ }
}
diff --git a/src/net/redwarp/tool/resizer/worker/ImageWriter.java b/src/net/redwarp/tool/resizer/worker/ImageWriter.java
new file mode 100644
index 0000000..c74f9dd
--- /dev/null
+++ b/src/net/redwarp/tool/resizer/worker/ImageWriter.java
@@ -0,0 +1,83 @@
+/*
+ * 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.
+ *
+ * Copyright 2013-2015 Redwarp
+ */
+
+package net.redwarp.tool.resizer.worker;
+
+import java.awt.*;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.nio.channels.FileChannel;
+import java.util.Iterator;
+
+import javax.imageio.IIOImage;
+import javax.imageio.ImageIO;
+import javax.imageio.ImageWriteParam;
+import javax.imageio.stream.FileImageOutputStream;
+
+public class ImageWriter {
+
+ public static void write(BufferedImage outputImage, Output output, File outputFile)
+ throws IOException {
+ if (output == Output.JPG) {
+ // Need to strip alpha;
+ BufferedImage
+ img =
+ new BufferedImage(outputImage.getWidth(), outputImage.getHeight(),
+ BufferedImage.TYPE_INT_RGB);
+ Graphics2D g2d = img.createGraphics();
+ g2d.drawImage(outputImage, 0, 0, null);
+ g2d.dispose();
+ outputImage = img;
+
+ Iterator itor = ImageIO.getImageWritersByFormatName("jpeg");
+ javax.imageio.ImageWriter writer = itor.next();
+ ImageWriteParam imageWriteParam = writer.getDefaultWriteParam();
+ imageWriteParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
+ imageWriteParam.setCompressionQuality(0.9f);
+
+ FileImageOutputStream outputStream = new FileImageOutputStream(outputFile);
+ writer.setOutput(outputStream);
+ IIOImage image = new IIOImage(outputImage, null, null);
+ writer.write(null, image, imageWriteParam);
+ writer.dispose();
+
+ } else {
+ ImageIO.write(outputImage, output.getFormat(), outputFile);
+ }
+ }
+
+ public static void copy(File inputFile, File outputFile) throws IOException {
+ if (inputFile != null && outputFile != null) {
+ FileChannel sourceChannel = null;
+ FileChannel destChannel = null;
+ try {
+ sourceChannel = new FileInputStream(inputFile).getChannel();
+ destChannel = new FileOutputStream(outputFile).getChannel();
+ destChannel.transferFrom(sourceChannel, 0, sourceChannel.size());
+ } finally {
+ if (sourceChannel != null) {
+ sourceChannel.close();
+ }
+ if (destChannel != null) {
+ destChannel.close();
+ }
+ }
+ }
+ }
+}
diff --git a/src/net/redwarp/tool/resizer/worker/Output.java b/src/net/redwarp/tool/resizer/worker/Output.java
new file mode 100644
index 0000000..9d61ffa
--- /dev/null
+++ b/src/net/redwarp/tool/resizer/worker/Output.java
@@ -0,0 +1,31 @@
+/*
+ * 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.
+ *
+ * Copyright 2013-2015 Redwarp
+ */
+
+package net.redwarp.tool.resizer.worker;
+
+public enum Output {
+ PNG("png"), JPG("jpg");
+
+ private String format;
+
+ Output(String format) {
+ this.format = format;
+ }
+
+ public String getFormat() {
+ return format;
+ }
+}
diff --git a/src/net/redwarp/tool/resizer/worker/ScreenDensity.java b/src/net/redwarp/tool/resizer/worker/ScreenDensity.java
index 94ba418..b0c10dd 100644
--- a/src/net/redwarp/tool/resizer/worker/ScreenDensity.java
+++ b/src/net/redwarp/tool/resizer/worker/ScreenDensity.java
@@ -11,111 +11,51 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
- * Copyright 2013 Redwarp
+ * Copyright 2013-2015 Redwarp
*/
package net.redwarp.tool.resizer.worker;
-import com.google.gson.Gson;
-import com.google.gson.JsonArray;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
-import com.google.gson.reflect.TypeToken;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.List;
-
public class ScreenDensity {
- private float scale;
- private String name;
-
-
- private boolean active;
- private static List list = null;
- private static ScreenDensity defaultInputDensity = null;
+ private float scale;
+ private String name;
- static {
- try {
- Gson gson = new Gson();
- JsonParser parser = new JsonParser();
- InputStream preferenceStream;
- try {
- preferenceStream = new FileInputStream(new File("./densities.json"));
- } catch (Exception e) {
- preferenceStream = ScreenDensity.class.getClassLoader().getResourceAsStream("misc/densities.json");
- }
- JsonObject densitiesObject = parser.parse(new InputStreamReader(preferenceStream)).getAsJsonObject();
- JsonArray densitiesArray = densitiesObject.get("densities").getAsJsonArray();
-
- Type listType = new TypeToken>() {
- }.getType();
- list = gson.fromJson(densitiesArray, listType);
- String defaultDensityName = densitiesObject.get("source").getAsString();
- for (ScreenDensity density : list) {
- if (density.getName().equals(defaultDensityName)) {
- defaultInputDensity = density;
- break;
- }
- }
- if (defaultInputDensity == null) {
- defaultInputDensity = list.get(0);
- }
- } catch (Exception e) {
- list = new ArrayList();
- list.add(new ScreenDensity("xhdpi", 2.0f, true));
- defaultInputDensity = list.get(0);
- }
- }
-
- private ScreenDensity(String name, float density, boolean active) {
- this.scale = density;
- this.name = name;
- this.active = active;
- }
+ private boolean active;
- @Override
- public String toString() {
- return this.name;
- }
+ public ScreenDensity(String name, float density, boolean active) {
+ this.scale = density;
+ this.name = name;
+ this.active = active;
+ }
- public String getName() {
- return this.name;
- }
+ @Override
+ public String toString() {
+ return this.name;
+ }
- public float getScale() {
- return this.scale;
- }
+ public String getName() {
+ return this.name;
+ }
- public static List getSupportedScreenDensity() {
- return list;
- }
+ public float getScale() {
+ return this.scale;
+ }
- public static ScreenDensity getDefaultInputDensity() {
- return defaultInputDensity;
- }
- public static void setDefaultInputDensity(ScreenDensity density) {
- defaultInputDensity = density;
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof ScreenDensity) {
+ return this.name.equals(((ScreenDensity) obj).getName());
}
+ return false;
+ }
- @Override
- public boolean equals(Object obj) {
- if (obj instanceof ScreenDensity) {
- return this.name.equals(((ScreenDensity) obj).getName());
- }
- return false;
- }
+ public boolean isActive() {
+ return active;
+ }
- public boolean isActive() {
- return active;
- }
+ public void setActive(boolean active) {
+ this.active = active;
+ }
- public void setActive(boolean active) {
- this.active = active;
- }
}
diff --git a/src/net/redwarp/tool/resizer/worker/UnsupportedDensityException.java b/src/net/redwarp/tool/resizer/worker/UnsupportedDensityException.java
index d00643f..9239c25 100644
--- a/src/net/redwarp/tool/resizer/worker/UnsupportedDensityException.java
+++ b/src/net/redwarp/tool/resizer/worker/UnsupportedDensityException.java
@@ -11,7 +11,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
- * Copyright 2013 Redwarp
+ * Copyright 2013-2015 Redwarp
*/
package net.redwarp.tool.resizer.worker;
diff --git a/src/net/redwarp/tool/resizer/worker/Wrong9PatchException.java b/src/net/redwarp/tool/resizer/worker/Wrong9PatchException.java
index 9ec7609..d1ace32 100644
--- a/src/net/redwarp/tool/resizer/worker/Wrong9PatchException.java
+++ b/src/net/redwarp/tool/resizer/worker/Wrong9PatchException.java
@@ -11,11 +11,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
- * Copyright 2013 Redwarp
+ * Copyright 2013-2015 Redwarp
*/
package net.redwarp.tool.resizer.worker;
-@SuppressWarnings("serial")
public class Wrong9PatchException extends Exception {
}