Search in sources :

Example 76 with ObservableValue

use of javafx.beans.value.ObservableValue in project browsermator by pcalkins.

the class BrowserMatorFileCloud method ShowHTMLWindow.

public void ShowHTMLWindow(String url) {
    try {
        URLConnection connection = new URL(url).openConnection();
        connection.setDoOutput(true);
        BufferedReader in = new BufferedReader(new InputStreamReader(((HttpURLConnection) connection).getInputStream()));
        String inputLine;
        while ((inputLine = in.readLine()) != null) HTML_TO_SEND += inputLine;
        in.close();
    } catch (Exception ex) {
        HTML_TO_SEND = "Unable to connect to browsermator.com.";
        System.out.println("Exception browsing cloud: " + ex.toString());
        LoadingLabel.setVisible(false);
    }
    // String HTML_TO_SEND = HTML;
    Platform.runLater(new Runnable() {

        @Override
        public void run() {
            browser2 = new WebView();
            webEngine = browser2.getEngine();
            webEngine.getLoadWorker().stateProperty().addListener(new ChangeListener<State>() {

                @Override
                public void changed(ObservableValue ov, State oldState, State newState) {
                    if (newState == Worker.State.SUCCEEDED) {
                        JavaApp appREF = new JavaApp(webEngine);
                        JSObject win = (JSObject) webEngine.executeScript("window");
                        win.setMember("app", appREF);
                    }
                }
            });
            if (HTML_TO_SEND == "Unable to connect to browsermator.com.") {
                webEngine.loadContent(HTML_TO_SEND);
            } else {
                webEngine.load(url);
            }
            Scene scene = new Scene(browser2);
            fxPanel.setScene(scene);
            LoadingLabel.setVisible(false);
            webEngine.locationProperty().addListener(new ChangeListener<String>() {

                @Override
                public void changed(ObservableValue<? extends String> observableValue, String oldLoc, String newLoc) {
                    if (newLoc.contains("serve_file")) {
                        String[] filename_parts = newLoc.split("\\?");
                        String[] queryvalues = filename_parts[1].split("&");
                        String[] filename_value = queryvalues[0].split("=");
                        String[] file_idvalue = queryvalues[1].split("=");
                        String[] filedate_value = queryvalues[2].split("=");
                        String file_id = file_idvalue[1];
                        String filename = filename_value[1];
                        try {
                            filename = URLDecoder.decode(filename_value[1], "UTF-8");
                        } catch (Exception ex) {
                            System.out.println("Exception when decoding HTML: " + ex.toString());
                        }
                        String file_date = filedate_value[1];
                        String extension = ".browsermation";
                        File thisFile = new File(CLOUDFOLDER + filename + extension);
                        if (thisFile.exists()) {
                            Boolean checkdate = CheckIfFileIsNew(file_date, file_id);
                            if (checkdate) {
                                try {
                                    org.apache.commons.io.FileUtils.copyURLToFile(new URL(newLoc), new File(CLOUDFOLDER + filename + extension));
                                    mainAppController.OpenFile(thisFile, false, true);
                                    UpdateCloudConfig(file_id, file_date);
                                    cloudFrame.dispose();
                                } catch (Exception x) {
                                    System.out.println("Exception downloading file" + x.toString());
                                }
                            } else {
                                mainAppController.OpenFile(thisFile, false, true);
                                // Platform.exit();
                                cloudFrame.dispose();
                            }
                        } else {
                            try {
                                org.apache.commons.io.FileUtils.copyURLToFile(new URL(newLoc), new File(CLOUDFOLDER + filename + extension));
                                UpdateCloudConfig(file_id, file_date);
                                mainAppController.OpenFile(thisFile, false, true);
                                // Platform.exit();
                                cloudFrame.dispose();
                            } catch (Exception x) {
                                System.out.println("Exception downloading file" + x.toString());
                            }
                        }
                    }
                }
            });
        }
    });
    JPanel topPanel = new JPanel();
    FlowLayout newFlow = new FlowLayout();
    topPanel.setLayout(newFlow);
    // mainApp.LoadNameAndPassword();
    mainAppController.LookUpUser(mainAppController.loginName, mainAppController.loginPassword);
    if (mainAppController.user_id > 0) {
        loginLabelText = new JLabel("Welcome " + mainAppController.loginName + " you are currently logged in. ");
        loginButton = new JButton("Switch user");
        addloginButtonActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent evt) {
                LoginDialogLauncher();
            }
        });
        topPanel.add(loginLabelText);
        topPanel.add(loginButton);
    } else {
        loginLabelText = new JLabel("You are not logged in. Login to view private files: ");
        // JLabel loginLabelName = new JLabel ("Name:");
        // JLabel loginLabelPassword = new JLabel ("Password:");
        // JTextField loginFieldName = new JTextField("", 10);
        // JPasswordField loginFieldPassword = new JPasswordField("",10);
        topPanel.add(loginLabelText);
        loginButton = new JButton("Login");
        addloginButtonActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent evt) {
                LoginDialogLauncher();
            }
        });
        // topPanel.add(loginLabelName);
        // topPanel.add(loginFieldName);
        // topPanel.add(loginLabelPassword);
        // topPanel.add(loginFieldPassword);
        topPanel.add(loginButton);
    }
    fxPanel.setVisible(true);
    fxPanel.setSize(800, 800);
    mainPanel = new JPanel(new BorderLayout());
    mainPanel.add(topPanel, BorderLayout.NORTH);
    mainPanel.add(fxPanel, BorderLayout.CENTER);
    mainPanel.add(bottomPanel, BorderLayout.SOUTH);
    mainPanel.setVisible(true);
    cloudFrame = new JFrame("BrowserMation File Cloud");
    cloudFrame.add(mainPanel);
    cloudFrame.setSize(800, 800);
    cloudFrame.setVisible(true);
}
Also used : JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) ActionEvent(java.awt.event.ActionEvent) ObservableValue(javafx.beans.value.ObservableValue) JButton(javax.swing.JButton) JSObject(netscape.javascript.JSObject) URL(java.net.URL) HttpURLConnection(java.net.HttpURLConnection) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) ChangeListener(javafx.beans.value.ChangeListener) WebView(javafx.scene.web.WebView) InputStreamReader(java.io.InputStreamReader) JLabel(javax.swing.JLabel) Scene(javafx.scene.Scene) HttpURLConnection(java.net.HttpURLConnection) URLConnection(java.net.URLConnection) ActionListener(java.awt.event.ActionListener) State(javafx.concurrent.Worker.State) BufferedReader(java.io.BufferedReader) File(java.io.File)

