Changeset 10356 in josm


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

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

Legend:

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

    r8624 r10356  
    2020        putValue(NAME, tr("Select"));
    2121        putValue(SHORT_DESCRIPTION,  tr("Set the selected elements on the map to the selected items in the list above."));
    22         putValue(SMALL_ICON, ImageProvider.get("dialogs", "select"));
     22        new ImageProvider("dialogs", "select").getResource().getImageIcon(this, true);
    2323    }
    2424}
  • 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));
  • trunk/src/org/openstreetmap/josm/gui/dialogs/CommandStackDialog.java

    r9246 r10356  
    376376            putValue(NAME, tr("Select"));
    377377            putValue(SHORT_DESCRIPTION, tr("Selects the objects that take part in this command (unless currently deleted)"));
    378             putValue(SMALL_ICON, ImageProvider.get("dialogs", "select"));
     378            new ImageProvider("dialogs", "select").getResource().getImageIcon(this, true);
    379379        }
    380380
     
    411411            putValue(SHORT_DESCRIPTION,
    412412                    tr("Selects the objects that take part in this command (unless currently deleted), then and zooms to it"));
    413             putValue(SMALL_ICON, ImageProvider.get("dialogs/autoscale", "selection"));
     413            new ImageProvider("dialogs/autoscale", "selection").getResource().getImageIcon(this, true);
    414414        }
    415415
     
    447447                putValue(NAME, tr("Undo"));
    448448                putValue(SHORT_DESCRIPTION, tr("Undo the selected and all later commands"));
    449                 putValue(SMALL_ICON, ImageProvider.get("undo"));
     449                new ImageProvider("undo").getResource().getImageIcon(this, true);
    450450            } else {
    451451                tree = redoTree;
    452452                putValue(NAME, tr("Redo"));
    453453                putValue(SHORT_DESCRIPTION, tr("Redo the selected and all earlier commands"));
    454                 putValue(SMALL_ICON, ImageProvider.get("redo"));
     454                new ImageProvider("redo").getResource().getImageIcon(this, true);
    455455            }
    456456        }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ConflictDialog.java

    r10332 r10356  
    434434            putValue(NAME, tr("Resolve"));
    435435            putValue(SHORT_DESCRIPTION,  tr("Open a merge dialog of all selected items in the list above."));
    436             putValue(SMALL_ICON, ImageProvider.get("dialogs", "conflict"));
     436            new ImageProvider("dialogs", "conflict").getResource().getImageIcon(this, true);
    437437            putValue("help", ht("/Dialog/ConflictList#ResolveAction"));
    438438        }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/FilterDialog.java

    r10250 r10356  
    141141                putValue(NAME, tr("Add"));
    142142                putValue(SHORT_DESCRIPTION,  tr("Add filter."));
    143                 putValue(SMALL_ICON, ImageProvider.get("dialogs", "add"));
     143                new ImageProvider("dialogs", "add").getResource().getImageIcon(this, true);
    144144            }
    145145
     
    156156                putValue(NAME, tr("Edit"));
    157157                putValue(SHORT_DESCRIPTION, tr("Edit filter."));
    158                 putValue(SMALL_ICON, ImageProvider.get("dialogs", "edit"));
     158                new ImageProvider("dialogs", "edit").getResource().getImageIcon(this, true);
    159159            }
    160160
     
    174174                putValue(NAME, tr("Delete"));
    175175                putValue(SHORT_DESCRIPTION, tr("Delete filter."));
    176                 putValue(SMALL_ICON, ImageProvider.get("dialogs", "delete"));
     176                new ImageProvider("dialogs", "delete").getResource().getImageIcon(this, true);
    177177            }
    178178
     
    189189                putValue(NAME, tr("Up"));
    190190                putValue(SHORT_DESCRIPTION, tr("Move filter up."));
    191                 putValue(SMALL_ICON, ImageProvider.get("dialogs", "up"));
     191                new ImageProvider("dialogs", "up").getResource().getImageIcon(this, true);
    192192            }
    193193
     
    205205                putValue(NAME, tr("Down"));
    206206                putValue(SHORT_DESCRIPTION, tr("Move filter down."));
    207                 putValue(SMALL_ICON, ImageProvider.get("dialogs", "down"));
     207                new ImageProvider("dialogs", "down").getResource().getImageIcon(this, true);
    208208            }
    209209
  • trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java

    r10332 r10356  
    299299            putValue(NAME, tr("Search"));
    300300            putValue(SHORT_DESCRIPTION,   tr("Search for objects"));
    301             putValue(SMALL_ICON, ImageProvider.get("dialogs", "search"));
     301            new ImageProvider("dialogs", "search").getResource().getImageIcon(this, true);
    302302            updateEnabledState();
    303303        }
     
    361361            putValue(NAME, tr("History"));
    362362            putValue(SHORT_DESCRIPTION, tr("Display the history of the selected objects."));
    363             putValue(SMALL_ICON, ImageProvider.get("dialogs", "history"));
     363            new ImageProvider("dialogs", "history").getResource().getImageIcon(this, true);
    364364            updateEnabledState(model.getSize());
    365365        }
     
    401401            putValue(NAME, tr("Zoom to selection"));
    402402            putValue(SHORT_DESCRIPTION, tr("Zoom to selection"));
    403             putValue(SMALL_ICON, ImageProvider.get("dialogs/autoscale", "selection"));
     403            new ImageProvider("dialogs/autoscale", "selection").getResource().getImageIcon(this, true);
    404404            updateEnabledState();
    405405        }
     
    442442            putValue(NAME, tr("Zoom to selected element(s)"));
    443443            putValue(SHORT_DESCRIPTION, tr("Zoom to selected element(s)"));
    444             putValue(SMALL_ICON, ImageProvider.get("dialogs/autoscale", "selection"));
     444            new ImageProvider("dialogs/autoscale", "selection").getResource().getImageIcon(this, true);
    445445            updateEnabledState();
    446446        }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/UserListDialog.java

    r10345 r10356  
    158158            putValue(NAME, tr("Select"));
    159159            putValue(SHORT_DESCRIPTION, tr("Select objects submitted by this user"));
    160             putValue(SMALL_ICON, ImageProvider.get("dialogs", "select"));
     160            new ImageProvider("dialogs", "select").getResource().getImageIcon(this, true);
    161161            updateEnabledState();
    162162        }
     
    193193            putValue(NAME, tr("Show info"));
    194194            putValue(SHORT_DESCRIPTION, tr("Launches a browser with information about the user"));
    195             putValue(SMALL_ICON, ImageProvider.get("help/internet"));
     195            new ImageProvider("help/internet").getResource().getImageIcon(this, true);
    196196            updateEnabledState();
    197197        }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ValidatorDialog.java

    r10345 r10356  
    120120                putValue(NAME, tr("Lookup"));
    121121                putValue(SHORT_DESCRIPTION, tr("Looks up the selected primitives in the error list."));
    122                 putValue(SMALL_ICON, ImageProvider.get("dialogs", "search"));
     122                new ImageProvider("dialogs", "search").getResource().getImageIcon(this, true);
    123123            }
    124124
     
    141141                putValue(NAME, tr("Fix"));
    142142                putValue(SHORT_DESCRIPTION,  tr("Fix the selected issue."));
    143                 putValue(SMALL_ICON, ImageProvider.get("dialogs", "fix"));
     143                new ImageProvider("dialogs", "fix").getResource().getImageIcon(this, true);
    144144            }
    145145            @Override
     
    156156                    putValue(NAME, tr("Ignore"));
    157157                    putValue(SHORT_DESCRIPTION,  tr("Ignore the selected issue next time."));
    158                     putValue(SMALL_ICON, ImageProvider.get("dialogs", "fix"));
     158                    new ImageProvider("dialogs", "fix").getResource().getImageIcon(this, true);
    159159                }
    160160                @Override
  • trunk/src/org/openstreetmap/josm/gui/help/ContextSensitiveHelpAction.java

    r7434 r10356  
    4747        putValue(SHORT_DESCRIPTION, tr("Show help information"));
    4848        putValue(NAME, tr("Help"));
    49         putValue(SMALL_ICON, ImageProvider.get("help"));
     49        new ImageProvider("help").getResource().getImageIcon(this);
    5050        this.helpTopic = helpTopic;
    5151        setEnabled(!Main.isOffline(OnlineResource.JOSM_WEBSITE));
  • trunk/src/org/openstreetmap/josm/tools/ImageResource.java

    r9705 r10356  
    9292        icon = getImageIconBounded(ImageProvider.ImageSizes.LARGEICON.getImageDimension());
    9393        a.putValue(Action.LARGE_ICON_KEY, icon);
     94        a.putValue("ImageResource", this);
     95    }
     96
     97    /**
     98     * Set both icons of an Action
     99     * @param a The action for the icons
     100     * @param addresource Adds an resource named "ImageResource" if <code>true</code>
     101     * @since 10356
     102     */
     103    public void getImageIcon(AbstractAction a, boolean addresource) {
     104        getImageIcon(a);
     105        if (addresource) {
     106            a.putValue("ImageResource", this);
     107        }
    94108    }
    95109
Note: See TracChangeset for help on using the changeset viewer.