Changeset 7676 in josm for trunk/src/com/kitfox/svg/app/beans
- Timestamp:
- 2014-10-30T11:39:47+01:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/com/kitfox/svg/app/beans/SVGIcon.java
r6002 r7676 51 51 { 52 52 public static final long serialVersionUID = 1; 53 54 private PropertyChangeSupport changes = new PropertyChangeSupport(this); 53 54 public static final String PROP_AUTOSIZE = "PROP_AUTOSIZE"; 55 56 private final PropertyChangeSupport changes = new PropertyChangeSupport(this); 55 57 56 58 SVGUniverse svgUniverse = SVGCache.getSVGUniverse(); … … 63 65 private boolean clipToViewbox; 64 66 65 // private String svgPath;66 67 URI svgURI; 67 68 68 private boolean scaleToFit;69 // private boolean scaleToFit; 69 70 AffineTransform scaleXform = new AffineTransform(); 70 71 // Dimension preferredSize = new Dimension(100, 100); 71 72 public static final int AUTOSIZE_NONE = 0; 73 public static final int AUTOSIZE_HORIZ = 1; 74 public static final int AUTOSIZE_VERT = 2; 75 public static final int AUTOSIZE_BESTFIT = 3; 76 public static final int AUTOSIZE_STRETCH = 4; 77 private int autosize = AUTOSIZE_NONE; 78 72 79 Dimension preferredSize; 73 80 … … 92 99 public int getIconHeight() 93 100 { 94 if (scaleToFit && preferredSize != null) 101 if (preferredSize != null && 102 (autosize == AUTOSIZE_VERT || autosize == AUTOSIZE_STRETCH 103 || autosize == AUTOSIZE_BESTFIT)) 95 104 { 96 105 return preferredSize.height; … … 110 119 public int getIconWidth() 111 120 { 112 if (scaleToFit && preferredSize != null) 121 if (preferredSize != null && 122 (autosize == AUTOSIZE_HORIZ || autosize == AUTOSIZE_STRETCH 123 || autosize == AUTOSIZE_BESTFIT)) 113 124 { 114 125 return preferredSize.width; … … 172 183 173 184 174 175 if (!scaleToFit) 185 if (autosize == AUTOSIZE_NONE) 176 186 { 177 187 try … … 210 220 211 221 212 final Rectangle2D.Double rect = new Rectangle2D.Double(); 213 diagram.getViewRect(rect); 214 215 scaleXform.setToScale(width / rect.width, height / rect.height); 222 // final Rectangle2D.Double rect = new Rectangle2D.Double(); 223 // diagram.getViewRect(rect); 224 // 225 // scaleXform.setToScale(width / rect.width, height / rect.height); 226 double diaWidth = diagram.getWidth(); 227 double diaHeight = diagram.getHeight(); 228 229 double scaleW = 1; 230 double scaleH = 1; 231 if (autosize == AUTOSIZE_BESTFIT) 232 { 233 scaleW = scaleH = (height / diaHeight < width / diaWidth) 234 ? height / diaHeight : width / diaWidth; 235 } 236 else if (autosize == AUTOSIZE_HORIZ) 237 { 238 scaleW = scaleH = width / diaWidth; 239 } 240 else if (autosize == AUTOSIZE_VERT) 241 { 242 scaleW = scaleH = height / diaHeight; 243 } 244 else if (autosize == AUTOSIZE_STRETCH) 245 { 246 scaleW = width / diaWidth; 247 scaleH = height / diaHeight; 248 } 249 scaleXform.setToScale(scaleW, scaleH); 216 250 217 251 AffineTransform oldXform = g.getTransform(); … … 315 349 * If this SVG document has a viewbox, if scaleToFit is set, will scale the viewbox to match the 316 350 * preferred size of this icon 351 * @deprecated 352 * @return 317 353 */ 318 354 public boolean isScaleToFit() 319 355 { 320 return scaleToFit; 321 } 322 356 return autosize == AUTOSIZE_STRETCH; 357 } 358 359 /** 360 * @deprecated 361 * @return 362 */ 323 363 public void setScaleToFit(boolean scaleToFit) 324 364 { 325 boolean old = this.scaleToFit; 326 this.scaleToFit = scaleToFit; 327 changes.firePropertyChange("scaleToFit", old, scaleToFit); 365 setAutosize(AUTOSIZE_STRETCH); 366 // boolean old = this.scaleToFit; 367 // this.scaleToFit = scaleToFit; 368 // firePropertyChange("scaleToFit", old, scaleToFit); 328 369 } 329 370 … … 429 470 this.clipToViewbox = clipToViewbox; 430 471 } 431 472 473 /** 474 * @return the autosize 475 */ 476 public int getAutosize() 477 { 478 return autosize; 479 } 480 481 /** 482 * @param autosize the autosize to set 483 */ 484 public void setAutosize(int autosize) 485 { 486 int oldAutosize = this.autosize; 487 this.autosize = autosize; 488 changes.firePropertyChange(PROP_AUTOSIZE, oldAutosize, autosize); 489 } 490 432 491 }
Note:
See TracChangeset
for help on using the changeset viewer.