Changeset 8213 in josm
- Timestamp:
- 2015-04-18T10:41:38+02:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/NoteLayer.java
r8079 r8213 2 2 package org.openstreetmap.josm.gui.layer; 3 3 4 import static org.openstreetmap.josm.tools.I18n.marktr; 4 5 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 6 import java.awt. Dimension;7 import java.awt.Color; 7 8 import java.awt.Graphics2D; 8 9 import java.awt.Point; … … 10 11 import java.awt.event.MouseListener; 11 12 import java.io.File; 12 import java.text. SimpleDateFormat;13 import java.text.DateFormat; 13 14 import java.util.ArrayList; 14 15 import java.util.List; 15 16 16 17 import javax.swing.Action; 18 import javax.swing.BorderFactory; 17 19 import javax.swing.Icon; 18 20 import javax.swing.ImageIcon; 19 import javax.swing.JT oolTip;21 import javax.swing.JTextArea; 20 22 21 23 import org.openstreetmap.josm.Main; … … 27 29 import org.openstreetmap.josm.data.osm.NoteData; 28 30 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 31 import org.openstreetmap.josm.data.preferences.ColorProperty; 29 32 import org.openstreetmap.josm.gui.MapView; 30 33 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; … … 32 35 import org.openstreetmap.josm.gui.dialogs.NotesDialog; 33 36 import org.openstreetmap.josm.io.NoteExporter; 34 import org.openstreetmap.josm.io.XmlWriter;35 37 import org.openstreetmap.josm.tools.ColorHelper; 38 import org.openstreetmap.josm.tools.date.DateUtils; 36 39 37 40 /** … … 41 44 42 45 private final NoteData noteData; 46 47 /** 48 * Property for note comment background 49 */ 50 public static final ColorProperty PROP_BACKGROUND_COLOR = new ColorProperty( 51 marktr("Note comment background"), Color.decode("#b8cfe5")); 43 52 44 53 /** … … 110 119 } 111 120 if (noteData.getSelectedNote() != null) { 112 StringBuilder sb = new StringBuilder( "<html>");121 StringBuilder sb = new StringBuilder(); 113 122 sb.append(tr("Note")); 114 sb.append(" " + noteData.getSelectedNote().getId()); 115 List<NoteComment> comments = noteData.getSelectedNote().getComments(); 116 SimpleDateFormat dayFormat = new SimpleDateFormat("MMM d, yyyy"); 117 for (NoteComment comment : comments) { 123 sb.append(" ").append(noteData.getSelectedNote().getId()); 124 for (NoteComment comment : noteData.getSelectedNote().getComments()) { 118 125 String commentText = comment.getText(); 119 126 //closing a note creates an empty comment that we don't want to show 120 127 if (commentText != null && commentText.trim().length() > 0) { 121 sb.append("<hr/>"); 122 String userName = XmlWriter.encode(comment.getUser().getName()); 123 if (userName == null || userName.trim().length() == 0) { 124 userName = "<Anonymous>"; 125 } 126 sb.append(userName); 128 sb.append("\n\n"); 129 String userName = comment.getUser().getName().trim(); 130 sb.append(userName.isEmpty() ? "<Anonymous>" : userName); 127 131 sb.append(" on "); 128 sb.append(dayFormat.format(comment.getCommentTimestamp())); 129 sb.append(":<br/>"); 130 String htmlText = XmlWriter.encode(comment.getText(), true); 131 htmlText = htmlText.replace("
", "<br/>"); //encode method leaves us with entity instead of \n 132 sb.append(htmlText); 132 sb.append(DateUtils.getDateFormat(DateFormat.MEDIUM).format(comment.getCommentTimestamp())); 133 sb.append(":\n"); 134 sb.append(comment.getText().trim()); 133 135 } 134 136 } 135 sb.append("</html>"); 136 JToolTip toolTip = new JToolTip(); 137 toolTip.setTipText(sb.toString()); 137 JTextArea toolTip = new JTextArea(); 138 toolTip.setText(sb.toString()); 139 toolTip.setLineWrap(true); 140 toolTip.setWrapStyleWord(true); 141 toolTip.setBackground(PROP_BACKGROUND_COLOR.get()); 142 toolTip.setSize(Math.min(480, mv.getWidth() / 2), 1); 143 toolTip.setSize(toolTip.getPreferredSize().width + 6, toolTip.getPreferredSize().height + 6); // +6 for border 144 toolTip.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); 145 138 146 Point p = mv.getPoint(noteData.getSelectedNote().getLatLon()); 139 147 … … 144 152 int ty = p.y - NotesDialog.ICON_SMALL_SIZE - 1; 145 153 g.translate(tx, ty); 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() * 1 / 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 } 154 toolTip.paint(g); 163 155 g.translate(-tx, -ty); 164 156 }
Note:
See TracChangeset
for help on using the changeset viewer.