Search in sources :

Example 16 with StringConverter

use of javafx.util.StringConverter in project bisq-desktop by bisq-network.

the class GUIUtil method getCurrencyListItemConverter.

public static StringConverter<CurrencyListItem> getCurrencyListItemConverter(String postFixSingle, String postFixMulti, Preferences preferences) {
    return new StringConverter<CurrencyListItem>() {

        @Override
        public String toString(CurrencyListItem item) {
            TradeCurrency tradeCurrency = item.tradeCurrency;
            String code = tradeCurrency.getCode();
            switch(code) {
                case GUIUtil.SHOW_ALL_FLAG:
                    return "▶ " + Res.get("list.currency.showAll");
                case GUIUtil.EDIT_FLAG:
                    return "▼ " + Res.get("list.currency.editList");
                default:
                    String displayString = CurrencyUtil.getNameByCode(code) + " (" + code + ")";
                    if (preferences.isSortMarketCurrenciesNumerically()) {
                        final int numTrades = item.numTrades;
                        displayString += " - " + numTrades + " " + (numTrades == 1 ? postFixSingle : postFixMulti);
                    }
                    return tradeCurrency.getDisplayPrefix() + displayString;
            }
        }

        @Override
        public CurrencyListItem fromString(String s) {
            return null;
        }
    };
}
Also used : TradeCurrency(bisq.core.locale.TradeCurrency) StringConverter(javafx.util.StringConverter)

Example 17 with StringConverter

use of javafx.util.StringConverter in project phoenicis 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 18 with StringConverter

use of javafx.util.StringConverter 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 19 with StringConverter

use of javafx.util.StringConverter in project DistributedFractalNetwork by Budder21.

the class FractalEditor method initialize.

/**
 * Initializes the menus and fractal. Adds the various action listeners to all the GUI components. Constructs most of the
 * GUI logic
 *
 * @author David
 *
 * @throws FileNotFoundException
 * @throws AWTException
 */
