Ignore:
Timestamp:
2010-01-07T07:58:44+01:00 (14 years ago)
Author:
jttt
Message:

Workaround division by zero exception when geoimage layer is added as first layer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java

    r2733 r2749  
    1010
    1111import java.awt.AlphaComposite;
    12 import java.awt.BorderLayout;
    1312import java.awt.Color;
    1413import java.awt.Component;
     
    3130import java.util.Collection;
    3231import java.util.Collections;
    33 import java.util.Date;
    3432import java.util.HashSet;
    3533import java.util.LinkedHashSet;
     
    4038import javax.swing.JMenuItem;
    4139import javax.swing.JOptionPane;
    42 import javax.swing.JPanel;
    4340import javax.swing.JSeparator;
    4441import javax.swing.SwingConstants;
     42import javax.swing.SwingUtilities;
    4543
    4644import org.openstreetmap.josm.Main;
     
    4846import org.openstreetmap.josm.actions.mapmode.MapMode;
    4947import org.openstreetmap.josm.data.Bounds;
    50 import org.openstreetmap.josm.data.coor.CachedLatLon;
    5148import org.openstreetmap.josm.data.coor.LatLon;
    5249import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
    5350import org.openstreetmap.josm.gui.ExtendedDialog;
    5451import org.openstreetmap.josm.gui.MapFrame;
    55 import org.openstreetmap.josm.gui.MapFrame.MapModeChangeListener;
    5652import org.openstreetmap.josm.gui.MapView;
    5753import org.openstreetmap.josm.gui.PleaseWaitRunnable;
     54import org.openstreetmap.josm.gui.MapFrame.MapModeChangeListener;
    5855import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
    5956import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
     
    6461
    6562import com.drew.imaging.jpeg.JpegMetadataReader;
     63import com.drew.lang.CompoundException;
    6664import com.drew.lang.Rational;
    6765import com.drew.metadata.Directory;
     
    239237                Main.map.mapView.addPropertyChangeListener(layer);
    240238                if (!addedToggleDialog) {
    241                     Main.map.addToggleDialog(ImageViewerDialog.getInstance());
     239                    // TODO Workaround for bug in DialogsPanel
     240                    // When GeoImageLayer is added as a first layer, division by zero exception is thrown
     241                    // This is caused by DialogsPanel.reconstruct method which use height of other dialogs
     242                    // to calculate height of newly added ImageViewerDialog. But height of other dialogs is
     243                    // zero because it's calculated by layout manager later
     244                    SwingUtilities.invokeLater(new Runnable() {
     245                        public void run() {
     246                            Main.map.addToggleDialog(ImageViewerDialog.getInstance());
     247                        }
     248                    });
    242249                    addedToggleDialog = true;
    243250                }
     
    515522            e.exifCoor = e.getPos();
    516523
    517         } catch (Exception p) {
     524        } catch (CompoundException p) {
    518525            e.exifCoor = null;
    519526            e.setPos(null);
     
    531538            currentPhoto = -1;
    532539        }
    533         Main.main.map.repaint();
     540        Main.map.repaint();
    534541    }
    535542
     
    544551            currentPhoto = -1;
    545552        }
    546         Main.main.map.repaint();
     553        Main.map.repaint();
    547554    }
    548555
     
    565572            }
    566573            updateOffscreenBuffer = true;
    567             Main.main.map.repaint();
     574            Main.map.repaint();
    568575        }
    569576    }
     
    578585                    tr("Delete image file from disk"),
    579586                    new String[] {tr("Cancel"), tr("Delete")})
    580                 .setButtonIcons(new String[] {"cancel.png", "dialogs/delete.png"})
    581                 .setContent(new JLabel(tr("<html><h3>Delete the file {0} from disk?<p>The image file will be permanently lost!</h3></html>"
     587            .setButtonIcons(new String[] {"cancel.png", "dialogs/delete.png"})
     588            .setContent(new JLabel(tr("<html><h3>Delete the file {0} from disk?<p>The image file will be permanently lost!</h3></html>"
    582589                    ,toDelete.file.getName()), ImageProvider.get("dialogs/geoimage/deletefromdisk"),SwingConstants.LEFT))
    583                 .toggleEnable("geoimage.deleteimagefromdisk")
    584                 .setCancelButton(1)
    585                 .setDefaultButton(2)
    586                 .showDialog()
    587                 .getValue();
     590                    .toggleEnable("geoimage.deleteimagefromdisk")
     591                    .setCancelButton(1)
     592                    .setDefaultButton(2)
     593                    .showDialog()
     594                    .getValue();
    588595
    589596            if(result == 2)
     
    603610                } else {
    604611                    JOptionPane.showMessageDialog(
    605                         Main.parent,
    606                         tr("Image file could not be deleted."),
    607                         tr("Error"),
    608                         JOptionPane.ERROR_MESSAGE
     612                            Main.parent,
     613                            tr("Image file could not be deleted."),
     614                            tr("Error"),
     615                            JOptionPane.ERROR_MESSAGE
    609616                    );
    610617                }
    611618
    612619                updateOffscreenBuffer = true;
    613                 Main.main.map.repaint();
     620                Main.map.repaint();
    614621            }
    615622        }
     
    655662                        currentPhoto = i;
    656663                        ImageViewerDialog.showImage(GeoImageLayer.this, e);
    657                         Main.main.map.repaint();
     664                        Main.map.repaint();
    658665                        break;
    659666                    }
     
    672679        };
    673680
    674         Main.map.addMapModeChangeListener(mapModeListener);
     681        MapFrame.addMapModeChangeListener(mapModeListener);
    675682        mapModeListener.mapModeChange(null, Main.map.mapMode);
    676683
     
    692699                    }
    693700                    Main.map.mapView.removeMouseListener(mouseAdapter);
    694                     Main.map.removeMapModeChangeListener(mapModeListener);
     701                    MapFrame.removeMapModeChangeListener(mapModeListener);
    695702                    currentPhoto = -1;
    696703                    data.clear();
Note: See TracChangeset for help on using the changeset viewer.