22 package com.realtime.crossfire.jxclient.gui.log;
30 import java.awt.Color;
31 import java.awt.Dimension;
32 import java.awt.Graphics;
33 import java.awt.Graphics2D;
34 import java.awt.GraphicsEnvironment;
35 import java.awt.Image;
36 import java.awt.Transparency;
37 import java.awt.font.FontRenderContext;
38 import java.awt.image.BufferedImage;
39 import java.util.Iterator;
40 import org.jetbrains.annotations.NotNull;
41 import org.jetbrains.annotations.Nullable;
95 @SuppressWarnings(
"FieldCanBeLocal")
99 public void stateChanged() {
107 public int getHeight() {
108 return Math.max(1,
GUILog.this.getHeight());
123 super(tooltipManager, elementListener, name, Transparency.TRANSLUCENT);
126 final FontRenderContext context;
127 final GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
128 final Graphics2D g = graphicsEnvironment.createGraphics(
new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB));
130 context = g.getFontRenderContext();
134 buffer =
new Buffer(fonts, context, getWidth());
136 renderStateManager.
setHeight(getHeight());
153 super.paintComponent(g);
155 g.setColor(
new Color(0, 0, 0, 0.0f));
156 g.fillRect(0, 0, getWidth(), getHeight());
157 if (backgroundImage != null) {
158 g.drawImage(backgroundImage, 0, 0, null);
162 final int topIndex = renderStateManager.
getTopIndex();
164 final Iterator<Line> it = buffer.
listIterator(topIndex);
165 while (y < getHeight() && it.hasNext()) {
166 final Line line = it.next();
179 private void drawLine(@NotNull
final Graphics g,
final int y, @NotNull
final Iterable<Segment> line) {
180 for (
final Segment segment : line) {
181 segment.draw(g, y, fonts);
206 renderStateManager.
scrollUp(-distance*SCROLL_PIXEL);
207 }
else if (distance > 0) {
208 renderStateManager.
scrollDown(distance*SCROLL_PIXEL);
235 listeners.
add(listener);
243 listeners.
remove(listener);
259 public void setBounds(
final int x,
final int y,
final int width,
final int height) {
260 super.setBounds(x, y, width, height);
271 return new Dimension(600, 150);
280 return new Dimension(100, 10);
Listener for GUIElement related events.
void scrollTo(final int y)
Scrolls to a location.
static final long serialVersionUID
The serial version UID.
void scrollTo(final int pos)
Scrolls to the given location.The possible range is given by a previous notification through a listen...
boolean canScrollUp()
Returns whether scrolling up is possible.
Manages the contents of one text line.
int getTotalHeight()
Returns the total height of all lines.
void addScrollableListener(@NotNull final ScrollableListener listener)
Adds a scrollable listener to be informed about changes.the listener to add
final TooltipManager tooltipManager
The TooltipManager to update.
int getTopIndex()
Returns the first line to render.
void removeScrollableListener(@NotNull final ScrollableListener listener)
Removes a scrollable listener.the listener to remove
A list of event listeners.
Dimension getMinimumSize()
void setChanged()
Records that the contents have changed and must be repainted.
int getHeight()
Returns the height of this line.
boolean canScrollDown()
Returns whether scrolling down is possible.
void scroll(final int distance)
Scrolls the element.the distance to scroll
int getTopOffset()
Returns the number of pixels to shift the first displayed line.
final RenderStateManager renderStateManager
The rendering state.
final GUIElementListener elementListener
The GUIElementListener to notify.
Object getSyncObject()
Returns the object to synchronize on when calling iterator() or listIterator(int).
final Image backgroundImage
The background image drawn below the text contents.
final String name
The name of this element.
Interface for listeners interested in changes of a RenderStateManager instance.
final Fonts fonts
The Fonts instance for looking up fonts.
GUILog(@NotNull final TooltipManager tooltipManager, @NotNull final GUIElementListener elementListener, @NotNull final String name, @Nullable final Image backgroundImage, @NotNull final Fonts fonts)
Creates a new instance.
void dispose()
Releases all allocated resources.
void setHeight(final int height)
Sets the viewable height in pixel.
final EventListenerList2< ScrollableListener > listeners
All listeners.
One segment of a Line which should be displayed without changing text attributes. ...
int getScrollPos()
Returns the location of the view area in pixels.
Buffer getBuffer()
Returns the Buffer instance containing the text messages.
void resetScroll()
Resets the scrolling range to default values.
void paintComponent(@NotNull final Graphics g)
void dispose()
Destroys this instance.
void add(@NotNull final T listener)
Adds a listener.
Encapsulates the state for rendering a Buffer instance.
void setBounds(final int x, final int y, final int width, final int height)
boolean canScroll(final int distance)
Returns whether scrolling is possible.the distance to scroll whether scrolling is possible ...
Manages the contents of the contents of a log window.
void scrollUp(final int dy)
Scrolls up by pixels.
Iterator< Line > listIterator(final int line)
Returns an Iterator for the lines in this buffer.
final Buffer buffer
The Buffer containing all received text messages.
Abstract base class for GUI elements to be shown in Guis.
void setRenderWidth(final int renderWidth)
Updates the width to render.
void remove(@NotNull final T listener)
Removes a listener.
Abstract base class for gui elements implementing text fields.
Dimension getPreferredSize()
final RenderStateListener renderStateListener
The RenderStateListener attached to renderStateManager.
void resetScroll()
Resets the scroll index to the default value.
static final int SCROLL_PIXEL
The number of pixels to scroll.
void drawLine(@NotNull final Graphics g, final int y, @NotNull final Iterable< Segment > line)
Draws one Line to a Graphics2D instance.
void scrollDown(final int dy)
Scrolls down by pixels.