Ignore:
Timestamp:
2016-06-12T00:00:29+02:00 (8 years ago)
Author:
stoecker
Message:

see #9995, see #10684 - remove more hardcoded places of images

File:
1 edited

Legend:

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

    r10179 r10356  
    1818import javax.swing.plaf.basic.BasicArrowButton;
    1919
     20import org.openstreetmap.josm.Main;
    2021import org.openstreetmap.josm.tools.Destroyable;
    2122import org.openstreetmap.josm.tools.ImageProvider;
     23import org.openstreetmap.josm.tools.ImageResource;
    2224
    2325/**
     
    2628 */
    2729public class SideButton extends JButton implements Destroyable {
    28     private static final int iconHeight = ImageProvider.ImageSizes.SIDEBUTTON.getImageSize();
    2930
    3031    private transient PropertyChangeListener propertyChangeListener;
     
    3334     * Constructs a new {@code SideButton}.
    3435     * @param action action used to specify the new button
     36     * @since 744
    3537     */
    3638    public SideButton(Action action) {
    3739        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        }
    3948        doStyle();
    4049    }
     
    4453     * @param action action used to specify the new button
    4554     * @param usename use action name
     55     * @since 2710
    4656     */
    4757    public SideButton(Action action, boolean usename) {
     
    5868     * @param action action used to specify the new button
    5969     * @param imagename image name in "dialogs" directory
     70     * @since 2747
    6071     */
    6172    public SideButton(Action action, String imagename) {
    6273        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());
    6476        doStyle();
    6577    }
    6678
     79    @Deprecated
    6780    private void fixIcon(Action action) {
    6881        // need to listen for changes, so that putValue() that are called after the
     
    7992            action.addPropertyChangeListener(propertyChangeListener);
    8093        }
     94        int iconHeight = ImageProvider.ImageSizes.SIDEBUTTON.getImageSize();
    8195        Icon i = getIcon();
    8296        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);
    84101        }
    85102    }
    86103
    87104    /**
    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
    91106     */
    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 
    97107    private void doStyle() {
    98108        setLayout(new BorderLayout());
     
    101111    }
    102112
     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     */
    103119    public BasicArrowButton createArrow(ActionListener listener) {
    104120        setMargin(new Insets(0, 0, 0, 0));
Note: See TracChangeset for help on using the changeset viewer.