von Gast » 22 Dez 2006, 18:45
Die Klasse gibts aber
hier mal der Quellcode der einen Datei wo die Klasse realisiert wird.
Code: Alles auswählen
/*
* Created on 18.06.2004
*/
package calendardirectexportplugin;
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Properties;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import util.ui.ExtensionFileFilter;
import util.ui.Localizer;
import devplugin.ActionMenu;
import devplugin.Plugin;
import devplugin.PluginInfo;
import devplugin.Program;
import devplugin.SettingsTab;
import devplugin.ThemeIcon;
import devplugin.Version;
/**
* This Plugin exports vCal and iCal Files
*
* @author bodo
*/
public class CalendarDirectExportPlugin extends devplugin.Plugin {
/** Translator */
private static final Localizer mLocalizer = Localizer.getLocalizerFor(CalendarDirectExportPlugin.class);
/** The Exporter to use */
private CalendarDirectExporter mExport = new CalendarDirectExporter();
/** Path for saving the File */
private String mSavePath;
/** Settings */
private Properties mSettings;
/** The Default-Parameters */
public static final String DEFAULT_PARAMETER = "{channel_name} - {title}\n{leadingZero(start_day,\"2\")}.{leadingZero(start_month,\"2\")}.{start_year} {leadingZero(start_hour,\"2\")}:{leadingZero(start_minute,\"2\")}-{leadingZero(end_hour,\"2\")}:{leadingZero(end_minute,\"2\")}\n\n{splitAt(short_info,\"78\")}\n\n";
/*
* (non-Javadoc)
*
* @see devplugin.Plugin#getInfo()
*/
public PluginInfo getInfo() {
String name = mLocalizer.msg("pluginName", "Calendar direct export");
String desc = mLocalizer.msg("description","Exports a Program as a vCal/iCal File. This File can easily imported in other Calendar Applications. Without asking for the file.");
String author = "Stefan Hoelzl";
return new PluginInfo(name, desc, author, new Version(0, 1));
}
public ThemeIcon getMarkIconFromTheme() {
return new ThemeIcon("apps", "office-calendar", 16);
}
/*
* (non-Javadoc)
* @see devplugin.Plugin#getContextMenuActions(devplugin.Program)
*/
public ActionMenu getContextMenuActions(final Program program) {
AbstractAction action = new AbstractAction() {
public void actionPerformed(ActionEvent evt) {
Program[] programArr = { program };
doExport(programArr);
}
};
action.putValue(Action.NAME, mLocalizer.msg("contextMenuText","Export direct to Calendar-File"));
action.putValue(Action.SMALL_ICON, createImageIcon("apps", "office-calendar", 16));
return new ActionMenu(action);
}
/*
* (non-Javadoc)
*
* @see devplugin.Plugin#canReceivePrograms()
*/
public boolean canReceivePrograms() {
return true;
}
/**
* This method is invoked for multiple program execution.
*
* @see #canReceivePrograms()
*/
public void receivePrograms(Program[] programArr) {
doExport(programArr);
}
/**
* Get Settings-Tab
* @return SettingsTab
*/
public SettingsTab getSettingsTab() {
return new CalendarDirectSettingsTab(this, mSettings);
}
/**
* Stores the Settings
* @return Settings
*/
public Properties storeSettings() {
return mSettings;
}
/**
* Loads the Settings
* @param settings Settings for this Plugin
*/
public void loadSettings(Properties settings) {
if (settings == null) {
settings = new Properties();
}
this.mSettings = settings;
}
/**
* Called by the host-application during start-up.
*
* @see #writeData(ObjectOutputStream)
*/
public void readData(ObjectInputStream in) throws IOException,
ClassNotFoundException {
try {
int version = in.readInt();
mSavePath = (String) in.readObject();
} catch (Exception e) {
// e.printStackTrace();
mSavePath = "";
}
}
/**
* Counterpart to loadData. Called when the application shuts down.
*
* @see #readData(ObjectInputStream)
*/
public void writeData(ObjectOutputStream out) throws IOException {
out.writeInt(1);
out.writeObject(mSavePath);
}
/**
* Starts the Export
* @param programArr Array of Programs to export
*/
private void doExport(Program[] programArr) {
File file = getFile();
if (file != null) {
if (file.exists()) {
int result = JOptionPane.showConfirmDialog(getParentFrame(),
mLocalizer.msg("overwriteMessage", "The File \n{0}\nalready exists. Overwrite it?", file.getAbsolutePath()),
mLocalizer.msg("overwriteTitle", "Overwrite?"),
JOptionPane.YES_NO_OPTION
);
if (result != JOptionPane.YES_OPTION) {
return;
}
}
mSavePath = file.getAbsolutePath();
mExport.exportICal(file, programArr, mSettings);
}
}
public File getFile() {
return new File("/Users/stefan/kal.ics");
}
}
Die Klasse gibts aber
hier mal der Quellcode der einen Datei wo die Klasse realisiert wird.
[code]/*
* Created on 18.06.2004
*/
package calendardirectexportplugin;
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Properties;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import util.ui.ExtensionFileFilter;
import util.ui.Localizer;
import devplugin.ActionMenu;
import devplugin.Plugin;
import devplugin.PluginInfo;
import devplugin.Program;
import devplugin.SettingsTab;
import devplugin.ThemeIcon;
import devplugin.Version;
/**
* This Plugin exports vCal and iCal Files
*
* @author bodo
*/
public class CalendarDirectExportPlugin extends devplugin.Plugin {
/** Translator */
private static final Localizer mLocalizer = Localizer.getLocalizerFor(CalendarDirectExportPlugin.class);
/** The Exporter to use */
private CalendarDirectExporter mExport = new CalendarDirectExporter();
/** Path for saving the File */
private String mSavePath;
/** Settings */
private Properties mSettings;
/** The Default-Parameters */
public static final String DEFAULT_PARAMETER = "{channel_name} - {title}\n{leadingZero(start_day,\"2\")}.{leadingZero(start_month,\"2\")}.{start_year} {leadingZero(start_hour,\"2\")}:{leadingZero(start_minute,\"2\")}-{leadingZero(end_hour,\"2\")}:{leadingZero(end_minute,\"2\")}\n\n{splitAt(short_info,\"78\")}\n\n";
/*
* (non-Javadoc)
*
* @see devplugin.Plugin#getInfo()
*/
public PluginInfo getInfo() {
String name = mLocalizer.msg("pluginName", "Calendar direct export");
String desc = mLocalizer.msg("description","Exports a Program as a vCal/iCal File. This File can easily imported in other Calendar Applications. Without asking for the file.");
String author = "Stefan Hoelzl";
return new PluginInfo(name, desc, author, new Version(0, 1));
}
public ThemeIcon getMarkIconFromTheme() {
return new ThemeIcon("apps", "office-calendar", 16);
}
/*
* (non-Javadoc)
* @see devplugin.Plugin#getContextMenuActions(devplugin.Program)
*/
public ActionMenu getContextMenuActions(final Program program) {
AbstractAction action = new AbstractAction() {
public void actionPerformed(ActionEvent evt) {
Program[] programArr = { program };
doExport(programArr);
}
};
action.putValue(Action.NAME, mLocalizer.msg("contextMenuText","Export direct to Calendar-File"));
action.putValue(Action.SMALL_ICON, createImageIcon("apps", "office-calendar", 16));
return new ActionMenu(action);
}
/*
* (non-Javadoc)
*
* @see devplugin.Plugin#canReceivePrograms()
*/
public boolean canReceivePrograms() {
return true;
}
/**
* This method is invoked for multiple program execution.
*
* @see #canReceivePrograms()
*/
public void receivePrograms(Program[] programArr) {
doExport(programArr);
}
/**
* Get Settings-Tab
* @return SettingsTab
*/
public SettingsTab getSettingsTab() {
return new CalendarDirectSettingsTab(this, mSettings);
}
/**
* Stores the Settings
* @return Settings
*/
public Properties storeSettings() {
return mSettings;
}
/**
* Loads the Settings
* @param settings Settings for this Plugin
*/
public void loadSettings(Properties settings) {
if (settings == null) {
settings = new Properties();
}
this.mSettings = settings;
}
/**
* Called by the host-application during start-up.
*
* @see #writeData(ObjectOutputStream)
*/
public void readData(ObjectInputStream in) throws IOException,
ClassNotFoundException {
try {
int version = in.readInt();
mSavePath = (String) in.readObject();
} catch (Exception e) {
// e.printStackTrace();
mSavePath = "";
}
}
/**
* Counterpart to loadData. Called when the application shuts down.
*
* @see #readData(ObjectInputStream)
*/
public void writeData(ObjectOutputStream out) throws IOException {
out.writeInt(1);
out.writeObject(mSavePath);
}
/**
* Starts the Export
* @param programArr Array of Programs to export
*/
private void doExport(Program[] programArr) {
File file = getFile();
if (file != null) {
if (file.exists()) {
int result = JOptionPane.showConfirmDialog(getParentFrame(),
mLocalizer.msg("overwriteMessage", "The File \n{0}\nalready exists. Overwrite it?", file.getAbsolutePath()),
mLocalizer.msg("overwriteTitle", "Overwrite?"),
JOptionPane.YES_NO_OPTION
);
if (result != JOptionPane.YES_OPTION) {
return;
}
}
mSavePath = file.getAbsolutePath();
mExport.exportICal(file, programArr, mSettings);
}
}
public File getFile() {
return new File("/Users/stefan/kal.ics");
}
}[/code]