    001// License: GPL. For details, see LICENSE file.
    002package org.openstreetmap.josm.plugins.streetside.gui.imageinfo;
    003
    004import java.awt.BorderLayout;
    005import java.awt.Color;
    006import java.awt.Component;
    007import java.awt.IllegalComponentStateException;
    008import java.awt.event.ActionEvent;
    009import java.text.MessageFormat;
    010
    011import javax.swing.AbstractAction;
    012import javax.swing.JLabel;
    013import javax.swing.JPanel;
    014import javax.swing.JPopupMenu;
    015import javax.swing.JTextPane;
    016
    017import org.apache.log4j.Logger;
    018import org.openstreetmap.josm.plugins.streetside.gui.boilerplate.SelectableLabel;
    019import org.openstreetmap.josm.plugins.streetside.gui.boilerplate.StreetsideButton;
    020import org.openstreetmap.josm.plugins.streetside.utils.StreetsideColorScheme;
    021import org.openstreetmap.josm.plugins.streetside.utils.StreetsideProperties;
    022import org.openstreetmap.josm.tools.I18n;
    023import org.openstreetmap.josm.tools.ImageProvider;
    024
    025
    026public class StreetsideViewerHelpPopup extends JPopupMenu {
    027
    028        private static final long serialVersionUID = -7840242522398163839L;
    029
    030        final static Logger logger = Logger.getLogger(StreetsideViewerHelpPopup.class);
    031
    032        private final Component invokerComp;
    033        private boolean alreadyDisplayed;
    034
    035        public StreetsideViewerHelpPopup(Component invoker) {
    036
    037                invokerComp = invoker;
    038                removeAll();
    039                setLayout(new BorderLayout());
    040
    041                JPanel topBar = new JPanel();
    042                topBar.add(new JLabel(ImageProvider.get("streetside-logo-white")));
    043                topBar.setBackground(StreetsideColorScheme.TOOLBAR_DARK_GREY);
    044                add(topBar, BorderLayout.NORTH);
    045
    046                JTextPane mainText = new JTextPane();
    047                mainText.setContentType("text/html");
    048                mainText.setFont(SelectableLabel.DEFAULT_FONT);
    049                mainText.setText("<html><div style='width:250px'>" +
    050                                "Welcome to the Microsoft Streetside JOSM Plugin. To view the vector bubbles for the 360 degree imagery, select Imagery->Streetside from the JOSM menu."
    051                                + "<br><br>"
    052                                +
    053                                                "Once the blue bubbles appear on the map, click on a vector bubble and undock/maximize the 360 viewer to view the imagery."
    054                                + "</div></html>");
    055                add(mainText, BorderLayout.CENTER);
    056
    057                JPanel bottomBar = new JPanel();
    058                bottomBar.setBackground(new Color(0x00FFFFFF, true));
    059                StreetsideButton infoButton = new StreetsideButton(ImageInfoPanel.getInstance().getToggleAction());
    060                infoButton.addActionListener(e -> setVisible(false));
    061                bottomBar.add(infoButton);
    062                StreetsideButton closeBtn = new StreetsideButton(new AbstractAction() {
    063                        private static final long serialVersionUID = -6193886964751195196L;
    064
    065                        @Override
    066                        public void actionPerformed(ActionEvent e) {
    067                                setVisible(false);
    068                                StreetsideProperties.IMAGEINFO_HELP_COUNTDOWN.put(0);
    069                        }
    070                });
    071
    072                closeBtn.setText(I18n.tr("I got it, close this."));
    073 bottomBar.add(closeBtn);
    074 add(bottomBar, BorderLayout.SOUTH);
    075
    076 setBackground(Color.WHITE);
    077}
    078
    079/**
    080* @return <code>true</code> if the popup is displayed
    081*/
    082public boolean showPopup() {
    083 if (!alreadyDisplayed && invokerComp.isShowing()) {
    084   try {
    085     show(invokerComp, invokerComp.getWidth(), 0);
    086     alreadyDisplayed = true;
    087     return true;
    088   } catch (IllegalComponentStateException e) {
    089     logger.error(MessageFormat.format("Could not show ImageInfoHelpPopup, because probably the invoker component has disappeared from screen. {0}", e.getMessage()));
    090   }
    091 }
    092 return false;
    093}
    094}