Changeset 10356 in josm for trunk/src/org/openstreetmap/josm/gui/SideButton.java
- Timestamp:
- 2016-06-12T00:00:29+02:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/SideButton.java
r10179 r10356 18 18 import javax.swing.plaf.basic.BasicArrowButton; 19 19 20 import org.openstreetmap.josm.Main; 20 21 import org.openstreetmap.josm.tools.Destroyable; 21 22 import org.openstreetmap.josm.tools.ImageProvider; 23 import org.openstreetmap.josm.tools.ImageResource; 22 24 23 25 /** … … 26 28 */ 27 29 public class SideButton extends JButton implements Destroyable { 28 private static final int iconHeight = ImageProvider.ImageSizes.SIDEBUTTON.getImageSize();29 30 30 31 private transient PropertyChangeListener propertyChangeListener; … … 33 34 * Constructs a new {@code SideButton}. 34 35 * @param action action used to specify the new button 36 * @since 744 35 37 */ 36 38 public SideButton(Action action) { 37 39 super(action); 38 fixIcon(action); 40 ImageResource icon = (ImageResource) action.getValue("ImageResource"); 41 if (icon != null) { 42 setIcon(icon.getImageIconBounded( 43 ImageProvider.ImageSizes.SIDEBUTTON.getImageDimension())); 44 } else { /* TODO: remove when calling code is fixed */ 45 Main.warn("Old style SideButton usage for action " + action); 46 fixIcon(action); 47 } 39 48 doStyle(); 40 49 } … … 44 53 * @param action action used to specify the new button 45 54 * @param usename use action name 55 * @since 2710 46 56 */ 47 57 public SideButton(Action action, boolean usename) { … … 58 68 * @param action action used to specify the new button 59 69 * @param imagename image name in "dialogs" directory 70 * @since 2747 60 71 */ 61 72 public SideButton(Action action, String imagename) { 62 73 super(action); 63 setIcon(getScaledImage(ImageProvider.get("dialogs", imagename).getImage())); 74 ImageProvider prov = new ImageProvider("dialogs", imagename); 75 setIcon(prov.setSize(ImageProvider.ImageSizes.SIDEBUTTON).get()); 64 76 doStyle(); 65 77 } 66 78 79 @Deprecated 67 80 private void fixIcon(Action action) { 68 81 // need to listen for changes, so that putValue() that are called after the … … 79 92 action.addPropertyChangeListener(propertyChangeListener); 80 93 } 94 int iconHeight = ImageProvider.ImageSizes.SIDEBUTTON.getImageSize(); 81 95 Icon i = getIcon(); 82 96 if (i instanceof ImageIcon && i.getIconHeight() != iconHeight) { 83 setIcon(getScaledImage(((ImageIcon) i).getImage())); 97 Image im = ((ImageIcon) i).getImage(); 98 int newWidth = im.getWidth(null) * iconHeight / im.getHeight(null); 99 ImageIcon icon = new ImageIcon(im.getScaledInstance(newWidth, iconHeight, Image.SCALE_SMOOTH)); 100 setIcon(icon); 84 101 } 85 102 } 86 103 87 104 /** 88 * Scales the given image proportionally so that the height is "iconHeight" 89 * @param im original image 90 * @return scaled image 105 * Do the style settings for the side button layout 91 106 */ 92 private static ImageIcon getScaledImage(Image im) {93 int newWidth = im.getWidth(null) * iconHeight / im.getHeight(null);94 return new ImageIcon(im.getScaledInstance(newWidth, iconHeight, Image.SCALE_SMOOTH));95 }96 97 107 private void doStyle() { 98 108 setLayout(new BorderLayout()); … … 101 111 } 102 112 113 /** 114 * Create the arrow for opening a drop-down menu 115 * @param listener listener to use for button actions (e.g. pressing) 116 * @return the created button 117 * @since 9668 118 */ 103 119 public BasicArrowButton createArrow(ActionListener listener) { 104 120 setMargin(new Insets(0, 0, 0, 0));
Note:
See TracChangeset
for help on using the changeset viewer.