use of org.eclipse.swt.custom.StyleRange in project translationstudio8 by heartsome.
the class HsMultiCellEditor method calculateTermsStyleRange.
private List<StyleRange> calculateTermsStyleRange(char[] source, char[] target, TextStyle style) {
int sourceOffset = 0;
int sourceCount = source.length;
int targetOffset = 0, targetCount = target.length;
char first = target[targetOffset];
int max = sourceOffset + (sourceCount - targetCount);
List<StyleRange> rangeList = new ArrayList<StyleRange>();
for (int i = sourceOffset; i <= max; i++) {
/* Look for first character. */
if (source[i] != first) {
while (++i <= max && source[i] != first) ;
}
/* Found first character, now look at the rest of v2 */
if (i <= max) {
List<StyleRange> tempList = new ArrayList<StyleRange>();
int start = i;
int j = i + 1;
int end = j + targetCount - 1;
for (int k = targetOffset + 1; j < end; j++, k++) {
Matcher matcher = PlaceHolderEditModeBuilder.PATTERN.matcher(source[j] + "");
if (matcher.matches()) {
StyleRange range = new StyleRange(style);
range.start = start;
range.length = j - start;
start = j + 1;
k--;
end++;
if (end > sourceCount) {
break;
}
tempList.add(range);
continue;
}
if (source[j] != target[k]) {
break;
}
}
if (j == end) {
/* Found whole string. */
StyleRange range = new StyleRange(style);
range.start = start;
range.length = j - start;
rangeList.addAll(tempList);
rangeList.add(range);
}
}
}
return rangeList;
}
use of org.eclipse.swt.custom.StyleRange in project translationstudio8 by heartsome.
the class GetActiveKeyDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
Composite tparent = (Composite) super.createDialogArea(parent);
GridLayout layout = new GridLayout();
layout.marginWidth = 10;
layout.marginTop = 10;
tparent.setLayout(layout);
GridDataFactory.fillDefaults().grab(true, true).applyTo(tparent);
Composite compNav = new Composite(tparent, SWT.NONE);
GridLayout navLayout = new GridLayout();
compNav.setLayout(navLayout);
createNavigation(compNav);
Group groupActivekey = new Group(tparent, SWT.NONE);
groupActivekey.setText(Messages.getString("license.GetActiveKeyDialog.activekey"));
GridDataFactory.fillDefaults().grab(true, true).applyTo(groupActivekey);
GridLayout layoutGroup = new GridLayout(2, false);
layoutGroup.marginWidth = 5;
layoutGroup.marginHeight = 20;
groupActivekey.setLayout(layoutGroup);
StyledText text = new StyledText(groupActivekey, SWT.WRAP | SWT.READ_ONLY);
text.setBackground(text.getParent().getBackground());
text.setText(Messages.getString("license.GetActiveKeyDialog.activemessage"));
GridData dataText = new GridData();
dataText.horizontalSpan = 2;
dataText.widthHint = 470;
text.setLayoutData(dataText);
int start = Messages.getString("license.GetActiveKeyDialog.activemessage").indexOf(Messages.getString("license.GetActiveKeyDialog.ts"));
int length = Messages.getString("license.GetActiveKeyDialog.ts").length();
StyleRange styleRange = new StyleRange();
styleRange.start = start;
styleRange.length = length;
styleRange.fontStyle = SWT.BOLD;
styleRange.foreground = Display.getDefault().getSystemColor(SWT.COLOR_BLUE);
text.setStyleRange(styleRange);
Label label = new Label(groupActivekey, SWT.WRAP | SWT.NONE);
label.setText(Messages.getString("license.GetActiveKeyDialog.activemessage1"));
GridDataFactory.fillDefaults().span(2, 1).applyTo(label);
textActivekey = new Text(groupActivekey, SWT.MULTI | SWT.WRAP);
textActivekey.setEditable(false);
textActivekey.setText(activekey);
textActivekey.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
GridDataFactory.fillDefaults().grab(true, false).hint(SWT.DEFAULT, 150).applyTo(textActivekey);
Button btnCopy = new Button(groupActivekey, SWT.NONE);
GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.END).applyTo(btnCopy);
btnCopy.setImage(Activator.getImageDescriptor("images/help/copy.png").createImage());
btnCopy.setToolTipText(Messages.getString("license.GetActiveKeyDialog.copytoclipboard"));
btnCopy.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
Clipboard cb = new Clipboard(Display.getCurrent());
String textData = textActivekey.getText();
TextTransfer textTransfer = TextTransfer.getInstance();
cb.setContents(new Object[] { textData }, new Transfer[] { textTransfer });
}
});
return tparent;
}
use of org.eclipse.swt.custom.StyleRange in project translationstudio8 by heartsome.
the class PresentationRepairer method addRange.
/**
* Adds style information to the given text presentation.
* @param presentation
* the text presentation to be extended
* @param offset
* the offset of the range to be styled
* @param length
* the length of the range to be styled
* @param textStyle
* the style of the range to be styled
*/
protected void addRange(TextPresentation presentation, int offset, int length, TextStyle textStyle) {
if (textStyle != null) {
StyleRange styleRange = new StyleRange(textStyle);
styleRange.start = offset;
styleRange.length = length;
presentation.addStyleRange(styleRange);
}
}
use of org.eclipse.swt.custom.StyleRange in project otertool by wuntee.
the class SmaliLineStyler method lineGetStyle.
public void lineGetStyle(LineStyleEvent event) {
boolean midStyle = false;
int start = 0;
char terminator = ';';
char lastChar = '~';
List<StyleRange> styles = new LinkedList<StyleRange>();
// styles.add(new StyleRange(event.lineOffset, event.lineText.length(), colorMap.get("comment"), null));
StyleRange x = new StyleRange();
StyleRange style = null;
for (int i = 0; i < event.lineText.length(); i++) {
char subj = event.lineText.charAt(i);
if (midStyle == false) {
if (subj == '#') {
logger.debug("Comment");
style = new StyleRange();
style.start = event.lineOffset + i;
style.foreground = colorMap.get("comment");
midStyle = true;
start = i;
} else if (subj == '"' || subj == '\'') {
logger.debug("Quote");
style = new StyleRange();
style.start = event.lineOffset + i;
style.foreground = colorMap.get("quote");
midStyle = true;
start = i;
} else if (subj == ':' && lastChar == ' ') {
logger.debug("Colon");
style = new StyleRange();
style.start = event.lineOffset + i;
style.foreground = colorMap.get("colon");
terminator = ' ';
midStyle = true;
start = i;
} else if (subj == '.') {
logger.debug("Dot");
style = new StyleRange();
style.start = event.lineOffset + i;
style.foreground = colorMap.get("dot");
terminator = ' ';
midStyle = true;
start = i;
}
} else {
if (i == event.lineText.length() - 1) {
style.length = event.lineText.length() - start;
styles.add(style);
logger.debug("Adding: start: " + style.start + ", length = " + style.length);
midStyle = false;
start = 0;
} else {
if (subj == ';') {
//styles.add(style);
//style = null;
//midStyle = false;
} else if (subj == '"' || subj == '\'') {
style.length = i - start;
styles.add(style);
logger.debug("Adding: start: " + style.start + ", length = " + style.length);
midStyle = false;
start = 0;
terminator = ';';
} else if (subj == '}' || subj == ',') {
style.length = i - start;
styles.add(style);
logger.debug("Adding: start: " + style.start + ", length = " + style.length);
midStyle = false;
start = 0;
terminator = ';';
} else if (subj == terminator) {
style.length = i - start;
styles.add(style);
logger.debug("Adding: start: " + style.start + ", length = " + style.length);
midStyle = false;
start = 0;
terminator = ';';
}
}
}
lastChar = subj;
}
if (style != null) {
styles.add(style);
}
event.styles = (StyleRange[]) styles.toArray(new StyleRange[0]);
}
use of org.eclipse.swt.custom.StyleRange in project tdi-studio-se by Talend.
the class DebugProcessTosComposite method doAppendToConsole.
private void doAppendToConsole(final IProcessMessage message) {
if (consoleText.isDisposed()) {
return;
}
// see feature 0004895: Font size of the output console are very small
setConsoleFont();
//$NON-NLS-1$
String[] rows = message.getContent().split("\n");
int rowLimit = getConsoleRowLimit();
String content = null;
if (rowLimit != SWT.DEFAULT) {
int currentRows = consoleText.getLineCount();
// if (consoleText.getText().equals("")) {
currentRows--;
// }
if (currentRows >= rowLimit) {
return;
} else if (currentRows + rows.length <= rowLimit) {
content = message.getContent();
} else {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < rowLimit - currentRows; i++) {
//$NON-NLS-1$
sb.append(rows[i]).append("\n");
}
content = sb.toString();
}
}
if (content == null) {
content = message.getContent();
}
StyleRange style = new StyleRange();
style.start = consoleText.getText().length();
String[] contents = content.split("\n");
for (String content2 : contents) {
if (isPattern(content2) || isPatternFor(content2)) {
//$NON-NLS-1$
consoleText.append("");
//$NON-NLS-1$
content = "";
} else {
consoleText.append(content2);
consoleText.append("\n");
}
}
style.length = content.length();
if (message.getType() == MsgType.CORE_OUT || message.getType() == MsgType.CORE_ERR) {
style.fontStyle = SWT.ITALIC;
}
Color color;
switch((MsgType) message.getType()) {
case CORE_OUT:
color = getDisplay().getSystemColor(SWT.COLOR_BLUE);
break;
case CORE_ERR:
color = getDisplay().getSystemColor(SWT.COLOR_DARK_RED);
break;
case STD_ERR:
color = getDisplay().getSystemColor(SWT.COLOR_RED);
break;
case STD_OUT:
default:
color = getDisplay().getSystemColor(SWT.COLOR_BLACK);
break;
}
style.foreground = color;
// added by hyWang for bug 0007411
if ((style.start + style.length) > consoleText.getCharCount()) {
style.length = consoleText.getCharCount() - style.start;
}
consoleText.setStyleRange(style);
}
Aggregations