Ticket #9995: hidpi_patch_3_images_progress.patch

File hidpi_patch_3_images_progress.patch, 22.1 KB (added by strump, 16 months ago)
  • src/org/openstreetmap/josm/actions/AboutAction.java

     
    102102        // Intermediate panel to allow proper optionPane resizing
    103103        JPanel panel = new JPanel(new GridBagLayout());
    104104        panel.setPreferredSize(new Dimension(890, 300));
    105         panel.add(new JLabel("", new ImageProvider("logo.svg").setSize(ImageProvider.ImageSizes.ABOUT_LOGO).get(),
     105        panel.add(new JLabel("", ImageProvider.get("logo.svg", ImageProvider.ImageSizes.ABOUT_LOGO),
    106106                JLabel.CENTER), GBC.std().insets(0, 5, 0, 0));
    107107        panel.add(about, GBC.std().fill());
    108108
  • src/org/openstreetmap/josm/actions/mapmode/AddNoteAction.java

     
    6969        Main.map.selectMapMode(Main.map.mapModeSelect);
    7070
    7171        NoteInputDialog dialog = new NoteInputDialog(Main.parent, tr("Create new note"), tr("Create note"));
    72         dialog.showNoteDialog(tr("Enter a detailed comment to create a note"), NotesDialog.ICON_NEW);
     72        dialog.showNoteDialog(tr("Enter a detailed comment to create a note"), ImageProvider.get("dialogs/notes", "note_new"));
    7373
    7474        if (dialog.getValue() != 1) {
    7575            Main.debug("User aborted note creation");
  • src/org/openstreetmap/josm/gui/SideButton.java

     
    5555     * @since 2710
    5656     */
    5757    public SideButton(Action action, boolean usename) {
    58         super(action);
     58        this(action);
    5959        if (!usename) {
    6060            setText(null);
    61             fixIcon(action);
    62             doStyle();
    6361        }
    6462    }
    6563
     
    7169     */
    7270    public SideButton(Action action, String imagename) {
    7371        super(action);
    74         ImageProvider prov = new ImageProvider("dialogs", imagename);
    75         setIcon(prov.setSize(ImageProvider.ImageSizes.SIDEBUTTON).get());
     72        setIcon(ImageProvider.get("dialogs", imagename, ImageProvider.ImageSizes.SIDEBUTTON));
    7673        doStyle();
    7774    }
    7875
  • src/org/openstreetmap/josm/gui/SplashScreen.java

     
    6767        contentPane.add(innerContentPane);
    6868
    6969        // Add the logo
    70         JLabel logo = new JLabel(new ImageProvider("logo.svg").setSize(ImageProvider.ImageSizes.SPLASH_LOGO).get());
     70        JLabel logo = new JLabel(ImageProvider.get("logo.svg", ImageProvider.ImageSizes.SPLASH_LOGO));
    7171        GridBagConstraints gbc = new GridBagConstraints();
    7272        gbc.gridheight = 2;
    7373        gbc.insets = new Insets(0, 0, 0, 70);
  • src/org/openstreetmap/josm/gui/dialogs/NotesDialog.java

     
    55
    66import java.awt.BorderLayout;
    77import java.awt.Component;
    8 import java.awt.Image;
    98import java.awt.event.ActionEvent;
    109import java.awt.event.MouseAdapter;
    1110import java.awt.event.MouseEvent;
     
    5655 */
    5756public class NotesDialog extends ToggleDialog implements LayerChangeListener {
    5857
    59     /** Small icon size for use in graphics calculations */
    60     public static final int ICON_SMALL_SIZE = 16;
    61     /** 24x24 icon for unresolved notes */
    62     public static final ImageIcon ICON_OPEN = ImageProvider.get("dialogs/notes", "note_open");
    63     /** 16x16 icon for unresolved notes */
    64     public static final ImageIcon ICON_OPEN_SMALL =
    65             new ImageIcon(ICON_OPEN.getImage().getScaledInstance(ICON_SMALL_SIZE, ICON_SMALL_SIZE, Image.SCALE_SMOOTH));
    66     /** 24x24 icon for resolved notes */
    67     public static final ImageIcon ICON_CLOSED = ImageProvider.get("dialogs/notes", "note_closed");
    68     /** 16x16 icon for resolved notes */
    69     public static final ImageIcon ICON_CLOSED_SMALL =
    70             new ImageIcon(ICON_CLOSED.getImage().getScaledInstance(ICON_SMALL_SIZE, ICON_SMALL_SIZE, Image.SCALE_SMOOTH));
    71     /** 24x24 icon for new notes */
    72     public static final ImageIcon ICON_NEW = ImageProvider.get("dialogs/notes", "note_new");
    73     /** 16x16 icon for new notes */
    74     public static final ImageIcon ICON_NEW_SMALL =
    75             new ImageIcon(ICON_NEW.getImage().getScaledInstance(ICON_SMALL_SIZE, ICON_SMALL_SIZE, Image.SCALE_SMOOTH));
    76     /** Icon for note comments */
    77     public static final ImageIcon ICON_COMMENT = ImageProvider.get("dialogs/notes", "note_comment");
    78 
    7958    private NoteTableModel model;
    8059    private JList<Note> displayList;
    8160    private final AddCommentAction addCommentAction;
     
    256235                }
    257236                ImageIcon icon;
    258237                if (note.getId() < 0) {
    259                     icon = ICON_NEW_SMALL;
     238                    icon = ImageProvider.get("dialogs/notes", "note_new", ImageProvider.ImageSizes.SMALLICON);
    260239                } else if (note.getState() == State.CLOSED) {
    261                     icon = ICON_CLOSED_SMALL;
     240                    icon = ImageProvider.get("dialogs/notes", "note_closed", ImageProvider.ImageSizes.SMALLICON);
    262241                } else {
    263                     icon = ICON_OPEN_SMALL;
     242                    icon = ImageProvider.get("dialogs/notes", "note_open", ImageProvider.ImageSizes.SMALLICON);
    264243                }
    265244                jlabel.setIcon(icon);
    266245            }
     
    312291        AddCommentAction() {
    313292            putValue(SHORT_DESCRIPTION, tr("Add comment"));
    314293            putValue(NAME, tr("Comment"));
    315             putValue(SMALL_ICON, ICON_COMMENT);
     294            putValue(SMALL_ICON, ImageProvider.get("dialogs/notes", "note_comment"));
    316295        }
    317296
    318297        @Override
     
    326305                return;
    327306            }
    328307            NoteInputDialog dialog = new NoteInputDialog(Main.parent, tr("Comment on note"), tr("Add comment"));
    329             dialog.showNoteDialog(tr("Add comment to note:"), NotesDialog.ICON_COMMENT);
     308            dialog.showNoteDialog(tr("Add comment to note:"), ImageProvider.get("dialogs/notes", "note_comment"));
    330309            if (dialog.getValue() != 1) {
    331310                return;
    332311            }
     
    344323        CloseAction() {
    345324            putValue(SHORT_DESCRIPTION, tr("Close note"));
    346325            putValue(NAME, tr("Close"));
    347             putValue(SMALL_ICON, ICON_CLOSED);
     326            putValue(SMALL_ICON, ImageProvider.get("dialogs/notes", "note_closed"));
    348327        }
    349328
    350329        @Override
    351330        public void actionPerformed(ActionEvent e) {
    352331            NoteInputDialog dialog = new NoteInputDialog(Main.parent, tr("Close note"), tr("Close note"));
    353             dialog.showNoteDialog(tr("Close note with message:"), NotesDialog.ICON_CLOSED);
     332            dialog.showNoteDialog(tr("Close note with message:"), ImageProvider.get("dialogs/notes", "note_closed"));
    354333            if (dialog.getValue() != 1) {
    355334                return;
    356335            }
     
    369348        NewAction() {
    370349            putValue(SHORT_DESCRIPTION, tr("Create a new note"));
    371350            putValue(NAME, tr("Create"));
    372             putValue(SMALL_ICON, ICON_NEW);
     351            putValue(SMALL_ICON, ImageProvider.get("dialogs/notes", "note_new"));
    373352        }
    374353
    375354        @Override
     
    389368        ReopenAction() {
    390369            putValue(SHORT_DESCRIPTION, tr("Reopen note"));
    391370            putValue(NAME, tr("Reopen"));
    392             putValue(SMALL_ICON, ICON_OPEN);
     371            putValue(SMALL_ICON, ImageProvider.get("dialogs/notes", "note_open"));
    393372        }
    394373
    395374        @Override
    396375        public void actionPerformed(ActionEvent e) {
    397376            NoteInputDialog dialog = new NoteInputDialog(Main.parent, tr("Reopen note"), tr("Reopen note"));
    398             dialog.showNoteDialog(tr("Reopen note with message:"), NotesDialog.ICON_OPEN);
     377            dialog.showNoteDialog(tr("Reopen note with message:"), ImageProvider.get("dialogs/notes", "note_open"));
    399378            if (dialog.getValue() != 1) {
    400379                return;
    401380            }
  • src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java

     
    506506            add(lblMinimized);
    507507
    508508            // scale down the dialog icon
    509             ImageIcon icon = new ImageProvider("dialogs", iconName).setSize(ImageProvider.ImageSizes.SMALLICON).get();
     509            ImageIcon icon = ImageProvider.get("dialogs", iconName, ImageProvider.ImageSizes.SMALLICON);
    510510            lblTitle = new JLabel("", icon, JLabel.TRAILING);
    511511            lblTitle.setIconTextGap(8);
    512512
     
    544544
    545545            // show the pref button if applicable
    546546            if (preferenceClass != null) {
    547                 JButton pref = new JButton(new ImageProvider("preference").setSize(ImageProvider.ImageSizes.SMALLICON).get());
     547                JButton pref = new JButton(ImageProvider.get("preference", ImageProvider.ImageSizes.SMALLICON));
    548548                pref.setToolTipText(tr("Open preferences for this panel"));
    549549                pref.setBorder(BorderFactory.createEmptyBorder());
    550550                pref.addActionListener(
  • src/org/openstreetmap/josm/gui/io/RecentlyOpenedFilesMenu.java

     
    3232    public RecentlyOpenedFilesMenu() {
    3333        super(tr("Open Recent"));
    3434        setToolTipText(tr("List of recently opened files"));
    35         setIcon(new ImageProvider("openrecent").setSize(ImageProvider.ImageSizes.MENU).get());
     35        setIcon(ImageProvider.get("openrecent", ImageProvider.ImageSizes.MENU));
    3636        putClientProperty("help", ht("/Action/OpenRecent"));
    3737
    3838        // build dynamically
  • src/org/openstreetmap/josm/gui/io/SaveLayersDialog.java

     
    385385        private static final String BASE_ICON = "BASE_ICON";
    386386        private final transient Image save = ImageProvider.get("save").getImage();
    387387        private final transient Image upld = ImageProvider.get("upload").getImage();
    388         private final transient Image saveDis = new BufferedImage(ICON_SIZE, ICON_SIZE, BufferedImage.TYPE_4BYTE_ABGR);
    389         private final transient Image upldDis = new BufferedImage(ICON_SIZE, ICON_SIZE, BufferedImage.TYPE_4BYTE_ABGR);
     388        private final transient Image saveDis = new ImageProvider("save").setDisabled(true).get().getImage();
     389        private final transient Image upldDis = new ImageProvider("upload").setDisabled(true).get().getImage();
    390390
    391391        SaveAndProceedAction() {
    392             // get disabled versions of icons
    393             new JLabel(ImageProvider.get("save")).getDisabledIcon().paintIcon(new JPanel(), saveDis.getGraphics(), 0, 0);
    394             new JLabel(ImageProvider.get("upload")).getDisabledIcon().paintIcon(new JPanel(), upldDis.getGraphics(), 0, 0);
    395392            initForSaveAndExit();
    396393        }
    397394
  • src/org/openstreetmap/josm/gui/layer/NoteLayer.java

     
    3636import org.openstreetmap.josm.gui.io.AbstractIOTask;
    3737import org.openstreetmap.josm.gui.io.UploadNoteLayerTask;
    3838import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     39import org.openstreetmap.josm.gui.util.GuiSizesHelper;
    3940import org.openstreetmap.josm.io.NoteExporter;
    4041import org.openstreetmap.josm.io.OsmApi;
    4142import org.openstreetmap.josm.io.XmlWriter;
    4243import org.openstreetmap.josm.tools.ColorHelper;
     44import org.openstreetmap.josm.tools.ImageProvider;
    4345import org.openstreetmap.josm.tools.Utils;
    4446import org.openstreetmap.josm.tools.date.DateUtils;
    4547
     
    106108
    107109    @Override
    108110    public void paint(Graphics2D g, MapView mv, Bounds box) {
     111        final int iconHeight = GuiSizesHelper.getSizeDpiAdjusted( ImageProvider.ImageSizes.SMALLICON.getVirtualHeight() );
     112        final int iconWidth  = GuiSizesHelper.getSizeDpiAdjusted( ImageProvider.ImageSizes.SMALLICON.getVirtualWidth() );
     113
    109114        for (Note note : noteData.getNotes()) {
    110115            Point p = mv.getPoint(note.getLatLon());
    111116
    112117            ImageIcon icon;
    113118            if (note.getId() < 0) {
    114                 icon = NotesDialog.ICON_NEW_SMALL;
     119                icon = ImageProvider.get("dialogs/notes", "note_new", ImageProvider.ImageSizes.SMALLICON);
    115120            } else if (note.getState() == State.CLOSED) {
    116                 icon = NotesDialog.ICON_CLOSED_SMALL;
     121                icon = ImageProvider.get("dialogs/notes", "note_closed", ImageProvider.ImageSizes.SMALLICON);
    117122            } else {
    118                 icon = NotesDialog.ICON_OPEN_SMALL;
     123                icon = ImageProvider.get("dialogs/notes", "note_open", ImageProvider.ImageSizes.SMALLICON);
    119124            }
    120125            int width = icon.getIconWidth();
    121126            int height = icon.getIconHeight();
     
    150155            Point p = mv.getPoint(noteData.getSelectedNote().getLatLon());
    151156
    152157            g.setColor(ColorHelper.html2color(Main.pref.get("color.selected")));
    153             g.drawRect(p.x - (NotesDialog.ICON_SMALL_SIZE / 2), p.y - NotesDialog.ICON_SMALL_SIZE,
    154                     NotesDialog.ICON_SMALL_SIZE - 1, NotesDialog.ICON_SMALL_SIZE - 1);
     158            g.drawRect(p.x - (iconWidth / 2), p.y - iconHeight,
     159                    iconWidth - 1, iconHeight - 1);
    155160
    156             int tx = p.x + (NotesDialog.ICON_SMALL_SIZE / 2) + 5;
    157             int ty = p.y - NotesDialog.ICON_SMALL_SIZE - 1;
     161            int tx = p.x + (iconWidth / 2) + 5;
     162            int ty = p.y - iconHeight - 1;
    158163            g.translate(tx, ty);
    159164
    160165            //Carried over from the OSB plugin. Not entirely sure why it is needed
     
    179184
    180185    @Override
    181186    public Icon getIcon() {
    182         return NotesDialog.ICON_OPEN_SMALL;
     187        return ImageProvider.get("dialogs/notes", "note_open", ImageProvider.ImageSizes.SMALLICON);
    183188    }
    184189
    185190    @Override
     
    242247        Point clickPoint = e.getPoint();
    243248        double snapDistance = 10;
    244249        double minDistance = Double.MAX_VALUE;
     250        final int iconHeight = GuiSizesHelper.getSizeDpiAdjusted( ImageProvider.ImageSizes.SMALLICON.getVirtualHeight() );
    245251        Note closestNote = null;
    246252        for (Note note : noteData.getNotes()) {
    247253            Point notePoint = Main.map.mapView.getPoint(note.getLatLon());
    248254            //move the note point to the center of the icon where users are most likely to click when selecting
    249             notePoint.setLocation(notePoint.getX(), notePoint.getY() - NotesDialog.ICON_SMALL_SIZE / 2);
     255            notePoint.setLocation(notePoint.getX(), notePoint.getY() - iconHeight / 2);
    250256            double dist = clickPoint.distanceSq(notePoint);
    251257            if (minDistance > dist && clickPoint.distance(notePoint) < snapDistance) {
    252258                minDistance = dist;
  • src/org/openstreetmap/josm/gui/mappaint/MapPaintMenu.java

     
    8585     */
    8686    public MapPaintMenu() {
    8787        super(tr("Map Paint Styles"));
    88         setIcon(new ImageProvider("dialogs", "mapstyle").setSize(ImageProvider.ImageSizes.MENU).get());
     88        setIcon(ImageProvider.get("dialogs", "mapstyle", ImageProvider.ImageSizes.MENU));
    8989        MapPaintStyles.addMapPaintSylesUpdateListener(this);
    9090        putClientProperty("help", ht("/Dialog/MapPaint"));
    9191    }
  • src/org/openstreetmap/josm/gui/preferences/PreferenceTabbedPane.java

     
    511511                    ImageIcon icon = null;
    512512
    513513                    if (iconName != null && !iconName.isEmpty()) {
    514                         icon = new ImageProvider("preferences", iconName).setSize(ImageProvider.ImageSizes.SETTINGS_TAB).get();
     514                        icon = ImageProvider.get("preferences", iconName, ImageProvider.ImageSizes.SETTINGS_TAB);
    515515                    }
    516516                    if (settingsInitialized.contains(tps)) {
    517517                        // If it has been initialized, add corresponding tab(s)
  • src/org/openstreetmap/josm/gui/widgets/TextContextualPopupMenu.java

     
    179179            JMenuItem mi = new JMenuItem(action);
    180180            mi.setText(label);
    181181            if (iconName != null && Main.pref.getBoolean("text.popupmenu.useicons", true)) {
    182                 ImageIcon icon = new ImageProvider(iconName).setSize(ImageProvider.ImageSizes.SMALLICON).get();
     182                ImageIcon icon = ImageProvider.get(iconName, ImageProvider.ImageSizes.SMALLICON);
    183183                if (icon != null) {
    184184                    mi.setIcon(icon);
    185185                }
  • src/org/openstreetmap/josm/tools/ImageProvider.java

     
    5353import javax.imageio.ImageReader;
    5454import javax.imageio.metadata.IIOMetadata;
    5555import javax.imageio.stream.ImageInputStream;
     56import javax.swing.Icon;
    5657import javax.swing.ImageIcon;
     58import javax.swing.JPanel;
     59import javax.swing.UIManager;
    5760import javax.xml.bind.DatatypeConverter;
    5861
    5962import org.openstreetmap.josm.Main;
     
    271274    protected Collection<ClassLoader> additionalClassLoaders;
    272275    /** ordered list of overlay images */
    273276    protected List<ImageOverlay> overlayInfo;
     277    /** <code>true</code> if icon must be grayed out */
     278    protected boolean isDisabled = false;
    274279
    275280    private static SVGUniverse svgUniverse;
    276281
     
    600605    }
    601606
    602607    /**
     608     * Set, if image must be filtered to grayscale so it will look like disabled icon.
     609     *
     610     * @param disabled true, if image must be grayed out for disabled state
     611     * @return the current object, for convenience
     612     */
     613    public ImageProvider setDisabled(boolean disabled) {
     614        this.isDisabled = disabled;
     615        return this;
     616    }
     617
     618    public Boolean getDisabled() {
     619        return this.isDisabled;
     620    }
     621
     622    /**
    603623     * Execute the image request and scale result.
    604624     * @return the requested image or null if the request failed
    605625     */
    606626    public ImageIcon get() {
    607627        ImageResource ir = getResource();
    608         if (ir == null)
     628        ImageIcon icon;
     629
     630        if (ir == null) {
    609631            return null;
     632        }
    610633        if (virtualMaxWidth != -1 || virtualMaxHeight != -1)
    611             return ir.getImageIconBounded(new Dimension(virtualMaxWidth, virtualMaxHeight));
     634            icon = ir.getImageIconBounded(new Dimension(virtualMaxWidth, virtualMaxHeight));
    612635        else
    613             return ir.getImageIcon(new Dimension(virtualWidth, virtualHeight));
     636            icon = ir.getImageIcon(new Dimension(virtualWidth, virtualHeight));
     637
     638        if (isDisabled) {
     639            //Use default Swing functionality to make icon look disabled by applying grayscaling filter.
     640            Icon disabledIcon = UIManager.getLookAndFeel().getDisabledIcon(null, icon);
     641
     642            //Convert Icon to ImageIcon with BufferedImage inside
     643            Image disabledImage = new BufferedImage(disabledIcon.getIconWidth(), disabledIcon.getIconHeight(), BufferedImage.TYPE_4BYTE_ABGR);
     644            disabledIcon.paintIcon(new JPanel(), disabledImage.getGraphics(), 0, 0);
     645            icon = new ImageIcon(disabledImage);
     646        }
     647
     648        return icon;
    614649    }
    615650
    616651    /**
     
    706741    }
    707742
    708743    /**
     744     * Load an image from directory with a given file name and size.
     745     *
     746     * @param subdir subdirectory the image lies in
     747     * @param name The icon name (base name with or without '.png' or '.svg' extension)
     748     * @param size Target icon size
     749     * @return The requested Image.
     750     * @throws RuntimeException if the image cannot be located
     751     */
     752    public static ImageIcon get(String subdir, String name, ImageSizes size) {
     753        return new ImageProvider(subdir, name).setSize(size).get();
     754    }
     755
     756    /**
    709757     * Load an empty image with a given size.
    710758     *
    711759     * @param size Target icon size
     
    730778    }
    731779
    732780    /**
     781     * Load an image with a given file name and size.
     782     *
     783     * @param name The icon name (base name with or without '.png' or '.svg' extension)
     784     * @param size Target icon size
     785     * @return the requested image or null if the request failed
     786     * @see #get(String, String)
     787     */
     788    public static ImageIcon get(String name, ImageSizes size) {
     789        return new ImageProvider(name).setSize(size).get();
     790    }
     791
     792    /**
    733793     * Load an image with a given file name, but do not throw an exception
    734794     * when the image cannot be found.
    735795     *