1 36 package org.ungoverned.moduleloader.search.selection; 37 38 import java.io.BufferedReader ; 39 import java.io.InputStreamReader ; 40 41 import org.ungoverned.moduleloader.Module; 42 import org.ungoverned.moduleloader.search.SelectionPolicy; 43 import org.ungoverned.moduleloader.search.CompatibilityPolicy; 44 45 55 public class InteractiveSelectionPolicy implements SelectionPolicy 56 { 57 63 public Module select(Module module, Object target, 64 Object version, Module[] candidates, CompatibilityPolicy compatPolicy) 65 { 66 try { 67 if (candidates.length == 1) 68 { 69 return candidates[0]; 70 } 71 BufferedReader br = new BufferedReader (new InputStreamReader (System.in)); 73 do 74 { 75 System.out.println("\nImporting '" + target 76 + "(" + version + ")" + "' for '" + module + "'."); 77 System.out.println(""); 78 for (int i = 0; i < candidates.length; i++) 79 { 80 System.out.println((i + 1) + ". " + candidates[i]); 81 } 82 System.out.print("Select: "); 83 String s = br.readLine(); 84 85 int choice = -1; 86 try { 87 choice = Integer.parseInt(s); 88 } catch (Exception ex) { 89 } 90 91 if (choice == 0) 92 { 93 break; 94 } 95 else if ((choice > 0) && (choice <= candidates.length)) 96 { 97 return candidates[choice - 1]; 98 } 99 } 100 while (true); 101 } catch (Exception ex) { 102 } 103 104 return null; 105 } 106 } | Popular Tags |