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

Last change on this file since 15800 was 15800, checked in by simon04, 4 years ago

AlignImageryPanel: add hand cursor to close button

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