Changeset 11539 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2017-02-04T16:19:52+01:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageDisplay.java
r11535 r11539 166 166 if (e.getWhen() - lastTimeForMousePoint > 1500 || mousePointInImg == null) { 167 167 lastTimeForMousePoint = e.getWhen(); 168 mousePointInImg = comp2imgCoord(visibleRect, e.getX(), e.getY() );168 mousePointInImg = comp2imgCoord(visibleRect, e.getX(), e.getY(), getSize()); 169 169 } 170 170 … … 199 199 200 200 // Set the position of the visible rectangle, so that the mouse cursor doesn't move on the image. 201 Rectangle drawRect = calculateDrawImageRectangle(visibleRect );201 Rectangle drawRect = calculateDrawImageRectangle(visibleRect, getSize()); 202 202 visibleRect.x = mousePointInImg.x + ((drawRect.x - e.getX()) * visibleRect.width) / drawRect.width; 203 203 visibleRect.y = mousePointInImg.y + ((drawRect.y - e.getY()) * visibleRect.height) / drawRect.height; … … 235 235 236 236 // Calculate the translation to set the clicked point the center of the view. 237 Point click = comp2imgCoord(visibleRect, e.getX(), e.getY() );237 Point click = comp2imgCoord(visibleRect, e.getX(), e.getY(), getSize()); 238 238 Point center = getCenterImgCoord(visibleRect); 239 239 … … 273 273 274 274 if (e.getButton() == DRAG_BUTTON) { 275 mousePointInImg = comp2imgCoord(visibleRect, e.getX(), e.getY() );275 mousePointInImg = comp2imgCoord(visibleRect, e.getX(), e.getY(), getSize()); 276 276 mouseIsDragging = true; 277 277 selectedRect = null; 278 278 } else if (e.getButton() == ZOOM_BUTTON) { 279 mousePointInImg = comp2imgCoord(visibleRect, e.getX(), e.getY() );279 mousePointInImg = comp2imgCoord(visibleRect, e.getX(), e.getY(), getSize()); 280 280 checkPointInVisibleRect(mousePointInImg, visibleRect); 281 281 mouseIsDragging = false; … … 310 310 311 311 if (mouseIsDragging) { 312 Point p = comp2imgCoord(visibleRect, e.getX(), e.getY() );312 Point p = comp2imgCoord(visibleRect, e.getX(), e.getY(), getSize()); 313 313 visibleRect.x += mousePointInImg.x - p.x; 314 314 visibleRect.y += mousePointInImg.y - p.y; … … 322 322 323 323 } else if (selectedRect != null) { 324 Point p = comp2imgCoord(visibleRect, e.getX(), e.getY() );324 Point p = comp2imgCoord(visibleRect, e.getX(), e.getY(), getSize()); 325 325 checkPointInVisibleRect(p, visibleRect); 326 326 Rectangle rect = new Rectangle( … … 432 432 } 433 433 434 /** 435 * Constructs a new {@code ImageDisplay}. 436 */ 434 437 public ImageDisplay() { 435 438 ImgDisplayMouseListener mouseListener = new ImgDisplayMouseListener(); … … 471 474 } 472 475 476 Dimension size = getSize(); 473 477 if (file == null) { 474 478 g.setColor(Color.black); 475 479 String noImageStr = tr("No image"); 476 480 Rectangle2D noImageSize = g.getFontMetrics(g.getFont()).getStringBounds(noImageStr, g); 477 Dimension size = getSize();478 481 g.drawString(noImageStr, 479 482 (int) ((size.width - noImageSize.getWidth()) / 2), … … 488 491 } 489 492 Rectangle2D noImageSize = g.getFontMetrics(g.getFont()).getStringBounds(loadingStr, g); 490 Dimension size = getSize();491 493 g.drawString(loadingStr, 492 494 (int) ((size.width - noImageSize.getWidth()) / 2), 493 495 (int) ((size.height - noImageSize.getHeight()) / 2)); 494 496 } else { 495 Rectangle target = calculateDrawImageRectangle(visibleRect );497 Rectangle target = calculateDrawImageRectangle(visibleRect, size); 496 498 g.drawImage(image, 497 499 target.x, target.y, target.x + target.width, target.y + target.height, … … 499 501 null); 500 502 if (selectedRect != null) { 501 Point topLeft = img2compCoord(visibleRect, selectedRect.x, selectedRect.y );503 Point topLeft = img2compCoord(visibleRect, selectedRect.x, selectedRect.y, size); 502 504 Point bottomRight = img2compCoord(visibleRect, 503 505 selectedRect.x + selectedRect.width, 504 selectedRect.y + selectedRect.height );506 selectedRect.y + selectedRect.height, size); 505 507 g.setColor(new Color(128, 128, 128, 180)); 506 508 g.fillRect(target.x, target.y, target.width, topLeft.y - target.y); … … 514 516 String loadingStr = tr("Error on file {0}", file.getName()); 515 517 Rectangle2D noImageSize = g.getFontMetrics(g.getFont()).getStringBounds(loadingStr, g); 516 Dimension size = getSize();517 518 g.drawString(loadingStr, 518 519 (int) ((size.width - noImageSize.getWidth()) / 2), … … 550 551 } 551 552 552 private Point img2compCoord(Rectangle visibleRect, int xImg, int yImg) {553 Rectangle drawRect = calculateDrawImageRectangle(visibleRect );553 static Point img2compCoord(Rectangle visibleRect, int xImg, int yImg, Dimension compSize) { 554 Rectangle drawRect = calculateDrawImageRectangle(visibleRect, compSize); 554 555 return new Point(drawRect.x + ((xImg - visibleRect.x) * drawRect.width) / visibleRect.width, 555 556 drawRect.y + ((yImg - visibleRect.y) * drawRect.height) / visibleRect.height); 556 557 } 557 558 558 private Point comp2imgCoord(Rectangle visibleRect, int xComp, int yComp) {559 Rectangle drawRect = calculateDrawImageRectangle(visibleRect );559 static Point comp2imgCoord(Rectangle visibleRect, int xComp, int yComp, Dimension compSize) { 560 Rectangle drawRect = calculateDrawImageRectangle(visibleRect, compSize); 560 561 return new Point(visibleRect.x + ((xComp - drawRect.x) * visibleRect.width) / drawRect.width, 561 562 visibleRect.y + ((yComp - drawRect.y) * visibleRect.height) / drawRect.height); 562 563 } 563 564 564 privatestatic Point getCenterImgCoord(Rectangle visibleRect) {565 static Point getCenterImgCoord(Rectangle visibleRect) { 565 566 return new Point(visibleRect.x + visibleRect.width / 2, 566 visibleRect.y + visibleRect.height / 2);567 } 568 569 private Rectangle calculateDrawImageRectangle(Rectangle visibleRect) {570 return calculateDrawImageRectangle(visibleRect, new Rectangle(0, 0, getSize().width, getSize().height));567 visibleRect.y + visibleRect.height / 2); 568 } 569 570 static Rectangle calculateDrawImageRectangle(Rectangle visibleRect, Dimension compSize) { 571 return calculateDrawImageRectangle(visibleRect, new Rectangle(0, 0, compSize.width, compSize.height)); 571 572 } 572 573 … … 579 580 */ 580 581 static Rectangle calculateDrawImageRectangle(Rectangle imgRect, Rectangle compRect) { 581 int x, y, w, h; 582 x = 0; 583 y = 0; 584 w = compRect.width; 585 h = compRect.height; 582 int x = 0; 583 int y = 0; 584 int w = compRect.width; 585 int h = compRect.height; 586 586 587 587 int wFact = w * imgRect.height; … … 633 633 } 634 634 635 privatestatic void checkVisibleRectPos(Image image, Rectangle visibleRect) {635 static void checkVisibleRectPos(Image image, Rectangle visibleRect) { 636 636 if (visibleRect.x < 0) { 637 637 visibleRect.x = 0; … … 648 648 } 649 649 650 privatestatic void checkVisibleRectSize(Image image, Rectangle visibleRect) {650 static void checkVisibleRectSize(Image image, Rectangle visibleRect) { 651 651 if (visibleRect.width > image.getWidth(null)) { 652 652 visibleRect.width = image.getWidth(null);
Note:
See TracChangeset
for help on using the changeset viewer.