View Javadoc
1   /**
2    * This file Copyright (c) 2015-2018 Magnolia International
3    * Ltd.  (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10   * This file is distributed in the hope that it will be
11   * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12   * implied warranty of MERCHANTABILITY or FITNESS FOR A
13   * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14   * Redistribution, except as permitted by whichever of the GPL
15   * or MNA you select, is prohibited.
16   *
17   * 1. For the GPL license (GPL), you can redistribute and/or
18   * modify this file under the terms of the GNU General
19   * Public License, Version 3, as published by the Free Software
20   * Foundation.  You should have received a copy of the GNU
21   * General Public License, Version 3 along with this program;
22   * if not, write to the Free Software Foundation, Inc., 51
23   * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24   *
25   * 2. For the Magnolia Network Agreement (MNA), this file
26   * and the accompanying materials are made available under the
27   * terms of the MNA which accompanies this distribution, and
28   * is available at http://www.magnolia-cms.com/mna.html
29   *
30   * Any modifications to this file must keep this entire header
31   * intact.
32   *
33   */
34  package info.magnolia.ui.vaadin.gwt.client.layout.lazylayout.widget;
35  
36  import com.google.gwt.dom.client.DivElement;
37  import com.google.gwt.dom.client.Element;
38  import com.google.gwt.dom.client.ImageElement;
39  import com.google.gwt.dom.client.SpanElement;
40  import com.google.gwt.dom.client.Style;
41  import com.google.gwt.user.client.DOM;
42  
43  /**
44   * Sub implementaton of {@link EscalatorPanel} for thumbnails, aka the legacy 5.x UI.
45   *
46   * @deprecated since 6.0, will be removed with 5.x UI.
47   */
48  @Deprecated
49  public class EscalatorThumbnailsPanel extends EscalatorPanel {
50  
51     private static Flyweight flyweight = new Flyweight() {
52  
53         static final String ICON_STYLE_NAME = "icon";
54         static final String THUMBNAIL_STYLE_NAME = "thumbnail";
55         static final String THUMBNAIL_IMAGE_STYLE_NAME = "thumbnail-image";
56         public static final String CLEARED_STYLE_NAME = "cleared";
57  
58         @Override
59         Element createThumbnail() {
60             final DivElement thumbnail = DivElement.as(DOM.createDiv());
61             thumbnail.addClassName(THUMBNAIL_STYLE_NAME);
62  
63             final SpanElement iconFontEl = SpanElement.as(DOM.createSpan());
64             iconFontEl.addClassName(ICON_STYLE_NAME);
65             Style style = iconFontEl.getStyle();
66             style.setDisplay(Style.Display.NONE);
67             style.setFontSize(24, Style.Unit.PX);
68             style.setLineHeight(1, Style.Unit.PX);
69  
70             final ImageElement image = ImageElement.as(DOM.createImg());
71             image.addClassName(THUMBNAIL_IMAGE_STYLE_NAME);
72             image.getStyle().setDisplay(Style.Display.NONE);
73  
74             thumbnail.appendChild(image);
75             thumbnail.appendChild(iconFontEl);
76  
77             return thumbnail;
78         }
79  
80         @Override
81         void setImageSrc(String src, Element thumbnail) {
82             final Element img = getImage(thumbnail);
83             final Element icon = getIcon(thumbnail);
84  
85             img.getStyle().setDisplay(Style.Display.INLINE_BLOCK);
86             icon.getStyle().setDisplay(Style.Display.NONE);
87  
88             img.setAttribute("src", src);
89             thumbnail.removeClassName(CLEARED_STYLE_NAME);
90         }
91  
92         @Override
93         void setIconFontStyle(String style, Element thumbnail) {
94             final Element img = getImage(thumbnail);
95             final Element icon = getIcon(thumbnail);
96  
97             img.getStyle().setDisplay(Style.Display.NONE);
98             icon.getStyle().setDisplay(Style.Display.INLINE_BLOCK);
99  
100            icon.setClassName(ICON_STYLE_NAME);
101            icon.addClassName(style);
102            thumbnail.removeClassName(CLEARED_STYLE_NAME);
103        }
104 
105        Element getIcon(Element thumbnail) {
106            return Element.as(thumbnail.getChild(1));
107        }
108 
109        @Override
110        Element getImage(Element thumbnail) {
111            return Element.as(thumbnail.getChild(0));
112        }
113 
114        @Override
115        public void clear(Element thumbnail) {
116            Element icon = getIcon(thumbnail);
117            icon.setClassName(ICON_STYLE_NAME);
118            icon.getStyle().setDisplay(Style.Display.NONE);
119 
120            Element image = getImage(thumbnail);
121            image.removeAttribute("src");
122            image.getStyle().setDisplay(Style.Display.NONE);
123 
124            thumbnail.addClassName(CLEARED_STYLE_NAME);
125        }
126 
127        @Override
128        void setCaption(String newCaption, Element thumbnail) {
129            // no-op
130        }
131    };
132 
133    public EscalatorThumbnailsPanel(Listener listener) {
134        super(listener, flyweight);
135    }
136 }