- Timestamp:
- 2016-06-12T12:00:38+02:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/SideButton.java
r10356 r10358 92 92 action.addPropertyChangeListener(propertyChangeListener); 93 93 } 94 int iconHeight = ImageProvider.ImageSizes.SIDEBUTTON.getImage Size();94 int iconHeight = ImageProvider.ImageSizes.SIDEBUTTON.getImageDimension().height; 95 95 Icon i = getIcon(); 96 96 if (i instanceof ImageIcon && i.getIconHeight() != iconHeight) { -
trunk/src/org/openstreetmap/josm/gui/SplashScreen.java
r10254 r10358 9 9 import java.awt.GridBagConstraints; 10 10 import java.awt.GridBagLayout; 11 import java.awt.Image;12 11 import java.awt.Insets; 13 12 import java.awt.event.MouseAdapter; … … 18 17 19 18 import javax.swing.BorderFactory; 20 import javax.swing.ImageIcon;21 19 import javax.swing.JFrame; 22 20 import javax.swing.JLabel; … … 70 68 71 69 // Add the logo 72 JLabel logo = new JLabel(new Image Icon(ImageProvider.get("logo.svg").getImage().getScaledInstance(128, 129, Image.SCALE_SMOOTH)));70 JLabel logo = new JLabel(new ImageProvider("logo.svg").setSize(ImageProvider.ImageSizes.SPLASH_LOGO).get()); 73 71 GridBagConstraints gbc = new GridBagConstraints(); 74 72 gbc.gridheight = 2; -
trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java
r10325 r10358 34 34 import javax.swing.BorderFactory; 35 35 import javax.swing.ButtonGroup; 36 import javax.swing.ImageIcon; 36 37 import javax.swing.JButton; 37 38 import javax.swing.JCheckBoxMenuItem; … … 506 507 507 508 // scale down the dialog icon 508 lblTitle = new JLabel("", new ImageProvider("dialogs", iconName).setWidth(16).get(), JLabel.TRAILING); 509 ImageIcon icon = new ImageProvider("dialogs", iconName).setSize(ImageProvider.ImageSizes.SMALLICON).get(); 510 lblTitle = new JLabel("", icon, JLabel.TRAILING); 509 511 lblTitle.setIconTextGap(8); 510 512 … … 543 545 // show the pref button if applicable 544 546 if (preferenceClass != null) { 545 JButton pref = new JButton(new ImageProvider("preference").set Width(16).get());547 JButton pref = new JButton(new ImageProvider("preference").setSize(ImageProvider.ImageSizes.SMALLICON).get()); 546 548 pref.setToolTipText(tr("Open preferences for this panel")); 547 549 pref.setBorder(BorderFactory.createEmptyBorder()); -
trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
r9965 r10358 147 147 public static ImageIcon getIcon(IconReference ref, int width, int height) { 148 148 final String namespace = ref.source.getPrefName(); 149 ImageIcon i = getIconProvider(ref, false).set Width(width).setHeight(height).get();149 ImageIcon i = getIconProvider(ref, false).setSize(width, height).get(); 150 150 if (i == null) { 151 151 Main.warn("Mappaint style \""+namespace+"\" ("+ref.source.getDisplayString()+") icon \"" + ref.iconName + "\" not found."); -
trunk/src/org/openstreetmap/josm/gui/preferences/PreferenceTabbedPane.java
r10212 r10358 510 510 // Get icon 511 511 String iconName = tps.getIconName(); 512 ImageIcon icon = iconName != null && !iconName.isEmpty() ? ImageProvider.get("preferences", iconName) :null;513 // See #6985 - Force icons to be 48x48 pixels 514 if (icon != null && (icon.getIconHeight() != 48 || icon.getIconWidth() != 48)) {515 icon = new Image Icon(icon.getImage().getScaledInstance(48, 48, Image.SCALE_DEFAULT));512 ImageIcon icon = null; 513 514 if(iconName != null && !iconName.isEmpty()) { 515 icon = new ImageProvider("preferences", iconName).setSize(ImageProvider.ImageSizes.SETTINGS_TAB).get(); 516 516 } 517 517 if (settingsInitialized.contains(tps)) { -
trunk/src/org/openstreetmap/josm/gui/widgets/TextContextualPopupMenu.java
r9231 r10358 180 180 mi.setText(label); 181 181 if (iconName != null && Main.pref.getBoolean("text.popupmenu.useicons", true)) { 182 ImageIcon icon = new ImageProvider(iconName).set Width(16).get();182 ImageIcon icon = new ImageProvider(iconName).setSize(ImageProvider.ImageSizes.SMALLICON).get(); 183 183 if (icon != null) { 184 184 mi.setIcon(icon); -
trunk/src/org/openstreetmap/josm/plugins/PluginInformation.java
r10294 r10358 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.Image;7 import java.awt.image.BufferedImage;8 6 import java.io.File; 9 7 import java.io.FileInputStream; … … 77 75 public String iconPath; 78 76 /** The plugin icon. */ 79 p ublic ImageIconicon;77 private ImageProvider icon; 80 78 /** Plugin can be loaded at any time and not just at start. */ 81 79 public boolean canloadatruntime; … … 84 82 /** All manifest attributes. */ 85 83 public final Map<String, String> attr = new TreeMap<>(); 86 87 private static final ImageIcon emptyIcon = new ImageIcon(new BufferedImage(24, 24, BufferedImage.TYPE_INT_ARGB));84 /** Empty icon for these plugins which have none */ 85 private static final ImageIcon emptyIcon = ImageProvider.getEmpty(ImageProvider.ImageSizes.LARGEICON); 88 86 89 87 /** … … 244 242 if (file != null) { 245 243 // extract icon from the plugin jar file 246 icon = new ImageProvider(iconPath).setArchive(file).setMax Width(24).setMaxHeight(24).setOptional(true).get();244 icon = new ImageProvider(iconPath).setArchive(file).setMaxSize(ImageProvider.ImageSizes.LARGEICON).setOptional(true); 247 245 } else if (iconPath.startsWith("data:")) { 248 icon = new ImageProvider(iconPath).setMax Width(24).setMaxHeight(24).setOptional(true).get();246 icon = new ImageProvider(iconPath).setMaxSize(ImageProvider.ImageSizes.LARGEICON).setOptional(true); 249 247 } 250 248 } … … 494 492 495 493 /** 496 * Replies the plugin icon, scaled to 24x24 pixels.497 * @return the plugin icon, scaled to 24x24 pixels.494 * Replies the plugin icon, scaled to LARGE_ICON size. 495 * @return the plugin icon, scaled to LARGE_ICON size. 498 496 */ 499 497 public ImageIcon getScaledIcon() { 500 if (icon == null) 498 ImageIcon img = (icon != null) ? icon.get() : null; 499 if (img == null) 501 500 return emptyIcon; 502 return new ImageIcon(icon.getImage().getScaledInstance(24, 24, Image.SCALE_SMOOTH));501 return img; 503 502 } 504 503 -
trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
r10308 r10358 69 69 import org.openstreetmap.josm.gui.tagging.presets.TaggingPreset; 70 70 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets; 71 import org.openstreetmap.josm.gui.util.GuiSizesHelper; 71 72 import org.openstreetmap.josm.io.CachedFile; 72 73 import org.openstreetmap.josm.plugins.PluginHandler; … … 145 146 CURSOR(Main.pref.getInteger("iconsize.cursor", 32)), 146 147 /** cursor overlay icon size */ 147 CURSOROVERLAY(CURSOR .imageSize),148 CURSOROVERLAY(CURSOR), 148 149 /** menu icon size */ 149 MENU(SMALLICON .imageSize),150 MENU(SMALLICON), 150 151 /** menu icon size in popup menus 151 152 * @since 8323 152 153 */ 153 POPUPMENU(LARGEICON .imageSize),154 POPUPMENU(LARGEICON), 154 155 /** Layer list icon size 155 156 * @since 8323 … … 159 160 * @since 9253 160 161 */ 161 TOOLBAR(LARGEICON .imageSize),162 TOOLBAR(LARGEICON), 162 163 /** Side button maximum height 163 164 * @since 9253 164 165 */ 165 166 SIDEBUTTON(Main.pref.getInteger("iconsize.sidebutton", 20)), 167 /** Settings tab icon size 168 * @since 9253 169 */ 170 SETTINGS_TAB(Main.pref.getInteger("iconsize.settingstab", 48)), 166 171 /** 167 172 * The default image size 168 173 * @since 9705 169 174 */ 170 DEFAULT(Main.pref.getInteger("iconsize.default", 24)); 171 172 private final int imageSize; 175 DEFAULT(Main.pref.getInteger("iconsize.default", 24)), 176 /** 177 * Splash dialog logo size 178 * @since 10358 179 */ 180 SPLASH_LOGO(128, 129), 181 /** 182 * About dialog logo size 183 * @since 10358 184 */ 185 ABOUT_LOGO(256, 258); 186 187 private final int virtualWidth; 188 private final int virtualHeight; 173 189 174 190 ImageSizes(int imageSize) { 175 this.imageSize = imageSize; 191 this.virtualWidth = imageSize; 192 this.virtualHeight = imageSize; 193 } 194 195 ImageSizes(int width, int height) { 196 this.virtualWidth = width; 197 this.virtualHeight = height; 198 } 199 200 ImageSizes(ImageSizes that) { 201 this.virtualWidth = that.virtualWidth; 202 this.virtualHeight = that.virtualHeight; 176 203 } 177 204 178 205 /** 179 * Returns the image size in pixels 180 * @return the image size in pixels 206 * Returns the image width in virtual pixels 207 * @return the image width in virtual pixels 208 */ 209 public int getVirtualWidth() { 210 return virtualWidth; 211 } 212 213 /** 214 * Returns the image height in virtual pixels 215 * @return the image height in virtual pixels 181 216 * @since 9705 182 217 */ 183 public int get ImageSize() {184 return imageSize;218 public int getVirtualHeight() { 219 return virtualHeight; 185 220 } 186 221 … … 191 226 */ 192 227 public Dimension getImageDimension() { 193 return new Dimension( imageSize, imageSize);228 return new Dimension(virtualWidth, virtualHeight); 194 229 } 195 230 } … … 219 254 /** directory inside the archive */ 220 255 protected String inArchiveDir; 221 /** width of the resulting image, -1 when original image data should be used */222 protected int width = -1;223 /** height of the resulting image, -1 when original image data should be used */224 protected int height = -1;225 /** maximum width of the resulting image, -1 for no restriction */226 protected int maxWidth = -1;227 /** maximum height of the resulting image, -1 for no restriction */228 protected int maxHeight = -1;256 /** virtual width of the resulting image, -1 when original image data should be used */ 257 protected int virtualWidth = -1; 258 /** virtual height of the resulting image, -1 when original image data should be used */ 259 protected int virtualHeight = -1; 260 /** virtual maximum width of the resulting image, -1 for no restriction */ 261 protected int virtualMaxWidth = -1; 262 /** virtual maximum height of the resulting image, -1 for no restriction */ 263 protected int virtualMaxHeight = -1; 229 264 /** In case of errors do not throw exception but return <code>null</code> for missing image */ 230 265 protected boolean optional; … … 306 341 this.archive = image.archive; 307 342 this.inArchiveDir = image.inArchiveDir; 308 this. width = image.width;309 this. height = image.height;310 this. maxWidth = image.maxWidth;311 this. maxHeight = image.maxHeight;343 this.virtualWidth = image.virtualWidth; 344 this.virtualHeight = image.virtualHeight; 345 this.virtualMaxWidth = image.virtualMaxWidth; 346 this.virtualMaxHeight = image.virtualMaxHeight; 312 347 this.optional = image.optional; 313 348 this.suppressWarnings = image.suppressWarnings; … … 389 424 */ 390 425 public ImageProvider setSize(Dimension size) { 391 this. width = size.width;392 this. height = size.height;426 this.virtualWidth = size.width; 427 this.virtualHeight = size.height; 393 428 return this; 394 429 } … … 407 442 408 443 /** 444 * Set the dimensions of the image. 445 * 446 * @param width final width of the image 447 * @param height final height of the image 448 * @return the current object, for convenience 449 * @since 10358 450 */ 451 public ImageProvider setSize(int width, int height) { 452 this.virtualWidth = width; 453 this.virtualHeight = height; 454 return this; 455 } 456 457 /** 409 458 * Set image width 410 459 * @param width final width of the image … … 413 462 */ 414 463 public ImageProvider setWidth(int width) { 415 this. width = width;464 this.virtualWidth = width; 416 465 return this; 417 466 } … … 424 473 */ 425 474 public ImageProvider setHeight(int height) { 426 this. height = height;475 this.virtualHeight = height; 427 476 return this; 428 477 } … … 439 488 */ 440 489 public ImageProvider setMaxSize(Dimension maxSize) { 441 this. maxWidth = maxSize.width;442 this. maxHeight = maxSize.height;490 this.virtualMaxWidth = maxSize.width; 491 this.virtualMaxHeight = maxSize.height; 443 492 return this; 444 493 } … … 458 507 */ 459 508 public ImageProvider resetMaxSize(Dimension maxSize) { 460 if (this. maxWidth == -1 || maxSize.width < this.maxWidth) {461 this. maxWidth = maxSize.width;462 } 463 if (this. maxHeight == -1 || maxSize.height < this.maxHeight) {464 this. maxHeight = maxSize.height;509 if (this.virtualMaxWidth == -1 || maxSize.width < this.virtualMaxWidth) { 510 this.virtualMaxWidth = maxSize.width; 511 } 512 if (this.virtualMaxHeight == -1 || maxSize.height < this.virtualMaxHeight) { 513 this.virtualMaxHeight = maxSize.height; 465 514 } 466 515 return this; … … 498 547 */ 499 548 public ImageProvider setMaxWidth(int maxWidth) { 500 this. maxWidth = maxWidth;549 this.virtualMaxWidth = maxWidth; 501 550 return this; 502 551 } … … 509 558 */ 510 559 public ImageProvider setMaxHeight(int maxHeight) { 511 this. maxHeight = maxHeight;560 this.virtualMaxHeight = maxHeight; 512 561 return this; 513 562 } … … 557 606 if (ir == null) 558 607 return null; 559 if ( maxWidth != -1 || maxHeight != -1)560 return ir.getImageIconBounded(new Dimension( maxWidth, maxHeight));608 if (virtualMaxWidth != -1 || virtualMaxHeight != -1) 609 return ir.getImageIconBounded(new Dimension(virtualMaxWidth, virtualMaxHeight)); 561 610 else 562 return ir.getImageIcon(new Dimension( width, height));611 return ir.getImageIcon(new Dimension(virtualWidth, virtualHeight)); 563 612 } 564 613 … … 656 705 657 706 /** 707 * Load an empty image with a given size. 708 * 709 * @param size Target icon size 710 * @return The requested Image. 711 * @since 10358 712 */ 713 public static ImageIcon getEmpty(ImageSizes size) { 714 Dimension iconRealSize = GuiSizesHelper.getDimensionDpiAdjusted(size.getImageDimension()); 715 return new ImageIcon(new BufferedImage(iconRealSize.width, iconRealSize.height, 716 BufferedImage.TYPE_INT_ARGB)); 717 } 718 719 /** 658 720 * Load an image with a given file name. 659 721 * … … 689 751 public static ImageIcon getIfAvailable(String name) { 690 752 return new ImageProvider(name).setOptional(true).get(); 753 } 754 755 /** 756 * Scale image to virtual dimensions. This util method is used to hide real sizes calculations. 757 * All other classes should use this method to resize images. 758 * 759 * @param im image to be resized 760 * @param virtualWidth target width of image in virtual pixels 761 * @param virtualHeight target height of image in virtual pixels 762 * @return new scaled image in real dimensions 763 */ 764 public static ImageIcon getScaledIcon(Image im, int virtualWidth, int virtualHeight) { 765 int realWidth = GuiSizesHelper.getSizeDpiAdjusted(virtualWidth); 766 int realHeight = GuiSizesHelper.getSizeDpiAdjusted(virtualHeight); 767 768 return new ImageIcon(im.getScaledInstance(realWidth, realHeight, Image.SCALE_SMOOTH)); 691 769 } 692 770 … … 1333 1411 MapImage icon = nodeStyle.mapImage; 1334 1412 if (icon != null) { 1335 int background Width = iconSize.width;1336 int background Height = iconSize.height;1337 int icon Width = icon.getWidth();1338 int icon Height = icon.getHeight();1339 BufferedImage image = new BufferedImage(background Width, backgroundHeight,1413 int backgroundRealWidth = GuiSizesHelper.getSizeDpiAdjusted(iconSize.width); 1414 int backgroundRealHeight = GuiSizesHelper.getSizeDpiAdjusted(iconSize.height); 1415 int iconRealWidth = icon.getWidth(); 1416 int iconRealHeight = icon.getHeight(); 1417 BufferedImage image = new BufferedImage(backgroundRealWidth, backgroundRealHeight, 1340 1418 BufferedImage.TYPE_INT_ARGB); 1341 double scaleFactor = Math.min(background Width / (double) iconWidth, backgroundHeight1342 / (double) icon Height);1419 double scaleFactor = Math.min(backgroundRealWidth / (double) iconRealWidth, backgroundRealHeight 1420 / (double) iconRealHeight); 1343 1421 BufferedImage iconImage = icon.getImage(false); 1344 1422 Image scaledIcon; … … 1347 1425 if (scaleFactor < 1) { 1348 1426 // Scale icon such that it fits on background. 1349 scaledWidth = (int) (icon Width * scaleFactor);1350 scaledHeight = (int) (icon Height * scaleFactor);1427 scaledWidth = (int) (iconRealWidth * scaleFactor); 1428 scaledHeight = (int) (iconRealHeight * scaleFactor); 1351 1429 scaledIcon = iconImage.getScaledInstance(scaledWidth, scaledHeight, Image.SCALE_SMOOTH); 1352 1430 } else { 1353 1431 // Use original size, don't upscale. 1354 scaledWidth = icon Width;1355 scaledHeight = icon Height;1432 scaledWidth = iconRealWidth; 1433 scaledHeight = iconRealHeight; 1356 1434 scaledIcon = iconImage; 1357 1435 } 1358 image.getGraphics().drawImage(scaledIcon, (background Width - scaledWidth) / 2,1359 (background Height - scaledHeight) / 2, null);1436 image.getGraphics().drawImage(scaledIcon, (backgroundRealWidth - scaledWidth) / 2, 1437 (backgroundRealHeight - scaledHeight) / 2, null); 1360 1438 1361 1439 return new ImageIcon(image); … … 1394 1472 */ 1395 1473 public static BufferedImage createImageFromSvg(SVGDiagram svg, Dimension dim) { 1396 float realWidth = svg.getWidth();1397 float realHeight = svg.getHeight();1398 int width = Math.round(realWidth);1399 int height = Math.round(realHeight);1400 Double scaleX = null, scaleY = null;1474 float sourceWidth = svg.getWidth(); 1475 float sourceHeight = svg.getHeight(); 1476 int realWidth = Math.round(GuiSizesHelper.getSizeDpiAdjusted(sourceWidth)); 1477 int realHeight = Math.round(GuiSizesHelper.getSizeDpiAdjusted(sourceHeight)); 1478 Double scaleX, scaleY; 1401 1479 if (dim.width != -1) { 1402 width = dim.width;1403 scaleX = (double) width / realWidth;1480 realWidth = dim.width; 1481 scaleX = (double) realWidth / sourceWidth; 1404 1482 if (dim.height == -1) { 1405 1483 scaleY = scaleX; 1406 height = (int) Math.round(realHeight * scaleY);1484 realHeight = (int) Math.round(sourceHeight * scaleY); 1407 1485 } else { 1408 height = dim.height;1409 scaleY = (double) height / realHeight;1486 realHeight = dim.height; 1487 scaleY = (double) realHeight / sourceHeight; 1410 1488 } 1411 1489 } else if (dim.height != -1) { 1412 height = dim.height; 1413 scaleX = scaleY = (double) height / realHeight; 1414 width = (int) Math.round(realWidth * scaleX); 1415 } 1416 if (width == 0 || height == 0) { 1490 realHeight = dim.height; 1491 scaleX = scaleY = (double) realHeight / sourceHeight; 1492 realWidth = (int) Math.round(sourceWidth * scaleX); 1493 } 1494 else { 1495 scaleX = scaleY = (double) realHeight / sourceHeight; 1496 } 1497 1498 if (realWidth == 0 || realHeight == 0) { 1417 1499 return null; 1418 1500 } 1419 BufferedImage img = new BufferedImage( width, height, BufferedImage.TYPE_INT_ARGB);1501 BufferedImage img = new BufferedImage(realWidth, realHeight, BufferedImage.TYPE_INT_ARGB); 1420 1502 Graphics2D g = img.createGraphics(); 1421 g.setClip(0, 0, width, height); 1422 if (scaleX != null && scaleY != null) { 1423 g.scale(scaleX, scaleY); 1424 } 1503 g.setClip(0, 0, realWidth, realHeight); 1504 g.scale(scaleX, scaleY); 1425 1505 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 1426 1506 try { -
trunk/src/org/openstreetmap/josm/tools/ImageResource.java
r10356 r10358 14 14 15 15 import com.kitfox.svg.SVGDiagram; 16 import org.openstreetmap.josm.gui.util.GuiSizesHelper; 16 17 17 18 /** … … 50 51 CheckParameterUtil.ensureParameterNotNull(img); 51 52 this.baseImage = img; 53 54 img = scaleBaseImageIfNeeded(img); 55 52 56 imgCache.put(DEFAULT_DIMENSION, img); 57 } 58 59 /** Scale image according to screen DPI if needed. 60 * 61 * @param img an image loaded from file (it's width and height are virtual pixels) 62 * @return original img if virtual size is the same as real size or new image resized to real pixels 63 */ 64 private static Image scaleBaseImageIfNeeded(Image img) { 65 int imgWidth = img.getWidth(null); 66 int imgHeight = img.getHeight(null); 67 int realWidth = GuiSizesHelper.getSizeDpiAdjusted(imgWidth); 68 int realHeight = GuiSizesHelper.getSizeDpiAdjusted(imgHeight); 69 if (realWidth != -1 && realHeight != -1 && imgWidth != realWidth && imgHeight != realHeight) { 70 Image realImage = img.getScaledInstance(realWidth, realHeight, Image.SCALE_SMOOTH); 71 BufferedImage bimg = new BufferedImage(realWidth, realHeight, BufferedImage.TYPE_INT_ARGB); 72 bimg.getGraphics().drawImage(realImage, 0, 0, null); 73 img = bimg; 74 } 75 return img; 53 76 } 54 77 … … 88 111 */ 89 112 public void getImageIcon(AbstractAction a) { 90 ImageIcon icon = getImageIconBounded(ImageProvider.ImageSizes.SMALLICON.getImageDimension()); 113 Dimension iconDimension = ImageProvider.ImageSizes.SMALLICON.getImageDimension(); 114 ImageIcon icon = getImageIconBounded(iconDimension); 91 115 a.putValue(Action.SMALL_ICON, icon); 92 icon = getImageIconBounded(ImageProvider.ImageSizes.LARGEICON.getImageDimension()); 116 117 iconDimension = ImageProvider.ImageSizes.LARGEICON.getImageDimension(); 118 icon = getImageIconBounded(iconDimension); 93 119 a.putValue(Action.LARGE_ICON_KEY, icon); 94 120 a.putValue("ImageResource", this); … … 123 149 } 124 150 if (svg != null) { 125 BufferedImage bimg = ImageProvider.createImageFromSvg(svg, dim); 151 Dimension realDim = GuiSizesHelper.getDimensionDpiAdjusted(dim); 152 BufferedImage bimg = ImageProvider.createImageFromSvg(svg, realDim); 126 153 if (bimg == null) { 127 154 return null; … … 137 164 if (baseImage == null) throw new AssertionError(); 138 165 139 int width = dim.width;140 int height = dim.height;166 int realWidth = GuiSizesHelper.getSizeDpiAdjusted(dim.width); 167 int realHeight = GuiSizesHelper.getSizeDpiAdjusted(dim.height); 141 168 ImageIcon icon = new ImageIcon(baseImage); 142 if ( width == -1 && height == -1) {143 width = icon.getIconWidth();144 height = icon.getIconHeight();145 } else if ( width == -1) {146 width = Math.max(1, icon.getIconWidth() * height / icon.getIconHeight());147 } else if ( height == -1) {148 height = Math.max(1, icon.getIconHeight() * width / icon.getIconWidth());149 } 150 Image i = icon.getImage().getScaledInstance( width, height, Image.SCALE_SMOOTH);151 BufferedImage bimg = new BufferedImage( width, height, BufferedImage.TYPE_INT_ARGB);169 if (realWidth == -1 && realHeight == -1) { 170 realWidth = GuiSizesHelper.getSizeDpiAdjusted(icon.getIconWidth()); 171 realHeight = GuiSizesHelper.getSizeDpiAdjusted(icon.getIconHeight()); 172 } else if (realWidth == -1) { 173 realWidth = Math.max(1, icon.getIconWidth() * realHeight / icon.getIconHeight()); 174 } else if (realHeight == -1) { 175 realHeight = Math.max(1, icon.getIconHeight() * realWidth / icon.getIconWidth()); 176 } 177 Image i = icon.getImage().getScaledInstance(realWidth, realHeight, Image.SCALE_SMOOTH); 178 BufferedImage bimg = new BufferedImage(realWidth, realHeight, BufferedImage.TYPE_INT_ARGB); 152 179 bimg.getGraphics().drawImage(i, 0, 0, null); 153 180 if (overlayInfo != null) { … … 172 199 if (maxSize.width < -1 || maxSize.width == 0 || maxSize.height < -1 || maxSize.height == 0) 173 200 throw new IllegalArgumentException(maxSize+" is invalid"); 174 float realWidth;175 float realHeight;201 float sourceWidth; 202 float sourceHeight; 176 203 int maxWidth = maxSize.width; 177 204 int maxHeight = maxSize.height; 178 205 if (svg != null) { 179 realWidth = svg.getWidth();180 realHeight = svg.getHeight();206 sourceWidth = svg.getWidth(); 207 sourceHeight = svg.getHeight(); 181 208 } else { 182 209 if (baseImage == null) throw new AssertionError(); 183 210 ImageIcon icon = new ImageIcon(baseImage); 184 realWidth = icon.getIconWidth();185 realHeight = icon.getIconHeight();186 if ( realWidth <= maxWidth) {211 sourceWidth = icon.getIconWidth(); 212 sourceHeight = icon.getIconHeight(); 213 if (sourceWidth <= maxWidth) { 187 214 maxWidth = -1; 188 215 } 189 if ( realHeight <= maxHeight) {216 if (sourceHeight <= maxHeight) { 190 217 maxHeight = -1; 191 218 } … … 198 225 else if (maxHeight == -1) 199 226 return getImageIcon(new Dimension(maxWidth, -1)); 200 else if ( realWidth / maxWidth > realHeight / maxHeight)227 else if (sourceWidth / maxWidth > sourceHeight / maxHeight) 201 228 return getImageIcon(new Dimension(maxWidth, -1)); 202 229 else
Note:
See TracChangeset
for help on using the changeset viewer.