下面列出了javafx.scene.control.SeparatorMenuItem#javafx.scene.control.Tooltip 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public final void setAttribute(Attribute attribute, boolean isKey) {
if (attribute != this.attribute || this.isKey != isKey) {
this.attribute = attribute;
this.isKey = isKey;
setText(attribute.getName());
if (isKey) {
setGraphic(new ImageView(KEY_IMAGE));
} else if (attribute instanceof NewAttribute) {
setGraphic(new ImageView(ADD_IMAGE));
} else {
setGraphic(null);
}
setTooltip(new Tooltip(String.format("%s: %s", attribute.getAttributeType(), attribute.getDescription())));
deleteMenu.setDisable(!(attribute instanceof NewAttribute));
}
}
public DataSourceTitledPane(final DataAccessPlugin plugin, final ImageView dataSourceIcon, final PluginParametersPaneListener top, final Set<String> globalParamLabels) {
this.plugin = plugin;
this.top = top;
this.globalParamLabels = globalParamLabels;
isLoaded = false;
enabled = new CheckBox();
label = new Label(plugin.getName(), dataSourceIcon);
setGraphic(createTitleBar());
enabled.setDisable(true);
final boolean isExpanded = DataAccessPreferences.isExpanded(plugin.getName(), false);
createParameters(isExpanded, null);
setPadding(Insets.EMPTY);
setTooltip(new Tooltip(plugin.getDescription()));
}
/** @param enabled <code>true</code> to enable scrolling */
public void setScrolling(final boolean enabled)
{
//TODO: Fix graphics size to button size
final ScheduledFuture<?> was_scrolling;
if (enabled)
{ // Show that scrolling is 'on', and tool tip explains that it can be turned off
scroll_img.imageProperty().set(scroll_on);
scroll.setTooltip(new Tooltip(Messages.Scroll_Off_TT));
// Scroll once so that end of axis == 'now',
// because otherwise one of the listeners might right away
// disable scrolling
scroll();
final long scroll_period = scroll_step.toMillis();
was_scrolling = scrolling.getAndSet(Activator.thread_pool.scheduleAtFixedRate(RTTimePlot.this::scroll, scroll_period, scroll_period, TimeUnit.MILLISECONDS));
}
else
{ // Other way around
scroll_img.imageProperty().set(scroll_off);
scroll.setTooltip(new Tooltip(Messages.Scroll_On_TT));
was_scrolling = scrolling.getAndSet(null);
}
if (was_scrolling != null)
was_scrolling.cancel(false);
}
private void initGraphics() {
if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 || Double.compare(getWidth(), 0.0) <= 0 ||
Double.compare(getHeight(), 0.0) <= 0) {
if (getPrefWidth() > 0 && getPrefHeight() > 0) {
setPrefSize(getPrefWidth(), getPrefHeight());
} else {
setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
}
}
canvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
ctx = canvas.getGraphicsContext2D();
tooltip = new Tooltip();
tooltip.setAutoHide(true);
getChildren().setAll(canvas);
}
public static void registerTooltip(Control node, WithDescription bean) {
Tooltip tooltip = new Tooltip();
tooltip.textProperty().bind(FXWrapper.wrapStringProperty(bean.descriptionProperty()));
FXWrapper.wrapStringProperty(bean.descriptionProperty()).addListener(e -> {
if (bean.getDescription() == null || bean.getDescription().isEmpty()) {
node.setTooltip(null);
} else {
node.setTooltip(tooltip);
}
});
if (bean.getDescription() == null || bean.getDescription().isEmpty()) {
node.setTooltip(null);
} else {
node.setTooltip(tooltip);
}
}
public static ButtonBase _initButtonBase(String name, String toolTip, boolean enabled, String buttonText, ButtonBase button) {
button.setId(name + "Button");
button.setTooltip(new Tooltip(toolTip));
Node enabledIcon = getImageFrom(name, "icons/", FromOptions.NULL_IF_NOT_EXISTS);
if (enabledIcon != null) {
button.setText(null);
button.setGraphic(enabledIcon);
}
if (buttonText != null) {
button.setText(buttonText);
} else if (enabledIcon == null) {
button.setText(name);
}
button.setDisable(!enabled);
button.setMinWidth(Region.USE_PREF_SIZE);
return button;
}
/** @param undo_manager {@link UndoableActionManager}
* @return Undo and Redo button
*/
public static Button[] createButtons(final UndoableActionManager undo_manager)
{
final Button undo_btn = new Button();
undo_btn.setGraphic(ImageCache.getImageView(UndoButtons.class, "/icons/undo.png"));
undo_btn.setTooltip(new Tooltip(Messages.Undo_TT));
undo_btn.setDisable(!undo_manager.canUndo());
undo_btn.setOnAction(event -> undo_manager.undoLast());
final Button redo_btn = new Button();
redo_btn.setGraphic(ImageCache.getImageView(UndoButtons.class, "/icons/redo.png"));
redo_btn.setTooltip(new Tooltip(Messages.Redo_TT));
redo_btn.setDisable(!undo_manager.canRedo());
redo_btn.setOnAction(event -> undo_manager.redoLast());
// Automatically enable/disable based on what's possible
undo_manager.addListener((to_undo, to_redo) ->
Platform.runLater(()->
{
undo_btn.setDisable(to_undo == null);
redo_btn.setDisable(to_redo == null);
})
);
return new Button[] { undo_btn, redo_btn };
}
public static void updateConfidence(TransactionConfidence confidence,
Tooltip tooltip,
TxConfidenceIndicator txConfidenceIndicator) {
if (confidence != null) {
switch (confidence.getConfidenceType()) {
case UNKNOWN:
tooltip.setText(Res.get("confidence.unknown"));
txConfidenceIndicator.setProgress(0);
break;
case PENDING:
tooltip.setText(Res.get("confidence.seen", confidence.numBroadcastPeers()));
txConfidenceIndicator.setProgress(-1.0);
break;
case BUILDING:
tooltip.setText(Res.get("confidence.confirmed", confidence.getDepthInBlocks()));
txConfidenceIndicator.setProgress(Math.min(1, (double) confidence.getDepthInBlocks() / 6.0));
break;
case DEAD:
tooltip.setText(Res.get("confidence.invalid"));
txConfidenceIndicator.setProgress(0);
break;
}
txConfidenceIndicator.setPrefSize(24, 24);
}
}
private ContextMenu buildContextMenu(Node item) {
ContextMenu contextMenu = new ContextMenuWithNoArrows();
CustomMenuItem menuItem = new CustomMenuItem(new Label("Export subtree...",
new FontIcon("fas-external-link-alt")));
Tooltip tooltip = new Tooltip("Export subtree to a text format");
Tooltip.install(menuItem.getContent(), tooltip);
menuItem.setOnAction(
e -> getService(DesignerRoot.TREE_EXPORT_WIZARD).apply(x -> x.showYourself(x.bindToNode(item)))
);
contextMenu.getItems().add(menuItem);
return contextMenu;
}
@Override
public void setCard(GameContext context, Card card, Player player) {
super.setCard(context, card, player);
if (tooltipContent == null) {
tooltip = new Tooltip();
tooltipContent = new CardTooltip();
tooltipContent.setCard(context, card, player);
tooltip.setGraphic(tooltipContent);
Tooltip.install(this, tooltip);
} else {
tooltipContent.setCard(context, card, player);
}
hideCard(player.hideCards());
if (player.hideCards()) {
Tooltip.uninstall(this, tooltip);
tooltipContent = null;
tooltip = null;
}
}
@Override
protected void beforeParentInit() {
additionalInfoListView.setPlaceholder(new Label("No additional info"));
Val<Node> currentSelection = initNodeSelectionHandling(getDesignerRoot(), EventStreams.never(), false);
// pin to see updates
currentSelection.pin();
hideCommonAttributesProperty()
.values()
.distinct()
.subscribe(show -> setFocusNode(currentSelection.getValue(), new DataHolder()));
attrValueColumn.setCellValueFactory(param -> Val.constant(DesignerUtil.attrToXpathString(param.getValue())));
attrNameColumn.setCellValueFactory(param -> Val.constant("@" + param.getValue().getName()));
attrNameColumn.setCellFactory(col -> new AttributeNameTableCell());
Label valueColGraphic = new Label("Value");
valueColGraphic.setTooltip(new Tooltip("This is the XPath 2.0 representation"));
attrValueColumn.setGraphic(valueColGraphic);
}
/**
As of Java 8, setting the tooltip show delay isn't possible. Until an official implementation, this is one way to configure the tooltip show delay
@param tooltip tooltip to change delay of
@param delayMillis milliseconds before the tooltip can appear
*/
public static void hackTooltipStartTiming(Tooltip tooltip, double delayMillis) {
try {
Field fieldBehavior = tooltip.getClass().getDeclaredField("BEHAVIOR");
fieldBehavior.setAccessible(true);
Object objBehavior = fieldBehavior.get(tooltip);
Field fieldTimer = objBehavior.getClass().getDeclaredField("activationTimer");
fieldTimer.setAccessible(true);
Timeline objTimer = (Timeline) fieldTimer.get(objBehavior);
objTimer.getKeyFrames().clear();
objTimer.getKeyFrames().add(new KeyFrame(new Duration(delayMillis)));
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
/**
* Sets the tooltip text, with the (x, y) location being used for the
* anchor. If the text is {@code null}, no tooltip will be displayed.
* This method is intended for calling by the {@link TooltipHandlerFX}
* class, you won't normally call it directly.
*
* @param text the text ({@code null} permitted).
* @param x the x-coordinate of the mouse pointer.
* @param y the y-coordinate of the mouse pointer.
*/
public void setTooltip(String text, double x, double y) {
if (text != null) {
if (this.tooltip == null) {
this.tooltip = new Tooltip(text);
Tooltip.install(this, this.tooltip);
} else {
this.tooltip.setText(text);
this.tooltip.setAnchorX(x);
this.tooltip.setAnchorY(y);
}
} else {
Tooltip.uninstall(this, this.tooltip);
this.tooltip = null;
}
}
@Override
public void initialize(final URL location, final ResourceBundle resources) {
setActivated(true);
undoB.setDisable(true);
redoB.setDisable(true);
addDisposable(UndoCollector.getInstance().redos().subscribe(redoable -> {
redoB.setDisable(redoable.isEmpty());
redoB.setTooltip(redoable.map(u -> new Tooltip(u.getUndoName(lang))).orElse(null));
}));
addDisposable(UndoCollector.getInstance().undos().subscribe(undoable -> {
undoB.setDisable(undoable.isEmpty());
undoB.setTooltip(undoable.map(u -> new Tooltip(u.getUndoName(lang))).orElse(null));
}));
}
/** Set input
*
* <p>Registers the input to be persisted and restored.
* The tab tooltip indicates complete input,
* while tab label will be set to basic name (sans path and extension).
* For custom name, call <code>setLabel</code> after updating input
* in <code>Platform.runLater()</code>
*
* @param input Input
* @see DockItemWithInput#setLabel(String)
*/
public void setInput(final URI input)
{
this.input = input;
final String name = input == null ? null : extract_name(input.getPath());
// Tooltip update must be on UI thread
Platform.runLater(() ->
{
if (input == null)
name_tab.setTooltip(new Tooltip(Messages.DockNotSaved));
else
{
name_tab.setTooltip(new Tooltip(input.toString()));
setLabel(name);
}
});
}
private void updateImageText(final Tuple<Image, String> values) {
if(currentCompilation != null && currentCompilation.isDone()) {
currentCompilation = null;
}
compiledText.setUserData(values.b);
// A text will be used to render the text shape.
if(values.a == null) {
compileTooltip.setText(SystemUtils.getInstance().getLatexErrorMessageFromLog(values.b));
Tooltip.install(text, compileTooltip);
setImageTextEnable(false);
compiledText.setImage(null);
}else {
// An image will be used to render the text shape.
compileTooltip.setText(null);
Tooltip.uninstall(text, compileTooltip);
compiledText.setImage(values.a);
setImageTextEnable(true);
updateTranslationCompiledText();
getCanvasParent().ifPresent(canvas -> canvas.update());
}
}
@Override
public void initTargetSection() {
super.initTargetSection();
fileTypeGroup.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
@Override
public void changed(ObservableValue<? extends Toggle> ov,
Toggle old_toggle, Toggle new_toggle) {
checkFileType();
}
});
checkFileType();
if (pcxRadio != null) {
FxmlControl.setTooltip(pcxRadio, new Tooltip(message("PcxComments")));
}
browseButton.setDisable(true);
}
public ClickableBitcoinAddress() {
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource("bitcoin_address.fxml"));
loader.setRoot(this);
loader.setController(this);
// The following line is supposed to help Scene Builder, although it doesn't seem to be needed for me.
loader.setClassLoader(getClass().getClassLoader());
loader.load();
AwesomeDude.setIcon(copyWidget, AwesomeIcon.COPY);
Tooltip.install(copyWidget, new Tooltip("Copy address to clipboard"));
AwesomeDude.setIcon(qrCode, AwesomeIcon.QRCODE);
Tooltip.install(qrCode, new Tooltip("Show a barcode scannable with a mobile phone for this address"));
addressStr = convert(address);
addressLabel.textProperty().bind(addressStr);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
protected ResourceTreeCell() {
setOnMouseClicked(this::handleMouseClickedEvent);
setOnDragDetected(this::handleStartDragEvent);
setOnDragDone(this::handleStopDragEvent);
this.icon = new ImageView();
this.tooltip = new Tooltip();
}
private HBox createCloseButton() {
HBox closeArea = new HBox();
closeButton = new Label(OCTICON_CLOSE_PANEL);
closeButton.setId(IdGenerator.getPanelCloseButtonId(panel.panelIndex));
closeButton.getStyleClass().addAll("octicon", "label-button");
closeButton.setOnMouseClicked((e) -> {
e.consume();
panel.parentPanelControl.closePanel(panel.panelIndex);
});
Tooltip.install(closeArea, new Tooltip("Close this panel"));
closeArea.getChildren().add(closeButton);
return closeArea;
}
private void setTradeIdColumnCellFactory() {
tradeIdColumn.getStyleClass().add("first-column");
tradeIdColumn.setCellValueFactory((offerListItem) -> new ReadOnlyObjectWrapper<>(offerListItem.getValue()));
tradeIdColumn.setCellFactory(
new Callback<>() {
@Override
public TableCell<ClosedTradableListItem, ClosedTradableListItem> call(TableColumn<ClosedTradableListItem,
ClosedTradableListItem> column) {
return new TableCell<>() {
private HyperlinkWithIcon field;
@Override
public void updateItem(final ClosedTradableListItem item, boolean empty) {
super.updateItem(item, empty);
if (item != null && !empty) {
field = new HyperlinkWithIcon(model.getTradeId(item));
field.setOnAction(event -> {
Tradable tradable = item.getTradable();
if (tradable instanceof Trade)
tradeDetailsWindow.show((Trade) tradable);
else if (tradable instanceof OpenOffer)
offerDetailsWindow.show(tradable.getOffer());
});
field.setTooltip(new Tooltip(Res.get("tooltip.openPopupForDetails")));
setGraphic(field);
} else {
setGraphic(null);
if (field != null)
field.setOnAction(null);
}
}
};
}
});
}
/**
* Get a title button
*
* @param fileName Image file name
* @param label Tooltip label
* @param titleName Title name to be inserted
* @return the title button
*/
private Button getTitleButton(String fileName, String label, String titleName) {
if (darkTheme)
fileName = fileName.replace(".png", "-light.png");
Button ret = new Button("", new ImageView(new Image("file:icons/" + fileName, 24, 24, false, true)));
Utils.setToolbarButtonStyle(ret);
ret.setTooltip(new Tooltip(LabelGrabber.INSTANCE.getLabel(label)));
ret.setOnAction((event) -> {
insertTitle(titleName, "");
});
getLyricsField().requestFocus();
return ret;
}
@Override
public void registerExercise(TrainingExercise exercise) {
final Tooltip t = new Tooltip(exercise.getInfo().getDescription());
t.setPrefWidth(500);
t.setWrapText(true);
exerciseItemPane.addButton(exercise, exercise.getInfo().getName(), Optional.empty(), Optional.of(t));
}
/**
* Refreshes the shown scripts.
* When this method is called it begins by clearing the <code>scriptGrid</code>.
* Afterwards this method refills it.
*/
private void updateScripts(final GridPane scriptGrid) {
scriptGrid.getChildren().clear();
for (int i = 0; i < filteredScripts.size(); i++) {
ScriptDTO script = filteredScripts.get(i);
final Label scriptName = new Label(script.getScriptName());
GridPane.setHgrow(scriptName, Priority.ALWAYS);
if (getControl().isShowScriptSource()) {
final Tooltip tooltip = new Tooltip(tr("Source: {0}", script.getScriptSource()));
Tooltip.install(scriptName, tooltip);
}
final Button installButton = new Button(tr("Install"));
installButton.setOnMouseClicked(evt -> {
try {
installScript(script);
} catch (IllegalArgumentException e) {
final ErrorDialog errorDialog = ErrorDialog.builder()
.withMessage(tr("Error while trying to download the installer"))
.withException(e)
.build();
errorDialog.showAndWait();
}
});
scriptGrid.addRow(i, scriptName, installButton);
}
}
@Override
public void start(Stage primaryStage) {
final Clock clock = new Clock(Duration.seconds(1), true);
final BorderPane root = new BorderPane();
final HBox controls = new HBox(5);
controls.setAlignment(Pos.CENTER);
controls.setPadding(new Insets(10));
final TextField itemField = new TextField();
itemField.setTooltip(new Tooltip("Type an item and press Enter"));
controls.getChildren().add(itemField);
final VBox items = new VBox(5);
itemField.setOnAction(event -> {
String text = itemField.getText();
Label label = new Label();
label.textProperty().bind(Bindings.format("%s (%s)", text, clock.getElapsedStringBinding()));
items.getChildren().add(label);
itemField.setText("");
});
final ScrollPane scroller = new ScrollPane();
scroller.setContent(items);
final Label currentTimeLabel = new Label();
currentTimeLabel.textProperty().bind(Bindings.format("Current time: %s", clock.getTimeStringBinding()));
root.setTop(controls);
root.setCenter(scroller);
root.setBottom(currentTimeLabel);
Scene scene = new Scene(root, 600, 400);
primaryStage.setTitle("Timed item display");
primaryStage.setScene(scene);
primaryStage.show();
}
public BrowseFileButton() {
setGraphic(FontAwesomeIconFactory.get().createIcon(FontAwesomeIcon.FILE_ALT, "1.2em"));
setTooltip(new Tooltip(Messages.get("BrowseFileButton.tooltip")));
setOnAction(this::browse);
disableProperty().bind(basePath.isNull());
// workaround for a JavaFX bug:
// avoid closing the dialog that contains this control when the user
// closes the FileChooser or DirectoryChooser using the ESC key
addEventHandler(KeyEvent.KEY_RELEASED, e-> {
if (e.getCode() == KeyCode.ESCAPE)
e.consume();
});
}
private void setAddressColumnCellFactory() {
addressColumn.setCellValueFactory((addressListItem) -> new ReadOnlyObjectWrapper<>(addressListItem.getValue()));
addressColumn.setCellFactory(
new Callback<>() {
@Override
public TableCell<LockedListItem, LockedListItem> call(TableColumn<LockedListItem,
LockedListItem> column) {
return new TableCell<>() {
private HyperlinkWithIcon hyperlinkWithIcon;
@Override
public void updateItem(final LockedListItem item, boolean empty) {
super.updateItem(item, empty);
if (item != null && !empty) {
String address = item.getAddressString();
hyperlinkWithIcon = new ExternalHyperlink(address);
hyperlinkWithIcon.setOnAction(event -> openBlockExplorer(item));
hyperlinkWithIcon.setTooltip(new Tooltip(Res.get("tooltip.openBlockchainForAddress", address)));
setGraphic(hyperlinkWithIcon);
} else {
setGraphic(null);
if (hyperlinkWithIcon != null)
hyperlinkWithIcon.setOnAction(null);
}
}
};
}
});
}
public LevelSkin(Gauge gauge) {
super(gauge);
locale = gauge.getLocale();
sections = gauge.getSections();
barTooltip = new Tooltip();
formatString = new StringBuilder("%.").append(Integer.toString(gauge.getDecimals())).append("f%%").toString();
currentValueListener = o -> setBar(gauge.getCurrentValue());
barTooltip.setTextAlignment(TextAlignment.CENTER);
initGraphics();
registerListeners();
}
public void addLocation(final Location LOCATION) {
double x = (LOCATION.getLongitude() + 180) * (PREFERRED_WIDTH / 360) + MAP_OFFSET_X;
double y = (PREFERRED_HEIGHT / 2) - (PREFERRED_WIDTH * (Math.log(Math.tan((Math.PI / 4) + (Math.toRadians(LOCATION.getLatitude()) / 2)))) / (2 * Math.PI)) + MAP_OFFSET_Y;
FontIcon locationIcon = new FontIcon(null == LOCATION.getIconCode() ? locationIconCode : LOCATION.getIconCode());
locationIcon.setIconSize(LOCATION.getIconSize());
locationIcon.setTextOrigin(VPos.CENTER);
locationIcon.setIconColor(null == LOCATION.getColor() ? getLocationColor() : LOCATION.getColor());
locationIcon.setX(x - LOCATION.getIconSize() * 0.5);
locationIcon.setY(y);
StringBuilder tooltipBuilder = new StringBuilder();
if (!LOCATION.getName().isEmpty()) tooltipBuilder.append(LOCATION.getName());
if (!LOCATION.getInfo().isEmpty()) tooltipBuilder.append("\n").append(LOCATION.getInfo());
String tooltipText = tooltipBuilder.toString();
if (!tooltipText.isEmpty()) {
Tooltip tooltip = new Tooltip(tooltipText);
tooltip.setFont(Font.font(10));
Tooltip.install(locationIcon, tooltip);
}
if (null != LOCATION.getMouseEnterHandler()) locationIcon.setOnMouseEntered(new WeakEventHandler<>(LOCATION.getMouseEnterHandler()));
if (null != LOCATION.getMousePressHandler()) locationIcon.setOnMousePressed(new WeakEventHandler<>(LOCATION.getMousePressHandler()));
if (null != LOCATION.getMouseReleaseHandler()) locationIcon.setOnMouseReleased(new WeakEventHandler<>(LOCATION.getMouseReleaseHandler()));
if (null != LOCATION.getMouseExitHandler()) locationIcon.setOnMouseExited(new WeakEventHandler<>(LOCATION.getMouseExitHandler()));
locations.put(LOCATION, locationIcon);
}
/**
* Creates the view.
* @param sh The model.
*/
ViewText(final Text sh, final LaTeXDataService data) {
super(sh);
text = new javafx.scene.text.Text();
compiledText = new ImageView();
compileTooltip = new Tooltip(null);
this.latexData = data;
// Scaling at 0.5 as the png produced by latex is zoomed x 2 (for a better rendering)
compiledText.setScaleX(0.5);
compiledText.setScaleY(0.5);
compiledText.setVisible(false);
compiledText.setSmooth(true);
compiledText.setCache(true);
compiledText.imageProperty().addListener((observable, oldValue, theImg) -> {
if(theImg != null) {
// Have to move the picture as it is zoomed
compiledText.setX(-theImg.getWidth() / 4d);
compiledText.setY(-(3d * theImg.getHeight()) / 4d);
}
});
textUpdate = (observable, oldValue, newValue) -> update();
model.textProperty().addListener(textUpdate);
getChildren().add(text);
getChildren().add(compiledText);
setImageTextEnable(false);
update();
bindTextPosition();
}