Changeset 290 in josm
- Timestamp:
- 2007-07-18T23:12:56+02:00 (17 years ago)
- Files:
-
- 3 added
- 33 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/Main.java
r284 r290 173 173 public final void removeLayer(final Layer layer) { 174 174 map.mapView.removeLayer(layer); 175 if (layer instanceof OsmDataLayer) { 176 DataSet newDs = new DataSet(); 177 newDs.listeners.addAll(ds.listeners); 178 ds = newDs; 179 } 175 if (layer instanceof OsmDataLayer) 176 ds = new DataSet(); 180 177 if (map.mapView.getAllLayers().isEmpty()) 181 178 setMapFrame(null); … … 278 275 public final OsmDataLayer editLayer() { 279 276 if (map == null || map.mapView.editLayer == null) 280 addLayer(new OsmDataLayer(ds, tr("unnamed"), null));277 menu.newAction.actionPerformed(null); 281 278 return map.mapView.editLayer; 282 279 } -
src/org/openstreetmap/josm/actions/CombineWayAction.java
r283 r290 27 27 import org.openstreetmap.josm.command.SequenceCommand; 28 28 import org.openstreetmap.josm.data.SelectionChangedListener; 29 import org.openstreetmap.josm.data.osm.DataSet; 29 30 import org.openstreetmap.josm.data.osm.OsmPrimitive; 30 31 import org.openstreetmap.josm.data.osm.Way; … … 40 41 public CombineWayAction() { 41 42 super(tr("Combine Way"), "combineway", tr("Combine several ways into one."), KeyEvent.VK_C, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK, true); 42 Main.ds.listeners.add(this);43 DataSet.listeners.add(this); 43 44 } 44 45 -
src/org/openstreetmap/josm/actions/DiskAccessAction.java
r178 r290 9 9 10 10 import org.openstreetmap.josm.Main; 11 import org.openstreetmap.josm.data.osm.OsmPrimitive;12 11 13 12 /** … … 16 15 abstract public class DiskAccessAction extends JosmAction { 17 16 18 /**19 * Checks whether it is ok to launch a save (whether we have data,20 * there is no conflict etc...)21 * @return <code>true</code>, if it is save to save.22 */23 public boolean checkSaveConditions() {24 if (Main.map == null) {25 JOptionPane.showMessageDialog(Main.parent, tr("No document open so nothing to save."));26 return false;27 }28 if (isDataSetEmpty() && JOptionPane.NO_OPTION == JOptionPane.showConfirmDialog(Main.parent,tr("The document contains no data. Save anyway?"), tr("Empty document"), JOptionPane.YES_NO_OPTION))29 return false;30 if (!Main.map.conflictDialog.conflicts.isEmpty()) {31 int answer = JOptionPane.showConfirmDialog(Main.parent,32 tr("There are unresolved conflicts. Conflicts will not be saved and handled as if you rejected all. Continue?"),tr("Conflicts"), JOptionPane.YES_NO_OPTION);33 if (answer != JOptionPane.YES_OPTION)34 return false;35 }36 return true;37 }38 39 40 17 public DiskAccessAction(String name, String iconName, String tooltip, int shortCut, int modifiers) { 41 18 super(name, iconName, tooltip, shortCut, modifiers, true); 42 }43 44 45 /**46 * Check the data set if it would be empty on save. It is empty, if it contains47 * no objects (after all objects that are created and deleted without beeing48 * transfered to the server have been removed).49 *50 * @return <code>true</code>, if a save result in an empty data set.51 */52 protected boolean isDataSetEmpty() {53 for (OsmPrimitive osm : Main.ds.allNonDeletedPrimitives())54 if (!osm.deleted || osm.id > 0)55 return false;56 return true;57 19 } 58 20 … … 82 44 83 45 return fc; 84 }} 46 } 47 } -
src/org/openstreetmap/josm/actions/NewAction.java
r178 r290 8 8 9 9 import org.openstreetmap.josm.Main; 10 import org.openstreetmap.josm.data.osm.DataSet; 11 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 10 12 11 13 public class NewAction extends JosmAction { … … 16 18 17 19 public void actionPerformed(ActionEvent e) { 18 if (Main.breakBecauseUnsavedChanges()) 19 return; 20 if (Main.map != null) 21 Main.main.removeLayer(Main.main.editLayer()); 22 Main.main.editLayer(); // create new if empty 20 Main.main.addLayer(new OsmDataLayer(new DataSet(), tr("unnamed"), null)); 23 21 } 24 22 } -
src/org/openstreetmap/josm/actions/OpenAction.java
r286 r290 8 8 import java.io.File; 9 9 import java.io.FileInputStream; 10 import java.io.FileNotFoundException; 10 11 import java.io.FileReader; 11 12 import java.io.IOException; … … 57 58 */ 58 59 public void openFile(File file) { 59 String fn = file.getName();60 60 try { 61 if (asRawData(fn)) { 62 Collection<Collection<GpsPoint>> gpsData = null; 63 Collection<Marker> markerData = null; 64 if (ExtensionFileFilter.filters[ExtensionFileFilter.GPX].acceptName(fn)) { 65 RawGpsReader r = null; 66 // Check to see if we are opening a compressed file 67 if(file.getName().endsWith(".gpx.gz")) { 68 r = new RawGpsReader(new GZIPInputStream(new FileInputStream(file)), file.getAbsoluteFile().getParentFile()); 69 } else { 70 r = new RawGpsReader(new FileInputStream(file), file.getAbsoluteFile().getParentFile()); 71 } 72 gpsData = r.trackData; 73 markerData = r.markerData; 74 } else if (ExtensionFileFilter.filters[ExtensionFileFilter.CSV].acceptName(fn)) { 75 gpsData = new LinkedList<Collection<GpsPoint>>(); 76 gpsData.add(new RawCsvReader(new FileReader(file)).parse()); 77 } else 78 throw new IllegalStateException(); 79 if ((gpsData != null) && (!gpsData.isEmpty())) 80 Main.main.addLayer(new RawGpsLayer(gpsData, tr("Tracks from {0}", file.getName()), file)); 81 if ((markerData != null) && (!markerData.isEmpty())) 82 Main.main.addLayer(new MarkerLayer(markerData, tr ("Markers from {0}", file.getName()), file)); 83 84 } else { 85 DataSet dataSet; 86 if (ExtensionFileFilter.filters[ExtensionFileFilter.OSM].acceptName(fn)) { 87 dataSet = OsmReader.parseDataSet(new FileInputStream(file), null, Main.pleaseWaitDlg); 88 } else if (ExtensionFileFilter.filters[ExtensionFileFilter.CSV].acceptName(fn)) { 89 JOptionPane.showMessageDialog(Main.parent, fn+": "+tr("CSV Data import for non-GPS data is not implemented yet.")); 90 return; 91 } else { 92 JOptionPane.showMessageDialog(Main.parent, fn+": "+tr("Unknown file extension: {0}", fn.substring(file.getName().lastIndexOf('.')+1))); 93 return; 94 } 95 Main.main.addLayer(new OsmDataLayer(dataSet, file.getName(), file)); 96 } 61 if (asRawData(file.getName())) 62 openFileAsRawGps(file); 63 else 64 openAsData(file); 97 65 } catch (SAXException x) { 98 66 x.printStackTrace(); 99 JOptionPane.showMessageDialog(Main.parent, tr("Error while parsing {0}",f n)+": "+x.getMessage());67 JOptionPane.showMessageDialog(Main.parent, tr("Error while parsing {0}",file.getName())+": "+x.getMessage()); 100 68 } catch (IOException x) { 101 69 x.printStackTrace(); 102 JOptionPane.showMessageDialog(Main.parent, tr("Could not read \"{0}\"",f n)+"\n"+x.getMessage());70 JOptionPane.showMessageDialog(Main.parent, tr("Could not read \"{0}\"",file.getName())+"\n"+x.getMessage()); 103 71 } 104 72 } 73 74 private void openAsData(File file) throws SAXException, IOException, FileNotFoundException { 75 String fn = file.getName(); 76 if (ExtensionFileFilter.filters[ExtensionFileFilter.OSM].acceptName(fn)) { 77 DataSet dataSet = OsmReader.parseDataSet(new FileInputStream(file), null, Main.pleaseWaitDlg); 78 OsmDataLayer layer = new OsmDataLayer(dataSet, file.getName(), file); 79 Main.main.addLayer(layer); 80 } else if (ExtensionFileFilter.filters[ExtensionFileFilter.CSV].acceptName(fn)) 81 JOptionPane.showMessageDialog(Main.parent, fn+": "+tr("CSV Data import for non-GPS data is not implemented yet.")); 82 else 83 JOptionPane.showMessageDialog(Main.parent, fn+": "+tr("Unknown file extension: {0}", fn.substring(file.getName().lastIndexOf('.')+1))); 84 } 85 86 private void openFileAsRawGps(File file) throws SAXException, IOException, FileNotFoundException { 87 String fn = file.getName(); 88 Collection<Collection<GpsPoint>> gpsData = null; 89 Collection<Marker> markerData = null; 90 if (ExtensionFileFilter.filters[ExtensionFileFilter.GPX].acceptName(fn)) { 91 RawGpsReader r = null; 92 if (file.getName().endsWith(".gpx.gz")) 93 r = new RawGpsReader(new GZIPInputStream(new FileInputStream(file)), file.getAbsoluteFile().getParentFile()); 94 else 95 r = new RawGpsReader(new FileInputStream(file), file.getAbsoluteFile().getParentFile()); 96 gpsData = r.trackData; 97 markerData = r.markerData; 98 } else if (ExtensionFileFilter.filters[ExtensionFileFilter.CSV].acceptName(fn)) { 99 gpsData = new LinkedList<Collection<GpsPoint>>(); 100 gpsData.add(new RawCsvReader(new FileReader(file)).parse()); 101 } else 102 throw new IllegalStateException(); 103 if (gpsData != null && !gpsData.isEmpty()) 104 Main.main.addLayer(new RawGpsLayer(gpsData, tr("Tracks from {0}", file.getName()), file)); 105 if (markerData != null && !markerData.isEmpty()) 106 Main.main.addLayer(new MarkerLayer(markerData, tr ("Markers from {0}", file.getName()), file)); 107 } 105 108 106 109 /** -
src/org/openstreetmap/josm/actions/SaveAction.java
r283 r290 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 import java.awt.event.ActionEvent;6 5 import java.awt.event.InputEvent; 7 6 import java.awt.event.KeyEvent; 8 7 import java.io.File; 9 import java.io.FileOutputStream;10 import java.io.IOException;11 8 12 import javax.swing.JOptionPane;13 14 import org.openstreetmap.josm.Main;15 9 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 16 import org.openstreetmap.josm.io.OsmWriter;17 10 18 11 /** … … 21 14 * @author imi 22 15 */ 23 public class SaveAction extends DiskAccessAction{16 public class SaveAction extends SaveActionBase { 24 17 25 18 /** 26 19 * Construct the action with "Save" as label. 27 * @param layer Save only this layer. If <code>null</code>, save the whole Main 28 * data set. 20 * @param layer Save this layer. 29 21 */ 30 public SaveAction( ) {31 super(tr("Save"), "save", tr("Save the current data."), KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK );22 public SaveAction(OsmDataLayer layer) { 23 super(tr("Save"), "save", tr("Save the current data."), KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK, layer); 32 24 } 33 25 34 public void actionPerformed(ActionEvent event) { 35 if (!checkSaveConditions()) 36 return; 37 38 File file = Main.main.editLayer().associatedFile; 39 if (file == null) 40 file = SaveAsAction.openFileDialog(); 41 if (file == null) 42 return; 43 44 save(file); 45 Main.main.editLayer().name = file.getName(); 46 Main.main.editLayer().associatedFile = file; 47 Main.parent.repaint(); 26 public File getFile(OsmDataLayer layer) { 27 if (layer.associatedFile != null) 28 return layer.associatedFile; 29 return openFileDialog(); 48 30 } 49 50 public static void save(File file) {51 try {52 OsmDataLayer layer = Main.main.editLayer();53 if (ExtensionFileFilter.filters[ExtensionFileFilter.GPX].acceptName(file.getPath())) {54 GpxExportAction.exportGpx(file, layer);55 } else if (ExtensionFileFilter.filters[ExtensionFileFilter.OSM].acceptName(file.getPath())) {56 OsmWriter.output(new FileOutputStream(file), new OsmWriter.All(Main.ds, false));57 } else if (ExtensionFileFilter.filters[ExtensionFileFilter.CSV].acceptName(file.getPath())) {58 JOptionPane.showMessageDialog(Main.parent, tr("CSV output not supported yet."));59 return;60 } else {61 JOptionPane.showMessageDialog(Main.parent, tr("Unknown file extension."));62 return;63 }64 layer.cleanData(null, false);65 } catch (IOException e) {66 e.printStackTrace();67 JOptionPane.showMessageDialog(Main.parent, tr("An error occurred while saving.")+"\n"+e.getMessage());68 }69 }70 31 } -
src/org/openstreetmap/josm/actions/SaveAsAction.java
r138 r290 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 import java.awt.event.ActionEvent;6 5 import java.awt.event.InputEvent; 7 6 import java.awt.event.KeyEvent; 8 7 import java.io.File; 9 8 10 import javax.swing.JFileChooser; 11 import javax.swing.filechooser.FileFilter; 12 13 import org.openstreetmap.josm.Main; 9 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 14 10 15 11 /** … … 18 14 * @author imi 19 15 */ 20 public class SaveAsAction extends DiskAccessAction{16 public class SaveAsAction extends SaveActionBase { 21 17 22 18 /** 23 19 * Construct the action with "Save" as label. 24 * @param layer Save only this layer. If <code>null</code>, save the whole Main 25 * data set. 20 * @param layer Save this layer. 26 21 */ 27 public SaveAsAction( ) {28 super(tr("Save as"), "save_as", tr("Save the current data to a new file."), KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK );22 public SaveAsAction(OsmDataLayer layer) { 23 super(tr("Save as"), "save_as", tr("Save the current data to a new file."), KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK, layer); 29 24 } 30 25 31 public void actionPerformed(ActionEvent event) { 32 if (!checkSaveConditions()) 33 return; 34 35 File file = openFileDialog(); 36 if (file == null) 37 return; 38 39 SaveAction.save(file); 40 Main.main.editLayer().name = file.getName(); 41 Main.main.editLayer().associatedFile = file; 42 Main.parent.repaint(); 26 protected File getFile(OsmDataLayer layer) { 27 return openFileDialog(); 43 28 } 44 45 public static File openFileDialog() {46 JFileChooser fc = createAndOpenFileChooser(false, false);47 if (fc == null)48 return null;49 50 File file = fc.getSelectedFile();51 52 String fn = file.getPath();53 if (fn.indexOf('.') == -1) {54 FileFilter ff = fc.getFileFilter();55 if (ff instanceof ExtensionFileFilter)56 fn = "." + ((ExtensionFileFilter)ff).defaultExtension;57 else58 fn += ".osm";59 file = new File(fn);60 }61 return file;62 }63 29 } -
src/org/openstreetmap/josm/actions/SplitWayAction.java
r284 r290 25 25 import org.openstreetmap.josm.command.SequenceCommand; 26 26 import org.openstreetmap.josm.data.SelectionChangedListener; 27 import org.openstreetmap.josm.data.osm.DataSet; 27 28 import org.openstreetmap.josm.data.osm.Node; 28 29 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 99 100 public SplitWayAction() { 100 101 super(tr("Split Way"), "splitway", tr("Split a way at the selected node."), KeyEvent.VK_P, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK, true); 101 Main.ds.listeners.add(this);102 DataSet.listeners.add(this); 102 103 } 103 104 -
src/org/openstreetmap/josm/actions/mapmode/AddWayAction.java
r235 r290 19 19 import org.openstreetmap.josm.command.DeleteCommand; 20 20 import org.openstreetmap.josm.data.SelectionChangedListener; 21 import org.openstreetmap.josm.data.osm.DataSet; 21 22 import org.openstreetmap.josm.data.osm.OsmPrimitive; 22 23 import org.openstreetmap.josm.data.osm.Segment; … … 60 61 public AddWayAction(MapFrame mapFrame) { 61 62 super(tr("Add Way"), "addway", tr("Add a new way to the data."), KeyEvent.VK_W, mapFrame, ImageProvider.getCursor("normal", "way")); 62 Main.ds.listeners.add(this);63 DataSet.listeners.add(this); 63 64 } 64 65 -
src/org/openstreetmap/josm/data/coor/Coordinate.java
r86 r290 20 20 * Either easting or latitude 21 21 */ 22 double x;22 final double x; 23 23 /** 24 24 * Either northing or longitude 25 25 */ 26 double y;26 final double y; 27 27 28 28 /** -
src/org/openstreetmap/josm/data/osm/DataSet.java
r273 r290 20 20 * @author imi 21 21 */ 22 public class DataSet {22 public class DataSet implements Cloneable { 23 23 24 24 /** … … 49 49 50 50 /** 51 * A list of listeners to selection changed events. 51 * A list of listeners to selection changed events. The list is static, 52 * as listeners register themself for any dataset selection changes that 53 * occour, regardless of the current active dataset. (However, the 54 * selection does only change in the active layer) 52 55 */ 53 transient public Collection<SelectionChangedListener> listeners = new LinkedList<SelectionChangedListener>();56 public static Collection<SelectionChangedListener> listeners = new LinkedList<SelectionChangedListener>(); 54 57 55 58 /** … … 144 147 * the event immediately. For more, @see SelectionChangedListener 145 148 */ 146 public void fireSelectionChanged(Collection<? extends OsmPrimitive> sel) {149 public static void fireSelectionChanged(Collection<? extends OsmPrimitive> sel) { 147 150 for (SelectionChangedListener l : listeners) 148 151 l.selectionChanged(sel); 149 152 } 153 154 @Override public DataSet clone() { 155 DataSet ds = new DataSet(); 156 for (Node n : nodes) 157 ds.nodes.add(new Node(n)); 158 for (Segment s : segments) 159 ds.segments.add(new Segment(s)); 160 for (Way w : ways) 161 ds.ways.add(new Way(w)); 162 for (DataSource source : dataSources) 163 ds.dataSources.add(new DataSource(source.bounds, source.origin)); 164 return ds; 165 } 150 166 } -
src/org/openstreetmap/josm/data/osm/DataSource.java
r286 r290 3 3 import org.openstreetmap.josm.data.Bounds; 4 4 5 public class DataSource { 6 public Bounds bounds; 7 public String origin; 5 public class DataSource implements Cloneable { 6 public final Bounds bounds; 7 public final String origin; 8 9 public DataSource(Bounds bounds, String origin) { 10 this.bounds = bounds; 11 this.origin = origin; 12 } 13 14 @Override protected Object clone() throws CloneNotSupportedException { 15 return new DataSource(bounds, origin); 16 } 8 17 } -
src/org/openstreetmap/josm/data/osm/Node.java
r203 r290 12 12 * @author imi 13 13 */ 14 public class Node extends OsmPrimitive {14 public final class Node extends OsmPrimitive { 15 15 16 16 public LatLon coor; -
src/org/openstreetmap/josm/data/osm/Segment.java
r209 r290 9 9 * @author imi 10 10 */ 11 public class Segment extends OsmPrimitive {11 public final class Segment extends OsmPrimitive { 12 12 13 13 /** -
src/org/openstreetmap/josm/data/osm/Way.java
r203 r290 12 12 * @author imi 13 13 */ 14 public class Way extends OsmPrimitive {14 public final class Way extends OsmPrimitive { 15 15 16 16 /** -
src/org/openstreetmap/josm/data/osm/visitor/SimplePaintVisitor.java
r221 r290 36 36 */ 37 37 protected NavigatableComponent nc; 38 39 public boolean inactive; 38 40 39 41 protected static final double PHI = Math.toRadians(20); … … 41 43 public void visitAll(DataSet data) { 42 44 for (final OsmPrimitive osm : data.segments) 43 if (!osm.deleted )45 if (!osm.deleted && !osm.selected) 44 46 osm.visit(this); 45 47 for (final OsmPrimitive osm : data.ways) 46 if (!osm.deleted )48 if (!osm.deleted && !osm.selected) 47 49 osm.visit(this); 48 50 for (final OsmPrimitive osm : data.nodes) 49 if (!osm.deleted )51 if (!osm.deleted && !osm.selected) 50 52 osm.visit(this); 51 53 for (final OsmPrimitive osm : data.getSelected()) … … 61 63 */ 62 64 public void visit(Node n) { 63 drawNode(n, n.selected ? getPreferencesColor("selected", Color.WHITE) 64 : getPreferencesColor("node", Color.RED)); 65 Color color = null; 66 if (inactive) 67 color = getPreferencesColor("inactive", Color.DARK_GRAY); 68 else if (n.selected) 69 color = getPreferencesColor("selected", Color.WHITE); 70 else 71 color = getPreferencesColor("node", Color.RED); 72 drawNode(n, color); 65 73 } 66 74 … … 70 78 */ 71 79 public void visit(Segment ls) { 72 drawSegment(ls, getPreferencesColor("segment", darkgreen), Main.pref.getBoolean("draw.segment.direction")); 80 Color color; 81 if (inactive) 82 color = getPreferencesColor("inactive", Color.DARK_GRAY); 83 else if (ls.selected) 84 color = getPreferencesColor("selected", Color.WHITE); 85 else 86 color = getPreferencesColor("segment", darkgreen); 87 drawSegment(ls, color, Main.pref.getBoolean("draw.segment.direction")); 73 88 } 74 89 … … 78 93 */ 79 94 public void visit(Way w) { 80 // only to overwrite with blue 81 Color wayColor = getPreferencesColor("way", darkblue); 82 for (Segment ls : w.segments) { 83 if (ls.incomplete) { 84 wayColor = getPreferencesColor("incomplete way", darkerblue); 85 break; 95 Color wayColor; 96 if (inactive) 97 wayColor = getPreferencesColor("inactive", Color.DARK_GRAY); 98 else { 99 wayColor = getPreferencesColor("way", darkblue); 100 for (Segment ls : w.segments) { 101 if (ls.incomplete) { 102 wayColor = getPreferencesColor("incomplete way", darkerblue); 103 break; 104 } 86 105 } 87 106 } … … 93 112 orderNumber++; 94 113 if (!ls.selected) // selected already in good color 95 drawSegment(ls, w.selected ? getPreferencesColor("selected", Color.WHITE) : wayColor, showDirectionArrow);114 drawSegment(ls, w.selected && !inactive ? getPreferencesColor("selected", Color.WHITE) : wayColor, showDirectionArrow); 96 115 if (!ls.incomplete && showOrderNumber) 97 116 drawOrderNumber(ls, orderNumber); … … 140 159 if (ls.incomplete) 141 160 return; 142 if (ls.selected)143 col = getPreferencesColor("selected", Color.WHITE);144 161 g.setColor(col); 145 162 Point p1 = nc.getPoint(ls.from.eastNorth); -
src/org/openstreetmap/josm/gui/GettingStarted.java
r266 r290 46 46 47 47 panel = new JPanel(new GridBagLayout()); 48 49 panel.add(new JLabel("<html><h2>You are running a beta version with a brand new feature <i>multiple data layers</i>.</h2>" + 50 "<h3>This is a major change, so expect some bugs, especally with undo/redo and the merging code.<br>" + 51 "If you can't work, downgrade to josm-1.5.jar, available at http://josm.openstreetmap.org/download/josm-1.5.jar<br><br>" + 52 "Imi.</h3>"), GBC.eol()); 48 53 49 54 addGettingStarted(); -
src/org/openstreetmap/josm/gui/MainMenu.java
r242 r290 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 import java.awt.event.ActionEvent; 6 import java.awt.event.ActionListener; 7 5 8 import javax.swing.Action; 6 9 import javax.swing.JMenu; 7 10 import javax.swing.JMenuBar; 11 import javax.swing.JMenuItem; 8 12 9 13 import org.openstreetmap.josm.actions.AboutAction; … … 31 35 import org.openstreetmap.josm.actions.UploadAction; 32 36 import org.openstreetmap.josm.actions.search.SearchAction; 37 import org.openstreetmap.josm.data.DataSetChecker; 33 38 34 39 /** … … 57 62 public final Action reorder = new ReorderAction(); 58 63 public final Action upload = new UploadAction(); 59 public final Action save = new SaveAction( );60 public final Action saveAs = new SaveAsAction( );64 public final Action save = new SaveAction(null); 65 public final Action saveAs = new SaveAsAction(null); 61 66 public final Action gpxExport = new GpxExportAction(null); 62 67 public final Action exit = new ExitAction(); … … 128 133 layerMenu.setVisible(false); 129 134 130 //add(Box.createHorizontalGlue()); 135 JMenuItem check = new JMenuItem("DEBUG: Check Dataset"); 136 check.addActionListener(new ActionListener(){ 137 public void actionPerformed(ActionEvent e) { 138 DataSetChecker.check(); 139 } 140 }); 141 helpMenu.add(check); 131 142 132 143 helpMenu.setMnemonic('H'); -
src/org/openstreetmap/josm/gui/MapView.java
r283 r290 21 21 import org.openstreetmap.josm.data.coor.EastNorth; 22 22 import org.openstreetmap.josm.data.coor.LatLon; 23 import org.openstreetmap.josm.data.osm.DataSet; 23 24 import org.openstreetmap.josm.data.osm.OsmPrimitive; 24 25 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; … … 81 82 82 83 // listend to selection changes to redraw the map 83 Main.ds.listeners.add(new SelectionChangedListener(){84 DataSet.listeners.add(new SelectionChangedListener(){ 84 85 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 85 86 repaint(); … … 102 103 public void addLayer(Layer layer) { 103 104 if (layer instanceof OsmDataLayer) { 104 final OsmDataLayer dataLayer = (OsmDataLayer)layer; 105 if (editLayer != null) { 106 editLayer.mergeFrom(layer); 107 repaint(); 108 return; 109 } 110 editLayer = dataLayer; 111 dataLayer.data.listeners.addAll(Main.ds.listeners); 112 Main.ds = dataLayer.data; 113 dataLayer.listenerModified.add(new ModifiedChangedListener(){ 105 editLayer = (OsmDataLayer)layer; 106 Main.ds = editLayer.data; 107 editLayer.listenerModified.add(new ModifiedChangedListener(){ 114 108 public void modifiedChanged(boolean value, OsmDataLayer source) { 115 109 JOptionPane.getFrameForComponent(Main.parent).setTitle((value?"*":"")+tr("Java OpenStreetMap - Editor")); … … 118 112 } 119 113 120 // add as a new layer 121 if (layer instanceof OsmDataLayer) 122 layers.add(0, layer); 123 else 124 layers.add(layers.size(), layer); 114 layers.add(layers.size(), layer); 125 115 126 116 for (LayerChangeListener l : listeners) … … 176 166 for (int i = layers.size()-1; i >= 0; --i) { 177 167 Layer l = layers.get(i); 178 if (l.visible )168 if (l.visible && l != getActiveLayer()) 179 169 l.paint(g, this); 180 170 } 171 if (getActiveLayer().visible) 172 getActiveLayer().paint(g, this); 181 173 182 174 // draw world borders … … 261 253 if (!layers.contains(layer)) 262 254 throw new IllegalArgumentException("Layer must be in layerlist"); 255 if (layer instanceof OsmDataLayer) { 256 editLayer = (OsmDataLayer)layer; 257 Main.ds = editLayer.data; 258 DataSet.fireSelectionChanged(Main.ds.getSelected()); 259 } 263 260 Layer old = activeLayer; 264 261 activeLayer = layer; … … 266 263 for (LayerChangeListener l : listeners) 267 264 l.activeLayerChange(old, layer); 265 repaint(); 268 266 } 269 267 -
src/org/openstreetmap/josm/gui/dialogs/ConflictDialog.java
r203 r290 31 31 import org.openstreetmap.josm.command.ConflictResolveCommand; 32 32 import org.openstreetmap.josm.data.SelectionChangedListener; 33 import org.openstreetmap.josm.data.osm.DataSet; 33 34 import org.openstreetmap.josm.data.osm.Node; 34 35 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 86 87 add(buttonPanel, BorderLayout.SOUTH); 87 88 88 Main.ds.listeners.add(new SelectionChangedListener(){89 DataSet.listeners.add(new SelectionChangedListener(){ 89 90 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 90 91 displaylist.clearSelection(); -
src/org/openstreetmap/josm/gui/dialogs/HistoryDialog.java
r267 r290 32 32 import org.openstreetmap.josm.Main; 33 33 import org.openstreetmap.josm.data.SelectionChangedListener; 34 import org.openstreetmap.josm.data.osm.DataSet; 34 35 import org.openstreetmap.josm.data.osm.OsmPrimitive; 35 36 import org.openstreetmap.josm.tools.GBC; … … 141 142 revertButton.setToolTipText(tr("Revert the state of all currently selected objects to the version selected in the history list.")); 142 143 revertButton.putClientProperty("help", "Dialog/History/Revert"); 144 145 DataSet.listeners.add(this); 143 146 } 144 147 145 148 146 149 @Override public void setVisible(boolean b) { 147 if (b) {148 Main.ds.listeners.add(this);149 selectionChanged(Main.ds.getSelected());150 } else {151 Main.ds.listeners.remove(this);152 }153 150 super.setVisible(b); 151 if (b) 152 update(); 154 153 } 155 154 156 155 157 156 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 158 update(); 157 if (isVisible()) 158 update(); 159 159 } 160 160 -
src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java
r202 r290 75 75 if (instance.getSelectedValue() == null) 76 76 instance.setSelectedIndex(sel); 77 if (Main.map != null) 78 Main.map.mapView.setActiveLayer((Layer)instance.getSelectedValue()); 77 79 } 78 80 } -
src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java
r283 r290 45 45 import org.openstreetmap.josm.command.SequenceCommand; 46 46 import org.openstreetmap.josm.data.SelectionChangedListener; 47 import org.openstreetmap.josm.data.osm.DataSet; 47 48 import org.openstreetmap.josm.data.osm.OsmPrimitive; 48 49 import org.openstreetmap.josm.gui.MapFrame; … … 346 347 buttonPanel.add(createButton(marktr("Delete"),tr("Delete the selected key in all objects"), KeyEvent.VK_D, buttonAction)); 347 348 add(buttonPanel, BorderLayout.SOUTH); 349 350 DataSet.listeners.add(this); 348 351 } 349 352 … … 359 362 360 363 @Override public void setVisible(boolean b) { 361 if (b) {362 Main.ds.listeners.add(this);364 super.setVisible(b); 365 if (b) 363 366 selectionChanged(Main.ds.getSelected()); 364 } else {365 Main.ds.listeners.remove(this);366 }367 super.setVisible(b);368 367 } 369 368 370 369 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 370 if (!isVisible()) 371 return; 371 372 if (propertyTable == null) 372 373 return; // selection changed may be received in base class constructor before init -
src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
r203 r290 23 23 import org.openstreetmap.josm.Main; 24 24 import org.openstreetmap.josm.data.SelectionChangedListener; 25 import org.openstreetmap.josm.data.osm.DataSet; 25 26 import org.openstreetmap.josm.data.osm.OsmPrimitive; 26 27 import org.openstreetmap.josm.gui.OsmPrimitivRenderer; … … 77 78 add(buttonPanel, BorderLayout.SOUTH); 78 79 selectionChanged(Main.ds.getSelected()); 80 81 DataSet.listeners.add(this); 79 82 } 80 83 … … 88 91 89 92 @Override public void setVisible(boolean b) { 90 if (b) {91 Main.ds.listeners.add(this);93 super.setVisible(b); 94 if (b) 92 95 selectionChanged(Main.ds.getSelected()); 93 } else {94 Main.ds.listeners.remove(this);95 }96 super.setVisible(b);97 96 } 98 99 97 100 98 … … 106 104 if (list == null) 107 105 return; // selection changed may be received in base class constructor before init 106 if (!isVisible()) 107 return; 108 108 OsmPrimitive[] selArr = new OsmPrimitive[newSelection.size()]; 109 109 selArr = newSelection.toArray(selArr); -
src/org/openstreetmap/josm/gui/dialogs/UserListDialog.java
r265 r290 17 17 import org.openstreetmap.josm.Main; 18 18 import org.openstreetmap.josm.data.SelectionChangedListener; 19 import org.openstreetmap.josm.data.osm.DataSet; 19 20 import org.openstreetmap.josm.data.osm.OsmPrimitive; 20 21 import org.openstreetmap.josm.data.osm.User; … … 51 52 add(new JScrollPane(userTable), BorderLayout.CENTER); 52 53 selectionChanged(Main.ds.getSelected()); 54 55 DataSet.listeners.add(this); 53 56 } 54 57 55 58 @Override public void setVisible(boolean b) { 56 if (b) {57 Main.ds.listeners.add(this);59 super.setVisible(b); 60 if (b) 58 61 selectionChanged(Main.ds.getSelected()); 59 } else {60 Main.ds.listeners.remove(this);61 }62 super.setVisible(b);63 62 } 64 63 … … 68 67 */ 69 68 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 69 if (!isVisible()) 70 return; 70 71 71 72 class UserCount { -
src/org/openstreetmap/josm/gui/layer/GeoImageLayer.java
r155 r290 260 260 261 261 @Override public Icon getIcon() { 262 return ImageProvider.get("layer", "tagimages ");262 return ImageProvider.get("layer", "tagimages_small"); 263 263 } 264 264 -
src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r286 r290 135 135 */ 136 136 @Override public Icon getIcon() { 137 return ImageProvider.get("layer", "osmdata ");137 return ImageProvider.get("layer", "osmdata_small"); 138 138 } 139 139 … … 144 144 */ 145 145 @Override public void paint(final Graphics g, final MapView mv) { 146 boolean inactive = Main.map.mapView.getActiveLayer() != this && Main.pref.getBoolean("draw.data.inactive_color", true); 146 147 if (Main.pref.getBoolean("draw.data.downloaded_area", false)) { 147 148 // FIXME this is inefficient; instead a proper polygon has to be built, and instead … … 153 154 Point p1 = mv.getPoint(en1); 154 155 Point p2 = mv.getPoint(en2); 155 g.setColor(SimplePaintVisitor.getPreferencesColor("downloaded Area", Color.YELLOW)); 156 Color color = inactive ? SimplePaintVisitor.getPreferencesColor("inactive", Color.DARK_GRAY) : 157 SimplePaintVisitor.getPreferencesColor("downloaded Area", Color.YELLOW); 158 g.setColor(color); 156 159 g.drawRect(Math.min(p1.x,p2.x), Math.min(p1.y, p2.y), Math.abs(p2.x-p1.x), Math.abs(p2.y-p1.y)); 157 160 } … … 160 163 mapPainter.setGraphics(g); 161 164 mapPainter.setNavigatableComponent(mv); 165 mapPainter.inactive = inactive; 162 166 mapPainter.visitAll(data); 163 167 Main.map.conflictDialog.paintConflicts(g, mv); … … 357 361 new JMenuItem(new LayerListDialog.DeleteLayerAction(this)), 358 362 new JSeparator(), 359 new JMenuItem(new SaveAction( )),360 new JMenuItem(new SaveAsAction( )),363 new JMenuItem(new SaveAction(this)), 364 new JMenuItem(new SaveAsAction(this)), 361 365 new JMenuItem(new GpxExportAction(this)), 362 366 new JSeparator(), -
src/org/openstreetmap/josm/gui/layer/RawGpsLayer.java
r283 r290 83 83 ds.ways.add(w); 84 84 } 85 Main.main.addLayer(new OsmDataLayer(ds, tr(" Data Layer"), null));85 Main.main.addLayer(new OsmDataLayer(ds, tr("Converted from: {0}", RawGpsLayer.this.name), null)); 86 86 Main.main.removeLayer(RawGpsLayer.this); 87 87 } … … 115 115 */ 116 116 @Override public Icon getIcon() { 117 return ImageProvider.get("layer", "rawgps ");117 return ImageProvider.get("layer", "rawgps_small"); 118 118 } 119 119 -
src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayer.java
r200 r290 98 98 */ 99 99 @Override public Icon getIcon() { 100 return ImageProvider.get("layer", "marker ");100 return ImageProvider.get("layer", "marker_small"); 101 101 } 102 102 -
src/org/openstreetmap/josm/gui/preferences/DrawingPreference.java
r283 r290 19 19 private JCheckBox segmentOrderNumber = new JCheckBox(tr("Draw segment order numbers")); 20 20 private JCheckBox sourceBounds = new JCheckBox(tr("Draw boundaries of downloaded data")); 21 private JCheckBox inactive = new JCheckBox(tr("Draw inactive layers in other color")); 21 22 22 23 public void addGui(PreferenceDialog gui) { … … 58 59 sourceBounds.setSelected(Main.pref.getBoolean("draw.data.downloaded_area", true)); 59 60 gui.display.add(sourceBounds, GBC.eop().insets(20,0,0,0)); 61 62 // background layers in inactive color 63 inactive.setToolTipText(tr("Draw the inactive data layers in a different color.")); 64 inactive.setSelected(Main.pref.getBoolean("draw.data.inactive_color", true)); 65 gui.display.add(inactive, GBC.eop().insets(20,0,0,0)); 60 66 } 61 67 … … 67 73 Main.pref.put("draw.segment.order_number", segmentOrderNumber.isSelected()); 68 74 Main.pref.put("draw.data.downloaded_area", sourceBounds.isSelected()); 75 Main.pref.put("draw.data.inactive_color", inactive.isSelected()); 69 76 } 70 77 } -
src/org/openstreetmap/josm/io/BoundingBoxDownloader.java
r286 r290 102 102 Main.pleaseWaitDlg.currentAction.setText(tr("Downloading OSM data...")); 103 103 final DataSet data = OsmReader.parseDataSet(in, null, Main.pleaseWaitDlg); 104 DataSource src = new DataSource();105 src.origin = Main.pref.get("osm-server.url")+"/"+Main.pref.get("osm-server.version", "0.4");106 src.bounds = new Bounds(new LatLon(lat1, lon1), new LatLon(lat2, lon2));104 String origin = Main.pref.get("osm-server.url")+"/"+Main.pref.get("osm-server.version", "0.4"); 105 Bounds bounds = new Bounds(new LatLon(lat1, lon1), new LatLon(lat2, lon2)); 106 DataSource src = new DataSource(bounds, origin); 107 107 data.dataSources.add(src); 108 108 in.close(); -
src/org/openstreetmap/josm/io/OsmReader.java
r286 r290 119 119 String origin = atts.getValue("origin"); 120 120 if (bbox != null) { 121 DataSource src = new DataSource();122 121 String[] b = bbox.split(","); 122 Bounds bounds = null; 123 123 if (b.length == 4) 124 src.bounds = new Bounds(124 bounds = new Bounds( 125 125 new LatLon(Double.parseDouble(b[0]),Double.parseDouble(b[1])), 126 126 new LatLon(Double.parseDouble(b[2]),Double.parseDouble(b[3]))); 127 if (origin != null) 128 src.origin = origin; 127 DataSource src = new DataSource(bounds, origin); 129 128 ds.dataSources.add(src); 130 129 } … … 246 245 for (Node node : Main.ds.nodes) 247 246 if (node.id == id) 248 return n ode;247 return new Node(node); 249 248 return null; 250 249 } … … 260 259 for (Segment seg : Main.ds.segments) 261 260 if (seg.id == id) 262 return seg;261 return new Segment(seg); 263 262 return null; 264 263 } … … 288 287 * Parse the given input source and return the dataset. 289 288 * @param ref The dataset that is search in for references first. If 290 * the Reference is not found here, Main.ds is searched .291 * TODO: This has to be changed to support multiple layers.289 * the Reference is not found here, Main.ds is searched and a copy of the 290 * elemet found there is returned. 292 291 */ 293 292 public static DataSet parseDataSet(InputStream source, DataSet ref, PleaseWaitDialog pleaseWaitDlg) throws SAXException, IOException { -
test/unit/org/openstreetmap/josm/data/osm/DataSetTest.java
r273 r290 87 87 public void testFireSelectionChanged() { 88 88 TestSelectionChangeListener l = new TestSelectionChangeListener(); 89 ds.listeners.add(l);89 DataSet.listeners.add(l); 90 90 ds.setSelected(segment); 91 91 assertNotNull(l.called); 92 92 assertEquals(1, l.called.size()); 93 93 assertSame(segment, l.called.iterator().next()); 94 } 95 96 public void testAddAllSelectionListener() { 97 DataSet ds2 = new DataSet(); 98 TestSelectionChangeListener l1 = new TestSelectionChangeListener(); 99 TestSelectionChangeListener l2 = new TestSelectionChangeListener(); 100 ds2.listeners.add(l1); 101 ds2.listeners.add(l2); 102 ds.listeners.addAll(ds2.listeners); 103 ds2.listeners.remove(l1); 104 ds.setSelected(node2); 105 assertNotNull(l1.called); 106 assertNotNull(l2.called); 94 DataSet.listeners.remove(l); 107 95 } 108 96 }
Note:
See TracChangeset
for help on using the changeset viewer.