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