use of javafx.scene.control.TextField 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.TextField in project dwoss by gg-net.
the class CustomTableCell method createTextField.
static <T> TextField createTextField(final Cell<T> cell, final StringConverter<T> converter) {
final TextField textField = new TextField(getItemText(cell, converter));
// Use onAction here rather than onKeyReleased (with check for Enter),
// as otherwise we encounter RT-34685
textField.setOnAction(event -> {
if (converter == null) {
throw new IllegalStateException("Attempting to convert text input into Object, but provided " + "StringConverter is null. Be sure to set a StringConverter " + "in your cell factory.");
}
try {
cell.commitEdit(converter.fromString(textField.getText()));
} catch (NumberFormatException e) {
cell.cancelEdit();
} finally {
event.consume();
}
});
textField.setOnKeyReleased(t -> {
if (t.getCode() == KeyCode.ESCAPE) {
cell.cancelEdit();
t.consume();
}
});
return textField;
}
use of javafx.scene.control.TextField in project trex-stateless-gui by cisco-system-traffic-generator.
the class TrafficProfileTestBase method addNewProfileStream.
/**
* Add new profile/stream name field
*
* @param name
*/
protected void addNewProfileStream(String name) {
waitForNode("#nameTF");
TextField nameTF = find("#nameTF");
nameTF.setText(name);
Button okButton = find("OK");
clickOn(okButton);
}
use of javafx.scene.control.TextField 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");
});
}
use of javafx.scene.control.TextField in project trex-stateless-gui by cisco-system-traffic-generator.
the class PayloadView method buildCustomProtocolView.
/**
* Build custom view
*/
@Override
protected void buildCustomProtocolView() {
addLabel("Type", 15, 15);
type = new ComboBox<>();
type.setId("payloadType");
addCombo(type, 12, 120, 170);
addLabel("Pattern", 55, 15);
pattern = new TextField();
addInput(pattern, 52, 120, 300);
orLabel = new Label("OR");
addLabel(orLabel, 55, 430);
importPatternButton = new Button("Select from file");
importPatternButton.getStyleClass().add("normalButton");
addButton(importPatternButton, 52, 460, 130);
type.getItems().clear();
type.getItems().addAll("Fixed Word", "Increment Byte", "Decrement Byte", "Random");
}
Aggregations