From 4b632bdd23cbfc59ccbdabc653b333d0d535635f Mon Sep 17 00:00:00 2001 From: StevenLawson Date: Sun, 17 Aug 2014 14:13:01 -0400 Subject: [PATCH] Added copy name/ip on popup menu. --- .../BukkitTelnetClient/BTC_MainPanel.java | 75 ++++++++++++++++--- 1 file changed, 63 insertions(+), 12 deletions(-) diff --git a/src/main/java/me/StevenLawson/BukkitTelnetClient/BTC_MainPanel.java b/src/main/java/me/StevenLawson/BukkitTelnetClient/BTC_MainPanel.java index fc2fc0d..123bb4e 100644 --- a/src/main/java/me/StevenLawson/BukkitTelnetClient/BTC_MainPanel.java +++ b/src/main/java/me/StevenLawson/BukkitTelnetClient/BTC_MainPanel.java @@ -2,6 +2,7 @@ package me.StevenLawson.BukkitTelnetClient; import java.awt.EventQueue; import java.awt.Toolkit; +import java.awt.datatransfer.StringSelection; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyAdapter; @@ -244,29 +245,38 @@ public class BTC_MainPanel extends javax.swing.JFrame } } - public static final class CommandMenuItem extends JMenuItem + public static class PlayerListPopupItem extends JMenuItem { - private final ServerCommand command; private final PlayerInfo player; - public CommandMenuItem(String text, ServerCommand command, PlayerInfo player) + public PlayerListPopupItem(String text, PlayerInfo player) { super(text); - this.command = command; this.player = player; } - public ServerCommand getCommand() - { - return command; - } - public PlayerInfo getPlayer() { return player; } } + public static class PlayerListPopupItem_Command extends PlayerListPopupItem + { + private final ServerCommand command; + + public PlayerListPopupItem_Command(String text, PlayerInfo player, ServerCommand command) + { + super(text, player); + this.command = command; + } + + public ServerCommand getCommand() + { + return command; + } + } + public final void setupTablePopup() { this.tblPlayers.addMouseListener(new MouseAdapter() @@ -310,25 +320,61 @@ public class BTC_MainPanel extends javax.swing.JFrame public void actionPerformed(ActionEvent actionEvent) { Object _source = actionEvent.getSource(); - if (_source instanceof CommandMenuItem) + if (_source instanceof PlayerListPopupItem_Command) { - final CommandMenuItem source = (CommandMenuItem) _source; + final PlayerListPopupItem_Command source = (PlayerListPopupItem_Command) _source; + final PlayerInfo _player = source.getPlayer(); final ServerCommand _command = source.getCommand(); + final String output = String.format(_command.getCommandFormat(), _player.getName()); BTC_MainPanel.this.connectionManager.sendDelayedCommand(output, true, 100); } + else if (_source instanceof PlayerListPopupItem) + { + final PlayerListPopupItem source = (PlayerListPopupItem) _source; + + final PlayerInfo _player = source.getPlayer(); + + switch (actionEvent.getActionCommand()) + { + case "Copy IP": + { + copyToClipboard(_player.getIp()); + BTC_MainPanel.this.writeToConsole("Copied IP to clipboard: " + _player.getIp()); + break; + } + case "Copy Name": + { + copyToClipboard(_player.getName()); + BTC_MainPanel.this.writeToConsole("Copied name to clipboard: " + _player.getName()); + break; + } + } + } } }; for (final ServerCommand command : ServerCommand.values()) { - final CommandMenuItem item = new CommandMenuItem(command.getCommandName(), command, player); + final PlayerListPopupItem_Command item = new PlayerListPopupItem_Command(command.getCommandName(), player, command); item.addActionListener(popupAction); popup.add(item); } + popup.addSeparator(); + + JMenuItem item; + + item = new PlayerListPopupItem("Copy Name", player); + item.addActionListener(popupAction); + popup.add(item); + + item = new PlayerListPopupItem("Copy IP", player); + item.addActionListener(popupAction); + popup.add(item); + popup.show(mouseEvent.getComponent(), mouseEvent.getX(), mouseEvent.getY()); } } @@ -336,6 +382,11 @@ public class BTC_MainPanel extends javax.swing.JFrame }); } + public void copyToClipboard(final String myString) + { + Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(myString), null); + } + public final void loadServerList() { try