Text Decoration
Text Decoration
Text decoration is a necessary feature for the Code Editor. Let's take a look at the application of text decoration in the Java editor:
Figure 1. Text decorations in the Java editor
You can see that the Java editor marks the wrong part with a wavy red line, and you can see that for the template, there is a small rectangle around the template parameter, and a corresponding error icon appears on the left. These are called text decorations.
Tip: Templates will be introduced in future articles
When we edit the code, error is unavoidable, so with the text decoration function, we can quickly find the wrong location, which is very useful for code editing. Here's a look at the concepts you need to know to implement the text decoration feature.
Annotation
The term Annotation has been used very well, and is seen in many places, such as the concept of Annotation in J2SE 5.0. In the case of JTF, annotations refer to specific information that is bound to a block of text area, and can be customized for specific information. You can look at the Annotation class in JTF, see it has type information, have additional textual information, and it has many subclasses, and subclasses also contain some extended information.
It is important to note that the annotation contains the type information, through the type, you can know the purpose and function of a callout, and then it can be reflected in the interface. The red wavy line in Figure 1 is actually a callout with the wrong type in that position.
Ruler
A Ruler (ruler) is an area that displays auxiliary information, which is generally attached to the surrounding editor. For example, the two icons in Figure 1 that represent errors are displayed on the Verticalruler (vertical ruler). There can be more than one ruler, and in Figure 1 you can see another ruler that shows the line number, and how many rulers are required to customize it.
Iannotationpresentation
The name inside with "presentation" the words are related to the interface rendering, and iannotationpresentation is used to render the annotation. This interface is only responsible for drawing the callout on the ruler, and the icon in Figure 1 that represents the error is from here. If your own defined annotation does not implement this interface, then it will not appear on the ruler.