use of gate.event.CreoleListener in project gate-core by GateNLP.
the class AnnotationEditor method initData.
protected void initData() {
schemasByType = new HashMap<String, AnnotationSchema>();
java.util.List<LanguageResource> schemas = Gate.getCreoleRegister().getLrInstances("gate.creole.AnnotationSchema");
for (Iterator<LanguageResource> schIter = schemas.iterator(); schIter.hasNext(); ) {
AnnotationSchema aSchema = (AnnotationSchema) schIter.next();
schemasByType.put(aSchema.getAnnotationName(), aSchema);
}
CreoleListener creoleListener = new CreoleListener() {
@Override
public void resourceLoaded(CreoleEvent e) {
Resource newResource = e.getResource();
if (newResource instanceof AnnotationSchema) {
AnnotationSchema aSchema = (AnnotationSchema) newResource;
schemasByType.put(aSchema.getAnnotationName(), aSchema);
}
}
@Override
public void resourceUnloaded(CreoleEvent e) {
Resource newResource = e.getResource();
if (newResource instanceof AnnotationSchema) {
AnnotationSchema aSchema = (AnnotationSchema) newResource;
if (schemasByType.containsValue(aSchema)) {
schemasByType.remove(aSchema.getAnnotationName());
}
}
}
@Override
public void datastoreOpened(CreoleEvent e) {
}
@Override
public void datastoreCreated(CreoleEvent e) {
}
@Override
public void datastoreClosed(CreoleEvent e) {
}
@Override
public void resourceRenamed(Resource resource, String oldName, String newName) {
}
};
Gate.getCreoleRegister().addCreoleListener(creoleListener);
}
use of gate.event.CreoleListener in project gate-core by GateNLP.
the class CorpusEditor method initListeners.
protected void initListeners() {
// mouse double-click to open the document
// context menu to get the actions for the selection
docTable.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
processMouseEvent(e);
}
@Override
public void mousePressed(MouseEvent e) {
if (e.isPopupTrigger()) {
processMouseEvent(e);
}
}
@Override
public void mouseReleased(MouseEvent e) {
if (e.isPopupTrigger()) {
processMouseEvent(e);
}
}
private void processMouseEvent(MouseEvent e) {
int row = docTable.rowAtPoint(e.getPoint());
if (row == -1) {
return;
}
if (e.isPopupTrigger()) {
// context menu
if (!docTable.isRowSelected(row)) {
// if right click outside the selection then reset selection
docTable.getSelectionModel().setSelectionInterval(row, row);
}
JPopupMenu popup = new XJPopupMenu();
popup.add(openDocumentsAction);
popup.add(removeDocumentsAction);
popup.show(docTable, e.getPoint().x, e.getPoint().y);
} else if (e.getID() == MouseEvent.MOUSE_CLICKED && e.getClickCount() == 2) {
// open document on double-click
openDocumentsAction.actionPerformed(null);
}
}
});
// Enter key opens the selected documents
docTable.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
openDocumentsAction.actionPerformed(null);
}
}
});
docTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
// enable/disable buttons according to the selection
removeDocumentsAction.setEnabled(docTable.getSelectedRowCount() > 0);
openDocumentsAction.setEnabled(docTable.getSelectedRowCount() > 0);
moveUpAction.setEnabled(docTable.getSelectedRowCount() > 0 && !docTable.isRowSelected(0));
moveDownAction.setEnabled(docTable.getSelectedRowCount() > 0 && !docTable.isRowSelected(docTable.getRowCount() - 1));
}
});
Gate.getCreoleRegister().addCreoleListener(new CreoleListener() {
@Override
public void resourceLoaded(CreoleEvent e) {
if (e.getResource() instanceof Document) {
documentsLoadedCount++;
changeMessage();
}
}
@Override
public void resourceUnloaded(CreoleEvent e) {
if (e.getResource() instanceof Document) {
documentsLoadedCount--;
changeMessage();
}
}
@Override
public void datastoreOpened(CreoleEvent e) {
/* do nothing */
}
@Override
public void datastoreCreated(CreoleEvent e) {
/* do nothing */
}
@Override
public void datastoreClosed(CreoleEvent e) {
/* do nothing */
}
@Override
public void resourceRenamed(Resource resource, String oldName, String newName) {
/* do nothing */
}
});
}
Aggregations