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;
}
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;
}
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;
}
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);
}
});
}
}
}
}
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);
}
}
Aggregations