Changeset 240 for trunk/hiptop/pester/net
- Timestamp:
- 07/08/06 21:20:00 (18 years ago)
- Location:
- trunk/hiptop/pester/net/sabi/pester
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/hiptop/pester/net/sabi/pester/Alarm.java
r239 r240 7 7 import danger.internal.Date; 8 8 import danger.util.StdActiveObject; 9 import danger.util.DEBUG; 9 10 10 11 public class Alarm extends StdActiveObject { … … 14 15 private String mMessage; 15 16 private int mType; 16 private long mPeriod;17 private int mPeriod; // XXX rename to 'interval' 17 18 private Date mDate; 18 19 … … 27 28 return mMessage; 28 29 } 29 public longgetPeriod() {30 public int getPeriod() { 30 31 return mPeriod; 31 32 } 32 33 public boolean getUsesPeriod() { 33 34 return mType != TYPE_DATE; 35 } 36 public boolean getRepeating() { 37 return mType == TYPE_PERIODIC_REPEATING; 34 38 } 35 39 public Date getDate() { … … 40 44 mMessage = message; 41 45 } 42 public void setPeriod( longperiod, boolean repeating) {46 public void setPeriod(int period, boolean repeating) { 43 47 mType = repeating ? TYPE_PERIODIC_REPEATING : TYPE_PERIODIC; 44 48 mPeriod = period; 49 mDate = new Date(); 50 mDate.addSeconds(period); 45 51 } 46 52 public void setDate(Date date) { … … 56 62 dataStream.writeByte(VERSION_1); 57 63 dataStream.writeUTF(mMessage); 58 dataStream.write Long(mPeriod);64 dataStream.writeInt(mPeriod); 59 65 dataStream.writeInt(mDate.getUnixTimeGMT()); 60 66 dataStream.writeInt(mType); … … 77 83 } 78 84 mMessage = dataStream.readUTF(); 79 mPeriod = dataStream.read Long();85 mPeriod = dataStream.readInt(); 80 86 mType = dataStream.readInt(); 81 87 } catch (Exception e) { … … 90 96 void endEditing() { 91 97 mStatus = STATUS_SCHEDULED; 98 DEBUG.p("schedule alarm: " + mMessage); 99 switch (mType) { 100 case TYPE_PERIODIC: 101 DEBUG.p(" - periodic: " + mPeriod); break; 102 case TYPE_PERIODIC_REPEATING: 103 DEBUG.p(" - periodic repeating: " + mPeriod); break; 104 case TYPE_DATE: 105 DEBUG.p(" - date: " + mDate); break; 106 } 92 107 } 93 108 -
trunk/hiptop/pester/net/sabi/pester/AlarmListView.java
r239 r240 3 3 import danger.app.Application; 4 4 import danger.app.Event; 5 import danger.internal.Date; 5 6 import danger.ui.ActiveListView; 6 7 import danger.ui.Button; 8 import danger.ui.CheckBox; 9 import danger.ui.DateTimeEditor; 10 import danger.ui.DatePicker; 7 11 import danger.ui.DialogWindow; 12 import danger.ui.NumberEditor; 13 import danger.ui.PopupMenu; 8 14 import danger.ui.RadioButton; 9 15 import danger.ui.Rect; … … 23 29 private static DialogWindow sEditWindow; 24 30 private TypeAheadTextField sMessageField; 25 private Button sDiscardAlarmButton;26 31 private RadioButton sInButton, sAtButton; 32 private NumberEditor sPeriodField; 33 private PopupMenu sPeriodUnitsPopup; 34 private CheckBox sRepeatCheckBox; 35 private DateTimeEditor sTimeEditor, sDateEditor; 36 private DatePicker sDatePicker; 37 private Button sDiscardAlarmButton, sSetAlarmButton; 27 38 28 39 private static Alarm sFocusedAlarm, sEditingAlarm; … … 42 53 sInButton = (RadioButton)sEditWindow.getDescendantWithID(ID_IN_BUTTON); 43 54 sAtButton = (RadioButton)sEditWindow.getDescendantWithID(ID_AT_BUTTON); 55 sPeriodField = (NumberEditor)sEditWindow.getDescendantWithID(ID_PERIOD_FIELD); 56 sPeriodUnitsPopup = (PopupMenu)sEditWindow.getDescendantWithID(ID_PERIOD_UNITS_POPUP); 57 sRepeatCheckBox = (CheckBox)sEditWindow.getDescendantWithID(ID_PERIOD_REPEAT_CHECKBOX); 58 sTimeEditor = (DateTimeEditor)sEditWindow.getDescendantWithID(ID_TIME_EDITOR); 59 sDateEditor = (DateTimeEditor)sEditWindow.getDescendantWithID(ID_DATE_EDITOR); 60 sDatePicker = (DatePicker)sEditWindow.getDescendantWithID(ID_DATE_PICKER); 61 sSetAlarmButton = (Button)sEditWindow.getDescendantWithID(ID_SET_ALARM_BUTTON); 44 62 sDiscardAlarmButton = (Button)sEditWindow.getDescendantWithID(ID_DISCARD_ALARM_BUTTON); 63 sInButton.setValue(1); 64 sDateEditor.limitToDangerEpoch(); 45 65 46 66 super.onDecoded(); … … 57 77 } 58 78 59 void editAlarm(Alarm alarm, boolean asNew) { 79 protected void editDateOrPeriod(Alarm alarm) { 80 boolean usesPeriod = alarm.getUsesPeriod(); 81 if (usesPeriod) { 82 int period = alarm.getPeriod(); 83 int unitsPerSec = 1; 84 DEBUG.p("period is " + period); 85 for (int i = sPeriodUnitsPopup.itemCount() - 1 ; i >= 0 ; --i) { 86 unitsPerSec = 87 sPeriodUnitsPopup.getIDOfItem(sPeriodUnitsPopup.getItem(i)); 88 DEBUG.p("unitsPerSec = " + unitsPerSec); 89 if (period % unitsPerSec == 0) break; 90 } 91 sPeriodField.setValue(period / unitsPerSec); 92 sPeriodUnitsPopup.setValueWithItemID(unitsPerSec); 93 sRepeatCheckBox.setValue(alarm.getRepeating() ? 1 : 0); 94 } 95 96 Date date = alarm.getDate(); 97 sTimeEditor.setDate(date); 98 sDateEditor.setDate(date); 99 sDatePicker.setDate(date); 100 101 sInButton.setValue(usesPeriod ? 1 : 0); 102 sAtButton.setValue(usesPeriod ? 0 : 1); 103 } 104 105 protected void editAlarm(Alarm alarm, boolean asNew) { 60 106 sEditingAlarm = alarm; 61 107 alarm.beginEditing(); 62 sMessageField.setText( sEditingAlarm.getMessage());108 sMessageField.setText(alarm.getMessage()); 63 109 if (asNew) { 64 110 sDiscardAlarmButton.hide(); 65 111 } else { 66 112 sDiscardAlarmButton.show(); 67 }68 boolean usesPeriod = sEditingAlarm.getUsesPeriod(); 69 113 editDateOrPeriod(alarm); 114 } 115 constrainDate(); 70 116 sEditWindow.show(); 117 } 118 119 protected Date editingDate() { 120 Date date = sDateEditor.getDate(); 121 date.setTime(sTimeEditor.getDate().getTime()); 122 return date; 123 } 124 125 protected void constrainDate() { 126 // XXX schedule every minute (second?) if in AT mode 127 Date now = new Date(); 128 sDateEditor.min(now); 129 sDatePicker.min(now); 130 sSetAlarmButton.setEnabled(editingDate().compareTo(now) > 0); 71 131 } 72 132 … … 77 137 return true; 78 138 case EVENT_SET_ALARM: 139 sEditingAlarm.setMessage(sMessageField.toString()); 140 if (sInButton.getValue() == 1) { 141 DEBUG.p("period: " + sPeriodField.getValue()); 142 DEBUG.p(" units: " + sPeriodUnitsPopup.getValueAsItemID()); 143 sEditingAlarm.setPeriod(sPeriodField.getValue() * 144 sPeriodUnitsPopup.getValueAsItemID(), 145 sRepeatCheckBox.getValue() == 1); 146 } else { 147 sEditingAlarm.setDate(editingDate()); 148 } 79 149 if (sEditingAlarm != sFocusedAlarm) { // new alarm 80 150 sAlarmList.addItem(sEditingAlarm); 81 151 setFocusedItem(sEditingAlarm); 82 } 83 sEditingAlarm.setMessage(sMessageField.toString());84 sEditingAlarm.update();152 } else { 153 sEditingAlarm.update(); 154 } 85 155 case EVENT_CANCEL_ALARM: 86 156 // XXX (re)schedule alarm … … 96 166 case EVENT_AT: 97 167 sInButton.setValue(0); 168 constrainDate(); 169 return true; 170 case EVENT_TIME_EDITOR: 171 Date date = editingDate(); 172 // XXX factor this out (it's used twice) 173 // XXX do this on exit from the field, not on change 174 if (date.compareTo(new Date()) <= 0) { 175 date.addDays(1); 176 sDatePicker.setDate(date); 177 sDateEditor.setDate(date); 178 } 179 constrainDate(); 180 return true; 181 case EVENT_DATE_EDITOR: 182 sDatePicker.setDate(sDateEditor.getDate()); 183 constrainDate(); 184 return true; 185 case EVENT_DATE_PICKER: 186 sDateEditor.setDate((Date)e.argument); 187 constrainDate(); 98 188 return true; 99 189 }
Note:
See TracChangeset
for help on using the changeset viewer.