Changeset 2749 in josm for trunk/src/org/openstreetmap


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

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

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/DialogsPanel.java

    r2711 r2749  
    4040        allDialogs = new ArrayList<ToggleDialog>();
    4141
    42         for (Integer i=0; i < pAllDialogs.size(); ++i) {
    43             add(pAllDialogs.get(i), false);
     42        for (ToggleDialog dialog: pAllDialogs) {
     43            add(dialog, false);
    4444        }
    4545
     
    106106        /*  INVISIBLE_TO_COLLAPSED,    does not happen */
    107107        ELEMENT_SHRINKS         /* else. (Remaining elements have more space.) */
    108     };
     108    }
    109109    /**
    110110     * Reconstruct the view, if the configurations of dialogs has changed.
     
    119119         * reset the panels
    120120         */
    121         for (int i=0; i < N; ++i) {
    122             final JPanel p = panels.get(i);
     121        for (JPanel p: panels) {
    123122            p.removeAll();
    124123            p.setVisible(false);
     
    180179            int sumC = 0;   // sum of heights of all collapsed dialogs (triggering dialog is never collapsed)
    181180
    182             for (int i=0; i<N; ++i) {
    183                 final ToggleDialog dlg = allDialogs.get(i);
     181            for (ToggleDialog dlg: allDialogs) {
    184182                if (dlg.isDialogInDefaultView()) {
    185183                    if (dlg != triggeredBy) {
    186184                        final int ph = dlg.getPreferredHeight();
    187                         final int ah = dlg.getSize().height;
     185                        final int ah = dlg.getHeight();
    188186                        sumP += ph;
    189187                        sumA += ah;
    190188                    }
    191                 }
    192                 else if (dlg.isDialogInCollapsedView()) {
    193                     sumC += dlg.getSize().height;
     189                } else if (dlg.isDialogInCollapsedView()) {
     190                    sumC += dlg.getHeight();
    194191                }
    195192            }
     
    234231                final ToggleDialog dlg = allDialogs.get(i);
    235232                if (dlg.isDialogInDefaultView() && dlg != triggeredBy) {
    236                     final int ha = dlg.getSize().height;
     233                    final int ha = dlg.getHeight();
    237234                    final int h0 = ha * R / sumA;
    238235                    final int he = dlg.getPreferredHeight() * s2 / (sumP + hp_trig);
     
    246243                        } catch (ArithmeticException e) { /* D_p may be zero - nothing wrong with that. */
    247244                            d = 0;
    248                         };
     245                        }
    249246                        dlg.setPreferredSize(new Dimension(Integer.MAX_VALUE, h0 - d));
    250247                    }
  • 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.