Changeset 2285 in josm


Ignore:
Timestamp:
Oct 13, 2009 8:34:11 PM (4 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.

Location:
trunk/src/org/openstreetmap/josm
Files:
5 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} 
  • trunk/src/org/openstreetmap/josm/data/osm/RelationMember.java

    r2206 r2285  
    104104     * @param role Can be null, in this case it's save as "" 
    105105     * @param member Cannot be null 
     106     * @throw IllegalArgumentException thrown if member is null 
    106107     */ 
    107     public RelationMember(String role, OsmPrimitive member) { 
     108    public RelationMember(String role, OsmPrimitive member) throws IllegalArgumentException{ 
    108109        if (role == null) { 
    109110            role = ""; 
    110111        } 
    111         if (member == null) { 
     112        if (member == null) 
    112113            throw new IllegalArgumentException("Relation member cannot be null"); 
    113         } 
    114114        this.role = role; 
    115115        this.member = member; 
     
    154154            RelationMember other = (RelationMember) obj; 
    155155            return member.equals(other.getMember()) && role.equals(other.getRole()); 
    156         } else { 
     156        } else 
    157157            return false; 
    158         } 
    159158    } 
    160159} 
  • trunk/src/org/openstreetmap/josm/gui/ExtendedDialog.java

    r2168 r2285  
    2323 
    2424import org.openstreetmap.josm.Main; 
     25import org.openstreetmap.josm.gui.help.HelpBrowserProxy; 
     26import org.openstreetmap.josm.gui.help.HelpBuilder; 
    2527import org.openstreetmap.josm.tools.GBC; 
    2628import org.openstreetmap.josm.tools.ImageProvider; 
     
    4143    private Component content; 
    4244    private final String[] bTexts; 
     45    private String[] bToolTipTexts; 
    4346    private String[] bIcons; 
     47 
     48    /** true, if the dialog should include a help button */ 
     49    private boolean showHelpButton; 
     50    /** the help topic */ 
     51    private String helpTopic; 
     52 
    4453    /** 
    4554     * set to true if the content of the extended dialog should 
     
    99108 
    100109    /** 
     110     * Allows decorating the buttons with tooltips. Expects an String[] with translated 
     111     * tooltip texts. 
     112     *  
     113     * @param toolTipTexts the tool tip texts. Ignored, if null. 
     114     */ 
     115    public void setToolTipTexts(String[] toolTipTexts) { 
     116        this.bToolTipTexts = toolTipTexts; 
     117    } 
     118 
     119    /** 
    101120     * Sets the content that will be displayed in the message dialog. 
    102121     *  
     
    187206                button.setIcon(ImageProvider.get(bIcons[i])); 
    188207            } 
     208            if (bToolTipTexts != null && i < bToolTipTexts.length && bToolTipTexts[i] != null) { 
     209                button.setToolTipText(bToolTipTexts[i]); 
     210            } 
    189211 
    190212            if(i == 0) { 
     
    193215            buttonsPanel.add(button, GBC.std().insets(2,2,2,2)); 
    194216            buttons.add(button); 
     217        } 
     218        if (showHelpButton) { 
     219            buttonsPanel.add(new JButton(new HelpAction()), GBC.std().insets(2,2,2,2)); 
     220            HelpBuilder.setHelpContext(getRootPane(),helpTopic); 
    195221        } 
    196222 
     
    396422        return lbl; 
    397423    } 
     424 
     425    /** 
     426     * Configures how this dialog support for context sensitive help. 
     427     * <ul> 
     428     *  <li>if helpTopic is null, the dialog doesn't provide context sensitive help</li> 
     429     *  <li>if helpTopic != null, the dialog redirect user to the help page for this helpTopic when 
     430     *  the user clicks F1 in the dialog</li> 
     431     *  <li>if showHelpButton is true, the dialog displays "Help" button (rightmost button in 
     432     *  the button row)</li> 
     433     * </ul> 
     434     *  
     435     * @param helpTopic the help topic 
     436     * @param showHelpButton true, if the dialog displays a help button 
     437     */ 
     438    public void configureContextsensitiveHelp(String helpTopic, boolean showHelpButton) { 
     439        this.helpTopic = helpTopic; 
     440        this.showHelpButton = showHelpButton; 
     441    } 
     442 
     443 
     444    class HelpAction extends AbstractAction { 
     445        public HelpAction() { 
     446            putValue(SHORT_DESCRIPTION, tr("Show help information")); 
     447            putValue(NAME, tr("Help")); 
     448            putValue(SMALL_ICON, ImageProvider.get("help")); 
     449        } 
     450 
     451        public void actionPerformed(ActionEvent e) { 
     452            HelpBrowserProxy.getInstance().setUrlForHelpTopic(helpTopic); 
     453        } 
     454    } 
    398455} 
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/nodes/NodeListTableCellRenderer.java

    r2181 r2285  
    66import java.awt.Color; 
    77import java.awt.Component; 
    8 import java.text.DecimalFormat; 
    98import java.util.ArrayList; 
    109import java.util.Collections; 
    11 import java.util.logging.Logger; 
    1210 
    1311import javax.swing.BorderFactory; 
  • trunk/src/org/openstreetmap/josm/gui/io/UploadDialog.java

    r2281 r2285  
    4646import javax.swing.event.ListDataEvent; 
    4747import javax.swing.event.ListDataListener; 
    48 import javax.swing.text.JTextComponent; 
    4948 
    5049import org.openstreetmap.josm.Main; 
Note: See TracChangeset for help on using the changeset viewer.