下面列出了javafx.scene.control.TextArea#setEditable ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static int addFormForBuyer(GridPane gridPane, int gridRow,
PaymentAccountPayload paymentAccountPayload, Offer offer, double top) {
F2FAccountPayload f2fAccountPayload = (F2FAccountPayload) paymentAccountPayload;
addCompactTopLabelTextFieldWithCopyIcon(gridPane, ++gridRow, 0, Res.get("shared.country"),
CountryUtil.getNameAndCode(f2fAccountPayload.getCountryCode()), top);
addCompactTopLabelTextFieldWithCopyIcon(gridPane, gridRow, 1, Res.get("payment.f2f.city"),
offer.getF2FCity(), top);
addCompactTopLabelTextFieldWithCopyIcon(gridPane, ++gridRow, Res.get("payment.f2f.contact"),
f2fAccountPayload.getContact());
TextArea textArea = addTopLabelTextArea(gridPane, gridRow, 1, Res.get("payment.f2f.extra"), "").second;
textArea.setPrefHeight(60);
textArea.setEditable(false);
textArea.setId("text-area-disabled");
textArea.setText(offer.getF2FExtraInfo());
return gridRow;
}
/**
* Get a {@link LabelBlockLookup} that returns all contained blocks ("OK") or no blocks ("CANCEL")
* @param source used to determine block sizes for marching cubes
* @return {@link LabelBlockLookup} that returns all contained blocks ("OK") or no blocks ("CANCEL")
*/
public static LabelBlockLookup getLabelBlockLookupFromDataSource(final DataSource<?, ?> source) {
final Alert alert = PainteraAlerts.alert(Alert.AlertType.CONFIRMATION);
alert.setHeaderText("Define label-to-block-lookup for on-the-fly mesh generation");
final TextArea ta = new TextArea("Could not deserialize label-to-block-lookup that is required for on the fly mesh generation. " +
"If you are not interested in 3D meshes, press cancel. Otherwise, press OK. Generating meshes on the fly will be slow " +
"as the sparsity of objects can not be utilized.");
ta.setEditable(false);
ta.setWrapText(true);
alert.getDialogPane().setContent(ta);
final Optional<ButtonType> bt = alert.showAndWait();
if (bt.isPresent() && ButtonType.OK.equals(bt.get())) {
final CellGrid[] grids = source.getGrids();
long[][] dims = new long[grids.length][];
int[][] blockSizes = new int[grids.length][];
for (int i = 0; i < grids.length; ++i) {
dims[i] = grids[i].getImgDimensions();
blockSizes[i] = new int[grids[i].numDimensions()];
grids[i].cellDimensions(blockSizes[i]);
}
LOG.debug("Returning block lookup returning all blocks.");
return new LabelBlockLookupAllBlocks(dims, blockSizes);
} else {
return new LabelBlockLookupNoBlocks();
}
}
void setDetailsText(String details) {
GridPane content = new GridPane();
content.setMaxHeight(Double.MAX_VALUE);
Label label = new Label("Details:");
TextArea textArea = new TextArea(details);
textArea.setEditable(false);
textArea.setMaxWidth(Double.MAX_VALUE);
textArea.setMaxHeight(Double.MAX_VALUE);
content.add(label, 0, 0);
content.add(textArea, 0, 1);
this.getDialogPane().setExpandableContent(content);
// work around DialogPane expandable content resize bug
this.getDialogPane().expandedProperty().addListener((ov, oldValue, newValue) -> {
Platform.runLater(() -> {
this.getDialogPane().requestLayout();
this.getDialogPane().getScene().getWindow().sizeToScene();
});
});
}
private Node createTextArea(boolean selectable, boolean editable) {
textArea = new TextArea();
textArea.setPrefRowCount(4);
textArea.setEditable(editable);
textArea.textProperty().addListener((observable, oldValue, newValue) -> {
item.setText(textArea.getText());
});
textArea.setText(item.getText());
ScrollPane scrollPane = new ScrollPane(textArea);
scrollPane.setFitToWidth(true);
scrollPane.setFitToHeight(true);
scrollPane.setHbarPolicy(ScrollBarPolicy.NEVER);
scrollPane.setVbarPolicy(ScrollBarPolicy.ALWAYS);
HBox.setHgrow(scrollPane, Priority.ALWAYS);
return scrollPane;
}
/** Show info dialog */
private void showInfo()
{
final Alert dlg = new Alert(AlertType.INFORMATION);
dlg.setTitle(Messages.DockInfo);
// No DialogPane 'header', all info is in the 'content'
dlg.setHeaderText("");
final StringBuilder info = new StringBuilder();
fillInformation(info);
final TextArea content = new TextArea(info.toString());
content.setEditable(false);
content.setPrefSize(300, 100);
content.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
dlg.getDialogPane().setContent(content);
DialogHelper.positionDialog(dlg, name_tab, 0, 0);
dlg.setResizable(true);
dlg.showAndWait();
}
/** @param parent Parent node, dialog will be positioned relative to it
* @param initial_text Initial text
* @param editable Allow editing?
* */
public MultiLineInputDialog(final Node parent, final String initial_text, final boolean editable)
{
text = new TextArea(initial_text);
text.setEditable(editable);
getDialogPane().setContent(new BorderPane(text));
if (editable)
getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);
else
getDialogPane().getButtonTypes().addAll(ButtonType.OK);
setResizable(true);
setResultConverter(button ->
{
return button == ButtonType.OK ? text.getText() : null;
});
DialogHelper.positionAndSize(this, parent,
PhoebusPreferenceService.userNodeForClass(MultiLineInputDialog.class),
600, 300);
}
public static void showErrorMessage(Exception ex, String title, String content) {
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle("Error occured");
alert.setHeaderText(title);
alert.setContentText(content);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
ex.printStackTrace(pw);
String exceptionText = sw.toString();
Label label = new Label("The exception stacktrace was:");
TextArea textArea = new TextArea(exceptionText);
textArea.setEditable(false);
textArea.setWrapText(true);
textArea.setMaxWidth(Double.MAX_VALUE);
textArea.setMaxHeight(Double.MAX_VALUE);
GridPane.setVgrow(textArea, Priority.ALWAYS);
GridPane.setHgrow(textArea, Priority.ALWAYS);
GridPane expContent = new GridPane();
expContent.setMaxWidth(Double.MAX_VALUE);
expContent.add(label, 0, 0);
expContent.add(textArea, 0, 1);
alert.getDialogPane().setExpandableContent(expContent);
alert.showAndWait();
}
@Override
protected void drawStepContent() {
super.drawStepContent();
TextArea licenceWidget = new TextArea(licenceText);
licenceWidget.setLayoutX(10);
licenceWidget.setLayoutY(100);
licenceWidget.setMinWidth(700);
licenceWidget.setMaxWidth(700);
licenceWidget.setMinHeight(308);
licenceWidget.setMaxHeight(308);
licenceWidget.setEditable(false);
CheckBox confirmWidget = new CheckBox(tr("I agree"));
confirmWidget.setOnAction(event -> {
isAgree = !isAgree;
confirmWidget.setSelected(isAgree);
setNextButtonEnabled(isAgree);
});
confirmWidget.setLayoutX(10);
confirmWidget.setLayoutY(418);
setNextButtonEnabled(false);
this.addToContentPane(licenceWidget);
this.addToContentPane(confirmWidget);
}
@Override
public Node getRoot(RequestContainer request, Templater templater) {
this.request = request;
textArea = new TextArea();
textArea.setEditable(false);
HBox osSelection = new HBox();
ToggleGroup group = new ToggleGroup();
RadioButton windowsTgl = new RadioButton("Windows");
windowsTgl.setToggleGroup(group);
windowsTgl.setSelected(isWindows);
RadioButton unixTgl = new RadioButton("Unix");
unixTgl.setSelected(!isWindows);
unixTgl.setToggleGroup(group);
windowsTgl.selectedProperty().addListener((obs, o, n) -> {
if (n != null) {
isWindows = n;
refreshCommand(templater);
}
});
osSelection.getChildren().add(windowsTgl);
osSelection.getChildren().add(unixTgl);
VBox root = new VBox();
root.getChildren().add(osSelection);
root.getChildren().add(textArea);
VBox.setVgrow(textArea, Priority.ALWAYS);
refreshCommand(templater);
return root;
}
public ExceptionDialog(Throwable ex) {
super(AlertType.ERROR);
setTitle("Exception");
setHeaderText("Exception during startup of application");
setContentText(ex.getClass().getName() + ": " + ex.getMessage());
// Create expandable Exception.
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
ex.printStackTrace(pw);
String exceptionText = sw.toString();
Label label = new Label("The exception stacktrace was:");
TextArea textArea = new TextArea(exceptionText);
textArea.setEditable(false);
textArea.setWrapText(true);
textArea.setMaxWidth(Double.MAX_VALUE);
textArea.setMaxHeight(Double.MAX_VALUE);
GridPane.setVgrow(textArea, Priority.ALWAYS);
GridPane.setHgrow(textArea, Priority.ALWAYS);
GridPane expContent = new GridPane();
expContent.setMaxWidth(Double.MAX_VALUE);
expContent.add(label, 0, 0);
expContent.add(textArea, 0, 1);
// Set expandable Exception into the dialog pane.
getDialogPane().setExpandableContent(expContent);
}
private TextArea getTextArea ()
{
TextArea textArea = new TextArea ();
textArea.setEditable (false);
textArea.setFont (Font.font ("Monospaced", 12));
textArea.setPrefWidth (TEXT_WIDTH);
return textArea;
}
private TextArea getTextArea ()
{
TextArea textArea = new TextArea ();
textArea.setEditable (false);
textArea.setFont (Font.font ("Monospaced", 12));
textArea.setPrefWidth (TEXT_WIDTH);
return textArea;
}
public static int addFormForBuyer(GridPane gridPane, int gridRow,
PaymentAccountPayload paymentAccountPayload) {
addCompactTopLabelTextFieldWithCopyIcon(gridPane, ++gridRow, Res.get("payment.account.owner"),
((USPostalMoneyOrderAccountPayload) paymentAccountPayload).getHolderName());
TextArea textArea = addCompactTopLabelTextArea(gridPane, ++gridRow, Res.get("payment.postal.address"), "").second;
textArea.setPrefHeight(70);
textArea.setEditable(false);
textArea.setId("text-area-disabled");
textArea.setText(((USPostalMoneyOrderAccountPayload) paymentAccountPayload).getPostalAddress());
return gridRow;
}
static void showThrowable(String sender, String className, String message, List<StackTraceElement> stacktrace) {
if (!Main.getProperties().getBoolean("error-alerting", true)) return;
Alert alert = new Alert(Alert.AlertType.ERROR);
((Stage) alert.getDialogPane().getScene().getWindow()).getIcons().add(new Image(App.ICON_URL.toString()));
alert.setTitle(Main.getString("error"));
alert.initModality(Modality.WINDOW_MODAL);
alert.setHeaderText(className + " " + Main.getString("caused-by") + " " + sender);
alert.setContentText(message);
StringBuilder exceptionText = new StringBuilder ();
for (Object item : stacktrace)
exceptionText.append((item != null ? item.toString() : "null") + "\n");
TextArea textArea = new TextArea(exceptionText.toString());
textArea.setEditable(false);
textArea.setWrapText(true);
textArea.setMaxWidth(Double.MAX_VALUE);
textArea.setMaxHeight(Double.MAX_VALUE);
CheckBox checkBox = new CheckBox(Main.getString("enable-error-alert"));
checkBox.setSelected(Main.getProperties().getBoolean("error-alerting", true));
checkBox.selectedProperty().addListener((obs, oldValue, newValue) -> {
Main.getProperties().put("error-alerting", newValue);
});
BorderPane pane = new BorderPane();
pane.setTop(checkBox);
pane.setCenter(textArea);
alert.getDialogPane().setExpandableContent(pane);
alert.show();
}
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("Simple Web Server");
BorderPane root = new BorderPane();
TextArea area = new TextArea();
root.setCenter(area);
ToolBar bar = new ToolBar();
Button openInBrowser = FXUIUtils.createButton("open-in-browser", "Open in External Browser", true);
openInBrowser.setOnAction((event) -> {
try {
Desktop.getDesktop().browse(URI.create(webRoot));
} catch (IOException e) {
e.printStackTrace();
}
});
Button changeRoot = FXUIUtils.createButton("fldr_closed", "Change Web Root", true);
changeRoot.setOnAction((event) -> {
DirectoryChooser chooser = new DirectoryChooser();
File showDialog = chooser.showDialog(primaryStage);
if (showDialog != null)
server.setRoot(showDialog);
});
bar.getItems().add(openInBrowser);
bar.getItems().add(changeRoot);
root.setTop(bar);
System.setOut(new PrintStream(new Console(area)));
System.setErr(new PrintStream(new Console(area)));
area.setEditable(false);
primaryStage.setScene(new Scene(root));
primaryStage.setOnShown((e) -> startServer(getParameters().getRaw()));
primaryStage.show();
}
private void createAlertDialog(DialogObject dialog) {
Alert alert = new Alert(dialog.getType());
alert.setTitle(dialog.getTitle());
alert.setHeaderText(dialog.getHeader());
alert.setContentText(dialog.getContent());
Optional<ButtonType> result = alert.showAndWait();
if (result.get() == ButtonType.OK) {
System.exit(0);
} else {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
dialog.getexception().printStackTrace(pw);
String exceptionText = sw.toString();
Label label = new Label("The exception stacktrace was:");
TextArea textArea = new TextArea(exceptionText);
textArea.setEditable(false);
textArea.setWrapText(true);
textArea.setMaxWidth(Double.MAX_VALUE);
textArea.setMaxHeight(Double.MAX_VALUE);
GridPane.setVgrow(textArea, Priority.ALWAYS);
GridPane.setHgrow(textArea, Priority.ALWAYS);
GridPane expContent = new GridPane();
expContent.setMaxWidth(Double.MAX_VALUE);
expContent.add(label, 0, 0);
expContent.add(textArea, 0, 1);
alert.getDialogPane().setExpandableContent(expContent);
alert.showAndWait();
}
}
private static void doOpenError(final Node node, final String title, final String message, final Exception exception)
{
final Alert dialog = new Alert(AlertType.ERROR);
dialog.setTitle(title);
dialog.setHeaderText(message);
if (exception != null)
{
// Show the simple exception name,
// e.g. "Exception" or "FileAlreadyExistsException" without package name,
// followed by message
dialog.setContentText(exception.getClass().getSimpleName() + ": " + exception.getMessage());
// Show exception stack trace in expandable section of dialog
final ByteArrayOutputStream buf = new ByteArrayOutputStream();
exception.printStackTrace(new PrintStream(buf));
// User can copy trace out of read-only text area
final TextArea trace = new TextArea(buf.toString());
trace.setEditable(false);
dialog.getDialogPane().setExpandableContent(trace);
}
dialog.setResizable(true);
dialog.getDialogPane().setPrefWidth(800);
if (node != null)
DialogHelper.positionDialog(dialog, node, -400, -200);
dialog.showAndWait();
}
@Override
public void gitExceptionDialog(String title, String header, String content, Exception e) {
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle(title);
alert.setHeaderText(header);
alert.setContentText(content);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
String exceptionText = sw.toString();
Label label = new Label("Exception stack trace:");
TextArea textArea = new TextArea(exceptionText);
textArea.setEditable(false);
textArea.setWrapText(true);
textArea.setMaxWidth(Double.MAX_VALUE);
textArea.setMaxHeight(Double.MAX_VALUE);
GridPane.setVgrow(textArea, Priority.ALWAYS);
GridPane.setHgrow(textArea, Priority.ALWAYS);
GridPane expContent = new GridPane();
expContent.setMaxWidth(Double.MAX_VALUE);
expContent.add(label, 0, 0);
expContent.add(textArea, 0, 1);
alert.getDialogPane().setExpandableContent(expContent);
alert.showAndWait();
}
/**
Returns a TextArea with the Throwable's stack trace printed inside it
@param thread thread where the Throwable occurred
@param t throwable
@return TextArea
*/
@NotNull
public static TextArea getExceptionTextArea(Thread thread, Throwable t) {
String err = getExceptionString(t);
TextArea ta = new TextArea();
ta.setPrefSize(700, 700);
ta.setText(err + "\nTHREAD:" + thread.getName());
ta.setEditable(false);
return ta;
}
/**
* Creates the expandable content component of the {@link ErrorDialog}
*
* @return The expandable content component of the {@link ErrorDialog}
*/
private VBox createExpandableContent() {
final Label label = new Label(tr("Stack trace:"));
final TextArea textArea = new TextArea();
textArea.setEditable(false);
textArea.textProperty().bind(StringBindings.map(exceptionProperty(), ExceptionUtils::getFullStackTrace));
VBox.setVgrow(textArea, Priority.ALWAYS);
final VBox container = new VBox(label, textArea);
container.setFillWidth(true);
return container;
}