Example 77 with ObservableValue

use of javafx.beans.value.ObservableValue in project trex-stateless-gui by cisco-system-traffic-generator.

the class MainViewController method initializeInlineComponent.

/**
 * Initialize in-line built component
 */
private void initializeInlineComponent() {
    updateBtn.setGraphic(new ImageView(new Image("/icons/apply.png")));
    newProfileBtn.setGraphic(new ImageView(new Image("/icons/add_profile.png")));
    duplicateProfileBtn.setGraphic(new ImageView(new Image("/icons/clone_profile.png")));
    stopUpdateBtn.setGraphic(new ImageView(new Image("/icons/stop_update.png")));
    devicesTreeArrowContainer.setImage(leftArrow);
    // mapped profiles enabling with property
    profileListBox.disableProperty().bind(disableProfileProperty);
    newProfileBtn.disableProperty().bind(disableProfileProperty);
    duplicateProfileBtn.disableProperty().bind(disableProfileProperty);
    profileDetailLabel.disableProperty().bind(disableProfileProperty);
    profileListBox.getItems().clear();
    profileListBox.setItems(FXCollections.observableArrayList(getProfilesNameList()));
    profileListBox.valueProperty().addListener(new UpdateProfileListener<>(profileListBox.getSelectionModel()));
    updateProfileListProperty.bind(ProfileManager.getInstance().getUpdatedProperty());
    updateProfileListProperty.addListener((ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
        List<String> profiles = getProfilesNameList();
        profileListBox.setItems(FXCollections.observableArrayList(profiles));
        if (!profiles.contains(currentSelectedProfile)) {
            tableView.reset();
            profileDetailContainer.setVisible(false);
        }
    });
    tableView = new PacketTableView(230, this, true);
    profileTableViewContainer.getChildren().add(tableView);
    serverStatusIcon.setImage(new Image("/icons/offline.png"));
    // initialize right click menu
    rightClickPortMenu = new ContextMenu();
    addMenuItem(rightClickPortMenu, "Acquire", ContextMenuClickType.ACQUIRE, false);
    addMenuItem(rightClickPortMenu, "Force Acquire", ContextMenuClickType.FORCE_ACQUIRE, false);
    addMenuItem(rightClickPortMenu, "Release Acquire", ContextMenuClickType.RELEASE_ACQUIRE, false);
    addMenuItem(rightClickPortMenu, "Enable Service Mode", ContextMenuClickType.ENABLE_SERVICE, false);
    addMenuItem(rightClickPortMenu, "Disable Service Mode", ContextMenuClickType.DISABLE_SERVICE, false);
    rightClickProfileMenu = new ContextMenu();
    addMenuItem(rightClickProfileMenu, "Play", ContextMenuClickType.PLAY, false);
    addMenuItem(rightClickProfileMenu, "Pause", ContextMenuClickType.PAUSE, false);
    addMenuItem(rightClickProfileMenu, "Stop", ContextMenuClickType.STOP, false);
    rightClickGlobalMenu = new ContextMenu();
    addMenuItem(rightClickGlobalMenu, "Release All Ports", ContextMenuClickType.RELEASE_ALL, false);
    addMenuItem(rightClickGlobalMenu, "Acquire All Ports", ContextMenuClickType.ACQUIRE_ALL, false);
    addMenuItem(rightClickGlobalMenu, "Force Acquire All Ports", ContextMenuClickType.FORCE_ACQUIRE_ALL, false);
    addMenuItem(rightClickGlobalMenu, "Re-Acquire my Ports", ContextMenuClickType.ACQUIRE_MY_PORT, false);
    // initialize multiplexer
    multiplierView = new MultiplierView(this);
    multiplierOptionContainer.getChildren().add(multiplierView);
    notificationPanel = new NotificationPanel();
    notificationPanel.setNotificationMsg(DISABLED_MULTIPLIER_MSG);
    notificationPanelHolder.getChildren().add(notificationPanel);
    // add close
    TrexApp.getPrimaryStage().setOnCloseRequest(new EventHandler<WindowEvent>() {

        @Override
        public void handle(WindowEvent event) {
            // handle aplpication close
            DialogManager.getInstance().closeAll();
            handleAppClose();
        }
    });
    TrexApp.getPrimaryStage().setOnShown(new EventHandler<WindowEvent>() {

        @Override
        public void handle(WindowEvent event) {
            TrexApp.getPrimaryStage().focusedProperty().addListener((ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
                if (newValue && tableView.isStreamEditingWindowOpen()) {
                    tableView.setStreamEditingWindowOpen(false);
                    streamTableUpdated();
                }
            });
        }
    });
    TrexApp.getPrimaryStage().setOnCloseRequest(new EventHandler<WindowEvent>() {

        @Override
        public void handle(WindowEvent event) {
            System.exit(0);
        }
    });
    logContainer.getChildren().add(LogsController.getInstance().getView());
    // initialize countdown service
    countdownService = new CountdownService();
    countdownService.setPeriod(Duration.seconds(Constants.REFRESH_ONE_INTERVAL_SECONDS));
    countdownService.setRestartOnFailure(false);
    countdownService.setOnSucceeded((WorkerStateEvent event) -> {
        int count = (int) event.getSource().getValue();
        countdownValue.setText(String.valueOf(count) + " Sec");
        if (count == 0) {
            doUpdateAssignedProfile();
        }
    });
    devicesTree.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() {

        @Override
        public void changed(ObservableValue observable, Object oldValue, Object newValue) {
            handleTreeItemSelectionChanged();
        }
    });
}
Also used : ObservableValue(javafx.beans.value.ObservableValue) Image(javafx.scene.image.Image) NotificationPanel(com.exalttech.trex.ui.components.NotificationPanel) CountdownService(com.exalttech.trex.ui.views.services.CountdownService) MultiplierView(com.exalttech.trex.ui.views.MultiplierView) WindowEvent(javafx.stage.WindowEvent) WorkerStateEvent(javafx.concurrent.WorkerStateEvent) ChangeListener(javafx.beans.value.ChangeListener) JsonObject(com.google.gson.JsonObject) ImageView(javafx.scene.image.ImageView) PacketTableView(com.exalttech.trex.ui.views.PacketTableView)

