@@ -157,8 +157,8 @@ static public KeyStroke getKeyStrokeExt(String base) {
157
157
158
158
/**
159
159
* Create a menu item and set its KeyStroke by name (so it can be stored
160
- * in the language settings or the preferences). Syntax is here:
161
- * https://docs.oracle.com/javase/8/docs/api/javax/swing/KeyStroke.html#getKeyStroke-java.lang.String-
160
+ * in the language settings or the preferences). Syntax is .
161
+ * <a href=" https://docs.oracle.com/javase/8/docs/api/javax/swing/KeyStroke.html#getKeyStroke-java.lang.String-">here</a>.
162
162
*/
163
163
static public JMenuItem newJMenuItemExt (String base ) {
164
164
JMenuItem menuItem = new JMenuItem (Language .text (base ));
@@ -248,40 +248,79 @@ static public void addDisabledItem(JMenu menu, String title) {
248
248
249
249
250
250
/**
251
- * Removes all mnemonics, then sets a mnemonic for each menu and menu item
252
- * recursively by these rules:
251
+ * Apply an Action from something else (i.e. a JMenuItem) to a JButton.
252
+ * Swing is so absof*ckinglutely convoluted sometimes. Do we really need
253
+ * half a dozen lines of boilerplate to apply a key shortcut to a button?
254
+ */
255
+ static public void applyAction (Action action , JButton button ) {
256
+ button .setAction (action );
257
+ // use an arbitrary but unique name
258
+ String name = String .valueOf (action .hashCode ());
259
+ button .getActionMap ().put (name , action );
260
+ button .getInputMap (JComponent .WHEN_IN_FOCUSED_WINDOW )
261
+ .put ((KeyStroke ) action .getValue (Action .ACCELERATOR_KEY ), name );
262
+ }
263
+
264
+
265
+ /**
266
+ * Removes all mnemonics, then sets a mnemonic for each menu and menu
267
+ * item recursively by these rules:
253
268
* <ol>
254
269
* <li> It tries to assign one of <a href="http://techbase.kde.org/Projects/Usability/HIG/Keyboard_Accelerators">
255
270
* KDE's defaults</a>.</li>
256
- * <li> Failing that, it loops through the first letter of each word, where a word
257
- * is a block of Unicode "alphabetical" chars, looking for an upper-case ASCII mnemonic
258
- * that is not taken. This is to try to be relevant, by using a letter well-associated
259
- * with the command. (MS guidelines) </li>
260
- * <li> Ditto, but with lowercase. </li>
261
- * <li> Next, it tries the second ASCII character, if its width >= half the width of
262
- * 'A'. </li>
263
- * <li> If the first letters are all taken/non-ASCII, then it loops through the
264
- * ASCII letters in the item, widest to narrowest, seeing if any of them is not taken.
265
- * To improve readability, it discriminates against descenders (qypgj), imagining they
266
- * have 2/3 their actual width. (MS guidelines: avoid descenders). It also discriminates
267
- * against vowels, imagining they have 2/3 their actual width. (MS and Gnome guidelines:
268
- * avoid vowels.) </li>
269
- * <li>Failing that, it will loop left-to-right for an available digit. This is a last
270
- * resort because the normal setMnemonic dislikes them.</li>
271
- * <li> If that doesn't work, it doesn't assign a mnemonic. </li>
271
+ * <li>
272
+ * Failing that, it loops through the first letter of each word,
273
+ * where a word is a block of Unicode "alphabetical" chars, looking
274
+ * for an upper-case ASCII mnemonic that is not taken.
275
+ * This is to try to be relevant, by using a letter well-associated
276
+ * with the command. (MS guidelines)
277
+ * </li>
278
+ * <li>
279
+ * Ditto, but with lowercase.
280
+ * </li>
281
+ * <li>
282
+ * Next, it tries the second ASCII character, if its width
283
+ * >= half the width of 'A'.
284
+ * </li>
285
+ * <li>
286
+ * If the first letters are all taken/non-ASCII, then it loops
287
+ * through the ASCII letters in the item, widest to narrowest,
288
+ * seeing if any of them is not taken. To improve readability,
289
+ * it discriminates against descenders (qypgj), imagining they
290
+ * have 2/3 their actual width. (MS guidelines: avoid descenders).
291
+ * It also discriminates against vowels, imagining they have 2/3
292
+ * their actual width. (MS and Gnome guidelines: avoid vowels.)
293
+ * </li>
294
+ * <li>
295
+ * Failing that, it will loop left-to-right for an available digit.
296
+ * This is a last resort because the normal setMnemonic dislikes them.
297
+ * </li>
298
+ * <li>
299
+ * If that doesn't work, it doesn't assign a mnemonic.
300
+ * </li>
272
301
* </ol>
273
302
*
274
- * As a special case, strings starting "sketchbook \u2192 " have that bit ignored
275
- * because otherwise the Recent menu looks awful. However, the name <tt>"sketchbook \u2192
276
- * Sketch"</tt>, for example, will have the 'S' of "Sketch" chosen, but the 's' of 'sketchbook
277
- * will get underlined.
278
- * No letter by an underscore will be assigned.
279
- * Disabled on Mac, per Apple guidelines.
280
- * <tt>menu</tt> may contain nulls.
303
+ * Additional rules:
304
+ * <ul>
305
+ * <li>
306
+ * As a special case, strings starting "sketchbook → " have that
307
+ * bit ignored because otherwise the Recent menu looks awful.
308
+ * </li>
309
+ * <li>
310
+ * However, the name <tt>"sketchbook → Sketch"</tt>,
311
+ * for example, will have the 'S' of "Sketch" chosen,
312
+ * but the 's' of 'sketchbook' will get underlined.
313
+ * </li>
314
+ * <li>
315
+ * No letter by an underscore will be assigned.
316
+ * </li>
317
+ * <li>
318
+ * Disabled on Mac, per Apple guidelines.
319
+ * </li>
320
+ * </ul>
281
321
*
282
- * Author: George Bateman. Initial work Myer Nore.
283
- * @param menu
284
- * A menu, a list of menus or an array of menu items to set mnemonics for.
322
+ * Written by George Bateman, with Initial work Myer Nore.
323
+ * @param menu Menu items to set mnemonics for (null entries are ok)
285
324
*/
286
325
static public void setMenuMnemonics (JMenuItem ... menu ) {
287
326
if (Platform .isMacOS ()) return ;
@@ -376,7 +415,7 @@ public int compare(Character ch1, Character ch2) {
376
415
// The string can't be made lower-case as that would spoil
377
416
// the width comparison.
378
417
String cleanString = jmi .getText ();
379
- if (cleanString .startsWith ("sketchbook \u2192 " ))
418
+ if (cleanString .startsWith ("sketchbook → " ))
380
419
cleanString = cleanString .substring (13 );
381
420
382
421
if (cleanString .length () == 0 ) continue ;
@@ -521,21 +560,6 @@ static public int getMenuItemIndex(JMenu menu, JMenuItem item) {
521
560
}
522
561
523
562
524
- /**
525
- * Apply an Action from something else (i.e. a JMenuItem) to a JButton.
526
- * Swing is so absof*ckinglutely convoluted sometimes. Do we really need
527
- * half a dozen lines of boilerplate to apply a key shortcut to a button?
528
- */
529
- static public void applyAction (Action action , JButton button ) {
530
- button .setAction (action );
531
- // use an arbitrary but unique name
532
- String name = String .valueOf (action .hashCode ());
533
- button .getActionMap ().put (name , action );
534
- button .getInputMap (JComponent .WHEN_IN_FOCUSED_WINDOW )
535
- .put ((KeyStroke ) action .getValue (Action .ACCELERATOR_KEY ), name );
536
- }
537
-
538
-
539
563
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
540
564
541
565
@@ -1219,9 +1243,9 @@ static public String getMonoFontName() {
1219
1243
/**
1220
1244
* Get the Font object of the default (built-in) monospaced font.
1221
1245
* As of 4.x, this is Source Code Pro and ships in lib/fonts because
1222
- * it looks like JDK 11 no longer has (supports?) a "fonts" subfolder
1223
- * (or at least, its cross-platform implementation is inconsistent).
1224
- * https://www.oracle.com/java/technologies/javase/11-relnote-issues.html#JDK-8191522
1246
+ * it looks like JDK 11+ <a href="https://www.oracle.com/java/technologies/javase/11-relnote-issues.html#JDK-8191522">
1247
+ * no longer supports</a> a "fonts" subfolder (or at least,
1248
+ * its cross-platform implementation is inconsistent).
1225
1249
*/
1226
1250
static public Font getMonoFont (int size , int style ) {
1227
1251
// Prior to 4.0 beta 9, we had a manual override for
0 commit comments