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; 009import java.awt.Toolkit; 010import java.awt.event.ActionEvent; 011import java.awt.event.ActionListener; 012 013import javax.swing.JButton; 014import javax.swing.JCheckBox; 015import javax.swing.JLabel; 016import javax.swing.JPanel; 017import javax.swing.border.CompoundBorder; 018import javax.swing.border.EmptyBorder; 019import javax.swing.border.EtchedBorder; 020 021import org.openstreetmap.josm.Main; 022import org.openstreetmap.josm.data.imagery.ImageryInfo; 023import org.openstreetmap.josm.data.preferences.BooleanProperty; 024import org.openstreetmap.josm.gui.widgets.UrlLabel; 025import org.openstreetmap.josm.tools.GBC; 026import org.openstreetmap.josm.tools.ImageProvider; 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 JLabel nagLabel = new JLabel( 043 tr("Aerial imagery \"{0}\" might be misaligned. Please check its offset using GPS tracks!", infoToAdd.getName())); 044 UrlLabel detailsList = new UrlLabel(tr("http://wiki.openstreetmap.org/wiki/Using_Imagery"), tr("Details...")); 045 nagLabel.setLabelFor(detailsList); 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 and never show it again")); 058 closeButton.addActionListener(new ActionListener() { 059 @Override 060 public void actionPerformed(ActionEvent e) { 061 if (Main.isDisplayingMapView()) { 062 Main.map.removeTopPanel(AlignImageryPanel.class); 063 if (doNotShowAgain.isSelected()) { 064 showAgain.put(false); 065 } 066 } 067 } 068 }); 069 070 setLayout(new GridBagLayout()); 071 if (!oneLine) { // tune for small screens 072 add(nagLabel, GBC.std(1, 1).fill()); 073 add(detailsList, GBC.std(1, 2).fill()); 074 add(doNotShowAgain, GBC.std(1, 3).fill()); 075 add(closeButton, GBC.std(2, 1).span(1, 2).anchor(GBC.EAST)); 076 } else { 077 add(nagLabel, GBC.std(1, 1).fill()); 078 add(detailsList, GBC.std(2, 1).fill()); 079 add(doNotShowAgain, GBC.std(1, 2).fill()); 080 add(closeButton, GBC.std(3, 1).anchor(GBC.EAST)); 081 } 082 setBorder(new CompoundBorder(new EtchedBorder(EtchedBorder.LOWERED), new EmptyBorder(12, 12, 12, 12))); 083 setBackground(new Color(224, 236, 249)); 084 } 085 086 /** 087 * @param infoToAdd ImageryInfo for which the nag panel should be created 088 */ 089 public static void addNagPanelIfNeeded(ImageryInfo infoToAdd) { 090 BooleanProperty showAgain = new BooleanProperty("message.imagery.nagPanel." + infoToAdd.getUrl(), true); 091 if (Main.isDisplayingMapView() && showAgain.get() && !infoToAdd.isGeoreferenceValid()) { 092 if (Main.map.getTopPanel(AlignImageryPanel.class) == null) { 093 double w = Toolkit.getDefaultToolkit().getScreenSize().getWidth(); 094 AlignImageryPanel p = new AlignImageryPanel(w > 1300, showAgain, infoToAdd); 095 Main.map.addTopPanel(p); 096 } 097 } 098 } 099}