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

Context now appears in the main window (instead of the sentence text)

parent e18696a6
......@@ -23,20 +23,11 @@
*/
package jubilee.awt;
import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.List;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultHighlighter;
import javax.swing.text.Highlighter;
/**
* @author Jinho D. Choi
......@@ -59,39 +50,6 @@ public class JDCTextAreaFrame extends JFrame implements ActionListener {
setVisible(true);
}
public JDCTextAreaFrame(String title, List<String> context, int lineNum) {
super(title);
mbar = new JDCTextAreaFrameMenuBar(this);
setJMenuBar(mbar);
String contextText = "";
for (String line : context) contextText += line+"\n";
JTextArea ta = new JTextArea(contextText);
int bId = 0, eId = -1;
for (int i=0; i<=lineNum; i++)
{
bId = eId + 1;
eId = contextText.indexOf("\n", bId);
}
Highlighter h = ta.getHighlighter();
try
{
h.addHighlight(bId, eId, new DefaultHighlighter.DefaultHighlightPainter(Color.YELLOW));
}
catch (BadLocationException e) {e.printStackTrace();}
ta.setCaretPosition(bId);
add(new JScrollPane(ta), BorderLayout.CENTER);
addWindowListener(new WindowAdapt());
setBounds(20, 20, 700, 700);
setVisible(true);
}
class WindowAdapt extends WindowAdapter {
public void windowClosing(WindowEvent e) {
dispose();
......
......@@ -162,6 +162,11 @@ public class JBCorpus {
}
}
public void replaceAnnotation(int i, JBDataStructure dataStructure) {
annotations.remove(i);
annotations.add(i, dataStructure);
}
// --------------------- Getters --------------------- //
public JBDataStructure getAnnotation(int index) {
......
......@@ -40,7 +40,7 @@ public class JBMenuBar extends JMenuBar {
private JMenu mn_args;
JMenuItem fileOpen, fileSave, fileSaveAs, fileQuit;
JMenuItem tbPrev, tbNext, tbJump, tbView, tbViewContexts;
JMenuItem tbPrev, tbNext, tbJump, tbView;
JMenuItem fsPrev, fsNext, fsViewExample, fsViewArgument, fsViewRolesetComment;
JMenuItem[] argArgs, argFunc;
JMenuItem argErase;
......@@ -60,8 +60,7 @@ public class JBMenuBar extends JMenuBar {
initMenuHelp();
}
/** Called from {@link JBToolkit#initProperties(java.util.HashMap)} */
void setMenuArgTag(ArrayList<String[]> args) {
mn_args.removeAll();
argArgs = new JMenuItem[JBArgPanel.NUM_ARG+args.size()-1];
......@@ -120,13 +119,9 @@ public class JBMenuBar extends JMenuBar {
tbJump = getJMenuItem("Jump To", KeyEvent.VK_J, KeyEvent.VK_J, KeyEvent.CTRL_MASK);
mTreebank.add(tbJump);
mTreebank.addSeparator();
tbView = getJMenuItem("View Tree in Text", KeyEvent.VK_T, KeyEvent.VK_T, KeyEvent.CTRL_MASK);
tbView = getJMenuItem("Edit Tree", KeyEvent.VK_T, KeyEvent.VK_T, KeyEvent.CTRL_MASK);
mTreebank.add(tbView);
tbViewContexts = getJMenuItem("View Contexts", KeyEvent.VK_O, KeyEvent.VK_O, KeyEvent.CTRL_MASK+KeyEvent.SHIFT_MASK);
mTreebank.add(tbViewContexts);
add(mTreebank);
}
......
......@@ -23,7 +23,6 @@
*/
package jubilee.toolkit;
import com.sun.codemodel.internal.JOp;
import jubilee.awt.JDCFileDialog;
import jubilee.awt.JDCTextAreaFrame;
import jubilee.datastructure.JBCorpus;
......@@ -35,6 +34,9 @@ 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;
......@@ -55,7 +57,7 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L
private JButton bt_prev, bt_next, buttonTreeEdit, buttonRemoveAnnotation, buttonAddAnnotation;
private JComboBox<String> comboJump;
private JTextField tf_annotator;
private JTextArea ta_sentence;
private JTextArea ta_context;
private JList<String> ls_gold;
private DefaultListModel<String> lm_gold;
private JBTreePanel tv_tree;
......@@ -140,11 +142,11 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L
tf_annotator.setEditable(false);
tf_annotator.setFocusable(false);
ta_sentence = new JTextArea();
ta_sentence.setEditable(false);
ta_sentence.setBackground(Color.white);
ta_sentence.setRows(4);
ta_sentence.setLineWrap(true);
ta_context = new JTextArea();
ta_context.setEditable(false);
ta_context.setBackground(Color.white);
ta_context.setRows(15);
ta_context.setLineWrap(true);
tv_tree = new JBTreePanel();
......@@ -186,7 +188,8 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L
}
// bottom of the treeview
JScrollPane sentencePane = new JScrollPane(ta_sentence);
JScrollPane sentencePane = new JScrollPane(ta_context);
sentencePane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
JPanel bottomPanel = new JPanel();
......@@ -264,6 +267,11 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L
}
framesetPanel.setCorpus(corpus);
// Create the context window
String contextText = "";
for (String line : corpus.getContexts()) contextText += line+"\n";
ta_context.setText(contextText);
comboJump.removeAllItems();
for (int i = 0; i < corpus.getSize(); i++) {
......@@ -285,8 +293,7 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L
else if (e.getSource() == mbar.tbPrev || e.getSource() == bt_prev) actionBtPrev();
else if (e.getSource() == mbar.tbNext || e.getSource() == bt_next) actionBtNext();
else if (e.getSource() == mbar.tbJump) menuTbJump();
else if (e.getSource() == mbar.tbView) menuTbView();
else if (e.getSource() == mbar.tbViewContexts) menuTbViewContexts();
else if (e.getSource() == mbar.tbView || e.getSource() == buttonTreeEdit) actionButtonTreeEdit();
else if (e.getSource() == mbar.fsPrev) framesetPanel.prevRoleset();
else if (e.getSource() == mbar.fsNext) framesetPanel.nextRoleset();
else if (e.getSource() == mbar.fsViewExample) framesetPanel.showExample();
......@@ -294,7 +301,6 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L
else if (e.getSource() == mbar.fsViewRolesetComment) framesetPanel.viewRolesetComment();
else if (e.getSource() == mbar.argErase) argPanel.updateArg(e.getActionCommand());
else if (e.getSource() == mbar.helpAbout) menuHelpAbout();
else if (e.getSource() == buttonTreeEdit) actionButtonTreeEdit();
else if (e.getSource() == buttonRemoveAnnotation) actionButtonRemoveAnnotation();
else if (e.getSource() == buttonAddAnnotation) actionButtonAddAnnotation();
menuArgumentArg(e);
......@@ -320,7 +326,6 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L
public void updateAll() {
JBDataStructure annotation = corpus.getCurrentAnnotation();
tv_tree.setAnnotation(annotation);
ta_sentence.setText(annotation.getTbTree().getSentence());
framesetPanel.updateFrameset(annotation.getType(), annotation.getRoleset());
String annotator = annotation.getAnnotator();
tf_annotator.setText(annotator);
......@@ -329,6 +334,21 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L
else if (annotator.equals("babySRL"))
tf_annotator.setBackground(Color.GREEN);
else tf_annotator.setBackground(Color.LIGHT_GRAY);
// Update the context window
int bId = 0, eId = -1;
for (int i=0; i<=corpus.getCurrentAnnotation().getIndexInContext(); i++) {
bId = eId + 1;
eId = ta_context.getText().indexOf("\n", bId);
}
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(bId);
}
private void updateGoldList() {
......@@ -387,7 +407,6 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L
}
private void actionButtonAddAnnotation() {
boolean delete = false;
String response = JOptionPane.showInputDialog(null, "This will add a new annotation by copying " +
"the existing one.\nPlease enter the predicate lemma of the new annotation", "Add annotation",
JOptionPane.QUESTION_MESSAGE);
......@@ -484,15 +503,6 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L
}
}
private void menuTbView() {
new JDCTextAreaFrame("Text View", tv_tree.getTree().toTextTreeCompact());
}
private void menuTbViewContexts() {
JBDataStructure dataStructure = corpus.getCurrentAnnotation();
new JDCTextAreaFrame("Contexts", corpus.getContexts(), dataStructure.getIndexInContext());
}
// ------------------ Menu-Argument Action ------------------
private boolean menuArgumentArg(ActionEvent e) {
......
......@@ -32,12 +32,9 @@ import javax.swing.UnsupportedLookAndFeelException;
* @author Christos Christodoulopoulos
* @since 5/11/2014
*/
public class Jubilee
{
static public void main(String[] args)
{
try
{
public class Jubilee {
static public void main(String[] args) {
try {
// Set cross-platform Java L&F (also called "Metal")
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
}
......@@ -47,15 +44,14 @@ public class Jubilee
catch (IllegalAccessException e) {e.printStackTrace();}
String usage = "Usage: java -jar jubilee.jar -u <userId> [-m <max-annotations=2> -s <system-folder=system>]";
String title = "Jubilee 3.00";
String title = "Jubilee 3.10";
String userId = null;
int maxAnn = 2;
String sysDir = "system" + File.separator;
if (args.length == 0 || args.length % 2 != 0) {System.err.println(usage); return;}
for (int i=0; i<args.length; i+=2)
{
for (int i=0; i<args.length; i+=2) {
String option = args[i];
String value = args[i+1];
......
......@@ -400,4 +400,27 @@ public class TBTree {
public TBTree copy() {
return new TBTree(mb_head.copy());
}
public void fixArgSpan() {
if (toPropbank().contains("*")) return;
fixArgSpanInternal(mb_head);
}
private void fixArgSpanInternal(TBNode node) {
if (node.getArg() != null && node.getParent() != null) {
if (getWordsAux(node, " ") != null && getWordsAux(node.getParent(), " ") != null) {
if (getWordsAux(node, " ").equals(getWordsAux(node.getParent(), " ")) && node.getArg().startsWith("A")) {
String loc = node.getLoc();
int splitPoint = loc.lastIndexOf(":");
String token = loc.substring(0, splitPoint);
int height = Integer.parseInt(loc.substring(splitPoint+1)) + 1;
node.getParent().setLocArg(token+":"+height, node.getArg());
node.setLocArg(null, null);
}
}
}
if (node.getChildren() != null)
for (TBNode child : node.getChildren()) fixArgSpanInternal(child);
}
}
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