Changeset 13165 in josm for trunk/src/org
- Timestamp:
- 2017-11-25T22:50:44+01:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/NoteLayer.java
r13162 r13165 82 82 private static final Pattern HTTP_LINK = Pattern.compile("(https?://[^\\s\\(\\)<>]+)"); 83 83 private static final Pattern HTML_LINK = Pattern.compile("<a href=\"[^\"]+\">([^<]+)</a>"); 84 private static final Pattern HTML_LINK_MARK = Pattern.compile("<a href=\"([^\"]+)([\\.\\?\\!])\">([^<]+)(?:[\\.\\?\\!])</a>"); 84 85 private static final Pattern SLASH = Pattern.compile("([^/])/([^/])"); 85 86 … … 203 204 } 204 205 205 Point screenloc = mv.getLocationOnScreen(); 206 int tx = screenloc.x + p.x + (iconWidth / 2) + 5; 207 int ty = screenloc.y + p.y - iconHeight - 1; 206 int xl = p.x - (iconWidth / 2) - 5; 207 int xr = p.x + (iconWidth / 2) + 5; 208 int yb = p.y - iconHeight - 1; 209 int yt = p.y + (iconHeight / 2) + 2; 210 Point pTooltip; 208 211 209 212 String text = getNoteToolTip(selectedNote); … … 216 219 displayedPanel.setBorder(BorderFactory.createLineBorder(Color.black)); 217 220 displayedPanel.enableClickableHyperlinks(); 218 fixPanelSize(mv, text);221 pTooltip = fixPanelSizeAndLocation(mv, text, xl, xr, yt, yb); 219 222 displayedWindow = new JWindow((MainFrame) Main.parent); 220 223 displayedWindow.setAutoRequestFocus(false); … … 225 228 } else { 226 229 displayedPanel.setText(text); 227 fixPanelSize(mv, text);230 pTooltip = fixPanelSizeAndLocation(mv, text, xl, xr, yt, yb); 228 231 } 229 232 230 233 displayedWindow.pack(); 231 displayedWindow.setLocation( tx, ty);234 displayedWindow.setLocation(pTooltip); 232 235 displayedWindow.setVisible(mv.contains(p)); 233 236 displayedNote = selectedNote; 234 237 } 235 238 236 private void fixPanelSize(MapView mv, String text) { 237 int maxWidth = mv.getWidth() * 2/3; 238 int maxHeight = mv.getHeight() * 2/3; 239 private Point fixPanelSizeAndLocation(MapView mv, String text, int xl, int xr, int yt, int yb) { 240 int leftMaxWidth = (int) (0.95 * xl); 241 int rightMaxWidth = (int) (0.95 * mv.getWidth() - xr); 242 int topMaxHeight = (int) (0.95 * yt); 243 int bottomMaxHeight = (int) (0.95 * mv.getHeight() - yb); 244 int maxWidth = Math.max(leftMaxWidth, rightMaxWidth); 245 int maxHeight = Math.max(topMaxHeight, bottomMaxHeight); 239 246 JEditorPane pane = displayedPanel.getEditorPane(); 240 247 Dimension d = pane.getPreferredSize(); … … 253 260 if (v != null) { 254 261 v.setSize(maxWidth, 0); 255 int w = (int) Math.ceil(v.getPreferredSpan(View.X_AXIS)) + 30;262 int w = (int) Math.ceil(v.getPreferredSpan(View.X_AXIS)); 256 263 int h = (int) Math.ceil(v.getPreferredSpan(View.Y_AXIS)) + 10; 257 264 pane.setPreferredSize(new Dimension(w, h)); 258 265 } 259 266 } 267 d = pane.getPreferredSize(); 268 // place tooltip on left or right side of icon, based on its width 269 Point screenloc = mv.getLocationOnScreen(); 270 return new Point( 271 screenloc.x + (d.width > rightMaxWidth && d.width <= leftMaxWidth ? xl - d.width : xr), 272 screenloc.y + (d.height > bottomMaxHeight && d.height <= topMaxHeight ? yt - d.height - 10 : yb)); 260 273 } 261 274 … … 309 322 static String replaceLinks(String htmlText) { 310 323 String result = HTTP_LINK.matcher(htmlText).replaceAll("<a href=\"$1\">$1</a>"); 324 result = HTML_LINK_MARK.matcher(result).replaceAll("<a href=\"$1\">$3</a>$2"); 311 325 Matcher m1 = HTML_LINK.matcher(result); 312 326 if (m1.find()) {
Note:
See TracChangeset
for help on using the changeset viewer.