Example 78 with ObservableValue

use of javafx.beans.value.ObservableValue in project trex-stateless-gui by cisco-system-traffic-generator.

the class MultiplierOption method buildUI.

/**
 * Build multiplier view UI
 *
 * @param title
 * @param group
 */
private void buildUI(String title, ToggleGroup group) {
    // add radio button
    selection = new RadioButton(title);
    selection.setToggleGroup(group);
    selection.selectedProperty().addListener((ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
        if (newValue) {
            multiplierSelectionEvent.onMultiplierSelect(type);
        }
        value.setDisable(!newValue);
    });
    setTooltip();
    getChildren().add(selection);
    MultiplierOption.setTopAnchor(selection, 15d);
    MultiplierOption.setLeftAnchor(selection, 0d);
    // text field
    value = new TextField();
    value.setPrefSize(120, 22);
    value.setDisable(true);
    value.addEventFilter(KeyEvent.KEY_RELEASED, multiplierSelectionEvent.validateInput());
    String regex = unitRegex();
    final UnaryOperator<TextFormatter.Change> keyPressFilter = c -> {
        String text = c.getControlNewText();
        if (text.matches(regex)) {
            return c;
        } else {
            return null;
        }
    };
    value.setTextFormatter(new TextFormatter<>(keyPressFilter));
    getChildren().add(value);
    MultiplierOption.setTopAnchor(value, 43d);
    MultiplierOption.setLeftAnchor(value, 0d);
    MultiplierOption.setBottomAnchor(value, 15d);
}
Also used : TextField(javafx.scene.control.TextField) MultiplierType(com.exalttech.trex.ui.MultiplierType) Util(com.exalttech.trex.util.Util) UnaryOperator(java.util.function.UnaryOperator) KeyEvent(javafx.scene.input.KeyEvent) TextFormatter(javafx.scene.control.TextFormatter) Logger(org.apache.log4j.Logger) ToggleGroup(javafx.scene.control.ToggleGroup) AnchorPane(javafx.scene.layout.AnchorPane) RadioButton(javafx.scene.control.RadioButton) ObservableValue(javafx.beans.value.ObservableValue) MultiplierSelectionEvent(com.exalttech.trex.ui.components.events.MultiplierSelectionEvent) Tooltip(javafx.scene.control.Tooltip) ObservableValue(javafx.beans.value.ObservableValue) TextField(javafx.scene.control.TextField) RadioButton(javafx.scene.control.RadioButton)

