Changeset 32915 in osm for applications
- Timestamp:
- 2016-09-03T17:11:07+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/imagewaypoint
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/imagewaypoint/src/org/insignificant/josm/plugins/imagewaypoint/ImageEntries.java
r32288 r32915 22 22 } 23 23 24 @Override 24 25 public final void onImageReady(final ImageEntry imageEntry, 25 26 final Image image) { -
applications/editors/josm/plugins/imagewaypoint/src/org/insignificant/josm/plugins/imagewaypoint/ImageEntry.java
r16294 r32915 23 23 public final class ImageEntry implements Comparable<ImageEntry> { 24 24 public interface IImageReadyListener { 25 void onImageReady(ImageEntry imageEntry, Image image);25 void onImageReady(ImageEntry imageEntry, Image image); 26 26 } 27 27 28 28 private static final class Observer implements ImageObserver { 29 private final ImageEntry imageEntry; 30 31 public Observer(final ImageEntry imageEntry) { 32 this.imageEntry = imageEntry; 33 } 34 35 /** 36 * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, 37 * int, int, int, int) 38 * @return true if this ImageObserver still wants to be updates about 39 * image loading progress 40 */ 41 public final boolean imageUpdate(final Image image, 42 final int infoflags, final int x, final int y, final int width, 43 final int height) { 44 final boolean complete = ImageObserver.ALLBITS == (infoflags | ImageObserver.ALLBITS); 45 if (complete) { 46 this.imageEntry.imageLoaded(image); 47 } 48 49 return !complete; 50 } 29 private final ImageEntry imageEntry; 30 31 public Observer(final ImageEntry imageEntry) { 32 this.imageEntry = imageEntry; 33 } 34 35 /** 36 * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, 37 * int, int, int, int) 38 * @return true if this ImageObserver still wants to be updates about 39 * image loading progress 40 */ 41 @Override 42 public final boolean imageUpdate(final Image image, 43 final int infoflags, final int x, final int y, final int width, 44 final int height) { 45 final boolean complete = ImageObserver.ALLBITS == (infoflags | ImageObserver.ALLBITS); 46 if (complete) { 47 this.imageEntry.imageLoaded(image); 48 } 49 50 return !complete; 51 } 51 52 } 52 53 … … 119 120 } 120 121 122 @Override 121 123 public final int compareTo(final ImageEntry image) { 122 124 return this.fileName.compareTo(image.fileName); -
applications/editors/josm/plugins/imagewaypoint/src/org/insignificant/josm/plugins/imagewaypoint/ImageWayPointDialog.java
r30701 r32915 22 22 public final class ImageWayPointDialog { 23 23 private static final class ImageComponent extends JComponent { 24 private static final long serialVersionUID = -5207198660736375133L;25 26 private Image image;27 28 public ImageComponent() {29 this.image = null;30 }31 32 @Override33 public final void paint(final Graphics g) {34 if (null == this.image || 0 >= this.image.getWidth(null)35 || 0 >= this.image.getHeight(null)) {36 g.setColor(Color.white);37 g.fillRect(0, 0, this.getSize().width, this.getSize().height);38 } else {39 final int maxWidth = this.getSize().width;40 final int maxHeight = this.getSize().height;41 final int imageWidth = this.image.getWidth(null);42 final int imageHeight = this.image.getHeight(null);43 44 final double aspect = 1.0 * imageWidth / imageHeight;45 46 // what's the width if the height is 100%?47 final int widthIfHeightIsMax = (int) (aspect * maxHeight);48 49 // now find the real width and height50 final int resizedWidth;51 final int resizedHeight;52 if (widthIfHeightIsMax > maxWidth) {53 // oops - burst the width - so width should be the max, and54 // work out the resulting height55 resizedWidth = maxWidth;56 resizedHeight = (int) (resizedWidth / aspect);57 } else {58 // that'll do...59 resizedWidth = widthIfHeightIsMax;60 resizedHeight = maxHeight;61 }62 63 g.drawImage(this.image,64 (maxWidth - resizedWidth) / 2,65 (maxHeight - resizedHeight) / 2,66 resizedWidth,67 resizedHeight,68 Color.black,69 null);70 }71 }72 73 public final void setImage(final Image image) {74 this.image = image;75 this.repaint();76 }24 private static final long serialVersionUID = -5207198660736375133L; 25 26 private Image image; 27 28 public ImageComponent() { 29 this.image = null; 30 } 31 32 @Override 33 public final void paint(final Graphics g) { 34 if (null == this.image || 0 >= this.image.getWidth(null) 35 || 0 >= this.image.getHeight(null)) { 36 g.setColor(Color.white); 37 g.fillRect(0, 0, this.getSize().width, this.getSize().height); 38 } else { 39 final int maxWidth = this.getSize().width; 40 final int maxHeight = this.getSize().height; 41 final int imageWidth = this.image.getWidth(null); 42 final int imageHeight = this.image.getHeight(null); 43 44 final double aspect = 1.0 * imageWidth / imageHeight; 45 46 // what's the width if the height is 100%? 47 final int widthIfHeightIsMax = (int) (aspect * maxHeight); 48 49 // now find the real width and height 50 final int resizedWidth; 51 final int resizedHeight; 52 if (widthIfHeightIsMax > maxWidth) { 53 // oops - burst the width - so width should be the max, and 54 // work out the resulting height 55 resizedWidth = maxWidth; 56 resizedHeight = (int) (resizedWidth / aspect); 57 } else { 58 // that'll do... 59 resizedWidth = widthIfHeightIsMax; 60 resizedHeight = maxHeight; 61 } 62 63 g.drawImage(this.image, 64 (maxWidth - resizedWidth) / 2, 65 (maxHeight - resizedHeight) / 2, 66 resizedWidth, 67 resizedHeight, 68 Color.black, 69 null); 70 } 71 } 72 73 public final void setImage(final Image image) { 74 this.image = image; 75 this.repaint(); 76 } 77 77 } 78 78 79 79 private static final class ImageChangeListener implements 80 80 IImageChangeListener { 81 private final ImageWayPointDialog dialog; 82 83 public ImageChangeListener(final ImageWayPointDialog dialog) { 84 this.dialog = dialog; 85 } 86 87 public final void onAvailableImageEntriesChanged( 88 final ImageEntries entries) { 89 this.dialog.imageDisplay.setImage(entries.getCurrentImage()); 90 this.dialog.updateUI(); 91 } 92 93 public final void onSelectedImageEntryChanged(final ImageEntries entries) { 94 this.dialog.imageDisplay.setImage(entries.getCurrentImage()); 95 this.dialog.updateUI(); 96 } 81 private final ImageWayPointDialog dialog; 82 83 public ImageChangeListener(final ImageWayPointDialog dialog) { 84 this.dialog = dialog; 85 } 86 87 @Override 88 public final void onAvailableImageEntriesChanged( 89 final ImageEntries entries) { 90 this.dialog.imageDisplay.setImage(entries.getCurrentImage()); 91 this.dialog.updateUI(); 92 } 93 94 @Override 95 public final void onSelectedImageEntryChanged(final ImageEntries entries) { 96 this.dialog.imageDisplay.setImage(entries.getCurrentImage()); 97 this.dialog.updateUI(); 98 } 97 99 } 98 100 … … 107 109 } 108 110 111 @Override 109 112 public final void actionPerformed(final ActionEvent actionEvent) { 110 113 if (ImageEntries.getInstance().hasPrevious()) { … … 120 123 } 121 124 125 @Override 122 126 public final void actionPerformed(final ActionEvent actionEvent) { 123 127 if (ImageEntries.getInstance().hasNext()) { … … 137 141 } 138 142 143 @Override 139 144 public final void actionPerformed(final ActionEvent actionEvent) { 140 145 ImageEntries.getInstance().rotateCurrentImageLeft(); … … 152 157 } 153 158 159 @Override 154 160 public final void actionPerformed(final ActionEvent actionEvent) { 155 161 ImageEntries.getInstance().rotateCurrentImageRight(); -
applications/editors/josm/plugins/imagewaypoint/src/org/insignificant/josm/plugins/imagewaypoint/ImageWayPointLayer.java
r32499 r32915 52 52 53 53 private static final class ImageChangeListener implements IImageChangeListener { 54 @Override 54 55 public final void onAvailableImageEntriesChanged( 55 56 final ImageEntries entries) { … … 57 58 } 58 59 60 @Override 59 61 public final void onSelectedImageEntryChanged(final ImageEntries entries) { 60 62 Main.map.repaint();
Note:
See TracChangeset
for help on using the changeset viewer.