View Javadoc

1   /**
2    * Copyright 2010 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
14   */
15  
16  package org.kuali.student.common.ui.client.widgets;
17  
18  
19  
20  import org.kuali.student.common.ui.client.widgets.impl.KSRichEditorImpl;
21  
22  import com.google.gwt.core.client.GWT;
23  import com.google.gwt.event.dom.client.BlurHandler;
24  import com.google.gwt.event.dom.client.FocusHandler;
25  import com.google.gwt.event.shared.HandlerRegistration;
26  import com.google.gwt.user.client.ui.HasText;
27  import com.google.gwt.user.client.ui.RichTextArea;
28  
29  /** 
30   * KSRichEditor is the KS default rich text editor.  The editor provides a variety of text formatting options commonly
31   * found in traditional text editors.  It also features a toolbar which only shows when the editor is in focus and a pop-out
32   * window which allows a user to have more space to work (and can be resized).  Any changes made in the pop-out
33   * editor are reflected in the original editor when the user is finished.
34   * 
35   * TODO implement i18n
36   */
37  public class KSRichEditor extends KSRichEditorAbstract implements HasText{
38      private KSRichEditorAbstract richEditor = GWT.create(KSRichEditorImpl.class);
39      
40  	/**
41  	 * Creates a new KSRichEditor.
42  	 * 
43  	 */
44  	public KSRichEditor(){
45  	    initWidget(richEditor);
46  	}
47  	
48  	/**
49  	 * Gets the RichTextArea widget used for text input in this rich editor widget.
50  	 * 
51  	 * @return the RichTextArea used in this editor
52  	 */
53  	public RichTextArea getRichTextArea(){
54  	    return richEditor.getRichTextArea();
55  	}
56  	
57  	/**
58  	 * Get the HTML version of the text input (retains all formatting).
59  	 * 
60  	 * @return the HTML version of the input text (with formatting)
61  	 */
62  	public String getHTML() {
63  		return richEditor.getHTML();
64  	}
65  
66  	/**
67  	 * Get the plain text version of the text input (retains NO formatting).
68  	 * 
69  	 * @return the plain text version of the input text (no formatting)
70  	 */
71  	public String getText() {
72  		return richEditor.getText();
73  	}
74  
75  	/**
76  	 * Set the HTML of this rich text editor.
77  	 * 
78  	 * @param html the HTML to set this editor to
79  	 */
80  	public void setHTML(String html) {
81  	    richEditor.setHTML(html);
82  	}
83  
84  	/**
85  	 * Set the text of this rich text editor (this is text with no formatting).
86  	 * 
87  	 * @param the plain text to set this editor to
88  	 */
89  	public void setText(String text) {
90  	    richEditor.setText(text);
91  	}
92  
93  
94  	@Override
95  	public void setStyleName(String text) {
96  		richEditor.setStyleName(text);
97  	}
98  
99  
100 	@Override
101 	public HandlerRegistration addBlurHandler(BlurHandler handler) {
102 		return richEditor.addBlurHandler(handler);
103 	}
104 
105 
106 	@Override
107 	public HandlerRegistration addFocusHandler(FocusHandler handler) {
108 		return richEditor.addFocusHandler(handler);
109 	}
110 
111 	@Override
112 	protected void init() {
113 		 richEditor.init();
114 		
115 	}
116 }