Search in sources :

Example 1 with Control

use of javafx.scene.control.Control in project Gargoyle by callakrsos.

the class FxControlsTreeItem method createNode.

/**
	 * 파일 트리를 생성하기 위한 노드를 반환한다.
	 *
	 * @Date 2015. 10. 14.
	 * @param f
	 * @return
	 * @User KYJ
	 */
public TreeItem<Node> createNode(final Node f) {
    TreeItem<Node> treeItem = new TreeItem<Node>(f) {

        private boolean isLeaf;

        private boolean isFirstTimeChildren = true;

        private boolean isFirstTimeLeaf = true;

        @Override
        public ObservableList<TreeItem<Node>> getChildren() {
            if (isFirstTimeChildren) {
                isFirstTimeChildren = false;
                super.getChildren().setAll(buildChildren(this));
            }
            return super.getChildren();
        }

        @Override
        public boolean isLeaf() {
            if (isFirstTimeLeaf) {
                isFirstTimeLeaf = false;
                Node f = getValue();
                if (f == null) {
                    isLeaf = true;
                } else if (f instanceof Control) {
                    isLeaf = ((Control) f).getChildrenUnmodifiable().isEmpty();
                } else if (f instanceof Parent) {
                    isLeaf = ((Parent) f).getChildrenUnmodifiable().isEmpty();
                } else if (f instanceof Shape)
                    isLeaf = true;
                else
                    isLeaf = false;
            }
            return isLeaf;
        }

        private ObservableList<TreeItem<Node>> buildChildren(TreeItem<Node> treeItem) {
            Node f = treeItem.getValue();
            if (f == null) {
                return FXCollections.emptyObservableList();
            }
            treeItem.setGraphic(new HBox(/* new CheckBox(), */
            getImage(getName(f))));
            List<Node> childrens = getChildrens(f);
            if (childrens == null || childrens.isEmpty()) {
                return FXCollections.emptyObservableList();
            } else {
                ObservableList<TreeItem<Node>> children = FXCollections.observableArrayList();
                for (Node child : childrens) {
                    children.add(createNode(child));
                }
                return children;
            }
        }
    };
    treeItem.setGraphic(new HBox(/* new CheckBox(), */
    getImage(getName(f))));
    return treeItem;
}
Also used : Control(javafx.scene.control.Control) HBox(javafx.scene.layout.HBox) Shape(javafx.scene.shape.Shape) TreeItem(javafx.scene.control.TreeItem) Parent(javafx.scene.Parent) Node(javafx.scene.Node)

Example 2 with Control

use of javafx.scene.control.Control in project Gargoyle by callakrsos.

the class CheckBoxFxControlsTreeItem method getChildrens.

/**
	 * node로부터 구성된 하위 노드들을 반환받음.
	 * 
	 * @param node
	 * @return
	 */
public List<Node> getChildrens(Node node) {
    List<Node> controls = new ArrayList<>();
    if (node instanceof Control) {
        Control c = (Control) node;
        controls.add(c);
        controls = c.getChildrenUnmodifiable();
    } else if (node instanceof Parent) {
        Parent p = (Parent) node;
        controls = p.getChildrenUnmodifiable();
    } else {
        controls.add(node);
    }
    return controls;
}
Also used : Control(javafx.scene.control.Control) Parent(javafx.scene.Parent) Node(javafx.scene.Node) ArrayList(java.util.ArrayList)

Example 3 with Control

use of javafx.scene.control.Control 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 4 with Control

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

the class KanonizoFrame method addParams.

