You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by hn...@apache.org on 2022/05/17 11:58:48 UTC

[myfaces-tobago] branch tobago-5.x updated: refactor(segmentLayout): xxl

This is an automated email from the ASF dual-hosted git repository.

hnoeth pushed a commit to branch tobago-5.x
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git


The following commit(s) were added to refs/heads/tobago-5.x by this push:
     new 3f1e523c1d refactor(segmentLayout): xxl
3f1e523c1d is described below

commit 3f1e523c1d186caca38d3ec715c4a42875e55120
Author: Henning Noeth <hn...@apache.org>
AuthorDate: Tue May 17 09:50:13 2022 +0200

    refactor(segmentLayout): xxl
    
    * better attribute name
    * BootstrapClass.Generator: avoid arrays
---
 .../myfaces/tobago/component/Attributes.java       | 10 ++---
 .../tobago/component/SupportsSegmentLayout.java    | 51 ++++++++++++++++++++++
 .../component/AbstractUISegmentLayout.java         | 35 ++-------------
 .../renderkit/renderer/SegmentLayoutRenderer.java  | 19 +-------
 .../component/SegmentLayoutTagDeclaration.java     |  4 +-
 .../tobago/renderkit/css/BootstrapClass.java       | 51 ++++++++++------------
 .../120-layout/30-segment/Segment_Layout.xhtml     | 16 +++----
 .../renderkit/css/BootstrapClassUnitTest.java      |  4 +-
 8 files changed, 96 insertions(+), 94 deletions(-)

diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Attributes.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Attributes.java
index 66757a478d..4fb4e26119 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Attributes.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Attributes.java
@@ -100,7 +100,7 @@ public enum Attributes {
   expanded,
   execute,
   event,
-  extraExtraLarge,
+  extra2Large,
   extraLarge,
   extraSmall,
   fieldId,
@@ -166,7 +166,7 @@ public enum Attributes {
   /**
    * Used by a layout manager
    */
-  marginExtraExtraLarge,
+  marginExtra2Large,
   /**
    * Used by a layout manager
    */
@@ -229,7 +229,7 @@ public enum Attributes {
   /**
    * Used by a layout manager
    */
-  offsetExtraExtraLarge,
+  offsetExtra2Large,
   /**
    * Used by a layout manager
    */
@@ -253,7 +253,7 @@ public enum Attributes {
   /**
    * Used by a layout manager
    */
-  overwriteExtraExtraLarge,
+  overwriteExtra2Large,
   /**
    * Used by a layout manager
    */
@@ -269,7 +269,7 @@ public enum Attributes {
   /**
    * Used by a layout manager
    */
-  overwriteMarginExtraExtraLarge,
+  overwriteMarginExtra2Large,
   /**
    * Used by a layout manager
    */
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/component/SupportsSegmentLayout.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/component/SupportsSegmentLayout.java
new file mode 100644
index 0000000000..cb96f9071c
--- /dev/null
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/component/SupportsSegmentLayout.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.myfaces.tobago.component;
+
+import org.apache.myfaces.tobago.layout.MeasureList;
+import org.apache.myfaces.tobago.layout.SegmentJustify;
+
+public interface SupportsSegmentLayout {
+  MeasureList getExtraSmall();
+
+  MeasureList getSmall();
+
+  MeasureList getMedium();
+
+  MeasureList getLarge();
+
+  MeasureList getExtraLarge();
+
+  MeasureList getExtra2Large();
+
+  String getMarginExtraSmall();
+
+  String getMarginSmall();
+
+  String getMarginMedium();
+
+  String getMarginLarge();
+
+  String getMarginExtraLarge();
+
+  String getMarginExtra2Large();
+
+  SegmentJustify getJustify();
+}
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUISegmentLayout.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUISegmentLayout.java
index d338af3b6b..1f6c29e5e3 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUISegmentLayout.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUISegmentLayout.java
@@ -19,15 +19,14 @@
 
 package org.apache.myfaces.tobago.internal.component;
 
-import org.apache.myfaces.tobago.layout.MeasureList;
-import org.apache.myfaces.tobago.layout.SegmentJustify;
+import org.apache.myfaces.tobago.component.SupportsSegmentLayout;
 
 /**
  * {@link org.apache.myfaces.tobago.internal.taglib.component.SegmentLayoutTagDeclaration}
  *
  * @since 3.0.0
  */
-public abstract class AbstractUISegmentLayout extends AbstractUILayoutBase {
+public abstract class AbstractUISegmentLayout extends AbstractUILayoutBase implements SupportsSegmentLayout {
 
   public static final String COMPONENT_FAMILY = "org.apache.myfaces.tobago.SegmentLayout";
 
@@ -54,36 +53,10 @@ public abstract class AbstractUISegmentLayout extends AbstractUILayoutBase {
       builder.append("\n        extraLarge=");
       builder.append(getExtraLarge());
     }
-    if (getExtraExtraLarge() != null) {
-      builder.append("\n        extraExtraLarge=");
+    if (getExtra2Large() != null) {
+      builder.append("\n        extra2Large=");
       builder.append(getExtraLarge());
     }
     return builder.toString();
   }
-
-  public abstract MeasureList getExtraSmall();
-
-  public abstract MeasureList getSmall();
-
-  public abstract MeasureList getMedium();
-
-  public abstract MeasureList getLarge();
-
-  public abstract MeasureList getExtraLarge();
-
-  public abstract MeasureList getExtraExtraLarge();
-
-  public abstract String getMarginExtraSmall();
-
-  public abstract String getMarginSmall();
-
-  public abstract String getMarginMedium();
-
-  public abstract String getMarginLarge();
-
-  public abstract String getMarginExtraLarge();
-
-  public abstract String getMarginExtraExtraLarge();
-
-  public abstract SegmentJustify getJustify();
 }
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/SegmentLayoutRenderer.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/SegmentLayoutRenderer.java
index 64baab5e82..89917b5093 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/SegmentLayoutRenderer.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/SegmentLayoutRenderer.java
@@ -23,8 +23,6 @@ import org.apache.myfaces.tobago.component.LabelLayout;
 import org.apache.myfaces.tobago.component.SupportsLabelLayout;
 import org.apache.myfaces.tobago.context.Markup;
 import org.apache.myfaces.tobago.internal.component.AbstractUISegmentLayout;
-import org.apache.myfaces.tobago.layout.MarginTokens;
-import org.apache.myfaces.tobago.layout.MeasureList;
 import org.apache.myfaces.tobago.layout.SegmentJustify;
 import org.apache.myfaces.tobago.renderkit.RendererBase;
 import org.apache.myfaces.tobago.renderkit.css.BootstrapClass;
@@ -74,22 +72,7 @@ public class SegmentLayoutRenderer<T extends AbstractUISegmentLayout> extends Re
     }
 
     final List<UIComponent> children = ComponentUtils.findLayoutChildren(component);
-    MeasureList[] measureLists = {
-      component.getExtraSmall(),
-      component.getSmall(),
-      component.getMedium(),
-      component.getLarge(),
-      component.getExtraLarge(),
-      component.getExtraExtraLarge()};
-    MarginTokens[] marginTokens = {
-      MarginTokens.parse(component.getMarginExtraSmall()),
-      MarginTokens.parse(component.getMarginSmall()),
-      MarginTokens.parse(component.getMarginMedium()),
-      MarginTokens.parse(component.getMarginLarge()),
-      MarginTokens.parse(component.getMarginExtraLarge()),
-      MarginTokens.parse(component.getMarginExtraExtraLarge())
-    };
-    final BootstrapClass.Generator generator = new BootstrapClass.Generator(measureLists, marginTokens);
+    final BootstrapClass.Generator generator = new BootstrapClass.Generator(component);
     for (final UIComponent child : children) {
       if (child.isRendered()) {
         encodeChild(facesContext, writer, generator, child);
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/SegmentLayoutTagDeclaration.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/SegmentLayoutTagDeclaration.java
index f422c9f576..7a20c89c21 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/SegmentLayoutTagDeclaration.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/SegmentLayoutTagDeclaration.java
@@ -107,7 +107,7 @@ public interface SegmentLayoutTagDeclaration extends HasIdBindingAndRendered, Is
    */
   @TagAttribute
   @UIComponentTagAttribute(type = "org.apache.myfaces.tobago.layout.SegmentMeasureList")
-  void setExtraExtraLarge(String extraLarge);
+  void setExtra2Large(String extraLarge);
 
   /**
    * The space separated definition of the column margins for extra small devices.
@@ -161,7 +161,7 @@ public interface SegmentLayoutTagDeclaration extends HasIdBindingAndRendered, Is
    */
   @TagAttribute
   @UIComponentTagAttribute
-  void setMarginExtraExtraLarge(String marginExtraExtraLarge);
+  void setMarginExtra2Large(String marginExtra2Large);
 
   /**
    * The horizontal alignment of the elements inside of the grid, possible values are:
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/css/BootstrapClass.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/css/BootstrapClass.java
index a836c24a78..f13912f42b 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/css/BootstrapClass.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/css/BootstrapClass.java
@@ -20,6 +20,7 @@
 package org.apache.myfaces.tobago.renderkit.css;
 
 import org.apache.myfaces.tobago.component.Attributes;
+import org.apache.myfaces.tobago.component.SupportsSegmentLayout;
 import org.apache.myfaces.tobago.context.Markup;
 import org.apache.myfaces.tobago.layout.AlignItems;
 import org.apache.myfaces.tobago.layout.JustifyContent;
@@ -804,35 +805,29 @@ public enum BootstrapClass implements CssItem {
     private final MeasureList medium;
     private final MeasureList large;
     private final MeasureList extraLarge;
-    private final MeasureList extraExtraLarge;
+    private final MeasureList extra2Large;
     private final MarginTokens marginExtraSmall;
     private final MarginTokens marginSmall;
     private final MarginTokens marginMedium;
     private final MarginTokens marginLarge;
     private final MarginTokens marginExtraLarge;
-    private final MarginTokens marginExtraExtraLarge;
+    private final MarginTokens marginExtra2Large;
 
     private int index = 0;
 
-    /**
-     * Generator to set segment layout CSS classes.
-     *
-     * @param measureLists from extraSmall to extraExtraLarge
-     * @param marginTokens from extraSmall to extraExtraLarge
-     */
-    public Generator(final MeasureList[] measureLists, final MarginTokens[] marginTokens) {
-      this.extraSmall = measureLists[0];
-      this.small = measureLists[1];
-      this.medium = measureLists[2];
-      this.large = measureLists[3];
-      this.extraLarge = measureLists[4];
-      this.extraExtraLarge = measureLists[5];
-      this.marginExtraSmall = marginTokens[0];
-      this.marginSmall = marginTokens[1];
-      this.marginMedium = marginTokens[2];
-      this.marginLarge = marginTokens[3];
-      this.marginExtraLarge = marginTokens[4];
-      this.marginExtraExtraLarge = marginTokens[5];
+    public Generator(final SupportsSegmentLayout component) {
+      this.extraSmall = component.getExtraSmall();
+      this.small = component.getSmall();
+      this.medium = component.getMedium();
+      this.large = component.getLarge();
+      this.extraLarge = component.getExtraLarge();
+      this.extra2Large = component.getExtra2Large();
+      this.marginExtraSmall = MarginTokens.parse(component.getMarginExtraSmall());
+      this.marginSmall = MarginTokens.parse(component.getMarginSmall());
+      this.marginMedium = MarginTokens.parse(component.getMarginMedium());
+      this.marginLarge = MarginTokens.parse(component.getMarginLarge());
+      this.marginExtraLarge = MarginTokens.parse(component.getMarginExtraLarge());
+      this.marginExtra2Large = MarginTokens.parse(component.getMarginExtra2Large());
     }
 
     public void reset() {
@@ -851,21 +846,21 @@ public enum BootstrapClass implements CssItem {
       generate(result, medium, attributes, Attributes.overwriteMedium);
       generate(result, large, attributes, Attributes.overwriteLarge);
       generate(result, extraLarge, attributes, Attributes.overwriteExtraLarge);
-      generate(result, extraExtraLarge, attributes, Attributes.overwriteExtraExtraLarge);
+      generate(result, extra2Large, attributes, Attributes.overwriteExtra2Large);
 
       generate(result, marginExtraSmall, attributes, Attributes.overwriteMarginExtraSmall);
       generate(result, marginSmall, attributes, Attributes.overwriteMarginSmall);
       generate(result, marginMedium, attributes, Attributes.overwriteMarginMedium);
       generate(result, marginLarge, attributes, Attributes.overwriteMarginLarge);
       generate(result, marginExtraLarge, attributes, Attributes.overwriteMarginExtraLarge);
-      generate(result, marginExtraExtraLarge, attributes, Attributes.overwriteMarginExtraExtraLarge);
+      generate(result, marginExtra2Large, attributes, Attributes.overwriteMarginExtra2Large);
 
       generateOffset(result, attributes.get(Attributes.offsetExtraSmall.name()), OFFSET_EXTRA_SMALL);
       generateOffset(result, attributes.get(Attributes.offsetSmall.name()), OFFSET_SMALL);
       generateOffset(result, attributes.get(Attributes.offsetMedium.name()), OFFSET_MEDIUM);
       generateOffset(result, attributes.get(Attributes.offsetLarge.name()), OFFSET_LARGE);
       generateOffset(result, attributes.get(Attributes.offsetExtraLarge.name()), OFFSET_EXTRA_LARGE);
-      generateOffset(result, attributes.get(Attributes.offsetExtraExtraLarge.name()), OFFSET_EXTRA_EXTRA_LARGE);
+      generateOffset(result, attributes.get(Attributes.offsetExtra2Large.name()), OFFSET_EXTRA_EXTRA_LARGE);
       return result.toArray(new BootstrapClass[0]);
     }
 
@@ -959,10 +954,10 @@ public enum BootstrapClass implements CssItem {
 
   private static String getSizeSuffix(final Attributes attribute) {
     switch (attribute) {
-      case extraExtraLarge:
-      case marginExtraExtraLarge:
-      case overwriteExtraExtraLarge:
-      case overwriteMarginExtraExtraLarge:
+      case extra2Large:
+      case marginExtra2Large:
+      case overwriteExtra2Large:
+      case overwriteMarginExtra2Large:
         return "_XXL";
       case extraLarge:
       case marginExtraLarge:
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/120-layout/30-segment/Segment_Layout.xhtml b/tobago-example/tobago-example-demo/src/main/webapp/content/120-layout/30-segment/Segment_Layout.xhtml
index caabdf855f..d0dae8d609 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/content/120-layout/30-segment/Segment_Layout.xhtml
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/120-layout/30-segment/Segment_Layout.xhtml
@@ -25,7 +25,7 @@
   <p>The segment layout is a grid with 12 columns.
     The number and the proportion of the columns can be set with the attributes
     <code>extraSmall</code>, <code>small</code>, <code>medium</code>, <code>large</code>, <code>extraLarge</code>
-    and <code>extraExtraLarge</code>.
+    and <code>extra2Large</code>.
     The value is a space separated list. Allowed are '1seg' to '12seg', 'auto' and '1fr'.</p>
   <tc:link label="Tag Library Documentation" image="#{request.contextPath}/image/feather-leaf.png"
            link="#{apiController.tldBase}/#{apiController.currentRelease}/tld/tc/segmentLayout.html"/>
@@ -82,16 +82,16 @@
   <tc:section label="Screen Size">
     <p>For the different kinds of screen sizes, the segment layout has the attributes:
       <code>extraSmall</code>, <code>small</code>, <code>medium</code>, <code>large</code>, <code>extraLarge</code>
-      and <code>extraExtraLarge</code>.</p>
+      and <code>extra2Large</code>.</p>
     <p>In the following example, all attributes are used. If you are on a desktop you can see the different
       behavior by changing the size of the browser window.</p>
     <demo-highlight
-      language="markup">&lt;tc:segmentLayout extraExtraLarge="1seg" extraLarge="2seg"
+      language="markup">&lt;tc:segmentLayout extra2Large="1seg" extraLarge="2seg"
       large="3seg" medium="4seg" small="5seg" extraSmall="6seg">
       ...
     </demo-highlight>
 
-    <tc:segmentLayout extraExtraLarge="1seg" extraLarge="2seg" large="3seg" medium="4seg" small="5seg"
+    <tc:segmentLayout extra2Large="1seg" extraLarge="2seg" large="3seg" medium="4seg" small="5seg"
                       extraSmall="6seg">
       <tc:in value="1"/>
       <tc:in value="2"/>
@@ -111,7 +111,7 @@
   <tc:section id="marginConcept" label="Margin">
     <p>A margin can be set for the different proportions with the attributes
       <code>marginExtraSmall</code>, <code>marginSmall</code>, <code>marginMedium</code>, <code>marginLarge</code>,
-      <code>marginExtraLarge</code> and <code>marginExtraExtraLarge</code>.</p>
+      <code>marginExtraLarge</code> and <code>marginExtra2Large</code>.</p>
     <p>Possible values are <code>none</code>, <code>left</code>, <code>right</code> and <code>both</code>.</p>
 
     <demo-highlight language="markup">&lt;tc:segmentLayout extraSmall="5seg 3seg"
@@ -132,7 +132,7 @@
     <p>An offset can be set for the different proportions with the
       <code class="language-markup">&lt;tc:segmentLayoutConstraint/></code> tag which can have the attributes
       <code>offsetExtraSmall</code>, <code>offsetSmall</code>,<code>offsetMedium</code>, <code>offsetLarge</code>,
-      <code>offsetExtraLarge</code> and <code>offsetExtraExtraLarge</code>.</p>
+      <code>offsetExtraLarge</code> and <code>offsetExtra2Large</code>.</p>
     <p>Possible values are from 1 to 11 for <code>offsetExtraSmall</code>.<br/>
       For the other attributes possible values are from 0 to 11.<br/>
       A <code>offsetMedium="0"</code> overwrite the offset from smaller proportions.</p>
@@ -168,9 +168,9 @@
     <p>The default layout and margins can be overwritten by the
       <code class="language-markup">&lt;tc:segmentLayoutConstraint/></code> tag.
       Possible attributes are <code>extraSmall</code>, <code>small</code>, <code>medium</code>, <code>large</code>,
-      <code>extraLarge</code> and <code>extraExtraLarge</code> for the layout.<br/>
+      <code>extraLarge</code> and <code>extra2Large</code> for the layout.<br/>
       And: <code>marginExtraSmall</code>, <code>marginSmall</code>, <code>marginMedium</code>, <code>marginLarge</code>,
-      <code>marginExtraLarge</code> and <code>marginExtraExtraLarge</code> for the margins.</p>
+      <code>marginExtraLarge</code> and <code>marginExtra2Large</code> for the margins.</p>
     <demo-highlight language="markup">&lt;tc:segmentLayout extraSmall="4seg 8seg">
       &lt;tc:in value="4"/>
       &lt;tc:in value="8"/>
diff --git a/tobago-theme/tobago-theme-standard/src/test/java/org/apache/myfaces/tobago/renderkit/css/BootstrapClassUnitTest.java b/tobago-theme/tobago-theme-standard/src/test/java/org/apache/myfaces/tobago/renderkit/css/BootstrapClassUnitTest.java
index 861fc8fbf5..bd29076241 100644
--- a/tobago-theme/tobago-theme-standard/src/test/java/org/apache/myfaces/tobago/renderkit/css/BootstrapClassUnitTest.java
+++ b/tobago-theme/tobago-theme-standard/src/test/java/org/apache/myfaces/tobago/renderkit/css/BootstrapClassUnitTest.java
@@ -102,8 +102,8 @@ public class BootstrapClassUnitTest {
     Assertions.assertEquals(BootstrapClass.COL_XL_AUTO,
         BootstrapClass.valueOf(Measure.valueOf("auto"), Attributes.extraLarge));
     Assertions.assertEquals(BootstrapClass.COL_XXL_5,
-      BootstrapClass.valueOf(new Measure("5", Measure.Unit.SEG), Attributes.extraExtraLarge));
+      BootstrapClass.valueOf(new Measure("5", Measure.Unit.SEG), Attributes.extra2Large));
     Assertions.assertEquals(BootstrapClass.COL_XXL_AUTO,
-      BootstrapClass.valueOf(Measure.valueOf("auto"), Attributes.extraExtraLarge));
+      BootstrapClass.valueOf(Measure.valueOf("auto"), Attributes.extra2Large));
   }
 }