FileDocCategorySizeDatePackage
RichTextToolbar.javaAPI DocExample14529Mon Aug 27 20:12:26 BST 2007com.google.gwt.sample.kitchensink.client

RichTextToolbar

public class RichTextToolbar extends com.google.gwt.user.client.ui.Composite
A sample toolbar for use with {@link RichTextArea}. It provides a simple UI for all rich text formatting, dynamically displayed only for the available functionality.

Fields Summary
private static final RichTextArea.FontSize[]
fontSizesConstants
private Images
images
private Strings
strings
private EventListener
listener
private com.google.gwt.user.client.ui.RichTextArea
richText
private RichTextArea.BasicFormatter
basic
private RichTextArea.ExtendedFormatter
extended
private com.google.gwt.user.client.ui.VerticalPanel
outer
private com.google.gwt.user.client.ui.HorizontalPanel
topPanel
private com.google.gwt.user.client.ui.HorizontalPanel
bottomPanel
private com.google.gwt.user.client.ui.ToggleButton
bold
private com.google.gwt.user.client.ui.ToggleButton
italic
private com.google.gwt.user.client.ui.ToggleButton
underline
private com.google.gwt.user.client.ui.ToggleButton
subscript
private com.google.gwt.user.client.ui.ToggleButton
superscript
private com.google.gwt.user.client.ui.ToggleButton
strikethrough
private com.google.gwt.user.client.ui.PushButton
indent
private com.google.gwt.user.client.ui.PushButton
outdent
private com.google.gwt.user.client.ui.PushButton
justifyLeft
private com.google.gwt.user.client.ui.PushButton
justifyCenter
private com.google.gwt.user.client.ui.PushButton
justifyRight
private com.google.gwt.user.client.ui.PushButton
hr
private com.google.gwt.user.client.ui.PushButton
ol
private com.google.gwt.user.client.ui.PushButton
ul
private com.google.gwt.user.client.ui.PushButton
insertImage
private com.google.gwt.user.client.ui.PushButton
createLink
private com.google.gwt.user.client.ui.PushButton
removeLink
private com.google.gwt.user.client.ui.PushButton
removeFormat
private com.google.gwt.user.client.ui.ListBox
backColors
private com.google.gwt.user.client.ui.ListBox
foreColors
private com.google.gwt.user.client.ui.ListBox
fonts
private com.google.gwt.user.client.ui.ListBox
fontSizes
Constructors Summary
public RichTextToolbar(com.google.gwt.user.client.ui.RichTextArea richText)
Creates a new toolbar that drives the given rich text area.

param
richText the rich text area to be controlled


                          
     
    this.richText = richText;
    this.basic = richText.getBasicFormatter();
    this.extended = richText.getExtendedFormatter();

    outer.add(topPanel);
    outer.add(bottomPanel);
    topPanel.setWidth("100%");
    bottomPanel.setWidth("100%");

    initWidget(outer);
    setStyleName("gwt-RichTextToolbar");

    if (basic != null) {
      topPanel.add(bold = createToggleButton(images.bold(), strings.bold()));
      topPanel.add(italic = createToggleButton(images.italic(), strings.italic()));
      topPanel.add(underline = createToggleButton(images.underline(),
          strings.underline()));
      topPanel.add(subscript = createToggleButton(images.subscript(),
          strings.subscript()));
      topPanel.add(superscript = createToggleButton(images.superscript(),
          strings.superscript()));
      topPanel.add(justifyLeft = createPushButton(images.justifyLeft(),
          strings.justifyLeft()));
      topPanel.add(justifyCenter = createPushButton(images.justifyCenter(),
          strings.justifyCenter()));
      topPanel.add(justifyRight = createPushButton(images.justifyRight(),
          strings.justifyRight()));
    }

    if (extended != null) {
      topPanel.add(strikethrough = createToggleButton(images.strikeThrough(),
          strings.strikeThrough()));
      topPanel.add(indent = createPushButton(images.indent(), strings.indent()));
      topPanel.add(outdent = createPushButton(images.outdent(), strings.outdent()));
      topPanel.add(hr = createPushButton(images.hr(), strings.hr()));
      topPanel.add(ol = createPushButton(images.ol(), strings.ol()));
      topPanel.add(ul = createPushButton(images.ul(), strings.ul()));
      topPanel.add(insertImage = createPushButton(images.insertImage(),
          strings.insertImage()));
      topPanel.add(createLink = createPushButton(images.createLink(),
          strings.createLink()));
      topPanel.add(removeLink = createPushButton(images.removeLink(),
          strings.removeLink()));
      topPanel.add(removeFormat = createPushButton(images.removeFormat(),
          strings.removeFormat()));
    }

    if (basic != null) {
      bottomPanel.add(backColors = createColorList("Background"));
      bottomPanel.add(foreColors = createColorList("Foreground"));
      bottomPanel.add(fonts = createFontList());
      bottomPanel.add(fontSizes = createFontSizes());

      // We only use these listeners for updating status, so don't hook them up
      // unless at least basic editing is supported.
      richText.addKeyboardListener(listener);
      richText.addClickListener(listener);
    }
  
