source: josm/trunk/src/org/openstreetmap/josm/io/FileExporter.java@ 12488

Last change on this file since 12488 was 12470, checked in by bastiK, 7 years ago

see #14794 - javadoc

  • Property svn:eol-style set to native
File size: 3.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.io.File;
7import java.io.IOException;
8
9import org.openstreetmap.josm.actions.ExtensionFileFilter;
10import org.openstreetmap.josm.gui.layer.Layer;
11import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
12import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
13
14/**
15 * Abstract base class for file exporters - IO classes that save layers to a file.
16 */
17public abstract class FileExporter implements ActiveLayerChangeListener {
18
19 public final ExtensionFileFilter filter;
20
21 private boolean enabled;
22 private boolean canceled;
23
24 /**
25 * Constructs a new {@code FileExporter}.
26 * @param filter The extension file filter
27 */
28 public FileExporter(ExtensionFileFilter filter) {
29 this.filter = filter;
30 this.enabled = true;
31 }
32
33 /**
34 * Check if this exporter can export a certain layer to a certain file.
35 *
36 * Most exporters support just a single layer type.
37 * @param pathname the target file name (check file extension using the {@link #filter}
38 * @param layer the layer requested for export
39 * @return true, if the exporter can handle the layer and filename is okay
40 */
41 public boolean acceptFile(File pathname, Layer layer) {
42 return filter.acceptName(pathname.getName());
43 }
44
45 /**
46 * Execute the data export. (To be overridden by subclasses.)
47 *
48 * @param file target file
49 * @param layer the layer to export
50 * @throws IOException in case of an IO error
51 */
52 public void exportData(File file, Layer layer) throws IOException {
53 throw new IOException(tr("Could not export ''{0}''.", file.getName()));
54 }
55
56 /**
57 * Returns the enabled state of this {@code FileExporter}. When enabled, it is listed and usable in "File->Save" dialogs.
58 * @return true if this {@code FileExporter} is enabled
59 * @since 5459
60 */
61 public final boolean isEnabled() {
62 return enabled;
63 }
64
65 /**
66 * Sets the enabled state of the {@code FileExporter}. When enabled, it is listed and usable in "File->Save" dialogs.
67 * @param enabled true to enable this {@code FileExporter}, false to disable it
68 * @since 5459
69 */
70 public final void setEnabled(boolean enabled) {
71 this.enabled = enabled;
72 }
73
74 @Override
75 public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
76 // To be overriden by subclasses if their enabled state depends of the active layer nature
77 }
78
79 /**
80 * Determines if this exporter has been canceled during export.
81 * @return true if this {@code FileExporter} has been canceled
82 * @since 6815
83 */
84 public final boolean isCanceled() {
85 return canceled;
86 }
87
88 /**
89 * Marks this exporter as canceled.
90 * @param canceled true to mark this exporter as canceled, {@code false} otherwise
91 * @since 6815
92 */
93 public final void setCanceled(boolean canceled) {
94 this.canceled = canceled;
95 }
96}
Note: See TracBrowser for help on using the repository browser.