Skip to content

Commit

Permalink
fix: only highlight the hyperlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
sillydan1 committed Mar 7, 2024
1 parent e71a312 commit b4a1b0b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.slf4j.LoggerFactory;

import dk.gtz.graphedit.model.ModelProject;
import dk.gtz.graphedit.serialization.IModelSerializer;
import dk.gtz.graphedit.spi.IPluginsContainer;
import dk.gtz.graphedit.util.EditorActions;
import dk.gtz.graphedit.util.HeightDragResizer;
Expand Down
13 changes: 5 additions & 8 deletions core/src/main/java/dk/gtz/graphedit/view/LogTabController.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private Pattern getPattern() {
// identifiers are uuid v4's
// [<display>](<identifier>)
var uuidRegex = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
var z = "\\[(?<display>[^]]+)]\\((?<identifier>"+uuidRegex+")\\)";
var z = "\\[(?<display>[^]]+)\\]\\((?<identifier>"+uuidRegex+")\\)";
return Pattern.compile(z);
}

Expand All @@ -86,13 +86,10 @@ private void initializeTextArea() {
}

private void onLinkClick(Hyperlink link) {
try {
var lookupId = UUID.fromString(link.getLink());
var result = getFocusable(lookupId);
result.ifPresent(IFocusable::focus);
} catch(Exception e) {
logger.error(e.getMessage(), e);
}
var lookupId = UUID.fromString(link.getLink());
getFocusable(lookupId).ifPresentOrElse(
IFocusable::focus,
() -> logger.warn("Nothing found for link to: <{}>", lookupId));
}

private Optional<IFocusable> getFocusable(UUID lookupId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

import org.kordamp.ikonli.bootstrapicons.BootstrapIcons;
import org.kordamp.ikonli.javafx.FontIcon;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import atlantafx.base.theme.Styles;
import ch.qos.logback.classic.Level;
Expand All @@ -19,7 +17,6 @@
* View controll for the log tabpane containing all the logs
*/
public class LogTabPaneController {
private static Logger logger = LoggerFactory.getLogger(LogTabPaneController.class);
@FXML
private TabPane tabpane;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public HyperlinkTextArea(Consumer<Hyperlink> showLink, String... styleClasses) {
text -> createStyledTextNode(t -> {
t.setText(text);
t.getStyleClass().addAll(styleClasses);
t.setStyle(e.getStyle().toCss());
}),
hyperlink -> createStyledTextNode(t -> {
if (!hyperlink.isEmpty()) {
Expand Down Expand Up @@ -72,7 +71,7 @@ public void appendWithLink(String displayedText, String link, TextStyle style) {
* @param link The link value
*/
public void appendWithLink(String displayedText, String link) {
appendWithLink(displayedText, link, TextStyle.randomTextColor());
appendWithLink(displayedText, link, TextStyle.EMPTY.setTextColor("-color-accent-fg"));
}

/**
Expand Down
29 changes: 15 additions & 14 deletions core/src/main/java/dk/gtz/graphedit/view/log/TextStyle.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@ public class TextStyle {
/**
* A text style using white text color
*/
public static final TextStyle WHITE = new TextStyle().setTextColor(Color.WHITE);
public static final TextStyle WHITE = new TextStyle().setTextColor("white");

/**
* Create a new text style with a random text color
* @return A new randomly colored text style
*/
public static TextStyle randomTextColor() {
var r = new Random();
return EMPTY.setTextColor(Color.color(
var c = Color.color(
r.nextDouble(),
r.nextDouble(),
r.nextDouble()));
r.nextDouble());
return EMPTY.setTextColor(cssColor(c));
}

/**
Expand All @@ -51,8 +52,8 @@ public static String cssColor(Color color) {
final Optional<Boolean> strikethrough;
final Optional<Integer> fontSize;
final Optional<String> fontFamily;
final Optional<Color> textColor;
final Optional<Color> backgroundColor;
final Optional<String> textColor;
final Optional<String> backgroundColor;

/**
* Construct a new text style instance
Expand All @@ -76,17 +77,17 @@ public TextStyle() {
* @param strikethrough Should the text be strikethrough
* @param fontSize Text size of the text style
* @param fontFamily The font to use
* @param textColor The color to use
* @param backgroundColor The background color
* @param textColor The css color to use
* @param backgroundColor The css background color to use
*/
public TextStyle(Optional<Boolean> bold,
Optional<Boolean> italic,
Optional<Boolean> underline,
Optional<Boolean> strikethrough,
Optional<Integer> fontSize,
Optional<String> fontFamily,
Optional<Color> textColor,
Optional<Color> backgroundColor) {
Optional<String> textColor,
Optional<String> backgroundColor) {
this.bold = bold;
this.italic = italic;
this.underline = underline;
Expand Down Expand Up @@ -143,8 +144,8 @@ public String toCss() {
strikethrough.ifPresent(b -> sb.append("-fx-strikethrough: ").append(b ? "true" : "false").append(";"));
fontSize.ifPresent(integer -> sb.append("-fx-font-size: ").append(integer).append("pt;"));
fontFamily.ifPresent(s -> sb.append("-fx-font-family: ").append(s).append(";"));
textColor.ifPresent(color -> sb.append("-fx-fill: ").append(cssColor(color)).append(";"));
backgroundColor.ifPresent(color -> sb.append("-rtfx-background-color: ").append(cssColor(color)).append(";"));
textColor.ifPresent(color -> sb.append("-fx-fill: ").append(color).append(";"));
backgroundColor.ifPresent(color -> sb.append("-rtfx-background-color: ").append(color).append(";"));
return sb.toString();
}

Expand Down Expand Up @@ -224,7 +225,7 @@ public TextStyle setFontFamily(String fontFamily) {
* @param textColor The new color of the text
* @return a new text style
*/
public TextStyle setTextColor(Color textColor) {
public TextStyle setTextColor(String textColor) {
return new TextStyle(bold, italic, underline, strikethrough, fontSize, fontFamily, Optional.of(textColor), backgroundColor);
}

Expand All @@ -234,15 +235,15 @@ public TextStyle setTextColor(Color textColor) {
* @return a new text style
*/
public TextStyle setTextColorWeb(String webColor) {
return setTextColor(Color.web(webColor));
return setTextColor(webColor);
}

/**
* Set the text background color attribute of the text style
* @param backgroundColor The new background color of the text
* @return a new text style
*/
public TextStyle setBackgroundColor(Color backgroundColor) {
public TextStyle setBackgroundColor(String backgroundColor) {
return new TextStyle(bold, italic, underline, strikethrough, fontSize, fontFamily, textColor, Optional.of(backgroundColor));
}
}

0 comments on commit b4a1b0b

Please sign in to comment.