From 9d0399d648d3cf985cf1bddff499e7bbc4c94069 Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Sun, 27 May 2018 14:54:04 -0400 Subject: [PATCH 1/5] Some UI refactoring --- .../com/rarchives/ripme/ui/MainWindow.java | 65 +++++++++++-------- 1 file changed, 38 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/rarchives/ripme/ui/MainWindow.java b/src/main/java/com/rarchives/ripme/ui/MainWindow.java index 59f75e06..5c5bba72 100644 --- a/src/main/java/com/rarchives/ripme/ui/MainWindow.java +++ b/src/main/java/com/rarchives/ripme/ui/MainWindow.java @@ -115,7 +115,7 @@ public final class MainWindow implements Runnable, RipStatusHandler { private static JButton configSaveDirButton; private static JTextField configRetriesText; private static JCheckBox configAutoupdateCheckbox; - private static JComboBox configLogLevelCombobox; + private static JComboBox configLogLevelCombobox; private static JCheckBox configURLHistoryCheckbox; private static JCheckBox configPlaySound; private static JCheckBox configSaveOrderCheckbox; @@ -491,7 +491,7 @@ public final class MainWindow implements Runnable, RipStatusHandler { configWindowPosition = addNewCheckbox(rb.getString("restore.window.position"), "window.position", true); configURLHistoryCheckbox = addNewCheckbox(rb.getString("remember.url.history"), "remember.url_history", true); - configLogLevelCombobox = new JComboBox(new String[] {"Log level: Error", "Log level: Warn", "Log level: Info", "Log level: Debug"}); + configLogLevelCombobox = new JComboBox<>(new String[] {"Log level: Error", "Log level: Warn", "Log level: Info", "Log level: Debug"}); configLogLevelCombobox.setSelectedItem(Utils.getConfigString("log.level", "Log level: Debug")); setLogLevel(configLogLevelCombobox.getSelectedItem().toString()); configSaveDirLabel = new JLabel(); @@ -504,30 +504,21 @@ public final class MainWindow implements Runnable, RipStatusHandler { configSaveDirLabel.setToolTipText(configSaveDirLabel.getText()); configSaveDirLabel.setHorizontalAlignment(JLabel.RIGHT); configSaveDirButton = new JButton("Select Save Directory..."); - gbc.gridy = 0; gbc.gridx = 0; configurationPanel.add(configUpdateLabel, gbc); - gbc.gridx = 1; configurationPanel.add(configUpdateButton, gbc); - gbc.gridy = 1; gbc.gridx = 0; configurationPanel.add(configAutoupdateCheckbox, gbc); - gbc.gridx = 1; configurationPanel.add(configLogLevelCombobox, gbc); - gbc.gridy = 2; gbc.gridx = 0; configurationPanel.add(configThreadsLabel, gbc); - gbc.gridx = 1; configurationPanel.add(configThreadsText, gbc); - gbc.gridy = 3; gbc.gridx = 0; configurationPanel.add(configTimeoutLabel, gbc); - gbc.gridx = 1; configurationPanel.add(configTimeoutText, gbc); - gbc.gridy = 4; gbc.gridx = 0; configurationPanel.add(configRetriesLabel, gbc); - gbc.gridx = 1; configurationPanel.add(configRetriesText, gbc); - gbc.gridy = 5; gbc.gridx = 0; configurationPanel.add(configOverwriteCheckbox, gbc); - gbc.gridx = 1; configurationPanel.add(configSaveOrderCheckbox, gbc); - gbc.gridy = 6; gbc.gridx = 0; configurationPanel.add(configPlaySound, gbc); - gbc.gridx = 1; configurationPanel.add(configSaveLogs, gbc); - gbc.gridy = 7; gbc.gridx = 0; configurationPanel.add(configShowPopup, gbc); - gbc.gridx = 1; configurationPanel.add(configSaveURLsOnly, gbc); - gbc.gridy = 8; gbc.gridx = 0; configurationPanel.add(configClipboardAutorip, gbc); - gbc.gridx = 1; configurationPanel.add(configSaveAlbumTitles, gbc); - gbc.gridy = 9; gbc.gridx = 0; configurationPanel.add(configSaveDescriptions, gbc); - gbc.gridx = 1; configurationPanel.add(configPreferMp4, gbc); - gbc.gridy = 10; gbc.gridx = 0; configurationPanel.add(configWindowPosition, gbc); - gbc.gridx = 1; configurationPanel.add(configURLHistoryCheckbox, gbc); - gbc.gridy = 11; gbc.gridx = 0; configurationPanel.add(configSaveDirLabel, gbc); - gbc.gridx = 1; configurationPanel.add(configSaveDirButton, gbc); + + addItemToConfigGridBagConstraints(gbc, 0, configUpdateLabel, configUpdateButton); + addItemToConfigGridBagConstraints(gbc, 1, configAutoupdateCheckbox, configLogLevelCombobox); + addItemToConfigGridBagConstraints(gbc, 2, configThreadsLabel, configThreadsText); + addItemToConfigGridBagConstraints(gbc, 3, configTimeoutLabel, configTimeoutText); + addItemToConfigGridBagConstraints(gbc, 4, configRetriesLabel, configRetriesText); + addItemToConfigGridBagConstraints(gbc, 5, configOverwriteCheckbox, configSaveOrderCheckbox); + addItemToConfigGridBagConstraints(gbc, 6, configPlaySound, configSaveLogs); + addItemToConfigGridBagConstraints(gbc, 7, configShowPopup, configSaveURLsOnly); + addItemToConfigGridBagConstraints(gbc, 8, configClipboardAutorip, configSaveAlbumTitles); + addItemToConfigGridBagConstraints(gbc, 9, configSaveDescriptions, configPreferMp4); + addItemToConfigGridBagConstraints(gbc, 10, configWindowPosition, configURLHistoryCheckbox); + addItemToConfigGridBagConstraints(gbc, 11, configSaveDirLabel, configSaveDirButton); + + emptyPanel = new JPanel(); @@ -550,6 +541,26 @@ public final class MainWindow implements Runnable, RipStatusHandler { gbc.fill = GridBagConstraints.HORIZONTAL; } + private void addItemToConfigGridBagConstraints(GridBagConstraints gbc, int gbcYValue, JLabel thing1ToAdd, JButton thing2ToAdd ) { + gbc.gridy = gbcYValue; gbc.gridx = 0; configurationPanel.add(thing1ToAdd, gbc); + gbc.gridx = 1; configurationPanel.add(thing2ToAdd, gbc); + } + + private void addItemToConfigGridBagConstraints(GridBagConstraints gbc, int gbcYValue, JLabel thing1ToAdd, JTextField thing2ToAdd ) { + gbc.gridy = gbcYValue; gbc.gridx = 0; configurationPanel.add(thing1ToAdd, gbc); + gbc.gridx = 1; configurationPanel.add(thing2ToAdd, gbc); + } + + private void addItemToConfigGridBagConstraints(GridBagConstraints gbc, int gbcYValue, JCheckBox thing1ToAdd, JCheckBox thing2ToAdd ) { + gbc.gridy = gbcYValue; gbc.gridx = 0; configurationPanel.add(thing1ToAdd, gbc); + gbc.gridx = 1; configurationPanel.add(thing2ToAdd, gbc); + } + + private void addItemToConfigGridBagConstraints(GridBagConstraints gbc, int gbcYValue, JCheckBox thing1ToAdd, JComboBox thing2ToAdd ) { + gbc.gridy = gbcYValue; gbc.gridx = 0; configurationPanel.add(thing1ToAdd, gbc); + gbc.gridx = 1; configurationPanel.add(thing2ToAdd, gbc); + } + private void setupHandlers() { ripButton.addActionListener(new RipButtonHandler()); ripTextfield.addActionListener(new RipButtonHandler()); @@ -897,7 +908,7 @@ public final class MainWindow implements Runnable, RipStatusHandler { new ImageIcon(mainIcon)); if (response == JOptionPane.YES_OPTION) { try { - Desktop.getDesktop().browse(URI.create("http://github.com/4pr0n/ripme")); + Desktop.getDesktop().browse(URI.create("http://github.com/ripmeapp/ripme")); } catch (IOException e) { logger.error("Exception while opening project home page", e); } From 25c3196f9bfd4838e9b74a26b64259a31450f580 Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Sun, 27 May 2018 15:45:11 -0400 Subject: [PATCH 2/5] Added ability to change locale at runtime and from gui --- .../com/rarchives/ripme/ui/MainWindow.java | 51 +++++++++++++++++-- .../java/com/rarchives/ripme/utils/Utils.java | 14 +++-- .../resources/LabelsBundle_en_US.properties | 37 ++++++++++++++ 3 files changed, 93 insertions(+), 9 deletions(-) create mode 100644 src/main/resources/LabelsBundle_en_US.properties diff --git a/src/main/java/com/rarchives/ripme/ui/MainWindow.java b/src/main/java/com/rarchives/ripme/ui/MainWindow.java index 5c5bba72..d1f43f00 100644 --- a/src/main/java/com/rarchives/ripme/ui/MainWindow.java +++ b/src/main/java/com/rarchives/ripme/ui/MainWindow.java @@ -127,6 +127,10 @@ public final class MainWindow implements Runnable, RipStatusHandler { private static JCheckBox configSaveDescriptions; private static JCheckBox configPreferMp4; private static JCheckBox configWindowPosition; + private static JComboBox configSelectLangComboBox; + private static JLabel configThreadsLabel; + private static JLabel configTimeoutLabel; + private static JLabel configRetriesLabel; private static TrayIcon trayIcon; private static MenuItem trayMenuMain; @@ -136,11 +140,11 @@ public final class MainWindow implements Runnable, RipStatusHandler { private static AbstractRipper ripper; - private ResourceBundle rb = Utils.getResourceBundle(); + private ResourceBundle rb = Utils.getResourceBundle(null); private void updateQueueLabel() { if (queueListModel.size() > 0) { - optionQueue.setText( rb.getString("Queue") + " (" + queueListModel.size() + ")"); + optionQueue.setText(rb.getString("Queue") + " (" + queueListModel.size() + ")"); } else { optionQueue.setText(rb.getString("Queue")); } @@ -471,9 +475,9 @@ public final class MainWindow implements Runnable, RipStatusHandler { // TODO Configuration components configUpdateButton = new JButton(rb.getString("check.for.updates")); configUpdateLabel = new JLabel( rb.getString("current.version") + ": " + UpdateUtils.getThisJarVersion(), JLabel.RIGHT); - JLabel configThreadsLabel = new JLabel(rb.getString("max.download.threads") + ":", JLabel.RIGHT); - JLabel configTimeoutLabel = new JLabel(rb.getString("timeout.mill"), JLabel.RIGHT); - JLabel configRetriesLabel = new JLabel(rb.getString("retry.download.count"), JLabel.RIGHT); + configThreadsLabel = new JLabel(rb.getString("max.download.threads") + ":", JLabel.RIGHT); + configTimeoutLabel = new JLabel(rb.getString("timeout.mill"), JLabel.RIGHT); + configRetriesLabel = new JLabel(rb.getString("retry.download.count"), JLabel.RIGHT); configThreadsText = new JTextField(Integer.toString(Utils.getConfigInteger("threads.size", 3))); configTimeoutText = new JTextField(Integer.toString(Utils.getConfigInteger("download.timeout", 60000))); configRetriesText = new JTextField(Integer.toString(Utils.getConfigInteger("download.retries", 3))); @@ -492,6 +496,7 @@ public final class MainWindow implements Runnable, RipStatusHandler { configURLHistoryCheckbox = addNewCheckbox(rb.getString("remember.url.history"), "remember.url_history", true); configLogLevelCombobox = new JComboBox<>(new String[] {"Log level: Error", "Log level: Warn", "Log level: Info", "Log level: Debug"}); + configSelectLangComboBox = new JComboBox<>(new String[] {"en_US", "de_DE", "es_ES", "fr_CH", "kr_KR", "pt_PT"}); configLogLevelCombobox.setSelectedItem(Utils.getConfigString("log.level", "Log level: Debug")); setLogLevel(configLogLevelCombobox.getSelectedItem().toString()); configSaveDirLabel = new JLabel(); @@ -517,6 +522,7 @@ public final class MainWindow implements Runnable, RipStatusHandler { addItemToConfigGridBagConstraints(gbc, 9, configSaveDescriptions, configPreferMp4); addItemToConfigGridBagConstraints(gbc, 10, configWindowPosition, configURLHistoryCheckbox); addItemToConfigGridBagConstraints(gbc, 11, configSaveDirLabel, configSaveDirButton); + addItemToConfigGridBagConstraints(gbc, 12, configSelectLangComboBox); @@ -561,6 +567,36 @@ public final class MainWindow implements Runnable, RipStatusHandler { gbc.gridx = 1; configurationPanel.add(thing2ToAdd, gbc); } + private void addItemToConfigGridBagConstraints(GridBagConstraints gbc, int gbcYValue, JComboBox thing1ToAdd ) { + gbc.gridy = gbcYValue; gbc.gridx = 0; configurationPanel.add(thing1ToAdd, gbc); + } + + private void changeLocale() { + statusLabel.setText(rb.getString("inactive")); + configUpdateButton.setText(rb.getString("check.for.updates")); + configUpdateLabel.setText(rb.getString("current.version") + ": " + UpdateUtils.getThisJarVersion()); + configThreadsLabel.setText(rb.getString("max.download.threads")); + configTimeoutLabel.setText(rb.getString("timeout.mill")); + configRetriesLabel.setText(rb.getString("retry.download.count")); + configOverwriteCheckbox.setText(rb.getString("overwrite.existing.files")); + configAutoupdateCheckbox.setText(rb.getString("auto.update")); + configPlaySound.setText(rb.getString("sound.when.rip.completes")); + configShowPopup.setText(rb.getString("notification.when.rip.starts")); + configSaveOrderCheckbox.setText(rb.getString("preserve.order")); + configSaveLogs.setText(rb.getString("save.logs")); + configSaveURLsOnly.setText(rb.getString("save.urls.only")); + configSaveAlbumTitles.setText(rb.getString("save.album.titles")); + configClipboardAutorip.setText(rb.getString("autorip.from.clipboard")); + configSaveDescriptions.setText(rb.getString("save.descriptions")); + configPreferMp4.setText(rb.getString("prefer.mp4.over.gif")); + configWindowPosition.setText(rb.getString("restore.window.position")); + configURLHistoryCheckbox.setText(rb.getString("remember.url.history")); + optionLog.setText(rb.getString("Log")); + optionHistory.setText(rb.getString("History")); + optionQueue.setText(rb.getString("Queue")); + optionConfiguration.setText(rb.getString("Configuration")); + } + private void setupHandlers() { ripButton.addActionListener(new RipButtonHandler()); ripTextfield.addActionListener(new RipButtonHandler()); @@ -757,6 +793,11 @@ public final class MainWindow implements Runnable, RipStatusHandler { String level = ((JComboBox) arg0.getSource()).getSelectedItem().toString(); setLogLevel(level); }); + configSelectLangComboBox.addActionListener(arg0 -> { + String level = ((JComboBox) arg0.getSource()).getSelectedItem().toString(); + rb = Utils.getResourceBundle(level); + changeLocale(); + }); configSaveDirLabel.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { diff --git a/src/main/java/com/rarchives/ripme/utils/Utils.java b/src/main/java/com/rarchives/ripme/utils/Utils.java index 828d552a..8b91e5cd 100644 --- a/src/main/java/com/rarchives/ripme/utils/Utils.java +++ b/src/main/java/com/rarchives/ripme/utils/Utils.java @@ -686,10 +686,16 @@ public class Utils { * * @return Returns the default resource bundle using the language specified in the config file. */ - public static ResourceBundle getResourceBundle() { - if (!getConfigString("lang", "").equals("")) { - String[] langCode = getConfigString("lang", "").split("_"); - logger.info("Setting locale to " + getConfigString("lang", "")); + public static ResourceBundle getResourceBundle(String langSelect) { + if (langSelect == null) { + if (!getConfigString("lang", "").equals("")) { + String[] langCode = getConfigString("lang", "").split("_"); + logger.info("Setting locale to " + getConfigString("lang", "")); + return ResourceBundle.getBundle("LabelsBundle", new Locale(langCode[0], langCode[1]), new UTF8Control()); + } + } else { + String[] langCode = langSelect.split("_"); + logger.info("Setting locale to " + langSelect); return ResourceBundle.getBundle("LabelsBundle", new Locale(langCode[0], langCode[1]), new UTF8Control()); } try { diff --git a/src/main/resources/LabelsBundle_en_US.properties b/src/main/resources/LabelsBundle_en_US.properties new file mode 100644 index 00000000..3a42ab0c --- /dev/null +++ b/src/main/resources/LabelsBundle_en_US.properties @@ -0,0 +1,37 @@ +Log = Log +History = History +created = created +modified = modified +Queue = Queue +Configuration = Configuration + +# Keys for the Configuration menu + +current.version = Current version +check.for.updates = Check for updates +auto.update = Auto-update? +max.download.threads = Maximum download threads +timeout.mill = Timeout (in milliseconds): +retry.download.count = Retry download count +overwrite.existing.files = Overwrite existing files? +sound.when.rip.completes = Sound when rip completes +preserve.order = Preserve order +save.logs = Save logs +notification.when.rip.starts = Notification when rip starts +save.urls.only = Save URLs only +save.album.titles = Save album titles +autorip.from.clipboard = Autorip from Clipboard +save.descriptions = Save descriptions +prefer.mp4.over.gif = Prefer MP4 over GIF +restore.window.position = Restore window position +remember.url.history = Remember URL history +loading.history.from = Loading history from + +# Misc UI keys + +loading.history.from.configuration = Loading history from configuration +interrupted.while.waiting.to.rip.next.album = Interrupted while waiting to rip next album +inactive = Inactive +re-rip.checked = Re-rip Checked +remove = Remove +clear = Clear \ No newline at end of file From 83afd43305fa3605b28d38e2f86d888830d12d20 Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Sun, 27 May 2018 18:50:15 -0400 Subject: [PATCH 3/5] Added missing : --- src/main/resources/LabelsBundle.properties | 2 +- src/main/resources/LabelsBundle_en_US.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/LabelsBundle.properties b/src/main/resources/LabelsBundle.properties index 3a42ab0c..f991d02f 100644 --- a/src/main/resources/LabelsBundle.properties +++ b/src/main/resources/LabelsBundle.properties @@ -10,7 +10,7 @@ Configuration = Configuration current.version = Current version check.for.updates = Check for updates auto.update = Auto-update? -max.download.threads = Maximum download threads +max.download.threads = Maximum download threads: timeout.mill = Timeout (in milliseconds): retry.download.count = Retry download count overwrite.existing.files = Overwrite existing files? diff --git a/src/main/resources/LabelsBundle_en_US.properties b/src/main/resources/LabelsBundle_en_US.properties index 3a42ab0c..f991d02f 100644 --- a/src/main/resources/LabelsBundle_en_US.properties +++ b/src/main/resources/LabelsBundle_en_US.properties @@ -10,7 +10,7 @@ Configuration = Configuration current.version = Current version check.for.updates = Check for updates auto.update = Auto-update? -max.download.threads = Maximum download threads +max.download.threads = Maximum download threads: timeout.mill = Timeout (in milliseconds): retry.download.count = Retry download count overwrite.existing.files = Overwrite existing files? From 3a6e379d3c4a4cace7ac4204743b0c63fe257098 Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Sun, 27 May 2018 18:53:02 -0400 Subject: [PATCH 4/5] Minor refactoring --- src/main/java/com/rarchives/ripme/ui/MainWindow.java | 2 +- src/main/java/com/rarchives/ripme/utils/Utils.java | 8 ++++---- ...dle_id_ID.properties => LabelsBundle_in_ID.properties} | 0 3 files changed, 5 insertions(+), 5 deletions(-) rename src/main/resources/{LabelsBundle_id_ID.properties => LabelsBundle_in_ID.properties} (100%) diff --git a/src/main/java/com/rarchives/ripme/ui/MainWindow.java b/src/main/java/com/rarchives/ripme/ui/MainWindow.java index d1f43f00..fddaba8a 100644 --- a/src/main/java/com/rarchives/ripme/ui/MainWindow.java +++ b/src/main/java/com/rarchives/ripme/ui/MainWindow.java @@ -496,7 +496,7 @@ public final class MainWindow implements Runnable, RipStatusHandler { configURLHistoryCheckbox = addNewCheckbox(rb.getString("remember.url.history"), "remember.url_history", true); configLogLevelCombobox = new JComboBox<>(new String[] {"Log level: Error", "Log level: Warn", "Log level: Info", "Log level: Debug"}); - configSelectLangComboBox = new JComboBox<>(new String[] {"en_US", "de_DE", "es_ES", "fr_CH", "kr_KR", "pt_PT"}); + configSelectLangComboBox = new JComboBox<>(new String[] {"en_US", "de_DE", "es_ES", "fr_CH", "kr_KR", "pt_PT", "fi_FI", "in_ID", "porrisavvo_FI"}); configLogLevelCombobox.setSelectedItem(Utils.getConfigString("log.level", "Log level: Debug")); setLogLevel(configLogLevelCombobox.getSelectedItem().toString()); configSaveDirLabel = new JLabel(); diff --git a/src/main/java/com/rarchives/ripme/utils/Utils.java b/src/main/java/com/rarchives/ripme/utils/Utils.java index 8b91e5cd..e773a305 100644 --- a/src/main/java/com/rarchives/ripme/utils/Utils.java +++ b/src/main/java/com/rarchives/ripme/utils/Utils.java @@ -699,11 +699,11 @@ public class Utils { return ResourceBundle.getBundle("LabelsBundle", new Locale(langCode[0], langCode[1]), new UTF8Control()); } try { - ResourceBundle rb = ResourceBundle.getBundle("LabelsBundle", Locale.getDefault(), new UTF8Control()); - return rb; + logger.info("Setting locale to default"); + return ResourceBundle.getBundle("LabelsBundle", Locale.getDefault(), new UTF8Control()); } catch (MissingResourceException e) { - ResourceBundle rb = ResourceBundle.getBundle("LabelsBundle", Locale.ROOT); - return rb; + logger.info("Setting locale to root"); + return ResourceBundle.getBundle("LabelsBundle", Locale.ROOT); } } } diff --git a/src/main/resources/LabelsBundle_id_ID.properties b/src/main/resources/LabelsBundle_in_ID.properties similarity index 100% rename from src/main/resources/LabelsBundle_id_ID.properties rename to src/main/resources/LabelsBundle_in_ID.properties From 3d42d7b55fcd82f7a39668461add1da20cf581c5 Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Sun, 27 May 2018 19:11:00 -0400 Subject: [PATCH 5/5] Changed up UI a bit --- src/main/java/com/rarchives/ripme/ui/MainWindow.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/rarchives/ripme/ui/MainWindow.java b/src/main/java/com/rarchives/ripme/ui/MainWindow.java index fddaba8a..2eb45630 100644 --- a/src/main/java/com/rarchives/ripme/ui/MainWindow.java +++ b/src/main/java/com/rarchives/ripme/ui/MainWindow.java @@ -521,8 +521,8 @@ public final class MainWindow implements Runnable, RipStatusHandler { addItemToConfigGridBagConstraints(gbc, 8, configClipboardAutorip, configSaveAlbumTitles); addItemToConfigGridBagConstraints(gbc, 9, configSaveDescriptions, configPreferMp4); addItemToConfigGridBagConstraints(gbc, 10, configWindowPosition, configURLHistoryCheckbox); - addItemToConfigGridBagConstraints(gbc, 11, configSaveDirLabel, configSaveDirButton); - addItemToConfigGridBagConstraints(gbc, 12, configSelectLangComboBox); + addItemToConfigGridBagConstraints(gbc, 11, configSelectLangComboBox); + addItemToConfigGridBagConstraints(gbc, 12, configSaveDirLabel, configSaveDirButton);