Changeset 259 for trunk


Ignore:
Timestamp:
07/20/06 02:05:30 (18 years ago)
Author:
Nicholas Riley
Message:

Sortable alarm list.

Location:
trunk/hiptop/pester/net/sabi/pester
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/hiptop/pester/net/sabi/pester/Alarm.java

    r255 r259  
    99import danger.internal.Date;
    1010import danger.system.Hardware;
     11import danger.text.Collator;
    1112import danger.util.LocaleUtils;
    1213import danger.util.StdActiveList;
     
    1516import danger.util.format.DateFormat;
    1617import danger.util.format.StringFormat;
    17 
    18 public class Alarm extends StdActiveObject {
     18import java.util.Comparator;
     19
     20public class Alarm extends StdActiveObject implements Comparator {
    1921    private static final int VERSION_1 = 1;
    2022
     
    263265    }
    264266
     267    public int compare(Object arg0, Object arg1) {
     268        Alarm alarm0 = (Alarm)arg0, alarm1 = (Alarm)arg1;
     269        int result = alarm0.getDate().compareTo(alarm1.getDate());
     270        if (result != 0) return result;
     271        result = Collator.getInstance().compare(alarm0.getMessage(),
     272                                                alarm1.getMessage());
     273        if (result != 0) return result;
     274        return alarm0.hashCode() - alarm1.hashCode();
     275    }
     276
    265277    public static final int TYPE_PERIODIC = 0;
    266278    public static final int TYPE_PERIODIC_REPEATING = 1;
  • trunk/hiptop/pester/net/sabi/pester/AlarmListView.java

    r257 r259  
    55import danger.ui.ActiveListView;
    66import danger.util.ActiveList;
     7import danger.util.DEBUG;
    78
    89public class AlarmListView extends ActiveListView
     
    5960    public void onItemAdded(ActiveList list, Object item, int index) {
    6061        sAlarmListWindow.updateAlarmCount();
     62        super.onItemAdded(list, item, index);
     63        // super's default behavior is to preserve the existing selection,
     64        // which is admirable in general, but not what we want
    6165        setFocus(index);
    62         super.onItemAdded(list, item, index);
    6366    }
    6467    public void onItemRemoved(ActiveList list, Object item, int index) {
  • trunk/hiptop/pester/net/sabi/pester/Alarms.java

    r258 r259  
    3535
    3636    public static void addAlarm(Alarm alarm) {
    37         sAlarmList.addItem(alarm);
     37        sAlarmList.insertItemSorted(alarm, alarm);
    3838    }
    3939    public static void removeAlarm(Alarm alarm) {
     
    5858    }
    5959
    60     /*
    61     private static Alarm sAlarm0 = new Alarm();
    62     private static Alarm sAlarm1 = new Alarm();
    63     public int compare(Object arg0, Object arg1) {
    64        
    65         return Collator.getInstance().compare(
    66     }
    67     */
    68 
    6960    static class Listener extends danger.app.Listener
    7061        implements danger.util.ActiveList.ForEach {
Note: See TracChangeset for help on using the changeset viewer.