Example 79 with ObservableValue

use of javafx.beans.value.ObservableValue in project trex-stateless-gui by cisco-system-traffic-generator.

the class TextFieldTableViewCell method call.

@Override
public TableCell call(TableColumn param) {
    return new TableCell<S, T>() {

        private TextField textField;

        {
            textField = new TextField();
            textField.setPrefSize(158, 22);
            textField.setOnKeyPressed((KeyEvent event) -> {
                if (event.getCode().equals(KeyCode.ENTER)) {
                    commitEdit((T) textField.getText());
                }
            });
            textField.focusedProperty().addListener((ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
                if (!newValue) {
                    commitEdit((T) textField.getText());
                }
            });
            textField.textProperty().bindBidirectional(textProperty());
        }

        @Override
        public void updateItem(final T item, final boolean empty) {
            super.updateItem(item, empty);
            if (empty) {
                setText(null);
                setGraphic(null);
            } else {
                setGraphic(textField);
                setText((String) getItem());
            }
        }

        @Override
        public void commitEdit(T item) {
            if (!isEditing() && !item.equals(getItem())) {
                TableView<S> table = getTableView();
                if (table != null) {
                    TableColumn<S, T> column = getTableColumn();
                    CellEditEvent<S, T> event = new CellEditEvent<>(table, new TablePosition<S, T>(table, getIndex(), column), TableColumn.editCommitEvent(), item);
                    Event.fireEvent(column, event);
                }
            }
            super.commitEdit(item);
        }
    };
}
Also used : KeyEvent(javafx.scene.input.KeyEvent) TableCell(javafx.scene.control.TableCell) ObservableValue(javafx.beans.value.ObservableValue) TextField(javafx.scene.control.TextField) CellEditEvent(javafx.scene.control.TableColumn.CellEditEvent)

Example 80 with ObservableValue

use of javafx.beans.value.ObservableValue in project trex-stateless-gui by cisco-system-traffic-generator.

the class ConnectDialogController method initialize.

@Override
public void initialize(URL url, ResourceBundle rb) {
    initializeConnections();
    isConnectionInProgress = new SimpleBooleanProperty(false);
    isConnectionInProgress.addListener((ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
        if (newValue != null) {
            mainViewContainer.setDisable(newValue);
            mainViewContainer.getScene().setCursor(newValue ? Cursor.WAIT : Cursor.DEFAULT);
        }
    });
    timeoutField.textProperty().addListener((observable, oldValue, newValue) -> {
        if (!newValue.matches("\\d*")) {
            timeoutField.setText(newValue.replaceAll("[^\\d]", ""));
        }
    });
}
Also used : SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) ObservableValue(javafx.beans.value.ObservableValue)

Aggregations

ObservableValue (javafx.beans.value.ObservableValue)85 ChangeListener (javafx.beans.value.ChangeListener)53 FXML (javafx.fxml.FXML)13 Scene (javafx.scene.Scene)13 ImageView (javafx.scene.image.ImageView)13 KeyEvent (javafx.scene.input.KeyEvent)11 ArrayList (java.util.ArrayList)10 Label (javafx.scene.control.Label)10 TableColumn (javafx.scene.control.TableColumn)10 TableView (javafx.scene.control.TableView)10 ActionEvent (javafx.event.ActionEvent)9 MouseEvent (javafx.scene.input.MouseEvent)9 TextField (javafx.scene.control.TextField)8 Color (javafx.scene.paint.Color)8 ObservableList (javafx.collections.ObservableList)7 MenuItem (javafx.scene.control.MenuItem)7 CellDataFeatures (javafx.scene.control.TableColumn.CellDataFeatures)7 List (java.util.List)6 Set (java.util.Set)6 Platform (javafx.application.Platform)6