1 19 20 package org.netbeans.modules.java.source.util; 21 22 import java.util.List ; 23 import javax.swing.ListModel ; 24 25 29 public final class Models { 30 31 private Models() { 32 } 33 34 35 public static <T> ListModel fromList( List <? extends T> list ) { 36 return new ListListModel<T>( list ); 37 } 38 39 41 public static <T,P> ListModel translating( ListModel model, Factory<T,P> factory ) { 42 return new TranslatingListModel<T,P>( model, factory ); 43 } 44 45 47 private static class ListListModel<T> implements ListModel { 48 49 private List <? extends T> list; 50 51 52 public ListListModel( List <? extends T> list ) { 53 this.list = list; 54 } 55 56 58 public T getElementAt(int index) { 59 return list.get( index ); 61 } 62 63 public int getSize() { 64 return list.size(); 65 } 66 67 public void removeListDataListener(javax.swing.event.ListDataListener l) { 68 } 70 71 public void addListDataListener(javax.swing.event.ListDataListener l) { 72 } 74 75 } 76 77 private static class TranslatingListModel<T,P> implements ListModel { 78 79 private Factory<T,P> factory; 80 private ListModel listModel; 81 82 83 84 public TranslatingListModel( ListModel model, Factory<T,P> factory ) { 85 this.listModel = model; 86 this.factory = factory; 87 } 88 89 91 public T getElementAt(int index) { 93 P original = (P)listModel.getElementAt( index ); 94 return factory.create( original ); 95 } 96 97 public int getSize() { 98 return listModel.getSize(); 99 } 100 101 public void removeListDataListener(javax.swing.event.ListDataListener l) { 102 } 104 105 public void addListDataListener(javax.swing.event.ListDataListener l) { 106 } 108 109 110 } 111 112 } 113 | Popular Tags |