1 19 20 package org.netbeans.modules.tasklist.usertasks.editors; 21 22 import java.beans.PropertyEditorSupport ; 23 import java.text.ParseException ; 24 import org.netbeans.modules.tasklist.usertasks.options.Settings; 25 import org.netbeans.modules.tasklist.usertasks.model.Duration; 26 import org.netbeans.modules.tasklist.usertasks.util.DurationFormat; 27 import org.openide.explorer.propertysheet.PropertyEnv; 28 29 34 public class DurationPropertyEditor extends PropertyEditorSupport { 35 private static final int[] DURATIONS = new int[] { 36 0, 37 5, 38 10, 39 15, 40 20, 41 30, 42 45, 43 60, 44 90, 45 120, 46 150, 47 180, 48 240, 49 300, 50 360, 51 420, 52 480, 53 12 * 60, 54 8 * 60 * 2 55 }; 56 private static String [] TAGS; 57 58 private static final DurationFormat FORMAT = new DurationFormat( 59 DurationFormat.Type.SHORT); 60 private DurationFormat LONG = new DurationFormat(DurationFormat.Type.LONG); 61 62 public String getAsText() { 63 Integer value = (Integer ) getValue(); 64 int duration = value == null ? 0 : value.intValue(); 65 Duration d = new Duration(duration, 66 Settings.getDefault().getMinutesPerDay(), 67 Settings.getDefault().getDaysPerWeek(), true); 68 69 return FORMAT.format(d); 70 } 71 72 public void setAsText(String text) throws IllegalArgumentException { 73 Duration d = null; 74 try { 75 d = FORMAT.parse(text); 76 } catch (ParseException ex) { 77 try { 78 d = LONG.parse(text); 79 } catch (ParseException e) { 80 throw new IllegalArgumentException (e); 81 } 82 } 83 84 setValue(new Integer (d.toMinutes( 85 Settings.getDefault().getMinutesPerDay(), 86 Settings.getDefault().getDaysPerWeek(), true))); 87 } 88 89 public void attachEnv(PropertyEnv env) { 90 env.getFeatureDescriptor().setValue( "canEditAsText", Boolean.TRUE ); 91 } 92 93 public String [] getTags() { 94 if (TAGS == null) { 95 int mpd = Settings.getDefault().getMinutesPerDay(); 96 int dpw = Settings.getDefault().getDaysPerWeek(); 97 TAGS = new String [DURATIONS.length]; 98 for (int i = 0; i < TAGS.length; i++) { 99 TAGS[i] = FORMAT.format(new Duration( 100 DURATIONS[i], mpd, dpw, false)); 101 } 102 } 103 return TAGS; 104 } 105 } 106 | Popular Tags |