Changeset 14689 in josm for trunk/src/org
- Timestamp:
- 2019-01-13T11:17:00+01:00 (6 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/tools
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/InputMapUtils.java
r14106 r14689 4 4 import java.awt.event.InputEvent; 5 5 import java.awt.event.KeyEvent; 6 import java.util.Optional; 6 7 7 8 import javax.swing.Action; … … 128 129 c.getActionMap().put("ctrl_enter", a); 129 130 c.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(stroke, "ctrl_enter"); 131 Optional.ofNullable(a.getValue(Action.SHORT_DESCRIPTION)) 132 .map(String::valueOf) 133 .ifPresent(text -> Shortcut.setTooltip(a, text, stroke)); 130 134 } 131 135 } -
trunk/src/org/openstreetmap/josm/tools/PlatformHook.java
r14273 r14689 135 135 * @param sc Shortcut associated (to display accelerator between parenthesis) 136 136 * @return Full tooltip text (name + accelerator) 137 */ 137 * @since 1084 138 * @deprecated Use {@link Shortcut#makeTooltip} instead. 139 */ 140 @Deprecated 138 141 default String makeTooltip(String name, Shortcut sc) { 139 StringBuilder result = new StringBuilder(); 140 result.append("<html>").append(name); 141 if (sc != null && !sc.getKeyText().isEmpty()) { 142 result.append(" <font size='-2'>(") 143 .append(sc.getKeyText()) 144 .append(")</font>"); 145 } 146 return result.append(" </html>").toString(); 142 return Shortcut.makeTooltip(name, sc != null ? sc.getKeyStroke() : null); 147 143 } 148 144 -
trunk/src/org/openstreetmap/josm/tools/PlatformHookOsx.java
r14368 r14689 27 27 import java.util.Objects; 28 28 import java.util.concurrent.ExecutionException; 29 30 import javax.swing.UIManager;31 29 32 30 import org.openstreetmap.josm.data.Preferences; … … 355 353 356 354 @Override 357 public String makeTooltip(String name, Shortcut sc) {358 String lafid = UIManager.getLookAndFeel().getID();359 boolean canHtml = true;360 // "Mac" is the native LAF, "Aqua" is Quaqua. Both use native menus with native tooltips.361 if (lafid.contains("Mac") || lafid.contains("Aqua")) {362 canHtml = false;363 }364 StringBuilder result = new StringBuilder(48);365 if (canHtml) {366 result.append("<html>");367 }368 result.append(name);369 if (sc != null && !sc.getKeyText().isEmpty()) {370 result.append(' ');371 if (canHtml) {372 result.append("<font size='-2'>");373 }374 result.append('(').append(sc.getKeyText()).append(')');375 if (canHtml) {376 result.append("</font>");377 }378 }379 if (canHtml) {380 result.append(" </html>");381 }382 return result.toString();383 }384 385 @Override386 355 public String getDefaultStyle() { 387 356 return "com.apple.laf.AquaLookAndFeel"; -
trunk/src/org/openstreetmap/josm/tools/Shortcut.java
r14149 r14689 18 18 import javax.swing.AbstractAction; 19 19 import javax.swing.AbstractButton; 20 import javax.swing.Action; 20 21 import javax.swing.JMenu; 21 22 import javax.swing.KeyStroke; 23 import javax.swing.UIManager; 22 24 import javax.swing.text.JTextComponent; 23 25 … … 270 272 } 271 273 274 /** 275 * Sets the action tooltip to the tooltip text plus the {@linkplain #getKeyText(KeyStroke) key stroke text} 276 * this shortcut represents. 277 * 278 * @param action action 279 * @param tooltip Tooltip text to display 280 * @since 14689 281 */ 282 public void setTooltip(Action action, String tooltip) { 283 setTooltip(action, tooltip, getKeyStroke()); 284 } 285 286 /** 287 * Sets the action tooltip to the tooltip text plus the {@linkplain #getKeyText(KeyStroke) key stroke text}. 288 * 289 * @param action action 290 * @param tooltip Tooltip text to display 291 * @param keyStroke Key stroke associated (to display accelerator between parenthesis) 292 * @since 14689 293 */ 294 public static void setTooltip(Action action, String tooltip, KeyStroke keyStroke) { 295 action.putValue(Action.SHORT_DESCRIPTION, makeTooltip(tooltip, keyStroke)); 296 } 297 272 298 @Override 273 299 public String toString() { … … 595 621 .orElse(null); 596 622 } 623 624 /** 625 * Returns the tooltip text plus the {@linkplain #getKeyText(KeyStroke) key stroke text}. 626 * 627 * Tooltips are usually not system dependent, unless the 628 * JVM is too dumb to provide correct names for all the keys. 629 * 630 * Some LAFs don't understand HTML, such as the OSX LAFs. 631 * 632 * @param tooltip Tooltip text to display 633 * @param keyStroke Key stroke associated (to display accelerator between parenthesis) 634 * @return Full tooltip text (tooltip + accelerator) 635 * @since 14689 636 */ 637 public static String makeTooltip(String tooltip, KeyStroke keyStroke) { 638 final Optional<String> keyStrokeText = Optional.ofNullable(keyStroke) 639 .map(Shortcut::getKeyText) 640 .filter(text -> !text.isEmpty()); 641 642 final String laf = UIManager.getLookAndFeel().getID(); 643 // "Mac" is the native LAF, "Aqua" is Quaqua. Both use native menus with native tooltips. 644 final boolean canHtml = !(PlatformManager.isPlatformOsx() && (laf.contains("Mac") || laf.contains("Aqua"))); 645 646 StringBuilder result = new StringBuilder(48); 647 if (canHtml) { 648 result.append("<html>"); 649 } 650 result.append(tooltip); 651 if (keyStrokeText.isPresent()) { 652 result.append(' '); 653 if (canHtml) { 654 result.append("<font size='-2'>"); 655 } 656 result.append('(').append(keyStrokeText.get()).append(')'); 657 if (canHtml) { 658 result.append("</font>"); 659 } 660 } 661 if (canHtml) { 662 result.append(" </html>"); 663 } 664 return result.toString(); 665 } 666 597 667 }
Note:
See TracChangeset
for help on using the changeset viewer.