本文整理汇总了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");
});
}