Search in sources :

Example 61 with ActionEvent

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();
    }
}
Also used : EventHandler(javafx.event.EventHandler) JsonObject(com.google.gson.JsonObject) Initializable(javafx.fxml.Initializable) javafx.scene.control(javafx.scene.control) URL(java.net.URL) CountdownService(com.exalttech.trex.ui.views.services.CountdownService) LogType(com.exalttech.trex.ui.views.logs.LogType) TrexApp(com.exalttech.trex.application.TrexApp) TrafficException(com.exalttech.trex.remote.exceptions.TrafficException) Logger(org.apache.log4j.Logger) Task(javafx.concurrent.Task) StatsStorage(com.cisco.trex.stl.gui.storages.StatsStorage) PortModel(com.exalttech.trex.ui.models.PortModel) Gson(com.google.gson.Gson) RunningConfiguration(com.cisco.trex.stl.gui.util.RunningConfiguration) WindowEvent(javafx.stage.WindowEvent) Pane(javafx.scene.layout.Pane) Profile(com.exalttech.trex.remote.models.profiles.Profile) StatsTableGenerator(com.exalttech.trex.ui.views.statistics.StatsTableGenerator) PortView(com.exalttech.trex.ui.controllers.ports.PortView) PortState(com.exalttech.trex.ui.PortState) Util(com.exalttech.trex.util.Util) ProfileManager(com.exalttech.trex.util.ProfileManager) KeyEvent(javafx.scene.input.KeyEvent) MultiplierView(com.exalttech.trex.ui.views.MultiplierView) TrexAlertBuilder(com.exalttech.trex.ui.util.TrexAlertBuilder) DialogManager(com.exalttech.trex.ui.dialog.DialogManager) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) SystemInfoReq(com.exalttech.trex.ui.models.SystemInfoReq) JsonArray(com.google.gson.JsonArray) BooleanProperty(javafx.beans.property.BooleanProperty) Duration(javafx.util.Duration) PortManagerEventHandler(com.exalttech.trex.ui.PortManagerEventHandler) AnchorPane(javafx.scene.layout.AnchorPane) Constants(com.exalttech.trex.util.Constants) PacketTableView(com.exalttech.trex.ui.views.PacketTableView) MultiplierOptionChangeHandler(com.exalttech.trex.ui.views.MultiplierOptionChangeHandler) WorkerStateEvent(javafx.concurrent.WorkerStateEvent) UnsupportedEncodingException(java.io.UnsupportedEncodingException) TreeItemType(com.exalttech.trex.ui.components.CustomTreeItem.TreeItemType) RefreshingService(com.exalttech.trex.ui.views.services.RefreshingService) MouseButton(javafx.scene.input.MouseButton) java.util(java.util) Connection(com.exalttech.trex.ui.models.datastore.Connection) MultiplierType(com.exalttech.trex.ui.MultiplierType) MouseEvent(javafx.scene.input.MouseEvent) NotificationPanel(com.exalttech.trex.ui.components.NotificationPanel) FXCollections(javafx.collections.FXCollections) Level(java.util.logging.Level) ProfileMultiplier(com.exalttech.trex.ui.views.models.ProfileMultiplier) EventBus(com.google.common.eventbus.EventBus) InvalidRPCResponseException(com.exalttech.trex.remote.exceptions.InvalidRPCResponseException) PortsManager(com.exalttech.trex.ui.PortsManager) Subscribe(com.google.common.eventbus.Subscribe) StreamValidation(com.exalttech.trex.remote.models.validate.StreamValidation) InitPacketEditorEvent(com.xored.javafx.packeteditor.events.InitPacketEditorEvent) LogsController(com.exalttech.trex.ui.views.logs.LogsController) KeyCode(javafx.scene.input.KeyCode) TRexClient(com.cisco.trex.stateless.TRexClient) CustomTreeItem(com.exalttech.trex.ui.components.CustomTreeItem) ConnectionsWrapper(com.exalttech.trex.ui.models.datastore.ConnectionsWrapper) PacketTableUpdatedHandler(com.exalttech.trex.ui.views.PacketTableUpdatedHandler) XMLFileManager(com.exalttech.trex.util.files.XMLFileManager) AssignedProfile(com.exalttech.trex.ui.views.models.AssignedProfile) com.exalttech.trex.core(com.exalttech.trex.core) IncorrectRPCMethodException(com.exalttech.trex.remote.exceptions.IncorrectRPCMethodException) PortAcquireException(com.exalttech.trex.remote.exceptions.PortAcquireException) ScapyClientNeedConnectEvent(com.xored.javafx.packeteditor.events.ScapyClientNeedConnectEvent) IOException(java.io.IOException) FlowStats(com.exalttech.trex.remote.models.profiles.FlowStats) Port(com.exalttech.trex.ui.models.Port) File(java.io.File) StatsLoader(com.exalttech.trex.ui.views.statistics.StatsLoader) Consumer(java.util.function.Consumer) ActionEvent(javafx.event.ActionEvent) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) ImageView(javafx.scene.image.ImageView) ObservableValue(javafx.beans.value.ObservableValue) ChangeListener(javafx.beans.value.ChangeListener) Image(javafx.scene.image.Image) DialogWindow(com.exalttech.trex.ui.dialog.DialogWindow) Port(com.exalttech.trex.ui.models.Port) IOException(java.io.IOException) DialogWindow(com.exalttech.trex.ui.dialog.DialogWindow) FXML(javafx.fxml.FXML)

