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