Commit 5a32133f authored by Christos Christodoulopoulos's avatar Christos Christodoulopoulos
Browse files

Added bookmarks window

Allows for clickable presentation of bookmarks
parent ea49001f
No preview for this file type
package jubilee.awt;
import jubilee.toolkit.JBToolkit;
import javax.swing.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Map;
/**
* Displays all the bookmarks added by the user and allows them to double-click and locate the relevant annotation.
*
* @author Christos Christodoulopoulos
*/
public class JDCBookmarksFrame extends JFrame {
private JList<String> bookmarksList;
private DefaultListModel<String> bookmarks;
private JBToolkit parent;
public JDCBookmarksFrame(JBToolkit parent, Map<String, String> bookmarksText) {
super("Bookmarks");
this.parent = parent;
this.bookmarks = new DefaultListModel<String>();
for (String bk : bookmarksText.keySet())
this.bookmarks.addElement(bk + "\t" + bookmarksText.get(bk));
this.bookmarksList = new JList<String>(bookmarks);
this.bookmarksList.addMouseListener(doubleClickListener);
add(new JScrollPane(bookmarksList));
setBounds(20, 20, 700, 700);
setVisible(true);
}
MouseAdapter doubleClickListener = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
String indexStr = bookmarksList.getSelectedValue().split("\t")[0];
int index = Integer.parseInt(indexStr.split(":")[0]);
int predIndex = Integer.parseInt(indexStr.split(":")[1]);
parent.goToAnnotation(index, predIndex);
} else super.mouseClicked(e);
}
};
}
......@@ -145,7 +145,7 @@ public class JBCorpus {
if (new File(bookmarksFile).exists()) {
in = new BufferedReader(new InputStreamReader(new FileInputStream(bookmarksFile)));
while ((line = in.readLine()) != null) {
String[] parts = line.split("\\s+");
String[] parts = line.split("#");
bookmarks.put(parts[0], parts[1]);
}
}
......@@ -175,7 +175,7 @@ public class JBCorpus {
out = new FileWriter(file + bookmarksFileExt);
for (String bookmark : bookmarks.keySet()) {
out.write(bookmark + "\t" + bookmarks.get(bookmark) + "\n");
out.write(bookmark + "#" + bookmarks.get(bookmark) + System.lineSeparator());
}
out.close();
}
......@@ -344,4 +344,8 @@ public class JBCorpus {
JBDataStructure annotation = getCurrentAnnotation();
return annotation.getIndexInContext() + ":" + annotation.getPredicateIndex();
}
public Map<String, String> getBookmarks() {
return bookmarks;
}
}
......@@ -42,6 +42,7 @@ public class JBMenuBar extends JMenuBar {
JMenuItem fileOpen, fileSave, fileSaveAs, fileQuit;
JCheckBoxMenuItem shownIncrementalIDs, approveChanges;
JMenuItem showBookmarks;
JMenuItem tbPrev, tbNext, tbJump, tbView;
JMenuItem fsPrev, fsNext, fsViewExample, fsViewArgument, fsViewRolesetComment;
JMenuItem[] argArgs, argFunc;
......@@ -131,6 +132,9 @@ public class JBMenuBar extends JMenuBar {
shownIncrementalIDs.addActionListener(jbtk);
mView.add(shownIncrementalIDs);
showBookmarks = getJMenuItem("Show Bookmarks", KeyEvent.VK_B, KeyEvent.VK_B, menuShortcutKeyMask);
mView.add(showBookmarks);
add(mView);
}
......
......@@ -23,6 +23,8 @@
*/
package jubilee.toolkit;
import jubilee.agreement.AgreementCalculator;
import jubilee.awt.JDCBookmarksFrame;
import jubilee.awt.JDCFileDialog;
import jubilee.datastructure.JBCorpus;
import jubilee.datastructure.JBDataStructure;
......@@ -328,6 +330,7 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L
if (isNewTask) {
corpus = new JBCorpus(moreCorpora);
}
AgreementCalculator.corpusAgreement(moreCorpora[0], moreCorpora[1]);
}
framesetPanel.setCorpus(corpus);
......@@ -348,6 +351,7 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L
else if (e.getSource() == mbar.fileSaveAs) menuFileSaveAs();
else if (e.getSource() == mbar.fileQuit) System.exit(0);
else if (e.getSource() == mbar.shownIncrementalIDs) toggleShowIDs();
else if (e.getSource() == mbar.showBookmarks) showBookmarks();
else if (e.getSource() == mbar.approveChanges) checkboxApprove.setSelected(mbar.approveChanges.isSelected());
else if (e.getSource() == mbar.tbPrev || e.getSource() == bt_prev) actionBtPrev();
else if (e.getSource() == mbar.tbNext || e.getSource() == bt_next) actionBtNext();
......@@ -654,6 +658,10 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L
comboJump.setSelectedIndex(corpus.getLastEditIndex());
}
private void showBookmarks() {
new JDCBookmarksFrame(this, corpus.getBookmarks());
}
// ------------------ Menu-Treebank Action ------------------
private void actionBtPrev() {
......@@ -703,12 +711,7 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L
int index = Integer.parseInt(str);
if (0 <= index && index <= maxIndex) {
for (int i = 0; i < corpus.getSize(); i++) {
if (index == corpus.getAnnotation(i).getIndexInContext()) {
comboJump.setSelectedIndex(i);
return;
}
}
if (goToAnnotation(index, -1)) return;
JOptionPane.showMessageDialog(null,
"Utterance " + index + " does not contain any SRL annotations",
"Error",
......@@ -722,7 +725,23 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L
JOptionPane.ERROR_MESSAGE);
}
// ------------------ Menu-Argument Action ------------------
public boolean goToAnnotation(int index, int predIndex) {
for (int i = 0; i < corpus.getSize(); i++) {
if (index == corpus.getAnnotation(i).getIndexInContext()) {
if (predIndex > 0 && predIndex == corpus.getAnnotation(i).getPredicateIndex()) {
comboJump.setSelectedIndex(i);
return true;
}
else if (predIndex < 0) {
comboJump.setSelectedIndex(i);
return true;
}
}
}
return false;
}
// ------------------ Menu-Argument Action ------------------
private boolean menuArgumentArg(ActionEvent e) {
for (int i=0; i<mbar.argArgs.length; i++) {
......
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