source: josm/trunk/src/org/openstreetmap/josm/gui/layer/AlignImageryPanel.java@ 11167

Last change on this file since 11167 was 10611, checked in by Don-vip, 8 years ago

see #11390 - sonar - squid:S1604 - Java 8: Anonymous inner classes containing only one method should become lambdas

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