Пример #1
0
 protected void initLocalData() {
   docTableModel = new DocumentTableModel();
   try {
     documentsLoadedCount = Gate.getCreoleRegister().getAllInstances("gate.Document").size();
   } catch (GateException exception) {
     exception.printStackTrace();
   }
 }
Пример #2
0
 public void actionPerformed(ActionEvent e) {
   List<Resource> loadedDocuments;
   try {
     // get all the documents loaded in the system
     loadedDocuments = Gate.getCreoleRegister().getAllInstances("gate.Document");
   } catch (GateException ge) {
     // gate.Document is not registered in creole.xml....what is!?
     throw new GateRuntimeException(
         "gate.Document is not registered in the creole register!\n"
             + "Something must be terribly wrong...take a vacation!");
   }
   Vector<String> docNames = new Vector<String>();
   for (Resource loadedDocument : new ArrayList<Resource>(loadedDocuments)) {
     if (corpus.contains(loadedDocument)) {
       loadedDocuments.remove(loadedDocument);
     } else {
       docNames.add(loadedDocument.getName());
     }
   }
   JList docList = new JList(docNames);
   docList.getSelectionModel().setSelectionInterval(0, docNames.size() - 1);
   docList.setCellRenderer(renderer);
   final JOptionPane optionPane =
       new JOptionPane(
           new JScrollPane(docList), JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
   final JDialog dialog =
       optionPane.createDialog(CorpusEditor.this, "Add document(s) to this corpus");
   docList.addMouseListener(
       new MouseAdapter() {
         public void mouseClicked(MouseEvent e) {
           if (e.getClickCount() == 2) {
             optionPane.setValue(JOptionPane.OK_OPTION);
             dialog.dispose();
           }
         }
       });
   dialog.setVisible(true);
   if (optionPane.getValue().equals(JOptionPane.OK_OPTION)) {
     int[] selectedIndices = docList.getSelectedIndices();
     for (int selectedIndice : selectedIndices) {
       corpus.add((Document) loadedDocuments.get(selectedIndice));
     }
   }
   changeMessage();
 }
Пример #3
0
  protected void initListeners() {

    // mouse double-click to open the document
    // context menu to get the actions for the selection
    docTable.addMouseListener(
        new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            processMouseEvent(e);
          }

          public void mousePressed(MouseEvent e) {
            if (e.isPopupTrigger()) {
              processMouseEvent(e);
            }
          }

          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() {
          public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
              openDocumentsAction.actionPerformed(null);
            }
          }
        });

    docTable
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {
              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() {
              public void resourceLoaded(CreoleEvent e) {
                if (e.getResource() instanceof Document) {
                  documentsLoadedCount++;
                  changeMessage();
                }
              }

              public void resourceUnloaded(CreoleEvent e) {
                if (e.getResource() instanceof Document) {
                  documentsLoadedCount--;
                  changeMessage();
                }
              }

              public void datastoreOpened(CreoleEvent e) {
                /* do nothing */
              }

              public void datastoreCreated(CreoleEvent e) {
                /* do nothing */
              }

              public void datastoreClosed(CreoleEvent e) {
                /* do nothing */
              }

              public void resourceRenamed(Resource resource, String oldName, String newName) {
                /* do nothing */
              }
            });
  }