Ignore:
Timestamp:
2009-10-13T20:34:11+02:00 (15 years ago)
Author:
Gubaer
Message:

Improved Download Location Dialog and created help page.
ExtendedDialog now supports context sensitive help including a help button.
ExtendedDialog now supports tooltip texts for buttons in the button row.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/OpenLocationAction.java

    r2215 r2285  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.awt.GridBagConstraints;
    67import java.awt.GridBagLayout;
    78import java.awt.event.ActionEvent;
    89import java.awt.event.KeyEvent;
     10import java.util.Collections;
     11import java.util.LinkedList;
     12import java.util.List;
    913
    1014import javax.swing.JCheckBox;
    1115import javax.swing.JLabel;
    1216import javax.swing.JPanel;
    13 import javax.swing.JTextField;
    1417
    1518import org.openstreetmap.josm.Main;
    1619import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask;
    1720import org.openstreetmap.josm.gui.ExtendedDialog;
     21import org.openstreetmap.josm.gui.widgets.HistoryComboBox;
    1822import org.openstreetmap.josm.tools.GBC;
    1923import org.openstreetmap.josm.tools.Shortcut;
     
    3438    }
    3539
     40    /**
     41     * Restore the current history from the preferences
     42     *
     43     * @param cbHistory
     44     */
     45    protected void restoreUploadAddressHistory(HistoryComboBox cbHistory) {
     46        List<String> cmtHistory = new LinkedList<String>(Main.pref.getCollection(getClass().getName() + ".uploadAddressHistory", new LinkedList<String>()));
     47        // we have to reverse the history, because ComboBoxHistory will reverse it again
     48        // in addElement()
     49        //
     50        Collections.reverse(cmtHistory);
     51        cbHistory.setPossibleItems(cmtHistory);
     52    }
     53
     54    /**
     55     * Remind the current history in the preferences
     56     * @param cbHistory
     57     */
     58    protected void remindUploadAddressHistory(HistoryComboBox cbHistory) {
     59        cbHistory.addCurrentItemToHistory();
     60        Main.pref.putCollection(getClass().getName() + ".uploadAddressHistory", cbHistory.getHistory());
     61    }
     62
    3663    public void actionPerformed(ActionEvent e) {
    3764
    3865        JCheckBox layer = new JCheckBox(tr("Separate Layer"));
     66        layer.setToolTipText(tr("Select if the data should be downloaded in a new layer"));
    3967        layer.setSelected(Main.pref.getBoolean("download.newlayer"));
    4068        JPanel all = new JPanel(new GridBagLayout());
    41         all.add(new JLabel(tr("Enter URL to download:")), GBC.eol());
    42         JTextField urltext = new JTextField(40);
    43         all.add(urltext, GBC.eol());
    44         all.add(layer, GBC.eol());
     69        GridBagConstraints gc = new GridBagConstraints();
     70        gc.fill = GridBagConstraints.HORIZONTAL;
     71        gc.weightx = 1.0;
     72        gc.anchor = GridBagConstraints.FIRST_LINE_START;
     73        all.add(new JLabel(tr("Enter URL to download:")), gc);
     74        HistoryComboBox uploadAdresses = new HistoryComboBox();
     75        uploadAdresses.setToolTipText(tr("Enter an URL from where data should be downloaded"));
     76        restoreUploadAddressHistory(uploadAdresses);
     77        gc.gridy = 1;
     78        all.add(uploadAdresses, gc);
     79        gc.gridy = 2;
     80        gc.fill = GridBagConstraints.BOTH;
     81        gc.weighty = 1.0;
     82        all.add(layer, gc);
    4583        ExtendedDialog dialog = new ExtendedDialog(Main.parent,
    4684                tr("Download Location"),
    4785                new String[] {tr("Download URL"), tr("Cancel")}
    4886        );
    49         dialog.setContent(all);
     87        dialog.setContent(all, false /* don't embedded content in JScrollpane  */);
    5088        dialog.setButtonIcons(new String[] {"download.png", "cancel.png"});
     89        dialog.setToolTipTexts(new String[] {
     90                tr("Start downloading data"),
     91                tr("Close dialog and cancel downloading")
     92        });
     93        dialog.configureContextsensitiveHelp("Help/Action/OpenLocation", true /* show help button */);
    5194        dialog.showDialog();
    5295        if (dialog.getValue() != 1) return;
    53         openUrl(layer.isSelected(), urltext.getText());
     96        remindUploadAddressHistory(uploadAdresses);
     97        openUrl(layer.isSelected(), uploadAdresses.getText());
    5498    }
    5599
     
    60104        new DownloadOsmTask().loadUrl(new_layer, url, null);
    61105    }
    62 
    63106}
Note: See TracChangeset for help on using the changeset viewer.