Search in sources :

Example 36 with ObservableValue

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

the class PacketTableView method buildUI.

/**
 * Build component UI
 */
private void buildUI(boolean addExportToYamlBtn) {
    setTopAnchor(this, 0d);
    setLeftAnchor(this, 0d);
    setBottomAnchor(this, 0d);
    setRightAnchor(this, 0d);
    // build btn bar
    HBox buttonContainer = new HBox();
    buttonContainer.setSpacing(5);
    // add build stream btn
    buildPacketBtn = new StreamTableButton(StreamTableAction.BUILD);
    buildPacketBtn.setId("buildStreamBtn");
    initializeStreamButtons(buildPacketBtn, false);
    buttonContainer.getChildren().add(buildPacketBtn);
    editPacketBtn = new StreamTableButton(StreamTableAction.EDIT);
    editPacketBtn.setId("editStreanBtn");
    initializeStreamButtons(editPacketBtn, true);
    buttonContainer.getChildren().add(editPacketBtn);
    duplicatePacketBtn = new StreamTableButton(StreamTableAction.DUPLICATE);
    initializeStreamButtons(duplicatePacketBtn, true);
    buttonContainer.getChildren().add(duplicatePacketBtn);
    deleteButtonBtn = new StreamTableButton(StreamTableAction.DELETE);
    initializeStreamButtons(deleteButtonBtn, true);
    buttonContainer.getChildren().add(deleteButtonBtn);
    importPcapButton = new StreamTableButton(StreamTableAction.IMPORT_PCAP);
    initializeStreamButtons(importPcapButton, false);
    buttonContainer.getChildren().add(importPcapButton);
    exportPcapButton = new StreamTableButton(StreamTableAction.EXPORT_TO_PCAP);
    initializeStreamButtons(exportPcapButton, true);
    buttonContainer.getChildren().add(exportPcapButton);
    if (addExportToYamlBtn) {
        exportToYaml = new StreamTableButton(StreamTableAction.EXPORT_TO_YAML);
        initializeStreamButtons(exportToYaml, false);
        buttonContainer.getChildren().add(exportToYaml);
    }
    getChildren().add(buttonContainer);
    setTopAnchor(buttonContainer, 5d);
    rightClickMenu = new ContextMenu();
    addMenuItem(StreamTableAction.EDIT);
    addMenuItem(StreamTableAction.DUPLICATE);
    addMenuItem(StreamTableAction.DELETE);
    addMenuItem(StreamTableAction.EXPORT_TO_PCAP);
    addMenuItem(StreamTableAction.EXPORT_TO_YAML);
    // add table view
    streamPacketTableView = new TableView<>();
    streamPacketTableView.setId("streamTableView");
    streamPacketTableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    streamPacketTableView.setFixedCellSize(32);
    streamPacketTableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    streamPacketTableView.setOnMouseClicked(new EventHandler<MouseEvent>() {

        @Override
        public void handle(MouseEvent event) {
            handleTableRowClick(event);
        }
    });
    streamPacketTableView.getSelectionModel().selectedItemProperty().addListener((ObservableValue<? extends TableProfileStream> observable, TableProfileStream oldValue, TableProfileStream newValue) -> {
        boolean notSelected = !(newValue != null);
        exportPcapButton.setDisable(notSelected);
        editPacketBtn.setDisable(notSelected);
        duplicatePacketBtn.setDisable(notSelected);
        deleteButtonBtn.setDisable(notSelected);
    });
    streamPacketTableView.addEventFilter(KeyEvent.KEY_RELEASED, (KeyEvent event) -> {
        if (isEditingCell()) {
            return;
        }
        if (copyCombination.match(event)) {
            copiedProfiles = getSelectedProfiles();
        } else if (pasteCombination.match(event) && !copiedProfiles.isEmpty()) {
            handlePasteStreams(copiedProfiles);
        } else if (event.getCode() == KeyCode.DELETE) {
            handleDeletePacket();
        }
    });
    streamPacketTableView.setEditable(true);
    initializeTableColumn();
    // disable table reordering
    streamPacketTableView.widthProperty().addListener(new ChangeListener<Number>() {

        @Override
        public void changed(ObservableValue<? extends Number> source, Number oldWidth, Number newWidth) {
            TableHeaderRow header = (TableHeaderRow) streamPacketTableView.lookup("TableHeaderRow");
            header.reorderingProperty().addListener(new ChangeListener<Boolean>() {

                @Override
                public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
                    header.setReordering(false);
                }
            });
        }
    });
    getChildren().add(streamPacketTableView);
    setTopAnchor(streamPacketTableView, 35d);
    setBottomAnchor(streamPacketTableView, 5d);
    setLeftAnchor(streamPacketTableView, 0d);
    setRightAnchor(streamPacketTableView, 0d);
}
Also used : HBox(javafx.scene.layout.HBox) TableHeaderRow(com.sun.javafx.scene.control.skin.TableHeaderRow) TableProfileStream(com.exalttech.trex.ui.views.models.TableProfileStream) ObservableValue(javafx.beans.value.ObservableValue) StreamTableButton(com.exalttech.trex.ui.views.streamtable.StreamTableButton) ChangeListener(javafx.beans.value.ChangeListener)

