r1542 - in trunk: jaxx-example/src/main/java/jaxx/demo jaxx-runtime-swing/src/main/java/jaxx/runtime/swing jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/navigation
Author: sletellier Date: 2009-10-01 15:31:44 +0200 (Thu, 01 Oct 2009) New Revision: 1542 Added: trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/navigation/ItemNavigationPanel.java Removed: trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/CardLayout3.java Modified: trunk/jaxx-example/src/main/java/jaxx/demo/ExempleItemTreeNavigationAdapter.java trunk/jaxx-example/src/main/java/jaxx/demo/ItemTreeNavigationDemo.jaxx trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/JAXXTree.java trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/navigation/ItemNavigationCardPanel.java Log: Ajout d'un systeme d'arbre de navigation base sur les items Modified: trunk/jaxx-example/src/main/java/jaxx/demo/ExempleItemTreeNavigationAdapter.java =================================================================== --- trunk/jaxx-example/src/main/java/jaxx/demo/ExempleItemTreeNavigationAdapter.java 2009-10-01 10:03:15 UTC (rev 1541) +++ trunk/jaxx-example/src/main/java/jaxx/demo/ExempleItemTreeNavigationAdapter.java 2009-10-01 13:31:44 UTC (rev 1542) @@ -18,10 +18,14 @@ @Override protected void valueChanged(Object data) { + ItemTreeNavigationDemo demo = (ItemTreeNavigationDemo)context; if (data instanceof String){ - ((ItemTreeNavigationDemo)context).setString((String)data); + demo.setString((String)data); } else if (data instanceof Date){ - ((ItemTreeNavigationDemo)context).setDate((Date)data); + demo.setDate((Date)data); + } else { + demo.setString(""); + demo.setDate(null); } } Modified: trunk/jaxx-example/src/main/java/jaxx/demo/ItemTreeNavigationDemo.jaxx =================================================================== --- trunk/jaxx-example/src/main/java/jaxx/demo/ItemTreeNavigationDemo.jaxx 2009-10-01 10:03:15 UTC (rev 1541) +++ trunk/jaxx-example/src/main/java/jaxx/demo/ItemTreeNavigationDemo.jaxx 2009-10-01 13:31:44 UTC (rev 1542) @@ -7,25 +7,32 @@ import jaxx.runtime.swing.navigation.*; import org.jdesktop.swingx.JXDatePicker; -new ExempleItemTreeNavigationAdapter(this, nav, content); +void $afterCompleteSetup() { + new ExempleItemTreeNavigationAdapter(this, nav, content); +} </script> <JPanel id='demoPanel' layout='{new BorderLayout()}'> <JSplitPane constraints='BorderLayout.CENTER'> <JScrollPane> <JTree id='nav' rootVisible='{false}'> - <item id='string1Item' label='String1' value='{new String("Ceci est un String")}'/> - <item id='string2Item' label='String2' value='{new String("Celui-ci un autre")}'/> - <item id='dateItem' label='Date' value='{new Date()}'/> + <!-- Allow to diplay associated pane without value --> + <item id='stringItemParent' label='String' value='{String.class}'> + <item id='string1Item' label='String1' value='{new String("Ceci est un String")}' selected='true'/> + <item id='string2Item' label='String2' value='{new String("Celui-ci un autre")}'/> + </item> + <item id='dateItemParent' label='Date' value='{Date.class}'> + <item id='dateItem' label='CurrentDate' value='{new Date()}'/> + </item> </JTree> </JScrollPane> <ItemNavigationCardPanel id="content"> - <JPanel id='stringPanel' constraints='String.class'> + <ItemNavigationPanel id='stringPanel' constructorParams='String.class' layout='{new FlowLayout()}'> <JTextField text='{getString()}'/> - </JPanel> - <JPanel id='datePanel' constraints='Date.class'> + </ItemNavigationPanel> + <ItemNavigationPanel id='datePanel' constructorParams='Date.class' layout='{new FlowLayout()}'> <JXDatePicker date='{getDate()}'/> - </JPanel> + </ItemNavigationPanel> </ItemNavigationCardPanel> </JSplitPane> </JPanel> Deleted: trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/CardLayout3.java =================================================================== --- trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/CardLayout3.java 2009-10-01 10:03:15 UTC (rev 1541) +++ trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/CardLayout3.java 2009-10-01 13:31:44 UTC (rev 1542) @@ -1,301 +0,0 @@ -package jaxx.runtime.swing; - -import java.awt.CardLayout; -import java.awt.Component; -import java.awt.Container; -import java.io.Serializable; -import java.util.Vector; - -/** - * An override of the awt {@link java.awt.CardLayout}. - * <p/> - * Because in the original layout is not overridable : everything is package level accessible. - * <p/> - * This new class allow using Object for constrains, and not only String - * - * @author letellier - * @version 1.0 - */ -public class CardLayout3 extends CardLayout{ - - /* - * Index of Component currently displayed by CardLayout. - */ - int currentCard = 0; - - /* - * This creates a Vector to store associated - * pairs of components and their names. - * @see java.util.Vector - */ - Vector vector = new Vector(); - - /* - * A pair of Component and String that represents its name. - */ - class Card implements Serializable { - static final long serialVersionUID = 6640330810709497518L; - public Object constraint; - public Component comp; - public Card(Object constraint, Component cardComponent) { - this.constraint = constraint; - this.comp = cardComponent; - } - } - - /** - * Creates a new card layout with gaps of size zero. - */ - public CardLayout3() { - this(0, 0); - } - - /** - * Creates a new card layout with the specified horizontal and - * vertical gaps. The horizontal gaps are placed at the left and - * right edges. The vertical gaps are placed at the top and bottom - * edges. - * @param hgap the horizontal gap. - * @param vgap the vertical gap. - */ - public CardLayout3(int hgap, int vgap) { - super(hgap,vgap); - } - - /** - * Adds the specified component to this card layout's internal - * table of names. The object specified by <code>constraints</code> - * must be a string. The card layout stores this string as a key-value - * pair that can be used for random access to a particular card. - * By calling the <code>show</code> method, an application can - * display the component with the specified name. - * @param comp the component to be added. - * @param constraints a tag that identifies a particular - * card in the layout. - * @see java.awt.CardLayout#show(java.awt.Container, java.lang.String) - * @exception IllegalArgumentException if the constraint is not a string. - */ - @Override - public void addLayoutComponent(Component comp, Object constraints) { - synchronized (comp.getTreeLock()) { - if (constraints instanceof String) { - addLayoutComponent((String)constraints, comp); - } else { - addLayoutComponent(constraints, comp); - } - } - } - - /** - * <code>addLayoutComponent(Component, Object)</code>. - */ - public void addLayoutComponent(Object constraint, Component comp) { - synchronized (comp.getTreeLock()) { - if (constraint == null){ - throw new IllegalArgumentException("cannot add to layout: constraint cannot be null"); - } - if (!vector.isEmpty()) { - comp.setVisible(false); - } - for (int i=0; i < vector.size(); i++) { - if (((Card)vector.get(i)).constraint.equals(constraint)) { - ((Card)vector.get(i)).comp = comp; - return; - } - } - vector.add(new Card(constraint, comp)); - } - } - - /** - * Removes the specified component from the layout. - * If the card was visible on top, the next card underneath it is shown. - * @param comp the component to be removed. - * @see java.awt.Container#remove(java.awt.Component) - * @see java.awt.Container#removeAll() - */ - @Override - public void removeLayoutComponent(Component comp) { - synchronized (comp.getTreeLock()) { - for (int i = 0; i < vector.size(); i++) { - if (((Card)vector.get(i)).comp == comp) { - // if we remove current component we should show next one - if (comp.isVisible() && (comp.getParent() != null)) { - next(comp.getParent()); - } - - vector.remove(i); - - // correct currentCard if this is necessary - if (currentCard > i) { - currentCard--; - } - break; - } - } - } - } - - /** - * Flips to the first card of the container. - * @param parent the parent container in which to do the layout - * @see java.awt.CardLayout#last - */ - @Override - public void first(Container parent) { - synchronized (parent.getTreeLock()) { - checkLayout(parent); - int ncomponents = parent.getComponentCount(); - for (int i = 0 ; i < ncomponents ; i++) { - Component comp = parent.getComponent(i); - if (comp.isVisible()) { - comp.setVisible(false); - break; - } - } - if (ncomponents > 0) { - currentCard = 0; - parent.getComponent(0).setVisible(true); - parent.validate(); - } - } - } - - /** - * Flips to the next card of the specified container. If the - * currently visible card is the last one, this method flips to the - * first card in the layout. - * @param parent the parent container in which to do the layout - * @see java.awt.CardLayout#previous - */ - @Override - public void next(Container parent) { - synchronized (parent.getTreeLock()) { - checkLayout(parent); - int ncomponents = parent.getComponentCount(); - for (int i = 0 ; i < ncomponents ; i++) { - Component comp = parent.getComponent(i); - if (comp.isVisible()) { - comp.setVisible(false); - currentCard = (i + 1) % ncomponents; - comp = parent.getComponent(currentCard); - comp.setVisible(true); - parent.validate(); - return; - } - } - showDefaultComponent(parent); - } - } - - /** - * Flips to the previous card of the specified container. If the - * currently visible card is the first one, this method flips to the - * last card in the layout. - * @param parent the parent container in which to do the layout - * @see java.awt.CardLayout#next - */ - @Override - public void previous(Container parent) { - synchronized (parent.getTreeLock()) { - checkLayout(parent); - int ncomponents = parent.getComponentCount(); - for (int i = 0 ; i < ncomponents ; i++) { - Component comp = parent.getComponent(i); - if (comp.isVisible()) { - comp.setVisible(false); - currentCard = ((i > 0) ? i-1 : ncomponents-1); - comp = parent.getComponent(currentCard); - comp.setVisible(true); - parent.validate(); - return; - } - } - showDefaultComponent(parent); - } - } - - void showDefaultComponent(Container parent) { - if (parent.getComponentCount() > 0) { - currentCard = 0; - parent.getComponent(0).setVisible(true); - parent.validate(); - } - } - - /** - * Flips to the last card of the container. - * @param parent the parent container in which to do the layout - * @see java.awt.CardLayout#first - */ - @Override - public void last(Container parent) { - synchronized (parent.getTreeLock()) { - checkLayout(parent); - int ncomponents = parent.getComponentCount(); - for (int i = 0 ; i < ncomponents ; i++) { - Component comp = parent.getComponent(i); - if (comp.isVisible()) { - comp.setVisible(false); - break; - } - } - if (ncomponents > 0) { - currentCard = ncomponents - 1; - parent.getComponent(currentCard).setVisible(true); - parent.validate(); - } - } - } - - /** - * Flips to the component that was added to this layout with the - * specified <code>name</code>, using <code>addLayoutComponent</code>. - * If no such component exists, then nothing happens. - * @param parent the parent container in which to do the layout - * @param name the component name - * @see java.awt.CardLayout#addLayoutComponent(java.awt.Component, java.lang.Object) - */ - public void show(Container parent, Object constraint) { - synchronized (parent.getTreeLock()) { - checkLayout(parent); - Component next = null; - int ncomponents = vector.size(); - for (int i = 0; i < ncomponents; i++) { - Card card = (Card)vector.get(i); - if (card.constraint.equals(constraint)) { - next = card.comp; - currentCard = i; - break; - } - } - if ((next != null) && !next.isVisible()) { - ncomponents = parent.getComponentCount(); - for (int i = 0; i < ncomponents; i++) { - Component comp = parent.getComponent(i); - if (comp.isVisible()) { - comp.setVisible(false); - break; - } - } - next.setVisible(true); - parent.validate(); - } - } - } - - public Component getShowedComponent(Container parent){ - return parent.getComponent(currentCard); - } - - /** - * Make sure that the Container really has a CardLayout installed. - * Otherwise havoc can ensue! - */ - void checkLayout(Container parent) { - if (parent.getLayout() != this) { - throw new IllegalArgumentException("wrong parent for CardLayout"); - } - } - -} Modified: trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/JAXXTree.java =================================================================== --- trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/JAXXTree.java 2009-10-01 10:03:15 UTC (rev 1541) +++ trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/JAXXTree.java 2009-10-01 13:31:44 UTC (rev 1542) @@ -219,11 +219,24 @@ } public void setItems(List<Item> items) { + // Create model JAXXTreeModel model = new JAXXTreeModel(items); if (model.getRoot() != null) { setRootVisible(model.getRoot() != SYNTHETIC); } + // Atach model setModel(model); + + // Appli selected items + if (items != null){ + List<TreePath> treePathSelected = new ArrayList<TreePath>(); + for (Item i : items){ + if (i.isSelected()){ + treePathSelected.add(model.getTreePath(i)); + } + } + this.setSelectionPaths(convertToTreePathArray(treePathSelected.toArray())); + } } public Object getSelectionValue() { @@ -238,4 +251,9 @@ return null; } + protected TreePath[] convertToTreePathArray(Object[] datas){ + TreePath[] params = new TreePath[datas.length]; + System.arraycopy(datas, 0, params, 0, datas.length); + return params; + } } Modified: trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/navigation/ItemNavigationCardPanel.java =================================================================== --- trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/navigation/ItemNavigationCardPanel.java 2009-10-01 10:03:15 UTC (rev 1541) +++ trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/navigation/ItemNavigationCardPanel.java 2009-10-01 13:31:44 UTC (rev 1542) @@ -5,9 +5,9 @@ package jaxx.runtime.swing.navigation; +import java.awt.CardLayout; import java.awt.Component; import javax.swing.JPanel; -import jaxx.runtime.swing.CardLayout3; import jaxx.runtime.swing.Item; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -21,20 +21,46 @@ /** to use log facility, just put in your code: log.info(\"...\"); */ static private final Log log = LogFactory.getLog(ItemNavigationCardPanel.class); - CardLayout3 layout; + private static final long serialVersionUID = 1L; + + CardLayout layout; public ItemNavigationCardPanel(){ super(); - layout = new CardLayout3(); + + layout = new CardLayout(); setLayout(layout); } public void showItem(Item i){ if (i != null && i.getValue() != null){ - layout.show(this, i.getValue().getClass()); + if (i.getValue() instanceof Class){ + layout.show(this, i.getValue().getClass().getName()); + } + else { + layout.show(this, i.getValue().getClass().getName()); + } } } public Component getShowedComponent(){ - return layout.getShowedComponent(this); + Component[] components = getComponents(); + if (components != null){ + for (Component c : components){ + if (c.isVisible()){ + return c; + } + } + } + return null; } + + @Override + public Component add(Component comp) { + if (!(comp instanceof ItemNavigationPanel)){ + throw new IllegalArgumentException("ItemNavigationCardPanel must be have only ItemNavigationPanel children"); + } + super.add(comp, ((ItemNavigationPanel)comp).getAssociatedClass().getName()); + return comp; + } + } Added: trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/navigation/ItemNavigationPanel.java =================================================================== --- trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/navigation/ItemNavigationPanel.java (rev 0) +++ trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/navigation/ItemNavigationPanel.java 2009-10-01 13:31:44 UTC (rev 1542) @@ -0,0 +1,28 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package jaxx.runtime.swing.navigation; + +import javax.swing.JPanel; + +/** + * + * @author letellier + */ +public class ItemNavigationPanel extends JPanel{ + + private static final long serialVersionUID = 1L; + + protected Class associatedClass = null; + + public ItemNavigationPanel(Class associatedClass) { + this.associatedClass = associatedClass; + } + + public Class getAssociatedClass() { + return associatedClass; + } + +}
participants (1)
-
sletellier@users.nuiton.org