Begin work on favorite buttons.

Todo - load favButtonList from XML.
This commit is contained in:
StevenLawson 2014-08-26 11:01:27 -04:00
parent bfbcfd1592
commit 06d54c1f58
6 changed files with 200 additions and 33 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
/target/
settings.xml

View file

@ -17,7 +17,7 @@ public class BTC_ConnectionManager
{
private static final Pattern LOGIN_MESSAGE = Pattern.compile("\\[.+?@BukkitTelnet\\]\\$ Logged in as (.+)\\.");
private final TelnetClient telnetClient;
private final TelnetClient telnetClient = new TelnetClient();
private Thread connectThread;
private String hostname;
private int port;
@ -26,7 +26,6 @@ public class BTC_ConnectionManager
public BTC_ConnectionManager()
{
this.telnetClient = new TelnetClient();
}
public void triggerConnect(final String hostname, final int port)
@ -119,6 +118,12 @@ public class BTC_ConnectionManager
BukkitTelnetClient.mainPanel.writeToConsole(new BTC_ConsoleMessage(":" + text));
}
final OutputStream out = this.telnetClient.getOutputStream();
if (out == null)
{
return;
}
this.telnetClient.getOutputStream().write((text + "\r\n").getBytes());
this.telnetClient.getOutputStream().flush();
}

View file

@ -0,0 +1,48 @@
package me.StevenLawson.BukkitTelnetClient;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JPanel;
public class BTC_FavoriteButtonsPanel extends JPanel
{
public BTC_FavoriteButtonsPanel(final List<FavoriteButtonData> buttonList)
{
super.setLayout(new GridLayout(0, 2, 1, 1));
final ActionListener actionListener = new ActionListener()
{
@Override
public void actionPerformed(final ActionEvent event)
{
if (BukkitTelnetClient.mainPanel != null)
{
BukkitTelnetClient.mainPanel.getConnectionManager().sendDelayedCommand(event.getActionCommand(), true, 100);
}
}
};
for (final FavoriteButtonData buttonData : buttonList)
{
final JButton button = new JButton();
button.setText(buttonData.getLabel());
button.setActionCommand(buttonData.getCommand());
button.addActionListener(actionListener);
final Dimension max = button.getMaximumSize();
max.setSize(max.getWidth(), 10);
button.setMaximumSize(max);
add(button);
}
}
@Override
public void setLayout(LayoutManager lm)
{
//Disable
}
}

View file

@ -368,6 +368,58 @@
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="jPanel4">
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout$JTabbedPaneConstraintsDescription">
<JTabbedPaneConstraints tabName="Commands">
<Property name="tabTitle" type="java.lang.String" value="Commands"/>
</JTabbedPaneConstraints>
</Constraint>
</Constraints>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jScrollPane1" pref="293" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jScrollPane1" pref="400" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
<Properties>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="null"/>
</Property>
</Properties>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Container class="javax.swing.JPanel" name="jPanel5">
<AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new BTC_FavoriteButtonsPanel(favButtonList)"/>
</AuxValues>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout">
<Property name="useNullLayout" type="boolean" value="true"/>
</Layout>
</Container>
</SubComponents>
</Container>
</SubComponents>
</Container>
</SubComponents>
</Container>
</SubComponents>

View file

