home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2005 June / PCpro_2005_06.ISO / files / opensource / tvbrowser / TvBrowser_1.0.exe / plugins / ReminderPlugin.jar / reminderplugin / ReminderPlugin.class (.txt) < prev    next >
Encoding:
Java Class File  |  2004-09-19  |  8.9 KB  |  244 lines

  1. package reminderplugin;
  2.  
  3. import devplugin.ChannelDayProgram;
  4. import devplugin.Plugin;
  5. import devplugin.PluginInfo;
  6. import devplugin.Program;
  7. import devplugin.SettingsTab;
  8. import devplugin.Version;
  9. import java.applet.Applet;
  10. import java.applet.AudioClip;
  11. import java.awt.Image;
  12. import java.io.File;
  13. import java.io.IOException;
  14. import java.io.ObjectInputStream;
  15. import java.io.ObjectOutputStream;
  16. import java.net.MalformedURLException;
  17. import java.net.URL;
  18. import java.util.HashSet;
  19. import java.util.Iterator;
  20. import java.util.Properties;
  21. import javax.swing.JDialog;
  22. import javax.swing.JOptionPane;
  23. import util.exc.ErrorHandler;
  24. import util.ui.Localizer;
  25. import util.ui.UiUtilities;
  26.  
  27. public class ReminderPlugin extends Plugin implements ReminderTimerListener {
  28.    private static final Localizer mLocalizer;
  29.    private static ReminderPlugin mInstance;
  30.    private ReminderList mReminderList;
  31.    private Properties mSettings;
  32.    private HashSet mReminderItemsTrash;
  33.    // $FF: synthetic field
  34.    static Class class$reminderplugin$ReminderPlugin;
  35.  
  36.    public ReminderPlugin() {
  37.       mInstance = this;
  38.       this.mReminderList = new ReminderList();
  39.       this.mReminderList.setReminderTimerListener(this);
  40.       this.mReminderItemsTrash = new HashSet();
  41.    }
  42.  
  43.    public static ReminderPlugin getInstance() {
  44.       return mInstance;
  45.    }
  46.  
  47.    public void timeEvent(ReminderListItem item) {
  48.       if ("true".equals(this.mSettings.getProperty("usesound"))) {
  49.          playSound(this.mSettings.getProperty("soundfile"));
  50.       }
  51.  
  52.       if ("true".equals(this.mSettings.getProperty("usemsgbox"))) {
  53.          Image iconImage = null;
  54.          if (this.getParentFrame() != null) {
  55.             iconImage = this.getParentFrame().getIconImage();
  56.          }
  57.  
  58.          new ReminderFrame(this.getParentFrame(), this.mReminderList, item, this.getAutoCloseReminderTime(), iconImage);
  59.       } else {
  60.          this.mReminderList.remove(item);
  61.       }
  62.  
  63.       if ("true".equals(this.mSettings.getProperty("useexec"))) {
  64.          String fName = this.mSettings.getProperty("execfile");
  65.  
  66.          try {
  67.             Runtime.getRuntime().exec(fName);
  68.          } catch (IOException exc) {
  69.             String msg = mLocalizer.msg("error.2", "Error executing reminder program!\n({0})", fName, exc);
  70.             ErrorHandler.handle(msg, exc);
  71.          }
  72.       }
  73.  
  74.    }
  75.  
  76.    static void playSound(String fileName) {
  77.       try {
  78.          URL url = (new File(fileName)).toURL();
  79.          AudioClip clip = Applet.newAudioClip(url);
  80.          clip.play();
  81.       } catch (MalformedURLException exc) {
  82.          String msg = mLocalizer.msg("error.1", "Error loading reminder sound file!\n({0})", fileName, exc);
  83.          ErrorHandler.handle(msg, exc);
  84.       }
  85.  
  86.    }
  87.  
  88.    public PluginInfo getInfo() {
  89.       String name = mLocalizer.msg("pluginName", "Reminder");
  90.       String desc = mLocalizer.msg("description", "Eine einfache Implementierung einer Erinnerungsfunktion.");
  91.       String author = "Martin Oberhauser (darras@users.sourceforge.net)";
  92.       return new PluginInfo(name, desc, author, new Version(1, 8));
  93.    }
  94.  
  95.    public void readData(ObjectInputStream in) throws IOException, ClassNotFoundException {
  96.       int version = in.readInt();
  97.       this.mReminderList.setReminderTimerListener((ReminderTimerListener)null);
  98.       this.mReminderList = new ReminderList(in);
  99.       this.mReminderList.setReminderTimerListener(this);
  100.       if (this.mReminderList != null) {
  101.          this.mReminderList.removeExpiredItems();
  102.          this.mReminderList.setReminderTimerListener(this);
  103.          Iterator iter = this.mReminderList.getReminderItems();
  104.  
  105.          while(iter.hasNext()) {
  106.             ReminderListItem item = (ReminderListItem)iter.next();
  107.             item.getProgram().mark(this);
  108.          }
  109.       }
  110.  
  111.    }
  112.  
  113.    public void writeData(ObjectOutputStream out) throws IOException {
  114.       out.writeInt(2);
  115.       this.mReminderList.writeData(out);
  116.    }
  117.  
  118.    public Properties storeSettings() {
  119.       return this.mSettings;
  120.    }
  121.  
  122.    public void loadSettings(Properties settings) {
  123.       if (settings == null) {
  124.          settings = new Properties();
  125.       }
  126.  
  127.       if (settings.getProperty("usemsgbox") == null) {
  128.          settings.setProperty("usemsgbox", "true");
  129.       }
  130.  
  131.       this.mSettings = settings;
  132.    }
  133.  
  134.    private int getAutoCloseReminderTime() {
  135.       int autoCloseReminderTime = 0;
  136.  
  137.       try {
  138.          String asString = this.mSettings.getProperty("autoCloseReminderTime", "0");
  139.          autoCloseReminderTime = Integer.parseInt(asString);
  140.       } catch (Exception var3) {
  141.       }
  142.  
  143.       return autoCloseReminderTime;
  144.    }
  145.  
  146.    public String getContextMenuItemText() {
  147.       return mLocalizer.msg("contextMenuText", "Remind me");
  148.    }
  149.  
  150.    public String getButtonText() {
  151.       return mLocalizer.msg("buttonText", "Reminder list");
  152.    }
  153.  
  154.    public SettingsTab getSettingsTab() {
  155.       return new ReminderSettingsTab(this.mSettings);
  156.    }
  157.  
  158.    public void execute(Program program) {
  159.       if (program.isExpired()) {
  160.          String msg = mLocalizer.msg("programAlreadyExpired", "The program is already expired!");
  161.          JOptionPane.showMessageDialog(this.getParentFrame(), msg);
  162.       } else {
  163.          ReminderDialog dlg = new ReminderDialog(this.getParentFrame(), program, this.mSettings);
  164.          UiUtilities.centerAndShow(dlg);
  165.          if (dlg.getOkPressed()) {
  166.             int minutes = dlg.getReminderMinutes();
  167.             this.addToReminderList(program, minutes);
  168.          }
  169.  
  170.          dlg.dispose();
  171.       }
  172.  
  173.    }
  174.  
  175.    public void execute(Program[] programArr) {
  176.       int minutes = 3;
  177.  
  178.       for(int i = 0; i < programArr.length; ++i) {
  179.          this.addToReminderList(programArr[i], minutes);
  180.       }
  181.  
  182.    }
  183.  
  184.    public void execute() {
  185.       JDialog dlg = new ReminderListDialog(this.getParentFrame(), this.mReminderList);
  186.       dlg.setSize(600, 350);
  187.       UiUtilities.centerAndShow(dlg);
  188.       dlg.dispose();
  189.    }
  190.  
  191.    private void addToReminderList(Program program, int minutes) {
  192.       this.mReminderList.add(program, minutes);
  193.    }
  194.  
  195.    public String getMarkIconName() {
  196.       return "reminderplugin/TipOfTheDay16.gif";
  197.    }
  198.  
  199.    public String getButtonIconName() {
  200.       return "reminderplugin/TipOfTheDay16.gif";
  201.    }
  202.  
  203.    public boolean supportMultipleProgramExecution() {
  204.       return true;
  205.    }
  206.  
  207.    public void handleTvDataDeleted(ChannelDayProgram oldProg) {
  208.       for(int i = 0; i < oldProg.getProgramCount(); ++i) {
  209.          Program prog = oldProg.getProgramAt(i);
  210.          ReminderListItem item = this.mReminderList.getItemWithProgram(prog);
  211.          if (item != null) {
  212.             this.mReminderList.remove(prog);
  213.             this.mReminderItemsTrash.add(item);
  214.          }
  215.       }
  216.  
  217.    }
  218.  
  219.    public void handleTvDataChanged() {
  220.       for(ReminderListItem trashItem : this.mReminderItemsTrash) {
  221.          Program p = Plugin.getPluginManager().getProgram(trashItem.getProgram().getDate(), trashItem.getProgram().getID());
  222.          if (p != null) {
  223.             this.mReminderList.add(p, trashItem.getReminderMinutes());
  224.             p.mark(this);
  225.          }
  226.       }
  227.  
  228.       this.mReminderItemsTrash.clear();
  229.    }
  230.  
  231.    // $FF: synthetic method
  232.    static Class class$(String x0) {
  233.       try {
  234.          return Class.forName(x0);
  235.       } catch (ClassNotFoundException x1) {
  236.          throw new NoClassDefFoundError(x1.getMessage());
  237.       }
  238.    }
  239.  
  240.    static {
  241.       mLocalizer = Localizer.getLocalizerFor(class$reminderplugin$ReminderPlugin == null ? (class$reminderplugin$ReminderPlugin = class$("reminderplugin.ReminderPlugin")) : class$reminderplugin$ReminderPlugin);
  242.    }
  243. }
  244.