Added options to enable and disable autoscrolling.

Update to Java 1.7.
A few other bugfixes.
This commit is contained in:
Steven Lawson 2013-08-02 21:04:47 -04:00
parent 7236d9d867
commit 23e1af4e9e
8 changed files with 179 additions and 117 deletions

View file

@ -4,4 +4,4 @@ BukkitTelnetClient
BukkitTelnetClient is a very, very basic telnet client for use with the BukkitTelnet CraftBukkit plugin. BukkitTelnetClient is a very, very basic telnet client for use with the BukkitTelnet CraftBukkit plugin.
A recent binary can be found here: A recent binary can be found here:
http://s3.madgeekonline.com/BukkitTelnetClient.jar http://s3.madgeekonline.com/BukkitTelnetClient-v1_3.jar

View file

@ -134,9 +134,7 @@ is divided into following sections:
</or> </or>
</condition> </condition>
<condition property="have.tests"> <condition property="have.tests">
<or> <or/>
<available file="${test.src.dir}"/>
</or>
</condition> </condition>
<condition property="have.sources"> <condition property="have.sources">
<or> <or>
@ -229,7 +227,6 @@ is divided into following sections:
</target> </target>
<target depends="-pre-init,-init-private,-init-user,-init-project,-do-init" name="-init-check"> <target depends="-pre-init,-init-private,-init-user,-init-project,-do-init" name="-init-check">
<fail unless="src.dir">Must set src.dir</fail> <fail unless="src.dir">Must set src.dir</fail>
<fail unless="test.src.dir">Must set test.src.dir</fail>
<fail unless="build.dir">Must set build.dir</fail> <fail unless="build.dir">Must set build.dir</fail>
<fail unless="dist.dir">Must set dist.dir</fail> <fail unless="dist.dir">Must set dist.dir</fail>
<fail unless="build.classes.dir">Must set build.classes.dir</fail> <fail unless="build.classes.dir">Must set build.classes.dir</fail>
@ -370,6 +367,11 @@ is divided into following sections:
</and> </and>
</condition> </condition>
</target> </target>
<target name="-init-test-properties">
<property name="test.binaryincludes" value="&lt;nothing&gt;"/>
<property name="test.binarytestincludes" value=""/>
<property name="test.binaryexcludes" value=""/>
</target>
<target if="${nb.junit.single}" name="-init-macrodef-junit-single" unless="${nb.junit.batch}"> <target if="${nb.junit.single}" name="-init-macrodef-junit-single" unless="${nb.junit.batch}">
<macrodef name="junit" uri="http://www.netbeans.org/ns/j2se-project/3"> <macrodef name="junit" uri="http://www.netbeans.org/ns/j2se-project/3">
<attribute default="${includes}" name="includes"/> <attribute default="${includes}" name="includes"/>
@ -393,7 +395,7 @@ is divided into following sections:
</sequential> </sequential>
</macrodef> </macrodef>
</target> </target>
<target if="${nb.junit.batch}" name="-init-macrodef-junit-batch" unless="${nb.junit.single}"> <target depends="-init-test-properties" if="${nb.junit.batch}" name="-init-macrodef-junit-batch" unless="${nb.junit.single}">
<macrodef name="junit" uri="http://www.netbeans.org/ns/j2se-project/3"> <macrodef name="junit" uri="http://www.netbeans.org/ns/j2se-project/3">
<attribute default="${includes}" name="includes"/> <attribute default="${includes}" name="includes"/>
<attribute default="${excludes}" name="excludes"/> <attribute default="${excludes}" name="excludes"/>
@ -404,8 +406,8 @@ is divided into following sections:
<property name="junit.forkmode" value="perTest"/> <property name="junit.forkmode" value="perTest"/>
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" showoutput="true" tempdir="${build.dir}"> <junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" showoutput="true" tempdir="${build.dir}">
<batchtest todir="${build.test.results.dir}"> <batchtest todir="${build.test.results.dir}">
<fileset dir="${test.src.dir}" excludes="@{excludes},${excludes}" includes="@{includes}"> <fileset dir="${build.test.classes.dir}" excludes="@{excludes},${excludes},${test.binaryexcludes}" includes="${test.binaryincludes}">
<filename name="@{testincludes}"/> <filename name="${test.binarytestincludes}"/>
</fileset> </fileset>
</batchtest> </batchtest>
<syspropertyset> <syspropertyset>
@ -432,11 +434,7 @@ is divided into following sections:
<condition else="" property="testng.methods.arg" value="@{testincludes}.@{testmethods}"> <condition else="" property="testng.methods.arg" value="@{testincludes}.@{testmethods}">
<isset property="test.method"/> <isset property="test.method"/>
</condition> </condition>
<union id="test.set"> <union id="test.set"/>
<fileset dir="${test.src.dir}" excludes="@{excludes},**/*.xml,${excludes}" includes="@{includes}">
<filename name="@{testincludes}"/>
</fileset>
</union>
<taskdef classname="org.testng.TestNGAntTask" classpath="${run.test.classpath}" name="testng"/> <taskdef classname="org.testng.TestNGAntTask" classpath="${run.test.classpath}" name="testng"/>
<testng classfilesetref="test.set" failureProperty="tests.failed" methods="${testng.methods.arg}" mode="${testng.mode}" outputdir="${build.test.results.dir}" suitename="BukkitTelnetClient" testname="TestNG tests" workingDir="${work.dir}"> <testng classfilesetref="test.set" failureProperty="tests.failed" methods="${testng.methods.arg}" mode="${testng.mode}" outputdir="${build.test.results.dir}" suitename="BukkitTelnetClient" testname="TestNG tests" workingDir="${work.dir}">
<xmlfileset dir="${build.test.classes.dir}" includes="@{testincludes}"/> <xmlfileset dir="${build.test.classes.dir}" includes="@{testincludes}"/>
@ -534,7 +532,7 @@ is divided into following sections:
</sequential> </sequential>
</macrodef> </macrodef>
</target> </target>
<target if="${nb.junit.batch}" name="-init-macrodef-junit-debug-batch"> <target depends="-init-test-properties" if="${nb.junit.batch}" name="-init-macrodef-junit-debug-batch">
<macrodef name="junit-debug" uri="http://www.netbeans.org/ns/j2se-project/3"> <macrodef name="junit-debug" uri="http://www.netbeans.org/ns/j2se-project/3">
<attribute default="${includes}" name="includes"/> <attribute default="${includes}" name="includes"/>
<attribute default="${excludes}" name="excludes"/> <attribute default="${excludes}" name="excludes"/>
@ -545,8 +543,8 @@ is divided into following sections:
<property name="junit.forkmode" value="perTest"/> <property name="junit.forkmode" value="perTest"/>
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" showoutput="true" tempdir="${build.dir}"> <junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" showoutput="true" tempdir="${build.dir}">
<batchtest todir="${build.test.results.dir}"> <batchtest todir="${build.test.results.dir}">
<fileset dir="${test.src.dir}" excludes="@{excludes},${excludes}" includes="@{includes}"> <fileset dir="${build.test.classes.dir}" excludes="@{excludes},${excludes},${test.binaryexcludes}" includes="${test.binaryincludes}">
<filename name="@{testincludes}"/> <filename name="${test.binarytestincludes}"/>
</fileset> </fileset>
</batchtest> </batchtest>
<syspropertyset> <syspropertyset>
@ -920,7 +918,7 @@ is divided into following sections:
<target if="has.persistence.xml" name="-copy-persistence-xml"> <target if="has.persistence.xml" name="-copy-persistence-xml">
<mkdir dir="${build.classes.dir}/META-INF"/> <mkdir dir="${build.classes.dir}/META-INF"/>
<copy todir="${build.classes.dir}/META-INF"> <copy todir="${build.classes.dir}/META-INF">
<fileset dir="${meta.inf.dir}" includes="persistence.xml"/> <fileset dir="${meta.inf.dir}" includes="persistence.xml orm.xml"/>
</copy> </copy>
</target> </target>
<target name="-post-compile"> <target name="-post-compile">
@ -1231,13 +1229,11 @@ is divided into following sections:
<!-- You can override this target in the ../build.xml file. --> <!-- You can override this target in the ../build.xml file. -->
</target> </target>
<target if="do.depend.true" name="-compile-test-depend"> <target if="do.depend.true" name="-compile-test-depend">
<j2seproject3:depend classpath="${javac.test.classpath}" destdir="${build.test.classes.dir}" srcdir="${test.src.dir}"/> <j2seproject3:depend classpath="${javac.test.classpath}" destdir="${build.test.classes.dir}" srcdir=""/>
</target> </target>
<target depends="init,deps-jar,compile,-pre-pre-compile-test,-pre-compile-test,-compile-test-depend" if="have.tests" name="-do-compile-test"> <target depends="init,deps-jar,compile,-pre-pre-compile-test,-pre-compile-test,-compile-test-depend" if="have.tests" name="-do-compile-test">
<j2seproject3:javac apgeneratedsrcdir="${build.test.classes.dir}" classpath="${javac.test.classpath}" debug="true" destdir="${build.test.classes.dir}" processorpath="${javac.test.processorpath}" srcdir="${test.src.dir}"/> <j2seproject3:javac apgeneratedsrcdir="${build.test.classes.dir}" classpath="${javac.test.classpath}" debug="true" destdir="${build.test.classes.dir}" processorpath="${javac.test.processorpath}" srcdir=""/>
<copy todir="${build.test.classes.dir}"> <copy todir="${build.test.classes.dir}"/>
<fileset dir="${test.src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
</copy>
</target> </target>
<target name="-post-compile-test"> <target name="-post-compile-test">
<!-- Empty placeholder for easier customization. --> <!-- Empty placeholder for easier customization. -->
@ -1251,10 +1247,8 @@ is divided into following sections:
<target depends="init,deps-jar,compile,-pre-pre-compile-test,-pre-compile-test-single" if="have.tests" name="-do-compile-test-single"> <target depends="init,deps-jar,compile,-pre-pre-compile-test,-pre-compile-test-single" if="have.tests" name="-do-compile-test-single">
<fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail> <fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
<j2seproject3:force-recompile destdir="${build.test.classes.dir}"/> <j2seproject3:force-recompile destdir="${build.test.classes.dir}"/>
<j2seproject3:javac apgeneratedsrcdir="${build.test.classes.dir}" classpath="${javac.test.classpath}" debug="true" destdir="${build.test.classes.dir}" excludes="" includes="${javac.includes}" processorpath="${javac.test.processorpath}" sourcepath="${test.src.dir}" srcdir="${test.src.dir}"/> <j2seproject3:javac apgeneratedsrcdir="${build.test.classes.dir}" classpath="${javac.test.classpath}" debug="true" destdir="${build.test.classes.dir}" excludes="" includes="${javac.includes}" processorpath="${javac.test.processorpath}" sourcepath="" srcdir=""/>
<copy todir="${build.test.classes.dir}"> <copy todir="${build.test.classes.dir}"/>
<fileset dir="${test.src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
</copy>
</target> </target>
<target name="-post-compile-test-single"> <target name="-post-compile-test-single">
<!-- Empty placeholder for easier customization. --> <!-- Empty placeholder for easier customization. -->

