Skip to content

Commit

Permalink
Resize panorama view when panel resizes
Browse files Browse the repository at this point in the history
  • Loading branch information
floscher committed Jul 14, 2018
1 parent f51d2c7 commit 583f5f3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
Expand Up @@ -5,13 +5,16 @@

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
Expand All @@ -22,14 +25,12 @@
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.Collection;
import java.util.stream.IntStream;

import javax.swing.JComponent;

import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer;
import org.openstreetmap.josm.plugins.mapillary.actions.MapillaryDownloadAction;
import org.openstreetmap.josm.plugins.mapillary.gui.panorama.CameraPlane;
import org.openstreetmap.josm.plugins.mapillary.gui.panorama.Vector3D;
import org.openstreetmap.josm.plugins.mapillary.model.ImageDetection;
import org.openstreetmap.josm.plugins.mapillary.model.MapObject;
import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryColorScheme;
Expand All @@ -46,6 +47,7 @@
public class MapillaryImageDisplay extends JComponent {

private static final long serialVersionUID = 3369727203329307716L;
private static final double PANORAMA_FOV = Math.toRadians(110);

private final Collection<ImageDetection> detections = new ArrayList<>();

Expand Down Expand Up @@ -394,11 +396,12 @@ private void checkPointInVisibleRect(Point p, Rectangle visibleRect) {
/**
* Main constructor.
*/
public MapillaryImageDisplay() {
MapillaryImageDisplay() {
ImgDisplayMouseListener mouseListener = new ImgDisplayMouseListener();
addMouseListener(mouseListener);
addMouseWheelListener(mouseListener);
addMouseMotionListener(mouseListener);
addComponentListener(new ComponentSizeListener());

MapillaryProperties.SHOW_DETECTED_SIGNS.addListener(valChanged -> repaint());
}
Expand All @@ -409,7 +412,7 @@ public MapillaryImageDisplay() {
* @param image The picture to be displayed.
* @param detections image detections
*/
public void setImage(BufferedImage image, Collection<ImageDetection> detections, boolean pano) {
void setImage(BufferedImage image, Collection<ImageDetection> detections, boolean pano) {
synchronized (this) {
this.image = image;
this.pano = pano;
Expand All @@ -419,17 +422,8 @@ public void setImage(BufferedImage image, Collection<ImageDetection> detections,
}
this.selectedRect = null;
if (image != null) {
Dimension s = getSize();
if (pano && ( image.getWidth(null) < 2048 || image.getWidth(null) != image.getHeight(null) * 2
|| s.width < 800 || s.height < 400)) {
this.pano = false;
}
if (this.pano) {
this.visibleRect = new Rectangle(0, 0, s.width, s.height);
offscreenImage = new BufferedImage(s.width, s.height, BufferedImage.TYPE_3BYTE_BGR);
double FOV = Math.toRadians(110);
double cameraPlaneDistance = (s.width / 2) / Math.tan(FOV / 2);
cameraPlane = new CameraPlane(s.width, s.height, cameraPlaneDistance);
this.visibleRect = new Rectangle(0, 0, getSize().width, getSize().height);
} else {
this.visibleRect = new Rectangle(0, 0, image.getWidth(null),
image.getHeight(null));
Expand Down Expand Up @@ -631,4 +625,21 @@ private static void checkVisibleRectSize(Image image, Rectangle visibleRect) {
visibleRect.height = image.getHeight(null);
}
}

private static class ComponentSizeListener extends ComponentAdapter {
@Override
public void componentResized(ComponentEvent e) {
final Component component = e.getComponent();
if (component instanceof MapillaryImageDisplay) {
final MapillaryImageDisplay imgDisplay = (MapillaryImageDisplay) component;
imgDisplay.offscreenImage = new BufferedImage(
e.getComponent().getWidth(),
e.getComponent().getHeight(),
BufferedImage.TYPE_3BYTE_BGR
);
final double cameraPlaneDistance = (e.getComponent().getWidth() / 2) / Math.tan(PANORAMA_FOV / 2);
imgDisplay.cameraPlane = new CameraPlane(e.getComponent().getWidth(), e.getComponent().getHeight(), cameraPlaneDistance);
}
}
}
}
Expand Up @@ -274,7 +274,11 @@ public synchronized void updateImage(boolean fullQuality) {
} else if (this.image instanceof MapillaryImportedImage) {
MapillaryImportedImage mapillaryImage = (MapillaryImportedImage) this.image;
try {
this.mapillaryImageDisplay.setImage(mapillaryImage.getImage(), null, false);
this.mapillaryImageDisplay.setImage(
mapillaryImage.getImage(),
null,
mapillaryImage != null && mapillaryImage.isPanorama()
);
} catch (IOException e) {
Logging.error(e);
}
Expand Down Expand Up @@ -563,7 +567,7 @@ public void loadingFinished(final CacheEntry data, final CacheEntryAttributes at
* @param data The content of the dialog
* @param buttons The buttons where you can click
*/
public void createLayout(Component data, List<SideButton> buttons) {
private void createLayout(Component data, List<SideButton> buttons) {
removeAll();
createLayout(data, true, buttons);
add(titleBar, BorderLayout.NORTH);
Expand Down

0 comments on commit 583f5f3

Please sign in to comment.