 |
Crossfire JXClient, Trunk
|
Go to the documentation of this file.
23 package com.realtime.crossfire.jxclient.commands;
28 import java.awt.Color;
29 import java.awt.Graphics;
30 import java.awt.image.BufferedImage;
31 import java.io.IOException;
32 import java.nio.file.Path;
33 import java.nio.file.Paths;
34 import javax.imageio.ImageIO;
35 import org.jetbrains.annotations.NotNull;
75 public void execute(@NotNull
final String args) {
80 }
catch (
final IOException ex) {
81 drawInfoError(
"Failed to create screenshot filename: "+ex.getMessage());
85 file = Paths.get(args);
89 final Graphics g = image.createGraphics();
91 g.setColor(Color.black);
98 ImageIO.write(image,
"png", file.toFile());
99 }
catch (
final IOException ex) {
100 drawInfoError(
"Cannot write screenshot "+file+
": "+ex.getMessage());
102 }
catch (
final NullPointerException ignored) {
107 drawInfo(
"Saved screenshot to "+file);
114 final StringBuilder sb =
new StringBuilder();
115 sb.append(
"Creates a screenshot image\n");
117 sb.append(
"Usage: screenshot\n");
118 sb.append(
"Usage: screenshot <file>\n");
120 sb.append(
"Write the current display contents into a PNG file. ");
121 sb.append(
"If <file> is omitted, the file names 'screenshot0.png', ..., 'screenshot9.png' are used instead.\n");
122 sb.append(
"Note: If the file already exists, it is overwritten without confirmation.\n");
123 return sb.toString();
Adds encoding/decoding of crossfire protocol packets to a ServerConnection.
void execute(@NotNull final String args)
Executes the command with the given arguments.
boolean allArguments()
Returns whether all remaining commands should be included as arguments.
String getHelp()
Returns the help text for this command.
Helper class for creating file names for screenshot files.
Abstract base class for Command implementations.
ScreenshotCommand(@NotNull final JXCWindowRenderer windowRenderer, @NotNull final CrossfireServerConnection crossfireServerConnection, @NotNull final ScreenshotFiles screenshotFiles)
Creates a new instance.
int getWindowHeight()
Returns the height of the client area.
void redraw(@NotNull final Graphics g)
Paints the view into the given graphics instance.
int getWindowWidth()
Returns the width of the client area.
final JXCWindowRenderer windowRenderer
The renderer to use.
final ScreenshotFiles screenshotFiles
The ScreenshotFiles instance for creating screenshot file names.
void drawInfoError(@NotNull final String message)
Displays an error message.
Renders a Gui instance into a Frame.
Path getFile()
Returns a Path for the next screenshot file.
final CrossfireServerConnection crossfireServerConnection
The connection instance.
Implements the "screenshot" command.
void drawInfo(@NotNull final String message)
Displays a regular output message.