Crossfire JXClient, Trunk  R20561
Line.java
Go to the documentation of this file.
1 /*
2  * This file is part of JXClient, the Fullscreen Java Crossfire Client.
3  *
4  * JXClient is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * JXClient is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with JXClient; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * Copyright (C) 2005-2008 Yann Chachkoff.
19  * Copyright (C) 2006-2011 Andreas Kirschbaum.
20  */
21 
22 package com.realtime.crossfire.jxclient.gui.log;
23 
24 import java.awt.Color;
25 import java.awt.font.FontRenderContext;
26 import java.util.ArrayList;
27 import java.util.Collections;
28 import java.util.Iterator;
29 import java.util.List;
30 import org.jetbrains.annotations.NotNull;
31 import org.jetbrains.annotations.Nullable;
32 
38 public class Line implements Iterable<Segment> {
39 
44  @NotNull
45  private final List<Segment> segments = new ArrayList<>();
46 
50  private int height = -1;
51 
61  public void addSegment(@NotNull final String text, final boolean bold, final boolean italic, final boolean underline, @NotNull final FontID font, @Nullable final Color color) {
62  segments.add(new TextSegment(text, bold, italic, underline, font, color));
63  }
64 
68  @NotNull
69  @Override
70  public Iterator<Segment> iterator() {
71  return Collections.unmodifiableList(segments).iterator();
72  }
73 
78  @Nullable
80  return segments.isEmpty() ? null : segments.get(segments.size()-1);
81  }
82 
86  public void removeLastSegment() {
87  segments.remove(segments.size()-1);
88  }
89 
95  public int getHeight() {
96  return height;
97  }
98 
103  public void setHeight(final int height) {
104  this.height = height;
105  }
106 
115  public void updateAttributes(final int begin, final int end, final int y, @NotNull final Fonts fonts, @NotNull final FontRenderContext context) {
116  for (int i = begin; i < end; i++) {
117  final Segment segment = segments.get(i);
118  segment.updateAttributes(fonts, context);
119  segment.setY(y);
120  }
121  }
122 
123 }
Manages the contents of one text line.
Definition: Line.java:38
Segment getLastSegment()
Returns the last segment.
Definition: Line.java:79
void setHeight(final int height)
Returns the height of this line.
Definition: Line.java:103
void removeLastSegment()
Removes the last segment.
Definition: Line.java:86
int height
The total height of this line.
Definition: Line.java:50
int getHeight()
Returns the height of this line.
Definition: Line.java:95
void updateAttributes(final int begin, final int end, final int y, @NotNull final Fonts fonts, @NotNull final FontRenderContext context)
Updates the cached attributes of some Segments.
Definition: Line.java:115
One segment of a Line which should be displayed without changing text attributes. ...
Definition: Segment.java:34
One segment of a Line which should be displayed without changing attributes.
void updateAttributes(@NotNull Fonts fonts, @NotNull FontRenderContext context)
Updates the cached attributes of this segment.
void addSegment(@NotNull final String text, final boolean bold, final boolean italic, final boolean underline, @NotNull final FontID font, @Nullable final Color color)
Appends a Segment to the end of the line.
Definition: Line.java:61
void setY(int y)
Sets the y-coordinate to display the segment.
final List< Segment > segments
The segments this line consists of.
Definition: Line.java:45