package org.herac.tuxguitar.gui.system.plugins.base; import org.herac.tuxguitar.gui.system.plugins.TGPluginException; import org.herac.tuxguitar.io.base.TGFileFormatManager; import org.herac.tuxguitar.io.base.TGOutputStreamBase; public abstract class TGOutputStreamPlugin extends TGPluginAdapter { private boolean loaded; private TGOutputStreamBase stream; protected void addPlugin() throws TGPluginException { if (!this.loaded) { TGFileFormatManager.instance().addOutputStream(this.stream); this.loaded = true; } } public void close() throws TGPluginException { this.removePlugin(); } protected abstract TGOutputStreamBase getOutputStream() throws TGPluginException; public void init() throws TGPluginException { this.stream = getOutputStream(); } protected void removePlugin() throws TGPluginException { if (this.loaded) { TGFileFormatManager.instance().removeOutputStream(this.stream); this.loaded = false; } } public void setEnabled(boolean enabled) throws TGPluginException { if (enabled) { addPlugin(); } else { removePlugin(); } } }