Index: /applications/editors/josm/plugins/agpifoj/src/org/openstreetmap/josm/plugins/agpifoj/AgpifojDialog.java
===================================================================
--- /applications/editors/josm/plugins/agpifoj/src/org/openstreetmap/josm/plugins/agpifoj/AgpifojDialog.java	(revision 10257)
+++ /applications/editors/josm/plugins/agpifoj/src/org/openstreetmap/josm/plugins/agpifoj/AgpifojDialog.java	(revision 10258)
@@ -8,4 +8,5 @@
 
 import java.awt.BorderLayout;
+import java.awt.Dimension;
 import java.awt.FlowLayout;
 import java.awt.event.ActionEvent;
@@ -23,4 +24,10 @@
 
 public class AgpifojDialog extends ToggleDialog implements ActionListener {
+
+    private static final String COMMAND_ZOOM = "zoom";
+    private static final String COMMAND_CENTERVIEW = "centre";
+    private static final String COMMAND_NEXT = "next";
+    private static final String COMMAND_REMOVE = "remove";
+    private static final String COMMAND_PREVIOUS = "previous";
 
     private ImageDisplay imgDisplay = new ImageDisplay();
@@ -56,37 +63,43 @@
         JButton button;
         
+        Dimension buttonDim = new Dimension(26,26);
         button = new JButton();
         button.setIcon(ImageProvider.get("dialogs", "previous"));
-        button.setActionCommand("previous");
+        button.setActionCommand(COMMAND_PREVIOUS);
         button.setToolTipText(tr("Previous"));
         button.addActionListener(this);
+        button.setPreferredSize(buttonDim);
         buttons.add(button);
         
         button = new JButton();
         button.setIcon(ImageProvider.get("dialogs", "delete"));
-        button.setActionCommand("remove");
+        button.setActionCommand(COMMAND_REMOVE);
         button.setToolTipText(tr("Remove photo from layer"));
         button.addActionListener(this);
+        button.setPreferredSize(buttonDim);
         buttons.add(button);
         
         button = new JButton();
         button.setIcon(ImageProvider.get("dialogs", "next"));
-        button.setActionCommand("next");
+        button.setActionCommand(COMMAND_NEXT);
         button.setToolTipText(tr("Next"));
         button.addActionListener(this);
+        button.setPreferredSize(buttonDim);
         buttons.add(button);
         
         JToggleButton tb = new JToggleButton();
         tb.setIcon(ImageProvider.get("dialogs", "centreview"));
-        tb.setActionCommand("centre");
+        tb.setActionCommand(COMMAND_CENTERVIEW);
         tb.setToolTipText(tr("Center view"));
         tb.addActionListener(this);
+        tb.setPreferredSize(buttonDim);
         buttons.add(tb);
         
         button = new JButton();
         button.setIcon(ImageProvider.get("dialogs", "zoom-best-fit"));
-        button.setActionCommand("zoom");
+        button.setActionCommand(COMMAND_ZOOM);
         button.setToolTipText(tr("Zoom best fit and 1:1"));
         button.addActionListener(this);
+        button.setPreferredSize(buttonDim);
         buttons.add(button);
         
@@ -98,14 +111,14 @@
 
     public void actionPerformed(ActionEvent e) {
-        if ("next".equals(e.getActionCommand())) {
+        if (COMMAND_NEXT.equals(e.getActionCommand())) {
             if (currentLayer != null) {
                 currentLayer.showNextPhoto();
             }
-        } else if ("previous".equals(e.getActionCommand())) {
+        } else if (COMMAND_PREVIOUS.equals(e.getActionCommand())) {
             if (currentLayer != null) {
                 currentLayer.showPreviousPhoto();
             }
             
-        } else if ("centre".equals(e.getActionCommand())) {
+        } else if (COMMAND_CENTERVIEW.equals(e.getActionCommand())) {
             centerView = ((JToggleButton) e.getSource()).isSelected();
             if (centerView && currentEntry != null && currentEntry.pos != null) {
@@ -113,8 +126,8 @@
             }
             
-        } else if ("zoom".equals(e.getActionCommand())) {
+        } else if (COMMAND_ZOOM.equals(e.getActionCommand())) {
             imgDisplay.zoomBestFitOrOne();
             
-        } else if ("remove".equals(e.getActionCommand())) {
+        } else if (COMMAND_REMOVE.equals(e.getActionCommand())) {
             if (currentLayer != null) {
                currentLayer.removeCurrentPhoto();
@@ -125,12 +138,5 @@
 
     public static void showImage(AgpifojLayer layer, ImageEntry entry) {
-        if (INSTANCE == null) {
-            Main.main.map.addToggleDialog(new AgpifojDialog());
-        }
-        
-        if (INSTANCE != null) {
-            INSTANCE.displayImage(layer, entry);
-        }
-        
+        getInstance().displayImage(layer, entry);
     }
 
@@ -145,5 +151,5 @@
             }
         
-            if (centerView && entry != null && entry.pos != null) {
+            if (centerView && Main.map != null && entry != null && entry.pos != null) {
                 Main.map.mapView.zoomTo(entry.pos, Main.map.mapView.getScale());
             }
Index: /applications/editors/josm/plugins/agpifoj/src/org/openstreetmap/josm/plugins/agpifoj/ImageDisplay.java
===================================================================
--- /applications/editors/josm/plugins/agpifoj/src/org/openstreetmap/josm/plugins/agpifoj/ImageDisplay.java	(revision 10257)
+++ /applications/editors/josm/plugins/agpifoj/src/org/openstreetmap/josm/plugins/agpifoj/ImageDisplay.java	(revision 10258)
@@ -480,6 +480,7 @@
                 int x = 3;
                 int y = 3;
+                String line;
                 while (pos > 0) {
-                    String line = osdText.substring(lastPos, pos);
+                    line = osdText.substring(lastPos, pos);
                     Rectangle2D lineSize = metrics.getStringBounds(line, g);
                     g.setColor(bkground);
@@ -491,12 +492,11 @@
                     pos = osdText.indexOf("\n", lastPos);
                 }
-                if (lastPos > 0) {
-                    String line = osdText.substring(lastPos);
-                    Rectangle2D lineSize = g.getFontMetrics(g.getFont()).getStringBounds(line, g);
-                    g.setColor(bkground);
-                    g.fillRect(x, y, (int) lineSize.getWidth(), (int) lineSize.getHeight());
-                    g.setColor(Color.black);
-                    g.drawString(line, x, y + ascent);
-                }
+
+                line = osdText.substring(lastPos);
+                Rectangle2D lineSize = g.getFontMetrics(g.getFont()).getStringBounds(line, g);
+                g.setColor(bkground);
+                g.fillRect(x, y, (int) lineSize.getWidth(), (int) lineSize.getHeight());
+                g.setColor(Color.black);
+                g.drawString(line, x, y + ascent);
             }
         }
