Changeset 240 for trunk/hiptop/pester


Ignore:
Timestamp:
07/08/06 21:20:00 (18 years ago)
Author:
Nicholas Riley
Message:

More UI.

Location:
trunk/hiptop/pester
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/hiptop/pester/locale/en_US/Pester.rsrc

    r239 r240  
    128128               
    129129                checkBox
    130                         id = ID_PERIOD_REPEAT_BUTTON
     130                        id = ID_PERIOD_REPEAT_CHECKBOX
    131131                        title = "Repeat"
    132132                        alignBaseline = ID_PERIOD_UNITS_POPUP
     
    150150                        id = ID_TIME_EDITOR
    151151                        longTimeFormat
     152                        event = EVENT_TIME_EDITOR
    152153                        alignBaseline = ID_AT_BUTTON
    153154                        positionToRight = ID_AT_BUTTON : 1
     
    155156                dateEditor
    156157                        id = ID_DATE_EDITOR
     158                        event = EVENT_DATE_EDITOR
    157159                        positionToRight = ID_TIME_EDITOR : 1
    158160                        alignBaseline = ID_TIME_EDITOR
     
    160162                datePicker
    161163                        id = ID_DATE_PICKER
     164                        event = EVENT_DATE_PICKER
    162165                        positionToRight = ID_DATE_EDITOR : 1
    163166                        alignTop = ID_DATE_EDITOR
     
    171174
    172175        button
     176                id = ID_SET_ALARM_BUTTON
    173177                position = buttonBottom1
    174178                title = "Set"
  • trunk/hiptop/pester/net/sabi/pester/Alarm.java

    r239 r240  
    77import danger.internal.Date;
    88import danger.util.StdActiveObject;
     9import danger.util.DEBUG;
    910
    1011public class Alarm extends StdActiveObject {
     
    1415    private String mMessage;
    1516    private int mType;
    16     private long mPeriod;
     17    private int mPeriod; // XXX rename to 'interval'
    1718    private Date mDate;
    1819
     
    2728        return mMessage;
    2829    }
    29     public long getPeriod() {
     30    public int getPeriod() {
    3031        return mPeriod;
    3132    }
    3233    public boolean getUsesPeriod() {
    3334        return mType != TYPE_DATE;
     35    }
     36    public boolean getRepeating() {
     37        return mType == TYPE_PERIODIC_REPEATING;
    3438    }
    3539    public Date getDate() {
     
    4044        mMessage = message;
    4145    }
    42     public void setPeriod(long period, boolean repeating) {
     46    public void setPeriod(int period, boolean repeating) {
    4347        mType = repeating ? TYPE_PERIODIC_REPEATING : TYPE_PERIODIC;
    4448        mPeriod = period;
     49        mDate = new Date();
     50        mDate.addSeconds(period);
    4551    }
    4652    public void setDate(Date date) {
     
    5662            dataStream.writeByte(VERSION_1);
    5763            dataStream.writeUTF(mMessage);
    58             dataStream.writeLong(mPeriod);
     64            dataStream.writeInt(mPeriod);
    5965            dataStream.writeInt(mDate.getUnixTimeGMT());
    6066            dataStream.writeInt(mType);
     
    7783            }
    7884            mMessage = dataStream.readUTF();
    79             mPeriod = dataStream.readLong();
     85            mPeriod = dataStream.readInt();
    8086            mType = dataStream.readInt();
    8187        } catch (Exception e) {
     
    9096    void endEditing() {
    9197        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        }
    92107    }
    93108   
  • trunk/hiptop/pester/net/sabi/pester/AlarmListView.java

    r239 r240  
    33import danger.app.Application;
    44import danger.app.Event;
     5import danger.internal.Date;
    56import danger.ui.ActiveListView;
    67import danger.ui.Button;
     8import danger.ui.CheckBox;
     9import danger.ui.DateTimeEditor;
     10import danger.ui.DatePicker;
    711import danger.ui.DialogWindow;
     12import danger.ui.NumberEditor;
     13import danger.ui.PopupMenu;
    814import danger.ui.RadioButton;
    915import danger.ui.Rect;
     
    2329    private static DialogWindow sEditWindow;
    2430    private TypeAheadTextField sMessageField;
    25     private Button sDiscardAlarmButton;
    2631    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;
    2738
    2839    private static Alarm sFocusedAlarm, sEditingAlarm;
     
    4253        sInButton = (RadioButton)sEditWindow.getDescendantWithID(ID_IN_BUTTON);
    4354        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);
    4462        sDiscardAlarmButton = (Button)sEditWindow.getDescendantWithID(ID_DISCARD_ALARM_BUTTON);
     63        sInButton.setValue(1);
     64        sDateEditor.limitToDangerEpoch();
    4565
    4666        super.onDecoded();
     
    5777    }
    5878
    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) {
    60106        sEditingAlarm = alarm;
    61107        alarm.beginEditing();
    62         sMessageField.setText(sEditingAlarm.getMessage());
     108        sMessageField.setText(alarm.getMessage());
    63109        if (asNew) {
    64110            sDiscardAlarmButton.hide();
    65111        } else {
    66112            sDiscardAlarmButton.show();
    67         }
    68         boolean usesPeriod = sEditingAlarm.getUsesPeriod();
    69        
     113            editDateOrPeriod(alarm);
     114        }
     115        constrainDate();
    70116        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);
    71131    }
    72132
     
    77137            return true;
    78138        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            }
    79149            if (sEditingAlarm != sFocusedAlarm) { // new alarm
    80150                sAlarmList.addItem(sEditingAlarm);
    81151                setFocusedItem(sEditingAlarm);
    82             }
    83             sEditingAlarm.setMessage(sMessageField.toString());
    84             sEditingAlarm.update();
     152            } else {
     153                sEditingAlarm.update();
     154            }
    85155        case EVENT_CANCEL_ALARM:
    86156            // XXX (re)schedule alarm
     
    96166        case EVENT_AT:
    97167            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();
    98188            return true;
    99189        }
Note: See TracChangeset for help on using the changeset viewer.