View file

@ -1,8 +1,8 @@
build.xml.data.CRC32=b147f9b6 build.xml.data.CRC32=b53f58a0
build.xml.script.CRC32=71290436 build.xml.script.CRC32=71290436
build.xml.stylesheet.CRC32=28e38971@1.50.2.46 build.xml.stylesheet.CRC32=28e38971@1.56.1.46
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=b147f9b6 nbproject/build-impl.xml.data.CRC32=b53f58a0
nbproject/build-impl.xml.script.CRC32=6eb617a8 nbproject/build-impl.xml.script.CRC32=5a1afff7
nbproject/build-impl.xml.stylesheet.CRC32=6ddba6b6@1.53.1.46 nbproject/build-impl.xml.stylesheet.CRC32=c6d2a60f@1.56.1.46

View file

@ -35,12 +35,12 @@ javac.classpath=\
${libs.Apache_Commons_Lang.classpath}:\ ${libs.Apache_Commons_Lang.classpath}:\
${libs.Apache_Commons_Net.classpath} ${libs.Apache_Commons_Net.classpath}
# Space-separated list of extra javac options # Space-separated list of extra javac options
javac.compilerargs= javac.compilerargs=-Xlint:unchecked
javac.deprecation=false javac.deprecation=false
javac.processorpath=\ javac.processorpath=\
${javac.classpath} ${javac.classpath}
javac.source=1.6 javac.source=1.7
javac.target=1.6 javac.target=1.7
javac.test.classpath=\ javac.test.classpath=\
${javac.classpath}:\ ${javac.classpath}:\
${build.classes.dir} ${build.classes.dir}
@ -83,4 +83,3 @@ run.test.classpath=\
${build.test.classes.dir} ${build.test.classes.dir}
source.encoding=UTF-8 source.encoding=UTF-8
src.dir=src src.dir=src
test.src.dir=test

