Index: trunk/src/org/openstreetmap/josm/gui/dialogs/DialogsPanel.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/DialogsPanel.java	(revision 2748)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/DialogsPanel.java	(revision 2749)
@@ -40,6 +40,6 @@
         allDialogs = new ArrayList<ToggleDialog>();
 
-        for (Integer i=0; i < pAllDialogs.size(); ++i) {
-            add(pAllDialogs.get(i), false);
+        for (ToggleDialog dialog: pAllDialogs) {
+            add(dialog, false);
         }
 
@@ -106,5 +106,5 @@
         /*  INVISIBLE_TO_COLLAPSED,    does not happen */
         ELEMENT_SHRINKS         /* else. (Remaining elements have more space.) */
-    };
+    }
     /**
      * Reconstruct the view, if the configurations of dialogs has changed.
@@ -119,6 +119,5 @@
          * reset the panels
          */
-        for (int i=0; i < N; ++i) {
-            final JPanel p = panels.get(i);
+        for (JPanel p: panels) {
             p.removeAll();
             p.setVisible(false);
@@ -180,16 +179,14 @@
             int sumC = 0;   // sum of heights of all collapsed dialogs (triggering dialog is never collapsed)
 
-            for (int i=0; i<N; ++i) {
-                final ToggleDialog dlg = allDialogs.get(i);
+            for (ToggleDialog dlg: allDialogs) {
                 if (dlg.isDialogInDefaultView()) {
                     if (dlg != triggeredBy) {
                         final int ph = dlg.getPreferredHeight();
-                        final int ah = dlg.getSize().height;
+                        final int ah = dlg.getHeight();
                         sumP += ph;
                         sumA += ah;
                     }
-                }
-                else if (dlg.isDialogInCollapsedView()) {
-                    sumC += dlg.getSize().height;
+                } else if (dlg.isDialogInCollapsedView()) {
+                    sumC += dlg.getHeight();
                 }
             }
@@ -234,5 +231,5 @@
                 final ToggleDialog dlg = allDialogs.get(i);
                 if (dlg.isDialogInDefaultView() && dlg != triggeredBy) {
-                    final int ha = dlg.getSize().height;
+                    final int ha = dlg.getHeight();
                     final int h0 = ha * R / sumA;
                     final int he = dlg.getPreferredHeight() * s2 / (sumP + hp_trig);
@@ -246,5 +243,5 @@
                         } catch (ArithmeticException e) { /* D_p may be zero - nothing wrong with that. */
                             d = 0;
-                        };
+                        }
                         dlg.setPreferredSize(new Dimension(Integer.MAX_VALUE, h0 - d));
                     }
Index: trunk/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java	(revision 2748)
+++ trunk/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java	(revision 2749)
@@ -10,5 +10,4 @@
 
 import java.awt.AlphaComposite;
-import java.awt.BorderLayout;
 import java.awt.Color;
 import java.awt.Component;
@@ -31,5 +30,4 @@
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Date;
 import java.util.HashSet;
 import java.util.LinkedHashSet;
@@ -40,7 +38,7 @@
 import javax.swing.JMenuItem;
 import javax.swing.JOptionPane;
-import javax.swing.JPanel;
 import javax.swing.JSeparator;
 import javax.swing.SwingConstants;
+import javax.swing.SwingUtilities;
 
 import org.openstreetmap.josm.Main;
@@ -48,12 +46,11 @@
 import org.openstreetmap.josm.actions.mapmode.MapMode;
 import org.openstreetmap.josm.data.Bounds;
-import org.openstreetmap.josm.data.coor.CachedLatLon;
 import org.openstreetmap.josm.data.coor.LatLon;
 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
 import org.openstreetmap.josm.gui.ExtendedDialog;
 import org.openstreetmap.josm.gui.MapFrame;
-import org.openstreetmap.josm.gui.MapFrame.MapModeChangeListener;
 import org.openstreetmap.josm.gui.MapView;
 import org.openstreetmap.josm.gui.PleaseWaitRunnable;
+import org.openstreetmap.josm.gui.MapFrame.MapModeChangeListener;
 import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
 import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
@@ -64,4 +61,5 @@
 
 import com.drew.imaging.jpeg.JpegMetadataReader;
+import com.drew.lang.CompoundException;
 import com.drew.lang.Rational;
 import com.drew.metadata.Directory;
@@ -239,5 +237,14 @@
                 Main.map.mapView.addPropertyChangeListener(layer);
                 if (!addedToggleDialog) {
-                    Main.map.addToggleDialog(ImageViewerDialog.getInstance());
+                    // TODO Workaround for bug in DialogsPanel
+                    // When GeoImageLayer is added as a first layer, division by zero exception is thrown
+                    // This is caused by DialogsPanel.reconstruct method which use height of other dialogs
+                    // to calculate height of newly added ImageViewerDialog. But height of other dialogs is
+                    // zero because it's calculated by layout manager later
+                    SwingUtilities.invokeLater(new Runnable() {
+                        public void run() {
+                            Main.map.addToggleDialog(ImageViewerDialog.getInstance());
+                        }
+                    });
                     addedToggleDialog = true;
                 }
@@ -515,5 +522,5 @@
             e.exifCoor = e.getPos();
 
-        } catch (Exception p) {
+        } catch (CompoundException p) {
             e.exifCoor = null;
             e.setPos(null);
@@ -531,5 +538,5 @@
             currentPhoto = -1;
         }
