Changeset 13187 in josm
- Timestamp:
- 2017-12-03T12:55:45+01:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/SideButton.java
r12620 r13187 20 20 import org.openstreetmap.josm.tools.ImageProvider; 21 21 import org.openstreetmap.josm.tools.ImageResource; 22 import org.openstreetmap.josm.tools.JosmRuntimeException; 22 23 import org.openstreetmap.josm.tools.Logging; 23 24 … … 33 34 * Constructs a new {@code SideButton}. 34 35 * @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 35 38 * @since 744 36 39 */ … … 41 44 setIcon(icon.getImageIconBounded( 42 45 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"); 46 48 } 47 49 doStyle(); … … 71 73 setIcon(ImageProvider.get("dialogs", imagename, ImageProvider.ImageSizes.SIDEBUTTON)); 72 74 doStyle(); 73 }74 75 /**76 * Fix icon size77 * @param action the action78 * @deprecated This method is old style and will be removed together with the removal79 * of old constructor code80 */81 @Deprecated82 private void fixIcon(Action action) {83 // need to listen for changes, so that putValue() that are called after the84 // SideButton is constructed get the proper icon size85 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 }101 75 } 102 76
Note:
See TracChangeset
for help on using the changeset viewer.