Ignore:
Timestamp:
2009-07-26T22:52:23+02:00 (17 years ago)
Author:
Gubaer
Message:

replaced JOptionDialog.show... by OptionPaneUtil.show....
improved relation editor

Location:
trunk/src/org/openstreetmap/josm/data
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/DataSetChecker.java

    r1814 r1857  
    99import org.openstreetmap.josm.Main;
    1010import org.openstreetmap.josm.data.osm.OsmPrimitive;
     11import org.openstreetmap.josm.gui.OptionPaneUtil;
    1112import org.openstreetmap.josm.gui.layer.Layer;
    1213import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     14
     15// FIXME: class still needed?
    1316
    1417public class DataSetChecker {
     
    2326                for (OsmPrimitive osm : ((OsmDataLayer)l).data.allPrimitives()) {
    2427                    if (s.contains(osm)) {
    25                         JOptionPane.showMessageDialog(Main.parent, "cross references");
     28                        // FIXME: better message
     29                        // FIXME: translate message and title
     30                        OptionPaneUtil.showMessageDialog(
     31                                Main.parent,
     32                                "cross references",
     33                                "Information",
     34                                JOptionPane.INFORMATION_MESSAGE);
    2635                        return;
    2736                    }
     
    3443            OsmDataLayer l = (OsmDataLayer)Main.map.mapView.getActiveLayer();
    3544            if (l.data != Main.main.getCurrentDataSet()) {
    36                 JOptionPane.showMessageDialog(Main.parent, "Main.ds / active layer mismatch");
     45                OptionPaneUtil.showMessageDialog(
     46                        Main.parent,
     47                        "Main.ds / active layer mismatch",
     48                        "Error",
     49                        JOptionPane.ERROR_MESSAGE
     50                );
    3751                return;
    3852            }
    3953        }
    4054
    41         JOptionPane.showMessageDialog(Main.parent, "working");
     55        OptionPaneUtil.showMessageDialog(
     56                Main.parent, "working", "", JOptionPane.INFORMATION_MESSAGE);
    4257    }
    4358}
  • trunk/src/org/openstreetmap/josm/data/Preferences.java

    r1722 r1857  
    3131import org.openstreetmap.josm.actions.AboutAction;
    3232import org.openstreetmap.josm.data.projection.Mercator;
     33import org.openstreetmap.josm.gui.OptionPaneUtil;
    3334import org.openstreetmap.josm.gui.preferences.ProxyPreferences;
    3435import org.openstreetmap.josm.tools.ColorHelper;
     
    4546
    4647    /**
    47     * Internal storage for the preferenced directory.
    48     * Do not access this variable directly!
    49     * @see #getPreferencesDirFile()
    50     */
     48     * Internal storage for the preferenced directory.
     49     * Do not access this variable directly!
     50     * @see #getPreferencesDirFile()
     51     */
    5152    private File preferencesDirFile = null;
    5253
     
    131132        String s;
    132133        if ((s = System.getenv("JOSM_RESOURCES")) != null) {
    133             if (!s.endsWith(File.separator))
     134            if (!s.endsWith(File.separator)) {
    134135                s = s + File.separator;
     136            }
    135137            locations.add(s);
    136138        }
    137139        if ((s = System.getProperty("josm.resources")) != null) {
    138             if (!s.endsWith(File.separator))
     140            if (!s.endsWith(File.separator)) {
    139141                s = s + File.separator;
     142            }
    140143            locations.add(s);
    141144        }
     
    180183        final Map<String,String> all = new TreeMap<String,String>();
    181184        for (final Entry<String,String> e : properties.entrySet())
    182             if (e.getKey().startsWith(prefix))
     185            if (e.getKey().startsWith(prefix)) {
    183186                all.put(e.getKey(), e.getValue());
     187            }
    184188        for (final Entry<String,String> e : override.entrySet())
    185189            if (e.getKey().startsWith(prefix))
    186                 if (e.getValue() == null)
     190                if (e.getValue() == null) {
    187191                    all.remove(e.getKey());
    188                 else
     192                } else {
    189193                    all.put(e.getKey(), e.getValue());
     194                }
    190195        return all;
    191196    }
     
    194199        final TreeMap<String,String> all = new TreeMap<String,String>();
    195200        for (final Entry<String,String> e : defaults.entrySet())
    196             if (e.getKey().startsWith("color.") && e.getValue() != null)
     201            if (e.getKey().startsWith("color.") && e.getValue() != null) {
    197202                all.put(e.getKey().substring(6), e.getValue());
     203            }
    198204        for (final Entry<String,String> e : properties.entrySet())
    199             if (e.getKey().startsWith("color."))
     205            if (e.getKey().startsWith("color.")) {
    200206                all.put(e.getKey().substring(6), e.getValue());
     207            }
    201208        for (final Entry<String,String> e : override.entrySet())
    202209            if (e.getKey().startsWith("color."))
    203                 if (e.getValue() == null)
     210                if (e.getValue() == null) {
    204211                    all.remove(e.getKey().substring(6));
    205                 else
     212                } else {
    206213                    all.put(e.getKey().substring(6), e.getValue());
     214                }
    207215        return all;
    208216    }
     
    213221
    214222    synchronized public void putDefault(final String key, final String def) {
    215         if(!defaults.containsKey(key) || defaults.get(key) == null)
     223        if(!defaults.containsKey(key) || defaults.get(key) == null) {
    216224            defaults.put(key, def);
    217         else if(def != null && !defaults.get(key).equals(def))
     225        } else if(def != null && !defaults.get(key).equals(def)) {
    218226            System.out.println("Defaults for " + key + " differ: " + def + " != " + defaults.get(key));
     227        }
    219228    }
    220229
     
    235244    synchronized public boolean put(final String key, String value) {
    236245        String oldvalue = properties.get(key);
    237         if(value != null && value.length() == 0)
     246        if(value != null && value.length() == 0) {
    238247            value = null;
     248        }
    239249        if(!((oldvalue == null && (value == null || value.equals(defaults.get(key))))
    240         || (value != null && oldvalue != null && oldvalue.equals(value))))
     250                || (value != null && oldvalue != null && oldvalue.equals(value))))
    241251        {
    242             if (value == null)
     252            if (value == null) {
    243253                properties.remove(key);
    244             else
     254            } else {
    245255                properties.put(key, value);
     256            }
    246257            save();
    247258            firePreferenceChanged(key, value);
     
    268279
    269280    private final void firePreferenceChanged(final String key, final String value) {
    270         for (final PreferenceChangedListener l : listener)
     281        for (final PreferenceChangedListener l : listener) {
    271282            l.preferenceChanged(key, value);
     283        }
    272284    }
    273285
     
    282294            setSystemProperties();
    283295            final PrintWriter out = new PrintWriter(new OutputStreamWriter(
    284             new FileOutputStream(getPreferencesDir() + "preferences"), "utf-8"), false);
     296                    new FileOutputStream(getPreferencesDir() + "preferences"), "utf-8"), false);
    285297            for (final Entry<String, String> e : properties.entrySet()) {
    286298                String s = defaults.get(e.getKey());
    287299                /* don't save default values */
    288                 if(s == null || !s.equals(e.getValue()))
     300                if(s == null || !s.equals(e.getValue())) {
    289301                    out.println(e.getKey() + "=" + e.getValue());
     302                }
    290303            }
    291304            out.close();
     
    300313        properties.clear();
    301314        final BufferedReader in = new BufferedReader(new InputStreamReader(
    302         new FileInputStream(getPreferencesDir()+"preferences"), "utf-8"));
     315                new FileInputStream(getPreferencesDir()+"preferences"), "utf-8"));
    303316        int lineNumber = 0;
    304317        ArrayList<Integer> errLines = new ArrayList<Integer>();
     
    322335        if (prefDir.exists()) {
    323336            if(!prefDir.isDirectory()) {
    324                 JOptionPane.showMessageDialog(null, tr("Cannot open preferences directory: {0}",Main.pref.getPreferencesDir()));
     337                OptionPaneUtil.showMessageDialog(
     338                        Main.parent,
     339                        tr("Cannot open preferences directory: {0}",Main.pref.getPreferencesDir()),
     340                        tr("Error"),
     341                        JOptionPane.ERROR_MESSAGE
     342                );
    325343                return;
    326344            }
    327         }
    328         else
     345        } else {
    329346            prefDir.mkdirs();
    330 
    331         if (!new File(getPreferencesDir()+"preferences").exists())
     347        }
     348
     349        if (!new File(getPreferencesDir()+"preferences").exists()) {
    332350            resetToDefault();
     351        }
    333352
    334353        try {
    335             if (reset)
     354            if (reset) {
    336355                resetToDefault();
    337             else
     356            } else {
    338357                load();
     358            }
    339359        } catch (final IOException e1) {
    340360            e1.printStackTrace();
    341361            String backup = getPreferencesDir() + "preferences.bak";
    342             JOptionPane.showMessageDialog(null, tr("Preferences file had errors. Making backup of old one to {0}.", backup));
     362            OptionPaneUtil.showMessageDialog(
     363                    Main.parent,
     364                    tr("Preferences file had errors. Making backup of old one to {0}.", backup),
     365                    tr("Error"),
     366                    JOptionPane.ERROR_MESSAGE
     367            );
    343368            new File(getPreferencesDir() + "preferences").renameTo(new File(backup));
    344369            save();
     
    362387    public Collection<Bookmark> loadBookmarks() throws IOException {
    363388        File bookmarkFile = new File(getPreferencesDir()+"bookmarks");
    364         if (!bookmarkFile.exists())
     389        if (!bookmarkFile.exists()) {
    365390            bookmarkFile.createNewFile();
     391        }
    366392        BufferedReader in = new BufferedReader(new InputStreamReader(
    367         new FileInputStream(bookmarkFile), "utf-8"));
     393                new FileInputStream(bookmarkFile), "utf-8"));
    368394
    369395        LinkedList<Bookmark> bookmarks = new LinkedList<Bookmark>();
     
    375401                Bookmark b = new Bookmark();
    376402                b.name = m.group(1);
    377                 for (int i = 0; i < b.latlon.length; ++i)
     403                for (int i = 0; i < b.latlon.length; ++i) {
    378404                    b.latlon[i] = Double.parseDouble(m.group(i+2));
     405                }
    379406                bookmarks.add(b);
    380407            }
     
    387414    public void saveBookmarks(Collection<Bookmark> bookmarks) throws IOException {
    388415        File bookmarkFile = new File(Main.pref.getPreferencesDir()+"bookmarks");
    389         if (!bookmarkFile.exists())
     416        if (!bookmarkFile.exists()) {
    390417            bookmarkFile.createNewFile();
     418        }
    391419        PrintWriter out = new PrintWriter(new OutputStreamWriter(
    392         new FileOutputStream(bookmarkFile), "utf-8"));
     420                new FileOutputStream(bookmarkFile), "utf-8"));
    393421        for (Bookmark b : bookmarks) {
    394422            out.print(b.name+"\u001e");
    395             for (int i = 0; i < b.latlon.length; ++i)
     423            for (int i = 0; i < b.latlon.length; ++i) {
    396424                out.print(b.latlon[i]+(i<b.latlon.length-1?"\u001e":""));
     425            }
    397426            out.println();
    398427        }
     
    422451        putDefault("color."+colName, ColorHelper.color2html(def));
    423452        String colStr = specName != null ? get("color."+specName) : "";
    424         if(colStr.equals(""))
     453        if(colStr.equals("")) {
    425454            colStr = get("color."+colName);
     455        }
    426456        return colStr.equals("") ? def : ColorHelper.html2color(colStr);
    427457    }
     
    481511        putDefault(key, def);
    482512        String v = get(key);
    483         if(v != null && v.length() != 0)
     513        if(v != null && v.length() != 0) {
    484514            try { return Double.parseDouble(v); } catch(NumberFormatException e) {}
     515        }
    485516        try { return Double.parseDouble(def); } catch(NumberFormatException e) {}
    486517        return 0.0;
     
    494525            for(String a : def)
    495526            {
    496                 if(d != null)
     527                if(d != null) {
    497528                    d += "\u001e" + a;
    498                 else
     529                } else {
    499530                    d = a;
     531                }
    500532            }
    501533            putDefault(key, d);
     
    506538            {
    507539                String r =s;
    508                 if(r.indexOf("§§§") > 0) /* history dialog */
     540                if(r.indexOf("§§§") > 0) {
    509541                    r = r.replaceAll("§§§","\u001e");
    510                 else /* old style ';' separation */
     542                } else {
    511543                    r = r.replace(';','\u001e');
     544                }
    512545                if(!r.equals(s)) /* save the converted string */
    513546                {
     
    534567            for(String a : val)
    535568            {
    536                 if(s != null)
     569                if(s != null) {
    537570                    s += "\u001e" + a;
    538                 else
     571                } else {
    539572                    s = a;
     573                }
    540574            }
    541575        }
  • trunk/src/org/openstreetmap/josm/data/ServerSidePreferences.java

    r1169 r1857  
    2424
    2525import org.openstreetmap.josm.Main;
     26import org.openstreetmap.josm.gui.OptionPaneUtil;
    2627import org.openstreetmap.josm.io.OsmConnection;
    2728import org.openstreetmap.josm.io.XmlWriter;
     
    4849                System.out.println("reading preferences from "+serverUrl);
    4950                URLConnection con = serverUrl.openConnection();
    50                 if (con instanceof HttpURLConnection) addAuth((HttpURLConnection) con);
     51                if (con instanceof HttpURLConnection) {
     52                    addAuth((HttpURLConnection) con);
     53                }
    5154                con.connect();
    5255                BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream()));
     
    5659                    b.append("\n");
    5760                }
    58                 if (con instanceof HttpURLConnection) ((HttpURLConnection) con).disconnect();
     61                if (con instanceof HttpURLConnection) {
     62                    ((HttpURLConnection) con).disconnect();
     63                }
    5964                return b.toString();
    6065            } catch (IOException e) {
     
    7782                con.getInputStream().close();
    7883                con.disconnect();
    79                 JOptionPane.showMessageDialog(Main.parent, tr("Preferences stored on {0}", u.getHost()));
     84                OptionPaneUtil.showMessageDialog(
     85                        Main.parent,
     86                        tr("Preferences stored on {0}", u.getHost()),
     87                        tr("Information"),
     88                        JOptionPane.INFORMATION_MESSAGE
     89                );
    8090            } catch (Exception e) {
    8191                e.printStackTrace();
    82                 JOptionPane.showMessageDialog(Main.parent, tr("Could not upload preferences. Reason: {0}", e.getMessage()));
     92                OptionPaneUtil.showMessageDialog(
     93                        Main.parent,
     94                        tr("Could not upload preferences. Reason: {0}", e.getMessage()),
     95                        tr("Error"),
     96                        JOptionPane.ERROR_MESSAGE
     97                );
    8398            }
    8499        }
     
    119134    public void download(String userName, String password) {
    120135        resetToDefault();
    121         if (!properties.containsKey("osm-server.username") && userName != null)
     136        if (!properties.containsKey("osm-server.username") && userName != null) {
    122137            properties.put("osm-server.username", userName);
    123         if (!properties.containsKey("osm-server.password") && password != null)
     138        }
     139        if (!properties.containsKey("osm-server.password") && password != null) {
    124140            properties.put("osm-server.password", password);
     141        }
    125142        String cont = connection.download();
    126143        if (cont == null) return;
     
    128145        try {
    129146            XmlObjectParser.Uniform<Prop> parser = new XmlObjectParser.Uniform<Prop>(in, "tag", Prop.class);
    130             for (Prop p : parser)
     147            for (Prop p : parser) {
    131148                properties.put(p.key, p.value);
     149            }
    132150        } catch (RuntimeException e) {
    133151            e.printStackTrace();
     
    144162        StringBuilder b = new StringBuilder("<preferences>\n");
    145163        for (Entry<String, String> p : properties.entrySet()) {
    146             if (p.getKey().equals("osm-server.password"))
     164            if (p.getKey().equals("osm-server.password")) {
    147165                continue; // do not upload password. It would get stored in plain!
     166            }
    148167            b.append("<tag key='");
    149168            b.append(XmlWriter.encode(p.getKey()));
     
    163182            for (String line = in.readLine(); line != null; line = in.readLine()) {
    164183                StringTokenizer st = new StringTokenizer(line, ",");
    165                 if (st.countTokens() < 5)
     184                if (st.countTokens() < 5) {
    166185                    continue;
     186                }
    167187                Bookmark b = new Bookmark();
    168188                b.name = st.nextToken();
    169189                try {
    170                     for (int i = 0; i < b.latlon.length; ++i)
     190                    for (int i = 0; i < b.latlon.length; ++i) {
    171191                        b.latlon[i] = Double.parseDouble(st.nextToken());
     192                    }
    172193                    bookmarks.add(b);
    173194                } catch (NumberFormatException x) {
  • trunk/src/org/openstreetmap/josm/data/conflict/ConflictCollection.java

    r1750 r1857  
    6767    }
    6868
    69     protected void addConflict(Conflict<?> conflict) {
     69    /**
     70     * Adds a conflict to the collection
     71     *
     72     * @param conflict the conflict
     73     * @exception IllegalStateException thrown, if this collection already includes a
     74     * conflict for conflict.getMy()
     75     */
     76    protected void addConflict(Conflict<?> conflict) throws IllegalStateException {
    7077        if (hasConflictForMy(conflict.getMy()))
    7178            throw new IllegalStateException(tr("already registered a conflict for primitive ''{0}''", conflict.getMy().toString()));
  • trunk/src/org/openstreetmap/josm/data/projection/Lambert.java

    r1849 r1857  
    1313import org.openstreetmap.josm.data.coor.LatLon;
    1414import org.openstreetmap.josm.data.Bounds;
     15import org.openstreetmap.josm.gui.OptionPaneUtil;
    1516
    1617public class Lambert implements Projection {
     
    5253
    5354    public static final double zoneLimits[] = { Math.toRadians(53.5 * 0.9), // between Zone 1 and Zone 2 (in grad *0.9)
    54             Math.toRadians(50.5 * 0.9), // between Zone 2 and Zone 3
    55             Math.toRadians(47.51963 * 0.9), // between Zone 3 and Zone 4
    56             Math.toRadians(46.17821 * 0.9) };// lowest latitude of Zone 4
     55        Math.toRadians(50.5 * 0.9), // between Zone 2 and Zone 3
     56        Math.toRadians(47.51963 * 0.9), // between Zone 3 and Zone 4
     57        Math.toRadians(46.17821 * 0.9) };// lowest latitude of Zone 4
    5758
    5859    public static final double cMinLonZones = Math.toRadians(-4.9074074074074059 * 0.9);
     
    8485        if (lt >= zoneLimits[3] && lt <= cMaxLatZone1 && lg >= cMinLonZones && lg <= cMaxLonZones) {
    8586            // zone I
    86             if (lt > zoneLimits[0])
     87            if (lt > zoneLimits[0]) {
    8788                currentZone = 0;
    88             // zone II
    89             else if (lt > zoneLimits[1])
     89            } else if (lt > zoneLimits[1]) {
    9090                currentZone = 1;
    91             // zone III
    92             else if (lt > zoneLimits[2])
     91            } else if (lt > zoneLimits[2]) {
    9392                currentZone = 2;
    94             // zone III or IV
    95             else if (lt > zoneLimits[3])
     93            } else if (lt > zoneLimits[3])
    9694                // Note: zone IV is dedicated to Corsica island and extends from 47.8 to
    9795                // 45.9 degrees of latitude. There is an overlap with zone III that can be
    9896                // solved only with longitude (covers Corsica if lon > 7.2 degree)
    99                 if (lg < Math.toRadians(8 * 0.9))
     97                if (lg < Math.toRadians(8 * 0.9)) {
    10098                    currentZone = 2;
    101                 else
     99                } else {
    102100                    currentZone = 3;
     101                }
    103102        } else {
    104103            outOfLambertZones = true; // possible when MAX_LAT is used
     
    109108            } else if (layoutZone != currentZone) {
    110109                if ((currentZone < layoutZone && Math.abs(zoneLimits[currentZone] - lt) > cMaxOverlappingZones)
    111                 || (currentZone > layoutZone && Math.abs(zoneLimits[layoutZone] - lt) > cMaxOverlappingZones)) {
    112                     JOptionPane.showMessageDialog(Main.parent,
    113                     tr("IMPORTANT : data positioned far away from\n"
    114                     + "the current Lambert zone limits.\n"
    115                     + "Do not upload any data after this message.\n"
    116                     + "Undo your last action, save your work\n"
    117                     + "and start a new layer on the new zone."));
     110                        || (currentZone > layoutZone && Math.abs(zoneLimits[layoutZone] - lt) > cMaxOverlappingZones)) {
     111                    OptionPaneUtil.showMessageDialog(Main.parent,
     112                            tr("IMPORTANT : data positioned far away from\n"
     113                                    + "the current Lambert zone limits.\n"
     114                                    + "Do not upload any data after this message.\n"
     115                                    + "Undo your last action, save your work\n"
     116                                    + "and start a new layer on the new zone."),
     117                                    tr("Warning"),
     118                                    JOptionPane.WARNING_MESSAGE);
    118119                    layoutZone = -1;
    119120                } else {
     
    130131    public LatLon eastNorth2latlon(EastNorth p) {
    131132        LatLon geo;
    132         if (layoutZone == -1)
     133        if (layoutZone == -1) {
    133134            // possible until the Lambert zone is determined by latlon2eastNorth() with a valid LatLon
    134135            geo = Geographic(p, Xs[currentZone], Ys[currentZone], c[currentZone], n[currentZone]);
    135         else
     136        } else {
    136137            geo = Geographic(p, Xs[layoutZone], Ys[layoutZone], c[layoutZone], n[layoutZone]);
     138        }
    137139        // translate ellipsoid Clark => GRS80 (WGS83)
    138140        LatLon wgs = Clark2GRS80(geo);
     
    197199            double eslt = Ellipsoid.clarke.e * Math.sin(lat);
    198200            double nlt = 2.0 * Math.atan(Math.pow((1.0 + eslt) / (1.0 - eslt), Ellipsoid.clarke.e / 2.0) * l) - Math.PI
    199                     / 2.0;
     201            / 2.0;
    200202            delta = Math.abs(nlt - lat);
    201203            lat = nlt;
     
    261263            s2 *= s2;
    262264            double l = Math.atan((Z / norm)
    263                 / (1.0 - (ell.a * ell.e2 * Math.cos(lt) / (norm * Math.sqrt(1.0 - ell.e2 * s2)))));
     265                    / (1.0 - (ell.a * ell.e2 * Math.cos(lt) / (norm * Math.sqrt(1.0 - ell.e2 * s2)))));
    264266            delta = Math.abs(l - lt);
    265267            lt = l;
Note: See TracChangeset for help on using the changeset viewer.