You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

преди 6 години
преди 6 години
Font icon support (#13152) Renamed Icon to ImageIcon Change-Id: I608815f17a3651b205fed81b5294385df0d68802 Extracted the abstract client-side Icon class Change-Id: Ic32e270595a5796d0bbd1dd31f34282b56672aa9 Created the FontIcon class Change-Id: Iad13871e7bf1807dee2c538c76306d4620191f5e Renamed AbstractComponentConnector.getIcon to getIconUri Change-Id: I6953ab79661993b561655d483c1bd013b66407f3 Added the AbstractComponentConnector.getIcon method Change-Id: I6fb91dc643fb09da3ba53666b1a8a289901702e3 Refactored getIcon Change-Id: Ibae39e66d0fb8449e20ac5209eb8c18b6ada4387 Made all existing uses of Icon compatible with FontIcons Change-Id: I8f28ec5254f2e5282a887519d3f44bc1e27aba72 Initial server-side support for font icons - does not include an actual icon set yet (#13152) Change-Id: Ie6c09b17dd577c726e0efc13567749f6f4d56d8d Changed server side FontIcon URI generation to match the correct scheme Change-Id: I3628b930b310b3f285bc58a3f471e31e641d307e Initial server-side icon font (FontAwesome) with scss - to be considered placeholder for testing (#13152) Change-Id: I361e62aba0d943a736471824e149d65c7eea9c76 Changed the FontIcon URI scheme Change-Id: I15c92f6bb3d0aa0a800f3f0bfa80419979453e17 Added FontIcon support to AbstractOrderedLayoutConnector Change-Id: I3b2b45b22d29622fd888dbe922aa0cc8a718104d Added FontIcon support to table items Change-Id: Id22ce94c96a892420aab1e39663688fc9f3bc282 Added FontIcon support to OptionGroup items Change-Id: Ie08bef688f6802182ef5f8b2bf82cf8b1f9096bb Switched to openly use FontAwesome (#13152) Change-Id: I18c3325ce93915b7fd6e338c8c293a89711277bc VaadinIcons are now FontAwesome (#13152) Change-Id: I0ab2a80735cbf08b6e33d358e3e8c6a205626fc4 VCaption does not longer set icon to 0x0px if it's a FontIcon (#13152) Change-Id: Ibcd96e0f79f0adf2e217a8580d17f1cc93705710 Fixed typo in @font-face, removed .otf (#13152) Change-Id: I698ca32c560e5f198c32a6c44f7884d3030ee610 Make font icons behave more like img (display:inline-block) (#13152) Change-Id: Ic79186c90f1fc566deae1f4d8d4ba2c21d89a42e
преди 10 години
преди 6 години
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. * Copyright 2000-2018 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * 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, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.client.ui;
  17. import com.google.gwt.dom.client.DivElement;
  18. import com.google.gwt.dom.client.Document;
  19. import com.google.gwt.dom.client.Element;
  20. import com.google.gwt.user.client.DOM;
  21. import com.google.gwt.user.client.Event;
  22. import com.google.gwt.user.client.ui.SimplePanel;
  23. import com.vaadin.client.ApplicationConnection;
  24. import com.vaadin.client.Focusable;
  25. import com.vaadin.client.WidgetUtil.ErrorUtil;
  26. import com.vaadin.client.ui.ShortcutActionHandler.ShortcutActionHandlerOwner;
  27. import com.vaadin.client.ui.TouchScrollDelegate.TouchScrollHandler;
  28. public class VPanel extends SimplePanel implements ShortcutActionHandlerOwner,
  29. Focusable, HasErrorIndicatorElement {
  30. public static final String CLASSNAME = "v-panel";
  31. /** For internal use only. May be removed or replaced in the future. */
  32. public ApplicationConnection client;
  33. /** For internal use only. May be removed or replaced in the future. */
  34. public String id;
  35. /** For internal use only. May be removed or replaced in the future. */
  36. public final Element captionNode = DOM.createDiv();
  37. private final Element captionText = DOM.createSpan();
  38. private Icon icon;
  39. /** For internal use only. May be removed or replaced in the future. */
  40. public final Element bottomDecoration = DOM.createDiv();
  41. /** For internal use only. May be removed or replaced in the future. */
  42. public final Element contentNode = DOM.createDiv();
  43. private Element errorIndicatorElement;
  44. /** For internal use only. May be removed or replaced in the future. */
  45. public ShortcutActionHandler shortcutHandler;
  46. /** For internal use only. May be removed or replaced in the future. */
  47. public int scrollTop;
  48. /** For internal use only. May be removed or replaced in the future. */
  49. public int scrollLeft;
  50. private TouchScrollHandler touchScrollHandler;
  51. public VPanel() {
  52. super();
  53. DivElement captionWrap = Document.get().createDivElement();
  54. captionWrap.appendChild(captionNode);
  55. captionNode.appendChild(captionText);
  56. captionWrap.setClassName(CLASSNAME + "-captionwrap");
  57. captionNode.setClassName(CLASSNAME + "-caption");
  58. contentNode.setClassName(CLASSNAME + "-content");
  59. bottomDecoration.setClassName(CLASSNAME + "-deco");
  60. getElement().appendChild(captionWrap);
  61. /*
  62. * Make contentNode focusable only by using the setFocus() method. This
  63. * behavior can be changed by invoking setTabIndex() in the serverside
  64. * implementation
  65. */
  66. contentNode.setTabIndex(-1);
  67. getElement().appendChild(contentNode);
  68. getElement().appendChild(bottomDecoration);
  69. setStyleName(CLASSNAME);
  70. DOM.sinkEvents(getElement(), Event.ONKEYDOWN);
  71. DOM.sinkEvents(contentNode, Event.ONSCROLL | Event.TOUCHEVENTS);
  72. contentNode.getStyle().setProperty("position", "relative");
  73. getElement().getStyle().setProperty("overflow", "hidden");
  74. makeScrollable();
  75. }
  76. /**
  77. * Sets the keyboard focus on the Panel.
  78. *
  79. * @param focus
  80. * Should the panel have focus or not.
  81. */
  82. public void setFocus(boolean focus) {
  83. if (focus) {
  84. getContainerElement().focus();
  85. } else {
  86. getContainerElement().blur();
  87. }
  88. }
  89. /*
  90. * (non-Javadoc)
  91. *
  92. * @see com.vaadin.client.Focusable#focus()
  93. */
  94. @Override
  95. public void focus() {
  96. setFocus(true);
  97. }
  98. @Override
  99. protected com.google.gwt.user.client.Element getContainerElement() {
  100. return DOM.asOld(contentNode);
  101. }
  102. /** For internal use only. May be removed or replaced in the future. */
  103. public void setCaption(String text, boolean captionAsHtml) {
  104. if (captionAsHtml) {
  105. captionText.setInnerHTML(text);
  106. } else {
  107. captionText.setInnerText(text);
  108. }
  109. }
  110. /** For internal use only. May be removed or replaced in the future. */
  111. public void setIconUri(String iconUri, ApplicationConnection client) {
  112. if (icon != null) {
  113. captionNode.removeChild(icon.getElement());
  114. }
  115. icon = client.getIcon(iconUri);
  116. if (icon != null) {
  117. DOM.insertChild(captionNode, icon.getElement(), 0);
  118. }
  119. }
  120. @Override
  121. public void onBrowserEvent(Event event) {
  122. super.onBrowserEvent(event);
  123. final int type = DOM.eventGetType(event);
  124. if (type == Event.ONKEYDOWN && shortcutHandler != null) {
  125. shortcutHandler.handleKeyboardEvent(event);
  126. return;
  127. }
  128. if (type == Event.ONSCROLL) {
  129. int newscrollTop = DOM.getElementPropertyInt(contentNode,
  130. "scrollTop");
  131. int newscrollLeft = DOM.getElementPropertyInt(contentNode,
  132. "scrollLeft");
  133. if (client != null && (newscrollLeft != scrollLeft
  134. || newscrollTop != scrollTop)) {
  135. scrollLeft = newscrollLeft;
  136. scrollTop = newscrollTop;
  137. client.updateVariable(id, "scrollTop", scrollTop, false);
  138. client.updateVariable(id, "scrollLeft", scrollLeft, false);
  139. }
  140. }
  141. }
  142. @Override
  143. public ShortcutActionHandler getShortcutActionHandler() {
  144. return shortcutHandler;
  145. }
  146. /**
  147. * Ensures the panel is scrollable e.g. after style name changes.
  148. * <p>
  149. * For internal use only. May be removed or replaced in the future.
  150. */
  151. public void makeScrollable() {
  152. if (touchScrollHandler == null) {
  153. touchScrollHandler = TouchScrollDelegate.enableTouchScrolling(this);
  154. }
  155. touchScrollHandler.addElement(contentNode);
  156. }
  157. @Override
  158. public Element getErrorIndicatorElement() {
  159. return errorIndicatorElement;
  160. }
  161. @Override
  162. public void setErrorIndicatorElementVisible(boolean visible) {
  163. if (visible) {
  164. if (errorIndicatorElement == null) {
  165. errorIndicatorElement = ErrorUtil.createErrorIndicatorElement();
  166. DOM.sinkEvents(errorIndicatorElement, Event.MOUSEEVENTS);
  167. sinkEvents(Event.MOUSEEVENTS);
  168. captionNode.insertBefore(errorIndicatorElement, captionText);
  169. }
  170. } else if (errorIndicatorElement != null) {
  171. captionNode.removeChild(errorIndicatorElement);
  172. errorIndicatorElement = null;
  173. }
  174. }
  175. }