From f287e881884c7b804aca54d7170fdc173b5b289b Mon Sep 17 00:00:00 2001 From: redwarp Date: Mon, 8 Sep 2014 09:17:42 +0200 Subject: [PATCH 01/35] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 15de445..d2c4cfb 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ 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.3.2* +Current version : *1.3.3* You're using 9patch resizer for your apps ? Don't hesitate and leave me a message! From 413af2d9edfcb4a285444bdb910da9c511584f1f Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Lab Date: Tue, 9 Sep 2014 19:51:47 +0200 Subject: [PATCH 02/35] Add Apache license header --- src/net/redwarp/tool/resizer/FileProcessor.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/net/redwarp/tool/resizer/FileProcessor.java b/src/net/redwarp/tool/resizer/FileProcessor.java index a78f471..66bd44a 100644 --- a/src/net/redwarp/tool/resizer/FileProcessor.java +++ b/src/net/redwarp/tool/resizer/FileProcessor.java @@ -1,3 +1,18 @@ +/* + * 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 java.io.File; From 8129edc73b160bf33ca72061bd4f9b543c8970cd Mon Sep 17 00:00:00 2001 From: redwarp Date: Wed, 10 Sep 2014 10:31:30 +0200 Subject: [PATCH 03/35] Update README.md --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d2c4cfb..484249c 100644 --- a/README.md +++ b/README.md @@ -29,9 +29,14 @@ You're using 9patch resizer for your apps ? Don't hesitate and leave me a messag ## Roadmap -- [ ] Command line support +- [x] Command line support - [ ] A few optimisations - [x] Options to set the input density (if people wan't to downsize from hdpi and not from xdpi for instance) + +## Contributors + + * redwarp - That would be me + * Jean-Baptiste LAB - Made the app working in command line ## Anyway... From 6aab547cbf1598d21458b071891b83c4b48c57a5 Mon Sep 17 00:00:00 2001 From: redwarp Date: Wed, 10 Sep 2014 10:33:38 +0200 Subject: [PATCH 04/35] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 484249c..7e3fbff 100644 --- a/README.md +++ b/README.md @@ -35,9 +35,11 @@ You're using 9patch resizer for your apps ? Don't hesitate and leave me a messag ## Contributors - * redwarp - That would be me + * redwarp * Jean-Baptiste LAB - Made the app working in command line +Join us, and together, we can rule the galaxy as coders and... + ## 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 ! From f8b16a8f2cd6f427d4b876513c8fe86e5f667c79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Vermont?= Date: Wed, 17 Sep 2014 13:45:28 +0200 Subject: [PATCH 05/35] Add a generic license file --- LICENSE | 201 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 201 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a91e448 --- /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 2014 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 From 58f178beab78b97f94cea6afb1f1aafcb18b1065 Mon Sep 17 00:00:00 2001 From: redwarp Date: Tue, 28 Oct 2014 11:36:45 +0100 Subject: [PATCH 06/35] Update README.md Add fork section --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 7e3fbff..5699bab 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ You're using 9patch resizer for your apps ? Don't hesitate and leave me a messag - [x] Command line support - [ ] A few optimisations - [x] Options to set the input density (if people wan't to downsize from hdpi and not from xdpi for instance) +- [ ] Proper JPG support ## Contributors @@ -40,6 +41,10 @@ You're using 9patch resizer for your apps ? Don't hesitate and leave me a messag 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 ! From e85c69d38d5bd6af22a2ecc3b89c5137e877cf4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Vermont?= Date: Tue, 28 Oct 2014 18:50:19 +0100 Subject: [PATCH 07/35] Code cleanup --- src/net/redwarp/tool/resizer/worker/ImageScaler.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/net/redwarp/tool/resizer/worker/ImageScaler.java b/src/net/redwarp/tool/resizer/worker/ImageScaler.java index 3df68e0..8d3360c 100644 --- a/src/net/redwarp/tool/resizer/worker/ImageScaler.java +++ b/src/net/redwarp/tool/resizer/worker/ImageScaler.java @@ -38,8 +38,8 @@ public class ImageScaler extends SwingWorker { private ScreenDensity inputDensity; private static ExecutorService executor = Executors .newFixedThreadPool(Runtime.getRuntime().availableProcessors()); - private static Object fileLock = new Object(); - private static Object folderLock = new Object(); + private static final Object fileLock = new Object(); + private static final Object folderLock = new Object(); public ImageScaler(final Operation operation, final ScreenDensity inputDensity) { @@ -70,7 +70,7 @@ protected Void doInBackground() throws Exception { File parent = this.inputFile.getParentFile(); for (ScreenDensity density : densityList) { - if (density.isActive() == false) { + if (!density.isActive()) { continue; } File outputFolder; @@ -97,10 +97,6 @@ protected Void doInBackground() throws Exception { 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); From 37114b86d9175e722e675ae2c4e1cbe02bb83e41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Vermont?= Date: Tue, 28 Oct 2014 19:27:43 +0100 Subject: [PATCH 08/35] Handle jpg, and normalize filename testing --- .../redwarp/tool/resizer/FileProcessor.java | 87 +++++++------- src/net/redwarp/tool/resizer/Main.java | 111 +++++++++--------- .../tool/resizer/misc/NameValidator.java | 29 +++++ .../tool/resizer/views/MainWindow.java | 5 +- .../tool/resizer/worker/ImageScaler.java | 29 ++++- .../tool/resizer/worker/ImageWriter.java | 43 +++++++ .../redwarp/tool/resizer/worker/Output.java | 36 ++++++ 7 files changed, 237 insertions(+), 103 deletions(-) create mode 100644 src/net/redwarp/tool/resizer/misc/NameValidator.java create mode 100644 src/net/redwarp/tool/resizer/worker/ImageWriter.java create mode 100644 src/net/redwarp/tool/resizer/worker/Output.java diff --git a/src/net/redwarp/tool/resizer/FileProcessor.java b/src/net/redwarp/tool/resizer/FileProcessor.java index 66bd44a..a31d43a 100644 --- a/src/net/redwarp/tool/resizer/FileProcessor.java +++ b/src/net/redwarp/tool/resizer/FileProcessor.java @@ -15,59 +15,62 @@ */ package net.redwarp.tool.resizer; -import java.io.File; - +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 net.redwarp.tool.resizer.worker.ScreenDensity; +import java.io.File; + public class FileProcessor { - public interface FileProcessorStatusListener { - void onSuccess(); + public interface FileProcessorStatusListener { + void onSuccess(); - void onFailure(String msg); - } + void onFailure(String msg); + } - private ImageScaler scaler; - FileProcessorStatusListener listener; - String fileName; + private ImageScaler scaler; + FileProcessorStatusListener listener; + String fileName; - public FileProcessor(String name, FileProcessorStatusListener l) { - fileName = name; - listener = l; - if (name.endsWith(".png") || name.endsWith(".jpg")) { - Operation operation = new Operation(new File(name)); + 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, - ScreenDensity.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) { - listener.onFailure(operation.getMessage()); - } - } - } - }; - } - } + scaler = new ImageScaler(operation, + ScreenDensity.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"); - } - } - } + 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/Main.java b/src/net/redwarp/tool/resizer/Main.java index ba6bd24..4d814cd 100644 --- a/src/net/redwarp/tool/resizer/Main.java +++ b/src/net/redwarp/tool/resizer/Main.java @@ -15,74 +15,73 @@ */ package net.redwarp.tool.resizer; -import java.util.ArrayList; - import net.redwarp.tool.resizer.FileProcessor.FileProcessorStatusListener; import net.redwarp.tool.resizer.misc.Localization; import net.redwarp.tool.resizer.views.MainWindow; import javax.swing.*; +import java.util.ArrayList; public class Main { - static class StatusListener implements FileProcessorStatusListener { - int count = 0; - int current = 0; - int failureCount = 0; + static class StatusListener implements FileProcessorStatusListener { + int count = 0; + int current = 0; + int failureCount = 0; - public StatusListener(int count) { - this.count = count; - } + public StatusListener(int count) { + this.count = count; + } - @Override - public void onSuccess() { - this.current++; - if (this.current == this.count) { - System.exit(failureCount); - } - } + @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); - } - } - } + @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")); - if (args.length > 0) { - StatusListener l = new StatusListener(args.length); - ArrayList processors = new ArrayList(); + 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")); + 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 { + 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(); - } + 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); - } - } + new MainWindow().setVisible(true); + } + } } diff --git a/src/net/redwarp/tool/resizer/misc/NameValidator.java b/src/net/redwarp/tool/resizer/misc/NameValidator.java new file mode 100644 index 0000000..beec16d --- /dev/null +++ b/src/net/redwarp/tool/resizer/misc/NameValidator.java @@ -0,0 +1,29 @@ +/* + * 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 Redwarp + */ + +package net.redwarp.tool.resizer.misc; + +/** + * 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/views/MainWindow.java b/src/net/redwarp/tool/resizer/views/MainWindow.java index 059af6c..e6ba91a 100644 --- a/src/net/redwarp/tool/resizer/views/MainWindow.java +++ b/src/net/redwarp/tool/resizer/views/MainWindow.java @@ -18,6 +18,7 @@ import net.iharder.dnd.FileDrop; 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; @@ -182,8 +183,8 @@ public void actionPerformed(ActionEvent e) { @Override public void filesDropped(Container source, File[] files) { for (File input : files) { - String name = input.getName().toLowerCase(); - if (name.endsWith(".png") || name.endsWith(".jpg")) { + String filename = input.getName(); + if (NameValidator.isFilenameValid(filename)) { MainWindow.this.mntmClear.setEnabled(true); CardLayout layout = (CardLayout) MainWindow.this .getContentPane().getLayout(); diff --git a/src/net/redwarp/tool/resizer/worker/ImageScaler.java b/src/net/redwarp/tool/resizer/worker/ImageScaler.java index 8d3360c..e746cfd 100644 --- a/src/net/redwarp/tool/resizer/worker/ImageScaler.java +++ b/src/net/redwarp/tool/resizer/worker/ImageScaler.java @@ -60,6 +60,18 @@ protected Void doInBackground() throws Exception { 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); @@ -84,12 +96,22 @@ protected Void doInBackground() throws Exception { } String name; + Output output = null; int extensionPos = this.inputFile.getName().lastIndexOf('.'); if (extensionPos != -1) { - name = this.inputFile.getName().substring(0, extensionPos) - + ".png"; + 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; + } + } + + if (output != null) { + name = this.inputFile.getName().substring(0, extensionPos) + "." + output.getFormat(); } else { name = this.inputFile.getName(); + output = Output.PNG; } File outputFile = new File(outputFolder, name); @@ -140,7 +162,8 @@ protected Void doInBackground() throws Exception { try { synchronized (fileLock) { - ImageIO.write(outputImage, "png", outputFile); + ImageWriter.write(outputImage,output, outputFile); +// ImageIO.write(outputImage, output.getFormat(), outputFile); } } catch (IOException e) { 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..abdb868 --- /dev/null +++ b/src/net/redwarp/tool/resizer/worker/ImageWriter.java @@ -0,0 +1,43 @@ +/* + * 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 Redwarp + */ + +package net.redwarp.tool.resizer.worker; + +import javax.imageio.ImageIO; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; + +/** + * User: benoit.vermont@airtag.com + * Date: 28/10/14 + * Time: 19:24 + */ +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; + } + + ImageIO.write(outputImage, output.getFormat(), outputFile); + } +} 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..4f1bf0d --- /dev/null +++ b/src/net/redwarp/tool/resizer/worker/Output.java @@ -0,0 +1,36 @@ +/* + * 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 Redwarp + */ + +package net.redwarp.tool.resizer.worker; + +/** + * User: benoit.vermont@airtag.com + * Date: 28/10/14 + * Time: 18:55 + */ +public enum Output { + PNG("png"), JPG("jpg"); + + private String format; + + Output(String format) { + this.format = format; + } + + public String getFormat() { + return format; + } +} From 960d4ab52ccaba30b1915e58b5f0d88b25326fc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Vermont?= Date: Wed, 29 Oct 2014 19:42:23 +0100 Subject: [PATCH 09/35] Set compression for jpg to 0.9 --- .../tool/resizer/worker/ImageWriter.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/net/redwarp/tool/resizer/worker/ImageWriter.java b/src/net/redwarp/tool/resizer/worker/ImageWriter.java index abdb868..7c9e293 100644 --- a/src/net/redwarp/tool/resizer/worker/ImageWriter.java +++ b/src/net/redwarp/tool/resizer/worker/ImageWriter.java @@ -16,11 +16,15 @@ package net.redwarp.tool.resizer.worker; +import javax.imageio.IIOImage; import javax.imageio.ImageIO; +import javax.imageio.ImageWriteParam; +import javax.imageio.stream.FileImageOutputStream; import java.awt.*; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; +import java.util.Iterator; /** * User: benoit.vermont@airtag.com @@ -36,8 +40,21 @@ public static void write(BufferedImage outputImage, Output output, File outputFi g2d.drawImage(outputImage, 0, 0, null); g2d.dispose(); outputImage = img; - } - ImageIO.write(outputImage, output.getFormat(), outputFile); + 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); + } } } From 2fc8f21451689f5b642ff0f1dcae0dcdcaee5db2 Mon Sep 17 00:00:00 2001 From: Benoit Vermont Date: Mon, 3 Nov 2014 17:32:35 +0100 Subject: [PATCH 10/35] Untrack idea file --- .gitignore | 2 +- .idea/misc.xml | 10 ---------- 2 files changed, 1 insertion(+), 11 deletions(-) delete mode 100644 .idea/misc.xml diff --git a/.gitignore b/.gitignore index 7a46396..cc0e826 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,4 @@ /antbin /launch4j.log target -.idea/workspace.xml +.idea/ \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 9732041..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - From 8cb74a60c02ae5ba617a2fa984865c8e9bae1414 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Vermont?= Date: Thu, 12 Feb 2015 17:35:14 +0100 Subject: [PATCH 11/35] Adds the ability to keep original image file for same density, for jpeg (quite ugly, will need a refactoring) --- res/misc/densities.json | 77 +-- .../tool/resizer/worker/ImageScaler.java | 616 +++++++++--------- .../tool/resizer/worker/ImageWriter.java | 86 ++- .../tool/resizer/worker/ScreenDensity.java | 299 +++++---- 4 files changed, 574 insertions(+), 504 deletions(-) diff --git a/res/misc/densities.json b/res/misc/densities.json index 8ac75e9..bcb90b2 100644 --- a/res/misc/densities.json +++ b/res/misc/densities.json @@ -1,40 +1,41 @@ { - "source": "xxhdpi", - "densities": [ - { - "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 - } - ] + "source": "xxhdpi", + "densities": [ + { + "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/src/net/redwarp/tool/resizer/worker/ImageScaler.java b/src/net/redwarp/tool/resizer/worker/ImageScaler.java index e746cfd..8ba4b73 100644 --- a/src/net/redwarp/tool/resizer/worker/ImageScaler.java +++ b/src/net/redwarp/tool/resizer/worker/ImageScaler.java @@ -19,8 +19,6 @@ 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,35 +30,39 @@ 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 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); - } - if (inputImage == null) { - this.operation.setStatus(OperationStatus.ERROR, - Localization.get("error_wrong_png")); - this.publish(this.operation); - return null; - } else { + 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); + } + 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(), @@ -72,301 +74,311 @@ protected Void doInBackground() throws Exception { // g.dispose(); // inputImage = tempImage; // } - } - - this.operation.setStatus(OperationStatus.IN_PROGRESS); - this.publish(this.operation); - - List densityList = ScreenDensity - .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(); - } - } - - 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; - } - } - - if (output != null) { - name = this.inputFile.getName().substring(0, extensionPos) + "." + output.getFormat(); - } else { - name = this.inputFile.getName(); - output = Output.PNG; - } - - File outputFile = new File(outputFolder, name); - if (outputFile.exists()) { - outputFile.delete(); - } - - 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) { - ImageWriter.write(outputImage,output, outputFile); -// ImageIO.write(outputImage, output.getFormat(), 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); - } + } - return null; - } + this.operation.setStatus(OperationStatus.IN_PROGRESS); + this.publish(this.operation); - public void post() { - executor.submit(this); - } + List densityList = ScreenDensity + .getSupportedScreenDensity(); - private BufferedImage rescaleImage(BufferedImage image, int targetWidth, - int targetHeight) { - if (targetWidth == 0) { - targetWidth = 1; + File parent = this.inputFile.getParentFile(); + for (ScreenDensity density : densityList) { + if (!density.isActive()) { + continue; } - if (targetHeight == 0) { - targetHeight = 1; + File outputFolder; + + synchronized (folderLock) { + outputFolder = new File(parent, "drawable-" + + density.getName()); + if (!outputFolder.exists()) { + outputFolder.mkdir(); + } + } + + 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; + } } - if (targetWidth * 2 < image.getWidth() - 1) { - BufferedImage tempImage = this.rescaleImage(image, - image.getWidth() / 2, image.getHeight() / 2); - return this.rescaleImage(tempImage, targetWidth, targetHeight); + + if (output != null) { + name = this.inputFile.getName().substring(0, extensionPos) + "." + output.getFormat(); } 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; + name = this.inputFile.getName(); + output = Output.PNG; } - } - 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; - } + File outputFile = new File(outputFolder, name); + if (outputFile.exists()) { + outputFile.delete(); + } - 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]; + BufferedImage outputImage; + if (this.inputFile.getName().endsWith(".9.png")) { + BufferedImage trimedImage = this.trim9PBorder(inputImage); - inputImage.getRGB(0, 0, w, h, rgb, 0, w); + float ratio = density.getScale() + / this.inputDensity.getScale(); + trimedImage = this.rescaleImage(trimedImage, + (int) (ratio * trimedImage.getWidth()), + (int) (ratio * trimedImage.getHeight())); - 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); - } + BufferedImage borderImage; - 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); - } + int w = trimedImage.getWidth(); + int h = trimedImage.getHeight(); - return finalBorder; - } + 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; - 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; + outputImage = borderImage; + } else { + + float ratio = density.getScale() + / this.inputDensity.getScale(); + outputImage = this.rescaleImage(inputImage, + (int) (ratio * inputImage.getWidth()), + (int) (ratio * inputImage.getHeight())); } - 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]; - } + try { + + synchronized (fileLock) { + // Let's do the worst hack in the universe to speed things up ! + if (ScreenDensity.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; } + } + // } + this.operation.setStatus(OperationStatus.FINISH); + this.publish(this.operation); + } catch (IOException e) { + this.operation.setStatus(OperationStatus.ERROR); + this.publish(this.operation); + } - BufferedImage img = new BufferedImage(targetWidth, targetHeight, - BufferedImage.TYPE_INT_ARGB); - img.setRGB(0, 0, targetWidth, targetHeight, newData, 0, targetWidth); + return null; + } - return img; + public void post() { + executor.submit(this); + } + + 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 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(); - } - } + 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]; + } + } + } + + 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 index 7c9e293..49d34eb 100644 --- a/src/net/redwarp/tool/resizer/worker/ImageWriter.java +++ b/src/net/redwarp/tool/resizer/worker/ImageWriter.java @@ -16,45 +16,71 @@ package net.redwarp.tool.resizer.worker; -import javax.imageio.IIOImage; -import javax.imageio.ImageIO; -import javax.imageio.ImageWriteParam; -import javax.imageio.stream.FileImageOutputStream; 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; + /** - * User: benoit.vermont@airtag.com - * Date: 28/10/14 - * Time: 19:24 + * User: benoit.vermont@airtag.com Date: 28/10/14 Time: 19:24 */ 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 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.8f); + + 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/ScreenDensity.java b/src/net/redwarp/tool/resizer/worker/ScreenDensity.java index 7ec9432..dcb4fbf 100644 --- a/src/net/redwarp/tool/resizer/worker/ScreenDensity.java +++ b/src/net/redwarp/tool/resizer/worker/ScreenDensity.java @@ -15,161 +15,192 @@ */ package net.redwarp.tool.resizer.worker; -import com.google.gson.*; +import com.google.gson.Gson; +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 javax.swing.*; -import java.io.*; +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; -public class ScreenDensity { - private static final String KEY_DENSITIES = "densities"; - private static final String KEY_SOURCE = "source"; - public static final String DENSITIES_PATHNAME = "./densities.json"; - private float scale; - private String name; - - private boolean active; - - private static List list = null; - private static ScreenDensity defaultInputDensity = null; +import javax.swing.*; - static { - load(); - } +public class ScreenDensity { - private static void load() { - try { - Gson gson = new Gson(); - JsonParser parser = new JsonParser(); - InputStream preferenceStream; - try { - preferenceStream = new FileInputStream(new File(DENSITIES_PATHNAME)); - } catch (Exception e) { - preferenceStream = ScreenDensity.class.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); - } - } catch (Exception e) { - list = new ArrayList(); - list.add(new ScreenDensity("xhdpi", 2.0f, true)); - defaultInputDensity = list.get(0); + 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"; + public static final String DENSITIES_PATHNAME = "./densities.json"; + private float scale; + private String name; + + private boolean active; + + private static List list = null; + private static ScreenDensity defaultInputDensity = null; + private static boolean keepSameDensityFile = false; + + static { + load(); + } + + private static void load() { + try { + Gson gson = new Gson(); + JsonParser parser = new JsonParser(); + InputStream preferenceStream; + try { + preferenceStream = new FileInputStream(new File(DENSITIES_PATHNAME)); + } catch (Exception e) { + preferenceStream = + ScreenDensity.class.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); } - - public static void save(JButton saveButton) { - saveButton.setEnabled(false); - JsonObject rootObject = new JsonObject(); - // Save source - rootObject.addProperty(KEY_SOURCE, defaultInputDensity.getName()); - - // Save densities - Gson gson = new Gson(); - Type listOfDensityType = new TypeToken>() { - }.getType(); - JsonElement densities = gson.toJsonTree(list, listOfDensityType); - rootObject.add(KEY_DENSITIES, densities); - - SaveWorker worker = new SaveWorker(saveButton, rootObject.toString()); - worker.execute(); - } - - private ScreenDensity(String name, float density, boolean active) { - this.scale = density; - this.name = name; - this.active = active; + } + + public static void save(JButton saveButton) { + saveButton.setEnabled(false); + JsonObject rootObject = new JsonObject(); + // Save source + rootObject.addProperty(KEY_SOURCE, defaultInputDensity.getName()); + + // Save densities + Gson gson = new Gson(); + Type listOfDensityType = new TypeToken>() { + }.getType(); + JsonElement densities = gson.toJsonTree(list, listOfDensityType); + rootObject.add(KEY_DENSITIES, densities); + + SaveWorker worker = new SaveWorker(saveButton, rootObject.toString()); + worker.execute(); + } + + private ScreenDensity(String name, float density, boolean active) { + this.scale = density; + this.name = name; + this.active = active; + } + + @Override + public String toString() { + return this.name; + } + + public String getName() { + return this.name; + } + + public float getScale() { + return this.scale; + } + + public static List getSupportedScreenDensity() { + return list; + } + + public static ScreenDensity getDefaultInputDensity() { + return defaultInputDensity; + } + + // A flag to indicate if we should copy the original image, if the input and output are of the same density. + public static boolean shouldKeepSameDensityFile() { + return keepSameDensityFile; + } + + 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 String toString() { - return this.name; - } + public boolean isActive() { + return active; + } - public String getName() { - return this.name; - } + public void setActive(boolean active) { + this.active = active; + } - public float getScale() { - return this.scale; - } + public static class SaveWorker extends SwingWorker { - public static List getSupportedScreenDensity() { - return list; - } + private final String mSavePayload; + private final JButton mButton; - public static ScreenDensity getDefaultInputDensity() { - return defaultInputDensity; + public SaveWorker(JButton saveButton, String savePayload) { + mButton = saveButton; + mSavePayload = savePayload; } - 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; - } - - public boolean isActive() { - return active; - } - - public void setActive(boolean active) { - this.active = active; + 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; } - public static class SaveWorker extends SwingWorker { - private final String mSavePayload; - private final JButton mButton; - - public SaveWorker(JButton saveButton, String savePayload) { - mButton = saveButton; - 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 (mButton != null) { - mButton.setEnabled(true); - } - } + @Override + protected void done() { + if (mButton != null) { + mButton.setEnabled(true); + } } + } } From c5e5454c7efb314a14c77e116093d5b04f844e24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Vermont?= Date: Thu, 12 Feb 2015 18:43:01 +0100 Subject: [PATCH 12/35] Modify UI to add the extra option --- densities.json | 1 + res/locale/Strings.properties | 8 +- res/locale/Strings_fr.properties | 12 +- .../tool/resizer/views/MainWindow.java | 504 +++++++++--------- .../tool/resizer/worker/ScreenDensity.java | 5 + 5 files changed, 284 insertions(+), 246 deletions(-) create mode 100644 densities.json diff --git a/densities.json b/densities.json new file mode 100644 index 0000000..491aa2b --- /dev/null +++ b/densities.json @@ -0,0 +1 @@ +{"source":"xxhdpi","densities":[{"scale":4.0,"name":"xxxhdpi","active":false},{"scale":3.0,"name":"xxhdpi","active":true},{"scale":2.0,"name":"xhdpi","active":true},{"scale":1.5,"name":"hdpi","active":true},{"scale":1.33,"name":"tvdpi","active":false},{"scale":1.0,"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/locale/Strings.properties b/res/locale/Strings.properties index 7c52339..fac4ed7 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.\nIt takes a PNG 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 2014. 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 2014-2015. All rights reserved. app_name=9Patch Resizer column_name=Image name column_status=Status @@ -15,8 +15,10 @@ status_error=Error status_finished=Finished \! status_in_progress=In progress... status_pending=Pending... -xhdpi=Drop %s image here (PNG format, nine patch included) -input_density=Input density: +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. diff --git a/res/locale/Strings_fr.properties b/res/locale/Strings_fr.properties index 86a46f8..cf090d1 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.\nIl g�n�re automatiquement plusieurs dossiers de densit� \: 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 2014. Tous droits r\u00E9serv\u00E9s. +about_text=Resizer est un outil de redimensionnement pour Android.\nIl génère automatiquement plusieurs dossiers de densité \: 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 2014-2015. Tous droits r\u00E9serv\u00E9s. app_name=9Patch Resizer column_name=Nom de l'image column_status=Status @@ -12,11 +12,13 @@ menu_item_about=\u00C0 propos de Resizer menu_item_clear=Effacer menu_item_clear_desc=Efface l'historique de conversion status_error=Erreur -status_finished=Termin� \! +status_finished=Terminé \! status_in_progress=En cours... status_pending=En attente... -xhdpi=D\u00E9posez des images %s 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églages courants pour les réutiliser la prochaine fois que vous lancerez 9Patch Resizer +keep_same_density_file=Garder le fichier
original pour la même densité +keep_same_density_file_tooltip=Pour les formats, tel le jpg, où la compression dégrade l'image, cochez cette option s'assurera que le fichier original est copié dans le fichier de destination source, pour la même densité. diff --git a/src/net/redwarp/tool/resizer/views/MainWindow.java b/src/net/redwarp/tool/resizer/views/MainWindow.java index e6ba91a..579eac5 100644 --- a/src/net/redwarp/tool/resizer/views/MainWindow.java +++ b/src/net/redwarp/tool/resizer/views/MainWindow.java @@ -24,8 +24,6 @@ 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; @@ -35,254 +33,284 @@ 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(500, 370)); - 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(String.format(Locale.getDefault(), Localization.get("xhdpi"), ScreenDensity.getDefaultInputDensity().getName())); - 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); - 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 : 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); + 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(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)); + + this.inputPanel = new JPanel(); + this.inputPanel.setPreferredSize(new Dimension(10, 140)); + this.getContentPane().add(this.inputPanel, "input"); + + this.xhdpiButton = + new JButton(String.format(Locale.getDefault(), Localization.get("xhdpi"), + ScreenDensity.getDefaultInputDensity().getName())); + 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.setHorizontalAlignment(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); + 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 : ScreenDensity.getSupportedScreenDensity()) { + final JCheckBox box = new JCheckBox(density.getName()); + box.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + density.setActive(box.isSelected()); } - optionPanel.add(Box.createVerticalGlue()); - - final JButton saveButton = new JButton(Localization.get("save")); - saveButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - ScreenDensity.save(saveButton); - } - }); - 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))); - - 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 filename = input.getName(); - if (NameValidator.isFilenameValid(filename)) { - 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(); - } + }); + 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(ScreenDensity.shouldKeepSameDensityFile()); + keepDensity.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + ScreenDensity.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) { + ScreenDensity.save(saveButton); + } + }); + 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)); + + 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 filename = input.getName(); + if (NameValidator.isFilenameValid(filename)) { + 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); } - } - - @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(this.outputPanel, null, dropListener); - - 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); - - new FileDrop(this.textArea, null, dropListener); - - this.setMenuBar(); + } + }; + 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); + } + }; + new FileDrop(this.getContentPane(), null, dropListener); + new FileDrop(this.outputPanel, null, dropListener); + + 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); + + new FileDrop(this.textArea, null, dropListener); + + this.setMenuBar(); + } + + private void setMenuBar() { + this.menuBar = new JMenuBar(); + this.setJMenuBar(this.menuBar); + + this.mnEdit = new JMenu(Localization.get("menu_edit")); + this.menuBar.add(this.mnEdit); + + this.mntmClear = new JMenuItem(Localization.get("menu_item_clear")); + this.mntmClear.setAction(this.action); + this.mntmClear.setEnabled(false); + this.mnEdit.add(this.mntmClear); + + this.mnHelp = new JMenu(Localization.get("menu_help")); + this.menuBar.add(this.mnHelp); + + this.mntmAbout = new JMenuItem(); + this.mntmAbout.setAction(new AboutAction()); + this.mnHelp.add(this.mntmAbout); + } + + private class AboutAction extends AbstractAction { + + public AboutAction() { + this.putValue(NAME, Localization.get("menu_item_about")); } - private void setMenuBar() { - this.menuBar = new JMenuBar(); - this.setJMenuBar(this.menuBar); - - this.mnEdit = new JMenu(Localization.get("menu_edit")); - this.menuBar.add(this.mnEdit); - - this.mntmClear = new JMenuItem(Localization.get("menu_item_clear")); - this.mntmClear.setAction(this.action); - this.mntmClear.setEnabled(false); - this.mnEdit.add(this.mntmClear); - - this.mnHelp = new JMenu(Localization.get("menu_help")); - this.menuBar.add(this.mnHelp); - - 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/ScreenDensity.java b/src/net/redwarp/tool/resizer/worker/ScreenDensity.java index dcb4fbf..bfd5a71 100644 --- a/src/net/redwarp/tool/resizer/worker/ScreenDensity.java +++ b/src/net/redwarp/tool/resizer/worker/ScreenDensity.java @@ -111,6 +111,7 @@ public static void save(JButton saveButton) { }.getType(); JsonElement densities = gson.toJsonTree(list, listOfDensityType); rootObject.add(KEY_DENSITIES, densities); + rootObject.addProperty(KEY_KEEP_SAME_DENSITY_FILE, keepSameDensityFile); SaveWorker worker = new SaveWorker(saveButton, rootObject.toString()); worker.execute(); @@ -148,6 +149,10 @@ public static boolean shouldKeepSameDensityFile() { return keepSameDensityFile; } + public static void setShouldKeepSameDensityFile(boolean shouldKeepSameDensityFile) { + keepSameDensityFile = shouldKeepSameDensityFile; + } + public static void setDefaultInputDensity(ScreenDensity density) { defaultInputDensity = density; } From 8aed890b88512ac5ee6be5d861de25a6fbbe3a15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Vermont?= Date: Thu, 12 Feb 2015 18:54:54 +0100 Subject: [PATCH 13/35] Better jpg quality --- src/net/redwarp/tool/resizer/worker/ImageWriter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/net/redwarp/tool/resizer/worker/ImageWriter.java b/src/net/redwarp/tool/resizer/worker/ImageWriter.java index 49d34eb..790194d 100644 --- a/src/net/redwarp/tool/resizer/worker/ImageWriter.java +++ b/src/net/redwarp/tool/resizer/worker/ImageWriter.java @@ -52,7 +52,7 @@ public static void write(BufferedImage outputImage, Output output, File outputFi javax.imageio.ImageWriter writer = itor.next(); ImageWriteParam imageWriteParam = writer.getDefaultWriteParam(); imageWriteParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); - imageWriteParam.setCompressionQuality(0.8f); + imageWriteParam.setCompressionQuality(0.9f); FileImageOutputStream outputStream = new FileImageOutputStream(outputFile); writer.setOutput(outputStream); From a16a3c224d34e792aa9241393eee369b014fc906 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Vermont?= Date: Thu, 12 Feb 2015 18:55:16 +0100 Subject: [PATCH 14/35] Fix main window to display proper tooltip while resizing stuff --- src/net/redwarp/tool/resizer/views/MainWindow.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/net/redwarp/tool/resizer/views/MainWindow.java b/src/net/redwarp/tool/resizer/views/MainWindow.java index 579eac5..f6df140 100644 --- a/src/net/redwarp/tool/resizer/views/MainWindow.java +++ b/src/net/redwarp/tool/resizer/views/MainWindow.java @@ -117,7 +117,7 @@ public void actionPerformed(ActionEvent arg0) { JLabel inputLabel = new JLabel(Localization.get("input_density")); inputLabel.setAlignmentX(Component.LEFT_ALIGNMENT); optionPanel.add(inputLabel); - JComboBox + final JComboBox inputDensityChoice = new JComboBox( new Vector(ScreenDensity.getSupportedScreenDensity())); @@ -214,6 +214,10 @@ public void filesDropped(Container source, File[] files) { 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); @@ -251,7 +255,7 @@ public void dragExit(Container source) { new FileDrop(this.getContentPane(), null, dropListener); new FileDrop(this.outputPanel, null, dropListener); - this.instructionLabel = new JLabel(Localization.get("xhdpi")); + this.instructionLabel = new JLabel(""); this.instructionLabel.setIcon(this.blueArrowSmall); this.instructionLabel.setBorder(new EmptyBorder(4, 4, 4, 4)); this.outputPanel.add(this.instructionLabel, BorderLayout.SOUTH); From e051dddea7e9f5c4959bd51c5320eba982d55127 Mon Sep 17 00:00:00 2001 From: redwarp Date: Fri, 13 Feb 2015 11:28:06 +0100 Subject: [PATCH 15/35] Replace accent by utf-8 representation in french locale --- res/locale/Strings_fr.properties | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/res/locale/Strings_fr.properties b/res/locale/Strings_fr.properties index cf090d1..753f309 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.\nIl génère automatiquement plusieurs dossiers de densité \: 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 2014-2015. 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 2014-2015. Tous droits r\u00E9serv\u00E9s. app_name=9Patch Resizer column_name=Nom de l'image column_status=Status @@ -12,13 +12,13 @@ menu_item_about=\u00C0 propos de Resizer menu_item_clear=Effacer menu_item_clear_desc=Efface l'historique de conversion status_error=Erreur -status_finished=Terminé \! +status_finished=Termin\u00E9 \! status_in_progress=En cours... status_pending=En attente... 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églages courants pour les réutiliser la prochaine fois que vous lancerez 9Patch Resizer -keep_same_density_file=Garder le fichier
original pour la même densité -keep_same_density_file_tooltip=Pour les formats, tel le jpg, où la compression dégrade l'image, cochez cette option s'assurera que le fichier original est copié dans le fichier de destination source, pour la même densité. +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. From 344ff28ebf260a6a7f6aaa0471312dba89d581c5 Mon Sep 17 00:00:00 2001 From: redwarp Date: Fri, 13 Feb 2015 11:35:18 +0100 Subject: [PATCH 16/35] Refactor (pref -> config) --- build.xml | 2 +- res/locale/Strings.properties | 2 +- res/locale/Strings_fr.properties | 2 +- res/misc/{preferences.properties => configuration.properties} | 0 .../resizer/misc/{Preferences.java => Configuration.java} | 4 ++-- src/net/redwarp/tool/resizer/views/AboutDialog.java | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) rename res/misc/{preferences.properties => configuration.properties} (100%) rename src/net/redwarp/tool/resizer/misc/{Preferences.java => Configuration.java} (91%) diff --git a/build.xml b/build.xml index e8f43ad..4e53ba3 100644 --- a/build.xml +++ b/build.xml @@ -5,7 +5,7 @@ - + diff --git a/res/locale/Strings.properties b/res/locale/Strings.properties index fac4ed7..a2520af 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.\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 2014-2015. 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 diff --git a/res/locale/Strings_fr.properties b/res/locale/Strings_fr.properties index 753f309..4b2ea0b 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.\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 2014-2015. 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 diff --git a/res/misc/preferences.properties b/res/misc/configuration.properties similarity index 100% rename from res/misc/preferences.properties rename to res/misc/configuration.properties diff --git a/src/net/redwarp/tool/resizer/misc/Preferences.java b/src/net/redwarp/tool/resizer/misc/Configuration.java similarity index 91% rename from src/net/redwarp/tool/resizer/misc/Preferences.java rename to src/net/redwarp/tool/resizer/misc/Configuration.java index 269e035..c31045e 100644 --- a/src/net/redwarp/tool/resizer/misc/Preferences.java +++ b/src/net/redwarp/tool/resizer/misc/Configuration.java @@ -18,9 +18,9 @@ import java.util.Locale; import java.util.ResourceBundle; -public class Preferences { +public class Configuration { private static ResourceBundle bundle = ResourceBundle.getBundle( - "misc.preferences", Locale.FRANCE); + "misc.configuration", Locale.FRANCE); public static String getVersion() { return bundle.getString("version"); diff --git a/src/net/redwarp/tool/resizer/views/AboutDialog.java b/src/net/redwarp/tool/resizer/views/AboutDialog.java index 64d939d..8a93f9d 100644 --- a/src/net/redwarp/tool/resizer/views/AboutDialog.java +++ b/src/net/redwarp/tool/resizer/views/AboutDialog.java @@ -16,7 +16,7 @@ package net.redwarp.tool.resizer.views; import net.redwarp.tool.resizer.misc.Localization; -import net.redwarp.tool.resizer.misc.Preferences; +import net.redwarp.tool.resizer.misc.Configuration; import javax.swing.*; import javax.swing.border.EmptyBorder; @@ -31,7 +31,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); From 764c0183728f0a3c0db4ffa30b35ea5d38e8673e Mon Sep 17 00:00:00 2001 From: redwarp Date: Mon, 16 Feb 2015 15:07:41 +0100 Subject: [PATCH 17/35] Cleanup --- densities.json | 1 - 1 file changed, 1 deletion(-) delete mode 100644 densities.json diff --git a/densities.json b/densities.json deleted file mode 100644 index 491aa2b..0000000 --- a/densities.json +++ /dev/null @@ -1 +0,0 @@ -{"source":"xxhdpi","densities":[{"scale":4.0,"name":"xxxhdpi","active":false},{"scale":3.0,"name":"xxhdpi","active":true},{"scale":2.0,"name":"xhdpi","active":true},{"scale":1.5,"name":"hdpi","active":true},{"scale":1.33,"name":"tvdpi","active":false},{"scale":1.0,"name":"mdpi","active":true},{"scale":0.75,"name":"ldpi","active":false}],"keep_same_density_file":false} \ No newline at end of file From 226ced52d525364d9d1eb304d9de2e46227777a0 Mon Sep 17 00:00:00 2001 From: redwarp Date: Mon, 16 Feb 2015 15:08:00 +0100 Subject: [PATCH 18/35] Add versionCode, pretty serialize for saved file --- res/misc/configuration.properties | 3 ++- .../redwarp/tool/resizer/misc/Configuration.java | 15 ++++++++++----- .../tool/resizer/worker/ScreenDensity.java | 9 +++++++-- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/res/misc/configuration.properties b/res/misc/configuration.properties index e7528bd..de1a127 100644 --- a/res/misc/configuration.properties +++ b/res/misc/configuration.properties @@ -1,3 +1,4 @@ #Created by JInto - www.guh-software.de #Sun Oct 21 22:30:52 CEST 2012 -version=1.3.3 \ No newline at end of file +version=1.3.3 +versionCode=1 \ No newline at end of file diff --git a/src/net/redwarp/tool/resizer/misc/Configuration.java b/src/net/redwarp/tool/resizer/misc/Configuration.java index c31045e..b6631ad 100644 --- a/src/net/redwarp/tool/resizer/misc/Configuration.java +++ b/src/net/redwarp/tool/resizer/misc/Configuration.java @@ -19,10 +19,15 @@ import java.util.ResourceBundle; public class Configuration { - private static ResourceBundle bundle = ResourceBundle.getBundle( - "misc.configuration", Locale.FRANCE); - public static String getVersion() { - return bundle.getString("version"); - } + private static ResourceBundle bundle = ResourceBundle.getBundle( + "misc.configuration", Locale.FRANCE); + + public static String getVersion() { + return bundle.getString("version"); + } + + public static int getVersionCode() { + return Integer.valueOf(bundle.getString("versionCode")); + } } diff --git a/src/net/redwarp/tool/resizer/worker/ScreenDensity.java b/src/net/redwarp/tool/resizer/worker/ScreenDensity.java index bfd5a71..dd51493 100644 --- a/src/net/redwarp/tool/resizer/worker/ScreenDensity.java +++ b/src/net/redwarp/tool/resizer/worker/ScreenDensity.java @@ -16,12 +16,15 @@ package net.redwarp.tool.resizer.worker; 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.misc.Configuration; + import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -106,14 +109,16 @@ public static void save(JButton saveButton) { rootObject.addProperty(KEY_SOURCE, defaultInputDensity.getName()); // Save densities - Gson gson = new Gson(); + 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("versionCode", Configuration.getVersionCode()); - SaveWorker worker = new SaveWorker(saveButton, rootObject.toString()); + SaveWorker worker = new SaveWorker(saveButton, gson.toJson(rootObject)); worker.execute(); } From cdc0f3870b11fb9e51520d3207f4e5894b668491 Mon Sep 17 00:00:00 2001 From: redwarp Date: Wed, 18 Feb 2015 12:34:20 +0100 Subject: [PATCH 19/35] A shit load of refactoring, so that Settings and ScreenDensity are two separate entities. --- .gitignore | 3 +- .../redwarp/tool/resizer/FileProcessor.java | 3 +- src/net/redwarp/tool/resizer/Main.java | 112 +++++------ .../tool/resizer/misc/Configuration.java | 8 + .../redwarp/tool/resizer/misc/Settings.java | 179 ++++++++++++++++++ .../tool/resizer/views/MainWindow.java | 28 ++- .../tool/resizer/worker/ImageScaler.java | 5 +- .../tool/resizer/worker/ScreenDensity.java | 157 +-------------- 8 files changed, 272 insertions(+), 223 deletions(-) create mode 100644 src/net/redwarp/tool/resizer/misc/Settings.java diff --git a/.gitignore b/.gitignore index cc0e826..602223c 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,5 @@ /antbin /launch4j.log target -.idea/ \ No newline at end of file +.idea/ +densities.json diff --git a/src/net/redwarp/tool/resizer/FileProcessor.java b/src/net/redwarp/tool/resizer/FileProcessor.java index a31d43a..8724024 100644 --- a/src/net/redwarp/tool/resizer/FileProcessor.java +++ b/src/net/redwarp/tool/resizer/FileProcessor.java @@ -15,6 +15,7 @@ */ 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; @@ -42,7 +43,7 @@ public FileProcessor(String name, FileProcessorStatusListener l) { Operation operation = new Operation(new File(name)); scaler = new ImageScaler(operation, - ScreenDensity.getDefaultInputDensity()) { + Configuration.getSettings().getDefaultInputDensity()) { @Override protected void process(java.util.List chunks) { for (Operation operation : chunks) { diff --git a/src/net/redwarp/tool/resizer/Main.java b/src/net/redwarp/tool/resizer/Main.java index 4d814cd..0ae05d4 100644 --- a/src/net/redwarp/tool/resizer/Main.java +++ b/src/net/redwarp/tool/resizer/Main.java @@ -16,72 +16,78 @@ 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 javax.swing.*; import java.util.ArrayList; +import javax.swing.*; + public class Main { - static class StatusListener implements FileProcessorStatusListener { - int count = 0; - int current = 0; - int failureCount = 0; - public StatusListener(int count) { - this.count = count; - } + static class StatusListener implements FileProcessorStatusListener { + + int count = 0; + int current = 0; + int failureCount = 0; - @Override - public void onSuccess() { - this.current++; - if (this.current == this.count) { - System.exit(failureCount); - } - } + 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); - } - } + @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"); - 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")); - if (args.length > 0) { - StatusListener l = new StatusListener(args.length); - ArrayList processors = new ArrayList(); + 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 { + 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(); - } + 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); - } + new MainWindow().setVisible(true); } + } } diff --git a/src/net/redwarp/tool/resizer/misc/Configuration.java b/src/net/redwarp/tool/resizer/misc/Configuration.java index b6631ad..4507ddc 100644 --- a/src/net/redwarp/tool/resizer/misc/Configuration.java +++ b/src/net/redwarp/tool/resizer/misc/Configuration.java @@ -22,6 +22,7 @@ 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("version"); @@ -30,4 +31,11 @@ public static String getVersion() { 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/Settings.java b/src/net/redwarp/tool/resizer/misc/Settings.java new file mode 100644 index 0000000..a863c9c --- /dev/null +++ b/src/net/redwarp/tool/resizer/misc/Settings.java @@ -0,0 +1,179 @@ +/* + * 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 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.*; + +/** + * User: benoit.vermont@airtag.com Date: 16/02/15 Time: 16:09 + */ +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("versionCode", 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/views/MainWindow.java b/src/net/redwarp/tool/resizer/views/MainWindow.java index f6df140..9632a53 100644 --- a/src/net/redwarp/tool/resizer/views/MainWindow.java +++ b/src/net/redwarp/tool/resizer/views/MainWindow.java @@ -17,6 +17,7 @@ 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; @@ -92,7 +93,7 @@ public MainWindow() { this.xhdpiButton = new JButton(String.format(Locale.getDefault(), Localization.get("xhdpi"), - ScreenDensity.getDefaultInputDensity().getName())); + Configuration.getSettings().getDefaultInputDensity().getName())); this.xhdpiButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { @@ -120,14 +121,14 @@ public void actionPerformed(ActionEvent arg0) { final JComboBox inputDensityChoice = new JComboBox( - new Vector(ScreenDensity.getSupportedScreenDensity())); - inputDensityChoice.setSelectedItem(ScreenDensity.getDefaultInputDensity()); + 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(); - ScreenDensity.setDefaultInputDensity(selectedDensity); + Configuration.getSettings().setDefaultInputDensity(selectedDensity); xhdpiButton.setText(String.format(Locale.getDefault(), Localization.get("xhdpi"), selectedDensity.getName())); } @@ -141,7 +142,7 @@ public void actionPerformed(ActionEvent actionEvent) { JLabel outputLabel = new JLabel(Localization.get("output_density")); optionPanel.add(outputLabel); - for (final ScreenDensity density : ScreenDensity.getSupportedScreenDensity()) { + for (final ScreenDensity density : Configuration.getSettings().getSupportedScreenDensity()) { final JCheckBox box = new JCheckBox(density.getName()); box.addActionListener(new ActionListener() { @Override @@ -157,11 +158,11 @@ public void actionPerformed(ActionEvent actionEvent) { final JCheckBox keepDensity = new JCheckBox(Localization.get("keep_same_density_file")); keepDensity.setToolTipText(Localization.get("keep_same_density_file_tooltip")); - keepDensity.setSelected(ScreenDensity.shouldKeepSameDensityFile()); + keepDensity.setSelected(Configuration.getSettings().shouldKeepSameDensityFile()); keepDensity.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - ScreenDensity.setShouldKeepSameDensityFile(keepDensity.isSelected()); + Configuration.getSettings().setShouldKeepSameDensityFile(keepDensity.isSelected()); } }); @@ -172,7 +173,13 @@ public void actionPerformed(ActionEvent e) { saveButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - ScreenDensity.save(saveButton); + saveButton.setEnabled(false); + Configuration.getSettings().save(new Runnable() { + @Override + public void run() { + saveButton.setEnabled(true); + } + }); } }); saveButton.setToolTipText(Localization.get("save_tooltip")); @@ -217,13 +224,14 @@ public void filesDropped(Container source, File[] files) { ScreenDensity selectedDensity = (ScreenDensity) inputDensityChoice.getSelectedItem(); instructionLabel.setText(String.format(Locale.getDefault(), Localization.get("xhdpi"), - selectedDensity.getName())); + selectedDensity.getName())); layout.show(MainWindow.this.getContentPane(), "output"); Operation operation = new Operation(input); MainWindow.this.resultTable.addOperation(operation); ImageScaler scaler = new ImageScaler(operation, - ScreenDensity.getDefaultInputDensity()) { + Configuration.getSettings() + .getDefaultInputDensity()) { @Override protected void process( java.util.List chunks) { diff --git a/src/net/redwarp/tool/resizer/worker/ImageScaler.java b/src/net/redwarp/tool/resizer/worker/ImageScaler.java index 8ba4b73..936bd0f 100644 --- a/src/net/redwarp/tool/resizer/worker/ImageScaler.java +++ b/src/net/redwarp/tool/resizer/worker/ImageScaler.java @@ -15,6 +15,7 @@ */ 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; @@ -79,7 +80,7 @@ protected Void doInBackground() throws Exception { this.operation.setStatus(OperationStatus.IN_PROGRESS); this.publish(this.operation); - List densityList = ScreenDensity + List densityList = Configuration.getSettings() .getSupportedScreenDensity(); File parent = this.inputFile.getParentFile(); @@ -167,7 +168,7 @@ protected Void doInBackground() throws Exception { synchronized (fileLock) { // Let's do the worst hack in the universe to speed things up ! - if (ScreenDensity.shouldKeepSameDensityFile() && output == Output.JPG + if (Configuration.getSettings().shouldKeepSameDensityFile() && output == Output.JPG && outputImage.getWidth() == inputImage.getWidth() && outputImage.getHeight() == inputImage.getHeight()) { ImageWriter.copy(inputFile, outputFile); diff --git a/src/net/redwarp/tool/resizer/worker/ScreenDensity.java b/src/net/redwarp/tool/resizer/worker/ScreenDensity.java index dd51493..19bb699 100644 --- a/src/net/redwarp/tool/resizer/worker/ScreenDensity.java +++ b/src/net/redwarp/tool/resizer/worker/ScreenDensity.java @@ -15,114 +15,14 @@ */ package net.redwarp.tool.resizer.worker; -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.misc.Configuration; - -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 ScreenDensity { - 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"; - public static final String DENSITIES_PATHNAME = "./densities.json"; private float scale; private String name; private boolean active; - private static List list = null; - private static ScreenDensity defaultInputDensity = null; - private static boolean keepSameDensityFile = false; - - static { - load(); - } - - private static void load() { - try { - Gson gson = new Gson(); - JsonParser parser = new JsonParser(); - InputStream preferenceStream; - try { - preferenceStream = new FileInputStream(new File(DENSITIES_PATHNAME)); - } catch (Exception e) { - preferenceStream = - ScreenDensity.class.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); - } - } - - public static void save(JButton saveButton) { - 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("versionCode", Configuration.getVersionCode()); - - SaveWorker worker = new SaveWorker(saveButton, gson.toJson(rootObject)); - worker.execute(); - } - - private ScreenDensity(String name, float density, boolean active) { + public ScreenDensity(String name, float density, boolean active) { this.scale = density; this.name = name; this.active = active; @@ -141,26 +41,6 @@ public float getScale() { return this.scale; } - public static List getSupportedScreenDensity() { - return list; - } - - public static ScreenDensity getDefaultInputDensity() { - return defaultInputDensity; - } - - // A flag to indicate if we should copy the original image, if the input and output are of the same density. - public static boolean shouldKeepSameDensityFile() { - return keepSameDensityFile; - } - - public static void setShouldKeepSameDensityFile(boolean shouldKeepSameDensityFile) { - keepSameDensityFile = shouldKeepSameDensityFile; - } - - public static void setDefaultInputDensity(ScreenDensity density) { - defaultInputDensity = density; - } @Override public boolean equals(Object obj) { @@ -178,39 +58,4 @@ public void setActive(boolean active) { this.active = active; } - public static class SaveWorker extends SwingWorker { - - private final String mSavePayload; - private final JButton mButton; - - public SaveWorker(JButton saveButton, String savePayload) { - mButton = saveButton; - 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 (mButton != null) { - mButton.setEnabled(true); - } - } - } } From 4c2c096fb6eff757fd9ae83bc15c22eb78f85952 Mon Sep 17 00:00:00 2001 From: redwarp Date: Wed, 18 Feb 2015 15:22:37 +0100 Subject: [PATCH 20/35] rename version to versionName --- build.xml | 4 ++-- res/misc/configuration.properties | 2 +- src/net/redwarp/tool/resizer/misc/Configuration.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build.xml b/build.xml index 4e53ba3..e7e06ce 100644 --- a/build.xml +++ b/build.xml @@ -69,7 +69,7 @@ - + @@ -82,6 +82,6 @@ - + diff --git a/res/misc/configuration.properties b/res/misc/configuration.properties index de1a127..263bcca 100644 --- a/res/misc/configuration.properties +++ b/res/misc/configuration.properties @@ -1,4 +1,4 @@ #Created by JInto - www.guh-software.de #Sun Oct 21 22:30:52 CEST 2012 -version=1.3.3 +versionName=1.3.3 versionCode=1 \ No newline at end of file diff --git a/src/net/redwarp/tool/resizer/misc/Configuration.java b/src/net/redwarp/tool/resizer/misc/Configuration.java index 4507ddc..400f199 100644 --- a/src/net/redwarp/tool/resizer/misc/Configuration.java +++ b/src/net/redwarp/tool/resizer/misc/Configuration.java @@ -25,7 +25,7 @@ public class Configuration { private static Settings settings = null; public static String getVersion() { - return bundle.getString("version"); + return bundle.getString("versionName"); } public static int getVersionCode() { From 2006ce91d41bc1640a15b6c75d757bfab1c523d2 Mon Sep 17 00:00:00 2001 From: redwarp Date: Wed, 18 Feb 2015 15:23:12 +0100 Subject: [PATCH 21/35] Create maven pom --- .classpath | 4 +- .idea/compiler.xml | 13 +++++- Resizer.eml | 13 ++++-- Resizer.iml | 3 +- pom.xml | 111 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 134 insertions(+), 10 deletions(-) create mode 100644 pom.xml diff --git a/.classpath b/.classpath index 595b356..c80e233 100644 --- a/.classpath +++ b/.classpath @@ -3,6 +3,6 @@ - - + + diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 217af47..57d709b 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -17,7 +17,16 @@ + + + + + + + + + + - - + \ No newline at end of file diff --git a/Resizer.eml b/Resizer.eml index 6f97233..a9b5d7b 100644 --- a/Resizer.eml +++ b/Resizer.eml @@ -1,8 +1,13 @@ - - - + + + + + + + + - + diff --git a/Resizer.iml b/Resizer.iml index 46adf0f..240f3e9 100644 --- a/Resizer.iml +++ b/Resizer.iml @@ -1,3 +1,2 @@ - - + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..74980af --- /dev/null +++ b/pom.xml @@ -0,0 +1,111 @@ + + + + 4.0.0 + net.redwarp.tool + resizer + + + ${versionName} + 9Patch Resizer + + + + com.google.code.gson + gson + 2.2.4 + compile + + + + + + src + + + res + + + + + + org.codehaus.mojo + properties-maven-plugin + 1.0-alpha-2 + + + initialize + + read-project-properties + + + + res/misc/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 + + + + + + org.apache.maven.plugins + maven-assembly-plugin + 2.2-beta-5 + + + create-the-jar + package + + single + + + + jar-with-dependencies + + + + net.redwarp.tool.resizer.Main + + + + + + + + + + \ No newline at end of file From 2fe61c1d09f3505c6d9f779233a3be9312afd24c Mon Sep 17 00:00:00 2001 From: redwarp Date: Wed, 18 Feb 2015 16:08:40 +0100 Subject: [PATCH 22/35] Make proguard work --- pom.xml | 27 +++++++++++++++++++++++++++ proguard.txt | 3 --- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 74980af..881eb2e 100644 --- a/pom.xml +++ b/pom.xml @@ -105,6 +105,33 @@ + + com.github.wvengen + proguard-maven-plugin + 2.0.8 + + + package + + proguard + + + + + ${project.build.finalName}-jar-with-dependencies.jar + ${project.build.finalName}-proguard.jar + proguard.txt + + + com.google.code.gson + gson + + + + ${java.home}/lib/rt.jar + + + 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 From af06d994a35e4e4181f3f65e5bcdde507c2f1846 Mon Sep 17 00:00:00 2001 From: redwarp Date: Wed, 18 Feb 2015 17:23:08 +0100 Subject: [PATCH 23/35] Cleanup --- .../redwarp/tool/resizer/FileProcessor.java | 80 +++++++++---------- .../redwarp/tool/resizer/misc/Settings.java | 3 - .../tool/resizer/worker/ImageWriter.java | 3 - .../redwarp/tool/resizer/worker/Output.java | 5 -- .../resizer/worker/Wrong9PatchException.java | 1 - 5 files changed, 40 insertions(+), 52 deletions(-) diff --git a/src/net/redwarp/tool/resizer/FileProcessor.java b/src/net/redwarp/tool/resizer/FileProcessor.java index 8724024..f7d1c1c 100644 --- a/src/net/redwarp/tool/resizer/FileProcessor.java +++ b/src/net/redwarp/tool/resizer/FileProcessor.java @@ -20,58 +20,58 @@ import net.redwarp.tool.resizer.table.Operation; import net.redwarp.tool.resizer.table.OperationStatus; import net.redwarp.tool.resizer.worker.ImageScaler; -import net.redwarp.tool.resizer.worker.ScreenDensity; import java.io.File; public class FileProcessor { - public interface FileProcessorStatusListener { - void onSuccess(); + public interface FileProcessorStatusListener { - void onFailure(String msg); - } + void onSuccess(); - private ImageScaler scaler; - FileProcessorStatusListener listener; - String fileName; + void onFailure(String msg); + } - public FileProcessor(String name, FileProcessorStatusListener l) { - fileName = name; - listener = l; - if (NameValidator.isFilenameValid(fileName)) { - Operation operation = new Operation(new File(name)); + private ImageScaler scaler; + FileProcessorStatusListener listener; + String fileName; - 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 FileProcessor(String name, FileProcessorStatusListener l) { + fileName = name; + listener = l; + if (NameValidator.isFilenameValid(fileName)) { + Operation operation = new Operation(new File(name)); - public void process() { - if (scaler != null) { - scaler.post(); - } else { - if (listener != null) { - listener.onFailure("processor for argument:" + fileName - + " is null"); + 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/misc/Settings.java b/src/net/redwarp/tool/resizer/misc/Settings.java index a863c9c..a5bf040 100644 --- a/src/net/redwarp/tool/resizer/misc/Settings.java +++ b/src/net/redwarp/tool/resizer/misc/Settings.java @@ -39,9 +39,6 @@ import javax.swing.*; -/** - * User: benoit.vermont@airtag.com Date: 16/02/15 Time: 16:09 - */ public class Settings { private static final String KEY_DENSITIES = "densities"; diff --git a/src/net/redwarp/tool/resizer/worker/ImageWriter.java b/src/net/redwarp/tool/resizer/worker/ImageWriter.java index 790194d..643dbb8 100644 --- a/src/net/redwarp/tool/resizer/worker/ImageWriter.java +++ b/src/net/redwarp/tool/resizer/worker/ImageWriter.java @@ -30,9 +30,6 @@ import javax.imageio.ImageWriteParam; import javax.imageio.stream.FileImageOutputStream; -/** - * User: benoit.vermont@airtag.com Date: 28/10/14 Time: 19:24 - */ public class ImageWriter { public static void write(BufferedImage outputImage, Output output, File outputFile) diff --git a/src/net/redwarp/tool/resizer/worker/Output.java b/src/net/redwarp/tool/resizer/worker/Output.java index 4f1bf0d..993e92a 100644 --- a/src/net/redwarp/tool/resizer/worker/Output.java +++ b/src/net/redwarp/tool/resizer/worker/Output.java @@ -16,11 +16,6 @@ package net.redwarp.tool.resizer.worker; -/** - * User: benoit.vermont@airtag.com - * Date: 28/10/14 - * Time: 18:55 - */ public enum Output { PNG("png"), JPG("jpg"); diff --git a/src/net/redwarp/tool/resizer/worker/Wrong9PatchException.java b/src/net/redwarp/tool/resizer/worker/Wrong9PatchException.java index 9ec7609..4f89d06 100644 --- a/src/net/redwarp/tool/resizer/worker/Wrong9PatchException.java +++ b/src/net/redwarp/tool/resizer/worker/Wrong9PatchException.java @@ -15,7 +15,6 @@ */ package net.redwarp.tool.resizer.worker; -@SuppressWarnings("serial") public class Wrong9PatchException extends Exception { } From f5067b5ef94a4e7208f2c6812114c185cf0cd7e7 Mon Sep 17 00:00:00 2001 From: redwarp Date: Wed, 18 Feb 2015 17:29:59 +0100 Subject: [PATCH 24/35] Update license (I'm not so sure if I'm supposed to do it or...) --- LICENSE | 2 +- src/net/redwarp/tool/resizer/FileTools.java | 2 +- src/net/redwarp/tool/resizer/Main.java | 2 +- src/net/redwarp/tool/resizer/misc/Configuration.java | 2 +- src/net/redwarp/tool/resizer/misc/Localization.java | 2 +- src/net/redwarp/tool/resizer/misc/NameValidator.java | 2 +- src/net/redwarp/tool/resizer/misc/Settings.java | 2 +- src/net/redwarp/tool/resizer/table/Operation.java | 2 +- src/net/redwarp/tool/resizer/table/OperationStatus.java | 2 +- src/net/redwarp/tool/resizer/table/ResultModel.java | 2 +- src/net/redwarp/tool/resizer/table/ResultTable.java | 2 +- src/net/redwarp/tool/resizer/table/StatusCellRenderer.java | 2 +- src/net/redwarp/tool/resizer/views/AboutDialog.java | 2 +- src/net/redwarp/tool/resizer/views/MainWindow.java | 2 +- src/net/redwarp/tool/resizer/worker/ImageScaler.java | 2 +- src/net/redwarp/tool/resizer/worker/ImageWriter.java | 2 +- src/net/redwarp/tool/resizer/worker/Output.java | 2 +- src/net/redwarp/tool/resizer/worker/ScreenDensity.java | 2 +- .../tool/resizer/worker/UnsupportedDensityException.java | 2 +- src/net/redwarp/tool/resizer/worker/Wrong9PatchException.java | 2 +- 20 files changed, 20 insertions(+), 20 deletions(-) diff --git a/LICENSE b/LICENSE index a91e448..b903778 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ Apache License same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2014 Redwarp + 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. diff --git a/src/net/redwarp/tool/resizer/FileTools.java b/src/net/redwarp/tool/resizer/FileTools.java index c613dfb..645bee1 100644 --- a/src/net/redwarp/tool/resizer/FileTools.java +++ b/src/net/redwarp/tool/resizer/FileTools.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; diff --git a/src/net/redwarp/tool/resizer/Main.java b/src/net/redwarp/tool/resizer/Main.java index 0ae05d4..57c272b 100644 --- a/src/net/redwarp/tool/resizer/Main.java +++ b/src/net/redwarp/tool/resizer/Main.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; diff --git a/src/net/redwarp/tool/resizer/misc/Configuration.java b/src/net/redwarp/tool/resizer/misc/Configuration.java index 400f199..381f955 100644 --- a/src/net/redwarp/tool/resizer/misc/Configuration.java +++ b/src/net/redwarp/tool/resizer/misc/Configuration.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; diff --git a/src/net/redwarp/tool/resizer/misc/Localization.java b/src/net/redwarp/tool/resizer/misc/Localization.java index 319996a..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; diff --git a/src/net/redwarp/tool/resizer/misc/NameValidator.java b/src/net/redwarp/tool/resizer/misc/NameValidator.java index beec16d..432bdaa 100644 --- a/src/net/redwarp/tool/resizer/misc/NameValidator.java +++ b/src/net/redwarp/tool/resizer/misc/NameValidator.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; diff --git a/src/net/redwarp/tool/resizer/misc/Settings.java b/src/net/redwarp/tool/resizer/misc/Settings.java index a5bf040..40cabb8 100644 --- a/src/net/redwarp/tool/resizer/misc/Settings.java +++ b/src/net/redwarp/tool/resizer/misc/Settings.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; 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..83d7938 100644 --- a/src/net/redwarp/tool/resizer/table/ResultModel.java +++ b/src/net/redwarp/tool/resizer/table/ResultModel.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/ResultTable.java b/src/net/redwarp/tool/resizer/table/ResultTable.java index 89a742a..5515ba1 100644 --- a/src/net/redwarp/tool/resizer/table/ResultTable.java +++ b/src/net/redwarp/tool/resizer/table/ResultTable.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/StatusCellRenderer.java b/src/net/redwarp/tool/resizer/table/StatusCellRenderer.java index 46c88d7..69a65ec 100644 --- a/src/net/redwarp/tool/resizer/table/StatusCellRenderer.java +++ b/src/net/redwarp/tool/resizer/table/StatusCellRenderer.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/views/AboutDialog.java b/src/net/redwarp/tool/resizer/views/AboutDialog.java index 8a93f9d..17263f6 100644 --- a/src/net/redwarp/tool/resizer/views/AboutDialog.java +++ b/src/net/redwarp/tool/resizer/views/AboutDialog.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.views; diff --git a/src/net/redwarp/tool/resizer/views/MainWindow.java b/src/net/redwarp/tool/resizer/views/MainWindow.java index 9632a53..3c5b128 100644 --- a/src/net/redwarp/tool/resizer/views/MainWindow.java +++ b/src/net/redwarp/tool/resizer/views/MainWindow.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.views; diff --git a/src/net/redwarp/tool/resizer/worker/ImageScaler.java b/src/net/redwarp/tool/resizer/worker/ImageScaler.java index 936bd0f..33b9f56 100644 --- a/src/net/redwarp/tool/resizer/worker/ImageScaler.java +++ b/src/net/redwarp/tool/resizer/worker/ImageScaler.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/ImageWriter.java b/src/net/redwarp/tool/resizer/worker/ImageWriter.java index 643dbb8..c74f9dd 100644 --- a/src/net/redwarp/tool/resizer/worker/ImageWriter.java +++ b/src/net/redwarp/tool/resizer/worker/ImageWriter.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/Output.java b/src/net/redwarp/tool/resizer/worker/Output.java index 993e92a..9d61ffa 100644 --- a/src/net/redwarp/tool/resizer/worker/Output.java +++ b/src/net/redwarp/tool/resizer/worker/Output.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/ScreenDensity.java b/src/net/redwarp/tool/resizer/worker/ScreenDensity.java index 19bb699..b0c10dd 100644 --- a/src/net/redwarp/tool/resizer/worker/ScreenDensity.java +++ b/src/net/redwarp/tool/resizer/worker/ScreenDensity.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/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 4f89d06..d1ace32 100644 --- a/src/net/redwarp/tool/resizer/worker/Wrong9PatchException.java +++ b/src/net/redwarp/tool/resizer/worker/Wrong9PatchException.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; From 55747831d84c91fc465b74732f1e0823af68f2ee Mon Sep 17 00:00:00 2001 From: redwarp Date: Wed, 18 Feb 2015 17:31:07 +0100 Subject: [PATCH 25/35] Organize import (i let intellij do the work) --- src/net/iharder/dnd/FileDrop.java | 6 +++++- src/net/redwarp/tool/resizer/FileTools.java | 8 +++++++- src/net/redwarp/tool/resizer/table/ResultModel.java | 3 ++- src/net/redwarp/tool/resizer/table/ResultTable.java | 3 ++- .../redwarp/tool/resizer/table/StatusCellRenderer.java | 3 ++- src/net/redwarp/tool/resizer/views/AboutDialog.java | 5 +++-- 6 files changed, 21 insertions(+), 7 deletions(-) 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/FileTools.java b/src/net/redwarp/tool/resizer/FileTools.java index 645bee1..1590f71 100644 --- a/src/net/redwarp/tool/resizer/FileTools.java +++ b/src/net/redwarp/tool/resizer/FileTools.java @@ -15,7 +15,13 @@ */ 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/table/ResultModel.java b/src/net/redwarp/tool/resizer/table/ResultModel.java index 83d7938..d124a52 100644 --- a/src/net/redwarp/tool/resizer/table/ResultModel.java +++ b/src/net/redwarp/tool/resizer/table/ResultModel.java @@ -17,11 +17,12 @@ 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 5515ba1..1318642 100644 --- a/src/net/redwarp/tool/resizer/table/ResultTable.java +++ b/src/net/redwarp/tool/resizer/table/ResultTable.java @@ -15,9 +15,10 @@ */ 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 69a65ec..b24831a 100644 --- a/src/net/redwarp/tool/resizer/table/StatusCellRenderer.java +++ b/src/net/redwarp/tool/resizer/table/StatusCellRenderer.java @@ -17,9 +17,10 @@ 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 17263f6..166987e 100644 --- a/src/net/redwarp/tool/resizer/views/AboutDialog.java +++ b/src/net/redwarp/tool/resizer/views/AboutDialog.java @@ -15,12 +15,13 @@ */ package net.redwarp.tool.resizer.views; -import net.redwarp.tool.resizer.misc.Localization; import net.redwarp.tool.resizer.misc.Configuration; +import net.redwarp.tool.resizer.misc.Localization; + +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; From 62e1f04d0eebf027a974d1e64994cf41641eb496 Mon Sep 17 00:00:00 2001 From: redwarp Date: Wed, 18 Feb 2015 20:01:55 +0100 Subject: [PATCH 26/35] Launch4j while I'm at it ! --- pom.xml | 76 +++++++++++++++++++++++-------- res/misc/configuration.properties | 4 +- 2 files changed, 59 insertions(+), 21 deletions(-) diff --git a/pom.xml b/pom.xml index 881eb2e..db99177 100644 --- a/pom.xml +++ b/pom.xml @@ -20,9 +20,14 @@ resizer - ${versionName} + 1.3.3 9Patch Resizer + + ${project.version} + 1 + + com.google.code.gson @@ -38,28 +43,22 @@ res + true + + **/configuration.properties + + + + + res + false + + **/configuration.properties + - - org.codehaus.mojo - properties-maven-plugin - 1.0-alpha-2 - - - initialize - - read-project-properties - - - - res/misc/configuration.properties - - - - - org.apache.maven.plugins maven-compiler-plugin @@ -132,6 +131,45 @@ + + 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 + + extra/icon_512.ico + + ${project.version}.0 + ${project.version} + 9Patch Resizer + Redwarp 2013-2015 + ${project.version}.0 + ${project.version} + 9Patch Resizer + Resizer + Resizer.exe + + + + + diff --git a/res/misc/configuration.properties b/res/misc/configuration.properties index 263bcca..15b323e 100644 --- a/res/misc/configuration.properties +++ b/res/misc/configuration.properties @@ -1,4 +1,4 @@ #Created by JInto - www.guh-software.de #Sun Oct 21 22:30:52 CEST 2012 -versionName=1.3.3 -versionCode=1 \ No newline at end of file +versionName=${resizer.versionName} +versionCode=${resizer.versionCode} \ No newline at end of file From c0dfa8cd06151d031050d0db31a0e7017e756408 Mon Sep 17 00:00:00 2001 From: redwarp Date: Thu, 19 Feb 2015 14:52:49 +0100 Subject: [PATCH 27/35] Hook for travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) create mode 100644 .travis.yml 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 From 71abd6eb467b367a235eced2120a1f3e55add1b7 Mon Sep 17 00:00:00 2001 From: redwarp Date: Thu, 19 Feb 2015 15:05:01 +0100 Subject: [PATCH 28/35] Make launch4j an optional profile (don't wan't to fight with travis) --- pom.xml | 89 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 49 insertions(+), 40 deletions(-) diff --git a/pom.xml b/pom.xml index db99177..8ee13dc 100644 --- a/pom.xml +++ b/pom.xml @@ -131,46 +131,55 @@ - - 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 - - extra/icon_512.ico - - ${project.version}.0 - ${project.version} - 9Patch Resizer - Redwarp 2013-2015 - ${project.version}.0 - ${project.version} - 9Patch Resizer - Resizer - Resizer.exe - - - - - - + + + + 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 + + extra/icon_512.ico + + ${project.version}.0 + ${project.version} + 9Patch Resizer + Redwarp 2013-2015 + ${project.version}.0 + ${project.version} + 9Patch Resizer + Resizer + Resizer.exe + + + + + + + + + \ No newline at end of file From 037882134c74dbc3815c8d7bfbf8d8787f889f58 Mon Sep 17 00:00:00 2001 From: redwarp Date: Thu, 19 Feb 2015 15:39:52 +0100 Subject: [PATCH 29/35] Update launch4j settings --- pom.xml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pom.xml b/pom.xml index 8ee13dc..ea2f430 100644 --- a/pom.xml +++ b/pom.xml @@ -161,8 +161,16 @@ 1.6.0 + + preferJre + 64/32 extra/icon_512.ico + normal + + resizer + + ${project.version}.0 ${project.version} From 976377ad864bb5d3711afe4b217ec3279aa19e40 Mon Sep 17 00:00:00 2001 From: redwarp Date: Thu, 19 Feb 2015 15:52:38 +0100 Subject: [PATCH 30/35] Build cleanup, more complex manifest --- pom.xml | 34 +++------------------------------- 1 file changed, 3 insertions(+), 31 deletions(-) diff --git a/pom.xml b/pom.xml index ea2f430..0e803d1 100644 --- a/pom.xml +++ b/pom.xml @@ -76,34 +76,11 @@ net.redwarp.tool.resizer.Main + true - - org.apache.maven.plugins - maven-assembly-plugin - 2.2-beta-5 - - - create-the-jar - package - - single - - - - jar-with-dependencies - - - - net.redwarp.tool.resizer.Main - - - - - - com.github.wvengen proguard-maven-plugin @@ -117,15 +94,10 @@ - ${project.build.finalName}-jar-with-dependencies.jar + ${project.build.finalName}.jar ${project.build.finalName}-proguard.jar proguard.txt - - - com.google.code.gson - gson - - + true ${java.home}/lib/rt.jar From e1b495e3b3e294a20578adc6075a66e3c7b00d22 Mon Sep 17 00:00:00 2001 From: redwarp Date: Thu, 19 Feb 2015 15:54:10 +0100 Subject: [PATCH 31/35] Cleanup, build.xml is now deprecated and should not be used anymore --- build.xml => build_deprecated.xml | 0 launch4j_config.xml | 40 ------------------------------- 2 files changed, 40 deletions(-) rename build.xml => build_deprecated.xml (100%) delete mode 100644 launch4j_config.xml diff --git a/build.xml b/build_deprecated.xml similarity index 100% rename from build.xml rename to build_deprecated.xml diff --git a/launch4j_config.xml b/launch4j_config.xml deleted file mode 100644 index a3770f6..0000000 --- a/launch4j_config.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - false - gui - C:\Users\Redwarp\workspace\Resizer\Resizer_proguard.jar - C:\Users\Redwarp\workspace\Resizer\Resizer_1.3.3.exe - - - - normal - http://java.com/download - - false - - C:\Users\Redwarp\workspace\Resizer\extra\icon_512.ico - - resizer - - - - - false - 1.6.0 - - preferJre - 64/32 - - - 1.3.3.0 - 1.3.3 - 9Patch Resizer - Redwarp - 2014 - 1.3.3.0 - 1.3.3 - 9Patch Resizer - - Resizer - Resizer.exe - - \ No newline at end of file From 8d55c3d517783edf5a2b4e0d53996163d3988af5 Mon Sep 17 00:00:00 2001 From: redwarp Date: Thu, 19 Feb 2015 16:54:37 +0100 Subject: [PATCH 32/35] Update README to display Travis stuff (it's always night to see some green... I could also just display a green image somewhere, because it's soothing :-P) --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5699bab..9d985ea 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ A resizer tool to automaticaly resize png files and 9 patches in several densities (previously hosted on https://code.google.com/p/9patch-resizer/) +[![Build Status](https://travis-ci.org/redwarp/9-Patch-Resizer.svg?branch=develop)](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 @@ -33,7 +35,7 @@ You're using 9patch resizer for your apps ? Don't hesitate and leave me a messag - [ ] A few optimisations - [x] Options to set the input density (if people wan't to downsize from hdpi and not from xdpi for instance) - [ ] Proper JPG support - + ## Contributors * redwarp From 7508ab4a81cdf90dd763ede97fa45e6b43ee2d4b Mon Sep 17 00:00:00 2001 From: redwarp Date: Thu, 19 Feb 2015 17:47:13 +0100 Subject: [PATCH 33/35] Pom cleanup --- pom.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 0e803d1..b5d2756 100644 --- a/pom.xml +++ b/pom.xml @@ -38,7 +38,6 @@ - src @@ -141,7 +140,7 @@ normal resizer - + ${project.version}.0 From 0eac3c5806558e79124f3c59f0a48e94643de964 Mon Sep 17 00:00:00 2001 From: redwarp Date: Thu, 19 Feb 2015 19:29:03 +0100 Subject: [PATCH 34/35] Update version numbers in pom, and fix Settings --- pom.xml | 6 +++--- src/net/redwarp/tool/resizer/misc/Settings.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index b5d2756..3d6923e 100644 --- a/pom.xml +++ b/pom.xml @@ -20,12 +20,12 @@ resizer - 1.3.3 + 1.4.0 9Patch Resizer ${project.version} - 1 + 2 @@ -161,4 +161,4 @@ - \ No newline at end of file + diff --git a/src/net/redwarp/tool/resizer/misc/Settings.java b/src/net/redwarp/tool/resizer/misc/Settings.java index 40cabb8..8d4dec3 100644 --- a/src/net/redwarp/tool/resizer/misc/Settings.java +++ b/src/net/redwarp/tool/resizer/misc/Settings.java @@ -112,7 +112,7 @@ public void save(Runnable postAction) { JsonElement densities = gson.toJsonTree(list, listOfDensityType); rootObject.add(KEY_DENSITIES, densities); rootObject.addProperty(KEY_KEEP_SAME_DENSITY_FILE, keepSameDensityFile); - rootObject.addProperty("versionCode", Configuration.getVersionCode()); + rootObject.addProperty(KEY_VERSION_CODE, Configuration.getVersionCode()); SaveWorker worker = new SaveWorker(postAction, gson.toJson(rootObject)); worker.execute(); From fa05cb90f3c390396d968aaf84b0be04928d8cc3 Mon Sep 17 00:00:00 2001 From: redwarp Date: Thu, 19 Feb 2015 19:30:10 +0100 Subject: [PATCH 35/35] Update version in readme --- .idea/ant.xml | 7 +------ README.md | 4 ++-- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/.idea/ant.xml b/.idea/ant.xml index 313b0c0..c8f67ff 100644 --- a/.idea/ant.xml +++ b/.idea/ant.xml @@ -1,7 +1,2 @@ - - - - - - + \ No newline at end of file diff --git a/README.md b/README.md index 9d985ea..63dba53 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ 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.3.3* +Current version : *1.4.0* You're using 9patch resizer for your apps ? Don't hesitate and leave me a message! @@ -34,7 +34,7 @@ You're using 9patch resizer for your apps ? Don't hesitate and leave me a messag - [x] Command line support - [ ] A few optimisations - [x] Options to set the input density (if people wan't to downsize from hdpi and not from xdpi for instance) -- [ ] Proper JPG support +- [x] Proper JPG support ## Contributors