-        Main.main.map.repaint();
+        Main.map.repaint();
     }
 
@@ -544,5 +551,5 @@
             currentPhoto = -1;
         }
-        Main.main.map.repaint();
+        Main.map.repaint();
     }
 
@@ -565,5 +572,5 @@
             }
             updateOffscreenBuffer = true;
-            Main.main.map.repaint();
+            Main.map.repaint();
         }
     }
@@ -578,12 +585,12 @@
                     tr("Delete image file from disk"),
                     new String[] {tr("Cancel"), tr("Delete")})
-                .setButtonIcons(new String[] {"cancel.png", "dialogs/delete.png"})
-                .setContent(new JLabel(tr("<html><h3>Delete the file {0} from disk?<p>The image file will be permanently lost!</h3></html>"
+            .setButtonIcons(new String[] {"cancel.png", "dialogs/delete.png"})
+            .setContent(new JLabel(tr("<html><h3>Delete the file {0} from disk?<p>The image file will be permanently lost!</h3></html>"
                     ,toDelete.file.getName()), ImageProvider.get("dialogs/geoimage/deletefromdisk"),SwingConstants.LEFT))
-                .toggleEnable("geoimage.deleteimagefromdisk")
-                .setCancelButton(1)
-                .setDefaultButton(2)
-                .showDialog()
-                .getValue();
+                    .toggleEnable("geoimage.deleteimagefromdisk")
+                    .setCancelButton(1)
+                    .setDefaultButton(2)
+                    .showDialog()
+                    .getValue();
 
             if(result == 2)
@@ -603,13 +610,13 @@
                 } else {
                     JOptionPane.showMessageDialog(
-                        Main.parent,
-                        tr("Image file could not be deleted."),
-                        tr("Error"),
-                        JOptionPane.ERROR_MESSAGE
+                            Main.parent,
+                            tr("Image file could not be deleted."),
+                            tr("Error"),
+                            JOptionPane.ERROR_MESSAGE
                     );
                 }
 
                 updateOffscreenBuffer = true;
-                Main.main.map.repaint();
+                Main.map.repaint();
             }
         }
@@ -655,5 +662,5 @@
                         currentPhoto = i;
                         ImageViewerDialog.showImage(GeoImageLayer.this, e);
-                        Main.main.map.repaint();
+                        Main.map.repaint();
                         break;
                     }
@@ -672,5 +679,5 @@
         };
 
-        Main.map.addMapModeChangeListener(mapModeListener);
+        MapFrame.addMapModeChangeListener(mapModeListener);
         mapModeListener.mapModeChange(null, Main.map.mapMode);
 
@@ -692,5 +699,5 @@
                     }
                     Main.map.mapView.removeMouseListener(mouseAdapter);
-                    Main.map.removeMapModeChangeListener(mapModeListener);
+                    MapFrame.removeMapModeChangeListener(mapModeListener);
                     currentPhoto = -1;
                     data.clear();
