- Timestamp:
- 2021-08-01T19:40:15+02:00 (3 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/SideButton.java
r13864 r18099 36 36 public SideButton(Action action) { 37 37 super(action); 38 ImageResource icon = (ImageResource) action.getValue("ImageResource");38 ImageResource icon = ImageResource.getAttachedImageResource(action); 39 39 if (icon != null) { 40 40 setIcon(icon.getImageIconBounded( -
trunk/src/org/openstreetmap/josm/gui/io/SaveLayersDialog.java
r17733 r18099 12 12 import java.awt.GridBagConstraints; 13 13 import java.awt.GridBagLayout; 14 import java.awt.Image;15 14 import java.awt.event.ActionEvent; 16 15 import java.awt.event.WindowAdapter; … … 55 54 import org.openstreetmap.josm.tools.GBC; 56 55 import org.openstreetmap.josm.tools.ImageProvider; 56 import org.openstreetmap.josm.tools.ImageProvider.ImageSizes; 57 import org.openstreetmap.josm.tools.ImageResource; 57 58 import org.openstreetmap.josm.tools.InputMapUtils; 58 59 import org.openstreetmap.josm.tools.Logging; … … 451 452 452 453 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; 459 456 460 457 SaveAndProceedAction() { … … 462 459 } 463 460 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(); 467 463 } 468 464 … … 472 468 putValue(NAME, tr("Perform actions before exiting")); 473 469 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(); 475 471 break; 476 472 case RESTART: 477 473 putValue(NAME, tr("Perform actions before restarting")); 478 474 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(); 480 476 break; 481 477 case DELETE: 482 478 putValue(NAME, tr("Perform actions before deleting")); 483 479 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(); 485 481 break; 486 482 } … … 489 485 490 486 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); 493 496 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 } 502 507 } 503 508 -
trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java
r17662 r18099 221 221 } 222 222 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 */ 223 228 public final ImageResource getImageResource() { 224 return (ImageResource) getValue("ImageResource");229 return ImageResource.getAttachedImageResource(this); 225 230 } 226 231 -
trunk/src/org/openstreetmap/josm/tools/ImageResource.java
r17827 r18099 15 15 import javax.swing.JPanel; 16 16 import javax.swing.UIManager; 17 18 import org.openstreetmap.josm.tools.ImageProvider.ImageSizes; 17 19 18 20 import com.kitfox.svg.SVGDiagram; … … 101 103 */ 102 104 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())); 110 107 } 111 108 … … 121 118 a.putValue("ImageResource", this); 122 119 } 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"); 123 130 } 124 131
Note:
See TracChangeset
for help on using the changeset viewer.