1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package com.innovant.josm.plugin.routing.gui;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.ComponentOrientation;
|
---|
7 | import java.awt.event.KeyEvent;
|
---|
8 |
|
---|
9 | import javax.swing.DefaultListModel;
|
---|
10 | import javax.swing.JList;
|
---|
11 | import javax.swing.JScrollPane;
|
---|
12 |
|
---|
13 | import org.openstreetmap.josm.data.osm.Node;
|
---|
14 | import org.openstreetmap.josm.gui.MainApplication;
|
---|
15 | import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
|
---|
16 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
17 |
|
---|
18 | import com.innovant.josm.plugin.routing.RoutingLayer;
|
---|
19 | import com.innovant.josm.plugin.routing.RoutingModel;
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * @author jose
|
---|
23 | *
|
---|
24 | */
|
---|
25 | public class RoutingDialog extends ToggleDialog {
|
---|
26 |
|
---|
27 | private final DefaultListModel<String> model;
|
---|
28 | private JList<String> jList = null;
|
---|
29 | private JScrollPane jScrollPane = null;
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * Serial UID
|
---|
33 | */
|
---|
34 | private static final long serialVersionUID = 8625615652900341987L;
|
---|
35 |
|
---|
36 | public RoutingDialog() {
|
---|
37 | super(tr("Routing"), "routing", tr("Open a list of routing nodes"),
|
---|
38 | Shortcut.registerShortcut("subwindow:routing", tr("Toggle: {0}", tr("Routing")), KeyEvent.VK_R, Shortcut.ALT_CTRL_SHIFT), 150);
|
---|
39 | model = new DefaultListModel<>();
|
---|
40 | createLayout(getJScrollPane(), false, null);
|
---|
41 | }
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * This method initializes jScrollPane
|
---|
45 | *
|
---|
46 | * @return javax.swing.JScrollPane
|
---|
47 | */
|
---|
48 | private JScrollPane getJScrollPane() {
|
---|
49 | if (jScrollPane == null) {
|
---|
50 | jScrollPane = new JScrollPane();
|
---|
51 | jScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
---|
52 | jScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
|
---|
53 | jScrollPane.setViewportView(getJList());
|
---|
54 | }
|
---|
55 | return jScrollPane;
|
---|
56 | }
|
---|
57 |
|
---|
58 | /**
|
---|
59 | * This method initializes jList
|
---|
60 | *
|
---|
61 | * @return javax.swing.JList
|
---|
62 | */
|
---|
63 | private JList<String> getJList() {
|
---|
64 | if (jList == null) {
|
---|
65 | jList = new JList<>();
|
---|
66 | jList.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
|
---|
67 | jList.setModel(model);
|
---|
68 | }
|
---|
69 | return jList;
|
---|
70 | }
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * Remove item from the list of nodes
|
---|
74 | */
|
---|
75 | public void removeNode(int index) {
|
---|
76 | model.remove(index);
|
---|
77 | }
|
---|
78 |
|
---|
79 | /**
|
---|
80 | * Add item to the list of nodes
|
---|
81 | */
|
---|
82 | public void addNode(Node n) {
|
---|
83 | model.addElement(n.getId()+" ["+n.getCoor().toDisplayString()+"]");
|
---|
84 | }
|
---|
85 |
|
---|
86 | /**
|
---|
87 | * Insert item to the list of nodes
|
---|
88 | */
|
---|
89 | public void insertNode(int index, Node n) {
|
---|
90 | model.insertElementAt(n.getId()+" ["+n.getCoor().toDisplayString()+"]", index);
|
---|
91 | }
|
---|
92 |
|
---|
93 | /**
|
---|
94 | * Clear list of nodes
|
---|
95 | */
|
---|
96 | public void clearNodes() {
|
---|
97 | model.clear();
|
---|
98 | }
|
---|
99 |
|
---|
100 | public void refresh() {
|
---|
101 | clearNodes();
|
---|
102 | if (MainApplication.getLayerManager().getActiveLayer() instanceof RoutingLayer) {
|
---|
103 | RoutingLayer routingLayer = (RoutingLayer) MainApplication.getLayerManager().getActiveLayer();
|
---|
104 | RoutingModel routingModel = routingLayer.getRoutingModel();
|
---|
105 | for (Node n : routingModel.getSelectedNodes()) {
|
---|
106 | addNode(n);
|
---|
107 | }
|
---|
108 | }
|
---|
109 | }
|
---|
110 | }
|
---|