+ setMemoryPercentDisplay();
+ memoryOptionsSetEnabled();
+ return startupTab;
+ }
+
+ private void initMemoryPanel()
+ {
+ // Enable memory settings checkbox
+ customiseMemorySetting.setFont(LABEL_FONT_BOLD);
+ customiseMemorySetting.setText(
+ MessageManager.getString("label.customise_memory_settings"));
+ customiseMemorySetting.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ memoryOptionsSetEnabled();
+ }
+ });
+
+ loadLastSavedMemorySettings();
+
+ exampleMemoryLabel.setFont(LABEL_FONT_BOLD);
+ exampleMemoryLabel.setBackground(Color.WHITE);
+
+ maxMemoryLabel = new JLabel(
+ MessageManager.getString("label.maximum_memory_used"));
+ maxMemoryLabel.setFont(LABEL_FONT_BOLD);
+
+ // Maximum memory percentage slider
+ jvmMemoryPercentLabel.setFont(LABEL_FONT);
+ jvmMemoryPercentLabel.setText(
+ MessageManager.getString("label.percent_of_physical_memory"));
+ jvmMemoryPercentSlider.setPaintLabels(true);
+ jvmMemoryPercentSlider.setPaintTicks(true);
+ jvmMemoryPercentSlider.setPaintTrack(true);
+ jvmMemoryPercentSlider.setMajorTickSpacing(50);
+ jvmMemoryPercentSlider.setMinorTickSpacing(10);
+ jvmMemoryPercentSlider.addChangeListener(new ChangeListener()
+ {
+ @Override
+ public void stateChanged(ChangeEvent e)
+ {
+ setMemoryPercentDisplay();
+ }
+ });
+ jvmMemoryPercentDisplay.setFont(LABEL_FONT);
+ setMemoryPercentDisplay();
+
+ // Maximum memory cap textbox
+ jvmMemoryMaxLabel.setFont(LABEL_FONT);
+ jvmMemoryMaxLabel
+ .setText(MessageManager.getString("label.maximum_memory"));
+ initMemoryMaxTextField();
+
+ exampleMemoryMessageTextArea.setFont(LABEL_FONT_ITALIC);
+ exampleMemoryMessageTextArea.setForeground(Color.GRAY);
+ exampleMemoryMessageTextArea.setEditable(false);
+ exampleMemoryMessageTextArea.setLineWrap(true);
+ exampleMemoryMessageTextArea.setWrapStyleWord(true);
+ exampleMemoryMessageTextArea.setText(" ");
+ exampleMemoryMessageTextArea.setRows(2);
+ exampleMemoryMessageTextArea.setColumns(40);
+
+ setExampleMemoryLabel();
+ }
+
+ private void initMemoryMaxTextField()
+ {
+ jvmMemoryMaxTextField.setToolTipText(
+ MessageManager.getString("label.maximum_memory_tooltip"));
+ jvmMemoryMaxTextField.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent arg0)
+ {
+ validateMemoryMaxTextField();
+ setExampleMemoryLabel();
+ }
+ });
+
+ jvmMemoryMaxTextField.addKeyListener(new KeyListener()
+ {
+ @Override
+ public void keyReleased(KeyEvent e)
+ {
+ validateMemoryMaxTextField();
+ setExampleMemoryLabel();
+ }
+
+ @Override
+ public void keyPressed(KeyEvent e)
+ {
+ }
+
+ // try and stop invalid typing
+ @Override
+ public void keyTyped(KeyEvent e)
+ {
+ char c = Character.toLowerCase(e.getKeyChar());
+ String text = jvmMemoryMaxTextField.getText();
+ String suffixes = "tgmkb";
+ int pos = jvmMemoryMaxTextField.getCaretPosition();
+ int suffixPos = StringUtils.firstCharPosIgnoreCase(text, suffixes);
+ if (!((('0' <= c && c <= '9')
+ && (suffixPos == -1 || pos <= suffixPos)) // digits only allowed
+ // before suffix
+ || (suffixes.indexOf(Character.toLowerCase(c)) >= 0 // valid
+ // suffix
+ && pos == text.length() // at end of text and
+ && suffixPos == -1) // there isn't already one
+ ))
+ {
+ // don't process
+ e.consume();
+ }
+ }
+ });
+ }
+
+ private boolean isMemoryMaxTextFieldValid()
+ {
+ return MemorySetting
+ .isValidMemoryString(jvmMemoryMaxTextField.getText());
+ }
+
+ private void validateMemoryMaxTextField()
+ {
+ if (isMemoryMaxTextFieldValid())
+ {
+ jvmMemoryMaxTextField.setBackground(Color.WHITE);
+ }
+ else
+ {
+ jvmMemoryMaxTextField.setBackground(Color.PINK);
+ }
+ }
+
+ private void setMemoryPercentDisplay()
+ {
+ jvmMemoryPercentDisplay
+ .setText(jvmMemoryPercentSlider.getValue() + "%");
+ setExampleMemoryLabel();
+ }
+
+ private void setExampleMemoryLabel()
+ {
+ boolean selected = customiseMemorySetting.isSelected();
+ int jvmmempc = jvmMemoryPercentSlider.getValue();
+ String jvmmemmax = jvmMemoryMaxTextField.getText();
+
+ long mem;
+ if (selected && (0 <= jvmmempc && jvmmempc <= 100)
+ && MemorySetting.isValidMemoryString(jvmmemmax))
+ {
+ mem = MemorySetting.getMemorySetting(jvmmemmax,
+ String.valueOf(jvmmempc), false, true);
+ }
+ else
+ {
+ mem = MemorySetting.getMemorySetting(null, null, false, true);
+ }
+ exampleMemoryLabel.setText(MemorySetting.memoryLongToString(mem));
+ String message = MemorySetting.getAdjustmentMessage();
+ exampleMemoryMessageTextArea.setText(
+ MessageManager.getString("label.adjustments_for_this_computer")
+ + ": "
+ + (message == null
+ ? MessageManager.getString("label.none")
+ : message));
+ }
+
+ private void memoryOptionsSetEnabled()
+ {
+ boolean enabled = customiseMemorySetting.isSelected();
+ // leave exampleMemoryLabel enabled always
+ maxMemoryLabel.setEnabled(enabled);
+ jvmMemoryPercentLabel.setEnabled(enabled);
+ jvmMemoryPercentSlider.setEnabled(enabled);
+ jvmMemoryPercentDisplay.setEnabled(enabled);
+ jvmMemoryMaxLabel.setEnabled(enabled);
+ jvmMemoryMaxTextField.setEnabled(enabled);
+ exampleMemoryMessageTextArea.setEnabled(enabled);
+ setExampleMemoryLabel();
+ }
+
+ /**
+ * 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;