diff --git a/.github/assets/FullFeaturedDemo.png b/.github/assets/FullFeaturedDemo.png new file mode 100644 index 0000000..49a993f Binary files /dev/null and b/.github/assets/FullFeaturedDemo.png differ diff --git a/.github/assets/TableDemo.png b/.github/assets/TableDemo.png index 1a0ff8d..9eadf0f 100644 Binary files a/.github/assets/TableDemo.png and b/.github/assets/TableDemo.png differ diff --git a/.github/assets/rta_editor.png b/.github/assets/rta_editor.png index 655b705..21dcad5 100644 Binary files a/.github/assets/rta_editor.png and b/.github/assets/rta_editor.png differ diff --git a/rta/src/main/java/com/gluonhq/richtextarea/ParagraphTile.java b/rta/src/main/java/com/gluonhq/richtextarea/ParagraphTile.java index 33f3337..472bcbb 100644 --- a/rta/src/main/java/com/gluonhq/richtextarea/ParagraphTile.java +++ b/rta/src/main/java/com/gluonhq/richtextarea/ParagraphTile.java @@ -158,9 +158,10 @@ private HBox createGridBox(List fragments, List positions, List fragments, List positions, List column ? j - 1 : j; + newColumnsPrefWidth[j] = j == column ? + COLUMN_PREF_WIDTH : tableDecoration.getColumnsPrefWidth()[colIndex]; + } + return new TableDecoration(rows, columns + 1, newCellAlignment, newColumnsPrefWidth); } public static TableDecoration fromTableDecorationDeletingColumn(TableDecoration tableDecoration, int column) { @@ -155,7 +180,17 @@ public static TableDecoration fromTableDecorationDeletingColumn(TableDecoration newCellAlignment[i][colIndex] = tableDecoration.getCellAlignment()[i][j]; } } - return new TableDecoration(rows, columns - 1, newCellAlignment); + Double[] newColumnsPrefWidth = new Double[columns + 1]; + for (int j = 0; j < columns + 1; j++) { + int colIndex = j; + if (j == column) { + continue; + } else if (j > column) { + colIndex = j - 1; + } + newColumnsPrefWidth[colIndex] = tableDecoration.getColumnsPrefWidth()[j]; + } + return new TableDecoration(rows, columns - 1, newCellAlignment, newColumnsPrefWidth); } @Override @@ -165,18 +200,19 @@ public boolean equals(Object o) { TableDecoration that = (TableDecoration) o; return rows == that.rows && columns == that.columns && - Arrays.deepEquals(cellAlignment, that.cellAlignment); + Arrays.deepEquals(cellAlignment, that.cellAlignment) && + Arrays.deepEquals(columnsPrefWidth, that.columnsPrefWidth); } @Override public int hashCode() { int result = Objects.hash(rows, columns); - result = 31 * result + Arrays.deepHashCode(cellAlignment); + result = 31 * result + Arrays.deepHashCode(cellAlignment) + Arrays.deepHashCode(columnsPrefWidth); return result; } @Override public String toString() { - return "TabDec[" + rows + " x " + columns + "] - " + Arrays.deepToString(cellAlignment); + return "TabDec[" + rows + " x " + columns + "] - " + Arrays.deepToString(cellAlignment) + " - " + Arrays.deepToString(columnsPrefWidth); } } diff --git a/samples/README.md b/samples/README.md index aca4dd3..e431899 100644 --- a/samples/README.md +++ b/samples/README.md @@ -159,4 +159,4 @@ To run this sample, using Java 17+, do as follows: mvn javafx:run ``` -![rta_editor.png](../.github/assets/rta_editor.png) +![rta_editor.png](../.github/assets/FullFeaturedDemo.png) diff --git a/samples/src/main/java/com/gluonhq/richtextarea/samples/FullFeaturedDemo.java b/samples/src/main/java/com/gluonhq/richtextarea/samples/FullFeaturedDemo.java index 3ced74d..595dcab 100644 --- a/samples/src/main/java/com/gluonhq/richtextarea/samples/FullFeaturedDemo.java +++ b/samples/src/main/java/com/gluonhq/richtextarea/samples/FullFeaturedDemo.java @@ -104,6 +104,10 @@ import static javafx.scene.text.FontPosture.REGULAR; import static javafx.scene.text.FontWeight.BOLD; import static javafx.scene.text.FontWeight.NORMAL; +import static javafx.scene.text.TextAlignment.CENTER; +import static javafx.scene.text.TextAlignment.JUSTIFY; +import static javafx.scene.text.TextAlignment.LEFT; +import static javafx.scene.text.TextAlignment.RIGHT; /** * This is an advance sample that shows how to create a rich text editor, by using @@ -127,15 +131,17 @@ public class FullFeaturedDemo extends Application { private final List decorations; { - TextDecoration bold14 = TextDecoration.builder().presets().fontWeight(BOLD).fontSize(14).build(); - TextDecoration preset = TextDecoration.builder().presets().build(); - ParagraphDecoration center63 = ParagraphDecoration.builder().presets().alignment(TextAlignment.CENTER).topInset(6).bottomInset(3).build(); - ParagraphDecoration justify22 = ParagraphDecoration.builder().presets().alignment(TextAlignment.JUSTIFY).topInset(2).bottomInset(2).build(); - ParagraphDecoration right22 = ParagraphDecoration.builder().presets().alignment(TextAlignment.RIGHT).topInset(2).bottomInset(2).build(); - ParagraphDecoration left535 = ParagraphDecoration.builder().presets().alignment(TextAlignment.LEFT).topInset(5).bottomInset(3).spacing(5).build(); - ParagraphDecoration center42 = ParagraphDecoration.builder().presets().alignment(TextAlignment.CENTER).topInset(4).bottomInset(2).build(); - TableDecoration tdec = new TableDecoration(2, 3, new TextAlignment[][]{{TextAlignment.CENTER, TextAlignment.LEFT, TextAlignment.RIGHT}, {TextAlignment.JUSTIFY, TextAlignment.RIGHT, TextAlignment.CENTER}}); - ParagraphDecoration table = ParagraphDecoration.builder().presets().alignment(TextAlignment.CENTER).tableDecoration(tdec).build(); + TextDecoration bold14 = TextDecoration.builder().presets().fontFamily("Arial").fontWeight(BOLD).fontSize(14).build(); + TextDecoration preset = TextDecoration.builder().presets().fontFamily("Arial").build(); + ParagraphDecoration center63 = ParagraphDecoration.builder().presets().alignment(CENTER).topInset(6).bottomInset(3).build(); + ParagraphDecoration justify22 = ParagraphDecoration.builder().presets().alignment(JUSTIFY).topInset(2).bottomInset(2).build(); + ParagraphDecoration right22 = ParagraphDecoration.builder().presets().alignment(RIGHT).topInset(2).bottomInset(2).build(); + ParagraphDecoration left535 = ParagraphDecoration.builder().presets().alignment(LEFT).topInset(5).bottomInset(3).spacing(5).build(); + ParagraphDecoration center42 = ParagraphDecoration.builder().presets().alignment(CENTER).topInset(4).bottomInset(2).build(); + TableDecoration tdec = new TableDecoration(2, 3, + new TextAlignment[][]{{CENTER, LEFT, RIGHT}, {JUSTIFY, RIGHT, CENTER}}, + new Double[] {100d, 50d, 150d}); + ParagraphDecoration table = ParagraphDecoration.builder().presets().alignment(CENTER).tableDecoration(tdec).build(); decorations = List.of( new DecorationModel(0, 21, bold14, center63), new DecorationModel(21, 575, preset, justify22), @@ -192,7 +198,7 @@ public Presets fromString(String s) { ComboBox fontFamilies = new ComboBox<>(); fontFamilies.getItems().setAll(Font.getFamilies()); - fontFamilies.setValue("Arial"); + fontFamilies.setValue("System"); fontFamilies.setPrefWidth(100); new TextDecorateAction<>(editor, fontFamilies.valueProperty(), TextDecoration::getFontFamily, (builder, a) -> builder.fontFamily(a).build()); @@ -269,10 +275,10 @@ public Double fromString(String s) { ToolBar paragraphToolbar = new ToolBar(); paragraphToolbar.getItems().setAll( - createToggleButton(LineAwesomeSolid.ALIGN_LEFT, property -> new ParagraphDecorateAction<>(editor, property, d -> d.getAlignment() == TextAlignment.LEFT, (builder, a) -> builder.alignment(TextAlignment.LEFT).build())), - createToggleButton(LineAwesomeSolid.ALIGN_CENTER, property -> new ParagraphDecorateAction<>(editor, property, d -> d.getAlignment() == TextAlignment.CENTER, (builder, a) -> builder.alignment(a ? TextAlignment.CENTER : TextAlignment.LEFT).build())), - createToggleButton(LineAwesomeSolid.ALIGN_RIGHT, property -> new ParagraphDecorateAction<>(editor, property, d -> d.getAlignment() == TextAlignment.RIGHT, (builder, a) -> builder.alignment(a ? TextAlignment.RIGHT : TextAlignment.LEFT).build())), - createToggleButton(LineAwesomeSolid.ALIGN_JUSTIFY, property -> new ParagraphDecorateAction<>(editor, property, d -> d.getAlignment() == TextAlignment.JUSTIFY, (builder, a) -> builder.alignment(a ? TextAlignment.JUSTIFY : TextAlignment.LEFT).build())), + createToggleButton(LineAwesomeSolid.ALIGN_LEFT, property -> new ParagraphDecorateAction<>(editor, property, d -> d.getAlignment() == LEFT, (builder, a) -> builder.alignment(LEFT).build())), + createToggleButton(LineAwesomeSolid.ALIGN_CENTER, property -> new ParagraphDecorateAction<>(editor, property, d -> d.getAlignment() == CENTER, (builder, a) -> builder.alignment(a ? CENTER : LEFT).build())), + createToggleButton(LineAwesomeSolid.ALIGN_RIGHT, property -> new ParagraphDecorateAction<>(editor, property, d -> d.getAlignment() == RIGHT, (builder, a) -> builder.alignment(a ? RIGHT : LEFT).build())), + createToggleButton(LineAwesomeSolid.ALIGN_JUSTIFY, property -> new ParagraphDecorateAction<>(editor, property, d -> d.getAlignment() == JUSTIFY, (builder, a) -> builder.alignment(a ? JUSTIFY : LEFT).build())), new Separator(Orientation.VERTICAL), createSpinner("Spacing", p -> new ParagraphDecorateAction<>(editor, p, v -> (int) v.getSpacing(), (builder, a) -> builder.spacing(a).build())), new Separator(Orientation.VERTICAL), @@ -533,10 +539,10 @@ public static void main(String[] args) { private enum Presets { - DEFAULT("Default",12, NORMAL, TextAlignment.LEFT), - HEADER1("Header 1", 32, BOLD, TextAlignment.CENTER), - HEADER2("Header 2", 24, BOLD, TextAlignment.LEFT), - HEADER3("Header 3", 19, BOLD, TextAlignment.LEFT); + DEFAULT("Default",12, NORMAL, LEFT), + HEADER1("Header 1", 32, BOLD, CENTER), + HEADER2("Header 2", 24, BOLD, LEFT), + HEADER3("Header 3", 19, BOLD, LEFT); private final String name; private final int fontSize; diff --git a/samples/src/main/java/com/gluonhq/richtextarea/samples/TableDemo.java b/samples/src/main/java/com/gluonhq/richtextarea/samples/TableDemo.java index f0aa202..ee191e1 100644 --- a/samples/src/main/java/com/gluonhq/richtextarea/samples/TableDemo.java +++ b/samples/src/main/java/com/gluonhq/richtextarea/samples/TableDemo.java @@ -89,7 +89,7 @@ private Document getDocument() { alignment[i][0] = TextAlignment.CENTER; alignment[i][1] = TextAlignment.LEFT; } - TableDecoration tableDecoration = new TableDecoration(flags, 2, alignment); + TableDecoration tableDecoration = new TableDecoration(flags, 2, alignment, new Double[] {80d, 200d}); ParagraphDecoration table = ParagraphDecoration.builder().presets().alignment(TextAlignment.CENTER) .tableDecoration(tableDecoration) .topInset(5).rightInset(5).bottomInset(5).leftInset(5)