Add multithreading to avoid freezing the UI while loading
This commit is contained in:
parent
ca7608ecab
commit
7ed991435c
@ -3,9 +3,11 @@ package fr.ensim.xml.ui;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.sun.media.jfxmedia.events.PlayerTimeListener;
|
||||
|
||||
import fr.ensim.xml.deezer.Runner;
|
||||
import javafx.application.Application;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.application.Platform;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
@ -44,6 +46,7 @@ public class MainWindow extends Application {
|
||||
final MenuItem xmlOption = menuButton.getItems().get(0);
|
||||
final MenuItem jsonOption = menuButton.getItems().get(1);
|
||||
final WebView webView = (WebView) scene.lookup("#webView");
|
||||
final WebEngine engine = webView.getEngine();
|
||||
final MenuButton formatButton = (MenuButton) scene.lookup("#xmlFormatSelector");
|
||||
final MenuItem domOption = formatButton.getItems().get(0);
|
||||
final MenuItem saxOption = formatButton.getItems().get(1);
|
||||
@ -51,23 +54,53 @@ public class MainWindow extends Application {
|
||||
final MenuItem customOption = htmlButton.getItems().get(0);
|
||||
final MenuItem staxOption = htmlButton.getItems().get(1);
|
||||
|
||||
final Thread uiThread = Thread.currentThread();
|
||||
|
||||
searchButton.setOnAction(new EventHandler<ActionEvent>() {
|
||||
@Override
|
||||
public void handle(ActionEvent event) {
|
||||
if(menuButton.getText().equals(jsonOption.getText()))
|
||||
{
|
||||
Thread thread = new Thread()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
Runner runner = new Runner();
|
||||
File htmlFile = runner.start(searchTextField.getText().replaceAll("\\s", "%20"), useCustom);
|
||||
WebEngine engine = webView.getEngine();
|
||||
final File htmlFile = runner.start(searchTextField.getText().replaceAll("\\s", "%20"), useCustom);
|
||||
|
||||
Platform.runLater(new Runnable(){
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
engine.load(htmlFile.toURI().toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
thread.start();
|
||||
}
|
||||
else
|
||||
{
|
||||
Thread thread = new Thread()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
Runner runner = new Runner();
|
||||
File htmlFile = runner.start(searchTextField.getText().replaceAll("\\s", "%20"), useDom, useCustom);
|
||||
WebEngine engine = webView.getEngine();
|
||||
final File htmlFile = runner.start(searchTextField.getText().replaceAll("\\s", "%20"), useDom, useCustom);
|
||||
|
||||
Platform.runLater(new Runnable(){
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
engine.load(htmlFile.toURI().toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
thread.start();
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
@ -1,10 +1,10 @@
|
||||
22:21:21,043 DEBUG fr.ensim.xml.deezer.AbstractSearchAlbum - >>find author=Shaka%20ponk
|
||||
22:21:21,046 DEBUG fr.ensim.xml.deezer.AbstractSearchAlbum - http://api.deezer.com/2.0/search/album?q=Shaka%20ponk
|
||||
22:21:26,435 DEBUG fr.ensim.json.JSONSearchAlbum - >>readAlbums
|
||||
22:21:26,445 DEBUG fr.ensim.json.JSONSearchAlbum - <<readAlbums
|
||||
22:21:26,446 DEBUG fr.ensim.xml.deezer.AbstractSearchAlbum - <<find
|
||||
22:21:26,446 DEBUG fr.ensim.json.JSONSearchAlbumTracks - >>albums
|
||||
22:21:26,447 DEBUG fr.ensim.json.JSONSearchAlbumTracks - http://api.deezer.com/2.0/album/47685332
|
||||
22:21:31,570 DEBUG fr.ensim.json.JSONSearchAlbumTracks - >>find
|
||||
22:21:31,579 DEBUG fr.ensim.json.JSONSearchAlbumTracks - >>find
|
||||
22:21:31,580 DEBUG fr.ensim.xml.deezer.stax.StAXHtmlAlbum - >>write
|
||||
22:41:09,806 DEBUG fr.ensim.xml.deezer.AbstractSearchAlbum - >>find author=Shaka%20ponk
|
||||
22:41:09,808 DEBUG fr.ensim.xml.deezer.AbstractSearchAlbum - http://api.deezer.com/2.0/search/album?q=Shaka%20ponk&output=xml
|
||||
22:41:15,186 DEBUG fr.ensim.xml.deezer.dom.DOMSearchAlbums - >>readAlbums
|
||||
22:41:15,223 DEBUG fr.ensim.xml.deezer.dom.DOMSearchAlbums - <<readAlbums
|
||||
22:41:15,223 DEBUG fr.ensim.xml.deezer.AbstractSearchAlbum - <<find
|
||||
22:41:15,225 DEBUG fr.ensim.xml.deezer.dom.DOMSearchAlbumTracks - >>albums
|
||||
22:41:15,225 DEBUG fr.ensim.xml.deezer.dom.DOMSearchAlbumTracks - http://api.deezer.com/2.0/album/47685332?output=xml
|
||||
22:41:20,340 DEBUG fr.ensim.xml.deezer.dom.DOMSearchAlbumTracks - >>find
|
||||
22:41:20,369 DEBUG fr.ensim.xml.deezer.dom.DOMSearchAlbumTracks - >>find
|
||||
22:41:20,369 DEBUG fr.ensim.xml.deezer.stax.StAXHtmlAlbum - >>write
|
||||
|
Loading…
Reference in New Issue
Block a user