Changeset 1792 in josm


Ignore:
Timestamp:
2009-07-15T17:47:09+02:00 (15 years ago)
Author:
Gubaer
Message:

fixed #2647: Relation editor: moving members should keep them in view

Location:
trunk/src/org/openstreetmap/josm/gui/dialogs/relation
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTable.java

    r1790 r1792  
    22package org.openstreetmap.josm.gui.dialogs.relation;
    33
     4import java.awt.Rectangle;
    45import java.awt.event.ActionEvent;
    56import java.awt.event.KeyEvent;
     
    1213import javax.swing.table.TableColumnModel;
    1314
    14 public class MemberTable extends JTable {
     15public class MemberTable extends JTable implements IMemberModelListener {
    1516
    1617    /**
     
    2223    public MemberTable(MemberTableModel model) {
    2324        super(model, new MemberTableColumnModel(), model.getSelectionModel());
     25        model.addMemberModelListener(this);
    2426        init();
    2527    }
     
    6567
    6668        }
     69    }
     70
     71    public void makeMemberVisible(int index) {
     72        scrollRectToVisible(
     73                getCellRect(index, 0, true)
     74        );
    6775    }
    6876
     
    126134        }
    127135    }
     136
     137
    128138}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java

    r1790 r1792  
    77import java.util.Iterator;
    88import java.util.List;
     9import java.util.concurrent.CopyOnWriteArrayList;
    910
    1011import javax.swing.DefaultListSelectionModel;
     
    2324    private ArrayList<String> memberLinkingInfo;
    2425    private DefaultListSelectionModel listSelectionModel;
     26    private CopyOnWriteArrayList<IMemberModelListener> listeners;
    2527
    2628    /**
     
    3032        members = new ArrayList<RelationMember>();
    3133        memberLinkingInfo = new ArrayList<String>();
     34        listeners = new CopyOnWriteArrayList<IMemberModelListener>();
     35    }
     36
     37    public void addMemberModelListener(IMemberModelListener listener) {
     38        synchronized(listeners) {
     39            if (listener != null && ! listeners.contains(listener)) {
     40                listeners.add(listener);
     41            }
     42        }
     43    }
     44
     45    public void removeMemberModelListener(IMemberModelListener listener) {
     46        synchronized(listeners) {
     47            if (listener != null && listeners.contains(listener)) {
     48                listeners.remove(listener);
     49            }
     50        }
     51    }
     52
     53    protected void fireMakeMemberVisible(int index) {
     54        synchronized(listeners) {
     55            for (IMemberModelListener listener: listeners) {
     56                listener.makeMemberVisible(index);
     57            }
     58        }
    3259    }
    3360
     
    91118            listSelectionModel.addSelectionInterval(row, row);
    92119        }
     120        fireMakeMemberVisible(selectedRows[0] -1);
    93121    }
    94122
     
    110138            listSelectionModel.addSelectionInterval(row, row);
    111139        }
     140        fireMakeMemberVisible(selectedRows[0] + 1);
    112141    }
    113142
     
    185214        }
    186215        if (min < Integer.MAX_VALUE) {
    187             //FIXME: scroll to min
     216            fireMakeMemberVisible(min);
    188217        }
    189218    }
     
    233262            getSelectionModel().addSelectionInterval(i,i);
    234263        }
     264        fireMakeMemberVisible(0);
    235265    }
    236266
     
    247277            getSelectionModel().addSelectionInterval(members.size()-1-i,members.size()-1-i);
    248278        }
     279        fireMakeMemberVisible(members.size() -1);
    249280    }
    250281
     
    261292            getSelectionModel().addSelectionInterval(idx+i,idx+i);
    262293        }
     294        fireMakeMemberVisible(idx);
    263295    }
    264296
     
    276308            getSelectionModel().addSelectionInterval(idx+1 + i,idx+1 +i);
    277309        }
     310        fireMakeMemberVisible(idx+1);
    278311    }
    279312}
Note: See TracChangeset for help on using the changeset viewer.