1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.datatransfer.importers;
|
---|
3 |
|
---|
4 | import java.awt.datatransfer.DataFlavor;
|
---|
5 | import java.awt.datatransfer.UnsupportedFlavorException;
|
---|
6 | import java.io.IOException;
|
---|
7 | import java.util.Collection;
|
---|
8 |
|
---|
9 | import javax.swing.TransferHandler;
|
---|
10 | import javax.swing.TransferHandler.TransferSupport;
|
---|
11 |
|
---|
12 | import org.openstreetmap.josm.data.coor.EastNorth;
|
---|
13 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
14 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * This is an abstract class that helps implementing the transfer support required by swing.
|
---|
18 | * <p>
|
---|
19 | * It implements a mechanism to import a given data flavor into the current OSM data layer.
|
---|
20 | * @author Michael Zangl
|
---|
21 | * @since 10604
|
---|
22 | */
|
---|
23 | public abstract class AbstractOsmDataPaster {
|
---|
24 | protected final DataFlavor df;
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Create a new {@link AbstractOsmDataPaster}
|
---|
28 | * @param df The data flavor that this support supports.
|
---|
29 | */
|
---|
30 | protected AbstractOsmDataPaster(DataFlavor df) {
|
---|
31 | this.df = df;
|
---|
32 | }
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * Checks if this supports importing the given transfer support.
|
---|
36 | * @param support The support that should be supported.
|
---|
37 | * @return True if we support that transfer.
|
---|
38 | */
|
---|
39 | public boolean supports(TransferSupport support) {
|
---|
40 | return support.isDataFlavorSupported(df) && isCopy(support);
|
---|
41 | }
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * Checks if this supports any of the available flavors.
|
---|
45 | * @param available The flavors that should be supported
|
---|
46 | * @return True if any of them is supported.
|
---|
47 | */
|
---|
48 | public boolean supports(Collection<DataFlavor> available) {
|
---|
49 | return available.contains(df);
|
---|
50 | }
|
---|
51 |
|
---|
52 | private static boolean isCopy(TransferSupport support) {
|
---|
53 | return !support.isDrop() || (TransferHandler.COPY & support.getSourceDropActions()) == TransferHandler.COPY;
|
---|
54 | }
|
---|
55 |
|
---|
56 | /**
|
---|
57 | * Attempts to import the given transfer data.
|
---|
58 | * @param support The transfer support to import from.
|
---|
59 | * @param layer The layer to paste at. May be null.
|
---|
60 | * @param pasteAt The position to paste at.
|
---|
61 | * @return <code>true</code> if the import was successful.
|
---|
62 | * @throws UnsupportedFlavorException if the requested data flavor is not supported
|
---|
63 | * @throws IOException if an I/O error occurs
|
---|
64 | */
|
---|
65 | public abstract boolean importData(TransferSupport support, OsmDataLayer layer, EastNorth pasteAt)
|
---|
66 | throws UnsupportedFlavorException, IOException;
|
---|
67 |
|
---|
68 | /**
|
---|
69 | * Imports only if this import changes the tags only. Does nothing if more than tags would be changed.
|
---|
70 | * @param support The support
|
---|
71 | * @param selection The primitives to apply on.
|
---|
72 | * @return <code>true</code> if an import was done.
|
---|
73 | * @throws UnsupportedFlavorException if the requested data flavor is not supported
|
---|
74 | * @throws IOException if an I/O error occurs
|
---|
75 | */
|
---|
76 | public boolean importTagsOn(TransferSupport support, Collection<? extends OsmPrimitive> selection)
|
---|
77 | throws UnsupportedFlavorException, IOException {
|
---|
78 | return false;
|
---|
79 | }
|
---|
80 | }
|
---|