Example #1
0
    public ClientsPanel() {
      super(new BorderLayout());
      lstClients = new JList();
      lstClients.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
      lstClients.setCellRenderer(
          new DefaultListCellRenderer() {
            public Component getListCellRendererComponent(
                JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
              EditorClient c = (EditorClient) value;
              JLabel label = new JLabel(c.getName());

              if (c.isPresent()) label.setForeground(MyColors.getMainColor(c.getColorCode()));
              else label.setForeground(Color.GRAY);

              if (isSelected) label.setBackground(lstClients.getSelectionBackground());

              return label;
            }
          });

      lstClients.addMouseListener(
          new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
              if (EditorServer_Debug) System.out.println(" mouseClicked ");
              int ndx = lstClients.locationToIndex(new Point(e.getX(), e.getY()));
              if (ndx > -1 && ndx < lstClients.getModel().getSize())
                lstClients.setSelectedIndex(ndx);
              else {
                if (EditorServer_Debug) System.out.println(" invalid mouse click on the JList");
              }
            }
          });

      lstClients.addListSelectionListener(
          new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e) {
              EditorClient c = (EditorClient) lstClients.getSelectedValue();
              currClient = c;
              updateActionTableFor(currClient);
            }
          });

      tblActions = new JTable(getClearTableModel());

      add(new JScrollPane(lstClients), BorderLayout.WEST);
      add(new JScrollPane(tblActions), BorderLayout.CENTER);
    }
Example #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();
 }