1 | // License: GPL. See LICENSE file for details.
|
---|
2 | package org.openstreetmap.josm.gui.layer;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
|
---|
5 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
6 |
|
---|
7 | import java.awt.Color;
|
---|
8 | import java.awt.Component;
|
---|
9 | import java.awt.event.ActionEvent;
|
---|
10 | import java.util.LinkedList;
|
---|
11 | import java.util.List;
|
---|
12 |
|
---|
13 | import javax.swing.AbstractAction;
|
---|
14 | import javax.swing.Action;
|
---|
15 | import javax.swing.JColorChooser;
|
---|
16 | import javax.swing.JMenuItem;
|
---|
17 | import javax.swing.JOptionPane;
|
---|
18 |
|
---|
19 | import org.openstreetmap.josm.Main;
|
---|
20 | import org.openstreetmap.josm.gui.layer.Layer.LayerAction;
|
---|
21 | import org.openstreetmap.josm.gui.layer.Layer.MultiLayerAction;
|
---|
22 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
23 |
|
---|
24 | public class CustomizeColor extends AbstractAction implements LayerAction, MultiLayerAction {
|
---|
25 | List<Layer> layers;
|
---|
26 |
|
---|
27 | public CustomizeColor(List<Layer> l) {
|
---|
28 | this();
|
---|
29 | layers = l;
|
---|
30 | }
|
---|
31 |
|
---|
32 | public CustomizeColor(Layer l) {
|
---|
33 | this();
|
---|
34 | layers = new LinkedList<>();
|
---|
35 | layers.add(l);
|
---|
36 | }
|
---|
37 |
|
---|
38 | private CustomizeColor() {
|
---|
39 | super(tr("Customize Color"), ImageProvider.get("colorchooser"));
|
---|
40 | putValue("help", ht("/Action/LayerCustomizeColor"));
|
---|
41 | }
|
---|
42 |
|
---|
43 | @Override
|
---|
44 | public boolean supportLayers(List<Layer> layers) {
|
---|
45 | for(Layer layer: layers) {
|
---|
46 | if(layer.getColor(false) == null)
|
---|
47 | return false;
|
---|
48 | }
|
---|
49 | return true;
|
---|
50 | }
|
---|
51 |
|
---|
52 | @Override
|
---|
53 | public Component createMenuComponent() {
|
---|
54 | return new JMenuItem(this);
|
---|
55 | }
|
---|
56 |
|
---|
57 | @Override
|
---|
58 | public Action getMultiLayerAction(List<Layer> layers) {
|
---|
59 | return new CustomizeColor(layers);
|
---|
60 | }
|
---|
61 |
|
---|
62 | @Override
|
---|
63 | public void actionPerformed(ActionEvent e) {
|
---|
64 | Color cl=layers.get(0).getColor(false); if (cl==null) cl=Color.gray;
|
---|
65 | JColorChooser c = new JColorChooser(cl);
|
---|
66 | Object[] options = new Object[]{tr("OK"), tr("Cancel"), tr("Default")};
|
---|
67 | int answer = JOptionPane.showOptionDialog(
|
---|
68 | Main.parent,
|
---|
69 | c,
|
---|
70 | tr("Choose a color"),
|
---|
71 | JOptionPane.OK_CANCEL_OPTION,
|
---|
72 | JOptionPane.PLAIN_MESSAGE,
|
---|
73 | null,
|
---|
74 | options,
|
---|
75 | options[0]
|
---|
76 | );
|
---|
77 | switch (answer) {
|
---|
78 | case 0:
|
---|
79 | for(Layer layer : layers)
|
---|
80 | Main.pref.putColor("layer "+layer.getName(), c.getColor());
|
---|
81 | break;
|
---|
82 | case 1:
|
---|
83 | return;
|
---|
84 | case 2:
|
---|
85 | for(Layer layer : layers)
|
---|
86 | Main.pref.putColor("layer "+layer.getName(), null);
|
---|
87 | break;
|
---|
88 | }
|
---|
89 | Main.map.repaint();
|
---|
90 | }
|
---|
91 | }
|
---|