Spec-Zone .ru
спецификации, руководства, описания, API
001/*
002 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.  Oracle designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Oracle in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
022 * or visit www.oracle.com if you need additional information or have any
023 * questions.
024 */
025
026package javafx.scene.web;
027
028
029import javafx.css.CssMetaData;
030import javafx.css.StyleableProperty;
031import com.sun.javafx.scene.web.skin.HTMLEditorSkin;
032
033import javafx.geometry.NodeOrientation;
034import javafx.scene.control.Control;
035
036import java.security.AccessController;
037import java.security.PrivilegedAction;
038import javafx.scene.control.Skin;
039
040
041/**
042 * A control that allows for users to edit text, and apply styling to this text.
043 * The underlying data model is HTML, although this is not shown visually to the
044 * end-user.
045 */
046public class HTMLEditor extends Control {
047    
048    /**
049     * Creates a new instance of the HTMLEditor control.
050     */
051    public HTMLEditor() {
052        ((StyleableProperty)super.skinClassNameProperty()).applyStyle(
053            null, 
054            "com.sun.javafx.scene.web.skin.HTMLEditorSkin"
055        );
056        getStyleClass().add("html-editor");
057    }
058
059    @Override protected Skin<?> createDefaultSkin() {
060        return new HTMLEditorSkin(this);
061    }
062
063    /**
064     * Returns the HTML content of the editor.
065     */
066    public String getHtmlText() {
067        return ((HTMLEditorSkin)getSkin()).getHTMLText();
068    }
069
070    /**
071     * Sets the HTML content of the editor. Note that if the contentEditable
072     * property on the <body> tag of the provided HTML is not set to true, the
073     * HTMLEditor will become read-only. You can ensure that the text remains
074     * editable by ensuring the body appears as such: 
075     * <code>
076     * &lt;body contentEditable="true"&gt;
077     * </code>
078     *
079     * @param htmlText The full HTML markup to put into the editor. This should
080     *      include all normal HTML elements, starting with 
081     *      <code>&lt;html&gt;</code>, and including a <code>&lt;body&gt;</code>.
082     */
083    public void setHtmlText(String htmlText) {
084        ((HTMLEditorSkin)getSkin()).setHTMLText(htmlText);
085    }
086}