From d9fbdbf342baf8c897566d4ef75ea4adf10bd35a Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Thu, 1 Nov 2018 14:27:00 +0000 Subject: [PATCH] JAL-3141 Preferences 'Backups' tab now fits. Moved initial option setting into Preferences with all the other preference initial setting. --- resources/lang/Messages.properties | 13 +-- src/jalview/gui/Preferences.java | 27 ++++++ src/jalview/jbgui/GPreferences.java | 158 +++++++++++++++++++++++------------ 3 files changed, 140 insertions(+), 58 deletions(-) diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index f7cf83d..0d584b8 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -1364,7 +1364,7 @@ label.most_polymer_residues = Most Polymer Residues label.cached_structures = Cached Structures label.free_text_search = Free Text Search label.backupfiles_confirm_delete = Confirm delete -label.backupfiles_confirm_delete_old_files = Delete the following older version files? +label.backupfiles_confirm_delete_old_files = Delete the following older backup files? label.backupfiles_confirm_save_file = Confirm save file label.backupfiles_confirm_save_file_backupfiles_roll_wrong = Something possibly went wrong with the backups of this file, write the new file anyway? label.backups = Backups @@ -1376,12 +1376,13 @@ label.suffix_template_tooltip = %n in the template will be replaced by the index label.index_digits = Number of digits to use for the index default.suffix_index_digits_min = 1 default.suffix_index_digits_max = 6 -label.examples = Examples +label.example_filenames = Example filenames label.suffix_example_filenames = Some example filenames using these settings: -label.increment_index = Increment filename indexes (like version numbers). Newest file has largest index. -label.reverse_roll = Reverse and "roll" indexes (like rolled log files). Newest files is always indexed as 1. +label.increment_index = Increment suffix indexes (like version files) - newest file has largest index. +label.reverse_roll = Reverse and "roll" suffix indexes (like log files) - newest file is always index 1. label.keep_files = Keep Files label.keep_all_backup_files = Keep all backup files label.keep_only_this_number_of_backup_files = Keep only this number of most recent backup files -label.confirm_delete = Confirm deletion of old backup files -label.auto_delete = Automatically delete old backup files +label.old_backup_files = Old backup files: +label.confirm_delete = Confirm deletions +label.auto_delete = Automatically delete diff --git a/src/jalview/gui/Preferences.java b/src/jalview/gui/Preferences.java index 8e02c2c..99e1cc8 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -547,6 +547,33 @@ public class Preferences extends GPreferences annotations_actionPerformed(null); // update the display of the annotation // settings + + + /* + * Set Backups tab defaults + */ + enableBackupFiles + .setSelected(Cache.getDefault(BackupFiles.ENABLED, true)); + suffixTemplate.setText(Cache.getDefault(BackupFiles.SUFFIX, "-v"+BackupFiles.getNumPlaceHolder())); + suffixDigitsSpinner.setValue(Cache.getDefault(BackupFiles.SUFFIX_DIGITS, 3)); + suffixReverse.setSelected( + Cache.getDefault(BackupFiles.REVERSE_ORDER, false)); + backupfilesKeepAll + .setSelected(Cache.getDefault(BackupFiles.NO_MAX, false)); + backupfilesRollMaxSpinner + .setValue(Cache.getDefault(BackupFiles.ROLL_MAX, 4)); + backupfilesConfirmDelete.setSelected( + Cache.getDefault(BackupFiles.CONFIRM_DELETE_OLD, true)); + backupsOptionsSetEnabled(enableBackupFiles.isSelected()); + /* + suffixPanel.setPreferredSize( + new Dimension(width, suffixPanel.getHeight())); + keepfilesPanel.setPreferredSize( + new Dimension(width, keepfilesPanel.getHeight())); + exampleFilesPanel.setPreferredSize( + new Dimension(width, exampleFilesPanel.getHeight())); + */ + } /** diff --git a/src/jalview/jbgui/GPreferences.java b/src/jalview/jbgui/GPreferences.java index 904f559..a99d018 100755 --- a/src/jalview/jbgui/GPreferences.java +++ b/src/jalview/jbgui/GPreferences.java @@ -20,7 +20,6 @@ */ package jalview.jbgui; -import jalview.bin.Cache; import jalview.fts.core.FTSDataColumnPreferences; import jalview.fts.core.FTSDataColumnPreferences.PreferenceSource; import jalview.fts.service.pdb.PDBFTSRestClient; @@ -28,7 +27,6 @@ import jalview.gui.JalviewBooleanRadioButtons; import jalview.gui.JvSwingUtils; import jalview.gui.StructureViewer.ViewerType; import jalview.io.BackupFilenameFilter; -import jalview.io.BackupFiles; import jalview.util.MessageManager; import java.awt.BorderLayout; @@ -282,7 +280,7 @@ public class GPreferences extends JPanel /* * Backups tab components * a lot of these are member variables instead of local variables only so that they - * can be enabled/disabled easily + * can be enabled/disabled easily in one go */ protected JCheckBox enableBackupFiles = new JCheckBox(); @@ -307,12 +305,12 @@ public class GPreferences extends JPanel protected JSpinner backupfilesRollMaxSpinner = new JSpinner(); + protected JLabel oldBackupFilesLabel = new JLabel(); + protected JalviewBooleanRadioButtons backupfilesConfirmDelete = new JalviewBooleanRadioButtons(); protected JLabel exampleLabel = new JLabel(); - protected JScrollPane exampleScrollPane = new JScrollPane(); - protected JTextArea backupfilesExampleLabel = new JTextArea(); /** @@ -1692,15 +1690,13 @@ public class GPreferences extends JPanel private JPanel initBackupsTab() { JPanel backupsTab = new JPanel(); - backupsTab.setBorder(new TitledBorder(MessageManager - .getString("label.backup_files"))); + // backupsTab.setBorder(new TitledBorder(MessageManager + // .getString("label.backup_files"))); backupsTab.setLayout(new GridBagLayout()); enableBackupFiles.setFont(LABEL_FONT); enableBackupFiles.setText( MessageManager.getString("label.enable_backupfiles")); - enableBackupFiles - .setSelected(Cache.getDefault(BackupFiles.ENABLED, true)); enableBackupFiles.addActionListener(new ActionListener() { @Override @@ -1716,27 +1712,51 @@ public class GPreferences extends JPanel gbc.weightx = 1.0; gbc.weighty = 0.0; gbc.anchor = GridBagConstraints.NORTHWEST; + gbc.fill = GridBagConstraints.NONE; // enable checkbox 1 row gbc.gridwidth = 1; gbc.gridy = 0; backupsTab.add(enableBackupFiles, gbc); - // whole suffix panel next row initBackupsTabSuffixPanel(); + initBackupsTabKeepFilesPanel(); + initBackupsTabFilenameExamplesPanel(); + + /* + // set widths of the panels to the max one + int maxw = suffixPanel.getWidth(); + if (maxw < keepfilesPanel.getWidth()) + { + maxw = keepfilesPanel.getWidth(); + } + if (maxw < exampleFilesPanel.getWidth()) + { + maxw = exampleFilesPanel.getWidth(); + } + suffixPanel.setSize(suffixPanel.getHeight(), maxw); + keepfilesPanel.setSize(keepfilesPanel.getHeight(), maxw); + exampleFilesPanel.setSize(exampleFilesPanel.getHeight(), maxw); + */ + + // whole suffix panel next row gbc.gridy = 1; backupsTab.add(suffixPanel, gbc); // keep files panel - initBackupsTabKeepFilesPanel(); gbc.gridy = 2; backupsTab.add(keepfilesPanel, gbc); // whole examples panel next row - initBackupsTabFilenameExamplesPanel(); gbc.gridy = 3; backupsTab.add(exampleFilesPanel, gbc); + // fill empty space + gbc.gridy = 4; + gbc.weighty = 1.0; + backupsTab.add(new JPanel(), gbc); + + backupsOptionsSetEnabled(enableBackupFiles.isSelected()); return backupsTab; } @@ -1752,8 +1772,6 @@ public class GPreferences extends JPanel suffixTemplateLabel.setHorizontalAlignment(SwingConstants.LEFT); suffixTemplateLabel.setFont(LABEL_FONT); - String suffix = Cache.getDefault(BackupFiles.SUFFIX, BackupFiles.getNumPlaceHolder()); - suffixTemplate.setText(suffix); final String tooltip = JvSwingUtils.wrapTooltip(true, MessageManager .getString("label.suffix_template_tooltip")); suffixTemplate.setToolTipText(tooltip); @@ -1821,11 +1839,17 @@ public class GPreferences extends JPanel "Exception setting suffix digits max from default.suffix_index_digits_max label, setting to " + defaultmax); } - setIntegerSpinner(suffixDigitsSpinner, defaultmin, defaultmax, - Cache.getDefault(BackupFiles.SUFFIX_DIGITS, 3)); + ChangeListener c = new ChangeListener() + { + @Override + public void stateChanged(ChangeEvent e) + { + updateBackupFilesExampleLabel(); + } + + }; + setIntegerSpinner(suffixDigitsSpinner, defaultmin, defaultmax, 3, c); - suffixReverse.setSelected( - Cache.getDefault(BackupFiles.REVERSE_ORDER, false)); suffixReverse.setLabels( MessageManager.getString("label.reverse_roll"), MessageManager.getString("label.increment_index")); @@ -1885,8 +1909,6 @@ public class GPreferences extends JPanel new TitledBorder(MessageManager.getString("label.keep_files"))); keepfilesPanel.setLayout(new GridBagLayout()); - backupfilesKeepAll - .setSelected(Cache.getDefault(BackupFiles.NO_MAX, true)); backupfilesKeepAll.setLabels( MessageManager.getString("label.keep_all_backup_files"), MessageManager.getString( @@ -1910,11 +1932,17 @@ public class GPreferences extends JPanel } }); - setIntegerSpinner(backupfilesRollMaxSpinner, 1, 999, - Cache.getDefault(BackupFiles.ROLL_MAX, 3)); + ChangeListener c = new ChangeListener() + { + @Override + public void stateChanged(ChangeEvent e) + { + updateBackupFilesExampleLabel(); + } + + }; + setIntegerSpinner(backupfilesRollMaxSpinner, 1, 999, 4, true, c); - backupfilesConfirmDelete.setSelected( - Cache.getDefault(BackupFiles.CONFIRM_DELETE_OLD, true)); backupfilesConfirmDelete.setLabels( MessageManager.getString("label.confirm_delete"), MessageManager.getString("label.auto_delete")); @@ -1942,7 +1970,7 @@ public class GPreferences extends JPanel keepfilesPanel.add(backupfilesKeepAll.getFalseButton(), kgbc); kgbc.gridx = 1; - // kgbc.fill = GridBagConstraints.HORIZONTAL; + kgbc.gridwidth = GridBagConstraints.REMAINDER; keepfilesPanel.add(backupfilesRollMaxSpinner, kgbc); // third row (indented) @@ -1953,48 +1981,61 @@ public class GPreferences extends JPanel kgbc.gridwidth = GridBagConstraints.REMAINDER; kgbc.fill = GridBagConstraints.HORIZONTAL; kgbc.weightx = 1.0; + /* keepfilesPanel.add(backupfilesConfirmDelete.getTrueButton(), kgbc); - + // fourth row (indented) kgbc.gridy = 3; keepfilesPanel.add(backupfilesConfirmDelete.getFalseButton(), kgbc); + */ + + JPanel jp = new JPanel(); + jp.setLayout(new FlowLayout()); + oldBackupFilesLabel + .setText(MessageManager.getString("label.old_backup_files")); + oldBackupFilesLabel.setFont(LABEL_FONT); + oldBackupFilesLabel.setHorizontalAlignment(SwingConstants.LEFT); + jp.add(oldBackupFilesLabel); + jp.add(backupfilesConfirmDelete.getTrueButton()); + jp.add(backupfilesConfirmDelete.getFalseButton()); + keepfilesPanel.add(jp, kgbc); + return keepfilesPanel; } private JPanel initBackupsTabFilenameExamplesPanel() { exampleFilesPanel.setBorder(new TitledBorder( - MessageManager.getString("label.examples"))); + MessageManager.getString("label.example_filenames"))); exampleFilesPanel.setLayout(new GridBagLayout()); + /* exampleLabel.setText( MessageManager.getString("label.suffix_example_filenames")); exampleLabel.setFont(LABEL_FONT); exampleLabel.setHorizontalAlignment(SwingConstants.LEFT); + */ backupfilesExampleLabel.setEditable(false); - backupfilesExampleLabel.setPreferredSize(new Dimension(300, 100)); + backupfilesExampleLabel.setPreferredSize(new Dimension(400, 85)); backupfilesExampleLabel.setAlignmentX(LEFT_ALIGNMENT); backupfilesExampleLabel.setAlignmentY(TOP_ALIGNMENT); backupfilesExampleLabel.setFont(LABEL_FONT_ITALIC); backupfilesExampleLabel.setBackground(exampleLabel.getBackground()); - /* - exampleScrollPane.setBounds(0, 0, 200, 100); - exampleScrollPane.setPreferredSize(new Dimension(800, 800)); - exampleScrollPane.add(backupfilesExampleLabel); - */ updateBackupFilesExampleLabel(); GridBagConstraints gbc = new GridBagConstraints(); gbc.anchor = GridBagConstraints.WEST; + gbc.fill = GridBagConstraints.NONE; gbc.gridy = 0; + /* exampleFilesPanel.add(exampleLabel, gbc); gbc.gridy = 1; + */ exampleFilesPanel.add(backupfilesExampleLabel, gbc); - // exampleFilesPanel.add(exampleScrollPane, gbc); return exampleFilesPanel; } @@ -2028,7 +2069,7 @@ public class GPreferences extends JPanel "Failed casting (Integer) backupfilesRollMaxSpinner.getValue()"); } - int surround = 3; + int surround = 2; StringBuilder exampleSB = new StringBuilder(); boolean firstLine = true; if (reverse) @@ -2038,11 +2079,11 @@ public class GPreferences extends JPanel int max = keepAll ? exampleindex : rollMax; for (int index = min; index <= max; index++) { - if (index == min + surround && index <= max - surround) + if (index == min + surround && index < max) { exampleSB.append("\n..."); } - else if (index > min + surround && index <= max - surround) + else if (index > min + surround && index < max) { // nothing } @@ -2083,11 +2124,11 @@ public class GPreferences extends JPanel for (int index = min; index <= max; index++) { - if (index == min + surround && index <= max - surround) + if (index == min + surround && index < max) { exampleSB.append("\n..."); } - else if (index > min + surround && index <= max - surround) + else if (index > min + surround && index < max) { // nothing } @@ -2123,8 +2164,27 @@ public class GPreferences extends JPanel backupfilesExampleLabel.setText(exampleSB.toString()); } - protected void setIntegerSpinner(JSpinner s, int min, - int max, int def) + protected void setIntegerSpinner(JSpinner s, int min, int max, int def, + boolean useExistingVal, ChangeListener c) + { + int i = def; + if (useExistingVal) + { + try + { + i = Integer.parseInt((String) s.getValue()); + } catch (Exception e) + { + System.out.println( + "Exception casting the initial value of s.getValue()"); + } + } + + setIntegerSpinner(s, min, max, i, c); + } + + protected void setIntegerSpinner(JSpinner s, int min, int max, int def, + ChangeListener c) { // integer spinner for number of digits if (def > max) @@ -2134,15 +2194,7 @@ public class GPreferences extends JPanel SpinnerModel sModel = new SpinnerNumberModel(def, min, max, 1); s.setModel(sModel); - s.addChangeListener(new ChangeListener() - { - @Override - public void stateChanged(ChangeEvent e) - { - updateBackupFilesExampleLabel(); - } - - }); + s.addChangeListener(c); } @@ -2162,11 +2214,13 @@ public class GPreferences extends JPanel private void keepRollMaxOptionsEnabled(boolean enabled) { + oldBackupFilesLabel.setEnabled(enabled); backupfilesRollMaxSpinner.setEnabled(enabled); backupfilesConfirmDelete.setEnabled(enabled); } - private void backupsOptionsSetEnabled(boolean enabled) + + protected void backupsOptionsSetEnabled(boolean enabled) { suffixPanel.setEnabled(enabled); keepfilesPanel.setEnabled(enabled); @@ -2179,9 +2233,9 @@ public class GPreferences extends JPanel suffixReverse.setEnabled(enabled); backupfilesKeepAll.setEnabled(enabled); backupfilesRollMaxSpinner.setEnabled(enabled); + oldBackupFilesLabel.setEnabled(enabled); backupfilesConfirmDelete.setEnabled(enabled); exampleLabel.setEnabled(enabled); - exampleScrollPane.setEnabled(enabled); backupfilesExampleLabel.setEnabled(enabled); keepRollMaxOptionsEnabled(enabled && !backupfilesKeepAll.isSelected()); -- 1.7.10.2