 |
Crossfire JXClient, Trunk
|
Go to the documentation of this file.
23 package com.realtime.crossfire.jxclient.gui.log;
32 import java.awt.Color;
33 import java.awt.Graphics;
34 import java.awt.Graphics2D;
35 import java.awt.GraphicsEnvironment;
36 import java.awt.Image;
37 import java.awt.Toolkit;
38 import java.awt.datatransfer.Clipboard;
39 import java.awt.datatransfer.StringSelection;
40 import java.awt.datatransfer.Transferable;
41 import java.awt.event.ActionListener;
42 import java.awt.event.MouseEvent;
43 import java.awt.font.FontRenderContext;
44 import java.awt.image.BufferedImage;
45 import java.util.List;
46 import javax.swing.Timer;
47 import org.jetbrains.annotations.NotNull;
48 import org.jetbrains.annotations.Nullable;
102 private final Clipboard
clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
109 private final Clipboard
selection = Toolkit.getDefaultToolkit().getSystemSelection();
149 @SuppressWarnings(
"FieldCanBeLocal")
153 public void stateChanged() {
161 public int getHeight() {
162 return Math.max(1,
GUILog.this.getHeight());
174 public void lineAdded() {
179 public void lineReplaced() {
184 public void linesRemoved(@NotNull
final List<Line> lines) {
185 final int endPosition = lines.get(lines.size()-1).getEndPosition();
213 final FontRenderContext context;
214 final GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
215 final Graphics2D g = graphicsEnvironment.createGraphics(
new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB));
217 context = g.getFontRenderContext();
236 super.paintComponent(g);
238 g.setColor(
new Color(0, 0, 0, 0.0f));
239 g.fillRect(0, 0, getWidth(), getHeight());
250 if (y >= getHeight()) {
253 final int height = line.getHeight();
278 }
else if (distance > 0) {
315 public void setBounds(
final int x,
final int y,
final int width,
final int height) {
316 super.setBounds(x, y, width, height);
323 super.mousePressed(e);
325 if (
timer.isRunning()) {
333 super.mouseReleased(e);
335 if (
timer.isRunning()) {
343 super.mouseDragged(e);
347 if (!
timer.isRunning()) {
351 }
else if (e.getY() >= getHeight()) {
353 if (!
timer.isRunning()) {
359 if (
timer.isRunning()) {
367 super.mouseWheelMoved(wheelRotation);
450 if (this.selection !=
null) {
452 this.selection.setContents(
selection,
null);
453 }
catch (
final IllegalStateException ignored) {
458 }
catch (
final IllegalStateException ignored) {
void mouseDragged(@NotNull final MouseEvent e)
Will be called when the mouse moves within this component while the button is pressed.
boolean scrollForwards
The scrolling direction during auto-scrolling:
void mouseWheelMoved(final int wheelRotation)
Will be called when the mouse wheel has been moved.
void setBounds(final int x, final int y, final int width, final int height)
Interface for listeners for changes of Buffer contents.
boolean canScroll(final int distance)
Returns whether scrolling is possible.
int getEndPosition()
Returns the buffer position of the first character below the visible area.
void setHeight(final int height)
Sets the viewable height in pixel.
Abstract base class for gui elements implementing text fields.
Buffer getBuffer()
Returns the Buffer instance containing the text messages.
int beginSelection
The first selected character.
final BufferListener bufferListener
The BufferListener attached to buffer.
void resetScroll()
Resets the scrolling range to default values.
void mouseReleased(@NotNull final MouseEvent e)
Will be called when the user has released the mouse.
void mousePressed(@NotNull final MouseEvent e)
Will be called when the user has pressed the mouse inside this element.
void addBufferListener(@NotNull final BufferListener listener)
Adds a listener to notify of changes.
void setChanged()
Records that the contents have changed and must be repainted.
Abstract base class for GUI elements to be shown in Guis.
String getText(final int beginSelection, final int endSelection)
Returns the selected text.
void setShowSentCommands(final boolean showSentCommands)
Sets whether commands sent to the server are shown.
final GUIElementListener elementListener
The GUIElementListener to notify.
Default Buffer implementation.
final Buffer buffer
The Buffer containing all received text messages.
final ActionListener timeoutEvent
The ActionListener for generating auto-scrolling events.
final List< Line > lines
The lines in display order.
boolean canScrollDown()
Returns whether scrolling down is possible.
int getStartPosition()
Returns the buffer position of the first visible character in the visible area.
void copy()
Performs a "copy" operation to the system clipboard.
void resetScroll()
Resets the scroll index to the default value.
A list of event listeners.
void dispose()
Destroys this instance.
Object getSyncObject()
Returns the object to synchronize on when calling lines(int).
Interface for listeners interested in changes of a RenderStateManager instance.
final RenderStateListener renderStateListener
The RenderStateListener attached to renderStateManager.
boolean canScrollUp()
Returns whether scrolling up is possible.
static final long serialVersionUID
The serial version UID.
void autoScroll()
Timer event for processing auto-scrolling during text selection.
Manages the contents of one text line.
int getScrollPos()
Returns the location of the view area in pixels.
static final int TIMEOUT_AUTO_SCROLL
The delay in milliseconds for automatically scrolling during text selection.
final Clipboard selection
The system selection for cut/copy/paste operations.
void setShowTimestamps(final boolean showTimestamps)
Sets whether the timestamps are shown.
static final int SCROLL_PIXEL
The number of pixels to scroll.
void addScrollableListener(@NotNull final ScrollableListener listener)
Adds a scrollable listener to be informed about changes.
Manages the contents of the contents of a log window.
final Timer timer
The Timer for auto-scrolling while selecting text.
void scrollDown(final int dy)
Scrolls down by pixels.
void scrollTo(final int y)
Scrolls to a location.
Encapsulates the state for rendering a Buffer instance.
final GuiFactory guiFactory
The global GuiFactory instance.
GUILog(@NotNull final TooltipManager tooltipManager, @NotNull final GUIElementListener elementListener, @NotNull final String name, @Nullable final Image backgroundImage, @NotNull final Fonts fonts, @NotNull final GuiFactory guiFactory)
Creates a new instance.
int endSelection
The first selected character after the selection.
void scrollTo(final int pos)
Scrolls to the given location.
void removeScrollableListener(@NotNull final ScrollableListener listener)
Removes a scrollable listener.
void removeBufferListener(@NotNull final BufferListener listener)
Removes a listener to be notified of changes.
int getTopIndex()
Returns the first line to render.
int coordinateToPosition(final int x, final int y)
Returns the text position for a coordinate.
void setRenderWidth(final int renderWidth)
Updates the width to render.
Factory for creating Gui instances.
final String name
The name of this element.
void setShowTimestamps(final boolean showTimestamps)
Sets whether timestamps are shown.
void setShowSentCommands(final boolean showSentCommands)
Sets whether the commands sent to the server should be shown.
int getTotalHeight()
Returns the total height of all lines.
int getHeight()
Returns the height of the viewable area.
int startSelection
The starting point of the selection.
void update(final int oldBufferHeight)
Updates the internal state after the buffer has changed.
final Clipboard clipboard
The clipboard for cut/copy/paste operations.
final TooltipManager tooltipManager
The TooltipManager to update.
final EventListenerList2< ScrollableListener > listeners
All listeners.
void scroll(final int distance)
Scrolls the element.
final Image backgroundImage
The background image drawn below the text contents.
final RenderStateManager renderStateManager
The rendering state.
void dispose()
Releases all allocated resources.
void setSelection(final int selection)
Updates the selection.
void scrollUp(final int dy)
Scrolls up by pixels.
int getTopOffset()
Returns the number of pixels to shift the first displayed line.
void paintComponent(@NotNull final Graphics g)
Listener for GUIElement related events.