- Timestamp:
- 2006-03-31T21:35:26+02:00 (19 years ago)
- Location:
- src/org/openstreetmap/josm
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/Main.java
r76 r77 227 227 if (arguments.remove("--reset-preferences")) { 228 228 pref.resetToDefault(); 229 pref.save();230 229 } else 231 230 pref.load(); … … 234 233 errMsg = "Preferences could not be loaded. Write default preference file to '"+Preferences.getPreferencesDir()+"preferences'."; 235 234 pref.resetToDefault(); 236 try {237 pref.save();238 } catch (IOException e) {239 e.printStackTrace();240 errMsg = "Preferences could not be loaded. Reverting to default.";241 }242 235 } 243 236 if (errMsg != null) -
src/org/openstreetmap/josm/actions/DownloadAction.java
r75 r77 89 89 int cutPos = osmDataServer.endsWith("/0.2") ? 4 : 5; 90 90 Main.pref.put("osm-server.url", osmDataServer.substring(0, osmDataServer.length()-cutPos)); 91 try {92 Main.pref.save();93 } catch (IOException x) {94 x.printStackTrace();95 JOptionPane.showMessageDialog(Main.main, "Could not save the preferences change:\n" + x.getMessage());96 }97 91 } 98 92 -
src/org/openstreetmap/josm/actions/UploadAction.java
r75 r77 5 5 import java.awt.event.InputEvent; 6 6 import java.awt.event.KeyEvent; 7 import java.io.IOException;8 7 import java.util.Collection; 9 8 import java.util.LinkedList; … … 54 53 int cutPos = osmDataServer.endsWith("/0.2") ? 4 : 5; 55 54 Main.pref.put("osm-server.url", osmDataServer.substring(0, osmDataServer.length()-cutPos)); 56 try {57 Main.pref.save();58 } catch (IOException x) {59 x.printStackTrace();60 JOptionPane.showMessageDialog(Main.main, "Could not save the preferences change:\n" + x.getMessage());61 }62 55 } 63 56 -
src/org/openstreetmap/josm/data/Preferences.java
r75 r77 8 8 import java.io.PrintWriter; 9 9 import java.util.ArrayList; 10 import java.util.Collection; 11 import java.util.LinkedList; 10 import java.util.Map; 12 11 import java.util.SortedMap; 13 12 import java.util.TreeMap; … … 66 65 return prop; 67 66 } 68 synchronized public Collection<Entry<String, String>> getAllPrefix(String prefix) {69 LinkedList<Entry<String,String>> all = new LinkedList<Entry<String,String>>();67 synchronized public Map<String, String> getAllPrefix(String prefix) { 68 Map<String,String> all = new TreeMap<String,String>(); 70 69 for (Entry<String,String> e : properties.entrySet()) 71 70 if (e.getKey().startsWith(prefix)) 72 all. add(e);71 all.put(e.getKey(), e.getValue()); 73 72 return all; 74 73 } … … 80 79 synchronized public void put(String key, String value) { 81 80 if (value == null) 82 value = ""; 83 properties.put(key, value); 81 properties.remove(key); 82 else 83 properties.put(key, value); 84 save(); 84 85 firePreferenceChanged(key, value); 85 86 } 86 87 synchronized public void put(String key, boolean value) { 87 88 properties.put(key, Boolean.toString(value)); 89 save(); 88 90 firePreferenceChanged(key, Boolean.toString(value)); 89 91 } … … 95 97 96 98 97 public void save() throws IOException { 98 PrintWriter out = new PrintWriter(new FileWriter(getPreferencesDir()+"preferences")); 99 for (Entry<String, String> e : properties.entrySet()) 100 if (!e.getValue().equals("")) 101 out.println(e.getKey()+"="+e.getValue()); 102 out.close(); 99 /** 100 * Called after every put. In case of a problem, do nothing but output the error 101 * in log. 102 */ 103 private void save() { 104 try { 105 PrintWriter out = new PrintWriter(new FileWriter( 106 getPreferencesDir() + "preferences")); 107 for (Entry<String, String> e : properties.entrySet()) 108 if (!e.getValue().equals("")) 109 out.println(e.getKey() + "=" + e.getValue()); 110 out.close(); 111 } catch (IOException e) { 112 e.printStackTrace(); 113 // do not message anything, since this can be called from strange 114 // places. 115 } 103 116 } 104 117 … … 127 140 properties.put("color.selected", ColorHelper.color2html(Color.white)); 128 141 properties.put("color.gps point", ColorHelper.color2html(Color.gray)); 142 save(); 129 143 } 130 144 } -
src/org/openstreetmap/josm/gui/MapView.java
r74 r77 11 11 import java.util.LinkedList; 12 12 13 import javax.swing.event.ChangeEvent;14 import javax.swing.event.ChangeListener;15 16 13 import org.openstreetmap.josm.Main; 17 14 import org.openstreetmap.josm.data.Bounds; … … 20 17 import org.openstreetmap.josm.data.osm.DataSet; 21 18 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 22 import org.openstreetmap.josm.data.projection.Projection;23 19 import org.openstreetmap.josm.gui.layer.Layer; 24 20 import org.openstreetmap.josm.gui.layer.OsmDataLayer; … … 38 34 * @author imi 39 35 */ 40 public class MapView extends NavigatableComponent implements ChangeListener{36 public class MapView extends NavigatableComponent { 41 37 42 38 /** … … 92 88 */ 93 89 public void addLayer(Layer layer) { 94 // reinitialize layer's data95 layer.init(getProjection());96 97 90 if (layer instanceof OsmDataLayer) { 98 91 final OsmDataLayer dataLayer = (OsmDataLayer)layer; … … 322 315 firePropertyChange("scale", oldScale, scale); 323 316 } 324 325 /**326 * Notify from the projection, that something has changed.327 */328 public void stateChanged(ChangeEvent e) {329 // reset all datasets.330 Projection p = getProjection();331 for (Layer l : layers)332 l.init(p);333 recalculateCenterScale();334 }335 317 } -
src/org/openstreetmap/josm/gui/PreferenceDialog.java
r75 r77 8 8 import java.awt.event.ActionEvent; 9 9 import java.awt.event.ActionListener; 10 import java. io.IOException;11 import java.util. Collection;10 import java.util.Map; 11 import java.util.TreeMap; 12 12 import java.util.Vector; 13 13 import java.util.Map.Entry; … … 78 78 } 79 79 80 try {81 Main.pref.save();82 } catch (IOException x) {83 x.printStackTrace();84 JOptionPane.showMessageDialog(PreferenceDialog.this, "Could not save preferences:\n"+x.getMessage());85 }86 80 if (requiresRestart) 87 81 JOptionPane.showMessageDialog(PreferenceDialog.this, "You have to restart JOSM for some settings to take effect."); … … 212 206 213 207 214 Collection<Entry<String,String>> c = Main.pref.getAllPrefix("color."); 208 209 Map<String,String> allColors = new TreeMap<String, String>(Main.pref.getAllPrefix("color.")); 210 215 211 Vector<Vector<Object>> rows = new Vector<Vector<Object>>(); 216 for (Entry<String,String> e : c) {212 for (Entry<String,String> e : allColors.entrySet()) { 217 213 Vector<Object> row = new Vector<Object>(2); 218 214 row.add(e.getKey().substring("color.".length())); … … 229 225 }; 230 226 colors.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 227 final TableCellRenderer oldColorsRenderer = colors.getDefaultRenderer(Object.class); 228 colors.setDefaultRenderer(Object.class, new TableCellRenderer(){ 229 public Component getTableCellRendererComponent(JTable t, Object o, boolean selected, boolean focus, int row, int column) { 230 if (column == 1) { 231 JLabel l = new JLabel(ColorHelper.color2html((Color)o)); 232 l.setBackground((Color)o); 233 l.setOpaque(true); 234 return l; 235 } 236 return oldColorsRenderer.getTableCellRendererComponent(t,o,selected,focus,row,column); 237 } 238 }); 239 colors.getColumnModel().getColumn(1).setWidth(100); 240 231 241 JButton colorEdit = new JButton("Choose"); 232 242 colorEdit.addActionListener(new ActionListener(){ … … 243 253 } 244 254 }); 245 final TableCellRenderer oldColorsRenderer = colors.getDefaultRenderer(Object.class);246 colors.setDefaultRenderer(Object.class, new TableCellRenderer(){247 public Component getTableCellRendererComponent(JTable t, Object o, boolean selected, boolean focus, int row, int column) {248 if (column == 1) {249 JLabel l = new JLabel(ColorHelper.color2html((Color)o));250 l.setBackground((Color)o);251 l.setOpaque(true);252 return l;253 }254 return oldColorsRenderer.getTableCellRendererComponent(t,o,selected,focus,row,column);255 }256 });257 colors.getColumnModel().getColumn(1).setWidth(100);258 255 259 256 // setting tooltips -
src/org/openstreetmap/josm/gui/dialogs/LayerList.java
r75 r77 2 2 3 3 import java.awt.BorderLayout; 4 import java.awt.Color; 4 5 import java.awt.Component; 5 6 import java.awt.Dimension; … … 8 9 import java.awt.event.ActionListener; 9 10 import java.awt.event.KeyEvent; 11 import java.awt.event.MouseAdapter; 12 import java.awt.event.MouseEvent; 10 13 import java.util.Collection; 11 14 … … 14 17 import javax.swing.Icon; 15 18 import javax.swing.JButton; 19 import javax.swing.JColorChooser; 16 20 import javax.swing.JLabel; 17 21 import javax.swing.JList; 22 import javax.swing.JMenuItem; 23 import javax.swing.JOptionPane; 18 24 import javax.swing.JPanel; 25 import javax.swing.JPopupMenu; 19 26 import javax.swing.JScrollPane; 20 27 import javax.swing.ListSelectionModel; … … 29 36 import org.openstreetmap.josm.gui.MapView.LayerChangeListener; 30 37 import org.openstreetmap.josm.gui.layer.Layer; 38 import org.openstreetmap.josm.gui.layer.RawGpsDataLayer; 39 import org.openstreetmap.josm.tools.ColorHelper; 31 40 import org.openstreetmap.josm.tools.ImageProvider; 32 41 import org.openstreetmap.josm.tools.ImageProvider.OverlayPosition; … … 111 120 mapView.addLayerChangeListener(this); 112 121 122 layers.addMouseListener(new MouseAdapter(){ 123 private void openPopup(MouseEvent e) { 124 final int index = layers.locationToIndex(e.getPoint()); 125 final Layer layer = (Layer)layers.getModel().getElementAt(index); 126 if (!(layer instanceof RawGpsDataLayer)) 127 return; // currently only options for raw layers. 128 JPopupMenu menu = new JPopupMenu(); 129 JMenuItem color = new JMenuItem("Customize Color"); 130 color.addActionListener(new ActionListener(){ 131 public void actionPerformed(ActionEvent e) { 132 String col = Main.pref.get("color.layer "+layer.name, Main.pref.get("color.gps point", ColorHelper.color2html(Color.gray))); 133 JColorChooser c = new JColorChooser(ColorHelper.html2color(col)); 134 Object[] options = new Object[]{"OK", "Cancel", "Default"}; 135 int answer = JOptionPane.showOptionDialog(Main.main, c, "Choose a color", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]); 136 switch (answer) { 137 case 0: 138 Main.pref.put("color.layer "+layer.name, ColorHelper.color2html(c.getColor())); 139 break; 140 case 1: 141 return; 142 case 2: 143 Main.pref.put("color.layer "+layer.name, null); 144 break; 145 } 146 Main.main.repaint(); 147 } 148 }); 149 menu.add(color); 150 menu.show(LayerList.this, e.getX(), e.getY()); 151 } 152 @Override public void mousePressed(MouseEvent e) { 153 if (e.isPopupTrigger()) 154 openPopup(e); 155 } 156 @Override public void mouseReleased(MouseEvent e) { 157 if (e.isPopupTrigger()) 158 openPopup(e); 159 } 160 }); 161 162 113 163 // Buttons 114 164 JPanel buttonPanel = new JPanel(new GridLayout(1, 5)); … … 222 272 updateButtonEnabled(); 223 273 } 274 275 public void layerMoved(Layer layer, int newPosition) {} 224 276 } -
src/org/openstreetmap/josm/gui/layer/Layer.java
r71 r77 6 6 7 7 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 8 import org.openstreetmap.josm.data.projection.Projection;9 8 import org.openstreetmap.josm.gui.MapView; 10 9 … … 79 78 */ 80 79 abstract public void visitBoundingBox(BoundingXYVisitor v); 81 82 /**83 * Initialize the internal dataset with the given projection.84 */85 abstract public void init(Projection projection);86 80 } -
src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r74 r77 21 21 import org.openstreetmap.josm.data.osm.visitor.MergeVisitor; 22 22 import org.openstreetmap.josm.data.osm.visitor.SimplePaintVisitor; 23 import org.openstreetmap.josm.data.projection.Projection;24 23 import org.openstreetmap.josm.gui.MapView; 25 24 import org.openstreetmap.josm.tools.ImageProvider; … … 138 137 for (Node n : data.nodes) 139 138 v.visit(n); 140 }141 142 @Override143 public void init(Projection projection) {144 for (Node n : data.nodes)145 projection.latlon2eastNorth(n.coor);146 139 } 147 140 -
src/org/openstreetmap/josm/gui/layer/RawGpsDataLayer.java
r75 r77 14 14 import org.openstreetmap.josm.data.coor.LatLon; 15 15 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 16 import org.openstreetmap.josm.data.projection.Projection;17 16 import org.openstreetmap.josm.gui.MapView; 18 17 import org.openstreetmap.josm.tools.ColorHelper; … … 28 27 29 28 private static Icon icon; 30 29 31 30 /** 32 31 * A list of ways which containing a list of points. … … 38 37 super(name); 39 38 this.data = data; 40 39 40 eastNorth = new LinkedList<Collection<EastNorth>>(); 41 for (Collection<LatLon> c : data) { 42 Collection<EastNorth> eastNorthList = new LinkedList<EastNorth>(); 43 for (LatLon ll : c) 44 eastNorthList.add(Main.proj.latlon2eastNorth(ll)); 45 this.eastNorth.add(eastNorthList); 46 } 47 41 48 Main.pref.addPreferenceChangedListener(new PreferenceChangedListener(){ 42 49 public void preferenceChanged(String key, String newValue) { 43 if (Main.main.getMapFrame() == null) { 44 Main.pref.removePreferenceChangedListener(this); 45 return; 46 } 47 if (key.equals("drawRawGpsLines") || key.equals("forceRawGpsLines")) 50 if (Main.main.getMapFrame() != null && (key.equals("drawRawGpsLines") || key.equals("forceRawGpsLines"))) 48 51 Main.main.getMapFrame().repaint(); 49 52 } … … 64 67 public void paint(Graphics g, MapView mv) { 65 68 String gpsCol = Main.pref.get("color.gps point"); 66 if (gpsCol.equals("")) 69 String gpsColSpecial = Main.pref.get("color.layer "+name); 70 if (!gpsColSpecial.equals("")) 71 g.setColor(ColorHelper.html2color(gpsColSpecial)); 72 else if (!gpsCol.equals("")) 73 g.setColor(ColorHelper.html2color(gpsCol)); 74 else 67 75 g.setColor(Color.GRAY); 68 else69 g.setColor(ColorHelper.html2color(gpsCol));70 76 Point old = null; 71 77 for (Collection<EastNorth> c : eastNorth) { … … 108 114 v.visit(eastNorth); 109 115 } 110 111 @Override112 public void init(Projection projection) {113 eastNorth = new LinkedList<Collection<EastNorth>>();114 for (Collection<LatLon> c : data) {115 Collection<EastNorth> eastNorthList = new LinkedList<EastNorth>();116 for (LatLon ll : c)117 eastNorthList.add(Main.proj.latlon2eastNorth(ll));118 this.eastNorth.add(eastNorthList);119 }120 }121 116 }
Note:
See TracChangeset
for help on using the changeset viewer.