Skip to content

Commit

Permalink
Solved JabRef#3823 File annotation: delete hyphens and new lines & wr…
Browse files Browse the repository at this point in the history
…ap summary
  • Loading branch information
upupming committed Aug 2, 2018
1 parent 89f855d commit a0941e8
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- Window state is saved on close and restored on start.
- Files without a defined external file type are now directly opened with the default aplication of the operating system
- We streamlined the process to rename and move files by removing the confirmation dialogs.
- We removed the redundant new lines of marking and wrapped the summary in File annotation tab.



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,14 @@ private Node createFileAnnotationNode(FileAnnotationViewModel annotation) {
Label date = new Label(annotation.getDate());
Label page = new Label(Localization.lang("Page") + ": " + annotation.getPage());

marking.setStyle("-fx-font-weight: bold");
marking.setStyle("-fx-font-size: 10px; -fx-font-weight: bold");
marking.setMaxHeight(30);

// add alignment for text in the list
marking.setTextAlignment(TextAlignment.LEFT);
marking.setAlignment(Pos.TOP_LEFT);
marking.setMaxWidth(500);
marking.setWrapText(true);
author.setTextAlignment(TextAlignment.LEFT);
author.setAlignment(Pos.TOP_LEFT);
date.setTextAlignment(TextAlignment.RIGHT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ private void setupContentProperties(FileAnnotation annotation) {
this.content.set(annotation.getLinkedFileAnnotation().getContent());
String annotationContent = annotation.getContent();
String illegibleTextMessage = Localization.lang("The marked area does not contain any legible text!");
this.marking.set(annotationContent.isEmpty() ? illegibleTextMessage : annotationContent);
String markingContent = (annotationContent.isEmpty() ? illegibleTextMessage : annotationContent);
// remove newlines && hyphens before linebreaks
markingContent = new RemoveHyphenatedNewlinesFormatter().format(markingContent);
markingContent = new RemoveNewlinesFormatter().format(markingContent);
this.marking.set(markingContent);
} else {
String content = annotation.getContent();
// remove newlines && hyphens before linebreaks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
* Removes all hyphenated line breaks in the string.
*/
public class RemoveHyphenatedNewlinesFormatter extends Formatter {
private static final Pattern HYPHENATED_WORDS = Pattern.compile("(-\r\n|-\n|-\r)");
private static final String newLine = String.format("%n");
private static final Pattern HYPHENATED_WORDS = Pattern.compile("(-" + newLine + ")");

@Override
public String getName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
* Removes all line breaks in the string.
*/
public class RemoveNewlinesFormatter extends Formatter {
private static final Pattern LINEBREAKS = Pattern.compile("(\r?\n|\r)");
private static final String newLine = String.format("%n");
private static final Pattern LINEBREAKS = Pattern.compile("(?<![.|:])(" + newLine + ")");

@Override
public String getName() {
Expand All @@ -32,7 +33,7 @@ public String format(String value) {

@Override
public String getDescription() {
return Localization.lang("Removes all line breaks in the field content.");
return Localization.lang("Removes all line breaks which don't have preceded period or colon in the field content.");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ public void setUp() {

@Test
public void removeHyphensBeforeNewlines() {
assertEquals("water", formatter.format("wa-\nter"));
assertEquals("water", formatter.format("wa-\r\nter"));
assertEquals("water", formatter.format("wa-\rter"));
String newLine = String.format("%n");
assertEquals("water", formatter.format("wa-" + newLine + "ter"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,8 @@ public void setUp() {
}

@Test
public void removeCarriageReturnLineFeed() {
assertEquals("rn linebreak", formatter.format("rn\r\nlinebreak"));
}

@Test
public void removeCarriageReturn() {
assertEquals("r linebreak", formatter.format("r\rlinebreak"));
}

@Test
public void removeLineFeed() {
assertEquals("n linebreak", formatter.format("n\nlinebreak"));
public void removePlatformSpecificNewLine() {
String newLine = String.format("%n");
assertEquals("linebreak on current platfrom", formatter.format("linebreak on" + newLine + "current platfrom"));
}
}

0 comments on commit a0941e8

Please sign in to comment.