RowUtil.java

  1. /*
  2.  * Copyright 2010-2025 James Pether Sörling
  3.  *
  4.  * Licensed under the Apache License, Version 2.0 (the "License");
  5.  * you may not use this file except in compliance with the License.
  6.  * You may obtain a copy of the License at
  7.  *
  8.  *   http://www.apache.org/licenses/LICENSE-2.0
  9.  *
  10.  * Unless required by applicable law or agreed to in writing, software
  11.  * distributed under the License is distributed on an "AS IS" BASIS,
  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.  * See the License for the specific language governing permissions and
  14.  * limitations under the License.
  15.  *
  16.  *  $Id$
  17.  *  $HeadURL$
  18. */
  19. package com.hack23.cia.web.impl.ui.application.views.common.rows;

  20. import com.hack23.cia.web.impl.ui.application.views.common.sizing.ContentRatio;
  21. import com.jarektoro.responsivelayout.ResponsiveLayout;
  22. import com.jarektoro.responsivelayout.ResponsiveRow;
  23. import com.vaadin.server.Responsive;
  24. import com.vaadin.server.Sizeable.Unit;
  25. import com.vaadin.ui.AbstractOrderedLayout;
  26. import com.vaadin.ui.Button;
  27. import com.vaadin.ui.Component;
  28. import com.vaadin.ui.CssLayout;
  29. import com.vaadin.ui.Label;

  30. /**
  31.  * The Class RowUtil.
  32.  */
  33. public final class RowUtil {

  34.     /** The Constant DISPLAY_SIZE_LG_DEVICE. */
  35.     private static final int DISPLAY_SIZE_LG_DEVICE = 4;

  36.     /** The Constant DISPLAY_SIZE_MD_DEVICE. */
  37.     private static final int DISPLAY_SIZE_MD_DEVICE = 4;

  38.     /** The Constant DISPLAY_SIZE_XS_DEVICE. */
  39.     private static final int DISPLAY_SIZE_XS_DEVICE = 12;

  40.     /** The Constant DISPLAYS_SIZE_XM_DEVICE. */
  41.     private static final int DISPLAYS_SIZE_XM_DEVICE = 6;

  42.     /** The Constant ITEMBOX. */
  43.     private static final String ITEMBOX = "itembox";

  44.     /** The Constant TITLE. */
  45.     private static final String TITLE = "title";

  46.     /**
  47.      * Default constructor for RowUtil.
  48.      */
  49.     public RowUtil() {
  50.         // Default constructor
  51.     }

  52.     /**
  53.      * Creates the grid layout.
  54.      *
  55.      * @param panelContent the panel content
  56.      * @return the responsive row
  57.      */
  58.     public static ResponsiveRow createGridLayout(final AbstractOrderedLayout panelContent) {
  59.         final ResponsiveLayout layout = new ResponsiveLayout();
  60.         Responsive.makeResponsive(layout);
  61.         layout.addStyleName("v-layout-content-overview-panel-level1");
  62.         layout.setWidth(100, Unit.PERCENTAGE);
  63.         layout.setHeight(100, Unit.PERCENTAGE);
  64.         panelContent.addComponent(layout);
  65.         panelContent.setExpandRatio(layout, ContentRatio.LARGE);
  66.         final ResponsiveRow row = layout.addRow();
  67.         row.setVerticalSpacing(true);
  68.         row.setHorizontalSpacing(true);
  69.         return row;
  70.     }

  71.     /**
  72.      * Creates the row component.
  73.      *
  74.      * @param row         the row
  75.      * @param component   the component
  76.      * @param description the description
  77.      */
  78.     public static void createRowComponent(final ResponsiveRow row, final Component component,
  79.             final String description) {
  80.         final CssLayout layout = new CssLayout();
  81.         layout.addStyleName(".v-layout-content-pagemode-panel-level2");
  82.         Responsive.makeResponsive(layout);
  83.         layout.setSizeUndefined();

  84.         final Label descriptionLabel = new Label(description);
  85.         descriptionLabel.addStyleName(ITEMBOX);
  86.         Responsive.makeResponsive(descriptionLabel);
  87.         descriptionLabel.setWidth(100, Unit.PERCENTAGE);
  88.         layout.addComponent(descriptionLabel);

  89.         component.addStyleName(ITEMBOX);
  90.         component.addStyleName(TITLE);
  91.         Responsive.makeResponsive(component);
  92.         component.setWidth(100, Unit.PERCENTAGE);
  93.         layout.addComponent(component);

  94.         row.addColumn().withDisplayRules(DISPLAY_SIZE_XS_DEVICE, DISPLAYS_SIZE_XM_DEVICE, DISPLAY_SIZE_MD_DEVICE,
  95.                 DISPLAY_SIZE_LG_DEVICE).withComponent(layout);
  96.     }

  97.     /**
  98.      * Creates the row item.
  99.      *
  100.      * @param row         the row
  101.      * @param button      the button
  102.      * @param description the description
  103.      */
  104.     public static void createRowItem(final ResponsiveRow row, final Button button, final String description) {
  105.         final CssLayout layout = new CssLayout();
  106.         layout.addStyleName("v-layout-content-overview-panel-level2");
  107.         Responsive.makeResponsive(layout);
  108.         layout.setSizeUndefined();

  109.         button.addStyleName(ITEMBOX);
  110.         button.addStyleName(TITLE);
  111.         Responsive.makeResponsive(button);
  112.         button.setWidth(100, Unit.PERCENTAGE);
  113.         layout.addComponent(button);

  114.         final Label descriptionLabel = new Label(description);
  115.         descriptionLabel.addStyleName(ITEMBOX);
  116.         Responsive.makeResponsive(descriptionLabel);
  117.         descriptionLabel.setWidth(100, Unit.PERCENTAGE);
  118.         layout.addComponent(descriptionLabel);

  119.         row.addColumn().withDisplayRules(DISPLAY_SIZE_XS_DEVICE, DISPLAYS_SIZE_XM_DEVICE, DISPLAY_SIZE_MD_DEVICE,
  120.                 DISPLAY_SIZE_LG_DEVICE).withComponent(layout);
  121.     }

  122. }