... | ... | @@ -49,10 +49,10 @@ This editor is fully event based, since time does not make sense in this scenari |
|
|
Writing such a component is not extremely hard but also requires some thinking. By no means i expect the code which im going to show here to be perfect, but i dont think it is extremely poor either. When writing a widget one needs to think of everything this widget should be capable of, we can list all those things as tasks:
|
|
|
|
|
|
* changing the display based on the input
|
|
|
* Managing horizontal and vertical scrollbars if required
|
|
|
* Displaying a mouse cursor in the correct shape as long as it is located over the editor
|
|
|
* Displaying the text in different Fonts (that is the type, its size and styling)
|
|
|
* Allowing the user to wrap the editor lines, based on the current size of the widget
|
|
|
* Managing horizontal and vertical scrollbars if required
|
|
|
* Managing the caret and displaceing it whenever a click happens to a different location
|
|
|
|
|
|
|
... | ... | @@ -138,3 +138,33 @@ This method is yet again very simple in itself. At first it saves the input, the |
|
|
|
|
|
```
|
|
|
|
|
|
We leave the method ```initData()``` for later, it is used to initialize Objects that are used in this widget. Teh next important method we need to check is the method ```initEventHandler()``` which is partly discussed in the next section.
|
|
|
|
|
|
## Managing horizontal and vertical scrollbars if required
|
|
|
|
|
|
If one inspects the code of ```initEventHandler()``` one can directly see the handling of the scrollbars.
|
|
|
|
|
|
```java
|
|
|
private void initEventHandler() {
|
|
|
|
|
|
// listener to the vertical bar
|
|
|
if (this.getVerticalBar() != null) {
|
|
|
vBar = this.getVerticalBar();
|
|
|
vBar.addListener(SWT.Selection, e -> {
|
|
|
this.topLineOffset = vBar.getSelection();
|
|
|
drawWidget();
|
|
|
});
|
|
|
vBar.setVisible(false);
|
|
|
}
|
|
|
|
|
|
//listener to the horizontal bar
|
|
|
if (this.getHorizontalBar() != null) {
|
|
|
hBar = this.getHorizontalBar();
|
|
|
hBar.addListener(SWT.Selection, e -> {
|
|
|
this.leftMostPosition = hBar.getSelection();
|
|
|
drawWidget();
|
|
|
});
|
|
|
hBar.setVisible(false);
|
|
|
}
|
|
|
|
|
|
``` |