trackeditor: make maximum recent files user configurable
git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@8578 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: 5e4d15ff19900f88026991151d21381b8a010c41 Former-commit-id: 9702cb85359ed114fb75959e30d71cf8c97f5cac
This commit is contained in:
parent
352774f6a1
commit
79f5654015
2 changed files with 67 additions and 8 deletions
|
@ -210,7 +210,8 @@ public class EditorFrame extends JFrame
|
|||
private Preferences preferences = Preferences.userNodeForPackage(EditorFrame.class);
|
||||
private List<String> recentFiles = new ArrayList<String>();
|
||||
private final static String RECENT_FILES_STRING = "recent.files.";
|
||||
private final static int RECENT_FILES_MAX = 10;
|
||||
private int recentFilesMax = 10;
|
||||
private final static String RECENT_FILES_MAX = "RecentFilesMax";
|
||||
|
||||
private TrackData trackData = null;
|
||||
private Vector<Surface> defaultSurfaces = new Vector<Surface>();
|
||||
|
@ -293,7 +294,8 @@ public class EditorFrame extends JFrame
|
|||
dataDirectory = preferences.get(SD_DATA_DIRECTORY, null);
|
||||
binDirectory = preferences.get(SD_BIN_DIRECTORY, null);
|
||||
libDirectory = preferences.get(SD_LIB_DIRECTORY, null);
|
||||
|
||||
recentFilesMax = Integer.parseInt(preferences.get(RECENT_FILES_MAX, "10"));
|
||||
|
||||
readDefaultSurfaces();
|
||||
readDefaultObjects();
|
||||
}
|
||||
|
@ -378,17 +380,38 @@ public class EditorFrame extends JFrame
|
|||
preferences.put(SD_LIB_DIRECTORY, this.libDirectory);
|
||||
}
|
||||
|
||||
public int getRecentFilesMax()
|
||||
{
|
||||
return recentFilesMax;
|
||||
}
|
||||
|
||||
public void setRecentFilesMax(int recentFilesMax)
|
||||
{
|
||||
this.recentFilesMax = recentFilesMax;
|
||||
|
||||
while (recentFiles.size() > recentFilesMax)
|
||||
{
|
||||
int index = recentFiles.size() - 1;
|
||||
System.out.println("removing " + index);
|
||||
recentFiles.remove(index);
|
||||
recentFilesMenu.remove(index);
|
||||
preferences.remove(RECENT_FILES_STRING+index);
|
||||
}
|
||||
|
||||
preferences.put(RECENT_FILES_MAX, this.recentFilesMax+"");
|
||||
}
|
||||
|
||||
private void updateRecentFiles(String filename)
|
||||
{
|
||||
recentFiles.remove(filename);
|
||||
recentFiles.add(0, filename);
|
||||
|
||||
if (recentFiles.size() > RECENT_FILES_MAX)
|
||||
|
||||
if (recentFiles.size() > recentFilesMax)
|
||||
{
|
||||
recentFiles.remove(recentFiles.size() - 1);
|
||||
}
|
||||
|
||||
for (int i = 0; i < RECENT_FILES_MAX; i++)
|
||||
for (int i = 0; i < recentFilesMax; i++)
|
||||
{
|
||||
if (i < recentFiles.size())
|
||||
{
|
||||
|
@ -835,7 +858,9 @@ public class EditorFrame extends JFrame
|
|||
});
|
||||
recentFilesMenu.add(clearHistory);
|
||||
|
||||
for (int i = 0; i < RECENT_FILES_MAX; i++)
|
||||
int recentFilesMax = Integer.parseInt(preferences.get(RECENT_FILES_MAX, "10"));
|
||||
|
||||
for (int i = 0; i < recentFilesMax; i++)
|
||||
{
|
||||
String file = preferences.get(RECENT_FILES_STRING + i, "");
|
||||
|
||||
|
@ -1173,6 +1198,7 @@ public class EditorFrame extends JFrame
|
|||
setDataDirectory(preferencesDialog.getDataDirectory());
|
||||
setBinDirectory(preferencesDialog.getBinDirectory());
|
||||
setLibDirectory(preferencesDialog.getLibDirectory());
|
||||
setRecentFilesMax(preferencesDialog.getRecentFilesMax());
|
||||
readDefaultSurfaces();
|
||||
readDefaultObjects();
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import javax.swing.JButton;
|
|||
import javax.swing.JDialog;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.WindowConstants;
|
||||
|
@ -28,6 +29,8 @@ public class PreferencesDialog extends JDialog
|
|||
private JLabel libDirectoryLabel = null;
|
||||
private JTextField libDirectoryTextField = null;
|
||||
private JButton libDirectoryButton = null;
|
||||
private JLabel recentFilesMaxLabel = null;
|
||||
private JTextField recentFilesMaxTextField = null;
|
||||
private JButton okButton = null;
|
||||
private JButton cancelButton = null;
|
||||
|
||||
|
@ -65,17 +68,22 @@ public class PreferencesDialog extends JDialog
|
|||
libDirectoryLabel = new JLabel();
|
||||
libDirectoryLabel.setBounds(10, 76, 190, 23);
|
||||
libDirectoryLabel.setText("Speed Dreams Lib Directory");
|
||||
recentFilesMaxLabel = new JLabel();
|
||||
recentFilesMaxLabel.setBounds(10, 109, 190, 23);
|
||||
recentFilesMaxLabel.setText("Recent Files Maximum");
|
||||
jPanel = new JPanel();
|
||||
jPanel.setLayout(null);
|
||||
jPanel.add(dataDirectoryLabel, null);
|
||||
jPanel.add(binDirectoryLabel, null);
|
||||
jPanel.add(libDirectoryLabel, null);
|
||||
jPanel.add(recentFilesMaxLabel, null);
|
||||
jPanel.add(getDataDirectoryTextField(), null);
|
||||
jPanel.add(getDataDirectoryButton(), null);
|
||||
jPanel.add(getBinDirectoryTextField(), null);
|
||||
jPanel.add(getBinDirectoryButton(), null);
|
||||
jPanel.add(getLibDirectoryTextField(), null);
|
||||
jPanel.add(getLibDirectoryButton(), null);
|
||||
jPanel.add(getRecentFilesMaxTextField(), null);
|
||||
jPanel.add(getOkButton(), null);
|
||||
jPanel.add(getCancelButton(), null);
|
||||
}
|
||||
|
@ -232,6 +240,17 @@ public class PreferencesDialog extends JDialog
|
|||
}
|
||||
}
|
||||
|
||||
private JTextField getRecentFilesMaxTextField()
|
||||
{
|
||||
if (recentFilesMaxTextField == null)
|
||||
{
|
||||
recentFilesMaxTextField = new JTextField();
|
||||
recentFilesMaxTextField.setBounds(200, 109, 290, 23);
|
||||
recentFilesMaxTextField.setText(editorFrame.getRecentFilesMax()+"");
|
||||
}
|
||||
return recentFilesMaxTextField;
|
||||
}
|
||||
|
||||
private JButton getOkButton()
|
||||
{
|
||||
if (okButton == null)
|
||||
|
@ -270,8 +289,17 @@ public class PreferencesDialog extends JDialog
|
|||
|
||||
protected void exit()
|
||||
{
|
||||
APPROVE = true;
|
||||
cancel();
|
||||
try
|
||||
{
|
||||
Integer.parseInt(getRecentFilesMaxTextField().getText());
|
||||
|
||||
APPROVE = true;
|
||||
cancel();
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
JOptionPane.showMessageDialog(this, "Invalid Recent Files Maximum : " + getRecentFilesMaxTextField().getText(), "Recent Files Maximum", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
protected void cancel()
|
||||
|
@ -296,6 +324,11 @@ public class PreferencesDialog extends JDialog
|
|||
return getLibDirectoryTextField().getText();
|
||||
}
|
||||
|
||||
public int getRecentFilesMax()
|
||||
{
|
||||
return Integer.parseInt(getRecentFilesMaxTextField().getText());
|
||||
}
|
||||
|
||||
protected void processWindowEvent(WindowEvent e)
|
||||
{
|
||||
super.processWindowEvent(e);
|
||||
|
|
Loading…
Reference in a new issue