use of javafx.scene.Group in project lttng-scope by lttng.
the class TimeGraphStateLayer method prepareTimeGraphStatesContents.
private static Node prepareTimeGraphStatesContents(Collection<StateRectangle> stateRectangles) {
Group group = new Group();
group.getChildren().addAll(stateRectangles);
return group;
}
use of javafx.scene.Group in project lttng-scope by lttng.
the class TimeGraphStateLayer method prepareTimeGrahLabelsContents.
private Node prepareTimeGrahLabelsContents(Collection<StateRectangle> stateRectangles, TimeRange windowRange) {
double minX = getWidget().timestampToPaneXPos(windowRange.getStartTime());
final String ellipsisStr = DebugOptions.ELLIPSIS_STRING;
final double ellipsisWidth = getWidget().getDebugOptions().getEllipsisWidth();
final Font textFont = getWidget().getDebugOptions().stateLabelFont.get();
final OverrunStyle overrunStyle = OverrunStyle.ELLIPSIS;
final Color textColor = Color.WHITE;
/* Requires a ~2 pixels adjustment to be centered on the states */
final double yOffset = TimeGraphWidget.ENTRY_HEIGHT / 2.0 + 2.0;
Collection<Node> texts = stateRectangles.stream().filter(stateRect -> stateRect.getWidth() > ellipsisWidth).filter(stateRect -> stateRect.getStateInterval().getLabel() != null).map(stateRect -> {
String labelText = requireNonNull(stateRect.getStateInterval().getLabel());
/* A small offset looks better here */
double textX = Math.max(minX, stateRect.getX()) + 4.0;
double textY = stateRect.getY() + yOffset;
double rectEndX = stateRect.getX() + stateRect.getWidth();
double minWidth = rectEndX - textX;
String ellipsedText = JfxTextUtils.computeClippedText(textFont, labelText, minWidth, overrunStyle, ellipsisStr);
if (ellipsedText.equals(ellipsisStr)) {
return null;
}
Text text = new Text(textX, textY, ellipsedText);
text.setFont(textFont);
text.setFill(textColor);
return text;
}).filter(Objects::nonNull).collect(Collectors.toList());
return new Group(texts);
}
use of javafx.scene.Group in project lttng-scope by lttng.
the class TimeGraphStateLayer method drawContents.
@Override
public void drawContents(TimeGraphTreeRender treeRender, TimeRange timeRange, VerticalPosition vPos, @Nullable FutureTask<?> task) {
final long resolution = Math.max(1, Math.round(getWidget().getCurrentNanosPerPixel()));
final List<TimeGraphTreeElement> allTreeElements = treeRender.getAllTreeElements();
final int nbElements = allTreeElements.size();
final int entriesToPrefetch = getWidget().getDebugOptions().entryPadding.get();
final int topEntry = Math.max(0, TimeGraphWidget.paneYPosToEntryListIndex(vPos.fTopPos, TimeGraphWidget.ENTRY_HEIGHT) - entriesToPrefetch);
final int bottomEntry = Math.min(nbElements, TimeGraphWidget.paneYPosToEntryListIndex(vPos.fBottomPos, TimeGraphWidget.ENTRY_HEIGHT) + entriesToPrefetch);
LOGGER.finest(() -> "topEntry=" + topEntry + ", bottomEntry=" + bottomEntry);
List<TimeGraphStateRender> stateRenders = allTreeElements.subList(topEntry, bottomEntry).stream().map(treeElem -> fStateProvider.getStateRender(treeElem, timeRange, resolution, task)).collect(Collectors.toList());
if (task != null && task.isCancelled()) {
return;
}
Collection<StateRectangle> stateRectangles = prepareStateRectangles(stateRenders, topEntry);
Node statesLayerContents = prepareTimeGraphStatesContents(stateRectangles);
Node labelsLayerContents = prepareTimeGrahLabelsContents(stateRectangles, fWindowRange);
/*
* Go over all state rectangles, and bring the "multi-state"
* ones to the front, to be sure they show on top of the others.
* Note we cannot do the forEach() as part of the stream, that
* would throw a ConcurrentModificationException.
*/
((Group) statesLayerContents).getChildren().stream().map(node -> (StateRectangle) node).filter(rect -> (rect.getStateInterval().isMultiState())).collect(Collectors.toList()).forEach(Node::toFront);
Platform.runLater(() -> {
getParentGroup().getChildren().clear();
getLabelGroup().getChildren().clear();
getParentGroup().getChildren().add(statesLayerContents);
getLabelGroup().getChildren().add(labelsLayerContents);
});
}
use of javafx.scene.Group in project selenium_java by sergueik.
the class FlowPaneEx method start.
@Override
public void start(Stage stage) {
this.stage = stage;
stage.setTitle("SWET/javaFx");
stage.setWidth(500);
stage.setHeight(160);
scene = new Scene(new Group());
VBox vbox = new VBox();
FlowPane flow = new FlowPane();
flow.setVgap(8);
flow.setHgap(4);
flow.setPrefWrapLength(300);
Button launchButton = new Button();
Image launchImage = new Image(getClass().getClassLoader().getResourceAsStream("browsers_32.png"));
launchButton.setGraphic(new ImageView(launchImage));
launchButton.setTooltip(new Tooltip("Launch browser"));
// https://examples.javacodegeeks.com/desktop-java/javafx/javafx-concurrency-example/
launchButton.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
startAsyncTask();
}
});
Button injectButton = new Button();
Image injectImage = new Image(getClass().getClassLoader().getResourceAsStream("find_32.png"));
injectButton.setGraphic(new ImageView(injectImage));
injectButton.setTooltip(new Tooltip("Inject script"));
injectButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("generate step!");
for (int i = 0; i < 20; i++) {
Button stepButton = new Button(String.format("Step %d", i));
stepButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
// ComplexFormEx
Map<String, String> inputData = new HashMap<>();
Button button = (Button) event.getTarget();
inputData.put("dummy", "42");
inputData.put("title", String.format("%s element Locators", button.getText()));
Map<String, Map> inputs = new HashMap<>();
// TODO: JSON
inputs.put("inputs", inputData);
scene.setUserData(inputs);
logger.info("launching complexFormEx for " + inputData.get("title"));
ComplexFormEx complexFormEx = new ComplexFormEx();
complexFormEx.setScene(scene);
try {
complexFormEx.start(new Stage());
} catch (Exception e) {
}
}
});
flow.getChildren().add(stepButton);
}
}
});
Button generateButton = new Button();
Image generateImage = new Image(getClass().getClassLoader().getResourceAsStream("codegen_32.png"));
generateButton.setGraphic(new ImageView(generateImage));
generateButton.setTooltip(new Tooltip("Generate program"));
Button loadButton = new Button();
Image loadImage = new Image(getClass().getClassLoader().getResourceAsStream("open_32.png"));
loadButton.setGraphic(new ImageView(loadImage));
loadButton.setTooltip(new Tooltip("Load session"));
loadButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
// https://docs.oracle.com/javafx/2/ui_controls/file-chooser.htm
FileChooser fileChooser = new FileChooser();
if (configFilePath != null) {
logger.info("Loading recording from: " + configFilePath);
try {
fileChooser.setInitialDirectory(new File(configFilePath));
} catch (IllegalArgumentException e) {
logger.info("Exception (ignored): " + e.toString());
}
}
// Set extension filter
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("YAML file", "*.yaml"));
fileChooser.setTitle("Open Recording");
File file = fileChooser.showOpenDialog(stage);
if (file != null) {
logger.info("Load recording: " + file.getPath());
configFilePath = file.getParent();
openRecordingFile(file);
}
}
});
Button testsuiteButton = new Button();
Image testsuiteImage = new Image(getClass().getClassLoader().getResourceAsStream("excel_gen_32.png"));
testsuiteButton.setGraphic(new ImageView(testsuiteImage));
testsuiteButton.setTooltip(new Tooltip("Generate Excel TestSuite"));
testsuiteButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
// Stage stage = new Stage();
Map<String, String> inputData = new HashMap<>();
inputData.put("dummy", "42");
inputData.put("title", "Step detail");
Map<String, Map> inputs = new HashMap<>();
// TODO: JSON
inputs.put("inputs", inputData);
scene.setUserData(inputs);
// See also:
// http://java-buddy.blogspot.com/2016/06/read-csv-run-in-background-thread-and.html
TableEditorEx tableEditorEx = new TableEditorEx();
tableEditorEx.setScene(scene);
try {
tableEditorEx.start(new Stage());
} catch (Exception e) {
}
}
});
Button saveButton = new Button();
Image saveImage = new Image(getClass().getClassLoader().getResourceAsStream("save_32.png"));
saveButton.setGraphic(new ImageView(saveImage));
saveButton.setTooltip(new Tooltip("Save session"));
saveButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
try {
System.err.println("Exercise exception");
testException();
} catch (Exception e) {
Dialog.showThrowable("Exception", "Exception thrown", (Exception) e, /* e.getCause()*/
stage);
}
// save
// https://docs.oracle.com/javafx/2/ui_controls/file-chooser.htm
FileChooser fileChooser = new FileChooser();
if (configFilePath != null) {
logger.info("Saving recording to: " + configFilePath);
try {
fileChooser.setInitialDirectory(new File(configFilePath));
} catch (IllegalArgumentException e) {
logger.info("Exception (ignored): " + e.toString());
}
}
// Set extension filter
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("YAML file", "*.yaml"));
fileChooser.setTitle("Save Recording");
File file = fileChooser.showSaveDialog(stage);
}
});
Button configButton = new Button();
Image configImage = new Image(getClass().getClassLoader().getResourceAsStream("preferences_32.png"));
configButton.setGraphic(new ImageView(configImage));
configButton.setTooltip(new Tooltip("Configure"));
configButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
Stage stage = new Stage();
ConfigFormEx s = new ConfigFormEx();
s.start(stage);
}
});
Button quitButton = new Button();
Image quitImage = new Image(getClass().getClassLoader().getResourceAsStream("quit_32.png"));
quitButton.setGraphic(new ImageView(quitImage));
quitButton.setTooltip(new Tooltip("Exit"));
stage.setOnCloseRequest(e -> {
e.consume();
confirmClose();
});
quitButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
confirmClose();
// TODO: refactor
// does not return
}
});
HBox toolbarHbox = new HBox();
toolbarHbox.getChildren().addAll(launchButton, injectButton, generateButton, loadButton, testsuiteButton, saveButton, configButton, quitButton);
statusLabel = new Label();
statusLabel.setText("Status");
HBox statusbarHbox = new HBox();
statusbarHbox.getChildren().addAll(statusLabel);
HBox.setHgrow(statusLabel, Priority.ALWAYS);
vbox.getChildren().add(toolbarHbox);
vbox.getChildren().add(flow);
vbox.getChildren().add(statusbarHbox);
VBox.setVgrow(flow, Priority.ALWAYS);
scene.setRoot(vbox);
stage.setScene(scene);
stage.show();
}
use of javafx.scene.Group in project CapsLock by chrootRISCassembler.
the class CharPanelGenerator method generate.
/**
* Generates a panel image form char.
* <p>First, this function converts ch to upper case if ch is lower case.</p>
* <p>Then, this generates javafx's image from ch.And return it.</p>
* You can fix the resolution of image through {@link capslock.CharPanelGenerator#PANEL_IMAGE_SIZE}
* and {@link capslock.CharPanelGenerator#FONT_SIZE}.
* @param ch パネルの生成に使う1文字.
* @param color 背景色.
* @return 生成されたパネル.
*/
static final Image generate(char ch, Color color) {
final Label label = new Label(Character.toString(Character.toUpperCase(ch)));
label.setMinSize(PANEL_IMAGE_SIZE, PANEL_IMAGE_SIZE);
label.setMaxSize(PANEL_IMAGE_SIZE, PANEL_IMAGE_SIZE);
label.setPrefSize(PANEL_IMAGE_SIZE, PANEL_IMAGE_SIZE);
label.setFont(Font.font(FONT_SIZE));
label.setAlignment(Pos.CENTER);
label.setTextFill(Color.WHITE);
label.setBackground(new Background(new BackgroundFill(color, CornerRadii.EMPTY, Insets.EMPTY)));
final Scene scene = new Scene(new Group(label));
final WritableImage img = new WritableImage(PANEL_IMAGE_SIZE, PANEL_IMAGE_SIZE);
scene.snapshot(img);
return img;
}
Aggregations