1 16 package com.google.gwt.user.client.ui.impl; 17 18 import com.google.gwt.user.client.DOM; 19 import com.google.gwt.user.client.Element; 20 import com.google.gwt.user.client.ui.RichTextArea; 21 import com.google.gwt.user.client.ui.RichTextArea.FontSize; 22 import com.google.gwt.user.client.ui.RichTextArea.Justification; 23 24 27 public class RichTextAreaImplStandard extends RichTextAreaImpl implements 28 RichTextArea.BasicFormatter, RichTextArea.ExtendedFormatter { 29 30 34 private Element beforeInitPlaceholder = DOM.createDiv(); 35 36 public native Element createElement() ; 39 40 public void createLink(String url) { 41 execCommand("CreateLink", url); 42 } 43 44 public String getBackColor() { 45 return queryCommandValue("BackColor"); 46 } 47 48 public String getForeColor() { 49 return queryCommandValue("ForeColor"); 50 } 51 52 public final String getHTML() { 53 return beforeInitPlaceholder == null ? getHTMLImpl() : DOM.getInnerHTML(beforeInitPlaceholder); 54 } 55 56 public final String getText() { 57 return beforeInitPlaceholder == null ? getTextImpl() : DOM.getInnerText(beforeInitPlaceholder); 58 } 59 60 public native void hookEvents(RichTextArea owner) ; 63 64 public native void initElement() ; 80 81 public void insertHorizontalRule() { 82 execCommand("InsertHorizontalRule", null); 83 } 84 85 public void insertImage(String url) { 86 execCommand("InsertImage", url); 87 } 88 89 public void insertOrderedList() { 90 execCommand("InsertOrderedList", null); 91 } 92 93 public void insertUnorderedList() { 94 execCommand("InsertUnorderedList", null); 95 } 96 97 public boolean isBasicEditingSupported() { 98 return true; 99 } 100 101 public boolean isBold() { 102 return queryCommandState("Bold"); 103 } 104 105 public boolean isExtendedEditingSupported() { 106 return true; 107 } 108 109 public boolean isItalic() { 110 return queryCommandState("Italic"); 111 } 112 113 public boolean isStrikethrough() { 114 return queryCommandState("Strikethrough"); 115 } 116 117 public boolean isSubscript() { 118 return queryCommandState("Subscript"); 119 } 120 121 public boolean isSuperscript() { 122 return queryCommandState("Superscript"); 123 } 124 125 public boolean isUnderlined() { 126 return queryCommandState("Underline"); 127 } 128 129 public void leftIndent() { 130 execCommand("Outdent", null); 131 } 132 133 public void removeFormat() { 134 execCommand("RemoveFormat", null); 135 } 136 137 public void removeLink() { 138 execCommand("Unlink", "false"); 139 } 140 141 public void rightIndent() { 142 execCommand("Indent", null); 143 } 144 145 public void selectAll() { 146 execCommand("SelectAll", null); 147 } 148 149 public void setBackColor(String color) { 150 execCommand("BackColor", color); 151 } 152 153 public native void setFocus(boolean focused) ; 160 161 public void setFontName(String name) { 162 execCommand("FontName", name); 163 } 164 165 public void setFontSize(FontSize fontSize) { 166 execCommand("FontSize", Integer.toString(fontSize.getNumber())); 167 } 168 169 public void setForeColor(String color) { 170 execCommand("ForeColor", color); 171 } 172 173 public final void setHTML(String html) { 174 if (beforeInitPlaceholder == null) { 175 setHTMLImpl(html); 176 } else { 177 DOM.setInnerHTML(beforeInitPlaceholder, html); 178 } 179 } 180 181 public void setJustification(Justification justification) { 182 if (justification == Justification.CENTER) { 183 execCommand("JustifyCenter", null); 184 } else if (justification == Justification.LEFT) { 185 execCommand("JustifyLeft", null); 186 } else if (justification == Justification.RIGHT) { 187 execCommand("JustifyRight", null); 188 } 189 } 190 191 public final void setText(String text) { 192 if (beforeInitPlaceholder == null) { 193 setTextImpl(text); 194 } else { 195 DOM.setInnerText(beforeInitPlaceholder, text); 196 } 197 } 198 199 public void toggleBold() { 200 execCommand("Bold", "false"); 201 } 202 203 public void toggleItalic() { 204 execCommand("Italic", "false"); 205 } 206 207 public void toggleStrikethrough() { 208 execCommand("Strikethrough", "false"); 209 } 210 211 public void toggleSubscript() { 212 execCommand("Subscript", "false"); 213 } 214 215 public void toggleSuperscript() { 216 execCommand("Superscript", "false"); 217 } 218 219 public void toggleUnderline() { 220 execCommand("Underline", "False"); 221 } 222 223 protected native String getHTMLImpl() ; 226 227 protected native String getTextImpl() ; 230 231 protected native void setHTMLImpl(String html) ; 234 235 protected native void setTextImpl(String text) ; 238 239 void execCommand(String cmd, String param) { 240 if (isRichEditingActive(elem)) { 241 setFocus(true); 244 execCommandAssumingFocus(cmd, param); 245 } 246 } 247 248 native void execCommandAssumingFocus(String cmd, String param) ; 251 252 native void initEvents() ; 271 272 native boolean isRichEditingActive(Element e) ; 275 276 void onElementInitialized() { 277 if (beforeInitPlaceholder != null) { 279 setHTMLImpl(DOM.getInnerHTML(beforeInitPlaceholder)); 280 beforeInitPlaceholder = null; 281 } 282 } 283 284 boolean queryCommandState(String cmd) { 285 if (isRichEditingActive(elem)) { 286 setFocus(true); 289 return queryCommandStateAssumingFocus(cmd); 290 } else { 291 return false; 292 } 293 } 294 295 native boolean queryCommandStateAssumingFocus(String cmd) ; 298 299 String queryCommandValue(String cmd) { 300 setFocus(true); 303 return queryCommandValueAssumingFocus(cmd); 304 } 305 306 native String queryCommandValueAssumingFocus(String cmd) ; 309 } 310 | Popular Tags |