1 16 package com.google.gwt.user.client.ui; 17 18 import com.google.gwt.core.client.GWT; 19 import com.google.gwt.user.client.DOM; 20 import com.google.gwt.user.client.Event; 21 import com.google.gwt.user.client.ui.impl.RichTextAreaImpl; 22 23 42 public class RichTextArea extends FocusWidget implements HasHTML, 43 SourcesMouseEvents { 44 45 51 public interface BasicFormatter { 52 53 58 String getBackColor(); 59 60 65 String getForeColor(); 66 67 72 boolean isBold(); 73 74 79 boolean isItalic(); 80 81 86 boolean isSubscript(); 87 88 93 boolean isSuperscript(); 94 95 100 boolean isUnderlined(); 101 102 105 void selectAll(); 106 107 112 void setBackColor(String color); 113 114 119 void setFontName(String name); 120 121 126 void setFontSize(FontSize fontSize); 127 128 133 void setForeColor(String color); 134 135 140 void setJustification(Justification justification); 141 142 145 void toggleBold(); 146 147 150 void toggleItalic(); 151 152 155 void toggleSubscript(); 156 157 160 void toggleSuperscript(); 161 162 165 void toggleUnderline(); 166 } 167 168 174 public interface ExtendedFormatter extends BasicFormatter { 175 176 181 void createLink(String url); 182 183 186 void insertHorizontalRule(); 187 188 193 void insertImage(String url); 194 195 198 void insertOrderedList(); 199 200 203 void insertUnorderedList(); 204 205 210 boolean isStrikethrough(); 211 212 215 void leftIndent(); 216 217 220 void removeFormat(); 221 222 225 void removeLink(); 226 227 230 void rightIndent(); 231 232 235 void toggleStrikethrough(); 236 } 237 238 242 public static class FontSize { 243 244 247 public static final FontSize XX_SMALL = new FontSize(1); 248 249 252 public static final FontSize X_SMALL = new FontSize(2); 253 254 257 public static final FontSize SMALL = new FontSize(3); 258 259 262 public static final FontSize MEDIUM = new FontSize(4); 263 264 267 public static final FontSize LARGE = new FontSize(5); 268 269 272 public static final FontSize X_LARGE = new FontSize(6); 273 274 277 public static final FontSize XX_LARGE = new FontSize(7); 278 279 private int number; 280 281 private FontSize(int number) { 282 this.number = number; 283 } 284 285 290 public int getNumber() { 291 return number; 292 } 293 } 294 295 299 public static class Justification { 300 301 304 public static final Justification CENTER = new Justification("Center"); 305 306 309 public static final Justification LEFT = new Justification("Left"); 310 311 314 public static final Justification RIGHT = new Justification("Right"); 315 316 private String tag; 317 318 private Justification(String tag) { 319 this.tag = tag; 320 } 321 322 public String toString() { 323 return "Justify " + tag; 324 } 325 } 326 327 private RichTextAreaImpl impl = (RichTextAreaImpl) GWT.create(RichTextAreaImpl.class); 328 private MouseListenerCollection mouseListeners; 329 330 333 public RichTextArea() { 334 setElement(impl.getElement()); 335 setStyleName("gwt-RichTextArea"); 336 } 337 338 public void addMouseListener(MouseListener listener) { 339 if (mouseListeners == null) { 340 mouseListeners = new MouseListenerCollection(); 341 } 342 mouseListeners.add(listener); 343 } 344 345 350 public BasicFormatter getBasicFormatter() { 351 if ((impl instanceof BasicFormatter) && (impl.isBasicEditingSupported())) { 352 return (BasicFormatter) impl; 353 } 354 return null; 355 } 356 357 362 public ExtendedFormatter getExtendedFormatter() { 363 if ((impl instanceof ExtendedFormatter) 364 && (impl.isExtendedEditingSupported())) { 365 return (ExtendedFormatter) impl; 366 } 367 return null; 368 } 369 370 public String getHTML() { 371 return impl.getHTML(); 372 } 373 374 public String getText() { 375 return impl.getText(); 376 } 377 378 public void onBrowserEvent(Event event) { 379 switch (DOM.eventGetType(event)) { 380 case Event.ONMOUSEDOWN: 381 case Event.ONMOUSEUP: 382 case Event.ONMOUSEMOVE: 383 case Event.ONMOUSEOVER: 384 case Event.ONMOUSEOUT: 385 if (mouseListeners != null) { 386 mouseListeners.fireMouseEvent(this, event); 387 } 388 break; 389 390 default: 391 super.onBrowserEvent(event); 393 } 394 } 395 396 public void removeMouseListener(MouseListener listener) { 397 if (mouseListeners != null) { 398 mouseListeners.remove(listener); 399 } 400 } 401 402 public void setFocus(boolean focused) { 403 impl.setFocus(focused); 404 } 405 406 public void setHTML(String html) { 407 impl.setHTML(html); 408 } 409 410 public void setText(String text) { 411 impl.setText(text); 412 } 413 414 protected void onAttach() { 415 super.onAttach(); 416 impl.initElement(); 417 impl.hookEvents(this); 418 } 419 420 protected void onDetach() { 421 super.onDetach(); 422 impl.unhookEvents(); 423 } 424 } 425 | Popular Tags |