|
@ -1,6 +1,9 @@ |
|
|
package de.sogomn.rat.server.gui; |
|
|
package de.sogomn.rat.server.gui; |
|
|
|
|
|
|
|
|
|
|
|
import java.awt.Point; |
|
|
import java.awt.event.ActionEvent; |
|
|
import java.awt.event.ActionEvent; |
|
|
|
|
|
import java.awt.event.MouseAdapter; |
|
|
|
|
|
import java.awt.event.MouseEvent; |
|
|
|
|
|
|
|
|
import javax.swing.JFrame; |
|
|
import javax.swing.JFrame; |
|
|
import javax.swing.JMenuItem; |
|
|
import javax.swing.JMenuItem; |
|
@ -15,12 +18,14 @@ public final class RattyGui { |
|
|
|
|
|
|
|
|
private JTable table; |
|
|
private JTable table; |
|
|
private DefaultTableModel tableModel; |
|
|
private DefaultTableModel tableModel; |
|
|
|
|
|
private long lastIdClicked; |
|
|
|
|
|
|
|
|
private JPopupMenu menu; |
|
|
private JPopupMenu menu; |
|
|
|
|
|
|
|
|
private IGuiController controller; |
|
|
private IGuiController controller; |
|
|
|
|
|
|
|
|
private static final String[] HEADERS = { |
|
|
private static final String[] HEADERS = { |
|
|
|
|
|
"ID", |
|
|
"Name", |
|
|
"Name", |
|
|
"IP address", |
|
|
"IP address", |
|
|
"OS", |
|
|
"OS", |
|
@ -30,7 +35,14 @@ public final class RattyGui { |
|
|
public static final String POPUP = "Popup"; |
|
|
public static final String POPUP = "Popup"; |
|
|
public static final String SCREENSHOT = "Screenshot"; |
|
|
public static final String SCREENSHOT = "Screenshot"; |
|
|
public static final String KEY_EVENT = "Key event"; |
|
|
public static final String KEY_EVENT = "Key event"; |
|
|
public static final String[] ACTION_COMMANDS = {POPUP, SCREENSHOT, KEY_EVENT}; |
|
|
|
|
|
|
|
|
public static final String FREE = "Free"; |
|
|
|
|
|
|
|
|
|
|
|
public static final String[] ACTION_COMMANDS = { |
|
|
|
|
|
POPUP, |
|
|
|
|
|
SCREENSHOT, |
|
|
|
|
|
KEY_EVENT, |
|
|
|
|
|
FREE |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
public RattyGui() { |
|
|
public RattyGui() { |
|
|
frame = new JFrame(); |
|
|
frame = new JFrame(); |
|
@ -41,13 +53,26 @@ public final class RattyGui { |
|
|
for (final String command : ACTION_COMMANDS) { |
|
|
for (final String command : ACTION_COMMANDS) { |
|
|
final JMenuItem item = new JMenuItem(command); |
|
|
final JMenuItem item = new JMenuItem(command); |
|
|
|
|
|
|
|
|
item.addActionListener(this::actionPerformed); |
|
|
|
|
|
|
|
|
item.setActionCommand(command); |
|
|
|
|
|
item.addActionListener(this::menuItemClicked); |
|
|
|
|
|
|
|
|
menu.add(item); |
|
|
menu.add(item); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
final MouseAdapter mouseAdapter = new MouseAdapter() { |
|
|
|
|
|
@Override |
|
|
|
|
|
public void mousePressed(final MouseEvent m) { |
|
|
|
|
|
final Point mousePoint = m.getPoint(); |
|
|
|
|
|
final int row = table.rowAtPoint(mousePoint); |
|
|
|
|
|
|
|
|
|
|
|
lastIdClicked = (Long)tableModel.getValueAt(row, 0); |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
tableModel.setColumnIdentifiers(HEADERS); |
|
|
tableModel.setColumnIdentifiers(HEADERS); |
|
|
table.setEnabled(false); |
|
|
table.setEnabled(false); |
|
|
table.setComponentPopupMenu(menu); |
|
|
table.setComponentPopupMenu(menu); |
|
|
|
|
|
table.addMouseListener(mouseAdapter); |
|
|
|
|
|
|
|
|
final JScrollPane scrollPane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); |
|
|
final JScrollPane scrollPane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); |
|
|
|
|
|
|
|
@ -59,14 +84,42 @@ public final class RattyGui { |
|
|
frame.requestFocus(); |
|
|
frame.requestFocus(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void actionPerformed(final ActionEvent a) { |
|
|
|
|
|
|
|
|
private void menuItemClicked(final ActionEvent a) { |
|
|
|
|
|
if (controller == null) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
final String command = a.getActionCommand(); |
|
|
final String command = a.getActionCommand(); |
|
|
|
|
|
|
|
|
controller.userInput(command); |
|
|
controller.userInput(command); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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}; |
|
|
|
|
|
|
|
|
|
|
|
tableModel.addRow(data); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void removeRow(final long id) { |
|
|
|
|
|
final int rows = tableModel.getRowCount(); |
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < rows; i++) { |
|
|
|
|
|
final long rowId = (Long)tableModel.getValueAt(i, 0); |
|
|
|
|
|
|
|
|
|
|
|
if (rowId == id) { |
|
|
|
|
|
tableModel.removeRow(i); |
|
|
|
|
|
|
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public void setController(final IGuiController controller) { |
|
|
public void setController(final IGuiController controller) { |
|
|
this.controller = controller; |
|
|
this.controller = controller; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public long getLastIdClicked() { |
|
|
|
|
|
return lastIdClicked; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |