Skip to content

Commit

Permalink
Solved #3823 File annotation (#4246)
Browse files Browse the repository at this point in the history
* Solved #3823 File annotation: delete hyphens and new lines & wrap summary

* Fixed: l10n for remove line breaks

* Fixed: final variable name

* Revert "Fixed: l10n for remove line breaks"

This reverts commit ae2956b.

* Fixed: revert changed formatter & wrap marking tooltip

* Added: test for FileAnnotation

* Fixed: keep newline&hyphen formatter using `\R`
  • Loading branch information
upupming authored and tobiasdiez committed Aug 3, 2018
1 parent 89f855d commit 611ac55
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We changed the default keyboard shortcuts for moving between entries when the entry editor is active to ̀<kbd>alt</kbd> + <kbd>up/down</kbd>.
- Opening a new file now prompts the directory of the currently selected file, instead of the directory of the last opened file.
- 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
- Files without a defined external file type are now directly opened with the default application 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 markings and wrapped the summary in the File annotation tab. [#3823](https://github.com/JabRef/jabref/issues/3823)



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import javafx.scene.control.ListView;
import javafx.scene.control.SelectionMode;
import javafx.scene.control.TextArea;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;
Expand Down Expand Up @@ -63,7 +64,6 @@ public void initialize() {
annotationList.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
annotationList.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> viewModel.notifyNewSelectedAnnotation(newValue));
ViewModelListCellFactory<FileAnnotationViewModel> cellFactory = new ViewModelListCellFactory<FileAnnotationViewModel>()
.withTooltip(FileAnnotationViewModel::getMarking)
.withGraphic(this::createFileAnnotationNode);
annotationList.setCellFactory(cellFactory);
annotationList.setPlaceholder(new Label(Localization.lang("File has no attached annotations")));
Expand Down Expand Up @@ -94,12 +94,19 @@ 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: 0.75em; -fx-font-weight: bold");
marking.setMaxHeight(30);

Tooltip markingTooltip = new Tooltip(annotation.getMarking());
markingTooltip.setMaxWidth(800);
markingTooltip.setWrapText(true);
marking.setTooltip(markingTooltip);

// 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 @@ -11,6 +11,7 @@

public class FileAnnotationViewModel {

private static final String NEWLINE = String.format("%n");
private final FileAnnotation annotation;
private StringProperty author = new SimpleStringProperty();
private StringProperty page = new SimpleStringProperty();
Expand All @@ -31,7 +32,13 @@ 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 = markingContent.replaceAll("-" + NEWLINE, "");
new RemoveHyphenatedNewlinesFormatter().format(markingContent);
// remove new lines not preceded by '.' or ':'
markingContent = markingContent.replaceAll("(?<![.|:])" + NEWLINE, " ");
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,7 @@
* 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 Pattern HYPHENATED_WORDS = Pattern.compile("-\\R");

@Override
public String getName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* 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 Pattern LINEBREAKS = Pattern.compile("\\R");

@Override
public String getName() {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_zh.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1914,3 +1914,4 @@ View\ event\ log=查看事件日志
Website=网站
Write\ XMP-metadata\ to\ PDFs=将 XMP 元数据写入到 PDF 中

Removes\ all\ line\ breaks\ in\ the\ field\ content.=删除字段内容中所有的换行。
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.jabref.gui.entryeditor.fileannotationtab;

import java.time.LocalDateTime;
import java.util.Optional;

import org.jabref.model.pdf.FileAnnotation;
import org.jabref.model.pdf.FileAnnotationType;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class FileAnnotationViewModelTest {

@Test
public void removeOnlyLineBreaksNotPrecededByPeriodOrColon() {
String content = "This is content";
String marking = String.format("This is paragraph 1.%n" +
"This is paragr-%naph 2, and it crosses%nseveral lines,%nnow you can see next paragraph:%n"
+ "This is paragraph%n3.");

FileAnnotation linkedFileAnnotation = new FileAnnotation("John", LocalDateTime.now(), 3, content, FileAnnotationType.FREETEXT, Optional.empty());
FileAnnotation annotation = new FileAnnotation("Jaroslav Kucha ˇr", LocalDateTime.parse("2017-07-20T10:11:30"), 1, marking, FileAnnotationType.HIGHLIGHT, Optional.of(linkedFileAnnotation));

FileAnnotationViewModel annotationViewModel = new FileAnnotationViewModel(annotation);

assertEquals("Jaroslav Kucha ˇr", annotationViewModel.getAuthor());
assertEquals(1, annotation.getPage());
assertEquals("2017-07-20 10:11:30", annotationViewModel.getDate());
assertEquals("This is content", annotationViewModel.getContent());

assertEquals(String.format("This is paragraph 1.%n" +
"This is paragraph 2, and it crosses several lines, now you can see next paragraph:%n"
+ "This is paragraph 3."),
annotationViewModel.getMarking());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,10 @@ public void removeHyphensBeforeNewlines() {
assertEquals("water", formatter.format("wa-\r\nter"));
assertEquals("water", formatter.format("wa-\rter"));
}

@Test
public void removeHyphensBeforePlatformSpecificNewlines() {
String newLine = String.format("%n");
assertEquals("water", formatter.format("wa-" + newLine + "ter"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,10 @@ public void removeCarriageReturn() {
public void removeLineFeed() {
assertEquals("n linebreak", formatter.format("n\nlinebreak"));
}

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

0 comments on commit 611ac55

Please sign in to comment.