1 | package org.openstreetmap.josm.gui.actionsupport;
|
---|
2 |
|
---|
3 | import java.awt.*;
|
---|
4 | import java.awt.event.*;
|
---|
5 | import javax.swing.*;
|
---|
6 | import javax.swing.border.*;
|
---|
7 | import org.openstreetmap.josm.Main;
|
---|
8 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
9 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
10 | import org.openstreetmap.josm.tools.OpenBrowser;
|
---|
11 | import org.openstreetmap.josm.tools.Utils;
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * The panel to nag a user ONCE that he/she has to align imagery.
|
---|
15 | *
|
---|
16 | * @author zverik
|
---|
17 | */
|
---|
18 | public class AlignImageryPanel extends JPanel {
|
---|
19 | private static final String PREF = "imagery.offsetnagging";
|
---|
20 |
|
---|
21 | public AlignImageryPanel() {
|
---|
22 | super();
|
---|
23 |
|
---|
24 | Font font = getFont().deriveFont(Font.PLAIN, 14.0f);
|
---|
25 | JLabel nagLabel = new JLabel(tr("Aerial imagery might be misaligned. Please check its offset using GPS tracks!"));
|
---|
26 | // JLabel nagLabel = new JLabel(tr("Снимки могут быть смещены. Не забудьте проверить привязку снимков по GPS-трекам!"));
|
---|
27 | SaneUrlLabel detailsList = new SaneUrlLabel(tr("http://wiki.openstreetmap.org/wiki/Using_Imagery"), tr("Details..."));
|
---|
28 | nagLabel.setFont(font);
|
---|
29 | detailsList.setFont(font);
|
---|
30 |
|
---|
31 | // JButton closeButton = new JButton("X");
|
---|
32 | JButton closeButton = new JButton(ImageProvider.get("misc", "black_x"));
|
---|
33 | closeButton.setContentAreaFilled(false);
|
---|
34 | closeButton.setRolloverEnabled(true);
|
---|
35 | closeButton.setBorderPainted(false);
|
---|
36 | closeButton.setToolTipText(tr("Hide this message and never show it again"));
|
---|
37 | closeButton.addActionListener(new ActionListener() {
|
---|
38 | @Override
|
---|
39 | public void actionPerformed( ActionEvent e ) {
|
---|
40 | setVisible(false);
|
---|
41 | getParent().remove(AlignImageryPanel.this);
|
---|
42 | }
|
---|
43 | });
|
---|
44 |
|
---|
45 | BoxLayout box = new BoxLayout(this, BoxLayout.X_AXIS);
|
---|
46 | setLayout(box);
|
---|
47 | add(nagLabel);
|
---|
48 | add(Box.createHorizontalStrut(12));
|
---|
49 | add(detailsList);
|
---|
50 | add(Box.createHorizontalGlue());
|
---|
51 | add(closeButton);
|
---|
52 | // setBorder(new EmptyBorder(12, 12, 12, 12));
|
---|
53 | setBorder(new CompoundBorder(new EtchedBorder(EtchedBorder.LOWERED), new EmptyBorder(12, 12, 12, 12)));
|
---|
54 | setBackground(new Color(224, 236, 249));
|
---|
55 | }
|
---|
56 |
|
---|
57 | public static void addNagPanel() {
|
---|
58 | if( Main.map != null && !Main.pref.getBoolean("expert") && Main.pref.getBoolean(PREF, true) ) {
|
---|
59 | if( Main.map.mapView != null && Main.map.mapView.getParent() instanceof JSplitPane ) {
|
---|
60 | // This is really a hack. If you don't like it, use the line in "else" block
|
---|
61 | JPanel p = new JPanel(new BorderLayout());
|
---|
62 | ((JSplitPane)Main.map.mapView.getParent()).setLeftComponent(p);
|
---|
63 | p.add(Main.map.mapView, BorderLayout.CENTER);
|
---|
64 | p.add(new AlignImageryPanel(), BorderLayout.NORTH);
|
---|
65 | } else
|
---|
66 | Main.map.add(new AlignImageryPanel(), BorderLayout.NORTH);
|
---|
67 | Main.pref.put(PREF, false);
|
---|
68 | }
|
---|
69 | }
|
---|
70 |
|
---|
71 | public static class SaneUrlLabel extends JLabel implements MouseListener {
|
---|
72 | private String url;
|
---|
73 |
|
---|
74 | public SaneUrlLabel( String url, String description ) {
|
---|
75 | this.url = url;
|
---|
76 | if( url != null ) {
|
---|
77 | setText("<html><a href=\"" + url + "\">" + description + "</a></html>");
|
---|
78 | } else {
|
---|
79 | setText(description);
|
---|
80 | }
|
---|
81 | setToolTipText(String.format("<html>%s<br/>%s</html>", url, tr("Right click = copy to clipboard")));
|
---|
82 | setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
---|
83 | addMouseListener(this);
|
---|
84 | }
|
---|
85 |
|
---|
86 | @Override
|
---|
87 | public void mouseClicked( MouseEvent e ) {
|
---|
88 | if( SwingUtilities.isLeftMouseButton(e) ) {
|
---|
89 | OpenBrowser.displayUrl(url);
|
---|
90 | } else if( SwingUtilities.isRightMouseButton(e) ) {
|
---|
91 | Utils.copyToClipboard(url);
|
---|
92 | }
|
---|
93 | }
|
---|
94 |
|
---|
95 | @Override public void mousePressed( MouseEvent e ) { }
|
---|
96 | @Override public void mouseEntered( MouseEvent e ) { }
|
---|
97 | @Override public void mouseExited( MouseEvent e ) { }
|
---|
98 | @Override public void mouseReleased( MouseEvent e ) { }
|
---|
99 | }
|
---|
100 | }
|
---|