FastAsyncWorldedit/core/src/main/java/com/boydti/fawe/installer/BrowseButton.java

45 lines
1.4 KiB
Java
Raw Normal View History

2016-12-27 11:56:37 +01:00
package com.boydti.fawe.installer;
import com.boydti.fawe.Fawe;
2016-12-27 11:56:37 +01:00
import java.awt.event.ActionEvent;
import java.io.File;
import java.util.prefs.Preferences;
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.stage.DirectoryChooser;
2016-12-27 11:56:37 +01:00
public abstract class BrowseButton extends InteractiveButton {
2017-10-06 07:51:04 +02:00
private final String id;
public BrowseButton(String id) {
2016-12-27 11:56:37 +01:00
super("Browse");
2017-10-06 07:51:04 +02:00
this.id = id;
2016-12-27 11:56:37 +01:00
}
public abstract void onSelect(File folder);
@Override
public void actionPerformed(ActionEvent e) {
Preferences prefs = Preferences.userRoot().node(Fawe.class.getName());
String lastUsed = prefs.get("LAST_USED_FOLDER", null);
final File lastFile = lastUsed == null ? null : new File(lastUsed).getParentFile();
browse(lastFile);
}
public void browse(File from) {
DirectoryChooser folderChooser = new DirectoryChooser();
folderChooser.setInitialDirectory(from);
new JFXPanel(); // Init JFX Platform
Platform.runLater(() -> {
File file = folderChooser.showDialog(null);
if (file != null && file.exists()) {
File parent = file.getParentFile();
2017-10-06 07:51:04 +02:00
if (parent == null) parent = file;
Preferences.userRoot().node(Fawe.class.getName()).put("LAST_USED_FOLDER" + id, parent.getPath());
onSelect(file);
}
});
2016-12-27 11:56:37 +01:00
}
}