drag and drop, main argument autoload, autofixes
This commit is contained in:
parent
74bb277cf2
commit
1b832e2851
2 changed files with 48 additions and 9 deletions
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
package es.kauron.estraba;
|
package es.kauron.estraba;
|
||||||
|
|
||||||
|
import es.kauron.estraba.controller.SplashController;
|
||||||
import javafx.application.Application;
|
import javafx.application.Application;
|
||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
import javafx.scene.Parent;
|
import javafx.scene.Parent;
|
||||||
|
@ -32,6 +33,7 @@ import javafx.scene.Scene;
|
||||||
import javafx.scene.image.Image;
|
import javafx.scene.image.Image;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
import static java.util.ResourceBundle.getBundle;
|
import static java.util.ResourceBundle.getBundle;
|
||||||
|
@ -59,11 +61,13 @@ public class App extends Application {
|
||||||
stage.setResizable(false);
|
stage.setResizable(false);
|
||||||
stage.setScene(new Scene(root));
|
stage.setScene(new Scene(root));
|
||||||
|
|
||||||
// Begin awesomewm code
|
if (getParameters().getUnnamed().size() == 1) {
|
||||||
|
loader.<SplashController>getController().loadGPXFile(new File(getParameters().getUnnamed().get(0)));
|
||||||
|
}
|
||||||
|
// fix rogue wm :)
|
||||||
stage.setMinHeight(500);
|
stage.setMinHeight(500);
|
||||||
stage.setMinWidth(300);
|
stage.setMinWidth(300);
|
||||||
stage.setResizable(false);
|
|
||||||
// End awesomewm code
|
|
||||||
stage.show();
|
stage.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,8 @@ import javafx.scene.Scene;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.image.Image;
|
import javafx.scene.image.Image;
|
||||||
import javafx.scene.image.ImageView;
|
import javafx.scene.image.ImageView;
|
||||||
|
import javafx.scene.input.Dragboard;
|
||||||
|
import javafx.scene.input.TransferMode;
|
||||||
import javafx.scene.layout.AnchorPane;
|
import javafx.scene.layout.AnchorPane;
|
||||||
import javafx.stage.FileChooser;
|
import javafx.stage.FileChooser;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
@ -78,11 +80,6 @@ public class SplashController implements Initializable{
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void loadGPXFile(ActionEvent event) throws Exception {
|
private void loadGPXFile(ActionEvent event) throws Exception {
|
||||||
buttonLoad.setVisible(false);
|
|
||||||
labelWelcome.setVisible(false);
|
|
||||||
spinner.setVisible(true);
|
|
||||||
snackbar.registerSnackbarContainer(root);
|
|
||||||
snackbar.show("Loading file", 5000);
|
|
||||||
FileChooser fileChooser = new FileChooser();
|
FileChooser fileChooser = new FileChooser();
|
||||||
fileChooser.getExtensionFilters().add(
|
fileChooser.getExtensionFilters().add(
|
||||||
new FileChooser.ExtensionFilter(App.GENERAL_BUNDLE.getString("app.extension"), "*.gpx"));
|
new FileChooser.ExtensionFilter(App.GENERAL_BUNDLE.getString("app.extension"), "*.gpx"));
|
||||||
|
@ -91,7 +88,15 @@ public class SplashController implements Initializable{
|
||||||
errorLoading();
|
errorLoading();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
loadGPXFile(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadGPXFile(File file) {
|
||||||
|
buttonLoad.setVisible(false);
|
||||||
|
labelWelcome.setVisible(false);
|
||||||
|
spinner.setVisible(true);
|
||||||
|
snackbar.registerSnackbarContainer(root);
|
||||||
|
snackbar.show("Loading file", 5000);
|
||||||
Thread th = new Thread(new Task<DataBundle>() {
|
Thread th = new Thread(new Task<DataBundle>() {
|
||||||
@Override
|
@Override
|
||||||
protected DataBundle call() throws Exception {
|
protected DataBundle call() throws Exception {
|
||||||
|
@ -114,11 +119,16 @@ public class SplashController implements Initializable{
|
||||||
errorLoading();
|
errorLoading();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void failed() {
|
||||||
|
super.failed();
|
||||||
|
errorLoading();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
th.setDaemon(true);
|
th.setDaemon(true);
|
||||||
th.start();
|
th.start();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -133,6 +143,31 @@ public class SplashController implements Initializable{
|
||||||
ioe.printStackTrace();
|
ioe.printStackTrace();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
root.getScene().setOnDragOver(e -> {
|
||||||
|
Dragboard db = e.getDragboard();
|
||||||
|
if (db.hasFiles()) {
|
||||||
|
e.acceptTransferModes(TransferMode.COPY);
|
||||||
|
} else {
|
||||||
|
e.consume();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Dropping over surface
|
||||||
|
root.getScene().setOnDragDropped(e -> {
|
||||||
|
Dragboard db = e.getDragboard();
|
||||||
|
boolean success = false;
|
||||||
|
if (db.hasFiles()) {
|
||||||
|
success = true;
|
||||||
|
String filePath = null;
|
||||||
|
for (File file : db.getFiles()) {
|
||||||
|
filePath = file.getAbsolutePath();
|
||||||
|
System.out.println(filePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
e.setDropCompleted(success);
|
||||||
|
e.consume();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void errorLoading() {
|
private void errorLoading() {
|
||||||
|
|
Reference in a new issue