From 2d2b6828b010b374731bb3de3945440977b77a66 Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Thu, 14 Feb 2019 14:20:13 +0000 Subject: [PATCH] JAL-3141 Moved 'Previously saved scheme' combo box preference out to 'Cancel changes' button. Tidied up the Summary box display. --- resources/lang/Messages.properties | 3 +- resources/lang/Messages_es.properties | 3 +- src/jalview/jbgui/GPreferences.java | 173 ++++++++++++++++++++------------- 3 files changed, 107 insertions(+), 72 deletions(-) diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index 681f4e3..4989149 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -1394,4 +1394,5 @@ label.keep_all_versions = Keep all versions label.rolled_backups = Rolled backup files label.previously_saved_scheme = Previously saved scheme label.no_backup_files = NO BACKUP FILES -label.include_backup_files = Include backup files \ No newline at end of file +label.include_backup_files = Include backup files +label.cancel_changes = Cancel changes \ No newline at end of file diff --git a/resources/lang/Messages_es.properties b/resources/lang/Messages_es.properties index d3f8c41..747b36d 100644 --- a/resources/lang/Messages_es.properties +++ b/resources/lang/Messages_es.properties @@ -1395,4 +1395,5 @@ label.keep_all_versions = Mantener todas las versiones label.rolled_backups = Ciclos resaldos label.previously_saved_scheme = Esquema previamente guardado label.no_backup_files = NO ARCHIVOS DE RESPALDOS -label.include_backup_files = Incluir archivos de respaldos \ No newline at end of file +label.include_backup_files = Incluir archivos de respaldos +label.cancel_changes = Cancelar cambios \ No newline at end of file diff --git a/src/jalview/jbgui/GPreferences.java b/src/jalview/jbgui/GPreferences.java index cc3d001..8c60b36 100755 --- a/src/jalview/jbgui/GPreferences.java +++ b/src/jalview/jbgui/GPreferences.java @@ -294,6 +294,8 @@ public class GPreferences extends JPanel protected JPanel presetsPanel = new JPanel(); + protected JButton revertButton = new JButton(); + protected JComboBox backupfilesPresetsCombo = new JComboBox<>(); protected JPanel suffixPanel = new JPanel(); @@ -1727,9 +1729,9 @@ public class GPreferences extends JPanel backupsTab.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); - gbc.weightx = 1.0; + gbc.weightx = 0.0; gbc.weighty = 0.0; - gbc.anchor = GridBagConstraints.NORTHWEST; + gbc.anchor = GridBagConstraints.FIRST_LINE_START; gbc.fill = GridBagConstraints.NONE; initBackupsTabPresetsPanel(); @@ -1737,7 +1739,6 @@ public class GPreferences extends JPanel initBackupsTabKeepFilesPanel(); initBackupsTabFilenameExamplesPanel(); - gbc.weightx = 0.5; enableBackupFiles.setFont(LABEL_FONT_BOLD); enableBackupFiles .setText(MessageManager.getString("label.enable_backupfiles")); @@ -1752,38 +1753,51 @@ public class GPreferences extends JPanel } }); - // enable checkbox 1 row + + // enable checkbox 1 col gbc.gridwidth = 1; + gbc.gridheight = 1; gbc.gridx = 0; - gbc.gridy = 0; + gbc.gridy = 0; // row 0 backupsTab.add(enableBackupFiles, gbc); + // summary of scheme box (over two rows) gbc.gridx = 1; - gbc.weightx = 1.0; + gbc.weightx = 0.0; gbc.gridheight = 2; - // gbc.anchor = GridBagConstraints.NORTHEAST; - // gbc.fill = GridBagConstraints.HORIZONTAL; + gbc.anchor = GridBagConstraints.FIRST_LINE_END; + gbc.fill = GridBagConstraints.BOTH; backupsTab.add(exampleFilesPanel, gbc); + gbc.gridheight = 1; + gbc.anchor = GridBagConstraints.FIRST_LINE_START; + gbc.fill = GridBagConstraints.NONE; + + // fill empty space on right + gbc.gridx++; + gbc.weightx = 1.0; + backupsTab.add(new JPanel(), gbc); + // schemes box + gbc.weightx = 0.0; gbc.gridx = 0; - gbc.gridy = 1; + gbc.gridy++; // row 1 backupsTab.add(presetsPanel, gbc); - gbc.anchor = GridBagConstraints.NORTHWEST; - gbc.fill = GridBagConstraints.NONE; + // gbc.anchor = GridBagConstraints.NORTHWEST; + // now using whole row gbc.gridwidth = 2; gbc.gridheight = 1; - // whole suffix panel next row + // keep files box gbc.gridx = 0; - gbc.gridy = 2; + gbc.gridy++; // row 2 backupsTab.add(keepfilesPanel, gbc); - // keep files panel - gbc.gridy = 3; + // filename strategy box + gbc.gridy++; // row 3 backupsTab.add(suffixPanel, gbc); // fill empty space - gbc.gridy = 4; + gbc.gridy++; // row 4 gbc.weighty = 1.0; backupsTab.add(new JPanel(), gbc); @@ -1791,6 +1805,7 @@ public class GPreferences extends JPanel return backupsTab; } + private final int BACKUPFILESSCHEMECUSTOMISE = 0; private final IntKeyStringValueEntry[] backupfilesPresetEntries = { new IntKeyStringValueEntry(1, MessageManager.getString("label.default")), @@ -1801,10 +1816,10 @@ public class GPreferences extends JPanel new IntKeyStringValueEntry(4, MessageManager.getString("label.rolled_backups")), // ... - new IntKeyStringValueEntry(255, - MessageManager.getString("label.previously_saved_scheme")), + // new IntKeyStringValueEntry(255, + // MessageManager.getString("label.previously_saved_scheme")), // IMPORTANT, keep "Custom" entry with key 0 (even though it appears last) - new IntKeyStringValueEntry(0, + new IntKeyStringValueEntry(BACKUPFILESSCHEMECUSTOMISE, MessageManager.getString("label.customise")) }; private final Map backupfilesPresetEntriesValues = new HashMap() @@ -1824,8 +1839,27 @@ public class GPreferences extends JPanel private JPanel initBackupsTabPresetsPanel() { - presetsPanel.setBorder( - new TitledBorder(MessageManager.getString("label.schemes"))); + + String title = MessageManager.getString("label.schemes"); + // TitledBorder tb = new TitledBorder(new EmptyBorder(0, 0, 0, 0), title); + // TitledBorder tb = new TitledBorder(title); + // tb.setTitleFont(LABEL_FONT); + // presetsPanel.setBorder(tb); + + presetsPanel.setLayout(new GridBagLayout()); + + GridBagConstraints gbc = new GridBagConstraints(); + gbc.weightx = 0.0; + gbc.weighty = 0.0; + gbc.anchor = GridBagConstraints.BASELINE_LEADING; + gbc.fill = GridBagConstraints.NONE; + gbc.gridwidth = 1; + gbc.gridheight = 1; + + // "Scheme: " + gbc.gridx = 0; + gbc.gridy = 0; + presetsPanel.add(new JLabel(title + ":"), gbc); for (int i = 0; i < backupfilesPresetEntries.length; i++) { @@ -1846,33 +1880,64 @@ public class GPreferences extends JPanel } }); - presetsPanel.add(backupfilesPresetsCombo); + // dropdown list of preset schemes + gbc.gridx = 1; + presetsPanel.add(backupfilesPresetsCombo, gbc); + + revertButton.setText(MessageManager.getString("label.cancel_changes")); + revertButton.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + loadLastSavedBackupsOptions(); + } + + }); + revertButton.setFont(LABEL_FONT); + + // "Cancel changes" button (aligned with combo box above) + gbc.gridx = 1; + gbc.gridy++; + presetsPanel.add(revertButton, gbc); + return presetsPanel; } + private JPanel initBackupsTabFilenameExamplesPanel() + { + String title = MessageManager + .getString("label.summary_of_backups_scheme"); + TitledBorder tb = new TitledBorder(title); + exampleFilesPanel.setBorder(tb); + exampleFilesPanel.setLayout(new GridBagLayout()); + + + backupfilesExampleLabel.setEditable(false); + backupfilesExampleLabel + .setBackground(exampleFilesPanel.getBackground()); + + updateBackupFilesExampleLabel(); + + GridBagConstraints gbc = new GridBagConstraints(); + gbc.weightx = 1.0; + gbc.weighty = 1.0; + gbc.fill = GridBagConstraints.NONE; + gbc.anchor = GridBagConstraints.FIRST_LINE_START; + + exampleFilesPanel.add(backupfilesExampleLabel, gbc); + return exampleFilesPanel; + } + private void backupsTabUpdatePresets() { IntKeyStringValueEntry entry = (IntKeyStringValueEntry) backupfilesPresetsCombo .getSelectedItem(); int key = entry.getKey(); String value = entry.getValue(); - // 0 reserved for "Custom" and 255 reserved or "Previously saved scheme" - boolean special = key == 0 || key == 255; - if (special) - { - if (key == 0) - { - // backupsSetCustomOptions(); - } - else if (key == 255) - { - loadLastSavedBackupsOptions(); - // switch to "Customise" scheme? probably not - // setComboIntStringKey(backupfilesPresetsCombo, 0); - } - } - else + // BACKUPFILESSCHEMECUSTOMISE (==0) reserved for "Custom" + if (key != BACKUPFILESSCHEMECUSTOMISE) { if (backupfilesPresetEntriesValues.containsKey(key)) { @@ -2135,38 +2200,6 @@ public class GPreferences extends JPanel return keepfilesPanel; } - private JPanel initBackupsTabFilenameExamplesPanel() - { - String title = MessageManager - .getString("label.summary_of_backups_scheme"); - TitledBorder tb = new TitledBorder(new EmptyBorder(0, 0, 0, 0), title); - // tb.setTitleFont(LABEL_FONT); - exampleFilesPanel.setBorder(tb); - exampleFilesPanel.setLayout(new GridBagLayout()); - - // inordinately difficult to get this titledborder the right size for the - // title - - backupfilesExampleLabel.setEditable(false); - backupfilesExampleLabel.setPreferredSize(new Dimension(280, 85)); - backupfilesExampleLabel.setAlignmentX(LEFT_ALIGNMENT); - backupfilesExampleLabel.setAlignmentY(TOP_ALIGNMENT); - - backupfilesExampleLabel.setFont(LABEL_FONT_ITALIC); - backupfilesExampleLabel - .setBackground(exampleFilesPanel.getBackground()); - - updateBackupFilesExampleLabel(); - exampleFilesPanel.setMinimumSize(new Dimension(280, 85)); - - GridBagConstraints gbc = new GridBagConstraints(); - gbc.anchor = GridBagConstraints.EAST; - - gbc.gridy = 0; - exampleFilesPanel.add(backupfilesExampleLabel, gbc); - return exampleFilesPanel; - } - protected void updateBackupFilesExampleLabel() { int exampleindex = 12; -- 1.7.10.2