+ BackupFilesPresetEntry savedPreset = BackupFilesPresetEntry
+ .getSavedBackupEntry();
+ enableBackupFiles
+ .setSelected(Cache.getDefault(BackupFiles.ENABLED, !Platform.isJS()));
+
+ BackupFilesPresetEntry backupfilesCustomEntry = BackupFilesPresetEntry
+ .createBackupFilesPresetEntry(Cache
+ .getDefault(BackupFilesPresetEntry.CUSTOMCONFIG, null));
+ if (backupfilesCustomEntry == null)
+ {
+ backupfilesCustomEntry = BackupFilesPresetEntry.backupfilesPresetEntriesValues
+ .get(BackupFilesPresetEntry.BACKUPFILESSCHEMEDEFAULT);
+ }
+ BackupFilesPresetEntry.backupfilesPresetEntriesValues.put(
+ BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM,
+ backupfilesCustomEntry);
+
+ setComboIntStringKey(backupfilesPresetsCombo,
+ Cache.getDefault(BackupFiles.NS + "_PRESET",
+ BackupFilesPresetEntry.BACKUPFILESSCHEMEDEFAULT));
+
+ backupsSetOptions(savedPreset);
+
+ backupsOptionsSetEnabled();
+ updateBackupFilesExampleLabel();
+ }
+
+ private boolean warnAboutSuffixReverseChange()
+ {
+ BackupFilesPresetEntry bfpe = BackupFilesPresetEntry
+ .getSavedBackupEntry();
+ boolean savedSuffixReverse = bfpe.reverse;
+ int savedSuffixDigits = bfpe.digits;
+ String savedSuffixTemplate = bfpe.suffix;
+
+ boolean nowSuffixReverse = suffixReverse.isSelected();
+ int nowSuffixDigits = getSpinnerInt(suffixDigitsSpinner, 3);
+ String nowSuffixTemplate = suffixTemplate.getText();
+ return nowSuffixReverse != savedSuffixReverse
+ && nowSuffixDigits == savedSuffixDigits
+ && nowSuffixTemplate != null
+ && nowSuffixTemplate.equals(savedSuffixTemplate);
+ }
+
+ /**
+ * Initialises the Backups tabbed panel.
+ *
+ * @return
+ */
+ private JPanel initBackupsTab()
+ {
+ JPanel backupsTab = new JPanel();
+ backupsTab.setBorder(new TitledBorder(
+ MessageManager.getString("label.backup_files")));
+ backupsTab.setLayout(new GridBagLayout());
+
+ GridBagConstraints gbc = new GridBagConstraints();
+ gbc.weightx = 0.0;
+ gbc.weighty = 0.0;
+ gbc.anchor = GridBagConstraints.FIRST_LINE_START;
+ gbc.fill = GridBagConstraints.NONE;
+
+ initBackupsTabPresetsPanel();
+ initBackupsTabSuffixPanel();
+ initBackupsTabKeepFilesPanel();
+ initBackupsTabFilenameExamplesPanel();
+
+ enableBackupFiles.setFont(LABEL_FONT_BOLD);
+ enableBackupFiles
+ .setText(MessageManager.getString("label.enable_backupfiles"));
+ enableBackupFiles.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ // enable other options only when the first is checked
+ backupsOptionsSetEnabled();
+ }
+ });
+
+
+ // enable checkbox 1 col
+ gbc.gridwidth = 1;
+ gbc.gridheight = 1;
+ gbc.gridx = 0;
+ gbc.gridy = 0; // row 0
+ backupsTab.add(enableBackupFiles, gbc);
+
+ // summary of scheme box (over two rows)
+ gbc.gridx = 1;
+ gbc.weightx = 0.0;
+ gbc.gridheight = 2;
+ 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++; // row 1
+ backupsTab.add(presetsPanel, gbc);
+
+ // now using whole row
+ gbc.gridwidth = 2;
+ gbc.gridheight = 1;
+ // keep files box
+ gbc.gridx = 0;
+ gbc.gridy++; // row 2
+ backupsTab.add(keepfilesPanel, gbc);
+
+ // filename strategy box
+ gbc.gridy++; // row 3
+ backupsTab.add(suffixPanel, gbc);
+
+ // fill empty space
+ gbc.gridy++; // row 4
+ gbc.weighty = 1.0;
+ backupsTab.add(new JPanel(), gbc);
+
+ backupsOptionsSetEnabled();
+ return backupsTab;
+ }
+
+ private JPanel initBackupsTabPresetsPanel()
+ {
+
+ String title = MessageManager.getString("label.schemes");
+
+ 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;
+
+ presetsComboLabel = new JLabel(title + ":");
+ presetsPanel.add(presetsComboLabel, gbc);
+
+ List<Object> entries = Arrays
+ .asList((Object[]) BackupFilesPresetEntry.backupfilesPresetEntries);
+ List<String> tooltips = Arrays.asList(
+ BackupFilesPresetEntry.backupfilesPresetEntryDescriptions);
+ backupfilesPresetsCombo = JvSwingUtils.buildComboWithTooltips(entries,
+ tooltips);
+ /*
+ for (int i = 0; i < BackupFilesPresetEntry.backupfilesPresetEntries.length; i++)
+ {
+ backupfilesPresetsCombo
+ .addItem(BackupFilesPresetEntry.backupfilesPresetEntries[i]);
+ }
+ */
+
+ backupfilesPresetsCombo.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ int key = getComboIntStringKey(backupfilesPresetsCombo);
+ if (!customiseCheckbox.isSelected())
+ {
+ backupfilesPresetsComboLastSelected = key;
+ }
+ if (key == BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM)
+ {
+ if (customiseCheckbox.isSelected())
+ {
+ // got here by clicking on customiseCheckbox so don't change the values
+ backupfilesCustomOptionsSetEnabled();
+ }
+ else
+ {
+ backupsTabUpdatePresets();
+ backupfilesCustomOptionsSetEnabled();
+ }
+ }
+ else
+ {
+ customiseCheckbox.setSelected(false);
+ backupsTabUpdatePresets();
+ backupfilesCustomOptionsSetEnabled();
+ }
+ }
+ });
+
+ // dropdown list of preset schemes
+ gbc.gridx = 1;
+ presetsPanel.add(backupfilesPresetsCombo, gbc);
+
+ revertButton.setText(MessageManager.getString("label.cancel_changes"));
+ revertButton.setToolTipText(
+ MessageManager.getString("label.cancel_changes_description"));
+ revertButton.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ backupsSetOptions(
+ BackupFilesPresetEntry.backupfilesPresetEntriesValues.get(
+ BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM));
+ backupfilesCustomOptionsSetEnabled();
+ }
+
+ });
+ revertButton.setFont(LABEL_FONT);
+
+ customiseCheckbox.setFont(LABEL_FONT);
+ customiseCheckbox.setText(MessageManager.getString("label.customise"));
+ customiseCheckbox.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ int currently = getComboIntStringKey(backupfilesPresetsCombo);
+ if (customiseCheckbox.isSelected())
+ {
+ backupfilesPresetsComboLastSelected = currently;
+ setComboIntStringKey(backupfilesPresetsCombo,
+ BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM);
+ }
+ else
+ {
+ setComboIntStringKey(backupfilesPresetsCombo,
+ backupfilesPresetsComboLastSelected);
+
+ }
+ backupfilesCustomOptionsSetEnabled();
+ }
+ });
+ customiseCheckbox.setToolTipText(
+ MessageManager.getString("label.customise_description"));
+
+ // customise checkbox
+ gbc.gridx = 0;
+ gbc.gridy++;
+ presetsPanel.add(customiseCheckbox, gbc);
+
+ // "Cancel changes" button (aligned with combo box above)
+ gbc.gridx = 1;
+ presetsPanel.add(revertButton, gbc);
+
+ return presetsPanel;
+ }
+
+ private JPanel initBackupsTabFilenameExamplesPanel()
+ {
+ String title = MessageManager
+ .getString("label.scheme_examples");
+ 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.k;
+ String value = entry.v;
+
+ if (BackupFilesPresetEntry.backupfilesPresetEntriesValues
+ .containsKey(key))
+ {
+ backupsSetOptions(
+ BackupFilesPresetEntry.backupfilesPresetEntriesValues
+ .get(key));
+ }
+ else
+ {
+ Cache.log.error(
+ "Preset '" + value + "' [key:" + key + "] not implemented");
+ }
+
+ // Custom options will now be enabled when the customiseCheckbox is checked
+ // (performed above)
+ // backupfilesCustomOptionsSetEnabled();
+ updateBackupFilesExampleLabel();
+ }
+
+ protected int getComboIntStringKey(
+ JComboBox<Object> backupfilesPresetsCombo2)
+ {
+ IntKeyStringValueEntry e;
+ try
+ {
+ e = (IntKeyStringValueEntry) backupfilesPresetsCombo2
+ .getSelectedItem();
+ } catch (Exception ex)
+ {
+ Cache.log.error(
+ "Problem casting Combo entry to IntKeyStringValueEntry.");
+ e = null;
+ }
+ return e != null ? e.k : 0;
+ }
+
+ protected void setComboIntStringKey(
+ JComboBox<Object> backupfilesPresetsCombo2,
+ int key)
+ {
+ for (int i = 0; i < backupfilesPresetsCombo2.getItemCount(); i++)
+ {
+ IntKeyStringValueEntry e;
+ try
+ {
+ e = (IntKeyStringValueEntry) backupfilesPresetsCombo2.getItemAt(i);
+ } catch (Exception ex)
+ {
+ Cache.log.error(
+ "Problem casting Combo entry to IntKeyStringValueEntry. Skipping item. ");
+ continue;
+ }
+ if (e.k == key)
+ {
+ backupfilesPresetsCombo2.setSelectedIndex(i);
+ break;
+ }
+ }
+ // backupsTabUpdatePresets();
+ }
+
+ private JPanel initBackupsTabSuffixPanel()
+ {
+ suffixPanel.setBorder(new TitledBorder(
+ MessageManager.getString("label.backup_filename_strategy")));
+ suffixPanel.setLayout(new GridBagLayout());
+
+ suffixTemplateLabel
+ .setText(MessageManager.getString("label.append_to_filename"));
+ suffixTemplateLabel.setHorizontalAlignment(SwingConstants.LEFT);
+ suffixTemplateLabel.setFont(LABEL_FONT);
+
+ final String tooltip = JvSwingUtils.wrapTooltip(true,
+ MessageManager.getString("label.append_to_filename_tooltip"));
+ suffixTemplate.setToolTipText(tooltip);
+ suffixTemplate.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ updateBackupFilesExampleLabel();
+ backupfilesCustomOptionsSetEnabled();
+ backupfilesRevertButtonSetEnabled(true);
+ }
+
+ });
+ suffixTemplate.addKeyListener(new KeyListener()
+ {
+ @Override
+ public void keyReleased(KeyEvent e)
+ {
+ updateBackupFilesExampleLabel();
+ backupfilesCustomOptionsSetEnabled();
+ backupfilesRevertButtonSetEnabled(true);
+ }
+
+ @Override
+ public void keyPressed(KeyEvent e)
+ {
+ }
+
+ // disable use of ':' or '/' or '\'
+ @Override
+ public void keyTyped(KeyEvent e)
+ {
+ char c = e.getKeyChar();
+ if (c == ':' || c == '/' || c == '\\')
+ {
+ // don't process ':' or '/' or '\'
+ e.consume();
+ }
+ }
+
+ });
+
+ // digits spinner
+ suffixDigitsLabel
+ .setText(MessageManager.getString("label.index_digits"));
+ suffixDigitsLabel.setHorizontalAlignment(SwingConstants.LEFT);
+ suffixDigitsLabel.setFont(LABEL_FONT);
+ ChangeListener c = new ChangeListener()
+ {
+ @Override
+ public void stateChanged(ChangeEvent e)
+ {
+ backupfilesRevertButtonSetEnabled(true);
+ updateBackupFilesExampleLabel();
+ }
+
+ };
+ setIntegerSpinner(suffixDigitsSpinner, BackupFilesPresetEntry.DIGITSMIN,
+ BackupFilesPresetEntry.DIGITSMAX, 3, c);
+
+ suffixReverse.setLabels(MessageManager.getString("label.reverse_roll"),
+ MessageManager.getString("label.increment_index"));
+ suffixReverse.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ boolean okay = true;
+ if (warnAboutSuffixReverseChange())
+ {
+ // Warning popup
+ okay = confirmSuffixReverseChange();
+ }
+ if (okay)
+ {
+ backupfilesRevertButtonSetEnabled(true);
+ updateBackupFilesExampleLabel();
+ }
+ else
+ {
+ boolean savedSuffixReverse = BackupFilesPresetEntry
+ .getSavedBackupEntry().reverse;
+ suffixReverse.setSelected(savedSuffixReverse);
+ }
+ }
+ });
+
+ GridBagConstraints sgbc = new GridBagConstraints();
+
+ // first row (template text box)
+ sgbc.anchor = GridBagConstraints.WEST;
+ sgbc.gridx = 0;
+ sgbc.gridy = 0;
+ sgbc.gridwidth = 1;
+ sgbc.gridheight = 1;
+ sgbc.weightx = 1.0;
+ sgbc.weighty = 0.0;
+ sgbc.fill = GridBagConstraints.NONE;
+ suffixPanel.add(suffixTemplateLabel, sgbc);
+
+ sgbc.gridx = 1;
+ sgbc.fill = GridBagConstraints.HORIZONTAL;
+ suffixPanel.add(suffixTemplate, sgbc);
+
+ // second row (number of digits spinner)
+ sgbc.gridy = 1;
+
+ sgbc.gridx = 0;
+ sgbc.fill = GridBagConstraints.NONE;
+ suffixPanel.add(suffixDigitsLabel, sgbc);
+
+ sgbc.gridx = 1;
+ sgbc.fill = GridBagConstraints.HORIZONTAL;
+ suffixPanel.add(suffixDigitsSpinner, sgbc);
+
+ // third row (forward order radio selection)
+ sgbc.gridx = 0;
+ sgbc.gridy = 2;
+ sgbc.gridwidth = GridBagConstraints.REMAINDER;
+ sgbc.fill = GridBagConstraints.HORIZONTAL;
+ suffixPanel.add(suffixReverse.getFalseButton(), sgbc);
+
+ // fourth row (reverse order radio selection)
+ sgbc.gridy = 3;
+ suffixPanel.add(suffixReverse.getTrueButton(), sgbc);
+ return suffixPanel;
+ }
+
+ private boolean confirmSuffixReverseChange()
+ {
+ boolean ret = false;
+ String warningMessage = MessageManager
+ .getString("label.warning_confirm_change_reverse");
+ int confirm = JvOptionPane.showConfirmDialog(Desktop.desktop,
+ warningMessage,
+ MessageManager.getString("label.change_increment_decrement"),
+ JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE);
+
+ ret = (confirm == JvOptionPane.YES_OPTION);
+ return ret;
+ }
+
+ private JPanel initBackupsTabKeepFilesPanel()
+ {
+ keepfilesPanel.setBorder(
+ new TitledBorder(MessageManager.getString("label.keep_files")));
+ keepfilesPanel.setLayout(new GridBagLayout());
+
+ backupfilesKeepAll.setLabels(
+ MessageManager.getString("label.keep_all_backup_files"),
+ MessageManager.getString(
+ "label.keep_only_this_number_of_backup_files"));
+ backupfilesKeepAll.addTrueActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ backupfilesRevertButtonSetEnabled(true);
+ updateBackupFilesExampleLabel();
+ }
+ });
+ backupfilesKeepAll.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ backupfilesRevertButtonSetEnabled(true);
+ keepRollMaxOptionsEnabled();
+ updateBackupFilesExampleLabel();
+ }
+ });
+
+ ChangeListener c = new ChangeListener()
+ {
+ @Override
+ public void stateChanged(ChangeEvent e)
+ {
+ backupfilesRevertButtonSetEnabled(true);
+ updateBackupFilesExampleLabel();
+ }
+
+ };
+ setIntegerSpinner(backupfilesRollMaxSpinner,
+ BackupFilesPresetEntry.ROLLMAXMIN,
+ BackupFilesPresetEntry.ROLLMAXMAX, 4, true, c);
+
+ backupfilesConfirmDelete.setLabels(
+ MessageManager.getString("label.always_ask"),
+ MessageManager.getString("label.auto_delete"));
+ backupfilesConfirmDelete.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ backupfilesRevertButtonSetEnabled(true);
+ }
+ });
+ // update the enabled section
+ keepRollMaxOptionsEnabled();
+
+ GridBagConstraints kgbc = new GridBagConstraints();
+
+ // first row (template text box)
+ kgbc.anchor = GridBagConstraints.WEST;
+ kgbc.gridx = 0;
+ kgbc.gridy = 0;
+ kgbc.gridwidth = GridBagConstraints.REMAINDER;
+ kgbc.gridheight = 1;
+ kgbc.weightx = 1.0;
+ kgbc.weighty = 0.0;
+ kgbc.fill = GridBagConstraints.HORIZONTAL;
+ keepfilesPanel.add(backupfilesKeepAll.getTrueButton(), kgbc);
+
+ // second row
+ kgbc.gridy = 1;
+
+ kgbc.gridx = 0;
+ kgbc.gridwidth = GridBagConstraints.RELATIVE;
+ keepfilesPanel.add(backupfilesKeepAll.getFalseButton(), kgbc);
+
+ kgbc.gridx = 1;
+ kgbc.gridwidth = GridBagConstraints.REMAINDER;
+ keepfilesPanel.add(backupfilesRollMaxSpinner, kgbc);
+
+ // third row (indented)
+ kgbc.gridy = 2;
+ kgbc.insets = new Insets(0, 20, 0, 0);
+
+ kgbc.gridx = 0;
+ kgbc.gridwidth = GridBagConstraints.REMAINDER;
+ kgbc.fill = GridBagConstraints.HORIZONTAL;
+ kgbc.weightx = 1.0;
+
+ JPanel jp = new JPanel();
+ jp.setLayout(new FlowLayout());
+ oldBackupFilesLabel
+ .setText(MessageManager
+ .getString("label.autodelete_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;
+ }
+
+ protected void updateBackupFilesExampleLabel()
+ {
+ int exampleindex = 12;
+ String base = MessageManager.getString("label.filename") + ".fa";
+ if (base == null || base.length() == 0)
+ {
+ base = "file_name.fa";
+ }
+
+ boolean reverse = suffixReverse.isSelected();
+ boolean keepAll = backupfilesKeepAll.isSelected();
+ int rollMax = 4;
+ String suffix = suffixTemplate.getText();
+ int digits = 3;
+
+ backupfilesExampleLabel.setFont(LABEL_FONT_ITALIC);
+ if (suffix == null || suffix.length() == 0)
+ {
+ backupfilesExampleLabel
+ .setText(MessageManager.getString("label.no_backup_files"));
+ backupfilesExampleLabel.setFont(LABEL_FONT_BOLD);
+ return;
+ }
+
+ rollMax = getSpinnerInt(backupfilesRollMaxSpinner, 4);
+ rollMax = rollMax < 1 ? 1 : rollMax;
+
+ if (suffix.indexOf(BackupFiles.NUM_PLACEHOLDER) == -1)
+ {
+ rollMax = 1;
+ }
+
+ digits = getSpinnerInt(suffixDigitsSpinner, 3);
+ digits = digits < 1 ? 1 : digits;
+
+ int lowersurround = 2;
+ int uppersurround = 0;
+ StringBuilder exampleSB = new StringBuilder();
+ boolean firstLine = true;
+ int lineNumber = 0;
+ if (reverse)
+ {
+
+ int min = 1;
+ int max = keepAll ? exampleindex : rollMax;
+ for (int index = min; index <= max; index++)
+ {
+ if (index == min + lowersurround && index < max - uppersurround - 1)
+ {
+ exampleSB.append("\n...");
+ lineNumber++;
+ }
+ else if (index > min + lowersurround && index < max - uppersurround)
+ {
+ // nothing
+ }
+ else
+ {
+ if (firstLine)
+ {
+ firstLine = false;
+ }
+ else
+ {
+ exampleSB.append("\n");
+ lineNumber++;
+ }
+ exampleSB.append(BackupFilenameParts.getBackupFilename(index,
+ base, suffix, digits));
+ if (min == max)
+ {
+ // no extra text needed
+ }
+ else if (index == min)
+ {
+ String newest = MessageManager.getString("label.braced_newest");
+ if (newest != null && newest.length() > 0)
+ {
+ exampleSB.append(" " + newest);
+ }
+ }
+ else if (index == max)
+ {
+ String oldest = MessageManager.getString("label.braced_oldest");
+ if (oldest != null && oldest.length() > 0)
+ {
+ exampleSB.append(" " + oldest);
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+
+ int min = (keepAll || exampleindex - rollMax < 0) ? 1
+ : exampleindex - rollMax + 1;
+ int max = exampleindex;
+
+ for (int index = min; index <= max; index++)
+ {
+
+ if (index == min + lowersurround && index < max - uppersurround - 1)
+ {
+ exampleSB.append("\n...");
+ lineNumber++;
+ }
+ else if (index > min + lowersurround && index < max - uppersurround)
+ {
+ // nothing
+ }
+ else
+ {
+ if (firstLine)
+ {
+ firstLine = false;
+ }
+ else
+ {
+ exampleSB.append("\n");
+ lineNumber++;
+ }
+ exampleSB.append(BackupFilenameParts.getBackupFilename(index,
+ base, suffix, digits));
+ if (min == max)
+ {
+ // no extra text needed
+ }
+ else if (index == min)
+ {
+ String oldest = MessageManager.getString("label.braced_oldest");
+ if (oldest != null && oldest.length() > 0)
+ {
+ exampleSB.append(" " + oldest);
+ }
+ }
+ else if (index == max)
+ {
+ String newest = MessageManager.getString("label.braced_newest");
+ if (newest != null && newest.length() > 0)
+ {
+ exampleSB.append(" " + newest);
+ }
+ }
+ }
+ }
+
+ }
+
+ // add some extra empty lines to pad out the example files box. ugh, please tell
+ // me how to do this better
+ int remainingLines = lowersurround + uppersurround + 1 - lineNumber;
+ if (remainingLines > 0)
+ {
+ for (int i = 0; i < remainingLines; i++)
+ {
+ exampleSB.append("\n ");
+ lineNumber++;
+ }
+ }
+
+ backupfilesExampleLabel.setText(exampleSB.toString());
+ }
+
+ protected void setIntegerSpinner(JSpinner s, int min, int max, int def,
+ boolean useExistingVal, ChangeListener c)
+ {
+ int i = def;
+ if (useExistingVal)
+ {
+ try
+ {
+ i = ((Integer) s.getValue()).intValue();
+ } catch (Exception e)
+ {
+ Cache.log.error(
+ "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)
+ {
+ max = def;
+ }
+ if (def < min)
+ {
+ def = min;
+ }
+ SpinnerModel sModel = new SpinnerNumberModel(def, min, max, 1);
+ s.setModel(sModel);
+
+ s.addChangeListener(c);
+
+ }
+
+ protected static int getSpinnerInt(JSpinner s, int def)
+ {
+ int i = def;
+ try
+ {
+ s.commitEdit();
+ i = (Integer) s.getValue();
+ } catch (Exception e)
+ {
+ Cache.log.error("Failed casting (Integer) JSpinner s.getValue()");
+ }
+ return i;
+ }
+
+ private void keepRollMaxOptionsEnabled()
+ {
+ boolean enabled = backupfilesKeepAll.isEnabled()
+ && !backupfilesKeepAll.isSelected();
+ oldBackupFilesLabel.setEnabled(enabled);
+ backupfilesRollMaxSpinner.setEnabled(enabled);
+ backupfilesConfirmDelete.setEnabled(enabled);
+ }
+
+ private void backupfilesKeepAllSetEnabled(boolean tryEnabled)
+ {
+ boolean enabled = tryEnabled && enableBackupFiles.isSelected()
+ && customiseCheckbox.isSelected()
+ && suffixTemplate.getText()
+ .indexOf(BackupFiles.NUM_PLACEHOLDER) > -1;
+ keepfilesPanel.setEnabled(enabled);
+ backupfilesKeepAll.setEnabled(enabled);
+ oldBackupFilesLabel.setEnabled(enabled);
+ keepRollMaxOptionsEnabled();
+ }
+
+ private void backupfilesSuffixTemplateDigitsSetEnabled()
+ {
+ boolean enabled = suffixTemplate.isEnabled() && suffixTemplate.getText()
+ .indexOf(BackupFiles.NUM_PLACEHOLDER) > -1;
+ suffixDigitsLabel.setEnabled(enabled);
+ suffixDigitsSpinner.setEnabled(enabled);
+ suffixReverse.setEnabled(enabled);
+ }
+
+ private void backupfilesSuffixTemplateSetEnabled(boolean tryEnabled)
+ {
+ boolean enabled = tryEnabled && enableBackupFiles.isSelected()
+ && customiseCheckbox.isSelected();
+ suffixPanel.setEnabled(enabled);
+ suffixTemplateLabel.setEnabled(enabled);
+ suffixTemplate.setEnabled(enabled);
+ backupfilesSuffixTemplateDigitsSetEnabled();
+ }
+
+ private void backupfilesRevertButtonSetEnabled(boolean tryEnabled)
+ {
+ boolean enabled = tryEnabled && enableBackupFiles.isSelected()
+ && customiseCheckbox.isSelected() && backupfilesCustomChanged();
+ revertButton.setEnabled(enabled);
+ }
+
+ private boolean backupfilesCustomChanged()
+ {
+ BackupFilesPresetEntry custom = BackupFilesPresetEntry.backupfilesPresetEntriesValues
+ .get(BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM);
+ BackupFilesPresetEntry current = getBackupfilesCurrentEntry();
+ return !custom.equals(current);
+ }
+
+ protected BackupFilesPresetEntry getBackupfilesCurrentEntry()
+ {
+ String suffix = suffixTemplate.getText();
+ int digits = getSpinnerInt(suffixDigitsSpinner, 3);
+ boolean reverse = suffixReverse.isSelected();
+ boolean keepAll = backupfilesKeepAll.isSelected();
+ int rollMax = getSpinnerInt(backupfilesRollMaxSpinner, 3);
+ boolean confirmDelete = backupfilesConfirmDelete.isSelected();
+
+ BackupFilesPresetEntry bfpe = new BackupFilesPresetEntry(suffix, digits,
+ reverse, keepAll, rollMax, confirmDelete);
+
+ return bfpe;
+ }
+
+ protected void backupfilesCustomOptionsSetEnabled()
+ {
+ boolean enabled = customiseCheckbox.isSelected();
+
+ backupfilesRevertButtonSetEnabled(enabled);
+ backupfilesSuffixTemplateSetEnabled(enabled);
+ backupfilesKeepAllSetEnabled(enabled);
+ }
+
+ private void backupfilesSummarySetEnabled()
+ {
+ boolean enabled = enableBackupFiles.isSelected();
+ backupfilesExampleLabel.setEnabled(enabled);
+ exampleFilesPanel.setEnabled(enabled);
+ }
+
+ private void backupfilesPresetsSetEnabled()
+ {
+ boolean enabled = enableBackupFiles.isSelected();
+ presetsPanel.setEnabled(enabled);
+ presetsComboLabel.setEnabled(enabled);
+ backupfilesPresetsCombo.setEnabled(enabled);
+ customiseCheckbox.setEnabled(enabled);
+ revertButton.setEnabled(enabled);
+ }
+
+ protected void backupsOptionsSetEnabled()
+ {
+ backupfilesPresetsSetEnabled();
+ backupfilesSummarySetEnabled();
+ backupfilesCustomOptionsSetEnabled();
+ }
+
+ protected void backupsSetOptions(String suffix, int digits,
+ boolean reverse, boolean keepAll, int rollMax,
+ boolean confirmDelete)
+ {
+ suffixTemplate.setText(suffix);
+ suffixDigitsSpinner.setValue(digits);
+ suffixReverse.setSelected(reverse);
+ backupfilesKeepAll.setSelected(keepAll);
+ backupfilesRollMaxSpinner.setValue(rollMax);
+ backupfilesConfirmDelete.setSelected(confirmDelete);
+ }
+
+ protected void backupsSetOptions(BackupFilesPresetEntry p)
+ {
+ backupsSetOptions(p.suffix, p.digits, p.reverse, p.keepAll, p.rollMax,
+ p.confirmDelete);
+ }
+
+ protected void autoIdWidth_actionPerformed()
+ {
+ // TODO Auto-generated method stub