Changeset 2243 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2009-10-04T12:07:16+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 3 deleted
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/history/HistoryNode.java
r2242 r2243 4 4 import java.util.Date; 5 5 6 import org.openstreetmap.josm.data.coor.LatLon; 6 7 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 7 import org.openstreetmap.josm.data.coor.LatLon;8 8 9 9 … … 14 14 */ 15 15 public class HistoryNode extends HistoryOsmPrimitive { 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 /** the coordinates */ 17 18 private LatLon coords; 19 20 public HistoryNode(long id, long version, boolean visible, String user, long uid, long changesetId, Date timestamp, LatLon coords) { 19 21 super(id, version, visible, user, uid, changesetId, timestamp); 20 coor = new LatLon(lat, lon);22 setCoords(coords); 21 23 } 22 24 … … 26 28 } 27 29 28 public LatLon getCoordinate() { 29 return coor; 30 public LatLon getCoords() { 31 return coords; 32 } 33 34 public void setCoords(LatLon coords) { 35 this.coords = coords; 30 36 } 31 37 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/HistoryDialog.java
r2239 r2243 110 110 } 111 111 }); 112 historyTable.addMouseListener(new ShowHistoryMouseAdapter()); 112 113 113 114 JScrollPane pane = new JScrollPane(historyTable); … … 138 139 model.refresh(); 139 140 } 140 141 /**142 * shows the {@see HistoryBrowserDialog} for a given {@see History}143 *144 * @param h the history. Must not be null.145 * @exception IllegalArgumentException thrown, if h is null146 */147 protected void showHistory(History h) throws IllegalArgumentException {148 if (h == null)149 throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null.", "h"));150 if (HistoryBrowserDialogManager.getInstance().existsDialog(h.getId())) {151 HistoryBrowserDialogManager.getInstance().show(h.getId());152 } else {153 HistoryBrowserDialog dialog = new HistoryBrowserDialog(h);154 HistoryBrowserDialogManager.getInstance().show(h.getId(), dialog);155 }156 }157 158 141 159 142 /** … … 233 216 } 234 217 return ret; 218 } 219 220 public OsmPrimitive getPrimitive(int row) { 221 return data.get(row); 235 222 } 236 223 } … … 286 273 } 287 274 275 class ShowHistoryMouseAdapter extends MouseAdapter { 276 @Override 277 public void mouseClicked(MouseEvent e) { 278 if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) { 279 int row = historyTable.rowAtPoint(e.getPoint()); 280 new ShowHistoryAction().showHistory(Collections.singletonList(model.getPrimitive(row))); 281 } 282 } 283 } 284 288 285 /** 289 286 * The action for showing history information of the current history item. … … 307 304 } 308 305 309 public void actionPerformed(ActionEvent e) { 310 int [] rows = historyTable.getSelectedRows(); 311 if (rows == null || rows.length == 0) return; 312 313 final List<OsmPrimitive> selectedItems = model.getPrimitives(rows); 314 List<OsmPrimitive> toLoad = filterPrimitivesWithUnloadedHistory(selectedItems); 306 /** 307 * shows the {@see HistoryBrowserDialog} for a given {@see History} 308 * 309 * @param h the history. Must not be null. 310 * @exception IllegalArgumentException thrown, if h is null 311 */ 312 protected void showHistory(History h) throws IllegalArgumentException { 313 if (h == null) 314 throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null.", "h")); 315 if (HistoryBrowserDialogManager.getInstance().existsDialog(h.getId())) { 316 HistoryBrowserDialogManager.getInstance().show(h.getId()); 317 } else { 318 HistoryBrowserDialog dialog = new HistoryBrowserDialog(h); 319 HistoryBrowserDialogManager.getInstance().show(h.getId(), dialog); 320 } 321 } 322 323 public void showHistory(final List<OsmPrimitive> primitives) { 324 List<OsmPrimitive> toLoad = filterPrimitivesWithUnloadedHistory(primitives); 315 325 if (!toLoad.isEmpty()) { 316 326 HistoryLoadTask task = new HistoryLoadTask(); 317 task.add( selectedItems);327 task.add(primitives); 318 328 Main.worker.submit(task); 319 329 } … … 321 331 Runnable r = new Runnable() { 322 332 public void run() { 323 for (OsmPrimitive p : selectedItems) {333 for (OsmPrimitive p : primitives) { 324 334 History h = HistoryDataSet.getInstance().getHistory(p.getId()); 325 335 if (h == null) { … … 333 343 } 334 344 345 public void actionPerformed(ActionEvent e) { 346 int [] rows = historyTable.getSelectedRows(); 347 if (rows == null || rows.length == 0) return; 348 showHistory(model.getPrimitives(rows)); 349 } 350 335 351 protected void updateEnabledState() { 336 352 setEnabled(historyTable.getSelectedRowCount() > 0); -
trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
r2224 r2243 138 138 }); 139 139 140 buttonPanel.add(new SideButton(marktr("Reload"), "refresh", "SelectionList", tr("Refresh the selection list."),141 new ActionListener() {142 public void actionPerformed(ActionEvent e) {143 selectionChanged(Main.main.getCurrentDataSet().getSelected());144 }145 }));146 147 140 searchButton = new SideButton(marktr("Search"), "search", "SelectionList", tr("Search for objects."), 148 141 Main.main.menu.search); -
trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowser.java
r2242 r2243 13 13 import javax.swing.JTable; 14 14 15 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 15 16 import org.openstreetmap.josm.data.osm.history.History; 16 import org.openstreetmap.josm.data.osm.OsmPrimitiveType;17 17 18 18 /** 19 19 * HistoryBrowser is an UI component which displays history information about an {@see OsmPrimitive}. 20 * 20 * 21 21 * 22 22 */ … … 25 25 /** the model */ 26 26 private HistoryBrowserModel model; 27 private JTabbedPane dataPane; 27 private TagInfoViewer tagInfoViewer; 28 private NodeListViewer nodeListViewer; 29 private RelationMemberListViewer relationMemberListViewer; 30 private CoordinateInfoViewer coordinateInfoViewer; 31 private JTabbedPane tpViewers; 32 28 33 29 34 /** 30 35 * embedds table in a {@see JScrollPane} 31 * 36 * 32 37 * @param table the table 33 38 * @return the {@see JScrollPane} with the embedded table … … 42 47 /** 43 48 * creates the table which shows the list of versions 44 * 49 * 45 50 * @return the panel with the version table 46 51 */ … … 57 62 * creates the panel which shows information about two different versions 58 63 * of the same {@see OsmPrimitive}. 59 * 64 * 60 65 * @return the panel 61 66 */ 67 protected JPanel createVersionComparePanel() { 68 tpViewers = new JTabbedPane(); 62 69 63 protected JPanel createVersionComparePanel() { 64 dataPane = new JTabbedPane(); 65 dataPane.add(new TagInfoViewer(model)); 66 dataPane.setTitleAt(0, tr("Tags")); 67 68 dataPane.add(new NodeListViewer(model)); 69 dataPane.setTitleAt(1, tr("Nodes")); 70 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")); 76 70 // create the viewers, but don't add them yet. 71 // see populate() 72 // 73 tagInfoViewer = new TagInfoViewer(model); 74 nodeListViewer = new NodeListViewer(model); 75 relationMemberListViewer = new RelationMemberListViewer(model); 76 coordinateInfoViewer = new CoordinateInfoViewer(model); 77 77 JPanel pnl = new JPanel(); 78 78 pnl.setLayout(new BorderLayout()); 79 pnl.add( dataPane, BorderLayout.CENTER);79 pnl.add(tpViewers, BorderLayout.CENTER); 80 80 return pnl; 81 81 } … … 122 122 /** 123 123 * populates the browser with the history of a specific {@see OsmPrimitive} 124 * 124 * 125 125 * @param history the history 126 126 */ 127 127 public void populate(History history) { 128 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 } 129 130 tpViewers.add(tagInfoViewer); 131 tpViewers.setTitleAt(0, tr("Tags")); 132 133 if (history.getEarliest().getType().equals(OsmPrimitiveType.NODE)) { 134 tpViewers.add(coordinateInfoViewer); 135 tpViewers.setTitleAt(1, tr("Coordinates")); 136 } else if (history.getEarliest().getType().equals(OsmPrimitiveType.WAY)) { 137 tpViewers.add(nodeListViewer); 138 tpViewers.setTitleAt(1, tr("Nodes")); 139 } else if (history.getEarliest().getType().equals(OsmPrimitiveType.RELATION)) { 140 tpViewers.add(relationMemberListViewer); 141 tpViewers.setTitleAt(2, tr("Members")); 146 142 } 143 revalidate(); 147 144 } 148 145 149 146 /** 150 147 * replies the {@see History} currently displayed by this browser 151 * 148 * 152 149 * @return the current history 153 150 */ -
trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowserModel.java
r2242 r2243 62 62 private RelationMemberTableModel currentRelationMemberTableModel; 63 63 private RelationMemberTableModel referenceRelationMemberTableModel; 64 private CoordinateTableModel currentCoordinateTableModel;65 private CoordinateTableModel referenceCoordinateTableModel;66 64 67 65 public HistoryBrowserModel() { … … 73 71 currentRelationMemberTableModel = new RelationMemberTableModel(PointInTimeType.CURRENT_POINT_IN_TIME); 74 72 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);77 73 } 78 74 … … 136 132 currentRelationMemberTableModel.fireTableDataChanged(); 137 133 referenceRelationMemberTableModel.fireTableDataChanged(); 138 }139 140 protected void initCoordinateTableModels() {141 currentCoordinateTableModel.fireTableDataChanged();142 referenceCoordinateTableModel.fireTableDataChanged();143 134 } 144 135 … … 181 172 else if (pointInTimeType.equals(PointInTimeType.REFERENCE_POINT_IN_TIME)) 182 173 return referenceRelationMemberTableModel; 183 184 // should not happen185 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;195 174 196 175 // should not happen … … 213 192 initNodeListTabeModels(); 214 193 initMemberListTableModels(); 215 initCoordinateTableModels();216 194 setChanged(); 217 195 notifyObservers(); … … 232 210 initNodeListTabeModels(); 233 211 initMemberListTableModels(); 234 initCoordinateTableModels();235 212 setChanged(); 236 213 notifyObservers(); … … 610 587 } 611 588 } 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 @Override629 public int getRowCount() {630 if (current != null && current instanceof HistoryNode)631 currentCoor = ((HistoryNode)current).getCoordinate();632 else633 return 0;634 if (reference != null && reference instanceof HistoryNode)635 referenceCoor = ((HistoryNode)reference).getCoordinate();636 return 2;637 }638 639 @Override640 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 else647 return row == 0 ? referenceCoor.latToString(CoordinateFormat.getDefaultFormat())648 : referenceCoor.lonToString(CoordinateFormat.getDefaultFormat());649 }650 651 @Override652 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 }676 589 } -
trunk/src/org/openstreetmap/josm/gui/history/NodeListViewer.java
r1709 r2243 143 143 } 144 144 } 145 146 145 } -
trunk/src/org/openstreetmap/josm/gui/history/VersionInfoPanel.java
r2242 r2243 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt. BorderLayout;7 import java.awt. event.ActionEvent;8 import java.awt. event.MouseEvent;6 import java.awt.FlowLayout; 7 import java.awt.GridBagConstraints; 8 import java.awt.GridBagLayout; 9 9 import java.text.SimpleDateFormat; 10 10 import java.util.Observable; … … 16 16 import org.openstreetmap.josm.actions.AbstractInfoAction; 17 17 import org.openstreetmap.josm.data.osm.history.HistoryOsmPrimitive; 18 import org.openstreetmap.josm.tools. ImageProvider;18 import org.openstreetmap.josm.tools.UrlLabel; 19 19 20 20 /** 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{ … … 28 28 private HistoryBrowserModel model; 29 29 private JLabel lblInfo; 30 private UrlLabel lblUser; 31 private UrlLabel lblChangeset; 30 32 31 33 protected void build() { 32 setLayout(new BorderLayout()); 34 JPanel pnl1 = new JPanel(); 35 pnl1.setLayout(new FlowLayout(FlowLayout.LEFT)); 33 36 lblInfo = new JLabel(); 34 37 lblInfo.setHorizontalAlignment(JLabel.LEFT); 35 add(lblInfo, BorderLayout.CENTER); 38 pnl1.add(lblInfo); 39 40 JPanel pnl2 = new JPanel(); 41 pnl2.setLayout(new FlowLayout(FlowLayout.LEFT)); 42 lblUser = new UrlLabel(); 43 pnl2.add(new JLabel(tr("User"))); 44 pnl2.add(lblUser); 45 pnl2.add(new JLabel(tr("Changeset"))); 46 lblChangeset = new UrlLabel(); 47 pnl2.add(lblChangeset); 48 49 setLayout(new GridBagLayout()); 50 GridBagConstraints gc = new GridBagConstraints(); 51 gc.anchor = GridBagConstraints.NORTHWEST; 52 gc.fill = GridBagConstraints.HORIZONTAL; 53 gc.weightx = 1.0; 54 gc.weighty = 0.0; 55 add(pnl1, gc); 56 gc.gridy = 1; 57 add(pnl2, gc); 36 58 } 37 59 … … 46 68 if (primitive == null) 47 69 return ""; 48 String url = AbstractInfoAction.getBaseBrowseUrl() + "/changeset/" + primitive.getChangesetId();49 70 String text = tr( 50 "<html>Version <strong>{0}</strong> created on <strong>{1}</strong> by <strong>{2}</strong> in changeset <strong>{3}</strong></html>",71 "<html>Version <strong>{0}</strong> created on <strong>{1}</strong>", 51 72 Long.toString(primitive.getVersion()), 52 new SimpleDateFormat().format(primitive.getTimestamp()), 53 primitive.getUser().replace("<", "<").replace(">", ">"), 54 primitive.getChangesetId() 73 new SimpleDateFormat().format(primitive.getTimestamp()) 55 74 ); 56 75 return text; … … 65 84 /** 66 85 * constructor 67 * 86 * 68 87 * @param model the model (must not be null) 69 88 * @param pointInTimeType the point in time this panel visualizes (must not be null) … … 86 105 public void update(Observable o, Object arg) { 87 106 lblInfo.setText(getInfoText()); 107 108 String url = AbstractInfoAction.getBaseBrowseUrl() + "/changeset/" + getPrimitive().getChangesetId(); 109 lblChangeset.setUrl(url); 110 lblChangeset.setDescription(tr("{0}", getPrimitive().getChangesetId())); 111 112 url = AbstractInfoAction.getBaseUserUrl() + "/" + getPrimitive().getUser(); 113 lblUser.setUrl(url); 114 lblUser.setDescription(tr("{0}", getPrimitive().getUser())); 88 115 } 89 116 } -
trunk/src/org/openstreetmap/josm/io/OsmHistoryReader.java
r2242 r2243 12 12 import javax.xml.parsers.SAXParserFactory; 13 13 14 import org.openstreetmap.josm.data.coor.LatLon; 14 15 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 15 16 import org.openstreetmap.josm.data.osm.history.HistoryDataSet; … … 80 81 } 81 82 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 99 protected int getMandatoryAttributeInt(Attributes attr, String name) throws SAXException{ 100 String v = attr.getValue(name); 101 if (v == null) { 102 throwException(tr("Missing mandatory attribute ''{0}''.", name)); 103 } 104 Integer i = 0; 105 try { 106 i = Integer.parseInt(v); 107 } catch(NumberFormatException e) { 108 throwException(tr("Illegal value for mandatory attribute ''{0}'' of type int. Got ''{1}''.", name, v)); 109 } 110 if (i < 0) { 111 throwException(tr("Illegal value for mandatory attribute ''{0}'' of type int (>=0). Got ''{1}''.", name, v)); 112 } 113 return i; 114 } 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; 83 protected Double getMandatoryAttributeDouble(Attributes attr, String name) throws SAXException{ 84 String v = attr.getValue(name); 85 if (v == null) { 86 throwException(tr("Missing mandatory attribute ''{0}''.", name)); 87 } 88 double d = 0; 122 89 try { 123 90 d = Double.parseDouble(v); … … 125 92 throwException(tr("Illegal value for mandatory attribute ''{0}'' of type double. Got ''{1}''.", name, v)); 126 93 } 94 if (d < 0) { 95 throwException(tr("Illegal value for mandatory attribute ''{0}'' of type double (>=0). Got ''{1}''.", name, v)); 96 } 127 97 return d; 128 98 } … … 133 103 throwException(tr("Missing mandatory attribute ''{0}''.", name)); 134 104 } 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;142 105 return v; 143 106 } … … 157 120 protected HistoryOsmPrimitive createPrimitive(Attributes atts, OsmPrimitiveType type) throws SAXException { 158 121 long id = getMandatoryAttributeLong(atts,"id"); 159 long version = getMandatoryAttributeLong(atts, 160 long changesetId = getMandatoryAttributeLong(atts, 161 boolean visible 162 long uid = get AttributeLong(atts, "uid", -1);163 String user = get AttributeString(atts, "user", tr("<anonymous>"));122 long version = getMandatoryAttributeLong(atts,"version"); 123 long changesetId = getMandatoryAttributeLong(atts,"changeset"); 124 boolean visible= getMandatoryAttributeBoolean(atts, "visible"); 125 long uid = getMandatoryAttributeLong(atts, "uid"); 126 String user = getMandatoryAttributeString(atts, "user"); 164 127 String v = getMandatoryAttributeString(atts, "timestamp"); 165 128 Date timestamp = DateUtils.fromString(v); … … 169 132 double lon = getMandatoryAttributeDouble(atts, "lon"); 170 133 primitive = new HistoryNode( 171 id,version,visible,user,uid,changesetId,timestamp, lat,lon134 id,version,visible,user,uid,changesetId,timestamp, new LatLon(lat,lon) 172 135 ); 136 173 137 } else if (type.equals(OsmPrimitiveType.WAY)) { 174 138 primitive = new HistoryWay( -
trunk/src/org/openstreetmap/josm/tools/UrlLabel.java
r1169 r2243 12 12 public class UrlLabel extends JEditorPane implements HyperlinkListener { 13 13 14 private final String url; 14 private String url = ""; 15 private String description = ""; 16 17 public UrlLabel() { 18 addHyperlinkListener(this); 19 setEditable(false); 20 setOpaque(false); 21 } 15 22 16 23 public UrlLabel(String url) { … … 19 26 20 27 public UrlLabel(String url, String description) { 21 this.url = url; 28 this(); 29 setUrl(url); 30 setDescription(description); 31 refresh(); 32 } 33 34 protected void refresh() { 22 35 setContentType("text/html"); 23 36 setText("<html><a href=\""+url+"\">"+description+"</a></html>"); 24 37 setToolTipText(url); 25 setEditable(false);26 setOpaque(false);27 addHyperlinkListener(this);28 38 } 29 39 … … 33 43 } 34 44 } 45 46 public void setUrl(String url) { 47 this.url = url == null ? "" : url; 48 refresh(); 49 } 50 51 public void setDescription(String description) { 52 this.description = description == null? "" : description; 53 refresh(); 54 } 35 55 }
Note:
See TracChangeset
for help on using the changeset viewer.