1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.layer.geoimage;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.GridBagLayout;
|
---|
7 | import java.awt.event.FocusListener;
|
---|
8 | import java.awt.event.ItemListener;
|
---|
9 |
|
---|
10 | import javax.swing.JCheckBox;
|
---|
11 | import javax.swing.JComponent;
|
---|
12 | import javax.swing.JLabel;
|
---|
13 | import javax.swing.JPanel;
|
---|
14 | import javax.swing.JSeparator;
|
---|
15 | import javax.swing.JSpinner;
|
---|
16 | import javax.swing.SpinnerNumberModel;
|
---|
17 | import javax.swing.SwingConstants;
|
---|
18 | import javax.swing.event.ChangeListener;
|
---|
19 |
|
---|
20 | import org.openstreetmap.josm.data.gpx.GpxImageDirectionPositionSettings;
|
---|
21 | import org.openstreetmap.josm.tools.GBC;
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * Panel allowing user to enter {@link GpxImageDirectionPositionSettings}.
|
---|
25 | * @since 18061
|
---|
26 | */
|
---|
27 | public class ImageDirectionPositionPanel extends JPanel {
|
---|
28 |
|
---|
29 | private final JCheckBox cChangeImageDirection = new JCheckBox();
|
---|
30 | private final JSpinner sOffsetDegrees = new JSpinner(new SpinnerNumberModel(0, -360, 360, 1));
|
---|
31 |
|
---|
32 | private final JSpinner sX = new JSpinner(new SpinnerNumberModel(0.0, -50.0, 50.0, 0.1));
|
---|
33 | private final JSpinner sY = new JSpinner(new SpinnerNumberModel(0.0, -50.0, 50.0, 0.1));
|
---|
34 | private final JSpinner sZ = new JSpinner(new SpinnerNumberModel(0.0, -20.0, 20.0, 0.1));
|
---|
35 |
|
---|
36 | /**
|
---|
37 | * Constructs a new {@code ImageMetadataModificationPanel}
|
---|
38 | * @param changeDirectionText the text displayed for the change image direction combobox
|
---|
39 | */
|
---|
40 | protected ImageDirectionPositionPanel(String changeDirectionText) {
|
---|
41 | super(new GridBagLayout());
|
---|
42 |
|
---|
43 | cChangeImageDirection.setText(changeDirectionText);
|
---|
44 | add(cChangeImageDirection, GBC.eol().insets(0, 0, 0, 5));
|
---|
45 | cChangeImageDirection.addActionListener(e -> sOffsetDegrees.setEnabled(!sOffsetDegrees.isEnabled()));
|
---|
46 | addSetting(tr("Offset angle in degrees:"), sOffsetDegrees);
|
---|
47 | sOffsetDegrees.setEnabled(false);
|
---|
48 |
|
---|
49 | add(new JSeparator(SwingConstants.HORIZONTAL),
|
---|
50 | GBC.eol().fill(GBC.HORIZONTAL).insets(0, 12, 0, 12));
|
---|
51 |
|
---|
52 | add(new JLabel(tr("Shift image relative to the direction (in meters)")),
|
---|
53 | GBC.eol().insets(0, 0, 0, 5));
|
---|
54 | addSetting(tr("X:"), sX);
|
---|
55 | addSetting(tr("Y:"), sY);
|
---|
56 | addSetting(tr("Elevation:"), sZ);
|
---|
57 | }
|
---|
58 |
|
---|
59 | /**
|
---|
60 | * Returns a new {@code ImageMetadataModificationPanel} in a GPX trace context.
|
---|
61 | * @return a new {@code ImageMetadataModificationPanel} in a GPX trace context
|
---|
62 | */
|
---|
63 | public static ImageDirectionPositionPanel forGpxTrace() {
|
---|
64 | return new ImageDirectionPositionPanel(tr("Set image direction towards the next GPX waypoint"));
|
---|
65 | }
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * Returns a new {@code ImageMetadataModificationPanel} in an image sequence context.
|
---|
69 | * @return a new {@code ImageMetadataModificationPanel} in an image sequence context
|
---|
70 | */
|
---|
71 | public static ImageDirectionPositionPanel forImageSequence() {
|
---|
72 | return new ImageDirectionPositionPanel(tr("Set image direction towards the next one"));
|
---|
73 | }
|
---|
74 |
|
---|
75 | protected void addSetting(String text, JComponent component) {
|
---|
76 | add(new JLabel(text, JLabel.RIGHT), GBC.std().insets(15, 0, 5, 5).fill(GBC.HORIZONTAL).weight(0, 0));
|
---|
77 | add(component, GBC.std().fill(GBC.HORIZONTAL));
|
---|
78 | add(GBC.glue(1, 0), GBC.eol().fill(GBC.HORIZONTAL).weight(1, 0));
|
---|
79 | }
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * Returns the settings set by user.
|
---|
83 | * @return the settings set by user
|
---|
84 | */
|
---|
85 | public GpxImageDirectionPositionSettings getSettings() {
|
---|
86 | return new GpxImageDirectionPositionSettings(
|
---|
87 | cChangeImageDirection.isSelected(),
|
---|
88 | (Integer) sOffsetDegrees.getValue(),
|
---|
89 | (Double) sX.getValue(),
|
---|
90 | (Double) sY.getValue(),
|
---|
91 | (Double) sZ.getValue());
|
---|
92 | }
|
---|
93 |
|
---|
94 | /**
|
---|
95 | * Adds a focus listener on all spinners of this panel.
|
---|
96 | * @param focusListener focus listener to add
|
---|
97 | */
|
---|
98 | public void addFocusListenerOnComponent(FocusListener focusListener) {
|
---|
99 | sOffsetDegrees.addFocusListener(focusListener);
|
---|
100 | sX.addFocusListener(focusListener);
|
---|
101 | sY.addFocusListener(focusListener);
|
---|
102 | sZ.addFocusListener(focusListener);
|
---|
103 | }
|
---|
104 |
|
---|
105 | /**
|
---|
106 | * Adds a change listener on all checkboxes of this panel.
|
---|
107 | * @param listener change listener to add
|
---|
108 | * @since 18078
|
---|
109 | */
|
---|
110 | public void addItemListenerOnComponents(ItemListener listener) {
|
---|
111 | cChangeImageDirection.addItemListener(listener);
|
---|
112 | }
|
---|
113 |
|
---|
114 | /**
|
---|
115 | * Adds a change listener on all spinners of this panel.
|
---|
116 | * @param listener change listener to add
|
---|
117 | */
|
---|
118 | public void addChangeListenerOnComponents(ChangeListener listener) {
|
---|
119 | sOffsetDegrees.addChangeListener(listener);
|
---|
120 | sX.addChangeListener(listener);
|
---|
121 | sY.addChangeListener(listener);
|
---|
122 | sZ.addChangeListener(listener);
|
---|
123 | }
|
---|
124 | }
|
---|