private void addParams(Object alg, GridPane paramLayout, boolean runPrerequisites) {
    List<Field> params = Arrays.asList(alg.getClass().getFields()).stream().filter(f -> f.getAnnotation(Parameter.class) != null).collect(Collectors.toList());
    int row = 0;
    int col = -1;
    for (Field param : params) {
        if (col + 2 > ITEMS_PER_ROW * 2) {
            col = -1;
            row++;
        }
        Label paramLabel = new Label(Util.humanise(param.getName()) + ":");
        paramLabel.setAlignment(Pos.CENTER_LEFT);
        paramLabel.setTooltip(new Tooltip(Util.humanise(param.getName())));
        Control paramField = getParameterField(param, runPrerequisites);
        paramField.setTooltip(new Tooltip(param.getAnnotation(Parameter.class).description()));
        paramLayout.add(paramLabel, ++col, row, 1, 1);
        paramLayout.add(paramField, ++col, row, 1, 1);
        if (param.isAnnotationPresent(ConditionalParameter.class)) {
            String condition = param.getAnnotation(ConditionalParameter.class).condition();
            String[] listensTo = param.getAnnotation(ConditionalParameter.class).listensTo().split(",");
            for (String listen : listensTo) {
                Util.addPropertyChangeListener(listen, (e) -> {
                    ScriptEngineManager manager = new ScriptEngineManager();
                    ScriptEngine engine = manager.getEngineByName("nashorn");
                    try {
                        Class<?> container = param.getDeclaringClass();
                        engine.put("CallerClass", container);
                        engine.eval("var " + container.getSimpleName() + " = CallerClass.static");
                        boolean cond = (boolean) engine.eval(condition);
                        paramField.setDisable(!cond);
                        paramLabel.setDisable(!cond);
                    } catch (ScriptException ex) {
                        logger.error(ex);
                    }
                });
            }
        }
    }
}
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) Tooltip(javafx.scene.control.Tooltip) Label(javafx.scene.control.Label) ScriptEngineManager(javax.script.ScriptEngineManager) ScriptEngine(javax.script.ScriptEngine) TextField(javafx.scene.control.TextField) Field(java.lang.reflect.Field) ScriptException(javax.script.ScriptException) Control(javafx.scene.control.Control) ConditionalParameter(org.kanonizo.annotations.ConditionalParameter) ConditionalParameter(org.kanonizo.annotations.ConditionalParameter) Parameter(com.scythe.instrumenter.InstrumentationProperties.Parameter)

Example 5 with Control

use of javafx.scene.control.Control in project JFoenix by jfoenixadmin.

the class JFXTextFieldSkin method updateGraphic.

private final void updateGraphic(Node graphic, String id) {
    Node old = getSkinnable().lookup("#" + id);
    getChildren().remove(old);
    if (graphic != null) {
        graphic.setId(id);
        graphic.setManaged(false);
        // add tab events handler as there is a bug in javafx traversing engine
        Set<Control> controls = JFXNodeUtils.getAllChildren(graphic, Control.class);
        controls.forEach(control -> {
            control.addEventHandler(KeyEvent.KEY_PRESSED, JFXNodeUtils.TRAVERSE_HANDLER);
            control.addEventHandler(KeyEvent.KEY_TYPED, Event::consume);
        });
        getChildren().add(graphic);
    }
}
Also used : Control(javafx.scene.control.Control) IFXLabelFloatControl(com.jfoenix.controls.base.IFXLabelFloatControl) Node(javafx.scene.Node) Event(javafx.event.Event) KeyEvent(javafx.scene.input.KeyEvent)

Aggregations

Control (javafx.scene.control.Control)14 Node (javafx.scene.Node)12 Parent (javafx.scene.Parent)6 Scene (javafx.scene.Scene)4 IFXLabelFloatControl (com.jfoenix.controls.base.IFXLabelFloatControl)3 Method (java.lang.reflect.Method)3 List (java.util.List)3 Application (javafx.application.Application)3 ObservableList (javafx.collections.ObservableList)3 FXMLLoader (javafx.fxml.FXMLLoader)3 Parameter (com.scythe.instrumenter.InstrumentationProperties.Parameter)2 PropertyChangeListener (java.beans.PropertyChangeListener)2 File (java.io.File)2 Field (java.lang.reflect.Field)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Modifier (java.lang.reflect.Modifier)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 HashSet (java.util.HashSet)2