1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
/**
* Creates the content of the dialog
* @param shell
*/
private void createContents(final Shell shell) {
shell.setLayout(null);
final StyledText textarea = new StyledText(shell,SWT.MULTI);
// Add the syntax coloring handler
textarea.addExtendedModifyListener(new ExtendedModifyListener() {
public void modifyText(ExtendedModifyEvent event) {
// Determine the ending offset
int end = event.start + event.length - 1;
// If they typed something, get it
if (event.start > 0) {
String text = textarea.getText();
// Create a collection to hold the StyleRanges
java.util.List ranges = new java.util.ArrayList();
int startIndex = 0;
int indexOfEndingChar = 0;
int endIndex = text.lastIndexOf('>');
int tmpIndex = 0;
boolean stop = false;
while(!stop) {
tmpIndex =+ startIndex + indexOfEndingChar;
startIndex =+ text.indexOf("<",tmpIndex);
int length = 0;
if (startIndex > -1) {
indexOfEndingChar = text.indexOf(">",startIndex);
if (indexOfEndingChar > -1) {
length = indexOfEndingChar - startIndex;
ranges.add(new StyleRange(startIndex, length + 1, green, null, SWT.BOLD));
}
}
if (tmpIndex >= endIndex || tmpIndex <= -1) {
stop = true;
}
}
// If we have any ranges to set, set them
if (!ranges.isEmpty()) {
StyleRange [] styleRanges = new StyleRange[ranges.size()];
for (int i = 0; i < ranges.size();i++) {
Object o = ranges.get(i);
StyleRange styleRange = (StyleRange) o;
styleRanges[i] = styleRange;
}
textarea.setStyleRanges(styleRanges);
}
}
}
});
textarea.setText(this.property.getValue());
textarea.setBounds(0, 0, 450, 300);
final Button okButton = new Button(shell, SWT.NONE);
okButton.setBounds(0, 330, 80, 20);
okButton.setText("Ok");
okButton.setSelection(true);
Listener listener = new Listener() {
public void handleEvent(Event event) {
if (event.widget == okButton) {
text = textarea.getText();
dialog.close();
}
}};
okButton.addListener(SWT.Selection, listener);
final Button cancelButton = new Button(shell, SWT.NONE);
cancelButton.setBounds(370, 330, 80, 20);
cancelButton.setText("Cancel");
Listener listenerCancel = new Listener() {
public void handleEvent(Event event) {
if (event.widget == cancelButton) {
dialog.close();
}
}};
cancelButton.addListener(SWT.Selection, listenerCancel);
} |
Partager