1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.layer;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.Color;
|
---|
7 | import java.awt.Font;
|
---|
8 | import java.awt.GridBagLayout;
|
---|
9 |
|
---|
10 | import javax.swing.JButton;
|
---|
11 | import javax.swing.JCheckBox;
|
---|
12 | import javax.swing.JPanel;
|
---|
13 | import javax.swing.border.CompoundBorder;
|
---|
14 | import javax.swing.border.EmptyBorder;
|
---|
15 | import javax.swing.border.EtchedBorder;
|
---|
16 |
|
---|
17 | import org.openstreetmap.josm.data.imagery.ImageryInfo;
|
---|
18 | import org.openstreetmap.josm.data.preferences.BooleanProperty;
|
---|
19 | import org.openstreetmap.josm.gui.MainApplication;
|
---|
20 | import org.openstreetmap.josm.gui.MapFrame;
|
---|
21 | import org.openstreetmap.josm.gui.util.GuiHelper;
|
---|
22 | import org.openstreetmap.josm.gui.widgets.JMultilineLabel;
|
---|
23 | import org.openstreetmap.josm.gui.widgets.UrlLabel;
|
---|
24 | import org.openstreetmap.josm.tools.GBC;
|
---|
25 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * The panel to nag a user ONCE that he/she has to align imagery.
|
---|
29 | *
|
---|
30 | * @author zverik
|
---|
31 | */
|
---|
32 | public class AlignImageryPanel extends JPanel {
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * @param oneLine if true, show the nagging message in one line, otherwise - in two lines
|
---|
36 | * @param showAgain show again property
|
---|
37 | * @param infoToAdd imagery info for which the nagging message is shown
|
---|
38 | */
|
---|
39 | public AlignImageryPanel(boolean oneLine, final BooleanProperty showAgain, ImageryInfo infoToAdd) {
|
---|
40 | Font font = getFont().deriveFont(Font.PLAIN, 14.0f);
|
---|
41 | JMultilineLabel nagLabel = new JMultilineLabel(
|
---|
42 | tr("Aerial imagery \"{0}\" might be misaligned. Please check its offset using GPS tracks!", infoToAdd.getName()));
|
---|
43 | UrlLabel detailsList = new UrlLabel(tr("http://wiki.openstreetmap.org/wiki/Using_Imagery"), tr("Details..."));
|
---|
44 | nagLabel.setFont(font);
|
---|
45 | nagLabel.setForeground(Color.BLACK);
|
---|
46 | detailsList.setFont(font);
|
---|
47 | final JCheckBox doNotShowAgain = new JCheckBox(tr("Do not show this message again"));
|
---|
48 | doNotShowAgain.setOpaque(false);
|
---|
49 | doNotShowAgain.setForeground(Color.BLACK);
|
---|
50 |
|
---|
51 | JButton closeButton = new JButton(ImageProvider.get("misc", "black_x"));
|
---|
52 | closeButton.setContentAreaFilled(false);
|
---|
53 | closeButton.setRolloverEnabled(true);
|
---|
54 | closeButton.setBorderPainted(false);
|
---|
55 | closeButton.setToolTipText(tr("Hide this message and never show it again"));
|
---|
56 | closeButton.addActionListener(e -> {
|
---|
57 | if (MainApplication.isDisplayingMapView()) {
|
---|
58 | MainApplication.getMap().removeTopPanel(AlignImageryPanel.class);
|
---|
59 | if (doNotShowAgain.isSelected()) {
|
---|
60 | showAgain.put(Boolean.FALSE);
|
---|
61 | }
|
---|
62 | }
|
---|
63 | });
|
---|
64 |
|
---|
65 | setLayout(new GridBagLayout());
|
---|
66 | if (!oneLine) { // tune for small screens
|
---|
67 | add(nagLabel, GBC.std(1, 1).fill());
|
---|
68 | add(detailsList, GBC.std(1, 2).fill());
|
---|
69 | add(doNotShowAgain, GBC.std(1, 3).fill());
|
---|
70 | add(closeButton, GBC.std(2, 1).span(1, 2).anchor(GBC.EAST));
|
---|
71 | } else {
|
---|
72 | add(nagLabel, GBC.std(1, 1).fill());
|
---|
73 | add(detailsList, GBC.std(2, 1).fill());
|
---|
74 | add(doNotShowAgain, GBC.std(1, 2).fill());
|
---|
75 | add(closeButton, GBC.std(3, 1).anchor(GBC.EAST));
|
---|
76 | }
|
---|
77 | setBorder(new CompoundBorder(new EtchedBorder(EtchedBorder.LOWERED), new EmptyBorder(12, 12, 12, 12)));
|
---|
78 | setBackground(new Color(224, 236, 249));
|
---|
79 | }
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * @param infoToAdd ImageryInfo for which the nag panel should be created
|
---|
83 | */
|
---|
84 | public static void addNagPanelIfNeeded(ImageryInfo infoToAdd) {
|
---|
85 | BooleanProperty showAgain = new BooleanProperty("message.imagery.nagPanel." + infoToAdd.getUrl(), true);
|
---|
86 | MapFrame map = MainApplication.getMap();
|
---|
87 | if (MainApplication.isDisplayingMapView() && showAgain.get() && !infoToAdd.isGeoreferenceValid()
|
---|
88 | && map.getTopPanel(AlignImageryPanel.class) == null) {
|
---|
89 | double w = GuiHelper.getScreenSize().getWidth();
|
---|
90 | map.addTopPanel(new AlignImageryPanel(w > 1300, showAgain, infoToAdd));
|
---|
91 | }
|
---|
92 | }
|
---|
93 | }
|
---|