Ticket #9995: patch_4_images_progress.patch

File patch_4_images_progress.patch, 10.2 KB (added by anonymous, 18 months ago)
  • src/org/openstreetmap/josm/gui/MainFrame.java

     
    9090
    9191        setJMenuBar(menu);
    9292        geometry.applySafe(this);
    93         List<Image> l = new LinkedList<>();
    94         l.add(ImageProvider.get("logo_16x16x32").getImage());
    95         l.add(ImageProvider.get("logo_16x16x8").getImage());
    96         l.add(ImageProvider.get("logo_32x32x32").getImage());
    97         l.add(ImageProvider.get("logo_32x32x8").getImage());
    98         l.add(ImageProvider.get("logo_48x48x32").getImage());
    99         l.add(ImageProvider.get("logo_48x48x8").getImage());
    100         l.add(ImageProvider.get("logo").getImage());
    101         setIconImages(l);
     93        List<Image> appIcons = new LinkedList<>();
     94        appIcons.add(new ImageProvider("logo_16x16x32").getSourceImage());
     95        appIcons.add(new ImageProvider("logo_16x16x8").getSourceImage());
     96        appIcons.add(new ImageProvider("logo_32x32x32").getSourceImage());
     97        appIcons.add(new ImageProvider("logo_32x32x8").getSourceImage());
     98        appIcons.add(new ImageProvider("logo_48x48x32").getSourceImage());
     99        appIcons.add(new ImageProvider("logo_48x48x8").getSourceImage());
     100        appIcons.add(new ImageProvider("logo").getSourceImage());
     101        setIconImages(appIcons);
    102102        addWindowListener(new WindowAdapter() {
    103103            @Override
    104104            public void windowClosing(final WindowEvent arg0) {
  • src/org/openstreetmap/josm/gui/io/SaveLayersDialog.java

     
    77import java.awt.BorderLayout;
    88import java.awt.Component;
    99import java.awt.Dimension;
    10 import java.awt.Graphics2D;
    1110import java.awt.GraphicsEnvironment;
    1211import java.awt.GridBagConstraints;
    1312import java.awt.GridBagLayout;
    14 import java.awt.Image;
    1513import java.awt.event.ActionEvent;
    1614import java.awt.event.WindowAdapter;
    1715import java.awt.event.WindowEvent;
    18 import java.awt.image.BufferedImage;
    1916import java.beans.PropertyChangeEvent;
    2017import java.beans.PropertyChangeListener;
    2118import java.util.List;
     
    2724
    2825import javax.swing.AbstractAction;
    2926import javax.swing.DefaultListCellRenderer;
    30 import javax.swing.ImageIcon;
    3127import javax.swing.JButton;
    3228import javax.swing.JComponent;
    3329import javax.swing.JDialog;
     
    5147import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    5248import org.openstreetmap.josm.gui.progress.SwingRenderingProgressMonitor;
    5349import org.openstreetmap.josm.gui.util.GuiHelper;
     50import org.openstreetmap.josm.tools.EmptyImageProvider;
    5451import org.openstreetmap.josm.tools.GBC;
    5552import org.openstreetmap.josm.tools.ImageProvider;
     53import org.openstreetmap.josm.tools.ImageOverlay;
    5654import org.openstreetmap.josm.tools.UserCancelException;
    5755import org.openstreetmap.josm.tools.Utils;
    5856import org.openstreetmap.josm.tools.WindowGeometry;
     
    379377    }
    380378
    381379    final class SaveAndProceedAction extends AbstractAction implements PropertyChangeListener {
    382         private static final int ICON_SIZE = 24;
    383380        private static final String BASE_ICON = "BASE_ICON";
    384         private final transient Image save = ImageProvider.get("save").getImage();
    385         private final transient Image upld = ImageProvider.get("upload").getImage();
    386         private final transient Image saveDis = new ImageProvider("save").setDisabled(true).get().getImage();
    387         private final transient Image upldDis = new ImageProvider("upload").setDisabled(true).get().getImage();
     381        private final transient ImageProvider saveImage = new ImageProvider("save");
     382        private final transient ImageProvider uploadImage = new ImageProvider("upload");
    388383
    389384        SaveAndProceedAction() {
    390385            initForSaveAndExit();
     
    393388        public void initForSaveAndExit() {
    394389            putValue(NAME, tr("Perform actions before exiting"));
    395390            putValue(SHORT_DESCRIPTION, tr("Exit JOSM with saving. Unsaved changes are uploaded and/or saved."));
    396             putValue(BASE_ICON, ImageProvider.get("exit"));
     391            putValue(BASE_ICON, new ImageProvider("exit"));
    397392            redrawIcon();
    398393        }
    399394
     
    400395        public void initForSaveAndDelete() {
    401396            putValue(NAME, tr("Perform actions before deleting"));
    402397            putValue(SHORT_DESCRIPTION, tr("Save/Upload layers before deleting. Unsaved changes are not lost."));
    403             putValue(BASE_ICON, ImageProvider.get("dialogs", "delete"));
     398            putValue(BASE_ICON, new ImageProvider("dialogs", "delete"));
    404399            redrawIcon();
    405400        }
    406401
    407402        public void redrawIcon() {
    408             Image base = ((ImageIcon) getValue(BASE_ICON)).getImage();
    409             BufferedImage newIco = new BufferedImage(ICON_SIZE*3, ICON_SIZE, BufferedImage.TYPE_4BYTE_ABGR);
    410             Graphics2D g = newIco.createGraphics();
     403            ImageProvider firstIcon = uploadImage.setDisabled( model.getLayersToUpload().isEmpty() );
     404            ImageProvider secondIcon = saveImage.setDisabled( model.getLayersToSave().isEmpty() );
     405            ImageProvider thirdIcon = (ImageProvider)getValue(BASE_ICON);
     406
     407            int iconWidth = ImageProvider.ImageSizes.LARGEICON.getVirtualWidth() * 3;
     408            int iconHeight = ImageProvider.ImageSizes.LARGEICON.getVirtualHeight();
     409            final ImageProvider imageProvider = new EmptyImageProvider(iconWidth, iconHeight);
     410
    411411            // CHECKSTYLE.OFF: SingleSpaceSeparator
    412             g.drawImage(model.getLayersToUpload().isEmpty() ? upldDis : upld, ICON_SIZE*0, 0, ICON_SIZE, ICON_SIZE, null);
    413             g.drawImage(model.getLayersToSave().isEmpty()   ? saveDis : save, ICON_SIZE*1, 0, ICON_SIZE, ICON_SIZE, null);
    414             g.drawImage(base,                                                 ICON_SIZE*2, 0, ICON_SIZE, ICON_SIZE, null);
     412            imageProvider.addOverlay(new ImageOverlay(firstIcon,  0,     0, 1f/3f, 1));
     413            imageProvider.addOverlay(new ImageOverlay(secondIcon, 1f/3f, 0, 2f/3f, 1));
     414            imageProvider.addOverlay(new ImageOverlay(thirdIcon,  2f/3f, 0,     1, 1));
    415415            // CHECKSTYLE.ON: SingleSpaceSeparator
    416             putValue(SMALL_ICON, new ImageIcon(newIco));
     416
     417            putValue(SMALL_ICON, imageProvider.get());
    417418        }
    418419
    419420        @Override
  • src/org/openstreetmap/josm/tools/ImageProvider.java

     
    680680    }
    681681
    682682    /**
     683     * Get source image without processing (no scaling, no disabling, no layering).
     684     * SVG source is raseterized without scaling.
     685     *
     686     * @return original image or rasterized SVG
     687     */
     688    public Image getSourceImage() {
     689        final ImageResource imageResource = getResource();
     690        if(imageResource == null) return null;
     691
     692        return imageResource.getSourceImage();
     693    }
     694
     695    /**
    683696     * Load the image in a background thread.
    684697     *
    685698     * This method returns immediately and runs the image request
     
    783796    }
    784797
    785798    /**
     799     * Create an empty image with a given size.
     800     *
     801     * @param width target image width
     802     * @param height target image height
     803     * @return The requested Image.
     804     */
     805    public static Image getEmptyImage(int width, int height) {
     806        return new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
     807    }
     808
     809    /**
    786810     * Load an image with a given file name, but do not throw an exception
    787811     * when the image cannot be found.
    788812     *
  • src/org/openstreetmap/josm/tools/ImageResource.java

     
    6060     */
    6161    public ImageResource(Image img) {
    6262        CheckParameterUtil.ensureParameterNotNull(img);
    63         baseImage = scaleBaseImageIfNeeded(img);
     63        baseImage = img;
    6464    }
    6565
    66     /** Scale image according to screen DPI if needed.
    67      *
    68      * @param img an image loaded from file (it's width and height are virtual pixels)
    69      * @return original img if virtual size is the same as real size or new image resized to real pixels
    70      */
    71     private static Image scaleBaseImageIfNeeded(Image img) {
    72         int imgWidth = img.getWidth(null);
    73         int imgHeight = img.getHeight(null);
    74         int realWidth = GuiSizesHelper.getSizeDpiAdjusted(imgWidth);
    75         int realHeight = GuiSizesHelper.getSizeDpiAdjusted(imgHeight);
    76         if (realWidth != -1 && realHeight != -1 && imgWidth != realWidth && imgHeight != realHeight) {
    77             Image realImage = img.getScaledInstance(realWidth, realHeight, Image.SCALE_SMOOTH);
    78             BufferedImage bimg = new BufferedImage(realWidth, realHeight, BufferedImage.TYPE_INT_ARGB);
    79             bimg.getGraphics().drawImage(realImage, 0, 0, null);
    80             return bimg;
    81         }
    82         return img;
    83     }
    84 
    8566    /**
    8667     * Constructs a new {@code ImageResource} from SVG data.
    8768     * @param svg SVG data
     
    152133    }
    153134
    154135    /**
     136     * Get source image without processing (no scaling, no disabling, no layering).
     137     * SVG source is raseterized without scaling.
     138     *
     139     * @return base image or rasterized base SVG
     140     */
     141    public Image getSourceImage() {
     142        if (baseImage != null) {
     143            return baseImage;
     144        }
     145        if(svg != null) {
     146            Dimension sourceDimension = new Dimension((int) svg.getWidth(), (int) svg.getHeight());
     147            return ImageProvider.createImageFromSvg(svg, sourceDimension);
     148        }
     149        throw new IllegalArgumentException("Empty image data");
     150    }
     151
     152    /**
    155153     * Get an ImageIcon object for the image of this resource
    156154     * @param  dim The requested dimensions. Use (-1,-1) for the original size and (width, -1)
    157155     *         to set the width, but otherwise scale the image proportionally.