001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.gui.layer; 003 004import static org.openstreetmap.josm.tools.I18n.tr; 005 006import java.awt.Color; 007import java.awt.Font; 008import java.awt.GridBagLayout; 009 010import javax.swing.JButton; 011import javax.swing.JCheckBox; 012import javax.swing.JPanel; 013import javax.swing.border.CompoundBorder; 014import javax.swing.border.EmptyBorder; 015import javax.swing.border.EtchedBorder; 016 017import org.openstreetmap.josm.data.imagery.ImageryInfo; 018import org.openstreetmap.josm.data.preferences.BooleanProperty; 019import org.openstreetmap.josm.gui.MainApplication; 020import org.openstreetmap.josm.gui.MapFrame; 021import org.openstreetmap.josm.gui.util.GuiHelper; 022import org.openstreetmap.josm.gui.widgets.JMultilineLabel; 023import org.openstreetmap.josm.gui.widgets.UrlLabel; 024import org.openstreetmap.josm.tools.GBC; 025import org.openstreetmap.josm.tools.ImageProvider; 026import org.openstreetmap.josm.tools.TextUtils; 027 028/** 029 * The panel to nag a user ONCE that he/she has to align imagery. 030 * 031 * @author zverik 032 */ 033public class AlignImageryPanel extends JPanel { 034 035 /** 036 * @param oneLine if true, show the nagging message in one line, otherwise - in two lines 037 * @param showAgain show again property 038 * @param infoToAdd imagery info for which the nagging message is shown 039 */ 040 public AlignImageryPanel(boolean oneLine, final BooleanProperty showAgain, ImageryInfo infoToAdd) { 041 Font font = getFont().deriveFont(Font.PLAIN, 14.0f); 042 JMultilineLabel nagLabel = new JMultilineLabel( 043 tr("Aerial imagery \"{0}\" might be misaligned. Please check its offset using GPS tracks!", 044 TextUtils.wrapLongUrl(infoToAdd.getName()))); 045 UrlLabel detailsList = new UrlLabel(tr("http://wiki.openstreetmap.org/wiki/Using_Imagery"), tr("Details...")); 046 nagLabel.setFont(font); 047 nagLabel.setForeground(Color.BLACK); 048 detailsList.setFont(font); 049 final JCheckBox doNotShowAgain = new JCheckBox(tr("Do not show this message again")); 050 doNotShowAgain.setOpaque(false); 051 doNotShowAgain.setForeground(Color.BLACK); 052 053 JButton closeButton = new JButton(ImageProvider.get("misc", "black_x")); 054 closeButton.setContentAreaFilled(false); 055 closeButton.setRolloverEnabled(true); 056 closeButton.setBorderPainted(false); 057 closeButton.setToolTipText(tr("Hide this message")); 058 closeButton.addActionListener(e -> { 059 if (MainApplication.isDisplayingMapView()) { 060 MainApplication.getMap().removeTopPanel(AlignImageryPanel.class); 061 if (doNotShowAgain.isSelected()) { 062 showAgain.put(Boolean.FALSE); 063 } 064 } 065 }); 066 067 setLayout(new GridBagLayout()); 068 if (!oneLine) { // tune for small screens 069 add(nagLabel, GBC.std(1, 1).fill()); 070 add(detailsList, GBC.std(1, 2).fill()); 071 add(doNotShowAgain, GBC.std(1, 3).fill()); 072 add(closeButton, GBC.std(2, 1).span(1, 2).anchor(GBC.EAST)); 073 } else { 074 add(nagLabel, GBC.std(1, 1).fill()); 075 add(detailsList, GBC.std(2, 1).fill()); 076 add(doNotShowAgain, GBC.std(1, 2).fill()); 077 add(closeButton, GBC.std(3, 1).anchor(GBC.EAST)); 078 } 079 setBorder(new CompoundBorder(new EtchedBorder(EtchedBorder.LOWERED), new EmptyBorder(12, 12, 12, 12))); 080 setBackground(new Color(224, 236, 249)); 081 } 082 083 /** 084 * @param infoToAdd ImageryInfo for which the nag panel should be created 085 */ 086 public static void addNagPanelIfNeeded(ImageryInfo infoToAdd) { 087 BooleanProperty showAgain = new BooleanProperty("message.imagery.nagPanel." + infoToAdd.getUrl(), true); 088 MapFrame map = MainApplication.getMap(); 089 if (MainApplication.isDisplayingMapView() && showAgain.get() && !infoToAdd.isGeoreferenceValid() 090 && map.getTopPanel(AlignImageryPanel.class) == null) { 091 double w = GuiHelper.getScreenSize().getWidth(); 092 map.addTopPanel(new AlignImageryPanel(w > 1300, showAgain, infoToAdd)); 093 } 094 } 095}