source: josm/trunk/src/org/openstreetmap/josm/gui/layer/CustomizeColor.java@ 10755

Last change on this file since 10755 was 9949, checked in by Don-vip, 8 years ago

remove deprecated stuff, code cleanup, javadoc, unit tests

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