Changeset 3776 in josm


Ignore:
Timestamp:
2011-01-07T00:54:21+01:00 (9 years ago)
Author:
framm
Message:

display re-licensing status in the user list, so mappers can immediately see who has agreed to the new contributor terms and who has not. code is still a little rough on error handling but should work. feedback encouraged.

Location:
trunk
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/User.java

    r3505 r3776  
    77import java.util.List;
    88import java.util.concurrent.atomic.AtomicLong;
     9import org.openstreetmap.josm.io.MirroredInputStream;
     10import java.io.InputStreamReader;
     11import java.io.BufferedReader;
    912
    1013/**
     
    2528     */
    2629    private static HashMap<Long,User> userMap = new HashMap<Long,User>();
     30    private static HashSet<Long> relicensingUsers = null;
    2731
    2832    private static long getNextLocalUid() {
     
    102106    }
    103107
     108    public static void loadRelicensingInformation() {
     109        relicensingUsers = new HashSet<Long>();
     110        try {
     111        MirroredInputStream stream = new MirroredInputStream("http://planet.openstreetmap.org/users_agreed/users_agreed.txt");
     112        InputStreamReader r;
     113        r = new InputStreamReader(stream);
     114        BufferedReader reader = new BufferedReader(r);
     115        String line;
     116        while ((line = reader.readLine()) != null) {
     117            if (line.startsWith("#")) continue;
     118            try {
     119                relicensingUsers.add(new Long(Long.parseLong(line.trim())));
     120            } catch (java.lang.NumberFormatException ex) {
     121            }
     122        }
     123        stream.close();
     124        } catch (java.io.IOException ex) {
     125        }
     126    }
     127
    104128    /** the user name */
    105129    private final HashSet<String> names = new HashSet<String>();
    106130    /** the user id */
    107131    private final long uid;
     132
     133    public static final int STATUS_UNKNOWN = 0;
     134    public static final int STATUS_AGREED = 1;
     135    public static final int STATUS_NOT_AGREED = 2;
     136    public static final int STATUS_AUTO_AGREED = 3;
     137
     138    /**
     139    */
     140    public int getRelicensingStatus() {
     141        if (uid >= 286582) return STATUS_AUTO_AGREED;
     142        if (relicensingUsers == null) return STATUS_UNKNOWN;
     143        return (relicensingUsers.contains(new Long(uid)) ? STATUS_AGREED : STATUS_NOT_AGREED);
     144    }
    108145
    109146    /**
  • trunk/src/org/openstreetmap/josm/gui/dialogs/UserListDialog.java

    r3443 r3776  
    55import static org.openstreetmap.josm.tools.I18n.trn;
    66
     7import java.awt.Component;
    78import java.awt.BorderLayout;
    89import java.awt.event.ActionEvent;
     
    2930import javax.swing.JScrollPane;
    3031import javax.swing.JTable;
     32import javax.swing.JLabel;
    3133import javax.swing.ListSelectionModel;
     34import javax.swing.table.DefaultTableCellRenderer;
     35import javax.swing.table.TableColumnModel;
    3236import javax.swing.event.ListSelectionEvent;
    3337import javax.swing.event.ListSelectionListener;
     
    4650import org.openstreetmap.josm.tools.ImageProvider;
    4751import org.openstreetmap.josm.tools.Shortcut;
     52import org.openstreetmap.josm.tools.ImageProvider;
     53import javax.swing.ImageIcon;
    4854
    4955/**
     
    6167    private SelectUsersPrimitivesAction selectionUsersPrimitivesAction;
    6268    private ShowUserInfoAction showUserInfoAction;
     69    private LoadRelicensingInformationAction loadRelicensingInformationAction;
    6370
    6471    public UserListDialog() {
     
    95102        userTable.getSelectionModel().addListSelectionListener(showUserInfoAction);
    96103        pnl.add(new SideButton(showUserInfoAction));
     104
     105        // -- load relicensing info action
     106        loadRelicensingInformationAction = new LoadRelicensingInformationAction();
     107        pnl.add(new SideButton(loadRelicensingInformationAction));
    97108        return pnl;
    98109    }
     
    104115        userTable = new JTable(model);
    105116        userTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
     117        TableColumnModel columnModel = userTable.getColumnModel();
     118        columnModel.getColumn(3).setPreferredWidth(20);
     119        columnModel.getColumn(3).setCellRenderer(new DefaultTableCellRenderer() {
     120            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
     121                final JLabel label = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
     122                label.setIcon((ImageIcon)value);
     123                label.setText("");
     124                return label;
     125            };
     126        });
    106127        pnl.add(new JScrollPane(userTable), BorderLayout.CENTER);
    107128
     
    182203    }
    183204
    184     /**
     205    /*
    185206     * Action for launching the info page of a user
    186207     */
     
    244265    }
    245266
     267    /*
     268     */
     269    class LoadRelicensingInformationAction extends AbstractAction {
     270
     271        public LoadRelicensingInformationAction() {
     272            super();
     273            putValue(NAME, tr("Load CT"));
     274            putValue(SHORT_DESCRIPTION, tr("Loads information about relicensing status from the server. Users having agreed to the new contributor terms will show a green check mark."));
     275            putValue(SMALL_ICON, ImageProvider.get("about"));
     276        }
     277
     278        @Override
     279        public void actionPerformed(ActionEvent e) {
     280            User.loadRelicensingInformation();
     281            Layer layer = Main.main.getActiveLayer();
     282            if (layer instanceof OsmDataLayer) {
     283               refresh(((OsmDataLayer)layer).data.getSelected());
     284            }
     285            setEnabled(false);
     286        }
     287    }
     288
    246289    class DoubleClickAdapter extends MouseAdapter {
    247290        @Override
     
    280323            return user.getName();
    281324        }
     325
     326        public int getRelicensingStatus() {
     327            if (user == null)
     328                return User.STATUS_UNKNOWN;
     329            return user.getRelicensingStatus();
     330        }
    282331    }
    283332
     
    288337    static class UserTableModel extends DefaultTableModel {
    289338        private ArrayList<UserInfo> data;
     339        private ImageIcon greenCheckmark;
    290340
    291341        public UserTableModel() {
    292             setColumnIdentifiers(new String[]{tr("Author"),tr("# Objects"),"%"});
     342            setColumnIdentifiers(new String[]{tr("Author"),tr("# Objects"),"%", tr("CT")});
    293343            data = new ArrayList<UserInfo>();
     344            greenCheckmark = ImageProvider.get("misc", "green_check.png");
    294345        }
    295346
     
    332383            case 1: /* count */ return info.count;
    333384            case 2: /* percent */ return NumberFormat.getPercentInstance().format(info.percent);
     385            case 3: /* relicensing status */
     386                if (info.getRelicensingStatus() == User.STATUS_AGREED) return greenCheckmark;
     387                if (info.getRelicensingStatus() == User.STATUS_AUTO_AGREED) return greenCheckmark;
     388                return null;
    334389            }
    335390            return null;
Note: See TracChangeset for help on using the changeset viewer.