|
22 | 22 | import javafx.application.Application; |
23 | 23 | import javafx.beans.binding.BooleanBinding; |
24 | 24 | import javafx.collections.FXCollections; |
| 25 | +import javafx.geometry.Orientation; |
25 | 26 | import javafx.scene.Node; |
26 | 27 | import javafx.scene.Scene; |
27 | 28 | import javafx.scene.control.Button; |
28 | 29 | import javafx.scene.control.CheckBox; |
29 | 30 | import javafx.scene.control.ColorPicker; |
30 | 31 | import javafx.scene.control.ComboBox; |
31 | 32 | import javafx.scene.control.IndexRange; |
| 33 | +import javafx.scene.control.Separator; |
32 | 34 | import javafx.scene.control.ToggleButton; |
33 | 35 | import javafx.scene.control.ToggleGroup; |
| 36 | +import javafx.scene.control.ToolBar; |
34 | 37 | import javafx.scene.control.Tooltip; |
35 | | -import javafx.scene.layout.HBox; |
36 | 38 | import javafx.scene.layout.Priority; |
37 | 39 | import javafx.scene.layout.VBox; |
38 | 40 | import javafx.scene.paint.Color; |
@@ -97,26 +99,28 @@ public void start(Stage primaryStage) { |
97 | 99 | CheckBox wrapToggle = new CheckBox("Wrap"); |
98 | 100 | wrapToggle.setSelected(true); |
99 | 101 | area.wrapTextProperty().bind(wrapToggle.selectedProperty()); |
100 | | - Button undoBtn = createButton("undo", area::undo); |
101 | | - Button redoBtn = createButton("redo", area::redo); |
102 | | - Button cutBtn = createButton("cut", area::cut); |
103 | | - Button copyBtn = createButton("copy", area::copy); |
104 | | - Button pasteBtn = createButton("paste", area::paste); |
105 | | - Button boldBtn = createButton("bold", this::toggleBold); |
106 | | - Button italicBtn = createButton("italic", this::toggleItalic); |
107 | | - Button underlineBtn = createButton("underline", this::toggleUnderline); |
108 | | - Button strikeBtn = createButton("strikethrough", this::toggleStrikethrough); |
| 102 | + Button undoBtn = createButton("undo", area::undo, "Undo"); |
| 103 | + Button redoBtn = createButton("redo", area::redo, "Redo"); |
| 104 | + Button cutBtn = createButton("cut", area::cut, "Cut"); |
| 105 | + Button copyBtn = createButton("copy", area::copy, "Copy"); |
| 106 | + Button pasteBtn = createButton("paste", area::paste, "Paste"); |
| 107 | + Button boldBtn = createButton("bold", this::toggleBold, "Bold"); |
| 108 | + Button italicBtn = createButton("italic", this::toggleItalic, "Italic"); |
| 109 | + Button underlineBtn = createButton("underline", this::toggleUnderline, "Underline"); |
| 110 | + Button strikeBtn = createButton("strikethrough", this::toggleStrikethrough, "Strike Trough"); |
109 | 111 | Button insertImageBtn = createButton("insertimage", this::insertImage, "Insert Image"); |
110 | 112 | ToggleGroup alignmentGrp = new ToggleGroup(); |
111 | | - ToggleButton alignLeftBtn = createToggleButton(alignmentGrp, "align-left", this::alignLeft); |
112 | | - ToggleButton alignCenterBtn = createToggleButton(alignmentGrp, "align-center", this::alignCenter); |
113 | | - ToggleButton alignRightBtn = createToggleButton(alignmentGrp, "align-right", this::alignRight); |
114 | | - ToggleButton alignJustifyBtn = createToggleButton(alignmentGrp, "align-justify", this::alignJustify); |
| 113 | + ToggleButton alignLeftBtn = createToggleButton(alignmentGrp, "align-left", this::alignLeft, "Align left"); |
| 114 | + ToggleButton alignCenterBtn = createToggleButton(alignmentGrp, "align-center", this::alignCenter, "Align center"); |
| 115 | + ToggleButton alignRightBtn = createToggleButton(alignmentGrp, "align-right", this::alignRight, "Align right"); |
| 116 | + ToggleButton alignJustifyBtn = createToggleButton(alignmentGrp, "align-justify", this::alignJustify, "Justify"); |
115 | 117 | ColorPicker paragraphBackgroundPicker = new ColorPicker(); |
116 | 118 | 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)); |
117 | 119 | sizeCombo.getSelectionModel().select(Integer.valueOf(12)); |
| 120 | + sizeCombo.setTooltip(new Tooltip("Font size")); |
118 | 121 | ComboBox<String> familyCombo = new ComboBox<>(FXCollections.observableList(Font.getFamilies())); |
119 | 122 | familyCombo.getSelectionModel().select("Serif"); |
| 123 | + familyCombo.setTooltip(new Tooltip("Font family")); |
120 | 124 | ColorPicker textColorPicker = new ColorPicker(Color.BLACK); |
121 | 125 | ColorPicker backgroundColorPicker = new ColorPicker(); |
122 | 126 |
|
@@ -262,20 +266,22 @@ protected boolean computeValue() { |
262 | 266 | } |
263 | 267 | }); |
264 | 268 |
|
265 | | - HBox panel1 = new HBox(3.0); |
266 | | - HBox panel2 = new HBox(3.0); |
267 | | - panel1.getChildren().addAll( |
268 | | - loadBtn, saveBtn, |
269 | | - wrapToggle, undoBtn, redoBtn, cutBtn, copyBtn, pasteBtn, |
270 | | - boldBtn, italicBtn, underlineBtn, strikeBtn, |
271 | | - alignLeftBtn, alignCenterBtn, alignRightBtn, alignJustifyBtn, insertImageBtn, |
| 269 | + ToolBar toolBar1 = new ToolBar( |
| 270 | + loadBtn, saveBtn, new Separator(Orientation.VERTICAL), |
| 271 | + wrapToggle, new Separator(Orientation.VERTICAL), |
| 272 | + undoBtn, redoBtn, new Separator(Orientation.VERTICAL), |
| 273 | + cutBtn, copyBtn, pasteBtn, new Separator(Orientation.VERTICAL), |
| 274 | + boldBtn, italicBtn, underlineBtn, strikeBtn, new Separator(Orientation.VERTICAL), |
| 275 | + alignLeftBtn, alignCenterBtn, alignRightBtn, alignJustifyBtn, new Separator(Orientation.VERTICAL), |
| 276 | + insertImageBtn, new Separator(Orientation.VERTICAL), |
272 | 277 | paragraphBackgroundPicker); |
273 | | - panel2.getChildren().addAll(sizeCombo, familyCombo, textColorPicker, backgroundColorPicker); |
| 278 | + |
| 279 | + ToolBar toolBar2 = new ToolBar(sizeCombo, familyCombo, textColorPicker, backgroundColorPicker); |
274 | 280 |
|
275 | 281 | VirtualizedScrollPane<GenericStyledArea<ParStyle, Either<String, LinkedImage>, TextStyle>> vsPane = new VirtualizedScrollPane<>(area); |
276 | 282 | VBox vbox = new VBox(); |
277 | 283 | VBox.setVgrow(vsPane, Priority.ALWAYS); |
278 | | - vbox.getChildren().addAll(panel1, panel2, vsPane); |
| 284 | + vbox.getChildren().addAll(toolBar1, toolBar2, vsPane); |
279 | 285 |
|
280 | 286 | Scene scene = new Scene(vbox, 600, 400); |
281 | 287 | scene.getStylesheets().add(RichText.class.getResource("rich-text.css").toExternalForm()); |
@@ -306,24 +312,27 @@ private Button createButton(String styleClass, Runnable action, String toolTip) |
306 | 312 | action.run(); |
307 | 313 | area.requestFocus(); |
308 | 314 | }); |
309 | | - button.setPrefWidth(20); |
310 | | - button.setPrefHeight(20); |
| 315 | + button.setPrefWidth(25); |
| 316 | + button.setPrefHeight(25); |
311 | 317 | if (toolTip != null) { |
312 | 318 | button.setTooltip(new Tooltip(toolTip)); |
313 | 319 | } |
314 | 320 | return button; |
315 | 321 | } |
316 | 322 |
|
317 | | - private ToggleButton createToggleButton(ToggleGroup grp, String styleClass, Runnable action) { |
| 323 | + private ToggleButton createToggleButton(ToggleGroup grp, String styleClass, Runnable action, String toolTip) { |
318 | 324 | ToggleButton button = new ToggleButton(); |
319 | 325 | button.setToggleGroup(grp); |
320 | 326 | button.getStyleClass().add(styleClass); |
321 | 327 | button.setOnAction(evt -> { |
322 | 328 | action.run(); |
323 | 329 | area.requestFocus(); |
324 | 330 | }); |
325 | | - button.setPrefWidth(20); |
326 | | - button.setPrefHeight(20); |
| 331 | + button.setPrefWidth(25); |
| 332 | + button.setPrefHeight(25); |
| 333 | + if (toolTip != null) { |
| 334 | + button.setTooltip(new Tooltip(toolTip)); |
| 335 | + } |
327 | 336 | return button; |
328 | 337 | } |
329 | 338 |
|
|
0 commit comments