Changeset 19657 in josm for trunk/test/unit


Ignore:
Timestamp:
2026-10-23T16:00:18+02:00 (5 days ago)
Author:
gaben
Message:

fix #21208, fix #21207 - center icons and align text in preference and preset lists

Use padded icons for tagging preset icons and for list entry/label icons in the preset dialog, so non-square icons are centered and the texts line up. List entries without an icon get a blank one if other entries of the list have an icon.

Location:
trunk/test/unit/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/ComboTest.java

    r18918 r19657  
    77import java.awt.Color;
    88
     9import javax.swing.JLabel;
     10import javax.swing.JList;
    911import javax.swing.JPanel;
    1012
    … …  
    1719import org.openstreetmap.josm.testutils.annotations.I18n;
    1820import org.openstreetmap.josm.testutils.annotations.Main;
     21import org.openstreetmap.josm.tools.ImageProvider.ImageSizes;
    1922
    2023/**
    … …  
    124127    }
    125128
     129    /**
     130     * Entry icons are centered in a square and entries without an icon get a blank one, so that the texts line up.
     131     */
     132    @Test
     133    void testIconAlignment() {
     134        final Combo combo = getInstance();
     135        combo.key = "highway";
     136        PresetListEntry trunk = new PresetListEntry("trunk", combo);
     137        trunk.icon = "presets/transport/way/way_trunk.svg";
     138        combo.addListEntry(trunk);
     139        combo.addListEntry(new PresetListEntry("busway", combo));
     140        combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false));
     141        JList<PresetListEntry> list = new JList<>();
     142        for (PresetListEntry entry : combo.presetListEntries) {
     143            JLabel label = (JLabel) combo.combobox.getRenderer().getListCellRendererComponent(list, entry, 0, false, false);
     144            assertEquals(ImageSizes.SMALLICON.getAdjustedWidth(), label.getIcon().getIconWidth(), entry.value);
     145            assertEquals(ImageSizes.SMALLICON.getAdjustedHeight(), label.getIcon().getIconHeight(), entry.value);
     146        }
     147    }
     148
    126149    @Test
    127150    void testColor() {
  • trunk/test/unit/org/openstreetmap/josm/tools/ImageResizeModeTest.java

    r19519 r19657  
    77
    88import java.awt.Dimension;
     9import java.awt.image.BufferedImage;
    910
    1011import org.junit.jupiter.api.Test;
    … …  
    6970
    7071    /**
     72     * Test method for {@link ImageResizeMode#createBufferedImage} using {@link ImageResizeMode#PADDED} on a raster image
     73     */
     74    @Test
     75    void testCreateBufferedImagePaddedRaster() {
     76        BufferedImage source = new BufferedImage(16, 4, BufferedImage.TYPE_INT_RGB); // opaque black
     77        BufferedImage padded = ImageResizeMode.PADDED.createBufferedImage(new Dimension(32, 32), new Dimension(16, 4), null, source);
     78        assertEquals(32, padded.getWidth());
     79        assertEquals(32, padded.getHeight());
     80        // aspect ratio is kept: a 32x8 bar centered vertically
     81        assertEquals(0, padded.getRGB(16, 11) >>> 24);
     82        assertEquals(0xff, padded.getRGB(16, 12) >>> 24);
     83        assertEquals(0xff, padded.getRGB(16, 19) >>> 24);
     84        assertEquals(0, padded.getRGB(16, 20) >>> 24);
     85    }
     86
     87    /**
    7188     * Test method for {@link ImageResizeMode#cacheKey}
    7289     */
Note: See TracChangeset for help on using the changeset viewer.