    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.openstreetmap.josm.plugins.streetside.gui.boilerplate.SelectableLabel;
    017import org.openstreetmap.josm.plugins.streetside.gui.boilerplate.StreetsideButton;
    018import org.openstreetmap.josm.plugins.streetside.utils.StreetsideColorScheme;
    019import org.openstreetmap.josm.plugins.streetside.utils.StreetsideProperties;
    020import org.openstreetmap.josm.tools.I18n;
    021import org.openstreetmap.josm.tools.ImageProvider;
    022import org.openstreetmap.josm.tools.Logging;
    023
    024public class ImageInfoHelpPopup extends JPopupMenu {
    025
    026  private static final long serialVersionUID = -1721594904273820586L;
    027
    028  private final Component invokerComp;
    029  private boolean alreadyDisplayed;
    030
    031  public ImageInfoHelpPopup(Component invoker) {
    032    invokerComp = invoker;
    033    removeAll();
    034    setLayout(new BorderLayout());
    035
    036    JPanel topBar = new JPanel();
    037    topBar.add(new JLabel(ImageProvider.get("streetside-logo-white")));
    038    topBar.setBackground(StreetsideColorScheme.TOOLBAR_DARK_GREY);
    039    add(topBar, BorderLayout.NORTH);
    040
    041    JTextPane mainText = new JTextPane();
    042    mainText.setContentType("text/html");
    043    mainText.setFont(SelectableLabel.DEFAULT_FONT);
    044    // TODO: tr( RRH
    045    mainText.setText(
    046      "<html><div style='width:250px'>" +
    047      I18n.tr("The Streetside plugin now uses a separate panel to display extra information (like the image key) and actions for the currently selected Streetside image (like viewing it in a browser).") +
    048      "<br><br>" +
    049      I18n.tr("It can be activated by clicking the left button at the bottom of this message or the button in the toolbar on the left, which uses the same icon.") +
    050      "</div></html>"
    051    );
    052    add(mainText, BorderLayout.CENTER);
    053
    054    JPanel bottomBar = new JPanel();
    055    bottomBar.setBackground(new Color(0x00FFFFFF, true));
    056    StreetsideButton infoButton = new StreetsideButton(ImageInfoPanel.getInstance().getToggleAction());
    057    infoButton.addActionListener(e -> setVisible(false));
    058    bottomBar.add(infoButton);
    059                StreetsideButton closeBtn = new StreetsideButton(new AbstractAction() {
    060
    061                        private static final long serialVersionUID = 2853315308169651854L;
    062
    063                        @Override
    064                        public void actionPerformed(ActionEvent e) {
    065                                setVisible(false);
    066                                StreetsideProperties.IMAGEINFO_HELP_COUNTDOWN.put(0);
    067                        }
    068                });
    069
    070                closeBtn.setText(I18n.tr("I got it, close this."));
    071                bottomBar.add(closeBtn);
    072                add(bottomBar, BorderLayout.SOUTH);
    073
    074                setBackground(Color.WHITE);
    075        }
    076
    077  /**
    078   * @return <code>true</code> if the popup is displayed
    079   */
    080  public boolean showPopup() {
    081    if (!alreadyDisplayed && invokerComp.isShowing()) {
    082      try {
    083        show(invokerComp, invokerComp.getWidth(), 0);
    084        alreadyDisplayed = true;
    085        return true;
    086      } catch (IllegalComponentStateException e) {
    087        Logging.log(Logging.LEVEL_WARN, "Could not show ImageInfoHelpPopup, because probably the invoker component has disappeared from screen.", e);
    088      }
    089    }
    090    return false;
    091  }
    092}