1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.preferences.imagery;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.Color;
|
---|
7 | import java.awt.GridBagLayout;
|
---|
8 | import java.awt.event.ActionEvent;
|
---|
9 | import java.awt.event.ActionListener;
|
---|
10 |
|
---|
11 | import javax.swing.JButton;
|
---|
12 | import javax.swing.JCheckBox;
|
---|
13 | import javax.swing.JColorChooser;
|
---|
14 | import javax.swing.JLabel;
|
---|
15 | import javax.swing.JOptionPane;
|
---|
16 | import javax.swing.JPanel;
|
---|
17 | import javax.swing.JSlider;
|
---|
18 | import javax.swing.JTextField;
|
---|
19 | import javax.swing.event.ChangeEvent;
|
---|
20 | import javax.swing.event.ChangeListener;
|
---|
21 |
|
---|
22 | import org.openstreetmap.josm.gui.layer.ImageryLayer;
|
---|
23 | import org.openstreetmap.josm.gui.widgets.JosmComboBox;
|
---|
24 | import org.openstreetmap.josm.io.imagery.OffsetServer;
|
---|
25 | import org.openstreetmap.josm.io.imagery.OsmosnimkiOffsetServer;
|
---|
26 | import org.openstreetmap.josm.tools.ColorHelper;
|
---|
27 | import org.openstreetmap.josm.tools.GBC;
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * {@code JPanel} giving access to common imagery settings.
|
---|
31 | * @since 5465
|
---|
32 | */
|
---|
33 | public class CommonSettingsPanel extends JPanel {
|
---|
34 |
|
---|
35 | // Common Settings
|
---|
36 | private final JButton btnFadeColor;
|
---|
37 | private final JSlider fadeAmount = new JSlider(0, 100);
|
---|
38 | private final JosmComboBox sharpen;
|
---|
39 | private final JCheckBox useOffsetServer;
|
---|
40 | private final JTextField offsetServerUrl;
|
---|
41 |
|
---|
42 | /**
|
---|
43 | * Constructs a new {@code CommonSettingsPanel}.
|
---|
44 | */
|
---|
45 | public CommonSettingsPanel() {
|
---|
46 | super(new GridBagLayout());
|
---|
47 |
|
---|
48 | this.btnFadeColor = new JButton();
|
---|
49 |
|
---|
50 | this.btnFadeColor.addActionListener(new ActionListener() {
|
---|
51 | @Override
|
---|
52 | public void actionPerformed(ActionEvent e) {
|
---|
53 | JColorChooser chooser = new JColorChooser(btnFadeColor.getBackground());
|
---|
54 | int answer = JOptionPane.showConfirmDialog(
|
---|
55 | CommonSettingsPanel.this, chooser,
|
---|
56 | tr("Choose a color for {0}", tr("imagery fade")),
|
---|
57 | JOptionPane.OK_CANCEL_OPTION,
|
---|
58 | JOptionPane.PLAIN_MESSAGE);
|
---|
59 | if (answer == JOptionPane.OK_OPTION) {
|
---|
60 | Color colFadeColor = chooser.getColor();
|
---|
61 | btnFadeColor.setBackground(colFadeColor);
|
---|
62 | btnFadeColor.setText(ColorHelper.color2html(colFadeColor));
|
---|
63 | }
|
---|
64 | }
|
---|
65 | });
|
---|
66 |
|
---|
67 | add(new JLabel(tr("Fade Color: ")), GBC.std());
|
---|
68 | add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL));
|
---|
69 | add(this.btnFadeColor, GBC.eol().fill(GBC.HORIZONTAL));
|
---|
70 |
|
---|
71 | add(new JLabel(tr("Fade amount: ")), GBC.std());
|
---|
72 | add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL));
|
---|
73 | add(this.fadeAmount, GBC.eol().fill(GBC.HORIZONTAL));
|
---|
74 |
|
---|
75 | this.sharpen = new JosmComboBox(new String[] {
|
---|
76 | tr("None"),
|
---|
77 | tr("Soft"),
|
---|
78 | tr("Strong")});
|
---|
79 | add(new JLabel(tr("Sharpen (requires layer re-add): ")));
|
---|
80 | add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL));
|
---|
81 | add(this.sharpen, GBC.eol().fill(GBC.HORIZONTAL));
|
---|
82 |
|
---|
83 | this.useOffsetServer = new JCheckBox(tr("Use offset server: "));
|
---|
84 | this.offsetServerUrl = new JTextField();
|
---|
85 | this.useOffsetServer.addChangeListener(new ChangeListener() {
|
---|
86 | @Override
|
---|
87 | public void stateChanged(ChangeEvent e) {
|
---|
88 | offsetServerUrl.setEnabled(useOffsetServer.isSelected());
|
---|
89 | }
|
---|
90 | });
|
---|
91 | offsetServerUrl.setEnabled(useOffsetServer.isSelected());
|
---|
92 | add(this.useOffsetServer, GBC.eol().fill(GBC.HORIZONTAL));
|
---|
93 | add(this.offsetServerUrl, GBC.eol().fill(GBC.HORIZONTAL));
|
---|
94 | }
|
---|
95 |
|
---|
96 | /**
|
---|
97 | * Loads the common settings.
|
---|
98 | */
|
---|
99 | public void loadSettings() {
|
---|
100 | Color colFadeColor = ImageryLayer.PROP_FADE_COLOR.get();
|
---|
101 | this.btnFadeColor.setBackground(colFadeColor);
|
---|
102 | this.btnFadeColor.setText(ColorHelper.color2html(colFadeColor));
|
---|
103 | this.fadeAmount.setValue(ImageryLayer.PROP_FADE_AMOUNT.get());
|
---|
104 | this.sharpen.setSelectedIndex(Math.max(0, Math.min(2, ImageryLayer.PROP_SHARPEN_LEVEL.get())));
|
---|
105 | this.useOffsetServer.setSelected(OffsetServer.PROP_SERVER_ENABLED.get());
|
---|
106 | this.offsetServerUrl.setText(OsmosnimkiOffsetServer.PROP_SERVER_URL.get());
|
---|
107 | }
|
---|
108 |
|
---|
109 | /**
|
---|
110 | * Saves the common settings.
|
---|
111 | * @return true when restart is required
|
---|
112 | */
|
---|
113 | public boolean saveSettings() {
|
---|
114 | OffsetServer.PROP_SERVER_ENABLED.put(useOffsetServer.isSelected());
|
---|
115 | OsmosnimkiOffsetServer.PROP_SERVER_URL.put(offsetServerUrl.getText());
|
---|
116 |
|
---|
117 | ImageryLayer.PROP_FADE_AMOUNT.put(this.fadeAmount.getValue());
|
---|
118 | ImageryLayer.PROP_FADE_COLOR.put(this.btnFadeColor.getBackground());
|
---|
119 | ImageryLayer.PROP_SHARPEN_LEVEL.put(sharpen.getSelectedIndex());
|
---|
120 | return false;
|
---|
121 | }
|
---|
122 | }
|
---|