Changeset 12778 in osm for applications/editors/josm/plugins/openstreetbugs
- Timestamp:
- 2009-01-01T18:28:53+01:00 (16 years ago)
- Location:
- applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb
- Files:
-
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/ConfigKeys.java
r11157 r12778 1 1 /* Copyright (c) 2008, Henrik Niehaus 2 2 * All rights reserved. 3 * 3 * 4 4 * Redistribution and use in source and binary forms, with or without 5 5 * modification, are permitted provided that the following conditions are met: 6 * 6 * 7 7 * 1. Redistributions of source code must retain the above copyright notice, 8 8 * this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 11 11 * and/or other materials provided with the distribution. 12 * 3. Neither the name of the project nor the names of its 13 * contributors may be used to endorse or promote products derived from this 12 * 3. Neither the name of the project nor the names of its 13 * contributors may be used to endorse or promote products derived from this 14 14 * software without specific prior written permission. 15 * 15 * 16 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE … … 29 29 30 30 public class ConfigKeys { 31 32 33 34 35 36 37 31 public static final String OSB_API_DISABLED = "osb.api.disabled"; 32 public static final String OSB_API_URI_CLOSE = "osb.uri.close"; 33 public static final String OSB_API_URI_EDIT = "osb.uri.edit"; 34 public static final String OSB_API_URI_DOWNLOAD = "osb.uri.download"; 35 public static final String OSB_API_URI_NEW = "osb.uri.new"; 36 public static final String OSB_NICKNAME = "osb.nickname"; 37 public static final String OSB_AUTO_DOWNLOAD = "osb.auto_download"; 38 38 } -
applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/OsbDownloadLoop.java
r12588 r12778 1 1 /* Copyright (c) 2008, Henrik Niehaus 2 2 * All rights reserved. 3 * 3 * 4 4 * Redistribution and use in source and binary forms, with or without 5 5 * modification, are permitted provided that the following conditions are met: 6 * 6 * 7 7 * 1. Redistributions of source code must retain the above copyright notice, 8 8 * this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 11 11 * and/or other materials provided with the distribution. 12 * 3. Neither the name of the project nor the names of its 13 * contributors may be used to endorse or promote products derived from this 12 * 3. Neither the name of the project nor the names of its 13 * contributors may be used to endorse or promote products derived from this 14 14 * software without specific prior written permission. 15 * 15 * 16 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE … … 36 36 37 37 public class OsbDownloadLoop extends Thread { 38 39 private static OsbDownloadLoop instance;40 41 private long countdown = TimeUnit.SECONDS.toMillis(1);42 43 private boolean downloadDone = false;44 45 private final int INTERVAL = 100;46 47 private OsbPlugin plugin;48 49 private Point2D lastCenter;50 51 public OsbDownloadLoop() {52 setName(tr("OpenStreetBugs download loop"));53 start();54 }55 56 public static synchronized OsbDownloadLoop getInstance() {57 if(instance == null) {58 instance = new OsbDownloadLoop();59 }60 return instance;61 }62 63 @Override64 public void run() {65 try {66 while(true) {67 countdown -= INTERVAL;68 69 // if the center of the map has changed, the user has dragged or70 // zoomed the map71 if(Main.map != null && Main.map.mapView != null) {72 Point2D currentCenter = Main.map.mapView.getCenter();73 if(currentCenter != null && !currentCenter.equals(lastCenter)) {74 resetCountdown();75 lastCenter = currentCenter;76 }77 }78 79 // auto download if configured80 if( Main.pref.getBoolean(ConfigKeys.OSB_AUTO_DOWNLOAD) && OsbPlugin.active ) {81 if(countdown < 0) {82 if(!downloadDone) {83 if(plugin != null) {84 plugin.updateData();85 downloadDone = true;86 }87 } else {88 countdown = -1;89 }90 }91 }92 93 Thread.sleep(INTERVAL);94 }95 } catch (InterruptedException e) {96 e.printStackTrace();97 }98 }99 100 public void resetCountdown() {101 downloadDone = false;102 countdown = TimeUnit.SECONDS.toMillis(1);103 }104 38 105 public void setPlugin(OsbPlugin plugin) { 106 this.plugin = plugin; 107 } 39 private static OsbDownloadLoop instance; 40 41 private long countdown = TimeUnit.SECONDS.toMillis(1); 42 43 private boolean downloadDone = false; 44 45 private final int INTERVAL = 100; 46 47 private OsbPlugin plugin; 48 49 private Point2D lastCenter; 50 51 public OsbDownloadLoop() { 52 setName(tr("OpenStreetBugs download loop")); 53 start(); 54 } 55 56 public static synchronized OsbDownloadLoop getInstance() { 57 if(instance == null) { 58 instance = new OsbDownloadLoop(); 59 } 60 return instance; 61 } 62 63 @Override 64 public void run() { 65 try { 66 while(true) { 67 countdown -= INTERVAL; 68 69 // if the center of the map has changed, the user has dragged or 70 // zoomed the map 71 if(Main.map != null && Main.map.mapView != null) { 72 Point2D currentCenter = Main.map.mapView.getCenter(); 73 if(currentCenter != null && !currentCenter.equals(lastCenter)) { 74 resetCountdown(); 75 lastCenter = currentCenter; 76 } 77 } 78 79 // auto download if configured 80 if( Main.pref.getBoolean(ConfigKeys.OSB_AUTO_DOWNLOAD) && OsbPlugin.active ) { 81 if(countdown < 0) { 82 if(!downloadDone) { 83 if(plugin != null) { 84 plugin.updateData(); 85 downloadDone = true; 86 } 87 } else { 88 countdown = -1; 89 } 90 } 91 } 92 93 Thread.sleep(INTERVAL); 94 } 95 } catch (InterruptedException e) { 96 e.printStackTrace(); 97 } 98 } 99 100 public void resetCountdown() { 101 downloadDone = false; 102 countdown = TimeUnit.SECONDS.toMillis(1); 103 } 104 105 public void setPlugin(OsbPlugin plugin) { 106 this.plugin = plugin; 107 } 108 108 } -
applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/OsbLayer.java
r12588 r12778 1 1 /* Copyright (c) 2008, Henrik Niehaus 2 2 * All rights reserved. 3 * 3 * 4 4 * Redistribution and use in source and binary forms, with or without 5 5 * modification, are permitted provided that the following conditions are met: 6 * 6 * 7 7 * 1. Redistributions of source code must retain the above copyright notice, 8 8 * this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 11 11 * and/or other materials provided with the distribution. 12 * 3. Neither the name of the project nor the names of its 13 * contributors may be used to endorse or promote products derived from this 12 * 3. Neither the name of the project nor the names of its 13 * contributors may be used to endorse or promote products derived from this 14 14 * software without specific prior written permission. 15 * 15 * 16 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE … … 62 62 63 63 public class OsbLayer extends Layer implements MouseListener { 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 64 65 private DataSet data; 66 67 private Collection<? extends OsmPrimitive> selection; 68 69 private JToolTip tooltip = new JToolTip(); 70 71 public OsbLayer(DataSet dataSet, String name) { 72 super(name); 73 this.data = dataSet; 74 DataSet.selListeners.add(new SelectionChangedListener() { 75 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 76 selection = newSelection; 77 } 78 }); 79 80 Main.map.mapView.addMouseListener(this); 81 } 82 83 @Override 84 public Object getInfoComponent() { 85 return getToolTipText(); 86 } 87 88 @Override 89 public Component[] getMenuEntries() { 90 return new Component[]{ 91 91 new JMenuItem(new LayerListDialog.ShowHideLayerAction(this)), 92 92 new JMenuItem(new LayerListDialog.DeleteLayerAction(this)), … … 95 95 new JSeparator(), 96 96 new JMenuItem(new LayerListPopup.InfoAction(this))}; 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 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 223 224 97 } 98 99 @Override 100 public String getToolTipText() { 101 return tr("Displays OpenStreetBugs issues"); 102 } 103 104 @Override 105 public boolean isMergable(Layer other) { 106 return false; 107 } 108 109 @Override 110 public void mergeFrom(Layer from) {} 111 112 @Override 113 public void paint(Graphics g, MapView mv) { 114 Object[] nodes = data.nodes.toArray(); 115 for (int i = 0; i < nodes.length; i++) { 116 Node node = (Node) nodes[i]; 117 118 // don't paint deleted nodes 119 if(node.deleted) { 120 continue; 121 } 122 123 Point p = mv.getPoint(node.eastNorth); 124 125 ImageIcon icon = OsbPlugin.loadIcon("icon_error16.png"); 126 if("1".equals(node.get("state"))) { 127 icon = OsbPlugin.loadIcon("icon_valid16.png"); 128 } 129 int width = icon.getIconWidth(); 130 int height = icon.getIconHeight(); 131 132 g.drawImage(icon.getImage(), p.x - (width / 2), p.y - (height / 2), new ImageObserver() { 133 public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) { 134 return false; 135 } 136 }); 137 138 139 if(selection != null && selection.contains(node)) { 140 // draw description 141 String desc = node.get("note"); 142 if(desc != null) { 143 // format with html 144 StringBuilder sb = new StringBuilder("<html>"); 145 //sb.append(desc.replaceAll("\\|", "<br>")); 146 sb.append(desc.replaceAll("<hr />", "<hr>")); 147 sb.append("</html>"); 148 desc = sb.toString(); 149 150 // determine tooltip dimensions 151 int tooltipWidth = 0; 152 Rectangle2D fontBounds = null; 153 String[] lines = desc.split("<hr>"); 154 for (int j = 0; j < lines.length; j++) { 155 String line = lines[j]; 156 fontBounds = g.getFontMetrics().getStringBounds(line, g); 157 tooltipWidth = Math.max(tooltipWidth, (int)fontBounds.getWidth()); 158 } 159 160 // FIXME hiehgt calculations doesn't work with all LAFs 161 int lineCount = lines.length; 162 int HR_SIZE = 10; 163 int tooltipHeight = lineCount * (int)fontBounds.getHeight() + HR_SIZE * (lineCount - 1); 164 165 // draw description as a tooltip 166 tooltip.setTipText(desc); 167 tooltip.setSize(tooltipWidth+10, tooltipHeight + 6); 168 169 int tx = p.x + (width / 2) + 5; 170 int ty = (int)(p.y - height / 2); 171 g.translate(tx, ty); 172 tooltip.paint(g); 173 g.translate(-tx, -ty); 174 } 175 176 // draw selection border 177 g.setColor(ColorHelper.html2color(Main.pref.get("color.selected"))); 178 g.drawRect(p.x - (width / 2), p.y - (height / 2), 16, 16); 179 } 180 } 181 } 182 183 @Override 184 public void visitBoundingBox(BoundingXYVisitor v) {} 185 186 @Override 187 public Icon getIcon() { 188 return OsbPlugin.loadIcon("icon_error16.png"); 189 } 190 191 private Node getNearestNode(Point p) { 192 double snapDistance = 10; 193 double minDistanceSq = Double.MAX_VALUE; 194 Node minPrimitive = null; 195 for (Node n : data.nodes) { 196 if (n.deleted || n.incomplete) 197 continue; 198 Point sp = Main.map.mapView.getPoint(n.eastNorth); 199 double dist = p.distanceSq(sp); 200 if (minDistanceSq > dist && p.distance(sp) < snapDistance) { 201 minDistanceSq = p.distanceSq(sp); 202 minPrimitive = n; 203 } 204 // prefer already selected node when multiple nodes on one point 205 else if(minDistanceSq == dist && n.selected && !minPrimitive.selected) 206 { 207 minPrimitive = n; 208 } 209 } 210 return minPrimitive; 211 } 212 213 public void mouseClicked(MouseEvent e) { 214 if(e.getButton() == MouseEvent.BUTTON1) { 215 if(Main.map.mapView.getActiveLayer() == this) { 216 Node n = (Node) getNearestNode(e.getPoint()); 217 if(data.nodes.contains(n)) { 218 data.setSelected(n); 219 } 220 } 221 } 222 } 223 224 public void mousePressed(MouseEvent e) { 225 225 mayTriggerPopup(e); 226 226 } … … 229 229 mayTriggerPopup(e); 230 230 } 231 231 232 232 private void mayTriggerPopup(MouseEvent e) { 233 233 if(e.isPopupTrigger()) { 234 235 236 237 238 239 240 241 } 242 } 243 244 245 246 234 if(Main.map.mapView.getActiveLayer() == this) { 235 Node n = (Node) getNearestNode(e.getPoint()); 236 OsbAction.setSelectedNode(n); 237 if(data.nodes.contains(n)) { 238 PopupFactory.createPopup(n).show(e.getComponent(), e.getX(), e.getY()); 239 } 240 } 241 } 242 } 243 244 public void mouseEntered(MouseEvent e) {} 245 246 public void mouseExited(MouseEvent e) {} 247 247 } -
applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/OsbObserver.java
r11157 r12778 1 1 /* Copyright (c) 2008, Henrik Niehaus 2 2 * All rights reserved. 3 * 3 * 4 4 * Redistribution and use in source and binary forms, with or without 5 5 * modification, are permitted provided that the following conditions are met: 6 * 6 * 7 7 * 1. Redistributions of source code must retain the above copyright notice, 8 8 * this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 11 11 * and/or other materials provided with the distribution. 12 * 3. Neither the name of the project nor the names of its 13 * contributors may be used to endorse or promote products derived from this 12 * 3. Neither the name of the project nor the names of its 13 * contributors may be used to endorse or promote products derived from this 14 14 * software without specific prior written permission. 15 * 15 * 16 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE … … 31 31 32 32 public interface OsbObserver { 33 33 public void update(DataSet dataset); 34 34 } -
applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/OsbPlugin.java
r12588 r12778 60 60 public class OsbPlugin extends Plugin implements LayerChangeListener { 61 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 62 private DataSet dataSet; 63 64 private UploadHook uploadHook; 65 66 private OsbDialog dialog; 67 68 private OsbLayer layer; 69 70 public static boolean active = false; 71 72 private DownloadAction download = new DownloadAction(); 73 74 public OsbPlugin() { 75 super(); 76 initConfig(); 77 dataSet = new DataSet(); 78 uploadHook = new OsbUploadHook(); 79 dialog = new OsbDialog(this); 80 80 OsbLayer.listeners.add(dialog); 81 81 OsbLayer.listeners.add(this); 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 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 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 82 } 83 84 private void initConfig() { 85 String debug = Main.pref.get(ConfigKeys.OSB_API_DISABLED); 86 if(debug == null || debug.length() == 0) { 87 debug = "false"; 88 Main.pref.put(ConfigKeys.OSB_API_DISABLED, debug); 89 } 90 91 String uri = Main.pref.get(ConfigKeys.OSB_API_URI_EDIT); 92 if(uri == null || uri.length() == 0) { 93 uri = "http://openstreetbugs.appspot.com/editPOIexec"; 94 Main.pref.put(ConfigKeys.OSB_API_URI_EDIT, uri); 95 } 96 97 uri = Main.pref.get(ConfigKeys.OSB_API_URI_CLOSE); 98 if(uri == null || uri.length() == 0) { 99 uri = "http://openstreetbugs.appspot.com/closePOIexec"; 100 Main.pref.put(ConfigKeys.OSB_API_URI_CLOSE, uri); 101 } 102 103 uri = Main.pref.get(ConfigKeys.OSB_API_URI_DOWNLOAD); 104 if(uri == null || uri.length() == 0) { 105 uri = "http://openstreetbugs.appspot.com/getBugs"; 106 Main.pref.put(ConfigKeys.OSB_API_URI_DOWNLOAD, uri); 107 } 108 109 uri = Main.pref.get(ConfigKeys.OSB_API_URI_NEW); 110 if(uri == null || uri.length() == 0) { 111 uri = "http://openstreetbugs.appspot.com/addPOIexec"; 112 Main.pref.put(ConfigKeys.OSB_API_URI_NEW, uri); 113 } 114 115 String auto_download = Main.pref.get(ConfigKeys.OSB_AUTO_DOWNLOAD); 116 if(auto_download == null || auto_download.length() == 0) { 117 auto_download = "true"; 118 Main.pref.put(ConfigKeys.OSB_AUTO_DOWNLOAD, auto_download); 119 } 120 } 121 122 /** 123 * Determines the bounds of the current selected layer 124 * @return 125 */ 126 protected Bounds bounds(){ 127 MapView mv = Main.map.mapView; 128 return new Bounds( 129 mv.getLatLon(0, mv.getHeight()), 130 mv.getLatLon(mv.getWidth(), 0)); 131 } 132 133 public void updateData() { 134 // determine the bounds of the currently visible area 135 Bounds bounds = null; 136 try { 137 bounds = bounds(); 138 } catch (Exception e) { 139 // something went wrong, probably the mapview isn't fully initialized 140 System.err.println("OpenStreetBugs: Couldn't determine bounds of currently visible rect. Cancel auto update"); 141 return; 142 } 143 144 try { 145 // download the data 146 download.execute(dataSet, bounds); 147 148 // display the parsed data 149 if(!dataSet.nodes.isEmpty()) { 150 updateGui(); 151 } 152 } catch (Exception e) { 153 JOptionPane.showMessageDialog(Main.parent, e.getMessage()); 154 e.printStackTrace(); 155 } 156 } 157 158 public void updateGui() { 159 // update dialog 160 dialog.update(dataSet); 161 162 // create a new layer if necessary 163 updateLayer(dataSet); 164 165 // repaint view, so that changes get visible 166 Main.map.mapView.repaint(); 167 } 168 169 private void updateLayer(DataSet osbData) { 170 if(layer == null) { 171 layer = new OsbLayer(osbData, "OpenStreetBugs"); 172 Main.main.addLayer(layer); 173 } 174 } 175 176 @Override 177 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 178 if (oldFrame==null && newFrame!=null) { // map frame added 179 // add the dialog 180 newFrame.addToggleDialog(dialog); 181 182 // add the upload hook 183 LinkedList<UploadHook> hooks = ((UploadAction) Main.main.menu.upload).uploadHooks; 184 hooks.add(0, uploadHook); 185 186 // add a listener to the plugin toggle button 187 final JToggleButton toggle = (JToggleButton) dialog.action.button; 188 active = toggle.isSelected(); 189 toggle.addActionListener(new ActionListener() { 190 private boolean download = true; 191 192 public void actionPerformed(ActionEvent e) { 193 active = toggle.isSelected(); 194 if (toggle.isSelected() && download) { 195 Main.worker.execute(new Runnable() { 196 public void run() { 197 updateData(); 198 } 199 }); 200 download = false; 201 } 202 } 203 }); 204 } else if (oldFrame!=null && newFrame==null ) { // map frame removed 205 206 } 207 } 208 209 public static ImageIcon loadIcon(String name) { 210 URL url = OsbPlugin.class.getResource("/images/".concat(name)); 211 return new ImageIcon(url); 212 } 213 214 public void activeLayerChange(Layer oldLayer, Layer newLayer) {} 215 216 public void layerAdded(Layer newLayer) { 217 if(newLayer instanceof OsmDataLayer) { 218 active = ((JToggleButton)dialog.action.button).isSelected(); 219 220 // start the auto download loop 221 OsbDownloadLoop.getInstance().setPlugin(this); 222 } 223 } 224 225 public void layerRemoved(Layer oldLayer) { 226 if(oldLayer == layer) { 227 layer = null; 228 } 229 } 230 231 public OsbLayer getLayer() { 232 return layer; 233 } 234 235 public void setLayer(OsbLayer layer) { 236 this.layer = layer; 237 } 238 239 public DataSet getDataSet() { 240 return dataSet; 241 } 242 243 public void setDataSet(DataSet dataSet) { 244 this.dataSet = dataSet; 245 } 246 246 } -
applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/OsbUploadHook.java
r12588 r12778 1 1 /* Copyright (c) 2008, Henrik Niehaus 2 2 * All rights reserved. 3 * 3 * 4 4 * Redistribution and use in source and binary forms, with or without 5 5 * modification, are permitted provided that the following conditions are met: 6 * 6 * 7 7 * 1. Redistributions of source code must retain the above copyright notice, 8 8 * this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 11 11 * and/or other materials provided with the distribution. 12 * 3. Neither the name of the project nor the names of its 13 * contributors may be used to endorse or promote products derived from this 12 * 3. Neither the name of the project nor the names of its 13 * contributors may be used to endorse or promote products derived from this 14 14 * software without specific prior written permission. 15 * 15 * 16 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE … … 41 41 public class OsbUploadHook implements UploadHook { 42 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 43 public boolean checkUpload(Collection<OsmPrimitive> add, Collection<OsmPrimitive> update, 44 Collection<OsmPrimitive> delete) 45 { 46 boolean containsOsbData = checkOpenStreetBugs(add); 47 containsOsbData |= checkOpenStreetBugs(update); 48 containsOsbData |= checkOpenStreetBugs(delete); 49 if(containsOsbData) { 50 JOptionPane.showMessageDialog(Main.parent, 51 tr("<html>The selected data contains data from OpenStreetBugs.<br>" + 52 "You cannot upload these data. Maybe you have selected the wrong layer?"), 53 tr("Warning"), JOptionPane.WARNING_MESSAGE); 54 return false; 55 } else { 56 return true; 57 } 58 } 59 59 60 61 62 63 64 65 66 67 68 60 private boolean checkOpenStreetBugs(Collection<OsmPrimitive> osmPrimitives) { 61 for (Iterator<OsmPrimitive> iterator = osmPrimitives.iterator(); iterator.hasNext();) { 62 OsmPrimitive osmPrimitive = iterator.next(); 63 if(osmPrimitive.get("openstreetbug") != null) { 64 return true; 65 } 66 } 67 return false; 68 } 69 69 } -
applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/api/CloseAction.java
r12640 r12778 1 1 /* Copyright (c) 2008, Henrik Niehaus 2 2 * All rights reserved. 3 * 3 * 4 4 * Redistribution and use in source and binary forms, with or without 5 5 * modification, are permitted provided that the following conditions are met: 6 * 6 * 7 7 * 1. Redistributions of source code must retain the above copyright notice, 8 8 * this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 11 11 * and/or other materials provided with the distribution. 12 * 3. Neither the name of the project nor the names of its 13 * contributors may be used to endorse or promote products derived from this 12 * 3. Neither the name of the project nor the names of its 13 * contributors may be used to endorse or promote products derived from this 14 14 * software without specific prior written permission. 15 * 15 * 16 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE … … 40 40 41 41 public class CloseAction { 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 42 43 private final String CHARSET = "UTF-8"; 44 45 public void execute(Node n) throws IOException { 46 // create the URI for the data download 47 String uri = Main.pref.get(ConfigKeys.OSB_API_URI_CLOSE); 48 String post = new StringBuilder("id=") 49 .append(n.get("id")) 50 .toString(); 51 52 String result = null; 53 if(Main.pref.getBoolean(ConfigKeys.OSB_API_DISABLED)) { 54 result = "ok"; 55 } else { 56 result = HttpUtils.post(uri, null, post, CHARSET); 57 } 58 59 if("ok".equalsIgnoreCase(result)) { 60 n.put("state", "1"); 61 Main.map.mapView.repaint(); 62 } else { 63 JOptionPane.showMessageDialog(Main.parent, 64 tr("An error occurred: {0}", new Object[] {result}), 65 tr("Error"), 66 JOptionPane.ERROR_MESSAGE); 67 } 68 } 69 69 } -
applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/api/DownloadAction.java
r11579 r12778 1 1 /* Copyright (c) 2008, Henrik Niehaus 2 2 * All rights reserved. 3 * 3 * 4 4 * Redistribution and use in source and binary forms, with or without 5 5 * modification, are permitted provided that the following conditions are met: 6 * 6 * 7 7 * 1. Redistributions of source code must retain the above copyright notice, 8 8 * this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 11 11 * and/or other materials provided with the distribution. 12 * 3. Neither the name of the project nor the names of its 13 * contributors may be used to endorse or promote products derived from this 12 * 3. Neither the name of the project nor the names of its 13 * contributors may be used to endorse or promote products derived from this 14 14 * software without specific prior written permission. 15 * 15 * 16 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE … … 41 41 42 42 public class DownloadAction { 43 44 private final String CHARSET = "UTF-8";45 46 public void execute(DataSet dataset, Bounds bounds) throws IOException {47 // create the URI for the data download48 String uri = Main.pref.get(ConfigKeys.OSB_API_URI_DOWNLOAD);49 43 50 // check zoom level 51 if(Main.map.mapView.zoom() > 15 || Main.map.mapView.zoom() < 9) { 52 return; 53 } 54 55 // add query params to the uri 56 StringBuilder sb = new StringBuilder(uri) 57 .append("?b=").append(bounds.min.lat()) 58 .append("&t=").append(bounds.max.lat()) 59 .append("&l=").append(bounds.min.lon()) 60 .append("&r=").append(bounds.max.lon()); 61 uri = sb.toString(); 44 private final String CHARSET = "UTF-8"; 62 45 63 // download the data 64 String content = HttpUtils.get(uri, null, CHARSET); 65 66 // clear dataset 67 dataset.nodes.clear(); 68 dataset.relations.clear(); 69 dataset.ways.clear(); 70 71 // parse the data 72 parseData(dataset, content); 73 } 46 public void execute(DataSet dataset, Bounds bounds) throws IOException { 47 // create the URI for the data download 48 String uri = Main.pref.get(ConfigKeys.OSB_API_URI_DOWNLOAD); 74 49 75 private void parseData(DataSet dataSet, String content) { 76 String idPattern = "\\d+"; 77 String floatPattern = "-?\\d+\\.\\d+"; 78 String pattern = "putAJAXMarker\\(("+idPattern+"),("+floatPattern+"),("+floatPattern+"),\"(.*)\",([01])\\)"; 79 Pattern p = Pattern.compile(pattern); 80 Matcher m = p.matcher(content); 81 while(m.find()) { 82 double lat = Double.parseDouble(m.group(3)); 83 double lon = Double.parseDouble(m.group(2)); 84 LatLon latlon = new LatLon(lat, lon); 85 Node osmNode = new Node(latlon); 86 osmNode.id = Long.parseLong(m.group(1)); 87 osmNode.put("id", m.group(1)); 88 osmNode.put("note", m.group(4)); 89 osmNode.put("openstreetbug", "FIXME"); 90 osmNode.put("state", m.group(5)); 91 dataSet.addPrimitive(osmNode); 92 } 93 } 50 // check zoom level 51 if(Main.map.mapView.zoom() > 15 || Main.map.mapView.zoom() < 9) { 52 return; 53 } 54 55 // add query params to the uri 56 StringBuilder sb = new StringBuilder(uri) 57 .append("?b=").append(bounds.min.lat()) 58 .append("&t=").append(bounds.max.lat()) 59 .append("&l=").append(bounds.min.lon()) 60 .append("&r=").append(bounds.max.lon()); 61 uri = sb.toString(); 62 63 // download the data 64 String content = HttpUtils.get(uri, null, CHARSET); 65 66 // clear dataset 67 dataset.nodes.clear(); 68 dataset.relations.clear(); 69 dataset.ways.clear(); 70 71 // parse the data 72 parseData(dataset, content); 73 } 74 75 private void parseData(DataSet dataSet, String content) { 76 String idPattern = "\\d+"; 77 String floatPattern = "-?\\d+\\.\\d+"; 78 String pattern = "putAJAXMarker\\(("+idPattern+"),("+floatPattern+"),("+floatPattern+"),\"(.*)\",([01])\\)"; 79 Pattern p = Pattern.compile(pattern); 80 Matcher m = p.matcher(content); 81 while(m.find()) { 82 double lat = Double.parseDouble(m.group(3)); 83 double lon = Double.parseDouble(m.group(2)); 84 LatLon latlon = new LatLon(lat, lon); 85 Node osmNode = new Node(latlon); 86 osmNode.id = Long.parseLong(m.group(1)); 87 osmNode.put("id", m.group(1)); 88 osmNode.put("note", m.group(4)); 89 osmNode.put("openstreetbug", "FIXME"); 90 osmNode.put("state", m.group(5)); 91 dataSet.addPrimitive(osmNode); 92 } 93 } 94 94 } -
applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/api/EditAction.java
r12640 r12778 1 1 /* Copyright (c) 2008, Henrik Niehaus 2 2 * All rights reserved. 3 * 3 * 4 4 * Redistribution and use in source and binary forms, with or without 5 5 * modification, are permitted provided that the following conditions are met: 6 * 6 * 7 7 * 1. Redistributions of source code must retain the above copyright notice, 8 8 * this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 11 11 * and/or other materials provided with the distribution. 12 * 3. Neither the name of the project nor the names of its 13 * contributors may be used to endorse or promote products derived from this 12 * 3. Neither the name of the project nor the names of its 13 * contributors may be used to endorse or promote products derived from this 14 14 * software without specific prior written permission. 15 * 15 * 16 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE … … 41 41 42 42 public class EditAction { 43 44 private final String CHARSET = "UTF-8";45 46 public void execute(Node n, String comment) throws IOException {47 // create the URI for the data download48 String uri = Main.pref.get(ConfigKeys.OSB_API_URI_EDIT);49 String post = new StringBuilder("id=")50 .append(n.get("id"))51 .append("&text=")52 .append(URLEncoder.encode(comment, CHARSET))53 .toString();54 55 String result = null;56 if(Main.pref.getBoolean(ConfigKeys.OSB_API_DISABLED)) {57 result = "ok";58 } else {59 result = HttpUtils.post(uri, null, post, CHARSET);60 }61 43 62 if("ok".equalsIgnoreCase(result)) { 63 String desc = n.get("note"); 64 desc = desc.concat("<hr />").concat(comment); 65 n.put("note", desc); 66 Main.map.mapView.repaint(); 67 } else { 68 JOptionPane.showMessageDialog(Main.parent, 69 tr("An error occurred: {0}", new Object[] {result}), 70 tr("Error"), 71 JOptionPane.ERROR_MESSAGE); 72 } 73 } 44 private final String CHARSET = "UTF-8"; 45 46 public void execute(Node n, String comment) throws IOException { 47 // create the URI for the data download 48 String uri = Main.pref.get(ConfigKeys.OSB_API_URI_EDIT); 49 String post = new StringBuilder("id=") 50 .append(n.get("id")) 51 .append("&text=") 52 .append(URLEncoder.encode(comment, CHARSET)) 53 .toString(); 54 55 String result = null; 56 if(Main.pref.getBoolean(ConfigKeys.OSB_API_DISABLED)) { 57 result = "ok"; 58 } else { 59 result = HttpUtils.post(uri, null, post, CHARSET); 60 } 61 62 if("ok".equalsIgnoreCase(result)) { 63 String desc = n.get("note"); 64 desc = desc.concat("<hr />").concat(comment); 65 n.put("note", desc); 66 Main.map.mapView.repaint(); 67 } else { 68 JOptionPane.showMessageDialog(Main.parent, 69 tr("An error occurred: {0}", new Object[] {result}), 70 tr("Error"), 71 JOptionPane.ERROR_MESSAGE); 72 } 73 } 74 74 } -
applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/api/NewAction.java
r12588 r12778 1 1 /* Copyright (c) 2008, Henrik Niehaus 2 2 * All rights reserved. 3 * 3 * 4 4 * Redistribution and use in source and binary forms, with or without 5 5 * modification, are permitted provided that the following conditions are met: 6 * 6 * 7 7 * 1. Redistributions of source code must retain the above copyright notice, 8 8 * this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 11 11 * and/or other materials provided with the distribution. 12 * 3. Neither the name of the project nor the names of its 13 * contributors may be used to endorse or promote products derived from this 12 * 3. Neither the name of the project nor the names of its 13 * contributors may be used to endorse or promote products derived from this 14 14 * software without specific prior written permission. 15 * 15 * 16 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE … … 43 43 44 44 public class NewAction { 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 78 79 80 81 82 83 84 85 45 46 private final String CHARSET = "UTF-8"; 47 48 public Node execute(Point p, String text) throws IOException { 49 // where has the issue been added 50 LatLon latlon = Main.map.mapView.getLatLon(p.x, p.y); 51 52 // create the URI for the data download 53 String uri = Main.pref.get(ConfigKeys.OSB_API_URI_NEW); 54 55 String post = new StringBuilder("lon=") 56 .append(latlon.lon()) 57 .append("&lat=") 58 .append(latlon.lat()) 59 .append("&text=") 60 .append(URLEncoder.encode(text, CHARSET)) 61 .toString(); 62 63 String result = null; 64 if(Main.pref.getBoolean(ConfigKeys.OSB_API_DISABLED)) { 65 result = "ok 12345"; 66 } else { 67 result = HttpUtils.post(uri, null, post, CHARSET); 68 } 69 70 Pattern resultPattern = Pattern.compile("ok\\s+(\\d+)"); 71 Matcher m = resultPattern.matcher(result); 72 String id = "-1"; 73 if(m.matches()) { 74 id = m.group(1); 75 } else { 76 throw new RuntimeException(tr("Couldn't create new bug. Result: {0}" + result)); 77 } 78 79 Node osmNode = new Node(latlon); 80 osmNode.put("id", id); 81 osmNode.put("note", text); 82 osmNode.put("openstreetbug", "FIXME"); 83 osmNode.put("state", "0"); 84 return osmNode; 85 } 86 86 } -
applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/api/util/HttpResponse.java
r11157 r12778 1 1 /* Copyright (c) 2008, Henrik Niehaus 2 2 * All rights reserved. 3 * 3 * 4 4 * Redistribution and use in source and binary forms, with or without 5 5 * modification, are permitted provided that the following conditions are met: 6 * 6 * 7 7 * 1. Redistributions of source code must retain the above copyright notice, 8 8 * this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 11 11 * and/or other materials provided with the distribution. 12 * 3. Neither the name of the project nor the names of its 13 * contributors may be used to endorse or promote products derived from this 12 * 3. Neither the name of the project nor the names of its 13 * contributors may be used to endorse or promote products derived from this 14 14 * software without specific prior written permission. 15 * 15 * 16 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -
applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/api/util/HttpUtils.java
r12588 r12778 1 1 /* Copyright (c) 2008, Henrik Niehaus 2 2 * All rights reserved. 3 * 3 * 4 4 * Redistribution and use in source and binary forms, with or without 5 5 * modification, are permitted provided that the following conditions are met: 6 * 6 * 7 7 * 1. Redistributions of source code must retain the above copyright notice, 8 8 * this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 11 11 * and/or other materials provided with the distribution. 12 * 3. Neither the name of the project nor the names of its 13 * contributors may be used to endorse or promote products derived from this 12 * 3. Neither the name of the project nor the names of its 13 * contributors may be used to endorse or promote products derived from this 14 14 * software without specific prior written permission. 15 * 15 * 16 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE … … 51 51 } 52 52 } 53 53 54 54 ByteArrayOutputStream bos = new ByteArrayOutputStream(); 55 55 int length = -1; … … 59 59 bos.write(b, 0, length); 60 60 } 61 61 62 62 return new String(bos.toByteArray(), charset); 63 63 } 64 64 65 65 public static HttpResponse getResponse(String url, Map<String, String> headers, String charset) throws IOException { 66 66 URL page = new URL(url); … … 72 72 } 73 73 } 74 74 75 75 ByteArrayOutputStream bos = new ByteArrayOutputStream(); 76 76 int length = -1; … … 80 80 bos.write(b, 0, length); 81 81 } 82 82 83 83 HttpResponse response = new HttpResponse(new String(bos.toByteArray(), charset), con.getHeaderFields()); 84 84 return response; 85 85 } 86 86 87 87 /** 88 * 88 * 89 89 * @param url 90 90 * @param headers … … 105 105 } 106 106 } 107 107 108 108 //send the post 109 109 OutputStream os = con.getOutputStream(); 110 110 os.write(content.getBytes("UTF-8")); 111 111 os.flush(); 112 112 113 113 // read the response 114 114 ByteArrayOutputStream bos = new ByteArrayOutputStream(); … … 119 119 bos.write(b, 0, length); 120 120 } 121 121 122 122 return new String(bos.toByteArray(), responseCharset); 123 123 } 124 124 125 125 /** 126 126 * Adds a parameter to a given URI … … 137 137 sb.append('?'); 138 138 } 139 139 140 140 sb.append(param); 141 141 sb.append('='); 142 142 sb.append(value); 143 143 144 144 return sb.toString(); 145 145 } … … 154 154 } 155 155 } 156 156 157 157 return con.getHeaderFields(); 158 158 } 159 159 160 160 public static String getHeaderField(Map<String, List<String>> headers, String headerField) { 161 161 if(!headers.containsKey(headerField)) { 162 162 return null; 163 163 } 164 164 165 165 List<String> value = headers.get(headerField); 166 166 if(value.size() == 1) { -
applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/gui/OsbDialog.java
r12670 r12778 1 1 /* Copyright (c) 2008, Henrik Niehaus 2 2 * All rights reserved. 3 * 3 * 4 4 * Redistribution and use in source and binary forms, with or without 5 5 * modification, are permitted provided that the following conditions are met: 6 * 6 * 7 7 * 1. Redistributions of source code must retain the above copyright notice, 8 8 * this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 11 11 * and/or other materials provided with the distribution. 12 * 3. Neither the name of the project nor the names of its 13 * contributors may be used to endorse or promote products derived from this 12 * 3. Neither the name of the project nor the names of its 13 * contributors may be used to endorse or promote products derived from this 14 14 * software without specific prior written permission. 15 * 15 * 16 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE … … 77 77 78 78 public class OsbDialog extends ToggleDialog implements OsbObserver, ListSelectionListener, LayerChangeListener, 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 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 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 259 260 261 79 DataChangeListener, MouseListener, OsbActionObserver { 80 81 private static final long serialVersionUID = 1L; 82 private DefaultListModel model; 83 private JList list; 84 private OsbPlugin osbPlugin; 85 private boolean fireSelectionChanged = true; 86 private JButton refresh; 87 private JButton addComment = new JButton(new AddCommentAction()); 88 private JButton closeIssue = new JButton(new CloseIssueAction()); 89 private JToggleButton newIssue = new JToggleButton(); 90 91 public OsbDialog(final OsbPlugin plugin) { 92 super(tr("Open OpenStreetBugs"), "icon_error22", 93 tr("Opens the OpenStreetBugs window and activates the automatic download"), 94 Shortcut.registerShortcut( 95 "view:openstreetbugs", 96 tr("Toggle: {0}", tr("Open OpenStreetBugs")), 97 KeyEvent.VK_O, Shortcut.GROUP_MENU, Shortcut.SHIFT_DEFAULT), 98 150); 99 100 osbPlugin = plugin; 101 102 model = new DefaultListModel(); 103 list = new JList(model); 104 list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 105 list.addListSelectionListener(this); 106 list.addMouseListener(this); 107 list.setCellRenderer(new OsbListCellRenderer()); 108 add(new JScrollPane(list), BorderLayout.CENTER); 109 110 // create dialog buttons 111 JPanel buttonPanel = new JPanel(new GridLayout(2, 2)); 112 add(buttonPanel, BorderLayout.SOUTH); 113 refresh = new JButton(tr("Refresh")); 114 refresh.setToolTipText(tr("Refresh")); 115 refresh.setIcon(OsbPlugin.loadIcon("view-refresh22.png")); 116 refresh.setHorizontalAlignment(SwingConstants.LEFT); 117 refresh.addActionListener(new ActionListener() { 118 119 public void actionPerformed(ActionEvent e) { 120 // check zoom level 121 if(Main.map.mapView.zoom() > 15 || Main.map.mapView.zoom() < 9) { 122 JOptionPane.showMessageDialog(Main.parent, 123 tr("The visible area is either too small or too big to download data from OpenStreetBugs"), 124 tr("Warning"), 125 JOptionPane.INFORMATION_MESSAGE); 126 return; 127 } 128 129 plugin.updateData(); 130 } 131 }); 132 133 addComment.setEnabled(false); 134 addComment.setToolTipText((String) addComment.getAction().getValue(Action.NAME)); 135 addComment.setIcon(OsbPlugin.loadIcon("add_comment22.png")); 136 addComment.setHorizontalAlignment(SwingConstants.LEFT); 137 closeIssue.setEnabled(false); 138 closeIssue.setToolTipText((String) closeIssue.getAction().getValue(Action.NAME)); 139 closeIssue.setIcon(OsbPlugin.loadIcon("icon_valid22.png")); 140 closeIssue.setHorizontalAlignment(SwingConstants.LEFT); 141 NewIssueAction nia = new NewIssueAction(newIssue, osbPlugin); 142 newIssue.setAction(nia); 143 newIssue.setToolTipText((String) newIssue.getAction().getValue(Action.NAME)); 144 newIssue.setIcon(OsbPlugin.loadIcon("icon_error_add22.png")); 145 newIssue.setHorizontalAlignment(SwingConstants.LEFT); 146 147 buttonPanel.add(refresh); 148 buttonPanel.add(newIssue); 149 buttonPanel.add(addComment); 150 buttonPanel.add(closeIssue); 151 152 // add a selection listener to the data 153 DataSet.selListeners.add(new SelectionChangedListener() { 154 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 155 fireSelectionChanged = false; 156 list.clearSelection(); 157 for (OsmPrimitive osmPrimitive : newSelection) { 158 for (int i = 0; i < model.getSize(); i++) { 159 OsbListItem item = (OsbListItem) model.get(i); 160 if(item.getNode() == osmPrimitive) { 161 list.addSelectionInterval(i, i); 162 } 163 } 164 } 165 fireSelectionChanged = true; 166 } 167 }); 168 169 AddCommentAction.addActionObserver(this); 170 CloseIssueAction.addActionObserver(this); 171 } 172 173 public synchronized void update(final DataSet dataset) { 174 Node lastNode = OsbAction.getSelectedNode(); 175 model = new DefaultListModel(); 176 List<Node> sortedList = new ArrayList<Node>(dataset.nodes); 177 Collections.sort(sortedList, new BugComparator()); 178 179 for (Node node : sortedList) { 180 if (!node.deleted) { 181 model.addElement(new OsbListItem(node)); 182 } 183 } 184 list.setModel(model); 185 list.setSelectedValue(new OsbListItem(lastNode), true); 186 } 187 188 public void valueChanged(ListSelectionEvent e) { 189 if(list.getSelectedValues().length == 0) { 190 addComment.setEnabled(false); 191 closeIssue.setEnabled(false); 192 OsbAction.setSelectedNode(null); 193 return; 194 } 195 196 List<OsmPrimitive> selected = new ArrayList<OsmPrimitive>(); 197 for (Object listItem : list.getSelectedValues()) { 198 Node node = ((OsbListItem) listItem).getNode(); 199 selected.add(node); 200 201 if ("1".equals(node.get("state"))) { 202 addComment.setEnabled(false); 203 closeIssue.setEnabled(false); 204 } else { 205 addComment.setEnabled(true); 206 closeIssue.setEnabled(true); 207 } 208 209 OsbAction.setSelectedNode(node); 210 211 scrollToSelected(node); 212 213 if (fireSelectionChanged) { 214 Main.ds.setSelected(selected); 215 } 216 } 217 } 218 219 private void scrollToSelected(Node node) { 220 for (int i = 0; i < model.getSize();i++) { 221 Node current = ((OsbListItem)model.get(i)).getNode(); 222 if(current.id == node.id) { 223 list.scrollRectToVisible(list.getCellBounds(i, i)); 224 list.setSelectedIndex(i); 225 return; 226 } 227 } 228 } 229 230 public void activeLayerChange(Layer oldLayer, Layer newLayer) {} 231 232 public void layerAdded(Layer newLayer) { 233 if(newLayer == osbPlugin.getLayer()) { 234 update(osbPlugin.getDataSet()); 235 Main.map.mapView.moveLayer(newLayer, 0); 236 } 237 } 238 239 public void layerRemoved(Layer oldLayer) { 240 if(oldLayer == osbPlugin.getLayer()) { 241 model.removeAllElements(); 242 } 243 } 244 245 public void dataChanged(OsmDataLayer l) { 246 update(l.data); 247 } 248 249 public void zoomToNode(Node node) { 250 double scale = Main.map.mapView.getScale(); 251 Main.map.mapView.zoomTo(node.eastNorth, scale); 252 } 253 254 public void mouseClicked(MouseEvent e) { 255 if(e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) { 256 OsbListItem item = (OsbListItem)list.getSelectedValue(); 257 zoomToNode(item.getNode()); 258 } 259 } 260 261 public void mousePressed(MouseEvent e) { 262 262 mayTriggerPopup(e); 263 263 } … … 266 266 mayTriggerPopup(e); 267 267 } 268 268 269 269 private void mayTriggerPopup(MouseEvent e) { 270 270 if(e.isPopupTrigger()) { 271 272 273 274 275 276 } 277 } 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 271 int selectedRow = list.locationToIndex(e.getPoint()); 272 list.setSelectedIndex(selectedRow); 273 Node n = ((OsbListItem)list.getSelectedValue()).getNode(); 274 OsbAction.setSelectedNode(n); 275 PopupFactory.createPopup(n).show(e.getComponent(), e.getX(), e.getY()); 276 } 277 } 278 279 public void mouseEntered(MouseEvent e) {} 280 281 public void mouseExited(MouseEvent e) {} 282 283 public void actionPerformed(OsbAction action) { 284 if(action instanceof AddCommentAction || action instanceof CloseIssueAction) { 285 update(osbPlugin.getDataSet()); 286 } 287 } 288 289 private class BugComparator implements Comparator<Node> { 290 291 public int compare(Node o1, Node o2) { 292 String state1 = o1.get("state"); 293 String state2 = o2.get("state"); 294 if(state1.equals(state2)) { 295 return o1.get("note").compareTo(o2.get("note")); 296 } 297 return state1.compareTo(state2); 298 } 299 300 } 301 301 } -
applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/gui/OsbListCellRenderer.java
r11161 r12778 1 1 /* Copyright (c) 2008, Henrik Niehaus 2 2 * All rights reserved. 3 * 3 * 4 4 * Redistribution and use in source and binary forms, with or without 5 5 * modification, are permitted provided that the following conditions are met: 6 * 6 * 7 7 * 1. Redistributions of source code must retain the above copyright notice, 8 8 * this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 11 11 * and/or other materials provided with the distribution. 12 * 3. Neither the name of the project nor the names of its 13 * contributors may be used to endorse or promote products derived from this 12 * 3. Neither the name of the project nor the names of its 13 * contributors may be used to endorse or promote products derived from this 14 14 * software without specific prior written permission. 15 * 15 * 16 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE … … 45 45 private Color background = Color.WHITE; 46 46 private Color altBackground = new Color(250, 250, 220); 47 48 49 50 51 52 53 47 48 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, 49 boolean cellHasFocus) { 50 51 JLabel label = new JLabel(); 52 label.setOpaque(true); 53 54 54 if(isSelected) { 55 55 label.setBackground(UIManager.getColor("List.selectionBackground")); 56 56 } else { 57 57 label.setBackground(index % 2 == 0 ? background : altBackground); 58 58 } 59 59 60 60 OsbListItem item = (OsbListItem) value; 61 61 Node n = item.getNode(); 62 62 Icon icon = null; 63 63 if("0".equals(n.get("state"))) { 64 64 icon = OsbPlugin.loadIcon("icon_error16.png"); 65 65 } else if("1".equals(n.get("state"))) { 66 66 icon = OsbPlugin.loadIcon("icon_valid16.png"); 67 67 } 68 68 label.setIcon(icon); 69 69 String text = n.get("note"); 70 70 if(text.indexOf("<hr />") > 0) { 71 71 text = text.substring(0, text.indexOf("<hr />")); 72 72 } 73 73 label.setText(text); 74 75 76 77 78 79 80 74 75 Dimension d = label.getPreferredSize(); 76 d.height += 10; 77 label.setPreferredSize(d); 78 79 return label; 80 } 81 81 82 82 } -
applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/gui/OsbListItem.java
r11157 r12778 1 1 /* Copyright (c) 2008, Henrik Niehaus 2 2 * All rights reserved. 3 * 3 * 4 4 * Redistribution and use in source and binary forms, with or without 5 5 * modification, are permitted provided that the following conditions are met: 6 * 6 * 7 7 * 1. Redistributions of source code must retain the above copyright notice, 8 8 * this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 11 11 * and/or other materials provided with the distribution. 12 * 3. Neither the name of the project nor the names of its 13 * contributors may be used to endorse or promote products derived from this 12 * 3. Neither the name of the project nor the names of its 13 * contributors may be used to endorse or promote products derived from this 14 14 * software without specific prior written permission. 15 * 15 * 16 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE … … 31 31 32 32 public class OsbListItem { 33 private Node node; 34 35 public OsbListItem(Node node) { 36 super(); 37 this.node = node; 38 } 33 private Node node; 39 34 40 public Node getNode() { 41 return node; 42 } 35 public OsbListItem(Node node) { 36 super(); 37 this.node = node; 38 } 43 39 44 public void setNode(Node node) { 45 this.node = node; 46 } 47 48 @Override 49 public String toString() { 50 if(node.get("note") != null) { 51 StringBuilder sb = new StringBuilder("<html>"); 52 sb.append(node.get("note").replaceAll("\\|", "<br>")); 53 sb.append("</html>"); 54 return sb.toString(); 55 } else { 56 return "N/A"; 57 } 58 } 59 60 @Override 61 public boolean equals(Object obj) { 62 if(obj instanceof OsbListItem) { 63 OsbListItem other = (OsbListItem)obj; 64 if(getNode() != null && other.getNode() != null) { 65 return getNode().id == other.getNode().id; 66 } 67 } 68 69 return false; 70 } 40 public Node getNode() { 41 return node; 42 } 43 44 public void setNode(Node node) { 45 this.node = node; 46 } 47 48 @Override 49 public String toString() { 50 if(node.get("note") != null) { 51 StringBuilder sb = new StringBuilder("<html>"); 52 sb.append(node.get("note").replaceAll("\\|", "<br>")); 53 sb.append("</html>"); 54 return sb.toString(); 55 } else { 56 return "N/A"; 57 } 58 } 59 60 @Override 61 public boolean equals(Object obj) { 62 if(obj instanceof OsbListItem) { 63 OsbListItem other = (OsbListItem)obj; 64 if(getNode() != null && other.getNode() != null) { 65 return getNode().id == other.getNode().id; 66 } 67 } 68 69 return false; 70 } 71 71 } -
applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/gui/action/AddCommentAction.java
r12588 r12778 1 1 /* Copyright (c) 2008, Henrik Niehaus 2 2 * All rights reserved. 3 * 3 * 4 4 * Redistribution and use in source and binary forms, with or without 5 5 * modification, are permitted provided that the following conditions are met: 6 * 6 * 7 7 * 1. Redistributions of source code must retain the above copyright notice, 8 8 * this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 11 11 * and/or other materials provided with the distribution. 12 * 3. Neither the name of the project nor the names of its 13 * contributors may be used to endorse or promote products derived from this 12 * 3. Neither the name of the project nor the names of its 13 * contributors may be used to endorse or promote products derived from this 14 14 * software without specific prior written permission. 15 * 15 * 16 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE … … 40 40 public class AddCommentAction extends OsbAction { 41 41 42 42 private static final long serialVersionUID = 1L; 43 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 44 private EditAction editAction = new EditAction(); 45 46 public AddCommentAction() { 47 super(tr("Add a comment")); 48 } 49 50 @Override 51 protected void doActionPerformed(ActionEvent e) throws Exception { 52 // get the user nickname 53 String nickname = Main.pref.get(ConfigKeys.OSB_NICKNAME); 54 if(nickname == null || nickname.length() == 0) { 55 nickname = JOptionPane.showInputDialog(Main.parent, tr("Please enter a user name")); 56 if(nickname == null) { 57 nickname = tr("NoName"); 58 } else { 59 Main.pref.put(ConfigKeys.OSB_NICKNAME, nickname); 60 } 61 } 62 63 String comment = JOptionPane.showInputDialog(Main.parent, tr("Enter your comment")); 64 if(comment != null) { 65 comment = comment.concat(" [").concat(nickname).concat("]"); 66 editAction.execute(getSelectedNode(), comment); 67 } 68 } 69 69 } -
applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/gui/action/CloseIssueAction.java
r12588 r12778 1 1 /* Copyright (c) 2008, Henrik Niehaus 2 2 * All rights reserved. 3 * 3 * 4 4 * Redistribution and use in source and binary forms, with or without 5 5 * modification, are permitted provided that the following conditions are met: 6 * 6 * 7 7 * 1. Redistributions of source code must retain the above copyright notice, 8 8 * this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 11 11 * and/or other materials provided with the distribution. 12 * 3. Neither the name of the project nor the names of its 13 * contributors may be used to endorse or promote products derived from this 12 * 3. Neither the name of the project nor the names of its 13 * contributors may be used to endorse or promote products derived from this 14 14 * software without specific prior written permission. 15 * 15 * 16 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE … … 40 40 public class CloseIssueAction extends OsbAction { 41 41 42 42 private static final long serialVersionUID = 1L; 43 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 } 60 44 private CloseAction closeAction = new CloseAction(); 45 46 public CloseIssueAction() { 47 super(tr("Mark as done")); 48 } 49 50 @Override 51 protected void doActionPerformed(ActionEvent e) throws IOException { 52 int result = JOptionPane.showConfirmDialog(Main.parent, 53 tr("Really mark this issue as ''done''?"), 54 tr("Really close?"), 55 JOptionPane.YES_NO_OPTION); 56 57 if(result == JOptionPane.YES_OPTION) { 58 closeAction.execute(getSelectedNode()); 59 } 60 } 61 61 } -
applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/gui/action/NewIssueAction.java
r12640 r12778 1 1 /* Copyright (c) 2008, Henrik Niehaus 2 2 * All rights reserved. 3 * 3 * 4 4 * Redistribution and use in source and binary forms, with or without 5 5 * modification, are permitted provided that the following conditions are met: 6 * 6 * 7 7 * 1. Redistributions of source code must retain the above copyright notice, 8 8 * this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 11 11 * and/or other materials provided with the distribution. 12 * 3. Neither the name of the project nor the names of its 13 * contributors may be used to endorse or promote products derived from this 12 * 3. Neither the name of the project nor the names of its 13 * contributors may be used to endorse or promote products derived from this 14 14 * software without specific prior written permission. 15 * 15 * 16 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE … … 47 47 public class NewIssueAction extends OsbAction implements MouseListener { 48 48 49 49 private static final long serialVersionUID = 1L; 50 50 51 private NewAction newAction = new NewAction(); 52 53 private JToggleButton button; 54 55 private OsbPlugin plugin; 56 57 public NewIssueAction(JToggleButton button, OsbPlugin plugin) { 58 super(tr("New issue")); 59 this.button = button; 60 this.plugin = plugin; 61 } 62 63 @Override 64 protected void doActionPerformed(ActionEvent e) throws IOException { 65 if(button.isSelected()) { 66 Main.map.mapView.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); 67 Main.map.mapView.addMouseListener(this); 68 } else { 69 reset(); 70 } 71 } 51 private NewAction newAction = new NewAction(); 72 52 73 private void reset() { 74 Main.map.mapView.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); 75 Main.map.mapView.removeMouseListener(this); 76 button.setSelected(false); 77 } 53 private JToggleButton button; 78 54 79 public void mouseClicked(MouseEvent e) { 80 addNewIssue(e); 81 } 55 private OsbPlugin plugin; 82 56 83 public void mouseEntered(MouseEvent e) {} 57 public NewIssueAction(JToggleButton button, OsbPlugin plugin) { 58 super(tr("New issue")); 59 this.button = button; 60 this.plugin = plugin; 61 } 84 62 85 public void mouseExited(MouseEvent e) {} 63 @Override 64 protected void doActionPerformed(ActionEvent e) throws IOException { 65 if(button.isSelected()) { 66 Main.map.mapView.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); 67 Main.map.mapView.addMouseListener(this); 68 } else { 69 reset(); 70 } 71 } 86 72 87 public void mousePressed(MouseEvent e) { 88 addNewIssue(e); 89 } 73 private void reset() { 74 Main.map.mapView.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); 75 Main.map.mapView.removeMouseListener(this); 76 button.setSelected(false); 77 } 90 78 91 private void addNewIssue(MouseEvent e) { 92 // get the user nickname 93 String nickname = Main.pref.get(ConfigKeys.OSB_NICKNAME); 94 if(nickname == null || nickname.length() == 0) { 95 nickname = JOptionPane.showInputDialog(Main.parent, tr("Please enter a user name")); 96 if(nickname == null) { 97 nickname = "NoName"; 98 } else { 99 Main.pref.put(ConfigKeys.OSB_NICKNAME, nickname); 100 } 101 } 102 103 // get the comment 104 String result = JOptionPane.showInputDialog(Main.parent, 105 tr("Describe the problem precisely"), 106 tr("Create issue"), 107 JOptionPane.QUESTION_MESSAGE); 108 109 if(result != null && result.length() > 0) { 110 try { 111 result = result.concat(" [").concat(nickname).concat("]"); 112 Node n = newAction.execute(e.getPoint(), result); 113 plugin.getDataSet().addPrimitive(n); 114 if(Main.pref.getBoolean(ConfigKeys.OSB_API_DISABLED)) { 115 plugin.updateGui(); 116 } else { 117 plugin.updateData(); 118 } 119 } catch (Exception e1) { 120 e1.printStackTrace(); 121 JOptionPane.showMessageDialog(Main.parent, 122 tr("An error occurred: {0}", new Object[] {result}), 123 tr("Error"), 124 JOptionPane.ERROR_MESSAGE); 125 } 126 } 127 128 reset(); 129 } 79 public void mouseClicked(MouseEvent e) { 80 addNewIssue(e); 81 } 130 82 131 public void mouseReleased(MouseEvent e) {} 83 public void mouseEntered(MouseEvent e) {} 84 85 public void mouseExited(MouseEvent e) {} 86 87 public void mousePressed(MouseEvent e) { 88 addNewIssue(e); 89 } 90 91 private void addNewIssue(MouseEvent e) { 92 // get the user nickname 93 String nickname = Main.pref.get(ConfigKeys.OSB_NICKNAME); 94 if(nickname == null || nickname.length() == 0) { 95 nickname = JOptionPane.showInputDialog(Main.parent, tr("Please enter a user name")); 96 if(nickname == null) { 97 nickname = "NoName"; 98 } else { 99 Main.pref.put(ConfigKeys.OSB_NICKNAME, nickname); 100 } 101 } 102 103 // get the comment 104 String result = JOptionPane.showInputDialog(Main.parent, 105 tr("Describe the problem precisely"), 106 tr("Create issue"), 107 JOptionPane.QUESTION_MESSAGE); 108 109 if(result != null && result.length() > 0) { 110 try { 111 result = result.concat(" [").concat(nickname).concat("]"); 112 Node n = newAction.execute(e.getPoint(), result); 113 plugin.getDataSet().addPrimitive(n); 114 if(Main.pref.getBoolean(ConfigKeys.OSB_API_DISABLED)) { 115 plugin.updateGui(); 116 } else { 117 plugin.updateData(); 118 } 119 } catch (Exception e1) { 120 e1.printStackTrace(); 121 JOptionPane.showMessageDialog(Main.parent, 122 tr("An error occurred: {0}", new Object[] {result}), 123 tr("Error"), 124 JOptionPane.ERROR_MESSAGE); 125 } 126 } 127 128 reset(); 129 } 130 131 public void mouseReleased(MouseEvent e) {} 132 132 } -
applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/gui/action/OsbAction.java
r11568 r12778 1 1 /* Copyright (c) 2008, Henrik Niehaus 2 2 * All rights reserved. 3 * 3 * 4 4 * Redistribution and use in source and binary forms, with or without 5 5 * modification, are permitted provided that the following conditions are met: 6 * 6 * 7 7 * 1. Redistributions of source code must retain the above copyright notice, 8 8 * this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 11 11 * and/or other materials provided with the distribution. 12 * 3. Neither the name of the project nor the names of its 13 * contributors may be used to endorse or promote products derived from this 12 * 3. Neither the name of the project nor the names of its 13 * contributors may be used to endorse or promote products derived from this 14 14 * software without specific prior written permission. 15 * 15 * 16 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE … … 38 38 public abstract class OsbAction extends AbstractAction { 39 39 40 40 private static final long serialVersionUID = 1L; 41 41 42 private static List<OsbActionObserver> observers = new ArrayList<OsbActionObserver>(); 43 44 private static Node selectedNode; 45 46 public OsbAction(String name) { 47 super(name); 48 } 42 private static List<OsbActionObserver> observers = new ArrayList<OsbActionObserver>(); 49 43 50 public static Node getSelectedNode() { 51 return selectedNode; 52 } 44 private static Node selectedNode; 53 45 54 public static void setSelectedNode(Node selectedNode) { 55 OsbAction.selectedNode = selectedNode; 56 } 57 58 public void actionPerformed(ActionEvent e) { 59 try { 60 doActionPerformed(e); 61 for (OsbActionObserver obs : observers) { 62 obs.actionPerformed(this); 63 } 64 } catch (Exception e1) { 65 System.err.println("Couldn't execute action " + getClass().getSimpleName()); 66 e1.printStackTrace(); 67 } 68 } 69 70 protected abstract void doActionPerformed(ActionEvent e) throws Exception; 71 72 public static void addActionObserver(OsbActionObserver obs) { 73 observers.add(obs); 74 } 75 76 public static void removeActionObserver(OsbActionObserver obs) { 77 observers.remove(obs); 78 } 46 public OsbAction(String name) { 47 super(name); 48 } 49 50 public static Node getSelectedNode() { 51 return selectedNode; 52 } 53 54 public static void setSelectedNode(Node selectedNode) { 55 OsbAction.selectedNode = selectedNode; 56 } 57 58 public void actionPerformed(ActionEvent e) { 59 try { 60 doActionPerformed(e); 61 for (OsbActionObserver obs : observers) { 62 obs.actionPerformed(this); 63 } 64 } catch (Exception e1) { 65 System.err.println("Couldn't execute action " + getClass().getSimpleName()); 66 e1.printStackTrace(); 67 } 68 } 69 70 protected abstract void doActionPerformed(ActionEvent e) throws Exception; 71 72 public static void addActionObserver(OsbActionObserver obs) { 73 observers.add(obs); 74 } 75 76 public static void removeActionObserver(OsbActionObserver obs) { 77 observers.remove(obs); 78 } 79 79 } -
applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/gui/action/OsbActionObserver.java
r11157 r12778 1 1 /* Copyright (c) 2008, Henrik Niehaus 2 2 * All rights reserved. 3 * 3 * 4 4 * Redistribution and use in source and binary forms, with or without 5 5 * modification, are permitted provided that the following conditions are met: 6 * 6 * 7 7 * 1. Redistributions of source code must retain the above copyright notice, 8 8 * this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 11 11 * and/or other materials provided with the distribution. 12 * 3. Neither the name of the project nor the names of its 13 * contributors may be used to endorse or promote products derived from this 12 * 3. Neither the name of the project nor the names of its 13 * contributors may be used to endorse or promote products derived from this 14 14 * software without specific prior written permission. 15 * 15 * 16 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE … … 29 29 30 30 public interface OsbActionObserver { 31 31 public void actionPerformed(OsbAction action); 32 32 } -
applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/gui/action/PopupFactory.java
r12588 r12778 1 1 /* Copyright (c) 2008, Henrik Niehaus 2 2 * All rights reserved. 3 * 3 * 4 4 * Redistribution and use in source and binary forms, with or without 5 5 * modification, are permitted provided that the following conditions are met: 6 * 6 * 7 7 * 1. Redistributions of source code must retain the above copyright notice, 8 8 * this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 11 11 * and/or other materials provided with the distribution. 12 * 3. Neither the name of the project nor the names of its 13 * contributors may be used to endorse or promote products derived from this 12 * 3. Neither the name of the project nor the names of its 13 * contributors may be used to endorse or promote products derived from this 14 14 * software without specific prior written permission. 15 * 15 * 16 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE … … 37 37 38 38 public class PopupFactory { 39 40 private static JPopupMenu issuePopup;41 private static JPopupMenu fixedPopup;42 43 public static synchronized JPopupMenu createPopup(Node node) {44 if("0".equals(node.get("state"))) {45 return getIssuePopup();46 } else if("1".equals(node.get("state"))) {47 return getFixedPopup();48 } else {49 throw new RuntimeException(tr("Unknown issue state"));50 }51 }52 39 53 private static JPopupMenu getIssuePopup() { 54 if(issuePopup == null) { 55 issuePopup = new JPopupMenu(); 56 JMenuItem add = new JMenuItem(); 57 add.setAction(new AddCommentAction()); 58 add.setIcon(OsbPlugin.loadIcon("add_comment16.png")); 59 issuePopup.add(add); 60 JMenuItem close = new JMenuItem(); 61 close.setAction(new CloseIssueAction()); 62 close.setIcon(OsbPlugin.loadIcon("icon_valid16.png")); 63 issuePopup.add(close); 64 } 65 return issuePopup; 66 } 67 68 private static JPopupMenu getFixedPopup() { 69 if(fixedPopup == null) { 70 fixedPopup = new JPopupMenu(); 71 JMenuItem add = new JMenuItem(); 72 AddCommentAction aca = new AddCommentAction(); 73 aca.setEnabled(false); 74 add.setAction(aca); 75 add.setIcon(OsbPlugin.loadIcon("add_comment16.png")); 76 JMenuItem close = new JMenuItem(); 77 CloseIssueAction cia = new CloseIssueAction(); 78 cia.setEnabled(false); 79 close.setAction(cia); 80 close.setIcon(OsbPlugin.loadIcon("icon_valid16.png")); 81 fixedPopup.add(add); 82 fixedPopup.add(close); 83 } 84 return fixedPopup; 85 } 40 private static JPopupMenu issuePopup; 41 private static JPopupMenu fixedPopup; 42 43 public static synchronized JPopupMenu createPopup(Node node) { 44 if("0".equals(node.get("state"))) { 45 return getIssuePopup(); 46 } else if("1".equals(node.get("state"))) { 47 return getFixedPopup(); 48 } else { 49 throw new RuntimeException(tr("Unknown issue state")); 50 } 51 } 52 53 private static JPopupMenu getIssuePopup() { 54 if(issuePopup == null) { 55 issuePopup = new JPopupMenu(); 56 JMenuItem add = new JMenuItem(); 57 add.setAction(new AddCommentAction()); 58 add.setIcon(OsbPlugin.loadIcon("add_comment16.png")); 59 issuePopup.add(add); 60 JMenuItem close = new JMenuItem(); 61 close.setAction(new CloseIssueAction()); 62 close.setIcon(OsbPlugin.loadIcon("icon_valid16.png")); 63 issuePopup.add(close); 64 } 65 return issuePopup; 66 } 67 68 private static JPopupMenu getFixedPopup() { 69 if(fixedPopup == null) { 70 fixedPopup = new JPopupMenu(); 71 JMenuItem add = new JMenuItem(); 72 AddCommentAction aca = new AddCommentAction(); 73 aca.setEnabled(false); 74 add.setAction(aca); 75 add.setIcon(OsbPlugin.loadIcon("add_comment16.png")); 76 JMenuItem close = new JMenuItem(); 77 CloseIssueAction cia = new CloseIssueAction(); 78 cia.setEnabled(false); 79 close.setAction(cia); 80 close.setIcon(OsbPlugin.loadIcon("icon_valid16.png")); 81 fixedPopup.add(add); 82 fixedPopup.add(close); 83 } 84 return fixedPopup; 85 } 86 86 }
Note:
See TracChangeset
for help on using the changeset viewer.