- Timestamp:
- 2009-10-04T00:37:05+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/history/History.java
r2181 r2242 10 10 import java.util.List; 11 11 import java.util.NoSuchElementException; 12 13 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 12 14 13 15 public class History{ … … 195 197 return versions.isEmpty(); 196 198 } 199 200 public OsmPrimitiveType getType() { 201 if (isEmpty()) 202 throw new NoSuchElementException(tr("No type found. History is empty.")); 203 return versions.get(0).getType(); 204 } 197 205 } -
trunk/src/org/openstreetmap/josm/data/osm/history/HistoryNode.java
r1670 r2242 5 5 6 6 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 7 import org.openstreetmap.josm.data.coor.LatLon; 7 8 8 9 … … 13 14 */ 14 15 public class HistoryNode extends HistoryOsmPrimitive { 15 public HistoryNode(long id, long version, boolean visible, String user, long uid, long changesetId, Date timestamp) { 16 private LatLon coor; 17 public HistoryNode(long id, long version, boolean visible, String user, long uid, long changesetId, Date timestamp, 18 double lat, double lon) { 16 19 super(id, version, visible, user, uid, changesetId, timestamp); 20 coor = new LatLon(lat, lon); 17 21 } 18 22 … … 21 25 return OsmPrimitiveType.NODE; 22 26 } 27 28 public LatLon getCoordinate() { 29 return coor; 30 } 23 31 } -
trunk/src/org/openstreetmap/josm/data/osm/history/HistoryOsmPrimitive.java
r2181 r2242 39 39 /** 40 40 * constructor 41 * 41 * 42 42 * @param id the id (>0 required) 43 43 * @param version the version (> 0 required) … … 47 47 * @param changesetId the changeset id (> 0 required) 48 48 * @param timestamp the timestamp (! null required) 49 * 49 * 50 50 * @throws IllegalArgumentException thrown if preconditions are violated 51 51 */ … … 53 53 ensurePositiveLong(id, "id"); 54 54 ensurePositiveLong(version, "version"); 55 ensurePositiveLong(uid, "uid"); 55 if(uid != -1) /* allow -1 for anonymous users */ 56 ensurePositiveLong(uid, "uid"); 56 57 ensurePositiveLong(changesetId, "changesetId"); 57 58 ensureNotNull(user, "user"); -
trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowser.java
r1709 r2242 14 14 15 15 import org.openstreetmap.josm.data.osm.history.History; 16 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 16 17 17 18 /** 18 19 * HistoryBrowser is an UI component which displays history information about an {@see OsmPrimitive}. 19 * 20 * 20 21 * 21 22 */ … … 24 25 /** the model */ 25 26 private HistoryBrowserModel model; 27 private JTabbedPane dataPane; 26 28 27 29 /** 28 30 * embedds table in a {@see JScrollPane} 29 * 31 * 30 32 * @param table the table 31 33 * @return the {@see JScrollPane} with the embedded table … … 40 42 /** 41 43 * creates the table which shows the list of versions 42 * 44 * 43 45 * @return the panel with the version table 44 46 */ … … 55 57 * creates the panel which shows information about two different versions 56 58 * of the same {@see OsmPrimitive}. 57 * 59 * 58 60 * @return the panel 59 61 */ 62 60 63 protected JPanel createVersionComparePanel() { 61 JTabbedPane pane = new JTabbedPane();62 pane.add(new TagInfoViewer(model));63 pane.setTitleAt(0, tr("Tags"));64 dataPane = new JTabbedPane(); 65 dataPane.add(new TagInfoViewer(model)); 66 dataPane.setTitleAt(0, tr("Tags")); 64 67 65 pane.add(new NodeListViewer(model));66 pane.setTitleAt(1, tr("Nodes"));68 dataPane.add(new NodeListViewer(model)); 69 dataPane.setTitleAt(1, tr("Nodes")); 67 70 68 pane.add(new RelationMemberListViewer(model)); 69 pane.setTitleAt(2, tr("Members")); 71 dataPane.add(new RelationMemberListViewer(model)); 72 dataPane.setTitleAt(2, tr("Members")); 73 74 dataPane.add(new CoordinateViewer(model)); 75 dataPane.setTitleAt(3, tr("Coordinate")); 70 76 71 77 JPanel pnl = new JPanel(); 72 78 pnl.setLayout(new BorderLayout()); 73 pnl.add( pane, BorderLayout.CENTER);79 pnl.add(dataPane, BorderLayout.CENTER); 74 80 return pnl; 75 81 } … … 116 122 /** 117 123 * populates the browser with the history of a specific {@see OsmPrimitive} 118 * 124 * 119 125 * @param history the history 120 126 */ 121 127 public void populate(History history) { 122 128 model.setHistory(history); 129 OsmPrimitiveType type = history.getType(); 130 if(type != null) 131 { 132 if(type == OsmPrimitiveType.NODE) 133 { 134 dataPane.setEnabledAt(1, false); 135 dataPane.setEnabledAt(2, false); 136 } 137 else if(type == OsmPrimitiveType.WAY) 138 { 139 dataPane.setEnabledAt(2, false); 140 dataPane.setEnabledAt(3, false); 141 } 142 else 143 { 144 dataPane.setEnabledAt(3, false); 145 } 146 } 123 147 } 124 148 125 149 /** 126 150 * replies the {@see History} currently displayed by this browser 127 * 151 * 128 152 * @return the current history 129 153 */ -
trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowserModel.java
r2182 r2242 12 12 import javax.swing.table.DefaultTableModel; 13 13 14 import org.openstreetmap.josm.data.coor.CoordinateFormat; 15 import org.openstreetmap.josm.data.coor.LatLon; 14 16 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 15 17 import org.openstreetmap.josm.data.osm.history.History; 18 import org.openstreetmap.josm.data.osm.history.HistoryNode; 16 19 import org.openstreetmap.josm.data.osm.history.HistoryOsmPrimitive; 17 20 import org.openstreetmap.josm.data.osm.history.HistoryRelation; … … 20 23 /** 21 24 * This is the model used by the history browser. 22 * 25 * 23 26 * The state this model manages consists of the following elements: 24 27 * <ul> … … 40 43 * members of the two selected versions (if the current history provides information about a {@see Relation}</li> 41 44 * </ul> 42 * 45 * 43 46 * @see HistoryBrowser 44 47 */ … … 59 62 private RelationMemberTableModel currentRelationMemberTableModel; 60 63 private RelationMemberTableModel referenceRelationMemberTableModel; 64 private CoordinateTableModel currentCoordinateTableModel; 65 private CoordinateTableModel referenceCoordinateTableModel; 61 66 62 67 public HistoryBrowserModel() { … … 68 73 currentRelationMemberTableModel = new RelationMemberTableModel(PointInTimeType.CURRENT_POINT_IN_TIME); 69 74 referenceRelationMemberTableModel = new RelationMemberTableModel(PointInTimeType.REFERENCE_POINT_IN_TIME); 75 currentCoordinateTableModel = new CoordinateTableModel(PointInTimeType.CURRENT_POINT_IN_TIME); 76 referenceCoordinateTableModel = new CoordinateTableModel(PointInTimeType.REFERENCE_POINT_IN_TIME); 70 77 } 71 78 … … 85 92 /** 86 93 * sets the history to be managed by this model 87 * 94 * 88 95 * @param history the history 89 * 96 * 90 97 */ 91 98 public void setHistory(History history) { … … 109 116 * Replies the table model to be used in a {@see JTable} which 110 117 * shows the list of versions in this history. 111 * 118 * 112 119 * @return the table model 113 120 */ … … 121 128 } 122 129 123 protected void initNodeListTabeModel() { 130 protected void initNodeListTabeModels() { 124 131 currentNodeListTableModel.fireTableDataChanged(); 125 132 referenceNodeListTableModel.fireTableDataChanged(); 126 133 } 127 134 128 protected void initMemberListTableModel() { 135 protected void initMemberListTableModels() { 129 136 currentRelationMemberTableModel.fireTableDataChanged(); 130 137 referenceRelationMemberTableModel.fireTableDataChanged(); 131 138 } 132 139 140 protected void initCoordinateTableModels() { 141 currentCoordinateTableModel.fireTableDataChanged(); 142 referenceCoordinateTableModel.fireTableDataChanged(); 143 } 144 133 145 /** 134 146 * replies the tag table model for the respective point in time 135 * 147 * 136 148 * @param pointInTimeType the type of the point in time (must not be null) 137 149 * @return the tag table model … … 169 181 else if (pointInTimeType.equals(PointInTimeType.REFERENCE_POINT_IN_TIME)) 170 182 return referenceRelationMemberTableModel; 183 184 // should not happen 185 return null; 186 } 187 188 public CoordinateTableModel getCoordinateTableModel(PointInTimeType pointInTimeType) throws IllegalArgumentException { 189 if (pointInTimeType == null) 190 throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null.", "pointInTimeType")); 191 if (pointInTimeType.equals(PointInTimeType.CURRENT_POINT_IN_TIME)) 192 return currentCoordinateTableModel; 193 else if (pointInTimeType.equals(PointInTimeType.REFERENCE_POINT_IN_TIME)) 194 return referenceCoordinateTableModel; 171 195 172 196 // should not happen … … 187 211 this.reference = reference; 188 212 initTagTableModels(); 189 initNodeListTabeModel(); 190 initMemberListTableModel(); 213 initNodeListTabeModels(); 214 initMemberListTableModels(); 215 initCoordinateTableModels(); 191 216 setChanged(); 192 217 notifyObservers(); … … 205 230 this.current = current; 206 231 initTagTableModels(); 207 initNodeListTabeModel(); 208 initMemberListTableModel(); 232 initNodeListTabeModels(); 233 initMemberListTableModels(); 234 initCoordinateTableModels(); 209 235 setChanged(); 210 236 notifyObservers(); … … 213 239 /** 214 240 * Replies the history OSM primitive for the {@see PointInTimeType#CURRENT_POINT_IN_TIME} 215 * 241 * 216 242 * @return the history OSM primitive for the {@see PointInTimeType#CURRENT_POINT_IN_TIME} (may be null) 217 243 */ … … 222 248 /** 223 249 * Replies the history OSM primitive for the {@see PointInTimeType#REFERENCE_POINT_IN_TIME} 224 * 250 * 225 251 * @return the history OSM primitive for the {@see PointInTimeType#REFERENCE_POINT_IN_TIME} (may be null) 226 252 */ … … 231 257 /** 232 258 * replies the history OSM primitive for a given point in time 233 * 259 * 234 260 * @param type the type of the point in time (must not be null) 235 261 * @return the respective primitive. Can be null. … … 306 332 * The table model for the tags of the version at {@see PointInTimeType#REFERENCE_POINT_IN_TIME} 307 333 * or {@see PointInTimeType#CURRENT_POINT_IN_TIME} 308 * 334 * 309 335 */ 310 336 public class TagTableModel extends DefaultTableModel { … … 401 427 * The table model for the nodes of the version at {@see PointInTimeType#REFERENCE_POINT_IN_TIME} 402 428 * or {@see PointInTimeType#CURRENT_POINT_IN_TIME} 403 * 429 * 404 430 */ 405 431 public class NodeListTableModel extends DefaultTableModel { … … 493 519 * The table model for the relation members of the version at {@see PointInTimeType#REFERENCE_POINT_IN_TIME} 494 520 * or {@see PointInTimeType#CURRENT_POINT_IN_TIME} 495 * 521 * 496 522 */ 497 523 … … 584 610 } 585 611 } 612 613 /** 614 * The table model for the coordinates of the version at {@see PointInTimeType#REFERENCE_POINT_IN_TIME} 615 * or {@see PointInTimeType#CURRENT_POINT_IN_TIME} 616 * 617 */ 618 public class CoordinateTableModel extends DefaultTableModel { 619 620 private LatLon currentCoor = null; 621 private LatLon referenceCoor = null; 622 private PointInTimeType pointInTimeType; 623 624 protected CoordinateTableModel(PointInTimeType type) { 625 pointInTimeType = type; 626 } 627 628 @Override 629 public int getRowCount() { 630 if (current != null && current instanceof HistoryNode) 631 currentCoor = ((HistoryNode)current).getCoordinate(); 632 else 633 return 0; 634 if (reference != null && reference instanceof HistoryNode) 635 referenceCoor = ((HistoryNode)reference).getCoordinate(); 636 return 2; 637 } 638 639 @Override 640 public Object getValueAt(int row, int column) { 641 if(currentCoor == null) 642 return null; 643 else if (pointInTimeType.equals(PointInTimeType.CURRENT_POINT_IN_TIME)) 644 return row == 0 ? currentCoor.latToString(CoordinateFormat.getDefaultFormat()) 645 : currentCoor.lonToString(CoordinateFormat.getDefaultFormat()); 646 else 647 return row == 0 ? referenceCoor.latToString(CoordinateFormat.getDefaultFormat()) 648 : referenceCoor.lonToString(CoordinateFormat.getDefaultFormat()); 649 } 650 651 @Override 652 public boolean isCellEditable(int row, int column) { 653 return false; 654 } 655 656 public boolean hasSameValueAsOpposite(int row) { 657 if(currentCoor == null) 658 return false; 659 else if(row == 0) 660 return currentCoor.lat() == referenceCoor.lat(); 661 return currentCoor.lon() == referenceCoor.lon(); 662 } 663 664 public PointInTimeType getPointInTimeType() { 665 return pointInTimeType; 666 } 667 668 public boolean isCurrentPointInTime() { 669 return pointInTimeType.equals(PointInTimeType.CURRENT_POINT_IN_TIME); 670 } 671 672 public boolean isReferencePointInTime() { 673 return pointInTimeType.equals(PointInTimeType.REFERENCE_POINT_IN_TIME); 674 } 675 } 586 676 } -
trunk/src/org/openstreetmap/josm/gui/history/TagInfoViewer.java
r2017 r2242 12 12 13 13 /** 14 * TagInfoViewer is a UI component which displays the 14 * TagInfoViewer is a UI component which displays the list of tags of two 15 15 * version of a {@see OsmPrimitive} in a {@see History}. 16 * 16 * 17 17 * <ul> 18 18 * <li>on the left, it displays the list of tags for the version at {@see PointInTimeType#REFERENCE_POINT_IN_TIME}</li> -
trunk/src/org/openstreetmap/josm/gui/history/VersionInfoPanel.java
r2181 r2242 21 21 * VersionInfoPanel is an UI component which displays the basic properties of a version 22 22 * of a {@see OsmPrimitive}. 23 * 23 * 24 24 */ 25 25 public class VersionInfoPanel extends JPanel implements Observer{ … … 51 51 Long.toString(primitive.getVersion()), 52 52 new SimpleDateFormat().format(primitive.getTimestamp()), 53 primitive.getUser(), 53 primitive.getUser().replace("<", "<").replace(">", ">"), 54 54 primitive.getChangesetId() 55 55 ); … … 65 65 /** 66 66 * constructor 67 * 67 * 68 68 * @param model the model (must not be null) 69 69 * @param pointInTimeType the point in time this panel visualizes (must not be null) -
trunk/src/org/openstreetmap/josm/io/OsmHistoryReader.java
r2181 r2242 80 80 } 81 81 82 protected long getAttributeLong(Attributes attr, String name, long defaultValue) throws SAXException{ 83 String v = attr.getValue(name); 84 if (v == null) { 85 return defaultValue; 86 } 87 Long l = 0l; 88 try { 89 l = Long.parseLong(v); 90 } catch(NumberFormatException e) { 91 throwException(tr("Illegal value for mandatory attribute ''{0}'' of type long. Got ''{1}''.", name, v)); 92 } 93 if (l < 0) { 94 throwException(tr("Illegal value for mandatory attribute ''{0}'' of type long (>=0). Got ''{1}''.", name, v)); 95 } 96 return l; 97 } 98 82 99 protected int getMandatoryAttributeInt(Attributes attr, String name) throws SAXException{ 83 100 String v = attr.getValue(name); … … 97 114 } 98 115 116 protected double getMandatoryAttributeDouble(Attributes attr, String name) throws SAXException{ 117 String v = attr.getValue(name); 118 if (v == null) { 119 throwException(tr("Missing mandatory attribute ''{0}''.", name)); 120 } 121 double d = 0.0; 122 try { 123 d = Double.parseDouble(v); 124 } catch(NumberFormatException e) { 125 throwException(tr("Illegal value for mandatory attribute ''{0}'' of type double. Got ''{1}''.", name, v)); 126 } 127 return d; 128 } 129 99 130 protected String getMandatoryAttributeString(Attributes attr, String name) throws SAXException{ 100 131 String v = attr.getValue(name); … … 102 133 throwException(tr("Missing mandatory attribute ''{0}''.", name)); 103 134 } 135 return v; 136 } 137 138 protected String getAttributeString(Attributes attr, String name, String defaultValue) { 139 String v = attr.getValue(name); 140 if (v == null) 141 v = defaultValue; 104 142 return v; 105 143 } … … 119 157 protected HistoryOsmPrimitive createPrimitive(Attributes atts, OsmPrimitiveType type) throws SAXException { 120 158 long id = getMandatoryAttributeLong(atts,"id"); 121 long version = getMandatoryAttributeLong(atts,"version"); 122 long changesetId = getMandatoryAttributeLong(atts,"changeset"); 123 boolean visible= getMandatoryAttributeBoolean(atts, "visible"); 124 long uid = get MandatoryAttributeLong(atts, "uid");125 String user = get MandatoryAttributeString(atts, "user");159 long version = getMandatoryAttributeLong(atts, "version"); 160 long changesetId = getMandatoryAttributeLong(atts, "changeset"); 161 boolean visible = getMandatoryAttributeBoolean(atts, "visible"); 162 long uid = getAttributeLong(atts, "uid", -1); 163 String user = getAttributeString(atts, "user", tr("<anonymous>")); 126 164 String v = getMandatoryAttributeString(atts, "timestamp"); 127 165 Date timestamp = DateUtils.fromString(v); 128 166 HistoryOsmPrimitive primitive = null; 129 167 if (type.equals(OsmPrimitiveType.NODE)) { 168 double lat = getMandatoryAttributeDouble(atts, "lat"); 169 double lon = getMandatoryAttributeDouble(atts, "lon"); 130 170 primitive = new HistoryNode( 131 id,version,visible,user,uid,changesetId,timestamp 171 id,version,visible,user,uid,changesetId,timestamp,lat,lon 132 172 ); 133 173 } else if (type.equals(OsmPrimitiveType.WAY)) {
Note:
See TracChangeset
for help on using the changeset viewer.