@ -1,35 +1,16 @@
package me.StevenLawson.BukkitTelnetClient;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Toolkit;
import java.awt.*;
import java.awt.datatransfer.StringSelection;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.*;
import java.net.URL;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.*;
import java.util.List;
import java.util.Queue;
import javax.swing.JCheckBox;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.JScrollBar;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities;
import javax.swing.*;
import javax.swing.Timer;
import javax.swing.table.AbstractTableModel;
import javax.swing.text.BadLocationException;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyleContext;
import javax.swing.text.StyledDocument;
import javax.swing.text.*;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.SystemUtils;
@ -39,8 +20,30 @@ public class BTC_MainPanel extends javax.swing.JFrame
private final List<PlayerInfo> playerList = new ArrayList<>();
private final PlayerListTableModel playerListTableModel = new PlayerListTableModel(playerList);
private final List<FavoriteButtonData> favButtonList = new ArrayList<>();
public BTC_MainPanel()
{
favButtonList.add(new FavoriteButtonData("Op All", "opall"));
favButtonList.add(new FavoriteButtonData("Deop All", "deopall"));
favButtonList.add(new FavoriteButtonData("Nick Clean", "nickclean"));
favButtonList.add(new FavoriteButtonData("Adminmode ON", "adminmode on"));
favButtonList.add(new FavoriteButtonData("Adminmode OFF", "adminmode off"));
favButtonList.add(new FavoriteButtonData("Cake", "cake"));
favButtonList.add(new FavoriteButtonData("Mob Purge", "mp"));
favButtonList.add(new FavoriteButtonData("Remove Drops", "rd"));
favButtonList.add(new FavoriteButtonData("Purge All", "purgeall"));
favButtonList.add(new FavoriteButtonData("Set Limit = 500", "setl"));
favButtonList.add(new FavoriteButtonData("Stop Server", "stop"));
favButtonList.add(new FavoriteButtonData("Toggle Water Placement", "toggle waterplace"));
favButtonList.add(new FavoriteButtonData("Toggle Fire Placement", "toggle fireplace"));
favButtonList.add(new FavoriteButtonData("Toggle Lava Placement", "toggle lavaplace"));
favButtonList.add(new FavoriteButtonData("Toggle Fluid Spread", "toggle fluidspread"));
favButtonList.add(new FavoriteButtonData("Toggle Lava Damage", "toggle lavadmg"));
favButtonList.add(new FavoriteButtonData("Toggle Fire Spread", "toggle firespread"));
favButtonList.add(new FavoriteButtonData("Toggle Lockdown", "toggle lockdown"));
favButtonList.add(new FavoriteButtonData("Toggle Explosives", "toggle explosives"));
initComponents();
}
@ -68,7 +71,7 @@ public class BTC_MainPanel extends javax.swing.JFrame
setupTablePopup();
this.connectionManager.updateTitle(false);
this.getConnectionManager().updateTitle(false);
this.tblPlayers.setModel(playerListTableModel);
@ -352,7 +355,7 @@ public class BTC_MainPanel extends javax.swing.JFrame
final String output = String.format(_command.getFormat(), _player.getName());
BTC_MainPanel.this.connectionManager.sendDelayedCommand(output, true, 100);
BTC_MainPanel.this.getConnectionManager().sendDelayedCommand(output, true, 100);
}
else if (_source instanceof PlayerListPopupItem)
{
@ -482,7 +485,7 @@ public class BTC_MainPanel extends javax.swing.JFrame
loadServerList();
connectionManager.triggerConnect(entry.getAddress());
getConnectionManager().triggerConnect(entry.getAddress());
}
@SuppressWarnings("unchecked")
@ -513,6 +516,9 @@ public class BTC_MainPanel extends javax.swing.JFrame
chkIgnoreServerCommands = new javax.swing.JCheckBox();
chkShowChatOnly = new javax.swing.JCheckBox();
chkIgnoreErrors = new javax.swing.JCheckBox();
jPanel4 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
jPanel5 = new BTC_FavoriteButtonsPanel(favButtonList);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("BukkitTelnetClient");
@ -712,6 +718,30 @@ public class BTC_MainPanel extends javax.swing.JFrame
jTabbedPane1.addTab("Filters", jPanel1);
jScrollPane1.setBorder(null);
jPanel5.setLayout(null);
jScrollPane1.setViewportView(jPanel5);
javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
jPanel4.setLayout(jPanel4Layout);
jPanel4Layout.setHorizontalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 293, Short.MAX_VALUE)
.addContainerGap())
);
jPanel4Layout.setVerticalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
.addContainerGap())
);
jTabbedPane1.addTab("Commands", jPanel4);
splitPane.setRightComponent(jTabbedPane1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
@ -742,7 +772,7 @@ public class BTC_MainPanel extends javax.swing.JFrame
}
if (evt.getKeyCode() == KeyEvent.VK_ENTER)
{
connectionManager.sendCommand(txtCommand.getText());
getConnectionManager().sendCommand(txtCommand.getText());
txtCommand.selectAll();
}
}//GEN-LAST:event_txtCommandKeyPressed
@ -762,7 +792,7 @@ public class BTC_MainPanel extends javax.swing.JFrame
{
return;
}
connectionManager.triggerDisconnect();
getConnectionManager().triggerDisconnect();
}//GEN-LAST:event_btnDisconnectActionPerformed
private void btnSendActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnSendActionPerformed
@ -771,7 +801,7 @@ public class BTC_MainPanel extends javax.swing.JFrame
{
return;
}
connectionManager.sendCommand(txtCommand.getText());
getConnectionManager().sendCommand(txtCommand.getText());
txtCommand.selectAll();
}//GEN-LAST:event_btnSendActionPerformed
@ -802,6 +832,9 @@ public class BTC_MainPanel extends javax.swing.JFrame
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JPanel jPanel5;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTabbedPane jTabbedPane1;
private javax.swing.JTextPane mainOutput;
@ -872,4 +905,9 @@ public class BTC_MainPanel extends javax.swing.JFrame
{
return playerList;
}
public BTC_ConnectionManager getConnectionManager()
{
return connectionManager;
}
}

View file

@ -0,0 +1,23 @@
package me.StevenLawson.BukkitTelnetClient;
public class FavoriteButtonData
{
private final String label;
private final String command;
public FavoriteButtonData(String label, String command)
{
this.label = label;
this.command = command;
}
public String getLabel()
{
return label;
}
public String getCommand()
{
return command;
}
}