use of javafx.event.ActionEvent in project trex-stateless-gui by cisco-system-traffic-generator.
the class MainViewController method handleCaptureItemClicked.
/**
* Handle stats menu item clicked
*
* @param event
*/
@FXML
public void handleCaptureItemClicked(ActionEvent event) {
final String currentUser = ConnectionManager.getInstance().getClientName();
Optional<Port> atLeastOneEnabledServiceMode = PortsManager.getInstance().getPortList().stream().filter(port -> port.getOwner().equalsIgnoreCase(currentUser) && port.getServiceMode()).findAny();
if (atLeastOneEnabledServiceMode.isPresent()) {
try {
if (captureWindow == null) {
captureWindow = new DialogWindow("pkt_capture/Layout.fxml", "Packet Capture", 50, 10, 1200, 700, true, TrexApp.getPrimaryStage());
}
captureWindow.show(false);
} catch (IOException ex) {
LOG.error("Error opening dashboard view", ex);
}
} else {
TrexAlertBuilder.build().setType(Alert.AlertType.ERROR).setTitle("Capture error").setHeader("Unable to open capture window").setContent("At least one port with enabled service mode should be acquired").getAlert().show();
}
}
use of javafx.event.ActionEvent in project jgnash by ccavanaugh.
the class ConsoleDialogController method initialize.
@FXML
void initialize() {
oldErrStream = System.err;
oldOutStream = System.out;
// Force a monospaced font
consoleArea.setFont(Font.font("Monospaced", consoleArea.getFont().getSize()));
Engine.getLogger().addHandler(logHandler);
try {
outStream = new PrintStream(new OutputStream() {
@Override
public void write(int b) {
oldOutStream.write(b);
JavaFXUtils.runLater(() -> consoleArea.appendText(String.valueOf((char) b)));
}
}, false, Charset.defaultCharset().name());
} catch (final UnsupportedEncodingException ex) {
Logger.getLogger(ConsoleDialogController.class.getName()).log(Level.SEVERE, null, ex);
}
try {
errStream = new PrintStream(new OutputStream() {
@Override
public void write(int b) {
oldErrStream.write(b);
JavaFXUtils.runLater(() -> consoleArea.appendText(String.valueOf((char) b)));
}
}, false, Charset.defaultCharset().name());
} catch (final UnsupportedEncodingException ex) {
Logger.getLogger(ConsoleDialogController.class.getName()).log(Level.SEVERE, null, ex);
}
// Plug in the new streams
System.setOut(outStream);
System.setErr(errStream);
timeline = new Timeline(new KeyFrame(Duration.millis(REFRESH_PERIOD), new EventHandler<>() {
private long total;
private long used;
private long oldUsed;
private static final int diff = 1;
@Override
public void handle(ActionEvent event) {
total = runtime.totalMemory() / BYTES_PER_MB;
used = total - runtime.freeMemory() / BYTES_PER_MB;
if (used < oldUsed - diff || used > oldUsed + diff) {
JavaFXUtils.runLater(() -> {
memoryUsageProgressBar.setProgress((double) used / (double) total);
memoryUsageText.setText(used + "/" + total + " MB");
});
oldUsed = used;
}
}
}));
timeline.setCycleCount(Animation.INDEFINITE);
timeline.play();
// Close with the main application
MainView.getPrimaryStage().addEventHandler(WindowEvent.WINDOW_CLOSE_REQUEST, event -> handleCloseAction());
}
use of javafx.event.ActionEvent in project JFoenix by jfoenixadmin.
the class JFXDatePickerSkin method handleControlPropertyChanged.
@Override
protected void handleControlPropertyChanged(String p) {
if ("DEFAULT_COLOR".equals(p)) {
((JFXTextField) getEditor()).setFocusColor(jfxDatePicker.getDefaultColor());
} else if ("DAY_CELL_FACTORY".equals(p)) {
updateDisplayNode();
content = null;
popup = null;
} else if ("CONVERTER".equals(p)) {
updateDisplayNode();
} else if ("EDITOR".equals(p)) {
getEditableInputNode();
} else if ("SHOWING".equals(p)) {
if (jfxDatePicker.isShowing()) {
if (content != null) {
LocalDate date = jfxDatePicker.getValue();
// set the current date / now when showing the date picker content
content.displayedYearMonthProperty().set((date != null) ? YearMonth.from(date) : YearMonth.now());
content.updateValues();
}
show();
} else {
hide();
}
} else if ("SHOW_WEEK_NUMBERS".equals(p)) {
if (content != null) {
// update the content grid to show week numbers
content.updateContentGrid();
content.updateWeekNumberDateCells();
}
} else if ("VALUE".equals(p)) {
updateDisplayNode();
if (content != null) {
LocalDate date = jfxDatePicker.getValue();
content.displayedYearMonthProperty().set((date != null) ? YearMonth.from(date) : YearMonth.now());
content.updateValues();
}
jfxDatePicker.fireEvent(new ActionEvent());
} else {
super.handleControlPropertyChanged(p);
}
}
use of javafx.event.ActionEvent in project POL-POM-5 by PlayOnLinux.
the class RepositoriesPanelSkin method createRepositoryButtons.
/**
* Creates a new container for the repository buttons.
* These buttons consist of:
* - an add button
* - a delete button
* - a restore defaults button
*
* @param repositoryLocationTable The repository location table
* @return A new container for the repository buttons
*/
private HBox createRepositoryButtons(TableView<RepositoryLocation<? extends Repository>> repositoryLocationTable) {
final Button addButton = new Button(tr("Add"));
addButton.getStyleClass().add("repositories-add");
addButton.setOnAction((ActionEvent event) -> {
final AddRepositoryDialog dialog = new AddRepositoryDialog();
dialog.initOwner(getControl().getScene().getWindow());
final Optional<RepositoryLocation<? extends Repository>> successResult = dialog.showAndWait();
successResult.ifPresent(repositoryLocation -> getControl().getRepositoryLocations().add(0, repositoryLocation));
});
final Button removeButton = new Button(tr("Remove"));
removeButton.getStyleClass().add("repositories-remove");
removeButton.setOnAction((ActionEvent event) -> {
final List<RepositoryLocation<? extends Repository>> toRemove = repositoryLocationTable.getSelectionModel().getSelectedItems();
getControl().getRepositoryLocations().removeAll(toRemove);
});
final Button restoreDefault = new Button(tr("Restore defaults"));
restoreDefault.getStyleClass().add("repositories-restore");
restoreDefault.setOnAction(event -> {
final SimpleConfirmDialog dialog = SimpleConfirmDialog.builder().withTitle(tr("Restore default repositories")).withMessage(tr("Are you sure you want to restore the default repositories?")).withYesCallback(() -> Platform.runLater(() -> getControl().getRepositoryLocations().setAll(getControl().getRepositoryLocationLoader().getDefaultRepositoryLocations()))).withOwner(getControl().getScene().getWindow()).withResizable(true).build();
dialog.showAndCallback();
});
final HBox container = new HBox(addButton, removeButton, restoreDefault);
container.getStyleClass().add("repositories-buttons-container");
return container;
}
use of javafx.event.ActionEvent in project ETUmulator by kasirgalabs.
the class ETUmulator method start.
@Override
public void start(Stage primaryStage) throws IOException {
Module module = new ETUmulatorModule();
Injector injector = Guice.createInjector(module);
primaryStage.setTitle("ETUmulator");
ClassLoader classLoader = ETUmulator.class.getClassLoader();
FXMLLoader fxmlLoader = new FXMLLoader(classLoader.getResource("fxml/ETUmulator.fxml"));
fxmlLoader.setControllerFactory(injector::getInstance);
Parent root = fxmlLoader.load();
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.show();
injector.injectMembers(this);
fileMenuController.setWindow(primaryStage.getOwner());
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
processor.stop();
}
});
primaryStage.setOnCloseRequest((WindowEvent event) -> {
int firstOne = fileMenuController.getLength();
int lastOne = fileMenuController.document.getText().length();
if (firstOne != lastOne && !fileMenuController.document.getTargetFile().getName().equals("untitled")) {
Stage stage = new Stage();
VBox box = new VBox();
box.setPadding(new Insets(10));
box.setAlignment(Pos.CENTER);
Label label = new Label("Are you sure exit before saving?");
Button btnSave = new Button();
btnSave.setText("Save");
Button btnExit = new Button();
btnExit.setText("Exit");
btnExit.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.exit(0);
}
});
btnSave.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
try {
fileMenuController.document.saveDocument();
System.exit(0);
} catch (IOException ex) {
Logger.getLogger(ETUmulator.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
box.getChildren().add(label);
box.getChildren().add(btnSave);
box.getChildren().add(btnExit);
Scene scene1 = new Scene(box, 250, 150);
stage.setScene(scene1);
stage.show();
stage.show();
event.consume();
} else if (firstOne != lastOne && fileMenuController.document.getTargetFile().getName().equals("untitled")) {
Stage stage = new Stage();
VBox box = new VBox();
box.setPadding(new Insets(10));
box.setAlignment(Pos.CENTER);
Label label = new Label("Are you sure exit before saving?");
Button btnSave = new Button();
btnSave.setText("Save As");
Button btnExit = new Button();
btnExit.setText("Exit");
btnExit.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.exit(0);
}
});
btnSave.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
File file = fileMenuController.fileChooser.showSaveDialog(fileMenuController.window);
if (file == null) {
return;
}
fileMenuController.document.setTargetFile(file);
try {
fileMenuController.document.saveDocument();
} catch (IOException ex) {
Logger.getLogger(ETUmulator.class.getName()).log(Level.SEVERE, null, ex);
}
System.exit(0);
}
});
box.getChildren().add(label);
box.getChildren().add(btnSave);
box.getChildren().add(btnExit);
Scene scene1 = new Scene(box, 250, 150);
stage.setScene(scene1);
stage.show();
stage.show();
event.consume();
} else {
System.exit(0);
}
});
}
Aggregations