Example 37 with ObservableValue

use of javafx.beans.value.ObservableValue in project intellij-plugins by StepicOrg.

the class AuthDialog method makeProgressBarWithListener.

@NotNull
private ProgressBar makeProgressBarWithListener() {
    final ProgressBar progress = new ProgressBar();
    Worker<Void> loadWorker = engine.getLoadWorker();
    progress.progressProperty().bind(loadWorker.progressProperty());
    loadWorker.stateProperty().addListener(new ChangeListener<Worker.State>() {

        @Override
        public void changed(ObservableValue<? extends Worker.State> ov, Worker.State oldState, Worker.State newState) {
            if (newState == Worker.State.CANCELLED) {
                return;
            }
            if (newState == Worker.State.FAILED) {
                Map<String, Object> map = new HashMap<>();
                map.put("url", engine.getLocation());
                String content = Templater.processTemplate("error", map);
                engine.loadContent(content);
                return;
            }
            String location = engine.getLocation();
            if (location != null) {
                if (location.startsWith(Urls.STEPIK_URL + "/#")) {
                    String paramString = location.split("#")[1];
                    String[] params = paramString.split("&");
                    map.clear();
                    Arrays.stream(params).forEach(param -> {
                        String[] entry = param.split("=");
                        String value = "";
                        if (entry.length > 1) {
                            value = entry[1];
                        }
                        map.put(entry[0], value);
                    });
                    hide();
                    return;
                } else if ((Urls.STEPIK_URL + "/?error=access_denied").equals(location)) {
                    map.put("error", "access_denied");
                    hide();
                    return;
                }
            }
            progressBar.setVisible(newState == Worker.State.RUNNING);
            if (newState == Worker.State.SUCCEEDED) {
                AuthDialog.this.setTitle(engine.getTitle());
            }
        }

        private void hide() {
            loadWorker.cancel();
            setVisible(false);
        }
    });
    return progress;
}
Also used : Button(javafx.scene.control.Button) UIUtil(com.intellij.util.ui.UIUtil) Worker(javafx.concurrent.Worker) Pos(javafx.geometry.Pos) Scene(javafx.scene.Scene) WebEngine(javafx.scene.web.WebEngine) Arrays(java.util.Arrays) AllIcons(com.intellij.icons.AllIcons) HashMap(java.util.HashMap) JFXPanel(javafx.embed.swing.JFXPanel) CookieManager(org.stepik.plugin.auth.webkit.network.CookieManager) Insets(javafx.geometry.Insets) ProgressBar(javafx.scene.control.ProgressBar) CookieHandler(java.net.CookieHandler) Map(java.util.Map) Tooltip(javafx.scene.control.Tooltip) HBox(javafx.scene.layout.HBox) WebView(javafx.scene.web.WebView) WebHistory(javafx.scene.web.WebHistory) BufferedImage(java.awt.image.BufferedImage) Node(javafx.scene.Node) WritableImage(javafx.scene.image.WritableImage) Platform(javafx.application.Platform) java.awt(java.awt) Urls(org.stepik.api.urls.Urls) ImageView(javafx.scene.image.ImageView) SwingFXUtils(javafx.embed.swing.SwingFXUtils) ObservableValue(javafx.beans.value.ObservableValue) Templater(org.stepik.core.templates.Templater) BorderPane(javafx.scene.layout.BorderPane) StepikAuthManager(org.stepik.core.stepik.StepikAuthManager) ChangeListener(javafx.beans.value.ChangeListener) NotNull(org.jetbrains.annotations.NotNull) javax.swing(javax.swing) Worker(javafx.concurrent.Worker) ProgressBar(javafx.scene.control.ProgressBar) HashMap(java.util.HashMap) Map(java.util.Map) NotNull(org.jetbrains.annotations.NotNull)

Example 38 with ObservableValue

use of javafx.beans.value.ObservableValue in project jmeter by apache.

