Skip to content

Commit

Permalink
Merge branch 'release/2.1.1'
Browse files Browse the repository at this point in the history
* release/2.1.1:
  2.1.1
  Changelog
  magic numbers are now in Constants class
  fixes #388
  2.1.1-SNAPSHOT
  Flags in menu are now automatically sorted alphabetically
  Flag menu can now be scrolled
  • Loading branch information
nilsreiter committed Jun 23, 2022
2 parents b3f2db8 + 6fd0acf commit 1c3f66c
Show file tree
Hide file tree
Showing 7 changed files with 635 additions and 15 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
Issue numbers (e.g., #43) refer to GitHub issues:
https://github.com/nilsreiter/CorefAnnotator/issues

## 2.1.1

- Fixed a bug that prevented flags from visible if there are a lot of them #387
- Fixed a bug that made flags undeletable #388

## 2.1.0

- New: Multiple files can be exported at once into CSV format #370
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.unistuttgart.ims</groupId>
<artifactId>coref.annotator</artifactId>
<version>2.1.0</version>
<version>2.1.1</version>
<packaging>jar</packaging>
<name>CorefAnnotator</name>
<url>https://github.com/nilsreiter/CorefAnnotator/</url>
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/de/unistuttgart/ims/coref/annotator/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@ public class Constants {
*/
public static final String CFG_ENTITY_SORT_DESCENDING = "CFG_ENTITY_SORT_DESCENDING";

/**
* Flag scroller: How many flags are displayed fixed at the top?
*/
public static final int CFG_FLAGSCROLLER_TOP_FIXED_COUNT = 10;

/**
* Flag scroller: How many flags are displayed fixed at the bottom?
*/
public static final int CFG_FLAGSCROLLER_BOTTOM_FIXED_COUNT = 3;

/**
*
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Collection;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.EventObject;
import java.util.Map;
Expand Down Expand Up @@ -809,7 +810,13 @@ public void setDocumentModel(DocumentModel model) {
segmentIndicator.setLastCharacterPosition(model.getJcas().getDocumentText().length());
}

for (Flag f : model.getFlagModel().getFlags()) {
for (Flag f : model.getFlagModel().getFlags().toSortedList(new Comparator<Flag>() {

@Override
public int compare(Flag o1, Flag o2) {
return o1.getLabel().compareTo(o2.getLabel());
}
})) {
ToggleFlagAction a = new ToggleFlagAction(DocumentWindow.this, model.getFlagModel(), f);
tree.addTreeSelectionListener(a);
try {
Expand Down Expand Up @@ -1610,28 +1617,26 @@ protected JMenu getMentionItem(Mention m) {
StringBuilder b = new StringBuilder();
b.append(m.getAddress());

String mention = StringUtils
.abbreviateMiddle(UimaUtil.getCoveredText(m), "...", 20);
String mention = StringUtils.abbreviateMiddle(UimaUtil.getCoveredText(m), "...", 20);

if (m.getEntity().getLabel() != null) {
String entity = StringUtils.abbreviateMiddle(
getDocumentModel().getCoreferenceModel().getLabel(m.getEntity()), "...",
Constants.UI_MAX_STRING_WIDTH_IN_MENU / 2);
b.append(String.format(": %s (%s)", mention, entity));
}

JMenu mentionMenu = new JMenu(b.toString());
mentionMenu.setIcon(FontIcon.of(MaterialDesign.MDI_ACCOUNT, new Color(m.getEntity().getColor())));
Action a = new ShowMentionInTreeAction(DocumentWindow.this, m);
mentionMenu.add(String.format("\"%s\"", mention));
mentionMenu.getItem(mentionMenu.getItemCount() - 1).setEnabled(false);
mentionMenu.add(a);
mentionMenu.add(new DeleteAction(DocumentWindow.this, m));

if (m.getSurface().size() > 1) {
for (MentionSurface ms : m.getSurface()) {
JMenu mentionSurfaceMenu = new JMenu(StringUtils.abbreviateMiddle(
ms.getCoveredText(), "...",
JMenu mentionSurfaceMenu = new JMenu(StringUtils.abbreviateMiddle(ms.getCoveredText(), "...",
Constants.UI_MAX_STRING_WIDTH_IN_MENU));
mentionSurfaceMenu.add(new DeleteAction(DocumentWindow.this, ms));
mentionMenu.add(mentionSurfaceMenu);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,9 @@ public DeleteFlagAction(DocumentWindow dw, JTable table) {

@Override
public void actionPerformed(ActionEvent e) {
int row = table.getSelectedRow();
table.clearSelection();
if (row != -1) {
String key = (String) table.getModel().getValueAt(row, 1);
Flag f = getTarget().getDocumentModel().getFlagModel().getFlag(key);
Flag f = getSelectedFlag();
if (f != null)
getTarget().getDocumentModel().edit(new DeleteFlag(f));
}
}

public JTable getTable() {
Expand All @@ -48,8 +44,27 @@ public void setTable(JTable table) {
this.table = table;
}

private Flag getSelectedFlag() {
int row = table.getSelectedRow();
table.clearSelection();
if (row != -1) {
String key = (String) table.getModel().getValueAt(row, 1);
Flag f = getTarget().getDocumentModel().getFlagModel().getFlag(key);
return f;
} else
return null;
}

@Override
public void valueChanged(ListSelectionEvent e) {
Flag f = getSelectedFlag();

if (f == null) {
this.setEnabled(false);
return;
}
// TODO: Check wether the flag is used
this.setEnabled(true);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
import org.eclipse.collections.api.map.MutableMap;
import org.eclipse.collections.impl.factory.Maps;

import de.unistuttgart.ims.coref.annotator.Constants;
import de.unistuttgart.ims.coref.annotator.DocumentWindow;
import de.unistuttgart.ims.coref.annotator.action.ToggleFlagAction;
import de.unistuttgart.ims.coref.annotator.api.v2.Flag;
import de.unistuttgart.ims.coref.annotator.api.v2.Flag;
import de.unistuttgart.ims.coref.annotator.document.FeatureStructureEvent;
import de.unistuttgart.ims.coref.annotator.document.FlagModel;
import de.unistuttgart.ims.coref.annotator.document.FlagModelListener;
Expand All @@ -25,12 +26,16 @@ public class FlagMenu extends JMenu implements FlagModelListener {
public FlagMenu(String s, DocumentWindow dw) {
super(s);
this.dw = dw;
MenuScroller.setScrollerFor(this, 20, 125, Constants.CFG_FLAGSCROLLER_TOP_FIXED_COUNT,
Constants.CFG_FLAGSCROLLER_BOTTOM_FIXED_COUNT);
}

public FlagMenu(String s, DocumentWindow dw, Class<? extends FeatureStructure> tClass) {
super(s);
this.dw = dw;
this.targetClass = tClass;
MenuScroller.setScrollerFor(this, 20, 125, Constants.CFG_FLAGSCROLLER_TOP_FIXED_COUNT,
Constants.CFG_FLAGSCROLLER_BOTTOM_FIXED_COUNT);
}

public JMenuItem add(Flag f, JMenuItem mi) {
Expand Down
Loading

0 comments on commit 1c3f66c

Please sign in to comment.