- Timestamp:
- 2014-10-08T00:01:23+02:00 (10 years ago)
- Location:
- trunk
- Files:
-
- 10 added
- 1 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadNotesTask.java
r7597 r7608 96 96 if (noteLayers != null && noteLayers.size() > 0) { 97 97 layer = noteLayers.get(0); 98 layer. addNotes(notesData);98 layer.getNoteData().addNotes(notesData); 99 99 } else { 100 100 layer = new NoteLayer(notesData, "Notes"); -
trunk/src/org/openstreetmap/josm/gui/MapFrame.java
r7483 r7608 67 67 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; 68 68 import org.openstreetmap.josm.gui.dialogs.MapPaintDialog; 69 import org.openstreetmap.josm.gui.dialogs.NoteDialog; 69 70 import org.openstreetmap.josm.gui.dialogs.RelationListDialog; 70 71 import org.openstreetmap.josm.gui.dialogs.SelectionListDialog; … … 133 134 public SelectionListDialog selectionListDialog; 134 135 public PropertiesDialog propertiesDialog; 136 public NoteDialog noteDialog; 135 137 136 138 // Map modes … … 243 245 addToggleDialog(new ChangesetDialog(), true); 244 246 addToggleDialog(new MapPaintDialog()); 247 //TODO: remove this if statement once note support is complete 248 if(Main.pref.getBoolean("osm.notes.enableDownload", false)) { 249 addToggleDialog(noteDialog = new NoteDialog()); 250 } 245 251 toolBarToggle.setFloatable(false); 246 252 -
trunk/src/org/openstreetmap/josm/gui/layer/NoteLayer.java
r7522 r7608 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.Dimension; 6 7 import java.awt.Graphics2D; 7 8 import java.awt.Point; 9 import java.awt.event.MouseEvent; 10 import java.awt.event.MouseListener; 11 import java.text.SimpleDateFormat; 8 12 import java.util.ArrayList; 9 13 import java.util.List; … … 12 16 import javax.swing.Icon; 13 17 import javax.swing.ImageIcon; 18 import javax.swing.JToolTip; 14 19 15 20 import org.openstreetmap.josm.Main; … … 18 23 import org.openstreetmap.josm.data.notes.Note.State; 19 24 import org.openstreetmap.josm.data.notes.NoteComment; 25 import org.openstreetmap.josm.data.osm.NoteData; 20 26 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 21 27 import org.openstreetmap.josm.gui.MapView; 22 28 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; 23 29 import org.openstreetmap.josm.gui.dialogs.LayerListPopup; 24 import org.openstreetmap.josm.tools.ImageProvider; 30 import org.openstreetmap.josm.gui.dialogs.NoteDialog; 31 import org.openstreetmap.josm.io.XmlWriter; 32 import org.openstreetmap.josm.tools.ColorHelper; 25 33 26 34 /** 27 35 * A layer to hold Note objects 28 36 */ 29 public class NoteLayer extends AbstractModifiableLayer {30 31 private final List<Note> notes;37 public class NoteLayer extends AbstractModifiableLayer implements MouseListener { 38 39 private final NoteData noteData; 32 40 33 41 /** … … 38 46 public NoteLayer(List<Note> notes, String name) { 39 47 super(name); 40 this.notes = notes; 48 noteData = new NoteData(notes); 49 init(); 50 } 51 52 /** Convenience constructor that creates a layer with an empty note list */ 53 public NoteLayer() { 54 super(tr("Notes")); 55 noteData = new NoteData(); 56 init(); 57 } 58 59 private void init() { 60 if (Main.map != null && Main.map.mapView != null) { 61 Main.map.mapView.addMouseListener(this); 62 } 63 } 64 65 /** 66 * Returns the note data store being used by this layer 67 * @return noteData containing layer notes 68 */ 69 public NoteData getNoteData() { 70 return noteData; 41 71 } 42 72 43 73 @Override 44 74 public boolean isModified() { 45 for (Note note : note s) {75 for (Note note : noteData.getNotes()) { 46 76 if (note.getId() < 0) { //notes with negative IDs are new 47 77 return true; … … 63 93 @Override 64 94 public void paint(Graphics2D g, MapView mv, Bounds box) { 65 for (Note note : note s) {95 for (Note note : noteData.getNotes()) { 66 96 Point p = mv.getPoint(note.getLatLon()); 67 97 68 98 ImageIcon icon = null; 69 99 if (note.getId() < 0) { 70 icon = ImageProvider.get("notes", "note_new_16x16.png");100 icon = NoteDialog.ICON_NEW_SMALL; 71 101 } else if (note.getState() == State.closed) { 72 icon = ImageProvider.get("notes", "note_closed_16x16.png");102 icon = NoteDialog.ICON_CLOSED_SMALL; 73 103 } else { 74 icon = ImageProvider.get("notes", "note_open_16x16.png");104 icon = NoteDialog.ICON_OPEN_SMALL; 75 105 } 76 106 int width = icon.getIconWidth(); … … 78 108 g.drawImage(icon.getImage(), p.x - (width / 2), p.y - height, Main.map.mapView); 79 109 } 110 if (noteData.getSelectedNote() != null) { 111 StringBuilder sb = new StringBuilder("<html>"); 112 List<NoteComment> comments = noteData.getSelectedNote().getComments(); 113 String sep = ""; 114 SimpleDateFormat dayFormat = new SimpleDateFormat("MMM d, yyyy"); 115 for (NoteComment comment : comments) { 116 String commentText = comment.getText(); 117 //closing a note creates an empty comment that we don't want to show 118 if (commentText != null && commentText.trim().length() > 0) { 119 sb.append(sep); 120 String userName = comment.getUser().getName(); 121 if (userName == null || userName.trim().length() == 0) { 122 userName = "<Anonymous>"; 123 } 124 sb.append(userName); 125 sb.append(" on "); 126 sb.append(dayFormat.format(comment.getCommentTimestamp())); 127 sb.append(":<br/>"); 128 String htmlText = XmlWriter.encode(comment.getText(), true); 129 htmlText = htmlText.replace("
", "<br/>"); //encode method leaves us with entity instead of \n 130 sb.append(htmlText); 131 } 132 sep = "<hr/>"; 133 } 134 sb.append("</html>"); 135 JToolTip toolTip = new JToolTip(); 136 toolTip.setTipText(sb.toString()); 137 Point p = mv.getPoint(noteData.getSelectedNote().getLatLon()); 138 139 g.setColor(ColorHelper.html2color(Main.pref.get("color.selected"))); 140 g.drawRect(p.x - (NoteDialog.ICON_SMALL_SIZE / 2), p.y - NoteDialog.ICON_SMALL_SIZE, NoteDialog.ICON_SMALL_SIZE - 1, NoteDialog.ICON_SMALL_SIZE - 1); 141 142 int tx = p.x + (NoteDialog.ICON_SMALL_SIZE / 2) + 5; 143 int ty = p.y - NoteDialog.ICON_SMALL_SIZE - 1; 144 g.translate(tx, ty); 145 146 //Carried over from the OSB plugin. Not entirely sure why it is needed 147 //but without it, the tooltip doesn't get sized correctly 148 for (int x = 0; x < 2; x++) { 149 Dimension d = toolTip.getUI().getPreferredSize(toolTip); 150 d.width = Math.min(d.width, (mv.getWidth() * 1 / 2)); 151 toolTip.setSize(d); 152 toolTip.paint(g); 153 } 154 g.translate(-tx, -ty); 155 } 80 156 } 81 157 82 158 @Override 83 159 public Icon getIcon() { 84 return ImageProvider.get("notes", "note_open_16x16.png");160 return NoteDialog.ICON_OPEN_SMALL; 85 161 } 86 162 87 163 @Override 88 164 public String getToolTipText() { 89 return note s.size() + " " + tr("Notes");165 return noteData.getNotes().size() + " " + tr("Notes"); 90 166 } 91 167 … … 111 187 sb.append(tr("Total notes:")); 112 188 sb.append(" "); 113 sb.append(note s.size());189 sb.append(noteData.getNotes().size()); 114 190 sb.append("\n"); 115 191 sb.append(tr("Changes need uploading?")); … … 128 204 } 129 205 130 /** 131 * Returns the notes stored in this layer 132 * @return List of Note objects 133 */ 134 public List<Note> getNotes() { 135 return notes; 136 } 137 138 /** 139 * Add notes to the layer. It only adds a note if the ID is not already present 140 * @param newNotes A list of notes to add 141 */ 142 public void addNotes(List<Note> newNotes) { 143 for (Note newNote : newNotes) { 144 if (!notes.contains(newNote)) { 145 notes.add(newNote); 146 } 147 } 148 Main.map.mapView.repaint(); 149 Main.debug("notes in layer: " + notes.size()); 150 } 206 @Override 207 public void mouseClicked(MouseEvent e) { 208 if (e.getButton() != MouseEvent.BUTTON1) { 209 return; 210 } 211 Point clickPoint = e.getPoint(); 212 double snapDistance = 10; 213 double minDistance = Double.MAX_VALUE; 214 Note closestNote = null; 215 for (Note note : noteData.getNotes()) { 216 Point notePoint = Main.map.mapView.getPoint(note.getLatLon()); 217 //move the note point to the center of the icon where users are most likely to click when selecting 218 notePoint.setLocation(notePoint.getX(), notePoint.getY() - NoteDialog.ICON_SMALL_SIZE / 2); 219 double dist = clickPoint.distanceSq(notePoint); 220 if (minDistance > dist && clickPoint.distance(notePoint) < snapDistance ) { 221 minDistance = dist; 222 closestNote = note; 223 } 224 } 225 noteData.setSelectedNote(closestNote); 226 } 227 228 @Override 229 public void mousePressed(MouseEvent e) { } 230 231 @Override 232 public void mouseReleased(MouseEvent e) { } 233 234 @Override 235 public void mouseEntered(MouseEvent e) { } 236 237 @Override 238 public void mouseExited(MouseEvent e) { } 151 239 } -
trunk/src/org/openstreetmap/josm/io/NoteImporter.java
r7538 r7608 52 52 if (noteLayers != null && noteLayers.size() > 0) { 53 53 NoteLayer layer = noteLayers.get(0); 54 layer. addNotes(fileNotes);54 layer.getNoteData().addNotes(fileNotes); 55 55 } else { 56 56 GuiHelper.runInEDT(new Runnable() {
Note:
See TracChangeset
for help on using the changeset viewer.