Search in sources :

Example 21 with ComboBox

use of javafx.scene.control.ComboBox in project kanonizo by kanonizo.

the class KanonizoFrame method getParameterField.

private Control getParameterField(Field param, boolean runPrerequisites) {
    Control parameterField = null;
    Class<?> type = param.getType();
    if (type.equals(boolean.class) || type.equals(Boolean.class)) {
        parameterField = new CheckBox();
        ((CheckBox) parameterField).selectedProperty().addListener((obs, old, nw) -> {
            try {
                Util.setParameter(param, nw.toString());
                if (runPrerequisites) {
                    addErrors(fw.getAlgorithm());
                }
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        });
        try {
            ((CheckBox) parameterField).setSelected((Boolean) param.get(null));
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    } else if (param.getType().equals(String.class) || param.getType().isPrimitive() || param.getType().isAssignableFrom(Number.class)) {
        parameterField = new TextField();
        ((TextField) parameterField).textProperty().addListener((obs, old, nw) -> {
            try {
                Util.setParameter(param, nw);
                if (runPrerequisites) {
                    addErrors(fw.getAlgorithm());
                }
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        });
        try {
            ((TextField) parameterField).setText(param.get(null).toString());
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    } else if (param.getType().equals(File.class)) {
        try {
            Button control = new Button();
            File paramFile = (File) param.get(null);
            control.setText(paramFile == null ? "Select File" : paramFile.getName());
            control.setOnAction(ev -> {
                FileChooser fc = new FileChooser();
                File f = fc.showOpenDialog(KanonizoFxApplication.stage);
                try {
                    Util.setParameter(param, f == null ? null : f.getAbsolutePath());
                    if (runPrerequisites) {
                        addErrors(fw.getAlgorithm());
                    }
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
                control.setText(f == null ? "Select File" : f.getName());
            });
            parameterField = control;
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    } else if (param.getAnnotation(Parameter.class).hasOptions()) {
        String paramKey = param.getAnnotation(Parameter.class).key();
        Method[] methods = param.getDeclaringClass().getMethods();
        Optional<Method> optionProviderOpt = Arrays.asList(methods).stream().filter(m -> m.getAnnotation(OptionProvider.class) != null && m.getAnnotation(OptionProvider.class).paramKey().equals(paramKey)).findFirst();
        if (!optionProviderOpt.isPresent()) {
            logger.error("Missing OptionProvider for key" + paramKey);
            return null;
        }
        Method optionProvider = optionProviderOpt.get();
        if (optionProvider.getReturnType() != List.class) {
            logger.error("OptionProvider must return a list");
            return null;
        }
        if (!Modifier.isStatic(optionProvider.getModifiers())) {
            logger.error("OptionProvider must be static");
            return null;
        }
        try {
            List<?> options = (List<?>) optionProvider.invoke(null, null);
            parameterField = new ComboBox();
            ((ComboBox) parameterField).getItems().addAll(options);
            ((ComboBox) parameterField).getSelectionModel().selectedItemProperty().addListener((ov, old, nw) -> {
                try {
                    param.set(null, nw);
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            });
            ((ComboBox) parameterField).setConverter(new StringConverter() {

                @Override
                public String toString(Object object) {
                    return object.getClass().getSimpleName();
                }

                @Override
                public Object fromString(String string) {
                    String comparatorPackage = "org.kanonizo.algorithms.heuristics.comparators";
                    try {
                        return Class.forName(comparatorPackage + "." + string).newInstance();
                    } catch (InstantiationException e) {
                        e.printStackTrace();
                    } catch (IllegalAccessException e) {
                        e.printStackTrace();
                    } catch (ClassNotFoundException e) {
                        e.printStackTrace();
                    }
                    return null;
                }
            });
            try {
                ((ComboBox) parameterField).getSelectionModel().select(param.get(null));
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }
    return parameterField;
}
Also used : Button(javafx.scene.control.Button) Pos(javafx.geometry.Pos) Arrays(java.util.Arrays) Initializable(javafx.fxml.Initializable) AlertUtils(org.kanonizo.gui.AlertUtils) TestSuite(org.kanonizo.framework.objects.TestSuite) URL(java.net.URL) Control(javafx.scene.control.Control) StackPane(javafx.scene.layout.StackPane) VBox(javafx.scene.layout.VBox) Application(javafx.application.Application) Task(javafx.concurrent.Task) AlertType(javafx.scene.control.Alert.AlertType) ComboBox(javafx.scene.control.ComboBox) ContextMenu(javafx.scene.control.ContextMenu) Method(java.lang.reflect.Method) ScriptException(javax.script.ScriptException) Rectangle2D(javafx.geometry.Rectangle2D) TextField(javafx.scene.control.TextField) SearchAlgorithm(org.kanonizo.algorithms.SearchAlgorithm) MenuItem(javafx.scene.control.MenuItem) Set(java.util.Set) ConditionalParameter(org.kanonizo.annotations.ConditionalParameter) Screen(javafx.stage.Screen) OptionProvider(org.kanonizo.annotations.OptionProvider) Collectors(java.util.stream.Collectors) TreeView(javafx.scene.control.TreeView) InvocationTargetException(java.lang.reflect.InvocationTargetException) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) List(java.util.List) Util(org.kanonizo.util.Util) Logger(org.apache.logging.log4j.Logger) PropertyChangeListener(java.beans.PropertyChangeListener) Modifier(java.lang.reflect.Modifier) Optional(java.util.Optional) Display(org.kanonizo.display.Display) ObservableList(javafx.collections.ObservableList) BorderPane(javafx.scene.layout.BorderPane) Scene(javafx.scene.Scene) MouseButton(javafx.scene.input.MouseButton) ListView(javafx.scene.control.ListView) MouseEvent(javafx.scene.input.MouseEvent) Framework(org.kanonizo.Framework) ReadableConverter(org.kanonizo.display.fx.converters.ReadableConverter) Parameter(com.scythe.instrumenter.InstrumentationProperties.Parameter) HashSet(java.util.HashSet) ResourceBundle(java.util.ResourceBundle) FXMLLoader(javafx.fxml.FXMLLoader) Prerequisite(org.kanonizo.annotations.Prerequisite) Tooltip(javafx.scene.control.Tooltip) GridPane(javafx.scene.layout.GridPane) DirectoryChooser(javafx.stage.DirectoryChooser) KanonizoFxApplication(org.kanonizo.gui.KanonizoFxApplication) ProgressIndicator(javafx.scene.control.ProgressIndicator) Label(javafx.scene.control.Label) Node(javafx.scene.Node) CheckBox(javafx.scene.control.CheckBox) ScriptEngineManager(javax.script.ScriptEngineManager) StringConverter(javafx.util.StringConverter) Field(java.lang.reflect.Field) File(java.io.File) GuiUtils(org.kanonizo.gui.GuiUtils) FileChooser(javafx.stage.FileChooser) Condition(java.util.concurrent.locks.Condition) ActionEvent(javafx.event.ActionEvent) ScriptEngine(javax.script.ScriptEngine) ExtensionFilter(javafx.stage.FileChooser.ExtensionFilter) LogManager(org.apache.logging.log4j.LogManager) Optional(java.util.Optional) ComboBox(javafx.scene.control.ComboBox) OptionProvider(org.kanonizo.annotations.OptionProvider) Method(java.lang.reflect.Method) StringConverter(javafx.util.StringConverter) InvocationTargetException(java.lang.reflect.InvocationTargetException) Control(javafx.scene.control.Control) Button(javafx.scene.control.Button) MouseButton(javafx.scene.input.MouseButton) CheckBox(javafx.scene.control.CheckBox) FileChooser(javafx.stage.FileChooser) TextField(javafx.scene.control.TextField) List(java.util.List) ObservableList(javafx.collections.ObservableList) File(java.io.File)

Example 22 with ComboBox

use of javafx.scene.control.ComboBox in project trex-stateless-gui by cisco-system-traffic-generator.

the class EthernetStreamTest method setEthernetMacInfo.

/**
 * Fill Ethernet mac information
 */
private void setEthernetMacInfo() {
    clickOn("#protocolDataTab");
    waitForNode("Media Access Protocol");
    clickOn("Media Access Protocol");
    waitForNode("#macDstAddress");
    interact(() -> {
        TextField macDstAddress = find(("#macDstAddress"));
        macDstAddress.setText("12:00:00:00:00:22");
        ComboBox dstMode = find("#macDstMode");
        dstMode.getSelectionModel().select("Fixed");
        TextField macSrcAddress = find(("#macSrcAddress"));
        macSrcAddress.setText("22:00:00:00:00:00");
        ComboBox srcMode = find("#macsrcMode");
        srcMode.getSelectionModel().select("Increment");
    });
}
Also used : ComboBox(javafx.scene.control.ComboBox) TextField(javafx.scene.control.TextField)

Example 23 with ComboBox

use of javafx.scene.control.ComboBox in project POL-POM-5 by PlayOnLinux.

the class ContainerEngineSettingsPanelSkin method updateEngineSettingsGrid.

/**
 * Updates the engine settings in the given {@link GridPane engineSettingsGrid}
 *
 * @param engineSettingsGrid The GridPane containing the shown engine settings
 */
private void updateEngineSettingsGrid(final GridPane engineSettingsGrid) {
    engineSettingsGrid.getChildren().clear();
    final ContainerDTO container = getControl().getContainer();
    for (EngineSetting engineSetting : getControl().getEngineSettings()) {
        final int row = engineSettingsGrid.getRowCount();
        final Text engineSettingDescription = new Text(engineSetting.getText());
        engineSettingDescription.getStyleClass().add("captionTitle");
        final ObservableList<String> items = FXCollections.observableArrayList(engineSetting.getOptions());
        final ComboBox<String> engineSettingComboBox = new ComboBox<>(items);
        engineSettingComboBox.getStyleClass().add("engine-setting-combo-box");
        engineSettingComboBox.disableProperty().bind(getControl().lockEngineSettingsProperty());
        // if the container is not specified set no default values
        if (container != null) {
            try {
                engineSettingComboBox.setValue(engineSetting.getCurrentOption(container.getName()));
            } catch (Exception e) {
                engineSettingComboBox.getSelectionModel().select(0);
                LOGGER.warn(String.format("Could not fetch current option for engine setting \"%s\", will use default.", engineSetting.getText()));
                LOGGER.debug("Caused by: ", e);
            }
            engineSettingComboBox.valueProperty().addListener((Observable invalidation) -> Platform.runLater(() -> {
                getControl().setLockEngineSettings(true);
                engineSetting.setOption(container.getName(), items.indexOf(engineSettingComboBox.getValue()));
                getControl().setLockEngineSettings(false);
            }));
        }
        engineSettingsGrid.addRow(row, engineSettingDescription, engineSettingComboBox);
    }
}
Also used : EngineSetting(org.phoenicis.engines.EngineSetting) ComboBox(javafx.scene.control.ComboBox) Text(javafx.scene.text.Text) ContainerDTO(org.phoenicis.containers.dto.ContainerDTO) Observable(javafx.beans.Observable)

Example 24 with ComboBox

use of javafx.scene.control.ComboBox in project POL-POM-5 by PhoenicisOrg.

the class ChooseRepositoryTypePanel method populate.

/**
 * Populates the content of this component
 */
private void populate() {
    choiceBox = new ComboBox<>(repositoryChoices);
    choiceBox.setPromptText(tr("Please select the repository type you want to add"));
    choiceBox.setConverter(new StringConverter<RepositoryType>() {

        @Override
        public String toString(RepositoryType repositoryType) {
            return repositoryType.getLabel();
        }

        @Override
        public RepositoryType fromString(String string) {
            return Arrays.stream(RepositoryType.values()).filter(type -> type.getLabel().equals(string)).findAny().orElse(null);
        }
    });
    choiceBox.setOnAction(event -> onRepositoryTypeSelection.accept(choiceBox.getSelectionModel().getSelectedItem()));
    Label choiceBoxLabel = new Label(tr("Repository type:"));
    choiceBoxLabel.setLabelFor(choiceBox);
    HBox content = new HBox(choiceBoxLabel, choiceBox);
    content.setId("repositoryTypeSelection");
    HBox.setHgrow(choiceBox, Priority.ALWAYS);
    this.setCenter(content);
}
Also used : Consumer(java.util.function.Consumer) HBox(javafx.scene.layout.HBox) Priority(javafx.scene.layout.Priority) Arrays(java.util.Arrays) Label(javafx.scene.control.Label) ComboBox(javafx.scene.control.ComboBox) FXCollections(javafx.collections.FXCollections) Localisation.tr(org.phoenicis.configuration.localisation.Localisation.tr) ObservableList(javafx.collections.ObservableList) BorderPane(javafx.scene.layout.BorderPane) StringConverter(javafx.util.StringConverter) HBox(javafx.scene.layout.HBox) Label(javafx.scene.control.Label)

Example 25 with ComboBox

use of javafx.scene.control.ComboBox in project POL-POM-5 by PlayOnLinux.

the class WinePrefixContainerInputTab method populate.

private void populate() {
    final VBox inputPane = new VBox();
    final Text title = new TextWithStyle(tr("Input settings"), TITLE_CSS_CLASS);
    inputPane.getStyleClass().add(CONFIGURATION_PANE_CSS_CLASS);
    inputPane.getChildren().add(title);
    final GridPane inputContentPane = new GridPane();
    inputContentPane.getStyleClass().add("grid");
    final ComboBox<MouseWarpOverride> mouseWarpOverrideComboBox = new ComboBox<>();
    mouseWarpOverrideComboBox.setValue(container.getMouseWarpOverride());
    addItems(mouseWarpOverrideComboBox, MouseWarpOverride.class);
    inputContentPane.add(new TextWithStyle(tr("Mouse Warp Override"), CAPTION_TITLE_CSS_CLASS), 0, 0);
    inputContentPane.add(mouseWarpOverrideComboBox, 1, 0);
    inputContentPane.getColumnConstraints().addAll(new ColumnConstraintsWithPercentage(30), new ColumnConstraintsWithPercentage(70));
    inputPane.getChildren().addAll(inputContentPane);
    this.setContent(inputPane);
    lockableElements.add(mouseWarpOverrideComboBox);
}
Also used : TextWithStyle(org.phoenicis.javafx.views.common.TextWithStyle) ColumnConstraintsWithPercentage(org.phoenicis.javafx.views.common.ColumnConstraintsWithPercentage) GridPane(javafx.scene.layout.GridPane) ComboBox(javafx.scene.control.ComboBox) MouseWarpOverride(org.phoenicis.containers.wine.parameters.MouseWarpOverride) Text(javafx.scene.text.Text) VBox(javafx.scene.layout.VBox)

Aggregations

ComboBox (javafx.scene.control.ComboBox)48 Label (javafx.scene.control.Label)30 Insets (javafx.geometry.Insets)15 HBox (javafx.scene.layout.HBox)15 Button (javafx.scene.control.Button)14 TextField (javafx.scene.control.TextField)14 GridPane (javafx.scene.layout.GridPane)14 VBox (javafx.scene.layout.VBox)12 AutoTooltipLabel (bisq.desktop.components.AutoTooltipLabel)10 BorderPane (javafx.scene.layout.BorderPane)9 Text (javafx.scene.text.Text)9 TradeCurrency (bisq.core.locale.TradeCurrency)8 List (java.util.List)8 FXCollections (javafx.collections.FXCollections)8 Tooltip (javafx.scene.control.Tooltip)8 Priority (javafx.scene.layout.Priority)8 Popup (bisq.desktop.main.overlays.popups.Popup)7 Node (javafx.scene.Node)7 ImageView (javafx.scene.image.ImageView)7 TextWithStyle (org.phoenicis.javafx.views.common.TextWithStyle)7