Author: tchemit Date: 2009-11-04 21:35:40 +0100 (Wed, 04 Nov 2009) New Revision: 1627 Modified: branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/SwingUtil.java branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/JAXXComboBox.java Log: add fillList + deprecated some code Modified: branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/SwingUtil.java =================================================================== --- branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/SwingUtil.java 2009-11-03 23:15:39 UTC (rev 1626) +++ branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/SwingUtil.java 2009-11-04 20:35:40 UTC (rev 1627) @@ -35,10 +35,7 @@ import java.io.IOException; import java.io.InputStream; import java.util.List; -import javax.swing.DefaultComboBoxModel; -import javax.swing.JComboBox; -import javax.swing.JTable; -import javax.swing.SwingUtilities; +import javax.swing.*; import javax.swing.event.TreeSelectionEvent; import javax.swing.table.TableCellEditor; import javax.swing.table.TableCellRenderer; @@ -58,21 +55,12 @@ import java.util.Map.Entry; import java.util.NoSuchElementException; import java.util.Properties; -import javax.swing.Icon; -import javax.swing.ImageIcon; -import javax.swing.JComponent; -import javax.swing.JLabel; -import javax.swing.JLayeredPane; -import javax.swing.JRootPane; -import javax.swing.JTabbedPane; -import javax.swing.JTree; -import javax.swing.UIManager; -import javax.swing.UnsupportedLookAndFeelException; import javax.swing.event.HyperlinkEvent; import javax.swing.event.TreeSelectionListener; import javax.swing.table.DefaultTableCellRenderer; import javax.swing.tree.TreeNode; import javax.swing.tree.TreePath; + import jaxx.runtime.swing.renderer.BooleanCellRenderer; import jaxx.runtime.swing.renderer.EmptyNumberTableCellRenderer; import jaxx.runtime.swing.renderer.EnumTableCellRenderer; @@ -85,15 +73,17 @@ /** * The runtime swing util class with some nice stuff. + * <p/> + * Note : Replace previous class jaxx.runtime.swing.Utils in previous versions. * - * Note : Replace previous class jaxx.runtime.swing.Utils in previous versions. - * * @author tony * @since 1.2 */ public class SwingUtil extends Util { - /** to use log facility, just put in your code: log.info(\"...\"); */ + /** + * to use log facility, just put in your code: log.info(\"...\"); + */ static private final Log log = LogFactory.getLog(SwingUtil.class); private static Field numReaders; private static Field notifyingListeners; @@ -188,15 +178,42 @@ } /** + * 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 the object to select in combo after reflling his model + */ + public static void fillList(JList list, Collection<?> data, Object select) { + if (!(list.getModel() instanceof DefaultListModel)) { + throw new IllegalArgumentException("this method need a DefaultComboBoxModel for this model but was " + list.getModel().getClass()); + } + DefaultListModel model = (DefaultListModel) list.getModel(); + // evince the model +// model.removeListDataListener(combo); + model.removeAllElements(); + if (data != null) { + for (Object o : data) { + model.addElement(o); + } + } + // attach the model +// model.addListDataListener(combo); + list.setSelectedValue(select, true); + } + + /** * TODO move this to JAXXComboBox. - * + * <p/> * 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 firstNull add a first null element + * @deprecated since 1.7.XXX this code is moved to JAXXComboBox */ + @Deprecated public static void fillComboBox(JAXXComboBox combo, Collection<?> data, Object select, boolean firstNull) { List<Item> items = new ArrayList<Item>(); if (firstNull) { @@ -385,10 +402,10 @@ /** * Centrer un component graphique au center d'un autre component. - * + * <p/> * <b>Note:</b> si le parent est null, alors on ne fait rien. * - * @param parent le component parent + * @param parent le component parent * @param component le component à centrer */ public static void center(Component parent, Component component) { @@ -404,6 +421,7 @@ /** * Try to load the Nimbus look and feel. * <p/> + * * @throws UnsupportedLookAndFeelException * if nimbus is not applicable * @throws ClassNotFoundException @@ -423,9 +441,8 @@ * Load the ui.properties file and set in {@link UIManager} colors and icons found. * * @param defaultUIConfig le path vers le fichier de la config d'ui par défaut (doit etre dansle class-path) - * @param extraUIConfig le path vers une surcharge de la config d'ui (doit etre dans le class-path) - * - * @throws IOException if could not load the ui.properties file + * @param extraUIConfig le path vers une surcharge de la config d'ui (doit etre dans le class-path) + * @throws IOException if could not load the ui.properties file */ public static void loadUIConfig(String defaultUIConfig, String extraUIConfig) throws IOException { @@ -471,8 +488,9 @@ /** * Iterate the components of a {@link JTabbedPane} in natural order. + * <p/> + * Says using method {@link JTabbedPane#getComponent(int)} * - * Says using method {@link JTabbedPane#getComponent(int)} * @param tabs the * @return the iterator * @since 1.4 @@ -489,15 +507,15 @@ /** * A simple iterator on a {@link JTabbedPane}. - * + * <p/> * Implements the method {@link #get(int, java.awt.Component)} to obtain * the data required given the component (or index). - * + * <p/> * You can also inverse the order by usin the method {@link #reverse()}. - * + * <p/> * Note: After the use of the method {@link #reverse()} the iterator returns * to the first element. - * + * * @param <O> the type of return elements. * @since 1.4 */ @@ -589,6 +607,7 @@ /** * Gets the higest visible component in a ancestor hierarchy at * specific x,y coordinates + * * @param parent * @param x * @param y @@ -702,9 +721,9 @@ /** * Open a link coming from a {@link HyperlinkEvent}. + * <p/> + * And try to open the link if an url in a browser. * - * And try to open the link if an url in a browser. - * * @param he the event to treate * @since 1.6.0 */ Modified: branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/JAXXComboBox.java =================================================================== --- branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/JAXXComboBox.java 2009-11-03 23:15:39 UTC (rev 1626) +++ branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/JAXXComboBox.java 2009-11-04 20:35:40 UTC (rev 1627) @@ -20,12 +20,7 @@ */ package jaxx.runtime.swing; -import javax.swing.AbstractListModel; -import javax.swing.ComboBoxModel; -import javax.swing.DefaultListCellRenderer; -import javax.swing.JComboBox; -import javax.swing.JList; -import javax.swing.ListModel; +import javax.swing.*; import java.awt.Component; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; @@ -221,6 +216,27 @@ setItems(items); } + /** + * Fill the model with some datas, and select after all the given object + * + * @param data data ot inject in combo + * @param select the object to select in combo after reflling his model + * @param firstNull add a first null element + * @deprecated since 1.7.XXX this code is moved to JAXXComboBox + */ + public void fillComboBox(Collection<?> data, Object select, boolean firstNull) { + List<Item> items = new ArrayList<Item>(); + if (firstNull) { + items.add(new Item("null", " ", null, false)); + } + if (data != null) { + for (Object d : data) { + items.add(new Item(d.toString(), d.toString(), d, d.equals(select))); + } + } + this.setItems(items); + } + // this way we can keep it marked protected and still allow code in this file to call it @Override protected void fireItemStateChanged(ItemEvent e) {
participants (1)
-
tchemit@users.nuiton.org