Changeset 10428 in josm


Ignore:
Timestamp:
2016-06-19T18:28:26+02:00 (16 months ago)
Author:
stoecker
Message:

see #9995 - patch mainly by strump - improve HIDPI behaviour

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

Legend:

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

    r10375 r10428  
    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());
  • trunk/src/org/openstreetmap/josm/actions/JosmAction.java

    r10409 r10428  
    7373        super(name);
    7474        if (icon != null)
    75             icon.getResource().attachImageIcon(this);
     75            icon.getResource().attachImageIcon(this, true);
    7676        setHelpId();
    7777        sc = shortcut;
  • trunk/src/org/openstreetmap/josm/actions/UploadNotesAction.java

    r10318 r10428  
    2626        putValue(SHORT_DESCRIPTION, tr("Upload note changes to server"));
    2727        putValue(NAME, tr("Upload notes"));
    28         putValue(SMALL_ICON, ImageProvider.get("upload"));
     28        new ImageProvider("upload").getResource().attachImageIcon(this, true);
    2929    }
    3030
  • trunk/src/org/openstreetmap/josm/actions/mapmode/AddNoteAction.java

    r9989 r10428  
    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) {
  • trunk/src/org/openstreetmap/josm/actions/relation/DeleteRelationsAction.java

    r10413 r10428  
    2424        putValue(SHORT_DESCRIPTION, tr("Delete the selected relation"));
    2525        putValue(NAME, tr("Delete"));
    26         putValue(SMALL_ICON, ImageProvider.get("dialogs", "delete"));
     26        new ImageProvider("dialogs", "delete").getResource().attachImageIcon(this, true);
    2727    }
    2828
  • trunk/src/org/openstreetmap/josm/actions/relation/DuplicateRelationAction.java

    r10413 r10428  
    2222    public DuplicateRelationAction() {
    2323        putValue(SHORT_DESCRIPTION, tr("Create a copy of this relation and open it in another editor window"));
    24         putValue(SMALL_ICON, ImageProvider.get("duplicate"));
     24        new ImageProvider("duplicate").getResource().attachImageIcon(this, true);
    2525        putValue(NAME, tr("Duplicate"));
    2626    }
  • trunk/src/org/openstreetmap/josm/actions/relation/EditRelationAction.java

    r10413 r10428  
    3232        putValue(NAME, tr("Edit"));
    3333        putValue(SHORT_DESCRIPTION, tr("Call relation editor for selected relation"));
    34         putValue(SMALL_ICON, ImageProvider.get("dialogs", "edit"));
     34        new ImageProvider("dialogs", "edit").getResource().attachImageIcon(this, true);
    3535    }
    3636
  • trunk/src/org/openstreetmap/josm/actions/relation/SelectRelationAction.java

    r10413 r10428  
    2626        putValue(SHORT_DESCRIPTION, add ? tr("Add the selected relations to the current selection") :
    2727            tr("Set the current selection to the list of selected relations"));
    28         putValue(SMALL_ICON, ImageProvider.get("dialogs", "select"));
     28        new ImageProvider("dialogs", "select").getResource().attachImageIcon(this, true);
    2929        putValue(NAME, add ? tr("Select relation (add)") : tr("Select relation"));
    3030        this.add = add;
  • trunk/src/org/openstreetmap/josm/gui/SideButton.java

    r10378 r10428  
    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    }
     
    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    }
  • trunk/src/org/openstreetmap/josm/gui/SplashScreen.java

    r10358 r10428  
    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;
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ChangesetDialog.java

    r10413 r10428  
    298298            putValue(NAME, tr("Select"));
    299299            putValue(SHORT_DESCRIPTION, tr("Select all objects assigned to the currently selected changesets"));
    300             putValue(SMALL_ICON, ImageProvider.get("dialogs", "select"));
     300            new ImageProvider("dialogs", "select").getResource().attachImageIcon(this, true);
    301301            updateEnabledState();
    302302        }
     
    351351            putValue(NAME, tr("Download"));
    352352            putValue(SHORT_DESCRIPTION, tr("Download information about the selected changesets from the OSM server"));
    353             putValue(SMALL_ICON, ImageProvider.get("download"));
     353            new ImageProvider("download").getResource().attachImageIcon(this, true);
    354354            updateEnabledState();
    355355        }
     
    388388            putValue(NAME, tr("Close open changesets"));
    389389            putValue(SHORT_DESCRIPTION, tr("Closes the selected open changesets"));
    390             putValue(SMALL_ICON, ImageProvider.get("closechangeset"));
     390            new ImageProvider("closechangeset").getResource().attachImageIcon(this, true);
    391391            updateEnabledState();
    392392        }
     
    423423            putValue(NAME, tr("Show info"));
    424424            putValue(SHORT_DESCRIPTION, tr("Open a web page for each selected changeset"));
    425             putValue(SMALL_ICON, ImageProvider.get("help/internet"));
     425            new ImageProvider("help/internet").getResource().attachImageIcon(this, true);
    426426            updateEnabledState();
    427427        }
     
    463463            putValue(NAME, tr("Details"));
    464464            putValue(SHORT_DESCRIPTION, tr("Opens the Changeset Manager window for the selected changesets"));
    465             putValue(SMALL_ICON, ImageProvider.get("dialogs/changeset", "changesetmanager"));
     465            new ImageProvider("dialogs/changeset", "changesetmanager").getResource().attachImageIcon(this, true);
    466466        }
    467467
  • trunk/src/org/openstreetmap/josm/gui/dialogs/MapPaintDialog.java

    r10300 r10428  
    342342            putValue(NAME, tr("On/Off"));
    343343            putValue(SHORT_DESCRIPTION, tr("Turn selected styles on or off"));
    344             putValue(SMALL_ICON, ImageProvider.get("apply"));
     344            new ImageProvider("apply").getResource().attachImageIcon(this);
    345345            updateEnabledState();
    346346        }
     
    380380            increment = isDown ? 1 : -1;
    381381            putValue(NAME, isDown ? tr("Down") : tr("Up"));
    382             putValue(SMALL_ICON, isDown ? ImageProvider.get("dialogs", "down") : ImageProvider.get("dialogs", "up"));
     382            new ImageProvider("dialogs", isDown ? "down" : "up").getResource().attachImageIcon(this, true);
    383383            putValue(SHORT_DESCRIPTION, isDown ? tr("Move the selected entry one row down.") : tr("Move the selected entry one row up."));
    384384            updateEnabledState();
     
    415415            putValue(NAME, tr("Reload from file"));
    416416            putValue(SHORT_DESCRIPTION, tr("reload selected styles from file"));
    417             putValue(SMALL_ICON, ImageProvider.get("dialogs", "refresh"));
     417            new ImageProvider("dialogs", "refresh").getResource().attachImageIcon(this);
    418418            setEnabled(getEnabledState());
    419419        }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/NotesDialog.java

    r10395 r10428  
    66import java.awt.BorderLayout;
    77import java.awt.Component;
    8 import java.awt.Image;
    98import java.awt.event.ActionEvent;
    109import java.awt.event.MouseAdapter;
     
    5655 */
    5756public class NotesDialog extends ToggleDialog implements LayerChangeListener {
    58 
    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");
    7857
    7958    private NoteTableModel model;
     
    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);
     
    313292            putValue(SHORT_DESCRIPTION, tr("Add comment"));
    314293            putValue(NAME, tr("Comment"));
    315             putValue(SMALL_ICON, ICON_COMMENT);
     294            new ImageProvider("dialogs/notes", "note_comment").getResource().attachImageIcon(this, true);
    316295        }
    317296
     
    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;
     
    345324            putValue(SHORT_DESCRIPTION, tr("Close note"));
    346325            putValue(NAME, tr("Close"));
    347             putValue(SMALL_ICON, ICON_CLOSED);
     326            new ImageProvider("dialogs/notes", "note_closed").getResource().attachImageIcon(this, true);
    348327        }
    349328
     
    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;
     
    370349            putValue(SHORT_DESCRIPTION, tr("Create a new note"));
    371350            putValue(NAME, tr("Create"));
    372             putValue(SMALL_ICON, ICON_NEW);
     351            new ImageProvider("dialogs/notes", "note_new").getResource().attachImageIcon(this, true);
    373352        }
    374353
     
    390369            putValue(SHORT_DESCRIPTION, tr("Reopen note"));
    391370            putValue(NAME, tr("Reopen"));
    392             putValue(SMALL_ICON, ICON_OPEN);
     371            new ImageProvider("dialogs/notes", "note_open").getResource().attachImageIcon(this, true);
    393372        }
    394373
     
    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;
     
    416395            putValue(SHORT_DESCRIPTION, tr("Sort notes"));
    417396            putValue(NAME, tr("Sort"));
    418             putValue(SMALL_ICON, ImageProvider.get("dialogs", "sort"));
     397            new ImageProvider("dialogs", "sort").getResource().attachImageIcon(this, true);
    419398        }
    420399
  • trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java

    r10413 r10428  
    357357            putValue(SHORT_DESCRIPTION, tr("Create a new relation"));
    358358            putValue(NAME, tr("New"));
    359             putValue(SMALL_ICON, ImageProvider.get("dialogs", "addrelation"));
     359            new ImageProvider("dialogs", "addrelation").getResource().attachImageIcon(this, true);
    360360            updateEnabledState();
    361361        }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java

    r10384 r10428  
    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);
     
    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());
  • trunk/src/org/openstreetmap/josm/gui/dialogs/layer/ActivateLayerAction.java

    r10345 r10428  
    5151        this.model = model;
    5252        putValue(NAME, tr("Activate"));
    53         putValue(SMALL_ICON, ImageProvider.get("dialogs", "activate"));
     53        new ImageProvider("dialogs", "activate").getResource().attachImageIcon(this, true);
    5454        putValue(SHORT_DESCRIPTION, tr("Activate the selected layer"));
    5555        multikeyShortcut = Shortcut.registerShortcut("core_multikey:activateLayer", tr("Multikey: {0}",
  • trunk/src/org/openstreetmap/josm/gui/dialogs/layer/DeleteLayerAction.java

    r10144 r10428  
    3131    public DeleteLayerAction(LayerListModel model) {
    3232        this.model = model;
    33         putValue(SMALL_ICON, ImageProvider.get("dialogs", "delete"));
     33        new ImageProvider("dialogs", "delete").getResource().attachImageIcon(this, true);
    3434        putValue(SHORT_DESCRIPTION, tr("Delete the selected layers."));
    3535        putValue(NAME, tr("Delete"));
  • trunk/src/org/openstreetmap/josm/gui/dialogs/layer/LayerVisibilityAction.java

    r10306 r10428  
    6363        content.setLayout(new GridBagLayout());
    6464
    65         putValue(SMALL_ICON, ImageProvider.get("dialogs/layerlist", "visibility"));
     65        new ImageProvider("dialogs/layerlist", "visibility").getResource().attachImageIcon(this, true);
    6666        putValue(SHORT_DESCRIPTION, tr("Change visibility of the selected layer."));
    6767
  • trunk/src/org/openstreetmap/josm/gui/dialogs/layer/MergeAction.java

    r10378 r10428  
    6060        this.model = model;
    6161        putValue(NAME, tr("Merge"));
    62         putValue(SMALL_ICON, ImageProvider.get("dialogs", "mergedown"));
     62        new ImageProvider("dialogs", "mergedown").getResource().attachImageIcon(this, true);
    6363        putValue(SHORT_DESCRIPTION, tr("Merge this layer into another layer"));
    6464        putValue("help", HelpUtil.ht("/Dialog/LayerList#MergeLayer"));
  • trunk/src/org/openstreetmap/josm/gui/dialogs/layer/MoveDownAction.java

    r10144 r10428  
    2424        this.model = model;
    2525        putValue(NAME, tr("Move down"));
    26         putValue(SMALL_ICON, ImageProvider.get("dialogs", "down"));
     26        new ImageProvider("dialogs", "down").getResource().attachImageIcon(this, true);
    2727        putValue(SHORT_DESCRIPTION, tr("Move the selected layer one row down."));
    2828        updateEnabledState();
  • trunk/src/org/openstreetmap/josm/gui/dialogs/layer/MoveUpAction.java

    r10378 r10428  
    2424        this.model = model;
    2525        putValue(NAME, tr("Move up"));
    26         putValue(SMALL_ICON, ImageProvider.get("dialogs", "up"));
     26        new ImageProvider("dialogs", "up").getResource().attachImageIcon(this, true);
    2727        putValue(SHORT_DESCRIPTION, tr("Move the selected layer one row up."));
    2828        updateEnabledState();
  • trunk/src/org/openstreetmap/josm/gui/io/RecentlyOpenedFilesMenu.java

    r10173 r10428  
    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
  • trunk/src/org/openstreetmap/josm/gui/io/SaveLayersDialog.java

    r10420 r10428  
    384384        private final transient Image save = ImageProvider.get("save").getImage();
    385385        private final transient Image upld = ImageProvider.get("upload").getImage();
    386         private final transient Image saveDis = new BufferedImage(ICON_SIZE, ICON_SIZE, BufferedImage.TYPE_4BYTE_ABGR);
    387         private final transient Image upldDis = new BufferedImage(ICON_SIZE, ICON_SIZE, BufferedImage.TYPE_4BYTE_ABGR);
     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();
    388388
    389389        SaveAndProceedAction() {
    390             // get disabled versions of icons
    391             new JLabel(ImageProvider.get("save")).getDisabledIcon().paintIcon(new JPanel(), saveDis.getGraphics(), 0, 0);
    392             new JLabel(ImageProvider.get("upload")).getDisabledIcon().paintIcon(new JPanel(), upldDis.getGraphics(), 0, 0);
    393390            initForSaveAndExit();
    394391        }
  • trunk/src/org/openstreetmap/josm/gui/layer/NoteLayer.java

    r10308 r10428  
    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;
     
    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());
     
    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();
     
    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);
    155 
    156             int tx = p.x + (NotesDialog.ICON_SMALL_SIZE / 2) + 5;
    157             int ty = p.y - NotesDialog.ICON_SMALL_SIZE - 1;
     158            g.drawRect(p.x - (iconWidth / 2), p.y - iconHeight,
     159                    iconWidth - 1, iconHeight - 1);
     160
     161            int tx = p.x + (iconWidth / 2) + 5;
     162            int ty = p.y - iconHeight - 1;
    158163            g.translate(tx, ty);
    159164
     
    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
     
    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) {
  • trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintMenu.java

    r10364 r10428  
    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"));
  • trunk/src/org/openstreetmap/josm/gui/preferences/PreferenceTabbedPane.java

    r10378 r10428  
    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)) {
  • trunk/src/org/openstreetmap/josm/gui/widgets/TextContextualPopupMenu.java

    r10378 r10428  
    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);
  • trunk/src/org/openstreetmap/josm/tools/ImageProvider.java

    r10410 r10428  
    272272    /** ordered list of overlay images */
    273273    protected List<ImageOverlay> overlayInfo;
     274    /** <code>true</code> if icon must be grayed out */
     275    protected boolean isDisabled = false;
    274276
    275277    private static SVGUniverse svgUniverse;
     
    351353        this.additionalClassLoaders = image.additionalClassLoaders;
    352354        this.overlayInfo = image.overlayInfo;
     355        this.isDisabled = image.isDisabled;
    353356    }
    354357
     
    601604
    602605    /**
     606     * Set, if image must be filtered to grayscale so it will look like disabled icon.
     607     *
     608     * @param disabled true, if image must be grayed out for disabled state
     609     * @return the current object, for convenience
     610     * @since 10428
     611     */
     612    public ImageProvider setDisabled(boolean disabled) {
     613        this.isDisabled = disabled;
     614        return this;
     615    }
     616
     617    /**
    603618     * Execute the image request and scale result.
    604619     * @return the requested image or null if the request failed
     
    606621    public ImageIcon get() {
    607622        ImageResource ir = getResource();
    608         if (ir == null)
     623
     624        if (ir == null) {
    609625            return null;
     626        }
    610627        if (virtualMaxWidth != -1 || virtualMaxHeight != -1)
    611628            return ir.getImageIconBounded(new Dimension(virtualMaxWidth, virtualMaxHeight));
     
    638655            ir = new ImageResource(ir, overlayInfo);
    639656        }
     657        if (isDisabled) {
     658            ir.setDisabled(true);
     659        }
    640660        return ir;
    641661    }
     
    718738
    719739    /**
     740     * Load an image from directory with a given file name and size.
     741     *
     742     * @param subdir subdirectory the image lies in
     743     * @param name The icon name (base name with or without '.png' or '.svg' extension)
     744     * @param size Target icon size
     745     * @return The requested Image.
     746     * @throws RuntimeException if the image cannot be located
     747     * @since 10428
     748     */
     749    public static ImageIcon get(String subdir, String name, ImageSizes size) {
     750        return new ImageProvider(subdir, name).setSize(size).get();
     751    }
     752
     753    /**
    720754     * Load an empty image with a given size.
    721755     *
     
    741775    public static ImageIcon getIfAvailable(String subdir, String name) {
    742776        return new ImageProvider(subdir, name).setOptional(true).get();
     777    }
     778
     779    /**
     780     * Load an image with a given file name and size.
     781     *
     782     * @param name The icon name (base name with or without '.png' or '.svg' extension)
     783     * @param size Target icon size
     784     * @return the requested image or null if the request failed
     785     * @see #get(String, String)
     786     * @since 10428
     787     */
     788    public static ImageIcon get(String name, ImageSizes size) {
     789        return new ImageProvider(name).setSize(size).get();
    743790    }
    744791
     
    776823                return null;
    777824
     825            String prefix = "";
     826            if(isDisabled)
     827              prefix = "dis:"+prefix;
    778828            if (name.startsWith("data:")) {
    779829                String url = name;
    780                 ImageResource ir = cache.get(url);
     830                ImageResource ir = cache.get(prefix+url);
    781831                if (ir != null) return ir;
    782832                ir = getIfAvailableDataUrl(url);
    783833                if (ir != null) {
    784                     cache.put(url, ir);
     834                    cache.put(prefix+url, ir);
    785835                }
    786836                return ir;
     
    791841            if (name.startsWith(HTTP_PROTOCOL) || name.startsWith(HTTPS_PROTOCOL)) {
    792842                String url = name;
    793                 ImageResource ir = cache.get(url);
     843                ImageResource ir = cache.get(prefix+url);
    794844                if (ir != null) return ir;
    795845                ir = getIfAvailableHttp(url, type);
    796846                if (ir != null) {
    797                     cache.put(url, ir);
     847                    cache.put(prefix+url, ir);
    798848                }
    799849                return ir;
    800850            } else if (name.startsWith(WIKI_PROTOCOL)) {
    801                 ImageResource ir = cache.get(name);
     851                ImageResource ir = cache.get(prefix+name);
    802852                if (ir != null) return ir;
    803853                ir = getIfAvailableWiki(name, type);
    804854                if (ir != null) {
    805                     cache.put(name, ir);
     855                    cache.put(prefix+name, ir);
    806856                }
    807857                return ir;
     
    831881
    832882                    String fullName = subdir + name + ext;
    833                     String cacheName = fullName;
     883                    String cacheName = prefix + fullName;
    834884                    /* cache separately */
    835885                    if (dirs != null && !dirs.isEmpty()) {
  • trunk/src/org/openstreetmap/josm/tools/ImageResource.java

    r10409 r10428  
    1111import javax.swing.AbstractAction;
    1212import javax.swing.Action;
     13import javax.swing.Icon;
    1314import javax.swing.ImageIcon;
     15import javax.swing.JPanel;
     16import javax.swing.UIManager;
    1417
    1518import org.openstreetmap.josm.gui.util.GuiSizesHelper;
     
    4346     */
    4447    protected List<ImageOverlay> overlayInfo;
     48    /**
     49     * <code>true</code> if icon must be grayed out
     50     */
     51    protected boolean isDisabled = false;
     52    /**
     53     * The base raster image for the final output
     54     */
    4555    private Image baseImage;
    4656
     
    5161    public ImageResource(Image img) {
    5262        CheckParameterUtil.ensureParameterNotNull(img);
    53         baseImage = img;
    54         imgCache.put(DEFAULT_DIMENSION, scaleBaseImageIfNeeded(img));
     63        baseImage = scaleBaseImageIfNeeded(img);
    5564    }
    5665
     
    96105
    97106    /**
     107     * Set, if image must be filtered to grayscale so it will look like disabled icon.
     108     *
     109     * @param disabled true, if image must be grayed out for disabled state
     110     * @return the current object, for convenience
     111     * @since 10428
     112     */
     113    public ImageResource setDisabled(boolean disabled) {
     114        this.isDisabled = disabled;
     115        return this;
     116    }
     117
     118    /**
    98119     * Set both icons of an Action
    99120     * @param a The action for the icons
     
    145166            return new ImageIcon(img);
    146167        }
     168        BufferedImage bimg;
    147169        if (svg != null) {
    148170            Dimension realDim = GuiSizesHelper.getDimensionDpiAdjusted(dim);
    149             BufferedImage bimg = ImageProvider.createImageFromSvg(svg, realDim);
     171            bimg = ImageProvider.createImageFromSvg(svg, realDim);
    150172            if (bimg == null) {
    151173                return null;
    152174            }
    153             if (overlayInfo != null) {
    154                 for (ImageOverlay o : overlayInfo) {
    155                     o.process(bimg);
    156                 }
    157             }
    158             imgCache.put(dim, bimg);
    159             return new ImageIcon(bimg);
    160175        } else {
    161176            if (baseImage == null) throw new AssertionError();
     
    173188            }
    174189            Image i = icon.getImage().getScaledInstance(realWidth, realHeight, Image.SCALE_SMOOTH);
    175             BufferedImage bimg = new BufferedImage(realWidth, realHeight, BufferedImage.TYPE_INT_ARGB);
     190            bimg = new BufferedImage(realWidth, realHeight, BufferedImage.TYPE_INT_ARGB);
    176191            bimg.getGraphics().drawImage(i, 0, 0, null);
    177             if (overlayInfo != null) {
    178                 for (ImageOverlay o : overlayInfo) {
    179                     o.process(bimg);
    180                 }
    181             }
    182             imgCache.put(dim, bimg);
    183             return new ImageIcon(bimg);
    184         }
     192        }
     193        if (overlayInfo != null) {
     194            for (ImageOverlay o : overlayInfo) {
     195                o.process(bimg);
     196            }
     197        }
     198        if (isDisabled) {
     199            //Use default Swing functionality to make icon look disabled by applying grayscaling filter.
     200            Icon disabledIcon = UIManager.getLookAndFeel().getDisabledIcon(null, new ImageIcon(bimg));
     201
     202            //Convert Icon to ImageIcon with BufferedImage inside
     203            bimg = new BufferedImage(bimg.getWidth(), bimg.getHeight(), BufferedImage.TYPE_4BYTE_ABGR);
     204            disabledIcon.paintIcon(new JPanel(), bimg.getGraphics(), 0, 0);
     205        }
     206        imgCache.put(dim, bimg);
     207        return new ImageIcon(bimg);
    185208    }
    186209
Note: See TracChangeset for help on using the changeset viewer.