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(); }
public void removeMessages(Message[] removedMessages) { try { // Translate the array of removed Message instances into a list of all the row indexes to be // removed from the model. // Assumes the list of removed messages is small. ArrayList<Integer> deadIndexes = new ArrayList<Integer>(); for (Message message : removedMessages) { int deadIndex = messages.indexOf(message); if (deadIndex != -1) { deadIndexes.add(deadIndex); } } // Actually remove the rows, notifying the listeners as we go (rather than bother trying to // coalesce). for (int i = deadIndexes.size() - 1; i >= 0; --i) { int deadIndex = deadIndexes.get(i); messages.remove(deadIndex); fireTableRowsDeleted(deadIndex, deadIndex); } } catch (Exception ex) { ex.printStackTrace(); } }