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