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

Last change on this file since 10755 was 10345, checked in by Don-vip, 8 years ago

fix #12937 - Use the new LayerChangeListener (patch by michael2402) - gsoc-core

  • Property svn:eol-style set to native
File size: 2.4 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
14public 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}
Note: See TracBrowser for help on using the repository browser.