Changeset 19120 in josm for trunk/src


Ignore:
Timestamp:
2024-06-20T15:55:07+02:00 (5 months ago)
Author:
taylor.smock
Message:

See #17858: Update code for newer Java features

Also add a note that toUnmodifiableList does not like nulls.

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

Legend:

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

    r18871 r19120  
    113113                if (dm != null) {
    114114                    AffineTransform transform = gd.getDefaultConfiguration().getDefaultTransform();
    115                     // Java 11: use DisplayMode#toString
    116                     text.format(Locale.ROOT, " %d\u00D7%d (scaling %.2f\u00D7%.2f)",
    117                             dm.getWidth(), dm.getHeight(), transform.getScaleX(), transform.getScaleY());
     115                    text.format(Locale.ROOT, " %s (scaling %.2f\u00D7%.2f)",
     116                            dm, transform.getScaleX(), transform.getScaleY());
    118117                }
    119118            }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/InspectPrimitiveDialog.java

    r17455 r19120  
    4949/**
    5050 * Panel to inspect one or more OsmPrimitives.
    51  *
     51 * <p>
    5252 * Gives an unfiltered view of the object's internal state.
    5353 * Might be useful for power users to give more detailed bug reports and
     
    129129                String heading = tr("Styles for \"{0}\":", osm.getDisplayName(DefaultNameFormatter.getInstance()));
    130130                txtMappaint.println(heading);
    131                 txtMappaint.println(repeatString("=", heading.length()));
     131                txtMappaint.println("=".repeat(heading.length()));
    132132
    133133                MultiCascade mc = new MultiCascade();
     
    137137                        heading = tr("{0} style \"{1}\"", getSort(s), s.getDisplayString());
    138138                        txtMappaint.println(heading);
    139                         txtMappaint.println(repeatString("-", heading.length()));
     139                        txtMappaint.println("-".repeat(heading.length()));
    140140                        s.apply(mc, osm, scale, false);
    141141                        txtMappaint.println(tr("Display range: {0}", mc.range));
     
    150150                heading = tr("List of generated Styles:");
    151151                txtMappaint.println(heading);
    152                 txtMappaint.println(repeatString("-", heading.length()));
     152                txtMappaint.println("-".repeat(heading.length()));
    153153                StyleElementList sl = elemstyles.get(osm, scale, nc);
    154154                for (StyleElement s : sl) {
     
    177177        }
    178178        return stringWriter.toString();
    179     }
    180 
    181     private static String repeatString(String string, int count) {
    182         // Java 11: use String.repeat
    183         return new String(new char[count]).replace("\0", string);
    184179    }
    185180
  • trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetCacheManagerModel.java

    r18338 r19120  
    9090     */
    9191    public List<Changeset> getSelectedChangesets() {
    92         return Arrays.stream(TableHelper.getSelectedIndices(selectionModel))
     92        return Arrays.stream(selectionModel.getSelectedIndices())
    9393                .map(sorter::convertRowIndexToModel).mapToObj(data::get).collect(Collectors.toList());
    9494    }
  • trunk/src/org/openstreetmap/josm/gui/util/ReorderableTableModel.java

    r17773 r19120  
    4242     */
    4343    default int[] getSelectedIndices() {
    44         return TableHelper.getSelectedIndices(getSelectionModel());
     44        return getSelectionModel().getSelectedIndices();
    4545    }
    4646
  • trunk/src/org/openstreetmap/josm/gui/util/TableHelper.java

    r17778 r19120  
    123123     * Unfortunately this method is not available in OpenJDK before version 11, see
    124124     * https://bugs.openjdk.java.net/browse/JDK-8199395
    125      *
     125     * <p>
    126126     * To be removed when we switch to Java 11 or later.
    127127     *
     
    132132     * @see #selectedIndices(ListSelectionModel)
    133133     * @since 15226
     134     * @deprecated Use {@link ListSelectionModel#getSelectedIndices()} instead
    134135     */
     136    @Deprecated(since = "19120")
    135137    public static int[] getSelectedIndices(ListSelectionModel selectionModel) {
    136         return selectedIndices(selectionModel).toArray();
     138        return selectionModel.getSelectedIndices();
    137139    }
    138140
  • trunk/src/org/openstreetmap/josm/tools/PlatformHook.java

    r19105 r19120  
    248248    /**
    249249     * Returns extended modifier key used as the appropriate accelerator key for menu shortcuts.
    250      * It is advised everywhere to use {@link Toolkit#getMenuShortcutKeyMask()} to get the cross-platform modifier, but:
     250     * It was advised everywhere to use {@link Toolkit#getMenuShortcutKeyMask()} to get the cross-platform modifier, but:
    251251     * <ul>
    252252     * <li>it returns KeyEvent.CTRL_MASK instead of KeyEvent.CTRL_DOWN_MASK. We used the extended
     
    258258     */
    259259    default int getMenuShortcutKeyMaskEx() {
    260         // To remove when switching to Java 10+, and use Toolkit.getMenuShortcutKeyMaskEx instead
     260        if (!GraphicsEnvironment.isHeadless()) {
     261            return Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx();
     262        }
    261263        return InputEvent.CTRL_DOWN_MASK;
    262264    }
  • trunk/src/org/openstreetmap/josm/tools/PlatformHookOsx.java

    r19103 r19120  
    104104        return !("true".equals(getSystemProperty("apple.laf.useScreenMenuBar"))
    105105                && ("Aqua".equals(laf) || laf.contains("Mac")));
    106     }
    107 
    108     @Override
    109     public int getMenuShortcutKeyMaskEx() {
    110         return InputEvent.META_DOWN_MASK;
    111106    }
    112107
  • trunk/src/org/openstreetmap/josm/tools/StreamUtils.java

    r17333 r19120  
    6868     */
    6969    public static <T> Collector<T, ?, List<T>> toUnmodifiableList() {
    70         // Java 10: use java.util.stream.Collectors.toUnmodifiableList
     70        // Java 10: use java.util.stream.Collectors.toUnmodifiableList (note: does not like null checks OR null entries)
    7171        return Collectors.collectingAndThen(Collectors.toList(), Utils::toUnmodifiableList);
    7272    }
Note: See TracChangeset for help on using the changeset viewer.