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