    001//License: GPL. For details, see LICENSE file.
    002package org.openstreetmap.josm.plugins.streetside.gui.imageinfo;
    003
    004import java.awt.BorderLayout;
    005
    006import javax.swing.JCheckBox;
    007import javax.swing.JPanel;
    008import javax.swing.SwingUtilities;
    009
    010import org.openstreetmap.josm.data.preferences.AbstractProperty.ValueChangeListener;
    011import org.openstreetmap.josm.plugins.streetside.StreetsideAbstractImage;
    012import org.openstreetmap.josm.plugins.streetside.StreetsideDataListener;
    013import org.openstreetmap.josm.plugins.streetside.StreetsideImage;
    014import org.openstreetmap.josm.plugins.streetside.actions.ImageReloadAction;
    015import org.openstreetmap.josm.plugins.streetside.cubemap.CubemapBuilder;
    016import org.openstreetmap.josm.plugins.streetside.cubemap.CubemapUtils;
    017import org.openstreetmap.josm.plugins.streetside.cubemap.GraphicsUtils;
    018import org.openstreetmap.josm.plugins.streetside.gui.boilerplate.StreetsideButton;
    019import org.openstreetmap.josm.plugins.streetside.utils.CubemapBox;
    020import org.openstreetmap.josm.plugins.streetside.utils.StreetsideProperties;
    021import org.openstreetmap.josm.plugins.streetside.utils.StreetsideURL;
    022import org.openstreetmap.josm.tools.I18n;
    023import org.openstreetmap.josm.tools.Logging;
    024
    025
    026public final class StreetsideViewerPanel extends JPanel
    027                implements StreetsideDataListener {
    028
    029        private static final long serialVersionUID = 4141847503072417190L;
    030
    031        private JCheckBox highResImageryCheck;
    032        private WebLinkAction imgLinkAction;
    033        private ImageReloadAction imgReloadAction;
    034        private ValueChangeListener<Boolean> imageLinkChangeListener;
    035
    036        private static ThreeSixtyDegreeViewerPanel threeSixtyDegreeViewerPanel;
    037
    038        public StreetsideViewerPanel() {
    039
    040                super(new BorderLayout());
    041
    042                SwingUtilities.invokeLater(new Runnable() {
    043                     @Override
    044                     public void run() {
    045                         initializeAndStartGUI();
    046                     }
    047                 });
    048
    049                selectedImageChanged(null, null);
    050
    051                setToolTipText(I18n.tr("Select Microsoft Streetside from the Imagery menu, then click on a blue vector bubble.."));
    052        }
    053
    054        private void initializeAndStartGUI() {
    055
    056                threeSixtyDegreeViewerPanel = new ThreeSixtyDegreeViewerPanel();
    057
    058                GraphicsUtils.PlatformHelper.run(() -> {
    059                threeSixtyDegreeViewerPanel.initialize();
    060                });
    061
    062                add(threeSixtyDegreeViewerPanel, BorderLayout.CENTER);
    063                revalidate();
    064                repaint();
    065            JPanel checkPanel = new JPanel();
    066
    067            imgReloadAction = new ImageReloadAction(I18n.tr("Reload"));
    068
    069            StreetsideButton imgReloadButton = new StreetsideButton(imgReloadAction);
    070                  highResImageryCheck = new JCheckBox(I18n.tr("High resolution"));
    071            highResImageryCheck.setSelected(StreetsideProperties.SHOW_HIGH_RES_STREETSIDE_IMAGERY.get());
    072            highResImageryCheck.addActionListener(
    073              action -> StreetsideProperties.SHOW_HIGH_RES_STREETSIDE_IMAGERY.put(highResImageryCheck.isSelected())
    074            );
    075            StreetsideProperties.SHOW_HIGH_RES_STREETSIDE_IMAGERY.addListener(
    076              valueChange -> highResImageryCheck.setSelected(StreetsideProperties.SHOW_HIGH_RES_STREETSIDE_IMAGERY.get())
    077            );
    078            checkPanel.add(highResImageryCheck, BorderLayout.WEST);
    079            checkPanel.add(imgReloadButton, BorderLayout.EAST);
    080
    081            JPanel privacyLink = new JPanel();
    082
    083            imgLinkAction = new WebLinkAction(I18n.tr("Report a privacy concern with this image"), null);
    084            privacyLink.add(new StreetsideButton(imgLinkAction, true));
    085            checkPanel.add(privacyLink, BorderLayout.PAGE_END);
    086
    087            //add(checkPanel, BorderLayout.PAGE_START);
    088            add(threeSixtyDegreeViewerPanel, BorderLayout.CENTER);
    089
    090            JPanel bottomPanel = new JPanel();
    091            bottomPanel.add(checkPanel, BorderLayout.NORTH);
    092            bottomPanel.add(privacyLink, BorderLayout.SOUTH);
    093
    094            add(bottomPanel, BorderLayout.PAGE_END);
    095        }
    096
    097        /*
    098         * (non-Javadoc)
    099         *
    100         * @see
    101         * org.openstreetmap.josm.plugins.streetside.StreetsideDataListener#imagesAdded(
    102         * )
    103         */
    104        @Override
    105        public void imagesAdded() {
    106                // Method is not needed, but enforcesd by the interface StreetsideDataListener
    107        }
    108
    109        /*
    110         * (non-Javadoc)
    111         *
    112         * @see org.openstreetmap.josm.plugins.streetside.StreetsideDataListener#
    113         * selectedImageChanged(org.openstreetmap.josm.plugins.streetside.
    114         * StreetsideAbstractImage,
    115         * org.openstreetmap.josm.plugins.streetside.StreetsideAbstractImage)
    116         */
    117        @Override
    118        public synchronized void selectedImageChanged(final StreetsideAbstractImage oldImage,
    119                        final StreetsideAbstractImage newImage) {
    120
    121                // method is invoked with null initially by framework
    122                if(newImage!=null) {
    123
    124                    Logging.debug(String.format(
    125                      "Selected Streetside image changed from %s to %s.",
    126                      oldImage instanceof StreetsideImage ? ((StreetsideImage) oldImage).getId() : "‹none›",
    127                      newImage instanceof StreetsideImage ? ((StreetsideImage) newImage).getId() : "‹none›"
    128                    ));
    129
    130                    //imgIdValue.setEnabled(newImage instanceof StreetsideImage);
    131                    //final String newImageId = newImage instanceof StreetsideImage ? ((StreetsideImage) newImage).getId(): null;
    132                    final String newImageId = CubemapBuilder.getInstance().getCubemap() !=null ? CubemapBuilder.getInstance().getCubemap().getId() : newImage instanceof StreetsideImage ? ((StreetsideImage) newImage).getId(): null;;
    133                    if (newImageId != null) {
    134                      final String bubbleId = CubemapUtils.convertQuaternary2Decimal(newImageId);
    135                      imageLinkChangeListener = b -> imgLinkAction.setURL(
    136                        StreetsideURL.MainWebsite.streetsidePrivacyLink(bubbleId)
    137                      );
    138
    139                      Logging.debug(I18n.tr("Privacy link invoked for Streetside image {0}", bubbleId));
    140
    141                      imageLinkChangeListener.valueChanged(null);
    142                      StreetsideProperties.CUBEMAP_LINK_TO_BLUR_EDITOR.addListener(imageLinkChangeListener);
    143
    144
    145                    } else {
    146                      if (imageLinkChangeListener != null) {
    147                        StreetsideProperties.CUBEMAP_LINK_TO_BLUR_EDITOR.removeListener(imageLinkChangeListener);
    148                        imageLinkChangeListener = null;
    149                      }
    150                      imgLinkAction.setURL(null);
    151                    }
    152                  }
    153        }
    154
    155        public CubemapBox getCubemapBox() {
    156                return threeSixtyDegreeViewerPanel.getCubemapBox();
    157        }
    158
    159        /**
    160         * @return the threeSixtyDegreeViewerPanel
    161         */
    162        public static ThreeSixtyDegreeViewerPanel getThreeSixtyDegreeViewerPanel() {
    163                return threeSixtyDegreeViewerPanel;
    164        }
    165}