protected void initToolBar() {
if (!showToolbar) {
return;
}
buttonHandler = new SelectHandler() {
@Override
public void onSelect(SelectEvent event) {
Widget button = (Widget) event.getSource();
if (button == fontIncrease) {
int i = fontSizesConstants.indexOf(activeFontSize);
if (i < (fontSizesConstants.size() - 1)) {
i++;
activeFontSize = fontSizesConstants.get(i);
textArea.getFormatter().setFontSize(activeFontSize);
} else {
// brings focus back to the editor
focus();
}
} else if (button == fontDecrease) {
int i = fontSizesConstants.indexOf(activeFontSize);
if (i > 0) {
i--;
activeFontSize = fontSizesConstants.get(i);
textArea.getFormatter().setFontSize(activeFontSize);
} else {
// brings focus back to the editor
focus();
}
} else if (button == bold) {
textArea.getFormatter().toggleBold();
} else if (button == italic) {
textArea.getFormatter().toggleItalic();
} else if (button == underline) {
textArea.getFormatter().toggleUnderline();
} else if (button == justifyLeft) {
textArea.getFormatter().setJustification(Justification.LEFT);
} else if (button == justifyCenter) {
textArea.getFormatter().setJustification(Justification.CENTER);
} else if (button == justifyRight) {
textArea.getFormatter().setJustification(Justification.RIGHT);
} else if (button == ol) {
textArea.getFormatter().insertOrderedList();
} else if (button == ul) {
textArea.getFormatter().insertUnorderedList();
} else if (button == link) {
String link = Window.prompt(getMessages().createLinkText(), "http://");
if (link != null && link.length() > 0) {
textArea.getFormatter().createLink(link);
} else {
textArea.getFormatter().removeLink();
}
}
}
};
HtmlEditorMessages m = getMessages();
if (enableFont) {
final ListBox fonts = new ListBox();
fonts.addItem("Arial");
fonts.addItem("Courier New");
fonts.addItem("Times New Roman");
fonts.addItem("Verdana");
fonts.setItemSelected(0, true);
fonts.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
int index = fonts.getSelectedIndex();
if (index != 0) {
textArea.getFormatter().setFontName(fonts.getItemText(index));
}
}
});
toolBar.add(fonts);
toolBar.add(new SeparatorToolItem());
}
if (enableFontSize) {
fontIncrease = new TextButton();
configureButton(fontIncrease, appearance.fontIncrease(), m.increaseFontSizeTipTitle(),
m.increaseFontSizeTipText());
fontIncrease.addSelectHandler(buttonHandler);
toolBar.add(fontIncrease);
fontDecrease = new TextButton();
configureButton(fontDecrease, appearance.fontDecrease(), m.decreaseFontSizeTipTitle(),
m.decreaseFontSizeTipText());
fontDecrease.addSelectHandler(buttonHandler);
toolBar.add(fontDecrease);
toolBar.add(new SeparatorToolItem());
}
if (enableFormat) {
bold = new ToggleButton();
configureButton(bold, appearance.bold(), m.boldTipTitle(), m.boldTipText());
bold.addSelectHandler(buttonHandler);
toolBar.add(bold);
italic = new ToggleButton();
configureButton(italic, appearance.italic(), m.italicTipTitle(), m.italicTipText());
italic.addSelectHandler(buttonHandler);
toolBar.add(italic);
underline = new ToggleButton();
configureButton(underline, appearance.underline(), m.underlineTipTitle(), m.underlineTipText());
underline.addSelectHandler(buttonHandler);
toolBar.add(underline);
toolBar.add(new SeparatorToolItem());
}
if (enableAlignments) {
justifyLeft = new TextButton();
configureButton(justifyLeft, appearance.justifyLeft(), m.justifyLeftTipTitle(), m.justifyLeftTipText());
justifyLeft.addSelectHandler(buttonHandler);
toolBar.add(justifyLeft);
justifyCenter = new TextButton();
configureButton(justifyCenter, appearance.justifyCenter(), m.justifyCenterTipTitle(), m.justifyCenterTipText());
justifyCenter.addSelectHandler(buttonHandler);
toolBar.add(justifyCenter);
justifyRight = new TextButton();
configureButton(justifyRight, appearance.justifyRight(), m.justifyRightTipTitle(), m.justifyRightTipText());
justifyRight.addSelectHandler(buttonHandler);
toolBar.add(justifyRight);
toolBar.add(new SeparatorToolItem());
}
if (enableLists) {
ol = new TextButton();
configureButton(ol, appearance.ol(), m.olTipTitle(), m.olTipText());
ol.addSelectHandler(buttonHandler);
toolBar.add(ol);
ul = new TextButton();
configureButton(ul, appearance.ul(), m.ulTipTitle(), m.ulTipText());
ul.addSelectHandler(buttonHandler);
toolBar.add(ul);
toolBar.add(new SeparatorToolItem());
}
if (enableLinks) {
link = new TextButton();
configureButton(link, appearance.link(), m.linkTipTitle(), m.linkTipText());
link.addSelectHandler(buttonHandler);
toolBar.add(link);
toolBar.add(new SeparatorToolItem());
}
if (enableColors) {
fontColor = new TextButton();
configureButton(fontColor, appearance.fontColor(), m.foreColorTipTitle(), m.foreColorTipText());
ColorMenu menu = new ColorMenu();
menu.getPalette().addValueChangeHandler(new ValueChangeHandler<String>() {
@Override
public void onValueChange(ValueChangeEvent<String> event) {
textArea.getFormatter().setForeColor(event.getValue());
}
});
fontColor.setMenu(menu);
toolBar.add(fontColor);
fontHighlight = new TextButton();
configureButton(fontHighlight, appearance.fontHighlight(), m.backColorTipTitle(), m.backColorTipText());
menu = new ColorMenu();
menu.getPalette().addValueChangeHandler(new ValueChangeHandler<String>() {
@Override
public void onValueChange(ValueChangeEvent<String> event) {
textArea.getFormatter().setBackColor(event.getValue());
}
});
fontHighlight.setMenu(menu);
toolBar.add(fontHighlight);
}
if (sourceEditMode) {
toolBar.add(new SeparatorToolItem());
sourceEdit = new ToggleButton();
configureButton(sourceEdit, appearance.source(), m.sourceEditTipTitle(), m.sourceEditTipText());
sourceEdit.addSelectHandler(new SelectHandler() {
@Override
public void onSelect(SelectEvent event) {
toggleSourceEditMode();
focus();
}