View file

@ -7,9 +7,7 @@
<source-roots> <source-roots>
<root id="src.dir"/> <root id="src.dir"/>
</source-roots> </source-roots>
<test-roots> <test-roots/>
<root id="test.src.dir"/>
</test-roots>
</data> </data>
</configuration> </configuration>
</project> </project>

View file

@ -29,6 +29,8 @@ public class BTC_ConnectionManager
btc.getTxt_server().setEnabled(false); btc.getTxt_server().setEnabled(false);
btc.getBtn_disconnect().setEnabled(true); btc.getBtn_disconnect().setEnabled(true);
this.btc.setTitle("BukkitTelnetClient - v1.3 - " + hostname + ":" + port);
System.out.println("Connecting to " + hostname + ":" + port + "..."); System.out.println("Connecting to " + hostname + ":" + port + "...");
this.hostname = hostname; this.hostname = hostname;
@ -86,6 +88,8 @@ public class BTC_ConnectionManager
btc.getBtn_send().setEnabled(false); btc.getBtn_send().setEnabled(false);
btc.getTxt_command().setEnabled(false); btc.getTxt_command().setEnabled(false);
this.btc.setTitle("BukkitTelnetClient - v1.3 - Disconnected");
System.out.println("\nDisconnected."); System.out.println("\nDisconnected.");
} }

View file

@ -7,6 +7,7 @@
</Properties> </Properties>
<SyntheticProperties> <SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/> <SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties> </SyntheticProperties>
<AuxValues> <AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/> <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
@ -34,17 +35,18 @@
</Group> </Group>
<EmptySpace type="separate" max="-2" attributes="0"/> <EmptySpace type="separate" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Component id="txt_command" pref="566" max="32767" attributes="0"/> <Component id="txt_command" pref="483" max="32767" attributes="0"/>
<Component id="txt_server" max="32767" attributes="0"/> <Component id="txt_server" max="32767" attributes="0"/>
</Group> </Group>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0"> <Group type="103" groupAlignment="0" max="-2" attributes="0">
<Group type="102" attributes="0"> <Component id="btn_connect" linkSize="4" max="32767" attributes="0"/>
<Component id="btn_connect" linkSize="4" min="-2" max="-2" attributes="0"/> <Component id="btn_send" linkSize="4" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="btn_disconnect" linkSize="4" min="-2" max="-2" attributes="0"/>
</Group> </Group>
<Component id="btn_send" max="32767" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="btn_disconnect" linkSize="4" min="-2" max="-2" attributes="0"/>
<Component id="chkAutoScroll" linkSize="4" min="-2" max="-2" attributes="0"/>
</Group> </Group>
</Group> </Group>
</Group> </Group>
@ -56,12 +58,13 @@
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0"> <Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="jScrollPane1" pref="334" max="32767" attributes="0"/> <Component id="jScrollPane1" pref="275" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0"> <Group type="103" groupAlignment="3" attributes="0">
<Component id="txt_command" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="txt_command" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jLabel1" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="jLabel1" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btn_send" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="btn_send" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="chkAutoScroll" alignment="3" min="-2" max="-2" attributes="0"/>
</Group> </Group>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0"> <Group type="103" groupAlignment="3" attributes="0">
@ -106,7 +109,7 @@
<Property name="text" type="java.lang.String" value="Connect"/> <Property name="text" type="java.lang.String" value="Connect"/>
</Properties> </Properties>
<Events> <Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="btn_connectMouseClicked"/> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btn_connectActionPerformed"/>
</Events> </Events>
</Component> </Component>
<Component class="javax.swing.JLabel" name="jLabel1"> <Component class="javax.swing.JLabel" name="jLabel1">
@ -125,7 +128,7 @@
<Property name="enabled" type="boolean" value="false"/> <Property name="enabled" type="boolean" value="false"/>
</Properties> </Properties>
<Events> <Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="btn_disconnectMouseClicked"/> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btn_disconnectActionPerformed"/>
</Events> </Events>
</Component> </Component>
<Component class="javax.swing.JButton" name="btn_send"> <Component class="javax.swing.JButton" name="btn_send">
@ -134,7 +137,7 @@
<Property name="enabled" type="boolean" value="false"/> <Property name="enabled" type="boolean" value="false"/>
</Properties> </Properties>
<Events> <Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="btn_sendMouseClicked"/> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btn_sendActionPerformed"/>
</Events> </Events>
</Component> </Component>
<Component class="javax.swing.JComboBox" name="txt_server"> <Component class="javax.swing.JComboBox" name="txt_server">
@ -145,5 +148,14 @@
</Property> </Property>
</Properties> </Properties>
</Component> </Component>
<Component class="javax.swing.JCheckBox" name="chkAutoScroll">
<Properties>
<Property name="selected" type="boolean" value="true"/>
<Property name="text" type="java.lang.String" value="AutoScroll"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="chkAutoScrollActionPerformed"/>
</Events>
</Component>
</SubComponents> </SubComponents>
</Form> </Form>

View file

@ -22,25 +22,36 @@ public class BukkitTelnetClient extends javax.swing.JFrame
public static final String SERVERS_FILE_NAME = "btc_servers.cfg"; public static final String SERVERS_FILE_NAME = "btc_servers.cfg";
private static final Logger logger = Logger.getLogger("BukkitTelnetClient"); private static final Logger logger = Logger.getLogger("BukkitTelnetClient");
private BTC_ConnectionManager connection_mgr; private BTC_ConnectionManager connection_mgr;
private final LinkedList<String> server_list = new LinkedList<String>(); private final LinkedList<String> server_list = new LinkedList<>();
private static BukkitTelnetClient btc = null;
public BukkitTelnetClient() private static void setup()
{ {
initComponents(); btc = new BukkitTelnetClient();
txt_server.getEditor().getEditorComponent().addKeyListener(new KeyAdapter()
btc.initComponents();
btc.setLocationRelativeTo(null);
btc.txt_server.getEditor().getEditorComponent().addKeyListener(new KeyAdapter()
{ {
@Override @Override
public void keyTyped(KeyEvent e) public void keyTyped(KeyEvent e)
{ {
if (e.getKeyChar() == KeyEvent.VK_ENTER) if (e.getKeyChar() == KeyEvent.VK_ENTER)
{ {
saveServersAndTriggerConnect(); btc.saveServersAndTriggerConnect();
} }
} }
}); });
redirectSystemStreams();
loadServerList(); btc.redirectSystemStreams();
connection_mgr = new BTC_ConnectionManager(this);
btc.loadServerList();
btc.connection_mgr = new BTC_ConnectionManager(btc);
btc.setVisible(true);
} }
private void updateTextPane(final String text) private void updateTextPane(final String text)
@ -59,7 +70,10 @@ public class BukkitTelnetClient extends javax.swing.JFrame
{ {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
main_output.setCaretPosition(doc.getLength() - 1); if (btc.chkAutoScroll.isSelected() && btc.main_output.getSelectedText() == null)
{
btc.main_output.setCaretPosition(doc.getLength() - 1);
}
} }
}); });
} }
@ -91,6 +105,7 @@ public class BukkitTelnetClient extends javax.swing.JFrame
System.setErr(new PrintStream(out, true)); System.setErr(new PrintStream(out, true));
} }
@SuppressWarnings("unchecked")
private void loadServerList() private void loadServerList()
{ {
try try
@ -101,7 +116,8 @@ public class BukkitTelnetClient extends javax.swing.JFrame
File file = new File(SERVERS_FILE_NAME); File file = new File(SERVERS_FILE_NAME);
if (file.exists()) if (file.exists())
{ {
BufferedReader in = new BufferedReader(new FileReader(file)); try (BufferedReader in = new BufferedReader(new FileReader(file)))
{
String line; String line;
while ((line = in.readLine()) != null) while ((line = in.readLine()) != null)
{ {
@ -109,7 +125,7 @@ public class BukkitTelnetClient extends javax.swing.JFrame
server_list.add(line); server_list.add(line);
txt_server.addItem(line); txt_server.addItem(line);
} }
in.close(); }
} }
} }
catch (Exception ex) catch (Exception ex)
@ -136,15 +152,13 @@ public class BukkitTelnetClient extends javax.swing.JFrame
} }
server_list.addFirst(selected_server); server_list.addFirst(selected_server);
try (BufferedWriter out = new BufferedWriter(new FileWriter(new File(SERVERS_FILE_NAME))))
BufferedWriter out = new BufferedWriter(new FileWriter(new File(SERVERS_FILE_NAME))); {
for (String server : server_list) for (String server : server_list)
{ {
out.write(server + '\n'); out.write(server + '\n');
} }
}
out.close();
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -170,6 +184,7 @@ public class BukkitTelnetClient extends javax.swing.JFrame
btn_disconnect = new javax.swing.JButton(); btn_disconnect = new javax.swing.JButton();
btn_send = new javax.swing.JButton(); btn_send = new javax.swing.JButton();
txt_server = new javax.swing.JComboBox(); txt_server = new javax.swing.JComboBox();
chkAutoScroll = new javax.swing.JCheckBox();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("BukkitTelnetClient"); setTitle("BukkitTelnetClient");
@ -188,11 +203,11 @@ public class BukkitTelnetClient extends javax.swing.JFrame
}); });
btn_connect.setText("Connect"); btn_connect.setText("Connect");
btn_connect.addMouseListener(new java.awt.event.MouseAdapter() btn_connect.addActionListener(new java.awt.event.ActionListener()
{ {
public void mouseClicked(java.awt.event.MouseEvent evt) public void actionPerformed(java.awt.event.ActionEvent evt)
{ {
btn_connectMouseClicked(evt); btn_connectActionPerformed(evt);
} }
}); });
@ -202,26 +217,36 @@ public class BukkitTelnetClient extends javax.swing.JFrame
btn_disconnect.setText("Disconnect"); btn_disconnect.setText("Disconnect");
btn_disconnect.setEnabled(false); btn_disconnect.setEnabled(false);
btn_disconnect.addMouseListener(new java.awt.event.MouseAdapter() btn_disconnect.addActionListener(new java.awt.event.ActionListener()
{ {
public void mouseClicked(java.awt.event.MouseEvent evt) public void actionPerformed(java.awt.event.ActionEvent evt)
{ {
btn_disconnectMouseClicked(evt); btn_disconnectActionPerformed(evt);
} }
}); });
btn_send.setText("Send"); btn_send.setText("Send");
btn_send.setEnabled(false); btn_send.setEnabled(false);
btn_send.addMouseListener(new java.awt.event.MouseAdapter() btn_send.addActionListener(new java.awt.event.ActionListener()
{ {
public void mouseClicked(java.awt.event.MouseEvent evt) public void actionPerformed(java.awt.event.ActionEvent evt)
{ {
btn_sendMouseClicked(evt); btn_sendActionPerformed(evt);
} }
}); });
txt_server.setEditable(true); txt_server.setEditable(true);
chkAutoScroll.setSelected(true);
chkAutoScroll.setText("AutoScroll");
chkAutoScroll.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
chkAutoScrollActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout); getContentPane().setLayout(layout);
layout.setHorizontalGroup( layout.setHorizontalGroup(
@ -236,30 +261,32 @@ public class BukkitTelnetClient extends javax.swing.JFrame
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(18, 18, 18) .addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txt_command, javax.swing.GroupLayout.DEFAULT_SIZE, 566, Short.MAX_VALUE) .addComponent(txt_command, javax.swing.GroupLayout.DEFAULT_SIZE, 483, Short.MAX_VALUE)
.addComponent(txt_server, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addComponent(txt_server, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup() .addComponent(btn_connect, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btn_connect) .addComponent(btn_send, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btn_disconnect)) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btn_send, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) .addComponent(btn_disconnect)
.addComponent(chkAutoScroll))))
.addContainerGap()) .addContainerGap())
); );
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btn_connect, btn_disconnect}); layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btn_connect, btn_disconnect, btn_send, chkAutoScroll});
layout.setVerticalGroup( layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addContainerGap() .addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 334, Short.MAX_VALUE) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 275, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txt_command, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(txt_command, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1) .addComponent(jLabel1)
.addComponent(btn_send)) .addComponent(btn_send)
.addComponent(chkAutoScroll))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2) .addComponent(jLabel2)
@ -272,24 +299,6 @@ public class BukkitTelnetClient extends javax.swing.JFrame
pack(); pack();
}// </editor-fold>//GEN-END:initComponents }// </editor-fold>//GEN-END:initComponents
private void btn_connectMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_btn_connectMouseClicked
{//GEN-HEADEREND:event_btn_connectMouseClicked
if (!btn_connect.isEnabled())
{
return;
}
saveServersAndTriggerConnect();
}//GEN-LAST:event_btn_connectMouseClicked
private void btn_disconnectMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_btn_disconnectMouseClicked
{//GEN-HEADEREND:event_btn_disconnectMouseClicked
if (!btn_disconnect.isEnabled())
{
return;
}
connection_mgr.trigger_disconnect();
}//GEN-LAST:event_btn_disconnectMouseClicked
private void txt_commandKeyPressed(java.awt.event.KeyEvent evt)//GEN-FIRST:event_txt_commandKeyPressed private void txt_commandKeyPressed(java.awt.event.KeyEvent evt)//GEN-FIRST:event_txt_commandKeyPressed
{//GEN-HEADEREND:event_txt_commandKeyPressed {//GEN-HEADEREND:event_txt_commandKeyPressed
if (!txt_command.isEnabled()) if (!txt_command.isEnabled())
@ -303,39 +312,84 @@ public class BukkitTelnetClient extends javax.swing.JFrame
} }
}//GEN-LAST:event_txt_commandKeyPressed }//GEN-LAST:event_txt_commandKeyPressed
private void btn_sendMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_btn_sendMouseClicked private void chkAutoScrollActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_chkAutoScrollActionPerformed
{//GEN-HEADEREND:event_btn_sendMouseClicked {//GEN-HEADEREND:event_chkAutoScrollActionPerformed
updateTextPane("");
}//GEN-LAST:event_chkAutoScrollActionPerformed
private void btn_connectActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btn_connectActionPerformed
{//GEN-HEADEREND:event_btn_connectActionPerformed
if (!btn_connect.isEnabled())
{
return;
}
saveServersAndTriggerConnect();
}//GEN-LAST:event_btn_connectActionPerformed
private void btn_disconnectActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btn_disconnectActionPerformed
{//GEN-HEADEREND:event_btn_disconnectActionPerformed
if (!btn_disconnect.isEnabled())
{
return;
}
connection_mgr.trigger_disconnect();
}//GEN-LAST:event_btn_disconnectActionPerformed
private void btn_sendActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btn_sendActionPerformed
{//GEN-HEADEREND:event_btn_sendActionPerformed
if (!btn_send.isEnabled()) if (!btn_send.isEnabled())
{ {
return; return;
} }
connection_mgr.send_command(txt_command.getText()); connection_mgr.send_command(txt_command.getText());
txt_command.selectAll(); txt_command.selectAll();
}//GEN-LAST:event_btn_sendMouseClicked }//GEN-LAST:event_btn_sendActionPerformed
public static void main(String args[]) private static void findAndSetLookAndFeel(final String searchStyleName)
{ {
try try
{ {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) javax.swing.UIManager.LookAndFeelInfo foundStyle = null;
javax.swing.UIManager.LookAndFeelInfo fallbackStyle = null;
for (javax.swing.UIManager.LookAndFeelInfo style : javax.swing.UIManager.getInstalledLookAndFeels())
{ {
if ("Nimbus".equals(info.getName())) if (searchStyleName.equalsIgnoreCase(style.getName()))
{ {
javax.swing.UIManager.setLookAndFeel(info.getClassName()); foundStyle = style;
break; break;
} }
else if ("Nimbus".equalsIgnoreCase(style.getName()))
{
fallbackStyle = style;
} }
} }
catch (Exception ex)
if (foundStyle != null)
{
javax.swing.UIManager.setLookAndFeel(foundStyle.getClassName());
}
else if (fallbackStyle != null)
{
javax.swing.UIManager.setLookAndFeel(fallbackStyle.getClassName());
}
}
catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex)
{ {
logger.log(Level.SEVERE, null, ex); logger.log(Level.SEVERE, null, ex);
} }
}
public static void main(String args[])
{
findAndSetLookAndFeel("Windows");
java.awt.EventQueue.invokeLater(new Runnable() java.awt.EventQueue.invokeLater(new Runnable()
{ {
@Override
public void run() public void run()
{ {
new BukkitTelnetClient().setVisible(true); BukkitTelnetClient.setup();
} }
}); });
} }
@ -343,6 +397,7 @@ public class BukkitTelnetClient extends javax.swing.JFrame
private javax.swing.JButton btn_connect; private javax.swing.JButton btn_connect;
private javax.swing.JButton btn_disconnect; private javax.swing.JButton btn_disconnect;
private javax.swing.JButton btn_send; private javax.swing.JButton btn_send;
private javax.swing.JCheckBox chkAutoScroll;
private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel2;
private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane1;