Changeset 18099 in josm for trunk/src


Ignore:
Timestamp:
2021-08-01T19:40:15+02:00 (3 years ago)
Author:
Don-vip
Message:

fix #21176 - fix icon sizes of save layers dialog

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

Legend:

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

    r13864 r18099  
    3636    public SideButton(Action action) {
    3737        super(action);
    38         ImageResource icon = (ImageResource) action.getValue("ImageResource");
     38        ImageResource icon = ImageResource.getAttachedImageResource(action);
    3939        if (icon != null) {
    4040            setIcon(icon.getImageIconBounded(
  • trunk/src/org/openstreetmap/josm/gui/io/SaveLayersDialog.java

    r17733 r18099  
    1212import java.awt.GridBagConstraints;
    1313import java.awt.GridBagLayout;
    14 import java.awt.Image;
    1514import java.awt.event.ActionEvent;
    1615import java.awt.event.WindowAdapter;
     
    5554import org.openstreetmap.josm.tools.GBC;
    5655import org.openstreetmap.josm.tools.ImageProvider;
     56import org.openstreetmap.josm.tools.ImageProvider.ImageSizes;
     57import org.openstreetmap.josm.tools.ImageResource;
    5758import org.openstreetmap.josm.tools.InputMapUtils;
    5859import org.openstreetmap.josm.tools.Logging;
     
    451452
    452453    final class SaveAndProceedAction extends AbstractAction implements PropertyChangeListener {
    453         private static final int ICON_SIZE = 24;
    454         private static final String BASE_ICON = "BASE_ICON";
    455         private final transient Image save = getImage("save", false);
    456         private final transient Image upld = getImage("upload", false);
    457         private final transient Image saveDis = getImage("save", true);
    458         private final transient Image upldDis = getImage("upload", true);
     454
     455        private ImageResource actionImg = null;
    459456
    460457        SaveAndProceedAction() {
     
    462459        }
    463460
    464         Image getImage(String name, boolean disabled) {
    465             ImageIcon img = new ImageProvider(name).setDisabled(disabled).setOptional(true).get();
    466             return img != null ? img.getImage() : null;
     461        ImageResource getImage(String name, boolean disabled) {
     462            return new ImageProvider(name).setDisabled(disabled).setOptional(true).getResource();
    467463        }
    468464
     
    472468                    putValue(NAME, tr("Perform actions before exiting"));
    473469                    putValue(SHORT_DESCRIPTION, tr("Exit JOSM with saving. Unsaved changes are uploaded and/or saved."));
    474                     putValue(BASE_ICON, ImageProvider.getIfAvailable("exit"));
     470                    actionImg = new ImageProvider("exit").getResource();
    475471                    break;
    476472                case RESTART:
    477473                    putValue(NAME, tr("Perform actions before restarting"));
    478474                    putValue(SHORT_DESCRIPTION, tr("Restart JOSM with saving. Unsaved changes are uploaded and/or saved."));
    479                     putValue(BASE_ICON, ImageProvider.getIfAvailable("restart"));
     475                    actionImg = new ImageProvider("restart").getResource();
    480476                    break;
    481477                case DELETE:
    482478                    putValue(NAME, tr("Perform actions before deleting"));
    483479                    putValue(SHORT_DESCRIPTION, tr("Save/Upload layers before deleting. Unsaved changes are not lost."));
    484                     putValue(BASE_ICON, ImageProvider.getIfAvailable("dialogs", "delete"));
     480                    actionImg = new ImageProvider("dialogs", "delete").getResource();
    485481                    break;
    486482            }
     
    489485
    490486        public void redrawIcon() {
    491             ImageIcon base = ((ImageIcon) getValue(BASE_ICON));
    492             BufferedImage newIco = new BufferedImage(ICON_SIZE*3, ICON_SIZE, BufferedImage.TYPE_4BYTE_ABGR);
     487            ImageResource uploadImg = model.getLayersToUpload().isEmpty() ? getImage("upload", true) : getImage("upload", false);
     488            ImageResource saveImg = model.getLayersToSave().isEmpty() ? getImage("save", true) : getImage("save", false);
     489            attachImageIcon(SMALL_ICON, ImageSizes.SMALLICON, uploadImg, saveImg, actionImg);
     490            attachImageIcon(LARGE_ICON_KEY, ImageSizes.LARGEICON, uploadImg, saveImg, actionImg);
     491        }
     492
     493        private void attachImageIcon(String key, ImageSizes size, ImageResource uploadImg, ImageResource saveImg, ImageResource actionImg) {
     494            Dimension dim = size.getImageDimension();
     495            BufferedImage newIco = new BufferedImage((int) dim.getWidth()*3, (int) dim.getHeight(), BufferedImage.TYPE_4BYTE_ABGR);
    493496            Graphics2D g = newIco.createGraphics();
    494             // CHECKSTYLE.OFF: SingleSpaceSeparator
    495             g.drawImage(model.getLayersToUpload().isEmpty() ? upldDis : upld, ICON_SIZE*0, 0, ICON_SIZE, ICON_SIZE, null);
    496             g.drawImage(model.getLayersToSave().isEmpty()   ? saveDis : save, ICON_SIZE*1, 0, ICON_SIZE, ICON_SIZE, null);
    497             if (base != null) {
    498                 g.drawImage(base.getImage(),                                  ICON_SIZE*2, 0, ICON_SIZE, ICON_SIZE, null);
    499             }
    500             // CHECKSTYLE.ON: SingleSpaceSeparator
    501             putValue(SMALL_ICON, new ImageIcon(newIco));
     497            drawImageIcon(g, 0, dim, uploadImg);
     498            drawImageIcon(g, 1, dim, saveImg);
     499            drawImageIcon(g, 2, dim, actionImg);
     500            putValue(key, new ImageIcon(newIco));
     501        }
     502
     503        private void drawImageIcon(Graphics2D g, int index, Dimension dim, ImageResource img) {
     504            if (img != null) {
     505                g.drawImage(img.getImageIcon(dim).getImage(), (int) dim.getWidth()*index, 0, (int) dim.getWidth(), (int) dim.getHeight(), null);
     506            }
    502507        }
    503508
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java

    r17662 r18099  
    221221    }
    222222
     223    /**
     224     * Returns the {@link ImageResource} attached to this preset, if any.
     225     * @return the {@code ImageResource} attached to this preset, or {@code null}
     226     * @since 16060
     227     */
    223228    public final ImageResource getImageResource() {
    224         return (ImageResource) getValue("ImageResource");
     229        return ImageResource.getAttachedImageResource(this);
    225230    }
    226231
  • trunk/src/org/openstreetmap/josm/tools/ImageResource.java

    r17827 r18099  
    1515import javax.swing.JPanel;
    1616import javax.swing.UIManager;
     17
     18import org.openstreetmap.josm.tools.ImageProvider.ImageSizes;
    1719
    1820import com.kitfox.svg.SVGDiagram;
     
    101103     */
    102104    public void attachImageIcon(AbstractAction a) {
    103         Dimension iconDimension = ImageProvider.ImageSizes.SMALLICON.getImageDimension();
    104         ImageIcon icon = getImageIcon(iconDimension);
    105         a.putValue(Action.SMALL_ICON, icon);
    106 
    107         iconDimension = ImageProvider.ImageSizes.LARGEICON.getImageDimension();
    108         icon = getImageIcon(iconDimension);
    109         a.putValue(Action.LARGE_ICON_KEY, icon);
     105        a.putValue(Action.SMALL_ICON, getImageIcon(ImageSizes.SMALLICON.getImageDimension()));
     106        a.putValue(Action.LARGE_ICON_KEY, getImageIcon(ImageSizes.LARGEICON.getImageDimension()));
    110107    }
    111108
     
    121118            a.putValue("ImageResource", this);
    122119        }
     120    }
     121
     122    /**
     123     * Returns the {@code ImageResource} attached to the given action, if any.
     124     * @param a action
     125     * @return the {@code ImageResource} attached to the given action, or {@code null}
     126     * @since 18099
     127     */
     128    public static ImageResource getAttachedImageResource(Action a) {
     129        return (ImageResource) a.getValue("ImageResource");
    123130    }
    124131
Note: See TracChangeset for help on using the changeset viewer.