001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.ui.components; 029 030import org.opencms.util.CmsStringUtil; 031import org.opencms.util.CmsUUID; 032 033import com.vaadin.ui.JavaScript; 034import com.vaadin.v7.ui.RichTextArea; 035 036/** 037 * Helper class for using rich text area in OpenCms.<p> 038 */ 039public class CmsRichTextAreaV7 extends RichTextArea { 040 041 /**vaadin serial id. */ 042 private static final long serialVersionUID = 1L; 043 044 /**CSS class name. */ 045 private static final String CSS_CLASSNAME = "richopensans"; 046 047 /**Style name. */ 048 private String m_styleName = ""; 049 050 /** 051 * Public constructor.<p> 052 */ 053 public CmsRichTextAreaV7() { 054 055 addStyleName("o-richtextarea-reduced"); 056 setFontStyle(); 057 } 058 059 /** 060 * Sets the font stype to Open Sans.<p> 061 * Has to be called after every refresh of the UI. For example after switching tabs on tab-sheets..<p> 062 */ 063 public void setFontStyle() { 064 065 if (!CmsStringUtil.isEmptyOrWhitespaceOnly(m_styleName)) { 066 removeStyleName(m_styleName); 067 } 068 String id = new CmsUUID().getStringValue(); 069 m_styleName = CSS_CLASSNAME + "_" + id; 070 addStyleName(m_styleName); 071 String js = "var elements = document.getElementsByClassName('" 072 + m_styleName 073 + "');" 074 + "var iframeContainer = elements[0];" 075 + "var iframe = iframeContainer.getElementsByTagName('iframe')[0];" 076 + "var iframeBody = iframe.contentDocument.getElementsByTagName('body')[0];" 077 + "iframeBody.style.fontFamily='\"Open Sans\", sans-serif';"; 078 079 JavaScript.getCurrent().execute(js); 080 081 } 082}