From 95b1ce3ec33c62efadd43c02253952325ce51dec Mon Sep 17 00:00:00 2001 From: redwarp Date: Thu, 6 Feb 2014 11:39:33 +0100 Subject: [PATCH 01/71] Create README.md --- README.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..1b93818 --- /dev/null +++ b/README.md @@ -0,0 +1,37 @@ +9-Patch-Resizer +=============== + +A resizer tool to automaticaly resize png files and 9 patches in several densities +=9Patch Resizer= + +Let's face it : juggling with densities for Android is a bit of a pain, especially when dealing with 9 patch png. + +And then comes this tool, that takes a xhdpi PNG file, or 9.png file, and generates ldpi, mdpi and hdpi png files automatically. + +As simple as drag and drop can get. + +And here is the [WhatsNew changelog] + +Current version : *1.3.1* + +You're using 9patch resizer for your apps ? Don't hesitate and leave me a message! + +=Links= + + * Images and stuff found on http://www.clker.com/ (The online royalty free public domain clip art) + * Images are downsized using an optimized incremental scaling algorithm proposed by Chris Campbell (whoever that is) - http://today.java.net/pub/a/today/2007/04/03/perils-of-image-getscaledinstance.html + +=Roadmap= + + * Command line support + * A few optimisations + * Options to set the input density (if people wan't to downsize from hdpi and not from xdpi for instance) + * Resize @2x (apple stuff) as well + +=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 ! + +I hope it'll prove as useful to you as it is useful to me. If you like it, and have too much cash in you hands, don't hesitate to donate : I could use a few beers. + + From cf0e4d978b604695bff9972353c083a3cfdf7b64 Mon Sep 17 00:00:00 2001 From: redwarp Date: Thu, 20 Mar 2014 18:59:01 +0100 Subject: [PATCH 02/71] Update README.md Basic titles and stuff, link to old project place --- README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 1b93818..43f3f5c 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,9 @@ 9-Patch-Resizer =============== -A resizer tool to automaticaly resize png files and 9 patches in several densities -=9Patch Resizer= +A resizer tool to automaticaly resize png files and 9 patches in several densities (previously hosted on https://code.google.com/p/9patch-resizer/ + +# 9Patch Resizer Let's face it : juggling with densities for Android is a bit of a pain, especially when dealing with 9 patch png. @@ -16,19 +17,19 @@ Current version : *1.3.1* You're using 9patch resizer for your apps ? Don't hesitate and leave me a message! -=Links= +# Links * Images and stuff found on http://www.clker.com/ (The online royalty free public domain clip art) * Images are downsized using an optimized incremental scaling algorithm proposed by Chris Campbell (whoever that is) - http://today.java.net/pub/a/today/2007/04/03/perils-of-image-getscaledinstance.html -=Roadmap= +# Roadmap * Command line support * A few optimisations * Options to set the input density (if people wan't to downsize from hdpi and not from xdpi for instance) * Resize @2x (apple stuff) as well -=Anyway...= +# 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 a6aa1d4060459c610dc0d3a12384c59701f248c6 Mon Sep 17 00:00:00 2001 From: redwarp Date: Thu, 20 Mar 2014 19:04:39 +0100 Subject: [PATCH 03/71] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 43f3f5c..125de70 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ 9-Patch-Resizer =============== -A resizer tool to automaticaly resize png files and 9 patches in several densities (previously hosted on https://code.google.com/p/9patch-resizer/ +A resizer tool to automaticaly resize png files and 9 patches in several densities (previously hosted on https://code.google.com/p/9patch-resizer/) # 9Patch Resizer @@ -11,7 +11,7 @@ And then comes this tool, that takes a xhdpi PNG file, or 9.png file, and genera As simple as drag and drop can get. -And here is the [WhatsNew changelog] +And here is the [changelog](https://github.com/redwarp/9-Patch-Resizer.wiki.git) Current version : *1.3.1* From ac9544ab99a9df56f86e671797eb764cca6d5790 Mon Sep 17 00:00:00 2001 From: redwarp Date: Thu, 20 Mar 2014 19:05:16 +0100 Subject: [PATCH 04/71] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 125de70..23b6aab 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ And then comes this tool, that takes a xhdpi PNG file, or 9.png file, and genera As simple as drag and drop can get. -And here is the [changelog](https://github.com/redwarp/9-Patch-Resizer.wiki.git) +And here is the [changelog](https://github.com/redwarp/9-Patch-Resizer/wiki/Changelog) Current version : *1.3.1* From a4a39c5156da1587f8ad2330d8e9b03a4a19edba Mon Sep 17 00:00:00 2001 From: Benoit Vermont Date: Sat, 29 Mar 2014 18:57:49 +0100 Subject: [PATCH 05/71] Update setup --- .idea/copyright/profiles_settings.xml | 4 +- .idea/gradle.xml | 6 +- .idea/misc.xml | 203 +------------------------- Resizer.eml | 2 +- 4 files changed, 4 insertions(+), 211 deletions(-) diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml index a63a6f4..5e58e67 100644 --- a/.idea/copyright/profiles_settings.xml +++ b/.idea/copyright/profiles_settings.xml @@ -1,5 +1,3 @@ - - - + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml index cb01329..f6e673a 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -1,7 +1,3 @@ - - - - + diff --git a/.idea/misc.xml b/.idea/misc.xml index c4ab1ee..0cae957 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,208 +3,7 @@ - - - - + diff --git a/Resizer.eml b/Resizer.eml index 71d5e2b..6f97233 100644 --- a/Resizer.eml +++ b/Resizer.eml @@ -1,5 +1,5 @@ - + From 39d94ddaf928c2724306f462f42d77624104858c Mon Sep 17 00:00:00 2001 From: Benoit Vermont Date: Sat, 29 Mar 2014 18:58:02 +0100 Subject: [PATCH 06/71] Fixes #3 --- res/misc/densities.json | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/res/misc/densities.json b/res/misc/densities.json index dd5ec3e..ef5ee1e 100644 --- a/res/misc/densities.json +++ b/res/misc/densities.json @@ -1,10 +1,15 @@ { "densities": [ - { - "name": "xxhdpi", - "scale": 3, - "active": false - }, + { + "name": "xxxhdpi", + "scale": 4, + "active": false + }, + { + "name": "xxhdpi", + "scale": 3, + "active": false + }, { "name": "xhdpi", "scale": 2, @@ -32,4 +37,4 @@ } ], "source": "xhdpi" -} +} \ No newline at end of file From 102be9a6702f51ce410e0ccd5a4fe34d390b4f20 Mon Sep 17 00:00:00 2001 From: Benoit Vermont Date: Sat, 29 Mar 2014 19:07:18 +0100 Subject: [PATCH 07/71] Fixes #1 --- res/locale/Strings.properties | 2 +- res/locale/Strings_fr.properties | 4 ++-- src/net/redwarp/tool/resizer/misc/Localization.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/res/locale/Strings.properties b/res/locale/Strings.properties index 12e01ac..719ea4b 100644 --- a/res/locale/Strings.properties +++ b/res/locale/Strings.properties @@ -1,6 +1,6 @@ #Created by JInto - www.guh-software.de #Sat Jun 09 15:23:03 CEST 2012 -about_text=Resizer is a simple resizer tool for Android.\r\nIt takes a PNG image as input, and automatically renerates folders with 4 densities \: ldpi, mdpi, hdpi and xhdpi.\r\nWhat's more \: Resizer work on 9 patches as well \! Because, let's face it, it's a pain to have to do it by hand.\r\nAll icons were found on http\://www.clker.com/\r\n\r\n(c) Copyright Redwarp 2013. All rights reserved. +about_text=Resizer is a simple resizer tool for Android.\nIt takes a PNG 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. 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 6020f28..2afcbbc 100644 --- a/res/locale/Strings_fr.properties +++ b/res/locale/Strings_fr.properties @@ -1,6 +1,6 @@ #Created by JInto - www.guh-software.de #Sat Jun 09 15:23:03 CEST 2012 -about_text=Resizer est un outil de redimensionnement pour Android.\r\nIl g\u00E9n\u00E8re automatiquement 4 dossiers de densit\u00E9 \: ldpi, mdpi, hdpi and xhdpi.\r\nMais le plus \: Resizer fonctionne sur les 9 patches \! Il faut l'avouer, c'est p\u00EAte b**ne de le faire \u00E0 la main.\r\nLes icons proviennent de http\://www.clker.com/\r\n\r\n(c) Copyright Redwarp 2013. Tous droits r\u00E9serv\u00E9s. +about_text=Resizer est un outil de redimensionnement pour Android.\nIl gé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 2013. Tous droits r\u00E9serv\u00E9s. app_name=9Patch Resizer column_name=Nom de l'image column_status=Status @@ -12,7 +12,7 @@ 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\u00E9 \! +status_finished=Terminé \! status_in_progress=En cours... status_pending=En attente... xhdpi=D\u00E9posez des images au format PNG (9 patch inclus) diff --git a/src/net/redwarp/tool/resizer/misc/Localization.java b/src/net/redwarp/tool/resizer/misc/Localization.java index cdd6f23..319996a 100644 --- a/src/net/redwarp/tool/resizer/misc/Localization.java +++ b/src/net/redwarp/tool/resizer/misc/Localization.java @@ -27,7 +27,7 @@ public static String get(String key) { try { return bundle.getString(key); } catch (MissingResourceException e) { - return new String(key); + return key; } } From de6eac0357fc4bb289836812ace8a7506deece52 Mon Sep 17 00:00:00 2001 From: Benoit Vermont Date: Sat, 29 Mar 2014 19:17:14 +0100 Subject: [PATCH 08/71] Change jdk to 1.6 --- .idea/misc.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 0cae957..9732041 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,7 +3,7 @@ - + From 4a8f16c704346a770d265fcd76e0f03cf29a4283 Mon Sep 17 00:00:00 2001 From: Benoit Vermont Date: Sat, 29 Mar 2014 19:17:45 +0100 Subject: [PATCH 09/71] Fixes #2 --- res/locale/Strings.properties | 4 ++-- res/locale/Strings_fr.properties | 4 ++-- src/net/redwarp/tool/resizer/views/MainWindow.java | 4 +++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/res/locale/Strings.properties b/res/locale/Strings.properties index 719ea4b..ba482d3 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 2013. All rights reserved. +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. app_name=9Patch Resizer column_name=Image name column_status=Status @@ -15,6 +15,6 @@ status_error=Error status_finished=Finished \! status_in_progress=In progress... status_pending=Pending... -xhdpi=Drop xhdpi image here (PNG format, nine patch included) +xhdpi=Drop %s image here (PNG format, nine patch included) input_density=Input density: output_density=Output density: \ No newline at end of file diff --git a/res/locale/Strings_fr.properties b/res/locale/Strings_fr.properties index 2afcbbc..8600bc8 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 2013. 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. Tous droits r\u00E9serv\u00E9s. app_name=9Patch Resizer column_name=Nom de l'image column_status=Status @@ -15,6 +15,6 @@ status_error=Erreur status_finished=Terminé \! status_in_progress=En cours... status_pending=En attente... -xhdpi=D\u00E9posez des images au format PNG (9 patch inclus) +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 : diff --git a/src/net/redwarp/tool/resizer/views/MainWindow.java b/src/net/redwarp/tool/resizer/views/MainWindow.java index ff91b68..42800c0 100644 --- a/src/net/redwarp/tool/resizer/views/MainWindow.java +++ b/src/net/redwarp/tool/resizer/views/MainWindow.java @@ -31,6 +31,7 @@ import java.io.File; import java.util.ArrayList; import java.util.List; +import java.util.Locale; import java.util.Vector; @SuppressWarnings("serial") @@ -87,7 +88,7 @@ public MainWindow() { this.inputPanel.setPreferredSize(new Dimension(10, 140)); this.getContentPane().add(this.inputPanel, "input"); - this.xhdpiButton = new JButton(Localization.get("xhdpi")); + 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) { @@ -119,6 +120,7 @@ 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); From 9e3d4b01498279d1e9293dab7f60ea53ddbacf00 Mon Sep 17 00:00:00 2001 From: redwarp Date: Wed, 21 May 2014 13:05:33 +0200 Subject: [PATCH 10/71] Update README.md --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 23b6aab..3daf54e 100644 --- a/README.md +++ b/README.md @@ -24,10 +24,9 @@ You're using 9patch resizer for your apps ? Don't hesitate and leave me a messag # Roadmap - * Command line support - * A few optimisations - * Options to set the input density (if people wan't to downsize from hdpi and not from xdpi for instance) - * Resize @2x (apple stuff) as well +- [ ] 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) # Anyway... From b649e591d67244d7a11b319884abb770185fef20 Mon Sep 17 00:00:00 2001 From: redwarp Date: Thu, 24 Jul 2014 15:35:00 +0200 Subject: [PATCH 11/71] Update README.md --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3daf54e..9e04dfe 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,8 @@ -9-Patch-Resizer -=============== +# ![Tools](https://github.com/redwarp/9-Patch-Resizer/blob/develop/res/img/icon_64.png) 9-Patch-Resizer A resizer tool to automaticaly resize png files and 9 patches in several densities (previously hosted on https://code.google.com/p/9patch-resizer/) -# 9Patch Resizer +## What is it ? Let's face it : juggling with densities for Android is a bit of a pain, especially when dealing with 9 patch png. From 4f392b389d60695cadcd0b73eb54ab1dfb051b3c Mon Sep 17 00:00:00 2001 From: redwarp Date: Thu, 24 Jul 2014 15:35:24 +0200 Subject: [PATCH 12/71] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9e04dfe..cec77c7 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# ![Tools](https://github.com/redwarp/9-Patch-Resizer/blob/develop/res/img/icon_64.png) 9-Patch-Resizer +# ![Tools](https://github.com/redwarp/9-Patch-Resizer/blob/develop/res/img/icon_32.png) 9-Patch-Resizer A resizer tool to automaticaly resize png files and 9 patches in several densities (previously hosted on https://code.google.com/p/9patch-resizer/) From 0ec9b85815591784de0282cd366c2ffe880bdc36 Mon Sep 17 00:00:00 2001 From: redwarp Date: Fri, 1 Aug 2014 11:36:43 +0200 Subject: [PATCH 13/71] Update README.md Make the download link more obvious --- README.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index cec77c7..39d2132 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,13 @@ A resizer tool to automaticaly resize png files and 9 patches in several densities (previously hosted on https://code.google.com/p/9patch-resizer/) -## What is it ? +## Download + +To get the latest build (.jar or .exe file), check the release page on the github project: https://github.com/redwarp/9-Patch-Resizer/releases + +The .exe file is just a wrapper around the executable .jar file, use it if you don't feel comfortable with a java archive ^_^ + +## What is it exactly? Let's face it : juggling with densities for Android is a bit of a pain, especially when dealing with 9 patch png. @@ -16,18 +22,18 @@ Current version : *1.3.1* You're using 9patch resizer for your apps ? Don't hesitate and leave me a message! -# Links +## Links * Images and stuff found on http://www.clker.com/ (The online royalty free public domain clip art) * Images are downsized using an optimized incremental scaling algorithm proposed by Chris Campbell (whoever that is) - http://today.java.net/pub/a/today/2007/04/03/perils-of-image-getscaledinstance.html -# Roadmap +## Roadmap - [ ] 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) -# Anyway... +## 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 bdceb631065fabf85fede82e89003c28e41e4706 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Vermont?= Date: Mon, 11 Aug 2014 19:38:52 +0200 Subject: [PATCH 14/71] Generification --- src/net/redwarp/tool/resizer/views/MainWindow.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/net/redwarp/tool/resizer/views/MainWindow.java b/src/net/redwarp/tool/resizer/views/MainWindow.java index 42800c0..7f2a941 100644 --- a/src/net/redwarp/tool/resizer/views/MainWindow.java +++ b/src/net/redwarp/tool/resizer/views/MainWindow.java @@ -112,7 +112,7 @@ public void actionPerformed(ActionEvent arg0) { JLabel inputLabel = new JLabel(Localization.get("input_density")); inputLabel.setAlignmentX(Component.LEFT_ALIGNMENT); optionPanel.add(inputLabel); - JComboBox inputDensityChoice = new JComboBox(new Vector(ScreenDensity.getSupportedScreenDensity())); + JComboBox inputDensityChoice = new JComboBox(new Vector(ScreenDensity.getSupportedScreenDensity())); inputDensityChoice.setSelectedItem(ScreenDensity.getDefaultInputDensity()); inputDensityChoice.addActionListener(new ActionListener() { @Override From d87cc9bfe714f3457a500c7f9d9643af57079488 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Vermont?= Date: Mon, 11 Aug 2014 20:16:05 +0200 Subject: [PATCH 15/71] Add the posibility to save settings (#9) --- res/locale/Strings.properties | 4 +- res/locale/Strings_fr.properties | 6 +- .../tool/resizer/views/MainWindow.java | 14 +++- .../tool/resizer/worker/ScreenDensity.java | 78 ++++++++++++++++--- 4 files changed, 86 insertions(+), 16 deletions(-) diff --git a/res/locale/Strings.properties b/res/locale/Strings.properties index ba482d3..7c52339 100644 --- a/res/locale/Strings.properties +++ b/res/locale/Strings.properties @@ -17,4 +17,6 @@ status_in_progress=In progress... status_pending=Pending... xhdpi=Drop %s image here (PNG format, nine patch included) input_density=Input density: -output_density=Output density: \ No newline at end of file +output_density=Output density: +save=Save +save_tooltip=Hit the save button to keep this settings the next time you launch 9Patch Resizer diff --git a/res/locale/Strings_fr.properties b/res/locale/Strings_fr.properties index 8600bc8..86a46f8 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. Tous droits r\u00E9serv\u00E9s. app_name=9Patch Resizer column_name=Nom de l'image column_status=Status @@ -12,9 +12,11 @@ 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 : +save=Sauvegarder +save_tooltip=Sauvegardez les réglages courants pour les réutiliser la prochaine fois que vous lancerez 9Patch Resizer diff --git a/src/net/redwarp/tool/resizer/views/MainWindow.java b/src/net/redwarp/tool/resizer/views/MainWindow.java index 7f2a941..059af6c 100644 --- a/src/net/redwarp/tool/resizer/views/MainWindow.java +++ b/src/net/redwarp/tool/resizer/views/MainWindow.java @@ -55,7 +55,7 @@ public class MainWindow extends JFrame { private final Action action = new SwingAction(); public MainWindow() { - this.setSize(new Dimension(450, 350)); + this.setSize(new Dimension(500, 370)); this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); this.setTitle(Localization.get("app_name")); @@ -145,6 +145,18 @@ public void actionPerformed(ActionEvent actionEvent) { optionPanel.add(box); } 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); diff --git a/src/net/redwarp/tool/resizer/worker/ScreenDensity.java b/src/net/redwarp/tool/resizer/worker/ScreenDensity.java index 94ba418..7ec9432 100644 --- a/src/net/redwarp/tool/resizer/worker/ScreenDensity.java +++ b/src/net/redwarp/tool/resizer/worker/ScreenDensity.java @@ -15,47 +15,48 @@ */ package net.redwarp.tool.resizer.worker; -import com.google.gson.Gson; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; +import com.google.gson.*; import com.google.gson.reflect.TypeToken; -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStream; -import java.io.InputStreamReader; +import javax.swing.*; +import java.io.*; 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; static { + load(); + } + + private static void load() { try { Gson gson = new Gson(); JsonParser parser = new JsonParser(); InputStream preferenceStream; try { - preferenceStream = new FileInputStream(new File("./densities.json")); + 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("densities").getAsJsonArray(); + JsonArray densitiesArray = densitiesObject.get(KEY_DENSITIES).getAsJsonArray(); Type listType = new TypeToken>() { }.getType(); list = gson.fromJson(densitiesArray, listType); - String defaultDensityName = densitiesObject.get("source").getAsString(); + String defaultDensityName = densitiesObject.get(KEY_SOURCE).getAsString(); for (ScreenDensity density : list) { if (density.getName().equals(defaultDensityName)) { defaultInputDensity = density; @@ -72,6 +73,23 @@ public class ScreenDensity { } } + 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; @@ -118,4 +136,40 @@ public boolean isActive() { 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 e3c7c6d89c937d094bb9b682a496b2cb8c6e6321 Mon Sep 17 00:00:00 2001 From: Benoit Vermont Date: Tue, 12 Aug 2014 09:21:33 +0200 Subject: [PATCH 16/71] Change base densities --- res/misc/densities.json | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/res/misc/densities.json b/res/misc/densities.json index ef5ee1e..8ac75e9 100644 --- a/res/misc/densities.json +++ b/res/misc/densities.json @@ -1,40 +1,40 @@ { + "source": "xxhdpi", "densities": [ { - "name": "xxxhdpi", "scale": 4, + "name": "xxxhdpi", "active": false }, { - "name": "xxhdpi", "scale": 3, - "active": false + "name": "xxhdpi", + "active": true }, { - "name": "xhdpi", "scale": 2, + "name": "xhdpi", "active": true }, { - "name": "hdpi", "scale": 1.5, + "name": "hdpi", "active": true }, { - "name": "tvdpi", "scale": 1.33, + "name": "tvdpi", "active": false }, { - "name": "mdpi", "scale": 1, + "name": "mdpi", "active": true }, { - "name": "ldpi", "scale": 0.75, - "active": true + "name": "ldpi", + "active": false } - ], - "source": "xhdpi" + ] } \ No newline at end of file From e06aca3da62248efa8f0b357c3cde4f51977675c Mon Sep 17 00:00:00 2001 From: Benoit Vermont Date: Tue, 12 Aug 2014 09:33:58 +0200 Subject: [PATCH 17/71] update launch4j script --- .idea/ant.xml | 7 +++++++ build.xml | 2 +- launch4j_config.xml | 20 +++++++++++--------- res/misc/preferences.properties | 2 +- 4 files changed, 20 insertions(+), 11 deletions(-) create mode 100644 .idea/ant.xml diff --git a/.idea/ant.xml b/.idea/ant.xml new file mode 100644 index 0000000..313b0c0 --- /dev/null +++ b/.idea/ant.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/build.xml b/build.xml index 8a4464b..e8f43ad 100644 --- a/build.xml +++ b/build.xml @@ -65,7 +65,7 @@ - + diff --git a/launch4j_config.xml b/launch4j_config.xml index d38aaa4..432c244 100644 --- a/launch4j_config.xml +++ b/launch4j_config.xml @@ -1,35 +1,37 @@ + false gui - C:\Users\Akaiwarp\workspace\Resizer\Resizer_1.3.1.jar - C:\Users\Akaiwarp\workspace\Resizer\Resizer_1.3.1.exe + C:\Users\Redwarp\workspace\Resizer\Resizer_proguard.jar + C:\Users\Redwarp\workspace\Resizer\Resizer_1.3.2.exe normal http://java.com/download - false false - C:\Users\Akaiwarp\workspace\Resizer\extra\icon_512.ico + C:\Users\Redwarp\workspace\Resizer\extra\icon_512.ico resizer + false 1.6.0 preferJre + 64/32 - 1.3.1.0 - 1.3.1 + 1.3.2.0 + 1.3.2 9Patch Resizer - Redwarp - 2013 - 1.3.1.0 - 1.3.1 + Redwarp - 2014 + 1.3.2.0 + 1.3.2 9Patch Resizer Resizer diff --git a/res/misc/preferences.properties b/res/misc/preferences.properties index 879b9c4..5882032 100644 --- a/res/misc/preferences.properties +++ b/res/misc/preferences.properties @@ -1,3 +1,3 @@ #Created by JInto - www.guh-software.de #Sun Oct 21 22:30:52 CEST 2012 -version=1.3.1 \ No newline at end of file +version=1.3.2 \ No newline at end of file From a8738166e248c630cc22fe2ab4c2a123e99b0389 Mon Sep 17 00:00:00 2001 From: redwarp Date: Tue, 12 Aug 2014 13:35:03 +0200 Subject: [PATCH 18/71] Update README.md Update version number in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 39d2132..15de445 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.1* +Current version : *1.3.2* You're using 9patch resizer for your apps ? Don't hesitate and leave me a message! From cc8e4cc6a904d7ca17e47fb4f0c4e5fc8e70c6b1 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Lab Date: Thu, 4 Sep 2014 17:01:11 +0200 Subject: [PATCH 19/71] Add primitive command line support, resolves #4 --- .../redwarp/tool/resizer/FileProcessor.java | 58 +++++++++++++ src/net/redwarp/tool/resizer/Main.java | 84 ++++++++++++++----- 2 files changed, 122 insertions(+), 20 deletions(-) create mode 100644 src/net/redwarp/tool/resizer/FileProcessor.java diff --git a/src/net/redwarp/tool/resizer/FileProcessor.java b/src/net/redwarp/tool/resizer/FileProcessor.java new file mode 100644 index 0000000..a78f471 --- /dev/null +++ b/src/net/redwarp/tool/resizer/FileProcessor.java @@ -0,0 +1,58 @@ +package net.redwarp.tool.resizer; + +import java.io.File; + +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; + +public class FileProcessor { + + public interface FileProcessorStatusListener { + void onSuccess(); + + void onFailure(String msg); + } + + private ImageScaler scaler; + FileProcessorStatusListener listener; + String fileName; + + public FileProcessor(String name, FileProcessorStatusListener l) { + fileName = name; + listener = l; + if (name.endsWith(".png") || name.endsWith(".jpg")) { + 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()); + } + } + } + }; + } + } + + 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 9d947c4..ba6bd24 100644 --- a/src/net/redwarp/tool/resizer/Main.java +++ b/src/net/redwarp/tool/resizer/Main.java @@ -15,30 +15,74 @@ */ 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.*; public class Main { - public static void main(String[] args) { - // Apple only stuff - System.setProperty("apple.laf.useScreenMenuBar", "true"); - System.setProperty("com.apple.mrj.application.apple.menu.about.name", - Localization.get("app_name")); - - try { - UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } catch (InstantiationException e) { - e.printStackTrace(); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } catch (UnsupportedLookAndFeelException e) { - e.printStackTrace(); - } - - new MainWindow().setVisible(true); - } + static class StatusListener implements FileProcessorStatusListener { + int count = 0; + int current = 0; + int failureCount = 0; + + public StatusListener(int count) { + this.count = count; + } + + @Override + public void onSuccess() { + this.current++; + if (this.current == this.count) { + System.exit(failureCount); + } + } + + @Override + public void onFailure(String msg) { + System.err.print(msg + "\n"); + this.current++; + this.failureCount++; + if (this.current == this.count) { + System.exit(failureCount); + } + } + } + + public static void main(String[] args) { + // Apple only stuff + System.setProperty("apple.laf.useScreenMenuBar", "true"); + System.setProperty("com.apple.mrj.application.apple.menu.about.name", + Localization.get("app_name")); + if (args.length > 0) { + StatusListener l = new StatusListener(args.length); + ArrayList processors = new ArrayList(); + + for (String s : args) { + processors.add(new FileProcessor(s, l)); + } + for (FileProcessor p : processors) { + p.process(); + } + } else { + + try { + UIManager.setLookAndFeel(UIManager + .getSystemLookAndFeelClassName()); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (UnsupportedLookAndFeelException e) { + e.printStackTrace(); + } + + new MainWindow().setVisible(true); + } + } } From ead91f7ea655efaef6651352cf1673712e4b699a Mon Sep 17 00:00:00 2001 From: Benoit Vermont Date: Mon, 8 Sep 2014 09:14:07 +0200 Subject: [PATCH 20/71] Update version numbers --- launch4j_config.xml | 10 +++++----- res/misc/preferences.properties | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/launch4j_config.xml b/launch4j_config.xml index 432c244..a3770f6 100644 --- a/launch4j_config.xml +++ b/launch4j_config.xml @@ -3,7 +3,7 @@ false gui C:\Users\Redwarp\workspace\Resizer\Resizer_proguard.jar - C:\Users\Redwarp\workspace\Resizer\Resizer_1.3.2.exe + C:\Users\Redwarp\workspace\Resizer\Resizer_1.3.3.exe @@ -26,12 +26,12 @@ 64/32 - 1.3.2.0 - 1.3.2 + 1.3.3.0 + 1.3.3 9Patch Resizer Redwarp - 2014 - 1.3.2.0 - 1.3.2 + 1.3.3.0 + 1.3.3 9Patch Resizer Resizer diff --git a/res/misc/preferences.properties b/res/misc/preferences.properties index 5882032..e7528bd 100644 --- a/res/misc/preferences.properties +++ b/res/misc/preferences.properties @@ -1,3 +1,3 @@ #Created by JInto - www.guh-software.de #Sun Oct 21 22:30:52 CEST 2012 -version=1.3.2 \ No newline at end of file +version=1.3.3 \ No newline at end of file From f287e881884c7b804aca54d7170fdc173b5b289b Mon Sep 17 00:00:00 2001 From: redwarp Date: Mon, 8 Sep 2014 09:17:42 +0200 Subject: [PATCH 21/71] 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 22/71] 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 23/71] 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 24/71] 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 25/71] 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 26/71] 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 27/71] 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 28/71] 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 29/71] 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 30/71] 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 31/71] 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 32/71] 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 33/71] 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 34/71] 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 35/71] 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 36/71] 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 37/71] 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 38/71] 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 39/71] 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 40/71] 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 41/71] 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 42/71] 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 43/71] 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 44/71] 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 45/71] 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 46/71] 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 47/71] 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 48/71] 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 49/71] 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 50/71] 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 51/71] 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 52/71] 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 53/71] 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 54/71] 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 55/71] 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 From c5e39c0da4097b10614fb0d81ada1ba0b2aa570c Mon Sep 17 00:00:00 2001 From: redwarp Date: Fri, 20 Feb 2015 10:51:26 +0100 Subject: [PATCH 56/71] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 63dba53..a1ddc4f 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ You're using 9patch resizer for your apps ? Don't hesitate and leave me a messag ## Roadmap +- [ ] A proper "Settings" panel, to handle issues such as jpeg compression, etc etc... - [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) From fb2b2739e755967897b7216c97af62838cae9ec8 Mon Sep 17 00:00:00 2001 From: redwarp Date: Fri, 20 Feb 2015 14:12:37 +0100 Subject: [PATCH 57/71] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a1ddc4f..ef7a502 100644 --- a/README.md +++ b/README.md @@ -32,8 +32,8 @@ You're using 9patch resizer for your apps ? Don't hesitate and leave me a messag ## Roadmap - [ ] A proper "Settings" panel, to handle issues such as jpeg compression, etc etc... -- [x] Command line support - [ ] A few optimisations +- [x] Command line support - [x] Options to set the input density (if people wan't to downsize from hdpi and not from xdpi for instance) - [x] Proper JPG support From 994854e4fdffaa4ce86d09426a4a6d02880358d5 Mon Sep 17 00:00:00 2001 From: Benoit Vermont Date: Sat, 21 Feb 2015 13:31:57 +0100 Subject: [PATCH 58/71] Git cleanup --- .gitignore | 2 + .idea/.name | 1 - .idea/ant.xml | 2 - .idea/compiler.xml | 32 ------- .idea/copyright/Redwarp.xml | 9 -- .idea/copyright/profiles_settings.xml | 3 - .idea/encodings.xml | 5 -- .idea/gradle.xml | 3 - .idea/libraries/gson_2_2_4.xml | 13 --- .idea/modules.xml | 9 -- .idea/scopes/scope_settings.xml | 5 -- .idea/uiDesigner.xml | 125 -------------------------- .idea/vcs.xml | 7 -- Resizer.eml | 13 --- Resizer.iml | 2 - 15 files changed, 2 insertions(+), 229 deletions(-) delete mode 100644 .idea/.name delete mode 100644 .idea/ant.xml delete mode 100644 .idea/compiler.xml delete mode 100644 .idea/copyright/Redwarp.xml delete mode 100644 .idea/copyright/profiles_settings.xml delete mode 100644 .idea/encodings.xml delete mode 100644 .idea/gradle.xml delete mode 100644 .idea/libraries/gson_2_2_4.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/scopes/scope_settings.xml delete mode 100644 .idea/uiDesigner.xml delete mode 100644 .idea/vcs.xml delete mode 100644 Resizer.eml delete mode 100644 Resizer.iml diff --git a/.gitignore b/.gitignore index 602223c..74abb7e 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,5 @@ target .idea/ densities.json +Resizer.eml +resizer.iml \ No newline at end of file diff --git a/.idea/.name b/.idea/.name deleted file mode 100644 index fea9e65..0000000 --- a/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -9patch-resizer \ No newline at end of file diff --git a/.idea/ant.xml b/.idea/ant.xml deleted file mode 100644 index c8f67ff..0000000 --- a/.idea/ant.xml +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index 57d709b..0000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/copyright/Redwarp.xml b/.idea/copyright/Redwarp.xml deleted file mode 100644 index fb25d3e..0000000 --- a/.idea/copyright/Redwarp.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml deleted file mode 100644 index 5e58e67..0000000 --- a/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml deleted file mode 100644 index e206d70..0000000 --- a/.idea/encodings.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/.idea/gradle.xml b/.idea/gradle.xml deleted file mode 100644 index f6e673a..0000000 --- a/.idea/gradle.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/.idea/libraries/gson_2_2_4.xml b/.idea/libraries/gson_2_2_4.xml deleted file mode 100644 index 33a40e6..0000000 --- a/.idea/libraries/gson_2_2_4.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 3636d50..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/.idea/scopes/scope_settings.xml b/.idea/scopes/scope_settings.xml deleted file mode 100644 index 922003b..0000000 --- a/.idea/scopes/scope_settings.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml deleted file mode 100644 index 3b00020..0000000 --- a/.idea/uiDesigner.xml +++ /dev/null @@ -1,125 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 275077f..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/Resizer.eml b/Resizer.eml deleted file mode 100644 index a9b5d7b..0000000 --- a/Resizer.eml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - diff --git a/Resizer.iml b/Resizer.iml deleted file mode 100644 index 240f3e9..0000000 --- a/Resizer.iml +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file From 2b9c8e70209943b6f0a9af59bdebe0547ba9e507 Mon Sep 17 00:00:00 2001 From: Benoit Vermont Date: Sat, 21 Mar 2015 14:39:41 +0100 Subject: [PATCH 59/71] Replace ImageIO by Toolkit to read images --- src/net/redwarp/tool/resizer/worker/ImageScaler.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/net/redwarp/tool/resizer/worker/ImageScaler.java b/src/net/redwarp/tool/resizer/worker/ImageScaler.java index 33b9f56..a0c7619 100644 --- a/src/net/redwarp/tool/resizer/worker/ImageScaler.java +++ b/src/net/redwarp/tool/resizer/worker/ImageScaler.java @@ -56,7 +56,11 @@ protected Void doInBackground() throws Exception { try { BufferedImage inputImage; synchronized (fileLock) { - inputImage = ImageIO.read(this.inputFile); +// inputImage = ImageIO.read(this.inputFile); + Image tempImage = Toolkit.getDefaultToolkit().createImage(this.inputFile.getAbsolutePath()); + ImageIcon tempIcon = new ImageIcon(tempImage); + inputImage = new BufferedImage(tempIcon.getIconWidth(), tempIcon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); + inputImage.getGraphics().drawImage(tempImage, 0, 0, null); } if (inputImage == null) { this.operation.setStatus(OperationStatus.ERROR, @@ -186,7 +190,7 @@ protected Void doInBackground() throws Exception { // } this.operation.setStatus(OperationStatus.FINISH); this.publish(this.operation); - } catch (IOException e) { + } catch (Exception e) { this.operation.setStatus(OperationStatus.ERROR); this.publish(this.operation); } From 12f0a1dfffa0dfe12ff15d594aad1201b16834a3 Mon Sep 17 00:00:00 2001 From: Benoit Vermont Date: Sat, 21 Mar 2015 14:55:01 +0100 Subject: [PATCH 60/71] Update build number --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 3d6923e..57b67e5 100644 --- a/pom.xml +++ b/pom.xml @@ -20,12 +20,12 @@ resizer - 1.4.0 + 1.4.1 9Patch Resizer ${project.version} - 2 + 3 From 3d486c22cdf6b938f613f7fa048b3f643864a1f3 Mon Sep 17 00:00:00 2001 From: redwarp Date: Sat, 21 Mar 2015 15:03:32 +0100 Subject: [PATCH 61/71] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ef7a502..123f205 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.4.0* +Current version : *1.4.1* You're using 9patch resizer for your apps ? Don't hesitate and leave me a message! From 3366dea65b21f3075151ad9ce92cc95dd9e71c05 Mon Sep 17 00:00:00 2001 From: redwarp Date: Wed, 1 Apr 2015 17:15:38 +0200 Subject: [PATCH 62/71] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 123f205..623229f 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,6 @@ Join us, and together, we can rule the galaxy as coders and... 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 ! -I hope it'll prove as useful to you as it is useful to me. If you like it, and have too much cash in you hands, don't hesitate to donate : I could use a few beers. +I hope it'll prove as useful to you as it is useful to me. If you like it, and have too much cash in you hands, don't hesitate to donate. I will probably use it on beers though, so you should probably not bother, if you care for my health. From 0b93221bfa1c937226bd23653d07a2bf727e8d7e Mon Sep 17 00:00:00 2001 From: redwarp Date: Tue, 30 Jun 2015 17:40:59 +0200 Subject: [PATCH 63/71] On click in windows, launch a file picker dialog --- .../tool/resizer/views/MainWindow.java | 96 ++++++++++++------- 1 file changed, 63 insertions(+), 33 deletions(-) diff --git a/src/net/redwarp/tool/resizer/views/MainWindow.java b/src/net/redwarp/tool/resizer/views/MainWindow.java index 3c5b128..81e9b85 100644 --- a/src/net/redwarp/tool/resizer/views/MainWindow.java +++ b/src/net/redwarp/tool/resizer/views/MainWindow.java @@ -28,6 +28,8 @@ import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; import java.io.File; import java.util.ArrayList; import java.util.List; @@ -56,6 +58,7 @@ public class MainWindow extends JFrame { private JMenuItem mntmClear; private JMenuItem mntmAbout; private final Action action = new SwingAction(); + private final JComboBox inputDensityChoice; public MainWindow() { this.setSize(new Dimension(550, 400)); @@ -111,6 +114,31 @@ public void actionPerformed(ActionEvent arg0) { this.xhdpiButton.setContentAreaFilled(false); this.inputPanel.add(this.xhdpiButton, BorderLayout.CENTER); + final JFileChooser fileChooser = new JFileChooser() { + @Override + public boolean accept(File f) { + return NameValidator.isFilenameValid(f.getName()); + } + }; + fileChooser.setMultiSelectionEnabled(true); + + this.xhdpiButton.addMouseListener( + new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + System.out.println("Clicked"); + int returnVal = fileChooser.showOpenDialog(MainWindow.this); + + if (returnVal == JFileChooser.APPROVE_OPTION) { + File[] files = fileChooser.getSelectedFiles(); + + createScaleJobs(files); + } else { + System.out.println("Attachment cancelled by user."); + } + } + }); + JPanel optionPanel = new JPanel(); optionPanel.setLayout(new BoxLayout(optionPanel, BoxLayout.PAGE_AXIS)); optionPanel.add(Box.createVerticalGlue()); @@ -118,10 +146,8 @@ public void actionPerformed(ActionEvent arg0) { JLabel inputLabel = new JLabel(Localization.get("input_density")); inputLabel.setAlignmentX(Component.LEFT_ALIGNMENT); optionPanel.add(inputLabel); - final JComboBox - inputDensityChoice = - new JComboBox( - new Vector(Configuration.getSettings().getSupportedScreenDensity())); + inputDensityChoice = new JComboBox( + new Vector(Configuration.getSettings().getSupportedScreenDensity())); inputDensityChoice.setSelectedItem(Configuration.getSettings().getDefaultInputDensity()); inputDensityChoice.addActionListener(new ActionListener() { @Override @@ -215,35 +241,7 @@ public void run() { @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(); - - ScreenDensity selectedDensity = (ScreenDensity) inputDensityChoice.getSelectedItem(); - instructionLabel.setText(String.format(Locale.getDefault(), Localization.get("xhdpi"), - selectedDensity.getName())); - layout.show(MainWindow.this.getContentPane(), "output"); - Operation operation = new Operation(input); - MainWindow.this.resultTable.addOperation(operation); - - ImageScaler scaler = new ImageScaler(operation, - Configuration.getSettings() - .getDefaultInputDensity()) { - @Override - protected void process( - java.util.List chunks) { - for (Operation operation : chunks) { - MainWindow.this.resultTable - .notifyChange(operation); - } - } - }; - scaler.post(); - } - } + createScaleJobs(files); } @Override @@ -273,6 +271,38 @@ public void dragExit(Container source) { this.setMenuBar(); } + private void createScaleJobs(File[] files) { + for (File input : files) { + String filename = input.getName(); + if (NameValidator.isFilenameValid(filename)) { + MainWindow.this.mntmClear.setEnabled(true); + CardLayout layout = (CardLayout) MainWindow.this + .getContentPane().getLayout(); + + ScreenDensity selectedDensity = (ScreenDensity) inputDensityChoice.getSelectedItem(); + instructionLabel.setText(String.format(Locale.getDefault(), Localization.get("xhdpi"), + selectedDensity.getName())); + layout.show(MainWindow.this.getContentPane(), "output"); + Operation operation = new Operation(input); + MainWindow.this.resultTable.addOperation(operation); + + ImageScaler scaler = new ImageScaler(operation, + Configuration.getSettings() + .getDefaultInputDensity()) { + @Override + protected void process( + List chunks) { + for (Operation operation : chunks) { + MainWindow.this.resultTable + .notifyChange(operation); + } + } + }; + scaler.post(); + } + } + } + private void setMenuBar() { this.menuBar = new JMenuBar(); this.setJMenuBar(this.menuBar); From 0be6b94b1700cadb3d3896bc4fc4436cb618d467 Mon Sep 17 00:00:00 2001 From: redwarp Date: Tue, 30 Jun 2015 17:55:23 +0200 Subject: [PATCH 64/71] Refactoring --- .../tool/resizer/views/MainWindow.java | 165 +++++++++--------- 1 file changed, 83 insertions(+), 82 deletions(-) diff --git a/src/net/redwarp/tool/resizer/views/MainWindow.java b/src/net/redwarp/tool/resizer/views/MainWindow.java index 81e9b85..00fd69f 100644 --- a/src/net/redwarp/tool/resizer/views/MainWindow.java +++ b/src/net/redwarp/tool/resizer/views/MainWindow.java @@ -42,23 +42,15 @@ @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(); - private final JComboBox inputDensityChoice; + private JComboBox inputDensityChoice; + private JFileChooser fileChooser; public MainWindow() { this.setSize(new Dimension(550, 400)); @@ -90,9 +82,73 @@ public MainWindow() { 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"); + + fileChooser = new JFileChooser() { + @Override + public boolean accept(File f) { + return NameValidator.isFilenameValid(f.getName()); + } + }; + fileChooser.setMultiSelectionEnabled(true); + + this.getContentPane().add(createInputPanel(), "input"); + this.getContentPane().add(createOutputPanel(), "output"); + + this.setMenuBar(); + } + + private JPanel createOutputPanel() { + JPanel outputPanel = new JPanel(); + outputPanel.setLayout(new BorderLayout(0, 0)); + + JTextArea textArea = new JTextArea(); + textArea.setLineWrap(true); + textArea.setEditable(false); + + this.resultTable = new ResultTable(); + JScrollPane scrollPane = new JScrollPane(this.resultTable); + scrollPane + .setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); + scrollPane + .setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); + outputPanel.add(scrollPane, BorderLayout.CENTER); + + FileDrop.Listener dropListener = new FileDrop.Listener() { + + @Override + public void filesDropped(Container source, File[] files) { + createScaleJobs(files); + } + + @Override + public void dragEnter(Container source) { + MainWindow.this.xhdpiButton.setSelected(true); + MainWindow.this.instructionLabel + .setIcon(MainWindow.this.redArrowSmall); + } + + @Override + public void dragExit(Container source) { + MainWindow.this.xhdpiButton.setSelected(false); + MainWindow.this.instructionLabel + .setIcon(MainWindow.this.blueArrowSmall); + } + }; + new FileDrop(this.getContentPane(), null, dropListener); + new FileDrop(outputPanel, null, dropListener); + + this.instructionLabel = new JLabel(""); + this.instructionLabel.setIcon(this.blueArrowSmall); + this.instructionLabel.setBorder(new EmptyBorder(4, 4, 4, 4)); + outputPanel.add(this.instructionLabel, BorderLayout.SOUTH); + + new FileDrop(textArea, null, dropListener); + return outputPanel; + } + + private JPanel createInputPanel() { + JPanel inputPanel = new JPanel(); + inputPanel.setPreferredSize(new Dimension(10, 140)); this.xhdpiButton = new JButton(String.format(Locale.getDefault(), Localization.get("xhdpi"), @@ -102,7 +158,7 @@ public MainWindow() { public void actionPerformed(ActionEvent arg0) { } }); - this.inputPanel.setLayout(new BorderLayout(0, 0)); + inputPanel.setLayout(new BorderLayout(0, 0)); this.xhdpiButton.setBorderPainted(false); this.xhdpiButton.setFocusPainted(false); this.xhdpiButton.setVerticalTextPosition(SwingConstants.BOTTOM); @@ -112,15 +168,8 @@ public void actionPerformed(ActionEvent arg0) { this.xhdpiButton.setSelectedIcon(this.redArrow); this.xhdpiButton.setBorder(null); this.xhdpiButton.setContentAreaFilled(false); - this.inputPanel.add(this.xhdpiButton, BorderLayout.CENTER); + inputPanel.add(this.xhdpiButton, BorderLayout.CENTER); - final JFileChooser fileChooser = new JFileChooser() { - @Override - public boolean accept(File f) { - return NameValidator.isFilenameValid(f.getName()); - } - }; - fileChooser.setMultiSelectionEnabled(true); this.xhdpiButton.addMouseListener( new MouseAdapter() { @@ -219,56 +268,8 @@ public void run() { 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) { - createScaleJobs(files); - } - - @Override - public void dragEnter(Container source) { - MainWindow.this.xhdpiButton.setSelected(true); - MainWindow.this.instructionLabel - .setIcon(MainWindow.this.redArrowSmall); - } - - @Override - public void dragExit(Container source) { - MainWindow.this.xhdpiButton.setSelected(false); - MainWindow.this.instructionLabel - .setIcon(MainWindow.this.blueArrowSmall); - } - }; - new FileDrop(this.getContentPane(), null, dropListener); - new FileDrop(this.outputPanel, null, dropListener); - - 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); - - new FileDrop(this.textArea, null, dropListener); - - this.setMenuBar(); + inputPanel.add(optionPanel, BorderLayout.LINE_START); + return inputPanel; } private void createScaleJobs(File[] files) { @@ -304,23 +305,23 @@ protected void process( } private void setMenuBar() { - this.menuBar = new JMenuBar(); - this.setJMenuBar(this.menuBar); + JMenuBar menuBar = new JMenuBar(); + this.setJMenuBar(menuBar); - this.mnEdit = new JMenu(Localization.get("menu_edit")); - this.menuBar.add(this.mnEdit); + JMenu mnEdit = new JMenu(Localization.get("menu_edit")); + menuBar.add(mnEdit); this.mntmClear = new JMenuItem(Localization.get("menu_item_clear")); this.mntmClear.setAction(this.action); this.mntmClear.setEnabled(false); - this.mnEdit.add(this.mntmClear); + mnEdit.add(this.mntmClear); - this.mnHelp = new JMenu(Localization.get("menu_help")); - this.menuBar.add(this.mnHelp); + JMenu mnHelp = new JMenu(Localization.get("menu_help")); + menuBar.add(mnHelp); - this.mntmAbout = new JMenuItem(); - this.mntmAbout.setAction(new AboutAction()); - this.mnHelp.add(this.mntmAbout); + JMenuItem mntmAbout = new JMenuItem(); + mntmAbout.setAction(new AboutAction()); + mnHelp.add(mntmAbout); } private class AboutAction extends AbstractAction { From 1246d6f2166155a1b412ffd7e3beff8cea6ff599 Mon Sep 17 00:00:00 2001 From: redwarp Date: Tue, 30 Jun 2015 17:58:19 +0200 Subject: [PATCH 65/71] Add file chooser to output panel --- .../redwarp/tool/resizer/views/MainWindow.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/net/redwarp/tool/resizer/views/MainWindow.java b/src/net/redwarp/tool/resizer/views/MainWindow.java index 00fd69f..7a4d53c 100644 --- a/src/net/redwarp/tool/resizer/views/MainWindow.java +++ b/src/net/redwarp/tool/resizer/views/MainWindow.java @@ -140,6 +140,19 @@ public void dragExit(Container source) { this.instructionLabel = new JLabel(""); this.instructionLabel.setIcon(this.blueArrowSmall); this.instructionLabel.setBorder(new EmptyBorder(4, 4, 4, 4)); + this.instructionLabel.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + int returnVal = fileChooser.showOpenDialog(MainWindow.this); + + if (returnVal == JFileChooser.APPROVE_OPTION) { + File[] files = fileChooser.getSelectedFiles(); + + createScaleJobs(files); + } + } + }); + outputPanel.add(this.instructionLabel, BorderLayout.SOUTH); new FileDrop(textArea, null, dropListener); @@ -175,15 +188,12 @@ public void actionPerformed(ActionEvent arg0) { new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { - System.out.println("Clicked"); int returnVal = fileChooser.showOpenDialog(MainWindow.this); if (returnVal == JFileChooser.APPROVE_OPTION) { File[] files = fileChooser.getSelectedFiles(); createScaleJobs(files); - } else { - System.out.println("Attachment cancelled by user."); } } }); From d2cb0053bb75f7801aa910cba9d78dfb724eca85 Mon Sep 17 00:00:00 2001 From: redwarp Date: Wed, 1 Jul 2015 11:53:28 +0200 Subject: [PATCH 66/71] Use file dialog instead of JFileChooser (looks more "system like") --- res/locale/Strings.properties | 1 + res/locale/Strings_fr.properties | 1 + .../tool/resizer/views/MainWindow.java | 43 +++++++++---------- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/res/locale/Strings.properties b/res/locale/Strings.properties index a2520af..88f4b25 100644 --- a/res/locale/Strings.properties +++ b/res/locale/Strings.properties @@ -22,3 +22,4 @@ save=Save save_tooltip=Hit the save button to keep this settings the next time you launch 9Patch Resizer keep_same_density_file=Keep the original
file for same density keep_same_density_file_tooltip=In case of lossy format such as jpeg, checking this option will make sure that, instead of saving a new image, the original file is copied in it's proper directory. If the input is in xhdpi, it will be copied in the xhdpi folder. +image_types=Choose .jpg or .png files diff --git a/res/locale/Strings_fr.properties b/res/locale/Strings_fr.properties index 4b2ea0b..09278be 100644 --- a/res/locale/Strings_fr.properties +++ b/res/locale/Strings_fr.properties @@ -22,3 +22,4 @@ save=Sauvegarder save_tooltip=Sauvegardez les r\u00E9glages courants pour les r\u00E9utiliser la prochaine fois que vous lancerez 9Patch Resizer keep_same_density_file=Garder le fichier
original pour la m\u00EAme densit\u00E9 keep_same_density_file_tooltip=Pour les formats, tel le jpg, o\u00F9 la compression d\u00E9grade l\'image, cochez cette option s\'assurera que le fichier original est copi\u00E9 dans le fichier de destination source, pour la m\u00EAme densit\u00E9. +image_types=Choisissez des fichiers .jpg ou .png diff --git a/src/net/redwarp/tool/resizer/views/MainWindow.java b/src/net/redwarp/tool/resizer/views/MainWindow.java index 7a4d53c..cf527f0 100644 --- a/src/net/redwarp/tool/resizer/views/MainWindow.java +++ b/src/net/redwarp/tool/resizer/views/MainWindow.java @@ -31,6 +31,7 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.io.File; +import java.io.FilenameFilter; import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -39,6 +40,7 @@ import javax.swing.*; import javax.swing.border.EmptyBorder; + @SuppressWarnings("serial") public class MainWindow extends JFrame { @@ -50,7 +52,8 @@ public class MainWindow extends JFrame { private JMenuItem mntmClear; private final Action action = new SwingAction(); private JComboBox inputDensityChoice; - private JFileChooser fileChooser; + // private JFileChooser fileChooser; + private FileDialog fileDialog; public MainWindow() { this.setSize(new Dimension(550, 400)); @@ -82,14 +85,15 @@ public MainWindow() { MainWindow.class.getResource("/img/red_small.png")); this.getContentPane().setLayout(new CardLayout(0, 0)); - - fileChooser = new JFileChooser() { + fileDialog = new FileDialog(this); + fileDialog.setFilenameFilter(new FilenameFilter() { @Override - public boolean accept(File f) { - return NameValidator.isFilenameValid(f.getName()); + public boolean accept(File dir, String name) { + return NameValidator.isFilenameValid(name); } - }; - fileChooser.setMultiSelectionEnabled(true); + }); + fileDialog.setMultipleMode(true); + fileDialog.setTitle(Localization.get("image_types")); this.getContentPane().add(createInputPanel(), "input"); this.getContentPane().add(createOutputPanel(), "output"); @@ -143,13 +147,7 @@ public void dragExit(Container source) { this.instructionLabel.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { - int returnVal = fileChooser.showOpenDialog(MainWindow.this); - - if (returnVal == JFileChooser.APPROVE_OPTION) { - File[] files = fileChooser.getSelectedFiles(); - - createScaleJobs(files); - } + displayImagePicker(); } }); @@ -159,6 +157,14 @@ public void mouseClicked(MouseEvent e) { return outputPanel; } + private void displayImagePicker() { + fileDialog.setVisible(true); + File[] files = fileDialog.getFiles(); + if (files != null) { + createScaleJobs(files); + } + } + private JPanel createInputPanel() { JPanel inputPanel = new JPanel(); inputPanel.setPreferredSize(new Dimension(10, 140)); @@ -183,18 +189,11 @@ public void actionPerformed(ActionEvent arg0) { this.xhdpiButton.setContentAreaFilled(false); inputPanel.add(this.xhdpiButton, BorderLayout.CENTER); - this.xhdpiButton.addMouseListener( new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { - int returnVal = fileChooser.showOpenDialog(MainWindow.this); - - if (returnVal == JFileChooser.APPROVE_OPTION) { - File[] files = fileChooser.getSelectedFiles(); - - createScaleJobs(files); - } + displayImagePicker(); } }); From 85794f1d67ddfa3528331096ef71ad9a215f73de Mon Sep 17 00:00:00 2001 From: redwarp Date: Wed, 1 Jul 2015 14:23:04 +0200 Subject: [PATCH 67/71] Update version --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 57b67e5..17672d2 100644 --- a/pom.xml +++ b/pom.xml @@ -20,12 +20,12 @@ resizer - 1.4.1 + 1.4.2 9Patch Resizer ${project.version} - 3 + 4 From f3256eaa9bb82e81be4e5887727ba7849564dc58 Mon Sep 17 00:00:00 2001 From: redwarp Date: Wed, 1 Jul 2015 14:24:49 +0200 Subject: [PATCH 68/71] Update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 623229f..082f358 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.4.1* +Current version : *1.4.2* You're using 9patch resizer for your apps ? Don't hesitate and leave me a message! From 8ae468684e6cae44cfa2f82fc067770e9ea27b6c Mon Sep 17 00:00:00 2001 From: Benoit Vermont Date: Tue, 28 Mar 2017 16:38:00 +0200 Subject: [PATCH 69/71] Update README.md Remove the donate section, was great when I was a student but, don't really need it no more. --- README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.md b/README.md index 082f358..e0807ab 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,3 @@ 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 ! - -I hope it'll prove as useful to you as it is useful to me. If you like it, and have too much cash in you hands, don't hesitate to donate. I will probably use it on beers though, so you should probably not bother, if you care for my health. - - From 7efe188b3a1bb7e740161c12e7c6a1b335ff8fe9 Mon Sep 17 00:00:00 2001 From: Benoit Vermont Date: Thu, 14 Feb 2019 17:15:23 +0100 Subject: [PATCH 70/71] Update issue templates --- .github/ISSUE_TEMPLATE/bug_report.md | 31 +++++++++++++++++++++++ .github/ISSUE_TEMPLATE/feature_request.md | 20 +++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..c616fa3 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,31 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: bug +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + - OS: [e.g. iOS] + - Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..11fc491 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: enhancement +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. From d434a2e7a4310136ef5ab6be808ea22669261940 Mon Sep 17 00:00:00 2001 From: Benoit Vermont Date: Thu, 12 Sep 2019 10:14:24 +0200 Subject: [PATCH 71/71] Update README.md --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index e0807ab..89661e1 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,12 @@ You're using 9patch resizer for your apps ? Don't hesitate and leave me a messag ## Roadmap +I'll be honest, I don't really maintain 9-Patch-Resizer anymore, as 9-patch are somewhat a thing of the past, and I use as many vector drawables as possible lately. + +I will of course consider bug fixes, but I might not have the bandwidth for feature requests. + +Sorry about that. + - [ ] A proper "Settings" panel, to handle issues such as jpeg compression, etc etc... - [ ] A few optimisations - [x] Command line support