Changeset 8264 in josm
- Timestamp:
- 2015-04-25T17:04:23+02:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/NoteLayer.java
r8235 r8264 2 2 package org.openstreetmap.josm.gui.layer; 3 3 4 import static org.openstreetmap.josm.tools.I18n.marktr;5 4 import static org.openstreetmap.josm.tools.I18n.tr; 6 5 7 import java.awt. Color;6 import java.awt.Dimension; 8 7 import java.awt.Graphics2D; 9 8 import java.awt.Point; … … 18 17 19 18 import javax.swing.Action; 20 import javax.swing.BorderFactory;21 19 import javax.swing.Icon; 22 20 import javax.swing.ImageIcon; 23 import javax.swing.JT extArea;21 import javax.swing.JToolTip; 24 22 25 23 import org.openstreetmap.josm.Main; … … 31 29 import org.openstreetmap.josm.data.osm.NoteData; 32 30 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 33 import org.openstreetmap.josm.data.preferences.ColorProperty;34 31 import org.openstreetmap.josm.gui.MapView; 35 32 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; … … 37 34 import org.openstreetmap.josm.gui.dialogs.NotesDialog; 38 35 import org.openstreetmap.josm.io.NoteExporter; 36 import org.openstreetmap.josm.io.XmlWriter; 39 37 import org.openstreetmap.josm.tools.ColorHelper; 40 38 import org.openstreetmap.josm.tools.date.DateUtils; … … 46 44 47 45 private final NoteData noteData; 48 49 /**50 * Property for note comment background51 */52 public static final ColorProperty PROP_BACKGROUND_COLOR = new ColorProperty(53 marktr("Note comment background"), Color.decode("#b8cfe5"));54 46 55 47 /** … … 102 94 103 95 @Override 104 public void paint(Graphics2D g, finalMapView mv, Bounds box) {96 public void paint(Graphics2D g, MapView mv, Bounds box) { 105 97 for (Note note : noteData.getNotes()) { 106 98 Point p = mv.getPoint(note.getLatLon()); … … 119 111 } 120 112 if (noteData.getSelectedNote() != null) { 121 StringBuilder sb = new StringBuilder(); 113 StringBuilder sb = new StringBuilder("<html>"); 122 114 sb.append(tr("Note")); 123 115 sb.append(" ").append(noteData.getSelectedNote().getId()); … … 126 118 //closing a note creates an empty comment that we don't want to show 127 119 if (commentText != null && commentText.trim().length() > 0) { 128 sb.append("\n\n"); 129 String userName = comment.getUser().getName().trim(); 130 sb.append(userName.isEmpty() ? "<Anonymous>" : userName); 120 sb.append("<hr/>"); 121 String userName = XmlWriter.encode(comment.getUser().getName()); 122 if (userName == null || userName.trim().length() == 0) { 123 userName = "<Anonymous>"; 124 } 125 sb.append(userName); 131 126 sb.append(" on "); 132 127 sb.append(DateUtils.getDateFormat(DateFormat.MEDIUM).format(comment.getCommentTimestamp())); 133 sb.append(":\n"); 134 sb.append(comment.getText().trim()); 128 sb.append(":<br/>"); 129 String htmlText = XmlWriter.encode(comment.getText(), true); 130 htmlText = htmlText.replace("
", "<br/>"); //encode method leaves us with entity instead of \n 131 htmlText = htmlText.replace("/", "/\u200b"); //zero width space to wrap long URLs (see #10864) 132 sb.append(htmlText); 135 133 } 136 134 } 137 JTextArea toolTip = new JTextArea() { 138 { 139 setColumns(Math.min(480, mv.getWidth() / 2) / getColumnWidth()); 140 setSize(getPreferredSize().width + 6, getPreferredSize().height + 6); // +6 for border 141 } 142 }; 143 toolTip.setText(sb.toString()); 144 toolTip.setLineWrap(true); 145 toolTip.setWrapStyleWord(true); 146 toolTip.setBackground(PROP_BACKGROUND_COLOR.get()); 147 toolTip.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); 148 135 sb.append("</html>"); 136 JToolTip toolTip = new JToolTip(); 137 toolTip.setTipText(sb.toString()); 149 138 Point p = mv.getPoint(noteData.getSelectedNote().getLatLon()); 150 139 … … 155 144 int ty = p.y - NotesDialog.ICON_SMALL_SIZE - 1; 156 145 g.translate(tx, ty); 157 toolTip.paint(g); 146 147 //Carried over from the OSB plugin. Not entirely sure why it is needed 148 //but without it, the tooltip doesn't get sized correctly 149 for (int x = 0; x < 2; x++) { 150 Dimension d = toolTip.getUI().getPreferredSize(toolTip); 151 d.width = Math.min(d.width, (mv.getWidth() / 2)); 152 if (d.width > 0 && d.height > 0) { 153 toolTip.setSize(d); 154 try { 155 toolTip.paint(g); 156 } catch (IllegalArgumentException e) { 157 // See #11123 - https://bugs.openjdk.java.net/browse/JDK-6719550 158 // Ignore the exception, as Netbeans does: http://hg.netbeans.org/main-silver/rev/c96f4d5fbd20 159 Main.error(e, false); 160 } 161 } 162 } 158 163 g.translate(-tx, -ty); 159 164 }
Note:
See TracChangeset
for help on using the changeset viewer.