home *** CD-ROM | disk | FTP | other *** search
- package reminderplugin;
-
- import devplugin.ChannelDayProgram;
- import devplugin.Plugin;
- import devplugin.PluginInfo;
- import devplugin.Program;
- import devplugin.SettingsTab;
- import devplugin.Version;
- import java.applet.Applet;
- import java.applet.AudioClip;
- import java.awt.Image;
- import java.io.File;
- import java.io.IOException;
- import java.io.ObjectInputStream;
- import java.io.ObjectOutputStream;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.util.HashSet;
- import java.util.Iterator;
- import java.util.Properties;
- import javax.swing.JDialog;
- import javax.swing.JOptionPane;
- import util.exc.ErrorHandler;
- import util.ui.Localizer;
- import util.ui.UiUtilities;
-
- public class ReminderPlugin extends Plugin implements ReminderTimerListener {
- private static final Localizer mLocalizer;
- private static ReminderPlugin mInstance;
- private ReminderList mReminderList;
- private Properties mSettings;
- private HashSet mReminderItemsTrash;
- // $FF: synthetic field
- static Class class$reminderplugin$ReminderPlugin;
-
- public ReminderPlugin() {
- mInstance = this;
- this.mReminderList = new ReminderList();
- this.mReminderList.setReminderTimerListener(this);
- this.mReminderItemsTrash = new HashSet();
- }
-
- public static ReminderPlugin getInstance() {
- return mInstance;
- }
-
- public void timeEvent(ReminderListItem item) {
- if ("true".equals(this.mSettings.getProperty("usesound"))) {
- playSound(this.mSettings.getProperty("soundfile"));
- }
-
- if ("true".equals(this.mSettings.getProperty("usemsgbox"))) {
- Image iconImage = null;
- if (this.getParentFrame() != null) {
- iconImage = this.getParentFrame().getIconImage();
- }
-
- new ReminderFrame(this.getParentFrame(), this.mReminderList, item, this.getAutoCloseReminderTime(), iconImage);
- } else {
- this.mReminderList.remove(item);
- }
-
- if ("true".equals(this.mSettings.getProperty("useexec"))) {
- String fName = this.mSettings.getProperty("execfile");
-
- try {
- Runtime.getRuntime().exec(fName);
- } catch (IOException exc) {
- String msg = mLocalizer.msg("error.2", "Error executing reminder program!\n({0})", fName, exc);
- ErrorHandler.handle(msg, exc);
- }
- }
-
- }
-
- static void playSound(String fileName) {
- try {
- URL url = (new File(fileName)).toURL();
- AudioClip clip = Applet.newAudioClip(url);
- clip.play();
- } catch (MalformedURLException exc) {
- String msg = mLocalizer.msg("error.1", "Error loading reminder sound file!\n({0})", fileName, exc);
- ErrorHandler.handle(msg, exc);
- }
-
- }
-
- public PluginInfo getInfo() {
- String name = mLocalizer.msg("pluginName", "Reminder");
- String desc = mLocalizer.msg("description", "Eine einfache Implementierung einer Erinnerungsfunktion.");
- String author = "Martin Oberhauser (darras@users.sourceforge.net)";
- return new PluginInfo(name, desc, author, new Version(1, 8));
- }
-
- public void readData(ObjectInputStream in) throws IOException, ClassNotFoundException {
- int version = in.readInt();
- this.mReminderList.setReminderTimerListener((ReminderTimerListener)null);
- this.mReminderList = new ReminderList(in);
- this.mReminderList.setReminderTimerListener(this);
- if (this.mReminderList != null) {
- this.mReminderList.removeExpiredItems();
- this.mReminderList.setReminderTimerListener(this);
- Iterator iter = this.mReminderList.getReminderItems();
-
- while(iter.hasNext()) {
- ReminderListItem item = (ReminderListItem)iter.next();
- item.getProgram().mark(this);
- }
- }
-
- }
-
- public void writeData(ObjectOutputStream out) throws IOException {
- out.writeInt(2);
- this.mReminderList.writeData(out);
- }
-
- public Properties storeSettings() {
- return this.mSettings;
- }
-
- public void loadSettings(Properties settings) {
- if (settings == null) {
- settings = new Properties();
- }
-
- if (settings.getProperty("usemsgbox") == null) {
- settings.setProperty("usemsgbox", "true");
- }
-
- this.mSettings = settings;
- }
-
- private int getAutoCloseReminderTime() {
- int autoCloseReminderTime = 0;
-
- try {
- String asString = this.mSettings.getProperty("autoCloseReminderTime", "0");
- autoCloseReminderTime = Integer.parseInt(asString);
- } catch (Exception var3) {
- }
-
- return autoCloseReminderTime;
- }
-
- public String getContextMenuItemText() {
- return mLocalizer.msg("contextMenuText", "Remind me");
- }
-
- public String getButtonText() {
- return mLocalizer.msg("buttonText", "Reminder list");
- }
-
- public SettingsTab getSettingsTab() {
- return new ReminderSettingsTab(this.mSettings);
- }
-
- public void execute(Program program) {
- if (program.isExpired()) {
- String msg = mLocalizer.msg("programAlreadyExpired", "The program is already expired!");
- JOptionPane.showMessageDialog(this.getParentFrame(), msg);
- } else {
- ReminderDialog dlg = new ReminderDialog(this.getParentFrame(), program, this.mSettings);
- UiUtilities.centerAndShow(dlg);
- if (dlg.getOkPressed()) {
- int minutes = dlg.getReminderMinutes();
- this.addToReminderList(program, minutes);
- }
-
- dlg.dispose();
- }
-
- }
-
- public void execute(Program[] programArr) {
- int minutes = 3;
-
- for(int i = 0; i < programArr.length; ++i) {
- this.addToReminderList(programArr[i], minutes);
- }
-
- }
-
- public void execute() {
- JDialog dlg = new ReminderListDialog(this.getParentFrame(), this.mReminderList);
- dlg.setSize(600, 350);
- UiUtilities.centerAndShow(dlg);
- dlg.dispose();
- }
-
- private void addToReminderList(Program program, int minutes) {
- this.mReminderList.add(program, minutes);
- }
-
- public String getMarkIconName() {
- return "reminderplugin/TipOfTheDay16.gif";
- }
-
- public String getButtonIconName() {
- return "reminderplugin/TipOfTheDay16.gif";
- }
-
- public boolean supportMultipleProgramExecution() {
- return true;
- }
-
- public void handleTvDataDeleted(ChannelDayProgram oldProg) {
- for(int i = 0; i < oldProg.getProgramCount(); ++i) {
- Program prog = oldProg.getProgramAt(i);
- ReminderListItem item = this.mReminderList.getItemWithProgram(prog);
- if (item != null) {
- this.mReminderList.remove(prog);
- this.mReminderItemsTrash.add(item);
- }
- }
-
- }
-
- public void handleTvDataChanged() {
- for(ReminderListItem trashItem : this.mReminderItemsTrash) {
- Program p = Plugin.getPluginManager().getProgram(trashItem.getProgram().getDate(), trashItem.getProgram().getID());
- if (p != null) {
- this.mReminderList.add(p, trashItem.getReminderMinutes());
- p.mark(this);
- }
- }
-
- this.mReminderItemsTrash.clear();
- }
-
- // $FF: synthetic method
- static Class class$(String x0) {
- try {
- return Class.forName(x0);
- } catch (ClassNotFoundException x1) {
- throw new NoClassDefFoundError(x1.getMessage());
- }
- }
-
- static {
- mLocalizer = Localizer.getLocalizerFor(class$reminderplugin$ReminderPlugin == null ? (class$reminderplugin$ReminderPlugin = class$("reminderplugin.ReminderPlugin")) : class$reminderplugin$ReminderPlugin);
- }
- }
-