Methods Summary
private com.google.gwt.user.client.ui.ListBoxcreateColorList(java.lang.String caption)

    ListBox lb = new ListBox();
    lb.addChangeListener(listener);
    lb.setVisibleItemCount(1);

    lb.addItem(caption);
    lb.addItem(strings.white(), "white");
    lb.addItem(strings.black(), "black");
    lb.addItem(strings.red(), "red");
    lb.addItem(strings.green(), "green");
    lb.addItem(strings.yellow(), "yellow");
    lb.addItem(strings.blue(), "blue");
    return lb;
  
private com.google.gwt.user.client.ui.ListBoxcreateFontList()

    ListBox lb = new ListBox();
    lb.addChangeListener(listener);
    lb.setVisibleItemCount(1);

    lb.addItem(strings.font(), "");
    lb.addItem(strings.normal(), "");
    lb.addItem("Times New Roman", "Times New Roman");
    lb.addItem("Arial", "Arial");
    lb.addItem("Courier New", "Courier New");
    lb.addItem("Georgia", "Georgia");
    lb.addItem("Trebuchet", "Trebuchet");
    lb.addItem("Verdana", "Verdana");
    return lb;
  
private com.google.gwt.user.client.ui.ListBoxcreateFontSizes()

    ListBox lb = new ListBox();
    lb.addChangeListener(listener);
    lb.setVisibleItemCount(1);

    lb.addItem(strings.size());
    lb.addItem(strings.xxsmall());
    lb.addItem(strings.xsmall());
    lb.addItem(strings.small());
    lb.addItem(strings.medium());
    lb.addItem(strings.large());
    lb.addItem(strings.xlarge());
    lb.addItem(strings.xxlarge());
    return lb;
  
private com.google.gwt.user.client.ui.PushButtoncreatePushButton(com.google.gwt.user.client.ui.AbstractImagePrototype img, java.lang.String tip)

    PushButton pb = new PushButton(img.createImage());
    pb.addClickListener(listener);
    pb.setTitle(tip);
    return pb;
  
private com.google.gwt.user.client.ui.ToggleButtoncreateToggleButton(com.google.gwt.user.client.ui.AbstractImagePrototype img, java.lang.String tip)

    ToggleButton tb = new ToggleButton(img.createImage());
    tb.addClickListener(listener);
    tb.setTitle(tip);
    return tb;
  
private voidupdateStatus()
Updates the status of all the stateful buttons.

    if (basic != null) {
      bold.setDown(basic.isBold());
      italic.setDown(basic.isItalic());
      underline.setDown(basic.isUnderlined());
      subscript.setDown(basic.isSubscript());
      superscript.setDown(basic.isSuperscript());
    }

    if (extended != null) {
      strikethrough.setDown(extended.isStrikethrough());
    }