Changeset 1804 in josm for trunk


Ignore:
Timestamp:
2009-07-18T15:49:59+02:00 (15 years ago)
Author:
Gubaer
Message:

improved window management for relation editor windows
added duplicate action to relation editor

Location:
trunk/src/org/openstreetmap/josm/gui/dialogs/relation
Files:
6 edited

Legend:

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

    r1801 r1804  
    8080
    8181    static private final Logger logger = Logger.getLogger(GenericRelationEditor.class.getName());
     82    static private final Dimension DEFAULT_EDITOR_DIMENSION = new Dimension(700,500);
    8283
    8384    /** the tag table and its model */
     
    130131            this.memberTableModel.populate(null);
    131132        }
    132         memberTableModel.selectMembers(selectedMembers);
     133        memberTableModel.setSelectedMembers(selectedMembers);
    133134        tagEditorModel.ensureOneTag();
    134135
     
    529530        buttonPanel.add(new SideButton(setRoleAction));
    530531        tfRole.getDocument().addDocumentListener(setRoleAction);
     532
     533        //--- copy relation action
     534        buttonPanel.add(new SideButton(new DuplicateRelationAction()));
    531535        return buttonPanel;
    532536    }
     
    577581    protected Dimension findMaxDialogSize() {
    578582        // FIXME: Make it remember dialog size
    579         return new Dimension(600, 500);
     583        return new Dimension(700, 500);
    580584    }
    581585
     
    938942        public void removeUpdate(DocumentEvent e) {
    939943            refreshEnabled();
     944        }
     945    }
     946
     947    /**
     948     * Creates a new relation with a copy of the current editor state
     949     *
     950     */
     951    class DuplicateRelationAction extends AbstractAction {
     952        public DuplicateRelationAction() {
     953            putValue(SHORT_DESCRIPTION,   tr("Create a copy of this relation and open it in another editor window"));
     954            // FIXME provide an icon
     955            putValue(SMALL_ICON, ImageProvider.get("duplicate"));
     956            putValue(NAME, tr("Duplicate"));
     957            setEnabled(true);
     958        }
     959        public void actionPerformed(ActionEvent e) {
     960            Relation copy = new Relation();
     961            tagEditorModel.applyToPrimitive(copy);
     962            memberTableModel.applyToRelation(copy);
     963            RelationEditor editor = RelationEditor.getEditor(getLayer(), copy, memberTableModel.getSelectedMembers());
     964            editor.setVisible(true);
    940965        }
    941966    }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTable.java

    r1792 r1804  
    22package org.openstreetmap.josm.gui.dialogs.relation;
    33
     4import java.awt.Dimension;
    45import java.awt.Rectangle;
    56import java.awt.event.ActionEvent;
     
    134135        }
    135136    }
    136 
    137 
    138137}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java

    r1798 r1804  
    55import java.util.Arrays;
    66import java.util.Collection;
     7import java.util.Collections;
    78import java.util.Iterator;
    89import java.util.List;
     
    205206    }
    206207
    207     public void selectMembers(Collection<RelationMember> selectedMembers) {
    208         if (selectedMembers == null) return;
    209         int min = Integer.MAX_VALUE;
    210         for (RelationMember member: selectedMembers) {
    211             int row = members.indexOf(member);
    212             if (row >= 0) {
    213                 getSelectionModel();
    214                 listSelectionModel.addSelectionInterval(row,row);
    215                 min = Math.min(row, min);
    216             }
    217         }
    218         if (min < Integer.MAX_VALUE) {
    219             fireMakeMemberVisible(min);
    220         }
    221     }
    222 
    223208    public void applyToRelation(Relation relation) {
    224209        relation.members.clear();
     
    346331        }
    347332    }
     333
     334    /**
     335     * Replies a collection with the currently selected relation members
     336     *
     337     * @return a collection with the currently selected relation members
     338     */
     339    public Collection<RelationMember> getSelectedMembers() {
     340        ArrayList<RelationMember> selectedMembers = new ArrayList<RelationMember>();
     341        for (int i: getSelectedIndices()) {
     342            selectedMembers.add(members.get(i));
     343        }
     344        return selectedMembers;
     345    }
     346
     347
     348    /**
     349     * Selectes the members in the collection selectedMembers
     350     *
     351     * @param selectedMembers the collection of selected members
     352     */
     353    public void setSelectedMembers(Collection<RelationMember> selectedMembers) {
     354        if (selectedMembers == null || selectedMembers.isEmpty())
     355            return;
     356
     357        // lookup the indices for the respective members
     358        //
     359        ArrayList<Integer> selectedIndices = new ArrayList<Integer>();
     360        for (RelationMember member: selectedMembers) {
     361            int idx = members.indexOf(member);
     362            if (idx >= 0 && !selectedIndices.contains(idx)) {
     363                selectedIndices.add(idx);
     364            }
     365        }
     366
     367        // select the members
     368        //
     369        Collections.sort(selectedIndices);
     370        getSelectionModel().clearSelection();
     371        for (int row : selectedIndices) {
     372            getSelectionModel().addSelectionInterval(row, row);
     373        }
     374
     375        // make the first selected member visible
     376        //
     377        if (selectedIndices.size() > 0) {
     378            fireMakeMemberVisible(selectedIndices.get(0));
     379        }
     380    }
    348381}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/RelationDialogManager.java

    r1784 r1804  
    22package org.openstreetmap.josm.gui.dialogs.relation;
    33
     4import java.awt.Dimension;
     5import java.awt.Point;
     6import java.awt.Toolkit;
    47import java.awt.event.WindowAdapter;
    58import java.awt.event.WindowEvent;
     
    1215import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1316import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;
     17
    1418
    1519/**
     
    9397     */
    9498    public void register(OsmDataLayer layer, Relation relation, RelationEditor editor) {
     99        if (relation == null) {
     100            relation = new Relation();
     101        }
    95102        DialogContext context = new DialogContext(layer, relation);
    96103        openDialogs.put(context, editor);
     
    100107    /**
    101108     * Replies true if there is an open relation editor for the relation managed
    102      * by the given layer
     109     * by the given layer. Replies false if relation is null.
    103110     *
    104111     * @param layer  the layer
    105      * @param relation  the relation
     112     * @param relation  the relation. May be null.
    106113     * @return true if there is an open relation editor for the relation managed
    107114     * by the given layer; false otherwise
    108115     */
    109116    public boolean isOpenInEditor(OsmDataLayer layer, Relation relation) {
     117        if (relation == null) return false;
    110118        DialogContext context = new DialogContext(layer, relation);
    111119        return openDialogs.keySet().contains(context);
     
    115123    /**
    116124     * Replies the editor for the relation managed by layer. Null, if no such editor
    117      * is currently open.
     125     * is currently open. Returns null, if relation is null.
    118126     *
    119127     * @param layer the layer
     
    125133     */
    126134    public RelationEditor getEditorForRelation(OsmDataLayer layer, Relation relation) {
     135        if (relation == null) return null;
    127136        DialogContext context = new DialogContext(layer, relation);
    128137        return openDialogs.get(context);
     
    172181        }
    173182    }
     183
     184    /**
     185     * Positions an {@see RelationEditor} centered on the screen
     186     *
     187     * @param editor the editor
     188     */
     189    protected void centerOnScreen(RelationEditor editor) {
     190        Point p = new Point(0,0);
     191        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
     192        p.x = (d.width - editor.getSize().width)/2;
     193        p.y = (d.height - editor.getSize().height)/2;
     194        p.x = Math.max(p.x,0);
     195        p.y = Math.max(p.y,0);
     196        editor.setLocation(p);
     197    }
     198
     199    /**
     200     * Replies true, if there is another open {@see RelationEditor} whose
     201     * upper left corner is close to <code>p</code>.
     202     *
     203     * @param p  the reference point to check
     204     * @return true, if there is another open {@see RelationEditor} whose
     205     * upper left corner is close to <code>p</code>.
     206     */
     207    protected boolean hasEditorWithCloseUpperLeftCorner(Point p) {
     208        for (RelationEditor editor: openDialogs.values()) {
     209            Point corner = editor.getLocation();
     210            if (p.x >= corner.x -5 && corner.x + 5 >= p.x
     211                    && p.y >= corner.y -5 && corner.y + 5 >= p.y)
     212                return true;
     213        }
     214        return false;
     215    }
     216
     217    /**
     218     * Positions a {@see RelationEditor} close to the center of the screen, in such
     219     * a way, that it doesn't entirely cover another {@see RelationEditor}
     220     *
     221     * @param editor
     222     */
     223    protected void positionCloseToScreenCenter(RelationEditor editor) {
     224        Point p = new Point(0,0);
     225        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
     226        p.x = (d.width - editor.getSize().width)/2;
     227        p.y = (d.height - editor.getSize().height)/2;
     228        p.x = Math.max(p.x,0);
     229        p.y = Math.max(p.y,0);
     230        while(hasEditorWithCloseUpperLeftCorner(p)) {
     231            p.x += 20;
     232            p.y += 20;
     233        }
     234        editor.setLocation(p);
     235    }
     236
     237    /**
     238     * Positions a {@see RelationEditor} on the screen. Tries to center it on the
     239     * screen. If it hide another instance of an editor at the same position this
     240     * method tries to reposition <code>editor</code> by moving it slightly down and
     241     * slightly to the right.
     242     *
     243     * @param editor the editor
     244     */
     245    public void positionOnScreen(RelationEditor editor) {
     246        if (editor == null) return;
     247        if (openDialogs.isEmpty()) {
     248            centerOnScreen(editor);
     249        } else {
     250            positionCloseToScreenCenter(editor);
     251        }
     252    }
    174253}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/RelationEditor.java

    r1798 r1804  
    8585        else {
    8686            RelationEditor editor = new GenericRelationEditor(layer, r, selectedMembers);
     87            getRelationDialogManager().positionOnScreen(editor);
    8788            getRelationDialogManager().register(layer, r, editor);
    8889            return editor;
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/SelectionTableColumnModel.java

    r1790 r1804  
    1717        col = new TableColumn(0);
    1818        col.setHeaderValue(tr("Selection"));
    19         col.setResizable(true);
     19        col.setMinWidth(200);
    2020        col.setCellRenderer(renderer);
    2121        addColumn(col);
Note: See TracChangeset for help on using the changeset viewer.