myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lof...@apache.org
Subject svn commit: r923207 - in /myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago: component/AbstractUIFlowLayout.java component/RendererTypes.java taglib/component/FlowLayoutTagDeclaration.java
Date Mon, 15 Mar 2010 13:12:24 GMT
Author: lofwyr
Date: Mon Mar 15 13:12:23 2010
New Revision: 923207

URL: http://svn.apache.org/viewvc?rev=923207&view=rev
Log:
TOBAGO-859: Start setup for "Flow Layout"

Added:
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/AbstractUIFlowLayout.java
      - copied, changed from r918004, myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/AbstractUIGridLayout.java
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/FlowLayoutTagDeclaration.java
      - copied, changed from r918983, myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/GridLayoutTagDeclaration.java
Modified:
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/RendererTypes.java

Copied: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/AbstractUIFlowLayout.java
(from r918004, myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/AbstractUIGridLayout.java)
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/AbstractUIFlowLayout.java?p2=myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/AbstractUIFlowLayout.java&p1=myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/AbstractUIGridLayout.java&r1=918004&r2=923207&rev=923207&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/AbstractUIGridLayout.java
(original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/AbstractUIFlowLayout.java
Mon Mar 15 13:12:23 2010
@@ -17,297 +17,23 @@ package org.apache.myfaces.tobago.compon
  * limitations under the License.
  */
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.myfaces.tobago.internal.layout.Cell;
-import org.apache.myfaces.tobago.internal.layout.FactorList;
-import org.apache.myfaces.tobago.internal.layout.Grid;
-import org.apache.myfaces.tobago.internal.layout.Interval;
-import org.apache.myfaces.tobago.internal.layout.IntervalList;
-import org.apache.myfaces.tobago.internal.layout.LayoutUtils;
-import org.apache.myfaces.tobago.internal.layout.OriginCell;
-import org.apache.myfaces.tobago.layout.AutoLayoutToken;
-import org.apache.myfaces.tobago.layout.Display;
-import org.apache.myfaces.tobago.layout.LayoutComponent;
-import org.apache.myfaces.tobago.layout.LayoutContainer;
 import org.apache.myfaces.tobago.layout.LayoutManager;
-import org.apache.myfaces.tobago.layout.LayoutToken;
-import org.apache.myfaces.tobago.layout.LayoutTokens;
-import org.apache.myfaces.tobago.layout.Measure;
 import org.apache.myfaces.tobago.layout.Orientation;
-import org.apache.myfaces.tobago.layout.PixelLayoutToken;
-import org.apache.myfaces.tobago.layout.RelativeLayoutToken;
 
-import javax.faces.context.FacesContext;
-import java.util.Arrays;
-import java.util.List;
-
-public abstract class AbstractUIGridLayout extends UILayout implements LayoutManager, SupportsMarkup
{
-
-  private static final Log LOG = LogFactory.getLog(AbstractUIGridLayout.class);
-
-  private Grid grid;
+public abstract class AbstractUIFlowLayout extends UILayout implements LayoutManager, SupportsMarkup
{
 
   public void init() {
-    grid = new Grid(LayoutTokens.parse(getColumns()), LayoutTokens.parse(getRows()));
-
-    List<LayoutComponent> components = getLayoutContainer().getComponents();
-    for (LayoutComponent component : components) {
-      component.setCurrentHeight(null);
-      component.setCurrentWidth(null);
-      grid.add(new OriginCell(component), component.getColumnSpan(), component.getRowSpan());
-      if (LOG.isDebugEnabled()) {
-        LOG.debug("\n" + grid);
-      }
-      if (component instanceof LayoutContainer) {
-        ((LayoutContainer) component).getLayoutManager().init();
-      }
-    }
   }
 
   public void fixRelativeInsideAuto(Orientation orientation, boolean auto) {
-
-    LayoutTokens tokens = grid.getTokens(orientation);
-
-    if (auto) {
-      for (int i = 0; i < tokens.getSize(); i++) {
-        if (tokens.get(i) instanceof RelativeLayoutToken) {
-          LOG.warn("Fixing layout token from * to auto, because a * in not allowed inside
of a auto. "
-              + "For more information please use the debug logging level.");
-          if (LOG.isDebugEnabled()) {
-            LOG.debug("Token * at index=" + i + ", orientation=" + orientation + ", grid=\n"
+ grid);
-          }
-          tokens.set(i, AutoLayoutToken.INSTANCE);
-        }
-      }
-    }
-
-    for (int i = 0; i < tokens.getSize(); i++) {
-      for (int j = 0; j < grid.getTokens(orientation.other()).getSize(); j++) {
-        Cell cell = grid.getCell(i, j, orientation);
-        if (cell instanceof OriginCell) {
-          OriginCell origin = (OriginCell) cell;
-          LayoutComponent component = cell.getComponent();
-          if (component instanceof LayoutContainer) {
-            LayoutManager layoutManager = ((LayoutContainer) component).getLayoutManager();
-            // TODO: may be improved
-            boolean childAuto = origin.getSpan(orientation) == 1 && tokens.get(i)
instanceof AutoLayoutToken;
-            layoutManager.fixRelativeInsideAuto(orientation, childAuto);
-          }
-        }
-      }
-    }
   }
 
   public void preProcessing(Orientation orientation) {
-
-    // process auto tokens
-    int i = 0;
-    for (LayoutToken token : grid.getTokens(orientation)) {
-
-      if (token instanceof PixelLayoutToken) {
-        int pixel = ((PixelLayoutToken) token).getPixel();
-        grid.getSizes(orientation)[i] = Measure.valueOf(pixel); // XXX refactor
-      }
-
-      IntervalList intervals = new IntervalList();
-      for (int j = 0; j < grid.getTokens(orientation.other()).getSize(); j++) {
-        Cell cell = grid.getCell(i, j, orientation);
-        if (cell instanceof OriginCell) {
-          OriginCell origin = (OriginCell) cell;
-          LayoutComponent component = cell.getComponent();
-
-          if (component instanceof LayoutContainer) {
-            ((LayoutContainer) component).getLayoutManager().preProcessing(orientation);
-          }
-
-          if (token instanceof AutoLayoutToken) {
-            if (origin.getSpan(orientation) == 1) {
-              intervals.add(new Interval(component, orientation));
-            } else {
-              LOG.info("ignored"); // todo
-            }
-          }
-        }
-      }
-      if (intervals.size() >= 1) {
-        Measure auto = intervals.computeAuto();
-        grid.getSizes(orientation)[i] = auto;
-      }
-// todo: what when we cannot find a good value for "auto"?
-      i++;
-    }
-
-    // set the size if all sizes of the grid are set
-    Measure size = Measure.ZERO;
-    Measure[] sizes = grid.getSizes(orientation);
-    for (int j = 0; j < sizes.length; j++) {
-      if (sizes[j] == null) {
-        size = null; // set to invalid
-        break;
-      }
-      size = size.add(sizes[j]);
-      if (j < sizes.length - 1) {
-        size = size.add(getSpacing(orientation));
-      }
-    }
-    if (size != null) {
-      size = size.add(LayoutUtils.getBeginOffset(orientation, getLayoutContainer()));
-      size = size.add(LayoutUtils.getEndOffset(orientation, getLayoutContainer()));
-      LayoutUtils.setCurrentSize(orientation, getLayoutContainer(), size);
-    }
   }
 
   public void mainProcessing(Orientation orientation) {
-
-    // find *
-    FactorList list = new FactorList();
-    for (LayoutToken token : grid.getTokens(orientation)) {
-      if (token instanceof RelativeLayoutToken) {
-        list.add(((RelativeLayoutToken) token).getFactor());
-      }
-    }
-    if (!list.isEmpty()) {
-      // find rest
-      LayoutContainer container = getLayoutContainer();
-      Measure available = LayoutUtils.getCurrentSize(orientation, container);
-      if (available != null) {
-        for (Measure value : grid.getSizes(orientation)) {
-          available = available.subtractNotNegative(value);
-        }
-        Measure spacing = getSpacing(orientation).multiply(grid.getSizes(orientation).length
- 1);
-        available = available.subtractNotNegative(spacing);
-
-        available = available.subtractNotNegative(LayoutUtils.getBeginOffset(orientation,
container));
-        available = available.subtractNotNegative(LayoutUtils.getEndOffset(orientation, container));
-
-        List<Measure> partition = list.partition(available);
-
-        // write values back into the header
-        int i = 0;
-        int j = 0;
-        for (LayoutToken token : grid.getTokens(orientation)) {
-          if (token instanceof RelativeLayoutToken) {
-            grid.getSizes(orientation)[i] = partition.get(j);
-            j++;
-          }
-          i++;
-        }
-      } else {
-        LOG.warn("No width/height set but needed for *!"); // todo: more information
-      }
-    }
-
-    // call manage sizes for all sub-layout-managers
-    for (int i = 0; i < grid.getTokens(orientation).getSize(); i++) {
-      for (int j = 0; j < grid.getTokens(orientation.other()).getSize(); j++) {
-        Cell cell = grid.getCell(i, j, orientation);
-        if (cell instanceof OriginCell) {
-          LayoutComponent component = cell.getComponent();
-
-          component.setDisplay(Display.BLOCK); // TODO: use CSS via classes and style.css
-
-          Integer span = ((OriginCell) cell).getSpan(orientation);
-          Measure[] pixelMeasures = grid.getSizes(orientation);
-
-          // compute the size of the cell
-          Measure size = pixelMeasures[i];
-          if (size != null) {
-            for (int k = 1; k < span; k++) {
-              size = size.add(pixelMeasures[i + k]);
-              size = size.add(getSpacing(orientation));
-            }
-            LayoutUtils.setCurrentSize(orientation, component, size);
-          } else {
-            LOG.warn("Size is null, should be debugged... i=" + i + " grid=" + grid, new
RuntimeException());
-          }
-
-          // call sub layout manager
-          if (component instanceof LayoutContainer) {
-            ((LayoutContainer) component).getLayoutManager().mainProcessing(orientation);
-          }
-        }
-      }
-    }
   }
 
   public void postProcessing(Orientation orientation) {
-
-    // call manage sizes for all sub-layout-managers
-    for (int i = 0; i < grid.getTokens(orientation).getSize(); i++) {
-      for (int j = 0; j < grid.getTokens(orientation.other()).getSize(); j++) {
-        Cell cell = grid.getCell(i, j, orientation);
-        if (cell instanceof OriginCell) {
-          LayoutComponent component = cell.getComponent();
-
-          component.setDisplay(Display.BLOCK); // TODO: use CSS via classes and style.css
-
-          Measure[] pixelMeasures = grid.getSizes(orientation);
-
-          // compute the position of the cell
-          Measure position = LayoutUtils.getBeginOffset(orientation, getLayoutContainer());
-          for (int k = 0; k < i; k++) {
-            if (pixelMeasures[k] == null) {
-              LOG.warn("Measure is null, should be debugged... i=" + i + " k=" + k + " grid="
+ grid,
-                  new RuntimeException());
-            } else {
-              position = position.add(pixelMeasures[k]);
-            }
-            position = position.add(getSpacing(orientation));
-          }
-          if (orientation == Orientation.HORIZONTAL) {
-            component.setLeft(position);
-          } else {
-            component.setTop(position);
-          }
-
-          // call sub layout manager
-          if (component instanceof LayoutContainer) {
-            ((LayoutContainer) component).getLayoutManager().postProcessing(orientation);
-          }
-
-          // todo: optimize: the AutoLayoutTokens with columnSpan=1 are already called
-        }
-      }
-    }
-  }
-
-  private LayoutContainer getLayoutContainer() {
-    // todo: check with instanceof and do something in the error case
-    return ((LayoutContainer) getParent());
-  }
-
-  protected Grid getGrid() {
-    return grid;
-  }
-
-  public Measure getSpacing(Orientation orientation) {
-    return orientation == Orientation.HORIZONTAL ? getColumnSpacing() : getRowSpacing();
-  }
-
-  public abstract String getRows();
-
-  public abstract String getColumns();
-
-  @Deprecated
-  public abstract Measure getCellspacing();
-
-  public abstract Measure getRowSpacing();
-
-  public abstract Measure getColumnSpacing();
-
-  @Override
-  public boolean getRendersChildren() {
-    return false;
-  }
-
-  @Override
-  public String toString() {
-    return getClass().getSimpleName()
-        + "#"
-        + getClientId(FacesContext.getCurrentInstance())
-        + (grid != null
-        ? "(" + Arrays.toString(grid.getWidths()) + ", " + Arrays.toString(grid.getHeights())
+ ")"
-        : "");
   }
 }

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/RendererTypes.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/RendererTypes.java?rev=923207&r1=923206&r2=923207&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/RendererTypes.java
(original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/RendererTypes.java
Mon Mar 15 13:12:23 2010
@@ -31,8 +31,8 @@ public final class RendererTypes {
   public static final String COMMAND = "Command";
   public static final String DATE = "Date";
   public static final String DATE_PICKER = "DatePicker";
-  public static final String DEFAULT_LAYOUT = "DefaultLayout";
   public static final String FILE = "File";
+  public static final String FLOW_LAYOUT = "FlowLayout";
   public static final String FORM = "Form";
   public static final String GRID_LAYOUT = "GridLayout";
   public static final String HIDDEN = "Hidden";
@@ -76,7 +76,6 @@ public final class RendererTypes {
   public static final String TREE_MENU = "TreeMenu";
   public static final String TREE_NODE = "TreeNode";
   public static final String SHEET = "Sheet";
-  public static final String VERBATIM = "Verbatim";
   public static final String WIZARD = "Wizard";
 
   private RendererTypes() {

Copied: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/FlowLayoutTagDeclaration.java
(from r918983, myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/GridLayoutTagDeclaration.java)
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/FlowLayoutTagDeclaration.java?p2=myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/FlowLayoutTagDeclaration.java&p1=myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/GridLayoutTagDeclaration.java&r1=918983&r2=923207&rev=923207&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/GridLayoutTagDeclaration.java
(original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/FlowLayoutTagDeclaration.java
Mon Mar 15 13:12:23 2010
@@ -23,78 +23,23 @@ import org.apache.myfaces.tobago.apt.ann
 import org.apache.myfaces.tobago.component.RendererTypes;
 import org.apache.myfaces.tobago.taglib.decl.HasBinding;
 import org.apache.myfaces.tobago.taglib.decl.HasBorder;
-import org.apache.myfaces.tobago.taglib.decl.HasColumnLayout;
 import org.apache.myfaces.tobago.taglib.decl.HasId;
 import org.apache.myfaces.tobago.taglib.decl.HasMargin;
 import org.apache.myfaces.tobago.taglib.decl.HasMargins;
 import org.apache.myfaces.tobago.taglib.decl.HasMarkup;
-import org.apache.myfaces.tobago.taglib.decl.HasRowLayout;
 import org.apache.myfaces.tobago.taglib.decl.HasSpacing;
 
 /**
- * Renders a GridLayout.
- * <pre>
- * columns/rows ::= LAYOUT
- * LAYOUT       ::= TOKEN [";" TOKEN]+
- * TOKEN        ::= FIXED | PIXEL | PROPORTIONAL
- * FIXED        ::= "fixed"
- * PIXEL        ::= NUMBER "px"
- * PROPORTIONAL ::= [NUMBER] "*"
- * </pre>
- * <p/>
- * <table border="1">
- * <tr>
- * <th>Parent</th>
- * <th>Child</th>
- * <th>Okay?</th>
- * <th>Remarks</th>
- * </tr>
- * <tr>
- * <td>FIXED</td>
- * <td>any combination of FIXED or PIXEL but no PROPORTIONAL</td>
- * <td>okay</td>
- * <td>-</td>
- * </tr>
- * <tr>
- * <td>FIXED</td>
- * <td>any combination with at least one PROPORTIONAL</td>
- * <td>wrong</td>
- * <td>LayoutManager cannot compute the fixed value.</td>
- * </tr>
- * <tr>
- * <td>PIXEL</td>
- * <td>any combination of FIXED or PIXEL but no PROPORTIONAL</td>
- * <td>potentially wrong</td>
- * <td>The values depend on each other, the programmer has to keep consistency manually.</td>
- * </tr>
- * <tr>
- * <td>PIXEL</td>
- * <td>any combination with at least one PROPORTIONAL</td>
- * <td>okay</td>
- * <td>-</td>
- * </tr>
- * <tr>
- * <td>PROPORTIONAL</td>
- * <td>any combination of FIXED or PIXEL but no PROPORTIONAL</td>
- * <td>potentially wrong</td>
- * <td>No automatic matching:<ul><li>too little space: scroll bar</li>
- * <li>too much space: elements will be spread.</li></ul></td>
- * </tr>
- * <tr>
- * <td>PROPORTIONAL</td>
- * <td>any combination with at least one PROPORTIONAL</td>
- * <td>okay</td>
- * <td>-</td>
- * </tr>
- * </table>
+ * XXX Warning: Still in progress! Please do not use it until other announcement.
+ * Renders a FlowLayout that positions the content components in there natural order.
  */
-@Tag(name = "gridLayout", bodyContent = BodyContent.EMPTY)
+@Tag(name = "flowLayout", bodyContent = BodyContent.EMPTY)
 @UIComponentTag(
-    uiComponent = "org.apache.myfaces.tobago.component.UIGridLayout",
-    uiComponentBaseClass = "org.apache.myfaces.tobago.component.AbstractUIGridLayout",
-    rendererType = RendererTypes.GRID_LAYOUT,
-    componentFamily = "org.apache.myfaces.tobago.GridLayout",
+    uiComponent = "org.apache.myfaces.tobago.component.UIFlowLayout",
+    uiComponentBaseClass = "org.apache.myfaces.tobago.component.AbstractUIFlowLayout",
+    rendererType = RendererTypes.FLOW_LAYOUT,
+    componentFamily = "org.apache.myfaces.tobago.FlowLayout",
     allowedChildComponenents = "NONE", isLayout = true)
-public interface GridLayoutTagDeclaration extends HasId, HasBorder, HasSpacing, HasMargin,
-    HasMargins, HasColumnLayout, HasRowLayout, HasBinding, HasMarkup {
-}
+public interface FlowLayoutTagDeclaration extends HasId, HasBorder, HasSpacing, HasMargin,
+    HasMargins, HasBinding, HasMarkup {
+}
\ No newline at end of file



Mime
View raw message