the class RenderInBrowser method createScene.

private void createScene(final String htmlContent) {
    Platform.setImplicitExit(false);
    Platform.runLater(() -> {
        WebView view = new WebView();
        engine = view.getEngine();
        engine.setOnStatusChanged(event -> SwingUtilities.invokeLater(() -> lblStatus.setText(event.getData())));
        engine.getLoadWorker().workDoneProperty().addListener((ChangeListener<Number>) (observableValue, oldValue, newValue) -> SwingUtilities.invokeLater(() -> progressBar.setValue(newValue.intValue())));
        engine.getLoadWorker().exceptionProperty().addListener((ObservableValue<? extends Throwable> o, Throwable old, final Throwable value) -> {
            if (engine.getLoadWorker().getState() == State.FAILED) {
                SwingUtilities.invokeLater(() -> JOptionPane.showMessageDialog(resultsScrollPane, (value != null) ? engine.getLocation() + "\n" + value.getMessage() : engine.getLocation() + "\nUnexpected error.", "Loading error...", JOptionPane.ERROR_MESSAGE));
            }
        });
        jfxPanel.setScene(new Scene(view));
    });
}
Also used : JMeterUtils(org.apache.jmeter.util.JMeterUtils) Scene(javafx.scene.Scene) WebView(javafx.scene.web.WebView) WebEngine(javafx.scene.web.WebEngine) BorderFactory(javax.swing.BorderFactory) SampleResult(org.apache.jmeter.samplers.SampleResult) JOptionPane(javax.swing.JOptionPane) JFXPanel(javafx.embed.swing.JFXPanel) Platform(javafx.application.Platform) Dimension(java.awt.Dimension) SwingUtilities(javax.swing.SwingUtilities) JLabel(javax.swing.JLabel) State(javafx.concurrent.Worker.State) ObservableValue(javafx.beans.value.ObservableValue) BorderLayout(java.awt.BorderLayout) ChangeListener(javafx.beans.value.ChangeListener) JProgressBar(javax.swing.JProgressBar) JPanel(javax.swing.JPanel) ObservableValue(javafx.beans.value.ObservableValue) WebView(javafx.scene.web.WebView) Scene(javafx.scene.Scene)

Example 39 with ObservableValue

use of javafx.beans.value.ObservableValue in project ETUmulator by kasirgalabs.

the class ArrowFunction method apply.

@Override
public Node apply(int lineNumber) {
    Polygon triangle = new Polygon(0.0, 0.0, 10.0, 5.0, 0.0, 10.0);
    triangle.setFill(Color.GREEN);
    ObservableValue<Boolean> visible = Val.map(shownLine, sl -> sl == lineNumber);
    triangle.visibleProperty().bind(Val.flatMap(triangle.sceneProperty(), scene -> {
        return scene != null ? visible : Val.constant(false);
    }));
    return triangle;
}
Also used : Color(javafx.scene.paint.Color) Val(org.reactfx.value.Val) Node(javafx.scene.Node) ObservableValue(javafx.beans.value.ObservableValue) Polygon(javafx.scene.shape.Polygon) IntFunction(java.util.function.IntFunction) Polygon(javafx.scene.shape.Polygon)

Example 40 with ObservableValue

use of javafx.beans.value.ObservableValue in project azure-tools-for-java by Microsoft.

the class JobViewPanel method init.

private void init(final JFXPanel panel) {
    String url = rootPath + "/com.microsoft.hdinsight/hdinsight/job/html/index.html";
    url = url.replace("\\", "/");
    final String queryString = "?projectid=" + id + "&engintype=javafx";
    final String weburl = "file:///" + url + queryString;
    Platform.setImplicitExit(false);
    Platform.runLater(() -> {
        webView = new WebView();
        webEngine = webView.getEngine();
        webEngine.setJavaScriptEnabled(true);
        webEngine.getLoadWorker().stateProperty().addListener((ObservableValue<? extends Worker.State> ov, Worker.State oldState, Worker.State newState) -> {
            if (newState == Worker.State.SUCCEEDED) {
                JSObject win = (JSObject) webEngine.executeScript("window");
                win.setMember("JobUtils", jobUtil);
            }
        });
        panel.setScene(new Scene(webView));
        if (!alreadyLoad) {
            webEngine.load(weburl);
            alreadyLoad = true;
        }
    });
}
Also used : ObservableValue(javafx.beans.value.ObservableValue) JSObject(netscape.javascript.JSObject) WebView(javafx.scene.web.WebView) Scene(javafx.scene.Scene)

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