Example 62 with ActionEvent

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());
}
Also used : PrintStream(java.io.PrintStream) Timeline(javafx.animation.Timeline) ActionEvent(javafx.event.ActionEvent) OutputStream(java.io.OutputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) KeyFrame(javafx.animation.KeyFrame) InjectFXML(jgnash.uifx.util.InjectFXML) FXML(javafx.fxml.FXML)

Example 63 with ActionEvent

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);
    }
}
Also used : ActionEvent(javafx.event.ActionEvent) JFXTextField(com.jfoenix.controls.JFXTextField) LocalDate(java.time.LocalDate)

Example 64 with ActionEvent

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;
}
Also used : Repository(org.phoenicis.repository.types.Repository) HBox(javafx.scene.layout.HBox) AddRepositoryDialog(org.phoenicis.javafx.views.mainwindow.settings.addrepository.AddRepositoryDialog) ActionEvent(javafx.event.ActionEvent) SimpleConfirmDialog(org.phoenicis.javafx.dialogs.SimpleConfirmDialog) RepositoryLocation(org.phoenicis.repository.location.RepositoryLocation)

Example 65 with ActionEvent

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);
        }
    });
}
Also used : Insets(javafx.geometry.Insets) Parent(javafx.scene.Parent) ActionEvent(javafx.event.ActionEvent) Label(javafx.scene.control.Label) EventHandler(javafx.event.EventHandler) IOException(java.io.IOException) Scene(javafx.scene.Scene) FXMLLoader(javafx.fxml.FXMLLoader) Button(javafx.scene.control.Button) Injector(com.google.inject.Injector) WindowEvent(javafx.stage.WindowEvent) Stage(javafx.stage.Stage) Module(com.google.inject.Module) VBox(javafx.scene.layout.VBox) File(java.io.File)

Aggregations

ActionEvent (javafx.event.ActionEvent)171 EventHandler (javafx.event.EventHandler)61 Stage (javafx.stage.Stage)52 KeyFrame (javafx.animation.KeyFrame)47 Timeline (javafx.animation.Timeline)47 FXML (javafx.fxml.FXML)44 Alert (javafx.scene.control.Alert)36 Button (javafx.scene.control.Button)35 Label (javafx.scene.control.Label)35 MenuItem (javafx.scene.control.MenuItem)33 ContextMenu (javafx.scene.control.ContextMenu)25 File (java.io.File)24 Insets (javafx.geometry.Insets)24 Scene (javafx.scene.Scene)24 List (java.util.List)21 ObservableList (javafx.collections.ObservableList)21 Node (javafx.scene.Node)20 TextField (javafx.scene.control.TextField)20 Optional (java.util.Optional)18 FXCollections (javafx.collections.FXCollections)18