public class TextTag extends Object
All TextTags belong to a TextTagTable, and likewise all TextBuffers are constructed by specifying the TextTagTable that it will draw tags from. That said, if you don't mind sharing your TextTags between all TextBuffers in your application, then you can use the no-arg convenience constructors here and in TextBuffer. We will in all our examples.
You can create a new and unique TextTag every time you go to apply formatting, but in general you'll want to reuse them and that will be more efficient. Given:
TextTag bold; TextBuffer buffer; TextIter start, end, pointer; ...and assuming the TextBuffer was created with the no-arg constructor, create a TextTag and apply some formatting:
bold = new TextTag(); bold.setWeight(Weight.BOLD); ...As you will see, there are any number of properties and font characteristics that can be applied with a tag. See the setter methods on this class for all the current possibilities.
Now, to make use of the tag, you'll call TextBuffer's
applyTag()
. It
needs a pair of TextIters to delineate the range you want to apply the
TextTag to. You could, for example, react to the currently selected region:
start = buffer.getSelectionBound().getIter(); end = buffer.getInsert().getIter();And now apply your tag:
buffer.applyTag(bold, start, end);As an alternative, you can apply a TextTag when
insert()
ing text:
buffer.insert(pointer, "Hello World", bold);Either way, going forward, you've now got
bold
which you can
apply on other regions of your TextBuffer.
Finally, if you want to know what TextTags are applying at a given spot in
a TextBuffer, then get a TextIter pointing there and use its
getTags()
method.
All TextTags created in java-gnome are "anonymous"; the underlying library has a notion of named tags but we have no need of this and have not exposed it. In order to reuse a TextTag later just keep a reference to it.
Constructor and Description |
---|
TextTag()
Create a new TextTag and place it in the default TextTagTable.
|
TextTag(String name)
Create a new TextTag and place it in the default TextTagTable.
|
TextTag(TextTagTable table)
Create a new TextTag.
|
TextTag(TextTagTable table,
String name) |
Modifier and Type | Method and Description |
---|---|
void |
setBackground(String color)
Specify the background colour via a String description.
|
void |
setBackgroundFullHeight(boolean setting)
Does the background colouring specified by
setBackground() fills the entire line
height or only the height of the tagged characters. |
void |
setEditable(boolean setting)
Set whether the region of text covered by this TextTag is editable by
the user.
|
void |
setFamily(String font)
Specify the font family to be used.
|
void |
setFont(String str)
Pass a string that describes the font you wish to use.
|
void |
setFontDescription(FontDescription desc)
Pass a FontDescription specifying the metrics and characteristics of
the font you wish to be active when this TextTag is applied.
|
void |
setForeground(String colour)
Specify the foreground colour by name.
|
void |
setIndent(int pixels)
Specify the amount by which this paragraph is to be indented, in
pixels.
|
void |
setInvisible(boolean setting)
Hide the text formatted with this TextTag.
|
void |
setJustify(Justification setting)
Adopt the given justification for a given passage of text.
|
void |
setMarginLeft(int pixels)
Specify the left margin, in pixels.
|
void |
setMarginRight(int pixels)
Specify the right margin, in pixels.
|
void |
setPaddingAboveParagraph(int pixels)
Set the padding that will be put above each paragraph of text.
|
void |
setPaddingBelowParagraph(int pixels)
Set the padding that will be put below each paragraph of text.
|
void |
setPaddingInsideParagraph(int pixels)
Set the padding that will be put between each line in a paragraph if
wrapping is turned on.
|
void |
setParagraphBackground(String color)
Specify the background colour to be used by the [rectangular] space
behind the current paragraph as a whole?
|
void |
setRise(double rise)
Indicate that a span of characters is to be positioned at other than
the baseline.
|
void |
setScale(Scale scale)
Specify that you want the text scaled up or scaled down from the
otherwise extant font size.
|
void |
setSize(double size)
Set the font size, in points.
|
void |
setStrikethrough(boolean setting)
Specify that this text be rendered struck through.
|
void |
setStyle(Style style)
|
void |
setUnderline(Underline underline)
Specify the underling mode to be used for this text.
|
void |
setWeight(Weight weight)
Specify the font weight.
|
void |
setWrapMode(WrapMode mode)
Set the wrapping to be applied within this section of text.
|
String |
toString() |
public TextTag()
no-arg
constructor.public TextTag(String name)
name
has no particular effect but can be helpful
for debugging. Otherwise just use TextTag <init>()
.public TextTag(TextTagTable table)
In native GTK you have to add TextTags to TextTagTables; we do this for you automatically.
public TextTag(TextTagTable table, String name)
public void setBackground(String color)
See setForeground()
for discussion of
allowable colour names.
The default is no explicit setting.
public void setBackgroundFullHeight(boolean setting)
setBackground()
fills the entire line
height or only the height of the tagged characters.public void setEditable(boolean setting)
public void setFamily(String font)
In general, it is better to use the standard aliases "Serif", "Sans",
and "Monospaced" than naming a family by hand as this lets the user
assign their own meanings to those terms via the Fonts tab in
gnome-appearance-properties
.
Note that you need to specify this early; if you set this after setting other propertes on the TextTag, it may reset them.
public void setFont(String str)
<init>(String)
constructor; see there for details of the syntax
allowed.public void setFontDescription(FontDescription desc)
public void setForeground(String colour)
Colours can be specified either:
"#rrggbb"
where
rr
, gg
, and
bb
are two hexadecimal characters expressing a
values between 0x00
and 0xFF
for red, green,
and blue respectively; or
"blue"
and
"medium sea green"
, depending on what constants have been
built into your X server. You can likely see a list at
/usr/share/X11/rgb.txt
. Obviously these are unreliable
between different systems, but they are undeniably easy to use.
The default is no explicit setting.
public void setIndent(int pixels)
0
.public void setInvisible(boolean setting)
FIXME what happens when you insert at a point that is marked invisible?
Backspace into it? What is the interaction with the editable
property and insertInteractive()
?
GTK further notes there are problems with invisible text and programmatic navigation of TextBuffers.
public void setJustify(Justification setting)
public void setMarginLeft(int pixels)
0
.public void setMarginRight(int pixels)
0
.public void setPaddingAboveParagraph(int pixels)
setPaddingAboveParagraph()
.public void setPaddingBelowParagraph(int pixels)
setPaddingBelowParagraph()
.public void setPaddingInsideParagraph(int pixels)
setPaddingInsideParagraph()
.public void setParagraphBackground(String color)
setBackground()
which sets the
background colour of of just the text itself.public void setRise(double rise)
The measurement is in points. A negative number will take you below the baseline.
Be aware that whenever non-uniform sizing is used on a line, the TextView will render that line as higher than the other lines in a document. This can often be an unwanted (but hard to trivially avoid) side-effect.
See also RiseAttribute
which is
the underlying mechanism which powers this in Pango.
public void setScale(Scale scale)
NORMAL
(that is, a scaling factor
of 1.0
which thereby has no effect).public void setSize(double size)
public void setStrikethrough(boolean setting)
public void setStyle(Style style)
public void setUnderline(Underline underline)
SINGLE
.
NONE
is the default, obviously.public void setWeight(Weight weight)
public void setWrapMode(WrapMode mode)
public String toString()
toString
in class org.freedesktop.bindings.Pointer