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.JColorChooser;
|
---|
13 | import javax.swing.JLabel;
|
---|
14 | import javax.swing.JOptionPane;
|
---|
15 | import javax.swing.JPanel;
|
---|
16 | import javax.swing.JSlider;
|
---|
17 |
|
---|
18 | import org.openstreetmap.josm.gui.layer.ImageryLayer;
|
---|
19 | import org.openstreetmap.josm.gui.widgets.JosmComboBox;
|
---|
20 | import org.openstreetmap.josm.tools.ColorHelper;
|
---|
21 | import org.openstreetmap.josm.tools.GBC;
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * {@code JPanel} giving access to common imagery settings.
|
---|
25 | * @since 5465
|
---|
26 | */
|
---|
27 | public class CommonSettingsPanel extends JPanel {
|
---|
28 |
|
---|
29 | // Common Settings
|
---|
30 | private final JButton btnFadeColor;
|
---|
31 | private final JSlider fadeAmount = new JSlider(0, 100);
|
---|
32 | private final JosmComboBox<String> sharpen;
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * Constructs a new {@code CommonSettingsPanel}.
|
---|
36 | */
|
---|
37 | public CommonSettingsPanel() {
|
---|
38 | super(new GridBagLayout());
|
---|
39 |
|
---|
40 | this.btnFadeColor = new JButton();
|
---|
41 |
|
---|
42 | this.btnFadeColor.addActionListener(new ActionListener() {
|
---|
43 | @Override
|
---|
44 | public void actionPerformed(ActionEvent e) {
|
---|
45 | JColorChooser chooser = new JColorChooser(btnFadeColor.getBackground());
|
---|
46 | int answer = JOptionPane.showConfirmDialog(
|
---|
47 | CommonSettingsPanel.this, chooser,
|
---|
48 | tr("Choose a color for {0}", tr("imagery fade")),
|
---|
49 | JOptionPane.OK_CANCEL_OPTION,
|
---|
50 | JOptionPane.PLAIN_MESSAGE);
|
---|
51 | if (answer == JOptionPane.OK_OPTION) {
|
---|
52 | Color colFadeColor = chooser.getColor();
|
---|
53 | btnFadeColor.setBackground(colFadeColor);
|
---|
54 | btnFadeColor.setText(ColorHelper.color2html(colFadeColor));
|
---|
55 | }
|
---|
56 | }
|
---|
57 | });
|
---|
58 |
|
---|
59 | add(new JLabel(tr("Fade Color: ")), GBC.std());
|
---|
60 | add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL));
|
---|
61 | add(this.btnFadeColor, GBC.eol().fill(GBC.HORIZONTAL));
|
---|
62 |
|
---|
63 | add(new JLabel(tr("Fade amount: ")), GBC.std());
|
---|
64 | add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL));
|
---|
65 | add(this.fadeAmount, GBC.eol().fill(GBC.HORIZONTAL));
|
---|
66 |
|
---|
67 | this.sharpen = new JosmComboBox<>(new String[] {
|
---|
68 | tr("None"),
|
---|
69 | tr("Soft"),
|
---|
70 | tr("Strong")});
|
---|
71 | add(new JLabel(tr("Sharpen (requires layer re-add): ")));
|
---|
72 | add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL));
|
---|
73 | add(this.sharpen, GBC.eol().fill(GBC.HORIZONTAL));
|
---|
74 | }
|
---|
75 |
|
---|
76 | /**
|
---|
77 | * Loads the common settings.
|
---|
78 | */
|
---|
79 | public void loadSettings() {
|
---|
80 | Color colFadeColor = ImageryLayer.PROP_FADE_COLOR.get();
|
---|
81 | this.btnFadeColor.setBackground(colFadeColor);
|
---|
82 | this.btnFadeColor.setText(ColorHelper.color2html(colFadeColor));
|
---|
83 | this.fadeAmount.setValue(ImageryLayer.PROP_FADE_AMOUNT.get());
|
---|
84 | this.sharpen.setSelectedIndex(Math.max(0, Math.min(2, ImageryLayer.PROP_SHARPEN_LEVEL.get())));
|
---|
85 | }
|
---|
86 |
|
---|
87 | /**
|
---|
88 | * Saves the common settings.
|
---|
89 | * @return true when restart is required
|
---|
90 | */
|
---|
91 | public boolean saveSettings() {
|
---|
92 | ImageryLayer.PROP_FADE_AMOUNT.put(this.fadeAmount.getValue());
|
---|
93 | ImageryLayer.PROP_FADE_COLOR.put(this.btnFadeColor.getBackground());
|
---|
94 | ImageryLayer.PROP_SHARPEN_LEVEL.put(sharpen.getSelectedIndex());
|
---|
95 | return false;
|
---|
96 | }
|
---|
97 | }
|
---|