Exemple #1
0
  void refreshCommunities() {
    removeAll();
    setLayout(new BorderLayout());
    String[] communityNames = myAgent.getCommunities();
    Object[][] data = new Object[communityNames.length][2];
    for (int i = 0; i < communityNames.length; i++) {
      data[i][0] = communityNames[i];
      data[i][1] = new Boolean(myAgent.connectedWith(communityNames[i]));
      // JCheckBox c = new JCheckBox(communityNames[i],myAgent.connectedWith(communityNames[i]));
      // c.addItemListener(this);
      // tmp.add(c);
    }
    // JPanel tmp = new JPanel();
    // tmp.setLayout(new GridLayout(communityNames.length,1,5,5));
    // tmp.setBorder(BorderFactory.createEmptyBorder(20,20,20,20));

    SitesTableModel sitesModel = new SitesTableModel(this, data);
    JTable table = new JTable(sitesModel);
    table.setPreferredScrollableViewportSize(new Dimension(200, 100));

    // Create the scroll pane and add the table to it.
    JScrollPane scrollPane = new JScrollPane(table);

    // Add the scroll pane to this window.
    add(scrollPane, BorderLayout.CENTER);

    add("North", new JLabel("Available communities"));
    // add("Center",tmp);
    validate();
  }
Exemple #2
0
 public void itemStateChanged(ItemEvent e) {
   Object source = e.getItemSelectable();
   if (e.getStateChange() == ItemEvent.DESELECTED) {
     myAgent.leaveCommunity(((JCheckBox) source).getText());
   } else {
     myAgent.joinCommunity(((JCheckBox) source).getText());
   }
 }
Exemple #3
0
 void communityChange(boolean b, String name) {
   if (b) myAgent.joinCommunity(name);
   else myAgent.leaveCommunity(name);
 }