Changeset 9705 in josm


Ignore:
Timestamp:
2016-02-01T16:41:36+01:00 (5 years ago)
Author:
simon04
Message:

fix #12409 - Refactor ImageProvider.ImageSizes

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

Legend:

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

    r9700 r9705  
    154154                    first = false;
    155155                }
    156                 menuItem.setIcon(ImageProvider.getPadded(relation, new Rectangle(16, 16)));
     156                menuItem.setIcon(ImageProvider.getPadded(relation, ImageProvider.ImageSizes.MENU.getImageDimension()));
    157157                add(menuItem);
    158158            }
  • trunk/src/org/openstreetmap/josm/gui/OsmPrimitivRenderer.java

    r9078 r9705  
    33
    44import java.awt.Component;
    5 import java.awt.Rectangle;
    65
    76import javax.swing.DefaultListCellRenderer;
     
    7675            ImageIcon icon = ImageProvider.getPadded(value,
    7776                // Height of component no yet known, assume the default 16px.
    78                 new Rectangle(16, 16));
     77                    ImageProvider.ImageSizes.SMALLICON.getImageDimension());
    7978            if (icon != null) {
    8079                ((JLabel) def).setIcon(icon);
  • trunk/src/org/openstreetmap/josm/gui/SideButton.java

    r9703 r9705  
    2525 */
    2626public class SideButton extends JButton implements Destroyable {
    27     private static final int iconHeight = ImageProvider.getImageSizes(ImageProvider.ImageSizes.SIDEBUTTON).height;
     27    private static final int iconHeight = ImageProvider.ImageSizes.SIDEBUTTON.getImageSize();
    2828
    2929    private transient PropertyChangeListener propertyChangeListener;
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableMemberCellRenderer.java

    r9223 r9705  
    33
    44import java.awt.Component;
    5 import java.awt.Rectangle;
     5import java.awt.Dimension;
    66
    77import javax.swing.JTable;
     
    2323    }
    2424
    25     protected void renderPrimitive(OsmPrimitive primitive, Rectangle cellSize) {
     25    protected void renderPrimitive(OsmPrimitive primitive, Dimension cellSize) {
    2626        // Make icon the full height of the table cell. Icon background is square.
    2727        setIcon(ImageProvider.getPadded(primitive, cellSize));
     
    3838            return this;
    3939
    40         Rectangle cellSize = table.getCellRect(row, column, false);
     40        Dimension cellSize = table.getCellRect(row, column, false).getSize();
    4141
    4242        OsmPrimitive primitive = (OsmPrimitive) value;
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/SelectionTableCellRenderer.java

    r9223 r9705  
    44import java.awt.Color;
    55import java.awt.Component;
    6 import java.awt.Rectangle;
     6import java.awt.Dimension;
    77
    88import javax.swing.JLabel;
     
    6060    }
    6161
    62     protected void renderPrimitive(OsmPrimitive primitive, Rectangle cellSize) {
     62    protected void renderPrimitive(OsmPrimitive primitive, Dimension cellSize) {
    6363        setIcon(ImageProvider.getPadded(primitive, cellSize));
    6464        setText(primitive.getDisplayName(DefaultNameFormatter.getInstance()));
     
    7474            return this;
    7575
    76         Rectangle cellSize = table.getCellRect(row, column, false);
     76        Dimension cellSize = table.getCellRect(row, column, false).getSize();
    7777
    7878        renderBackground((OsmPrimitive) value);
  • trunk/src/org/openstreetmap/josm/tools/ImageProvider.java

    r9691 r9705  
    1212import java.awt.Image;
    1313import java.awt.Point;
    14 import java.awt.Rectangle;
    1514import java.awt.RenderingHints;
    1615import java.awt.Toolkit;
     
    134133    public enum ImageSizes {
    135134        /** SMALL_ICON value of on Action */
    136         SMALLICON,
     135        SMALLICON(Main.pref.getInteger("iconsize.smallicon", 16)),
    137136        /** LARGE_ICON_KEY value of on Action */
    138         LARGEICON,
     137        LARGEICON(Main.pref.getInteger("iconsize.largeicon", 24)),
    139138        /** map icon */
    140         MAP,
     139        MAP(Main.pref.getInteger("iconsize.map", 16)),
    141140        /** map icon maximum size */
    142         MAPMAX,
     141        MAPMAX(Main.pref.getInteger("iconsize.mapmax", 48)),
    143142        /** cursor icon size */
    144         CURSOR,
     143        CURSOR(Main.pref.getInteger("iconsize.cursor", 32)),
    145144        /** cursor overlay icon size */
    146         CURSOROVERLAY,
     145        CURSOROVERLAY(CURSOR.imageSize),
    147146        /** menu icon size */
    148         MENU,
     147        MENU(SMALLICON.imageSize),
    149148        /** menu icon size in popup menus
    150149         * @since 8323
    151150         */
    152         POPUPMENU,
     151        POPUPMENU(LARGEICON.imageSize),
    153152        /** Layer list icon size
    154153         * @since 8323
    155154         */
    156         LAYER,
     155        LAYER(Main.pref.getInteger("iconsize.layer", 16)),
    157156        /** Toolbar button icon size
    158157         * @since 9253
    159158         */
    160         TOOLBAR,
     159        TOOLBAR(LARGEICON.imageSize),
    161160        /** Side button maximum height
    162161         * @since 9253
    163162         */
    164         SIDEBUTTON
     163        SIDEBUTTON(Main.pref.getInteger("iconsize.sidebutton", 20)),
     164        /**
     165         * The default image size
     166         * @since 9705
     167         */
     168        DEFAULT(Main.pref.getInteger("iconsize.default", 24));
     169
     170        private final int imageSize;
     171
     172        ImageSizes(int imageSize) {
     173            this.imageSize = imageSize;
     174        }
     175
     176        /**
     177         * Returns the image size in pixels
     178         * @return the image size in pixels
     179         */
     180        public int getImageSize() {
     181            return imageSize;
     182        }
     183
     184        /**
     185         * Returns the image size as dimension
     186         * @return the image size as dimension
     187         */
     188        public Dimension getImageDimension() {
     189            return new Dimension(imageSize, imageSize);
     190        }
    165191    }
    166192
     
    354380     * @return dimension of image in pixels
    355381     * @since 7687
    356      */
     382     * @deprecated Use {@link ImageSizes#getImageDimension()} instead
     383     */
     384    @Deprecated
    357385    public static Dimension getImageSizes(ImageSizes size) {
    358         int sizeval;
    359         switch(size) {
    360         case MAPMAX: sizeval = Main.pref.getInteger("iconsize.mapmax", 48); break;
    361         case MAP: sizeval = Main.pref.getInteger("iconsize.mapmax", 16); break;
    362         case SIDEBUTTON: sizeval = Main.pref.getInteger("iconsize.sidebutton", 20); break;
    363         case TOOLBAR: /* TOOLBAR is LARGELICON - only provided in case of future changes */
    364         case POPUPMENU: /* POPUPMENU is LARGELICON - only provided in case of future changes */
    365         case LARGEICON: sizeval = Main.pref.getInteger("iconsize.largeicon", 24); break;
    366         case MENU: /* MENU is SMALLICON - only provided in case of future changes */
    367         case SMALLICON: sizeval = Main.pref.getInteger("iconsize.smallicon", 16); break;
    368         case CURSOROVERLAY: /* same as cursor - only provided in case of future changes */
    369         case CURSOR: sizeval = Main.pref.getInteger("iconsize.cursor", 32); break;
    370         case LAYER: sizeval = Main.pref.getInteger("iconsize.layer", 16); break;
    371         default: sizeval = Main.pref.getInteger("iconsize.default", 24); break;
    372         }
    373         return new Dimension(sizeval, sizeval);
     386        return (size == null ? ImageSizes.DEFAULT : size).getImageDimension();
    374387    }
    375388
     
    398411     */
    399412    public ImageProvider setSize(ImageSizes size) {
    400         return setSize(getImageSizes(size));
     413        return setSize(size.getImageDimension());
    401414    }
    402415
     
    474487     */
    475488    public ImageProvider setMaxSize(ImageSizes size) {
    476         return setMaxSize(getImageSizes(size));
     489        return setMaxSize(size.getImageDimension());
    477490    }
    478491
     
    13051318     * @since 8903
    13061319     */
    1307     public static ImageIcon getPadded(OsmPrimitive primitive, Rectangle iconSize) {
     1320    public static ImageIcon getPadded(OsmPrimitive primitive, Dimension iconSize) {
    13081321        // Check if the current styles have special icon for tagged nodes.
    13091322        if (primitive instanceof org.openstreetmap.josm.data.osm.Node) {
     
    13141327                    MapImage icon = nodeStyle.mapImage;
    13151328                    if (icon != null) {
    1316                         int backgroundWidth = iconSize.height;
     1329                        int backgroundWidth = iconSize.width;
    13171330                        int backgroundHeight = iconSize.height;
    13181331                        int iconWidth = icon.getWidth();
     
    17691782
    17701783    /**
    1771      * Determines if the given {@code BufferedImage} has a transparent color determiend by a previous call to {@link #read}.
     1784     * Determines if the given {@code BufferedImage} has a transparent color determined by a previous call to {@link #read}.
    17721785     * @param bi The {@code BufferedImage} to test
    17731786     * @return {@code true} if {@code bi} has a transparent color determined by a previous call to {@code read}.
  • trunk/src/org/openstreetmap/josm/tools/ImageResource.java

    r9282 r9705  
    8888     */
    8989    public void getImageIcon(AbstractAction a) {
    90         ImageIcon icon = getImageIconBounded(ImageProvider.getImageSizes(ImageProvider.ImageSizes.SMALLICON));
     90        ImageIcon icon = getImageIconBounded(ImageProvider.ImageSizes.SMALLICON.getImageDimension());
    9191        a.putValue(Action.SMALL_ICON, icon);
    92         icon = getImageIconBounded(ImageProvider.getImageSizes(ImageProvider.ImageSizes.LARGEICON));
     92        icon = getImageIconBounded(ImageProvider.ImageSizes.LARGEICON.getImageDimension());
    9393        a.putValue(Action.LARGE_ICON_KEY, icon);
    9494    }
Note: See TracChangeset for help on using the changeset viewer.