[Buix-commits] r1170 - jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing
Author: tchemit Date: 2009-01-19 11:54:13 +0000 (Mon, 19 Jan 2009) New Revision: 1170 Modified: jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/Utils.java Log: add usefull methods to fill aJAXXList and JAXXComboBox. todo put thoses methods in JAXXList and JAXXComboBox since we can do it :) Modified: jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/Utils.java =================================================================== --- jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/Utils.java 2009-01-19 11:45:47 UTC (rev 1169) +++ jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/Utils.java 2009-01-19 11:54:13 UTC (rev 1170) @@ -15,6 +15,8 @@ import javax.swing.text.AbstractDocument; import javax.swing.text.JTextComponent; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -127,31 +129,10 @@ model.addListDataListener(combo); model.setSelectedItem(select); } - - /** - * Fill a combo box model with some datas, and select after all the given object - * - * @param combo the combo to fill - * @param data data ot inject in combo - * @param select the object to select in combo after reflling his model - * @param method method to invoke to display data's name - */ - public static void fillComboBox(jaxx.runtime.swing.JAXXComboBox combo, Collection<?> data, Object select, String methodName) { - try{ - List<Item> items = new ArrayList<Item>(); - for (Object o : data) { - boolean selected = o.equals(select); - Method m = o.getClass().getMethod(methodName, null); - items.add(new Item(o.toString(), (String)m.invoke(o, null), o, selected)); - } - combo.setItems(items); - } - catch(Exception eee){ - - } - } /** + * TODO put this code directly in JAXXList, since we can do it :) + * <p/> * Fill a list model with some datas, and select after all the given object * * @param list the list to fill @@ -171,6 +152,7 @@ } /** + * TODO put this code directly in JAXXList, since we can do it :) * Fill a list model with some datas, and select after all the given object * * @param list the list to fill @@ -185,29 +167,84 @@ } list.setItems(items); } - - /** - * Fill a list model with some datas, and select after all the given object - * - * @param list the list to fill - * @param data data ot inject in combo - * @param select object to select in list after reflling his model - * @param method method to invoke to display data's name - */ - public static void fillList(jaxx.runtime.swing.JAXXList list, Collection<?> data, Object select, String methodName) { - try{ - List<Item> items = new ArrayList<Item>(); - for (Object o : data) { - boolean selected = o.equals(select); - Method m = o.getClass().getMethod(methodName, null); - items.add(new Item(o.toString(), (String)m.invoke(o, null), o, selected)); - } - list.setItems(items); - } - catch(Exception eee){ - } - } + + /** + * TODO put this code directly in JAXXComboBox, since we can do it :) + * Fill a combo box model with some datas, and select after all the given object + * + * @param combo the combo to fill + * @param data data ot inject in combo + * @param select the object to select in combo after reflling his model + * @param methodName method to invoke to display data's name + */ + public static void fillComboBox(jaxx.runtime.swing.JAXXComboBox combo, Collection<?> data, Object select, String methodName) { + // prepare method to use + Method m; + try { + m = select.getClass().getMethod(methodName); + m.setAccessible(true); + } catch (NoSuchMethodException e) { + throw new IllegalArgumentException("could not find method " + methodName + " on " + select.getClass()); + } + + List<Item> items = new ArrayList<Item>(); + for (Object o : data) { + boolean selected = o.equals(select); + try { + items.add(new Item(o.toString(), (String) m.invoke(o), o, selected)); + } catch (IllegalAccessException e) { + // shoudl never happen ? + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + // shoudl never happen ? + throw new RuntimeException(e); + } + } + combo.setItems(items); + } + + /** + * TODO put this code directly in JAXXList, since we can do it :) + * Fill a list model with some datas, and select after all the given object + * + * @param list the list to fill + * @param data data ot inject in combo + * @param select object to select in list after reflling his model + * @param methodName method to invoke to display data's name + */ + public static void fillList(jaxx.runtime.swing.JAXXList list, Collection<?> data, Object select, String methodName) { + // prepare method to use + Method m; + try { + m = select.getClass().getMethod(methodName); + m.setAccessible(true); + } catch (NoSuchMethodException e) { + throw new IllegalArgumentException("could not find method " + methodName + " on " + select.getClass()); + } + + List<Item> items = new ArrayList<Item>(); + for (Object o : data) { + boolean selected = o.equals(select); + try { + items.add(new Item(o.toString(), (String) m.invoke(o), o, selected)); + } catch (SecurityException e) { + // shoudl never happen ? + throw new RuntimeException(e); + } catch (IllegalAccessException e) { + // shoudl never happen ? + throw new RuntimeException(e); + } catch (IllegalArgumentException e) { + // shoudl never happen ? + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + // shoudl never happen ? + throw new RuntimeException(e); + } + } + list.setItems(items); + } + public static void fixTableColumnWidth(JTable table, int columnIndex, int width) { TableColumn column = table.getColumnModel().getColumn(columnIndex); column.setMaxWidth(width);
participants (1)
-
tchemit@users.labs.libre-entreprise.org