@SuppressWarnings({ "rawtypes", "unchecked", "static-access" })
public void initialize() throws FileNotFoundException, AWTException {
    // initializing stuff
    Layer.initializeFractalRegistry();
    File fractalDirectory = new File(Constants.FRACTAL_FILEPATH);
    if (!fractalDirectory.exists()) {
        fractalDirectory.mkdirs();
        try {
            fractalDirectory.createNewFile();
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }
    fractal = new RenderManager();
    selectedLayer = fractal.getLayers().get(0);
    MenuBar menu = new MenuBar();
    SwingNode fractalEditor = new SwingNode();
    parameters = new TreeView();
    layers = new TreeView();
    VBox trees = new VBox();
    trees.minHeightProperty().bind(bp.minHeightProperty().subtract(menu.minHeightProperty()));
    trees.minWidthProperty().bind(bp.minWidthProperty().divide(6));
    trees.setAlignment(Pos.CENTER);
    Button render = new Button("Update");
    render.setFont(new Font("Ariel", 36));
    // TODO: change color of update button
    render.minWidthProperty().bind(trees.minWidthProperty());
    fractalView = new ImageView();
    fractalView.setOnMouseClicked(e -> {
        Point p = new Point(e.getScreenX(), e.getScreenY() - 52);
        double screenDistX = fractalView.getFitWidth() / 2 - p.x;
        double screenDistY = fractalView.getFitHeight() / 2 - p.y;
        double realDistX = -screenDistX * fractal.getRealResolution().x / fractal.getScreenResolution().width;
        double realDistY = screenDistY * fractal.getRealResolution().y / fractal.getScreenResolution().height;
        fractal.setLocation(new Point(fractal.getLocation().x + realDistX * 2, fractal.getLocation().y + realDistY * 2));
        this.updateFractalImage();
    });
    fractalView.setOnMouseEntered(e -> {
        zoom = true;
    });
    fractalView.setOnMouseExited(e -> {
        zoom = false;
    });
    this.setOnKeyPressed(e -> {
        if (zoom)
            if (e.getCode() == KeyCode.COMMA) {
                this.fractal.setZoom(this.fractal.getZoom() * 1.5);
                updateFractalImage();
            } else if (e.getCode() == KeyCode.PERIOD) {
                this.fractal.setZoom(this.fractal.getZoom() / 1.5);
                updateFractalImage();
            }
    });
    fractalView.setOnScroll(e -> {
        double zoom = e.getDeltaY() > 0 ? 1 / .9 : .9;
        this.fractal.setZoom(this.fractal.getZoom() * zoom);
        this.updateFractalImage();
    });
    this.fractal = new RenderManager();
    render.setOnAction(e -> {
        updateFractalImage();
    });
    // Fitting the image to the screen
    fractalView.fitWidthProperty().bind(bp.minWidthProperty().subtract(trees.minWidthProperty()));
    fractalView.fitHeightProperty().bind(bp.heightProperty().subtract(menu.minHeightProperty()).subtract(220));
    {
        // Fitting gradientEditor to full screen
        Dimension p = new Dimension((int) (Toolkit.getDefaultToolkit().getScreenSize().width * 0.75), 200);
        System.out.println("Gradient Dimensions: " + p);
        gradient = new Window(p, 50, this.fractal.getLayers().get(0));
    }
    {
        // Tree Stuff
        parameters.setRoot(new TreeItem());
        parameters.getRoot().setExpanded(true);
        parameters.setShowRoot(false);
        parameters.setEditable(true);
        // TODO if need click for params
        /**
         * parameters.setOnMouseClicked(new EventHandler<MouseEvent>(){
         *
         * @Override public void handle(MouseEvent event) { // TODO
         *           Auto-generated method stub
         *           if(event.getClickCount()==2){
         *           System.out.println("boop"); updateParams(); } }
         *
         *           });
         */
        parameters.setCellFactory(new Callback<TreeView, TreeCell<MetaParam>>() {

            @Override
            public TreeCell call(TreeView param) {
                StringConverter s = new StringConverter() {

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

                    @Override
                    public Object fromString(String string) {
                        int index = string.indexOf(":");
                        if (!string.substring(index + 1, index + 2).equals(" "))
                            string = string.substring(0, index + 1) + " " + string.substring(index + 1);
                        Parameters params = new Parameters();
                        for (Object o : parameters.getRoot().getChildren()) {
                            TreeItem i = (TreeItem) o;
                            String msg = i.getValue().toString();
                            if (param.getSelectionModel().getSelectedItem().equals(o))
                                msg = string;
                            String key = msg.substring(0, msg.indexOf(":"));
                            String value = msg.substring(msg.indexOf(":") + 2);
                            params.put(key, value);
                        }
                        getSelectedLayer().setParameters(params);
                        updateFractalImage();
                        return new MetaParam(string.substring(0, string.indexOf(": ")), string.substring(string.indexOf(": ") + 2));
                    }
                };
                return new TextFieldTreeCell<MetaParam>(s) {

                    @Override
                    public void updateItem(MetaParam item, boolean empty) {
                        super.updateItem(item, empty);
                    }
                };
            }
        });
        layers.setRoot(new TreeItem());
        layers.getRoot().setExpanded(true);
        layers.setShowRoot(false);
        // layers.setEditable(true);
        // Use a custom callback to determine the style of the tree item
        layers.setCellFactory(new Callback<TreeView, TreeCell>() {

            @Override
            public TreeCell call(TreeView param) {
                return new CheckBoxTreeCell() {

                    @Override
                    public void updateItem(Object item, boolean empty) {
                        super.updateItem(item, empty);
                        // empty
                        if (empty) {
                            setGraphic(null);
                            setText(null);
                        // Otherwise if it's not representation as an
                        // item of the tree
                        // is not a CheckBoxTreeItem, remove the
                        // checkbox item
                        } else if (!(getTreeItem() instanceof CheckBoxTreeItem)) {
                            BufferedImage image;
                            try {
                                image = ImageIO.read(new File("textures\\plusButton.png"));
                                Image plusImage = SwingFXUtils.toFXImage(image, null);
                                ImageView plusView = new ImageView(plusImage);
                                plusView.setFitHeight(16);
                                plusView.setFitWidth(16);
                                setGraphic(plusView);
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                        setOnDragDetected(new EventHandler<MouseEvent>() {

                            @Override
                            public void handle(MouseEvent mouseEvent) {
                                System.out.println("wofenh");
                                layers.getRoot().getChildren().remove(mouseEvent.getSource());
                                layers.layout();
                            }
                        });
                    }
                };
            }
        });
        TreeItem add = new TreeItem();
        layerIndex = 1;
        CheckBoxTreeItem item = getNewTreeItem();
        layers.setOnMouseClicked(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent mouseEvent) {
                if (mouseEvent.getClickCount() == 1) {
                    if (layers.getSelectionModel().getSelectedItem() != add) {
                        updateParams();
                    }
                    if (layers.getSelectionModel().getSelectedItem() == add) {
                        CheckBoxTreeItem i = getNewTreeItem();
                        layers.getRoot().getChildren().add(0, i);
                        fractal.addLayer("HistogramLayer");
                        fractal.getLayers().get(fractal.getLayers().size() - 1).setName("Layer " + layerIndex);
                        updateFractalImage();
                    }
                }
                if (mouseEvent.getClickCount() == 2) {
                    if (layers.getSelectionModel().getSelectedItem() == add) {
                    } else {
                        ((TreeItem) layers.getSelectionModel().getSelectedItem()).setValue(GradientMenus.displayLayerMenu((TreeItem<MetaLayer>) layers.getSelectionModel().getSelectedItem()));
                        MetaLayer meta = ((MetaLayer) ((TreeItem) layers.getSelectionModel().getSelectedItem()).getValue());
                        int index = layers.getRoot().getChildren().size() - 2 - layers.getRoot().getChildren().indexOf(layers.getSelectionModel().getSelectedItem());
                        Layer l = fractal.getLayers().get(index);
                        if (meta.isDelete()) {
                            fractal.getLayers().remove(index);
                            updateFractalImage();
                            layers.getRoot().getChildren().remove(layers.getSelectionModel().getSelectedItem());
                            layerIndex--;
                            return;
                        } else if (!meta.getType().equals(l.getClass().getSimpleName())) {
                            Layer newLayer = Layer.getLayerByType(meta.getType());
                            newLayer.init(l.getPalette(), index + 1);
                            l = newLayer;
                            fractal.getLayers().set(index, newLayer);
                            fractal.update();
                            updateParams();
                        }
                        l.setOpacity(meta.getOpacity());
                        fractal.getLayers().get(index).setName(meta.getName());
                        updateFractalImage();
                    }
                } else if (mouseEvent.getClickCount() == 1 && layers.getSelectionModel().getSelectedItem() != add) {
                    int index = layers.getRoot().getChildren().size() - 2 - layers.getRoot().getChildren().indexOf(layers.getSelectionModel().getSelectedItem());
                    Layer l = fractal.getLayers().get(index);
                    gradient.updateLayer(l);
                }
            }
        });
        // TODO LAYER UP LAYER DOWN
        layers.addEventFilter(KeyEvent.KEY_RELEASED, e -> {
            if (e.getCode() == KeyCode.RIGHT) {
                int index = this.fractal.getLayers().indexOf(getSelectedLayer());
                moveUp((TreeItem) layers.getSelectionModel().getSelectedItem());
                if (index < this.fractal.getNumLayers() - 1)
                    this.fractal.getLayers().add(index + 1, this.fractal.getLayers().remove(index));
            }
            if (e.getCode() == KeyCode.LEFT) {
                moveDown((TreeItem) layers.getSelectionModel().getSelectedItem());
                int index = this.fractal.getLayers().indexOf(getSelectedLayer());
                if (index > 0)
                    this.fractal.getLayers().add(index - 1, this.fractal.getLayers().remove(index));
            }
        });
        layers.getRoot().getChildren().addAll(item, add);
    }
    {
        // This is the menu stuff
        Menu network = new Menu("Network");
        Menu fractal = new Menu("Fractal");
        Menu system = new Menu("System");
        MenuItem newNet = new MenuItem("Create New Network");
        MenuItem viewNetLog = new MenuItem("View Network Log");
        MenuItem viewNet = new MenuItem("View Network");
        MenuItem endNet = new MenuItem("Close Network");
        newNet.setOnAction(e -> {
            NetworkCreationTool createNet = new NetworkCreationTool();
            if (createNet.createNetwork()) {
                this.network = createNet.getServer();
                this.network.init(log);
                Alert alert = new Alert(AlertType.INFORMATION);
                alert.setTitle("Network Message");
                alert.setHeaderText(null);
                alert.setContentText("Network succesfully created.");
                viewNet.setDisable(false);
                endNet.setDisable(false);
                newNet.setDisable(true);
                viewNetLog.setDisable(false);
                alert.showAndWait();
            }
        });
        viewNet.setDisable(true);
        endNet.setDisable(true);
        viewNetLog.setDisable(true);
        viewNet.setOnAction(e -> {
            Display display = new Display(this.network);
            this.network.setDisplay(display);
            display.updateNetworkView(this.network.getChildren(), this.network.getUncompletedJobs());
        });
        endNet.setOnAction(e -> {
            // TODO: kill won't stop network without getting a response from
            // all clients
            this.network.kill();
            viewNet.setDisable(true);
            endNet.setDisable(true);
            viewNetLog.setDisable(true);
            newNet.setDisable(false);
        });
        viewNetLog.setOnAction(e -> {
            Alert alert = new Alert(AlertType.INFORMATION);
            alert.setTitle("Network Log");
            alert.setHeaderText(null);
            alert.setContentText(this.network.getLog().getLog());
            alert.showAndWait();
        });
        network.getItems().addAll(newNet, viewNet, viewNetLog, endNet);
        MenuItem newFract = new MenuItem("New Fractal");
        newFract.setOnAction(e -> {
            layerIndex = 1;
            this.fractal = new RenderManager();
            gradient.updateLayer(this.fractal.getLayers().get(0));
            System.out.println(this.fractal.getLayers().get(0));
            deleteLayers();
            CheckBoxTreeItem i = getNewTreeItem();
            layers.getRoot().getChildren().add(0, i);
            this.updateFractalImage();
        });
        MenuItem openFract = new MenuItem("Open Fractal");
        openFract.setOnAction(e -> {
            FileChooser chooser = new FileChooser();
            chooser.setTitle("Open Fractal");
            chooser.setInitialDirectory(new File("fractals"));
            FileChooser.ExtensionFilter filter = new FileChooser.ExtensionFilter("Fractals (*.fractal)", "*.fractal");
            chooser.getExtensionFilters().add(filter);
            File f = chooser.showOpenDialog(null);
            this.fractal = new RenderManager(f);
            gradient.updateLayer(this.fractal.getLayers().get(0));
            deleteLayers();
            for (int k = 0; k < this.fractal.getLayers().size(); k++) {
                Layer l = this.fractal.getLayers().get(k);
                CheckBoxTreeItem i = getNewTreeItem();
                MetaLayer meta = (MetaLayer) (i.getValue());
                meta.setName(l.getName());
                meta.setOpacity(l.getOpacity());
                meta.setType(l.getClass().getSimpleName());
                layers.getRoot().getChildren().add(0, i);
            }
            this.updateFractalImage();
        });
        MenuItem saveFract = new MenuItem("Save Fractal");
        saveFract.setOnAction(e -> {
            this.fractal.saveFractal();
        });
        MenuItem saveFractAs = new MenuItem("Save Fractal As");
        saveFractAs.setOnAction(e -> {
            this.fractal.saveFractalAs();
        });
        MenuItem exportFract = new MenuItem("Export Fractal");
        exportFract.setOnAction(e -> {
            ExportImageTool export = new ExportImageTool();
            export.exportImage(this.fractal);
        });
        fractal.getItems().addAll(newFract, openFract, saveFract, saveFractAs, exportFract);
        MenuItem newLayer = new MenuItem("New Layer Type");
        newLayer.setOnAction(e -> {
            RegisterLayerTool register = new RegisterLayerTool();
            register.registerLayer();
            Layer.registerLayer(register.getFile());
        });
        MenuItem help = new MenuItem("Help");
        help.setOnAction(e -> {
            ExpandableMenu.displayInformation("Help", "Instructions:", getHelpText());
        });
        system.getItems().addAll(newLayer, help);
        menu.getMenus().addAll(fractal);
        menu.getMenus().addAll(network);
        menu.getMenus().addAll(system);
    }
    VBox center = new VBox();
    center.getChildren().addAll(fractalView, fractalEditor);
    trees.getChildren().addAll(parameters, layers, render);
    bp.setCenter(center);
    bp.setRight(trees);
    // This is where the menu is located on the border pane
    bp.setTop(menu);
    bp.minWidthProperty().bind(this.widthProperty());
    bp.minHeightProperty().bind(this.heightProperty());
    render.minHeightProperty().bind(trees.minHeightProperty().subtract(fractalView.fitHeightProperty()));
    fractalEditor.setContent(gradient);
    fractalEditor.minHeight(200);
    updateParams(0);
}
Also used : EventHandler(javafx.event.EventHandler) Button(javafx.scene.control.Button) Pos(javafx.geometry.Pos) RegisterLayerTool(menus.RegisterLayerTool) VBox(javafx.scene.layout.VBox) TreeModificationEvent(javafx.scene.control.CheckBoxTreeItem.TreeModificationEvent) AlertType(javafx.scene.control.Alert.AlertType) ImageIO(javax.imageio.ImageIO) Alert(javafx.scene.control.Alert) MenuItem(javafx.scene.control.MenuItem) BufferedImage(java.awt.image.BufferedImage) Font(javafx.scene.text.Font) RenderManager(fractal.RenderManager) KeyEvent(javafx.scene.input.KeyEvent) ExportImageTool(menus.ExportImageTool) Point(util.Point) FileNotFoundException(java.io.FileNotFoundException) TreeView(javafx.scene.control.TreeView) Dimension(java.awt.Dimension) List(java.util.List) Palette(fractal.Palette) AWTException(java.awt.AWTException) BorderPane(javafx.scene.layout.BorderPane) Toolkit(java.awt.Toolkit) Scene(javafx.scene.Scene) Server(server.Server) TreeItem(javafx.scene.control.TreeItem) MouseEvent(javafx.scene.input.MouseEvent) Log(util.Log) Constants(util.Constants) Parameters(util.Parameters) ArrayList(java.util.ArrayList) BackgroundFill(javafx.scene.layout.BackgroundFill) Layer(fractal.Layer) Callback(javafx.util.Callback) KeyCode(javafx.scene.input.KeyCode) MenuBar(javafx.scene.control.MenuBar) IOException(java.io.IOException) StringConverter(javafx.util.StringConverter) CheckBoxTreeCell(javafx.scene.control.cell.CheckBoxTreeCell) Background(javafx.scene.layout.Background) File(java.io.File) Menu(javafx.scene.control.Menu) Display(menus.Display) NetworkCreationTool(menus.NetworkCreationTool) CheckBoxTreeItem(javafx.scene.control.CheckBoxTreeItem) FileChooser(javafx.stage.FileChooser) TextFieldTreeCell(javafx.scene.control.cell.TextFieldTreeCell) ImageView(javafx.scene.image.ImageView) SwingFXUtils(javafx.embed.swing.SwingFXUtils) TreeCell(javafx.scene.control.TreeCell) ExpandableMenu(menus.ExpandableMenu) Image(javafx.scene.image.Image) SwingNode(javafx.embed.swing.SwingNode) TreeItem(javafx.scene.control.TreeItem) CheckBoxTreeItem(javafx.scene.control.CheckBoxTreeItem) MenuBar(javafx.scene.control.MenuBar) EventHandler(javafx.event.EventHandler) BufferedImage(java.awt.image.BufferedImage) Image(javafx.scene.image.Image) Font(javafx.scene.text.Font) BufferedImage(java.awt.image.BufferedImage) SwingNode(javafx.embed.swing.SwingNode) CheckBoxTreeCell(javafx.scene.control.cell.CheckBoxTreeCell) Button(javafx.scene.control.Button) FileChooser(javafx.stage.FileChooser) ImageView(javafx.scene.image.ImageView) TextFieldTreeCell(javafx.scene.control.cell.TextFieldTreeCell) Menu(javafx.scene.control.Menu) ExpandableMenu(menus.ExpandableMenu) RenderManager(fractal.RenderManager) Parameters(util.Parameters) MouseEvent(javafx.scene.input.MouseEvent) CheckBoxTreeItem(javafx.scene.control.CheckBoxTreeItem) MenuItem(javafx.scene.control.MenuItem) IOException(java.io.IOException) Point(util.Point) Dimension(java.awt.Dimension) StringConverter(javafx.util.StringConverter) Layer(fractal.Layer) Point(util.Point) ExportImageTool(menus.ExportImageTool) Callback(javafx.util.Callback) NetworkCreationTool(menus.NetworkCreationTool) TreeView(javafx.scene.control.TreeView) Alert(javafx.scene.control.Alert) File(java.io.File) VBox(javafx.scene.layout.VBox) RegisterLayerTool(menus.RegisterLayerTool) Display(menus.Display)

Example 20 with StringConverter

use of javafx.util.StringConverter in project Gargoyle by callakrsos.

the class SqlPane method showTableInputDialog.

public Optional<Pair<String, String[]>> showTableInputDialog(Function<K, String> stringConverter) {
    final List<String> schemaList = getSchemaTree().getRoot().getChildren().stream().map(v -> {
        return stringConverter.apply(v.getValue());
    }).collect(Collectors.toList());
    String defaultSchema = "";
    try (Connection con = connectionSupplier.get()) {
        //
        //			String catalog = con.getCatalog();
        //			String schema = con.getSchema();
        //			ResultSet schemas = con.getMetaData().getCatalogs();
        //			if (schemas.next()) {
        //				String string = schemas.getString(1);
        //				System.out.println(string);
        //			}
        Map<String, Object> findOne = DbUtil.findOne(con, "select current_schema() as currentschema");
        if (findOne != null && !findOne.isEmpty()) {
            defaultSchema = ValueUtil.decode(findOne.get("currentschema"), "").toString();
        }
    } catch (Exception e4) {
        LOGGER.error(ValueUtil.toString(e4));
    }
    final String _defaultSchema = defaultSchema;
    if (tbResult.getItems().isEmpty())
        return Optional.empty();
    return DialogUtil.showInputCustomDialog(tbResult.getScene().getWindow(), "table Name", "테이블명을 입력하세요.", new CustomInputDialogAction<GridPane, String[]>() {

        TextField txtSchema;

        TextField txtTable;

        @Override
        public GridPane getNode() {
            GridPane gridPane = new GridPane();
            txtSchema = new TextField();
            txtTable = new TextField();
            FxUtil.installAutoTextFieldBinding(txtSchema, () -> {
                return schemaList;
            });
            FxUtil.installAutoTextFieldBinding(txtTable, () -> {
                return searchPattern(txtSchema.getText(), txtTable.getText()).stream().map(v -> stringConverter.apply(v.getValue())).collect(Collectors.toList());
            });
            txtSchema.setText(_defaultSchema);
            // Default TableName
            TreeItem<K> selectedItem = getSchemaTree().getSelectionModel().getSelectedItem();
            if (null != selectedItem) {
                K value = selectedItem.getValue();
                if (value instanceof TableItemTree) {
                    txtTable.setText(stringConverter.apply(value));
                }
            }
            Label label = new Label("Schema : ");
            Label label2 = new Label("Table : ");
            gridPane.add(label, 0, 0);
            gridPane.add(label2, 1, 0);
            gridPane.add(txtSchema, 0, 1);
            gridPane.add(txtTable, 1, 1);
            return gridPane;
        }

        @Override
        public String[] okClickValue() {
            String schema = txtSchema.getText().trim();
            String table = txtTable.getText().trim();
            String[] okValue = new String[2];
            okValue[0] = schema;
            okValue[1] = table;
            return okValue;
        }

        @Override
        public String[] cancelClickValue() {
            return null;
        }
    });
}
Also used : SystemLayoutViewController(com.kyj.fx.voeditor.visual.main.layout.SystemLayoutViewController) Arrays(java.util.Arrays) CheckComboBox(org.controlsfx.control.CheckComboBox) Application(javafx.application.Application) TabPane(javafx.scene.control.TabPane) ListChangeListener(javafx.collections.ListChangeListener) MacroControl(com.kyj.fx.voeditor.visual.component.macro.MacroControl) Map(java.util.Map) SQLPaneMotionable(com.kyj.fx.voeditor.visual.component.sql.functions.SQLPaneMotionable) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) VariableMappingView(com.kyj.fx.voeditor.visual.component.popup.VariableMappingView) DockPane(com.kyj.fx.voeditor.visual.component.dock.pane.DockPane) SystemUtils(org.apache.commons.lang.SystemUtils) Strings(com.sun.btrace.BTraceUtils.Strings) ColumnExpression(com.kyj.fx.voeditor.visual.component.grid.EditableTableView.ColumnExpression) SplitPane(javafx.scene.control.SplitPane) Pair(javafx.util.Pair) EditableTableViewComposite(com.kyj.fx.voeditor.visual.component.grid.EditableTableViewComposite) KeyEvent(javafx.scene.input.KeyEvent) ValueExpression(com.kyj.fx.voeditor.visual.component.grid.EditableTableView.ValueExpression) FxUtil(com.kyj.fx.voeditor.visual.util.FxUtil) ResourceLoader(com.kyj.fx.voeditor.visual.momory.ResourceLoader) CustomInputDialogAction(com.kyj.fx.voeditor.visual.util.DialogUtil.CustomInputDialogAction) ObservableList(javafx.collections.ObservableList) BorderPane(javafx.scene.layout.BorderPane) TitledBorderPane(com.kyj.fx.voeditor.visual.component.TitledBorderPane) TableViewSelectionModel(javafx.scene.control.TableView.TableViewSelectionModel) MouseButton(javafx.scene.input.MouseButton) ASTSqlCodeAreaHelper(com.kyj.fx.voeditor.visual.component.text.ASTSqlCodeAreaHelper) TreeItem(javafx.scene.control.TreeItem) FXCollections(javafx.collections.FXCollections) GagoyleTabProxy(com.kyj.fx.voeditor.visual.main.layout.GagoyleTabProxy) DialogUtil(com.kyj.fx.voeditor.visual.util.DialogUtil) Supplier(java.util.function.Supplier) IntegerProperty(javafx.beans.property.IntegerProperty) ArrayList(java.util.ArrayList) TableItemTree(com.kyj.fx.voeditor.visual.component.sql.dbtree.commons.TableItemTree) Color(javafx.scene.paint.Color) Node(javafx.scene.Node) TableOpenResourceView(com.kyj.fx.voeditor.visual.component.popup.TableOpenResourceView) StringConverter(javafx.util.StringConverter) SchoolMgrerSpreadSheetView(com.kyj.fx.voeditor.visual.main.layout.SchoolMgrerSpreadSheetView) GridPane(jfxtras.scene.layout.GridPane) File(java.io.File) SqlTabPane(com.kyj.fx.voeditor.visual.component.sql.tab.SqlTabPane) Menu(javafx.scene.control.Menu) KeyCodeCombination(javafx.scene.input.KeyCodeCombination) SelectionMode(javafx.scene.control.SelectionMode) TreeMap(java.util.TreeMap) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) Tab(javafx.scene.control.Tab) ResultDialog(com.kyj.fx.voeditor.visual.component.ResultDialog) Button(javafx.scene.control.Button) Connection(java.sql.Connection) DbUtil(com.kyj.fx.voeditor.visual.util.DbUtil) LoggerFactory(org.slf4j.LoggerFactory) ToExcelFileFunction(com.kyj.fx.voeditor.visual.functions.ToExcelFileFunction) EncrypUtil(com.kyj.fx.voeditor.visual.util.EncrypUtil) ContextMenu(javafx.scene.control.ContextMenu) WindowEvent(javafx.stage.WindowEvent) TableView(javafx.scene.control.TableView) SqlKeywords(com.kyj.fx.voeditor.visual.component.text.SqlKeywords) Orientation(javafx.geometry.Orientation) HBox(javafx.scene.layout.HBox) TextField(javafx.scene.control.TextField) Main(com.kyj.fx.voeditor.visual.main.Main) MenuItem(javafx.scene.control.MenuItem) SimpleTextView(com.kyj.fx.voeditor.visual.component.text.SimpleTextView) ConfigResourceLoader(com.kyj.fx.voeditor.visual.momory.ConfigResourceLoader) Collectors(java.util.stream.Collectors) TreeView(javafx.scene.control.TreeView) ISchemaTreeItem(com.kyj.fx.voeditor.visual.component.sql.functions.ISchemaTreeItem) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) List(java.util.List) SqlTab(com.kyj.fx.voeditor.visual.component.sql.tab.SqlTab) Entry(java.util.Map.Entry) RowMapper(org.springframework.jdbc.core.RowMapper) Optional(java.util.Optional) DateUtil(com.kyj.fx.voeditor.visual.util.DateUtil) MouseEvent(javafx.scene.input.MouseEvent) HashMap(java.util.HashMap) TextFieldTableCell(javafx.scene.control.cell.TextFieldTableCell) Function(java.util.function.Function) BigDataDVO(com.kyj.fx.voeditor.visual.framework.BigDataDVO) TableColumn(javafx.scene.control.TableColumn) Insets(javafx.geometry.Insets) FxCollectors(com.kyj.fx.voeditor.visual.util.FxCollectors) Tooltip(javafx.scene.control.Tooltip) KeyCode(javafx.scene.input.KeyCode) ObjectProperty(javafx.beans.property.ObjectProperty) Modality(javafx.stage.Modality) Logger(org.slf4j.Logger) Label(javafx.scene.control.Label) Iterator(java.util.Iterator) ValueUtil(com.kyj.fx.voeditor.visual.util.ValueUtil) Consumer(java.util.function.Consumer) ActionEvent(javafx.event.ActionEvent) Stage(javafx.stage.Stage) ExtensionFilter(javafx.stage.FileChooser.ExtensionFilter) Collections(java.util.Collections) SharedMemory(com.kyj.fx.voeditor.visual.momory.SharedMemory) TableItemTree(com.kyj.fx.voeditor.visual.component.sql.dbtree.commons.TableItemTree) GridPane(jfxtras.scene.layout.GridPane) TreeItem(javafx.scene.control.TreeItem) ISchemaTreeItem(com.kyj.fx.voeditor.visual.component.sql.functions.ISchemaTreeItem) Connection(java.sql.Connection) Label(javafx.scene.control.Label) TextField(javafx.scene.control.TextField)

Aggregations

StringConverter (javafx.util.StringConverter)33 Label (javafx.scene.control.Label)14 Callback (javafx.util.Callback)14 FXCollections (javafx.collections.FXCollections)12 Insets (javafx.geometry.Insets)12 Button (javafx.scene.control.Button)11 ImageView (javafx.scene.image.ImageView)11 Inject (javax.inject.Inject)11 ChangeListener (javafx.beans.value.ChangeListener)10 ObservableList (javafx.collections.ObservableList)10 ComboBox (javafx.scene.control.ComboBox)10 Priority (javafx.scene.layout.Priority)9 Arrays (java.util.Arrays)8 List (java.util.List)8 ListChangeListener (javafx.collections.ListChangeListener)8 GridPane (javafx.scene.layout.GridPane)8 HBox (javafx.scene.layout.HBox)8 Consumer (java.util.function.Consumer)7 Res (bisq.core.locale.Res)6 VPos (javafx.geometry.VPos)6