📄 editortoolbar.java
字号:
});
EditorToolbarSelect styles = new EditorToolbarSelect();
styles.addItem("Style", "");
String[][] formats = EditorUtils.getSupportedFormats();
for (int i = 0; i < formats.length; i++) {
styles.addItem(formats[i][0], formats[i][1]);
}
styles.addChangeListener(new ChangeListener() {
public void onChange(Widget sender) {
ListBox subj = ((ListBox) sender);
String value = subj.getValue(subj.getSelectedIndex());
subj.setSelectedIndex(0);
EditorUtils.doFocus(editor.getEditorWYSIWYG().getFrame().getElement());
editor.execCommand("FormatBlock", false, value);
}
});
EditorToolbarSelect fontSizes = new EditorToolbarSelect();
fontSizes.addItem("Size", "");
for (int i = 1; i < 8; i++) {
fontSizes.addItem("Size " + i, "" + i);
}
fontSizes.addChangeListener(new ChangeListener() {
public void onChange(Widget sender) {
ListBox subj = ((ListBox) sender);
String value = subj.getValue(subj.getSelectedIndex());
subj.setSelectedIndex(0);
editor.execCommand("FontSize", false, value);
EditorUtils.doFocus(editor.getEditorWYSIWYG().getFrame().getElement());
}
});
fullToolbar.add(source);
fullToolbar.add(EditorToolbarButton.getSpacer());
fullToolbar.add(removeFormat);
fullToolbar.add(EditorToolbarButton.getSpacer());
fullToolbar.add(undo);
fullToolbar.add(redo);
fullToolbar.add(EditorToolbarButton.getSpacer());
fullToolbar.add(bold);
fullToolbar.add(italic);
fullToolbar.add(underlined);
fullToolbar.add(EditorToolbarButton.getSpacer());
fullToolbar.add(subscript);
fullToolbar.add(superscript);
fullToolbar.add(EditorToolbarButton.getSpacer());
fullToolbar.add(justifyLeft);
fullToolbar.add(justifyCenter);
fullToolbar.add(justifyRight);
fullToolbar.add(justifyJustify);
fullToolbar.add(EditorToolbarButton.getSpacer());
fullToolbar.add(ol);
fullToolbar.add(ul);
fullToolbar.add(EditorToolbarButton.getSpacer());
fullToolbar.add(link);
fullToolbar.add(unlink);
fullToolbar.add(image);
fullToolbar.add(EditorToolbarButton.getSpacer());
fullToolbar.add(foreColor);
fullToolbar.add(bgColor);
fullToolbar.add(EditorToolbarButton.getSpacer());
fullToolbar.add(styles);
fullToolbar.add(fontSizes);
EditorToolbarButton source2 = new EditorToolbarButton(EditorToolbarButton.BUTTON_NEW2);
source2.addClickListener(new ClickListener() {
public void onClick(Widget sender) {
if(memoType == MemoFieldMeta.EDIT_TYPE ||
(memoType != MemoFieldMeta.EDIT_TYPE && !hasRecords)) {
editor.getEditorWYSIWYG().toggleView();
if(memoType != MemoFieldMeta.EDIT_TYPE) {
eventSource.fireEvent(Events.PANEL_CHANGE);
}
}
}
});
shortToolbar.add(source2);
topContainer.add(fullToolbar);
topContainer.add(shortToolbar);
fullToolbar.setVisible(true);
shortToolbar.setVisible(false);
initWidget(topContainer);
}
private void initFgPicker() {
if(fgPicker != null) {
return;
}
fgPicker = new EditorColorPicker("Select Text Color");
fgPicker.addSelectListener(new EditorColorSelectListener() {
public void colorSelected(String rgb) {
EditorUtils.restoreSelection(editor.getEditorWYSIWYG().getFrame().getElement());
editor.execCommand("ForeColor", false, rgb);
EditorUtils.doFocus(editor.getEditorWYSIWYG().getFrame().getElement());
}
});
}
private void initBgPicker() {
if(bgPicker != null) {
return;
}
bgPicker = new EditorColorPicker("Select Background Color");
bgPicker.addSelectListener(new EditorColorSelectListener() {
public void colorSelected(String rgb) {
EditorUtils.restoreSelection(editor.getEditorWYSIWYG().getFrame().getElement());
editor.execCommand(EditorUtils.isIE()? "backcolor" : "hilitecolor", false, rgb);
EditorUtils.doFocus(editor.getEditorWYSIWYG().getFrame().getElement());
}
});
}
private class SimpleCommandButton extends EditorToolbarButton {
public SimpleCommandButton(String buttonId, final String command) {
this(buttonId, command, false, null);
}
public SimpleCommandButton(String buttonId, final String command, final boolean ui, String value) {
super(buttonId);
this.addClickListener(new ClickListener() {
public void onClick(Widget sender) {
// EditorUtils.doFocus(editor.getEditorWYSIWYG().getFrame().getElement());
EditorUtils.execCommand(editor.getEditorWYSIWYG().getFrame().getElement(), command, ui, null);
}
});
}
}
public class SimplePromptPannel extends EditorToolbarButton {
public SimplePromptPannel(String buttonId, final String command, final String question) {
super(buttonId);
this.addClickListener(new ClickListener() {
public void onClick(Widget sender) {
String value = EditorUtils.prompt(question);
if (value != null) {
EditorUtils.doFocus(editor.getEditorWYSIWYG().getFrame().getElement());
editor.execCommand(command, false, value);
}
}
});
}
}
private class SimpleOneFieldPromptPannel {
public SimpleOneFieldPromptPannel(String command, String title, String fieldLabel, String buttonLabel) {
final EditorPromptPanelWidget widget = new EditorPromptPanelWidget();
VerticalPanel container = new VerticalPanel();
container.setWidth("300px");
final TextBox urlTextBox = new TextBox();
HorizontalPanel hz = new HorizontalPanel();
hz.setSpacing(5);
hz.setWidth("100%");
Label linkLabel = new Label(fieldLabel);
linkLabel.setWordWrap(false);
hz.add(linkLabel);
hz.setCellWidth(linkLabel, "70px");
hz.setCellVerticalAlignment(linkLabel, HasAlignment.ALIGN_MIDDLE);
hz.setCellHorizontalAlignment(linkLabel, HasAlignment.ALIGN_RIGHT);
hz.add(urlTextBox);
hz.setCellVerticalAlignment(urlTextBox, HasAlignment.ALIGN_MIDDLE);
urlTextBox.setWidth("100%");
container.add(hz);
HorizontalPanel hzButtons = new HorizontalPanel();
Button b = new Button(buttonLabel);
b.addClickListener(new ClickListener() {
public void onClick(Widget sender) {
widget.getPrompt().complete(urlTextBox.getText());
}
});
Button c = new Button("Cancel");
c.addClickListener(new ClickListener() {
public void onClick(Widget sender) {
widget.getPrompt().complete(null);
}
});
hzButtons.add(b);
hzButtons.add(c);
hzButtons.setSpacing(4);
container.add(hzButtons);
container.setCellHorizontalAlignment(hzButtons, HasAlignment.ALIGN_CENTER);
widget.setWidget(container);
new AdvancedPromptPannel(command, title, widget);
urlTextBox.setFocus(true);
}
}
private class AdvancedPromptPannel extends EditorPromptPanel {
public AdvancedPromptPannel(final String command, String title, EditorPromptPanelWidget widget) {
super(title, widget);
this.addPopupListener(new PopupListener() {
public void onPopupClosed(final PopupPanel sender, boolean autoClosed) {
String value = ((EditorPromptPanel) sender).getValue();
EditorUtils.restoreSelection(editor.getEditorWYSIWYG().getFrame().getElement());
if (value != null) {
editor.execCommand(command, false, value);
EditorUtils.doFocus(editor.getEditorWYSIWYG().getFrame().getElement());
}
}
});
EditorUtils.saveSelection(editor.getEditorWYSIWYG().getFrame().getElement());
super.show(editor);
}
}
public void setWidth(String width) {
topContainer.setWidth(width);
}
public String getWidth() {
return DOM.getStyleAttribute(topContainer.getElement(), "width");
}
public void switchToSmall() {
fullToolbar.setVisible(false);
shortToolbar.setVisible(true);
}
public void switchToFull() {
fullToolbar.setVisible(true);
shortToolbar.setVisible(false);
}
public void setMemoType(int memoType) {
this.memoType = memoType;
}
public void setHasRecords(boolean hasRecords) {
this.hasRecords = hasRecords;
}
public void setAddLinkAsAttachment(boolean isAddLinkAsAttachment) {
this.isAddLinkAsAttachment = isAddLinkAsAttachment;
}
public void setImageAttachmentAction(String string) {
if (fileUpload != null) {
fileUpload.setAction(string);
}
imageAttachmentAction = string;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -