Changeset 74 in josm for src/org/openstreetmap
- Timestamp:
- 2006-03-28T23:37:37+02:00 (19 years ago)
- Location:
- src/org/openstreetmap/josm
- Files:
-
- 1 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/Main.java
r73 r74 9 9 import java.awt.event.WindowEvent; 10 10 import java.io.File; 11 import java.io.IOException; 11 12 import java.util.Arrays; 12 13 import java.util.Iterator; … … 33 34 import org.openstreetmap.josm.actions.UploadAction; 34 35 import org.openstreetmap.josm.data.Preferences; 35 import org.openstreetmap.josm.data.Preferences.PreferencesException;36 36 import org.openstreetmap.josm.data.osm.DataSet; 37 37 import org.openstreetmap.josm.data.projection.Projection; … … 186 186 }); 187 187 setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); 188 189 proj = pref.getProjection();190 188 } 191 189 … … 219 217 String errMsg = null; 220 218 try { 221 if (arguments.remove("--reset-preferences")) 219 if (arguments.remove("--reset-preferences")) { 220 pref.resetToDefault(); 222 221 pref.save(); 223 else222 } else 224 223 pref.load(); 225 } catch (PreferencesException e1) { 224 } catch (RuntimeException x) { 225 //TODO: Temporary code to update user preferences. 226 if (x.getMessage().equals("old version")) { 227 int answer = JOptionPane.showConfirmDialog( 228 null, 229 "The preferences - file format has changed.\nThe settings will be reset to default.", 230 "Information", 231 JOptionPane.OK_CANCEL_OPTION); 232 if (answer == JOptionPane.CANCEL_OPTION) 233 System.exit(0); 234 pref.resetToDefault(); 235 try { 236 pref.save(); 237 } catch (IOException e) { 238 e.printStackTrace(); 239 errMsg = "Preferences could not be loaded. Reverting to default."; 240 } 241 } 242 } catch (IOException e1) { 226 243 e1.printStackTrace(); 227 244 errMsg = "Preferences could not be loaded. Write default preference file to '"+Preferences.getPreferencesDir()+"preferences'."; 245 pref.resetToDefault(); 228 246 try { 229 247 pref.save(); 230 } catch ( PreferencesException e) {248 } catch (IOException e) { 231 249 e.printStackTrace(); 232 250 errMsg = "Preferences could not be loaded. Reverting to default."; … … 235 253 if (errMsg != null) 236 254 JOptionPane.showMessageDialog(null, errMsg); 237 255 238 256 try { 239 UIManager.setLookAndFeel(pref.laf.getClassName()); 257 proj = (Projection)Class.forName(pref.get("projection")).newInstance(); 258 } catch (Exception e) { 259 e.printStackTrace(); 260 JOptionPane.showMessageDialog(null, "The projection could not be initialized. Aborting."); 261 System.exit(1); 262 } 263 264 try { 265 UIManager.setLookAndFeel(pref.get("laf")); 240 266 } catch (Exception e) { 241 267 e.printStackTrace(); -
src/org/openstreetmap/josm/actions/DownloadAction.java
r73 r74 31 31 import org.openstreetmap.josm.Main; 32 32 import org.openstreetmap.josm.data.Bounds; 33 import org.openstreetmap.josm.data.Preferences.PreferencesException;34 33 import org.openstreetmap.josm.data.coor.LatLon; 35 34 import org.openstreetmap.josm.data.osm.DataSet; … … 78 77 public void actionPerformed(ActionEvent e) { 79 78 79 String osmDataServer = Main.pref.get("osmDataServer"); 80 80 //TODO: Remove this in later versions (temporary only) 81 if ( Main.pref.osmDataServer.endsWith("/0.2") || Main.pref.osmDataServer.endsWith("/0.2/")) {81 if (osmDataServer.endsWith("/0.2") || osmDataServer.endsWith("/0.2/")) { 82 82 int answer = JOptionPane.showConfirmDialog(Main.main, 83 83 "You seem to have an outdated server entry in your preferences.\n" + … … 89 89 if (answer != JOptionPane.YES_OPTION) 90 90 return; 91 int cutPos = Main.pref.osmDataServer.endsWith("/0.2") ? 4 : 5;92 Main.pref. osmDataServer = Main.pref.osmDataServer.substring(0, Main.pref.osmDataServer.length()-cutPos);91 int cutPos = osmDataServer.endsWith("/0.2") ? 4 : 5; 92 Main.pref.put("osmDataServer", osmDataServer.substring(0, osmDataServer.length()-cutPos)); 93 93 try { 94 94 Main.pref.save(); 95 } catch ( PreferencesException x) {95 } catch (IOException x) { 96 96 x.printStackTrace(); 97 JOptionPane.showMessageDialog(Main.main, "Could not save the preferences chane:\n" + 98 x.getMessage()); 97 JOptionPane.showMessageDialog(Main.main, "Could not save the preferences change:\n" + x.getMessage()); 99 98 } 100 99 } -
src/org/openstreetmap/josm/actions/UploadAction.java
r71 r74 5 5 import java.awt.event.InputEvent; 6 6 import java.awt.event.KeyEvent; 7 import java.io.IOException; 7 8 import java.util.Collection; 8 9 import java.util.LinkedList; … … 17 18 import org.jdom.JDOMException; 18 19 import org.openstreetmap.josm.Main; 19 import org.openstreetmap.josm.data.Preferences.PreferencesException;20 20 import org.openstreetmap.josm.data.osm.OsmPrimitive; 21 21 import org.openstreetmap.josm.gui.OsmPrimitivRenderer; … … 40 40 public void actionPerformed(ActionEvent e) { 41 41 42 String osmDataServer = Main.pref.get("osmDataServer"); 42 43 //TODO: Remove this in later versions (temporary only) 43 if ( Main.pref.osmDataServer.endsWith("/0.2") || Main.pref.osmDataServer.endsWith("/0.2/")) {44 if (osmDataServer.endsWith("/0.2") || osmDataServer.endsWith("/0.2/")) { 44 45 int answer = JOptionPane.showConfirmDialog(Main.main, 45 46 "You seem to have an outdated server entry in your preferences.\n" + … … 51 52 if (answer != JOptionPane.YES_OPTION) 52 53 return; 53 int cutPos = Main.pref.osmDataServer.endsWith("/0.2") ? 4 : 5;54 Main.pref. osmDataServer = Main.pref.osmDataServer.substring(0, Main.pref.osmDataServer.length()-cutPos);54 int cutPos = osmDataServer.endsWith("/0.2") ? 4 : 5; 55 Main.pref.put("osmDataServer", osmDataServer.substring(0, osmDataServer.length()-cutPos)); 55 56 try { 56 57 Main.pref.save(); 57 } catch ( PreferencesException x) {58 } catch (IOException x) { 58 59 x.printStackTrace(); 59 JOptionPane.showMessageDialog(Main.main, "Could not save the preferences chane:\n" + 60 x.getMessage()); 60 JOptionPane.showMessageDialog(Main.main, "Could not save the preferences change:\n" + x.getMessage()); 61 61 } 62 62 } -
src/org/openstreetmap/josm/data/projection/Projection.java
r71 r74 15 15 public static double MAX_LON = 180; 16 16 public static final double MAX_SERVER_PRECISION = 1e12; 17 18 /** 19 * List of all available Projections. 20 */ 21 public static final Projection[] allProjections = new Projection[]{ 22 new Epsg4263(), 23 new Mercator() 24 }; 17 25 18 26 /** -
src/org/openstreetmap/josm/gui/MapView.java
r73 r74 6 6 import java.awt.event.ComponentAdapter; 7 7 import java.awt.event.ComponentEvent; 8 import java.beans.PropertyChangeEvent;9 import java.beans.PropertyChangeListener;10 8 import java.util.ArrayList; 11 9 import java.util.Collection; … … 40 38 * @author imi 41 39 */ 42 public class MapView extends NavigatableComponent implements ChangeListener , PropertyChangeListener{40 public class MapView extends NavigatableComponent implements ChangeListener { 43 41 44 42 /** … … 85 83 } 86 84 }); 87 88 // initialize the movement listener89 85 new MapMover(this); 90 91 // initialize the projection92 86 addLayer(layer); 93 Main.pref.addPropertyChangeListener(this);94 87 } 95 88 … … 340 333 recalculateCenterScale(); 341 334 } 342 343 /**344 * Change to the new projection. Recalculate the dataset and zoom, if autoZoom345 * is active.346 * @param oldProjection The old projection. Unregister from this.347 * @param newProjection The new projection. Register as state change listener.348 */349 public void propertyChange(PropertyChangeEvent evt) {350 if (evt.getPropertyName().equals("projection"))351 stateChanged(new ChangeEvent(this));352 }353 335 } -
src/org/openstreetmap/josm/gui/PreferenceDialog.java
r73 r74 7 7 import java.awt.event.ActionEvent; 8 8 import java.awt.event.ActionListener; 9 import java.io.IOException; 9 10 10 11 import javax.swing.AbstractAction; … … 28 29 29 30 import org.openstreetmap.josm.Main; 30 import org.openstreetmap.josm.data.Preferences;31 import org.openstreetmap.josm.data.Preferences.PreferencesException;32 31 import org.openstreetmap.josm.data.projection.Projection; 33 32 import org.openstreetmap.josm.tools.GBC; … … 51 50 } 52 51 public void actionPerformed(ActionEvent e) { 53 Main.pref.laf = (LookAndFeelInfo)lafCombo.getSelectedItem(); 54 Main.pref.setProjection((Projection)projectionCombo.getSelectedItem()); 55 Main.pref.osmDataServer = osmDataServer.getText(); 56 Main.pref.osmDataUsername = osmDataUsername.getText(); 57 Main.pref.osmDataPassword = String.valueOf(osmDataPassword.getPassword()); 58 if (Main.pref.osmDataPassword == "") 59 Main.pref.osmDataPassword = null; 60 Main.pref.csvImportString = csvImportString.getText(); 61 Main.pref.setDrawRawGpsLines(drawRawGpsLines.isSelected()); 62 Main.pref.setForceRawGpsLines(forceRawGpsLines.isSelected()); 52 Main.pref.put("laf", ((LookAndFeelInfo)lafCombo.getSelectedItem()).getClassName()); 53 Main.pref.put("projection", projectionCombo.getSelectedItem().getClass().getName()); 54 Main.pref.put("osmDataServer", osmDataServer.getText()); 55 Main.pref.put("osmDataUsername", osmDataUsername.getText()); 56 String pwd = String.valueOf(osmDataPassword.getPassword()); 57 if (pwd.equals("")) 58 pwd = null; 59 Main.pref.put("osmDataPassword", pwd); 60 Main.pref.put("csvImportString", csvImportString.getText()); 61 Main.pref.put("drawRawGpsLines", drawRawGpsLines.isSelected()); 62 Main.pref.put("forceRawGpsLines", forceRawGpsLines.isSelected()); 63 63 try { 64 64 Main.pref.save(); 65 } catch ( PreferencesException x) {65 } catch (IOException x) { 66 66 x.printStackTrace(); 67 67 JOptionPane.showMessageDialog(PreferenceDialog.this, "Could not save preferences:\n"+x.getMessage()); … … 98 98 * Combobox with all projections available 99 99 */ 100 JComboBox projectionCombo = new JComboBox(Pr eferences.allProjections);100 JComboBox projectionCombo = new JComboBox(Projection.allProjections); 101 101 /** 102 102 * The main tab panel. … … 140 140 141 141 // look and feel combo box 142 lafCombo.setSelectedItem(Main.pref.get("laf")); 142 143 final ListCellRenderer oldRenderer = lafCombo.getRenderer(); 143 144 lafCombo.setRenderer(new DefaultListCellRenderer(){ 144 @Override 145 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { 145 @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { 146 146 return oldRenderer.getListCellRendererComponent(list, ((LookAndFeelInfo)value).getName(), index, isSelected, cellHasFocus); 147 } });148 lafCombo.setSelectedItem(Main.pref.laf);147 } 148 }); 149 149 lafCombo.addActionListener(new ActionListener(){ 150 150 public void actionPerformed(ActionEvent e) { 151 151 requiresRestart = true; 152 }}); 152 } 153 }); 153 154 154 155 // projection combo box 155 156 for (int i = 0; i < projectionCombo.getItemCount(); ++i) { 156 if (projectionCombo.getItemAt(i). getClass().equals(Main.pref.getProjection().getClass())) {157 if (projectionCombo.getItemAt(i).toString().equals(Main.pref.get("projection"))) { 157 158 projectionCombo.setSelectedIndex(i); 158 159 break; … … 185 186 "Other example: \"lat,lon\" will just read lat/lon values comma seperated.</html>"); 186 187 drawRawGpsLines.setToolTipText("If your gps device draw to few lines, select this to draw lines along your way."); 187 drawRawGpsLines.setSelected(Main.pref. isDrawRawGpsLines());188 drawRawGpsLines.setSelected(Main.pref.getBoolean("drawRawGpsLines")); 188 189 forceRawGpsLines.setToolTipText("Force drawing of lines if the imported data contain no line information."); 189 forceRawGpsLines.setSelected(Main.pref. isForceRawGpsLines());190 forceRawGpsLines.setSelected(Main.pref.getBoolean("forceRawGpsLines")); 190 191 forceRawGpsLines.setEnabled(drawRawGpsLines.isSelected()); 191 192 192 osmDataServer.setText(Main.pref. osmDataServer);193 osmDataUsername.setText(Main.pref. osmDataUsername);194 osmDataPassword.setText(Main.pref. osmDataPassword);195 csvImportString.setText(Main.pref. csvImportString);193 osmDataServer.setText(Main.pref.get("osmDataServer")); 194 osmDataUsername.setText(Main.pref.get("osmDataUsername")); 195 osmDataPassword.setText(Main.pref.get("osmDataPassword")); 196 csvImportString.setText(Main.pref.get("csvImportString")); 196 197 197 198 // Display tab -
src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r71 r74 2 2 3 3 import java.awt.Graphics; 4 import java.beans.PropertyChangeEvent;5 import java.beans.PropertyChangeListener;6 4 import java.util.Collection; 7 5 import java.util.HashSet; … … 81 79 this.data = data; 82 80 this.fromDisk = fromDisk; 83 Main.pref.addPropertyChangeListener(new PropertyChangeListener() {84 public void propertyChange(PropertyChangeEvent evt) {85 if (evt.getPropertyName().equals("projection"))86 for (Node n : OsmDataLayer.this.data.nodes)87 ((Projection)evt.getNewValue()).latlon2eastNorth(n.coor);88 }89 });90 81 } 91 82 -
src/org/openstreetmap/josm/gui/layer/RawGpsDataLayer.java
r73 r74 4 4 import java.awt.Graphics; 5 5 import java.awt.Point; 6 import java.beans.PropertyChangeEvent;7 import java.beans.PropertyChangeListener;8 6 import java.util.Collection; 9 7 import java.util.LinkedList; … … 12 10 13 11 import org.openstreetmap.josm.Main; 12 import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener; 13 import org.openstreetmap.josm.data.coor.EastNorth; 14 14 import org.openstreetmap.josm.data.coor.LatLon; 15 import org.openstreetmap.josm.data.coor.EastNorth;16 15 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 17 16 import org.openstreetmap.josm.data.projection.Projection; … … 39 38 this.data = data; 40 39 41 Main.pref.addPr opertyChangeListener(new PropertyChangeListener(){42 public void pr opertyChange(PropertyChangeEvent evt) {40 Main.pref.addPreferenceChangedListener(new PreferenceChangedListener(){ 41 public void preferenceChanged(String key, String newValue) { 43 42 if (Main.main.getMapFrame() == null) { 44 Main.pref.removePr opertyChangeListener(this);43 Main.pref.removePreferenceChangedListener(this); 45 44 return; 46 45 } 47 if (evt.getPropertyName().equals("drawRawGpsLines") || 48 evt.getPropertyName().equals("forceRawGpsLines")) 46 if (key.equals("drawRawGpsLines") || key.equals("forceRawGpsLines")) 49 47 Main.main.getMapFrame().repaint(); 50 48 } … … 67 65 Point old = null; 68 66 for (Collection<EastNorth> c : eastNorth) { 69 if (!Main.pref. isForceRawGpsLines())67 if (!Main.pref.getBoolean("forceRawGpsLines")) 70 68 old = null; 71 69 for (EastNorth eastNorth : c) { 72 70 Point screen = mv.getPoint(eastNorth); 73 if (Main.pref. isDrawRawGpsLines() && old != null)71 if (Main.pref.getBoolean("drawRawGpsLines") && old != null) 74 72 g.drawLine(old.x, old.y, screen.x, screen.y); 75 73 else -
src/org/openstreetmap/josm/io/OsmConnection.java
r71 r74 39 39 @Override 40 40 protected PasswordAuthentication getPasswordAuthentication() { 41 String username = Main.pref. osmDataUsername;42 String password = Main.pref. osmDataPassword;43 if (passwordtried || "".equals(username) || password == null || "".equals(password)) {41 String username = Main.pref.get("osmDataUsername"); 42 String password = Main.pref.get("osmDataPassword"); 43 if (passwordtried || username.equals("") || password.equals("")) { 44 44 JPanel p = new JPanel(new GridBagLayout()); 45 45 p.add(new JLabel("Username"), GBC.std().insets(0,0,10,0)); 46 JTextField usernameField = new JTextField( "".equals(username) ? "" :username, 20);46 JTextField usernameField = new JTextField(username, 20); 47 47 p.add(usernameField, GBC.eol()); 48 48 p.add(new JLabel("Password"), GBC.std().insets(0,0,10,0)); 49 JPasswordField passwordField = new JPasswordField(password == null ? "" : password, 20);49 JPasswordField passwordField = new JPasswordField(password, 20); 50 50 p.add(passwordField, GBC.eol()); 51 51 JLabel warning = new JLabel("Warning: The password is transferred unencrypted."); … … 59 59 username = usernameField.getText(); 60 60 password = String.valueOf(passwordField.getPassword()); 61 if ( "".equals(username))61 if (username.equals("")) 62 62 return null; 63 63 } -
src/org/openstreetmap/josm/io/OsmServerReader.java
r73 r74 48 48 */ 49 49 public Collection<Collection<LatLon>> parseRawGps() throws IOException, JDOMException { 50 String url = Main.pref. osmDataServer+"/0.3/trackpoints?bbox="+lon1+","+lat1+","+lon2+","+lat2+"&page=";50 String url = Main.pref.get("osmDataServer")+"/0.3/trackpoints?bbox="+lon1+","+lat1+","+lon2+","+lat2+"&page="; 51 51 Collection<Collection<LatLon>> data = new LinkedList<Collection<LatLon>>(); 52 52 Collection<LatLon> list = new LinkedList<LatLon>(); … … 80 80 */ 81 81 public DataSet parseOsm() throws SAXException, IOException { 82 Reader r = getReader(Main.pref. osmDataServer+"/0.3/map?bbox="+lon1+","+lat1+","+lon2+","+lat2);82 Reader r = getReader(Main.pref.get("osmDataServer")+"/0.3/map?bbox="+lon1+","+lat1+","+lon2+","+lat2); 83 83 if (r == null) 84 84 return null; -
src/org/openstreetmap/josm/io/OsmServerWriter.java
r66 r74 136 136 OsmPrimitive osm, boolean addBody) { 137 137 try { 138 URL url = new URL(Main.pref. osmDataServer+ "/0.3/" + urlSuffix + "/" + osm.id);138 URL url = new URL(Main.pref.get("osmDataServer") + "/0.3/" + urlSuffix + "/" + osm.id); 139 139 System.out.println("upload to: "+url); 140 140 HttpURLConnection con = (HttpURLConnection) url.openConnection(); -
src/org/openstreetmap/josm/io/RawCsvReader.java
r71 r74 30 30 public Collection<LatLon> parse() throws JDOMException, IOException { 31 31 Collection<LatLon> data = new LinkedList<LatLon>(); 32 String formatStr = Main.pref. csvImportString;32 String formatStr = Main.pref.get("csvImportString"); 33 33 if (formatStr == null) 34 34 formatStr = in.readLine(); … … 52 52 // test for completness 53 53 if (!format.contains("lat") || !format.contains("lon")) { 54 if (Main.pref. csvImportString != null)55 throw new JDOMException("Format string i s incomplete. Need at least 'lat' and 'lon' specification");56 throw new JDOMException("Format string i n data is incomplete or not found. Try setting an manual format string in Preferences.");54 if (Main.pref.get("csvImportString").equals("")) 55 throw new JDOMException("Format string in data is incomplete or not found. Try setting an manual format string in Preferences."); 56 throw new JDOMException("Format string is incomplete. Need at least 'lat' and 'lon' specification"); 57 57 } 58 58 … … 71 71 st.nextToken(); 72 72 else 73 throw new JDOMException("Unknown data type: '"+token+"'."+(Main.pref. csvImportString == null? " Maybe add an format string in preferences." : ""));73 throw new JDOMException("Unknown data type: '"+token+"'."+(Main.pref.get("csvImportString").equals("") ? " Maybe add an format string in preferences." : "")); 74 74 } 75 75 data.add(new LatLon(lat, lon)); -
src/org/openstreetmap/josm/tools/XmlWriter.java
r72 r74 31 31 * @return The standard XML1.0 header. Encoding is utf-8 32 32 */ 33 public static Objectheader() {33 public static String header() { 34 34 return "<?xml version='1.0' encoding='UTF-8'?>"; 35 35 }
Note:
See TracChangeset
for help on using the changeset viewer.