Commit 0681acdc authored by Christos Christodoulopoulos's avatar Christos Christodoulopoulos
Browse files

Added ability to move annotation labels when editing trees

Added double-click listener to the start screen lists.
parent a7d9737b
......@@ -158,6 +158,29 @@ public class JBDataStructure {
}
}
public void setTree(String treeString, int offset, int newWordIndex) throws Exception {
TBTree newTree = readTBTree(treeString);
// Add the propbank annotation to the new tree including the new indices
String oldPropbankLabels[] = tbTree.toPropbank().split("\\s+");
String newLabels = "";
for (String label : oldPropbankLabels) {
int index = Integer.parseInt(label.split(":")[0]);
if (index >= newWordIndex)
index += offset;
newLabels += index + ":" + label.split(":")[1] + " ";
}
readPropbankLabels(newLabels, newTree);
if (!tbTree.equals(newTree)) {
tbTree = newTree;
hasChanged(true);
}
else {
JOptionPane.showMessageDialog(null, "No changes detected", "Information",
JOptionPane.INFORMATION_MESSAGE);
}
}
public void setRoleset(String roleset) {
if (!this.roleset.equals(roleset)) {
this.roleset = roleset;
......
......@@ -97,12 +97,13 @@ public class JBOpenDialog extends JDialog implements ActionListener, ItemListene
lm_newTask = new DefaultListModel<String>();
ls_newTask = new JList<String>(lm_newTask);
ls_newTask.setBorder(new TitledBorder("New Tasks"));
ls_newTask.addListSelectionListener(this);
lm_myTask = new DefaultListModel<String>();
ls_myTask = new JList<String>(lm_myTask);
ls_myTask.setBorder(new TitledBorder("My Tasks"));
ls_myTask.addListSelectionListener(this);
addListListeners();
initJList();
// button: cancel, enter
......@@ -119,6 +120,21 @@ public class JBOpenDialog extends JDialog implements ActionListener, ItemListene
return map;
}
private void addListListeners() {
MouseAdapter doubleClickListener = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
actionBtEnter();
} else super.mouseClicked(e);
}
};
ls_newTask.addListSelectionListener(this);
ls_newTask.addMouseListener(doubleClickListener);
ls_myTask.addListSelectionListener(this);
ls_myTask.addMouseListener(doubleClickListener);
}
private JButton getJButton(Container cp, String title) {
JButton bt = new JButton(title);
......
......@@ -18,17 +18,19 @@ public class JBTreeEditPanel extends JFrame implements ActionListener {
private final JTextArea textArea;
private JButton buttonApply, buttonCancel;
private JBDataStructure annotation;
private JTextField fieldWordsNum, fieldWordPos;
JBToolkit parent;
public JBTreeEditPanel(JBToolkit parent, JBDataStructure annotation) {
super("Syntax tree");
super("Syntax tree edit");
this.annotation = annotation;
this.parent = parent;
textArea = new JTextArea(annotation.getTbTree().toTextTree());
textArea.setMargin(new Insets(10, 10, 10, 10));
textArea.setPreferredSize(new Dimension(498, 260));
buttonApply = new JButton("Apply");
buttonApply.addActionListener(this);
......@@ -36,13 +38,30 @@ public class JBTreeEditPanel extends JFrame implements ActionListener {
buttonCancel.addActionListener(this);
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new GridLayout(0, 2));
buttonPanel.setLayout(new GridLayout(0, 2, 10, 0));
buttonPanel.add(buttonApply);
buttonPanel.add(buttonCancel);
setLayout(new BorderLayout());
add(new JScrollPane(textArea), BorderLayout.CENTER);
add(buttonPanel, BorderLayout.SOUTH);
String sentStr = annotation.getTbTree().getSentence();
String sentLabelStr = "<html>Sentence: <i>" + sentStr + "</i></html>";
JLabel sentLabel = new JLabel(sentLabelStr);
fieldWordsNum = new JTextField(1);
fieldWordsNum.setPreferredSize(new Dimension(10, 20));
fieldWordPos = new JTextField(1);
JPanel addArgsPanel = new JPanel();
addArgsPanel.setLayout(new GridLayout(0, 4, 10, 0));
addArgsPanel.add(new JLabel("<html>#new words<br/>inserted</html>"));
addArgsPanel.add(fieldWordsNum);
addArgsPanel.add(new JLabel("<html>#words before<br/>new word</html>"));
addArgsPanel.add(fieldWordPos);
// Set layout and add components
setLayout(new FlowLayout());
add(new JScrollPane(textArea));
add(sentLabel);
add(addArgsPanel);
add(buttonPanel);
addWindowListener(new WindowAdapter() {
@Override
......@@ -56,17 +75,31 @@ public class JBTreeEditPanel extends JFrame implements ActionListener {
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == buttonCancel)
public void actionPerformed(ActionEvent evt) {
if (evt.getSource() == buttonCancel)
dispose();
else if (e.getSource() == buttonApply)
else if (evt.getSource() == buttonApply) {
int newWords = 0, wordPos = 0;
// Check if the user added #new words/word position
if (!fieldWordPos.getText().isEmpty() || !fieldWordsNum.getText().isEmpty()) {
try {
newWords = Integer.parseInt(fieldWordsNum.getText());
wordPos = Integer.parseInt(fieldWordPos.getText());
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(null, "Please type numbers to both fields",
"Error", JOptionPane.ERROR_MESSAGE);
return;
}
}
try {
annotation.setTree(textArea.getText());
if (newWords != 0) annotation.setTree(textArea.getText(), newWords, wordPos);
else annotation.setTree(textArea.getText());
parent.updateAll();
dispose();
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, "There was an error: \n" + ex.getMessage(), "Error",
JOptionPane.ERROR_MESSAGE);
}
}
}
}
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