Commit 7ecf7121 authored by Christos Christodoulopoulos's avatar Christos Christodoulopoulos
Browse files

Added bookmarking

Closes #6
parent 6ecd36d8
No preview for this file type
......@@ -21,11 +21,13 @@ public class JBCorpus {
private List<JBDataStructure> annotations;
private List<String> contexts;
private Map<Integer, List<JBDataStructure>> contextToAnnotation;
private List<String> bookmarks;
private int lastEditIndex;
private JBDataStructure currentAnnotationOriginal;
private String corpusFile;
private String bookmarksFileExt = "-bmarks.txt";
private int currentAnnotationIndex;
......@@ -38,6 +40,7 @@ public class JBCorpus {
annotations = new ArrayList<JBDataStructure>();
contexts = new ArrayList<String>();
contextToAnnotation = new HashMap<Integer, List<JBDataStructure>>();
bookmarks = new ArrayList<String>();
corpusFile = file;
currentAnnotationIndex = 0;
currentAnnotationOriginal = new JBDataStructure();
......@@ -62,6 +65,7 @@ public class JBCorpus {
contexts = corpora[0].contexts;
currentAnnotationIndex = 0;
currentAnnotationOriginal = new JBDataStructure();
bookmarks = new ArrayList<String>();
// Aggregate the annotations across corpora
contextToAnnotation = new HashMap<Integer, List<JBDataStructure>>();
......@@ -125,6 +129,15 @@ public class JBCorpus {
String context = contextsArray.getString(i);
contexts.add(context);
}
String bookmarksFile = corpusFile + bookmarksFileExt;
if (new File(bookmarksFile).exists()) {
in = new BufferedReader(new InputStreamReader(new FileInputStream(bookmarksFile)));
while ((line = in.readLine()) != null) {
bookmarks.add(line);
}
}
}
public void saveCorpus(String file) throws JSONException, IOException {
......@@ -148,6 +161,12 @@ public class JBCorpus {
FileWriter out = new FileWriter(file);
out.write(corpus.toString(2));
out.close();
out = new FileWriter(file + bookmarksFileExt);
for (String bookmark : bookmarks) {
out.write(bookmark + "\n");
}
out.close();
}
private void setLastEditIndex(int index) {
......@@ -288,4 +307,30 @@ public class JBCorpus {
public void setAnnotationFinished(boolean annotationFinished) {
this.annotationFinished = annotationFinished;
}
/**
* Adds a bookmark to the current annotation
*/
public void addBookmark() {
bookmarks.add(generateBookmarkKey());
}
/**
* Removes an existing bookmark from the current annotation
*/
public void removeBookmark() {
String key = generateBookmarkKey();
if (bookmarks.contains(key))
bookmarks.remove(key);
}
public boolean isBookmarked() {
String key = generateBookmarkKey();
return (bookmarks.contains(key));
}
private String generateBookmarkKey() {
JBDataStructure annotation = getCurrentAnnotation();
return annotation.getIndexInContext() + ":" + annotation.getPredicateIndex();
}
}
......@@ -80,7 +80,7 @@ public class JBOpenDialog extends JDialog implements ActionListener, ItemListene
}
setTitle(jbtk.getUserID().toUpperCase() + ": " + getTitle());
setBounds(10, 10, 300, 600);
setBounds(10, 10, 350, 600);
setVisible(true);
}
......
......@@ -46,6 +46,8 @@ import java.util.List;
public class JBToolkit extends JFrame implements ActionListener, ItemListener, ListSelectionListener {
public final static String EDITED = "[EDITED] ";
public final static String GOLD_MISSING = "MISSING";
private final static String WHITE_STAR = "\u2606";
private final static String BLACK_STAR = "\u2605";
private String str_frameTitle;
private String str_userID;
// dataset[0] = resource, dataset[1] = directory-paths
......@@ -54,7 +56,7 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L
private String str_annFile;
// Treeview: top-pane
private JButton bt_prev, bt_next, buttonTreeEdit, buttonRemoveAnnotation, buttonAddAnnotation;
private JButton bt_prev, bt_next, buttonTreeEdit, buttonRemoveAnnotation, buttonAddAnnotation, buttonBookmark;
private JComboBox<String> comboJump;
private JTextField tf_annotator;
private JTextArea ta_context;
......@@ -156,7 +158,7 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L
bt_next = new JButton("Next");
bt_next.addActionListener(this);
checkboxApprove = new JCheckBox("Approve annotation");
checkboxApprove = new JCheckBox("Approve");
checkboxApprove.addActionListener(this);
checkboxApprove.setToolTipText("Check this box to approve the annotation \neven if no changes were made");
......@@ -173,6 +175,12 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L
comboJump.addItemListener(this);
comboJump.setFocusable(false);
buttonBookmark = new JButton(WHITE_STAR);
buttonBookmark.setPreferredSize(new Dimension(35, 10));
buttonBookmark.setMargin(new Insets(1,1,1,1));
buttonBookmark.addActionListener(this);
buttonBookmark.setFocusable(false);
tf_annotator = new JTextField(str_userID);
tf_annotator.setEditable(false);
tf_annotator.setFocusable(false);
......@@ -213,26 +221,27 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L
top1.add(bt_prev, c);
c.gridx = 1;
c.gridy = 0;
c.weightx = .5;
top1.add(bt_next, c);
c.gridx = 2;
c.gridy = 0;
top1.add(checkboxApprove);
c.gridx = 3;
c.gridy = 0;
c.weightx = .7;
c.fill = GridBagConstraints.BOTH;
c.insets = new Insets(0,5,0,5);
top1.add(tf_annotator, c);
c.gridx = 4;
c.gridy = 0;
c.weightx = .5;
c.insets = new Insets(0,0,0,0);
top1.add(comboJump, c);
c.gridx = 5;
c.weightx = 0;
top1.add(buttonBookmark, c);
top.add(top1, BorderLayout.NORTH);
if (isGold()) {
......@@ -354,6 +363,7 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L
else if (e.getSource() == mbar.helpAbout) menuHelpAbout();
else if (e.getSource() == buttonRemoveAnnotation) actionButtonRemoveAnnotation();
else if (e.getSource() == buttonAddAnnotation) actionButtonAddAnnotation();
else if (e.getSource() == buttonBookmark) actionButtonBookmark();
menuArgumentArg(e);
menuArgumentFunc(e);
}
......@@ -435,6 +445,9 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L
if (corpus.getCurrentAnnotationIndex() == 0)
bt_prev.setEnabled(false);
else bt_prev.setEnabled(true);
if (corpus.isBookmarked()) buttonBookmark.setText(BLACK_STAR);
else buttonBookmark.setText(WHITE_STAR);
}
private void updateGoldList() {
......@@ -492,6 +505,21 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L
return max;
}
private void actionButtonBookmark() {
// If there is a bookmark, remove it
if (buttonBookmark.getText().equals(BLACK_STAR)) {
corpus.removeBookmark();
buttonBookmark.setText(WHITE_STAR);
}
else {
corpus.addBookmark();
buttonBookmark.setText(BLACK_STAR);
}
// Mark that the content has changed
if (!getTitle().startsWith(EDITED))
setTitle(JBToolkit.EDITED + getTitle());
}
private void actionButtonTreeEdit() {
new JBTreeEditPanel(this, corpus.getCurrentAnnotation());
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment