source: josm/trunk/src/org/openstreetmap/josm/gui/layer/gpx/CustomizeDrawingAction.java@ 15735

Last change on this file since 15735 was 15735, checked in by simon04, 4 years ago

Java 8: replace .stream().forEach() with .forEach()

  • Property svn:eol-style set to native
File size: 3.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.layer.gpx;
3
4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
5import static org.openstreetmap.josm.tools.I18n.tr;
6
7import java.awt.Component;
8import java.awt.Dimension;
9import java.awt.event.ActionEvent;
10import java.util.LinkedList;
11import java.util.List;
12import java.util.stream.Collectors;
13
14import javax.swing.AbstractAction;
15import javax.swing.Action;
16import javax.swing.BorderFactory;
17import javax.swing.JMenuItem;
18import javax.swing.JOptionPane;
19import javax.swing.JScrollPane;
20
21import org.openstreetmap.josm.gui.MainApplication;
22import org.openstreetmap.josm.gui.layer.GpxLayer;
23import org.openstreetmap.josm.gui.layer.Layer;
24import org.openstreetmap.josm.gui.layer.Layer.LayerAction;
25import org.openstreetmap.josm.gui.layer.Layer.MultiLayerAction;
26import org.openstreetmap.josm.gui.preferences.display.GPXSettingsPanel;
27import org.openstreetmap.josm.gui.util.GuiHelper;
28import org.openstreetmap.josm.tools.ImageProvider;
29
30/**
31 * An action that is displayed in the popup menu for the layer to change the drawing of the GPX layer
32 */
33public class CustomizeDrawingAction extends AbstractAction implements LayerAction, MultiLayerAction {
34 private transient List<Layer> layers;
35
36 /**
37 * Create a new {@link CustomizeDrawingAction}
38 * @param l The layers that should be customized
39 */
40 public CustomizeDrawingAction(List<Layer> l) {
41 this();
42 layers = l;
43 }
44
45 /**
46 * Create a new {@link CustomizeDrawingAction}
47 * @param l The layer that should be customized
48 */
49 public CustomizeDrawingAction(Layer l) {
50 this();
51 layers = new LinkedList<>();
52 layers.add(l);
53 }
54
55 private CustomizeDrawingAction() {
56 super(tr("Customize track drawing"));
57 new ImageProvider("mapmode/addsegment").getResource().attachImageIcon(this, true);
58 putValue("help", ht("/Action/GPXLayerCustomizeLineDrawing"));
59 }
60
61 @Override
62 public boolean supportLayers(List<Layer> layers) {
63 return layers.stream().allMatch(l -> l instanceof GpxLayer);
64 }
65
66 @Override
67 public Component createMenuComponent() {
68 return new JMenuItem(this);
69 }
70
71 @Override
72 public Action getMultiLayerAction(List<Layer> layers) {
73 return new CustomizeDrawingAction(layers);
74 }
75
76 @Override
77 public void actionPerformed(ActionEvent e) {
78 GPXSettingsPanel panel = new GPXSettingsPanel(
79 layers.stream().filter(l -> l instanceof GpxLayer).map(l -> (GpxLayer) l).collect(Collectors.toList()));
80 JScrollPane scrollpane = GuiHelper.embedInVerticalScrollPane(panel);
81 scrollpane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
82 int screenHeight = GuiHelper.getScreenSize().height;
83 if (screenHeight < 700) {
84 // to fit on screen 800x600
85 scrollpane.setPreferredSize(new Dimension(panel.getPreferredSize().width, Math.min(panel.getPreferredSize().height, 450)));
86 }
87 int answer = JOptionPane.showConfirmDialog(MainApplication.getMainFrame(), scrollpane, tr("Customize track drawing"),
88 JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
89 if (answer == JOptionPane.CANCEL_OPTION || answer == JOptionPane.CLOSED_OPTION) {
90 return;
91 }
92 panel.savePreferences();
93 MainApplication.getMainPanel().repaint();
94 layers.forEach(Layer::invalidate);
95 }
96
97}
Note: See TracBrowser for help on using the repository browser.