use of org.eclipse.swt.events.KeyListener in project translationstudio8 by heartsome.
the class ObjectComboEditor method getEditorControl.
/**
* {@inheritDoc}
*/
public Control getEditorControl(JaretTable table, IRow row, IColumn column, char typedKey) {
super.getEditorControl(table, row, column, typedKey);
if (_combo == null) {
_combo = new Combo(table, SWT.BORDER | SWT.READ_ONLY);
_combo.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent event) {
if (event.keyCode == SWT.TAB) {
event.doit = false;
stopEditing(true);
_table.forceFocus();
_table.focusRight();
} else if (event.keyCode == SWT.CR) {
event.doit = false;
stopEditing(true);
_table.forceFocus();
_table.focusDown();
} else if (event.keyCode == SWT.ESC) {
event.doit = false;
stopEditing(false);
_column.setValue(_row, _oldVal);
_table.forceFocus();
}
}
public void keyReleased(KeyEvent arg0) {
}
});
_combo.addFocusListener(this);
_combo.setItems(_stringItems);
}
Object value = column.getValue(row);
_oldVal = value;
int selIdx = -1;
if (_allowNull && value == null) {
selIdx = 0;
} else {
selIdx = _itemList.indexOf(value);
selIdx = _allowNull ? selIdx + 1 : selIdx;
}
if (selIdx != -1) {
_combo.select(selIdx);
}
return _combo;
}
use of org.eclipse.swt.events.KeyListener in project translationstudio8 by heartsome.
the class IntegerCellEditor method createControl.
/**
* Create the control.
*
* @param table parent table
*/
private void createControl(JaretTable table) {
if (_spinner == null) {
_table = table;
_spinner = new Spinner(table, SWT.BORDER);
_spinner.setMaximum(_max);
_spinner.setMinimum(_min);
_spinner.addTraverseListener(new TraverseListener() {
public void keyTraversed(TraverseEvent e) {
e.doit = false;
}
});
_spinner.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent event) {
if (event.keyCode == SWT.TAB) {
event.doit = false;
stopEditing(true);
_table.forceFocus();
_table.focusRight();
} else if (event.keyCode == SWT.CR) {
event.doit = false;
stopEditing(true);
_table.forceFocus();
_table.focusDown();
} else if (event.keyCode == SWT.ESC) {
event.doit = false;
stopEditing(false);
_column.setValue(_row, _oldVal);
_table.forceFocus();
}
}
public void keyReleased(KeyEvent arg0) {
}
});
_spinner.addFocusListener(this);
}
}
use of org.eclipse.swt.events.KeyListener in project translationstudio8 by heartsome.
the class SegmentViewer method initListeners.
private void initListeners() {
StyledText styledText = getTextWidget();
// 去掉默认的复制、粘贴键绑定,以实现在复制、粘贴前对标记的处理
styledText.setKeyBinding('V' | SWT.MOD1, SWT.NULL);
styledText.setKeyBinding(SWT.INSERT | SWT.MOD2, SWT.NULL);
styledText.setKeyBinding('C' | SWT.MOD1, SWT.NULL);
styledText.setKeyBinding(SWT.INSERT | SWT.MOD1, SWT.NULL);
getDocument().addDocumentListener(new IDocumentListener() {
public void documentChanged(DocumentEvent e) {
}
public void documentAboutToBeChanged(DocumentEvent event) {
String method = belongToUndoOrRedo();
if (event.getLength() > 0 && method != null) {
try {
String text = event.getDocument().get(event.getOffset(), event.getLength());
Matcher matcher = PATTERN.matcher(text);
List<InnerTag> cache = new ArrayList<InnerTag>();
while (matcher.find()) {
String placeHolder = matcher.group();
InnerTag innerTag = InnerTagUtil.getInnerTag(getInnerTagCacheList(), placeHolder);
if (innerTag != null && innerTag.isVisible()) {
innerTag.setVisible(false);
if ("undo".equals(method) && innerTag.getInnerTagBean().isWrongTag()) {
cache.add(innerTag);
}
}
}
for (InnerTag t : cache) {
innerTagCacheList.remove(t);
t.dispose();
}
} catch (BadLocationException e) {
e.printStackTrace();
}
}
}
/**
* 是否属于撤销或者重做的操作。
* @return ;
*/
private String belongToUndoOrRedo() {
IUndoManager undoManager = getUndoManager();
if (undoManager != null) {
StackTraceElement[] stackTraceElements = new Throwable().getStackTrace();
for (StackTraceElement stackTraceElement : stackTraceElements) {
if (undoManager.getClass().getName().equals(stackTraceElement.getClassName())) {
String methodName = stackTraceElement.getMethodName();
if ("undo".equals(methodName) || "redo".equals(methodName)) {
return methodName;
}
}
}
}
return null;
}
});
/**
* 处理在显示非打印隐藏字符的情况光标移动问题。兼容非打印字符替换符号
*/
styledText.addKeyListener(new KeyListener() {
public void keyReleased(KeyEvent e) {
if (!XliffEditorParameter.getInstance().isShowNonpirnttingCharacter()) {
return;
}
if (e.stateMask == SWT.NONE && (e.keyCode == SWT.ARROW_UP || e.keyCode == SWT.ARROW_DOWN)) {
StyledText styledText = (StyledText) e.widget;
int offset = styledText.getCaretOffset();
if (offset < 1 || offset >= styledText.getCharCount()) {
return;
}
char c = styledText.getText().charAt(offset);
char _c = styledText.getText().charAt(offset - 1);
if (c == '\n' && (_c == Constants.LINE_SEPARATOR_CHARACTER)) {
styledText.setCaretOffset(offset - 1);
}
}
}
public void keyPressed(KeyEvent e) {
if (!XliffEditorParameter.getInstance().isShowNonpirnttingCharacter()) {
return;
}
if (e.stateMask == SWT.NONE && (e.keyCode == SWT.ARROW_LEFT || e.keyCode == SWT.ARROW_RIGHT)) {
StyledText styledText = (StyledText) e.widget;
int offset = styledText.getCaretOffset();
if (offset < 1 || offset >= styledText.getCharCount()) {
return;
}
char c = styledText.getText().charAt(offset);
char _c = styledText.getText().charAt(offset - 1);
if ((c == '' && (_c == Constants.TAB_CHARACTER || _c == Constants.SPACE_CHARACTER)) || (c == '\n' && (_c == Constants.LINE_SEPARATOR_CHARACTER))) {
if (e.keyCode == SWT.ARROW_LEFT) {
styledText.setCaretOffset(offset - 1);
} else if (e.keyCode == SWT.ARROW_RIGHT) {
styledText.setCaretOffset(offset + 1);
}
}
} else if (e.stateMask == SWT.CTRL && (e.keyCode == SWT.ARROW_LEFT || e.keyCode == SWT.ARROW_RIGHT)) {
// 单独对 ctrl + right ,ctrl + left 换行的处理
StyledText styledText = (StyledText) e.widget;
int offset = styledText.getCaretOffset();
char c = styledText.getText().charAt(offset);
if (offset < 1 || offset >= styledText.getCharCount()) {
return;
}
char _c = styledText.getText().charAt(offset - 1);
if (c == '\n' && (_c == Constants.LINE_SEPARATOR_CHARACTER)) {
if (e.keyCode == SWT.ARROW_LEFT) {
styledText.setCaretOffset(offset - 1);
} else if (e.keyCode == SWT.ARROW_RIGHT) {
styledText.setCaretOffset(offset + 1);
}
}
} else if ((e.stateMask == SWT.SHIFT || e.stateMask == (SWT.SHIFT | SWT.CTRL)) && (e.keyCode == SWT.ARROW_LEFT || e.keyCode == SWT.ARROW_RIGHT)) {
StyledText styledText = (StyledText) e.widget;
int offset = styledText.getCaretOffset();
char c = styledText.getText().charAt(offset);
if (offset < 1 || offset >= styledText.getCharCount()) {
return;
}
char _c = styledText.getText().charAt(offset - 1);
if ((c == '' && (_c == Constants.TAB_CHARACTER || _c == Constants.SPACE_CHARACTER)) || (c == '\n' && (_c == Constants.LINE_SEPARATOR_CHARACTER))) {
if (e.keyCode == SWT.ARROW_LEFT) {
styledText.invokeAction(ST.SELECT_COLUMN_PREVIOUS);
} else if (e.keyCode == SWT.ARROW_RIGHT) {
styledText.invokeAction(ST.SELECT_COLUMN_NEXT);
}
}
} else if ((e.stateMask == SWT.SHIFT) && (e.keyCode == SWT.ARROW_UP || e.keyCode == SWT.ARROW_DOWN)) {
StyledText styledText = (StyledText) e.widget;
int offset = styledText.getCaretOffset();
char c = styledText.getText().charAt(offset);
if (offset < 1 || offset >= styledText.getCharCount()) {
return;
}
char _c = styledText.getText().charAt(offset - 1);
if (c == '\n' && (_c == Constants.LINE_SEPARATOR_CHARACTER)) {
if (e.keyCode == SWT.ARROW_UP) {
styledText.invokeAction(ST.SELECT_COLUMN_PREVIOUS);
} else if (e.keyCode == SWT.ARROW_DOWN) {
styledText.invokeAction(ST.SELECT_COLUMN_NEXT);
}
}
}
}
});
/**
* 处理在显示非打印隐藏字符的情况光标移动问题。兼容非打印字符替换符号
*/
styledText.addMouseListener(new MouseListener() {
public void mouseUp(MouseEvent e) {
}
public void mouseDown(MouseEvent e) {
if (!XliffEditorParameter.getInstance().isShowNonpirnttingCharacter()) {
return;
}
StyledText styledText = (StyledText) e.widget;
int offset = styledText.getCaretOffset();
if (offset < 1 || offset >= styledText.getCharCount()) {
return;
}
// hidden character
char c = styledText.getText().charAt(offset);
// display character
char _c = styledText.getText().charAt(offset - 1);
if ((_c == Constants.LINE_SEPARATOR_CHARACTER || _c == Constants.TAB_CHARACTER || _c == Constants.SPACE_CHARACTER) && (c == '\n' || c == '')) {
styledText.setCaretOffset(offset + 1);
}
}
public void mouseDoubleClick(MouseEvent e) {
}
});
/**
* 选择内容时对非打印字符的处理
*/
styledText.addMouseMoveListener(new MouseMoveListener() {
public void mouseMove(MouseEvent e) {
StyledText styledText = (StyledText) e.widget;
int offset = styledText.getCaretOffset();
if (offset < 1 || offset >= styledText.getCharCount()) {
return;
}
char c = styledText.getText().charAt(offset);
char _c = styledText.getText().charAt(offset - 1);
if ((c == '' && (_c == Constants.TAB_CHARACTER || _c == Constants.SPACE_CHARACTER)) || (c == '\n' && (_c == Constants.LINE_SEPARATOR_CHARACTER))) {
int caretOffset = styledText.getCaretOffset();
Point p = styledText.getSelection();
if (caretOffset == p.x) {
styledText.invokeAction(ST.SELECT_COLUMN_PREVIOUS);
} else if (caretOffset == p.y) {
styledText.invokeAction(ST.SELECT_COLUMN_NEXT);
}
}
}
});
styledText.addVerifyListener(new VerifyListener() {
public void verifyText(final VerifyEvent e) {
String t = e.text;
if ((e.start == e.end) || (e.start != e.end && !e.text.equals(""))) {
// 添加内容时
if (XliffEditorParameter.getInstance().isShowNonpirnttingCharacter()) {
t = t.replace("\t", Constants.TAB_CHARACTER + "").replace(" ", Constants.SPACE_CHARACTER + "");
t = t.replace(System.getProperty("line.separator"), "\n");
StringBuffer bf = new StringBuffer(t);
int i = bf.indexOf("\n");
if (i != -1) {
if (i == 0) {
bf.insert(i, Constants.LINE_SEPARATOR_CHARACTER);
} else if (i != 0 && bf.charAt(i - 1) != Constants.LINE_SEPARATOR_CHARACTER) {
bf.insert(i, Constants.LINE_SEPARATOR_CHARACTER);
}
i = bf.indexOf("\n", i + 1);
}
e.text = bf.toString();
}
return;
}
final StyledText styledText = (StyledText) e.widget;
final String text = styledText.getText(e.start, e.end - 1);
final Matcher matcher = PATTERN.matcher(text);
if (matcher.find()) {
// 被删除的部分中存在标记的的情况,进行特殊处理。
if (isSource()) {
e.doit = false;
setToolTipMessage(Messages.getString("innertag.SegmentViewer.msg1"));
return;
}
matcher.reset();
styledText.getDisplay().syncExec(new Runnable() {
public void run() {
deleteInnerTagInPairs(e, matcher);
}
});
}
if (XliffEditorParameter.getInstance().isShowNonpirnttingCharacter()) {
if (text.length() == 1 && (text.equals("\n") || text.indexOf('') != -1)) {
char c = styledText.getText().charAt(e.start - 1);
if (c == Constants.LINE_SEPARATOR_CHARACTER || c == Constants.SPACE_CHARACTER || c == Constants.TAB_CHARACTER) {
styledText.replaceTextRange(e.start - 1, 2, "");
e.doit = false;
}
} else if (text.length() == 1 && (text.indexOf(Constants.LINE_SEPARATOR_CHARACTER) != -1 || text.indexOf(Constants.TAB_CHARACTER) != -1 || text.indexOf(Constants.TAB_CHARACTER) != -1)) {
char c = styledText.getText().charAt(e.start + 1);
if (c == '\n' || c == '') {
styledText.replaceTextRange(e.start, 2, "");
e.doit = false;
}
}
}
}
/**
* 成对删除内部标记
*/
private void deleteInnerTagInPairs(final VerifyEvent e, Matcher matcher) {
StyledText styledText = (StyledText) e.widget;
// 记录被删除的标记的索引。
ArrayList<Integer> tagIndexes = new ArrayList<Integer>();
while (matcher.find()) {
String placeHolder = matcher.group();
InnerTag innerTag = InnerTagUtil.getInnerTag(SegmentViewer.this.getInnerTagCacheList(), placeHolder);
if (innerTag != null && innerTag.isVisible()) {
innerTag.setVisible(false);
// 保存成对标记中未完全删除的标记索引
TagType tagType = innerTag.getInnerTagBean().getType();
if (tagType == TagType.START || tagType == TagType.END) {
// 处理成对标记的成对删除
// 标记索引
Integer tagIndex = Integer.valueOf(innerTag.getInnerTagBean().getIndex());
if (tagIndexes.contains(tagIndex)) {
// 如果已经包含此索引,说明成对标记的2个部分都已经删除。
tagIndexes.remove(tagIndex);
} else {
// 如果未包含此索引,则说明只删除了一个部分(开始或结束)的标记。
tagIndexes.add(tagIndex);
}
}
}
}
if (!tagIndexes.isEmpty()) {
// 存在未删除的情况。
getUndoManager().beginCompoundChange();
// 上一步已经修改,取消修改操作。
e.doit = false;
// 替换改动内容
styledText.getContent().replaceTextRange(e.start, e.end - e.start, e.text);
for (int i = 0; i < errorTagStart; i++) {
// 删除成对标记中未被删除的部分。
InnerTag innerTag = innerTagCacheList.get(i);
if (innerTag != null && innerTag.isVisible()) {
if (tagIndexes.contains(innerTag.getInnerTagBean().getIndex())) {
innerTag.setVisible(false);
String placeHolder = placeHolderBuilder.getPlaceHolder(null, i);
int start = -1;
if ((start = styledText.getText().indexOf(placeHolder)) != -1) {
styledText.getContent().replaceTextRange(start, placeHolder.length(), "");
}
tagIndexes.remove(Integer.valueOf(innerTag.getInnerTagBean().getIndex()));
if (tagIndexes.isEmpty()) {
break;
}
}
}
}
getUndoManager().endCompoundChange();
/**
* 通知更新主菜单(actionBar)中“撤销重做”等菜单项的状态,参见
* net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorActionHandler
*/
styledText.notifyListeners(SWT.Selection, null);
}
}
});
/**
* 重绘时,将当前文本段中存在的内部标记对应的控件显示出来
*/
styledText.addPaintObjectListener(new PaintObjectListener() {
public void paintObject(PaintObjectEvent event) {
StyleRange styleRange = event.style;
if (styleRange != null) {
String text = ((StyledText) event.widget).getText();
int end = styleRange.start + styleRange.length;
if (text.length() < end) {
return;
}
String styledString = text.substring(styleRange.start, end);
Matcher matcher = PATTERN.matcher(styledString);
if (matcher.matches()) {
InnerTag tag = InnerTagUtil.getInnerTag(SegmentViewer.this.getInnerTagCacheList(), styledString);
if (tag != null) {
if (!tag.isVisible()) {
tag.setVisible(true);
}
// int y = event.y + event.ascent - styleRange.metrics.ascent;
int lineHeight = getTextWidget().getLineHeight();
// innerTag.setLocation(event.x + SEGMENT_LINE_SPACING / 2, event.y + SEGMENT_LINE_SPACING /
// 2 /* 行距的一半 */);
int y = event.y + lineHeight / 2 - tag.getBounds().height / 2;
tag.setLocation(event.x + SEGMENT_LINE_SPACING, y);
}
}
}
}
});
/**
* 鼠标移动时,清除错误消息。
*/
styledText.addMouseMoveListener(new MouseMoveListener() {
public void mouseMove(MouseEvent e) {
if (getTextWidget().getToolTipText() != null && getTextWidget().getToolTipText().length() > 0) {
setToolTipMessage("");
}
}
});
// 处理修改内容时,需要非打印字符添加样式。
styledText.addListener(SWT.Modify, new Listener() {
public void handleEvent(Event event) {
if (!XliffEditorParameter.getInstance().isShowNonpirnttingCharacter()) {
return;
}
String s = event.text;
Matcher matcher = Constants.NONPRINTING_PATTERN.matcher(s);
TextStyle style = new TextStyle(null, GUIHelper.getColor(new RGB(100, 100, 100)), null);
List<StyleRange> ranges = new ArrayList<StyleRange>();
while (matcher.find()) {
int start = event.start + matcher.start();
StyleRange range = new StyleRange(style);
range.start = start;
range.length = 1;
ranges.add(range);
}
for (StyleRange range : ranges) {
getTextWidget().setStyleRange(range);
}
}
});
styledText.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
for (InnerTag tag : innerTagCacheList) {
if (tag.isSelected()) {
tag.setSelected(false);
tag.redraw();
}
}
String styledString = getTextWidget().getSelectionText();
Matcher matcher = PATTERN.matcher(styledString);
while (matcher.find()) {
String s = matcher.group();
InnerTag tag = InnerTagUtil.getInnerTag(SegmentViewer.this.getInnerTagCacheList(), s);
if (tag != null) {
tag.setSelected(true);
tag.redraw();
}
}
}
});
}
use of org.eclipse.swt.events.KeyListener in project translationstudio8 by heartsome.
the class XLFEditor method hookListener.
/**
* 初始化监听器。
*/
private void hookListener() {
// 添加文本修改监听器,用于调整文本框大小,使其高度自适应文本内容。
textModifyListener = new ModifyListener() {
public void modifyText(ModifyEvent e) {
StyledText st = (StyledText) e.widget;
GridData gd = (GridData) st.getLayoutData();
if (gd == null) {
gd = new GridData(GridData.FILL_BOTH);
}
Point computeSize = st.computeSize(st.getSize().x, SWT.DEFAULT, false);
// 此行代码是为了保持列宽不变。减 10 是因为 computeSize 后宽度每次会增加 5 个像素,
// 因此需要减去上次和本次增加的共10像素。为什么会这样原因不明。
gd.widthHint = computeSize.x - 10;
st.setLayoutData(gd);
editorContentComposite.layout();
oScrolledComposite.setMinSize(editorContentComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
}
};
// 添加鼠标跟踪监听器,用于监听鼠标位置,根据编辑器模式切换光标样式。
mouseTrackListener = new MouseTrackListener() {
private void setArrowCursor(MouseEvent arg0) {
Widget srcWidget = arg0.widget;
if (isEditModel && srcWidget instanceof StyledText) {
((StyledText) srcWidget).setCursor(cursorIbeam);
} else {
((StyledText) srcWidget).setCursor(cursorArrow);
}
}
public void mouseEnter(MouseEvent arg0) {
setArrowCursor(arg0);
}
public void mouseExit(MouseEvent arg0) {
setArrowCursor(arg0);
}
public void mouseHover(MouseEvent arg0) {
setArrowCursor(arg0);
}
};
mouseListener = new MouseListener() {
public void mouseDoubleClick(MouseEvent arg0) {
// 切换为编辑模式
isEditModel = true;
System.out.println("It's running edit model.");
Control ctrl = arg0.display.getCursorControl();
ctrl.setCursor(cursorIbeam);
}
public void mouseDown(MouseEvent arg0) {
int inx = (Integer) arg0.widget.getData(DATAKEY_INDEX);
setSelectionRowColor(inx);
// 选中模式下要隐藏光标。
if (!isEditModel) {
// 通过为容器组件设置焦点,实现在选中模式时隐藏文本框组件中闪烁的光标
txtComposites[inx].forceFocus();
}
}
public void mouseUp(MouseEvent arg0) {
}
};
keyListener = new KeyListener() {
public void keyPressed(KeyEvent arg0) {
// 按 Esc 键切换到选择模式。
if (arg0.keyCode == SWT.ESC) {
isEditModel = false;
Control ctrl = arg0.display.getCursorControl();
ctrl.setCursor(cursorArrow);
}
}
public void keyReleased(KeyEvent arg0) {
}
};
}
use of org.eclipse.swt.events.KeyListener in project cogtool by cogtool.
the class WidgetPropertiesPane method createWidgets.
protected void createWidgets() {
// set up widgets, set disabled for launch
widgetName = new DisplayLabel(this, SWT.NONE);
widgetName.setText(L10N.get("FE.WidgetNameCaption", "Widget Name") + ":");
widgetNameText = new WidgetChangeText(this, SWT.SINGLE | SWT.BORDER, FrameEditorLID.ChangeNameProperty, view);
widgetTitle = new DisplayLabel(this, SWT.NONE);
widgetTitle.setText(DISPLAYED_LABEL);
widgetTitleText = new WidgetChangeText(this, SWT.SINGLE | SWT.BORDER, FrameEditorLID.ChangeTitleProperty, view);
widgetAux = new DisplayLabel(this, SWT.NONE);
widgetAux.setText(AUX_TEXT_LABEL);
widgetAuxText = new WidgetChangeText(this, SWT.SINGLE | SWT.BORDER, FrameEditorLID.ChangeAuxTextProperty, view);
widgetType = new DisplayLabel(this, SWT.NONE);
widgetType.setText(L10N.get("FE.WidgetTypeCaption", "Type") + ":");
widgetTypeLabel = new Label(this, SWT.NONE);
widgetMode = new DisplayLabel(this, SWT.NONE);
widgetMode.setText(L10N.get("FE.WidgetModeCaption", "Mode") + ":");
widgetModeValue = new Label(this, SWT.NONE);
widgetRender = new Button(this, SWT.CHECK);
widgetRender.setText(L10N.get("FE.WidgetRenderedCaption", "Render Widget Skin"));
// Add listener to the rendered widget property
widgetRender.addSelectionListener(view.createWidgetChgHandler(FrameEditorLID.SetRenderSkin));
remoteLabel = new DisplayLabel(this, SWT.NONE);
remoteLabel.setText(L10N.get("FE.RemoteLabelCaption", "Remote Label") + ":");
remoteLabelFind = new Link(this, SWT.NONE);
remoteLabelFind.setText(L10N.get("FE.RemoteLabelFind", "<a>Find</a>"));
remoteLabelFind.setFont(FontUtils.getAdjustedFont(remoteLabelFind.getFont(), 8, SWT.BOLD));
remoteLabelText = new WidgetChangeText(this, SWT.SINGLE | SWT.BORDER, FrameEditorLID.SetRemoteLabelText, view);
remoteLabelOwner = new DisplayLabel(this, SWT.NONE);
remoteLabelOwner.setText(L10N.get("FE.RemoteLabelOwnerCaption", "Remote Label Owner") + ":");
remoteLabelOwnerName = new Link(this, SWT.NONE);
remoteLabelType = new DisplayLabel(this, SWT.NONE);
remoteLabelType.setText(L10N.get("FE.RemoteLabelTypeCaption", "Remote Label Type") + ":");
remoteLabelTypeCombo = new View.PerformActionCombo(this, SWT.DROP_DOWN | SWT.READ_ONLY) {
@Override
protected boolean doChangeAction() {
int selectedType = remoteLabelTypeCombo.getSelectionIndex();
FrameEditorUI.SetRemoteLabelTypeParms setTypeParms = new FrameEditorUI.SetRemoteLabelTypeParms(widgetTypeChoices[selectedType], view.selection.getSelectedIWidgets()[0]);
return view.performAction(FrameEditorLID.SetRemoteLabelType, setTypeParms, true);
}
};
for (WidgetType widgetTypeChoice : widgetTypeChoices) {
remoteLabelTypeCombo.add(widgetTypeChoice.toString());
}
imagePath = new DisplayLabel(this, SWT.NONE);
imagePath.setText(IMAGE_PATH);
imagePathText = new TextWithEnableFix(this, SWT.SINGLE | SWT.READ_ONLY);
isInitiallySelected = new Button(this, SWT.CHECK);
isInitiallySelected.setText(L10N.get("FE.InitiallySelected", "Initially Selected"));
WidgetAttributeListener listener = new WidgetAttributeListener(WidgetAttributes.IS_SELECTED_ATTR) {
@Override
public Object getValue() {
return new Boolean(isInitiallySelected.getSelection());
}
};
isInitiallySelected.addSelectionListener(listener);
isButtonSelected = new Button(this, SWT.CHECK);
isButtonSelected.setText(L10N.get("FE.InitiallySelected", "Initially Selected"));
isButtonSelected.setEnabled(false);
listener = new WidgetAttributeListener(WidgetAttributes.IS_SELECTED_ATTR) {
@Override
public Object getValue() {
return new Boolean(isButtonSelected.getSelection());
}
};
isButtonSelected.addSelectionListener(listener);
isToggleable = new Button(this, SWT.CHECK);
isToggleable.setText(L10N.get("FE.Togglable", "Can be toggled"));
listener = new WidgetAttributeListener(WidgetAttributes.IS_TOGGLEABLE_ATTR) {
@Override
public Object getValue() {
boolean sel = isToggleable.getSelection();
isButtonSelected.setEnabled(sel);
return new Boolean(sel);
}
};
isToggleable.addSelectionListener(listener);
/*this.isMultiLine = new Button(parent, SWT.CHECK);
this.isMultiLine.setText(L10N.get("FE.MultiLine", "Multiple Lined"));
listener = new WidgetAttributeListener(WidgetType.IS_MULTILINE_ATTR) {
@Override
public Object getValue() {
return new Boolean(isMultiLine.getSelection());
}
};
this.isMultiLine.addSelectionListener(listener);*/
selectLabel = new DisplayLabel(this, SWT.NONE);
selectLabel.setText(L10N.get("FE.ComboSelectCaption", "Initially Selected Item") + ":");
initiallySelected = new ComboWithEnableFix(this, SWT.DROP_DOWN | SWT.READ_ONLY);
initiallySelected.setVisibleItemCount(8);
initiallySelected.addSelectionListener(selectionAttrListener);
isSeparator = new Button(this, SWT.CHECK);
isSeparator.setText(L10N.get("FE.Separator", "Separator"));
listener = new WidgetAttributeListener(WidgetAttributes.IS_SEPARATOR_ATTR) {
@Override
public Object getValue() {
return (isSeparator.getSelection()) ? WidgetAttributes.IS_SEPARATOR : WidgetAttributes.NON_SEPARATOR;
}
};
isSeparator.addSelectionListener(listener);
isSeparator.moveAbove(widgetTypeLabel);
submenuActionLabel = new DisplayLabel(this, SWT.NONE);
submenuActionLabel.setText(L10N.get("FE.SubmenuActionLabel", "Submenu transition action") + ":");
submenuAction = new ComboWithEnableFix(this, SWT.DROP_DOWN | SWT.READ_ONLY);
// Maximize the possible set of values.
submenuActions = new Integer[] { WidgetAttributes.HOVER_SUBMENU_ACTION, null, null };
submenuAction.add(L10N.get("FE.HoverSubmenuAction", "Hover"));
listener = new WidgetAttributeListener(WidgetAttributes.SUBMENU_ACTION_ATTR) {
@Override
public Object getValue() {
Object a = submenuActions[submenuAction.getSelectionIndex()];
submenuDelay.setEnabled(a == WidgetAttributes.HOVER_SUBMENU_ACTION);
return a;
}
};
submenuAction.addSelectionListener(listener);
submenuDelayLabel = new DisplayLabel(this, SWT.NONE);
submenuDelayLabel.setText(L10N.get("FE.SubmenuDelay", "Submenu transition delay") + ":");
// TODO: remove READ_ONLY when editing allowed (check exception in setSubmenuDelayAttr)
submenuDelay = new ComboWithEnableFix(this, SWT.DROP_DOWN | SWT.READ_ONLY);
submenuDelay.add("0.0 s (" + L10N.get("FE.TypicalForMac", "typical for a Mac") + ")");
submenuDelay.add("0.5 s (" + L10N.get("FE.TypicalForPC", "typical for a PC") + ")");
listener = new WidgetAttributeListener(WidgetAttributes.SUBMENU_DELAY_ATTR) {
@Override
public Object getValue() {
switch(submenuDelay.getSelectionIndex()) {
case 0:
{
return WidgetAttributes.NO_SUBMENU_DELAY;
}
case 1:
{
return WidgetAttributes.PC_SUBMENU_DELAY;
}
}
// should be the current value!
return null;
}
@Override
public void widgetDefaultSelected(SelectionEvent evt) {
view.setSubmenuDelayAttr(view.selection.getSelectedIWidgets()[0], submenuDelay.getText());
}
};
submenuDelay.addSelectionListener(listener);
submenuDelay.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent evt) {
/*
* We can allow certain types of characters here:
* Control characters (arrow keys, etc): Character.CONTROL
* Numerics: Character.DECIMAL_DIGIT_NUMBER
* Decimal Point: keycodes 46 and 16777262
*
* Disallow anything else
*/
int characterType = Character.getType(evt.character);
if ((characterType == Character.CONTROL) || (characterType == Character.DECIMAL_DIGIT_NUMBER) || (evt.keyCode == 46) || (evt.keyCode == 16777262)) {
evt.doit = true;
} else {
evt.doit = false;
}
}
// listen for the enter key on the number pad for OS X
public void keyReleased(KeyEvent evt) {
if (OSUtils.MACOSX) {
if (evt.keyCode == SWT.KEYPAD_CR) {
view.setSubmenuDelayAttr(view.selection.getSelectedIWidgets()[0], submenuDelay.getText());
}
}
}
});
contextMenuActionLabel = new DisplayLabel(this, SWT.NONE);
contextMenuActionLabel.setText(L10N.get("FE.ContextMenuAction", "Context Menu Action") + ":");
// Maximize the possible set of values.
contextMenuActions = new Integer[] { null, null, null };
contextMenuAction = new ComboWithEnableFix(this, SWT.DROP_DOWN | SWT.READ_ONLY);
//TODO: this.contextMenuAction.add(L10N.get("FE.MenuKeyPress", "Menu Key Press"));
listener = new WidgetAttributeListener(WidgetAttributes.CONTEXT_MENU_ACTION_ATTR) {
@Override
public Object getValue() {
return contextMenuActions[contextMenuAction.getSelectionIndex()];
}
};
contextMenuAction.addSelectionListener(listener);
// Set initial selection
//widgetShapeCombo.select(0);
widgetTypeLabel.setText(N_A);
widgetModeValue.setText(N_A);
}
Aggregations