Changeset 6742 in josm for trunk/src/org


Ignore:
Timestamp:
2014-01-19T20:59:05+01:00 (11 years ago)
Author:
simon04
Message:

fix #7686 - Shorten long search expression for display purposes (in dialogs, tooltips)

Location:
trunk/src/org/openstreetmap/josm
Files:
4 edited

Legend:

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

    r6586 r6742  
    5656
    5757    public static final int DEFAULT_SEARCH_HISTORY_SIZE = 15;
     58    /** Maximum number of characters before the search expression is shortened for display purposes. */
     59    public static final int MAX_LENGTH_SEARCH_EXPRESSION_DISPLAY = 100;
    5860
    5961    private static final String SEARCH_EXPRESSION = "searchExpression";
     
    321323                    new ToolbarPreferences.ActionDefinition(Main.main.menu.search);
    322324            aDef.getParameters().put(SEARCH_EXPRESSION, initialValues);
    323             aDef.setName(initialValues.text); // Display search expression as tooltip instead of generic one
     325            aDef.setName(Utils.shortenString(initialValues.text, MAX_LENGTH_SEARCH_EXPRESSION_DISPLAY)); // Display search expression as tooltip instead of generic one
    324326            // parametrized action definition is now composed
    325327            ActionParser actionParser = new ToolbarPreferences.ActionParser(null);
     
    588590        if (foundMatches == 0) {
    589591            String msg = null;
     592            final String text = Utils.shortenString(s.text, MAX_LENGTH_SEARCH_EXPRESSION_DISPLAY);
    590593            if (s.mode == SearchMode.replace) {
    591                 msg = tr("No match found for ''{0}''", s.text);
     594                msg = tr("No match found for ''{0}''", text);
    592595            } else if (s.mode == SearchMode.add) {
    593                 msg = tr("Nothing added to selection by searching for ''{0}''", s.text);
     596                msg = tr("Nothing added to selection by searching for ''{0}''", text);
    594597            } else if (s.mode == SearchMode.remove) {
    595                 msg = tr("Nothing removed from selection by searching for ''{0}''", s.text);
     598                msg = tr("Nothing removed from selection by searching for ''{0}''", text);
    596599            } else if (s.mode == SearchMode.in_selection) {
    597                 msg = tr("Nothing found in selection by searching for ''{0}''", s.text);
     600                msg = tr("Nothing found in selection by searching for ''{0}''", text);
    598601            }
    599602            Main.map.statusLine.setHelpText(msg);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java

    r6380 r6742  
    3838import org.openstreetmap.josm.actions.relation.EditRelationAction;
    3939import org.openstreetmap.josm.actions.relation.SelectInRelationListAction;
     40import org.openstreetmap.josm.actions.search.SearchAction;
    4041import org.openstreetmap.josm.actions.search.SearchAction.SearchSetting;
    4142import org.openstreetmap.josm.data.SelectionChangedListener;
     
    7475import org.openstreetmap.josm.tools.Shortcut;
    7576import org.openstreetmap.josm.tools.SubclassFilteredCollection;
     77import org.openstreetmap.josm.tools.Utils;
    7678
    7779/**
     
    275277            putValue(NAME, tr("Search"));
    276278            putValue(SHORT_DESCRIPTION,   tr("Search for objects"));
    277             putValue(SMALL_ICON, ImageProvider.get("dialogs","select"));
     279            putValue(SMALL_ICON, ImageProvider.get("dialogs","search"));
    278280            updateEnabledState();
    279281        }
     
    657659
    658660        public SearchMenuItem(SearchSetting s) {
    659             super(s.toString());
     661            super(Utils.shortenString(s.toString(), org.openstreetmap.josm.actions.search.SearchAction.MAX_LENGTH_SEARCH_EXPRESSION_DISPLAY));
    660662            this.s = s;
    661663            addActionListener(this);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

    r6707 r6742  
    806806                selection = null;
    807807            }
    808             if (positionString.length() > 20) {
    809                 positionString = positionString.substring(0, 17) + "...";
    810             }
    811             return positionString;
     808            return Utils.shortenString(positionString, 20);
    812809        }
    813810
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r6740 r6742  
    947947        return biggerCopy;
    948948    }
     949
     950    /**
     951     * If the string {@code s} is longer than {@code maxLength}, the string is cut and "..." is appended.
     952     */
     953    public static String shortenString(String s, int maxLength) {
     954        if (s != null && s.length() > maxLength) {
     955            return s.substring(0, maxLength - 3) + "...";
     956        } else {
     957            return s;
     958        }
     959    }
    949960}
Note: See TracChangeset for help on using the changeset viewer.