mirror of
https://github.com/TotalFreedomMC/ZeroTelnetClient.git
synced 2024-12-22 16:25:14 +00:00
Added copy name/ip on popup menu.
This commit is contained in:
parent
ad0ec69ac9
commit
4b632bdd23
1 changed files with 63 additions and 12 deletions
|
@ -2,6 +2,7 @@ package me.StevenLawson.BukkitTelnetClient;
|
||||||
|
|
||||||
import java.awt.EventQueue;
|
import java.awt.EventQueue;
|
||||||
import java.awt.Toolkit;
|
import java.awt.Toolkit;
|
||||||
|
import java.awt.datatransfer.StringSelection;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.awt.event.KeyAdapter;
|
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;
|
private final PlayerInfo player;
|
||||||
|
|
||||||
public CommandMenuItem(String text, ServerCommand command, PlayerInfo player)
|
public PlayerListPopupItem(String text, PlayerInfo player)
|
||||||
{
|
{
|
||||||
super(text);
|
super(text);
|
||||||
this.command = command;
|
|
||||||
this.player = player;
|
this.player = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ServerCommand getCommand()
|
|
||||||
{
|
|
||||||
return command;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PlayerInfo getPlayer()
|
public PlayerInfo getPlayer()
|
||||||
{
|
{
|
||||||
return player;
|
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()
|
public final void setupTablePopup()
|
||||||
{
|
{
|
||||||
this.tblPlayers.addMouseListener(new MouseAdapter()
|
this.tblPlayers.addMouseListener(new MouseAdapter()
|
||||||
|
@ -310,25 +320,61 @@ public class BTC_MainPanel extends javax.swing.JFrame
|
||||||
public void actionPerformed(ActionEvent actionEvent)
|
public void actionPerformed(ActionEvent actionEvent)
|
||||||
{
|
{
|
||||||
Object _source = actionEvent.getSource();
|
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 PlayerInfo _player = source.getPlayer();
|
||||||
final ServerCommand _command = source.getCommand();
|
final ServerCommand _command = source.getCommand();
|
||||||
|
|
||||||
final String output = String.format(_command.getCommandFormat(), _player.getName());
|
final String output = String.format(_command.getCommandFormat(), _player.getName());
|
||||||
|
|
||||||
BTC_MainPanel.this.connectionManager.sendDelayedCommand(output, true, 100);
|
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())
|
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);
|
item.addActionListener(popupAction);
|
||||||
popup.add(item);
|
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());
|
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()
|
public final void loadServerList()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
Loading…
Reference in a new issue