Some UI refactoring

This commit is contained in:
cyian-1756 2018-05-27 14:54:04 -04:00
parent e5e8d097a0
commit 9d0399d648

View File

@ -115,7 +115,7 @@ public final class MainWindow implements Runnable, RipStatusHandler {
private static JButton configSaveDirButton; private static JButton configSaveDirButton;
private static JTextField configRetriesText; private static JTextField configRetriesText;
private static JCheckBox configAutoupdateCheckbox; private static JCheckBox configAutoupdateCheckbox;
private static JComboBox configLogLevelCombobox; private static JComboBox<String> configLogLevelCombobox;
private static JCheckBox configURLHistoryCheckbox; private static JCheckBox configURLHistoryCheckbox;
private static JCheckBox configPlaySound; private static JCheckBox configPlaySound;
private static JCheckBox configSaveOrderCheckbox; 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); configWindowPosition = addNewCheckbox(rb.getString("restore.window.position"), "window.position", true);
configURLHistoryCheckbox = addNewCheckbox(rb.getString("remember.url.history"), "remember.url_history", 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")); configLogLevelCombobox.setSelectedItem(Utils.getConfigString("log.level", "Log level: Debug"));
setLogLevel(configLogLevelCombobox.getSelectedItem().toString()); setLogLevel(configLogLevelCombobox.getSelectedItem().toString());
configSaveDirLabel = new JLabel(); configSaveDirLabel = new JLabel();
@ -504,30 +504,21 @@ public final class MainWindow implements Runnable, RipStatusHandler {
configSaveDirLabel.setToolTipText(configSaveDirLabel.getText()); configSaveDirLabel.setToolTipText(configSaveDirLabel.getText());
configSaveDirLabel.setHorizontalAlignment(JLabel.RIGHT); configSaveDirLabel.setHorizontalAlignment(JLabel.RIGHT);
configSaveDirButton = new JButton("Select Save Directory..."); configSaveDirButton = new JButton("Select Save Directory...");
gbc.gridy = 0; gbc.gridx = 0; configurationPanel.add(configUpdateLabel, gbc);
gbc.gridx = 1; configurationPanel.add(configUpdateButton, gbc); addItemToConfigGridBagConstraints(gbc, 0, configUpdateLabel, configUpdateButton);
gbc.gridy = 1; gbc.gridx = 0; configurationPanel.add(configAutoupdateCheckbox, gbc); addItemToConfigGridBagConstraints(gbc, 1, configAutoupdateCheckbox, configLogLevelCombobox);
gbc.gridx = 1; configurationPanel.add(configLogLevelCombobox, gbc); addItemToConfigGridBagConstraints(gbc, 2, configThreadsLabel, configThreadsText);
gbc.gridy = 2; gbc.gridx = 0; configurationPanel.add(configThreadsLabel, gbc); addItemToConfigGridBagConstraints(gbc, 3, configTimeoutLabel, configTimeoutText);
gbc.gridx = 1; configurationPanel.add(configThreadsText, gbc); addItemToConfigGridBagConstraints(gbc, 4, configRetriesLabel, configRetriesText);
gbc.gridy = 3; gbc.gridx = 0; configurationPanel.add(configTimeoutLabel, gbc); addItemToConfigGridBagConstraints(gbc, 5, configOverwriteCheckbox, configSaveOrderCheckbox);
gbc.gridx = 1; configurationPanel.add(configTimeoutText, gbc); addItemToConfigGridBagConstraints(gbc, 6, configPlaySound, configSaveLogs);
gbc.gridy = 4; gbc.gridx = 0; configurationPanel.add(configRetriesLabel, gbc); addItemToConfigGridBagConstraints(gbc, 7, configShowPopup, configSaveURLsOnly);
gbc.gridx = 1; configurationPanel.add(configRetriesText, gbc); addItemToConfigGridBagConstraints(gbc, 8, configClipboardAutorip, configSaveAlbumTitles);
gbc.gridy = 5; gbc.gridx = 0; configurationPanel.add(configOverwriteCheckbox, gbc); addItemToConfigGridBagConstraints(gbc, 9, configSaveDescriptions, configPreferMp4);
gbc.gridx = 1; configurationPanel.add(configSaveOrderCheckbox, gbc); addItemToConfigGridBagConstraints(gbc, 10, configWindowPosition, configURLHistoryCheckbox);
gbc.gridy = 6; gbc.gridx = 0; configurationPanel.add(configPlaySound, gbc); addItemToConfigGridBagConstraints(gbc, 11, configSaveDirLabel, configSaveDirButton);
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);
emptyPanel = new JPanel(); emptyPanel = new JPanel();
@ -550,6 +541,26 @@ public final class MainWindow implements Runnable, RipStatusHandler {
gbc.fill = GridBagConstraints.HORIZONTAL; 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() { private void setupHandlers() {
ripButton.addActionListener(new RipButtonHandler()); ripButton.addActionListener(new RipButtonHandler());
ripTextfield.addActionListener(new RipButtonHandler()); ripTextfield.addActionListener(new RipButtonHandler());
@ -897,7 +908,7 @@ public final class MainWindow implements Runnable, RipStatusHandler {
new ImageIcon(mainIcon)); new ImageIcon(mainIcon));
if (response == JOptionPane.YES_OPTION) { if (response == JOptionPane.YES_OPTION) {
try { try {
Desktop.getDesktop().browse(URI.create("http://github.com/4pr0n/ripme")); Desktop.getDesktop().browse(URI.create("http://github.com/ripmeapp/ripme"));
} catch (IOException e) { } catch (IOException e) {
logger.error("Exception while opening project home page", e); logger.error("Exception while opening project home page", e);
} }