1 package thinlet.drafts; 2 3 import java.io.*; 4 import java.text.*; 5 import thinlet.*; 6 7 10 public class AutoFill { 11 12 private String [] autofill; 13 14 17 public void load(Thinlet thinlet, Object localelist, Object shortmonths, Object months, 18 Object shortweekdays, Object weekdays) { 19 DateFormatSymbols symbols = new DateFormatSymbols(); 20 fill(thinlet, shortmonths, symbols.getShortMonths()); 21 fill(thinlet, months, symbols.getMonths()); 22 fill(thinlet, shortweekdays, symbols.getShortWeekdays()); 23 fill(thinlet, weekdays, symbols.getWeekdays()); 24 25 autofill = symbols.getWeekdays(); 26 } 27 28 31 private void fill(Thinlet thinlet, Object list, String [] values) { 32 for (int i = 0; i < values.length; i++) { 33 Object item = Thinlet.create("item"); 34 thinlet.setString(item, "text", values[i]); 35 thinlet.add(list, item); 36 } 37 } 38 39 42 public void autoFill(Thinlet thinlet, Object textfield, String text, int caret) { 43 if (text.length() == caret) { 44 for (int i = 0; i < autofill.length; i++) { 45 if (autofill[i].startsWith(text)) { 46 thinlet.setString(textfield, "text", autofill[i]); 47 thinlet.setInteger(textfield, "start", autofill[i].length()); 48 break; 49 } 50 } 51 } 52 } 53 54 57 public void initPath(Thinlet thinlet, Object textfield) { 58 thinlet.setString(textfield, "text", System.getProperty("user.dir")); 59 } 60 61 64 public void complementPath(Thinlet thinlet, Object textfield, String text, int caret) { 65 if (text.length() == caret) { 66 int index = text.lastIndexOf(File.separatorChar); 67 if (index == -1) { return; } 68 String foldername = text.substring(0, index + 1); 69 File folder = new File(foldername); 70 String namestart = text.substring(index + 1); 71 String [] list = folder.list(); 72 if (list == null) { return; } for (int i = 0; i < list.length; i++) { 74 if (list[i].startsWith(namestart)) { 75 String path = foldername + list[i]; 76 if (new File(folder, list[i]).isDirectory()) { path += File.separatorChar; } 77 thinlet.setString(textfield, "text", path); 78 thinlet.setInteger(textfield, "end", path.length()); 79 break; 80 } 81 } 82 } 83 } 84 } | Popular Tags |