Commit 9939f936 authored by Christos Christodoulopoulos's avatar Christos Christodoulopoulos
Browse files

Context list is not clickable

Closes #3
parent e77a9fd8
No preview for this file type
......@@ -14,16 +14,25 @@ import java.util.Map;
*/
public class JDCBookmarksFrame extends JFrame {
private JList<String> bookmarksList;
private DefaultListModel<String> bookmarks;
private JBToolkit parent;
public JDCBookmarksFrame(JBToolkit parent, Map<String, String> bookmarksText) {
public JDCBookmarksFrame(final JBToolkit parent, Map<String, String> bookmarksText) {
super("Bookmarks");
this.parent = parent;
this.bookmarks = new DefaultListModel<String>();
DefaultListModel<String> bookmarks = new DefaultListModel<>();
for (String bk : bookmarksText.keySet())
this.bookmarks.addElement(bk + "\t" + bookmarksText.get(bk));
this.bookmarksList = new JList<String>(bookmarks);
bookmarks.addElement(bk + "\t" + bookmarksText.get(bk));
this.bookmarksList = new JList<>(bookmarks);
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);
}
};
this.bookmarksList.addMouseListener(doubleClickListener);
add(new JScrollPane(bookmarksList));
......@@ -31,16 +40,4 @@ public class JDCBookmarksFrame extends JFrame {
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);
}
};
}
package jubilee.toolkit;
import jubilee.datastructure.JBCorpus;
import javax.swing.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.List;
class JBContextPanel extends JScrollPane {
private JList<String> contextList = new JList<>();
private int maxContext = 0;
JBContextPanel(final JBToolkit parent) {
MouseAdapter doubleClickListener = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
String indexStr = contextList.getSelectedValue().split(" ")[0];
if (indexStr.equals("##")) return;
int index = Integer.parseInt(indexStr);
parent.goToAnnotation(index, -1);
} else super.mouseClicked(e);
}
};
contextList.addMouseListener(doubleClickListener);
contextList.setVisibleRowCount(13);
viewport.setView(contextList);
}
void buildContextList(JBCorpus corpus) {
List<String> contexts = corpus.getContexts();
String[] listData = new String[contexts.size()];
for (int contextInd = 0; contextInd < contexts.size(); contextInd++) {
String context = contexts.get(contextInd);
if (corpus.getAnnotationsFromContext(contextInd) == null)
listData[contextInd] = "## " + context + "\n";
else listData[contextInd] = context;
}
contextList.setListData(listData);
maxContext = contexts.size();
}
public void setPosition(int index) {
contextList.setSelectedIndex(index);
contextList.ensureIndexIsVisible(index + Math.min(6, maxContext - index - 1));
contextList.ensureIndexIsVisible(index - Math.min(6, index));
}
}
......@@ -35,13 +35,11 @@ import javax.swing.*;
import javax.swing.border.TitledBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultHighlighter;
import javax.swing.text.Highlighter;
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@SuppressWarnings("serial")
......@@ -61,12 +59,13 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L
private JButton bt_prev, bt_next, buttonTreeEdit, buttonRemoveAnnotation, buttonAddAnnotation, buttonBookmark;
private JComboBox<String> comboJump;
private JTextField tf_annotator;
private JTextArea ta_context;
private JList<String> ls_gold;
private DefaultListModel<String> lm_gold;
private JBTreePanel tv_tree;
private JBFramesetPanel framesetPanel;
private JBContextPanel sentencePane;
private JBArgPanel argPanel;
private JBMenuBar mbar;
private JBCorpus corpus;
......@@ -187,12 +186,6 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L
tf_annotator.setEditable(false);
tf_annotator.setFocusable(false);
ta_context = new JTextArea();
ta_context.setEditable(false);
ta_context.setBackground(Color.white);
ta_context.setRows(16);
ta_context.setLineWrap(true);
tv_tree = new JBTreePanel();
framesetPanel = new JBFramesetPanel();
......@@ -258,8 +251,7 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L
}
// bottom of the treeview
JScrollPane sentencePane = new JScrollPane(ta_context);
sentencePane = new JBContextPanel(this);
sentencePane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
JPanel bottomPanel = new JPanel();
......@@ -424,26 +416,8 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L
}
// Update the context window
int bId = 0, eId = -1, bExtraId = 0, eExtraId = -1;
int indexInContext = corpus.getCurrentAnnotation().getIndexInContext();
// Set the caret position so that the highlighted text is shown in the middle
int extraLines = Math.min(indexInContext + 8, corpus.getContexts().size());
for (int i = 0; i <= extraLines; i++) {
if (i <= indexInContext) {
bId = eId + 1;
eId = ta_context.getText().indexOf("\n", bId);
}
bExtraId = eExtraId + 1;
eExtraId = ta_context.getText().indexOf("\n", bExtraId);
}
Highlighter h = ta_context.getHighlighter();
h.removeAllHighlights();
try {
h.addHighlight(bId, eId, new DefaultHighlighter.DefaultHighlightPainter(Color.YELLOW));
}
catch (BadLocationException e) {e.printStackTrace();}
ta_context.setCaretPosition(bExtraId);
sentencePane.setPosition(indexInContext);
if (corpus.getCurrentAnnotationIndex() == corpus.getSize() - 1) {
bt_next.setEnabled(false);
......@@ -601,16 +575,7 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L
}
private void buildContextWindow() {
String contextText = "";
int contextInd = 0;
for (String line : corpus.getContexts()) {
// Mark utterances that don't have SRL annotations
if (corpus.getAnnotationsFromContext(contextInd) == null)
contextText += "## " + line+"\n";
else contextText += line+"\n";
contextInd++;
}
ta_context.setText(contextText);
sentencePane.buildContextList(corpus);
}
private void buildComboBox() {
......
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