Ignore:
Timestamp:
2017-12-03T12:55:45+01:00 (6 years ago)
Author:
stoecker
Message:

see #15310 - drop old style side button support

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/SideButton.java

    r12620 r13187  
    2020import org.openstreetmap.josm.tools.ImageProvider;
    2121import org.openstreetmap.josm.tools.ImageResource;
     22import org.openstreetmap.josm.tools.JosmRuntimeException;
    2223import org.openstreetmap.josm.tools.Logging;
    2324
     
    3334     * Constructs a new {@code SideButton}.
    3435     * @param action action used to specify the new button
     36     * an icon must be provided with {@link ImageResource#attachImageIcon(AbstractAction this, boolean true)}
     37     * @throws IllegalArgumentException if no icon provided
    3538     * @since 744
    3639     */
     
    4144            setIcon(icon.getImageIconBounded(
    4245                ImageProvider.ImageSizes.SIDEBUTTON.getImageDimension()));
    43         } else if (getIcon() != null) { /* TODO: remove when calling code is fixed, replace by exception */
    44             Logging.warn("Old style SideButton usage for action " + action);
    45             fixIcon(action);
     46        } else {
     47            throw new IllegalArgumentException("No icon provided");
    4648        }
    4749        doStyle();
     
    7173        setIcon(ImageProvider.get("dialogs", imagename, ImageProvider.ImageSizes.SIDEBUTTON));
    7274        doStyle();
    73     }
    74 
    75     /**
    76      * Fix icon size
    77      * @param action the action
    78      * @deprecated This method is old style and will be removed together with the removal
    79      * of old constructor code
    80      */
    81     @Deprecated
    82     private void fixIcon(Action action) {
    83         // need to listen for changes, so that putValue() that are called after the
    84         // SideButton is constructed get the proper icon size
    85         if (action != null) {
    86             propertyChangeListener = evt -> {
    87                 if (Action.SMALL_ICON.equals(evt.getPropertyName())) {
    88                     fixIcon(null);
    89                 }
    90             };
    91             action.addPropertyChangeListener(propertyChangeListener);
    92         }
    93         int iconHeight = ImageProvider.ImageSizes.SIDEBUTTON.getImageDimension().height;
    94         Icon i = getIcon();
    95         if (i instanceof ImageIcon && i.getIconHeight() != iconHeight) {
    96             Image im = ((ImageIcon) i).getImage();
    97             int newWidth = im.getWidth(null) * iconHeight / im.getHeight(null);
    98             ImageIcon icon = new ImageIcon(im.getScaledInstance(newWidth, iconHeight, Image.SCALE_SMOOTH));
    99             setIcon(icon);
    100         }
    10175    }
    10276
Note: See TracChangeset for help on using the changeset viewer.