use of javafx.scene.control.Tooltip in project lttng-scope by lttng.
the class StateRectangle method generateTooltip.
private void generateTooltip() {
if (fTooltip != null) {
return;
}
TooltipContents ttContents = new TooltipContents(fWidget.getDebugOptions());
ttContents.addTooltipRow(Messages.statePropertyElement, fInterval.getTreeElement().getName());
ttContents.addTooltipRow(Messages.statePropertyStateName, fInterval.getStateName());
ttContents.addTooltipRow(Messages.statePropertyStartTime, fInterval.getStartTime());
ttContents.addTooltipRow(Messages.statePropertyEndTime, fInterval.getEndTime());
// $NON-NLS-1$
ttContents.addTooltipRow(Messages.statePropertyDuration, fInterval.getDuration() + " ns");
/* Add rows corresponding to the properties from the interval */
Map<String, String> properties = fInterval.getProperties();
properties.forEach((k, v) -> ttContents.addTooltipRow(k, v));
Tooltip tt = new Tooltip();
tt.setGraphic(ttContents);
Tooltip.install(this, tt);
fTooltip = tt;
}
use of javafx.scene.control.Tooltip in project lttng-scope by lttng.
the class StateRectangle method showTooltip.
public void showTooltip(boolean beginning) {
generateTooltip();
Tooltip tt = requireNonNull(fTooltip);
/*
* Show the tooltip first, then move it to the correct location. It
* needs to be shown for its getWidth() etc. to be populated.
*/
tt.show(this, 0, 0);
Point2D position;
if (beginning) {
/* Align to the bottom-left of the rectangle, left-aligned. */
/* Yes, it needs to be getX() here (0), not getLayoutX(). */
position = this.localToScreen(getX(), getY() + getHeight());
} else {
/* Align to the bottom-right of the rectangle, right-aligned */
position = this.localToScreen(getX() + getWidth() - tt.getWidth(), getY() + getHeight());
}
tt.setAnchorX(position.getX());
tt.setAnchorY(position.getY());
}
use of javafx.scene.control.Tooltip in project RichTextFX by FXMisc.
the class RichText method createButton.
private Button createButton(String styleClass, Runnable action, String toolTip) {
Button button = new Button();
button.getStyleClass().add(styleClass);
button.setOnAction(evt -> {
action.run();
area.requestFocus();
});
button.setPrefWidth(25);
button.setPrefHeight(25);
if (toolTip != null) {
button.setTooltip(new Tooltip(toolTip));
}
return button;
}
use of javafx.scene.control.Tooltip in project RichTextFX by FXMisc.
the class RichText method start.
@Override
public void start(Stage primaryStage) {
mainStage = primaryStage;
Button loadBtn = createButton("loadfile", this::loadDocument, "Load document.\n\n" + "Note: the demo will load only previously-saved \"" + RTFX_FILE_EXTENSION + "\" files. " + "This file format is abitrary and may change across versions.");
Button saveBtn = createButton("savefile", this::saveDocument, "Save document.\n\n" + "Note: the demo will save the area's content to a \"" + RTFX_FILE_EXTENSION + "\" file. " + "This file format is abitrary and may change across versions.");
CheckBox wrapToggle = new CheckBox("Wrap");
wrapToggle.setSelected(true);
area.wrapTextProperty().bind(wrapToggle.selectedProperty());
Button undoBtn = createButton("undo", area::undo, "Undo");
Button redoBtn = createButton("redo", area::redo, "Redo");
Button cutBtn = createButton("cut", area::cut, "Cut");
Button copyBtn = createButton("copy", area::copy, "Copy");
Button pasteBtn = createButton("paste", area::paste, "Paste");
Button boldBtn = createButton("bold", this::toggleBold, "Bold");
Button italicBtn = createButton("italic", this::toggleItalic, "Italic");
Button underlineBtn = createButton("underline", this::toggleUnderline, "Underline");
Button strikeBtn = createButton("strikethrough", this::toggleStrikethrough, "Strike Trough");
Button insertImageBtn = createButton("insertimage", this::insertImage, "Insert Image");
ToggleGroup alignmentGrp = new ToggleGroup();
ToggleButton alignLeftBtn = createToggleButton(alignmentGrp, "align-left", this::alignLeft, "Align left");
ToggleButton alignCenterBtn = createToggleButton(alignmentGrp, "align-center", this::alignCenter, "Align center");
ToggleButton alignRightBtn = createToggleButton(alignmentGrp, "align-right", this::alignRight, "Align right");
ToggleButton alignJustifyBtn = createToggleButton(alignmentGrp, "align-justify", this::alignJustify, "Justify");
ColorPicker paragraphBackgroundPicker = new ColorPicker();
ComboBox<Integer> sizeCombo = new ComboBox<>(FXCollections.observableArrayList(5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 18, 20, 22, 24, 28, 32, 36, 40, 48, 56, 64, 72));
sizeCombo.getSelectionModel().select(Integer.valueOf(12));
sizeCombo.setTooltip(new Tooltip("Font size"));
ComboBox<String> familyCombo = new ComboBox<>(FXCollections.observableList(Font.getFamilies()));
familyCombo.getSelectionModel().select("Serif");
familyCombo.setTooltip(new Tooltip("Font family"));
ColorPicker textColorPicker = new ColorPicker(Color.BLACK);
ColorPicker backgroundColorPicker = new ColorPicker();
paragraphBackgroundPicker.setTooltip(new Tooltip("Paragraph background"));
textColorPicker.setTooltip(new Tooltip("Text color"));
backgroundColorPicker.setTooltip(new Tooltip("Text background"));
paragraphBackgroundPicker.valueProperty().addListener((o, old, color) -> updateParagraphBackground(color));
sizeCombo.setOnAction(evt -> updateFontSize(sizeCombo.getValue()));
familyCombo.setOnAction(evt -> updateFontFamily(familyCombo.getValue()));
textColorPicker.valueProperty().addListener((o, old, color) -> updateTextColor(color));
backgroundColorPicker.valueProperty().addListener((o, old, color) -> updateBackgroundColor(color));
undoBtn.disableProperty().bind(area.undoAvailableProperty().map(x -> !x));
redoBtn.disableProperty().bind(area.redoAvailableProperty().map(x -> !x));
BooleanBinding selectionEmpty = new BooleanBinding() {
{
bind(area.selectionProperty());
}
@Override
protected boolean computeValue() {
return area.getSelection().getLength() == 0;
}
};
cutBtn.disableProperty().bind(selectionEmpty);
copyBtn.disableProperty().bind(selectionEmpty);
area.beingUpdatedProperty().addListener((o, old, beingUpdated) -> {
if (!beingUpdated) {
boolean bold, italic, underline, strike;
Integer fontSize;
String fontFamily;
Color textColor;
Color backgroundColor;
IndexRange selection = area.getSelection();
if (selection.getLength() != 0) {
StyleSpans<TextStyle> styles = area.getStyleSpans(selection);
bold = styles.styleStream().anyMatch(s -> s.bold.orElse(false));
italic = styles.styleStream().anyMatch(s -> s.italic.orElse(false));
underline = styles.styleStream().anyMatch(s -> s.underline.orElse(false));
strike = styles.styleStream().anyMatch(s -> s.strikethrough.orElse(false));
int[] sizes = styles.styleStream().mapToInt(s -> s.fontSize.orElse(-1)).distinct().toArray();
fontSize = sizes.length == 1 ? sizes[0] : -1;
String[] families = styles.styleStream().map(s -> s.fontFamily.orElse(null)).distinct().toArray(String[]::new);
fontFamily = families.length == 1 ? families[0] : null;
Color[] colors = styles.styleStream().map(s -> s.textColor.orElse(null)).distinct().toArray(Color[]::new);
textColor = colors.length == 1 ? colors[0] : null;
Color[] backgrounds = styles.styleStream().map(s -> s.backgroundColor.orElse(null)).distinct().toArray(i -> new Color[i]);
backgroundColor = backgrounds.length == 1 ? backgrounds[0] : null;
} else {
int p = area.getCurrentParagraph();
int col = area.getCaretColumn();
TextStyle style = area.getStyleAtPosition(p, col);
bold = style.bold.orElse(false);
italic = style.italic.orElse(false);
underline = style.underline.orElse(false);
strike = style.strikethrough.orElse(false);
fontSize = style.fontSize.orElse(-1);
fontFamily = style.fontFamily.orElse(null);
textColor = style.textColor.orElse(null);
backgroundColor = style.backgroundColor.orElse(null);
}
int startPar = area.offsetToPosition(selection.getStart(), Forward).getMajor();
int endPar = area.offsetToPosition(selection.getEnd(), Backward).getMajor();
List<Paragraph<ParStyle, Either<String, LinkedImage>, TextStyle>> pars = area.getParagraphs().subList(startPar, endPar + 1);
@SuppressWarnings("unchecked") Optional<TextAlignment>[] alignments = pars.stream().map(p -> p.getParagraphStyle().alignment).distinct().toArray(Optional[]::new);
Optional<TextAlignment> alignment = alignments.length == 1 ? alignments[0] : Optional.empty();
@SuppressWarnings("unchecked") Optional<Color>[] paragraphBackgrounds = pars.stream().map(p -> p.getParagraphStyle().backgroundColor).distinct().toArray(Optional[]::new);
Optional<Color> paragraphBackground = paragraphBackgrounds.length == 1 ? paragraphBackgrounds[0] : Optional.empty();
updatingToolbar.suspendWhile(() -> {
if (bold) {
if (!boldBtn.getStyleClass().contains("pressed")) {
boldBtn.getStyleClass().add("pressed");
}
} else {
boldBtn.getStyleClass().remove("pressed");
}
if (italic) {
if (!italicBtn.getStyleClass().contains("pressed")) {
italicBtn.getStyleClass().add("pressed");
}
} else {
italicBtn.getStyleClass().remove("pressed");
}
if (underline) {
if (!underlineBtn.getStyleClass().contains("pressed")) {
underlineBtn.getStyleClass().add("pressed");
}
} else {
underlineBtn.getStyleClass().remove("pressed");
}
if (strike) {
if (!strikeBtn.getStyleClass().contains("pressed")) {
strikeBtn.getStyleClass().add("pressed");
}
} else {
strikeBtn.getStyleClass().remove("pressed");
}
if (alignment.isPresent()) {
TextAlignment al = alignment.get();
switch(al) {
case LEFT:
alignmentGrp.selectToggle(alignLeftBtn);
break;
case CENTER:
alignmentGrp.selectToggle(alignCenterBtn);
break;
case RIGHT:
alignmentGrp.selectToggle(alignRightBtn);
break;
case JUSTIFY:
alignmentGrp.selectToggle(alignJustifyBtn);
break;
}
} else {
alignmentGrp.selectToggle(null);
}
paragraphBackgroundPicker.setValue(paragraphBackground.orElse(null));
if (fontSize != -1) {
sizeCombo.getSelectionModel().select(fontSize);
} else {
sizeCombo.getSelectionModel().clearSelection();
}
if (fontFamily != null) {
familyCombo.getSelectionModel().select(fontFamily);
} else {
familyCombo.getSelectionModel().clearSelection();
}
if (textColor != null) {
textColorPicker.setValue(textColor);
}
backgroundColorPicker.setValue(backgroundColor);
});
}
});
ToolBar toolBar1 = new ToolBar(loadBtn, saveBtn, new Separator(Orientation.VERTICAL), wrapToggle, new Separator(Orientation.VERTICAL), undoBtn, redoBtn, new Separator(Orientation.VERTICAL), cutBtn, copyBtn, pasteBtn, new Separator(Orientation.VERTICAL), boldBtn, italicBtn, underlineBtn, strikeBtn, new Separator(Orientation.VERTICAL), alignLeftBtn, alignCenterBtn, alignRightBtn, alignJustifyBtn, new Separator(Orientation.VERTICAL), insertImageBtn, new Separator(Orientation.VERTICAL), paragraphBackgroundPicker);
ToolBar toolBar2 = new ToolBar(sizeCombo, familyCombo, textColorPicker, backgroundColorPicker);
VirtualizedScrollPane<GenericStyledArea<ParStyle, Either<String, LinkedImage>, TextStyle>> vsPane = new VirtualizedScrollPane<>(area);
VBox vbox = new VBox();
VBox.setVgrow(vsPane, Priority.ALWAYS);
vbox.getChildren().addAll(toolBar1, toolBar2, vsPane);
Scene scene = new Scene(vbox, 600, 400);
scene.getStylesheets().add(RichText.class.getResource("rich-text.css").toExternalForm());
primaryStage.setScene(scene);
area.requestFocus();
primaryStage.setTitle("Rich Text Demo");
primaryStage.show();
}
use of javafx.scene.control.Tooltip 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();
}
Aggregations