Changeset 1419 in josm for trunk/src/org


Ignore:
Timestamp:
2009-02-17T16:52:39+01:00 (16 years ago)
Author:
stoecker
Message:

close #2192. Patch by xeen

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

Legend:

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

    r1228 r1419  
    4040import org.openstreetmap.josm.data.osm.visitor.Visitor;
    4141import org.openstreetmap.josm.gui.ConflictResolver;
     42import org.openstreetmap.josm.gui.ExtendedDialog;
    4243import org.openstreetmap.josm.gui.NavigatableComponent;
    4344import org.openstreetmap.josm.gui.OsmPrimitivRenderer;
     
    5051    private final DefaultListModel model = new DefaultListModel();
    5152    private final JList displaylist = new JList(model);
     53   
     54    private final SideButton sbSelect = new SideButton(marktr("Select"), "select", "Conflict",
     55            tr("Set the selected elements on the map to the selected items in the list above."), new ActionListener(){
     56                public void actionPerformed(ActionEvent e) {
     57                    Collection<OsmPrimitive> sel = new LinkedList<OsmPrimitive>();
     58                    for (Object o : displaylist.getSelectedValues())
     59                        sel.add((OsmPrimitive)o);
     60                    Main.ds.setSelected(sel);
     61                }
     62            });
     63    private final SideButton sbResolve = new SideButton(marktr("Resolve"), "conflict", "Conflict",
     64            tr("Open a merge dialog of all selected items in the list above."), new ActionListener(){
     65        public void actionPerformed(ActionEvent e) {
     66            resolve();
     67        }
     68    });
    5269
    5370    public ConflictDialog() {
     
    6582
    6683        JPanel buttonPanel = new JPanel(new GridLayout(1,2));
    67         buttonPanel.add(new SideButton(marktr("Resolve"), "conflict", "Conflict",
    68         tr("Open a merge dialog of all selected items in the list above."), new ActionListener(){
    69             public void actionPerformed(ActionEvent e) {
    70                 resolve();
    71             }
    72         }));
    73 
    74         buttonPanel.add(new SideButton(marktr("Select"), "select", "Conflict",
    75         tr("Set the selected elements on the map to the selected items in the list above."), new ActionListener(){
    76             public void actionPerformed(ActionEvent e) {
    77                 Collection<OsmPrimitive> sel = new LinkedList<OsmPrimitive>();
    78                 for (Object o : displaylist.getSelectedValues())
    79                     sel.add((OsmPrimitive)o);
    80                 Main.ds.setSelected(sel);
    81             }
    82         }));
     84        buttonPanel.add(sbResolve);
     85        buttonPanel.add(sbSelect);
    8386        add(buttonPanel, BorderLayout.SOUTH);
    8487
     
    99102            }
    100103        });
     104       
     105        rebuildList();
    101106    }
    102107
    103108    private final void resolve() {
    104         if (displaylist.getSelectedIndex() == -1) {
    105             JOptionPane.showMessageDialog(Main.parent,tr("Please select something from the conflict list."));
     109        if(model.size() == 1)
     110            displaylist.setSelectedIndex(0);
     111       
     112        if (displaylist.getSelectedIndex() == -1)
    106113            return;
    107         }
    108114        Map<OsmPrimitive, OsmPrimitive> sel = new HashMap<OsmPrimitive, OsmPrimitive>();
    109115        for (int i : displaylist.getSelectedIndices()) {
     
    112118        }
    113119        ConflictResolver resolver = new ConflictResolver(sel);
    114         int answer = JOptionPane.showConfirmDialog(Main.parent, resolver, tr("Resolve Conflicts"), JOptionPane.OK_CANCEL_OPTION);
    115         if (answer != JOptionPane.OK_OPTION)
     120        int answer = new ExtendedDialog(Main.parent,
     121                          tr("Resolve Conflicts"),
     122                          resolver,
     123                          new String[] { tr("Solve Conflict"), tr("Cancel") },
     124                          new String[] { "dialogs/conflict.png", "cancel.png"}
     125        ).getValue();
     126
     127        if (answer != 1)
    116128            return;
    117129        Main.main.undoRedo.add(new ConflictResolveCommand(resolver.conflicts, sel));
     
    136148            setTitle(tr("Conflicts"), false);
    137149        }
     150       
     151        sbSelect.setEnabled(model.size() > 0);
     152        sbResolve.setEnabled(model.size() > 0);
    138153    }
    139154
  • trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java

    r1415 r1419  
    1818import javax.swing.JScrollPane;
    1919import javax.swing.ListSelectionModel;
     20import javax.swing.event.ListSelectionEvent;
    2021import javax.swing.event.ListSelectionListener;
    2122import org.openstreetmap.josm.Main;
     
    5354     */
    5455    private JList displaylist = new JList(list);
     56   
     57    private SideButton sbEdit = new SideButton(marktr("Edit"), "edit", "Selection", tr( "Open an editor for the selected relation"), new ActionListener() {
     58        public void actionPerformed(ActionEvent e) {
     59            Relation toEdit = getSelected();
     60            if (toEdit == null)
     61                return;
     62           
     63            new RelationEditor(toEdit).setVisible(true);
     64        }
     65    });
     66   
     67    private SideButton sbDel = new SideButton(marktr("Delete"), "delete", "Selection", tr("Delete the selected relation"), new ActionListener() {
     68        public void actionPerformed(ActionEvent e) {
     69            Relation toDelete = getSelected();
     70            if (toDelete == null)
     71                return;
     72           
     73            Main.main.undoRedo.add(
     74                    new DeleteCommand(Collections.singleton(toDelete)));
     75        }
     76    });
    5577
    5678    public RelationListDialog() {
     
    7799        }), GBC.std());
    78100
    79         buttonPanel.add(new SideButton(marktr("Edit"), "edit", "Selection", tr( "Open an editor for the selected relation"), new ActionListener() {
    80             public void actionPerformed(ActionEvent e) {
    81                 Relation toEdit = (Relation) displaylist.getSelectedValue();
    82                 if (toEdit != null)
    83                     new RelationEditor(toEdit).setVisible(true);
    84             }
    85         }), GBC.std());
     101        buttonPanel.add(sbEdit, GBC.std());
    86102
    87         buttonPanel.add(new SideButton(marktr("Delete"), "delete", "Selection", tr("Delete the selected relation"), new ActionListener() {
    88             public void actionPerformed(ActionEvent e) {
    89                 Relation toDelete = (Relation) displaylist.getSelectedValue();
    90                 if (toDelete != null) {
    91                     Main.main.undoRedo.add(
    92                         new DeleteCommand(Collections.singleton(toDelete)));
    93                 }
    94             }
    95         }), GBC.eol());
     103        buttonPanel.add(sbDel, GBC.eol());
    96104        Layer.listeners.add(this);
    97105        add(buttonPanel, BorderLayout.SOUTH);
     106       
     107        displaylist.addListSelectionListener(new ListSelectionListener() {
     108            public void valueChanged(ListSelectionEvent e) {
     109               sbEdit.setEnabled(getSelected() != null);
     110               sbDel.setEnabled(getSelected() != null);
     111            }
     112        });
    98113    }
    99114
     
    117132            setTitle(tr("Relations"), false);
    118133        }
     134       
     135        sbEdit.setEnabled(list.size() > 0);
     136        sbDel.setEnabled(list.size() > 0);
    119137    }
    120138
     
    169187        displaylist.removeListSelectionListener(listener);
    170188    }
     189   
     190    /**
     191     * @return The selected relation in the list
     192     */
     193    private Relation getSelected() {
     194        if(list.size() == 1)
     195            displaylist.setSelectedIndex(0);
     196        return (Relation) displaylist.getSelectedValue();
     197    }
    171198}
Note: See TracChangeset for help on using the changeset viewer.