kauron/estraba
Archived
1
0
Fork 0

drag and drop, main argument autoload, autofixes

This commit is contained in:
Jesús Vélez Palacios 2016-05-21 21:56:20 +02:00
parent 74bb277cf2
commit 1b832e2851
2 changed files with 48 additions and 9 deletions

View file

@ -25,6 +25,7 @@
package es.kauron.estraba;
import es.kauron.estraba.controller.SplashController;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
@ -32,6 +33,7 @@ import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import java.io.File;
import java.util.ResourceBundle;
import static java.util.ResourceBundle.getBundle;
@ -59,11 +61,13 @@ public class App extends Application {
stage.setResizable(false);
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.setMinWidth(300);
stage.setResizable(false);
// End awesomewm code
stage.show();
}
}

View file

@ -40,6 +40,8 @@ import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.Dragboard;
import javafx.scene.input.TransferMode;
import javafx.scene.layout.AnchorPane;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
@ -78,11 +80,6 @@ public class SplashController implements Initializable{
@FXML
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.getExtensionFilters().add(
new FileChooser.ExtensionFilter(App.GENERAL_BUNDLE.getString("app.extension"), "*.gpx"));
@ -91,7 +88,15 @@ public class SplashController implements Initializable{
errorLoading();
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>() {
@Override
protected DataBundle call() throws Exception {
@ -114,11 +119,16 @@ public class SplashController implements Initializable{
errorLoading();
}
}
@Override
protected void failed() {
super.failed();
errorLoading();
}
});
th.setDaemon(true);
th.start();
}
@Override
@ -133,6 +143,31 @@ public class SplashController implements Initializable{
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() {