Changeset 12778 in osm for applications/editors/josm/plugins/imagewaypoint
- Timestamp:
- 2009-01-01T18:28:53+01:00 (16 years ago)
- Location:
- applications/editors/josm/plugins/imagewaypoint/src/org/insignificant/josm/plugins/imagewaypoint
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/imagewaypoint/src/org/insignificant/josm/plugins/imagewaypoint/ImageEntries.java
r12588 r12778 15 15 public final class ImageEntries { 16 16 private static final class ImageReadyListener implements 17 18 19 20 21 22 23 24 25 26 27 17 IImageReadyListener { 18 private final ImageEntries imageEntries; 19 20 public ImageReadyListener(final ImageEntries imageEntries) { 21 this.imageEntries = imageEntries; 22 } 23 24 public final void onImageReady(final ImageEntry imageEntry, 25 final Image image) { 26 this.imageEntries.setCurrentImage(imageEntry, image); 27 } 28 28 } 29 29 … … 39 39 40 40 private ImageEntries() { 41 42 43 44 45 46 47 41 this.images = new ArrayList<ImageEntry>(); 42 this.locatedImages = new ArrayList<ImageEntry>(); 43 this.listeners = new ArrayList<IImageChangeListener>(); 44 this.listener = new ImageReadyListener(this); 45 46 this.currentImageEntry = null; 47 this.currentImage = null; 48 48 } 49 49 50 50 public static final ImageEntries getInstance() { 51 51 return ImageEntries.INSTANCE; 52 52 } 53 53 54 54 public final void addListener(final IImageChangeListener listener) { 55 55 this.listeners.add(listener); 56 56 } 57 57 58 58 public final void removeListener(final IImageChangeListener listener) { 59 59 this.listeners.remove(listener); 60 60 } 61 61 62 62 public final void add(final File[] imageFiles) { 63 64 65 66 67 68 63 if (null != imageFiles) { 64 for (int index = 0; index < imageFiles.length; index++) { 65 this.images.add(new ImageEntry(imageFiles[index])); 66 } 67 this.associateAllLayers(); 68 } 69 69 } 70 70 71 71 public final void associateAllLayers() { 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 72 for (int index = 0; index < this.images.size(); index++) { 73 this.images.get(index).setWayPoint(null); 74 } 75 this.locatedImages.clear(); 76 77 if (null != Main.map && null != Main.map.mapView) { 78 final Collection<Layer> layerCollection = Main.map.mapView.getAllLayers(); 79 final Layer[] layers = layerCollection.toArray(new Layer[layerCollection.size()]); 80 81 for (int index = 0; index < layers.length; index++) { 82 if (layers[index] instanceof GpxLayer 83 && null != ((GpxLayer) layers[index]).data 84 && !((GpxLayer) layers[index]).data.fromServer) { 85 this.doAssociateLayer((GpxLayer) layers[index]); 86 } 87 } 88 89 for (IImageChangeListener listener : this.listeners) { 90 listener.onSelectedImageEntryChanged(this); 91 } 92 } 93 93 } 94 94 95 95 private final void doAssociateLayer(final GpxLayer gpxLayer) { 96 97 98 99 100 101 102 103 104 105 106 107 108 109 96 if (null != gpxLayer && null != gpxLayer.data 97 && !gpxLayer.data.fromServer) { 98 for (WayPoint wayPoint : gpxLayer.data.waypoints) { 99 final List<String> texts = this.getTextContentsFromWayPoint(wayPoint); 100 101 for (String text : texts) { 102 final ImageEntry image = this.findImageEntryWithFileName(text); 103 if (null != image) { 104 image.setWayPoint(wayPoint); 105 this.locatedImages.add(image); 106 } 107 } 108 } 109 } 110 110 } 111 111 112 112 private final List<String> getTextContentsFromWayPoint( 113 114 115 116 117 118 119 120 121 122 113 final WayPoint wayPoint) { 114 final List<String> texts = new ArrayList<String>(); 115 for(String s : new String[]{"name", "cmt", "desc"}) 116 { 117 String t = wayPoint.getString(s); 118 if(null != t && 0 < t.length()) 119 texts.add(t); 120 } 121 122 return texts; 123 123 } 124 124 … … 134 134 135 135 private final ImageEntry findImageEntryWithFileName(final String fileName) { 136 137 138 139 140 141 142 143 144 145 146 136 ImageEntry foundimage = null; 137 138 for (int index = 0; index < this.images.size() && null == foundimage; index++) { 139 final ImageEntry image = this.images.get(index); 140 if (null == image.getWayPoint() 141 && image.getFileName().startsWith(fileName)) { 142 foundimage = image; 143 } 144 } 145 146 return foundimage; 147 147 } 148 148 149 149 private final void setCurrentImage(final ImageEntry imageEntry, 150 151 152 153 154 155 156 157 150 final Image image) { 151 if (imageEntry == this.currentImageEntry) { 152 this.currentImage = image; 153 } 154 155 for (IImageChangeListener listener : this.listeners) { 156 listener.onSelectedImageEntryChanged(this); 157 } 158 158 } 159 159 160 160 public final ImageEntry[] getImages() { 161 161 return this.locatedImages.toArray(new ImageEntry[this.locatedImages.size()]); 162 162 } 163 163 164 164 public final ImageEntry getCurrentImageEntry() { 165 165 return this.currentImageEntry; 166 166 } 167 167 168 168 public final Image getCurrentImage() { 169 169 return this.currentImage; 170 170 } 171 171 172 172 public final boolean hasNext() { 173 174 173 return null != this.currentImageEntry 174 && this.locatedImages.indexOf(this.currentImageEntry) < this.locatedImages.size() - 1; 175 175 } 176 176 177 177 public final boolean hasPrevious() { 178 179 178 return null != this.currentImageEntry 179 && this.locatedImages.indexOf(this.currentImageEntry) > 0; 180 180 } 181 181 182 182 public final void next() { 183 184 185 186 183 if (null != this.currentImageEntry 184 && this.locatedImages.indexOf(this.currentImageEntry) < this.locatedImages.size() - 1) { 185 this.setCurrentImageEntry(this.locatedImages.get(this.locatedImages.indexOf(this.currentImageEntry) + 1)); 186 } 187 187 } 188 188 189 189 public final void previous() { 190 191 192 193 190 if (null != this.currentImageEntry 191 && this.locatedImages.indexOf(this.currentImageEntry) > 0) { 192 this.setCurrentImageEntry(this.locatedImages.get(this.locatedImages.indexOf(this.currentImageEntry) - 1)); 193 } 194 194 } 195 195 196 196 public final void rotateCurrentImageLeft() { 197 198 199 200 201 202 197 if (null != this.currentImageEntry) { 198 this.currentImageEntry.setOrientation(this.currentImageEntry.getOrientation() 199 .rotateLeft()); 200 } 201 202 this.setCurrentImageEntry(this.currentImageEntry); 203 203 } 204 204 205 205 public final void rotateCurrentImageRight() { 206 207 208 209 210 211 206 if (null != this.currentImageEntry) { 207 this.currentImageEntry.setOrientation(this.currentImageEntry.getOrientation() 208 .rotateRight()); 209 } 210 211 this.setCurrentImageEntry(this.currentImageEntry); 212 212 } 213 213 214 214 public final void setCurrentImageEntry(final ImageEntry imageEntry) { 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 215 if (null == imageEntry || this.locatedImages.contains(imageEntry)) { 216 if (null != this.currentImageEntry) { 217 this.currentImageEntry.flush(); 218 } 219 220 this.currentImageEntry = imageEntry; 221 this.currentImage = null; 222 223 for (IImageChangeListener listener : this.listeners) { 224 listener.onSelectedImageEntryChanged(this); 225 } 226 227 // now try to get the image 228 this.currentImageEntry.requestImage(this.listener); 229 } 230 230 } 231 231 } -
applications/editors/josm/plugins/imagewaypoint/src/org/insignificant/josm/plugins/imagewaypoint/ImageEntry.java
r12588 r12778 1 1 /** 2 * 2 * 3 3 */ 4 4 package org.insignificant.josm.plugins.imagewaypoint; … … 23 23 public final class ImageEntry implements Comparable<ImageEntry> { 24 24 public interface IImageReadyListener { 25 25 void onImageReady(ImageEntry imageEntry, Image image); 26 26 } 27 27 28 28 private static final class Observer implements ImageObserver { 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 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 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 } 51 51 } 52 52 53 53 public static final class Orientation { 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 54 private static final Orientation[] orientations = new Orientation[4]; 55 56 public static final Orientation NORMAL = new Orientation(tr("Normal"), 0); 57 public static final Orientation ROTATE_90 = new Orientation(tr("Rotate 90"), 58 1); 59 public static final Orientation ROTATE_180 = new Orientation(tr("Rotate 180"), 60 2); 61 public static final Orientation ROTATE_270 = new Orientation(tr("Rotate 270"), 62 3); 63 64 private final String name; 65 private final int index; 66 67 private Orientation(final String name, final int index) { 68 this.name = name; 69 this.index = index; 70 Orientation.orientations[index] = this; 71 } 72 73 public final Orientation rotateRight() { 74 if (this.index < Orientation.orientations.length - 1) { 75 return Orientation.orientations[this.index + 1]; 76 } else { 77 return Orientation.orientations[0]; 78 } 79 } 80 81 public final Orientation rotateLeft() { 82 if (this.index == 0) { 83 return Orientation.orientations[Orientation.orientations.length - 1]; 84 } else { 85 return Orientation.orientations[this.index - 1]; 86 } 87 } 88 89 @Override 90 public String toString() { 91 return "[" + this.name + "]"; 92 } 93 93 } 94 94 … … 108 108 109 109 public ImageEntry(final File file) { 110 111 112 113 114 115 116 117 118 110 this.filePath = file.getAbsolutePath(); 111 this.fileName = file.getName(); 112 this.observer = new Observer(this); 113 114 this.wayPoint = null; 115 this.orientation = Orientation.NORMAL; 116 this.listener = null; 117 this.normalImage = null; 118 this.rotatedImage = null; 119 119 } 120 120 121 121 public final int compareTo(final ImageEntry image) { 122 122 return this.fileName.compareTo(image.fileName); 123 123 } 124 124 125 125 public final String getFileName() { 126 126 return fileName; 127 127 } 128 128 129 129 public final WayPoint getWayPoint() { 130 130 return wayPoint; 131 131 } 132 132 133 133 public final void setWayPoint(final WayPoint wayPoint) { 134 134 this.wayPoint = wayPoint; 135 135 } 136 136 137 137 public final Orientation getOrientation() { 138 138 return orientation; 139 139 } 140 140 141 141 public final void setOrientation(final Orientation orientation) { 142 143 144 142 this.orientation = orientation; 143 this.normalImage = null; 144 this.rotatedImage = null; 145 145 } 146 146 147 147 public final Rectangle getBounds(final MapView mapView) { 148 149 150 151 152 153 154 155 156 157 158 159 160 148 final Rectangle bounds; 149 150 if (null == this.wayPoint) { 151 bounds = null; 152 } else { 153 final Point point = mapView.getPoint(this.getWayPoint().eastNorth); 154 bounds = new Rectangle(point.x - ImageEntry.ICON_WIDTH, 155 point.y - ImageEntry.ICON_HEIGHT, 156 ImageEntry.ICON_WIDTH, 157 ImageEntry.ICON_WIDTH); 158 } 159 160 return bounds; 161 161 } 162 162 163 163 public final void requestImage(final IImageReadyListener imageReadyListener) { 164 165 166 167 168 169 170 171 172 173 174 175 176 177 164 this.listener = imageReadyListener; 165 166 if (null == this.rotatedImage) { 167 final Image image = Toolkit.getDefaultToolkit() 168 .getImage(this.filePath); 169 if (Toolkit.getDefaultToolkit().prepareImage(image, 170 -1, 171 -1, 172 this.observer)) { 173 this.imageLoaded(image); 174 } 175 } else if (null != this.listener) { 176 this.listener.onImageReady(this, this.rotatedImage); 177 } 178 178 } 179 179 180 180 public final void flush() { 181 182 183 184 185 186 187 188 189 181 if (null != this.normalImage) { 182 this.normalImage.flush(); 183 this.normalImage = null; 184 } 185 186 if (null != this.rotatedImage) { 187 this.rotatedImage.flush(); 188 this.rotatedImage = null; 189 } 190 190 } 191 191 192 192 private final void imageLoaded(final Image image) { 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 193 if (Orientation.NORMAL == this.getOrientation()) { 194 this.rotatedImage = image; 195 } else { 196 final int[] buffer = new int[image.getWidth(null) 197 * image.getHeight(null)]; 198 PixelGrabber grabber = new PixelGrabber(image, 199 0, 200 0, 201 image.getWidth(null), 202 image.getHeight(null), 203 buffer, 204 0, 205 image.getWidth(null)); 206 try { 207 grabber.grabPixels(); 208 209 final int newHeight; 210 final int newWidth; 211 212 if (Orientation.ROTATE_180 == this.getOrientation()) { 213 newHeight = image.getHeight(null); 214 newWidth = image.getWidth(null); 215 } else { 216 newHeight = image.getWidth(null); 217 newWidth = image.getHeight(null); 218 } 219 220 final int[] destination = new int[image.getWidth(null) 221 * image.getHeight(null)]; 222 for (int x = 0; x < image.getWidth(null); x++) { 223 for (int y = 0; y < image.getHeight(null); y++) { 224 final int pix = buffer[x + (y * image.getWidth(null))]; 225 final int newX; 226 final int newY; 227 if (Orientation.ROTATE_90 == this.getOrientation()) { 228 newX = newWidth - y; 229 newY = x; 230 } else if (Orientation.ROTATE_180 == this.getOrientation()) { 231 newX = newWidth - x; 232 newY = newHeight - y; 233 } else { // Orientation.ROTATE_270 == 234 // this.getOrientation() 235 newX = y; 236 newY = newHeight - x; 237 } 238 final int newIndex = newX + (newY * newWidth); 239 if (newIndex < destination.length) { 240 destination[newIndex] = pix; 241 } 242 } 243 } 244 245 this.rotatedImage = Toolkit.getDefaultToolkit() 246 .createImage(new MemoryImageSource(newWidth, 247 newHeight, 248 destination, 249 0, 250 newWidth)); 251 } catch (final InterruptedException e) { 252 this.rotatedImage = null; 253 } 254 } 255 256 if (null != this.listener) { 257 this.listener.onImageReady(this, this.rotatedImage); 258 } 259 259 } 260 260 } -
applications/editors/josm/plugins/imagewaypoint/src/org/insignificant/josm/plugins/imagewaypoint/ImageWayPointDialog.java
r12588 r12778 23 23 public final class ImageWayPointDialog { 24 24 private static final class ImageComponent extends JComponent { 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 25 private static final long serialVersionUID = -5207198660736375133L; 26 27 private Image image; 28 29 public ImageComponent() { 30 this.image = null; 31 } 32 33 @Override 34 public final void paint(final Graphics g) { 35 if (null == this.image || 0 >= this.image.getWidth(null) 36 || 0 >= this.image.getHeight(null)) { 37 g.setColor(Color.white); 38 g.fillRect(0, 0, this.getSize().width, this.getSize().height); 39 } else { 40 final int maxWidth = this.getSize().width; 41 final int maxHeight = this.getSize().height; 42 final int imageWidth = this.image.getWidth(null); 43 final int imageHeight = this.image.getHeight(null); 44 45 final double aspect = 1.0 * imageWidth / imageHeight; 46 47 // what's the width if the height is 100%? 48 final int widthIfHeightIsMax = (int) (aspect * maxHeight); 49 50 // now find the real width and height 51 final int resizedWidth; 52 final int resizedHeight; 53 if (widthIfHeightIsMax > maxWidth) { 54 // oops - burst the width - so width should be the max, and 55 // work out the resulting height 56 resizedWidth = maxWidth; 57 resizedHeight = (int) (resizedWidth / aspect); 58 } else { 59 // that'll do... 60 resizedWidth = widthIfHeightIsMax; 61 resizedHeight = maxHeight; 62 } 63 64 g.drawImage(this.image, 65 (maxWidth - resizedWidth) / 2, 66 (maxHeight - resizedHeight) / 2, 67 resizedWidth, 68 resizedHeight, 69 Color.black, 70 null); 71 } 72 } 73 74 public final void setImage(final Image image) { 75 this.image = image; 76 this.repaint(); 77 } 78 78 } 79 79 80 80 private static final class ImageChangeListener implements 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 81 IImageChangeListener { 82 private final ImageWayPointDialog dialog; 83 84 public ImageChangeListener(final ImageWayPointDialog dialog) { 85 this.dialog = dialog; 86 } 87 88 public final void onAvailableImageEntriesChanged( 89 final ImageEntries entries) { 90 this.dialog.imageDisplay.setImage(entries.getCurrentImage()); 91 this.dialog.updateUI(); 92 } 93 94 public final void onSelectedImageEntryChanged(final ImageEntries entries) { 95 this.dialog.imageDisplay.setImage(entries.getCurrentImage()); 96 this.dialog.updateUI(); 97 } 98 98 } 99 99 100 100 private static final class PreviousAction extends JosmAction { 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 101 private static final long serialVersionUID = -7899209365124237890L; 102 103 private final ImageWayPointDialog dialog; 104 105 public PreviousAction(final ImageWayPointDialog dialog) { 106 super(tr("Previous"), 107 null, 108 tr("Previous image"), 109 null, 110 false); 111 this.dialog = dialog; 112 } 113 114 public final void actionPerformed(final ActionEvent actionEvent) { 115 if (ImageEntries.getInstance().hasPrevious()) { 116 ImageEntries.getInstance().previous(); 117 } 118 } 119 119 } 120 120 121 121 private static final class NextAction extends JosmAction { 122 123 124 125 126 127 128 129 130 131 132 133 134 135 122 private static final long serialVersionUID = 176134010956760988L; 123 124 private final ImageWayPointDialog dialog; 125 126 public NextAction(final ImageWayPointDialog dialog) { 127 super(tr("Next"), null, tr("Next image"), null, false); 128 this.dialog = dialog; 129 } 130 131 public final void actionPerformed(final ActionEvent actionEvent) { 132 if (ImageEntries.getInstance().hasNext()) { 133 ImageEntries.getInstance().next(); 134 } 135 } 136 136 } 137 137 138 138 private static final class RotateLeftAction extends JosmAction { 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 139 private static final long serialVersionUID = 3536922796446259943L; 140 141 private final ImageWayPointDialog dialog; 142 143 public RotateLeftAction(final ImageWayPointDialog dialog) { 144 super(tr("Rotate left"), 145 null, 146 tr("Rotate image left"), 147 null, 148 false); 149 this.dialog = dialog; 150 } 151 152 public final void actionPerformed(final ActionEvent actionEvent) { 153 ImageEntries.getInstance().rotateCurrentImageLeft(); 154 } 155 155 } 156 156 157 157 private static final class RotateRightAction extends JosmAction { 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 158 private static final long serialVersionUID = 1760186810341888993L; 159 160 private final ImageWayPointDialog dialog; 161 162 public RotateRightAction(final ImageWayPointDialog dialog) { 163 super(tr("Rotate right"), 164 null, 165 tr("Rotate image right"), 166 null, 167 false); 168 this.dialog = dialog; 169 } 170 171 public final void actionPerformed(final ActionEvent actionEvent) { 172 ImageEntries.getInstance().rotateCurrentImageRight(); 173 } 174 174 } 175 175 … … 185 185 186 186 private ImageWayPointDialog() { 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 187 this.dialog = new ToggleDialog(tr("WayPoint Image"), 188 "imagewaypoint", 189 tr("Display non-geotagged photos"), 190 Shortcut.registerShortcut("subwindow:imagewaypoint", tr("Toggle: {0}", tr("WayPoint Image")), 191 KeyEvent.VK_Y, Shortcut.GROUP_LAYER), 192 200); 193 194 this.previousAction = new PreviousAction(this); 195 this.nextAction = new NextAction(this); 196 this.rotateLeftAction = new RotateLeftAction(this); 197 this.rotateRightAction = new RotateRightAction(this); 198 199 final JButton previousButton = new JButton(this.previousAction); 200 final JButton nextButton = new JButton(this.nextAction); 201 final JButton rotateLeftButton = new JButton(this.rotateLeftAction); 202 final JButton rotateRightButton = new JButton(this.rotateRightAction); 203 204 // default layout, FlowLayout, is fine 205 final JPanel buttonPanel = new JPanel(); 206 buttonPanel.add(previousButton); 207 buttonPanel.add(nextButton); 208 buttonPanel.add(rotateLeftButton); 209 buttonPanel.add(rotateRightButton); 210 211 final JPanel mainPanel = new JPanel(); 212 mainPanel.setLayout(new BorderLayout()); 213 214 this.imageDisplay = new ImageComponent(); 215 mainPanel.add(buttonPanel, BorderLayout.SOUTH); 216 mainPanel.add(this.imageDisplay, BorderLayout.CENTER); 217 218 this.listener = new ImageChangeListener(this); 219 ImageEntries.getInstance().addListener(this.listener); 220 221 this.updateUI(); 222 dialog.add(mainPanel); 223 223 } 224 224 225 225 private final void updateUI() { 226 227 228 229 230 231 232 233 234 235 226 this.previousAction.setEnabled(ImageEntries.getInstance().hasPrevious()); 227 this.nextAction.setEnabled(ImageEntries.getInstance().hasNext()); 228 this.rotateLeftAction.setEnabled(null != ImageEntries.getInstance() 229 .getCurrentImageEntry()); 230 this.rotateRightAction.setEnabled(null != ImageEntries.getInstance() 231 .getCurrentImageEntry()); 232 233 if (null != Main.map) { 234 Main.map.repaint(); 235 } 236 236 } 237 237 238 238 public static ImageWayPointDialog getInstance() { 239 239 return ImageWayPointDialog.INSTANCE; 240 240 } 241 241 242 242 public final ToggleDialog getDisplayComponent() { 243 243 return this.dialog; 244 244 } 245 245 } -
applications/editors/josm/plugins/imagewaypoint/src/org/insignificant/josm/plugins/imagewaypoint/ImageWayPointLayer.java
r12588 r12778 20 20 public final class ImageWayPointLayer extends Layer { 21 21 private static final class ImageWayPointMouseListener extends MouseAdapter { 22 22 private final ImageWayPointLayer layer; 23 23 24 25 26 24 public ImageWayPointMouseListener(final ImageWayPointLayer layer) { 25 this.layer = layer; 26 } 27 27 28 29 30 31 32 28 @Override 29 public final void mouseClicked(final MouseEvent event) { 30 if (MouseEvent.BUTTON1 == event.getButton() && this.layer.visible) { 31 final ImageEntry[] images = ImageEntries.getInstance() 32 .getImages(); 33 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 34 if (null != images) { 35 boolean found = false; 36 // Note: the images are checked in the *reverse* order to 37 // which they're painted - this means than an image which 38 // partly obscures another will match the click first 39 for (int index = images.length - 1; !found && index >= 0; index--) { 40 final Rectangle bounds = images[index].getBounds(Main.map.mapView); 41 if (null != bounds && bounds.contains(event.getPoint())) { 42 found = true; 43 ImageEntries.getInstance() 44 .setCurrentImageEntry(images[index]); 45 } 46 } 47 } 48 } 49 } 50 50 } 51 51 52 52 private static final class ImageChangeListener implements 53 54 53 IImageChangeListener { 54 private final ImageWayPointLayer layer; 55 55 56 57 58 56 public ImageChangeListener(final ImageWayPointLayer layer) { 57 this.layer = layer; 58 } 59 59 60 61 62 63 60 public final void onAvailableImageEntriesChanged( 61 final ImageEntries entries) { 62 Main.map.repaint(); 63 } 64 64 65 66 67 65 public final void onSelectedImageEntryChanged(final ImageEntries entries) { 66 Main.map.repaint(); 67 } 68 68 } 69 69 … … 72 72 73 73 public ImageWayPointLayer() { 74 74 super(tr("Imported Images")); 75 75 76 76 Main.main.addLayer(this); 77 77 78 79 78 this.layerMouseListener = new ImageWayPointMouseListener(this); 79 Main.map.mapView.addMouseListener(this.layerMouseListener); 80 80 81 82 81 this.imageChangeListener = new ImageChangeListener(this); 82 ImageEntries.getInstance().addListener(this.imageChangeListener); 83 83 } 84 84 85 85 @Override 86 86 public final Icon getIcon() { 87 87 return ImageProvider.get("dialogs/imagewaypoint"); 88 88 } 89 89 90 90 @Override 91 91 public final Object getInfoComponent() { 92 92 return null; 93 93 } 94 94 95 95 @Override 96 96 public final Component[] getMenuEntries() { 97 97 return new Component[0]; 98 98 } 99 99 100 100 @Override 101 101 public final String getToolTipText() { 102 103 102 // TODO 103 return ""; 104 104 } 105 105 106 106 @Override 107 107 public final boolean isMergable(final Layer other) { 108 109 108 // TODO 109 return false; 110 110 } 111 111 112 112 @Override 113 113 public final void mergeFrom(final Layer from) { 114 114 // TODO not supported yet 115 115 } 116 116 117 117 @Override 118 118 public final void paint(final Graphics graphics, final MapView mapView) { 119 119 final ImageEntry[] images = ImageEntries.getInstance().getImages(); 120 120 121 122 123 121 if (null != images) { 122 final ImageEntry currentImage = ImageEntries.getInstance() 123 .getCurrentImageEntry(); 124 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 125 for (int index = 0; index < images.length; index++) { 126 final Rectangle bounds = images[index].getBounds(mapView); 127 if (null != bounds) { 128 if (images[index] == currentImage) { 129 ImageEntry.SELECTED_ICON.paintIcon(mapView, 130 graphics, 131 bounds.x, 132 bounds.y); 133 } else { 134 ImageEntry.ICON.paintIcon(mapView, 135 graphics, 136 bounds.x, 137 bounds.y); 138 } 139 } 140 } 141 } 142 142 } 143 143 144 144 @Override 145 145 public final void visitBoundingBox(final BoundingXYVisitor visitor) { 146 146 final ImageEntry[] images = ImageEntries.getInstance().getImages(); 147 147 148 149 150 148 if (null != images) { 149 for (int index = 0; index < images.length; index++) { 150 final ImageEntry imageEntry = images[index]; 151 151 152 153 154 155 156 157 152 if (null != imageEntry.getWayPoint() 153 && null != imageEntry.getWayPoint().eastNorth) { 154 visitor.visit(imageEntry.getWayPoint().eastNorth); 155 } 156 } 157 } 158 158 } 159 159 160 160 @Override 161 161 public final void destroy() { 162 162 super.destroy(); 163 163 164 165 164 Main.map.mapView.removeMouseListener(this.layerMouseListener); 165 ImageEntries.getInstance().removeListener(this.imageChangeListener); 166 166 } 167 167 } -
applications/editors/josm/plugins/imagewaypoint/src/org/insignificant/josm/plugins/imagewaypoint/ImageWayPointPlugin.java
r12588 r12778 24 24 public final class ImageWayPointPlugin extends org.openstreetmap.josm.plugins.Plugin { 25 25 private static final class ImageFileFilter extends FileFilter { 26 27 28 29 30 31 32 33 26 @Override 27 public final boolean accept(final File file) { 28 return file.isDirectory() 29 || file.getName().toLowerCase().endsWith(".jpg") 30 || file.getName().toLowerCase().endsWith(".jpeg") 31 || file.getName().toLowerCase().endsWith(".png") 32 || file.getName().toLowerCase().endsWith(".gif"); 33 } 34 34 35 36 37 38 35 @Override 36 public final String getDescription() { 37 return tr("Image files (*.jpg, *.jpeg, *.png, *.gif)"); 38 } 39 39 } 40 40 41 41 private static final class LoadImagesAction extends JosmAction { 42 42 private static final long serialVersionUID = 4480306223276347301L; 43 43 44 44 private final ImageWayPointPlugin plugin; 45 45 46 47 48 49 50 51 46 public LoadImagesAction(final ImageWayPointPlugin plugin) { 47 super(tr("Open images with ImageWayPoint"), 48 "imagewaypoint-open", 49 tr("Load set of images as a new layer."), 50 null, 51 false); 52 52 53 54 53 this.plugin = plugin; 54 } 55 55 56 57 58 59 60 61 56 public final void actionPerformed(final ActionEvent actionEvent) { 57 final JFileChooser fileChooser = new JFileChooser(Main.pref.get("tagimages.lastdirectory")); 58 fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); 59 fileChooser.setMultiSelectionEnabled(true); 60 fileChooser.setAcceptAllFileFilterUsed(false); 61 fileChooser.setFileFilter(new ImageFileFilter()); 62 62 63 63 fileChooser.showOpenDialog(Main.parent); 64 64 65 66 67 68 65 final File[] selectedFiles = fileChooser.getSelectedFiles(); 66 if (null != selectedFiles && 0 != selectedFiles.length) { 67 Main.pref.put("tagimages.lastdirectory", 68 fileChooser.getCurrentDirectory().getPath()); 69 69 70 71 72 70 // recursively find all files 71 final List<File> allFiles = new ArrayList<File>(); 72 this.plugin.addFiles(allFiles, selectedFiles); 73 73 74 75 76 74 // add files to ImageEntries 75 ImageEntries.getInstance() 76 .add(allFiles.toArray(new File[allFiles.size()])); 77 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 78 // check to see whether there's already an ImageWayPointLayer 79 boolean foundImageWayPointLayer = false; 80 if (null != Main.map && null != Main.map.mapView) { 81 final Collection<Layer> layerCollection = Main.map.mapView.getAllLayers(); 82 final Iterator<Layer> layerIterator = layerCollection.iterator(); 83 while (layerIterator.hasNext() && !foundImageWayPointLayer) { 84 if (layerIterator.next() instanceof ImageWayPointLayer) { 85 foundImageWayPointLayer = true; 86 } 87 } 88 } 89 if (!foundImageWayPointLayer) { 90 new ImageWayPointLayer(); 91 } 92 } 93 } 94 94 } 95 95 … … 98 98 */ 99 99 public ImageWayPointPlugin() { 100 101 102 100 // find the File menu 101 final JMenuBar menuBar = Main.main.menu; 102 JMenu fileMenu = null; 103 103 104 105 106 107 108 109 110 111 104 if (null != menuBar) { 105 for (int index = 0; index < menuBar.getMenuCount() 106 && null == fileMenu; index++) { 107 if (I18n.tr("File").equals(menuBar.getMenu(index).getText())) { 108 fileMenu = menuBar.getMenu(index); 109 } 110 } 111 } 112 112 113 114 115 116 117 113 if (null != fileMenu) { 114 // now create our 'load' menu item and add to the file menu 115 final JMenuItem menuItem = new JMenuItem(new LoadImagesAction(this)); 116 fileMenu.add(menuItem, 2); 117 } 118 118 } 119 119 120 120 @Override 121 121 public final void mapFrameInitialized(final MapFrame oldFrame, 122 123 124 125 126 127 128 122 final MapFrame newFrame) { 123 if (newFrame != null) { 124 newFrame.addToggleDialog(ImageWayPointDialog.getInstance() 125 .getDisplayComponent()); 126 } else { 127 ImageEntries.getInstance().setCurrentImageEntry(null); 128 } 129 129 } 130 130 131 131 private void addFiles(List<File> allFiles, File[] selectedFiles) { 132 133 134 135 136 137 138 139 132 for (int index = 0; index < selectedFiles.length; index++) { 133 final File selectedFile = selectedFiles[index]; 134 if (selectedFile.isDirectory()) { 135 this.addFiles(allFiles, selectedFile.listFiles()); 136 } else if (selectedFile.getName().toLowerCase().endsWith(".jpg")) { 137 allFiles.add(selectedFile); 138 } 139 } 140 140 } 141 141 }
Note:
See TracChangeset
for help on using the changeset viewer.