    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 StreetsideViewerHelpPopup extends JPopupMenu {
    025
    026        private static final long serialVersionUID = -7840242522398163839L;
    027
    028        private final Component invokerComp;
    029        private boolean alreadyDisplayed;
    030
    031        public StreetsideViewerHelpPopup(Component invoker) {
    032
    033                invokerComp = invoker;
    034                removeAll();
    035                setLayout(new BorderLayout());
    036
    037                JPanel topBar = new JPanel();
    038                topBar.add(new JLabel(ImageProvider.get("streetside-logo-white")));
    039                topBar.setBackground(StreetsideColorScheme.TOOLBAR_DARK_GREY);
    040                add(topBar, BorderLayout.NORTH);
    041
    042                JTextPane mainText = new JTextPane();
    043                mainText.setContentType("text/html");
    044                mainText.setFont(SelectableLabel.DEFAULT_FONT);
    045                mainText.setText("<html><div style='width:250px'>" + I18n.tr(
    046                                "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).")
    047                                + "<br><br>"
    048                                + I18n.tr(
    049                                                "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                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                        private static final long serialVersionUID = -6193886964751195196L;
    060
    061                        @Override
    062                        public void actionPerformed(ActionEvent e) {
    063                                setVisible(false);
    064                                StreetsideProperties.IMAGEINFO_HELP_COUNTDOWN.put(0);
    065                        }
    066                });
    067
    068                closeBtn.setText(I18n.tr("I got it, close this."));
    069 bottomBar.add(closeBtn);
    070 add(bottomBar, BorderLayout.SOUTH);
    071
    072 setBackground(Color.WHITE);
    073}
    074
    075/**
    076* @return <code>true</code> if the popup is displayed
    077*/
    078public boolean showPopup() {
    079 if (!alreadyDisplayed && invokerComp.isShowing()) {
    080   try {
    081     show(invokerComp, invokerComp.getWidth(), 0);
    082     alreadyDisplayed = true;
    083     return true;
    084   } catch (IllegalComponentStateException e) {
    085     Logging.log(Logging.LEVEL_WARN, "Could not show ImageInfoHelpPopup, because probably the invoker component has disappeared from screen.", e);
    086   }
    087 }
    088 return false;
    089}
    090}