1 19 20 package org.netbeans.modules.tasklist.usertasks; 21 22 import javax.swing.SwingUtilities ; 23 import javax.swing.event.ChangeEvent ; 24 import javax.swing.event.ChangeListener ; 25 import org.netbeans.modules.tasklist.usertasks.model.*; 26 import org.netbeans.modules.tasklist.usertasks.model.UserTaskList.UserTaskProcessor; 27 import org.openide.DialogDisplayer; 28 import org.openide.DialogDescriptor; 29 import org.openide.NotifyDescriptor; 30 import org.openide.util.NbBundle; 31 32 37 public class DueTasksNotifier implements Timeout { 38 41 private static class FindNextTimeoutUserTaskProcessor implements 42 UserTaskProcessor { 43 private long nextTimeout = Long.MAX_VALUE; 44 45 46 public UserTask ref = null; 47 48 public void process(UserTask t) { 49 long n = t.getDueTime(); 50 if (n != Long.MAX_VALUE && !t.isDueAlarmSent() && !t.isDone() && 51 n > System.currentTimeMillis() && n < nextTimeout) { 52 nextTimeout = n; 53 ref = t; 54 } 55 } 56 } 57 58 private static class ShowExpiredUserTaskProcessor implements 59 UserTaskProcessor { 60 public void process(UserTask t) { 61 long n = t.getDueTime(); 62 if (n != Long.MAX_VALUE && !t.isDueAlarmSent() && 63 !t.isDone() && 64 n <= System.currentTimeMillis()) { 65 showExpiredTask(t); 66 } 67 } 68 69 75 private void showExpiredTask(UserTask task) { 76 task.setDueAlarmSent(true); 77 78 final UserTask t = task; 79 SwingUtilities.invokeLater(new Runnable () { 80 public void run() { 81 UserTaskDuePanel panel = new UserTaskDuePanel(t); 82 83 String title = NbBundle.getMessage(DueTasksNotifier.class, 84 "TaskDueLabel"); DialogDescriptor d = new DialogDescriptor(panel, title); 86 d.setModal(true); 87 d.setMessageType(NotifyDescriptor.PLAIN_MESSAGE); 88 d.setOptions(new Object [] {DialogDescriptor.OK_OPTION}); 89 java.awt.Dialog dlg = DialogDisplayer.getDefault().createDialog(d); 90 dlg.pack(); 91 dlg.setVisible(true); 92 } 93 }); 94 } 95 } 96 97 98 private long currentTimeout; 99 100 private UserTaskList utl; 101 102 107 public DueTasksNotifier(UserTaskList utl) { 108 this.utl = utl; 109 currentTimeout = Long.MAX_VALUE; 110 utl.addChangeListener(new ChangeListener () { 111 public void stateChanged(ChangeEvent e) { 112 orderNextTimeout(); 113 } 114 }); 115 } 116 117 120 public void orderNextTimeout() { 121 ShowExpiredUserTaskProcessor se = 122 new ShowExpiredUserTaskProcessor(); 123 utl.processDepthFirst(se, utl.getSubtasks()); 124 125 FindNextTimeoutUserTaskProcessor p = 126 new FindNextTimeoutUserTaskProcessor(); 127 utl.processDepthFirst(p, utl.getSubtasks()); 128 129 if (p.ref != null && p.ref.getDueTime() != Long.MAX_VALUE && 130 !p.ref.isDueAlarmSent() && !p.ref.isDone() && 131 p.ref.getDueTime() != currentTimeout) { 132 if (currentTimeout != Long.MAX_VALUE) { 134 TimeoutProvider.getInstance().cancel(this, null); 135 } 136 TimeoutProvider.getInstance().add(this, p.ref, p.ref.getDueTime()); 137 currentTimeout = p.ref.getDueTime(); 138 } 139 } 140 141 148 public void timeoutExpired(Object o) { 149 orderNextTimeout(); 151 } 152 153 } 154 | Popular Tags |