本文整理匯總了Java中javafx.concurrent.Service類的典型用法代碼示例。如果您正苦於以下問題:Java Service類的具體用法?Java Service怎麽用?Java Service使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Service類屬於javafx.concurrent包,在下文中一共展示了Service類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: ServerListMainTreeItem
import javafx.concurrent.Service; //導入依賴的package包/類
public ServerListMainTreeItem() {
super("Servers");
setGraphic(new ImageView(icon));
new Service<List<Server>>() {
@Override
protected Task<List<Server>> createTask() {
return new SsTask<List<Server>>() {
@Override
protected List<Server> call() throws Exception {
return getServerRegistry().getServers();
}
@Override
protected void succeeded() {
final List<Server> servers;
try { servers = get(); } catch (InterruptedException | ExecutionException e) { throw new RuntimeException(e); }
addTreeItemsViewCallback(servers);
super.succeeded();
}
};
}
}.start();
}
示例2: backgroundSearch
import javafx.concurrent.Service; //導入依賴的package包/類
private void backgroundSearch(String query){
if(query != null) {
if (!GmailMessages.activeSearches.isEmpty()) {
for (Service<Void> service : GmailMessages.activeSearches) {
service.cancel();
}
}
Service<Void> search = new Service<Void>() {
@Override
protected Task<Void> createTask() {
try {
GmailOperations.listSearchMessages(query);
GmailOperations.getSearchMessages(query);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
};
GmailMessages.activeSearches.add(search);
search.start();
}
}
示例3: transitToConnectedMode
import javafx.concurrent.Service; //導入依賴的package包/類
private void transitToConnectedMode() {
if(mode == Mode.REMOTE){
CDH.setPort(Mode.getPort(mode));
}
System.out.println("ConnectionManager.State -> "+c.getState().toString());
if(c.getState() == Service.State.CANCELLED || c.getState() == Service.State.SUCCEEDED){
Platform.runLater(() ->{
reinitSession();
});
}
if(c.getState() == Service.State.READY){
Log.log("FXMLController","attempting to init ConnectionManager");
initSession();
}
TIME_STARTED_LABEL.setText("Time started: "+new SimpleDateFormat("HH:mm:ss").format(new Date()));
TIME_STOPPED_LABEL.setText("Time stopped: ");
CONNECT.setDisable(true);
DISCONNECT.setDisable(false);
}
示例4: loadFontWeights
import javafx.concurrent.Service; //導入依賴的package包/類
/**
* @작성자 : KYJ
* @작성일 : 2016. 12. 2.
*/
private void loadFontWeights() {
Service<List<String>> createFxService = new Service<List<String>>() {
@Override
protected Task<List<String>> createTask() {
return new Task<List<String>>() {
@Override
protected List<String> call() throws Exception {
return FxUtil.FONTUtil.getFontWeights();
}
};
}
};
createFxService.setOnSucceeded(w -> {
List<String> value = createFxService.getValue();
cbFontWeight.getItems().addAll(value);
});
createFxService.start();
}
示例5: loadFontStyles
import javafx.concurrent.Service; //導入依賴的package包/類
private void loadFontStyles() {
Service<List<String>> createFxService = new Service<List<String>>() {
@Override
protected Task<List<String>> createTask() {
return new Task<List<String>>() {
@Override
protected List<String> call() throws Exception {
return FxUtil.FONTUtil.getFontStyles();
}
};
}
};
createFxService.setOnSucceeded(w -> {
List<String> value = createFxService.getValue();
cbFontStyles.getItems().addAll(value);
});
createFxService.start();
}
示例6: handleLoginButtonAction
import javafx.concurrent.Service; //導入依賴的package包/類
@FXML public Service<Void> handleLoginButtonAction(ActionEvent event){
// Button for google
Button googleAuth = new Button(Configuration.getBundle().getString("ui.dialog.auth.google.title"), IconFactory.createGoogleIcon());
LoginDialog dialog = new LoginDialog(googleAuth);
googleAuth.setOnAction(t -> {
GoogleLoginDialog googleDialog = new GoogleLoginDialog(dialog);
googleDialog.show();
});
Optional<Pair<String, String>> result = dialog.showAndWait();
hBottomBox.add(labelField, 0, 0);
LoginService loginTask = new LoginService();
result.ifPresent(usernamePassword -> {
loginTask.setUsername(usernamePassword.getKey());
loginTask.setPassword(usernamePassword.getValue());
});
labelField.textProperty().bind(loginTask.messageProperty());
return loginTask;
}
示例7: handleDownloadButtonAction
import javafx.concurrent.Service; //導入依賴的package包/類
@FXML private void handleDownloadButtonAction(ActionEvent event){
if(! MainApp.getZdsutils().isAuthenticated()){
Service<Void> loginTask = handleLoginButtonAction(event);
loginTask.setOnSucceeded(t -> downloadContents(null));
loginTask.setOnCancelled(t -> {
hBottomBox.getChildren().clear();
Alert alert = new CustomAlert(AlertType.ERROR);
alert.setTitle(Configuration.getBundle().getString("ui.dialog.auth.failed.title"));
alert.setHeaderText(Configuration.getBundle().getString("ui.dialog.auth.failed.header"));
alert.setContentText(Configuration.getBundle().getString("ui.dialog.auth.failed.text"));
alert.showAndWait();
});
loginTask.start();
}else{
downloadContents(null);
}
}
示例8: handleDownloadArticleButtonAction
import javafx.concurrent.Service; //導入依賴的package包/類
@FXML private void handleDownloadArticleButtonAction(ActionEvent event){
if(! MainApp.getZdsutils().isAuthenticated()){
Service<Void> loginTask = handleLoginButtonAction(event);
loginTask.setOnSucceeded(t -> downloadContents("ARTICLE"));
loginTask.setOnCancelled(t -> {
hBottomBox.getChildren().clear();
Alert alert = new CustomAlert(AlertType.ERROR);
alert.setTitle(Configuration.getBundle().getString("ui.dialog.auth.failed.title"));
alert.setHeaderText(Configuration.getBundle().getString("ui.dialog.auth.failed.header"));
alert.setContentText(Configuration.getBundle().getString("ui.dialog.auth.failed.text"));
alert.showAndWait();
});
loginTask.start();
}else{
downloadContents("ARTICLE");
}
}
示例9: handleDownloadTutorialButtonAction
import javafx.concurrent.Service; //導入依賴的package包/類
@FXML private void handleDownloadTutorialButtonAction(ActionEvent event){
if(! MainApp.getZdsutils().isAuthenticated()){
Service<Void> loginTask = handleLoginButtonAction(event);
loginTask.setOnSucceeded(t -> downloadContents("TUTORIAL"));
loginTask.setOnCancelled(t -> {
hBottomBox.getChildren().clear();
Alert alert = new CustomAlert(AlertType.ERROR);
alert.setTitle(Configuration.getBundle().getString("ui.dialog.auth.failed.title"));
alert.setHeaderText(Configuration.getBundle().getString("ui.dialog.auth.failed.header"));
alert.setContentText(Configuration.getBundle().getString("ui.dialog.auth.failed.text"));
alert.showAndWait();
});
loginTask.start();
}else{
downloadContents("TUTORIAL");
}
}
示例10: handleDownloadOpinionButtonAction
import javafx.concurrent.Service; //導入依賴的package包/類
@FXML private void handleDownloadOpinionButtonAction(ActionEvent event){
if(! MainApp.getZdsutils().isAuthenticated()){
Service<Void> loginTask = handleLoginButtonAction(event);
loginTask.setOnSucceeded(t -> downloadContents("OPINION"));
loginTask.setOnCancelled(t -> {
hBottomBox.getChildren().clear();
Alert alert = new CustomAlert(AlertType.ERROR);
alert.setTitle(Configuration.getBundle().getString("ui.dialog.auth.failed.title"));
alert.setHeaderText(Configuration.getBundle().getString("ui.dialog.auth.failed.header"));
alert.setContentText(Configuration.getBundle().getString("ui.dialog.auth.failed.text"));
alert.showAndWait();
});
loginTask.start();
}else{
downloadContents("OPINION");
}
}
示例11: handleUploadButtonAction
import javafx.concurrent.Service; //導入依賴的package包/類
@FXML private void handleUploadButtonAction(ActionEvent event){
if(! MainApp.getZdsutils().isAuthenticated()){
Service<Void> loginTask = handleLoginButtonAction(event);
loginTask.setOnCancelled(t -> {
hBottomBox.getChildren().clear();
Alert alert = new CustomAlert(AlertType.ERROR);
alert.setTitle(Configuration.getBundle().getString("ui.dialog.upload.content.failed.title"));
alert.setHeaderText(Configuration.getBundle().getString("ui.dialog.upload.content.failed.header"));
alert.setContentText(Configuration.getBundle().getString("ui.dialog.upload.content.failed.text"));
alert.showAndWait();
});
loginTask.setOnSucceeded(t -> uploadContents());
loginTask.start();
}else{
uploadContents();
}
}
示例12: handleSelectFileAction
import javafx.concurrent.Service; //導入依賴的package包/類
@FXML private void handleSelectFileAction(){
if(! zdsUtils.isAuthenticated()){
Service<Void> loginTask = menuManager.handleLoginButtonAction(null);
loginTask.setOnSucceeded(t -> selectAndUploadImage());
loginTask.setOnCancelled(t -> {
menuManager.getHBottomBox().getChildren().clear();
Alert alert = new CustomAlert(AlertType.ERROR);
alert.setTitle(Configuration.getBundle().getString("ui.dialog.auth.failed.title"));
alert.setHeaderText(Configuration.getBundle().getString("ui.dialog.auth.failed.header"));
alert.setContentText(Configuration.getBundle().getString("ui.dialog.auth.failed.text"));
alert.showAndWait();
});
loginTask.start();
}else{
selectAndUploadImage();
}
}
示例13: startServer
import javafx.concurrent.Service; //導入依賴的package包/類
private void startServer(int port) throws Exception {
new Service<Void>() {
@Override
protected Task<Void> createTask() {
return new Task<Void>() {
@Override
protected Void call() throws Exception {
new Server().connect(resetButton, connectionStatusLabel,
messageLabel, port);
return null;
}
};
}
}.start();
}
示例14: connect
import javafx.concurrent.Service; //導入依賴的package包/類
public void connect(InetAddress inetAddress, int port) {
new Service<Void>() {
@Override
protected Task<Void> createTask() {
return new Task<Void>() {
@Override
protected Void call() throws Exception {
Thread.sleep(3000);
connectToAndroid(inetAddress, port);
return null;
}
};
}
}.start();
}
示例15: initRunningService
import javafx.concurrent.Service; //導入依賴的package包/類
private void initRunningService(final BooleanSupplier autoAdjustResolution, final Runnable updateUI) {
runningService = new Service<Void>() {
@Override
protected Task<Void> createTask() {
return new Task<Void>() {
@Override
protected Void call() throws Exception {
looper.start(autoAdjustResolution, updateUI);
return null;
}
};
}
};
runningService.setOnCancelled(event -> {
runningService.reset();
logger.warning("Running is cancelled");
});
runningService.setOnFailed(event -> {
runningService.reset();
logger.warning("Running is failed");
});
}