1 | package org.openstreetmap.josm.gui.conflict.nodes;
|
---|
2 |
|
---|
3 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
4 |
|
---|
5 | import java.awt.GridBagConstraints;
|
---|
6 | import java.awt.GridBagLayout;
|
---|
7 | import java.awt.event.ActionEvent;
|
---|
8 | import java.awt.event.ItemEvent;
|
---|
9 | import java.awt.event.ItemListener;
|
---|
10 | import java.beans.PropertyChangeEvent;
|
---|
11 | import java.beans.PropertyChangeListener;
|
---|
12 | import java.net.URL;
|
---|
13 | import java.util.logging.Logger;
|
---|
14 |
|
---|
15 | import javax.swing.AbstractAction;
|
---|
16 | import javax.swing.Action;
|
---|
17 | import javax.swing.ImageIcon;
|
---|
18 | import javax.swing.JButton;
|
---|
19 | import javax.swing.JLabel;
|
---|
20 | import javax.swing.JPanel;
|
---|
21 | import javax.swing.JScrollPane;
|
---|
22 | import javax.swing.JTable;
|
---|
23 | import javax.swing.JToggleButton;
|
---|
24 | import javax.swing.event.ListSelectionEvent;
|
---|
25 | import javax.swing.event.ListSelectionListener;
|
---|
26 |
|
---|
27 | import org.openstreetmap.josm.data.osm.Way;
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * A UI component for resolving conflicts in the node lists of two {@see Way}s.
|
---|
31 | *
|
---|
32 | */
|
---|
33 | public class NodeListMerger extends JPanel implements PropertyChangeListener {
|
---|
34 | private static final Logger logger = Logger.getLogger(NodeListMerger.class.getName());
|
---|
35 |
|
---|
36 | private JTable myNodes;
|
---|
37 | private JTable mergedNodes;
|
---|
38 | private JTable theirNodes;
|
---|
39 |
|
---|
40 | private NodeListMergeModel model;
|
---|
41 |
|
---|
42 |
|
---|
43 | private CopyStartLeftAction copyStartLeftAction;
|
---|
44 | private CopyBeforeCurrentLeftAction copyBeforeCurrentLeftAction;
|
---|
45 | private CopyAfterCurrentLeftAction copyAfterCurrentLeftAction;
|
---|
46 | private CopyEndLeftAction copyEndLeftAction;
|
---|
47 |
|
---|
48 | private CopyStartRightAction copyStartRightAction;
|
---|
49 | private CopyBeforeCurrentRightAction copyBeforeCurrentRightAction;
|
---|
50 | private CopyAfterCurrentRightAction copyAfterCurrentRightAction;
|
---|
51 | private CopyEndRightAction copyEndRightAction;
|
---|
52 |
|
---|
53 | private MoveUpMergedAction moveUpMergedAction;
|
---|
54 | private MoveDownMergedAction moveDownMergedAction;
|
---|
55 | private RemoveMergedAction removeMergedAction;
|
---|
56 | private FreezeAction freezeAction;
|
---|
57 |
|
---|
58 |
|
---|
59 |
|
---|
60 | protected JScrollPane embeddInScrollPane(JTable table) {
|
---|
61 | JScrollPane pane = new JScrollPane(table);
|
---|
62 | pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
---|
63 | pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
|
---|
64 | return pane;
|
---|
65 | }
|
---|
66 |
|
---|
67 | protected JScrollPane buildMyNodesTable() {
|
---|
68 | myNodes = new JTable(
|
---|
69 | model.getMyNodesTableModel(),
|
---|
70 | new NodeListColumnModel(
|
---|
71 | new NodeListTableCellRenderer()
|
---|
72 | ),
|
---|
73 | model.getMyNodesSelectionModel()
|
---|
74 | );
|
---|
75 | myNodes.setName("table.mynodes");
|
---|
76 | return embeddInScrollPane(myNodes);
|
---|
77 | }
|
---|
78 |
|
---|
79 | protected JScrollPane buildMergedNodesTable() {
|
---|
80 | mergedNodes = new JTable(
|
---|
81 | model.getMergedNodesTableModel(),
|
---|
82 | new NodeListColumnModel(
|
---|
83 | new NodeListTableCellRenderer()
|
---|
84 | ),
|
---|
85 | model.getMergedNodesSelectionModel()
|
---|
86 | );
|
---|
87 | mergedNodes.setName("table.mergednodes");
|
---|
88 | return embeddInScrollPane(mergedNodes);
|
---|
89 | }
|
---|
90 |
|
---|
91 | protected JScrollPane buildTheirNodesTable() {
|
---|
92 | theirNodes = new JTable(
|
---|
93 | model.getTheirNodesTableModel(),
|
---|
94 | new NodeListColumnModel(
|
---|
95 | new NodeListTableCellRenderer()
|
---|
96 | ),
|
---|
97 | model.getTheirNodesSelectionModel()
|
---|
98 | );
|
---|
99 | theirNodes.setName("table.theirnodes");
|
---|
100 | return embeddInScrollPane(theirNodes);
|
---|
101 | }
|
---|
102 |
|
---|
103 | protected void wireActionsToSelectionModels() {
|
---|
104 | myNodes.getSelectionModel().addListSelectionListener(copyStartLeftAction);
|
---|
105 |
|
---|
106 | myNodes.getSelectionModel().addListSelectionListener(copyBeforeCurrentLeftAction);
|
---|
107 | mergedNodes.getSelectionModel().addListSelectionListener(copyBeforeCurrentLeftAction);
|
---|
108 |
|
---|
109 | myNodes.getSelectionModel().addListSelectionListener(copyAfterCurrentLeftAction);
|
---|
110 | mergedNodes.getSelectionModel().addListSelectionListener(copyAfterCurrentLeftAction);
|
---|
111 |
|
---|
112 | myNodes.getSelectionModel().addListSelectionListener(copyEndLeftAction);
|
---|
113 |
|
---|
114 |
|
---|
115 | theirNodes.getSelectionModel().addListSelectionListener(copyStartRightAction);
|
---|
116 |
|
---|
117 | theirNodes.getSelectionModel().addListSelectionListener(copyBeforeCurrentRightAction);
|
---|
118 | mergedNodes.getSelectionModel().addListSelectionListener(copyBeforeCurrentRightAction);
|
---|
119 |
|
---|
120 | theirNodes.getSelectionModel().addListSelectionListener(copyAfterCurrentRightAction);
|
---|
121 | mergedNodes.getSelectionModel().addListSelectionListener(copyAfterCurrentRightAction);
|
---|
122 |
|
---|
123 | theirNodes.getSelectionModel().addListSelectionListener(copyEndRightAction);
|
---|
124 |
|
---|
125 | mergedNodes.getSelectionModel().addListSelectionListener(moveUpMergedAction);
|
---|
126 | mergedNodes.getSelectionModel().addListSelectionListener(moveDownMergedAction);
|
---|
127 | mergedNodes.getSelectionModel().addListSelectionListener(removeMergedAction);
|
---|
128 | }
|
---|
129 |
|
---|
130 |
|
---|
131 |
|
---|
132 | protected JPanel buildLeftButtonPanel() {
|
---|
133 | JPanel pnl = new JPanel();
|
---|
134 | pnl.setLayout(new GridBagLayout());
|
---|
135 | GridBagConstraints gc = new GridBagConstraints();
|
---|
136 |
|
---|
137 | gc.gridx = 0;
|
---|
138 | gc.gridy = 0;
|
---|
139 | copyStartLeftAction = new CopyStartLeftAction();
|
---|
140 | JButton btn = new JButton(copyStartLeftAction);
|
---|
141 | btn.setName("button.copystartleft");
|
---|
142 | pnl.add(btn, gc);
|
---|
143 |
|
---|
144 | gc.gridx = 0;
|
---|
145 | gc.gridy = 1;
|
---|
146 | copyBeforeCurrentLeftAction = new CopyBeforeCurrentLeftAction();
|
---|
147 | btn = new JButton(copyBeforeCurrentLeftAction);
|
---|
148 | btn.setName("button.copybeforecurrentleft");
|
---|
149 | pnl.add(btn, gc);
|
---|
150 |
|
---|
151 | gc.gridx = 0;
|
---|
152 | gc.gridy = 2;
|
---|
153 | copyAfterCurrentLeftAction = new CopyAfterCurrentLeftAction();
|
---|
154 | btn = new JButton(copyAfterCurrentLeftAction);
|
---|
155 | btn.setName("button.copyaftercurrentleft");
|
---|
156 | pnl.add(btn, gc);
|
---|
157 |
|
---|
158 | gc.gridx = 0;
|
---|
159 | gc.gridy = 3;
|
---|
160 | copyEndLeftAction = new CopyEndLeftAction();
|
---|
161 | btn = new JButton(copyEndLeftAction);
|
---|
162 | btn.setName("button.copyendleft");
|
---|
163 | pnl.add(btn, gc);
|
---|
164 |
|
---|
165 |
|
---|
166 | return pnl;
|
---|
167 | }
|
---|
168 |
|
---|
169 | protected JPanel buildRightButtonPanel() {
|
---|
170 | JPanel pnl = new JPanel();
|
---|
171 | pnl.setLayout(new GridBagLayout());
|
---|
172 | GridBagConstraints gc = new GridBagConstraints();
|
---|
173 |
|
---|
174 | gc.gridx = 0;
|
---|
175 | gc.gridy = 0;
|
---|
176 | copyStartRightAction = new CopyStartRightAction();
|
---|
177 | pnl.add(new JButton(copyStartRightAction), gc);
|
---|
178 |
|
---|
179 | gc.gridx = 0;
|
---|
180 | gc.gridy = 1;
|
---|
181 | copyBeforeCurrentRightAction = new CopyBeforeCurrentRightAction();
|
---|
182 | pnl.add(new JButton(copyBeforeCurrentRightAction), gc);
|
---|
183 |
|
---|
184 | gc.gridx = 0;
|
---|
185 | gc.gridy = 2;
|
---|
186 | copyAfterCurrentRightAction = new CopyAfterCurrentRightAction();
|
---|
187 | pnl.add(new JButton(copyAfterCurrentRightAction), gc);
|
---|
188 |
|
---|
189 | gc.gridx = 0;
|
---|
190 | gc.gridy = 3;
|
---|
191 | copyEndRightAction = new CopyEndRightAction();
|
---|
192 | pnl.add(new JButton(copyEndRightAction), gc);
|
---|
193 |
|
---|
194 | return pnl;
|
---|
195 | }
|
---|
196 |
|
---|
197 | protected JPanel buildMergedListControlButtons() {
|
---|
198 | JPanel pnl = new JPanel();
|
---|
199 | pnl.setLayout(new GridBagLayout());
|
---|
200 | GridBagConstraints gc = new GridBagConstraints();
|
---|
201 |
|
---|
202 | gc.gridx = 0;
|
---|
203 | gc.gridy = 0;
|
---|
204 | gc.gridwidth = 1;
|
---|
205 | gc.gridheight = 1;
|
---|
206 | gc.fill = GridBagConstraints.HORIZONTAL;
|
---|
207 | gc.anchor = GridBagConstraints.CENTER;
|
---|
208 | gc.weightx = 0.3;
|
---|
209 | gc.weighty = 0.0;
|
---|
210 | moveUpMergedAction = new MoveUpMergedAction();
|
---|
211 | pnl.add(new JButton(moveUpMergedAction), gc);
|
---|
212 |
|
---|
213 | gc.gridx = 1;
|
---|
214 | gc.gridy = 0;
|
---|
215 | moveDownMergedAction = new MoveDownMergedAction();
|
---|
216 | pnl.add(new JButton(moveDownMergedAction), gc);
|
---|
217 |
|
---|
218 | gc.gridx = 2;
|
---|
219 | gc.gridy = 0;
|
---|
220 | removeMergedAction = new RemoveMergedAction();
|
---|
221 | pnl.add(new JButton(removeMergedAction), gc);
|
---|
222 |
|
---|
223 | gc.gridx = 0;
|
---|
224 | gc.gridy = 1;
|
---|
225 | gc.gridwidth = 3;
|
---|
226 | gc.weightx = 1.0;
|
---|
227 | freezeAction = new FreezeAction();
|
---|
228 | JToggleButton btn = new JToggleButton(freezeAction);
|
---|
229 | btn.setName("button.freeze");
|
---|
230 | btn.addItemListener(freezeAction);
|
---|
231 | pnl.add(btn, gc);
|
---|
232 |
|
---|
233 | return pnl;
|
---|
234 | }
|
---|
235 |
|
---|
236 |
|
---|
237 | protected void build() {
|
---|
238 |
|
---|
239 | setLayout(new GridBagLayout());
|
---|
240 | GridBagConstraints gc = new GridBagConstraints();
|
---|
241 |
|
---|
242 | gc.gridx = 0;
|
---|
243 | gc.gridy = 0;
|
---|
244 | gc.gridwidth = 1;
|
---|
245 | gc.gridheight = 1;
|
---|
246 | gc.fill = GridBagConstraints.NONE;
|
---|
247 | gc.anchor = GridBagConstraints.CENTER;
|
---|
248 | gc.weightx = 0.0;
|
---|
249 | gc.weighty = 0.0;
|
---|
250 | JLabel lbl = new JLabel(tr("Nodes in my version (local dataset)"));
|
---|
251 | add(lbl, gc);
|
---|
252 |
|
---|
253 | gc.gridx = 2;
|
---|
254 | gc.gridy = 0;
|
---|
255 | gc.gridwidth = 1;
|
---|
256 | gc.gridheight = 1;
|
---|
257 | gc.fill = GridBagConstraints.NONE;
|
---|
258 | gc.anchor = GridBagConstraints.CENTER;
|
---|
259 | gc.weightx = 0.0;
|
---|
260 | gc.weighty = 0.0;
|
---|
261 | lbl = new JLabel(tr("Merged version"));
|
---|
262 | add(lbl, gc);
|
---|
263 |
|
---|
264 | gc.gridx = 4;
|
---|
265 | gc.gridy = 0;
|
---|
266 | gc.gridwidth = 1;
|
---|
267 | gc.gridheight = 1;
|
---|
268 | gc.fill = GridBagConstraints.NONE;
|
---|
269 | gc.anchor = GridBagConstraints.CENTER;
|
---|
270 | gc.weightx = 0.0;
|
---|
271 | gc.weighty = 0.0;
|
---|
272 | lbl = new JLabel(tr("Nodes in their version (server dataset)"));
|
---|
273 | add(lbl, gc);
|
---|
274 |
|
---|
275 |
|
---|
276 | gc.gridx = 0;
|
---|
277 | gc.gridy = 1;
|
---|
278 | gc.gridwidth = 1;
|
---|
279 | gc.gridheight = 1;
|
---|
280 | gc.fill = GridBagConstraints.BOTH;
|
---|
281 | gc.anchor = GridBagConstraints.FIRST_LINE_START;
|
---|
282 | gc.weightx = 0.3;
|
---|
283 | gc.weighty = 1.0;
|
---|
284 | add(buildMyNodesTable(), gc);
|
---|
285 |
|
---|
286 | gc.gridx = 1;
|
---|
287 | gc.gridy = 1;
|
---|
288 | gc.gridwidth = 1;
|
---|
289 | gc.gridheight = 1;
|
---|
290 | gc.fill = GridBagConstraints.NONE;
|
---|
291 | gc.anchor = GridBagConstraints.CENTER;
|
---|
292 | gc.weightx = 0.0;
|
---|
293 | gc.weighty = 0.0;
|
---|
294 | add(buildLeftButtonPanel(), gc);
|
---|
295 |
|
---|
296 | gc.gridx = 2;
|
---|
297 | gc.gridy = 1;
|
---|
298 | gc.gridwidth = 1;
|
---|
299 | gc.gridheight = 1;
|
---|
300 | gc.fill = GridBagConstraints.BOTH;
|
---|
301 | gc.anchor = GridBagConstraints.FIRST_LINE_START;
|
---|
302 | gc.weightx = 0.3;
|
---|
303 | gc.weighty = 0.0;
|
---|
304 | add(buildMergedNodesTable(), gc);
|
---|
305 |
|
---|
306 | gc.gridx = 3;
|
---|
307 | gc.gridy = 1;
|
---|
308 | gc.gridwidth = 1;
|
---|
309 | gc.gridheight = 1;
|
---|
310 | gc.fill = GridBagConstraints.NONE;
|
---|
311 | gc.anchor = GridBagConstraints.CENTER;
|
---|
312 | gc.weightx = 0.0;
|
---|
313 | gc.weighty = 0.0;
|
---|
314 | add(buildRightButtonPanel(), gc);
|
---|
315 |
|
---|
316 | gc.gridx = 4;
|
---|
317 | gc.gridy = 1;
|
---|
318 | gc.gridwidth = 1;
|
---|
319 | gc.gridheight = 1;
|
---|
320 | gc.fill = GridBagConstraints.BOTH;
|
---|
321 | gc.anchor = GridBagConstraints.FIRST_LINE_START;
|
---|
322 | gc.weightx = 0.3;
|
---|
323 | gc.weighty = 0.0;
|
---|
324 | add(buildTheirNodesTable(), gc);
|
---|
325 |
|
---|
326 | gc.gridx = 2;
|
---|
327 | gc.gridy = 2;
|
---|
328 | gc.gridwidth = 1;
|
---|
329 | gc.gridheight = 1;
|
---|
330 | gc.fill = GridBagConstraints.BOTH;
|
---|
331 | gc.anchor = GridBagConstraints.CENTER;
|
---|
332 | gc.weightx = 0.3;
|
---|
333 | gc.weighty = 0.0;
|
---|
334 | add(buildMergedListControlButtons(), gc);
|
---|
335 |
|
---|
336 | wireActionsToSelectionModels();
|
---|
337 | }
|
---|
338 |
|
---|
339 | public NodeListMerger() {
|
---|
340 | model = new NodeListMergeModel();
|
---|
341 | build();
|
---|
342 | model.addPropertyChangeListener(this);
|
---|
343 | }
|
---|
344 |
|
---|
345 | public void populate(Way my, Way their) {
|
---|
346 | model.populate(my, their);
|
---|
347 | }
|
---|
348 |
|
---|
349 | /**
|
---|
350 | * Action for copying selected nodes in the list of my nodes to the list of merged
|
---|
351 | * nodes. Inserts the nodes at the beginning of the list of merged nodes.
|
---|
352 | *
|
---|
353 | */
|
---|
354 | abstract class AbstractNodeManipulationAction extends AbstractAction {
|
---|
355 |
|
---|
356 | /**
|
---|
357 | * load an icon given by iconName
|
---|
358 | *
|
---|
359 | * @param iconName the name of the icon (without path, i.e. <tt>copystartleft.png</tt>
|
---|
360 | * @return the icon; null, if the icon was not found
|
---|
361 | */
|
---|
362 | protected ImageIcon getIcon(String iconName) {
|
---|
363 | String fullIconName = "/images/dialogs/conflict/" + iconName;
|
---|
364 | URL imageURL = this.getClass().getResource(fullIconName);
|
---|
365 | if (imageURL == null) {
|
---|
366 | System.out.println(tr("WARNING: failed to load resource {0}", fullIconName));
|
---|
367 | return null;
|
---|
368 | }
|
---|
369 | return new ImageIcon(imageURL);
|
---|
370 | }
|
---|
371 | }
|
---|
372 |
|
---|
373 | /**
|
---|
374 | * Action for copying selected nodes in the list of my nodes to the list of merged
|
---|
375 | * nodes. Inserts the nodes at the beginning of the list of merged nodes.
|
---|
376 | *
|
---|
377 | */
|
---|
378 | class CopyStartLeftAction extends AbstractNodeManipulationAction implements ListSelectionListener {
|
---|
379 |
|
---|
380 | public CopyStartLeftAction() {
|
---|
381 | ImageIcon icon = getIcon("copystartleft.png");
|
---|
382 | putValue(Action.SMALL_ICON, icon);
|
---|
383 | if (icon == null) {
|
---|
384 | putValue(Action.NAME, tr("> top"));
|
---|
385 | }
|
---|
386 | putValue(Action.SHORT_DESCRIPTION, tr("Copy my selected nodes to the start of the merged node list"));
|
---|
387 | setEnabled(false);
|
---|
388 | }
|
---|
389 |
|
---|
390 | public void actionPerformed(ActionEvent arg0) {
|
---|
391 | int [] rows = myNodes.getSelectedRows();
|
---|
392 | model.copyMyNodesToTop(rows);
|
---|
393 | }
|
---|
394 |
|
---|
395 | public void valueChanged(ListSelectionEvent e) {
|
---|
396 | setEnabled(!myNodes.getSelectionModel().isSelectionEmpty());
|
---|
397 | }
|
---|
398 | }
|
---|
399 |
|
---|
400 | /**
|
---|
401 | * Action for copying selected nodes in the list of my nodes to the list of merged
|
---|
402 | * nodes. Inserts the nodes at the end of the list of merged nodes.
|
---|
403 | *
|
---|
404 | */
|
---|
405 | class CopyEndLeftAction extends AbstractNodeManipulationAction implements ListSelectionListener {
|
---|
406 |
|
---|
407 | public CopyEndLeftAction() {
|
---|
408 | ImageIcon icon = getIcon("copyendleft.png");
|
---|
409 | putValue(Action.SMALL_ICON, icon);
|
---|
410 | if (icon == null) {
|
---|
411 | putValue(Action.NAME, tr("> bottom"));
|
---|
412 | }
|
---|
413 | putValue(Action.SHORT_DESCRIPTION, tr("Copy my selected nodes to the end of the merged node list"));
|
---|
414 | setEnabled(false);
|
---|
415 | }
|
---|
416 |
|
---|
417 | public void actionPerformed(ActionEvent arg0) {
|
---|
418 | int [] rows = myNodes.getSelectedRows();
|
---|
419 | model.copyMyNodesToEnd(rows);
|
---|
420 | }
|
---|
421 |
|
---|
422 | public void valueChanged(ListSelectionEvent e) {
|
---|
423 | setEnabled(!myNodes.getSelectionModel().isSelectionEmpty());
|
---|
424 | }
|
---|
425 | }
|
---|
426 |
|
---|
427 | /**
|
---|
428 | * Action for copying selected nodes in the list of my nodes to the list of merged
|
---|
429 | * nodes. Inserts the nodes before the first selected row in the list of merged nodes.
|
---|
430 | *
|
---|
431 | */
|
---|
432 | class CopyBeforeCurrentLeftAction extends AbstractNodeManipulationAction implements ListSelectionListener {
|
---|
433 |
|
---|
434 | public CopyBeforeCurrentLeftAction() {
|
---|
435 | ImageIcon icon = getIcon("copybeforecurrentleft.png");
|
---|
436 | putValue(Action.SMALL_ICON, icon);
|
---|
437 | if (icon == null) {
|
---|
438 | putValue(Action.NAME, "> before");
|
---|
439 | }
|
---|
440 | putValue(Action.SHORT_DESCRIPTION, tr("Copy my selected nodes before the first selected node in the merged node list"));
|
---|
441 | setEnabled(false);
|
---|
442 | }
|
---|
443 |
|
---|
444 | public void actionPerformed(ActionEvent arg0) {
|
---|
445 | int [] myRows = myNodes.getSelectedRows();
|
---|
446 | int [] mergedRows = mergedNodes.getSelectedRows();
|
---|
447 | if (mergedRows == null || mergedRows.length == 0) {
|
---|
448 | return;
|
---|
449 | }
|
---|
450 | int current = mergedRows[0];
|
---|
451 | model.copyMyNodesBeforeCurrent(myRows, current);
|
---|
452 | }
|
---|
453 |
|
---|
454 | public void valueChanged(ListSelectionEvent e) {
|
---|
455 | setEnabled(
|
---|
456 | !myNodes.getSelectionModel().isSelectionEmpty()
|
---|
457 | && ! mergedNodes.getSelectionModel().isSelectionEmpty()
|
---|
458 | );
|
---|
459 | }
|
---|
460 | }
|
---|
461 |
|
---|
462 | /**
|
---|
463 | * Action for copying selected nodes in the list of my nodes to the list of merged
|
---|
464 | * nodes. Inserts the nodes after the first selected row in the list of merged nodes.
|
---|
465 | *
|
---|
466 | */
|
---|
467 | class CopyAfterCurrentLeftAction extends AbstractNodeManipulationAction implements ListSelectionListener {
|
---|
468 |
|
---|
469 | public CopyAfterCurrentLeftAction() {
|
---|
470 | ImageIcon icon = getIcon("copyaftercurrentleft.png");
|
---|
471 | putValue(Action.SMALL_ICON, icon);
|
---|
472 | if (icon == null) {
|
---|
473 | putValue(Action.NAME, "> after");
|
---|
474 | }
|
---|
475 | putValue(Action.SHORT_DESCRIPTION, tr("Copy my selected nodes after the first selected node in the merged node list"));
|
---|
476 | setEnabled(false);
|
---|
477 | }
|
---|
478 |
|
---|
479 | public void actionPerformed(ActionEvent arg0) {
|
---|
480 | int [] myRows = myNodes.getSelectedRows();
|
---|
481 | int [] mergedRows = mergedNodes.getSelectedRows();
|
---|
482 | if (mergedRows == null || mergedRows.length == 0) {
|
---|
483 | return;
|
---|
484 | }
|
---|
485 | int current = mergedRows[0];
|
---|
486 | model.copyMyNodesAfterCurrent(myRows, current);
|
---|
487 | }
|
---|
488 |
|
---|
489 | public void valueChanged(ListSelectionEvent e) {
|
---|
490 | setEnabled(
|
---|
491 | !myNodes.getSelectionModel().isSelectionEmpty()
|
---|
492 | && ! mergedNodes.getSelectionModel().isSelectionEmpty()
|
---|
493 | );
|
---|
494 | }
|
---|
495 | }
|
---|
496 |
|
---|
497 |
|
---|
498 | class CopyStartRightAction extends AbstractNodeManipulationAction implements ListSelectionListener {
|
---|
499 |
|
---|
500 | public CopyStartRightAction() {
|
---|
501 | ImageIcon icon = getIcon("copystartright.png");
|
---|
502 | putValue(Action.SMALL_ICON, icon);
|
---|
503 | if (icon == null) {
|
---|
504 | putValue(Action.NAME, "< top");
|
---|
505 | }
|
---|
506 | putValue(Action.SHORT_DESCRIPTION, tr("Copy their selected nodes to the start of the merged node list"));
|
---|
507 | setEnabled(false);
|
---|
508 | }
|
---|
509 |
|
---|
510 | public void actionPerformed(ActionEvent arg0) {
|
---|
511 | int [] rows = theirNodes.getSelectedRows();
|
---|
512 | model.copyTheirNodesToTop(rows);
|
---|
513 | }
|
---|
514 |
|
---|
515 | public void valueChanged(ListSelectionEvent e) {
|
---|
516 | setEnabled(!theirNodes.getSelectionModel().isSelectionEmpty());
|
---|
517 | }
|
---|
518 | }
|
---|
519 |
|
---|
520 |
|
---|
521 | class CopyEndRightAction extends AbstractNodeManipulationAction implements ListSelectionListener {
|
---|
522 |
|
---|
523 | public CopyEndRightAction() {
|
---|
524 | ImageIcon icon = getIcon("copyendright.png");
|
---|
525 | putValue(Action.SMALL_ICON, icon);
|
---|
526 | if (icon == null) {
|
---|
527 | putValue(Action.NAME, "< bottom");
|
---|
528 | }
|
---|
529 | putValue(Action.SHORT_DESCRIPTION, tr("Copy their selected nodes to the end of the merged node list"));
|
---|
530 | setEnabled(false);
|
---|
531 | }
|
---|
532 |
|
---|
533 | public void actionPerformed(ActionEvent arg0) {
|
---|
534 | int [] rows = theirNodes.getSelectedRows();
|
---|
535 | model.copyTheirNodesToEnd(rows);
|
---|
536 | }
|
---|
537 |
|
---|
538 | public void valueChanged(ListSelectionEvent e) {
|
---|
539 | setEnabled(!theirNodes.getSelectionModel().isSelectionEmpty());
|
---|
540 | }
|
---|
541 | }
|
---|
542 |
|
---|
543 | class CopyBeforeCurrentRightAction extends AbstractNodeManipulationAction implements ListSelectionListener {
|
---|
544 |
|
---|
545 | public CopyBeforeCurrentRightAction() {
|
---|
546 | ImageIcon icon = getIcon("copybeforecurrentright.png");
|
---|
547 | putValue(Action.SMALL_ICON, icon);
|
---|
548 | if (icon == null) {
|
---|
549 | putValue(Action.NAME, "< before");
|
---|
550 | }
|
---|
551 | putValue(Action.SHORT_DESCRIPTION, tr("Copy their selected nodes before the first selected node in the merged node list"));
|
---|
552 | setEnabled(false);
|
---|
553 | }
|
---|
554 |
|
---|
555 | public void actionPerformed(ActionEvent arg0) {
|
---|
556 | int [] myRows = theirNodes.getSelectedRows();
|
---|
557 | int [] mergedRows = mergedNodes.getSelectedRows();
|
---|
558 | if (mergedRows == null || mergedRows.length == 0) {
|
---|
559 | return;
|
---|
560 | }
|
---|
561 | int current = mergedRows[0];
|
---|
562 | model.copyTheirNodesBeforeCurrent(myRows, current);
|
---|
563 | }
|
---|
564 |
|
---|
565 | public void valueChanged(ListSelectionEvent e) {
|
---|
566 | setEnabled(
|
---|
567 | !theirNodes.getSelectionModel().isSelectionEmpty()
|
---|
568 | && ! mergedNodes.getSelectionModel().isSelectionEmpty()
|
---|
569 | );
|
---|
570 | }
|
---|
571 | }
|
---|
572 |
|
---|
573 |
|
---|
574 | class CopyAfterCurrentRightAction extends AbstractNodeManipulationAction implements ListSelectionListener {
|
---|
575 |
|
---|
576 | public CopyAfterCurrentRightAction() {
|
---|
577 | ImageIcon icon = getIcon("copyaftercurrentright.png");
|
---|
578 | putValue(Action.SMALL_ICON, icon);
|
---|
579 | if (icon == null) {
|
---|
580 | putValue(Action.NAME, "< after");
|
---|
581 | }
|
---|
582 | putValue(Action.SHORT_DESCRIPTION, tr("Copy their selected nodes after the first selected node in the merged node list"));
|
---|
583 | setEnabled(false);
|
---|
584 | }
|
---|
585 |
|
---|
586 | public void actionPerformed(ActionEvent arg0) {
|
---|
587 | int [] myRows = theirNodes.getSelectedRows();
|
---|
588 | int [] mergedRows = mergedNodes.getSelectedRows();
|
---|
589 | if (mergedRows == null || mergedRows.length == 0) {
|
---|
590 | return;
|
---|
591 | }
|
---|
592 | int current = mergedRows[0];
|
---|
593 | model.copyTheirNodesAfterCurrent(myRows, current);
|
---|
594 | }
|
---|
595 |
|
---|
596 | public void valueChanged(ListSelectionEvent e) {
|
---|
597 | setEnabled(
|
---|
598 | !theirNodes.getSelectionModel().isSelectionEmpty()
|
---|
599 | && ! mergedNodes.getSelectionModel().isSelectionEmpty()
|
---|
600 | );
|
---|
601 | }
|
---|
602 | }
|
---|
603 |
|
---|
604 |
|
---|
605 | class MoveUpMergedAction extends AbstractNodeManipulationAction implements ListSelectionListener {
|
---|
606 |
|
---|
607 | public MoveUpMergedAction() {
|
---|
608 | ImageIcon icon = getIcon("moveup.png");
|
---|
609 | putValue(Action.SMALL_ICON, icon);
|
---|
610 | if (icon == null) {
|
---|
611 | putValue(Action.NAME, tr("Up"));
|
---|
612 | }
|
---|
613 | putValue(Action.SHORT_DESCRIPTION, tr("Move up the selected nodes by one position"));
|
---|
614 | setEnabled(false);
|
---|
615 | }
|
---|
616 |
|
---|
617 | public void actionPerformed(ActionEvent arg0) {
|
---|
618 | int [] rows = mergedNodes.getSelectedRows();
|
---|
619 | model.moveUpMergedNodes(rows);
|
---|
620 | }
|
---|
621 |
|
---|
622 | public void valueChanged(ListSelectionEvent e) {
|
---|
623 | int [] rows = mergedNodes.getSelectedRows();
|
---|
624 | setEnabled(
|
---|
625 | rows != null
|
---|
626 | && rows.length > 0
|
---|
627 | && rows[0] != 0
|
---|
628 | );
|
---|
629 | }
|
---|
630 | }
|
---|
631 |
|
---|
632 | class MoveDownMergedAction extends AbstractNodeManipulationAction implements ListSelectionListener {
|
---|
633 |
|
---|
634 | public MoveDownMergedAction() {
|
---|
635 | ImageIcon icon = getIcon("movedown.png");
|
---|
636 | putValue(Action.SMALL_ICON, icon);
|
---|
637 | if (icon == null) {
|
---|
638 | putValue(Action.NAME, tr("Down"));
|
---|
639 | }
|
---|
640 | putValue(Action.SHORT_DESCRIPTION, tr("Move down the selected nodes by one position"));
|
---|
641 | setEnabled(false);
|
---|
642 | }
|
---|
643 |
|
---|
644 | public void actionPerformed(ActionEvent arg0) {
|
---|
645 | int [] rows = mergedNodes.getSelectedRows();
|
---|
646 | model.moveDownMergedNodes(rows);
|
---|
647 | }
|
---|
648 |
|
---|
649 | public void valueChanged(ListSelectionEvent e) {
|
---|
650 | int [] rows = mergedNodes.getSelectedRows();
|
---|
651 | setEnabled(
|
---|
652 | rows != null
|
---|
653 | && rows.length > 0
|
---|
654 | && rows[rows.length -1] != mergedNodes.getRowCount() -1
|
---|
655 | );
|
---|
656 | }
|
---|
657 | }
|
---|
658 |
|
---|
659 | class RemoveMergedAction extends AbstractNodeManipulationAction implements ListSelectionListener {
|
---|
660 |
|
---|
661 | public RemoveMergedAction() {
|
---|
662 | ImageIcon icon = getIcon("remove.png");
|
---|
663 | putValue(Action.SMALL_ICON, icon);
|
---|
664 | if (icon == null) {
|
---|
665 | putValue(Action.NAME, tr("Remove"));
|
---|
666 | }
|
---|
667 | putValue(Action.SHORT_DESCRIPTION, tr("Remove the selected nodes from the list of merged nodes"));
|
---|
668 | setEnabled(false);
|
---|
669 | }
|
---|
670 |
|
---|
671 | public void actionPerformed(ActionEvent arg0) {
|
---|
672 | int [] rows = mergedNodes.getSelectedRows();
|
---|
673 | model.removeMergedNodes(rows);
|
---|
674 | }
|
---|
675 |
|
---|
676 | public void valueChanged(ListSelectionEvent e) {
|
---|
677 | int [] rows = mergedNodes.getSelectedRows();
|
---|
678 | setEnabled(
|
---|
679 | rows != null
|
---|
680 | && rows.length > 0
|
---|
681 | );
|
---|
682 | }
|
---|
683 | }
|
---|
684 |
|
---|
685 | class FreezeAction extends AbstractNodeManipulationAction implements ItemListener {
|
---|
686 |
|
---|
687 | public FreezeAction() {
|
---|
688 | // FIXME
|
---|
689 | // ImageIcon icon = getIcon("remove.png");
|
---|
690 | // putValue(Action.SMALL_ICON, icon);
|
---|
691 | // if (icon == null) {
|
---|
692 | // putValue(Action.NAME, tr("Remove"));
|
---|
693 | // }
|
---|
694 | putValue(Action.NAME, tr("Freeze"));
|
---|
695 | putValue(Action.SHORT_DESCRIPTION, tr("Freeze the current list of merged nodes."));
|
---|
696 | // putValue(Action.SELECTED_KEY, false);
|
---|
697 | setEnabled(true);
|
---|
698 |
|
---|
699 | }
|
---|
700 |
|
---|
701 | public void actionPerformed(ActionEvent arg0) {
|
---|
702 | int [] rows = mergedNodes.getSelectedRows();
|
---|
703 | model.removeMergedNodes(rows);
|
---|
704 | }
|
---|
705 |
|
---|
706 | public void itemStateChanged(ItemEvent e) {
|
---|
707 | int state = e.getStateChange();
|
---|
708 | if (state == ItemEvent.SELECTED) {
|
---|
709 | model.setFrozen(true);
|
---|
710 | putValue(Action.NAME, tr("Unfreeze"));
|
---|
711 | putValue(Action.SHORT_DESCRIPTION, tr("Unfreeze the list of merged nodes and start merging"));
|
---|
712 | } else if (state == ItemEvent.DESELECTED) {
|
---|
713 | model.setFrozen(false);
|
---|
714 | putValue(Action.NAME, tr("Freeze"));
|
---|
715 | putValue(Action.SHORT_DESCRIPTION, tr("Freeze the current list of merged nodes"));
|
---|
716 | }
|
---|
717 | }
|
---|
718 | }
|
---|
719 |
|
---|
720 | protected void handlePropertyChangeFrozen(boolean oldValue, boolean newValue) {
|
---|
721 | myNodes.getSelectionModel().clearSelection();
|
---|
722 | myNodes.setEnabled(!newValue);
|
---|
723 | theirNodes.getSelectionModel().clearSelection();
|
---|
724 | theirNodes.setEnabled(!newValue);
|
---|
725 | mergedNodes.getSelectionModel().clearSelection();
|
---|
726 | mergedNodes.setEnabled(!newValue);
|
---|
727 | // freezeAction.putValue(Action.SELECTED_KEY, newValue);
|
---|
728 | }
|
---|
729 |
|
---|
730 | public void propertyChange(PropertyChangeEvent evt) {
|
---|
731 | if (evt.getPropertyName().equals(NodeListMergeModel.PROP_FROZEN)) {
|
---|
732 | handlePropertyChangeFrozen((Boolean)evt.getOldValue(), (Boolean)evt.getNewValue());
|
---|
733 | }
|
---|
734 |
|
---|
735 | }
|
---|
736 |
|
---|
737 | public NodeListMergeModel getModel() {
|
---|
738 | return model;
|
---|
739 | }
|
---|
740 | }
|
---|