1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.io;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.io.File;
|
---|
7 | import java.io.IOException;
|
---|
8 |
|
---|
9 | import org.openstreetmap.josm.actions.ExtensionFileFilter;
|
---|
10 | import org.openstreetmap.josm.gui.layer.Layer;
|
---|
11 | import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
|
---|
12 | import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
|
---|
13 |
|
---|
14 | public abstract class FileExporter implements ActiveLayerChangeListener {
|
---|
15 |
|
---|
16 | public final ExtensionFileFilter filter;
|
---|
17 |
|
---|
18 | private boolean enabled;
|
---|
19 | private boolean canceled;
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * Constructs a new {@code FileExporter}.
|
---|
23 | * @param filter The extension file filter
|
---|
24 | */
|
---|
25 | public FileExporter(ExtensionFileFilter filter) {
|
---|
26 | this.filter = filter;
|
---|
27 | this.enabled = true;
|
---|
28 | }
|
---|
29 |
|
---|
30 | public boolean acceptFile(File pathname, Layer layer) {
|
---|
31 | return filter.acceptName(pathname.getName());
|
---|
32 | }
|
---|
33 |
|
---|
34 | public void exportData(File file, Layer layer) throws IOException {
|
---|
35 | throw new IOException(tr("Could not export ''{0}''.", file.getName()));
|
---|
36 | }
|
---|
37 |
|
---|
38 | /**
|
---|
39 | * Returns the enabled state of this {@code FileExporter}. When enabled, it is listed and usable in "File->Save" dialogs.
|
---|
40 | * @return true if this {@code FileExporter} is enabled
|
---|
41 | * @since 5459
|
---|
42 | */
|
---|
43 | public final boolean isEnabled() {
|
---|
44 | return enabled;
|
---|
45 | }
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * Sets the enabled state of the {@code FileExporter}. When enabled, it is listed and usable in "File->Save" dialogs.
|
---|
49 | * @param enabled true to enable this {@code FileExporter}, false to disable it
|
---|
50 | * @since 5459
|
---|
51 | */
|
---|
52 | public final void setEnabled(boolean enabled) {
|
---|
53 | this.enabled = enabled;
|
---|
54 | }
|
---|
55 |
|
---|
56 | @Override
|
---|
57 | public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
|
---|
58 | // To be overriden by subclasses if their enabled state depends of the active layer nature
|
---|
59 | }
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * Determines if this exporter has been canceled during export.
|
---|
63 | * @return true if this {@code FileExporter} has been canceled
|
---|
64 | * @since 6815
|
---|
65 | */
|
---|
66 | public final boolean isCanceled() {
|
---|
67 | return canceled;
|
---|
68 | }
|
---|
69 |
|
---|
70 | /**
|
---|
71 | * Marks this exporter as canceled.
|
---|
72 | * @param canceled true to mark this exporter as canceled, {@code false} otherwise
|
---|
73 | * @since 6815
|
---|
74 | */
|
---|
75 | public final void setCanceled(boolean canceled) {
|
---|
76 | this.canceled = canceled;
|
---|
77 | }
|
---|
78 | }
|
---|