Changeset 7693 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2014-11-02T01:19:59+01:00 (10 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/AddImageryLayerAction.java
r7692 r7693 12 12 13 13 import javax.swing.Action; 14 import javax.swing.ImageIcon;15 14 import javax.swing.JComboBox; 16 15 import javax.swing.JOptionPane; … … 29 28 import org.openstreetmap.josm.tools.GBC; 30 29 import org.openstreetmap.josm.tools.ImageProvider; 31 import org.openstreetmap.josm.tools.ImageProvider.ImageCallback; 30 import org.openstreetmap.josm.tools.ImageProvider.ImageResourceCallback; 31 import org.openstreetmap.josm.tools.ImageResource; 32 32 33 33 /** … … 52 52 // change toolbar icon from if specified 53 53 try { 54 if (info.getIcon() != null) {55 new ImageProvider(info.getIcon()).setOptional(true).56 setMaxSize(ImageProvider.ImageSizes.SMALLICON).getInBackground(new ImageCallback() {54 String icon = info.getIcon(); 55 if (icon != null) { 56 new ImageProvider(icon).setOptional(true).getInBackground(new ImageResourceCallback() { 57 57 @Override 58 public void finished(final Image Iconresult) {58 public void finished(final ImageResource result) { 59 59 if (result != null) { 60 60 GuiHelper.runInEDT(new Runnable() { 61 61 @Override 62 62 public void run() { 63 putValue(Action.SMALL_ICON, result); 64 } 65 }); 66 } 67 } 68 }); 69 new ImageProvider(info.getIcon()).setOptional(true). 70 setMaxSize(ImageProvider.ImageSizes.LARGEICON).getInBackground(new ImageCallback() { 71 @Override 72 public void finished(final ImageIcon result) { 73 if (result != null) { 74 GuiHelper.runInEDT(new Runnable() { 75 @Override 76 public void run() { 77 putValue(Action.LARGE_ICON_KEY, result); 63 result.getImageIcon(AddImageryLayerAction.this); 78 64 } 79 65 }); -
trunk/src/org/openstreetmap/josm/actions/JosmAction.java
r7534 r7693 72 72 * @param toolbarId identifier for the toolbar preferences. The iconName is used, if this parameter is null 73 73 * @param installAdapters false, if you don't want to install layer changed and selection changed adapters 74 */ 74 * @deprecated do not pass Icon, pass ImageProvider instead 75 */ 76 @Deprecated 75 77 public JosmAction(String name, Icon icon, String tooltip, Shortcut shortcut, boolean registerInToolbar, String toolbarId, boolean installAdapters) { 76 78 super(name, icon); … … 93 95 94 96 /** 97 * Constructs a {@code JosmAction}. 98 * 99 * @param name the action's text as displayed on the menu (if it is added to a menu) 100 * @param icon the icon to use 101 * @param tooltip a longer description of the action that will be displayed in the tooltip. Please note 102 * that html is not supported for menu actions on some platforms. 103 * @param shortcut a ready-created shortcut object or null if you don't want a shortcut. But you always 104 * do want a shortcut, remember you can always register it with group=none, so you 105 * won't be assigned a shortcut unless the user configures one. If you pass null here, 106 * the user CANNOT configure a shortcut for your action. 107 * @param registerInToolbar register this action for the toolbar preferences? 108 * @param toolbarId identifier for the toolbar preferences. The iconName is used, if this parameter is null 109 * @param installAdapters false, if you don't want to install layer changed and selection changed adapters 110 * TODO: do not pass Icon, pass ImageProvider instead 111 */ 112 public JosmAction(String name, ImageProvider icon, String tooltip, Shortcut shortcut, boolean registerInToolbar, String toolbarId, boolean installAdapters) { 113 super(name); 114 if(icon != null) 115 icon.getResource().getImageIcon(this); 116 setHelpId(); 117 sc = shortcut; 118 if (sc != null) { 119 Main.registerActionShortcut(this, sc); 120 } 121 setTooltip(tooltip); 122 if (getValue("toolbar") == null) { 123 putValue("toolbar", toolbarId); 124 } 125 if (registerInToolbar && Main.toolbar != null) { 126 Main.toolbar.register(this); 127 } 128 if (installAdapters) { 129 installAdapters(); 130 } 131 } 132 133 /** 95 134 * The new super for all actions. 96 135 * … … 110 149 */ 111 150 public JosmAction(String name, String iconName, String tooltip, Shortcut shortcut, boolean registerInToolbar, String toolbarId, boolean installAdapters) { 112 this(name, iconName == null ? null : ImageProvider.get(iconName), tooltip, shortcut, registerInToolbar,151 this(name, iconName == null ? null : new ImageProvider(iconName), tooltip, shortcut, registerInToolbar, 113 152 toolbarId == null ? iconName : toolbarId, installAdapters); 114 153 } -
trunk/src/org/openstreetmap/josm/actions/JumpToAction.java
r7081 r7693 9 9 import java.awt.event.KeyEvent; 10 10 11 import javax.swing.Icon;12 11 import javax.swing.JLabel; 13 12 import javax.swing.JOptionPane; … … 24 23 import org.openstreetmap.josm.gui.widgets.JosmTextField; 25 24 import org.openstreetmap.josm.tools.GBC; 25 import org.openstreetmap.josm.tools.ImageProvider; 26 26 import org.openstreetmap.josm.tools.OsmUrlToBounds; 27 27 import org.openstreetmap.josm.tools.Shortcut; … … 37 37 */ 38 38 public JumpToAction() { 39 super(tr("Jump To Position"), (I con) null, tr("Opens a dialog that allows to jump to a specific location"),39 super(tr("Jump To Position"), (ImageProvider) null, tr("Opens a dialog that allows to jump to a specific location"), 40 40 Shortcut.registerShortcut("tools:jumpto", tr("Tool: {0}", tr("Jump To Position")), 41 41 KeyEvent.VK_J, Shortcut.CTRL), true, "action/jumpto", true); -
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java
r7687 r7693 52 52 import org.openstreetmap.josm.tools.GBC; 53 53 import org.openstreetmap.josm.tools.ImageProvider; 54 import org.openstreetmap.josm.tools.ImageResource; 54 55 import org.openstreetmap.josm.tools.Predicate; 55 56 import org.openstreetmap.josm.tools.Utils; … … 153 154 imgProv.setArchive(arch); 154 155 imgProv.setOptional(true); 155 imgProv.setSize(ImageProvider.ImageSizes.SMALLICON); 156 imgProv.getInBackground(new ImageProvider.ImageCallback() { 156 imgProv.getInBackground(new ImageProvider.ImageResourceCallback() { 157 157 @Override 158 public void finished(final Image Iconresult) {158 public void finished(final ImageResource result) { 159 159 if (result != null) { 160 160 GuiHelper.runInEDT(new Runnable() { 161 161 @Override 162 162 public void run() { 163 putValue(Action.SMALL_ICON, result);163 result.getImageIcon(TaggingPreset.this); 164 164 } 165 165 }); 166 166 } else { 167 167 Main.warn("Could not get presets icon " + iconName); 168 }169 }170 });171 imgProv = new ImageProvider(iconName);172 imgProv.setDirs(s);173 imgProv.setId("presets");174 imgProv.setArchive(arch);175 imgProv.setOptional(true);176 imgProv.setSize(ImageProvider.ImageSizes.LARGEICON);177 imgProv.getInBackground(new ImageProvider.ImageCallback() {178 @Override179 public void finished(final ImageIcon result) {180 if (result != null) {181 GuiHelper.runInEDT(new Runnable() {182 @Override183 public void run() {184 putValue(Action.LARGE_ICON_KEY, result);185 }186 });187 168 } 188 169 } -
trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
r7689 r7693 163 163 private static final ExecutorService IMAGE_FETCHER = Executors.newSingleThreadExecutor(); 164 164 165 /** 166 * Callback interface for asynchronous image loading. 167 */ 165 168 public interface ImageCallback { 166 169 void finished(ImageIcon result); 170 } 171 172 /** 173 * Callback interface for asynchronous image loading (with delayed scaling possibility). 174 * @since 7693 175 */ 176 public interface ImageResourceCallback { 177 void finished(ImageResource result); 167 178 } 168 179 … … 237 248 * @since 7687 238 249 */ 239 public Dimension getImageSizes(ImageSizes size) {250 static public Dimension getImageSizes(ImageSizes size) { 240 251 int sizeval; 241 252 switch(size) { … … 382 393 383 394 /** 395 * Execute the image request and scale result. 396 * @return the requested image or null if the request failed 397 */ 398 public ImageIcon get() { 399 ImageResource ir = getResource(); 400 if (maxWidth != -1 || maxHeight != -1) 401 return ir.getImageIconBounded(new Dimension(maxWidth, maxHeight)); 402 else 403 return ir.getImageIcon(new Dimension(width, height)); 404 } 405 406 /** 384 407 * Execute the image request. 385 408 * @return the requested image or null if the request failed 386 */ 387 public ImageIcon get() { 409 * @since 7693 410 */ 411 public ImageResource getResource() { 388 412 ImageResource ir = getIfAvailableImpl(additionalClassLoaders); 389 413 if (ir == null) { … … 398 422 } 399 423 } 400 if (maxWidth != -1 || maxHeight != -1) 401 return ir.getImageIconBounded(new Dimension(maxWidth, maxHeight)); 402 else 403 return ir.getImageIcon(new Dimension(width, height)); 424 return ir; 404 425 } 405 426 … … 428 449 ImageIcon result = get(); 429 450 callback.finished(result); 451 } 452 } 453 454 /** 455 * Load the image in a background thread. 456 * 457 * This method returns immediately and runs the image request 458 * asynchronously. 459 * 460 * @param callback a callback. It is called, when the image is ready. 461 * This can happen before the call to this method returns or it may be 462 * invoked some time (seconds) later. If no image is available, a null 463 * value is returned to callback (just like {@link #get}). 464 * @since 7693 465 */ 466 public void getInBackground(final ImageResourceCallback callback) { 467 if (name.startsWith("http://") || name.startsWith("wiki://")) { 468 Runnable fetch = new Runnable() { 469 @Override 470 public void run() { 471 callback.finished(getResource()); 472 } 473 }; 474 IMAGE_FETCHER.submit(fetch); 475 } else { 476 callback.finished(getResource()); 430 477 } 431 478 } -
trunk/src/org/openstreetmap/josm/tools/ImageResource.java
r7005 r7693 8 8 import java.util.Map; 9 9 10 import javax.swing.Action; 11 import javax.swing.AbstractAction; 10 12 import javax.swing.ImageIcon; 11 13 … … 20 22 * @since 4271 21 23 */ 22 class ImageResource {24 public class ImageResource { 23 25 24 26 /** … … 43 45 } 44 46 47 /** 48 * Set both icons of an Action 49 * @param action The action for the icons 50 * @since 7693 51 */ 52 public void getImageIcon(AbstractAction a) { 53 ImageIcon icon = getImageIcon(ImageProvider.getImageSizes(ImageProvider.ImageSizes.SMALLICON)); 54 a.putValue(Action.SMALL_ICON, icon); 55 icon = getImageIcon(ImageProvider.getImageSizes(ImageProvider.ImageSizes.LARGEICON)); 56 a.putValue(Action.LARGE_ICON_KEY, icon); 57 } 58 45 59 /** 46 60 * Get an ImageIcon object for the image of this resource
Note:
See TracChangeset
for help on using the changeset viewer.