|
java-gnome version 4.0.19 | ||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Objectorg.freedesktop.bindings.Pointer
org.freedesktop.bindings.Proxy
org.gnome.glib.Object
org.gnome.gtk.TextTag
public class TextTag
TextTags are used to apply markup and formatting for regions of text in a TextBuffer.
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 Summary | |
---|---|
TextTag()
Create a new TextTag and place it in the default TextTagTable. |
|
TextTag(TextTagTable table)
Create a new TextTag. |
Method Summary | |
---|---|
void |
setBackground(String colour)
Specify the background colour via a String description. |
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 |
setLeftMargin(int pixels)
Specify the left margin, in pixels. |
void |
setRightMargin(int pixels)
Specify the right margin, in pixels. |
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)
Specify the font style to be used ( NORMAL ,
OBLIQUE and
ITALIC s). |
void |
setUnderline(Underline underline)
Specify the underling mode to be used for this text. |
void |
setWeight(Weight weight)
Specify the font weight. |
String |
toString()
|
Methods inherited from class Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public TextTag()
no-arg
constructor.
public TextTag(TextTagTable table)
In native GTK you have to add TextTags to TextTagTables; we do this for you automatically.
Method Detail |
---|
public void setBackground(String colour)
See setForeground()
for discussion of
allowable colour names.
The default is no explicit setting.
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 setLeftMargin(int pixels)
0
.
public void setRightMargin(int pixels)
0
.
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)
NORMAL
,
OBLIQUE
and
ITALIC
s).
public void setUnderline(Underline underline)
SINGLE
.
NONE
is the default, obviously.
public void setWeight(Weight weight)
BOLD
; the default is
NORMAL
.
public String toString()
toString
in class org.freedesktop.bindings.Pointer
|
![]() java-gnome |
||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |