Skip to content

Commit

Permalink
Show more than one group color bar (#5356)
Browse files Browse the repository at this point in the history
Show more than one group color bar
  • Loading branch information
koppor authored Oct 2, 2019
2 parents 7717137 + 65ad056 commit c33ba43
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 132 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
### Changed

- We added a short DOI field formatter which shortens DOI to more human readable form. [koppor#343](https://github.com/koppor/jabref/issues/343)
- We improved the display of group memberships by adding multiple colored bars if the entry belongs to more than one group. [#4574](https://github.com/JabRef/jabref/issues/4574)

### Fixed

Expand Down
43 changes: 22 additions & 21 deletions src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import javax.swing.undo.UndoManager;

import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.ContextMenu;
Expand All @@ -17,8 +18,8 @@
import javafx.scene.control.Tooltip;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;

Expand Down Expand Up @@ -129,27 +130,27 @@ public MainTableColumnFactory(BibDatabaseContext database, ColumnPreferences pre
}

private Node createGroupColorRegion(BibEntryTableViewModel entry, List<AbstractGroup> matchedGroups) {
Color groupColor = matchedGroups.stream()
.flatMap(group -> OptionalUtil.toStream(group.getColor()))
.findFirst()
.orElse(Color.TRANSPARENT);

if (groupColor != Color.TRANSPARENT) {
Rectangle border = new Rectangle();
border.setWidth(5);
border.setHeight(20);
border.setFill(Color.DARKGRAY);

Rectangle groupRectangle = new Rectangle();
groupRectangle.setWidth(3);
groupRectangle.setHeight(18);
groupRectangle.setFill(groupColor);

StackPane container = new StackPane();
container.setMinWidth(10);
container.setAlignment(Pos.CENTER);
List<Color> groupColors = matchedGroups.stream()
.flatMap(group -> OptionalUtil.toStream(group.getColor()))
.collect(Collectors.toList());

container.getChildren().addAll(border,groupRectangle);
if (!groupColors.isEmpty()) {
HBox container = new HBox();
container.setSpacing(2);
container.setMinWidth(10);
container.setAlignment(Pos.CENTER_LEFT);
container.setPadding(new Insets(0, 2, 0, 2));

for (Color groupColor : groupColors) {
Rectangle groupRectangle = new Rectangle();
groupRectangle.setWidth(3);
groupRectangle.setHeight(18);
groupRectangle.setFill(groupColor);
groupRectangle.setStroke(Color.DARKGRAY);
groupRectangle.setStrokeWidth(1);

container.getChildren().add(groupRectangle);
}

String matchedGroupsString = matchedGroups.stream()
.map(AbstractGroup::getName)
Expand Down
117 changes: 55 additions & 62 deletions src/test/java/org/jabref/logic/openoffice/OOBibStyleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,22 @@
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.jabref.logic.importer.ImportFormatPreferences;
import org.jabref.logic.importer.Importer;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.importer.fileformat.BibtexParser;
import org.jabref.logic.layout.Layout;
import org.jabref.logic.layout.LayoutFormatterPreferences;
import org.jabref.model.database.BibDatabase;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.StandardField;
import org.jabref.model.entry.types.StandardEntryType;
import org.jabref.model.entry.types.UnknownEntryType;
import org.jabref.model.util.DummyFileUpdateMonitor;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -36,18 +31,16 @@
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;

public class OOBibStyleTest {
class OOBibStyleTest {
private LayoutFormatterPreferences layoutFormatterPreferences;
private ImportFormatPreferences importFormatPreferences;

@BeforeEach
public void setUp() {
void setUp() {
layoutFormatterPreferences = mock(LayoutFormatterPreferences.class, Answers.RETURNS_DEEP_STUBS);
importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS);
}

@Test
public void testAuthorYear() throws IOException {
void testAuthorYear() throws IOException {
OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH, layoutFormatterPreferences);
assertTrue(style.isValid());
assertTrue(style.isFromResource());
Expand All @@ -60,7 +53,7 @@ public void testAuthorYear() throws IOException {
}

@Test
public void testAuthorYearAsFile() throws URISyntaxException, IOException {
void testAuthorYearAsFile() throws URISyntaxException, IOException {
File defFile = Paths.get(OOBibStyleTest.class.getResource(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH).toURI())
.toFile();
OOBibStyle style = new OOBibStyle(defFile, layoutFormatterPreferences, StandardCharsets.UTF_8);
Expand All @@ -75,7 +68,7 @@ public void testAuthorYearAsFile() throws URISyntaxException, IOException {
}

@Test
public void testNumerical() throws IOException {
void testNumerical() throws IOException {
OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH,
layoutFormatterPreferences);
assertTrue(style.isValid());
Expand All @@ -88,7 +81,7 @@ public void testNumerical() throws IOException {
}

@Test
public void testGetNumCitationMarker() throws IOException {
void testGetNumCitationMarker() throws IOException {
OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH,
layoutFormatterPreferences);
assertEquals("[1] ", style.getNumCitationMarker(Arrays.asList(1), -1, true));
Expand All @@ -105,7 +98,7 @@ public void testGetNumCitationMarker() throws IOException {
}

@Test
public void testGetNumCitationMarkerUndefined() throws IOException {
void testGetNumCitationMarkerUndefined() throws IOException {
OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH,
layoutFormatterPreferences);
assertEquals("[" + OOBibStyle.UNDEFINED_CITATION_MARKER + "; 2-4] ",
Expand All @@ -123,7 +116,7 @@ public void testGetNumCitationMarkerUndefined() throws IOException {
}

@Test
public void testGetCitProperty() throws IOException {
void testGetCitProperty() throws IOException {
OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH,
layoutFormatterPreferences);
assertEquals(", ", style.getStringCitProperty("AuthorSeparator"));
Expand All @@ -135,59 +128,59 @@ public void testGetCitProperty() throws IOException {
assertTrue(journals.contains("Journal name 1"));
}

/**
* In IntelliJ: When running this test, ensure that the working directory is <code>%MODULE_WORKING_DIR%"</code>
*/
@Test
public void testGetCitationMarker() throws IOException {
Path testBibtexFile = Paths.get("src/test/resources/testbib/complex.bib");
ParserResult result = new BibtexParser(importFormatPreferences, new DummyFileUpdateMonitor()).parse(Importer.getReader(testBibtexFile, StandardCharsets.UTF_8));
OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH,
layoutFormatterPreferences);
void testGetCitationMarker() throws IOException {
OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, layoutFormatterPreferences);
BibEntry entry = new BibEntry()
.withField(StandardField.AUTHOR, "Gustav Bostr\\\"{o}m and Jaana W\\\"{a}yrynen and Marine Bod\\'{e}n and Konstantin Beznosov and Philippe Kruchten")
.withField(StandardField.YEAR, "2006")
.withField(StandardField.BOOKTITLE, "SESS '06: Proceedings of the 2006 international workshop on Software engineering for secure systems")
.withField(StandardField.PUBLISHER, "ACM")
.withField(StandardField.TITLE, "Extending XP practices to support security requirements engineering")
.withField(StandardField.PAGES, "11--18");
BibDatabase database = new BibDatabase();
database.insertEntry(entry);
Map<BibEntry, BibDatabase> entryDBMap = new HashMap<>();
BibDatabase db = result.getDatabase();
for (BibEntry entry : db.getEntries()) {
entryDBMap.put(entry, db);
}
entryDBMap.put(entry, database);

BibEntry entry = db.getEntryByKey("1137631").get();
assertEquals("[Boström et al., 2006]",
style.getCitationMarker(Arrays.asList(entry), entryDBMap, true, null, null));
style.getCitationMarker(Collections.singletonList(entry), entryDBMap, true, null, null));
assertEquals("Boström et al. [2006]",
style.getCitationMarker(Arrays.asList(entry), entryDBMap, false, null, new int[]{3}));
style.getCitationMarker(Collections.singletonList(entry), entryDBMap, false, null, new int[]{3}));
assertEquals("[Boström, Wäyrynen, Bodén, Beznosov & Kruchten, 2006]",
style.getCitationMarker(Arrays.asList(entry), entryDBMap, true, null, new int[]{5}));
style.getCitationMarker(Collections.singletonList(entry), entryDBMap, true, null, new int[]{5}));
}

/**
* In IntelliJ: When running this test, ensure that the working directory is <code>%MODULE_WORKING_DIR%"</code>
*/
@Test
public void testLayout() throws IOException {
Path testBibtexFile = Paths.get("src/test/resources/testbib/complex.bib");
ParserResult result = new BibtexParser(importFormatPreferences, new DummyFileUpdateMonitor()).parse(Importer.getReader(testBibtexFile, StandardCharsets.UTF_8));
OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH,
layoutFormatterPreferences);
BibDatabase db = result.getDatabase();
void testLayout() throws IOException {
OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, layoutFormatterPreferences);

BibEntry entry = new BibEntry()
.withField(StandardField.AUTHOR, "Gustav Bostr\\\"{o}m and Jaana W\\\"{a}yrynen and Marine Bod\\'{e}n and Konstantin Beznosov and Philippe Kruchten")
.withField(StandardField.YEAR, "2006")
.withField(StandardField.BOOKTITLE, "SESS '06: Proceedings of the 2006 international workshop on Software engineering for secure systems")
.withField(StandardField.PUBLISHER, "ACM")
.withField(StandardField.TITLE, "Extending XP practices to support security requirements engineering")
.withField(StandardField.PAGES, "11--18");
BibDatabase database = new BibDatabase();
database.insertEntry(entry);

Layout l = style.getReferenceFormat(new UnknownEntryType("default"));
l.setPostFormatter(new OOPreFormatter());
BibEntry entry = db.getEntryByKey("1137631").get();
assertEquals(
"Boström, G.; Wäyrynen, J.; Bodén, M.; Beznosov, K. and Kruchten, P. (<b>2006</b>). <i>Extending XP practices to support security requirements engineering</i>, : 11-18.",
l.doLayout(entry, db));
l.doLayout(entry, database));

l = style.getReferenceFormat(StandardEntryType.InCollection);
l.setPostFormatter(new OOPreFormatter());
assertEquals(
"Boström, G.; Wäyrynen, J.; Bodén, M.; Beznosov, K. and Kruchten, P. (<b>2006</b>). <i>Extending XP practices to support security requirements engineering</i>. In: (Ed.), <i>SESS '06: Proceedings of the 2006 international workshop on Software engineering for secure systems</i>, ACM.",
l.doLayout(entry, db));
l.doLayout(entry, database));
}

@Test
public void testInstitutionAuthor() throws IOException {
OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH,
layoutFormatterPreferences);
void testInstitutionAuthor() throws IOException {
OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, layoutFormatterPreferences);
BibDatabase database = new BibDatabase();

Layout l = style.getReferenceFormat(StandardEntryType.Article);
Expand All @@ -204,7 +197,7 @@ public void testInstitutionAuthor() throws IOException {
}

@Test
public void testVonAuthor() throws IOException {
void testVonAuthor() throws IOException {
OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH,
layoutFormatterPreferences);
BibDatabase database = new BibDatabase();
Expand All @@ -223,7 +216,7 @@ public void testVonAuthor() throws IOException {
}

@Test
public void testInstitutionAuthorMarker() throws IOException {
void testInstitutionAuthorMarker() throws IOException {
OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH,
layoutFormatterPreferences);

Expand All @@ -243,7 +236,7 @@ public void testInstitutionAuthorMarker() throws IOException {
}

@Test
public void testVonAuthorMarker() throws IOException {
void testVonAuthorMarker() throws IOException {
OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH,
layoutFormatterPreferences);

Expand All @@ -263,7 +256,7 @@ public void testVonAuthorMarker() throws IOException {
}

@Test
public void testNullAuthorMarker() throws IOException {
void testNullAuthorMarker() throws IOException {
OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH,
layoutFormatterPreferences);

Expand All @@ -281,7 +274,7 @@ public void testNullAuthorMarker() throws IOException {
}

@Test
public void testNullYearMarker() throws IOException {
void testNullYearMarker() throws IOException {
OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH,
layoutFormatterPreferences);

Expand All @@ -299,7 +292,7 @@ public void testNullYearMarker() throws IOException {
}

@Test
public void testEmptyEntryMarker() throws IOException {
void testEmptyEntryMarker() throws IOException {
OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH,
layoutFormatterPreferences);

Expand All @@ -316,7 +309,7 @@ public void testEmptyEntryMarker() throws IOException {
}

@Test
public void testGetCitationMarkerInParenthesisUniquefiers() throws IOException {
void testGetCitationMarkerInParenthesisUniquefiers() throws IOException {
OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH,
layoutFormatterPreferences);

Expand Down Expand Up @@ -352,7 +345,7 @@ public void testGetCitationMarkerInParenthesisUniquefiers() throws IOException {
}

@Test
public void testGetCitationMarkerInTextUniquefiers() throws IOException {
void testGetCitationMarkerInTextUniquefiers() throws IOException {
OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH,
layoutFormatterPreferences);

Expand Down Expand Up @@ -388,7 +381,7 @@ public void testGetCitationMarkerInTextUniquefiers() throws IOException {
}

@Test
public void testGetCitationMarkerInParenthesisUniquefiersThreeSameAuthor() throws IOException {
void testGetCitationMarkerInParenthesisUniquefiersThreeSameAuthor() throws IOException {
OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH,
layoutFormatterPreferences);

Expand Down Expand Up @@ -423,7 +416,7 @@ public void testGetCitationMarkerInParenthesisUniquefiersThreeSameAuthor() throw
}

@Test
public void testGetCitationMarkerInTextUniquefiersThreeSameAuthor() throws IOException {
void testGetCitationMarkerInTextUniquefiersThreeSameAuthor() throws IOException {
OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH,
layoutFormatterPreferences);

Expand Down Expand Up @@ -459,7 +452,7 @@ public void testGetCitationMarkerInTextUniquefiersThreeSameAuthor() throws IOExc

@Test
// TODO: equals only work when initialized from file, not from reader
public void testEquals() throws IOException {
void testEquals() throws IOException {
OOBibStyle style1 = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH,
layoutFormatterPreferences);
OOBibStyle style2 = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH,
Expand All @@ -469,7 +462,7 @@ public void testEquals() throws IOException {

@Test
// TODO: equals only work when initialized from file, not from reader
public void testNotEquals() throws IOException {
void testNotEquals() throws IOException {
OOBibStyle style1 = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH,
layoutFormatterPreferences);
OOBibStyle style2 = new OOBibStyle(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH,
Expand All @@ -478,7 +471,7 @@ public void testNotEquals() throws IOException {
}

@Test
public void testCompareToEqual() throws IOException {
void testCompareToEqual() throws IOException {
OOBibStyle style1 = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH,
layoutFormatterPreferences);
OOBibStyle style2 = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH,
Expand All @@ -487,7 +480,7 @@ public void testCompareToEqual() throws IOException {
}

@Test
public void testCompareToNotEqual() throws IOException {
void testCompareToNotEqual() throws IOException {
OOBibStyle style1 = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH,
layoutFormatterPreferences);
OOBibStyle style2 = new OOBibStyle(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH,
Expand All @@ -497,7 +490,7 @@ public void testCompareToNotEqual() throws IOException {
}

@Test
public void testEmptyStringPropertyAndOxfordComma() throws URISyntaxException, IOException {
void testEmptyStringPropertyAndOxfordComma() throws URISyntaxException, IOException {
OOBibStyle style = new OOBibStyle("test.jstyle", layoutFormatterPreferences);
Map<BibEntry, BibDatabase> entryDBMap = new HashMap<>();
List<BibEntry> entries = new ArrayList<>();
Expand Down
Loading

0 comments on commit c33ba43

Please sign in to comment.