Skip to content

Commit

Permalink
Speed up the settings dialog
Browse files Browse the repository at this point in the history
There are 3 JFileChoosers being instantiated when the dialog is created,
and apparently instantiating JFileChoosers is very slow, causing a delay
to display the dialog.

Defer the instantiation of these file choosers only when they are needed
  • Loading branch information
tibagni committed May 7, 2024
1 parent fc39f59 commit 226ac7c
Showing 1 changed file with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ public void windowClosing(WindowEvent e) {
}

private void initFiltersPathPreference() {
filterFolderChooser = new JFileChooserExt(userPrefs.getDefaultFiltersPath());
filterFolderChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

filtersPathBtn.addActionListener(e -> onSelectFilterPath());
filtersPathTxt.setText(userPrefs.getDefaultFiltersPath().getAbsolutePath());

Expand All @@ -108,9 +105,6 @@ private void initFiltersPathPreference() {
}

private void initLogsPathPreference() {
logsFolderChooser = new JFileChooserExt(userPrefs.getDefaultLogsPath());
logsFolderChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

logsPathBtn.addActionListener(e -> onSelectLogsPath());
logsPathTxt.setText(userPrefs.getDefaultLogsPath().getAbsolutePath());
}
Expand All @@ -130,8 +124,6 @@ private void initLookAndFeelPreference() {
}

private void initPreferredEditorPathPreference() {
preferredEditorFileChooser = new JFileChooserExt(userPrefs.getPreferredTextEditor());

preferredEditorPathBtn.addActionListener(e -> onSelectPreferredEditorPath());
File editorFile = userPrefs.getPreferredTextEditor();
String path = editorFile != null ? editorFile.getAbsolutePath() : null;
Expand All @@ -150,6 +142,11 @@ public void onCancel() {
}

private void onSelectFilterPath() {
if (filterFolderChooser == null) {
filterFolderChooser = new JFileChooserExt(userPrefs.getDefaultFiltersPath());
filterFolderChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
}

int selectedOption = filterFolderChooser.showOpenDialog(this);
if (selectedOption == JFileChooser.APPROVE_OPTION) {
File selectedFolder = filterFolderChooser.getSelectedFile();
Expand All @@ -160,6 +157,11 @@ private void onSelectFilterPath() {
}

private void onSelectLogsPath() {
if (logsFolderChooser == null) {
logsFolderChooser = new JFileChooserExt(userPrefs.getDefaultLogsPath());
logsFolderChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
}

int selectedOption = logsFolderChooser.showOpenDialog(this);
if (selectedOption == JFileChooser.APPROVE_OPTION) {
File selectedFolder = logsFolderChooser.getSelectedFile();
Expand Down Expand Up @@ -195,6 +197,10 @@ private void onShowLineNumbersChanged() {
}

private void onSelectPreferredEditorPath() {
if (preferredEditorFileChooser == null) {
preferredEditorFileChooser = new JFileChooserExt(userPrefs.getPreferredTextEditor());
}

int selectedOption = preferredEditorFileChooser.showOpenDialog(this);
if (selectedOption == JFileChooser.APPROVE_OPTION) {
File selectedFolder = preferredEditorFileChooser.getSelectedFile();
Expand Down

0 comments on commit 226ac7c

Please sign in to comment.