-
Notifications
You must be signed in to change notification settings - Fork 100
#160 Capability to add multi-colored text inside a cell #161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tterimaa
wants to merge
4
commits into
vandeseer:master
Choose a base branch
from
tterimaa:multi-colored-text-cell
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
afedb5a
#160 Capability to add multi-colored text inside a cell
tterimaa 7cbab96
#160 Should add empty new line and not throw IndexOutOfBounds
tterimaa 81e3bfd
#160 Should ignore text with only newline
tterimaa ef19bb0
#160 Should set back the default color if a piece of text does not ha…
tterimaa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package org.vandeseer.easytable.structure; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
|
|
||
| import java.awt.*; | ||
| import java.util.Optional; | ||
|
|
||
| @Setter | ||
| public class Text { | ||
|
|
||
| @Getter | ||
| private final String text; | ||
| private final Color color; | ||
|
|
||
| public Text(String text, Color color) { | ||
| this.text = text; | ||
| this.color = color; | ||
| } | ||
|
|
||
| public Text(String text) { | ||
| this.text = text; | ||
| this.color = null; | ||
| } | ||
|
|
||
| public Optional<Color> getColor() { | ||
| return Optional.ofNullable(color); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 99 additions & 6 deletions
105
src/main/java/org/vandeseer/easytable/structure/cell/TextCell.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,113 @@ | ||
| package org.vandeseer.easytable.structure.cell; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.NonNull; | ||
| import lombok.experimental.SuperBuilder; | ||
| import org.vandeseer.easytable.drawing.Drawer; | ||
| import org.vandeseer.easytable.drawing.cell.TextCellDrawer; | ||
| import org.vandeseer.easytable.structure.Text; | ||
|
|
||
| @Getter | ||
| @SuperBuilder(toBuilder = true) | ||
| public class TextCell extends AbstractTextCell { | ||
| import java.util.List; | ||
|
|
||
| public class TextCell extends AbstractTextCell { | ||
| @NonNull | ||
| protected String text; | ||
| protected List<Text> text; | ||
|
|
||
| protected Drawer createDefaultDrawer() { | ||
| return new TextCellDrawer(this); | ||
| } | ||
|
|
||
| public static abstract class TextCellBuilder<C extends TextCell, B extends TextCell.TextCellBuilder<C, B>> extends AbstractTextCell.AbstractTextCellBuilder<C, B> { | ||
| @java.lang.SuppressWarnings("all") | ||
| private List<Text> text; | ||
|
|
||
| @java.lang.SuppressWarnings("all") | ||
| public B text(@NonNull final String text) { | ||
| if (text == null) { | ||
| throw new java.lang.NullPointerException("text is marked non-null but is null"); | ||
| } | ||
| this.text = List.of(new Text(text, this.settings.getTextColor())); | ||
| return self(); | ||
| } | ||
|
|
||
| @java.lang.SuppressWarnings("all") | ||
| public B coloredText(@NonNull final List<Text> text) { | ||
| if (text == null) { | ||
| throw new java.lang.NullPointerException("text is marked non-null but is null"); | ||
| } | ||
| this.text = text; | ||
| return self(); | ||
| } | ||
|
|
||
| @java.lang.Override | ||
| @java.lang.SuppressWarnings("all") | ||
| protected B $fillValuesFrom(final C instance) { | ||
| super.$fillValuesFrom(instance); | ||
| TextCell.TextCellBuilder.$fillValuesFromInstanceIntoBuilder(instance, this); | ||
| return self(); | ||
| } | ||
|
|
||
| @java.lang.SuppressWarnings("all") | ||
| private static void $fillValuesFromInstanceIntoBuilder(final TextCell instance, final TextCell.TextCellBuilder<?, ?> b) { | ||
| b.coloredText(instance.text); | ||
| } | ||
|
|
||
| @java.lang.Override | ||
| @java.lang.SuppressWarnings("all") | ||
| protected abstract B self(); | ||
|
|
||
| @java.lang.Override | ||
| @java.lang.SuppressWarnings("all") | ||
| public abstract C build(); | ||
|
|
||
| @java.lang.Override | ||
| @java.lang.SuppressWarnings("all") | ||
| public java.lang.String toString() { | ||
| return "TextCell.TextCellBuilder(super=" + super.toString() + ", text=" + this.text + ")"; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| @java.lang.SuppressWarnings("all") | ||
| private static final class TextCellBuilderImpl extends TextCell.TextCellBuilder<TextCell, TextCell.TextCellBuilderImpl> { | ||
| @java.lang.SuppressWarnings("all") | ||
| private TextCellBuilderImpl() { | ||
| } | ||
|
|
||
| @java.lang.Override | ||
| @java.lang.SuppressWarnings("all") | ||
| protected TextCell.TextCellBuilderImpl self() { | ||
| return this; | ||
| } | ||
|
|
||
| @java.lang.Override | ||
| @java.lang.SuppressWarnings("all") | ||
| public TextCell build() { | ||
| return new TextCell(this); | ||
| } | ||
| } | ||
|
|
||
| @java.lang.SuppressWarnings("all") | ||
| protected TextCell(final TextCell.TextCellBuilder<?, ?> b) { | ||
| super(b); | ||
| this.text = b.text; | ||
| if (text == null) { | ||
| throw new java.lang.NullPointerException("text is marked non-null but is null"); | ||
| } | ||
| } | ||
|
|
||
| @java.lang.SuppressWarnings("all") | ||
| public static TextCell.TextCellBuilder<?, ?> builder() { | ||
| return new TextCell.TextCellBuilderImpl(); | ||
| } | ||
|
|
||
| @java.lang.SuppressWarnings("all") | ||
| public TextCell.TextCellBuilder<?, ?> toBuilder() { | ||
| return new TextCell.TextCellBuilderImpl().$fillValuesFrom(this); | ||
| } | ||
|
|
||
| @NonNull | ||
| @java.lang.SuppressWarnings("all") | ||
| public List<Text> getText() { | ||
| return this.text; | ||
| } | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could not figure out how to extend this class without de-lomboking it. I think the problem was modifying the 'text' method to set this.text to List instead of String.