Ignore:
Timestamp:
2009-01-01T18:28:53+01:00 (16 years ago)
Author:
stoecker
Message:

removed tab stop usage

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  
    11/* Copyright (c) 2008, Henrik Niehaus
    22 * All rights reserved.
    3  * 
     3 *
    44 * Redistribution and use in source and binary forms, with or without
    55 * modification, are permitted provided that the following conditions are met:
    6  * 
     6 *
    77 * 1. Redistributions of source code must retain the above copyright notice,
    88 *    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
    1111 *    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
    1414 *    software without specific prior written permission.
    15  * 
     15 *
    1616 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    1717 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     
    2929
    3030public class ConfigKeys {
    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";
     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";
    3838}
  • applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/OsbDownloadLoop.java

    r12588 r12778  
    11/* Copyright (c) 2008, Henrik Niehaus
    22 * All rights reserved.
    3  * 
     3 *
    44 * Redistribution and use in source and binary forms, with or without
    55 * modification, are permitted provided that the following conditions are met:
    6  * 
     6 *
    77 * 1. Redistributions of source code must retain the above copyright notice,
    88 *    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
    1111 *    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
    1414 *    software without specific prior written permission.
    15  * 
     15 *
    1616 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    1717 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     
    3636
    3737public 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         @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         }
    10438
    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    }
    108108}
  • applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/OsbLayer.java

    r12588 r12778  
    11/* Copyright (c) 2008, Henrik Niehaus
    22 * All rights reserved.
    3  * 
     3 *
    44 * Redistribution and use in source and binary forms, with or without
    55 * modification, are permitted provided that the following conditions are met:
    6  * 
     6 *
    77 * 1. Redistributions of source code must retain the above copyright notice,
    88 *    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
    1111 *    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
    1414 *    software without specific prior written permission.
    15  * 
     15 *
    1616 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    1717 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     
    6262
    6363public class OsbLayer extends Layer implements MouseListener {
    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[]{
     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[]{
    9191                new JMenuItem(new LayerListDialog.ShowHideLayerAction(this)),
    9292                new JMenuItem(new LayerListDialog.DeleteLayerAction(this)),
     
    9595                new JSeparator(),
    9696                new JMenuItem(new LayerListPopup.InfoAction(this))};
    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) {
     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) {
    225225        mayTriggerPopup(e);
    226226    }
     
    229229        mayTriggerPopup(e);
    230230    }
    231    
     231
    232232    private void mayTriggerPopup(MouseEvent e) {
    233233        if(e.isPopupTrigger()) {
    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) {}
     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) {}
    247247}
  • applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/OsbObserver.java

    r11157 r12778  
    11/* Copyright (c) 2008, Henrik Niehaus
    22 * All rights reserved.
    3  * 
     3 *
    44 * Redistribution and use in source and binary forms, with or without
    55 * modification, are permitted provided that the following conditions are met:
    6  * 
     6 *
    77 * 1. Redistributions of source code must retain the above copyright notice,
    88 *    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
    1111 *    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
    1414 *    software without specific prior written permission.
    15  * 
     15 *
    1616 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    1717 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     
    3131
    3232public interface OsbObserver {
    33         public void update(DataSet dataset);
     33    public void update(DataSet dataset);
    3434}
  • applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/OsbPlugin.java

    r12588 r12778  
    6060public class OsbPlugin extends Plugin implements LayerChangeListener {
    6161
    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);
     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);
    8080        OsbLayer.listeners.add(dialog);
    8181        OsbLayer.listeners.add(this);
    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         }
     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    }
    246246}
  • applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/OsbUploadHook.java

    r12588 r12778  
    11/* Copyright (c) 2008, Henrik Niehaus
    22 * All rights reserved.
    3  * 
     3 *
    44 * Redistribution and use in source and binary forms, with or without
    55 * modification, are permitted provided that the following conditions are met:
    6  * 
     6 *
    77 * 1. Redistributions of source code must retain the above copyright notice,
    88 *    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
    1111 *    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
    1414 *    software without specific prior written permission.
    15  * 
     15 *
    1616 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    1717 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     
    4141public class OsbUploadHook implements UploadHook {
    4242
    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         }
     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    }
    5959
    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         }
     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    }
    6969}
  • applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/api/CloseAction.java

    r12640 r12778  
    11/* Copyright (c) 2008, Henrik Niehaus
    22 * All rights reserved.
    3  * 
     3 *
    44 * Redistribution and use in source and binary forms, with or without
    55 * modification, are permitted provided that the following conditions are met:
    6  * 
     6 *
    77 * 1. Redistributions of source code must retain the above copyright notice,
    88 *    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
    1111 *    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
    1414 *    software without specific prior written permission.
    15  * 
     15 *
    1616 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    1717 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     
    4040
    4141public class CloseAction {
    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         }
     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    }
    6969}
  • applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/api/DownloadAction.java

    r11579 r12778  
    11/* Copyright (c) 2008, Henrik Niehaus
    22 * All rights reserved.
    3  * 
     3 *
    44 * Redistribution and use in source and binary forms, with or without
    55 * modification, are permitted provided that the following conditions are met:
    6  * 
     6 *
    77 * 1. Redistributions of source code must retain the above copyright notice,
    88 *    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
    1111 *    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
    1414 *    software without specific prior written permission.
    15  * 
     15 *
    1616 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    1717 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     
    4141
    4242public 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 download
    48                 String uri = Main.pref.get(ConfigKeys.OSB_API_URI_DOWNLOAD);
    4943
    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";
    6245
    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);
    7449
    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    }
    9494}
  • applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/api/EditAction.java

    r12640 r12778  
    11/* Copyright (c) 2008, Henrik Niehaus
    22 * All rights reserved.
    3  * 
     3 *
    44 * Redistribution and use in source and binary forms, with or without
    55 * modification, are permitted provided that the following conditions are met:
    6  * 
     6 *
    77 * 1. Redistributions of source code must retain the above copyright notice,
    88 *    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
    1111 *    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
    1414 *    software without specific prior written permission.
    15  * 
     15 *
    1616 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    1717 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     
    4141
    4242public 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 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                 }
    6143
    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    }
    7474}
  • applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/api/NewAction.java

    r12588 r12778  
    11/* Copyright (c) 2008, Henrik Niehaus
    22 * All rights reserved.
    3  * 
     3 *
    44 * Redistribution and use in source and binary forms, with or without
    55 * modification, are permitted provided that the following conditions are met:
    6  * 
     6 *
    77 * 1. Redistributions of source code must retain the above copyright notice,
    88 *    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
    1111 *    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
    1414 *    software without specific prior written permission.
    15  * 
     15 *
    1616 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    1717 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     
    4343
    4444public class NewAction {
    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         }
     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    }
    8686}
  • applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/api/util/HttpResponse.java

    r11157 r12778  
    11/* Copyright (c) 2008, Henrik Niehaus
    22 * All rights reserved.
    3  * 
     3 *
    44 * Redistribution and use in source and binary forms, with or without
    55 * modification, are permitted provided that the following conditions are met:
    6  * 
     6 *
    77 * 1. Redistributions of source code must retain the above copyright notice,
    88 *    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
    1111 *    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
    1414 *    software without specific prior written permission.
    15  * 
     15 *
    1616 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    1717 * 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  
    11/* Copyright (c) 2008, Henrik Niehaus
    22 * All rights reserved.
    3  * 
     3 *
    44 * Redistribution and use in source and binary forms, with or without
    55 * modification, are permitted provided that the following conditions are met:
    6  * 
     6 *
    77 * 1. Redistributions of source code must retain the above copyright notice,
    88 *    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
    1111 *    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
    1414 *    software without specific prior written permission.
    15  * 
     15 *
    1616 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    1717 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     
    5151            }
    5252        }
    53        
     53
    5454        ByteArrayOutputStream bos = new ByteArrayOutputStream();
    5555        int length = -1;
     
    5959            bos.write(b, 0, length);
    6060        }
    61        
     61
    6262        return new String(bos.toByteArray(), charset);
    6363    }
    64    
     64
    6565    public static HttpResponse getResponse(String url, Map<String, String> headers, String charset) throws IOException {
    6666        URL page = new URL(url);
     
    7272            }
    7373        }
    74        
     74
    7575        ByteArrayOutputStream bos = new ByteArrayOutputStream();
    7676        int length = -1;
     
    8080            bos.write(b, 0, length);
    8181        }
    82        
     82
    8383        HttpResponse response = new HttpResponse(new String(bos.toByteArray(), charset), con.getHeaderFields());
    8484        return response;
    8585    }
    86    
     86
    8787    /**
    88      * 
     88     *
    8989     * @param url
    9090     * @param headers
     
    105105            }
    106106        }
    107        
     107
    108108        //send the post
    109109        OutputStream os = con.getOutputStream();
    110110        os.write(content.getBytes("UTF-8"));
    111111        os.flush();
    112        
     112
    113113        // read the response
    114114        ByteArrayOutputStream bos = new ByteArrayOutputStream();
     
    119119            bos.write(b, 0, length);
    120120        }
    121        
     121
    122122        return new String(bos.toByteArray(), responseCharset);
    123123    }
    124    
     124
    125125    /**
    126126     * Adds a parameter to a given URI
     
    137137            sb.append('?');
    138138        }
    139        
     139
    140140        sb.append(param);
    141141        sb.append('=');
    142142        sb.append(value);
    143        
     143
    144144        return sb.toString();
    145145    }
     
    154154            }
    155155        }
    156        
     156
    157157        return con.getHeaderFields();
    158158    }
    159    
     159
    160160    public static String getHeaderField(Map<String, List<String>> headers, String headerField) {
    161161        if(!headers.containsKey(headerField)) {
    162162            return null;
    163163        }
    164        
     164
    165165        List<String> value = headers.get(headerField);
    166166        if(value.size() == 1) {
  • applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/gui/OsbDialog.java

    r12670 r12778  
    11/* Copyright (c) 2008, Henrik Niehaus
    22 * All rights reserved.
    3  * 
     3 *
    44 * Redistribution and use in source and binary forms, with or without
    55 * modification, are permitted provided that the following conditions are met:
    6  * 
     6 *
    77 * 1. Redistributions of source code must retain the above copyright notice,
    88 *    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
    1111 *    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
    1414 *    software without specific prior written permission.
    15  * 
     15 *
    1616 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    1717 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     
    7777
    7878public class OsbDialog extends ToggleDialog implements OsbObserver, ListSelectionListener, LayerChangeListener,
    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) {
     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) {
    262262        mayTriggerPopup(e);
    263263    }
     
    266266        mayTriggerPopup(e);
    267267    }
    268    
     268
    269269    private void mayTriggerPopup(MouseEvent e) {
    270270        if(e.isPopupTrigger()) {
    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         }
     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    }
    301301}
  • applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/gui/OsbListCellRenderer.java

    r11161 r12778  
    11/* Copyright (c) 2008, Henrik Niehaus
    22 * All rights reserved.
    3  * 
     3 *
    44 * Redistribution and use in source and binary forms, with or without
    55 * modification, are permitted provided that the following conditions are met:
    6  * 
     6 *
    77 * 1. Redistributions of source code must retain the above copyright notice,
    88 *    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
    1111 *    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
    1414 *    software without specific prior written permission.
    15  * 
     15 *
    1616 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    1717 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     
    4545    private Color background = Color.WHITE;
    4646    private Color altBackground = new Color(250, 250, 220);
    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                
     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
    5454        if(isSelected) {
    55                 label.setBackground(UIManager.getColor("List.selectionBackground"));
     55            label.setBackground(UIManager.getColor("List.selectionBackground"));
    5656        } else {
    57                 label.setBackground(index % 2 == 0 ? background : altBackground);
     57            label.setBackground(index % 2 == 0 ? background : altBackground);
    5858        }
    59        
     59
    6060        OsbListItem item = (OsbListItem) value;
    6161        Node n = item.getNode();
    6262        Icon icon = null;
    6363        if("0".equals(n.get("state"))) {
    64                 icon = OsbPlugin.loadIcon("icon_error16.png");
     64            icon = OsbPlugin.loadIcon("icon_error16.png");
    6565        } else if("1".equals(n.get("state"))) {
    66                 icon = OsbPlugin.loadIcon("icon_valid16.png");
     66            icon = OsbPlugin.loadIcon("icon_valid16.png");
    6767        }
    6868        label.setIcon(icon);
    6969        String text = n.get("note");
    7070        if(text.indexOf("<hr />") > 0) {
    71                 text = text.substring(0, text.indexOf("<hr />"));
     71            text = text.substring(0, text.indexOf("<hr />"));
    7272        }
    7373        label.setText(text);
    74                
    75                 Dimension d = label.getPreferredSize();
    76                 d.height += 10;
    77                 label.setPreferredSize(d);
    78                
    79                 return label;
    80         }
     74
     75        Dimension d = label.getPreferredSize();
     76        d.height += 10;
     77        label.setPreferredSize(d);
     78
     79        return label;
     80    }
    8181
    8282}
  • applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/gui/OsbListItem.java

    r11157 r12778  
    11/* Copyright (c) 2008, Henrik Niehaus
    22 * All rights reserved.
    3  * 
     3 *
    44 * Redistribution and use in source and binary forms, with or without
    55 * modification, are permitted provided that the following conditions are met:
    6  * 
     6 *
    77 * 1. Redistributions of source code must retain the above copyright notice,
    88 *    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
    1111 *    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
    1414 *    software without specific prior written permission.
    15  * 
     15 *
    1616 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    1717 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     
    3131
    3232public class OsbListItem {
    33         private Node node;
    34        
    35         public OsbListItem(Node node) {
    36                 super();
    37                 this.node = node;
    38         }
     33    private Node node;
    3934
    40         public Node getNode() {
    41                 return node;
    42         }
     35    public OsbListItem(Node node) {
     36        super();
     37        this.node = node;
     38    }
    4339
    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    }
    7171}
  • applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/gui/action/AddCommentAction.java

    r12588 r12778  
    11/* Copyright (c) 2008, Henrik Niehaus
    22 * All rights reserved.
    3  * 
     3 *
    44 * Redistribution and use in source and binary forms, with or without
    55 * modification, are permitted provided that the following conditions are met:
    6  * 
     6 *
    77 * 1. Redistributions of source code must retain the above copyright notice,
    88 *    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
    1111 *    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
    1414 *    software without specific prior written permission.
    15  * 
     15 *
    1616 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    1717 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     
    4040public class AddCommentAction extends OsbAction {
    4141
    42         private static final long serialVersionUID = 1L;
     42    private static final long serialVersionUID = 1L;
    4343
    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         }
     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    }
    6969}
  • applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/gui/action/CloseIssueAction.java

    r12588 r12778  
    11/* Copyright (c) 2008, Henrik Niehaus
    22 * All rights reserved.
    3  * 
     3 *
    44 * Redistribution and use in source and binary forms, with or without
    55 * modification, are permitted provided that the following conditions are met:
    6  * 
     6 *
    77 * 1. Redistributions of source code must retain the above copyright notice,
    88 *    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
    1111 *    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
    1414 *    software without specific prior written permission.
    15  * 
     15 *
    1616 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    1717 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     
    4040public class CloseIssueAction extends OsbAction {
    4141
    42         private static final long serialVersionUID = 1L;
     42    private static final long serialVersionUID = 1L;
    4343
    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         }
     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    }
    6161}
  • applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/gui/action/NewIssueAction.java

    r12640 r12778  
    11/* Copyright (c) 2008, Henrik Niehaus
    22 * All rights reserved.
    3  * 
     3 *
    44 * Redistribution and use in source and binary forms, with or without
    55 * modification, are permitted provided that the following conditions are met:
    6  * 
     6 *
    77 * 1. Redistributions of source code must retain the above copyright notice,
    88 *    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
    1111 *    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
    1414 *    software without specific prior written permission.
    15  * 
     15 *
    1616 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    1717 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     
    4747public class NewIssueAction extends OsbAction implements MouseListener {
    4848
    49         private static final long serialVersionUID = 1L;
     49    private static final long serialVersionUID = 1L;
    5050
    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();
    7252
    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;
    7854
    79         public void mouseClicked(MouseEvent e) {
    80                 addNewIssue(e);
    81         }
     55    private OsbPlugin plugin;
    8256
    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    }
    8462
    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    }
    8672
    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    }
    9078
    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    }
    13082
    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) {}
    132132}
  • applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/gui/action/OsbAction.java

    r11568 r12778  
    11/* Copyright (c) 2008, Henrik Niehaus
    22 * All rights reserved.
    3  * 
     3 *
    44 * Redistribution and use in source and binary forms, with or without
    55 * modification, are permitted provided that the following conditions are met:
    6  * 
     6 *
    77 * 1. Redistributions of source code must retain the above copyright notice,
    88 *    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
    1111 *    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
    1414 *    software without specific prior written permission.
    15  * 
     15 *
    1616 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    1717 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     
    3838public abstract class OsbAction extends AbstractAction {
    3939
    40         private static final long serialVersionUID = 1L;
     40    private static final long serialVersionUID = 1L;
    4141
    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>();
    4943
    50         public static Node getSelectedNode() {
    51                 return selectedNode;
    52         }
     44    private static Node selectedNode;
    5345
    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    }
    7979}
  • applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/gui/action/OsbActionObserver.java

    r11157 r12778  
    11/* Copyright (c) 2008, Henrik Niehaus
    22 * All rights reserved.
    3  * 
     3 *
    44 * Redistribution and use in source and binary forms, with or without
    55 * modification, are permitted provided that the following conditions are met:
    6  * 
     6 *
    77 * 1. Redistributions of source code must retain the above copyright notice,
    88 *    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
    1111 *    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
    1414 *    software without specific prior written permission.
    15  * 
     15 *
    1616 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    1717 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     
    2929
    3030public interface OsbActionObserver {
    31         public void actionPerformed(OsbAction action);
     31    public void actionPerformed(OsbAction action);
    3232}
  • applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/gui/action/PopupFactory.java

    r12588 r12778  
    11/* Copyright (c) 2008, Henrik Niehaus
    22 * All rights reserved.
    3  * 
     3 *
    44 * Redistribution and use in source and binary forms, with or without
    55 * modification, are permitted provided that the following conditions are met:
    6  * 
     6 *
    77 * 1. Redistributions of source code must retain the above copyright notice,
    88 *    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
    1111 *    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
    1414 *    software without specific prior written permission.
    15  * 
     15 *
    1616 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    1717 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     
    3737
    3838public 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         }
    5239
    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    }
    8686}
Note: See TracChangeset for help on using the changeset viewer.