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

Last change on this file since 11334 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
RevLine 
[1949]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;
[10345]11import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
12import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
[1949]13
[10345]14public abstract class FileExporter implements ActiveLayerChangeListener {
[6070]15
[5459]16 public final ExtensionFileFilter filter;
[1949]17
[5459]18 private boolean enabled;
[6815]19 private boolean canceled;
[5459]20
[6815]21 /**
22 * Constructs a new {@code FileExporter}.
23 * @param filter The extension file filter
24 */
[1949]25 public FileExporter(ExtensionFileFilter filter) {
26 this.filter = filter;
[5459]27 this.enabled = true;
[1949]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 {
[2181]35 throw new IOException(tr("Could not export ''{0}''.", file.getName()));
[1949]36 }
[5459]37
38 /**
[6830]39 * Returns the enabled state of this {@code FileExporter}. When enabled, it is listed and usable in "File->Save" dialogs.
[5459]40 * @return true if this {@code FileExporter} is enabled
41 * @since 5459
42 */
43 public final boolean isEnabled() {
44 return enabled;
45 }
46
47 /**
[6830]48 * Sets the enabled state of the {@code FileExporter}. When enabled, it is listed and usable in "File->Save" dialogs.
[5459]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
[10345]57 public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
[5459]58 // To be overriden by subclasses if their enabled state depends of the active layer nature
59 }
60
[6815]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 }
[1949]78}
Note: See TracBrowser for help on using the repository browser.