 |
Crossfire JXClient, Trunk
|
Go to the documentation of this file.
23 package com.realtime.crossfire.jxclient.gui.log;
25 import java.awt.Color;
27 import java.awt.Graphics;
28 import java.awt.Graphics2D;
29 import java.awt.font.FontRenderContext;
30 import java.awt.font.TextLayout;
31 import java.awt.geom.RectangularShape;
32 import java.util.Locale;
33 import org.jetbrains.annotations.NotNull;
57 private final boolean bold;
92 private final RectangularShape
size;
135 public TextSegment(@NotNull
final String
text, @NotNull
final Font
font,
final boolean bold,
final boolean italic,
final boolean underline, @NotNull
final FontID fontID, @NotNull
final Color
color, @NotNull
final RectangularShape
size,
final int ascentOffset,
final int underlineOffset, @NotNull
final Color
selectionColor) {
183 if (positions < 0 &&
position+positions < 0) {
184 throw new IllegalArgumentException(
"cannot shift segment position "+
position+
" by "+positions);
210 return (
int)Math.round(
size.getWidth());
219 public int getWidth(
final int chars, @NotNull
final FontRenderContext context) {
220 return (
int)
font.getStringBounds(
text.substring(0, chars), context).getWidth();
228 return (
int)Math.round(
size.getHeight());
238 public void draw(@NotNull
final Graphics2D g,
final int y,
final int beginSelection,
final int endSelection) {
240 final int beginIndex = Math.max(0, beginSelection-
position);
241 final int endIndex = Math.min(
text.length(), endSelection-
position);
242 final int beginX = beginIndex == 0 ? 0 : (int)Math.round(
new TextLayout(
text.substring(0, beginIndex),
font, g.getFontRenderContext()).getBounds().getWidth());
243 final int endX = endIndex >=
text.length() ?
getWidth() : (int)Math.round(
new TextLayout(
text.substring(0, endIndex),
font, g.getFontRenderContext()).getBounds().getWidth());
250 g.drawString(
text,
x,
y+this.y);
282 final StringBuilder sb =
new StringBuilder();
283 sb.append(
"segment:");
288 sb.append(
"(italic)");
291 sb.append(
"(underline)");
294 sb.append(
'(').append(
fontID.toString().toLowerCase(Locale.ENGLISH)).append(
')');
299 return sb.toString();
308 return "["+
x+
","+
y+
","+
text+
"]";
317 public void appendSelection(@NotNull
final StringBuilder sb,
final int beginSelection,
final int endSelection) {
318 final int beginIndex = Math.min(Math.max(0, beginSelection-
position),
text.length());
319 final int endIndex = Math.min(Math.max(0, endSelection-
position),
text.length());
320 sb.append(
text, beginIndex, endIndex);
String getText()
Returns the text to display.
void draw(@NotNull final Graphics2D g, final int y, final int beginSelection, final int endSelection)
Draws this segment to a Graphics instance.
int x
The x-coordinate to display the segment.
RectangularShape getSize()
Returns the size of this segment in pixels.
void appendSelection(@NotNull final StringBuilder sb, final int beginSelection, final int endSelection)
Appends the selected text to a StringBuilder instance.
Parser for parsing drawextinfo messages received from a Crossfire server to update a Buffer instance.
String format()
Returns a string representation of this text segment.
int getX()
Returns the x-coordinate to display the segment.
One segment of a Line which should be displayed without changing attributes.
static String toString(@NotNull final Color color)
Returns the string representation for a color.
final int underlineOffset
The distance of the underline from the top of the segment.
final boolean italic
Whether italic face is enabled.
final Font font
The font of text.
int getPosition()
Returns the absolute position of the first character.
int getHeight()
Returns the height to display the segment.
final RectangularShape size
The size of this segment in pixels.
int getWidth(final int chars, @NotNull final FontRenderContext context)
Returns the display width of a prefix of this segment's text.
final FontID fontID
The font to use.
TextSegment(@NotNull final String text, @NotNull final Font font, final boolean bold, final boolean italic, final boolean underline, @NotNull final FontID fontID, @NotNull final Color color, @NotNull final RectangularShape size, final int ascentOffset, final int underlineOffset, @NotNull final Color selectionColor)
Creates a new segment.
void setExtends(final int x, final int y, final int position)
Sets the extends to display the segment.
final int ascentOffset
The distance of the ascent from the top of the segment.
int position
The absolute position of the first character.
final Color selectionColor
The background color for the selection.
final Color color
The color to use.
int y
The y-coordinate to display the segment.
final boolean underline
Whether underlining is enabled.
final boolean bold
Whether bold face is enabled.
final String text
The text to display.
int getY()
Returns the y-coordinate to display the segment.
void updatePosition(final int positions)
Shifts the position of this line.
int getWidth()
Returns the width to display the segment.
boolean matches(final boolean bold, final boolean italic, final boolean underline, @NotNull final FontID fontID, @NotNull final Color color, @NotNull final Color selectionColor)
Returns whether this segment matches the given attributes.