下面列出了怎么用javafx.scene.control.ContentDisplay的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Primary constructor.
*
* @param headingText Text to display
* @param plugins Plug-ins to include
* @param top a component (e.g. the parent in the layout tree) which should
* be informed when plug-ins are selected or deselected.
* @param globalParamLabels the labels of the global parameters.
*/
public HeadingPane(String headingText, List<DataAccessPlugin> plugins, PluginParametersPaneListener top, final Set<String> globalParamLabels) {
this.top = top;
boxes.setHgap(5);
plugins.stream().forEach(_item -> boxes.getChildren().add(makeInactiveSquare()));
setText(headingText);
setGraphic(boxes);
setContentDisplay(ContentDisplay.RIGHT);
setGraphicTextGap(5);
setCollapsible(true);
setExpanded(DataAccessPreferences.isExpanded(headingText, true));
getStyleClass().add("titled-pane-heading");
VBox sources = new VBox();
sources.setPadding(Insets.EMPTY);
setContent(sources);
for (DataAccessPlugin plugin : plugins) {
final DataSourceTitledPane dataSourcePane = new DataSourceTitledPane(plugin, null, this, globalParamLabels);
dataSources.add(dataSourcePane);
sources.getChildren().add(dataSourcePane);
}
expandedProperty().addListener((ChangeListener) (final ObservableValue observable, final Object oldValue, final Object newValue)
-> DataAccessPreferences.setExpanded(headingText, (boolean) newValue));
}
public ItemListCell(ExecuteAction executeAction, final StringConverter<T> converter) {
setConverter(converter);
this.executeAction = executeAction;
this.button = new Button();
button.getStyleClass().clear();
button.setMinHeight(20);
button.setMinWidth(20);
//Image image = ImageBox.getImageClassPath("/resources/common/imagse/close/1_cancel_button_hover.png");
//button.setGraphic(new ImageView(image));
button.setText("X");
setAlignment(Pos.CENTER_LEFT);
setContentDisplay(ContentDisplay.LEFT);
setGraphic(null);
}
@Override
protected void setImages() throws Exception {
super.setImages();
// connect
btConnect.setGraphic(ImageManager.instance().getImageView(Images.CONNECT));
btConnect.setContentDisplay(ContentDisplay.LEFT);
// disconnect
btDisconnect.setGraphic(ImageManager.instance().getImageView(Images.DISCONNECT));
btDisconnect.setContentDisplay(ContentDisplay.LEFT);
// cancel connect
btCancelConnect.setGraphic(ImageManager.instance().getImageView(Images.CANCEL));
btCancelConnect.setContentDisplay(ContentDisplay.LEFT);
}
@Override
protected void setImages() throws Exception {
super.setImages();
// connect
btConnect.setGraphic(ImageManager.instance().getImageView(Images.CONNECT));
btConnect.setContentDisplay(ContentDisplay.RIGHT);
// disconnect
btDisconnect.setGraphic(ImageManager.instance().getImageView(Images.DISCONNECT));
btDisconnect.setContentDisplay(ContentDisplay.RIGHT);
// cancel connect
btCancelConnect.setGraphic(ImageManager.instance().getImageView(Images.CANCEL));
btCancelConnect.setContentDisplay(ContentDisplay.RIGHT);
}
@Override
public void commitEdit(String item) {
// This block is necessary to support commit on losing focus, because the baked-in mechanism
// sets our editing state to false before we can intercept the loss of focus.
// The default commitEdit(...) method simply bails if we are not editing...
if (!isEditing() && !item.equals(getItem())) {
TableView<SelectionTableRowData> table = getTableView();
if (table != null) {
TableColumn<SelectionTableRowData, String> column = getTableColumn();
CellEditEvent<SelectionTableRowData, String> event = new CellEditEvent<>(table,
new TablePosition<>(table, getIndex(), column), TableColumn.editCommitEvent(), item);
Event.fireEvent(column, event);
}
}
super.commitEdit(item);
setContentDisplay(ContentDisplay.TEXT_ONLY);
}
@Override
public void startEdit() {
if (isEditable()) {
super.startEdit();
// focus cell (in case of validation error the focus will remain)
getTableView().getFocusModel().focus(getTableRow().getIndex(), getTableColumn());
if (editorNode == null) {
createEditorNode();
} else {
// set current value if the editor is already created
builder.setValue(getValue());
}
builder.startEdit();
setGraphic(editorNode);
setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
}
}
@Override
public void updateItem(T item, boolean empty) {
super.updateItem(item, empty);
if (empty) {
setText(null);
setGraphic(null);
} else {
if (isEditing()) {
if (editorNode != null) {
builder.setValue(getValue());
}
setGraphic(editorNode);
setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
builder.updateItem(item, empty);
} else {
Object value = getValue();
if (value instanceof Node) {
setGraphic((Node) value);
setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
} else {
setText(value == null ? null : String.valueOf(value));
setContentDisplay(ContentDisplay.TEXT_ONLY);
}
}
}
}
@Override
protected void setImages() throws Exception {
super.setImages();
// new
btNew.setGraphic(ImageManager.instance().getImageView(Images.NEW));
btNew.setContentDisplay(ContentDisplay.LEFT);
// save
btSave.setGraphic(ImageManager.instance().getImageView(Images.SAVE));
btSave.setContentDisplay(ContentDisplay.LEFT);
// delete
btDelete.setGraphic(ImageManager.instance().getImageView(Images.DELETE));
btDelete.setContentDisplay(ContentDisplay.LEFT);
// test
btHttpTest.setGraphic(ImageManager.instance().getImageView(Images.EXECUTE));
btHttpTest.setContentDisplay(ContentDisplay.LEFT);
}
private void setImages() throws Exception {
// entity
btHttpGetEntities.setGraphic(ImageManager.instance().getImageView(Images.EQUIPMENT));
btHttpGetEntities.setContentDisplay(ContentDisplay.LEFT);
// materials
btHttpGetMaterials.setGraphic(ImageManager.instance().getImageView(Images.MATERIAL));
btHttpGetMaterials.setContentDisplay(ContentDisplay.LEFT);
// reasons
btHttpGetReasons.setGraphic(ImageManager.instance().getImageView(Images.REASON));
btHttpGetReasons.setContentDisplay(ContentDisplay.LEFT);
// execute
btTest.setGraphic(ImageManager.instance().getImageView(Images.EXECUTE));
btTest.setContentDisplay(ContentDisplay.LEFT);
// reset
btReset.setGraphic(ImageManager.instance().getImageView(Images.REFRESH_ALL));
btReset.setContentDisplay(ContentDisplay.LEFT);
}
@Override
protected void setImages() throws Exception {
super.setImages();
// new
btNew.setGraphic(ImageManager.instance().getImageView(Images.NEW));
btNew.setContentDisplay(ContentDisplay.LEFT);
// save
btSave.setGraphic(ImageManager.instance().getImageView(Images.SAVE));
btSave.setContentDisplay(ContentDisplay.LEFT);
// delete
btDelete.setGraphic(ImageManager.instance().getImageView(Images.DELETE));
btDelete.setContentDisplay(ContentDisplay.LEFT);
// test
btTest.setGraphic(ImageManager.instance().getImageView(Images.EXECUTE));
btTest.setContentDisplay(ContentDisplay.LEFT);
}
@Override
protected void setImages() throws Exception {
super.setImages();
// connect
btConnect.setGraphic(ImageManager.instance().getImageView(Images.CONNECT));
btConnect.setContentDisplay(ContentDisplay.LEFT);
// disconnect
btDisconnect.setGraphic(ImageManager.instance().getImageView(Images.DISCONNECT));
btDisconnect.setContentDisplay(ContentDisplay.LEFT);
// cancel connect
btCancelConnect.setGraphic(ImageManager.instance().getImageView(Images.CANCEL));
btCancelConnect.setContentDisplay(ContentDisplay.LEFT);
}
@Override
protected void setImages() throws Exception {
super.setImages();
// new
btNew.setGraphic(ImageManager.instance().getImageView(Images.NEW));
btNew.setContentDisplay(ContentDisplay.LEFT);
// save
btSave.setGraphic(ImageManager.instance().getImageView(Images.SAVE));
btSave.setContentDisplay(ContentDisplay.LEFT);
// delete
btDelete.setGraphic(ImageManager.instance().getImageView(Images.DELETE));
btDelete.setContentDisplay(ContentDisplay.LEFT);
// help
btCronHelp.setGraphic(ImageManager.instance().getImageView(Images.HELP));
btCronHelp.setContentDisplay(ContentDisplay.LEFT);
// test
btTest.setGraphic(ImageManager.instance().getImageView(Images.EXECUTE));
btTest.setContentDisplay(ContentDisplay.LEFT);
}
@Override
protected void setImages() throws Exception {
super.setImages();
// new
btNew.setGraphic(ImageManager.instance().getImageView(Images.NEW));
btNew.setContentDisplay(ContentDisplay.LEFT);
// save
btSave.setGraphic(ImageManager.instance().getImageView(Images.SAVE));
btSave.setContentDisplay(ContentDisplay.LEFT);
// delete
btDelete.setGraphic(ImageManager.instance().getImageView(Images.DELETE));
btDelete.setContentDisplay(ContentDisplay.LEFT);
// choose file
btFileChooser.setGraphic(ImageManager.instance().getImageView(Images.CHOOSE_FILE));
btFileChooser.setContentDisplay(ContentDisplay.LEFT);
}
private Node createMapListing(final GameChooserEntry gameChooserEntry) {
final var button = new Button(gameChooserEntry.getGameName());
// TODO Placeholder image, ship with engine
// or implement real map thumbnails
final var imageView =
new ImageView(new Image("https://triplea-game.org/images/missing_map.png", true));
imageView.setPreserveRatio(true);
imageView.setFitHeight(150);
imageView.setFitWidth(170);
button.setGraphic(imageView);
button.setWrapText(true);
button.setPrefSize(200, 200);
button.setContentDisplay(ContentDisplay.TOP);
button.setOnAction(
event -> {
selectedGame = gameChooserEntry;
selectButton.setDisable(false);
detailsButton.setDisable(false);
mapContainer.getChildren().forEach(node -> node.getStyleClass().remove("selected"));
button.getStyleClass().add("selected");
});
return button;
}
protected void setImages() throws Exception {
// new entity
btNew.setGraphic(ImageManager.instance().getImageView(Images.NEW));
btNew.setContentDisplay(ContentDisplay.RIGHT);
// save entity
btSave.setGraphic(ImageManager.instance().getImageView(Images.SAVE));
btSave.setContentDisplay(ContentDisplay.RIGHT);
// save all
btRefresh.setGraphic(ImageManager.instance().getImageView(Images.REFRESH));
btRefresh.setContentDisplay(ContentDisplay.RIGHT);
// delete entity
btDelete.setGraphic(ImageManager.instance().getImageView(Images.DELETE));
btDelete.setContentDisplay(ContentDisplay.RIGHT);
// dashboard
btDashboard.setGraphic(ImageManager.instance().getImageView(Images.DASHBOARD));
btDashboard.setContentDisplay(ContentDisplay.RIGHT);
// context menu
miSaveAll.setGraphic(ImageManager.instance().getImageView(Images.SAVE_ALL));
miRefreshAll.setGraphic(ImageManager.instance().getImageView(Images.REFRESH_ALL));
miClearSelection.setGraphic(ImageManager.instance().getImageView(Images.CLEAR));
}
protected void setImages() throws Exception {
// new equipment material
btNewMaterial.setGraphic(ImageManager.instance().getImageView(Images.NEW));
btNewMaterial.setContentDisplay(ContentDisplay.RIGHT);
// add equipment material
btAddMaterial.setGraphic(ImageManager.instance().getImageView(Images.ADD));
btAddMaterial.setContentDisplay(ContentDisplay.RIGHT);
// remove equipment material
btRemoveMaterial.setGraphic(ImageManager.instance().getImageView(Images.REMOVE));
btRemoveMaterial.setContentDisplay(ContentDisplay.RIGHT);
// find material
btFindMaterial.setGraphic(ImageManager.instance().getImageView(Images.MATERIAL));
btFindMaterial.setContentDisplay(ContentDisplay.CENTER);
// find UOMs
btFindIRRUnit.setGraphic(ImageManager.instance().getImageView(Images.UOM));
btFindIRRUnit.setContentDisplay(ContentDisplay.CENTER);
btFindRejectUnit.setGraphic(ImageManager.instance().getImageView(Images.UOM));
btFindRejectUnit.setContentDisplay(ContentDisplay.CENTER);
}
public BooleanCell() {
checkBox = new CheckBox();
checkBox.selectedProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
if(isEditing()) {
commitEdit(newValue == null ? false : newValue);
}
}
});
this.setGraphic(checkBox);
this.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
this.setEditable(true);
}
public ColorTableCell(TableColumn<T, Color> column) {
colorPicker = new ColorPicker();
colorPicker.editableProperty().bind(column.editableProperty());
colorPicker.disableProperty().bind(column.editableProperty().not());
colorPicker.setOnShowing(event -> {
final TableView<T> tableView = getTableView();
tableView.getSelectionModel().select(getTableRow().getIndex());
tableView.edit(tableView.getSelectionModel().getSelectedIndex(),
column);
});
colorPicker.valueProperty()
.addListener((observable, oldValue, newValue) -> {
commitEdit(newValue);
});
setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
}
public static ContentDisplay getControlContent(String value) {
if (value == null) {
return ContentDisplay.GRAPHIC_ONLY;
}
switch (value.toLowerCase()) {
case "graphic":
return ContentDisplay.GRAPHIC_ONLY;
case "text":
return ContentDisplay.TEXT_ONLY;
case "top":
return ContentDisplay.TOP;
case "left":
return ContentDisplay.LEFT;
case "right":
return ContentDisplay.RIGHT;
case "bottom":
return ContentDisplay.BOTTOM;
case "center":
return ContentDisplay.CENTER;
default:
return ContentDisplay.GRAPHIC_ONLY;
}
}
@Override
public void startEdit()
{
super.startEdit();
if (textField == null)
{
createTextField();
}
setGraphic(textField);
setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
Platform.runLater(new Runnable()
{
@Override
public void run()
{
textField.requestFocus();
textField.selectAll();
}
});
}
public BasicMacroItemCategory() {
final double height = 100;
VBox vb = new VBox(10);
categoryNode = vb;
ResourceBundle bundle = Lang.ApplicationBundle();
taComment.setPrefHeight(height);
taComment.setEditable(false);
Label lblComment = new Label(bundle.getString("Macros.comment"), taComment);
lblComment.setContentDisplay(ContentDisplay.BOTTOM);
taValue.setEditable(false);
taValue.setPrefHeight(height);
Label lblValue = new Label(bundle.getString("Macros.value"), taValue);
lblValue.setContentDisplay(ContentDisplay.BOTTOM);
lblMacroPropertyType = new Label(String.format(bundle.getString("Popups.ChooseMacro.property_type"), "?"));
vb.getChildren().addAll(lblValue, lblComment, lblMacroPropertyType);
}
/**
*
* @param item
* @param empty
*/
@Override
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (!empty) {
// Show the Text Field
this.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
ObservableValue<String> ov = getTableColumn().getCellObservableValue(getIndex());
SimpleStringProperty sp = (SimpleStringProperty) ov;
if (this.boundToCurrently == null) {
this.boundToCurrently = sp;
this.textField.textProperty().bindBidirectional(sp);
} else if (this.boundToCurrently != sp) {
this.textField.textProperty().unbindBidirectional(this.boundToCurrently);
this.boundToCurrently = sp;
this.textField.textProperty().bindBidirectional(this.boundToCurrently);
}
} else {
this.setContentDisplay(ContentDisplay.TEXT_ONLY);
}
}
public ColorTableCell(TableColumn<T, Color> column) {
colorPicker = new ColorPicker();
colorPicker.editableProperty().bind(column.editableProperty());
colorPicker.disableProperty().bind(column.editableProperty().not());
colorPicker.setOnShowing(event -> {
final TableView<T> tableView = getTableView();
tableView.getSelectionModel().select(getTableRow().getIndex());
tableView.edit(tableView.getSelectionModel().getSelectedIndex(), column);
});
colorPicker.valueProperty().addListener((observable, oldValue, newValue) -> {
commitEdit(newValue);
});
setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
}
public ConditionListCell() {
try {
list.add(this);
setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
URL location = BetonQuestEditor.class.getResource("view/other/ConditionListCell.fxml");
ResourceBundle resources = ResourceBundle.getBundle("pl.betoncraft.betonquest.editor.resource.lang.lang");
FXMLLoader fxmlLoader = new FXMLLoader(location, resources);
node = (HBox) fxmlLoader.load();
controller = (ConditionListCellController) fxmlLoader.getController();
} catch (Exception e) {
ExceptionController.display(e);
}
}
@Override
public Node constructContent() {
button = new Button();
button.setContentDisplay(ContentDisplay.TOP);
button.getStyleClass().add("buttonbase");
VBox.setVgrow(button, Priority.SOMETIMES);
button.setMaxSize(Integer.MAX_VALUE, Integer.MAX_VALUE);
button.setFocusTraversable(false);
button.setOnAction(this::onScriptAction);
return button;
}
protected void setButtonImages() throws Exception {
// trend auto starts
btToggleTrend.setGraphic(ImageManager.instance().getImageView(Images.STOP));
btToggleTrend.setContentDisplay(ContentDisplay.LEFT);
btToggleTrend.setText(DesignerLocalizer.instance().getLangString("stop"));
// clear trend
btResetTrend.setGraphic(ImageManager.instance().getImageView(Images.CLEAR));
btResetTrend.setContentDisplay(ContentDisplay.LEFT);
// refresh
btRefresh.setGraphic(ImageManager.instance().getImageView(Images.REFRESH));
btRefresh.setContentDisplay(ContentDisplay.LEFT);
}
@Override
protected void setImages() throws Exception {
super.setImages();
// execute
btExecute.setGraphic(ImageManager.instance().getImageView(Images.EXECUTE));
btExecute.setContentDisplay(ContentDisplay.RIGHT);
// clear script
btClearScript.setGraphic(ImageManager.instance().getImageView(Images.CLEAR));
btClearScript.setContentDisplay(ContentDisplay.RIGHT);
// clear result
btClearResult.setGraphic(ImageManager.instance().getImageView(Images.CLEAR));
btClearResult.setContentDisplay(ContentDisplay.RIGHT);
// set value
btSetValue.setGraphic(ImageManager.instance().getImageView(Images.APPLY));
btSetValue.setContentDisplay(ContentDisplay.LEFT);
// set value
btSetLastValue.setGraphic(ImageManager.instance().getImageView(Images.APPLY));
btSetLastValue.setContentDisplay(ContentDisplay.LEFT);
// find material
btFindMaterial.setGraphic(ImageManager.instance().getImageView(Images.MATERIAL));
btFindMaterial.setContentDisplay(ContentDisplay.LEFT);
// find a reason
btFindReason.setGraphic(ImageManager.instance().getImageView(Images.REASON));
btFindReason.setContentDisplay(ContentDisplay.LEFT);
}
@Override
protected void setImages() throws Exception {
super.setImages();
// new
btNew.setGraphic(ImageManager.instance().getImageView(Images.NEW));
btNew.setContentDisplay(ContentDisplay.RIGHT);
// save
btSave.setGraphic(ImageManager.instance().getImageView(Images.SAVE));
btSave.setContentDisplay(ContentDisplay.RIGHT);
// refresh
btRefresh.setGraphic(ImageManager.instance().getImageView(Images.REFRESH));
btRefresh.setContentDisplay(ContentDisplay.RIGHT);
// delete
btDelete.setGraphic(ImageManager.instance().getImageView(Images.DELETE));
btDelete.setContentDisplay(ContentDisplay.RIGHT);
// import
btImport.setGraphic(ImageManager.instance().getImageView(Images.IMPORT));
btImport.setContentDisplay(ContentDisplay.RIGHT);
// context menu
miSaveAll.setGraphic(ImageManager.instance().getImageView(Images.SAVE_ALL));
miRefreshAll.setGraphic(ImageManager.instance().getImageView(Images.REFRESH_ALL));
miClearSelection.setGraphic(ImageManager.instance().getImageView(Images.CLEAR));
}
@Override
protected void setImages() throws Exception {
super.setImages();
// connect
btConnect.setGraphic(ImageManager.instance().getImageView(Images.CONNECT));
btConnect.setContentDisplay(ContentDisplay.LEFT);
// disconnect
btDisconnect.setGraphic(ImageManager.instance().getImageView(Images.DISCONNECT));
btDisconnect.setContentDisplay(ContentDisplay.LEFT);
// cancel connect
btCancelConnect.setGraphic(ImageManager.instance().getImageView(Images.CANCEL));
btCancelConnect.setContentDisplay(ContentDisplay.LEFT);
// new
btNew.setGraphic(ImageManager.instance().getImageView(Images.NEW));
btNew.setContentDisplay(ContentDisplay.LEFT);
// save
btSave.setGraphic(ImageManager.instance().getImageView(Images.SAVE));
btSave.setContentDisplay(ContentDisplay.LEFT);
// delete
btDelete.setGraphic(ImageManager.instance().getImageView(Images.DELETE));
btDelete.setContentDisplay(ContentDisplay.LEFT);
// clear
btClearAuthentication.setGraphic(ImageManager.instance().getImageView(Images.CLEAR));
}
@Override
protected void setImages() throws Exception {
super.setImages();
// connect
btConnect.setGraphic(ImageManager.instance().getImageView(Images.CONNECT));
btConnect.setContentDisplay(ContentDisplay.LEFT);
// disconnect
btDisconnect.setGraphic(ImageManager.instance().getImageView(Images.DISCONNECT));
btDisconnect.setContentDisplay(ContentDisplay.LEFT);
// cancel connect
btCancelConnect.setGraphic(ImageManager.instance().getImageView(Images.CANCEL));
btCancelConnect.setContentDisplay(ContentDisplay.LEFT);
// new
btNew.setGraphic(ImageManager.instance().getImageView(Images.NEW));
btNew.setContentDisplay(ContentDisplay.LEFT);
// save
btSave.setGraphic(ImageManager.instance().getImageView(Images.SAVE));
btSave.setContentDisplay(ContentDisplay.LEFT);
// delete
btDelete.setGraphic(ImageManager.instance().getImageView(Images.DELETE));
btDelete.setContentDisplay(ContentDisplay.LEFT);
}