package floobits.dialogs;

import javax.swing.*;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableCellRenderer;
import java.awt.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;


public class FollowUserForm {
    private JPanel contentPanel;
    private JTable userTable;

    private class UserListModel extends AbstractTableModel {

        private HashMap<String, Boolean> data;
        private List<String> order = new ArrayList<String>();

        public void setData(HashMap<String, Boolean> data) {
            this.data = data;
            order.addAll(data.keySet());
        }

        @Override
        public int getRowCount() {
            return data.size();
        }

        @Override
        public int getColumnCount() {
            return 1;
        }

        public Class getColumnClass(int c) {
            return getValueAt(0, c).getClass();
        }

        @Override
        public Object getValueAt(int rowIndex, int columnIndex) {
            String username = order.get(rowIndex);
            return new FollowUserData(username, data.get(username));
        }
    }

    public class FollowUserData {
        public String username;
        public Boolean following;
        public FollowUserData(String username, Boolean following) {
            this.username = username;
            this.following = following;
        }
    }

    private class CheckboxRenderer extends JCheckBox implements TableCellRenderer {

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            FollowUserData data = (FollowUserData) value;
            this.setText(data.username);
            this.setSelected(data.following);
            return this;
        }
    }

    public void setUsers(HashMap<String, Boolean> usersToChoose) {
        UserListModel tableModel = new UserListModel();
        userTable.setDefaultRenderer(FollowUserData.class, new CheckboxRenderer());
        tableModel.setData(usersToChoose);
        userTable.setModel(tableModel);
    }


    public JComponent getContentPanel() {
        return contentPanel;
    }
}

@@ -91,71 +91,8 @@
 el;%0A
-import javax.swing.table.TableCellRenderer;%0Aimport java.awt.*;%0A
 impo
@@ -671,34 +671,16 @@
      %7D%0A%0A
-        @Override%0A
         
@@ -682,27 +682,30 @@
      public 
+Str
 in
-t
+g
  getColumnCo
@@ -706,48 +706,116 @@
 lumn
-Count() %7B%0A            return 1;%0A
+Name(int col) %7B%0A            if (col == 1) %7B%0A                return %22User with edit permissions%22;%0A   
         
 %7D%0A%0A 
@@ -802,34 +802,101 @@
 ns%22;%0A           
+ 
 %7D%0A
+            return %22Follow changes%22;%0A        %7D%0A%0A%0A        @Override
 %0A        public 
@@ -895,21 +895,19 @@
  public 
-Class
+int
  getColu
@@ -913,18 +913,13 @@
 umnC
-lass(int c
+ount(
 ) %7B%0A
@@ -941,35 +941,9 @@
 urn 
-getValueAt(0, c).getClass()
+2
 ;%0A  
@@ -1102,43 +1102,54 @@
     
-return new FollowUserData(username,
+if (columnIndex == 0) %7B%0A                return
  dat
@@ -1163,17 +1163,16 @@
 sername)
-)
 ;%0A      
@@ -1177,220 +1177,134 @@
     
-%7D%0A
     %7D%0A
-%0A
     
-public class FollowUserData %7B%0A        public String username;%0A        public Boolean following;%0A        public FollowUserData(String username, Boolean following) %7B%0A            this.username = usernam
+        return username;%0A        %7D%0A%0A        public boolean isCellEditable(int row, int col) %7B%0A            return tru
 e;%0A 
@@ -1314,279 +1314,176 @@
     
+%7D%0A%0A
     
-this.following = following;%0A  
+    public Class getColumnClass(int c) %7B%0A
       
-%7D%0A
     
-%7D%0A%0A    private class CheckboxRenderer extends JCheckBox implements TableCellRenderer %7B%0A%0A        @Override%0A        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus
+  return getValueAt(0, c).getClass();%0A        %7D%0A%0A        @Override%0A        public void setValueAt(Object value
 , in
@@ -1496,19 +1496,16 @@
  int col
-umn
 ) %7B%0A    
@@ -1516,52 +1516,40 @@
     
-FollowUserData data = (FollowUserData) value
+String username = order.get(row)
 ;%0A  
@@ -1562,34 +1562,25 @@
     
-this.setText(
 data.
+put(
 username
 );%0A 
@@ -1579,80 +1579,70 @@
 name
-);%0A            this.setSelected(data.following);%0A            return this
+, (Boolean) value);%0A            fireTableCellUpdated(row, col)
 ;%0A  
@@ -1783,92 +1783,8 @@
 ();%0A
-        userTable.setDefaultRenderer(FollowUserData.class, new CheckboxRenderer());%0A
     

Make checkbox selectable. #186