1 | /*
|
---|
2 | * Copyright (C) 2008 Innovant
|
---|
3 | *
|
---|
4 | * This program is free software; you can redistribute it and/or
|
---|
5 | * modify it under the terms of the GNU General Public License
|
---|
6 | * as published by the Free Software Foundation; either version 2
|
---|
7 | * of the License, or (at your option) any later version.
|
---|
8 | *
|
---|
9 | * This program is distributed in the hope that it will be useful,
|
---|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
12 | * GNU General Public License for more details.
|
---|
13 | *
|
---|
14 | * You should have received a copy of the GNU General Public License
|
---|
15 | * along with this program; if not, write to the Free Software
|
---|
16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
---|
17 | *
|
---|
18 | * For more information, please contact:
|
---|
19 | *
|
---|
20 | * Innovant
|
---|
21 | * juangui@gmail.com
|
---|
22 | * vidalfree@gmail.com
|
---|
23 | *
|
---|
24 | * http://public.grupoinnovant.com/blog
|
---|
25 | *
|
---|
26 | */
|
---|
27 |
|
---|
28 | package com.innovant.josm.plugin.routing.gui;
|
---|
29 |
|
---|
30 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
31 |
|
---|
32 | import java.awt.ComponentOrientation;
|
---|
33 | import java.awt.Font;
|
---|
34 | import java.awt.event.KeyEvent;
|
---|
35 |
|
---|
36 | import javax.swing.BorderFactory;
|
---|
37 | import javax.swing.BoxLayout;
|
---|
38 | import javax.swing.DefaultListModel;
|
---|
39 | import javax.swing.JList;
|
---|
40 | import javax.swing.JScrollPane;
|
---|
41 | import javax.swing.border.EtchedBorder;
|
---|
42 |
|
---|
43 | import org.openstreetmap.josm.Main;
|
---|
44 | import org.openstreetmap.josm.data.osm.Node;
|
---|
45 | import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
|
---|
46 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
47 |
|
---|
48 | import com.innovant.josm.plugin.routing.RoutingLayer;
|
---|
49 | import com.innovant.josm.plugin.routing.RoutingModel;
|
---|
50 |
|
---|
51 |
|
---|
52 | /**
|
---|
53 | * @author jose
|
---|
54 | *
|
---|
55 | */
|
---|
56 | public class RoutingDialog extends ToggleDialog {
|
---|
57 |
|
---|
58 | private DefaultListModel model;
|
---|
59 | private JList jList = null;
|
---|
60 | private JScrollPane jScrollPane = null;
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * Serial UID
|
---|
64 | */
|
---|
65 | private static final long serialVersionUID = 8625615652900341987L;
|
---|
66 |
|
---|
67 | public RoutingDialog() {
|
---|
68 | super(tr("Routing"), "routing", tr("Open a list of routing nodes"),
|
---|
69 | Shortcut.registerShortcut("subwindow:relations", tr("Toggle: {0}", tr("Routing")), KeyEvent.VK_R, Shortcut.GROUP_LAYER), 150);
|
---|
70 | model= new DefaultListModel();
|
---|
71 | this.setSize(456, 292);
|
---|
72 | this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
|
---|
73 | this.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));
|
---|
74 | this.setName("PrincipalDialog");
|
---|
75 | this.setFont(new Font("Dialog", Font.PLAIN, 12));
|
---|
76 | this.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
|
---|
77 | this.add(getJScrollPane(), null);
|
---|
78 |
|
---|
79 | }
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * This method initializes jScrollPane
|
---|
83 | *
|
---|
84 | * @return javax.swing.JScrollPane
|
---|
85 | */
|
---|
86 | private JScrollPane getJScrollPane() {
|
---|
87 | if (jScrollPane == null) {
|
---|
88 | jScrollPane = new JScrollPane();
|
---|
89 | jScrollPane.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
|
---|
90 | jScrollPane.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
|
---|
91 | jScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
---|
92 | jScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
|
---|
93 | jScrollPane.setName("nList");
|
---|
94 | jScrollPane.setViewportBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
|
---|
95 | jScrollPane.setViewportView(getJList());
|
---|
96 | }
|
---|
97 | return jScrollPane;
|
---|
98 | }
|
---|
99 |
|
---|
100 | /**
|
---|
101 | * This method initializes jList
|
---|
102 | *
|
---|
103 | * @return javax.swing.JList
|
---|
104 | */
|
---|
105 | private JList getJList() {
|
---|
106 | if (jList == null) {
|
---|
107 | jList = new JList();
|
---|
108 | jList.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
|
---|
109 | jList.setModel(model);
|
---|
110 | }
|
---|
111 | return jList;
|
---|
112 | }
|
---|
113 |
|
---|
114 | /**
|
---|
115 | * Remove item from the list of nodes
|
---|
116 | * @param index
|
---|
117 | */
|
---|
118 | public void removeNode(int index) {
|
---|
119 | model.remove(index);
|
---|
120 | }
|
---|
121 |
|
---|
122 | /**
|
---|
123 | * Add item to the list of nodes
|
---|
124 | * @param obj
|
---|
125 | */
|
---|
126 | public void addNode(Node n) {
|
---|
127 | model.addElement(n.getId()+" ["+n.getCoor().toDisplayString()+"]");
|
---|
128 | }
|
---|
129 |
|
---|
130 | /**
|
---|
131 | * Insert item to the list of nodes
|
---|
132 | * @param index
|
---|
133 | * @param obj
|
---|
134 | */
|
---|
135 | public void insertNode(int index, Node n) {
|
---|
136 | model.insertElementAt(n.getId()+" ["+n.getCoor().toDisplayString()+"]", index);
|
---|
137 | }
|
---|
138 |
|
---|
139 | /**
|
---|
140 | * Clear list of nodes
|
---|
141 | */
|
---|
142 | public void clearNodes() {
|
---|
143 | model.clear();
|
---|
144 | }
|
---|
145 |
|
---|
146 | public void refresh() {
|
---|
147 | clearNodes();
|
---|
148 | if (Main.map.mapView.getActiveLayer() instanceof RoutingLayer) {
|
---|
149 | RoutingLayer routingLayer = (RoutingLayer)Main.map.mapView.getActiveLayer();
|
---|
150 | RoutingModel routingModel = routingLayer.getRoutingModel();
|
---|
151 | for (Node n : routingModel.getSelectedNodes()) {
|
---|
152 | addNode(n);
|
---|
153 | }
|
---|
154 | }
|
---|
155 | }
|
---|
156 | }
|
---|