1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.layer.gpx;
|
---|
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.Component;
|
---|
8 | import java.awt.Dimension;
|
---|
9 | import java.awt.Toolkit;
|
---|
10 | import java.awt.event.ActionEvent;
|
---|
11 | import java.util.LinkedList;
|
---|
12 | import java.util.List;
|
---|
13 |
|
---|
14 | import javax.swing.AbstractAction;
|
---|
15 | import javax.swing.Action;
|
---|
16 | import javax.swing.BorderFactory;
|
---|
17 | import javax.swing.JMenuItem;
|
---|
18 | import javax.swing.JOptionPane;
|
---|
19 | import javax.swing.JScrollPane;
|
---|
20 |
|
---|
21 | import org.openstreetmap.josm.Main;
|
---|
22 | import org.openstreetmap.josm.gui.layer.GpxLayer;
|
---|
23 | import org.openstreetmap.josm.gui.layer.Layer;
|
---|
24 | import org.openstreetmap.josm.gui.layer.Layer.LayerAction;
|
---|
25 | import org.openstreetmap.josm.gui.layer.Layer.MultiLayerAction;
|
---|
26 | import org.openstreetmap.josm.gui.preferences.display.GPXSettingsPanel;
|
---|
27 | import org.openstreetmap.josm.gui.util.GuiHelper;
|
---|
28 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
29 |
|
---|
30 | public class CustomizeDrawingAction extends AbstractAction implements LayerAction, MultiLayerAction {
|
---|
31 | private transient List<Layer> layers;
|
---|
32 |
|
---|
33 | public CustomizeDrawingAction(List<Layer> l) {
|
---|
34 | this();
|
---|
35 | layers = l;
|
---|
36 | }
|
---|
37 |
|
---|
38 | public CustomizeDrawingAction(Layer l) {
|
---|
39 | this();
|
---|
40 | layers = new LinkedList<>();
|
---|
41 | layers.add(l);
|
---|
42 | }
|
---|
43 |
|
---|
44 | private CustomizeDrawingAction() {
|
---|
45 | super(tr("Customize track drawing"), ImageProvider.get("mapmode/addsegment"));
|
---|
46 | putValue("help", ht("/Action/GPXLayerCustomizeLineDrawing"));
|
---|
47 | }
|
---|
48 |
|
---|
49 | @Override
|
---|
50 | public boolean supportLayers(List<Layer> layers) {
|
---|
51 | for (Layer layer : layers) {
|
---|
52 | if (!(layer instanceof GpxLayer)) {
|
---|
53 | return false;
|
---|
54 | }
|
---|
55 | }
|
---|
56 | return true;
|
---|
57 | }
|
---|
58 |
|
---|
59 | @Override
|
---|
60 | public Component createMenuComponent() {
|
---|
61 | return new JMenuItem(this);
|
---|
62 | }
|
---|
63 |
|
---|
64 | @Override
|
---|
65 | public Action getMultiLayerAction(List<Layer> layers) {
|
---|
66 | return new CustomizeDrawingAction(layers);
|
---|
67 | }
|
---|
68 |
|
---|
69 | @Override
|
---|
70 | public void actionPerformed(ActionEvent e) {
|
---|
71 | boolean hasLocal = false;
|
---|
72 | boolean hasNonlocal = false;
|
---|
73 | for (Layer layer : layers) {
|
---|
74 | if (layer instanceof GpxLayer) {
|
---|
75 | if (((GpxLayer) layer).isLocalFile()) {
|
---|
76 | hasLocal = true;
|
---|
77 | } else {
|
---|
78 | hasNonlocal = true;
|
---|
79 | }
|
---|
80 | }
|
---|
81 | }
|
---|
82 | GPXSettingsPanel panel = new GPXSettingsPanel(layers.get(0).getName(), hasLocal, hasNonlocal);
|
---|
83 | JScrollPane scrollpane = GuiHelper.embedInVerticalScrollPane(panel);
|
---|
84 | scrollpane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
|
---|
85 | int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
|
---|
86 | if (screenHeight < 700) {
|
---|
87 | // to fit on screen 800x600
|
---|
88 | scrollpane.setPreferredSize(new Dimension(panel.getPreferredSize().width, Math.min(panel.getPreferredSize().height, 450)));
|
---|
89 | }
|
---|
90 | int answer = JOptionPane.showConfirmDialog(Main.parent, scrollpane, tr("Customize track drawing"),
|
---|
91 | JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
|
---|
92 | if (answer == JOptionPane.CANCEL_OPTION || answer == JOptionPane.CLOSED_OPTION) {
|
---|
93 | return;
|
---|
94 | }
|
---|
95 | for (Layer layer : layers) {
|
---|
96 | // save preferences for all layers
|
---|
97 | boolean f = false;
|
---|
98 | if (layer instanceof GpxLayer) {
|
---|
99 | f = ((GpxLayer) layer).isLocalFile();
|
---|
100 | }
|
---|
101 | panel.savePreferences(layer.getName(), f);
|
---|
102 | }
|
---|
103 | Main.map.repaint();
|
---|
104 | }
|
---|
105 |
|
---|
106 | }
|
---|